From 980a38734777f77bdb719d8508badddf13e0c814 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Tue, 20 Oct 2020 16:21:12 +0000 Subject: [PATCH] Site Health: Introduce the `WP_Site_Health::is_development_environment()` method. This allows Site Health tests to check if the current environment type is set to `development` or `local`. Use the new method: * In HTTPS tests, instead of a hardcoded check for `localhost`. * In `WP_DEBUG` and `WP_DEBUG_DISPLAY` tests, to set the status to `recommended` instead of `critical`. Props dkotter, Clorith, DavidAnderson, joyously, knutsp, afragen, SergeyBiryukov. Fixes #47058. git-svn-id: https://develop.svn.wordpress.org/trunk@49237 602fd350-edb4-49c9-b593-d223f7449a82 --- .../includes/class-wp-site-health.php | 25 ++++++++++++++++--- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/wp-admin/includes/class-wp-site-health.php b/src/wp-admin/includes/class-wp-site-health.php index 31bec1145c..67c6272b6b 100644 --- a/src/wp-admin/includes/class-wp-site-health.php +++ b/src/wp-admin/includes/class-wp-site-health.php @@ -106,8 +106,8 @@ class WP_Site_Health { if ( 'site-health' === $screen->id && ! isset( $_GET['tab'] ) ) { $tests = WP_Site_Health::get_tests(); - // Don't run https test on localhost. - if ( 'localhost' === preg_replace( '|https?://|', '', get_site_url() ) ) { + // Don't run https test on development environments. + if ( $this->is_development_environment() ) { unset( $tests['direct']['https_status'] ); } @@ -1465,6 +1465,11 @@ class WP_Site_Health { $result['status'] = 'critical'; + // On development environments, set the status to recommended. + if ( $this->is_development_environment() ) { + $result['status'] = 'recommended'; + } + $result['description'] .= sprintf( '

%s

', sprintf( @@ -2531,8 +2536,8 @@ class WP_Site_Health { 'critical' => 0, ); - // Don't run https test on localhost. - if ( 'localhost' === preg_replace( '|https?://|', '', get_site_url() ) ) { + // Don't run https test on development environments. + if ( $this->is_development_environment() ) { unset( $tests['direct']['https_status'] ); } @@ -2615,4 +2620,16 @@ class WP_Site_Health { set_transient( 'health-check-site-status-result', wp_json_encode( $site_status ) ); } + + /** + * Checks if the current environment type is set to 'development' or 'local'. + * + * @since 5.6.0 + * + * @return bool True if it is a development environment, false if not. + */ + public function is_development_environment() { + return in_array( wp_get_environment_type(), array( 'development', 'local' ), true ); + } + }