wp_get_environment_type
函数
wp_get_environment_type ( No parameters )
- 返回值
-
- (string) The current environment type.
- 定义位置
-
-
wp-includes/load.php
, line 191
-
wp-includes/load.php
- 引入
- 5.5.0
- 弃用
- –
Retrieves the current environment type.
The type can be set via the `WP_ENVIRONMENT_TYPE` global system variable,
or a constant of the same name.
Possible values are ‘local’, ‘development’, ‘staging’, and ‘production’.
If not set, the type defaults to ‘production’.
function wp_get_environment_type() { static $current_env = ''; if ( ! defined( 'WP_RUN_CORE_TESTS' ) && $current_env ) { return $current_env; } $wp_environments = array( 'local', 'development', 'staging', 'production', ); // Add a note about the deprecated WP_ENVIRONMENT_TYPES constant. if ( defined( 'WP_ENVIRONMENT_TYPES' ) && function_exists( '_deprecated_argument' ) ) { if ( function_exists( '__' ) ) { /* translators: %s: WP_ENVIRONMENT_TYPES */ $message = sprintf( __( 'The %s constant is no longer supported.' ), 'WP_ENVIRONMENT_TYPES' ); } else { $message = sprintf( 'The %s constant is no longer supported.', 'WP_ENVIRONMENT_TYPES' ); } _deprecated_argument( 'define()', '5.5.1', $message ); } // Check if the environment variable has been set, 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' ) && WP_ENVIRONMENT_TYPE ) { $current_env = WP_ENVIRONMENT_TYPE; } // Make sure the environment is an allowed one, and not accidentally set to an invalid value. if ( ! in_array( $current_env, $wp_environments, true ) ) { $current_env = 'production'; } return $current_env; }
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。