Make WordPress Core

Ticket #33161: 33161.diff

File 33161.diff, 2.3 KB (added by SergeyBiryukov, 3 years ago)
  • src/wp-includes/load.php

     
    142142 * @return string The current environment type.
    143143 */
    144144function wp_get_environment_type() {
    145         $approved_environments = array(
     145        $wp_environments = array(
    146146                'development',
    147147                'stage',
    148148                'production',
    149149        );
    150150
     151        // Check if the environment variable has been set, if `getenv` is available on the system.
     152        if ( function_exists( 'getenv' ) ) {
     153                $has_env = getenv( 'WP_ENVIRONMENT_TYPES' );
     154                if ( false !== $has_env ) {
     155                        $wp_environments = explode( ',', $has_env );
     156                }
     157        }
     158
     159        // Fetch the environment types from a constant, this overrides the global system variable.
     160        if ( defined( 'WP_ENVIRONMENT_TYPES' ) ) {
     161                $wp_environments = WP_ENVIRONMENT_TYPES;
     162        }
     163
    151164        /**
    152          * Filters the list of approved environment types.
     165         * Filters the list of supported environment types.
    153166         *
    154167         * This filter runs before it can be used by plugins. It is designed for non-web runtimes.
    155168         *
    156169         * @since 5.5.0
    157170         *
    158          * @param string $approved_environments The list of approved environment types. Possible values
    159          *                                      include 'development', 'stage', 'production'.
     171         * @param array $wp_environments The list of environment types. Possible values
     172         *                               include 'development', 'stage', 'production'.
    160173         */
    161         $approved_environments = apply_filters( 'wp_approved_environment_types', $approved_environments );
     174        $wp_environments = apply_filters( 'wp_environment_types', $wp_environments );
    162175
    163176        $current_env = '';
    164177
    165         // Check if a environment variable has been set for max flexibility, if `getenv` is available on the system.
     178        // Check if the environment variable has been set, if `getenv` is available on the system.
    166179        if ( function_exists( 'getenv' ) ) {
    167180                $has_env = getenv( 'WP_ENVIRONMENT_TYPE' );
    168181                if ( false !== $has_env ) {
     
    190203        $current_env = apply_filters( 'wp_get_environment_type', $current_env );
    191204
    192205        // 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 ) ) {
     206        if ( ! in_array( $current_env, $wp_environments, true ) ) {
    194207                $current_env = 'production';
    195208        }
    196209