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
This commit is contained in:
@@ -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( "<img $hwstring" );
|
||||
if ( isset( $attr['height'] ) && is_numeric( $attr['height'] ) ) {
|
||||
$height = absint( $attr['height'] );
|
||||
}
|
||||
if ( isset( $attr['width'] ) && is_numeric( $attr['width'] ) ) {
|
||||
$width = absint( $attr['width'] );
|
||||
}
|
||||
unset( $attr['height'], $attr['width'] );
|
||||
$attr = array_map( 'esc_attr', $attr );
|
||||
$hwstring = image_hwstring( $width, $height );
|
||||
$html = rtrim( "<img $hwstring" );
|
||||
|
||||
foreach ( $attr as $name => $value ) {
|
||||
$html .= " $name=" . '"' . $value . '"';
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user