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. Built from https://develop.svn.wordpress.org/trunk@58974 git-svn-id: http://core.svn.wordpress.org/trunk@58370 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
b734476509
commit
77af97466f
|
@ -1973,6 +1973,7 @@ function wp_filter_content_tags( $content, $context = null ) {
|
||||||
* @return string Converted `img` tag with optimization attributes added.
|
* @return string Converted `img` tag with optimization attributes added.
|
||||||
*/
|
*/
|
||||||
function wp_img_tag_add_loading_optimization_attrs( $image, $context ) {
|
function wp_img_tag_add_loading_optimization_attrs( $image, $context ) {
|
||||||
|
$src = preg_match( '/ src=["\']?([^"\']*)/i', $image, $matche_src ) ? $matche_src[1] : null;
|
||||||
$width = preg_match( '/ width=["\']([0-9]+)["\']/', $image, $match_width ) ? (int) $match_width[1] : null;
|
$width = preg_match( '/ width=["\']([0-9]+)["\']/', $image, $match_width ) ? (int) $match_width[1] : null;
|
||||||
$height = preg_match( '/ height=["\']([0-9]+)["\']/', $image, $match_height ) ? (int) $match_height[1] : null;
|
$height = preg_match( '/ height=["\']([0-9]+)["\']/', $image, $match_height ) ? (int) $match_height[1] : null;
|
||||||
$loading_val = preg_match( '/ loading=["\']([A-Za-z]+)["\']/', $image, $match_loading ) ? $match_loading[1] : null;
|
$loading_val = preg_match( '/ loading=["\']([A-Za-z]+)["\']/', $image, $match_loading ) ? $match_loading[1] : null;
|
||||||
|
@ -1987,6 +1988,7 @@ function wp_img_tag_add_loading_optimization_attrs( $image, $context ) {
|
||||||
$optimization_attrs = wp_get_loading_optimization_attributes(
|
$optimization_attrs = wp_get_loading_optimization_attributes(
|
||||||
'img',
|
'img',
|
||||||
array(
|
array(
|
||||||
|
'src' => $src,
|
||||||
'width' => $width,
|
'width' => $width,
|
||||||
'height' => $height,
|
'height' => $height,
|
||||||
'loading' => $loading_val,
|
'loading' => $loading_val,
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @global string $wp_version
|
||||||
*/
|
*/
|
||||||
$wp_version = '6.7-alpha-58972';
|
$wp_version = '6.7-alpha-58974';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||||
|
|
Loading…
Reference in New Issue