ce Provider is registered when the action fires, * or immediately if the action has already fired. * * @throws \TEC\Common\lucatume\DI52\ContainerException If the provider class is marked as deferred but * does not provide a set of deferred registrations. */ public function register_on_action( string $action, string $class, string ...$alias ): void { if ( did_action( $action ) ) { // If the action has already fired, register the provider immediately. $this->register( $class, ...$alias ); return; } // If the action has not fired yet, register the provider when it does. $registration_closure = function () use ( $action, $class, $alias, &$registration_closure ) { // Remove the closure from the action to avoid calling it again. remove_action( $action, $registration_closure ); $this->register( $class, ...$alias ); }; add_action( $action, $registration_closure ); } }