diff --git a/src/Assets/Assets.php b/src/Assets/Assets.php index 8cf02c1..018c9d8 100755 --- a/src/Assets/Assets.php +++ b/src/Assets/Assets.php @@ -681,6 +681,23 @@ protected function do_enqueue( Asset $asset, bool $force_enqueue = false ): void * */ public function register_in_wp( $assets = null ) { + if ( ! ( + did_action( 'init' ) || did_action( 'wp_enqueue_scripts' ) + || did_action( 'admin_enqueue_scripts' ) || did_action( 'login_enqueue_scripts' ) + ) + ) { + // Registering the asset now would trigger a doing_it_wrong notice: queue the assets to be registered later. + + if ( ! is_array( $assets ) ) { + $assets = [ $assets ]; + } + + // Register later, avoid the doing_it_wrong notice. + $this->assets = array_merge( $this->assets, $assets ); + + return; + } + if ( is_null( $assets ) ) { $assets = $this->get(); }