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:
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:
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!
]]>Hello,
I really like the “Display Environment Type” plugin and I use it on my WordPress site. I don’t know exactly what update this happened with, but I recently created a “staging” site for testing and realized that your plugin stopped working!
I deactivated all my plugins and left yours active.
I activated one by one and realized that as soon as I activated the “WPForms Lite” plugin, the word “Staging” disappears and the word “Production” appears incorrectly.
Can you help?
Thanks.
The plugin returns the WP Engine staging as Production
]]>Nice question.
Would it be possible to define a REST API in this plugin that can be used by other installations to get the custom colors from the url defined in the plugin?
You could then define the custom colors on one (or more) source site(s) and have the other sites use that source site to get the definitions from.
That way, you can have your own set of definitions which could be available to all site that require it. Ofcourse there still needs to be the default if the definition url is not available (reachable).