#54464 closed defect (bug) (fixed)
Twenty Twenty-One get_attachment_image_attributes_image_attributes not checking if variable isset properly
| Reported by: | wetah | Owned by: | audrasjb |
|---|---|---|---|
| Priority: | normal | Milestone: | 5.9 |
| Component: | Bundled Theme | Version: | |
| Severity: | normal | Keywords: | good-first-bug has-patch commit |
| Cc: | Focuses: | template |
Description
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 $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 $meta = wp_get_attachment_metadata( $attachment->ID ); if ( isset($meta['width']) && isset($meta['height']) ) { $width = (int) $meta['width']; $height = (int) $meta['height']; }
Attachments (1)
Change History (8)
Note:
See TracTickets
for help on using tickets.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
Patch created for width & height validation