WordPress.org

Make WordPress Core


Ignore:
Timestamp:
10/15/2020 01:58:28 AM (13 months 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.php

    r48808 r49154  
    134134                    $health_check_js_variables['site_status']['async'][] = array(
    135135                        'test'      => $test['test'],
     136                        'has_rest'  => ( isset( $test['has_rest'] ) ? $test['has_rest'] : false ),
    136137                        'completed' => false,
    137138                    );
     
    20812082     *
    20822083     * @since 5.2.0
     2084     * @since 5.6.0 Added support for `has_rest` and `permissions`.
    20832085     *
    20842086     * @return array The list of tests to run.
     
    21542156            'async'  => array(
    21552157                'dotorg_communication' => array(
    2156                     'label' => __( 'Communication with WordPress.org' ),
    2157                     'test'  => 'dotorg_communication',
     2158                    'label'    => __( 'Communication with WordPress.org' ),
     2159                    'test'     => rest_url( 'wp-site-health/v1/tests/dotorg-communication' ),
     2160                    'has_rest' => true,
    21582161                ),
    21592162                'background_updates'   => array(
    2160                     'label' => __( 'Background updates' ),
    2161                     'test'  => 'background_updates',
     2163                    'label'    => __( 'Background updates' ),
     2164                    'test'     => rest_url( 'wp-site-health/v1/tests/background-updates' ),
     2165                    'has_rest' => true,
    21622166                ),
    21632167                'loopback_requests'    => array(
    2164                     'label' => __( 'Loopback request' ),
    2165                     'test'  => 'loopback_requests',
     2168                    'label'    => __( 'Loopback request' ),
     2169                    'test'     => rest_url( 'wp-site-health/v1/tests/loopback-requests' ),
     2170                    'has_rest' => true,
    21662171                ),
    21672172            ),
     
    22002205         *         to avoid any collisions between tests.
    22012206         *
    2202          *         @type string $label A friendly label for your test to identify it by.
    2203          *         @type mixed  $test  A callable to perform a direct test, or a string Ajax action to be called
    2204          *                             to perform an async test.
     2207         *         @type string  $label       A friendly label for your test to identify it by.
     2208         *         @type mixed   $test        A callable to perform a direct test, or a string AJAX action to be
     2209         *                                    called to perform an async test.
     2210         *         @type boolean $has_rest    Optional. Denote if `$test` has a REST API endpoint.
    22052211         *     }
    22062212         * }
Note: See TracChangeset for help on using the changeset viewer.