Title: Feature request: extensible environment types
Last modified: December 18, 2024

---

# Feature request: extensible environment types

 *  Resolved [erniecom](https://wordpress.org/support/users/erniecom/)
 * (@erniecom)
 * [1 year, 5 months ago](https://wordpress.org/support/topic/feature-request-extensible-environment-types/)
 * I wanted to add a more descriptive environment type to support for instance Lando
   dev environment (on top of Docker). With the help of ChatGPT I found the following
   code to replace display-environment-type/app/Plugin.php method get_env_type_name:
 *     ```wp-block-code
       public static function get_env_type_name( $env_type ) {    switch ( $env_type ) {        case 'local':            $name = __( 'Local', 'display-environment-type' );            break;        case 'development':            $name = __( 'Development', 'display-environment-type' );            break;        case 'staging':            $name = __( 'Staging', 'display-environment-type' );            break;        case 'production':            $name = __( 'Production', 'display-environment-type' );            break;        default:            $name = __( 'Production', 'display-environment-type' );    }    /**     * Filter the environment type name.     *     * @param string $name     The translated environment name.     * @param string $env_type The environment type key.     */    return apply_filters( 'display_environment_type_name', $name, $env_type );}
       ```
   
 * User code to in theme or plugin to add custom environment types:
 *     ```wp-block-code
       add_filter( 'display_environment_type_name', function ( $name, $env_type ) {    // Map custom environment types to user-friendly names.    $custom_env_types = [        'lando' => __( 'Lando', 'display-environment-type' ),        'custom' => __( 'Custom Environment', 'display-environment-type' ),    ];    // Return custom name if it exists, otherwise fallback to the original name.    return isset( $custom_env_types[ $env_type ] ) ? $custom_env_types[ $env_type ] : $name;}, 10, 2 );
       ```
   
 * Would you please consider adding this small change in your code for our convenience?
   Thank you!
    -  This topic was modified 1 year, 5 months ago by [erniecom](https://wordpress.org/support/users/erniecom/).

Viewing 5 replies - 1 through 5 (of 5 total)

 *  Plugin Contributor [Roy Tanck](https://wordpress.org/support/users/roytanck/)
 * (@roytanck)
 * [1 year, 5 months ago](https://wordpress.org/support/topic/feature-request-extensible-environment-types/#post-18206059)
 * Thank you for your suggestion. Support for custom environment types was explicitly
   removed in WP 5.5.1: [https://make.wordpress.org/core/2020/08/27/wordpress-environment-types/](https://make.wordpress.org/core/2020/08/27/wordpress-environment-types/).
   It appears that your code relies on the `$env_type` parameter being set to something
   other than the four officially allowed values? That could be problematic, considering
   that WP (according to the blog post) resets any other values to `production`.
 *  Thread Starter [erniecom](https://wordpress.org/support/users/erniecom/)
 * (@erniecom)
 * [1 year, 5 months ago](https://wordpress.org/support/topic/feature-request-extensible-environment-types/#post-18206334)
 * You are right. I tested it and only the agreed environment types are passed on
   by core. Still the same, the filter allows a user to change the Notification 
   text that is seen in the admin menu. I changed the filter codo to test for an
   environment variable that only Lando sets in its http server and now it displays
   _Lando_ in stead of _Local_:
 *     ```wp-block-code
       add_filter( 'display_environment_type_name', function ( $name, $env_type ) {  // Map custom environment types to user-friendly names.  $custom_env_types = [];  if ($_ENV['LANDO']=='ON'){    $custom_env_types['local'] = __( 'Lando', 'display-environment-type' );  }  // Return custom name if it exists, otherwise fallback to the original name.  return isset( $custom_env_types[ $env_type ] ) ? $custom_env_types[ $env_type ] : $name;}, 10, 2 );
       ```
   
 * I also added filter code that shows the environment type in wp-login.php, which
   was what I was originally looking for. It would be another valuable addition 
   to your already appreciated plug-in. When I see a wrong notice there I avoid 
   both that of logging in and the risk of forgetting to look at the top line notice.
   Two notices is better than one for some.
 *  Plugin Contributor [Roy Tanck](https://wordpress.org/support/users/roytanck/)
 * (@roytanck)
 * [1 year, 5 months ago](https://wordpress.org/support/topic/feature-request-extensible-environment-types/#post-18206506)
 * I think I agree that adding the hook would increase the plugin’s flexibility.
   I’ll add it in the next release.
 * Thanks for suggesting a notice on the login screen. I’ll definitely look into
   that.
 *  Thread Starter [erniecom](https://wordpress.org/support/users/erniecom/)
 * (@erniecom)
 * [1 year, 5 months ago](https://wordpress.org/support/topic/feature-request-extensible-environment-types/#post-18206830)
 * I can share the code here as far as I got it:
 *     ```wp-block-code
       add_filter( 'login_message', function ( $message ) {  // Get the environment type using the WP_ENVIRONMENT_TYPE constant.  $environment_type = defined( 'WP_ENVIRONMENT_TYPE' ) ? WP_ENVIRONMENT_TYPE : 'unknown';  // Add a styled message to the login page.  $environment_message = sprintf(    '<p style="background: #f5f5f5; border-left: 4px solid %s; padding: 10px; margin-bottom: 20px; font-size: 14px;">                <strong>Environment:</strong> %s                        </p>',                        // Choose a color based on the environment type.                        $environment_type === 'production' ? '#d9534f' : ($environment_type === 'staging' ? '#f0ad4e' : '#5bc0de'),                                 ucfirst( $environment_type )  );  // Append the environment message to the existing login message.  return $environment_message . $message;});
       ```
   
 * It directly reads the constant WP_ENVIRONMENT_TYPE but it might read as well 
   take it from wp_get_environment_type() or better still, from your code so the
   new hook will work for both.
    -  This reply was modified 1 year, 5 months ago by [erniecom](https://wordpress.org/support/users/erniecom/).
 *  Plugin Contributor [Roy Tanck](https://wordpress.org/support/users/roytanck/)
 * (@roytanck)
 * [1 year, 5 months ago](https://wordpress.org/support/topic/feature-request-extensible-environment-types/#post-18210696)
 * I’ve just released version 1.3.4 which adds the hook (and is properly tested 
   with WP 1.3.4). Thanks for the suggestion!
 * As for the login screen, I’m wondering whether that should be optional (which
   would require adding settings to the plugin), and I want to investigate different
   ways that could be displayed. Definitely something I’ll consider for a future
   version.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Feature request: extensible environment types’ is closed to new replies.

 * ![](https://ps.w.org/display-environment-type/assets/icon-256x256.png?rev=2366333)
 * [Display Environment Type](https://wordpress.org/plugins/display-environment-type/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/display-environment-type/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/display-environment-type/)
 * [Active Topics](https://wordpress.org/support/plugin/display-environment-type/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/display-environment-type/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/display-environment-type/reviews/)

## Tags

 * [feature request](https://wordpress.org/support/topic-tag/feature-request/)

 * 5 replies
 * 2 participants
 * Last reply from: [Roy Tanck](https://wordpress.org/support/users/roytanck/)
 * Last activity: [1 year, 5 months ago](https://wordpress.org/support/topic/feature-request-extensible-environment-types/#post-18210696)
 * Status: resolved