From a9fb2f6a3805da4b038fcc38a0db3f52d3547a49 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Mon, 23 Sep 2019 20:03:15 +0000 Subject: [PATCH] Site Health: Introduce `site_status_test_result` filter for the output of a finished Site Health test. Props Clorith. Fixes #47864. git-svn-id: https://develop.svn.wordpress.org/trunk@46269 602fd350-edb4-49c9-b593-d223f7449a82 --- src/js/_enqueues/admin/site-health.js | 3 ++- .../includes/class-wp-site-health.php | 26 +++++++++++++++++-- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/js/_enqueues/admin/site-health.js b/src/js/_enqueues/admin/site-health.js index 6dbe1462d2..f5a6fed06f 100644 --- a/src/js/_enqueues/admin/site-health.js +++ b/src/js/_enqueues/admin/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/src/wp-admin/includes/class-wp-site-health.php b/src/wp-admin/includes/class-wp-site-health.php index c41534f7b4..5f7c6bc7b7 100644 --- a/src/wp-admin/includes/class-wp-site-health.php +++ b/src/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'] ) ); } }