WordPress.org

Make WordPress Core

Changeset 48188


Ignore:
Timestamp:
06/27/2020 10:34:02 AM (5 months ago)
Author:
SergeyBiryukov
Message:

Bootstrap/Load: Make some adjustments to wp_get_environment_type():

  • Rename the wp_approved_environment_types filter to wp_environment_types.
  • Introduce WP_ENVIRONMENT_TYPES system variable and constant to complement the filter.
  • Correct the argument type for the wp_environment_types filter.
  • Cache the result in a static variable to ensure consistent return value.
  • Rename the stage type to staging.

Follow-up to [47919].

Props dlh, dd32, TimothyBlynJacobs, johnbillion, pbiron.
See #33161.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/load.php

    r48168 r48188  
    135135 * a constant of the same name, or the {@see 'wp_get_environment_type'} filter.
    136136 *
    137  * Possible values include 'development', 'stage', 'production'. If not set,
     137 * Possible values include 'development', 'staging', 'production'. If not set,
    138138 * the type defaults to 'production'.
    139139 *
     
    143143 */
    144144function wp_get_environment_type() {
    145     $approved_environments = array(
     145    static $current_env = '';
     146
     147    if ( $current_env ) {
     148        return $current_env;
     149    }
     150
     151    $wp_environments = array(
    146152        'development',
    147         'stage',
     153        'staging',
    148154        'production',
    149155    );
    150156
     157    // Check if the environment variable has been set, if `getenv` is available on the system.
     158    if ( function_exists( 'getenv' ) ) {
     159        $has_env = getenv( 'WP_ENVIRONMENT_TYPES' );
     160        if ( false !== $has_env ) {
     161            $wp_environments = explode( ',', $has_env );
     162        }
     163    }
     164
     165    // Fetch the environment types from a constant, this overrides the global system variable.
     166    if ( defined( 'WP_ENVIRONMENT_TYPES' ) ) {
     167        $wp_environments = WP_ENVIRONMENT_TYPES;
     168    }
     169
    151170    /**
    152      * Filters the list of approved environment types.
     171     * Filters the list of supported environment types.
    153172     *
    154173     * This filter runs before it can be used by plugins. It is designed for non-web runtimes.
     
    156175     * @since 5.5.0
    157176     *
    158      * @param string $approved_environments The list of approved environment types. Possible values
    159      *                                      include 'development', 'stage', 'production'.
     177     * @param array $wp_environments The list of environment types. Possible values
     178     *                               include 'development', 'staging', 'production'.
    160179     */
    161     $approved_environments = apply_filters( 'wp_approved_environment_types', $approved_environments );
    162 
    163     $current_env = '';
    164 
    165     // Check if a environment variable has been set for max flexibility, if `getenv` is available on the system.
     180    $wp_environments = apply_filters( 'wp_environment_types', $wp_environments );
     181
     182    // Check if the environment variable has been set, if `getenv` is available on the system.
    166183    if ( function_exists( 'getenv' ) ) {
    167184        $has_env = getenv( 'WP_ENVIRONMENT_TYPE' );
     
    186203     *
    187204     * @param string $current_env The current environment type. Possible values
    188      *                            include 'development', 'stage', 'production'.
     205     *                            include 'development', 'staging', 'production'.
    189206     */
    190207    $current_env = apply_filters( 'wp_get_environment_type', $current_env );
    191208
    192209    // Make sure the environment is an allowed one, and not accidentally set to an invalid value.
    193     if ( ! in_array( $current_env, $approved_environments, true ) ) {
     210    if ( ! in_array( $current_env, $wp_environments, true ) ) {
    194211        $current_env = 'production';
    195212    }
     
    268285    require ABSPATH . '.maintenance';
    269286    // If the $upgrading timestamp is older than 10 minutes, consider maintenance over.
    270     if ( ( time() - $upgrading ) >= 600 ) {
     287    if ( ( time() - $upgrading ) >= 10 * MINUTE_IN_SECONDS ) {
    271288        return false;
    272289    }
Note: See TracChangeset for help on using the changeset viewer.