定制 offsetwp/hook-wordpress 二次开发

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

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

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 WordPress OffsetWP Hook WordPress

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-12-18