public
Created

Network Quick-Switch

  • Download Gist
network-quick-switch.php
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
<?php
/*
Plugin Name: Network Quick-Switch
Version: 1.0
Description: Adds the ability to quickly switch between site and network admin screens.
Author: scribu
Author URI: http://scribu.net/
*/
 
if ( is_multisite() ) {
add_action( 'admin_footer', 'network_quick_switch' );
add_filter( 'admin_user_info_links', 'remove_network_link' );
}
 
function network_quick_switch() {
$current_screen = get_current_screen();
 
if ( is_network_admin() ) {
$base = 'admin_url';
$text = __( 'Site Admin' );
} else {
$base = 'network_admin_url';
$text = __( 'Network Admin' );
}
 
if ( in_array( $current_screen->parent_file, array( 'plugins.php', 'themes.php', 'users.php' ) ) ) {
$url = $base( $current_screen->parent_file );
} else {
$url = $base();
}
?>
<a id="network-quick-switch" href="<?php echo $url; ?>"><?php echo $text; ?></a>
 
<style type="text/css">
#network-quick-switch {
background-color: #f1f1f1;
border-radius: 3px;
float: right;
margin: 4px 8px 0 0;
padding: 3px 8px;
}
</style>
 
<script type="text/javascript">
jQuery(function ($) {
$('#user_info').after( $('#network-quick-switch') );
});
</script>
<?php
}
 
function remove_network_link( $links ) {
unset( $links[10] );
 
return $links;
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.