Skip to content

Commit

Permalink
fix(Assets) avoid doing-it-wrong notices, register after init
Browse files Browse the repository at this point in the history
  • Loading branch information
lucatume committed May 3, 2024
1 parent c97e328 commit a11ce81
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/Assets/Assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down

0 comments on commit a11ce81

Please sign in to comment.