-
Notifications
You must be signed in to change notification settings - Fork 7
ToolKit
Methods:
-
get_environment()- Returns value of
WP_ENV, if defined (for example, in wp-config.php) - Returns value of environmental variable
ENVIRONMENT, if defined. Supports phpdotenv. - Default return of "production" when no variables are set.
- Returns value of
-
is_production()- Returns true ifget_environment()== "production", else false.
Setting Environment/Environmental Variables:
For example, if you wanted to set the development environment to "development" or "staging," you could:
- In wp-config.php:
define( 'WP_ENV', 'staging' ); - Create a
.envfile in your WordPress (or plugin/theme, if supported) root containing:ENVIRONMENT=staging. You may also set any other environmental variables in the.envfile(s) as desired (reference). - Define the environmental variable
ENVIRONMENTin your OS.
The choices of the using "production," etc string values and .env files was chosen to be compatible with Sage and Roots conventions.
Order of Operations:
This order can be useful for testing. Although the WP_ENV constant always takes precedence over anything else, if absent and if supported by your plugin/theme, you could set ENVIRONMENT=production in your WordPress root .env but set ENVIRONMENT=development in your plugin/theme's .env.
This would allow you to test the site in production mode, however, keep the plugin/theme in development mode (which, as another example, you may have configured not to cache scripts/certain variables in non-production mode).