wp_admin_bar_site_menu

Add the "Site Name" menu.

Description

wp_admin_bar_site_menu( (WP_Admin_Bar) $wp_admin_bar ); 

Parameters (1)

0. $wp_admin_bar (WP_Admin_Bar)
The wp admin bar.

Usage

  1. if ( !function_exists( 'wp_admin_bar_site_menu' ) ) { 
  2. require_once ABSPATH . WPINC . '/admin-bar.php'; 
  3.  
  4. // The wp admin bar. 
  5. $wp_admin_bar = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = wp_admin_bar_site_menu($wp_admin_bar); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/admin-bar.php  
  1. function wp_admin_bar_site_menu( $wp_admin_bar ) { 
  2. // Don't show for logged out users. 
  3. if ( ! is_user_logged_in() ) 
  4. return; 
  5.  
  6. // Show only when the user is a member of this site, or they're a super admin. 
  7. return; 
  8.  
  9. $blogname = get_bloginfo('name'); 
  10.  
  11. if ( ! $blogname ) { 
  12. $blogname = preg_replace( '#^(https?://)?(www.)?#', '', get_home_url() ); 
  13.  
  14. if ( is_network_admin() ) { 
  15. /** translators: %s: site name */ 
  16. $blogname = sprintf( __( 'Network Admin: %s' ), esc_html( get_network()->site_name ) ); 
  17. } elseif ( is_user_admin() ) { 
  18. /** translators: %s: site name */ 
  19. $blogname = sprintf( __( 'User Dashboard: %s' ), esc_html( get_network()->site_name ) ); 
  20.  
  21. $title = wp_html_excerpt( $blogname, 40, '…' ); 
  22.  
  23. $wp_admin_bar->add_menu( array( 
  24. 'id' => 'site-name',  
  25. 'title' => $title,  
  26. 'href' => ( is_admin() || ! current_user_can( 'read' ) ) ? home_url( '/' ) : admin_url(),  
  27. ) ); 
  28.  
  29. // Create submenu items. 
  30.  
  31. if ( is_admin() ) { 
  32. // Add an option to visit the site. 
  33. $wp_admin_bar->add_menu( array( 
  34. 'parent' => 'site-name',  
  35. 'id' => 'view-site',  
  36. 'title' => __( 'Visit Site' ),  
  37. 'href' => home_url( '/' ),  
  38. ) ); 
  39.  
  40. if ( is_blog_admin() && is_multisite() && current_user_can( 'manage_sites' ) ) { 
  41. $wp_admin_bar->add_menu( array( 
  42. 'parent' => 'site-name',  
  43. 'id' => 'edit-site',  
  44. 'title' => __( 'Edit Site' ),  
  45. 'href' => network_admin_url( 'site-info.php?id=' . get_current_blog_id() ),  
  46. ) ); 
  47.  
  48. } else if ( current_user_can( 'read' ) ) { 
  49. // We're on the front end, link to the Dashboard. 
  50. $wp_admin_bar->add_menu( array( 
  51. 'parent' => 'site-name',  
  52. 'id' => 'dashboard',  
  53. 'title' => __( 'Dashboard' ),  
  54. 'href' => admin_url(),  
  55. ) ); 
  56.  
  57. // Add the appearance submenu items. 
  58. wp_admin_bar_appearance_menu( $wp_admin_bar );