From 01e357b166b40677e794bc4907a6c08b836ae349 Mon Sep 17 00:00:00 2001 From: audrasjb Date: Mon, 7 Jul 2025 17:09:41 +0000 Subject: [PATCH] Media: expose height and width attributes to the `wp_get_attachment_image_attributes` filter. Include the image height and width in the attributes passed to the `wp_get_attachment_image_attributes` filter. Developers can use this to adjust the width and height attributes returned from the `wp_get_attachment_image_attributes` function. Reviewed by audrasjb. Merges [60415] to the 6.8 branch. Props divinenephron, nacin, Sam_a, wpsmith, anatolbroder, ericlewis, puggan, SergeyBiryukov, spacedmonkey, adamsilverstein, flixos90, sandeepdahiya, SirLouen. Fixes #14110. Built from https://develop.svn.wordpress.org/branches/6.8@60420 git-svn-id: http://core.svn.wordpress.org/branches/6.8@59756 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/media.php | 24 +++++++++++++++--------- wp-includes/version.php | 2 +- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/wp-includes/media.php b/wp-includes/media.php index da46ef90a7..63b7fa671a 100644 --- a/wp-includes/media.php +++ b/wp-includes/media.php @@ -1070,7 +1070,6 @@ function wp_get_attachment_image( $attachment_id, $size = 'thumbnail', $icon = f list( $src, $width, $height ) = $image; $attachment = get_post( $attachment_id ); - $hwstring = image_hwstring( $width, $height ); $size_class = $size; if ( is_array( $size_class ) ) { @@ -1090,15 +1089,14 @@ function wp_get_attachment_image( $attachment_id, $size = 'thumbnail', $icon = f * * @param string $context The context. Default 'wp_get_attachment_image'. */ - $context = apply_filters( 'wp_get_attachment_image_context', 'wp_get_attachment_image' ); - $attr = wp_parse_args( $attr, $default_attr ); + $context = apply_filters( 'wp_get_attachment_image_context', 'wp_get_attachment_image' ); + $attr = wp_parse_args( $attr, $default_attr ); + $attr['width'] = $width; + $attr['height'] = $height; - $loading_attr = $attr; - $loading_attr['width'] = $width; - $loading_attr['height'] = $height; $loading_optimization_attr = wp_get_loading_optimization_attributes( 'img', - $loading_attr, + $attr, $context ); @@ -1169,8 +1167,16 @@ function wp_get_attachment_image( $attachment_id, $size = 'thumbnail', $icon = f */ $attr = apply_filters( 'wp_get_attachment_image_attributes', $attr, $attachment, $size ); - $attr = array_map( 'esc_attr', $attr ); - $html = rtrim( " $value ) { $html .= " $name=" . '"' . $value . '"'; diff --git a/wp-includes/version.php b/wp-includes/version.php index 755e015348..fe3a4c4203 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.8.2-alpha-60412'; +$wp_version = '6.8.2-alpha-60420'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.