Skip to content

Instantly share code, notes, and snippets.

@scribu
Created September 10, 2011 16:23
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scribu/1208492 to your computer and use it in GitHub Desktop.
Save scribu/1208492 to your computer and use it in GitHub Desktop.
Network Quick-Switch
<?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;
}
@scribu
Copy link
Author

scribu commented Sep 10, 2011

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment