diff --git a/wp-admin/admin-ajax.php b/wp-admin/admin-ajax.php
index 28caf3d227..144facf7fe 100644
--- a/wp-admin/admin-ajax.php
+++ b/wp-admin/admin-ajax.php
@@ -143,7 +143,15 @@ $core_actions_post = array(
);
// Deprecated.
-$core_actions_post_deprecated = array( 'wp-fullscreen-save-post', 'press-this-save-post', 'press-this-add-category' );
+$core_actions_post_deprecated = array(
+ 'wp-fullscreen-save-post',
+ 'press-this-save-post',
+ 'press-this-add-category',
+ 'health-check-dotorg-communication',
+ 'health-check-is-in-debug-mode',
+ 'health-check-background-updates',
+ 'health-check-loopback-requests',
+);
$core_actions_post = array_merge( $core_actions_post, $core_actions_post_deprecated );
// Register core Ajax calls.
diff --git a/wp-admin/includes/ajax-actions.php b/wp-admin/includes/ajax-actions.php
index 357fdc8d52..f359732b15 100644
--- a/wp-admin/includes/ajax-actions.php
+++ b/wp-admin/includes/ajax-actions.php
@@ -5142,8 +5142,21 @@ function wp_ajax_wp_privacy_erase_personal_data() {
* Ajax handler for site health checks on server communication.
*
* @since 5.2.0
+ * @deprecated 5.6.0 Use WP_REST_Site_Health_Controller::test_dotorg_communication()
+ * @see WP_REST_Site_Health_Controller::test_dotorg_communication()
*/
function wp_ajax_health_check_dotorg_communication() {
+ _doing_it_wrong(
+ 'wp_ajax_health_check_dotorg_communication',
+ sprintf(
+ // translators: 1: The Site Health action that is no longer used by core. 2: The new function that replaces it.
+ __( 'The Site Health check for %1$s has been replaced with %2$s.' ),
+ 'wp_ajax_health_check_dotorg_communication',
+ 'WP_REST_Site_Health_Controller::test_dotorg_communication'
+ ),
+ '5.6.0'
+ );
+
check_ajax_referer( 'health-check-site-status' );
if ( ! current_user_can( 'view_site_health_checks' ) ) {
@@ -5162,8 +5175,21 @@ function wp_ajax_health_check_dotorg_communication() {
* Ajax handler for site health checks on background updates.
*
* @since 5.2.0
+ * @deprecated 5.6.0 Use WP_REST_Site_Health_Controller::test_background_updates()
+ * @see WP_REST_Site_Health_Controller::test_background_updates()
*/
function wp_ajax_health_check_background_updates() {
+ _doing_it_wrong(
+ 'wp_ajax_health_check_background_updates',
+ sprintf(
+ // translators: 1: The Site Health action that is no longer used by core. 2: The new function that replaces it.
+ __( 'The Site Health check for %1$s has been replaced with %2$s.' ),
+ 'wp_ajax_health_check_background_updates',
+ 'WP_REST_Site_Health_Controller::test_background_updates'
+ ),
+ '5.6.0'
+ );
+
check_ajax_referer( 'health-check-site-status' );
if ( ! current_user_can( 'view_site_health_checks' ) ) {
@@ -5182,8 +5208,21 @@ function wp_ajax_health_check_background_updates() {
* Ajax handler for site health checks on loopback requests.
*
* @since 5.2.0
+ * @deprecated 5.6.0 Use WP_REST_Site_Health_Controller::test_loopback_requests()
+ * @see WP_REST_Site_Health_Controller::test_loopback_requests()
*/
function wp_ajax_health_check_loopback_requests() {
+ _doing_it_wrong(
+ 'wp_ajax_health_check_loopback_requests',
+ sprintf(
+ // translators: 1: The Site Health action that is no longer used by core. 2: The new function that replaces it.
+ __( 'The Site Health check for %1$s has been replaced with %2$s.' ),
+ 'wp_ajax_health_check_loopback_requests',
+ 'WP_REST_Site_Health_Controller::test_loopback_requests'
+ ),
+ '5.6.0'
+ );
+
check_ajax_referer( 'health-check-site-status' );
if ( ! current_user_can( 'view_site_health_checks' ) ) {
@@ -5219,8 +5258,21 @@ function wp_ajax_health_check_site_status_result() {
* Ajax handler for site health check to get directories and database sizes.
*
* @since 5.2.0
+ * @deprecated 5.6.0 Use WP_REST_Site_Health_Controller::get_directory_sizes()
+ * @see WP_REST_Site_Health_Controller::get_directory_sizes()
*/
function wp_ajax_health_check_get_sizes() {
+ _doing_it_wrong(
+ 'wp_ajax_health_check_get_sizes',
+ sprintf(
+ // translators: 1: The Site Health action that is no longer used by core. 2: The new function that replaces it.
+ __( 'The Site Health check for %1$s has been replaced with %2$s.' ),
+ 'wp_ajax_health_check_get_sizes',
+ 'WP_REST_Site_Health_Controller::get_directory_sizes'
+ ),
+ '5.6.0'
+ );
+
check_ajax_referer( 'health-check-site-status-result' );
if ( ! current_user_can( 'view_site_health_checks' ) || is_multisite() ) {
diff --git a/wp-admin/includes/class-wp-site-health-auto-updates.php b/wp-admin/includes/class-wp-site-health-auto-updates.php
index 4e3383eb1a..0bcdbf28d2 100644
--- a/wp-admin/includes/class-wp-site-health-auto-updates.php
+++ b/wp-admin/includes/class-wp-site-health-auto-updates.php
@@ -90,46 +90,7 @@ class WP_Site_Health_Auto_Updates {
* @return array The test results.
*/
public function test_wp_version_check_attached() {
- if ( ! is_main_site() ) {
- return;
- }
-
- $cookies = wp_unslash( $_COOKIE );
- $timeout = 10;
- $headers = array(
- 'Cache-Control' => 'no-cache',
- );
- /** This filter is documented in wp-includes/class-wp-http-streams.php */
- $sslverify = apply_filters( 'https_local_ssl_verify', false );
-
- // Include Basic auth in loopback requests.
- if ( isset( $_SERVER['PHP_AUTH_USER'] ) && isset( $_SERVER['PHP_AUTH_PW'] ) ) {
- $headers['Authorization'] = 'Basic ' . base64_encode( wp_unslash( $_SERVER['PHP_AUTH_USER'] ) . ':' . wp_unslash( $_SERVER['PHP_AUTH_PW'] ) );
- }
-
- $url = add_query_arg(
- array(
- 'health-check-test-wp_version_check' => true,
- ),
- admin_url( 'site-health.php' )
- );
-
- $test = wp_remote_get( $url, compact( 'cookies', 'headers', 'timeout', 'sslverify' ) );
-
- if ( is_wp_error( $test ) ) {
- return array(
- 'description' => sprintf(
- /* translators: %s: Name of the filter used. */
- __( 'Could not confirm that the %s filter is available.' ),
- 'wp_version_check()'
- ),
- 'severity' => 'warning',
- );
- }
-
- $response = wp_remote_retrieve_body( $test );
-
- if ( 'yes' !== $response ) {
+ if ( ! has_filter( 'wp_version_check', 'wp_version_check' ) ) {
return array(
'description' => sprintf(
/* translators: %s: Name of the filter used. */
@@ -310,6 +271,11 @@ class WP_Site_Health_Auto_Updates {
* @return array The test results.
*/
function test_check_wp_filesystem_method() {
+ // Make sure the `request_filesystem_credentials` function is available during our REST call.
+ if ( ! function_exists( 'request_filesystem_credentials' ) ) {
+ require_once ABSPATH . '/wp-admin/includes/file.php';
+ }
+
$skin = new Automatic_Upgrader_Skin;
$success = $skin->request_filesystem_credentials( false, ABSPATH );
@@ -356,6 +322,11 @@ class WP_Site_Health_Auto_Updates {
return false;
}
+ // Make sure the `get_core_checksums` function is available during our REST call.
+ if ( ! function_exists( 'get_core_checksums' ) ) {
+ require_once ABSPATH . '/wp-admin/includes/update.php';
+ }
+
$checksums = get_core_checksums( $wp_version, 'en_US' );
$dev = ( false !== strpos( $wp_version, '-' ) );
// Get the last stable version's files and test against that.
diff --git a/wp-admin/includes/class-wp-site-health.php b/wp-admin/includes/class-wp-site-health.php
index de698d7a30..6070a57b9b 100644
--- a/wp-admin/includes/class-wp-site-health.php
+++ b/wp-admin/includes/class-wp-site-health.php
@@ -133,6 +133,7 @@ class WP_Site_Health {
if ( is_string( $test['test'] ) ) {
$health_check_js_variables['site_status']['async'][] = array(
'test' => $test['test'],
+ 'has_rest' => ( isset( $test['has_rest'] ) ? $test['has_rest'] : false ),
'completed' => false,
);
}
@@ -2080,6 +2081,7 @@ class WP_Site_Health {
* experiences.
*
* @since 5.2.0
+ * @since 5.6.0 Added support for `has_rest` and `permissions`.
*
* @return array The list of tests to run.
*/
@@ -2153,16 +2155,19 @@ class WP_Site_Health {
),
'async' => array(
'dotorg_communication' => array(
- 'label' => __( 'Communication with WordPress.org' ),
- 'test' => 'dotorg_communication',
+ 'label' => __( 'Communication with WordPress.org' ),
+ 'test' => rest_url( 'wp-site-health/v1/tests/dotorg-communication' ),
+ 'has_rest' => true,
),
'background_updates' => array(
- 'label' => __( 'Background updates' ),
- 'test' => 'background_updates',
+ 'label' => __( 'Background updates' ),
+ 'test' => rest_url( 'wp-site-health/v1/tests/background-updates' ),
+ 'has_rest' => true,
),
'loopback_requests' => array(
- 'label' => __( 'Loopback request' ),
- 'test' => 'loopback_requests',
+ 'label' => __( 'Loopback request' ),
+ 'test' => rest_url( 'wp-site-health/v1/tests/loopback-requests' ),
+ 'has_rest' => true,
),
),
);
@@ -2199,9 +2204,10 @@ class WP_Site_Health {
* Plugins and themes are encouraged to prefix test identifiers with their slug
* to avoid any collisions between tests.
*
- * @type string $label A friendly label for your test to identify it by.
- * @type mixed $test A callable to perform a direct test, or a string Ajax action to be called
- * to perform an async test.
+ * @type string $label A friendly label for your test to identify it by.
+ * @type mixed $test A callable to perform a direct test, or a string AJAX action to be
+ * called to perform an async test.
+ * @type boolean $has_rest Optional. Denote if `$test` has a REST API endpoint.
* }
* }
*/
diff --git a/wp-admin/js/site-health.js b/wp-admin/js/site-health.js
index 73d4fe922f..54497464cd 100644
--- a/wp-admin/js/site-health.js
+++ b/wp-admin/js/site-health.js
@@ -11,7 +11,6 @@ jQuery( document ).ready( function( $ ) {
var __ = wp.i18n.__,
_n = wp.i18n._n,
sprintf = wp.i18n.sprintf,
- data,
clipboard = new ClipboardJS( '.site-health-copy-buttons .copy-button' ),
isDebugTab = $( '.health-check-body.health-check-debug-tab' ).length,
pathsSizesSection = $( '#health-check-accordion-block-wp-paths-sizes' ),
@@ -78,11 +77,16 @@ jQuery( document ).ready( function( $ ) {
issueWrapper = $( '#health-check-issues-' + issue.status ),
heading,
count;
-
+
SiteHealth.site_status.issues[ issue.status ]++;
count = SiteHealth.site_status.issues[ issue.status ];
+ // If no test name is supplied, append a placeholder for markup references.
+ if ( typeof issue.test === 'undefined' ) {
+ issue.test = issue.status + count;
+ }
+
if ( 'critical' === issue.status ) {
heading = sprintf(
_n( '%s critical issue', '%s critical issues', count ),
@@ -119,10 +123,10 @@ jQuery( document ).ready( function( $ ) {
var $progressLabel = $( '.site-health-progress-label', $wrapper );
var $circle = $( '.site-health-progress svg #bar' );
var totalTests = parseInt( SiteHealth.site_status.issues.good, 0 ) +
- parseInt( SiteHealth.site_status.issues.recommended, 0 ) +
- ( parseInt( SiteHealth.site_status.issues.critical, 0 ) * 1.5 );
+ parseInt( SiteHealth.site_status.issues.recommended, 0 ) +
+ ( parseInt( SiteHealth.site_status.issues.critical, 0 ) * 1.5 );
var failedTests = ( parseInt( SiteHealth.site_status.issues.recommended, 0 ) * 0.5 ) +
- ( parseInt( SiteHealth.site_status.issues.critical, 0 ) * 1.5 );
+ ( parseInt( SiteHealth.site_status.issues.critical, 0 ) * 1.5 );
var val = 100 - Math.ceil( ( failedTests / totalTests ) * 100 );
if ( 0 === totalTests ) {
@@ -206,15 +210,49 @@ jQuery( document ).ready( function( $ ) {
this.completed = true;
- $.post(
- ajaxurl,
- data,
- function( response ) {
+ if ( 'undefined' !== typeof( this.has_rest ) && this.has_rest ) {
+ wp.apiRequest( {
+ url: this.test
+ } )
+ .done( function( response ) {
+ /** This filter is documented in wp-admin/includes/class-wp-site-health.php */
+ appendIssue( wp.hooks.applyFilters( 'site_status_test_result', response ) );
+ } )
+ .fail( function( response ) {
+ var description;
+
+ if ( 'undefined' !== typeof( response.responseJSON ) && 'undefined' !== typeof( response.responseJSON.message ) ) {
+ description = response.responseJSON.message;
+ } else {
+ description = __( 'No details available' );
+ }
+
+ addFailedSiteHealthCheckNotice( this.url, description );
+ } )
+ .always( function() {
+ maybeRunNextAsyncTest();
+ } );
+ } else {
+ $.post(
+ ajaxurl,
+ data
+ ).done( function( response ) {
/** This filter is documented in wp-admin/includes/class-wp-site-health.php */
appendIssue( wp.hooks.applyFilters( 'site_status_test_result', response.data ) );
+ } ).fail( function( response ) {
+ var description;
+
+ if ( 'undefined' !== typeof( response.responseJSON ) && 'undefined' !== typeof( response.responseJSON.message ) ) {
+ description = response.responseJSON.message;
+ } else {
+ description = __( 'No details available' );
+ }
+
+ addFailedSiteHealthCheckNotice( this.url, description );
+ } ).always( function() {
maybeRunNextAsyncTest();
- }
- );
+ } );
+ }
return false;
} );
@@ -225,6 +263,29 @@ jQuery( document ).ready( function( $ ) {
}
}
+ /**
+ * Add the details of a failed asynchronous test to the list of test results.
+ *
+ * @since 5.6.0
+ */
+ function addFailedSiteHealthCheckNotice( url, description ) {
+ var issue;
+
+ issue = {
+ 'status': 'recommended',
+ 'label': __( 'A test is unavailable' ),
+ 'badge': {
+ 'color': 'red',
+ 'label': __( 'Unavailable' )
+ },
+ 'description': '
' + url + '
' + description + '
', + 'actions': '' + }; + + /** This filter is documented in wp-admin/includes/class-wp-site-health.php */ + appendIssue( wp.hooks.applyFilters( 'site_status_test_result', issue ) ); + } + if ( 'undefined' !== typeof SiteHealth && ! isDebugTab ) { if ( 0 === SiteHealth.site_status.direct.length && 0 === SiteHealth.site_status.async.length ) { recalculateProgression(); @@ -243,32 +304,13 @@ jQuery( document ).ready( function( $ ) { } if ( 0 < SiteHealth.site_status.async.length ) { - data = { - 'action': 'health-check-' + SiteHealth.site_status.async[0].test.replace( '_', '-' ), - '_wpnonce': SiteHealth.nonce.site_status - }; - - SiteHealth.site_status.async[0].completed = true; - - $.post( - ajaxurl, - data, - function( response ) { - appendIssue( response.data ); - maybeRunNextAsyncTest(); - } - ); + maybeRunNextAsyncTest(); } else { recalculateProgression(); } } function getDirectorySizes() { - var data = { - action: 'health-check-get-sizes', - _wpnonce: SiteHealth.nonce.site_status_result - }; - var timestamp = ( new Date().getTime() ); // After 3 seconds announce that we're still waiting for directory sizes. @@ -276,20 +318,17 @@ jQuery( document ).ready( function( $ ) { wp.a11y.speak( __( 'Please wait...' ) ); }, 3000 ); - $.post( { - type: 'POST', - url: ajaxurl, - data: data, - dataType: 'json' + wp.apiRequest( { + path: '/wp-site-health/v1/directory-sizes' } ).done( function( response ) { - updateDirSizes( response.data || {} ); + updateDirSizes( response || {} ); } ).always( function() { var delay = ( new Date().getTime() ) - timestamp; $( '.health-check-wp-paths-sizes.spinner' ).css( 'visibility', 'hidden' ); recalculateProgression(); - if ( delay > 3000 ) { + if ( delay > 3000 ) { /* * We have announced that we're waiting. * Announce that we're ready after giving at least 3 seconds diff --git a/wp-admin/js/site-health.min.js b/wp-admin/js/site-health.min.js index 9056768ddd..fecd022138 100644 --- a/wp-admin/js/site-health.min.js +++ b/wp-admin/js/site-health.min.js @@ -1,2 +1,2 @@ /*! This file is auto-generated */ -jQuery(document).ready(function(l){var e,a,t,s,i,r=wp.i18n.__,n=wp.i18n._n,c=wp.i18n.sprintf,h=new ClipboardJS(".site-health-copy-buttons .copy-button"),u=l(".health-check-body.health-check-debug-tab").length,o=l("#health-check-accordion-block-wp-paths-sizes");function d(e){var t,s,a=wp.template("health-check-issue"),i=l("#health-check-issues-"+e.status);SiteHealth.site_status.issues[e.status]++,s=SiteHealth.site_status.issues[e.status],"critical"===e.status?t=c(n("%s critical issue","%s critical issues",s),''+s+""):"recommended"===e.status?t=c(n("%s recommended improvement","%s recommended improvements",s),''+s+""):"good"===e.status&&(t=c(n("%s item with no issues detected","%s items with no issues detected",s),''+s+"")),t&&l(".site-health-issue-count-title",i).html(t),l(".issues","#health-check-issues-"+e.status).append(a(e))}function p(){var e,t,s=l(".site-health-progress"),a=s.closest(".site-health-progress-wrapper"),i=l(".site-health-progress-label",a),n=l(".site-health-progress svg #bar"),c=parseInt(SiteHealth.site_status.issues.good,0)+parseInt(SiteHealth.site_status.issues.recommended,0)+1.5*parseInt(SiteHealth.site_status.issues.critical,0),h=.5*parseInt(SiteHealth.site_status.issues.recommended,0)+1.5*parseInt(SiteHealth.site_status.issues.critical,0),o=100-Math.ceil(h/c*100);0!==c?(a.removeClass("loading"),e=n.attr("r"),o<0&&(o=0),100"+t+"
",actions:""},r(wp.hooks.applyFilters("site_status_test_result",s))}i.on("success",function(e){var t=c(e.trigger),s=c(".success",t.closest("div"));e.clearSelection(),t.focus(),clearTimeout(a),s.removeClass("hidden"),a=setTimeout(function(){s.addClass("hidden"),i.clipboardAction.fakeElem&&i.clipboardAction.removeFake&&i.clipboardAction.removeFake()},3e3),wp.a11y.speak(h("Site information has been copied to your clipboard."))}),c(".health-check-accordion").on("click",".health-check-accordion-trigger",function(){"true"===c(this).attr("aria-expanded")?(c(this).attr("aria-expanded","false"),c("#"+c(this).attr("aria-controls")).attr("hidden",!0)):(c(this).attr("aria-expanded","true"),c("#"+c(this).attr("aria-controls")).attr("hidden",!1))}),c(".site-health-view-passed").on("click",function(){var e=c("#health-check-issues-good");e.toggleClass("hidden"),c(this).attr("aria-expanded",!e.hasClass("hidden"))}),"undefined"==typeof SiteHealth||d||(0===SiteHealth.site_status.direct.length&&0===SiteHealth.site_status.async.length?u():SiteHealth.site_status.issues={good:0,recommended:0,critical:0},0