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: Fix typo in attributes filter name #10002

Merged
merged 1 commit into from
Aug 9, 2018
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
1 change: 1 addition & 0 deletions class.jetpack.php
Original file line number Diff line number Diff line change
Expand Up @@ -6633,6 +6633,7 @@ public function deprecated_hooks() {
'jetpack_sso_auth_cookie_expirtation' => 'jetpack_sso_auth_cookie_expiration',
'jetpack_cache_plans' => null,
'jetpack_updated_theme' => 'jetpack_updated_themes',
'jetpack_lazy_images_skip_image_with_atttributes' => 'jetpack_lazy_images_skip_image_with_attributes',
);

// This is a silly loop depth. Better way?
Expand Down
17 changes: 17 additions & 0 deletions modules/lazy-images/lazy-images.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ static function process_image_attributes( $attributes ) {
*
* @module-lazy-images
*
* @deprecated 6.5.0 Use jetpack_lazy_images_skip_image_with_attributes instead.
*
* @since 5.9.0
*
* @param bool Default to not skip processing the current image.
Expand All @@ -218,6 +220,21 @@ static function process_image_attributes( $attributes ) {
return $attributes;
}

/**
* Allow plugins and themes to conditionally skip processing an image via its attributes.
*
* @module-lazy-images
*
* @since 6.5.0 Filter name was updated from jetpack_lazy_images_skip_image_with_atttributes to correct typo.
* @since 5.9.0
*
* @param bool Default to not skip processing the current image.
* @param array An array of attributes via wp_kses_hair() for the current image.
*/
if ( apply_filters( 'jetpack_lazy_images_skip_image_with_attributes', false, $attributes ) ) {
return $attributes;
}

$old_attributes = $attributes;

// Set placeholder and lazy-src
Expand Down
24 changes: 19 additions & 5 deletions tests/php/modules/lazy-images/test_class.lazy-images.php
Original file line number Diff line number Diff line change
Expand Up @@ -313,20 +313,34 @@ function get_should_skip_image_with_filtered_empty_blacklist_data() {
);
}

function test_jetpack_lazy_images_skip_image_with_atttributes_filter() {
/**
* @dataProvider get_skip_image_with_attributes_data
*/
function test_jetpack_lazy_images_skip_image_with_attributes_filter( $filter_name ) {
$instance = Jetpack_Lazy_Images::instance();
$src = '<img src="image.jpg" srcset="medium.jpg 1000w, large.jpg 2000w" class="wp-post-image"/>';

$this->assertContains( 'src="placeholder.jpg"', $instance->add_image_placeholders( $src ) );

add_filter( 'jetpack_lazy_images_skip_image_with_atttributes', '__return_true' );
add_filter( 'jetpack_lazy_images_skip_image_with_attributes', '__return_true' );
$this->assertNotContains( 'src="placeholder.jpg"', $instance->add_image_placeholders( $src ) );
remove_filter( 'jetpack_lazy_images_skip_image_with_atttributes', '__return_true' );
remove_filter( 'jetpack_lazy_images_skip_image_with_attributes', '__return_true' );

add_filter( 'jetpack_lazy_images_skip_image_with_atttributes', array( $this, '__skip_if_srcset' ), 10, 2 );
add_filter( 'jetpack_lazy_images_skip_image_with_attributes', array( $this, '__skip_if_srcset' ), 10, 2 );
$this->assertNotContains( 'src="placeholder.jpg"', $instance->add_image_placeholders( $src ) );
$this->assertContains( 'src="placeholder.jpg"', $instance->add_image_placeholders( '<img src="image.jpg" />' ) );
remove_filter( 'jetpack_lazy_images_skip_image_with_atttributes', array( $this, '__skip_if_srcset' ), 10, 2 );
remove_filter( 'jetpack_lazy_images_skip_image_with_attributes', array( $this, '__skip_if_srcset' ), 10, 2 );
}

function get_skip_image_with_attributes_data() {
return array(
'deprecated_filter_name_with_typo' => array(
'jetpack_lazy_images_skip_image_with_atttributes'
),
'correct_filter_name' => array(
'jetpack_lazy_images_skip_image_with_attributes'
),
);
}

/*
Expand Down