From 382480bffa1f93953feabdb87586dd32b3584c7c Mon Sep 17 00:00:00 2001 From: Andrea Fercia Date: Mon, 9 Oct 2023 12:25:56 +0200 Subject: [PATCH] Make sure to add filter and view file when needed. --- packages/block-library/src/image/index.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/block-library/src/image/index.php b/packages/block-library/src/image/index.php index a98c9d33747105..fa2a28590001a3 100644 --- a/packages/block-library/src/image/index.php +++ b/packages/block-library/src/image/index.php @@ -38,16 +38,6 @@ function render_block_core_image( $attributes, $content, $block ) { $view_js_file_handle = 'wp-block-image-view'; $script_handles = $block->block_type->view_script_handles; - /* - * Remove the filter and the JavaScript view file if previously added by - * other Image blocks. - */ - remove_filter( 'render_block_core/image', 'block_core_image_render_lightbox', 15 ); - // If the script is not needed, and it is still in the `view_script_handles`, remove it. - if ( in_array( $view_js_file_handle, $script_handles, true ) ) { - $block->block_type->view_script_handles = array_diff( $script_handles, array( $view_js_file_handle ) ); - } - /* * If the lightbox is enabled and the image is not linked, add the filter * and the JavaScript view file. @@ -73,6 +63,16 @@ function render_block_core_image( $attributes, $content, $block ) { * rendered changes, or if a new kind of filter is introduced. */ add_filter( 'render_block_core/image', 'block_core_image_render_lightbox', 15, 2 ); + } else { + /* + * Remove the filter and the JavaScript view file if previously added by + * other Image blocks. + */ + remove_filter( 'render_block_core/image', 'block_core_image_render_lightbox', 15 ); + // If the script is not needed, and it is still in the `view_script_handles`, remove it. + if ( in_array( $view_js_file_handle, $script_handles, true ) ) { + $block->block_type->view_script_handles = array_diff( $script_handles, array( $view_js_file_handle ) ); + } } return $processor->get_updated_html();