Bootstrap/Load: Introduce `wp_get_environment_type()` to retrieve the current environment type.

The type can be set via the `WP_ENVIRONMENT_TYPE` global system variable, a constant of the same name, or the `wp_get_environment_type` filter.

Possible values include `development`, `stage`, `production'. If not set, the type defaults to `production`.

Props Clorith, krogsgard, joostdevalk, frank-klein, Maelacuna, nathanrice, grierson, jchristopher, davidvee, jackfungi, johnbillion, tabrisrp, knutsp, ev3rywh3re, Rastaban, danielbachhuber, pfefferle, audrasjb, SergeyBiryukov.
Fixes #33161.
Built from https://develop.svn.wordpress.org/trunk@47919


git-svn-id: http://core.svn.wordpress.org/trunk@47693 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2020-06-06 11:07:12 +00:00
parent 0b9a800512
commit b19c1627e5
2 changed files with 70 additions and 1 deletions

View File

@ -128,6 +128,75 @@ function wp_check_php_mysql_versions() {
}
}
/**
* Retrieves the current environment type.
*
* The type can be set via the `WP_ENVIRONMENT_TYPE` global system variable,
* a constant of the same name, or the {@see 'wp_get_environment_type'} filter.
*
* Possible values include 'development', 'stage', 'production'. If not set,
* the type defaults to 'production'.
*
* @since 5.5.0
*
* @return string The current environment type.
*/
function wp_get_environment_type() {
$approved_environments = array(
'development',
'stage',
'production',
);
/**
* Filters the list of approved environment types.
*
* This filter runs before it can be used by plugins. It is designed for non-web runtimes.
*
* @since 5.5.0
*
* @param string $approved_environments The list of approved environment types. Possible values
* include 'development', 'stage', 'production'.
*/
$approved_environments = apply_filters( 'wp_approved_environment_types', $approved_environments );
$current_env = '';
// Check if a environment variable has been set for max flexibility, if `getenv` is available on the system.
if ( function_exists( 'getenv' ) ) {
$has_env = getenv( 'WP_ENVIRONMENT_TYPE' );
if ( false !== $has_env ) {
$current_env = $has_env;
}
}
// Fetch the environment from a constant, this overrides the global system variable.
if ( defined( 'WP_ENVIRONMENT_TYPE' ) ) {
$current_env = WP_ENVIRONMENT_TYPE;
}
/**
* Filters the current environment type.
*
* This filter runs before it can be used by plugins. It is designed for
* non-web runtimes. The value returned by this filter has a priority over both
* the `WP_ENVIRONMENT_TYPE` system variable and a constant of the same name.
*
* @since 5.5.0
*
* @param string $current_env The current environment type. Possible values
* include 'development', 'stage', 'production'.
*/
$current_env = apply_filters( 'wp_get_environment_type', $current_env );
// Make sure the environment is an allowed one, and not accidentally set to an invalid value.
if ( ! in_array( $current_env, $approved_environments, true ) ) {
$current_env = 'production';
}
return $current_env;
}
/**
* Don't load all of WordPress when handling a favicon.ico request.
*

View File

@ -13,7 +13,7 @@
*
* @global string $wp_version
*/
$wp_version = '5.5-alpha-47915';
$wp_version = '5.5-alpha-47919';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.