hametuha/wp-enqueue-manager
Composer 安装命令:
composer require hametuha/wp-enqueue-manager
包简介
A WordPress library to bulk register assets.
README 文档
README
Bulk register WordPress assets with specified folder structure. Good shortcut for your theme development.
Installation
Use composer.
composer require hametuha/wp-enqueue-manager
Usage
Write dependnecies in your assets(js and css) header as comment.
format is like wpdeps=dependencies. CSV ready.
This notation will be used for the deps argument of wp_register_script(doc) and wp_register_style(doc).
Operations should be done in init hook or before. Write codes in your functions.php.
Javascript
Header file should be like below:
/*! * wpdeps=jquery,thicbox */ jQuery(document).ready(function($){ // Do something. });
NOTICE: If you use autoprefixer or minify tools, be careful about cleaning up comments.
Then, register them all from your theme or plugin.
// Register all js in folder. // e.g. /assets/js/sample.js will be regsitered as 'my-sample'. Hametuha\WpEnqueueManager::register_js( __DIR__ . '/assets/, 'my-', '1.0.0' );
Stylesheet
Same as javascript, regsier
/*! * wpdeps=bootstrap */ body{ background-color: red; }
And, run register_styles.
// Register all css in folder. // e.g. /assets/css/sample.css will be regsitered as 'my-sample'. Hametuha\WpEnqueueManager::register_styles( __DIR__ . '/assets/, 'my-', '1.0.0' );
Versionning
If you are a theme or plugin author, it's proper to pass the version of your theme/plugin.
Lazy authors may just pass null or skip the argument. Then the file modified time will be used as version string.
Localization
For Javascript localization, you can bulk register localization vars.
Hametuha\WpEnqueueManager::register_js_var_files( __DIR__ . '/l10n );
File name equals js handle name. Camelized handle name should be var name. PHP files should return var array.
For example, if you put my-sample.php below in l10n directory.
<?php // Avoide direct load. defined( 'ABSPATH' ) || die(); // Return JS vars. return [ 'label' => 'This is my var!', ];
Registered infromation are below:
- Handle: my-sample
- Var name: MySample
- Var: returned array of file.
So, you can refer PHP variables from JS like this:
$('.button').on('click', function(){ alert(MySample.label); // => This is my var! };
License
MIT.
hametuha/wp-enqueue-manager 适用场景与选型建议
hametuha/wp-enqueue-manager 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 12.25k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2017 年 12 月 20 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 hametuha/wp-enqueue-manager 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 hametuha/wp-enqueue-manager 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 12.25k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 21
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: GPL-3.0-or-later
- 更新时间: 2017-12-20