In WordPress new function this environment function is added from 5.5. In this tutorial, we can learn how to use this. By default, this wp environment has the following values that are 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 set up.

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;
}

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *