*/ private array $actions = array(); /** * Registered filter hooks. * * @var array */ private array $filters = array(); /** * Queues an action hook for registration. * * @param string $hook The name of the WordPress action. * @param object $component The object instance containing the callback. * @param string $callback The method name to call on $component. * @param int $priority Hook priority. Default 10. * @param int $accepted_args Number of arguments the callback accepts. Default 1. * * @return void */ public function add_action( string $hook, object $component, string $callback, int $priority = 10, int $accepted_args = 1 ): void { $this->actions[] = array( 'hook' => $hook, 'component' => $component, 'callback' => $callback, 'priority' => $priority, 'accepted_args' => $accepted_args, ); } /** * Queues a filter hook for registration. * * @param string $hook The name of the WordPress filter. * @param object $component The object instance containing the callback. * @param string $callback The method name to call on $component. * @param int $priority Hook priority. Default 10. * @param int $accepted_args Number of arguments the callback accepts. Default 1. * * @return void */ public function add_filter( string $hook, object $component, string $callback, int $priority = 10, int $accepted_args = 1 ): void { $this->filters[] = array( 'hook' => $hook, 'component' => $component, 'callback' => $callback, 'priority' => $priority, 'accepted_args' => $accepted_args, ); } /** * Registers all queued actions and filters with WordPress. * * @return void */ public function run(): void { foreach ( $this->actions as $hook ) { $cb = array( $hook['component'], $hook['callback'] ); if ( is_callable( $cb ) ) { add_action( $hook['hook'], $cb, $hook['priority'], $hook['accepted_args'] ); } } foreach ( $this->filters as $hook ) { $cb = array( $hook['component'], $hook['callback'] ); if ( is_callable( $cb ) ) { add_filter( $hook['hook'], $cb, $hook['priority'], $hook['accepted_args'] ); } } } }