@@ -972,12 +972,15 @@ function wp_get_registered_image_subsizes() {
972972 * @type int $2 Image height in pixels.
973973 * @type bool $3 Whether the image is a resized image.
974974 * }
975+ * @phpstan-return array{ 0: string, 1: int, 2: int, 3: bool }|false
975976 */
976977function wp_get_attachment_image_src ( $ attachment_id , $ size = 'thumbnail ' , $ icon = false ) {
977978 // Get a thumbnail or intermediate image if there is one.
978979 $ image = image_downsize ( $ attachment_id , $ size );
979980 if ( ! $ image ) {
980- $ src = false ;
981+ $ src = false ;
982+ $ width = 0 ;
983+ $ height = 0 ;
981984
982985 if ( $ icon ) {
983986 $ src = wp_mime_type_icon ( $ attachment_id , '.svg ' );
@@ -988,7 +991,11 @@ function wp_get_attachment_image_src( $attachment_id, $size = 'thumbnail', $icon
988991
989992 $ src_file = $ icon_dir . '/ ' . wp_basename ( $ src );
990993
991- list ( $ width , $ height ) = wp_getimagesize ( $ src_file );
994+ $ image_size = wp_getimagesize ( $ src_file );
995+ if ( is_array ( $ image_size ) ) {
996+ $ width = $ image_size [0 ];
997+ $ height = $ image_size [1 ];
998+ }
992999
9931000 $ ext = strtolower ( substr ( $ src_file , -4 ) );
9941001
@@ -997,7 +1004,11 @@ function wp_get_attachment_image_src( $attachment_id, $size = 'thumbnail', $icon
9971004 $ width = 48 ;
9981005 $ height = 64 ;
9991006 } else {
1000- list ( $ width , $ height ) = wp_getimagesize ( $ src_file );
1007+ $ image_size = wp_getimagesize ( $ src_file );
1008+ if ( is_array ( $ image_size ) ) {
1009+ $ width = $ image_size [0 ];
1010+ $ height = $ image_size [1 ];
1011+ }
10011012 }
10021013 }
10031014 }
@@ -1024,7 +1035,16 @@ function wp_get_attachment_image_src( $attachment_id, $size = 'thumbnail', $icon
10241035 * an array of width and height values in pixels (in that order).
10251036 * @param bool $icon Whether the image should be treated as an icon.
10261037 */
1027- return apply_filters ( 'wp_get_attachment_image_src ' , $ image , $ attachment_id , $ size , $ icon );
1038+ $ source = apply_filters ( 'wp_get_attachment_image_src ' , $ image , $ attachment_id , $ size , $ icon );
1039+ if ( is_array ( $ source ) && isset ( $ source [0 ] ) && is_string ( $ source [0 ] ) ) {
1040+ return array (
1041+ $ source [0 ],
1042+ (int ) ( $ source [1 ] ?? 0 ),
1043+ (int ) ( $ source [2 ] ?? 0 ),
1044+ (bool ) ( $ source [3 ] ?? false ),
1045+ );
1046+ }
1047+ return false ;
10281048}
10291049
10301050/**
@@ -3230,10 +3250,23 @@ function wp_playlist_shortcode( $attr ) {
32303250 if ( $ atts ['images ' ] ) {
32313251 $ thumb_id = get_post_thumbnail_id ( $ attachment ->ID );
32323252 if ( ! empty ( $ thumb_id ) ) {
3233- list ( $ src , $ width , $ height ) = wp_get_attachment_image_src ( $ thumb_id , 'full ' );
3234- $ track ['image ' ] = compact ( 'src ' , 'width ' , 'height ' );
3235- list ( $ src , $ width , $ height ) = wp_get_attachment_image_src ( $ thumb_id , 'thumbnail ' );
3236- $ track ['thumb ' ] = compact ( 'src ' , 'width ' , 'height ' );
3253+ $ image_src_full = wp_get_attachment_image_src ( $ thumb_id , 'full ' );
3254+ if ( is_array ( $ image_src_full ) ) {
3255+ $ track ['image ' ] = array (
3256+ 'src ' => $ image_src_full [0 ],
3257+ 'width ' => $ image_src_full [1 ],
3258+ 'height ' => $ image_src_full [2 ],
3259+ );
3260+ }
3261+
3262+ $ image_src_thumb = wp_get_attachment_image_src ( $ thumb_id , 'thumbnail ' );
3263+ if ( is_array ( $ image_src_thumb ) ) {
3264+ $ track ['thumb ' ] = array (
3265+ 'src ' => $ image_src_thumb [0 ],
3266+ 'width ' => $ image_src_thumb [1 ],
3267+ 'height ' => $ image_src_thumb [2 ],
3268+ );
3269+ }
32373270 } else {
32383271 $ src = wp_mime_type_icon ( $ attachment ->ID , '.svg ' );
32393272 $ width = 48 ;
@@ -4711,10 +4744,23 @@ function wp_prepare_attachment_for_js( $attachment ) {
47114744
47124745 $ id = get_post_thumbnail_id ( $ attachment ->ID );
47134746 if ( ! empty ( $ id ) ) {
4714- list ( $ src , $ width , $ height ) = wp_get_attachment_image_src ( $ id , 'full ' );
4715- $ response ['image ' ] = compact ( 'src ' , 'width ' , 'height ' );
4716- list ( $ src , $ width , $ height ) = wp_get_attachment_image_src ( $ id , 'thumbnail ' );
4717- $ response ['thumb ' ] = compact ( 'src ' , 'width ' , 'height ' );
4747+ $ response_image_full = wp_get_attachment_image_src ( $ id , 'full ' );
4748+ if ( is_array ( $ response_image_full ) ) {
4749+ $ response ['image ' ] = array (
4750+ 'src ' => $ response_image_full [0 ],
4751+ 'width ' => $ response_image_full [1 ],
4752+ 'height ' => $ response_image_full [2 ],
4753+ );
4754+ }
4755+
4756+ $ response_image_thumb = wp_get_attachment_image_src ( $ id , 'thumbnail ' );
4757+ if ( is_array ( $ response_image_thumb ) ) {
4758+ $ response ['thumb ' ] = array (
4759+ 'src ' => $ response_image_thumb [0 ],
4760+ 'width ' => $ response_image_thumb [1 ],
4761+ 'height ' => $ response_image_thumb [2 ],
4762+ );
4763+ }
47184764 } else {
47194765 $ src = wp_mime_type_icon ( $ attachment ->ID , '.svg ' );
47204766 $ width = 48 ;
@@ -5724,6 +5770,7 @@ function wp_show_heic_upload_error( $plupload_settings ) {
57245770 * @param string $filename The file path.
57255771 * @param array $image_info Optional. Extended image information (passed by reference).
57265772 * @return array|false Array of image information or false on failure.
5773+ * @phpstan-return array{ 0: int, 1: int, 2: int, 3: string, mime: string, bits?: int, channels?: int }|false
57275774 */
57285775function wp_getimagesize ( $ filename , ?array &$ image_info = null ) {
57295776 // Don't silence errors when in debug mode, unless running unit tests.
0 commit comments