n5s/wp-hook-kit
Composer 安装命令:
composer require n5s/wp-hook-kit
包简介
A lightweight WordPress hook helper library. Register hooks before WordPress loads, run callbacks only once, and more.
关键字:
README 文档
README
A lightweight WordPress hook helper library. Register hooks before WordPress loads, run callbacks only once, and more.
Installation
composer require n5s/wp-hook-kit
Usage
use n5s\WpHookKit\Hook; // Basic usage - works even before WordPress is loaded Hook::addFilter('the_content', fn($content) => $content . '<p>Footer</p>'); Hook::addAction('init', fn() => register_post_type('book', [])); // Run a callback only once (removes itself after first execution) Hook::addFilterOnce('the_title', fn($title) => $title . ' - Launch Sale!'); Hook::addActionOnce('wp_footer', fn() => echo '<!-- First visit -->'); // Side effects - run code without modifying the filtered value Hook::addFilterSideEffect('the_content', function($content) { error_log('Content rendered: ' . strlen($content) . ' chars'); }); // Combine both: side effect that runs once Hook::addFilterSideEffectOnce('template_include', function($template) { log_first_template_load($template); }); // Register same callback on multiple hooks Hook::addFilters(['the_title', 'the_content'], 'esc_html'); Hook::addActions(['wp_head', 'wp_footer'], fn() => do_something());
All methods accept the standard WordPress parameters: $hook, $callback, $priority = 10, $accepted_args = 1.
Why?
Early registration: Register hooks before WordPress fully loads. The library writes directly to $wp_filter when add_filter() isn't available yet. Unlocks the power of bringing features without the "plugin" way hassle when it's not needed (library, composer autoloaded files, etc.).
Once variants: Because sometimes, you might not want your callback to be executed every time a hook is called.
Side effects: Runs your callback and returns the original value unchanged. Useful to trigger actions when an actual action isn't available, observe filter behavior, etc.
Acknowledgments
This package is gathering multiple package implementations inside a single library, credits goes to:
- wecodemore/wordpress-early-hook — Early hook registration. The only downside is that it can't safely be used inside a library (because Composer doesn't guarantee autoloaded files order). Plus some minor performance improvements.
- stevegrunwell/one-time-callbacks — Once variants
- alleyinteractive/wp-filter-side-effects — Side effects
License
MIT
n5s/wp-hook-kit 适用场景与选型建议
n5s/wp-hook-kit 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.96k 次下载、GitHub Stars 达 5, 最近一次更新时间为 2025 年 12 月 23 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「wordpress」 「filters」 「hooks」 「actions」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 n5s/wp-hook-kit 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 n5s/wp-hook-kit 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 n5s/wp-hook-kit 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Simple filters for laravel
Livewire Filters is a series of Livewire components that provide you with the tools to do live filtering of your data from your own Livewire components.
Hooks integrated in Voyager
Filters extension for Nette Framework
Laravel Advanced Filter
Provides a Data Grid tables for your Symfony project.
统计信息
- 总下载量: 3.96k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 5
- 点击次数: 3
- 依赖项目数: 4
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-12-23