#49943 closed defect (bug) (fixed)
Async Site Health tests can throw PHP notices
| Reported by: | schlessera | Owned by: | SergeyBiryukov |
|---|---|---|---|
| Priority: | normal | Milestone: | 5.4.2 |
| Component: | Site Health | Version: | 5.4 |
| Severity: | normal | Keywords: | has-patch good-first-bug fixed-major |
| Cc: | Focuses: |
Description
In the logic for checking asynchronous tests in the wp_cron_scheduled_check() method of the WP_Site_Health class, the following code is used to fetch the test result:
<?php if ( ! is_wp_error( $result_fetch ) ) { $results[] = json_decode( wp_remote_retrieve_body( $result_fetch ) ); } else { $results[] = array( 'status' => 'recommended', 'label' => __( 'A test is unavailable' ), ); }
If that request "succeeds" (meaning it didn't produce a WP_Error), but the response is not what was expected (like returning a page of HTML), the code immediately following will throw a PHP notice because it json_decode() will fail to decode the response's body and thus return null:
<?php foreach ( $results as $result ) { if ( 'critical' === $result['status'] ) { $site_status['critical']++; } elseif ( 'recommended' === $result['status'] ) { $site_status['recommended']++; } else { $site_status['good']++; } }
The notice that is thrown is:
Notice: Trying to access array offset on value of type null in wp-admin/includes/class-wp-site-health.php on line 2303
Attachments (1)
Change History (9)
Note:
See TracTickets
for help on using tickets.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
In 47628: