Advertisements

wp_admin_bar_site_menu

Definition:
function wp_admin_bar_site_menu( $wp_admin_bar ) {}

Add the "Site Name" menu.

Parameters

  • $wp_admin_bar

Source code

function wp_admin_bar_site_menu( $wp_admin_bar ) {

	global $current_site;



	// Don't show for logged out users.

	if ( ! is_user_logged_in() )

		return;



	// Show only when the user is a member of this site, or they're a super admin.

	if ( ! is_user_member_of_blog() && ! is_super_admin() )

		return;



	$blogname = get_bloginfo('name');



	if ( empty( $blogname ) )

		$blogname = preg_replace( '#^(https?://)?(www.)?#', '', get_home_url() );



	if ( is_network_admin() ) {

		$blogname = sprintf( __('Network Admin: %s'), esc_html( $current_site->site_name ) );

	} elseif ( is_user_admin() ) {

		$blogname = sprintf( __('Global Dashboard: %s'), esc_html( $current_site->site_name ) );

	}



	$title = wp_html_excerpt( $blogname, 40 );

	if ( $title != $blogname )

		$title = trim( $title ) . '…';



	$wp_admin_bar->add_menu( array(

		'id'    => 'site-name',

		'title' => $title,

		'href'  => is_admin() ? home_url( '/' ) : admin_url(),

	) );



	// Create submenu items.



	if ( is_admin() ) {

		// Add an option to visit the site.

		$wp_admin_bar->add_menu( array(

			'parent' => 'site-name',

			'id'     => 'view-site',

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

			'href'   => home_url( '/' ),

		) );



	// We're on the front end, print a copy of the admin menu.

	} else {

		// Add the dashboard item.

		$wp_admin_bar->add_menu( array(

			'parent' => 'site-name',

			'id'     => 'dashboard',

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

			'href'   => admin_url(),

		) );



		// Add the appearance submenu items.

		wp_admin_bar_appearance_menu( $wp_admin_bar );

	}

}

17418

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: