PHP code example of rockschtar / wordpress-controller

1. Go to this page and download the library: Download rockschtar/wordpress-controller library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

rockschtar / wordpress-controller example snippets


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;
    }
}