Skip to content

Commit

Permalink
Lazy Images: Fix regression with gazette featured image handling
Browse files Browse the repository at this point in the history
  • Loading branch information
ebinnion committed Feb 8, 2018
1 parent 3a7eaa3 commit ac9ad8e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 20 deletions.
42 changes: 22 additions & 20 deletions modules/lazy-images/lazy-images.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,30 +168,14 @@ static function process_image( $matches ) {
return $matches[0];
}

if (
! empty( $old_attributes_kses_hair['class'] ) &&
! empty( $old_attributes_kses_hair['class']['value'] ) &&
self::should_skip_image_with_blacklisted_class( $old_attributes_kses_hair['class']['value'] )
) {
return $matches[0];
}
$old_attributes = self::flatten_kses_hair_data( $old_attributes_kses_hair );
$new_attributes = self::process_image_attributes( $old_attributes );

/**
* Allow plugins and themes to conditionally skip processing an image via its attributes.
*
* @module-lazy-images
*
* @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_atttributes', false, $old_attributes_kses_hair ) ) {
// If we didn't add lazy attributes, just return the original image source.
if ( empty( $new_attributes['data-lazy-src'] ) ) {
return $matches[0];
}

$old_attributes = self::flatten_kses_hair_data( $old_attributes_kses_hair );
$new_attributes = self::process_image_attributes( $old_attributes );
$new_attributes_str = self::build_attributes_string( $new_attributes );

return sprintf( '<img %1$s><noscript>%2$s</noscript>', $new_attributes_str, $matches[0] );
Expand All @@ -212,6 +196,24 @@ static function process_image_attributes( $attributes ) {
return $attributes;
}

if ( ! empty( $attributes['class'] ) && self::should_skip_image_with_blacklisted_class( $attributes['class'] ) ) {
return $attributes;
}

/**
* Allow plugins and themes to conditionally skip processing an image via its attributes.
*
* @module-lazy-images
*
* @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_atttributes', false, $attributes ) ) {
return $attributes;
}

$old_attributes = $attributes;

// Set placeholder and lazy-src
Expand Down
15 changes: 15 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 @@ -115,6 +115,21 @@ function get_process_image_attributes_data() {
'data-lazy-sizes' => '(min-width: 36em) 33.3vw, 100vw'
)
),
'gazette_theme_featured_image' => array(
array(
'src' => 'image.jpg',
'width' => 10,
'height' => 10,
'class' => 'attachment-gazette-featured-content-thumbnail wp-post-image'
),
// should be unmodified
array(
'src' => 'image.jpg',
'width' => 10,
'height' => 10,
'class' => 'attachment-gazette-featured-content-thumbnail wp-post-image'
)
),
);
}

Expand Down

0 comments on commit ac9ad8e

Please sign in to comment.