Download the PHP package yard/wp-hook-registrar without Composer
On this page you can find all versions of the php package yard/wp-hook-registrar. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download yard/wp-hook-registrar
More information about yard/wp-hook-registrar
Files in yard/wp-hook-registrar
Package wp-hook-registrar
Short Description An Acorn package for WordPress hook registration.
License MIT
Informations about the package wp-hook-registrar
wp-hook-registrar
An Acorn package for WordPress Hook Registration.
Features
- [x] Register Hooks using php attributes
- [x] Configure Hook registration using a config file
- [x] Load plugin-specific hooks only when the plugin is active
See config for all configuration options.
Requirements
Installation
-
Install this package with Composer:
-
Run the Acorn WP-CLI command to discover this package:
-
Publish the config file with:
- Register all your project hooks in the published configuration file
config/hooks.php
.
Installation in WordPress plugins
To use this package in a standard WordPress plugin, you can use the HookRegistrar
to register hooks.
You can skip step 3 and 4 from the installation instructions above and instead add the following to your plugin's
main file:
Hook Attributes
This package provides two Attributes: Action
and Filter
. They can be used to register hooks instead of the
WordPress functions add_action() and add_filter()
This syntax allows you to place the hook registration directly above the method it invokes when the hook is triggered.
Notice that you do not need to pass the number of accepted arguments to the Action
and Filter
attributes as you would
with add_action()
and add_filter()
. Instead, the number of accepted arguments is determined by the method
signature.
You can add as many hooks to the same method as you want.