Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/js/_enqueues/admin/site-health.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,16 @@ jQuery( function( $ ) {
issue.test = issue.status + count;
}

/*
* Collect the test name and status so they can be cached server-side. These
* include the asynchronous tests that only run in the browser. Labels are left
* out on purpose, as they are translated and the cache is shared across locales.
*/
SiteHealth.site_status.results.push( {
test: issue.test,
status: issue.status
} );

if ( 'critical' === issue.status ) {
heading = sprintf(
_n( '%s critical issue', '%s critical issues', count ),
Expand Down Expand Up @@ -250,6 +260,7 @@ jQuery( function( $ ) {
}

if ( isStatusTab ) {
// Refresh the lightweight counts first, so a large detailed payload can't block them.
$.post(
ajaxurl,
{
Expand All @@ -259,6 +270,18 @@ jQuery( function( $ ) {
}
);

// Send the per-test results separately, as a best-effort detailed cache update.
if ( SiteHealth.site_status.results.length ) {
$.post(
ajaxurl,
{
'action': 'health-check-site-status-result',
'_wpnonce': SiteHealth.nonce.site_status_result,
'results': JSON.stringify( SiteHealth.site_status.results )
}
);
}

if ( 100 === val ) {
$( '.site-status-all-clear' ).removeClass( 'hide' );
$( '.site-status-has-issues' ).addClass( 'hide' );
Expand Down
38 changes: 37 additions & 1 deletion src/wp-admin/includes/ajax-actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -5457,7 +5457,13 @@ function wp_ajax_health_check_loopback_requests() {
/**
* Handles site health check to update the result status via AJAX.
*
* The aggregate counts and the full per-test results are sent as two independent
* requests, so a large results payload cannot prevent the lightweight counts from being
* refreshed. Each is handled on its own here, and either may be omitted.
*
* @since 5.2.0
* @since 7.1.0 The submitted counts are validated, and the optional full per-test results
* are sanitized and cached separately as the authoritative detailed results.
*/
function wp_ajax_health_check_site_status_result() {
check_ajax_referer( 'health-check-site-status-result' );
Expand All @@ -5466,7 +5472,37 @@ function wp_ajax_health_check_site_status_result() {
wp_send_json_error();
}

set_transient( 'health-check-site-status-result', wp_json_encode( $_POST['counts'] ) );
if ( ! class_exists( 'WP_Site_Health' ) ) {
require_once ABSPATH . 'wp-admin/includes/class-wp-site-health.php';
}

$updated = false;

// Refresh the lightweight, autoloaded aggregate counts used by the admin menu and Dashboard.
if ( isset( $_POST['counts'] ) && is_array( $_POST['counts'] ) ) {
$counts = wp_unslash( $_POST['counts'] );
WP_Site_Health::set_site_status_counts( $counts );

$updated = true;
}

/*
* Cache the full per-test results as the authoritative detailed results. These include
* the asynchronous tests that require JavaScript to run. The values are sanitized in
* WP_Site_Health::update_site_status_detail().
*/
if ( isset( $_POST['results'] ) && is_string( $_POST['results'] ) ) {
$results = json_decode( wp_unslash( $_POST['results'] ), true );

if ( is_array( $results ) ) {
WP_Site_Health::update_site_status_detail( $results, true );
$updated = true;
}
}

if ( ! $updated ) {
wp_send_json_error();
}

wp_send_json_success();
}
Expand Down
Loading
Loading