Last active
March 8, 2016 19:56
-
-
Save trepmal/f744c422d99e7b5a1f99 to your computer and use it in GitHub Desktop.
Show selected hosts
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: Host Info | |
function hostinfo_web_host() { | |
return apply_filters( 'hostinfo_web_host', gethostname() ); | |
} | |
function hostinfo_db_host() { | |
global $wpdb; | |
if ( isset( $wpdb->current_host ) ) { | |
$db_host = explode( ':', $wpdb->current_host ); | |
$db_host = array_shift( $db_host ); | |
} else { | |
$db_host = DB_HOST; | |
} | |
return apply_filters( 'hostinfo_db_host', $db_host ); | |
} | |
function hostinfo_admin_bar_menu( $wp_admin_bar ) { | |
$hosts = array(); | |
$hosts[] = hostinfo_web_host(); | |
$hosts[] = hostinfo_db_host(); | |
if ( strlen( implode( $hosts ) ) <= 30 ) { | |
$wp_admin_bar->add_menu( array( | |
'id' => 'seleted-hosts', | |
'title' => implode( ' / ', $hosts ), | |
) ); | |
} else { | |
$wp_admin_bar->add_menu( array( | |
'id' => 'seleted-hosts', | |
'title' => 'Hosts', | |
) ); | |
foreach ( $hosts as $k => $h ) { | |
$wp_admin_bar->add_menu( array( | |
'parent' => 'seleted-hosts', | |
'id' => 'seleted-hosts-'. $k, | |
'title' => $h, | |
) ); | |
} | |
} | |
} | |
add_action( 'admin_bar_menu', 'hostinfo_admin_bar_menu', 100 ); | |
function hostinfo_login_footer() { | |
echo hostinfo_web_host() . ' // ' . hostinfo_db_host(); | |
} | |
// add_action( 'login_footer', 'hostinfo_login_footer', 100 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment