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:
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!
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- You must be logged in to reply to this topic.