PHP code example of yard / wp-hook-registrar

1. Go to this page and download the library: Download yard/wp-hook-registrar 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/ */

    

yard / wp-hook-registrar example snippets


/**
 * Plugin Name: My Plugin
 */

ContainsHooks::class,
    \Plugin\AnotherClassContainsHooks::class,
];

$registrar = new \Yard\Hook\Registrar($classNames);
$registrar->registerHooks();

#[Action(string $hookName, int $priority = 10)]
public function doSomething(): void

#[Filter(string $hookName, int $priority = 10)]
public function filterSomething(): mixed



namespace App\Hooks;

use Yard\Hook\Action;
use Yard\Hook\Filter;

class Theme
{
    #[Action('save_post')]
    public function doSomething(int $postId, \WP_Post $post, bool $update): string
    {
        // do something
    }

    #[Filter('the_content')]
    #[Filter('the_excerpt')]
    public function filterSomething(string $content)
    {
        // filter content
        return $content;
    }
}