Download the PHP package piotrpress/wordpress-hooks without Composer
On this page you can find all versions of the php package piotrpress/wordpress-hooks. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download piotrpress/wordpress-hooks
More information about piotrpress/wordpress-hooks
Files in piotrpress/wordpress-hooks
Package wordpress-hooks
Short Description This library uses PHP Attributes (introduced in PHP version 8.0) to automagically add/remove WordPress Hooks (Filters and Actions) to/from functions and methods.
License GPL-3.0
Homepage https://github.com/PiotrPress/wordpress-hooks
Informations about the package wordpress-hooks
WordPress Hooks
This library uses PHP Attributes (introduced in PHP version 8.0
) to automagically add/remove WordPress Hooks (Filters and Actions) to/from functions and methods.
Note: The library supports PHP >= 7.4
version.
Installation
Load
Usage
Attributes
Functions
Examples
Hooks::add/remove( $object )
If object
argument is passed and callback
is omitted, then all hooks from object are added or removed.
This is an equivalent to:
Note: Hooks::add/remove()
methods can be called from the method, or even outside the object.
Hooks::add/remove( $object, $callback )
If object
and callback
arguments are passed, then only hooks for this method are added or removed.
This is an equivalent to:
Hooks::add/remove( callback: $callback )
If object
argument is omitted and callback
is passed, then only hooks for this function are added or removed.
This is an equivalent to:
Cache
Optionally, you can pass a cache object, which must implement PiotrPress\CacherInterface interface, as a third cache
argument to Hooks::add/remove()
methods.
This will cache the result of Hooks::get()
method, which provides a list of hooks for a given object, method or function using Reflection API, so caching its result can significantly improve the performance.
Example
Note: You can use simple file-based cache, which is provided by PiotrPress\Cacher library distributed with this library.
Kudos
Inspirations, feedback, ideas and feature requests provided by:
Troubleshooting
Note: Named arguments not working in PHP < 8.0
version.
Requirements
PHP >= 7.4
version.
License
GPL3.0