Advertisements

wp_admin_bar_my_sites_menu

Definition:
function wp_admin_bar_my_sites_menu( $wp_admin_bar ) {}

Add the "My Sites/[Site Name]" menu and all submenus.

Parameters

  • $wp_admin_bar

Source code

function wp_admin_bar_my_sites_menu( $wp_admin_bar ) {

	global $wpdb;



	// 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;



	$wp_admin_bar->add_menu( array(

		'id'    => 'my-sites',

		'title' => __( 'My Sites' ),

		'href'  => admin_url( 'my-sites.php' ),

	) );



	if ( is_super_admin() ) {

		$wp_admin_bar->add_group( array(

			'parent' => 'my-sites',

			'id'     => 'my-sites-super-admin',

		) );



		$wp_admin_bar->add_menu( array(

			'parent' => 'my-sites-super-admin',

			'id'     => 'network-admin',

			'title'  => __('Network Admin'),

			'href'   => network_admin_url(),

		) );



		$wp_admin_bar->add_menu( array(

			'parent' => 'network-admin',

			'id'     => 'network-admin-d',

			'title'  => __( 'Dashboard' ),

			'href'   => network_admin_url(),

		) );

		$wp_admin_bar->add_menu( array(

			'parent' => 'network-admin',

			'id'     => 'network-admin-s',

			'title'  => __( 'Sites' ),

			'href'   => network_admin_url( 'sites.php' ),

		) );

		$wp_admin_bar->add_menu( array(

			'parent' => 'network-admin',

			'id'     => 'network-admin-u',

			'title'  => __( 'Users' ),

			'href'   => network_admin_url( 'users.php' ),

		) );

		$wp_admin_bar->add_menu( array(

			'parent' => 'network-admin',

			'id'     => 'network-admin-v',

			'title'  => __( 'Visit Network' ),

			'href'   => network_home_url(),

		) );

	}



	// Add site links

	$wp_admin_bar->add_group( array(

		'parent' => 'my-sites',

		'id'     => 'my-sites-list',

		'meta'   => array(

			'class' => is_super_admin() ? 'ab-sub-secondary' : '',

		),

	) );



	$blue_wp_logo_url = includes_url('images/wpmini-blue.png');



	foreach ( (array) $wp_admin_bar->user->blogs as $blog ) {

		// @todo Replace with some favicon lookup.

		//$blavatar = '<img src="' . esc_url( blavatar_url( blavatar_domain( $blog->siteurl ), 'img', 16, $blue_wp_logo_url ) ) . '" alt="Blavatar" width="16" height="16" />';

		$blavatar = '<img src="' . esc_url($blue_wp_logo_url) . '" alt="' . esc_attr__( 'Blavatar' ) . '" width="16" height="16" class="blavatar"/>';



		$blogname = empty( $blog->blogname ) ? $blog->domain : $blog->blogname;

		$menu_id  = 'blog-' . $blog->userblog_id;



		$wp_admin_bar->add_menu( array(

			'parent'    => 'my-sites-list',

			'id'        => $menu_id,

			'title'     => $blavatar . $blogname,

			'href'      => get_admin_url( $blog->userblog_id ),

		) );



		$wp_admin_bar->add_menu( array(

			'parent' => $menu_id,

			'id'     => $menu_id . '-d',

			'title'  => __( 'Dashboard' ),

			'href'   => get_admin_url( $blog->userblog_id ),

		) );



		if ( current_user_can_for_blog( $blog->userblog_id, 'edit_posts' ) ) {

			$wp_admin_bar->add_menu( array(

				'parent' => $menu_id,

				'id'     => $menu_id . '-n',

				'title'  => __( 'New Post' ),

				'href'   => get_admin_url( $blog->userblog_id, 'post-new.php' ),

			) );

			$wp_admin_bar->add_menu( array(

				'parent' => $menu_id,

				'id'     => $menu_id . '-c',

				'title'  => __( 'Manage Comments' ),

				'href'   => get_admin_url( $blog->userblog_id, 'edit-comments.php' ),

			) );

		}



		$wp_admin_bar->add_menu( array(

			'parent' => $menu_id,

			'id'     => $menu_id . '-v',

			'title'  => __( 'Visit Site' ),

			'href'   => get_home_url( $blog->userblog_id, '/' ),

		) );

	}

}

10587

Advertisements

No comments yet... Be the first to leave a reply!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: