/wp-hook-annotations

Use PHP Docblock (annotations) to register WordPress hooks, filters and shortcodes.

Primary LanguagePHPMIT LicenseMIT

WP Hook Annotations

Latest Unstable Version Total Downloads License

Use PHP Docblock (annotations) to register WordPress hooks, filters and shortcodes.

Requirements

  • PHP 7.1+

Install

Via Composer

$ composer require dugajean/wp-hook-annotations

Usage

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")
 */

Testing

$ composer test

License

WP Hook Annotations is released under the MIT License.