mirror of
https://github.com/WordPress/WordPress.git
synced 2024-12-22 17:18:32 +01:00
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. Built from https://develop.svn.wordpress.org/trunk@48188 git-svn-id: http://core.svn.wordpress.org/trunk@47957 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
cb9c2ae83f
commit
5771b7dff9
@ -134,7 +134,7 @@ function wp_check_php_mysql_versions() {
|
|||||||
* The type can be set via the `WP_ENVIRONMENT_TYPE` global system variable,
|
* 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.
|
* a constant of the same name, or the {@see 'wp_get_environment_type'} filter.
|
||||||
*
|
*
|
||||||
* Possible values include 'development', 'stage', 'production'. If not set,
|
* Possible values include 'development', 'staging', 'production'. If not set,
|
||||||
* the type defaults to 'production'.
|
* the type defaults to 'production'.
|
||||||
*
|
*
|
||||||
* @since 5.5.0
|
* @since 5.5.0
|
||||||
@ -142,27 +142,44 @@ function wp_check_php_mysql_versions() {
|
|||||||
* @return string The current environment type.
|
* @return string The current environment type.
|
||||||
*/
|
*/
|
||||||
function wp_get_environment_type() {
|
function wp_get_environment_type() {
|
||||||
$approved_environments = array(
|
static $current_env = '';
|
||||||
|
|
||||||
|
if ( $current_env ) {
|
||||||
|
return $current_env;
|
||||||
|
}
|
||||||
|
|
||||||
|
$wp_environments = array(
|
||||||
'development',
|
'development',
|
||||||
'stage',
|
'staging',
|
||||||
'production',
|
'production',
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Check if the environment variable has been set, if `getenv` is available on the system.
|
||||||
|
if ( function_exists( 'getenv' ) ) {
|
||||||
|
$has_env = getenv( 'WP_ENVIRONMENT_TYPES' );
|
||||||
|
if ( false !== $has_env ) {
|
||||||
|
$wp_environments = explode( ',', $has_env );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fetch the environment types from a constant, this overrides the global system variable.
|
||||||
|
if ( defined( 'WP_ENVIRONMENT_TYPES' ) ) {
|
||||||
|
$wp_environments = WP_ENVIRONMENT_TYPES;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Filters the list of approved environment types.
|
* Filters the list of supported environment types.
|
||||||
*
|
*
|
||||||
* This filter runs before it can be used by plugins. It is designed for non-web runtimes.
|
* This filter runs before it can be used by plugins. It is designed for non-web runtimes.
|
||||||
*
|
*
|
||||||
* @since 5.5.0
|
* @since 5.5.0
|
||||||
*
|
*
|
||||||
* @param string $approved_environments The list of approved environment types. Possible values
|
* @param array $wp_environments The list of environment types. Possible values
|
||||||
* include 'development', 'stage', 'production'.
|
* include 'development', 'staging', 'production'.
|
||||||
*/
|
*/
|
||||||
$approved_environments = apply_filters( 'wp_approved_environment_types', $approved_environments );
|
$wp_environments = apply_filters( 'wp_environment_types', $wp_environments );
|
||||||
|
|
||||||
$current_env = '';
|
// Check if the environment variable has been set, if `getenv` is available on the system.
|
||||||
|
|
||||||
// Check if a environment variable has been set for max flexibility, if `getenv` is available on the system.
|
|
||||||
if ( function_exists( 'getenv' ) ) {
|
if ( function_exists( 'getenv' ) ) {
|
||||||
$has_env = getenv( 'WP_ENVIRONMENT_TYPE' );
|
$has_env = getenv( 'WP_ENVIRONMENT_TYPE' );
|
||||||
if ( false !== $has_env ) {
|
if ( false !== $has_env ) {
|
||||||
@ -185,12 +202,12 @@ function wp_get_environment_type() {
|
|||||||
* @since 5.5.0
|
* @since 5.5.0
|
||||||
*
|
*
|
||||||
* @param string $current_env The current environment type. Possible values
|
* @param string $current_env The current environment type. Possible values
|
||||||
* include 'development', 'stage', 'production'.
|
* include 'development', 'staging', 'production'.
|
||||||
*/
|
*/
|
||||||
$current_env = apply_filters( 'wp_get_environment_type', $current_env );
|
$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.
|
// Make sure the environment is an allowed one, and not accidentally set to an invalid value.
|
||||||
if ( ! in_array( $current_env, $approved_environments, true ) ) {
|
if ( ! in_array( $current_env, $wp_environments, true ) ) {
|
||||||
$current_env = 'production';
|
$current_env = 'production';
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -267,7 +284,7 @@ function wp_is_maintenance_mode() {
|
|||||||
|
|
||||||
require ABSPATH . '.maintenance';
|
require ABSPATH . '.maintenance';
|
||||||
// If the $upgrading timestamp is older than 10 minutes, consider maintenance over.
|
// If the $upgrading timestamp is older than 10 minutes, consider maintenance over.
|
||||||
if ( ( time() - $upgrading ) >= 600 ) {
|
if ( ( time() - $upgrading ) >= 10 * MINUTE_IN_SECONDS ) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @global string $wp_version
|
||||||
*/
|
*/
|
||||||
$wp_version = '5.5-alpha-48187';
|
$wp_version = '5.5-alpha-48188';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||||
|
Loading…
Reference in New Issue
Block a user