Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
use 'enqueue_block_assets' is available (#9332)
Browse files Browse the repository at this point in the history
  • Loading branch information
gigitux authored May 4, 2023
1 parent 3f5aed6 commit 4d81620
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/Assets/AssetDataRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,25 @@ public function __construct( Api $asset_api ) {
* Hook into WP asset registration for enqueueing asset data.
*/
protected function init() {
add_action( 'init', array( $this, 'register_data_script' ) );
if ( $this->is_site_editor() ) {
add_action( 'enqueue_block_editor_assets', array( $this, 'register_data_script' ) );
} else {
add_action( 'init', array( $this, 'register_data_script' ) );
}
add_action( 'wp_print_footer_scripts', array( $this, 'enqueue_asset_data' ), 2 );
add_action( 'admin_print_footer_scripts', array( $this, 'enqueue_asset_data' ), 2 );
}

/**
* Checks if the current URL is the Site Editor.
*
* @return boolean
*/
protected function is_site_editor() {
$url_path = isset( $_SERVER['REQUEST_URI'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : '';
return str_contains( $url_path, 'site-editor.php' );
}

/**
* Exposes core data via the wcSettings global. This data is shared throughout the client.
*
Expand Down

0 comments on commit 4d81620

Please sign in to comment.