New Plugin Displays WordPress Environment Type for Admins

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 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. 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.


7 responses to “New Plugin Displays WordPress Environment Type for Admins”

  1. This is the first plugin on to make use of the new function

    Except Query Monitor of course ;-)

    It’s worth noting there are a couple of tickets in the 5.5.1 milestone which may potentially change the behaviour of this functionality, although they are yet to be discussed at length.

    Consider adding “local” as environment on WP_ENVIRONMENT_TYPE:
    Consider removing the ability to alter the list of environment types:

    • Interesting tickets! Thanks for sharing.

      Personally, I think defining a general list of environment types such as production, staging, development is crucial and it makes the terminology consistent between developers. Users also can be able to add their own environment types if needed, but not removing the core ones.

    • Jetpack too!

      Jetpack has had a “Staging Site” mode for sometime, but it was triggered through a list of known staging sites (e.g. the standard staging URL from a WP Engine site) or someone adding out specific filter/constant.

      I think it is a huge win that there is a standard way so now any non-production site will trigger Jetpack’s staging mode.

  2. Thank you for writing about my plugin. Just to clarify, it does also show the environment type for staging (yellow) and development (green) servers.

    On the front end, it’ll only display the environment type for admins only, while within wp-admin it’ll display for all users. There’s a filter hook to further customize this behavior to fit your use case.

  3. Thank you for sharing this information.

    It is also useful when using different database credentials, fixed paths or urls. You can store them all in one file, for example wp-config.php.

    The plugin is also very useful to tell clients on which environment they are working. This is to prevent that clients are working on staging but expect that they are working on production.

  4. This helps the gradual shift of power from developers to website implementers. It could make it easier to set up a staging site on cheap entry-level shared hosting.


Subscribe Via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

%d bloggers like this: