: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
* @param WP_Admin_Bar $wp_admin_bar The WP_Admin_Bar instance.
function wp_admin_bar_customize_menu( $wp_admin_bar ) {
// Don't show if a block theme is activated and no plugins use the customizer.
if ( wp_is_block_theme() && ! has_action( 'customize_register' ) ) {
// Don't show for users who can't access the customizer or when in the admin.
if ( ! current_user_can( 'customize' ) || is_admin() ) {
// Don't show if the user cannot edit a given customize_changeset post currently being previewed.
if ( is_customize_preview() && $wp_customize->changeset_post_id()
&& ! current_user_can( get_post_type_object( 'customize_changeset' )->cap->edit_post, $wp_customize->changeset_post_id() )
$current_url = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
if ( is_customize_preview() && $wp_customize->changeset_uuid() ) {
$current_url = remove_query_arg( 'customize_changeset_uuid', $current_url );
$customize_url = add_query_arg( 'url', urlencode( $current_url ), wp_customize_url() );
if ( is_customize_preview() ) {
$customize_url = add_query_arg( array( 'changeset_uuid' => $wp_customize->changeset_uuid() ), $customize_url );
'title' => __( 'Customize' ),
'href' => $customize_url,
'class' => 'hide-if-no-customize',
add_action( 'wp_before_admin_bar_render', 'wp_customize_support_script' );
* Adds the "My Sites/[Site Name]" menu and all submenus.
* @param WP_Admin_Bar $wp_admin_bar The WP_Admin_Bar instance.
function wp_admin_bar_my_sites_menu( $wp_admin_bar ) {
// Don't show for logged out users or single site mode.
if ( ! is_user_logged_in() || ! is_multisite() ) {
// Show only when the user has at least one site, or they're a super admin.
if ( count( $wp_admin_bar->user->blogs ) < 1 && ! current_user_can( 'manage_network' ) ) {
if ( $wp_admin_bar->user->active_blog ) {
$my_sites_url = get_admin_url( $wp_admin_bar->user->active_blog->blog_id, 'my-sites.php' );
$my_sites_url = admin_url( 'my-sites.php' );
'title' => __( 'My Sites' ),
if ( current_user_can( 'manage_network' ) ) {
$wp_admin_bar->add_group(
'id' => 'my-sites-super-admin',
'parent' => 'my-sites-super-admin',
'title' => __( 'Network Admin' ),
'href' => network_admin_url(),
'parent' => 'network-admin',
'id' => 'network-admin-d',
'title' => __( 'Dashboard' ),
'href' => network_admin_url(),
if ( current_user_can( 'manage_sites' ) ) {
'parent' => 'network-admin',
'id' => 'network-admin-s',
'title' => __( 'Sites' ),
'href' => network_admin_url( 'sites.php' ),
if ( current_user_can( 'manage_network_users' ) ) {
'parent' => 'network-admin',
'id' => 'network-admin-u',
'title' => __( 'Users' ),
'href' => network_admin_url( 'users.php' ),
if ( current_user_can( 'manage_network_themes' ) ) {
'parent' => 'network-admin',
'id' => 'network-admin-t',
'title' => __( 'Themes' ),
'href' => network_admin_url( 'themes.php' ),
if ( current_user_can( 'manage_network_plugins' ) ) {
'parent' => 'network-admin',
'id' => 'network-admin-p',
'title' => __( 'Plugins' ),
'href' => network_admin_url( 'plugins.php' ),
if ( current_user_can( 'manage_network_options' ) ) {
'parent' => 'network-admin',
'id' => 'network-admin-o',
'title' => __( 'Settings' ),
'href' => network_admin_url( 'settings.php' ),
$wp_admin_bar->add_group(
'class' => current_user_can( 'manage_network' ) ? 'ab-sub-secondary' : '',
* Filters whether to show the site icons in toolbar.
* Returning false to this hook is the recommended way to hide site icons in the toolbar.
* A truthy return may have negative performance impact on large multisites.
* @param bool $show_site_icons Whether site icons should be shown in the toolbar. Default true.
$show_site_icons = apply_filters( 'wp_admin_bar_show_site_icons', true );
foreach ( (array) $wp_admin_bar->user->blogs as $blog ) {
switch_to_blog( $blog->userblog_id );
if ( true === $show_site_icons && has_site_icon() ) {
'<img class="blavatar" src="%s" srcset="%s 2x" alt="" width="16" height="16"%s />',
esc_url( get_site_icon_url( 16 ) ),
esc_url( get_site_icon_url( 32 ) ),
( wp_lazy_loading_enabled( 'img', 'site_icon_in_toolbar' ) ? ' loading="lazy"' : '' )
$blavatar = '<div class="blavatar"></div>';
$blogname = $blog->blogname;
$blogname = preg_replace( '#^(https?://)?(www.)?#', '', get_home_url() );
$menu_id = 'blog-' . $blog->userblog_id;
if ( current_user_can( 'read' ) ) {
'parent' => 'my-sites-list',
'title' => $blavatar . $blogname,
'title' => __( 'Dashboard' ),
'parent' => 'my-sites-list',
'title' => $blavatar . $blogname,
if ( current_user_can( get_post_type_object( 'post' )->cap->create_posts ) ) {
'title' => get_post_type_object( 'post' )->labels->new_item,
'href' => admin_url( 'post-new.php' ),
if ( current_user_can( 'edit_posts' ) ) {
'title' => __( 'Manage Comments' ),
'href' => admin_url( 'edit-comments.php' ),
'title' => __( 'Visit Site' ),
'href' => home_url( '/' ),
* @param WP_Admin_Bar $wp_admin_bar The WP_Admin_Bar instance.
function wp_admin_bar_shortlink_menu( $wp_admin_bar ) {
$short = wp_get_shortlink( 0, 'query' );
$html = '<input class="shortlink-input" type="text" readonly="readonly" value="' . esc_attr( $short ) . '" aria-label="' . __( 'Shortlink' ) . '" />';
'title' => __( 'Shortlink' ),
'meta' => array( 'html' => $html ),
* Provides an edit link for posts and terms.
* @since 5.5.0 Added a "View Post" link on Comments screen for a single post.
* @global WP_Query $wp_the_query WordPress Query object.
* @global int $user_id The ID of the user being edited. Not to be confused with the
* global $user_ID, which contains the ID of the current user.
* @global int $post_id The ID of the post when editing comments for a single post.
* @param WP_Admin_Bar $wp_admin_bar The WP_Admin_Bar instance.
function wp_admin_bar_edit_menu( $wp_admin_bar ) {
global $tag, $wp_the_query, $user_id, $post_id;
$current_screen = get_current_screen();
$post_type_object = null;
if ( 'post' === $current_screen->base ) {
$post_type_object = get_post_type_object( $post->post_type );
} elseif ( 'edit' === $current_screen->base ) {
$post_type_object = get_post_type_object( $current_screen->post_type );
} elseif ( 'edit-comments' === $current_screen->base && $post_id ) {
$post = get_post( $post_id );
$post_type_object = get_post_type_object( $post->post_type );
if ( ( 'post' === $current_screen->base || 'edit-comments' === $current_screen->base )
&& 'add' !== $current_screen->action
&& current_user_can( 'read_post', $post->ID )
&& ( $post_type_object->public )
&& ( $post_type_object->show_in_admin_bar ) ) {
if ( 'draft' === $post->post_status ) {
$preview_link = get_preview_post_link( $post );
'title' => $post_type_object->labels->view_item,
'href' => esc_url( $preview_link ),
'meta' => array( 'target' => 'wp-preview-' . $post->ID ),
'title' => $post_type_object->labels->view_item,
'href' => get_permalink( $post->ID ),
} elseif ( 'edit' === $current_screen->base
&& ( $post_type_object->public )
&& ( $post_type_object->show_in_admin_bar )
&& ( get_post_type_archive_link( $post_type_object->name ) )
&& ! ( 'post' === $post_type_object->name && 'posts' === get_option( 'show_on_front' ) ) ) {
'title' => $post_type_object->labels->view_items,
'href' => get_post_type_archive_link( $current_screen->post_type ),
} elseif ( 'term' === $current_screen->base && isset( $tag ) && is_object( $tag ) && ! is_wp_error( $tag ) ) {
$tax = get_taxonomy( $tag->taxonomy );
if ( is_term_publicly_viewable( $tag ) ) {
'title' => $tax->labels->view_item,
'href' => get_term_link( $tag ),
} elseif ( 'user-edit' === $current_screen->base && isset( $user_id ) ) {
$user_object = get_userdata( $user_id );
$view_link = get_author_posts_url( $user_object->ID );
if ( $user_object->exists() && $view_link ) {
'title' => __( 'View User' ),
$current_object = $wp_the_query->get_queried_object();
if ( empty( $current_object ) ) {
if ( ! empty( $current_object->post_type ) ) {
$post_type_object = get_post_type_object( $current_object->post_type );
$edit_post_link = get_edit_post_link( $current_object->ID );
&& current_user_can( 'edit_post', $current_object->ID )
&& $post_type_object->show_in_admin_bar ) {
'title' => $post_type_object->labels->edit_item,
'href' => $edit_post_link,
} elseif ( ! empty( $current_object->taxonomy ) ) {
$tax = get_taxonomy( $current_object->taxonomy );
$edit_term_link = get_edit_term_link( $current_object->term_id, $current_object->taxonomy );
if ( $tax && $edit_term_link && current_user_can( 'edit_term', $current_object->term_id ) ) {
'title' => $tax->labels->edit_item,
'href' => $edit_term_link,
} elseif ( $current_object instanceof WP_User && current_user_can( 'edit_user', $current_object->ID ) ) {
$edit_user_link = get_edit_user_link( $current_object->ID );
'title' => __( 'Edit User' ),
'href' => $edit_user_link,
* @since 6.5.0 Added a New Site link for network installations.
* @param WP_Admin_Bar $wp_admin_bar The WP_Admin_Bar instance.
function wp_admin_bar_new_content_menu( $wp_admin_bar ) {
$cpts = (array) get_post_types( array( 'show_in_admin_bar' => true ), 'objects' );
if ( isset( $cpts['post'] ) && current_user_can( $cpts['post']->cap->create_posts ) ) {
$actions['post-new.php'] = array( $cpts['post']->labels->name_admin_bar, 'new-post' );
if ( isset( $cpts['attachment'] ) && current_user_can( 'upload_files' ) ) {
$actions['media-new.php'] = array( $cpts['attachment']->labels->name_admin_bar, 'new-media' );
if ( current_user_can( 'manage_links' ) ) {
$actions['link-add.php'] = array( _x( 'Link', 'add new from admin bar' ), 'new-link' );
if ( isset( $cpts['page'] ) && current_user_can( $cpts['page']->cap->create_posts ) ) {
$actions['post-new.php?post_type=page'] = array( $cpts['page']->labels->name_admin_bar, 'new-page' );
unset( $cpts['post'], $cpts['page'], $cpts['attachment'] );
// Add any additional custom post types.
foreach ( $cpts as $cpt ) {
if ( ! current_user_can( $cpt->cap->create_posts ) ) {
$key = 'post-new.php?post_type=' . $cpt->name;
$actions[ $key ] = array( $cpt->labels->name_admin_bar, 'new-' . $cpt->name );
// Avoid clash with parent node and a 'content' post type.
if ( isset( $actions['post-new.php?post_type=content'] ) ) {
$actions['post-new.php?post_type=content'][1] = 'add-new-content';
if ( current_user_can( 'create_users' ) || ( is_multisite() && current_user_can( 'promote_users' ) ) ) {
$actions['user-new.php'] = array( _x( 'User', 'add new from admin bar' ), 'new-user' );
$title = '<span class="ab-icon" aria-hidden="true"></span><span class="ab-label">' . _x( 'New', 'admin bar menu group label' ) . '</span>';
'href' => admin_url( current( array_keys( $actions ) ) ),