Created
May 30, 2013 05:48
-
-
Save coreymckrill/5675926 to your computer and use it in GitHub Desktop.
If your WordPress deployment has multiple stages (ie local, staging, production), it can be helpful to have a visual reminder of which stage you are currently viewing in the browser. This adds a colorful box to the Admin Bar displaying the current environment, based on the value of WP_ENV defined in the wp-config file. Drop it into mu-plugins.
This file contains hidden or 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 Flag | |
* Description: Show the current environment (ie. local, staging, production) in the Admin Bar. | |
* Version: 1.0 | |
* Author: Corey McKrill | |
* Author URI: http://coreymckrill.com/ | |
* License: GNU General Public License v2.0 | |
* License URI: http://www.gnu.org/licenses/gpl-2.0.html | |
*/ | |
if ( ! class_exists( 'CMM_Environment_Flag' ) ) { | |
class CMM_Environment_Flag { | |
function __construct() { | |
add_action( 'admin_bar_menu', array( &$this, 'add_flag' ), 15 ); | |
add_action( 'wp_before_admin_bar_render', array( &$this, 'flag_style' ), 99 ); | |
} | |
function add_flag() { | |
global $wp_admin_bar; | |
if ( ! is_user_logged_in() ) { return; } | |
if ( ! is_super_admin() || ! is_admin_bar_showing() ) { return; } | |
if ( ! defined( 'WP_ENV' ) || ! is_string( WP_ENV ) ) { return; } | |
$args = array( | |
'id' => 'environment-flag-' . WP_ENV, | |
'title' => ucwords( WP_ENV ), | |
'parent' => false | |
); | |
$wp_admin_bar->add_node( $args ); | |
} | |
function flag_style() { ?> | |
<style type="text/css"> | |
#wpadminbar ul li#wp-admin-bar-environment-flag-local { background: orangered; } | |
#wpadminbar ul li#wp-admin-bar-environment-flag-staging { background: yellow; } | |
#wpadminbar ul li#wp-admin-bar-environment-flag-production { background: green; } | |
</style> | |
<?php } | |
} // end class | |
new CMM_Environment_Flag(); | |
} // end if |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment