[wp-trac] [WordPress Trac] #45676: wp_get_attachment_img_srcset() ignores $size, and returns all $image_meta.

WordPress Trac noreply at wordpress.org
Tue Dec 18 16:11:44 UTC 2018


#45676: wp_get_attachment_img_srcset() ignores $size, and returns all $image_meta.
--------------------------+------------------------------
 Reporter:  justlevine    |       Owner:  (none)
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  Media         |     Version:  5.0.1
 Severity:  normal        |  Resolution:
 Keywords:                |     Focuses:
--------------------------+------------------------------

Comment (by justlevine):

 Replying to [comment:2 subrataemfluence]:
 > Could this be ''that are **larger** than `$max_srcset_image_width`'', if
 I understand correctly?
 No. It currently takes all the registered images sizes that are less than
 `$max_srcset_image_width`. At default, it's all the image sizes less than
 1600px. It ''should'' return all the image sizes smaller than the
 registered image name your passing OR the max srcset width.

 E.g passing 'full' should return all sizes < `$max_srcset_image_width`,
 but passing `medium` should return all sizes smaller than `medium`.
 Currently, both return the same list of all sizes.



 > you are running a `foreach` loop inside a `! is_array( $image_meta )`
 check, i.e. trying to iterate an element which is clearly **not an
 array**. This will throw an error, since `foreach` cannot be applied here.

 Good point. Another reason why im not qualified to submit a PR :p.

 The intended logic is to test if `$image_meta` is being passed manually,
 and only if it is coming from `wp_get_attachment_metadata()` to filter the
 sizes.

 Logically, if someone is passing an `image_size`, you'd assume that any
 array of sizes they're passing manually would be smaller than the declared
 size, but since the current functionality is to ignore `image_size`,
 filtering the manually defined array could break back-compat.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/45676#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list