[wp-trac] [WordPress Trac] #50858: Site Health Check PHP notices with site_status_tests filter
WordPress Trac
noreply at wordpress.org
Wed Aug 5 11:30: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: Awaiting Review
Component: Site Health | Version: 5.4.2
Severity: normal | Keywords:
Focuses: |
--------------------------+-----------------------------
Some methods get the the tests array from `WP_Site_Health::get_tests()`
where a filter to "modify which site status tests are run on a site" is
available.
{{{
$tests = apply_filters( 'site_status_tests', $tests );
}}}
Found an attempt to reduce any unexpected load on a high profile
production site like this, which is
[https://codex.wordpress.org/Function_Reference/_return_empty_array a
valid return value] for a filter for arrays:
{{{
add_filter( 'site_status_tests', '__return_empty_array', 999999 );
}}}
With this filter in place some PHP notices are triggered e.g. when methods
`wp_cron_scheduled_check()` is called:
{{{
[05-Aug-2020 10:56:04 UTC] PHP Notice: Undefined index: direct in .../wp-
admin/includes/class-wp-site-health.php on line 109
[05-Aug-2020 10:56:04 UTC] PHP Warning: Invalid argument supplied for
foreach() in .../wp-admin/includes/class-wp-site-health.php on line 109
[05-Aug-2020 10:56:04 UTC] PHP Notice: Undefined index: async in .../wp-
admin/includes/class-wp-site-health.php on line 127
[05-Aug-2020 10:56:04 UTC] PHP Warning: Invalid argument supplied for
foreach() in .../wp-admin/includes/class-wp-site-health.php on line 127
}}}
Similar PHP notices are also triggered if method `enqueue_scripts()` is
called.
Suggested fix: Check if return value of filter is valid before using it,
similar to this:
{{{
if ( is_array( $tests ) && isset( $tests['direct'] ) && is_array(
$tests['direct'] ) ) { ...
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/50858>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list