[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 15:40:50 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 subrataemfluence):

 Could this be ''that are **larger** than `$max_srcset_image_width`'', if I
 understand correctly?

 Replying to [ticket:45676 justlevine]:
 > Currently, it returns an `srcset` of ''all the `$sizes` registered to
 the attachment'' (that are less than `$max_srcset_image_width`).
 >

 Also

 {{{#!php
 <?php
 if ( ! is_array( $image_meta ) ) {
   foreach ( $image_meta['sizes'] as $size_name->$meta) {
     ...
   }
 }
 }}}

 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.

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


More information about the wp-trac mailing list