One of the minor but useful additions to WordPress 5.5 is the new wp_get_environment_type() function. It makes it possible for plugin and theme authors to do some interesting things based on whether a site is identified as staging, development, production, or some other custom environment type. In discussion on the original trac ticket, Marius Jensen suggested a few ways this function could be useful:

  • It’s a function used for grabbing the current environment, this is to ensure everyone fetches the values the same way (to avoid using different terms and such).
  • Outbound emails could be filtered, and if get_environment() isn’t set to production then send them to the developer, allowing for legitimate email tests in stage setups without worrying about emails reaching end users.
  • API endpoints where you want to use a test endpoint when not in production to prevent data pollution.
  • Providing a wp-admin notice for non-production sites so it’s much clearer that what you are doing now will/won’t affect the site your business relies on.

The new function is already getting put to use in WordPress developer Roy Tanck’s new plugin called Display Environment Type. It adds a prominent red notice to the top of the admin for Production. Custom environment types will be set to blue with a lightbulb icon. (The colors used in the plugin are fixed and not configurable to help avoid confusion across servers.)

The environment type only displays for admin users. Tankck’s plugin also adds the current environment type to WordPress’ At-a-glance widget:

This is the first plugin on WordPress.org to make use of the new function, but developers are planning to use in other unique ways.

“We are adding our own custom environment vars here at Pantheon so plugin authors have the option of doing this but it would be so nice to have this in core so plugin authors don’t need to write host specific code,” Pantehon developer advocate John Richards commented on the original ticket for the new function.

WordPress plugin developer Rene Hermenau said he will be implementing this new concept in his WP Staging plugin in the next update. WP Staging, which is currently active on more than 50,000 installs, allows users to quickly create an exact copy of their sites for staging or development purposes.

WordPress.com has also added support for environment types in VIP Go, allowing developers to run different code for their sites depending on if it’s in production, development, or any other custom environment type configuration.