Download the PHP package kerryrandolph/wp-hook-annotations without Composer
On this page you can find all versions of the php package kerryrandolph/wp-hook-annotations. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download kerryrandolph/wp-hook-annotations
More information about kerryrandolph/wp-hook-annotations
Files in kerryrandolph/wp-hook-annotations
Package wp-hook-annotations
Short Description Use PHP docblock @annotations to register WordPress hooks, filters and shortcodes
License MIT
Homepage https://github.com/Kerry-Randolph/wp-hook-annotations
Informations about the package wp-hook-annotations
Wordpress Hook Annotations
Use PHP Docblock @annotations
to register WordPress hooks, filters and shortcodes.
Requirements
- PHP 7.2+
- PHP-DI 6
Install
Via Composer
Usage
Instead of wiring callbacks with boilerplate add_action()
, add_filter()
, or add_shortcode()
,
simply add the annotations directly to the callback function's docblock:
The following annotations can be used:
- The
priority
andaccepted_args
parameters are optional, and default to 10 and 1 respectively - Double quotes are required:
tag="double_quoted"
. single quotes will throw an exception
Wire multiple hooks to a single callback function:
Once you have added the hook annotations, you need to get the HookManager
object to process them.
If you are using Dependency Injection, the easiest way is by using the provided HookAware
trait:
The HookAware->processHooks
method is triggered automatically by the DI container, and uses reflection to discover the hooks and wire them into Wordpress.
Alternatively, you could get the HookManager
in the constructor via DI, and manually trigger processHooks
:
License
WP Hook Annotations is released under the MIT License.
All versions of wp-hook-annotations with dependencies
php-di/php-di Version ^6.0
doctrine/cache Version ^1.8
doctrine/annotations Version ^1.6
psr/container Version ^1.0