[wp-trac] [WordPress Trac] #50858: Site Health Check PHP notices with site_status_tests filter
WordPress Trac
noreply at wordpress.org
Fri Aug 7 00:56:58 UTC 2020
#50858: Site Health Check PHP notices with site_status_tests filter
----------------------------------------+---------------------
Reporter: Ov3rfly | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: 5.5.1
Component: Site Health | Version: 5.2
Severity: normal | Resolution:
Keywords: needs-patch good-first-bug | Focuses:
----------------------------------------+---------------------
Comment (by khag7):
I think it's reasonable to say that `$tests['direct']` and
`$tests['async']` must exist, even if they are empty arrays. If someone
unsets them completely using the filter, they should be immediately
recreated as empty arrays to prevent errors elsewhere. If I'm right about
that, those should not be able to be completely removed by the
`site_status_tests` filter.
What if we took the value returned from the filter and merged it into an
empty array containing two keys, `direct` and `async` which each have a
value of an empty array?
{{{
$tests = array_merge( array(
'direct' => array(),
'async' => array(),
), apply_filters( 'site_status_tests', $tests ) );
}}}
This means that even if the `direct` and `async` keys get completely
unset, we will put them back immediately, but as empty arrays. Methods
that make use of `get_tests` use a foreach loop on `tests['direct']` or
`tests['async']` and if the value of is simply an empty array, the foreach
loop doesn't run, and no error is thrown.
Option B is as previously suggested would be to do this every time
`get_tests` is called:
{{{
if ( is_array( $tests ) && isset( $tests['direct'] ) && is_array(
$tests['direct'] ) ) { ...
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/50858#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list