HookSubscriber.php
61 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Interface HookSubscriber Defines the contract for a |
| 5 | * class that can subscribe to a WordPress hook (action or filter) and handle it with optional configuration. |
| 6 | * Implementing classes should define which hook they subscribe to, |
| 7 | * the type of the hook (action or filter), and optionally the priority and argument count. |
| 8 | * |
| 9 | * @package Framework |
| 10 | * @subpackage Wordpress\Contracts |
| 11 | * @since 1.0.0 |
| 12 | */ |
| 13 | namespace Kirki\Framework\Wordpress\Contracts; |
| 14 | |
| 15 | \defined('ABSPATH') || exit; |
| 16 | interface HookSubscriber |
| 17 | { |
| 18 | /** |
| 19 | * Get the name of the WordPress hook this subscriber listens to. |
| 20 | * |
| 21 | * @return string The hook name (e.g., 'init', 'rest_api_init', etc.) |
| 22 | * |
| 23 | * @since 1.0.0 |
| 24 | */ |
| 25 | public function get_name(); |
| 26 | /** |
| 27 | * Get the type of the hook: 'action' or 'filter'. |
| 28 | * |
| 29 | * @return string Either 'action' or 'filter'. |
| 30 | * |
| 31 | * @since 1.0.0 |
| 32 | */ |
| 33 | public function get_type(); |
| 34 | /** |
| 35 | * Get the priority at which the hook should be fired. |
| 36 | * |
| 37 | * @return int The priority level (default is 10). |
| 38 | * |
| 39 | * @since 1.0.0 |
| 40 | */ |
| 41 | public function get_priority(); |
| 42 | /** |
| 43 | * Get the number of arguments the hook callback accepts. |
| 44 | * |
| 45 | * @return int Number of accepted arguments. |
| 46 | * |
| 47 | * @since 1.0.0 |
| 48 | */ |
| 49 | public function get_args_count(); |
| 50 | /** |
| 51 | * Handle the hook logic. Will be called when the hook is fired. |
| 52 | * |
| 53 | * @param mixed $args The positional arguments. |
| 54 | * |
| 55 | * @return mixed Return value is only used for filters. Actions can return void. |
| 56 | * |
| 57 | * @since 1.0.0 |
| 58 | */ |
| 59 | public function handle(...$args); |
| 60 | } |
| 61 |