rockschtar/wordpress-controller

Controller Trait for handling WordPress Hooks

2.4.0 2022-03-08 16:28 UTC

This package is auto-updated.

Last update: 2022-06-08 17:08:09 UTC


README

Controller Trait for handling WordPress Hooks

Requirements

Installation

Use composer to install vendor/package-name.

composer install rockschtar/wordpress-controller

Usage

use Rockschtar\WordPress\Controller\HookController;

class MyController
{
    use HookController;

    private function __construct()
    {
        $this->addAction('wp_head', 'wpHead');
        $this->addFilter('body_class', 'bodyClass');
    }

    private function wpHead(): void
    {
        echo '<something></something>';
    }

    private function bodyClass(?array $classes = []): array
    {
        if ($classes === null) {
            $classes = [];
        }

        $classes[] = 'my-body-class';

        return $classes;
    }
}

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT