*/ private array $actions = []; /** * Pending filter registrations. * * @var array */ private array $filters = []; /** Queues an action hook. */ public function add_action( string $hook, object $component, string $callback, int $priority = 10, int $accepted_args = 1 ): void { $this->actions[] = compact( 'hook', 'component', 'callback', 'priority', 'accepted_args' ); } /** Queues a filter hook. */ public function add_filter( string $hook, object $component, string $callback, int $priority = 10, int $accepted_args = 1 ): void { $this->filters[] = compact( 'hook', 'component', 'callback', 'priority', 'accepted_args' ); } /** Registers all queued hooks with WordPress; call once, after every service has queued its hooks. */ public function run(): void { foreach ( $this->filters as $hook ) { add_filter( $hook['hook'], [ $hook['component'], $hook['callback'] ], $hook['priority'], $hook['accepted_args'] ); } foreach ( $this->actions as $hook ) { add_action( $hook['hook'], [ $hook['component'], $hook['callback'] ], $hook['priority'], $hook['accepted_args'] ); } } }