shineunited/wordpress-hooks
Composer 安装命令:
composer require shineunited/wordpress-hooks
包简介
Tool for managing WordPress hooks prior to initialization.
README 文档
README
Description
A tool for managing WordPress hooks. Allows registration of hooks prior to WordPress initialization and provides a framework for defining hooks using PHP attributes.
Installation
to add wordpress-hooks, the recommended method is via composer.
$ composer require shineunited/wordpress-hooks
HookManager
The HookManager class provides static methods for managing WordPress hooks. While most of the functions are simply aliased to the built-in WordPress functions, some of them all management of hooks prior to initialization.
use ShineUnited\WordPress\Hooks\HookManager; function callback_function($param1, $param2) { // code } // this can be used prior to initialization HookManager::addFilter('filter-name', 'callback-function', 10, 2);
Attribute Hooks
Hooks can also be defined by using the Hook attributes and HookManager::register();
use ShineUnited\WordPress\Hooks\Filter; use ShineUnited\WordPress\Hooks\HookManager; class MyObjectHooks { #[Filter('lowercase')] public function lowercase(string $value): string { return strtolower($value); } #[Filter('uppercase')] public function uppercase(string $value): string { return strtoupper($value); } } $hooks = new MyObjectHooks(); HookManager::register($hooks); // WordPress Equivalent // add_filter('lowercase', [$hooks, 'lowercase'], 10, 1); // add_filter('uppercase', [$hooks, 'uppercase'], 10, 1);
Multiple hooks can be applied to a single callback.
use ShineUnited\WordPress\Hooks\Action; use ShineUnited\WordPress\Hooks\Filter; use ShineUnited\WordPress\Hooks\HookManager; $closure = #[Filter('example-filter', 12)] #[Action('example-action')] function($value) { // code }; HookManager::register($closure); // WordPress Equivalent: // add_filter('example-filter', $closure, 12, 1); // add_filter('example-action', $closure, 10, 1);
Function Reference
For more details and examples please see our documentation.
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-01-12