Skip to content

Instantly share code, notes, and snippets.

@dnaber-de
Last active July 13, 2017 21:28
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dnaber-de/5219882 to your computer and use it in GitHub Desktop.
Save dnaber-de/5219882 to your computer and use it in GitHub Desktop.
WordPress Plugin to show the Server Address (IP) in Admin-Bar
<?php
/**
* Plugin Name: dna IP to Admin Bar
* Plugin URI: https://gist.github.com/dnaber-de/5219882
* Description: Shows the current Server IP in the Admin Bar. (Requires PHP 5.3)
* Author: David Naber
* Author URI: http://dnaber.de/
* Version: 2013.03.22
* License: MIT
* License URI: http://opensource.org/licenses/mit-license.php
*/
namespace dna\ip_to_admin_bar;
if ( ! function_exists( 'add_filter' ) )
return;
add_action( 'plugins_loaded', array( Plugin::get_instance(), 'init_plugin' ) );
class Plugin {
/**
* the plugin instance
*
* @var Plugin
*/
private static $instance = NULL;
/**
* get the plugin instance
*
* @return Plugin
*/
public static function get_instance() {
if ( NULL === self::$instance )
self::$instance = new self;
return self::$instance;
}
/**
* hook in
*
* @wp-hook plugins_loaded
*/
public function init_plugin() {
add_action( 'wp_before_admin_bar_render', array( $this, 'admin_bar' ) );
}
/**
* add a item to the admin bar
*
* @wp-hook wp_before_admin_bar_render
* @global $wp_admin_bar;
* @return
*/
public function admin_bar() {
$server_addrss = $_SERVER[ 'SERVER_ADDR' ];
$GLOBALS[ 'wp_admin_bar' ]->add_menu(
array(
'id' => 'dna-ip-addr',
'title' => $server_addrss,
'href' => '#'
)
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment