[wp-trac] [WordPress Trac] #54464: Twenty Twenty-One get_attachment_image_attributes_image_attributes not checking if variable isset properly

WordPress Trac noreply at wordpress.org
Thu Nov 18 00:16:31 UTC 2021


#54464: Twenty Twenty-One get_attachment_image_attributes_image_attributes not
checking if variable isset properly
---------------------------+-----------------------------
 Reporter:  wetah          |      Owner:  (none)
     Type:  defect (bug)   |     Status:  new
 Priority:  normal         |  Milestone:  Awaiting Review
Component:  Bundled Theme  |    Version:
 Severity:  normal         |   Keywords:
  Focuses:  template       |
---------------------------+-----------------------------
 The `twenty_twenty_one_get_attachment_image_attributes` function, added to
 the filter `wp_get_attachment_image_attributes` in `inc/template-
 functions.php` incorrectly checks the existence of some variables in this
 piece of code:

 {{{#!php
 <?php
 $meta = wp_get_attachment_metadata( $attachment->ID );
 if ( $meta['width'] && $meta['height'] ) {
     $width  = (int) $meta['width'];
     $height = (int) $meta['height'];
 }
 }}}

 This causes an `Undefined index: width on line 460` error if the result
 from the function does not set any value to `$meta`. I believe something
 like this should be enough:

 {{{#!php
 <?php
 $meta = wp_get_attachment_metadata( $attachment->ID );
 if ( isset($meta['width']) && isset($meta['height']) ) {
     $width  = (int) $meta['width'];
     $height = (int) $meta['height'];
 }
 }}}

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


More information about the wp-trac mailing list