rockschtar/wordpress-controller

Controller Trait for handling WordPress Hooks

2.4.1 2023-08-02 09:43 UTC

This package is auto-updated.

Last update: 2024-12-01 00:12:24 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