From fcfaff63e6ddda7232c51993d591f51e842cb5a9 Mon Sep 17 00:00:00 2001 From: tijmen Date: Sun, 1 Feb 2026 20:29:30 +0100 Subject: [PATCH 01/11] Add woocommerce compat class --- .../woocommerce/class-tiny-woocommerce.php | 60 +++++++++++++++++++ tiny-compress-images.php | 1 + 2 files changed, 61 insertions(+) create mode 100644 src/compatibility/woocommerce/class-tiny-woocommerce.php diff --git a/src/compatibility/woocommerce/class-tiny-woocommerce.php b/src/compatibility/woocommerce/class-tiny-woocommerce.php new file mode 100644 index 0000000..1caaa05 --- /dev/null +++ b/src/compatibility/woocommerce/class-tiny-woocommerce.php @@ -0,0 +1,60 @@ +add_hooks(); + } + + private function add_hooks() + { + add_filter('tiny_skip_picture_wrap', array($this, 'skip_product_gallery_images'), 10, 2); + } + + /** + * Skip picture wrapping for WooCommerce product gallery images. + * + * Product gallery images need to remain as direct children of their parent + * elements for WooCommerce's variation switcher to work correctly. + * + * @param bool $should_skip Whether to skip this image. Default false. + * @param string $img The img tag HTML. + * @return bool True if the image should be skipped, false otherwise. + */ + public function skip_product_gallery_images($should_skip, $img) + { + if ($should_skip) { + return $should_skip; + } + + return stripos($img, 'woocommerce-product-gallery__image') !== false; + } +} diff --git a/tiny-compress-images.php b/tiny-compress-images.php index 2e56b0c..5cbca7e 100644 --- a/tiny-compress-images.php +++ b/tiny-compress-images.php @@ -27,6 +27,7 @@ require dirname( __FILE__ ) . '/src/class-tiny-picture.php'; require dirname( __FILE__ ) . '/src/compatibility/wpml/class-tiny-wpml.php'; require dirname( __FILE__ ) . '/src/compatibility/as3cf/class-tiny-as3cf.php'; +require dirname( __FILE__ ) . '/src/compatibility/woocommerce/class-tiny-woocommerce.php'; if ( Tiny_PHP::client_supported() ) { require dirname( __FILE__ ) . '/src/class-tiny-compress-client.php'; From 224160e4e9daf06ff5b3d0ce47daf9dea0b59079 Mon Sep 17 00:00:00 2001 From: tijmen Date: Sun, 1 Feb 2026 20:29:57 +0100 Subject: [PATCH 02/11] feat: add filter to skip specific images --- src/class-tiny-picture.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/class-tiny-picture.php b/src/class-tiny-picture.php index 1c9eaf9..e9b9afa 100644 --- a/src/class-tiny-picture.php +++ b/src/class-tiny-picture.php @@ -180,8 +180,21 @@ private function filter_images( $content ) { if ( ! preg_match_all( '/]*>/is', $content, $matches ) ) { return array(); } + $images = array(); foreach ( $matches[0] as $img ) { + /** + * Filters whether a specific image should be skipped from picture element wrapping. + * + * @since 3.6.9 + * + * @param bool $should_skip Whether to skip this image. Default false. + * @param string $img The img tag HTML. + */ + if ( apply_filters( 'tiny_skip_picture_wrap', false, $img ) ) { + continue; + } + $images[] = new Tiny_Source_Image( $img, $this->base_dir, From 3782ed987d678e2423fe238f5a6687e8b46f1ddb Mon Sep 17 00:00:00 2001 From: tijmen Date: Sun, 1 Feb 2026 22:25:24 +0100 Subject: [PATCH 03/11] Add filter for skipping html --- src/class-tiny-picture.php | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/src/class-tiny-picture.php b/src/class-tiny-picture.php index e9b9afa..435cc4c 100644 --- a/src/class-tiny-picture.php +++ b/src/class-tiny-picture.php @@ -176,25 +176,21 @@ private function filter_images( $content ) { // Strip