定制 shineunited/wordpress-hooks 二次开发

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

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

shineunited/wordpress-hooks

Composer 安装命令:

composer require shineunited/wordpress-hooks

包简介

Tool for managing WordPress hooks prior to initialization.

README 文档

README

License Latest Version PHP Version Main Status Release Status Develop Status

Description

A tool for managing WordPress hooks. Allows registration of hooks prior to WordPress initialization and provides a framework for defining hooks using PHP attributes.

Installation

to add wordpress-hooks, the recommended method is via composer.

$ composer require shineunited/wordpress-hooks

HookManager

The HookManager class provides static methods for managing WordPress hooks. While most of the functions are simply aliased to the built-in WordPress functions, some of them all management of hooks prior to initialization.

use ShineUnited\WordPress\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

Hooks can also be defined by using the Hook attributes and HookManager::register();

use ShineUnited\WordPress\Hooks\Filter;
use ShineUnited\WordPress\Hooks\HookManager;

class MyObjectHooks {

	#[Filter('lowercase')]
	public function lowercase(string $value): string {
		return strtolower($value);
	}

	#[Filter('uppercase')]
	public function uppercase(string $value): string {
		return strtoupper($value);
	}
}

$hooks = new MyObjectHooks();
HookManager::register($hooks);
// WordPress Equivalent
//   add_filter('lowercase', [$hooks, 'lowercase'], 10, 1);
//   add_filter('uppercase', [$hooks, 'uppercase'], 10, 1);

Multiple hooks can be applied to a single callback.

use ShineUnited\WordPress\Hooks\Action;
use ShineUnited\WordPress\Hooks\Filter;
use ShineUnited\WordPress\Hooks\HookManager;

$closure =
#[Filter('example-filter', 12)]
#[Action('example-action')]
function($value) {
	// code
};

HookManager::register($closure);
// WordPress Equivalent:
//   add_filter('example-filter', $closure, 12, 1);
//   add_filter('example-action', $closure, 10, 1);

Function Reference

For more details and examples please see our documentation.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-01-12

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固