[wp-trac] [WordPress Trac] #32117: wp_get_attachment_metadata sizes array file misses path if using year/month organizing

WordPress Trac noreply at wordpress.org
Fri Apr 24 15:58:52 UTC 2015


#32117: wp_get_attachment_metadata sizes array file misses path if using year/month
organizing
--------------------------+-----------------------------
 Reporter:  thomask       |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Media         |    Version:  4.2
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 wp_get_attachment_metadata returns array like this:

 {{{
 ["metadata"]=>
   array(5) {
     ["width"]=>
     int(3072)
     ["height"]=>
     int(2304)
     ["file"]=>
     string(25) "2015/03/GC702D01_high.jpg"
     ["sizes"]=>
     array(4) {
       ["thumbnail"]=>
       array(4) {
         ["file"]=>
         string(25) "GC702D01_high-200x150.jpg"
         ["width"]=>
         int(200)
         ["height"]=>
         int(150)
         ["mime-type"]=>
         string(10) "image/jpeg"
       }
 }}}
 as you can see, "file" in the first level of the array contains year and
 month (as i do have turned on organizing in year/month structure for
 uploads), but "file" in the second level for (e.g. in this case) the
 thumbnail size is only the file name, without the path.

 This is at least confusing, make it difficult to get the URL of the file -
 each size need to be then requested separately by
 wp_get_attachment_image_src function.

 IMO optimal solution would be to use full path in both $metadata['file']
 and $metadata['sizes'][$size]['file'] so the same name would have the same
 structure. But i do not know if it wouldn't have some compatibility
 issues.

 Less optimal imo would be to add there also the path - it can be there
 only once in the top level, as all sizes are currently always in the same
 folder, but i think this could lock us from possible changes / plugin
 modifications etc. E.g. I think that it would be great, if it would be
 possible (and even default) to have size name, as a folder, so that we
 would have thumbnails in uploads/thumbnail, medium size in uploads/medium
 ... - this would highly reduce the number of images in one folder in
 default settings and would reduce the problems with displaying them on
 most systems. And also if we would want to delete some defined size, we
 could simply delete one folder and save space.

 So the second optimal would be to show the path in sizes[$size] subarray,
 e.g.

 {{{
 ["metadata"]=>
   array(5) {
     ["sizes"]=>
     array(4) {
       ["thumbnail"]=>
       array(4) {
         ["file"]=>
         string(25) "GC702D01_high-200x150.jpg"
         ["path"]=>
         string(25) "2015/03/"
       }
 }}}

--
Ticket URL: <https://core.trac.wordpress.org/ticket/32117>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list