WordPress.org

Make WordPress Core


Ignore:
Timestamp:
10/20/2020 04:21:12 PM (11 months ago)
Author:
SergeyBiryukov
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-wp-site-health.php

    r49232 r49237  
    107107            $tests = WP_Site_Health::get_tests();
    108108
    109             // Don't run https test on localhost.
    110             if ( 'localhost' === preg_replace( '|https?://|', '', get_site_url() ) ) {
     109            // Don't run https test on development environments.
     110            if ( $this->is_development_environment() ) {
    111111                unset( $tests['direct']['https_status'] );
    112112            }
     
    14651465
    14661466                $result['status'] = 'critical';
     1467
     1468                // On development environments, set the status to recommended.
     1469                if ( $this->is_development_environment() ) {
     1470                    $result['status'] = 'recommended';
     1471                }
    14671472
    14681473                $result['description'] .= sprintf(
     
    25322537        );
    25332538
    2534         // Don't run https test on localhost.
    2535         if ( 'localhost' === preg_replace( '|https?://|', '', get_site_url() ) ) {
     2539        // Don't run https test on development environments.
     2540        if ( $this->is_development_environment() ) {
    25362541            unset( $tests['direct']['https_status'] );
    25372542        }
     
    26162621        set_transient( 'health-check-site-status-result', wp_json_encode( $site_status ) );
    26172622    }
     2623
     2624    /**
     2625     * Checks if the current environment type is set to 'development' or 'local'.
     2626     *
     2627     * @since 5.6.0
     2628     *
     2629     * @return bool True if it is a development environment, false if not.
     2630     */
     2631    public function is_development_environment() {
     2632        return in_array( wp_get_environment_type(), array( 'development', 'local' ), true );
     2633    }
     2634
    26182635}
Note: See TracChangeset for help on using the changeset viewer.