offsetwp/hook-wordpress
最新稳定版本:1.0.1
Composer 安装命令:
composer require offsetwp/hook-wordpress
包简介
Typed, secure, and maintainable WordPress Core action and filter hooks
README 文档
README
OffsetWP Hook
Typed, secure, and maintainable WordPress Core action and filter hooks
About OffsetWP WordPress
WordPress makes extensive use of hooks for its internal functioning. Unfortunately, the way it was developed makes it difficult to work with hook data:
- the callback is public and accessible by any other function
- to find out the returned parameters, you have to consult the documentation
- no auto-completion
OffsetWP Hook provides ready-to-use wrappers for native WordPress hooks. The wrappers already include the exact callback signatures, allowing for optimal autocompletion in your IDE.
Installation
composer require offsetwp/hook
Basic usage
use OffsetWP\Hook\WordPress\Filter\WPAdminFooterTextFilter; new class extends WPAdminFooterTextFilter { protected function handle( $text ) { return 'Made with love by OffsetWP | ' . $text; } };
Hook with a dynamique name
use OffsetWP\Hook\WordPress\Filter\WPGetMetaTypeMetadataFilter; new class extends WPGetMetaTypeMetadataFilter { public string $hook_name = 'get_post_metadata'; // 'get_{$meta_type}_metadata' protected function handle( $value, $object_id, $meta_key, $single, $meta_type ) { return $value; } };
Advanced usage
With more substantial development, it may be necessary for your hooks to use dependencies. All of this is possible, depending on your needs:
use OffsetWP\Hook\WordPress\Filter\WPAdminFooterTextFilter; new class extends WPAdminFooterTextFilter { public function __construct( private $myServiceName = 'CustomService' ) { return parent::__construct(); } protected function handle( $text ) { return $this->myServiceName . ' | ' . $text; } }
统计信息
- 总下载量: 3
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-12-18

