Automattic\WooCommerce\Internal\Admin
SiteHealth::register_async_test_routes
Register REST API routes for the tests that Site Health runs asynchronously.
Method of the class: SiteHealth{}
Hooks from the method
Returns
null. Nothing (null).
Usage
$SiteHealth = new SiteHealth(); $SiteHealth->register_async_test_routes(): void;
SiteHealth::register_async_test_routes() SiteHealth::register async test routes code WC 11.3.0
public function register_async_test_routes(): void {
foreach ( $this->get_woocommerce_site_health_tests() as $test_id => $test ) {
if ( empty( $test['async'] ) ) {
continue;
}
register_rest_route(
self::REST_NAMESPACE,
'/tests/' . $this->get_async_test_route( $test_id ),
array(
'methods' => 'GET',
'callback' => function () use ( $test_id ) {
/**
* This filter is documented in wp-admin/includes/class-wp-site-health.php
*
* Core runs it for direct tests only, so apply it here for tests moved to async.
*
* @since 5.3.0
*/
return rest_ensure_response( apply_filters( 'site_status_test_result', $this->run_test( $test_id ) ) );
},
'permission_callback' => function () {
return current_user_can( 'view_site_health_checks' );
},
)
);
}
}