diff --git a/src/Assets/AssetDataRegistry.php b/src/Assets/AssetDataRegistry.php index 2448082078a..a62c2f6ac9b 100644 --- a/src/Assets/AssetDataRegistry.php +++ b/src/Assets/AssetDataRegistry.php @@ -66,8 +66,15 @@ 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' ) ); - add_action( 'enqueue_block_assets', array( $this, 'enqueue_asset_data' ), 2 ); + // @todo: Remove this check when WordPress 6.3 is the minimum supported version. + if ( is_admin() ) { + add_action( 'enqueue_block_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 ); } /**