[wp-trac] [WordPress Trac] #35237: Invalid argument supplied for foreach() in /wp-includes/embed-template.php on line 54

WordPress Trac noreply at wordpress.org
Sun Dec 27 22:51:51 UTC 2015


#35237: Invalid argument supplied for foreach() in /wp-includes/embed-template.php
on line 54
--------------------------+-----------------------------
 Reporter:  MarkRH        |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Embeds        |    Version:  4.4
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 I believe I uncovered a bug. Support thread:
 https://wordpress.org/support/topic/invalid-argument-foreach-embed-
 templatephp-on-line-54?replies=7

 In my media settings I have thumbnails set to 200x200, medium 300x300,
 large 1024x1024.

 Some of my older posts have featured images that are smaller than 200x200.
 As such, these additional sizes were not created. When looking at the
 /embed/ variant of said post, this warning is generated in the PHP
 error_log file:


 {{{
 Invalid argument supplied for foreach() in /wp-includes/embed-template.php
 on line 54
 }}}

 I added the following code to echo the $meta variable:
 {{{#!php
 <?php
 $meta = wp_get_attachment_metadata( $thumbnail_id );
          if ($_SERVER['REMOTE_ADDR'] == HOME_IP) {
             print_r($meta);
          }
          if ( is_array( $meta ) ) {
             foreach ( $meta['sizes'] as $size => $data ) {
                if ( $data['width'] / $data['height'] > $aspect_ratio ) {
                   $aspect_ratio = $data['width'] / $data['height'];
                   $measurements = array( $data['width'], $data['height']
 );
                   $image_size   = $size;
                }
             }
          }
 }}}

 Here's what a post with the issue outputs:

 {{{

 Array
 (
     [width] => 105
     [height] => 107
     [hwstring_small] => height='96' width='94'
     [file] => 2011/03/stpatricks_clover.jpg
     [image_meta] => Array
         (
             [aperture] => 0
             [credit] =>
             [camera] =>
             [caption] =>
             [created_timestamp] => 0
             [copyright] =>
             [focal_length] => 0
             [iso] => 0
             [shutter_speed] => 0
             [title] =>
         )

 )
 }}}

 As you can see, there is no [sizes] section which causes the warning on
 the foreach line that uses it.  Posts which have no images associated with
 them or image larger than 200x200 do not have the issue.

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


More information about the wp-trac mailing list