Skip to content

How-to Guides

Technical References

Differentiate environments in code

We provide the VIP_GO_APP_ENVIRONMENT constant, which is populated with the name of the environment. This allows you to conditionally load code on a particular environment, or to avoid a particular environment.

Here’s an example of preventing code from running on production.

$disallowed_debug_envs = array(
    'production',
    'preprod',
);
if ( ! in_array( VIP_GO_APP_ENVIRONMENT, $disallowed_debug_envs, true ) ) {
    error_log( 'Some debugging information can go here and will never run on production or pre-production' );
}

Alternatively, you can have code which only runs on production:

if ( 'production' === VIP_GO_APP_ENVIRONMENT ) {
    // This code only runs on production, perhaps 
    // configuration for a live service
} else {
    // This code runs everywhere except production
}

For your local development environment, you may wish to set the VIP_GO_APP_ENVIRONMENT constant in wp-config.php. If the VIP_GO_APP_ENVIRONMENT constant is not set explicitly, the value will default to false. The value of VIP_GO_APP_ENVIRONMENT matches that in the site domain and also the branch tracked by that environment, e.g. the environment https://vipclientcom-develop.go-vip.net tracks the develop branch in Git, and has the environment name develop, therefore VIP_GO_APP_ENVIRONMENT contains the string develop.

Last updated: November 20, 2020