Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lazy Images: Skip images with data-skip-lazy attribute #14539

Merged
merged 1 commit into from
Feb 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions modules/lazy-images/lazy-images.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
28 changes: 28 additions & 0 deletions tests/php/modules/lazy-images/test_class.lazy-images.php
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,34 @@ function get_dont_process_images_with_classes_data() {
);
}

/**
* @dataProvider get_dont_process_images_with_skip_lazy_data_attribute_data
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL how to use @dataProvider! Thanks for adding the tests.

*/
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(
'<img src="image.jpg" srcset="medium.jpg 1000w, large.jpg 2000w" data-skip-lazy/>',
),
'skip-lazy-attr-true' => array(
'<img src="image.jpg" srcset="medium.jpg 1000w, large.jpg 2000w" data-skip-lazy="true"/>',
),
'skip-lazy-attr-1' => array(
'<img src="image.jpg" srcset="medium.jpg 1000w, large.jpg 2000w" data-skip-lazy="1"/>',
),
);
}

/**
* @dataProvider get_should_skip_image_with_blacklisted_class_data
*/
Expand Down