Make WordPress Core


Ignore:
Timestamp:
07/05/2023 07:28:02 PM (13 months ago)
Author:
flixos90
Message:

Media: Ensure custom header image tag supports loading optimization attributes.

This changeset is a follow up to [56037] and ensures that the get_header_image_tag() function receives the benefits of wp_get_loading_optimization_attributes() as well. Prior to fetchpriority support, this was not needed since the header image should never be lazy-loaded, but the image certainly is a fetchpriority candidate, so therefore it is crucial to have it supported.

Props felipeelia, spacedmonkey, mukesh27, westonruter, flixos90.
Fixes #58680.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/theme/customHeader.php

    r53948 r56142  
    175175    }
    176176
     177    /**
     178     * Tests default values of performance attributes for "get_header_image_tag".
     179     *
     180     * @ticket 58680
     181     */
     182    public function test_get_header_image_tag_with_default_performance_attributes() {
     183        $this->add_theme_support(
     184            array(
     185                'default-image' => 'http://localhost/default-header.jpg',
     186                'width'         => 60,
     187                'height'        => 60,
     188            )
     189        );
     190
     191        add_filter(
     192            'wp_min_priority_img_pixels',
     193            static function() {
     194                return 2500; // 50*50=2500
     195            }
     196        );
     197
     198        wp_high_priority_element_flag( true );
     199
     200        $html = get_header_image_tag();
     201        $this->assertStringNotContainsString( ' loading="lazy"', $html );
     202        $this->assertStringContainsString( ' fetchpriority="high"', $html );
     203        $this->assertStringContainsString( ' decoding="async"', $html );
     204    }
     205
     206    /**
     207     * Tests custom values of performance attributes for "get_header_image_tag".
     208     *
     209     * @ticket 58680
     210     */
     211    public function test_get_header_image_tag_with_custom_performance_attributes() {
     212        $this->add_theme_support(
     213            array(
     214                'default-image' => 'http://localhost/default-header.jpg',
     215                'width'         => 500,
     216                'height'        => 500,
     217            )
     218        );
     219
     220        $html = get_header_image_tag(
     221            array(
     222                'fetchpriority' => '',
     223                'decoding'      => '',
     224            )
     225        );
     226        $this->assertStringNotContainsString( ' fetchpriority="high"', $html );
     227        $this->assertStringNotContainsString( ' decoding="async"', $html );
     228    }
     229
     230    /**
     231     * Tests custom lazy loading for "get_header_image_tag".
     232     *
     233     * @ticket 58680
     234     */
     235    public function test_get_header_image_tag_with_custom_lazy_loading() {
     236        $this->add_theme_support(
     237            array(
     238                'default-image' => 'http://localhost/default-header.jpg',
     239                'width'         => 500,
     240                'height'        => 500,
     241            )
     242        );
     243
     244        $html = get_header_image_tag(
     245            array(
     246                'loading' => 'lazy',
     247            )
     248        );
     249        $this->assertStringNotContainsString( ' fetchpriority="high"', $html );
     250        $this->assertStringContainsString( ' loading="lazy"', $html );
     251    }
     252
    177253    public function test_get_custom_header_markup_without_registered_default_image() {
    178254        $this->add_theme_support();
Note: See TracChangeset for help on using the changeset viewer.