Get rid of “My Sites” admin bar menu in MultiSite

By default WordPress (3.3.1) performs a check when generates the admin bar object if current user have sites. The “My Site” menu is displayed if it does. That’s okey for multisites’ general purpose but my point is that current user don’t need that extra menu if it owns just one site. Hopefully it is quite easy to hook core and alter that behaviour using the ‘wp_before_admin_bar_render’ action. Here’s my solution.

class My_Network {

	public static function clean_admin_bar() {
		global $wp_admin_bar;

		if ( count( $wp_admin_bar->user->blogs ) > 1 || is_super_admin() ) return;

		$wp_admin_bar->remove_menu( 'my-sites' );
	}
}
add_action( 'wp_before_admin_bar_render', array( 'My_Network', 'clean_admin_bar' ) );

We basicly check wheather user is super admin or is registered to more than one site. If it’s not we wipe the whole “My Sites” stuff leaving the admin bar as it’s in any regular WordPress installation.

Leave a Reply