Skip to content

Instantly share code, notes, and snippets.

@DrewAPicture
Created October 27, 2012 04:09
Show Gist options
  • Save DrewAPicture/3962905 to your computer and use it in GitHub Desktop.
Save DrewAPicture/3962905 to your computer and use it in GitHub Desktop.
Add Network plugins links to WordPress Toolbar
/**
* Add plugin page links to Toolbar in Multisite
*
* Adds Toolbar link to the 'Plugins' list page in Network Admin
* Adds Toolbar link to 'Add New Plugin' in Network Admin
* @uses global $wp_admin_bar
*/
function ww_ms_plugin_toolbar_links() {
global $wp_admin_bar;
// Don't show for logged out users or single site mode.
if ( ! is_user_logged_in() || ! is_multisite() )
return;
// Show only when the user has at least one site, or they're a super admin.
if ( count( $wp_admin_bar->user->blogs ) < 1 && ! is_super_admin() )
return;
// First, pre-emptively remove a couple Network Admin menu items. We'll add them back later.
$wp_admin_bar->remove_node('network-admin-u'); // Network Admin > Users
$wp_admin_bar->remove_node('network-admin-v'); // Network Admin > Visit Network
// Add a link to the Network > Plugins page.
$wp_admin_bar->add_node( array(
'parent' => 'network-admin',
'id' => 'network-admin-p',
'title' => __( 'Plugins' ),
'href' => network_admin_url( 'plugins.php' ),
) );
// Add a link to the Network > Add New Plugin page.
$wp_admin_bar->add_node( array(
'parent' => 'network-admin',
'id' => 'network-admin-pi',
'title' => __( 'Install Plugin' ),
'href' => network_admin_url( 'plugin-install.php' ),
) );
// Re-add the Users link after Plugins
$wp_admin_bar->add_node( array(
'parent' => 'network-admin',
'id' => 'network-admin-u',
'title' => __( 'Users' ),
'href' => network_admin_url( 'users.php' ),
) );
// Re-add the Visit Network link at the very end.
$wp_admin_bar->add_node( array(
'parent' => 'network-admin',
'id' => 'network-admin-v',
'title' => __( 'Visit Network' ),
'href' => network_home_url(),
) );
}
add_action( 'wp_before_admin_bar_render', 'ww_ms_plugin_toolbar_links' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment