Skip to content

Instantly share code, notes, and snippets.

@georgestephanis
Last active October 13, 2020 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save georgestephanis/2937d3933f208367d3e176e0a6e3d3e9 to your computer and use it in GitHub Desktop.
Save georgestephanis/2937d3933f208367d3e176e0a6e3d3e9 to your computer and use it in GitHub Desktop.
This plugin adds a node to the adminbar clarifying the current environment setting if not production.
<?php
/*
* Plugin Name: Environment Notifier
* Plugin URI: http://github.com/georgestephanis/environment-notifier/
* Description: This plugin adds a node to the adminbar clarifying the current environment setting if not production.
* Author: George Stephanis
* Version: 1.0
* Author URI: http://wpspecialprojects.wordpress.com
*/
add_action( 'admin_bar_menu', function( $wp_admin_bar ) {
if ( ! function_exists( 'wp_get_environment_type' ) ) {
return;
}
$environment_type = wp_get_environment_type();
if ( 'production' === $environment_type ) {
return;
}
$wp_admin_bar->add_node( array(
'id' => 'environment',
'title' => ucwords( $environment_type ),
'parent' => 'top-secondary',
'meta' => array(
'class' => "environment-{$environment_type}",
)
) );
wp_register_style( 'environment-notifier', null );
wp_enqueue_style( 'environment-notifier' );
wp_add_inline_style( 'environment-notifier', '#wp-admin-bar-environment > .ab-item { background-color: #800; }' );
} );
@georgestephanis
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment