wp_get_environment_type

The timeline below displays how wordpress function wp_get_environment_type has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.1

/**
 * 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'.
 *
 * @since 5.5.0
 * @since 5.5.1 Added the 'local' type.
 * @since 5.5.1 Removed the ability to alter the list of types.
 *
 * @return string The current environment type.
 */
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;
}

WordPress Version: 5.9

/**
 * 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'.
 *
 * @since 5.5.0
 * @since 5.5.1 Added the 'local' type.
 * @since 5.5.1 Removed the ability to alter the list of types.
 *
 * @return string The current environment type.
 */
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')) {
        $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;
}

WordPress Version: 5.6

/**
 * 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'.
 *
 * @since 5.5.0
 * @since 5.5.1 Added the 'local' type.
 * @since 5.5.1 Removed the ability to alter the list of types.
 *
 * @return string The current environment type.
 */
function wp_get_environment_type()
{
    static $current_env = '';
    if ($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')) {
        $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;
}

WordPress Version: 5.1

/**
 * 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 include 'local', 'development', 'staging', 'production'.
 * If not set, the type defaults to 'production'.
 *
 * @since 5.5.0
 * @since 5.5.1 Added the 'local' type.
 * @since 5.5.1 Removed the ability to alter the list of types.
 *
 * @return string The current environment type.
 */
function wp_get_environment_type()
{
    static $current_env = '';
    if ($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')) {
        $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;
}

WordPress Version: 5.5

/**
 * 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 include 'development', 'staging', 'production'. If not set,
 * the type defaults to 'production'.
 *
 * @since 5.5.0
 *
 * @return string The current environment type.
 */
function wp_get_environment_type()
{
    static $current_env = '';
    if ($current_env) {
        return $current_env;
    }
    $wp_environments = array('development', 'staging', '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;
    }
    // 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')) {
        $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;
}