diff --git a/wp-admin/includes/class-wp-site-health.php b/wp-admin/includes/class-wp-site-health.php
index c41534f7b4..5f7c6bc7b7 100644
--- a/wp-admin/includes/class-wp-site-health.php
+++ b/wp-admin/includes/class-wp-site-health.php
@@ -96,13 +96,35 @@ class WP_Site_Health {
);
if ( method_exists( $this, $test_function ) && is_callable( array( $this, $test_function ) ) ) {
- $health_check_js_variables['site_status']['direct'][] = call_user_func( array( $this, $test_function ) );
+ /**
+ * Filter the output of a finished Site Health test.
+ *
+ * @since 5.3.0
+ *
+ * @param array $test_result {
+ * An associated array of test result data.
+ *
+ * @param string $label A label describing the test, and is used as a header in the output.
+ * @param string $status The status of the test, which can be a value of `good`, `recommended` or `critical`.
+ * @param array $badge {
+ * Tests are put into categories which have an associated badge shown, these can be modified and assigned here.
+ *
+ * @param string $label The test label, for example `Performance`.
+ * @param string $color Default `blue`. A string representing a color to use for the label.
+ * }
+ * @param string $description A more descriptive explanation of what the test looks for, and why it is important for the end user.
+ * @param string $actions An action to direct the user to where they can resolve the issue, if one exists.
+ * @param string $test The name of the test being ran, used as a reference point.
+ * }
+ */
+ $health_check_js_variables['site_status']['direct'][] = apply_filters( 'site_status_test_result', call_user_func( array( $this, $test_function ) ) );
continue;
}
}
if ( is_callable( $test['test'] ) ) {
- $health_check_js_variables['site_status']['direct'][] = call_user_func( $test['test'] );
+ /** This filter is documented in wp-admin/includes/class-wp-site-health.php */
+ $health_check_js_variables['site_status']['direct'][] = apply_filters( 'site_status_test_result', call_user_func( $test['test'] ) );
}
}
diff --git a/wp-admin/js/site-health.js b/wp-admin/js/site-health.js
index 6dbe1462d2..f5a6fed06f 100644
--- a/wp-admin/js/site-health.js
+++ b/wp-admin/js/site-health.js
@@ -179,7 +179,8 @@ jQuery( document ).ready( function( $ ) {
ajaxurl,
data,
function( response ) {
- AppendIssue( response.data );
+ /** This filter is documented in wp-admin/includes/class-wp-site-health.php */
+ AppendIssue( wp.hooks.applyFilters( 'site_status_test_result', response.data ) );
maybeRunNextAsyncTest();
}
);
diff --git a/wp-admin/js/site-health.min.js b/wp-admin/js/site-health.min.js
index e505aa04ee..5209aaaa8c 100644
--- a/wp-admin/js/site-health.min.js
+++ b/wp-admin/js/site-health.min.js
@@ -1 +1 @@
-jQuery(document).ready(function(a){function b(b){var c,d,e=wp.template("health-check-issue"),f=a("#health-check-issues-"+b.status);SiteHealth.site_status.issues[b.status]++,d=SiteHealth.site_status.issues[b.status],"critical"===b.status?c=j(i("%s critical issue","%s critical issues",d),''+d+""):"recommended"===b.status?c=j(i("%s recommended improvement","%s recommended improvements",d),''+d+""):"good"===b.status&&(c=j(i("%s item with no issues detected","%s items with no issues detected",d),''+d+"")),c&&a(".site-health-issue-count-title",f).html(c),a(".issues","#health-check-issues-"+b.status).append(e(b))}function c(){var b,c,d,e=a(".site-health-progress"),f=e.closest(".site-health-progress-wrapper"),g=a(".site-health-progress-label",f),i=a(".site-health-progress svg #bar"),j=parseInt(SiteHealth.site_status.issues.good,0)+parseInt(SiteHealth.site_status.issues.recommended,0)+1.5*parseInt(SiteHealth.site_status.issues.critical,0),k=.5*parseInt(SiteHealth.site_status.issues.recommended,0)+1.5*parseInt(SiteHealth.site_status.issues.critical,0),m=100-Math.ceil(k/j*100);return 0===j?void e.addClass("hidden"):(f.removeClass("loading"),b=i.attr("r"),c=Math.PI*(2*b),0>m&&(m=0),100parseInt(SiteHealth.site_status.issues.critical,0)&&a("#health-check-issues-critical").addClass("hidden"),1>parseInt(SiteHealth.site_status.issues.recommended,0)&&a("#health-check-issues-recommended").addClass("hidden"),80<=m&&0===parseInt(SiteHealth.site_status.issues.critical,0)?(f.addClass("green").removeClass("orange"),g.text(h("Good")),wp.a11y.speak(h("All site health tests have finished running. Your site is looking good, and the results are now available on the page."))):(f.addClass("orange").removeClass("green"),g.text(h("Should be improved")),wp.a11y.speak(h("All site health tests have finished running. There are items that should be addressed, and the results are now available on the page."))),void(l||(a.post(ajaxurl,{action:"health-check-site-status-result",_wpnonce:SiteHealth.nonce.site_status_result,counts:SiteHealth.site_status.issues}),100===m&&(a(".site-status-all-clear").removeClass("hide"),a(".site-status-has-issues").addClass("hide")))))}function d(){var e=!0;1<=SiteHealth.site_status.async.length&&a.each(SiteHealth.site_status.async,function(){var c={action:"health-check-"+this.test.replace("_","-"),_wpnonce:SiteHealth.nonce.site_status};return!!this.completed||(e=!1,this.completed=!0,a.post(ajaxurl,c,function(a){b(a.data),d()}),!1)}),e&&c()}function e(){var b={action:"health-check-get-sizes",_wpnonce:SiteHealth.nonce.site_status_result},d=(new Date).getTime(),e=window.setTimeout(function(){wp.a11y.speak(h("Please wait..."))},3e3);a.post({type:"POST",url:ajaxurl,data:b,dataType:"json"}).done(function(a){f(a.data||{})}).always(function(){var b=(new Date).getTime()-d;a(".health-check-wp-paths-sizes.spinner").css("visibility","hidden"),c(),b>3e3?(b=b>6e3?0:6500-b,window.setTimeout(function(){wp.a11y.speak(h("All site health tests have finished running."))},b)):window.clearTimeout(e),a(document).trigger("site-health-info-dirsizes-done")})}function f(b){var c=a("button.button.copy-button"),d=c.attr("data-clipboard-text");a.each(b,function(a,b){var c=b.debug||b.size;"undefined"!=typeof c&&(d=d.replace(a+": loading...",a+": "+c))}),c.attr("data-clipboard-text",d),m.find("td[class]").each(function(c,d){var e=a(d),f=e.attr("class");b.hasOwnProperty(f)&&b[f].size&&e.text(b[f].size)})}var g,h=wp.i18n.__,i=wp.i18n._n,j=wp.i18n.sprintf,k=new ClipboardJS(".site-health-copy-buttons .copy-button"),l=a(".health-check-body.health-check-debug-tab").length,m=a("#health-check-accordion-block-wp-paths-sizes");k.on("success",function(b){var c=a(b.trigger).closest("div");a(".success",c).addClass("visible"),wp.a11y.speak(h("Site information has been added to your clipboard."))}),a(".health-check-accordion").on("click",".health-check-accordion-trigger",function(){var b="true"===a(this).attr("aria-expanded");b?(a(this).attr("aria-expanded","false"),a("#"+a(this).attr("aria-controls")).attr("hidden",!0)):(a(this).attr("aria-expanded","true"),a("#"+a(this).attr("aria-controls")).attr("hidden",!1))}),a(".site-health-view-passed").on("click",function(){var b=a("#health-check-issues-good");b.toggleClass("hidden"),a(this).attr("aria-expanded",!b.hasClass("hidden"))}),"undefined"==typeof SiteHealth||l||(0===SiteHealth.site_status.direct.length&&0===SiteHealth.site_status.async.length?c():SiteHealth.site_status.issues={good:0,recommended:0,critical:0},0'+d+""):"recommended"===b.status?c=j(i("%s recommended improvement","%s recommended improvements",d),''+d+""):"good"===b.status&&(c=j(i("%s item with no issues detected","%s items with no issues detected",d),''+d+"")),c&&a(".site-health-issue-count-title",f).html(c),a(".issues","#health-check-issues-"+b.status).append(e(b))}function c(){var b,c,d,e=a(".site-health-progress"),f=e.closest(".site-health-progress-wrapper"),g=a(".site-health-progress-label",f),i=a(".site-health-progress svg #bar"),j=parseInt(SiteHealth.site_status.issues.good,0)+parseInt(SiteHealth.site_status.issues.recommended,0)+1.5*parseInt(SiteHealth.site_status.issues.critical,0),k=.5*parseInt(SiteHealth.site_status.issues.recommended,0)+1.5*parseInt(SiteHealth.site_status.issues.critical,0),m=100-Math.ceil(k/j*100);return 0===j?void e.addClass("hidden"):(f.removeClass("loading"),b=i.attr("r"),c=Math.PI*(2*b),0>m&&(m=0),100parseInt(SiteHealth.site_status.issues.critical,0)&&a("#health-check-issues-critical").addClass("hidden"),1>parseInt(SiteHealth.site_status.issues.recommended,0)&&a("#health-check-issues-recommended").addClass("hidden"),80<=m&&0===parseInt(SiteHealth.site_status.issues.critical,0)?(f.addClass("green").removeClass("orange"),g.text(h("Good")),wp.a11y.speak(h("All site health tests have finished running. Your site is looking good, and the results are now available on the page."))):(f.addClass("orange").removeClass("green"),g.text(h("Should be improved")),wp.a11y.speak(h("All site health tests have finished running. There are items that should be addressed, and the results are now available on the page."))),void(l||(a.post(ajaxurl,{action:"health-check-site-status-result",_wpnonce:SiteHealth.nonce.site_status_result,counts:SiteHealth.site_status.issues}),100===m&&(a(".site-status-all-clear").removeClass("hide"),a(".site-status-has-issues").addClass("hide")))))}function d(){var e=!0;1<=SiteHealth.site_status.async.length&&a.each(SiteHealth.site_status.async,function(){var c={action:"health-check-"+this.test.replace("_","-"),_wpnonce:SiteHealth.nonce.site_status};return!!this.completed||(e=!1,this.completed=!0,a.post(ajaxurl,c,function(a){b(wp.hooks.applyFilters("site_status_test_result",a.data)),d()}),!1)}),e&&c()}function e(){var b={action:"health-check-get-sizes",_wpnonce:SiteHealth.nonce.site_status_result},d=(new Date).getTime(),e=window.setTimeout(function(){wp.a11y.speak(h("Please wait..."))},3e3);a.post({type:"POST",url:ajaxurl,data:b,dataType:"json"}).done(function(a){f(a.data||{})}).always(function(){var b=(new Date).getTime()-d;a(".health-check-wp-paths-sizes.spinner").css("visibility","hidden"),c(),b>3e3?(b=b>6e3?0:6500-b,window.setTimeout(function(){wp.a11y.speak(h("All site health tests have finished running."))},b)):window.clearTimeout(e),a(document).trigger("site-health-info-dirsizes-done")})}function f(b){var c=a("button.button.copy-button"),d=c.attr("data-clipboard-text");a.each(b,function(a,b){var c=b.debug||b.size;"undefined"!=typeof c&&(d=d.replace(a+": loading...",a+": "+c))}),c.attr("data-clipboard-text",d),m.find("td[class]").each(function(c,d){var e=a(d),f=e.attr("class");b.hasOwnProperty(f)&&b[f].size&&e.text(b[f].size)})}var g,h=wp.i18n.__,i=wp.i18n._n,j=wp.i18n.sprintf,k=new ClipboardJS(".site-health-copy-buttons .copy-button"),l=a(".health-check-body.health-check-debug-tab").length,m=a("#health-check-accordion-block-wp-paths-sizes");k.on("success",function(b){var c=a(b.trigger).closest("div");a(".success",c).addClass("visible"),wp.a11y.speak(h("Site information has been added to your clipboard."))}),a(".health-check-accordion").on("click",".health-check-accordion-trigger",function(){var b="true"===a(this).attr("aria-expanded");b?(a(this).attr("aria-expanded","false"),a("#"+a(this).attr("aria-controls")).attr("hidden",!0)):(a(this).attr("aria-expanded","true"),a("#"+a(this).attr("aria-controls")).attr("hidden",!1))}),a(".site-health-view-passed").on("click",function(){var b=a("#health-check-issues-good");b.toggleClass("hidden"),a(this).attr("aria-expanded",!b.hasClass("hidden"))}),"undefined"==typeof SiteHealth||l||(0===SiteHealth.site_status.direct.length&&0===SiteHealth.site_status.async.length?c():SiteHealth.site_status.issues={good:0,recommended:0,critical:0},0