Setting up environment in wordpress
In wordpress new function this environment function added from 5.5. In this tutorial we can learn how to use this. By default this wp environment has following values that is production, local, development and staging.
The environment needs to be set up in the wp-config.php file. Like the below example in that we have used production you can change according to the environment you are going to setup.
define( 'WP_ENVIRONMENT_TYPE', 'staging' );
How to use it in your plugin or theme ?
Below is the example for using that.
switch ( wp_get_environment_type() ) {
case 'local':
case 'development':
do_nothing();
break;
case 'staging':
do_staging_thing();
break;
case 'production':
default:
do_production_thing();
break;
}