Hooks
config/hooks.php
Contains all the hook classes that should be loaded.
The goal is to group similar actions/filters together for example changing settings/values in a plugin.
Hook Classes
Section titled “Hook Classes”All hook classes are located in app/Hook and should implement the App\Lib\Contracts\HookContract interface.
<?php
namespace App\Hook;
use App\Lib\Contracts\HookContract;
class ExampleHook implements HookContract{ public function register(): void { add_action('init', [$this, 'setupNavMenus']); }
public function setupNavMenus(): void { register_nav_menus([ 'primary' => 'Primary Navigation', ]); }}Registering Hooks
Section titled “Registering Hooks”All hooks should be registered in config/hooks.php file.
This file contains an array of hook class names that should be loaded.
Registering a hook is as simple as adding the class string to the array.
<?php
use App\Hook\ExampleHook;
return [ // other hooks ExampleHook::class,];
