From 77af97466f302eff74bd799afb1600a112a5cf5e Mon Sep 17 00:00:00 2001 From: Felix Arntz Date: Tue, 3 Sep 2024 17:07:16 +0000 Subject: [PATCH] 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 --- wp-includes/media.php | 2 ++ wp-includes/version.php | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/wp-includes/media.php b/wp-includes/media.php index 5c93aee225..8a4277a2f5 100644 --- a/wp-includes/media.php +++ b/wp-includes/media.php @@ -1973,6 +1973,7 @@ function wp_filter_content_tags( $content, $context = null ) { * @return string Converted `img` tag with optimization attributes added. */ 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; $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; @@ -1987,6 +1988,7 @@ function wp_img_tag_add_loading_optimization_attrs( $image, $context ) { $optimization_attrs = wp_get_loading_optimization_attributes( 'img', array( + 'src' => $src, 'width' => $width, 'height' => $height, 'loading' => $loading_val, diff --git a/wp-includes/version.php b/wp-includes/version.php index 50dbedda25..8c5c0b7e4f 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @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.