paperpixel/wp-hooks
Composer 安装命令:
composer require paperpixel/wp-hooks
包简介
Split Wordpress functions.php file into small, readable hooks
关键字:
README 文档
README
Split Wordpress functions.php file into small, readable hooks.
Requirement
Your Wordpress files and plugins should be managed by composer. See Bedrock boilerplate Wordpress structure to get started.
Installation
Install with Composer: composer require paperpixel/wphooks
Usage
Creating a hook
Create a hook by extending WPHook class :
use WPHooks\WPHook; class ExampleHook extends WPHook { // Mandatory method, used to register actions and filters with Wordpress. public function register() { $this->add_action('init', 'my_action_hook'); $this->add_filter('the_title', 'my_filter_hook'); } private function my_action_hook() { // Stuff here will be called by Wordpress } private function my_filter_hook($title) { // Stuff here will be called by Wordpress } }
Note: we take advantage of Composer autoload
feature to import class by namespace with the keyword use.
Using the hook
In your functions.php class, instantiate ExampleHook and call register() method.
// functions.php include 'ExampleHook.php'; $example_hook = new ExampleHook(); $example_hook->register();
Easier hook creation with WPHookLoader
You can use WPHookLoader to instantiate your hooks easily :
// functions.php include 'ExampleHook.php'; include 'Hook1.php'; include 'Hook2.php'; include 'Hook3.php'; // You can pass a WPHook instance WPHooks\WPHookLoader::register(new ExampleHook()); // Or an array of WPHook instances WPHooks\WPHookLoader::register([ new Hook1(), new Hook2(), new Hook3(), ... ]);
Autoloading
We can leverage Composer's ClassLoader feature in our theme, so that we
don't have to require each hook in functions.php.
Considering this theme structure :
hooks/
actions/
ExampleAction.php
filters/
ExampleFilter.php
__autoload.php
functions.php
Start by creating the __autoload.php file :
// __autoload.php use Composer\Autoload\ClassLoader; $loader = new ClassLoader(); $loader-> register(); $loader->addPsr4('Hooks\\Actions\\', __DIR__ . '/hooks/actions'); $loader->addPsr4('Hooks\\Filters\\', __DIR__ . '/hooks/filters');
In your Hook class, add a namespace accordingly to __autoload.php :
// hooks/actions/ExampleAction.php namespace Hooks\Actions; use WPHooks\WPHook; class ExampleAction extends WPHook { function register() { ... } }
Finally, in functions.php, instantiate your hook :
// functions.php // Without WPHookLoader $example_actions = new Actions\ExampleAction(); // With WPHookLoader WPHooks\WPHookLoader::register(new Actions\ExampleAction());
paperpixel/wp-hooks 适用场景与选型建议
paperpixel/wp-hooks 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 26 次下载、GitHub Stars 达 0, 最近一次更新时间为 2016 年 01 月 20 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「wordpress」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 paperpixel/wp-hooks 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 paperpixel/wp-hooks 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 paperpixel/wp-hooks 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Must-use plugin integrating WordPress with the Upsun platform: environment awareness, router-cache friendliness, safe preview clones, deploy migrations, Site Health checks, and a wp upsun CLI command.
Inertia.js server-side adapter for PHP. Handles full visits, Inertia XHR visits, asset-version 409 handshakes and partial reloads. Framework-agnostic, with transparent WordPress integration.
Adds Cache-Tag HTTP response headers for singular WordPress content and purges Cloudflare by tag when content changes.
AI Chatbot & Helpdesk Agent for WooCommerce. Connects your store to Egentify for AI-powered chat, order tracking, email, and ticketing.
MIDDAG's reference architecture for a WordPress plugin — composes the OSS framework/wordpress/ui libraries end to end.
Assets helper package for the Hybrid Core framework.
统计信息
- 总下载量: 26
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 10
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: BSD
- 更新时间: 2016-01-20