WordPress Environment Type and Its Significance

WordPress added ability to define environment type around 5.5.

What:-

WordPress environment type is just a name used to define specific configuration/setup of WordPress(e.g development, staging).

It might affect the behaviour of the WordPress core. It also gives an opportunity/standard way to hosting companies, plugin and theme developers to react to the specific setup.

You could either use a php environment variable named WP_ENVIRONMENT_TYPE or define a constant with the same name to set it.

The currently allowed values are:-

  • local
  • development
  • staging
  • production

If a valid value is not specified, it falls back to ‘production’.

Usage:-

You can either define as environment variable or using constant. I prefer using constant in the wp-config.php

define( 'WP_ENVIRONMENT_TYPE', 'development' );

Existing usage in WordPress core:-

At the moment, the use of environment type is very limited.

In the WordPress core, it is used for the following purpose:-

  • To set debug mode on(WP_DEBUG) if the value is set to ‘development’
  • In the Site Health panel
    • to disable http tests if it is set to ‘development’
    • to mark some of the high impact issues as recommended action instead of critical on the status panel.
    • to show cache info if environment type is set to ‘production’ (by you or defaults)
  • To enable application password support for local development if the value is set to ‘local’. It won’t require https( which is required by default to enable application password in WordPress)

FAQ:-

  1. How do I find out the current environment of my WordPress setup?
    • If you are a site admin, visit dashboard->Tools -> Site Health -> Info->WordPress.
    • If you are a developer, you can use wp_get_environment_type() function.
  2. Can I set the environment via plugin?
    • Yes, but it will have no significance other than causing confusion. wp_get_environment_type() checks this only once(before plugins are loaded) and sets a static variable for further calls.
    • Avoid defining it in your plugins. Define it in wp-config.php
  3. What happens if I do not specify a valid value or I do not specify a value at all?
    • WordPress will consider the environment to be ‘production’.

References


Comments

Leave a Reply

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