array(), 'filter' => array(), ); /** * Queues an action registration. * * @param string $hook WordPress hook name. * @param callable $callback Callback to execute. * @param int $priority Priority at which to run. * @param int $accepted_args Number of accepted arguments. * @return void */ public function add_action( string $hook, callable $callback, int $priority = 10, int $accepted_args = 1 ): void { $this->hooks['action'][] = array( $hook, $callback, $priority, $accepted_args ); } /** * Queues a filter registration. * * @param string $hook WordPress hook name. * @param callable $callback Callback to execute. * @param int $priority Priority at which to run. * @param int $accepted_args Number of accepted arguments. * @return void */ public function add_filter( string $hook, callable $callback, int $priority = 10, int $accepted_args = 1 ): void { $this->hooks['filter'][] = array( $hook, $callback, $priority, $accepted_args ); } /** * Commits all queued hooks to WordPress. * * @return void */ public function register(): void { foreach ( $this->hooks['action'] as [ $hook, $callback, $priority, $accepted_args ] ) { add_action( $hook, $callback, $priority, $accepted_args ); } foreach ( $this->hooks['filter'] as [ $hook, $callback, $priority, $accepted_args ] ) { add_filter( $hook, $callback, $priority, $accepted_args ); } } /** * Returns the total number of queued hooks. * * @return int */ public function count(): int { return count( $this->hooks['action'] ) + count( $this->hooks['filter'] ); } }