dugajean/wp-hook-annotations

This package is abandoned and no longer maintained. No replacement package was suggested.

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

dev-master 2019-06-03 14:45 UTC

This package is auto-updated.

Last update: 2022-09-20 14:13:16 UTC


README

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.