mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-06-28 14:20:15 +00:00
Media: Ensure that large images before the main query loop are counted towards lazy-loading threshold.
Following [55318], [55847], and [56142], certain images in the header of the page have received support for potentially receiving `fetchpriority="high"` and having the `loading="lazy"` attribute omitted. However, these images being present did not affect the "content media count" which counts the images towards a certain threshold so that the first ones are not lazy-loaded. This changeset also increases that count for such header images if they are larger than a certain threshold. The threshold is used to avoid e.g. a header with lots of small images such as icon graphics to skew the lazy-loading behavior. Props thekt12, spacedmonkey, flixos90. Fixes #58635. git-svn-id: https://develop.svn.wordpress.org/trunk@56143 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -5094,6 +5094,55 @@ EOF;
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 58635
|
||||
*
|
||||
* @covers ::wp_get_loading_optimization_attributes
|
||||
*/
|
||||
public function test_wp_get_loading_optimization_attributes_header_block_template_increase_media_count() {
|
||||
$attr = $this->get_width_height_for_high_priority();
|
||||
wp_get_loading_optimization_attributes( 'img', $attr, 'template_part_' . WP_TEMPLATE_PART_AREA_HEADER );
|
||||
|
||||
// Images with a certain minimum size in the header of the page are also counted towards the threshold.
|
||||
$this->assertSame( 1, wp_increase_content_media_count( 0 ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 58635
|
||||
*
|
||||
* @covers ::wp_get_loading_optimization_attributes
|
||||
*/
|
||||
public function test_wp_get_loading_optimization_attributes_header_image_tag_increase_media_count() {
|
||||
$attr = $this->get_width_height_for_high_priority();
|
||||
wp_get_loading_optimization_attributes( 'img', $attr, 'get_header_image_tag' );
|
||||
|
||||
// Images with a certain minimum size in the header of the page are also counted towards the threshold.
|
||||
$this->assertSame( 1, wp_increase_content_media_count( 0 ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 58635
|
||||
*
|
||||
* @covers ::wp_get_loading_optimization_attributes
|
||||
*
|
||||
* @dataProvider data_wp_get_loading_attr_default_before_and_no_loop
|
||||
*
|
||||
* @param string $context Context for the element for which the `loading` attribute value is requested.
|
||||
*/
|
||||
public function test_wp_get_loading_optimization_attributes_image_before_loop_increase_media_count( $context ) {
|
||||
global $wp_query;
|
||||
|
||||
$wp_query = $this->get_new_wp_query_for_published_post();
|
||||
$this->set_main_query( $wp_query );
|
||||
do_action( 'get_header' );
|
||||
|
||||
$attr = $this->get_width_height_for_high_priority();
|
||||
wp_get_loading_optimization_attributes( 'img', $attr, $context );
|
||||
|
||||
// Images with a certain minimum size in the header of the page are also counted towards the threshold.
|
||||
$this->assertSame( 1, wp_increase_content_media_count( 0 ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to keep track of the last context returned by the 'wp_get_attachment_image_context' filter.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user