Opened 5 years ago
Closed 5 years ago
#54701 closed defect (bug) (duplicate)
Twenty Twenty-One: twenty_twenty_one_get_attachment_image_attributes() missing wp_get_attachment_metadata() check
| Reported by: | justlevine | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | Bundled Theme | Version: | 5.8.2 |
| Severity: | normal | Keywords: | |
| Cc: | Focuses: |
Description
Im getting a PHP notice from inc\template-functions.php::twenty_twenty_one_get_attachment_image_attributes() about accessing an array value on a boolean.
Issue stems from:
<?php $meta = wp_get_attachment_metadata( $attachment->ID ); if ( $meta['width'] && $meta['height'] ) { $width = (int) $meta['width']; $height = (int) $meta['height']; }
since wp_get_attachment_meta() can return false when no attachment id exists.
Trac stresses me out, but here's the fix:
<?php $meta = wp_get_attachment_metadata( $attachment->ID ); if( false === $meta ) { return $attr; } if ( $meta['width'] && $meta['height'] ) { $width = (int) $meta['width']; $height = (int) $meta['height']; }
Change History (1)
#1
@
5 years ago
- Milestone Awaiting Review
- Resolution → duplicate
- Status new → closed
- Summary TwentyTwentyOne: twenty_twenty_one_get_attachment_image_attributes() missing wp_get_attachment_metadata() check → Twenty Twenty-One: twenty_twenty_one_get_attachment_image_attributes() missing wp_get_attachment_metadata() check
Note:
See TracTickets
for help on using tickets.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
Hi there, welcome back to WordPress Trac!
Thanks for the report, this is already fixed for WordPress 5.9 in [52217] / #54464.