pop-backbone / php-hooks
A fork of PHP-Hooks, adapted to PoP - A fork of the WordPress filters hook system rolled in to a class to be ported into any PHP-based system
Conflicts
- gatographql-standalone/gatographql: <7.0.4
- gatographql/external-dependency-wrappers: <7.0.4
- gatographql/gatographql: <7.0.4
- gatographql/plugin-utils: <7.0.4
- gatographql/testing-schema: <7.0.4
- getpop/access-control: <7.0.4
- getpop/cache-control: <7.0.4
- getpop/component-model: <7.0.4
- getpop/componentrouting: <7.0.4
- getpop/definitions: <7.0.4
- getpop/dom-crawler: <7.0.4
- getpop/engine: <7.0.4
- getpop/engine-wp: <7.0.4
- getpop/engine-wp-bootloader: <7.0.4
- getpop/filestore: <7.0.4
- getpop/graphql-parser: <7.0.4
- getpop/guzzle-http: <7.0.4
- getpop/loosecontracts: <7.0.4
- getpop/mandatory-directives-by-configuration: <7.0.4
- getpop/markdown-convertor: <7.0.4
- getpop/root: <7.0.4
- getpop/root-wp: <7.0.4
- graphql-by-pop/graphiql: <7.0.4
- graphql-by-pop/graphql-clients-for-wp: <7.0.4
- graphql-by-pop/graphql-endpoint-for-wp: <7.0.4
- graphql-by-pop/graphql-request: <7.0.4
- graphql-by-pop/graphql-server: <7.0.4
- graphql-by-pop/graphql-voyager: <7.0.4
- phpunit-for-gatographql/dummy-schema: <7.0.4
- phpunit-for-gatographql/dummy-wp-schema: <7.0.4
- phpunit-for-gatographql/gatographql: <7.0.4
- phpunit-for-gatographql/gatographql-testing: <7.0.4
- phpunit-for-gatographql/webserver-requests: <7.0.4
- phpunit-for-gatographql/wpfaker-schema: <7.0.4
- pop-api/api: <7.0.4
- pop-api/api-clients: <7.0.4
- pop-api/api-endpoints: <7.0.4
- pop-api/api-endpoints-for-wp: <7.0.4
- pop-api/api-graphql: <7.0.4
- pop-api/api-mirrorquery: <7.0.4
- pop-api/api-rest: <7.0.4
- pop-backbone/wp-data-parser: <7.0.4
- pop-cms-schema/categories: <7.0.4
- pop-cms-schema/categories-wp: <7.0.4
- pop-cms-schema/category-mutations: <7.0.4
- pop-cms-schema/category-mutations-wp: <7.0.4
- pop-cms-schema/comment-mutations: <7.0.4
- pop-cms-schema/comment-mutations-wp: <7.0.4
- pop-cms-schema/commentmeta: <7.0.4
- pop-cms-schema/commentmeta-wp: <7.0.4
- pop-cms-schema/comments: <7.0.4
- pop-cms-schema/comments-wp: <7.0.4
- pop-cms-schema/custompost-categories-wp: <7.0.4
- pop-cms-schema/custompost-category-mutations: <7.0.4
- pop-cms-schema/custompost-category-mutations-wp: <7.0.4
- pop-cms-schema/custompost-mutations: <7.0.4
- pop-cms-schema/custompost-mutations-wp: <7.0.4
- pop-cms-schema/custompost-tag-mutations: <7.0.4
- pop-cms-schema/custompost-tag-mutations-wp: <7.0.4
- pop-cms-schema/custompost-tags-wp: <7.0.4
- pop-cms-schema/custompost-user-mutations: <7.0.4
- pop-cms-schema/custompost-user-mutations-wp: <7.0.4
- pop-cms-schema/custompostmedia: <7.0.4
- pop-cms-schema/custompostmedia-mutations: <7.0.4
- pop-cms-schema/custompostmedia-mutations-wp: <7.0.4
- pop-cms-schema/custompostmedia-wp: <7.0.4
- pop-cms-schema/custompostmeta: <7.0.4
- pop-cms-schema/custompostmeta-wp: <7.0.4
- pop-cms-schema/customposts: <7.0.4
- pop-cms-schema/customposts-wp: <7.0.4
- pop-cms-schema/media: <7.0.4
- pop-cms-schema/media-mutations: <7.0.4
- pop-cms-schema/media-mutations-wp: <7.0.4
- pop-cms-schema/media-wp: <7.0.4
- pop-cms-schema/menus: <7.0.4
- pop-cms-schema/menus-wp: <7.0.4
- pop-cms-schema/meta: <7.0.4
- pop-cms-schema/metaquery-wp: <7.0.4
- pop-cms-schema/page-mutations: <7.0.4
- pop-cms-schema/page-mutations-wp: <7.0.4
- pop-cms-schema/pagemedia-mutations: <7.0.4
- pop-cms-schema/pages: <7.0.4
- pop-cms-schema/pages-wp: <7.0.4
- pop-cms-schema/post-categories: <7.0.4
- pop-cms-schema/post-categories-wp: <7.0.4
- pop-cms-schema/post-category-mutations: <7.0.4
- pop-cms-schema/post-mutations: <7.0.4
- pop-cms-schema/post-tag-mutations: <7.0.4
- pop-cms-schema/post-tags: <7.0.4
- pop-cms-schema/post-tags-wp: <7.0.4
- pop-cms-schema/postmedia-mutations: <7.0.4
- pop-cms-schema/posts: <7.0.4
- pop-cms-schema/posts-wp: <7.0.4
- pop-cms-schema/queriedobject: <7.0.4
- pop-cms-schema/queriedobject-wp: <7.0.4
- pop-cms-schema/schema-commons: <7.0.4
- pop-cms-schema/schema-commons-wp: <7.0.4
- pop-cms-schema/settings: <7.0.4
- pop-cms-schema/settings-wp: <7.0.4
- pop-cms-schema/tag-mutations: <7.0.4
- pop-cms-schema/tag-mutations-wp: <7.0.4
- pop-cms-schema/tags: <7.0.4
- pop-cms-schema/tags-wp: <7.0.4
- pop-cms-schema/taxonomies: <7.0.4
- pop-cms-schema/taxonomies-wp: <7.0.4
- pop-cms-schema/taxonomy-mutations: <7.0.4
- pop-cms-schema/taxonomy-mutations-wp: <7.0.4
- pop-cms-schema/taxonomymeta: <7.0.4
- pop-cms-schema/taxonomymeta-wp: <7.0.4
- pop-cms-schema/taxonomyquery: <7.0.4
- pop-cms-schema/taxonomyquery-wp: <7.0.4
- pop-cms-schema/user-avatars: <7.0.4
- pop-cms-schema/user-avatars-wp: <7.0.4
- pop-cms-schema/user-roles: <7.0.4
- pop-cms-schema/user-roles-wp: <7.0.4
- pop-cms-schema/user-state: <7.0.4
- pop-cms-schema/user-state-mutations: <7.0.4
- pop-cms-schema/user-state-mutations-wp: <7.0.4
- pop-cms-schema/user-state-wp: <7.0.4
- pop-cms-schema/usermeta: <7.0.4
- pop-cms-schema/usermeta-wp: <7.0.4
- pop-cms-schema/users: <7.0.4
- pop-cms-schema/users-wp: <7.0.4
- pop-schema/directive-commons: <7.0.4
- pop-schema/extended-schema-commons: <7.0.4
- pop-schema/http-requests: <7.0.4
- pop-schema/schema-commons: <7.0.4
- pop-wp-schema/block-content-parser: <7.0.4
- pop-wp-schema/blocks: <7.0.4
- pop-wp-schema/commentmeta: <7.0.4
- pop-wp-schema/comments: <7.0.4
- pop-wp-schema/custompostmeta: <7.0.4
- pop-wp-schema/customposts: <7.0.4
- pop-wp-schema/media: <7.0.4
- pop-wp-schema/menus: <7.0.4
- pop-wp-schema/meta: <7.0.4
- pop-wp-schema/multisite: <7.0.4
- pop-wp-schema/pages: <7.0.4
- pop-wp-schema/posts: <7.0.4
- pop-wp-schema/schema-commons: <7.0.4
- pop-wp-schema/settings: <7.0.4
- pop-wp-schema/site: <7.0.4
- pop-wp-schema/taxonomymeta: <7.0.4
- pop-wp-schema/usermeta: <7.0.4
- pop-wp-schema/users: <7.0.4
- dev-master / 7.1.x-dev
- 7.0.4
- 7.0.3
- 7.0.2
- 7.0.1
- 7.0.0
- 6.0.2
- 6.0.1
- 6.0.0
- 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-11-20 06:21:18 UTC
README
This is a fork of PHP Hooks, adapted for PoP, and adding a couple of updates not merged in the original project.
Install
Via Composer
composer require pop-backbone/php-hooks
Development
The source code is hosted on the GatoGraphQL monorepo, under Backbone/packages/php-hooks
.
PHP-Hooks (Original README)
(Source: https://github.com/bainternet/PHP-Hooks)
The PHP Hooks Class is a fork of the WordPress filters hook system rolled in to a class to be ported into any php based system
- This class is heavily based on the WordPress plugin API and most (if not all) of the code comes from there.
Head Over to http://bainternet.github.io/PHP-Hooks/ For more info
How to Use?
Simple, Include the class file in your application bootstrap (setup/load/configuration or whatever you call it) and start hooking your filter and action hooks using the global $hooks
. Ex:
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'; }
then all that is left for you is to call the hooked function when you want anywhere in your application, EX:
echo '<div id="extra_header">'; global $hooks; $hooks->do_action('header_action'); echo '</div>';
and you output will be:
<div id="extra_header">this came from a hooked function</div>
Methods
ACTIONS:
add_action Hooks a function on to a specific 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 Execute functions hooked on a specific action hook.
- @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 Removes a function from a specified action hook.
- @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 Check if any action has been registered for a hook.
- @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 Retrieve the number of times an action is fired.
- @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
FILTERS:
add_filter Hooks a function or method to a specific filter action.
- @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 Removes a function from a specified filter hook.
- @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 Check if any filter has been registered for a hook.
- @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 Call the functions added to a filter hook.
- @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.
There are a few more methods but these are the main Ones you'll use :).
Download
You can download this project in either zip or tar formats
You can also clone the project with Git by running:
$ git clone git://github.com/bainternet/PHP-Hooks.git
License
Since this class is derived from the WordPress Plugin API so are the license and they are GPL http://www.gnu.org/licenses/gpl.html