wp_admin_bar_site_menu( WP_Admin_Bar $wp_admin_bar )
- Since
- 3.3.0
- Source
wp-includes/admin-bar.php:362
Adds the "Site Name" menu.
Parameters
$wp_admin_barWP_Admin_Bar- The WP_Admin_Bar instance.
Hooks fired · 1
One hook fires while wp_admin_bar_site_menu() runs, in this order:
- apply_filters( wp_admin_bar_show_site_icons )filterline 394 (+32 into the body)
Filters whether to show the site icons in toolbar.
Uses · 23
- is_user_logged_in()Determines whether the current visitor is a logged in user.
- is_user_member_of_blog()Finds out whether a user is a member of a given blog.
- current_user_can()Returns whether the current user has the specified capability.
- get_bloginfo()Retrieves information about the current site.
- get_home_url()Retrieves the URL for a given site where the front end is accessible.
- is_network_admin()Determines whether the current request is for the network administrative interface.
- __()Retrieves the translation of $text.
- esc_html()Escaping for HTML blocks.
- get_network()Retrieves network data given a network ID or network object.
- is_user_admin()Determines whether the current request is for a user admin screen.
- wp_html_excerpt()Safely extracts not more than the first $count characters from HTML string.
- apply_filters()Calls the callback functions that have been added to a filter hook.
Show all 23
- has_site_icon()Determines whether the site has a Site Icon.
- get_site_icon_url()Returns the Site Icon URL.
- esc_url()Checks and cleans a URL.
- is_admin()Determines whether the current request is for an administrative interface page.
- home_url()Retrieves the URL for the current site where the front end is accessible.
- admin_url()Retrieves the URL to the admin area for the current site.
- is_blog_admin()Determines whether the current request is for a site's administrative interface.
- is_multisite()Determines whether Multisite is enabled.
- network_admin_url()Retrieves the URL to the admin area for the network.
- get_current_blog_id()Retrieves the current site ID.
- wp_admin_bar_appearance_menu()Adds appearance submenu items to the "Site Name" menu.
Source
function wp_admin_bar_site_menu( $wp_admin_bar ) { // 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() && ! current_user_can( 'manage_network' ) ) { return; } $blogname = get_bloginfo( 'name' ); if ( ! $blogname ) { $blogname = preg_replace( '#^(https?://)?(www\.)?#', '', get_home_url() ); } if ( is_network_admin() ) { /* translators: %s: Site title. */ $blogname = sprintf( __( 'Network Admin: %s' ), esc_html( get_network()->site_name ) ); } elseif ( is_user_admin() ) { /* translators: %s: Site title. */ $blogname = sprintf( __( 'User Dashboard: %s' ), esc_html( get_network()->site_name ) ); } $title = wp_html_excerpt( $blogname, 40, '…' ); $meta = array( 'menu_title' => $title, ); if ( ! is_network_admin() && ! is_user_admin() ) { /** This filter is documented in wp-includes/admin-bar.php */ $show_site_icons = apply_filters( 'wp_admin_bar_show_site_icons', true ); if ( true === $show_site_icons && has_site_icon() ) { $site_icon_url = get_site_icon_url( 32 ); $site_icon_url_2x = get_site_icon_url( 64 ); $srcset = ( $site_icon_url_2x && $site_icon_url !== $site_icon_url_2x ) ? sprintf( ' srcset="%s 2x"', esc_url( $site_icon_url_2x ) ) : ''; $site_icon = sprintf( '<img class="site-icon" src="%s"%s alt="" width="20" height="20" />', esc_url( $site_icon_url ), $srcset ); $title = $site_icon . $title; $meta['class'] = 'has-site-icon'; } } $wp_admin_bar->add_node( array( 'id' => 'site-name', 'title' => $title, 'href' => ( is_admin() || ! current_user_can( 'read' ) ) ? home_url( '/' ) : admin_url(), 'meta' => $meta, ) ); // Create submenu items. if ( is_admin() ) { // Add an option to visit the site. $wp_admin_bar->add_node( array( 'parent' => 'site-name', 'id' => 'view-site', 'title' => __( 'Visit Site' ), 'href' => home_url( '/' ), ) ); if ( is_blog_admin() && is_multisite() && current_user_can( 'manage_sites' ) ) { $wp_admin_bar->add_node( array( 'parent' => 'site-name', 'id' => 'edit-site', 'title' => __( 'Manage Site' ), 'href' => network_admin_url( 'site-info.php?id=' . get_current_blog_id() ), ) );History
Introduced in 3.3.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-includes/admin-bar.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.