#49943 closed defect (bug) (fixed)
Async Site Health tests can throw PHP notices
Reported by: | schlessera | Owned by: | SergeyBiryukov |
---|---|---|---|
Milestone: | 5.4.2 | Priority: | normal |
Severity: | normal | Version: | 5.4 |
Component: | Site Health | Keywords: | has-patch good-first-bug fixed-major |
Focuses: | Cc: |
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)
#1
@
5 years ago
- Keywords needs-patch good-first-bug added
- Milestone changed from Awaiting Review to 5.5
#2
@
5 years ago
- Owner set to SergeyBiryukov
- Resolution set to fixed
- Status changed from new to closed
Note: See
TracTickets for help on using
tickets.
In 47628: