Use PHP Docblock (annotations) to register WordPress hooks, filters and shortcodes.
- PHP 7.1+
Via Composer
$ composer require dugajean/wp-hook-annotations
To automatically wire up your class, simply call the HookRegistry::bootstrap
method, like so:
<?php
namespace My\CoolNamespace;
use Dugajean\WpHookAnnotations\HookRegistry;
use Dugajean\WpHookAnnotations\Models\Action;
class MyClass
{
public function __construct(HookRegistry $hookRegistry)
{
$hookRegistry->bootstrap($this);
}
/**
* @Action(tag="init")
*/
public function doSomething()
{
// do something
}
}
And you're done!
The following annotations can be used:
/**
* @Action(tag="the hook name", priority=1, accepted_args=1)
* @Filter(tag="the filter name", priority=1, accepted_args=1)
* @Shortcode(tag="the shortcode code")
*/
$ composer test
WP Hook Annotations is released under the MIT License.