From 3548fe9dec30b25825e19ffc15ce8e96f51995c6 Mon Sep 17 00:00:00 2001 From: helgatheviking <507025+helgatheviking@users.noreply.github.com> Date: Thu, 18 Sep 2025 11:19:39 -0400 Subject: [PATCH 1/4] Move add_filter calls to block initialize(). Closes #61012. --- .../changelog/issues-61012-legacy-filters | 4 +++ .../Blocks/BlockTypes/ProductImageGallery.php | 29 ++++++++++++------- 2 files changed, 23 insertions(+), 10 deletions(-) create mode 100644 plugins/woocommerce/changelog/issues-61012-legacy-filters diff --git a/plugins/woocommerce/changelog/issues-61012-legacy-filters b/plugins/woocommerce/changelog/issues-61012-legacy-filters new file mode 100644 index 0000000000000..10eef4ace7f05 --- /dev/null +++ b/plugins/woocommerce/changelog/issues-61012-legacy-filters @@ -0,0 +1,4 @@ +Significance: patch +Type: fix + +Make legacy gallery filters available while rendering blocks diff --git a/plugins/woocommerce/src/Blocks/BlockTypes/ProductImageGallery.php b/plugins/woocommerce/src/Blocks/BlockTypes/ProductImageGallery.php index d70658eb99236..1e0305f5b7670 100644 --- a/plugins/woocommerce/src/Blocks/BlockTypes/ProductImageGallery.php +++ b/plugins/woocommerce/src/Blocks/BlockTypes/ProductImageGallery.php @@ -14,6 +14,25 @@ class ProductImageGallery extends AbstractBlock { */ protected $block_name = 'product-image-gallery'; + /** + * Initialize this block type. + * + * - Hook into WP lifecycle. + * - Register the block with WordPress. + */ + protected function initialize() { + parent::initialize(); + add_action( + 'wp_footer', + function () { + wc_get_template( 'single-product/photoswipe.php' ); + } + ); + add_filter( 'woocommerce_single_product_zoom_enabled', '__return_true' ); + add_filter( 'woocommerce_single_product_photoswipe_enabled', '__return_true' ); + add_filter( 'woocommerce_single_product_flexslider_enabled', '__return_true' ); + } + /** * It isn't necessary register block assets because it is a server side block. */ @@ -58,16 +77,6 @@ public function enqueue_legacy_assets() { wp_enqueue_script( 'wc-photoswipe-ui-default' ); wp_enqueue_style( 'photoswipe-default-skin' ); wp_enqueue_script( 'wc-single-product' ); - - add_action( - 'wp_footer', - function () { - wc_get_template( 'single-product/photoswipe.php' ); - } - ); - add_filter( 'woocommerce_single_product_zoom_enabled', '__return_true' ); - add_filter( 'woocommerce_single_product_photoswipe_enabled', '__return_true' ); - add_filter( 'woocommerce_single_product_flexslider_enabled', '__return_true' ); } /** From e7e52581531497e5de0b88e27f8fc6cb196d4bd3 Mon Sep 17 00:00:00 2001 From: helgatheviking <507025+helgatheviking@users.noreply.github.com> Date: Thu, 25 Sep 2025 09:14:44 -0400 Subject: [PATCH 2/4] move legacy gallery filters into render() --- .../src/Blocks/BlockTypes/ProductImageGallery.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/plugins/woocommerce/src/Blocks/BlockTypes/ProductImageGallery.php b/plugins/woocommerce/src/Blocks/BlockTypes/ProductImageGallery.php index 1e0305f5b7670..ab830d7a1e159 100644 --- a/plugins/woocommerce/src/Blocks/BlockTypes/ProductImageGallery.php +++ b/plugins/woocommerce/src/Blocks/BlockTypes/ProductImageGallery.php @@ -28,9 +28,6 @@ function () { wc_get_template( 'single-product/photoswipe.php' ); } ); - add_filter( 'woocommerce_single_product_zoom_enabled', '__return_true' ); - add_filter( 'woocommerce_single_product_photoswipe_enabled', '__return_true' ); - add_filter( 'woocommerce_single_product_flexslider_enabled', '__return_true' ); } /** @@ -104,6 +101,10 @@ protected function render( $attributes, $content, $block ) { return ''; } + add_filter( 'woocommerce_single_product_zoom_enabled', '__return_true' ); + add_filter( 'woocommerce_single_product_photoswipe_enabled', '__return_true' ); + add_filter( 'woocommerce_single_product_flexslider_enabled', '__return_true' ); + ob_start(); woocommerce_show_product_sale_flash(); $sale_badge_html = ob_get_clean(); From c48a2dcaecd3c78429992e28e3543c136ad3dae1 Mon Sep 17 00:00:00 2001 From: helgatheviking <507025+helgatheviking@users.noreply.github.com> Date: Fri, 26 Sep 2025 09:35:45 -0400 Subject: [PATCH 3/4] Finish moving add_action() to render() as well. --- .../Blocks/BlockTypes/ProductImageGallery.php | 23 ++++++------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/plugins/woocommerce/src/Blocks/BlockTypes/ProductImageGallery.php b/plugins/woocommerce/src/Blocks/BlockTypes/ProductImageGallery.php index ab830d7a1e159..0ee8df3808048 100644 --- a/plugins/woocommerce/src/Blocks/BlockTypes/ProductImageGallery.php +++ b/plugins/woocommerce/src/Blocks/BlockTypes/ProductImageGallery.php @@ -14,22 +14,6 @@ class ProductImageGallery extends AbstractBlock { */ protected $block_name = 'product-image-gallery'; - /** - * Initialize this block type. - * - * - Hook into WP lifecycle. - * - Register the block with WordPress. - */ - protected function initialize() { - parent::initialize(); - add_action( - 'wp_footer', - function () { - wc_get_template( 'single-product/photoswipe.php' ); - } - ); - } - /** * It isn't necessary register block assets because it is a server side block. */ @@ -101,6 +85,13 @@ protected function render( $attributes, $content, $block ) { return ''; } + add_action( + 'wp_footer', + function () { + wc_get_template( 'single-product/photoswipe.php' ); + } + ); + add_filter( 'woocommerce_single_product_zoom_enabled', '__return_true' ); add_filter( 'woocommerce_single_product_photoswipe_enabled', '__return_true' ); add_filter( 'woocommerce_single_product_flexslider_enabled', '__return_true' ); From dc1b403ae3f87106d9bcc53a518564067f64e465 Mon Sep 17 00:00:00 2001 From: helgatheviking <507025+helgatheviking@users.noreply.github.com> Date: Fri, 26 Sep 2025 09:46:24 -0400 Subject: [PATCH 4/4] Revert add_action() back to original place in enqueue_legacy_assets() --- .../src/Blocks/BlockTypes/ProductImageGallery.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/plugins/woocommerce/src/Blocks/BlockTypes/ProductImageGallery.php b/plugins/woocommerce/src/Blocks/BlockTypes/ProductImageGallery.php index 0ee8df3808048..8573b8b78af9f 100644 --- a/plugins/woocommerce/src/Blocks/BlockTypes/ProductImageGallery.php +++ b/plugins/woocommerce/src/Blocks/BlockTypes/ProductImageGallery.php @@ -58,6 +58,13 @@ public function enqueue_legacy_assets() { wp_enqueue_script( 'wc-photoswipe-ui-default' ); wp_enqueue_style( 'photoswipe-default-skin' ); wp_enqueue_script( 'wc-single-product' ); + + add_action( + 'wp_footer', + function () { + wc_get_template( 'single-product/photoswipe.php' ); + } + ); } /** @@ -85,13 +92,6 @@ protected function render( $attributes, $content, $block ) { return ''; } - add_action( - 'wp_footer', - function () { - wc_get_template( 'single-product/photoswipe.php' ); - } - ); - add_filter( 'woocommerce_single_product_zoom_enabled', '__return_true' ); add_filter( 'woocommerce_single_product_photoswipe_enabled', '__return_true' ); add_filter( 'woocommerce_single_product_flexslider_enabled', '__return_true' );