|
| 1 | +<?php |
| 2 | +/* |
| 3 | +* Tiny Compress Images - WordPress plugin. |
| 4 | +* Copyright (C) 2015-2018 Tinify B.V. |
| 5 | +* |
| 6 | +* This program is free software; you can redistribute it and/or modify it |
| 7 | +* under the terms of the GNU General Public License as published by the Free |
| 8 | +* Software Foundation; either version 2 of the License, or (at your option) |
| 9 | +* any later version. |
| 10 | +* |
| 11 | +* This program is distributed in the hope that it will be useful, but WITHOUT |
| 12 | +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 13 | +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 14 | +* more details. |
| 15 | +* |
| 16 | +* You should have received a copy of the GNU General Public License along |
| 17 | +* with this program; if not, write to the Free Software Foundation, Inc., 51 |
| 18 | +* Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 19 | +*/ |
| 20 | + |
| 21 | +/** |
| 22 | + * Handles WooCommerce compatibility |
| 23 | + * |
| 24 | + * @since 3.6.9 |
| 25 | + */ |
| 26 | +class Tiny_WooCommerce { |
| 27 | + |
| 28 | + public function __construct() { |
| 29 | + if ( ! class_exists( 'WooCommerce' ) ) { |
| 30 | + return; |
| 31 | + } |
| 32 | + |
| 33 | + $this->add_hooks(); |
| 34 | + } |
| 35 | + |
| 36 | + private function add_hooks() { |
| 37 | + add_filter( 'tiny_replace_with_picture', array( $this, 'skip_on_product_pages' ), 10, 1 ); |
| 38 | + } |
| 39 | + |
| 40 | + /** |
| 41 | + * We are skipping single product pages for now. |
| 42 | + * Variation images in the product gallery are injected through JavaScript but might never |
| 43 | + * display because the sourceset takes priority over the root img. The replacement is on the image and not |
| 44 | + * on the srcset. |
| 45 | + * |
| 46 | + * @since 3.6.9 |
| 47 | + * |
| 48 | + * @param bool $should_replace Whether to replace images with picture elements. |
| 49 | + * @return bool False on product pages, otherwise unchanged. |
| 50 | + */ |
| 51 | + public function skip_on_product_pages( $should_replace ) { |
| 52 | + if ( is_product() ) { |
| 53 | + return false; |
| 54 | + } |
| 55 | + |
| 56 | + return $should_replace; |
| 57 | + } |
| 58 | +} |
0 commit comments