From d762b954c14ae6757d6bc4ed2e767c375346b99d Mon Sep 17 00:00:00 2001 From: Luis Herranz Date: Wed, 12 Jul 2023 19:46:44 +0200 Subject: [PATCH] Filter to switch from the Interactivity API to the old implementation --- packages/block-library/src/file/index.php | 4 ++-- packages/block-library/src/navigation/index.php | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/block-library/src/file/index.php b/packages/block-library/src/file/index.php index 172bb5d836343d..e7775c5ffbdfb3 100644 --- a/packages/block-library/src/file/index.php +++ b/packages/block-library/src/file/index.php @@ -5,7 +5,7 @@ * @package WordPress */ -if ( defined( 'IS_GUTENBERG_PLUGIN' ) && IS_GUTENBERG_PLUGIN ) { +if ( apply_filters( 'gutenberg_block_core_file_use_interactivity_api', true ) ) { /** * Replaces view script for the File block with version using Interactivity API. * @@ -71,7 +71,7 @@ static function ( $matches ) { ); // If it uses the Interactivity API, add the directives. - if ( defined( 'IS_GUTENBERG_PLUGIN' ) && IS_GUTENBERG_PLUGIN && $should_load_view_script ) { + if ( apply_filters( 'gutenberg_block_core_file_use_interactivity_api', true ) && $should_load_view_script ) { $processor = new WP_HTML_Tag_Processor( $content ); $processor->next_tag(); $processor->set_attribute( 'data-wp-interactive', '' ); diff --git a/packages/block-library/src/navigation/index.php b/packages/block-library/src/navigation/index.php index cfdd20100af812..7fdde3f49d29d8 100644 --- a/packages/block-library/src/navigation/index.php +++ b/packages/block-library/src/navigation/index.php @@ -7,7 +7,7 @@ // These functions are used for the __unstableLocation feature and only active // when the gutenberg plugin is active. -if ( defined( 'IS_GUTENBERG_PLUGIN' ) && IS_GUTENBERG_PLUGIN ) { +if ( apply_filters( 'gutenberg_block_core_navigation_use_interactivity_api', true ) ) { /** * Returns the menu items for a WordPress menu location. * @@ -471,7 +471,7 @@ function render_block_core_navigation( $attributes, $content, $block ) { // - we don't have a relationship to a `wp_navigation` Post (via `ref`). // ...then create inner blocks from the classic menu assigned to that location. if ( - defined( 'IS_GUTENBERG_PLUGIN' ) && IS_GUTENBERG_PLUGIN && + apply_filters( 'gutenberg_block_core_navigation_use_interactivity_api', true ) && array_key_exists( '__unstableLocation', $attributes ) && ! array_key_exists( 'ref', $attributes ) && ! empty( block_core_navigation_get_menu_items_at_location( $attributes['__unstableLocation'] ) ) @@ -685,7 +685,7 @@ function render_block_core_navigation( $attributes, $content, $block ) { } // Add directives to the submenu if needed. - if ( defined( 'IS_GUTENBERG_PLUGIN' ) && IS_GUTENBERG_PLUGIN && $has_submenus && $should_load_view_script ) { + if ( apply_filters( 'gutenberg_block_core_navigation_use_interactivity_api', true ) && $has_submenus && $should_load_view_script ) { $w = new WP_HTML_Tag_Processor( $inner_blocks_html ); $inner_blocks_html = block_core_navigation_add_directives_to_submenu( $w, $attributes ); } @@ -733,7 +733,7 @@ function render_block_core_navigation( $attributes, $content, $block ) { $responsive_container_directives = ''; $responsive_dialog_directives = ''; $close_button_directives = ''; - if ( defined( 'IS_GUTENBERG_PLUGIN' ) && IS_GUTENBERG_PLUGIN && $should_load_view_script ) { + if ( apply_filters( 'gutenberg_block_core_navigation_use_interactivity_api', true ) && $should_load_view_script ) { $nav_element_directives = ' data-wp-interactive data-wp-context=\'{ "core": { "navigation": { "overlayOpenedBy": {}, "type": "overlay", "roleAttribute": "" } } }\'