[wp-trac] [WordPress Trac] #51390: Trying to access array offset on value of type bool in /var/www/realestate.columbian.com/htdocs/wp-admin/includes/meta-boxes.php on line 482
WordPress Trac
noreply at wordpress.org
Thu Sep 24 21:39:31 UTC 2020
#51390: Trying to access array offset on value of type bool in
/var/www/realestate.columbian.com/htdocs/wp-admin/includes/meta-boxes.php
on line 482
--------------------------+-----------------------------
Reporter: sproutchris | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: General | Version: 5.5.1
Severity: normal | Keywords:
Focuses: |
--------------------------+-----------------------------
I got an error in my debug log (running PHP 7.4):
{{{
Trying to access array offset on value of type bool in .../wp-
admin/includes/meta-boxes.php on line 482
}}}
The code in question is:
{{{
...
$post_formats = get_theme_support( 'post-formats' );
if ( is_array( $post_formats[0] ) ) :
...
}}}
`$post_formats` equals `false` in my scenario. I haven't added support
for "post-formats" in my theme (because I don't want it in my theme) so is
this is expected behavior or is this maybe in itself what's going wrong
here?
When WordPress then next asks PHP if `$post_formats[0]` is an array
(`is_array( $post_formats[0] )`) when `$post_formats` is a boolean
(therefore having no array items/indices), obviously PHP is going to throw
this error. If `get_theme_support()` returning a boolean instead of an
array is expected behavior, then I guess the easy fix would be:
{{{
if ( isset( $post_formats[0] ) && is_array( $post_formats[0] ) ) :
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/51390>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list