shinepress/hooks
最新稳定版本:1.0.0
Composer 安装命令:
composer require shinepress/hooks
包简介
Tools for managing WordPress hooks before and after initialization
README 文档
README
Description
A tool for managing WordPress hooks. Allows registration of hooks prior to WordPress initialization as well as providing attributes that can be used for the same purpose in conjuction with the ShinePress framework.
Installation
The recommendend installation method is with composer:
$ composer require shinepress/hooks
Usage
HookManager
The HookManager class provides static methods for managing WordPress hooks.
use ShinePress\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
When using the framework, hooks can be defined by adding attributes to functions in your custom module class.
use ShinePress\Framework\Module; use ShinePress\Hooks\Filter; class CustomModule extends Module { #[Filter('lowercase')] public function lowercase(string $value): string { return strtolower($value); } #[Filter('uppercase')] public function uppercase(string $value): string { return strtoupper($value); } } CustomModule::register(); // WordPress Equivalent: // add_filter('lowercase', [CustomModule::instance(), 'lowercase'], 10, 1); // add_filter('uppercase', [CustomModule::instance(), 'uppercase'], 10, 1);
Multiple hooks can also be applied to a single callback.
use ShinePress\Framework\Module; use ShinePress\Hooks\Action; use ShinePress\Hooks\Filter; class CustomModule extends Module { #[Filter('example-filter', 12)] #[Action('example-action')] public function exampleFunction(mixed $value) { // do something } } CustomModule::register(); // WordPress Equivalent: // add_filter('example-filter', [CustomModule::instance(), 'exampleFunction'], 12, 1); // add_action('example-action', [CustomModule::instance(), 'exampleFunction'], 10, 1);
统计信息
- 总下载量: 21
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-05-15