Site Health: Allow any callable added via `site_status_tests` filter to return test results for direct tests.

Async tests still need to be a string for the AJAX action.

Props kraftbj.
Fixes #46836.
Built from https://develop.svn.wordpress.org/trunk@45234


git-svn-id: http://core.svn.wordpress.org/trunk@45043 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2019-04-17 14:35:50 +00:00
parent 1be34a234f
commit 23de32062e
2 changed files with 26 additions and 16 deletions

View File

@ -71,28 +71,37 @@ class WP_Site_Health {
if ( 'site-health' === $screen->id && ! isset( $_GET['tab'] ) ) { if ( 'site-health' === $screen->id && ! isset( $_GET['tab'] ) ) {
$tests = WP_Site_Health::get_tests(); $tests = WP_Site_Health::get_tests();
// Don't run https test on localhost // Don't run https test on localhost
if ( 'localhost' === preg_replace( '|https?://|', '', get_site_url() ) ) { if ( 'localhost' === preg_replace( '|https?://|', '', get_site_url() ) ) {
unset( $tests['direct']['https_status'] ); unset( $tests['direct']['https_status'] );
} }
foreach ( $tests['direct'] as $test ) {
$test_function = sprintf(
'get_test_%s',
$test['test']
);
if ( method_exists( $this, $test_function ) && is_callable( array( $this, $test_function ) ) ) { foreach ( $tests['direct'] as $test ) {
$health_check_js_variables['site_status']['direct'][] = call_user_func( array( $this, $test_function ) ); if ( is_string( $test['test'] ) ) {
} else { $test_function = sprintf(
'get_test_%s',
$test['test']
);
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 ) );
continue;
}
}
if ( is_callable( $test['test'] ) ) {
$health_check_js_variables['site_status']['direct'][] = call_user_func( $test['test'] ); $health_check_js_variables['site_status']['direct'][] = call_user_func( $test['test'] );
} }
} }
foreach ( $tests['async'] as $test ) { foreach ( $tests['async'] as $test ) {
$health_check_js_variables['site_status']['async'][] = array( if ( is_string( $test['test'] ) ) {
'test' => $test['test'], $health_check_js_variables['site_status']['async'][] = array(
'completed' => false, 'test' => $test['test'],
); 'completed' => false,
);
}
} }
} }
@ -1798,7 +1807,7 @@ class WP_Site_Health {
} }
/** /**
* Add or modify which site status tests are ran on a site. * Add or modify which site status tests are run on a site.
* *
* The site health is determined by a set of tests based on best practices from * The site health is determined by a set of tests based on best practices from
* both the WordPress Hosting Team, but also web standards in general. * both the WordPress Hosting Team, but also web standards in general.
@ -1807,7 +1816,7 @@ class WP_Site_Health {
* checks may be handled by a host, and are therefore disabled in core. * checks may be handled by a host, and are therefore disabled in core.
* Or maybe you want to introduce a new test, is caching enabled/disabled/stale for example. * Or maybe you want to introduce a new test, is caching enabled/disabled/stale for example.
* *
* Test may be added either as direct, or asynchronous ones. Any test that may require some time * Tests may be added either as direct, or asynchronous ones. Any test that may require some time
* to complete should run asynchronously, to avoid extended loading periods within wp-admin. * to complete should run asynchronously, to avoid extended loading periods within wp-admin.
* *
* @since 5.2.0 * @since 5.2.0
@ -1822,7 +1831,8 @@ class WP_Site_Health {
* to avoid any collisions between tests. * to avoid any collisions between tests.
* *
* @type string $label A friendly label for your test to identify it by. * @type string $label A friendly label for your test to identify it by.
* @type string $test The ajax action to be called to perform the tests. * @type mixed $test A callable to perform a direct test, or a string AJAX action to be called
* to perform an async test.
* } * }
* } * }
*/ */

View File

@ -13,7 +13,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '5.2-beta3-45233'; $wp_version = '5.2-beta3-45234';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.