Skip to content

Write environment-specific code

The VIP Platform’s VIP_GO_APP_ENVIRONMENT constant and the WordPress function wp_get_environment_type() can both be used to customize environment-specific behavior in code. For example, a conditional statement could be used to set a variable with a different value depending on if the code is running on a production, development, or local environment. The VIP Platform constant and the WordPress function each return different values but can be used in a similar way.


The VIP_GO_APP_ENVIRONMENT constant is defined for each environment by the VIP Platform with the name of the VIP Platform environment. At a minimum, every VIP application has an environment named production. Additional environments may exist with names such as develop, staging, or preprod.

The VIP_GO_APP_ENVIRONMENT constant can be used to conditionally run code based on the environment to which the code has been deployed.

In this code example, VIP_GO_APP_ENVIRONMENT is used to restrict code to run only on the production environment:

if ( defined( 'VIP_GO_APP_ENVIRONMENT' ) && VIP_GO_APP_ENVIRONMENT === 'production' ) {
    // Run this only on production

In this code example, code is restricted from running on the production and preprod environments:

$disallowed_envs = array( 'production', 'preprod' );
if ( defined( 'VIP_GO_APP_ENVIRONMENT' ) && ! in_array( VIP_GO_APP_ENVIRONMENT, $disallowed_envs, true ) ) {
    // Run this code in all environments except prodution and preprod.

Using VIP_GO_APP_ENVIRONMENT in local environments

  • By default, VIP_GO_APP_ENVIRONMENT is already defined as local in a VIP Local Development Environment.
  • For other local development tools, such as VVV, the VIP_GO_APP_ENVIRONMENT constant is not pre-defined. To use the constant, define it as local in wp-config.php (e.g., define( 'VIP_GO_APP_ENVIRONMENT', 'local' ); ).
  • Never define VIP_GO_APP_ENVIRONMENT in vip-config.php or anywhere in the application code. It is already defined by the VIP Platform, so if the code is committed and deployed it will cause PHP warnings in the logs: Warning: Constant VIP_GO_APP_ENVIRONMENT already defined....

Using wp_get_environment_type()

The WordPress function wp_get_environment_type() can also be used to write environment-specific code in plugins or themes. wp_get_environment_type() can only be used after WordPress has fully loaded. As a result, it will not work as expected if added to vip-config.php, which loads before WordPress.

Unlike the value set in VIP_GO_APP_ENVIRONMENT, the output of wp_get_environment_type() is limited to four possible values: production, development, staging, and local. The VIP Platform sets the return value of wp_get_environment_type() based on the following mapping of common VIP Platform environment names:

VIP Platform environment namewp_get_environment_type() return value
local local
any other custom name
(preprod, staging, testing, uat, etc.)

Additional VIP Platform constants

Additional constants set by the VIP Platform with per-environment values can be used to customize environment-specific behavior. The constant name and its platform-set values are as follows:

  • VIP_GO_APP_BRANCH: The Git branch deploying to the environment (e.g., production, production-built, develop-built)
  • VIP_GO_APP_CURRENT_COMMIT_HASH: The Git commit SHA1 hash of the currently deployed code (e.g., e7ba94e2a07dc8f70e247660692164ce016b39ef)
  • VIP_GO_APP_ID: The environment’s unique numeric ID (e.g., 1234)
  • VIP_GO_APP_NAME: The application’s alias (e.g., mytestsite)

    Note that the VIP Platform constants listed above are not defined in a VIP Local Development Environment. As a best practice, code should always check that a constant is defined before using it, for example: if ( defined( 'VIP_GO_APP_NAME' ) ) { …

Listing the environment names of an application

Use the VIP-CLI command vip app [ID] to list the environments that belong to an application. The output from that command will also include the application ID, environment ID, name, type, and deploying branch for each listed environment.

Last updated: August 28, 2023

Relevant to

  • WordPress