Make WordPress Core


Ignore:
Timestamp:
09/03/2024 05:05:33 PM (3 months ago)
Author:
flixos90
Message:

Media: Consistently pass 'src' attribute to wp_get_loading_optimization_attributes().

A common use-case for the 'wp_get_loading_optimization_attributes' filter is to modify attributes based on the 'src' attribute. However, the wp_img_tag_add_loading_optimization_attrs() was not passing that attribute to the function as expected, which would make such usage of the filter unreliable. This changeset ensures the 'src' attribute is also passed in this scenario. All other calls to wp_get_loading_optimization_attributes() already included the attribute.

Props deepakrohilla, prestonwordsworth, mukesh27, adamsilverstein, joemcgill, flixos90.
Fixes #61436.
See #58893.

File:
1 edited

Legend:

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

    r58942 r58974  
    19741974 */
    19751975function wp_img_tag_add_loading_optimization_attrs( $image, $context ) {
     1976    $src               = preg_match( '/ src=["\']?([^"\']*)/i', $image, $matche_src ) ? $matche_src[1] : null;
    19761977    $width             = preg_match( '/ width=["\']([0-9]+)["\']/', $image, $match_width ) ? (int) $match_width[1] : null;
    19771978    $height            = preg_match( '/ height=["\']([0-9]+)["\']/', $image, $match_height ) ? (int) $match_height[1] : null;
     
    19881989        'img',
    19891990        array(
     1991            'src'           => $src,
    19901992            'width'         => $width,
    19911993            'height'        => $height,
Note: See TracChangeset for help on using the changeset viewer.