From a8dffa5207cfb11d595ca23efef20f96613d5d6f Mon Sep 17 00:00:00 2001 From: Luis Herranz Date: Thu, 25 Jan 2024 12:55:58 +0100 Subject: [PATCH] Prevent usage of `gutenberg_url` in block-library (#58242) * Prevent usage of gutenberg_url in block-library * Add includes_url * Update enqueue module identifiers --- packages/block-library/src/file/index.php | 6 +++--- packages/block-library/src/image/index.php | 2 +- packages/block-library/src/navigation/index.php | 6 +++--- packages/block-library/src/query/index.php | 2 +- packages/block-library/src/search/index.php | 6 +++--- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/packages/block-library/src/file/index.php b/packages/block-library/src/file/index.php index 24eaff8bac622e..06eb10cf1d895b 100644 --- a/packages/block-library/src/file/index.php +++ b/packages/block-library/src/file/index.php @@ -38,7 +38,7 @@ static function ( $matches ) { // If it's interactive, enqueue the script module and add the directives. if ( ! empty( $attributes['displayPreview'] ) ) { - wp_enqueue_script_module( '@wordpress/block-library/file-block' ); + wp_enqueue_script_module( '@wordpress/block-library/file' ); $processor = new WP_HTML_Tag_Processor( $content ); $processor->next_tag(); @@ -64,8 +64,8 @@ function register_block_core_file() { ); wp_register_script_module( - '@wordpress/block-library/file-block', - gutenberg_url( '/build/interactivity/file.min.js' ), + '@wordpress/block-library/file', + defined( 'IS_GUTENBERG_PLUGIN' ) && IS_GUTENBERG_PLUGIN ? gutenberg_url( '/build/interactivity/file.min.js' ) : includes_url( 'blocks/file/view.min.js' ), array( '@wordpress/interactivity' ), defined( 'GUTENBERG_VERSION' ) ? GUTENBERG_VERSION : get_bloginfo( 'version' ) ); diff --git a/packages/block-library/src/image/index.php b/packages/block-library/src/image/index.php index 3297c57d9eab35..f926890c1a3fc2 100644 --- a/packages/block-library/src/image/index.php +++ b/packages/block-library/src/image/index.php @@ -325,7 +325,7 @@ function register_block_core_image() { wp_register_script_module( '@wordpress/block-library/image', - gutenberg_url( '/build/interactivity/image.min.js' ), + defined( 'IS_GUTENBERG_PLUGIN' ) && IS_GUTENBERG_PLUGIN ? gutenberg_url( '/build/interactivity/image.min.js' ) : includes_url( 'blocks/image/view.min.js' ), array( '@wordpress/interactivity' ), defined( 'GUTENBERG_VERSION' ) ? GUTENBERG_VERSION : get_bloginfo( 'version' ) ); diff --git a/packages/block-library/src/navigation/index.php b/packages/block-library/src/navigation/index.php index 0f67a63e7acf27..a0672a0bed5801 100644 --- a/packages/block-library/src/navigation/index.php +++ b/packages/block-library/src/navigation/index.php @@ -567,7 +567,7 @@ private static function get_nav_element_directives( $is_interactive, $attributes */ private static function handle_view_script_module_loading( $attributes, $block, $inner_blocks ) { if ( static::is_interactive( $attributes, $inner_blocks ) ) { - wp_enqueue_script_module( '@wordpress/block-library/navigation-block' ); + wp_enqueue_script_module( '@wordpress/block-library/navigation' ); } } @@ -1081,8 +1081,8 @@ function register_block_core_navigation() { ); wp_register_script_module( - '@wordpress/block-library/navigation-block', - gutenberg_url( '/build/interactivity/navigation.min.js' ), + '@wordpress/block-library/navigation', + defined( 'IS_GUTENBERG_PLUGIN' ) && IS_GUTENBERG_PLUGIN ? gutenberg_url( '/build/interactivity/navigation.min.js' ) : includes_url( 'blocks/navigation/view.min.js' ), array( '@wordpress/interactivity' ), defined( 'GUTENBERG_VERSION' ) ? GUTENBERG_VERSION : get_bloginfo( 'version' ) ); diff --git a/packages/block-library/src/query/index.php b/packages/block-library/src/query/index.php index 5d509607a7dc88..e21601b1711872 100644 --- a/packages/block-library/src/query/index.php +++ b/packages/block-library/src/query/index.php @@ -101,7 +101,7 @@ function register_block_core_query() { wp_register_script_module( '@wordpress/block-library/query', - gutenberg_url( '/build/interactivity/query.min.js' ), + defined( 'IS_GUTENBERG_PLUGIN' ) && IS_GUTENBERG_PLUGIN ? gutenberg_url( '/build/interactivity/query.min.js' ) : includes_url( 'blocks/query/view.min.js' ), array( array( 'id' => '@wordpress/interactivity', diff --git a/packages/block-library/src/search/index.php b/packages/block-library/src/search/index.php index 266eb93ca82a47..ce4277601937b8 100644 --- a/packages/block-library/src/search/index.php +++ b/packages/block-library/src/search/index.php @@ -80,7 +80,7 @@ function render_block_core_search( $attributes ) { // If it's interactive, enqueue the script module and add the directives. $is_expandable_searchfield = 'button-only' === $button_position; if ( $is_expandable_searchfield ) { - wp_enqueue_script_module( '@wordpress/block-library/search-block' ); + wp_enqueue_script_module( '@wordpress/block-library/search' ); $input->set_attribute( 'data-wp-bind--aria-hidden', '!context.isSearchInputVisible' ); $input->set_attribute( 'data-wp-bind--tabindex', 'state.tabindex' ); @@ -198,8 +198,8 @@ function register_block_core_search() { ); wp_register_script_module( - '@wordpress/block-library/search-block', - gutenberg_url( '/build/interactivity/search.min.js' ), + '@wordpress/block-library/search', + defined( 'IS_GUTENBERG_PLUGIN' ) && IS_GUTENBERG_PLUGIN ? gutenberg_url( '/build/interactivity/search.min.js' ) : includes_url( 'blocks/search/view.min.js' ), array( '@wordpress/interactivity' ), defined( 'GUTENBERG_VERSION' ) ? GUTENBERG_VERSION : get_bloginfo( 'version' ) );