Make WordPress Core

Opened 3 years ago

Closed 21 months ago

#46113 closed defect (bug) (fixed)

Incongruent returned value for wp_get_attachment_image_src

Reported by: wido Owned by: johnbillion
Milestone: 5.5 Priority: normal
Severity: normal Version: 2.5
Component: Media Keywords: has-patch
Focuses: docs Cc:


As per docblock the function wp_get_attachment_image_src will return false|array Returns an array (url, width, height, is_intermediate), or false, if no image is available.

Function wp_get_attachment_image_src return an indexed array containing source, width and height, but not the intermediated value in case the internal call to image_downsize return false.

It's this latter that will return the array containing all of the elements, therefore if it's false wp_get_attachment_image_src will try to create them but will miss is_intermediated value.

Attachments (1)

46113.diff (1.2 KB) - added by johnbillion 22 months ago.

Download all attachments as: .zip

Change History (8)

#1 @desrosj
3 years ago

  • Focuses docs added

#2 @joemcgill
3 years ago

  • Milestone changed from Awaiting Review to Future Release

Good catch, @wido. The docs should be updated here to note that the fourth value in the array, i.e. is_intermediate is optional.

#3 @wido
2 years ago

@joemcgill What adding a default value for it instead? This will make the function more predictable.
False would be a good choice, it's the same default in image_downsize

#4 @joemcgill
2 years ago

@wido I think that would work too.

#5 @johnbillion
23 months ago

  • Milestone changed from Future Release to 5.5
  • Owner set to johnbillion
  • Status changed from new to accepted

I noticed this too when cleaning up the docs for this function. When the fallback icon is used, false should be added as the fourth element in the returned array. The function docs also need updating to reflect this parameter, as the change I made in [47394] is technically not correct due to the inconsistent return value.

22 months ago

#6 @johnbillion
22 months ago

  • Keywords has-patch added; needs-patch removed

#7 @johnbillion
21 months ago

  • Resolution set to fixed
  • Status changed from accepted to closed

In 47748:

Media: Ensure a consistent structure for the array returned by wp_get_attachment_image_src().

The array returned by this function previously included a fourth element only when an intermediate image size was used. This change ensures a consistent structure in the returned array regardless of the function's internal behaviour.

Props wido, joemcgill, johnbillion

Fixes #46113

Note: See TracTickets for help on using tickets.