定制 kynetcode/wpzylos-hooks 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

kynetcode/wpzylos-hooks

Composer 安装命令:

composer require kynetcode/wpzylos-hooks

包简介

WordPress hook management with plugin-scoped custom hooks for WPZylos framework

README 文档

README

PHP Version License GitHub

WordPress hook management with plugin-scoped custom hooks for WPZylos framework.

📖 Full Documentation | 🐛 Report Issues

✨ Features

  • Dual Hook API — Separate methods for WordPress core hooks and custom plugin hooks
  • Auto-Prefixed Custom Hooks — Plugin-scoped hooks prevent naming collisions
  • Fluent API — Chainable methods for clean registration
  • One-Time Hooks — Actions that self-remove after first execution
  • Hook Registry — Introspect all registered actions and filters

📋 Requirements

Requirement Version
PHP ^8.0
WordPress 6.0+

🚀 Installation

composer require KYNetCode/wpzylos-hooks

📖 Quick Start

use WPZylos\Framework\Hooks\HookManager;

$hooks = $app->make('hooks');

// WordPress core hooks (NEVER prefixed) — use wp* methods
$hooks->wpAction('init', [$this, 'initialize']);
$hooks->wpFilter('the_content', [$this, 'modifyContent']);

// Custom plugin hooks (ALWAYS prefixed) — use plain methods
$hooks->action('settings_saved', [$listener, 'onSettingsSaved']);
$hooks->filter('settings', [$this, 'filterSettings']);

// Fire & apply custom hooks
$hooks->doAction('settings_saved', $settings);
$filtered = $hooks->applyFilter('settings', $defaults);

🏗️ Core Concepts

The Dual API

HookManager provides two distinct APIs:

Purpose Register Listener Fire / Apply Remove
WordPress hooks wpAction(), wpFilter() (WordPress fires these) removeWpAction(), removeWpFilter()
Custom plugin hooks action(), filter() doAction(), applyFilter() removeAction(), removeFilter()

WordPress hooks (wp* methods) use the hook name exactly as provided — 'init', 'the_content', etc.

Custom plugin hooks (plain methods) automatically prefix the hook name via $context->hook() to prevent collisions between plugins.

WordPress Core Hooks

// Register actions on WordPress hooks
$hooks->wpAction('init', [$this, 'onInit']);
$hooks->wpAction('admin_menu', [$this, 'registerMenu'], 20);

// Register filters on WordPress hooks
$hooks->wpFilter('the_title', [$this, 'filterTitle']);
$hooks->wpFilter('body_class', [$this, 'addBodyClasses'], 10, 2);

// Remove hooks
$hooks->removeWpAction('init', [$this, 'onInit']);
$hooks->removeWpFilter('the_title', [$this, 'filterTitle']);

Custom Plugin Hooks

// Register listeners on your plugin's custom hooks
// If your plugin prefix is "myplugin", 'user_created' becomes 'myplugin_user_created'
$hooks->action('user_created', [$listener, 'onUserCreated']);
$hooks->filter('settings', [$this, 'filterSettings']);

// Fire a custom action
$hooks->doAction('user_created', $user);

// Apply a custom filter
$settings = $hooks->applyFilter('settings', $defaults);

// Remove custom hook listeners
$hooks->removeAction('user_created', [$listener, 'onUserCreated']);
$hooks->removeFilter('settings', [$this, 'filterSettings']);

One-Time Hooks

// Executes once then removes itself automatically
$hooks->once('init', function () {
    // Runs only on the first 'init' call
});

Fluent Chaining

$hooks
    ->wpAction('init', [$this, 'onInit'])
    ->wpAction('admin_menu', [$this, 'registerMenu'])
    ->wpFilter('the_content', [$this, 'filterContent']);

📦 Related Packages

Package Description
wpzylos-core Application foundation
wpzylos-events PSR-14 event dispatcher
wpzylos-scaffold Plugin template

📖 Documentation

For comprehensive documentation, tutorials, and API reference, visit wpzylos.com.

☕ Support the Project

📄 License

MIT License. See LICENSE for details.

🤝 Contributing

Contributions are welcome! Please see CONTRIBUTING.md for guidelines.

Made with ❤️ by KYNetCode

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 2
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-2.0-or-later
  • 更新时间: 2026-06-16

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固