actions[] = [ 'hook' => $hook, 'component' => $component, 'callback' => $callback, 'priority' => $priority, 'accepted_args' => $accepted_args, ]; } /** * Queue a filter hook for registration. * * @param string $hook_name Filter hook name. * @param object $component Object instance the callback lives on. * @param string $callback 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_name, object $component, string $callback, int $priority = 10, int $accepted_args = 1 ): void { $this->filters[] = [ 'hook' => $hook_name, 'component' => $component, 'callback' => $callback, 'priority' => $priority, 'accepted_args' => $accepted_args, ]; } /** * Register all queued actions and filters with WordPress. * * @return void */ public function run(): void { foreach ( $this->actions as $action ) { add_action( $action['hook'], [ $action['component'], $action['callback'] ], $action['priority'], $action['accepted_args'] ); } foreach ( $this->filters as $filter ) { add_filter( $filter['hook'], [ $filter['component'], $filter['callback'] ], $filter['priority'], $filter['accepted_args'] ); } } }