diff --git a/modules/lazy-images/lazy-images.php b/modules/lazy-images/lazy-images.php index c809284068514..7a1fa9a03dd33 100644 --- a/modules/lazy-images/lazy-images.php +++ b/modules/lazy-images/lazy-images.php @@ -202,6 +202,10 @@ static function process_image_attributes( $attributes ) { return $attributes; } + if ( isset( $attributes['data-skip-lazy'] ) ) { + return $attributes; + } + /** * Allow plugins and themes to conditionally skip processing an image via its attributes. * diff --git a/tests/php/modules/lazy-images/test_class.lazy-images.php b/tests/php/modules/lazy-images/test_class.lazy-images.php index bfa2bb00d97f5..72afd4b76b8fe 100644 --- a/tests/php/modules/lazy-images/test_class.lazy-images.php +++ b/tests/php/modules/lazy-images/test_class.lazy-images.php @@ -271,6 +271,34 @@ function get_dont_process_images_with_classes_data() { ); } + /** + * @dataProvider get_dont_process_images_with_skip_lazy_data_attribute_data + */ + function test_dont_process_images_with_skip_lazy_data_attribute( $input, $should_skip = true ) { + $instance = Jetpack_Lazy_Images::instance(); + $output = $instance->add_image_placeholders( $input ); + + if ( $should_skip ) { + $this->assertNotContains( 'srcset="placeholder.jpg"', $output ); + } else { + $this->assertContains( 'srcset="placeholder.jpg"', $output ); + } + } + + function get_dont_process_images_with_skip_lazy_data_attribute_data() { + return array( + 'skip_lazy_attr_only' => array( + '', + ), + 'skip-lazy-attr-true' => array( + '', + ), + 'skip-lazy-attr-1' => array( + '', + ), + ); + } + /** * @dataProvider get_should_skip_image_with_blacklisted_class_data */