From a89ded235c9cf1f3b6c3efbd67ae81830983c5c9 Mon Sep 17 00:00:00 2001 From: hbhalodia Date: Fri, 27 Feb 2026 13:37:45 +0530 Subject: [PATCH 1/8] Fix php warning if wp_get_attachment_image_src returns false --- src/wp-includes/embed.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/wp-includes/embed.php b/src/wp-includes/embed.php index dd21b6cf22fe1..c767e3349cf64 100644 --- a/src/wp-includes/embed.php +++ b/src/wp-includes/embed.php @@ -739,10 +739,14 @@ function get_oembed_response_data_rich( $data, $post, $width, $height ) { } if ( $thumbnail_id ) { - list( $thumbnail_url, $thumbnail_width, $thumbnail_height ) = wp_get_attachment_image_src( $thumbnail_id, array( $width, 0 ) ); - $data['thumbnail_url'] = $thumbnail_url; - $data['thumbnail_width'] = $thumbnail_width; - $data['thumbnail_height'] = $thumbnail_height; + $thumbnail_src = wp_get_attachment_image_src( $thumbnail_id, array( $width, 0 ) ); + + if ( $thumbnail_src ) { + list( $thumbnail_url, $thumbnail_width, $thumbnail_height ) = $thumbnail_src; + $data['thumbnail_url'] = $thumbnail_url; + $data['thumbnail_width'] = $thumbnail_width; + $data['thumbnail_height'] = $thumbnail_height; + } } return $data; From 167623d459b455a9b6d5dce1e3dad43f96a9f7fb Mon Sep 17 00:00:00 2001 From: hbhalodia Date: Mon, 9 Mar 2026 10:24:42 +0530 Subject: [PATCH 2/8] Address feedbacks --- src/wp-includes/embed.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/wp-includes/embed.php b/src/wp-includes/embed.php index c767e3349cf64..233efcfb3176f 100644 --- a/src/wp-includes/embed.php +++ b/src/wp-includes/embed.php @@ -741,11 +741,10 @@ function get_oembed_response_data_rich( $data, $post, $width, $height ) { if ( $thumbnail_id ) { $thumbnail_src = wp_get_attachment_image_src( $thumbnail_id, array( $width, 0 ) ); - if ( $thumbnail_src ) { - list( $thumbnail_url, $thumbnail_width, $thumbnail_height ) = $thumbnail_src; - $data['thumbnail_url'] = $thumbnail_url; - $data['thumbnail_width'] = $thumbnail_width; - $data['thumbnail_height'] = $thumbnail_height; + if ( is_array( $thumbnail_src ) ) { + $data['thumbnail_url'] = (string) ( $thumbnail_src[0] ?? '' ); + $data['thumbnail_width'] = (int) ( $thumbnail_src[1] ?? 0 ); + $data['thumbnail_height'] = (int) ( $thumbnail_src[2] ?? 0 ); } } From 405164d39e956fc422182b6c3643bf0d2b327a7b Mon Sep 17 00:00:00 2001 From: hbhalodia Date: Wed, 11 Mar 2026 11:24:56 +0530 Subject: [PATCH 3/8] Add gaurd for falsy values --- src/wp-includes/media.php | 56 ++++++++++++++++++++++++++++++++------- 1 file changed, 46 insertions(+), 10 deletions(-) diff --git a/src/wp-includes/media.php b/src/wp-includes/media.php index 3464fbf6328c2..300073dc73771 100644 --- a/src/wp-includes/media.php +++ b/src/wp-includes/media.php @@ -987,8 +987,14 @@ function wp_get_attachment_image_src( $attachment_id, $size = 'thumbnail', $icon $icon_dir = apply_filters( 'icon_dir', ABSPATH . WPINC . '/images/media' ); $src_file = $icon_dir . '/' . wp_basename( $src ); + $width = 0; + $height = 0; - list( $width, $height ) = wp_getimagesize( $src_file ); + $image_size = wp_getimagesize( $src_file ); + if ( is_array( $image_size ) ) { + $width = $image_size[0]; + $height = $image_size[1]; + } $ext = strtolower( substr( $src_file, -4 ) ); @@ -997,7 +1003,11 @@ function wp_get_attachment_image_src( $attachment_id, $size = 'thumbnail', $icon $width = 48; $height = 64; } else { - list( $width, $height ) = wp_getimagesize( $src_file ); + $image_size = wp_getimagesize( $src_file ); + if ( is_array( $image_size ) ) { + $width = $image_size[0]; + $height = $image_size[1]; + } } } } @@ -3230,10 +3240,23 @@ function wp_playlist_shortcode( $attr ) { if ( $atts['images'] ) { $thumb_id = get_post_thumbnail_id( $attachment->ID ); if ( ! empty( $thumb_id ) ) { - list( $src, $width, $height ) = wp_get_attachment_image_src( $thumb_id, 'full' ); - $track['image'] = compact( 'src', 'width', 'height' ); - list( $src, $width, $height ) = wp_get_attachment_image_src( $thumb_id, 'thumbnail' ); - $track['thumb'] = compact( 'src', 'width', 'height' ); + $image_src_full = wp_get_attachment_image_src( $thumb_id, 'full' ); + if ( is_array( $image_src_full ) ) { + $track['image'] = array( + 'src' => (string) ( $image_src_full[0] ?? '' ), + 'width' => (int) ( $image_src_full[1] ?? 0 ), + 'height' => (int) ( $image_src_full[2] ?? 0 ), + ); + } + + $image_src_thumb = wp_get_attachment_image_src( $thumb_id, 'thumbnail' ); + if ( is_array( $image_src_thumb ) ) { + $track['thumb'] = array( + 'src' => (string) ( $image_src_thumb[0] ?? '' ), + 'width' => (int) ( $image_src_thumb[1] ?? 0 ), + 'height' => (int) ( $image_src_thumb[2] ?? 0 ), + ); + } } else { $src = wp_mime_type_icon( $attachment->ID, '.svg' ); $width = 48; @@ -4711,10 +4734,23 @@ function wp_prepare_attachment_for_js( $attachment ) { $id = get_post_thumbnail_id( $attachment->ID ); if ( ! empty( $id ) ) { - list( $src, $width, $height ) = wp_get_attachment_image_src( $id, 'full' ); - $response['image'] = compact( 'src', 'width', 'height' ); - list( $src, $width, $height ) = wp_get_attachment_image_src( $id, 'thumbnail' ); - $response['thumb'] = compact( 'src', 'width', 'height' ); + $response_image_full = wp_get_attachment_image_src( $id, 'full' ); + if ( is_array( $response_image_full ) ) { + $response['image'] = array( + 'src' => (string) ( $response_image_full[0] ?? '' ), + 'width' => (int) ( $response_image_full[1] ?? 0 ), + 'height' => (int) ( $response_image_full[2] ?? 0 ), + ); + } + + $response_image_thumb = wp_get_attachment_image_src( $id, 'thumbnail' ); + if ( is_array( $response_image_thumb ) ) { + $response['thumb'] = array( + 'src' => (string) ( $response_image_thumb[0] ?? '' ), + 'width' => (int) ( $response_image_thumb[1] ?? 0 ), + 'height' => (int) ( $response_image_thumb[2] ?? 0 ), + ); + } } else { $src = wp_mime_type_icon( $attachment->ID, '.svg' ); $width = 48; From 481836fdbe1fc96359a454c89c39cef88b30493f Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Wed, 25 Mar 2026 16:39:03 -0700 Subject: [PATCH 4/8] Add array shapes for return types for wp_get_attachment_image_src() and wp_getimagesize() --- src/wp-includes/media.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/wp-includes/media.php b/src/wp-includes/media.php index a6aac018e3c49..c34597588872a 100644 --- a/src/wp-includes/media.php +++ b/src/wp-includes/media.php @@ -972,6 +972,7 @@ function wp_get_registered_image_subsizes() { * @type int $2 Image height in pixels. * @type bool $3 Whether the image is a resized image. * } + * @phpstan-return array{ 0: string, 1: int, 2: int, 3: bool }|false */ function wp_get_attachment_image_src( $attachment_id, $size = 'thumbnail', $icon = false ) { // Get a thumbnail or intermediate image if there is one. @@ -5760,6 +5761,7 @@ function wp_show_heic_upload_error( $plupload_settings ) { * @param string $filename The file path. * @param array $image_info Optional. Extended image information (passed by reference). * @return array|false Array of image information or false on failure. + * @phpstan-return array{ 0: int, 1: int, 2: int, 3: string, mime: string }|false */ function wp_getimagesize( $filename, ?array &$image_info = null ) { // Don't silence errors when in debug mode, unless running unit tests. From 6378984ed8085f41541d7b42650ab4bbe92f0a69 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Wed, 25 Mar 2026 17:09:34 -0700 Subject: [PATCH 5/8] Account for additional keys returned by getimagesize() --- src/wp-includes/media.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wp-includes/media.php b/src/wp-includes/media.php index c34597588872a..ee541fad4222b 100644 --- a/src/wp-includes/media.php +++ b/src/wp-includes/media.php @@ -5761,7 +5761,7 @@ function wp_show_heic_upload_error( $plupload_settings ) { * @param string $filename The file path. * @param array $image_info Optional. Extended image information (passed by reference). * @return array|false Array of image information or false on failure. - * @phpstan-return array{ 0: int, 1: int, 2: int, 3: string, mime: string }|false + * @phpstan-return array{ 0: int, 1: int, 2: int, 3: string, mime: string, bits?: int, channels?: int }|false */ function wp_getimagesize( $filename, ?array &$image_info = null ) { // Don't silence errors when in debug mode, unless running unit tests. From 1a343b07d5cd746f9a077e68898d6dd5e69446de Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Wed, 25 Mar 2026 17:22:43 -0700 Subject: [PATCH 6/8] Fix location for declaring vars --- src/wp-includes/media.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/wp-includes/media.php b/src/wp-includes/media.php index ee541fad4222b..412a573162387 100644 --- a/src/wp-includes/media.php +++ b/src/wp-includes/media.php @@ -978,7 +978,9 @@ function wp_get_attachment_image_src( $attachment_id, $size = 'thumbnail', $icon // Get a thumbnail or intermediate image if there is one. $image = image_downsize( $attachment_id, $size ); if ( ! $image ) { - $src = false; + $src = false; + $width = 0; + $height = 0; if ( $icon ) { $src = wp_mime_type_icon( $attachment_id, '.svg' ); @@ -988,8 +990,6 @@ function wp_get_attachment_image_src( $attachment_id, $size = 'thumbnail', $icon $icon_dir = apply_filters( 'icon_dir', ABSPATH . WPINC . '/images/media' ); $src_file = $icon_dir . '/' . wp_basename( $src ); - $width = 0; - $height = 0; $image_size = wp_getimagesize( $src_file ); if ( is_array( $image_size ) ) { From de7d55fa3ecd7095e0d6f0374ddc4042985dcb05 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Wed, 25 Mar 2026 17:24:54 -0700 Subject: [PATCH 7/8] Refactor to guarantee wp_get_attachment_image_src() always returns expected type --- src/wp-includes/media.php | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/src/wp-includes/media.php b/src/wp-includes/media.php index 412a573162387..5277ec351bc49 100644 --- a/src/wp-includes/media.php +++ b/src/wp-includes/media.php @@ -1035,7 +1035,16 @@ function wp_get_attachment_image_src( $attachment_id, $size = 'thumbnail', $icon * an array of width and height values in pixels (in that order). * @param bool $icon Whether the image should be treated as an icon. */ - return apply_filters( 'wp_get_attachment_image_src', $image, $attachment_id, $size, $icon ); + $source = apply_filters( 'wp_get_attachment_image_src', $image, $attachment_id, $size, $icon ); + if ( is_array( $source ) && isset( $source[0] ) && is_string( $source[0] ) ) { + return array( + $source[0], + (int) ( $source[1] ?? 0 ), + (int) ( $source[2] ?? 0 ), + (bool) ( $source[3] ?? false ), + ); + } + return false; } /** @@ -3244,18 +3253,18 @@ function wp_playlist_shortcode( $attr ) { $image_src_full = wp_get_attachment_image_src( $thumb_id, 'full' ); if ( is_array( $image_src_full ) ) { $track['image'] = array( - 'src' => (string) ( $image_src_full[0] ?? '' ), - 'width' => (int) ( $image_src_full[1] ?? 0 ), - 'height' => (int) ( $image_src_full[2] ?? 0 ), + 'src' => $image_src_full[0], + 'width' => $image_src_full[1], + 'height' => $image_src_full[2], ); } $image_src_thumb = wp_get_attachment_image_src( $thumb_id, 'thumbnail' ); if ( is_array( $image_src_thumb ) ) { $track['thumb'] = array( - 'src' => (string) ( $image_src_thumb[0] ?? '' ), - 'width' => (int) ( $image_src_thumb[1] ?? 0 ), - 'height' => (int) ( $image_src_thumb[2] ?? 0 ), + 'src' => $image_src_thumb[0], + 'width' => $image_src_thumb[1], + 'height' => $image_src_thumb[2], ); } } else { @@ -4738,18 +4747,18 @@ function wp_prepare_attachment_for_js( $attachment ) { $response_image_full = wp_get_attachment_image_src( $id, 'full' ); if ( is_array( $response_image_full ) ) { $response['image'] = array( - 'src' => (string) ( $response_image_full[0] ?? '' ), - 'width' => (int) ( $response_image_full[1] ?? 0 ), - 'height' => (int) ( $response_image_full[2] ?? 0 ), + 'src' => $response_image_full[0], + 'width' => $response_image_full[1], + 'height' => $response_image_full[2], ); } $response_image_thumb = wp_get_attachment_image_src( $id, 'thumbnail' ); if ( is_array( $response_image_thumb ) ) { $response['thumb'] = array( - 'src' => (string) ( $response_image_thumb[0] ?? '' ), - 'width' => (int) ( $response_image_thumb[1] ?? 0 ), - 'height' => (int) ( $response_image_thumb[2] ?? 0 ), + 'src' => $response_image_thumb[0], + 'width' => $response_image_thumb[1], + 'height' => $response_image_thumb[2], ); } } else { From 5e92a9a50adddf8b5262b4914e48a762b4aac1ea Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Wed, 25 Mar 2026 17:26:37 -0700 Subject: [PATCH 8/8] Remove now-redundant type coersion --- src/wp-includes/embed.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/wp-includes/embed.php b/src/wp-includes/embed.php index 233efcfb3176f..3fb8968c7c62c 100644 --- a/src/wp-includes/embed.php +++ b/src/wp-includes/embed.php @@ -742,9 +742,9 @@ function get_oembed_response_data_rich( $data, $post, $width, $height ) { $thumbnail_src = wp_get_attachment_image_src( $thumbnail_id, array( $width, 0 ) ); if ( is_array( $thumbnail_src ) ) { - $data['thumbnail_url'] = (string) ( $thumbnail_src[0] ?? '' ); - $data['thumbnail_width'] = (int) ( $thumbnail_src[1] ?? 0 ); - $data['thumbnail_height'] = (int) ( $thumbnail_src[2] ?? 0 ); + $data['thumbnail_url'] = $thumbnail_src[0]; + $data['thumbnail_width'] = $thumbnail_src[1]; + $data['thumbnail_height'] = $thumbnail_src[2]; } }