Last active
October 13, 2020 13:56
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; }' ); | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
More details on
wp_get_environment_type()
-- https://make.wordpress.org/core/2020/08/27/wordpress-environment-types/