Skip to content

Commit 1cd6823

Browse files
Media: ensure wp_get_attachment_image uses valid user-provided width and height.
Fix a bug introduced in WordPress 6.8.2 (r60415) that led to user supplied values for width and height in the $attr array passed to `wp_get_attachment_image` to be overwritten. Props rainbowgeek, ocean90, rollybueno, shreya0shrivastava, heybran, mukesh27. Fixes #63714. Built from https://develop.svn.wordpress.org/trunk@60641 git-svn-id: http://core.svn.wordpress.org/trunk@59977 1a063a9b-81f0-0310-95a4-ce76da25c4cd
1 parent 6b2e46f commit 1cd6823

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

wp-includes/media.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,9 +1091,17 @@ function wp_get_attachment_image( $attachment_id, $size = 'thumbnail', $icon = f
10911091
*/
10921092
$context = apply_filters( 'wp_get_attachment_image_context', 'wp_get_attachment_image' );
10931093

1094-
$attr = wp_parse_args( $attr, $default_attr );
1095-
$attr['width'] = $width;
1096-
$attr['height'] = $height;
1094+
$attr = wp_parse_args( $attr, $default_attr );
1095+
1096+
// Ensure that the `$width` doesn't overwrite an already valid user-provided width.
1097+
if ( ! isset( $attr['width'] ) || ! is_numeric( $attr['width'] ) ) {
1098+
$attr['width'] = $width;
1099+
}
1100+
1101+
// Ensure that the `$height` doesn't overwrite an already valid user-provided height.
1102+
if ( ! isset( $attr['height'] ) || ! is_numeric( $attr['height'] ) ) {
1103+
$attr['height'] = $height;
1104+
}
10971105

10981106
$loading_optimization_attr = wp_get_loading_optimization_attributes(
10991107
'img',

wp-includes/version.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*
1717
* @global string $wp_version
1818
*/
19-
$wp_version = '6.9-alpha-60640';
19+
$wp_version = '6.9-alpha-60641';
2020

2121
/**
2222
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.

0 commit comments

Comments
 (0)