WordPress.org

Make WordPress Core

Changeset 48239


Ignore:
Timestamp:
06/30/2020 08:32:44 PM (3 months ago)
Author:
flixos90
Message:

Media: Only add loading attribute to img tags using double quotes.

Props azaozz.
Fixes #50367.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/media.php

    r48237 r48239  
    15891589        }
    15901590
    1591         // Add extra attributes to the image markup.
     1591        // Add the srcset and sizes attributes to the image markup.
    15921592        return preg_replace( '/<img ([^>]+?)[\/ ]*>/', '<img $1' . $attr . ' />', $image );
    15931593    }
     
    17381738
    17391739        // Images should have source and dimension attributes for the `loading` attribute to be added.
    1740         if ( false === strpos( $image, ' src=' ) || false === strpos( $image, ' width=' ) || false === strpos( $image, ' height=' ) ) {
     1740        if ( false === strpos( $image, ' src="' ) || false === strpos( $image, ' width="' ) || false === strpos( $image, ' height="' ) ) {
    17411741            return $image;
    17421742        }
  • trunk/tests/phpunit/tests/media.php

    r48237 r48239  
    26842684        $this->assertNotContains( ' loading="lazy"', $img );
    26852685    }
     2686
     2687    /**
     2688     * @ticket 50367
     2689     */
     2690    function test_wp_img_tag_add_loading_attr_with_single_quotes() {
     2691        $img = "<img src='example.png' alt=' width='300' height='225' />";
     2692        $img = wp_img_tag_add_loading_attr( $img, 'test' );
     2693
     2694        $this->assertNotContains( ' loading="lazy"', $img );
     2695    }
    26862696}
    26872697
Note: See TracChangeset for help on using the changeset viewer.