Make WordPress Core


Ignore:
Timestamp:
10/15/2020 01:58:28 AM (4 years ago)
Author:
TimothyBlynJacobs
Message:

Site Health, REST API: Move async tests to REST API endpoints.

This provides more flexibility when writing tests and benefits from running in a front-end context which is necessary for some tests like checking that updates are supported. Additionally, this provides a more robust interface for developers who want to integrate with Site Health tests.

Because the wp/v2 endpoint is reserved for modeling core entities, site health is registered in its own wp-site-health/v1 namespace.

The existing ajax actions have been maintained for backward compatibility.

Props Clorith, chrisvanpatten, afragen, pokhriyal, TimothyBlynJacobs.
Fixes #48105.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-wp-site-health-auto-updates.php

    r48792 r49154  
    9191     */
    9292    public function test_wp_version_check_attached() {
    93         if ( ! is_main_site() ) {
    94             return;
    95         }
    96 
    97         $cookies = wp_unslash( $_COOKIE );
    98         $timeout = 10;
    99         $headers = array(
    100             'Cache-Control' => 'no-cache',
    101         );
    102         /** This filter is documented in wp-includes/class-wp-http-streams.php */
    103         $sslverify = apply_filters( 'https_local_ssl_verify', false );
    104 
    105         // Include Basic auth in loopback requests.
    106         if ( isset( $_SERVER['PHP_AUTH_USER'] ) && isset( $_SERVER['PHP_AUTH_PW'] ) ) {
    107             $headers['Authorization'] = 'Basic ' . base64_encode( wp_unslash( $_SERVER['PHP_AUTH_USER'] ) . ':' . wp_unslash( $_SERVER['PHP_AUTH_PW'] ) );
    108         }
    109 
    110         $url = add_query_arg(
    111             array(
    112                 'health-check-test-wp_version_check' => true,
    113             ),
    114             admin_url( 'site-health.php' )
    115         );
    116 
    117         $test = wp_remote_get( $url, compact( 'cookies', 'headers', 'timeout', 'sslverify' ) );
    118 
    119         if ( is_wp_error( $test ) ) {
    120             return array(
    121                 'description' => sprintf(
    122                     /* translators: %s: Name of the filter used. */
    123                     __( 'Could not confirm that the %s filter is available.' ),
    124                     '<code>wp_version_check()</code>'
    125                 ),
    126                 'severity'    => 'warning',
    127             );
    128         }
    129 
    130         $response = wp_remote_retrieve_body( $test );
    131 
    132         if ( 'yes' !== $response ) {
     93        if ( ! has_filter( 'wp_version_check', 'wp_version_check' ) ) {
    13394            return array(
    13495                'description' => sprintf(
     
    311272     */
    312273    function test_check_wp_filesystem_method() {
     274        // Make sure the `request_filesystem_credentials` function is available during our REST call.
     275        if ( ! function_exists( 'request_filesystem_credentials' ) ) {
     276            require_once ABSPATH . '/wp-admin/includes/file.php';
     277        }
     278
    313279        $skin    = new Automatic_Upgrader_Skin;
    314280        $success = $skin->request_filesystem_credentials( false, ABSPATH );
     
    355321        if ( 'direct' !== $wp_filesystem->method ) {
    356322            return false;
     323        }
     324
     325        // Make sure the `get_core_checksums` function is available during our REST call.
     326        if ( ! function_exists( 'get_core_checksums' ) ) {
     327            require_once ABSPATH . '/wp-admin/includes/update.php';
    357328        }
    358329
Note: See TracChangeset for help on using the changeset viewer.