pop-backbone / php-hooks
PHP-Hooks 的分支,适用于 PoP - 将 WordPress 过滤器钩子系统转换为类的分支,以便将其移植到任何基于 PHP 的系统
Conflicts
- gatographql/external-dependency-wrappers: <5.0.0
- gatographql/gatographql: <5.0.0
- gatographql/plugin-utils: <5.0.0
- gatographql/testing-schema: <5.0.0
- getpop/access-control: <5.0.0
- getpop/cache-control: <5.0.0
- getpop/component-model: <5.0.0
- getpop/componentrouting: <5.0.0
- getpop/definitions: <5.0.0
- getpop/dom-crawler: <5.0.0
- getpop/engine: <5.0.0
- getpop/engine-wp: <5.0.0
- getpop/engine-wp-bootloader: <5.0.0
- getpop/filestore: <5.0.0
- getpop/graphql-parser: <5.0.0
- getpop/guzzle-http: <5.0.0
- getpop/loosecontracts: <5.0.0
- getpop/mandatory-directives-by-configuration: <5.0.0
- getpop/markdown-convertor: <5.0.0
- getpop/root: <5.0.0
- getpop/root-wp: <5.0.0
- graphql-by-pop/graphiql: <5.0.0
- graphql-by-pop/graphql-clients-for-wp: <5.0.0
- graphql-by-pop/graphql-endpoint-for-wp: <5.0.0
- graphql-by-pop/graphql-request: <5.0.0
- graphql-by-pop/graphql-server: <5.0.0
- graphql-by-pop/graphql-voyager: <5.0.0
- phpunit-for-gatographql/dummy-schema: <5.0.0
- phpunit-for-gatographql/dummy-wp-schema: <5.0.0
- phpunit-for-gatographql/gatographql: <5.0.0
- phpunit-for-gatographql/gatographql-testing: <5.0.0
- phpunit-for-gatographql/webserver-requests: <5.0.0
- phpunit-for-gatographql/wpfaker-schema: <5.0.0
- pop-api/api: <5.0.0
- pop-api/api-clients: <5.0.0
- pop-api/api-endpoints: <5.0.0
- pop-api/api-endpoints-for-wp: <5.0.0
- pop-api/api-graphql: <5.0.0
- pop-api/api-mirrorquery: <5.0.0
- pop-api/api-rest: <5.0.0
- pop-backbone/wp-data-parser: <5.0.0
- pop-cms-schema/categories: <5.0.0
- pop-cms-schema/categories-wp: <5.0.0
- pop-cms-schema/category-mutations: <5.0.0
- pop-cms-schema/category-mutations-wp: <5.0.0
- pop-cms-schema/comment-mutations: <5.0.0
- pop-cms-schema/comment-mutations-wp: <5.0.0
- pop-cms-schema/commentmeta: <5.0.0
- pop-cms-schema/commentmeta-wp: <5.0.0
- pop-cms-schema/comments: <5.0.0
- pop-cms-schema/comments-wp: <5.0.0
- pop-cms-schema/custompost-categories-wp: <5.0.0
- pop-cms-schema/custompost-category-mutations: <5.0.0
- pop-cms-schema/custompost-category-mutations-wp: <5.0.0
- pop-cms-schema/custompost-mutations: <5.0.0
- pop-cms-schema/custompost-mutations-wp: <5.0.0
- pop-cms-schema/custompost-tag-mutations: <5.0.0
- pop-cms-schema/custompost-tag-mutations-wp: <5.0.0
- pop-cms-schema/custompost-tags-wp: <5.0.0
- pop-cms-schema/custompost-user-mutations: <5.0.0
- pop-cms-schema/custompost-user-mutations-wp: <5.0.0
- pop-cms-schema/custompostmedia: <5.0.0
- pop-cms-schema/custompostmedia-mutations: <5.0.0
- pop-cms-schema/custompostmedia-mutations-wp: <5.0.0
- pop-cms-schema/custompostmedia-wp: <5.0.0
- pop-cms-schema/custompostmeta: <5.0.0
- pop-cms-schema/custompostmeta-wp: <5.0.0
- pop-cms-schema/customposts: <5.0.0
- pop-cms-schema/customposts-wp: <5.0.0
- pop-cms-schema/media: <5.0.0
- pop-cms-schema/media-mutations: <5.0.0
- pop-cms-schema/media-mutations-wp: <5.0.0
- pop-cms-schema/media-wp: <5.0.0
- pop-cms-schema/menus: <5.0.0
- pop-cms-schema/menus-wp: <5.0.0
- pop-cms-schema/meta: <5.0.0
- pop-cms-schema/metaquery-wp: <5.0.0
- pop-cms-schema/page-mutations: <5.0.0
- pop-cms-schema/page-mutations-wp: <5.0.0
- pop-cms-schema/pagemedia-mutations: <5.0.0
- pop-cms-schema/pages: <5.0.0
- pop-cms-schema/pages-wp: <5.0.0
- pop-cms-schema/post-categories: <5.0.0
- pop-cms-schema/post-categories-wp: <5.0.0
- pop-cms-schema/post-category-mutations: <5.0.0
- pop-cms-schema/post-mutations: <5.0.0
- pop-cms-schema/post-tag-mutations: <5.0.0
- pop-cms-schema/post-tags: <5.0.0
- pop-cms-schema/post-tags-wp: <5.0.0
- pop-cms-schema/postmedia-mutations: <5.0.0
- pop-cms-schema/posts: <5.0.0
- pop-cms-schema/posts-wp: <5.0.0
- pop-cms-schema/queriedobject: <5.0.0
- pop-cms-schema/queriedobject-wp: <5.0.0
- pop-cms-schema/schema-commons: <5.0.0
- pop-cms-schema/schema-commons-wp: <5.0.0
- pop-cms-schema/settings: <5.0.0
- pop-cms-schema/settings-wp: <5.0.0
- pop-cms-schema/tag-mutations: <5.0.0
- pop-cms-schema/tag-mutations-wp: <5.0.0
- pop-cms-schema/tags: <5.0.0
- pop-cms-schema/tags-wp: <5.0.0
- pop-cms-schema/taxonomies: <5.0.0
- pop-cms-schema/taxonomies-wp: <5.0.0
- pop-cms-schema/taxonomy-mutations: <5.0.0
- pop-cms-schema/taxonomy-mutations-wp: <5.0.0
- pop-cms-schema/taxonomymeta: <5.0.0
- pop-cms-schema/taxonomymeta-wp: <5.0.0
- pop-cms-schema/taxonomyquery: <5.0.0
- pop-cms-schema/taxonomyquery-wp: <5.0.0
- pop-cms-schema/user-avatars: <5.0.0
- pop-cms-schema/user-avatars-wp: <5.0.0
- pop-cms-schema/user-roles: <5.0.0
- pop-cms-schema/user-roles-wp: <5.0.0
- pop-cms-schema/user-state: <5.0.0
- pop-cms-schema/user-state-mutations: <5.0.0
- pop-cms-schema/user-state-mutations-wp: <5.0.0
- pop-cms-schema/user-state-wp: <5.0.0
- pop-cms-schema/usermeta: <5.0.0
- pop-cms-schema/usermeta-wp: <5.0.0
- pop-cms-schema/users: <5.0.0
- pop-cms-schema/users-wp: <5.0.0
- pop-schema/directive-commons: <5.0.0
- pop-schema/extended-schema-commons: <5.0.0
- pop-schema/http-requests: <5.0.0
- pop-schema/schema-commons: <5.0.0
- pop-wp-schema/block-content-parser: <5.0.0
- pop-wp-schema/blocks: <5.0.0
- pop-wp-schema/commentmeta: <5.0.0
- pop-wp-schema/comments: <5.0.0
- pop-wp-schema/custompostmeta: <5.0.0
- pop-wp-schema/customposts: <5.0.0
- pop-wp-schema/media: <5.0.0
- pop-wp-schema/menus: <5.0.0
- pop-wp-schema/meta: <5.0.0
- pop-wp-schema/multisite: <5.0.0
- pop-wp-schema/pages: <5.0.0
- pop-wp-schema/posts: <5.0.0
- pop-wp-schema/schema-commons: <5.0.0
- pop-wp-schema/settings: <5.0.0
- pop-wp-schema/site: <5.0.0
- pop-wp-schema/taxonomymeta: <5.0.0
- pop-wp-schema/usermeta: <5.0.0
- pop-wp-schema/users: <5.0.0
- dev-master / 5.0.x-dev
- 5.0.0
- 4.2.0
- 4.1.1
- 4.1.0
- 4.0.1
- 4.0.0
- 3.0.0
- 2.6.1
- 2.6.0
- 2.5.2
- 2.5.1
- 2.5.0
- 2.4.1
- 2.4.0
- 2.3.0
- 2.2.3
- 2.2.2
- 2.2.1
- 2.2.0
- 2.1.3
- 2.1.2
- 2.1.1
- 2.1.0
- 2.0.1
- 1.6.0
- 1.5.5
- 1.5.4
- 1.5.3
- 1.5.2
- 1.5.1
- 1.5.0
- 1.4.0
- 1.3.1
- 1.3.0
- 1.2.0
- 1.1.1
- 1.1.0
- 1.0.15
- 1.0.14
- 1.0.13
- 1.0.12
- 1.0.11
- 1.0.10
- 1.0.9
- 1.0.8
- 1.0.7
- 1.0.6
- 1.0.5
- 1.0.4
- 1.0.3
- 1.0.2
- 1.0.1
- 1.0.0
- 0.10.2
- 0.10.1
- 0.10.0
- 0.9.10
- 0.9.9
- 0.9.8
- 0.9.7
- 0.9.6
- 0.9.5
- 0.9.4
- 0.9.3
- 0.9.2
- 0.9.1
- 0.9.0
This package is auto-updated.
Last update: 2024-09-07 03:39:19 UTC
README
这是一个 PHP Hooks 的分支,适用于 PoP,并添加了一些未合并到原始项目中的更新。
安装
通过 Composer
composer require pop-backbone/php-hooks
开发
源代码托管在 GatoGraphQL monorepo 上,在 Backbone/packages/php-hooks
。
PHP-Hooks (原始 README)
(来源: https://github.com/bainternet/PHP-Hooks)
PHP Hooks 类是 WordPress 过滤器钩子系统的分支,将其转换为类以移植到任何基于 PHP 的系统
- 此类主要基于 WordPress 插件 API,大部分(如果不是全部)代码都来自那里。
前往 http://bainternet.github.io/PHP-Hooks/ 获取更多信息
如何使用?
很简单,将类文件包含在您的应用程序引导程序中(设置/加载/配置或您叫它什么)并开始使用全局 $hooks
调用过滤器和动作钩子。例如
include_once('php-hooks.php'); global $hooks; $hooks->add_action('header_action','echo_this_in_header'); function echo_this_in_header(){ echo 'this came from a hooked function'; }
然后,您只需在应用程序的任何地方调用已连接的函数,例如
echo '<div id="extra_header">'; global $hooks; $hooks->do_action('header_action'); echo '</div>';
输出将是
<div id="extra_header">this came from a hooked function</div>
方法
动作
add_action 将函数连接到特定的动作。
- @access public
- @since 0.1
- @param string $tag The name of the action to which the $function_to_add is hooked.
- @param callback $function_to_add The name of the function you wish to be called.
- @param int $priority optional. Used to specify the order in which the functions associated with a particular action are executed (default: 10). Lower numbers correspond with earlier execution, and functions with the same priority are executed in the order in which they were added to the action.
- @param int $accepted_args optional. The number of arguments the function accept (default 1).
do_action 执行连接到特定动作钩子的函数。
- @access public
- @since 0.1
- @param string $tag The name of the action to be executed.
- @param mixed $arg,... Optional additional arguments which are passed on to the functions hooked to the action.
- @return null Will return null if $tag does not exist
remove_action 从指定的动作钩子中删除函数。
- @access public
- @since 0.1
- @param string $tag The action hook to which the function to be removed is hooked.
- @param callback $function_to_remove The name of the function which should be removed.
- @param int $priority optional The priority of the function (default: 10).
- @return boolean Whether the function is removed.
has_action 检查是否为钩子注册了任何动作。
- @access public
- @since 0.1
- @param string $tag The name of the action hook.
- @param callback $function_to_check optional.
- @return mixed If $function_to_check is omitted, returns boolean for whether the hook has anything registered.
When checking a specific function, the priority of that hook is returned, or false if the function is not attached.
When using the $function_to_check argument, this function may return a non-boolean value that evaluates to false (e.g.) 0, so use the === operator for testing the return value.
did_action 获取动作被触发的次数。
- @access public
- @since 0.1
- @param string $tag The name of the action hook.
- @return int The number of times action hook <tt>$tag</tt> is fired
过滤器
add_filter 将函数或方法连接到特定的过滤器动作。
- @access public
- @since 0.1
- @param string $tag The name of the filter to hook the $function_to_add to.
- @param callback $function_to_add The name of the function to be called when the filter is applied.
- @param int $priority optional. Used to specify the order in which the functions associated with a particular action are executed (default: 10). Lower numbers correspond with earlier execution, and functions with the same priority are executed in the order in which they were added to the action.
- @param int $accepted_args optional. The number of arguments the function accept (default 1).
- @return boolean true
remove_filter 从指定的过滤器钩子中删除函数。
- @access public
- @since 0.1
- @param string $tag The filter hook to which the function to be removed is hooked.
- @param callback $function_to_remove The name of the function which should be removed.
- @param int $priority optional. The priority of the function (default: 10).
- @param int $accepted_args optional. The number of arguments the function accepts (default: 1).
- @return boolean Whether the function existed before it was removed.
has_filter 检查是否为钩子注册了任何过滤器。
- @access public
- @since 0.1
- @param string $tag The name of the filter hook.
- @param callback $function_to_check optional.
- @return mixed If $function_to_check is omitted, returns boolean for whether the hook has anything registered.
When checking a specific function, the priority of that hook is returned, or false if the function is not attached.
When using the $function_to_check argument, this function may return a non-boolean value that evaluates to false (e.g.) 0, so use the === operator for testing the return value.
apply_filters 调用添加到过滤器钩子的函数。
- @access public
- @since 0.1
- @param string $tag The name of the filter hook.
- @param mixed $value The value on which the filters hooked to <tt>$tag</tt> are applied on.
- @param mixed $var,... Additional variables passed to the functions hooked to <tt>$tag</tt>.
- @return mixed The filtered value after all hooked functions are applied to it.
还有一些其他方法,但这些都是您将主要使用的方法:)。
下载
您还可以通过运行以下命令使用 Git 克隆项目
$ git clone git://github.com/bainternet/PHP-Hooks.git
许可证
由于此类派生自 WordPress 插件 API,因此许可证也是 GPL https://gnu.ac.cn/licenses/gpl.html