3 * Toolbar API: Top-level Toolbar functionality
11 * Instantiate the admin bar object and set it up as a global for access elsewhere.
13 * UNHOOKING THIS FUNCTION WILL NOT PROPERLY REMOVE THE ADMIN BAR.
14 * For that, use show_admin_bar(false) or the {@see 'show_admin_bar'} filter.
19 * @global WP_Admin_Bar $wp_admin_bar
21 * @return bool Whether the admin bar was successfully initialized.
23 function _wp_admin_bar_init() {
26 if ( ! is_admin_bar_showing() )
29 /* Load the admin bar class code ready for instantiation */
30 require_once( ABSPATH . WPINC . '/class-wp-admin-bar.php' );
32 /* Instantiate the admin bar */
35 * Filters the admin bar class to instantiate.
39 * @param string $wp_admin_bar_class Admin bar class to use. Default 'WP_Admin_Bar'.
41 $admin_bar_class = apply_filters( 'wp_admin_bar_class', 'WP_Admin_Bar' );
42 if ( class_exists( $admin_bar_class ) )
43 $wp_admin_bar = new $admin_bar_class;
47 $wp_admin_bar->initialize();
48 $wp_admin_bar->add_menus();
54 * Renders the admin bar to the page based on the $wp_admin_bar->menu member var.
56 * This is called very late on the footer actions so that it will render after
57 * anything else being added to the footer.
59 * It includes the {@see 'admin_bar_menu'} action which should be used to hook in and
60 * add new menus to the admin bar. That way you can be sure that you are adding at most
61 * optimal point, right before the admin bar is rendered. This also gives you access to
62 * the `$post` global, among others.
66 * @global WP_Admin_Bar $wp_admin_bar
68 function wp_admin_bar_render() {
71 if ( ! is_admin_bar_showing() || ! is_object( $wp_admin_bar ) )
75 * Load all necessary admin bar items.
77 * This is the hook used to add, remove, or manipulate admin bar items.
81 * @param WP_Admin_Bar $wp_admin_bar WP_Admin_Bar instance, passed by reference
83 do_action_ref_array( 'admin_bar_menu', array( &$wp_admin_bar ) );
86 * Fires before the admin bar is rendered.
90 do_action( 'wp_before_admin_bar_render' );
92 $wp_admin_bar->render();
95 * Fires after the admin bar is rendered.
99 do_action( 'wp_after_admin_bar_render' );
103 * Add the WordPress logo menu.
107 * @param WP_Admin_Bar $wp_admin_bar
109 function wp_admin_bar_wp_menu( $wp_admin_bar ) {
110 $wp_admin_bar->add_menu( array(
112 'title' => '<span class="ab-icon"></span><span class="screen-reader-text">' . __( 'About WordPress' ) . '</span>',
113 'href' => self_admin_url( 'about.php' ),
116 if ( is_user_logged_in() ) {
117 // Add "About WordPress" link
118 $wp_admin_bar->add_menu( array(
119 'parent' => 'wp-logo',
121 'title' => __('About WordPress'),
122 'href' => self_admin_url( 'about.php' ),
126 // Add WordPress.org link
127 $wp_admin_bar->add_menu( array(
128 'parent' => 'wp-logo-external',
130 'title' => __('WordPress.org'),
131 'href' => __('https://wordpress.org/'),
135 $wp_admin_bar->add_menu( array(
136 'parent' => 'wp-logo-external',
137 'id' => 'documentation',
138 'title' => __('Documentation'),
139 'href' => __('https://codex.wordpress.org/'),
143 $wp_admin_bar->add_menu( array(
144 'parent' => 'wp-logo-external',
145 'id' => 'support-forums',
146 'title' => __('Support Forums'),
147 'href' => __('https://wordpress.org/support/'),
151 $wp_admin_bar->add_menu( array(
152 'parent' => 'wp-logo-external',
154 'title' => __('Feedback'),
155 'href' => __('https://wordpress.org/support/forum/requests-and-feedback'),
160 * Add the sidebar toggle button.
164 * @param WP_Admin_Bar $wp_admin_bar
166 function wp_admin_bar_sidebar_toggle( $wp_admin_bar ) {
168 $wp_admin_bar->add_menu( array(
169 'id' => 'menu-toggle',
170 'title' => '<span class="ab-icon"></span><span class="screen-reader-text">' . __( 'Menu' ) . '</span>',
177 * Add the "My Account" item.
181 * @param WP_Admin_Bar $wp_admin_bar
183 function wp_admin_bar_my_account_item( $wp_admin_bar ) {
184 $user_id = get_current_user_id();
185 $current_user = wp_get_current_user();
190 if ( current_user_can( 'read' ) ) {
191 $profile_url = get_edit_profile_url( $user_id );
192 } elseif ( is_multisite() ) {
193 $profile_url = get_dashboard_url( $user_id, 'profile.php' );
195 $profile_url = false;
198 $avatar = get_avatar( $user_id, 26 );
199 $howdy = sprintf( __('Howdy, %1$s'), $current_user->display_name );
200 $class = empty( $avatar ) ? '' : 'with-avatar';
202 $wp_admin_bar->add_menu( array(
203 'id' => 'my-account',
204 'parent' => 'top-secondary',
205 'title' => $howdy . $avatar,
206 'href' => $profile_url,
214 * Add the "My Account" submenu items.
218 * @param WP_Admin_Bar $wp_admin_bar
220 function wp_admin_bar_my_account_menu( $wp_admin_bar ) {
221 $user_id = get_current_user_id();
222 $current_user = wp_get_current_user();
227 if ( current_user_can( 'read' ) ) {
228 $profile_url = get_edit_profile_url( $user_id );
229 } elseif ( is_multisite() ) {
230 $profile_url = get_dashboard_url( $user_id, 'profile.php' );
232 $profile_url = false;
235 $wp_admin_bar->add_group( array(
236 'parent' => 'my-account',
237 'id' => 'user-actions',
240 $user_info = get_avatar( $user_id, 64 );
241 $user_info .= "<span class='display-name'>{$current_user->display_name}</span>";
243 if ( $current_user->display_name !== $current_user->user_login )
244 $user_info .= "<span class='username'>{$current_user->user_login}</span>";
246 $wp_admin_bar->add_menu( array(
247 'parent' => 'user-actions',
249 'title' => $user_info,
250 'href' => $profile_url,
256 if ( false !== $profile_url ) {
257 $wp_admin_bar->add_menu( array(
258 'parent' => 'user-actions',
259 'id' => 'edit-profile',
260 'title' => __( 'Edit My Profile' ),
261 'href' => $profile_url,
265 $wp_admin_bar->add_menu( array(
266 'parent' => 'user-actions',
268 'title' => __( 'Log Out' ),
269 'href' => wp_logout_url(),
274 * Add the "Site Name" menu.
278 * @param WP_Admin_Bar $wp_admin_bar
280 function wp_admin_bar_site_menu( $wp_admin_bar ) {
281 // Don't show for logged out users.
282 if ( ! is_user_logged_in() )
285 // Show only when the user is a member of this site, or they're a super admin.
286 if ( ! is_user_member_of_blog() && ! is_super_admin() )
289 $blogname = get_bloginfo('name');
292 $blogname = preg_replace( '#^(https?://)?(www.)?#', '', get_home_url() );
295 if ( is_network_admin() ) {
296 $blogname = sprintf( __('Network Admin: %s'), esc_html( get_current_site()->site_name ) );
297 } elseif ( is_user_admin() ) {
298 $blogname = sprintf( __('User Dashboard: %s'), esc_html( get_current_site()->site_name ) );
301 $title = wp_html_excerpt( $blogname, 40, '…' );
303 $wp_admin_bar->add_menu( array(
306 'href' => ( is_admin() || ! current_user_can( 'read' ) ) ? home_url( '/' ) : admin_url(),
309 // Create submenu items.
312 // Add an option to visit the site.
313 $wp_admin_bar->add_menu( array(
314 'parent' => 'site-name',
316 'title' => __( 'Visit Site' ),
317 'href' => home_url( '/' ),
320 if ( is_blog_admin() && is_multisite() && current_user_can( 'manage_sites' ) ) {
321 $wp_admin_bar->add_menu( array(
322 'parent' => 'site-name',
324 'title' => __( 'Edit Site' ),
325 'href' => network_admin_url( 'site-info.php?id=' . get_current_blog_id() ),
329 } else if ( current_user_can( 'read' ) ) {
330 // We're on the front end, link to the Dashboard.
331 $wp_admin_bar->add_menu( array(
332 'parent' => 'site-name',
334 'title' => __( 'Dashboard' ),
335 'href' => admin_url(),
338 // Add the appearance submenu items.
339 wp_admin_bar_appearance_menu( $wp_admin_bar );
344 * Adds the "Customize" link to the Toolbar.
348 * @param WP_Admin_Bar $wp_admin_bar WP_Admin_Bar instance.
350 function wp_admin_bar_customize_menu( $wp_admin_bar ) {
351 // Don't show for users who can't access the customizer or when in the admin.
352 if ( ! current_user_can( 'customize' ) || is_admin() ) {
356 $current_url = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
357 $customize_url = add_query_arg( 'url', urlencode( $current_url ), wp_customize_url() );
359 $wp_admin_bar->add_menu( array(
361 'title' => __( 'Customize' ),
362 'href' => $customize_url,
364 'class' => 'hide-if-no-customize',
367 add_action( 'wp_before_admin_bar_render', 'wp_customize_support_script' );
371 * Add the "My Sites/[Site Name]" menu and all submenus.
375 * @param WP_Admin_Bar $wp_admin_bar
377 function wp_admin_bar_my_sites_menu( $wp_admin_bar ) {
378 // Don't show for logged out users or single site mode.
379 if ( ! is_user_logged_in() || ! is_multisite() )
382 // Show only when the user has at least one site, or they're a super admin.
383 if ( count( $wp_admin_bar->user->blogs ) < 1 && ! is_super_admin() )
386 if ( $wp_admin_bar->user->active_blog ) {
387 $my_sites_url = get_admin_url( $wp_admin_bar->user->active_blog->blog_id, 'my-sites.php' );
389 $my_sites_url = admin_url( 'my-sites.php' );
392 $wp_admin_bar->add_menu( array(
394 'title' => __( 'My Sites' ),
395 'href' => $my_sites_url,
398 if ( is_super_admin() ) {
399 $wp_admin_bar->add_group( array(
400 'parent' => 'my-sites',
401 'id' => 'my-sites-super-admin',
404 $wp_admin_bar->add_menu( array(
405 'parent' => 'my-sites-super-admin',
406 'id' => 'network-admin',
407 'title' => __('Network Admin'),
408 'href' => network_admin_url(),
411 $wp_admin_bar->add_menu( array(
412 'parent' => 'network-admin',
413 'id' => 'network-admin-d',
414 'title' => __( 'Dashboard' ),
415 'href' => network_admin_url(),
417 $wp_admin_bar->add_menu( array(
418 'parent' => 'network-admin',
419 'id' => 'network-admin-s',
420 'title' => __( 'Sites' ),
421 'href' => network_admin_url( 'sites.php' ),
423 $wp_admin_bar->add_menu( array(
424 'parent' => 'network-admin',
425 'id' => 'network-admin-u',
426 'title' => __( 'Users' ),
427 'href' => network_admin_url( 'users.php' ),
429 $wp_admin_bar->add_menu( array(
430 'parent' => 'network-admin',
431 'id' => 'network-admin-t',
432 'title' => __( 'Themes' ),
433 'href' => network_admin_url( 'themes.php' ),
435 $wp_admin_bar->add_menu( array(
436 'parent' => 'network-admin',
437 'id' => 'network-admin-p',
438 'title' => __( 'Plugins' ),
439 'href' => network_admin_url( 'plugins.php' ),
441 $wp_admin_bar->add_menu( array(
442 'parent' => 'network-admin',
443 'id' => 'network-admin-o',
444 'title' => __( 'Settings' ),
445 'href' => network_admin_url( 'settings.php' ),
450 $wp_admin_bar->add_group( array(
451 'parent' => 'my-sites',
452 'id' => 'my-sites-list',
454 'class' => is_super_admin() ? 'ab-sub-secondary' : '',
458 foreach ( (array) $wp_admin_bar->user->blogs as $blog ) {
459 switch_to_blog( $blog->userblog_id );
461 $blavatar = '<div class="blavatar"></div>';
463 $blogname = $blog->blogname;
466 $blogname = preg_replace( '#^(https?://)?(www.)?#', '', get_home_url() );
469 $menu_id = 'blog-' . $blog->userblog_id;
471 $wp_admin_bar->add_menu( array(
472 'parent' => 'my-sites-list',
474 'title' => $blavatar . $blogname,
475 'href' => admin_url(),
478 $wp_admin_bar->add_menu( array(
479 'parent' => $menu_id,
480 'id' => $menu_id . '-d',
481 'title' => __( 'Dashboard' ),
482 'href' => admin_url(),
485 if ( current_user_can( get_post_type_object( 'post' )->cap->create_posts ) ) {
486 $wp_admin_bar->add_menu( array(
487 'parent' => $menu_id,
488 'id' => $menu_id . '-n',
489 'title' => __( 'New Post' ),
490 'href' => admin_url( 'post-new.php' ),
494 if ( current_user_can( 'edit_posts' ) ) {
495 $wp_admin_bar->add_menu( array(
496 'parent' => $menu_id,
497 'id' => $menu_id . '-c',
498 'title' => __( 'Manage Comments' ),
499 'href' => admin_url( 'edit-comments.php' ),
503 $wp_admin_bar->add_menu( array(
504 'parent' => $menu_id,
505 'id' => $menu_id . '-v',
506 'title' => __( 'Visit Site' ),
507 'href' => home_url( '/' ),
510 restore_current_blog();
515 * Provide a shortlink.
519 * @param WP_Admin_Bar $wp_admin_bar
521 function wp_admin_bar_shortlink_menu( $wp_admin_bar ) {
522 $short = wp_get_shortlink( 0, 'query' );
523 $id = 'get-shortlink';
525 if ( empty( $short ) )
528 $html = '<input class="shortlink-input" type="text" readonly="readonly" value="' . esc_attr( $short ) . '" />';
530 $wp_admin_bar->add_menu( array(
532 'title' => __( 'Shortlink' ),
534 'meta' => array( 'html' => $html ),
539 * Provide an edit link for posts and terms.
543 * @global WP_Term $tag
544 * @global WP_Query $wp_the_query
546 * @param WP_Admin_Bar $wp_admin_bar
548 function wp_admin_bar_edit_menu( $wp_admin_bar ) {
549 global $tag, $wp_the_query;
552 $current_screen = get_current_screen();
555 if ( 'post' == $current_screen->base
556 && 'add' != $current_screen->action
557 && ( $post_type_object = get_post_type_object( $post->post_type ) )
558 && current_user_can( 'read_post', $post->ID )
559 && ( $post_type_object->public )
560 && ( $post_type_object->show_in_admin_bar ) )
562 if ( 'draft' == $post->post_status ) {
563 $preview_link = get_preview_post_link( $post );
564 $wp_admin_bar->add_menu( array(
566 'title' => $post_type_object->labels->view_item,
567 'href' => esc_url( $preview_link ),
568 'meta' => array( 'target' => 'wp-preview-' . $post->ID ),
571 $wp_admin_bar->add_menu( array(
573 'title' => $post_type_object->labels->view_item,
574 'href' => get_permalink( $post->ID )
577 } elseif ( 'term' == $current_screen->base
578 && isset( $tag ) && is_object( $tag ) && ! is_wp_error( $tag )
579 && ( $tax = get_taxonomy( $tag->taxonomy ) )
582 $wp_admin_bar->add_menu( array(
584 'title' => $tax->labels->view_item,
585 'href' => get_term_link( $tag )
589 $current_object = $wp_the_query->get_queried_object();
591 if ( empty( $current_object ) )
594 if ( ! empty( $current_object->post_type )
595 && ( $post_type_object = get_post_type_object( $current_object->post_type ) )
596 && current_user_can( 'edit_post', $current_object->ID )
597 && $post_type_object->show_in_admin_bar
598 && $edit_post_link = get_edit_post_link( $current_object->ID ) )
600 $wp_admin_bar->add_menu( array(
602 'title' => $post_type_object->labels->edit_item,
603 'href' => $edit_post_link
605 } elseif ( ! empty( $current_object->taxonomy )
606 && ( $tax = get_taxonomy( $current_object->taxonomy ) )
607 && current_user_can( $tax->cap->edit_terms )
608 && $edit_term_link = get_edit_term_link( $current_object->term_id, $current_object->taxonomy ) )
610 $wp_admin_bar->add_menu( array(
612 'title' => $tax->labels->edit_item,
613 'href' => $edit_term_link
620 * Add "Add New" menu.
624 * @param WP_Admin_Bar $wp_admin_bar
626 function wp_admin_bar_new_content_menu( $wp_admin_bar ) {
629 $cpts = (array) get_post_types( array( 'show_in_admin_bar' => true ), 'objects' );
631 if ( isset( $cpts['post'] ) && current_user_can( $cpts['post']->cap->create_posts ) )
632 $actions[ 'post-new.php' ] = array( $cpts['post']->labels->name_admin_bar, 'new-post' );
634 if ( isset( $cpts['attachment'] ) && current_user_can( 'upload_files' ) )
635 $actions[ 'media-new.php' ] = array( $cpts['attachment']->labels->name_admin_bar, 'new-media' );
637 if ( current_user_can( 'manage_links' ) )
638 $actions[ 'link-add.php' ] = array( _x( 'Link', 'add new from admin bar' ), 'new-link' );
640 if ( isset( $cpts['page'] ) && current_user_can( $cpts['page']->cap->create_posts ) )
641 $actions[ 'post-new.php?post_type=page' ] = array( $cpts['page']->labels->name_admin_bar, 'new-page' );
643 unset( $cpts['post'], $cpts['page'], $cpts['attachment'] );
645 // Add any additional custom post types.
646 foreach ( $cpts as $cpt ) {
647 if ( ! current_user_can( $cpt->cap->create_posts ) )
650 $key = 'post-new.php?post_type=' . $cpt->name;
651 $actions[ $key ] = array( $cpt->labels->name_admin_bar, 'new-' . $cpt->name );
653 // Avoid clash with parent node and a 'content' post type.
654 if ( isset( $actions['post-new.php?post_type=content'] ) )
655 $actions['post-new.php?post_type=content'][1] = 'add-new-content';
657 if ( current_user_can( 'create_users' ) || current_user_can( 'promote_users' ) )
658 $actions[ 'user-new.php' ] = array( _x( 'User', 'add new from admin bar' ), 'new-user' );
663 $title = '<span class="ab-icon"></span><span class="ab-label">' . _x( 'New', 'admin bar menu group label' ) . '</span>';
665 $wp_admin_bar->add_menu( array(
666 'id' => 'new-content',
668 'href' => admin_url( current( array_keys( $actions ) ) ),
671 foreach ( $actions as $link => $action ) {
672 list( $title, $id ) = $action;
674 $wp_admin_bar->add_menu( array(
675 'parent' => 'new-content',
678 'href' => admin_url( $link )
684 * Add edit comments link with awaiting moderation count bubble.
688 * @param WP_Admin_Bar $wp_admin_bar
690 function wp_admin_bar_comments_menu( $wp_admin_bar ) {
691 if ( !current_user_can('edit_posts') )
694 $awaiting_mod = wp_count_comments();
695 $awaiting_mod = $awaiting_mod->moderated;
696 $awaiting_text = sprintf( _n( '%s comment awaiting moderation', '%s comments awaiting moderation', $awaiting_mod ), number_format_i18n( $awaiting_mod ) );
698 $icon = '<span class="ab-icon"></span>';
699 $title = '<span id="ab-awaiting-mod" class="ab-label awaiting-mod pending-count count-' . $awaiting_mod . '" aria-hidden="true">' . number_format_i18n( $awaiting_mod ) . '</span>';
700 $title .= '<span class="screen-reader-text">' . $awaiting_text . '</span>';
702 $wp_admin_bar->add_menu( array(
704 'title' => $icon . $title,
705 'href' => admin_url('edit-comments.php'),
710 * Add appearance submenu items to the "Site Name" menu.
714 * @param WP_Admin_Bar $wp_admin_bar
716 function wp_admin_bar_appearance_menu( $wp_admin_bar ) {
717 $wp_admin_bar->add_group( array( 'parent' => 'site-name', 'id' => 'appearance' ) );
719 if ( current_user_can( 'switch_themes' ) ) {
720 $wp_admin_bar->add_menu( array(
721 'parent' => 'appearance',
723 'title' => __( 'Themes' ),
724 'href' => admin_url( 'themes.php' ),
728 if ( ! current_user_can( 'edit_theme_options' ) ) {
732 if ( current_theme_supports( 'widgets' ) ) {
733 $wp_admin_bar->add_menu( array(
734 'parent' => 'appearance',
736 'title' => __( 'Widgets' ),
737 'href' => admin_url( 'widgets.php' ),
741 if ( current_theme_supports( 'menus' ) || current_theme_supports( 'widgets' ) )
742 $wp_admin_bar->add_menu( array( 'parent' => 'appearance', 'id' => 'menus', 'title' => __('Menus'), 'href' => admin_url('nav-menus.php') ) );
744 if ( current_theme_supports( 'custom-background' ) ) {
745 $wp_admin_bar->add_menu( array(
746 'parent' => 'appearance',
747 'id' => 'background',
748 'title' => __( 'Background' ),
749 'href' => admin_url( 'themes.php?page=custom-background' ),
751 'class' => 'hide-if-customize',
756 if ( current_theme_supports( 'custom-header' ) ) {
757 $wp_admin_bar->add_menu( array(
758 'parent' => 'appearance',
760 'title' => __( 'Header' ),
761 'href' => admin_url( 'themes.php?page=custom-header' ),
763 'class' => 'hide-if-customize',
771 * Provide an update link if theme/plugin/core updates are available.
775 * @param WP_Admin_Bar $wp_admin_bar
777 function wp_admin_bar_updates_menu( $wp_admin_bar ) {
779 $update_data = wp_get_update_data();
781 if ( !$update_data['counts']['total'] )
784 $title = '<span class="ab-icon"></span><span class="ab-label">' . number_format_i18n( $update_data['counts']['total'] ) . '</span>';
785 $title .= '<span class="screen-reader-text">' . $update_data['title'] . '</span>';
787 $wp_admin_bar->add_menu( array(
790 'href' => network_admin_url( 'update-core.php' ),
792 'title' => $update_data['title'],
802 * @param WP_Admin_Bar $wp_admin_bar
804 function wp_admin_bar_search_menu( $wp_admin_bar ) {
808 $form = '<form action="' . esc_url( home_url( '/' ) ) . '" method="get" id="adminbarsearch">';
809 $form .= '<input class="adminbar-input" name="s" id="adminbar-search" type="text" value="" maxlength="150" />';
810 $form .= '<label for="adminbar-search" class="screen-reader-text">' . __( 'Search' ) . '</label>';
811 $form .= '<input type="submit" class="adminbar-button" value="' . __('Search') . '"/>';
814 $wp_admin_bar->add_menu( array(
815 'parent' => 'top-secondary',
819 'class' => 'admin-bar-search',
826 * Add secondary menus.
830 * @param WP_Admin_Bar $wp_admin_bar
832 function wp_admin_bar_add_secondary_groups( $wp_admin_bar ) {
833 $wp_admin_bar->add_group( array(
834 'id' => 'top-secondary',
836 'class' => 'ab-top-secondary',
840 $wp_admin_bar->add_group( array(
841 'parent' => 'wp-logo',
842 'id' => 'wp-logo-external',
844 'class' => 'ab-sub-secondary',
850 * Style and scripts for the admin bar.
854 function wp_admin_bar_header() { ?>
855 <style type="text/css" media="print">#wpadminbar { display:none; }</style>
860 * Default admin bar callback.
864 function _admin_bar_bump_cb() { ?>
865 <style type="text/css" media="screen">
866 html { margin-top: 32px !important; }
867 * html body { margin-top: 32px !important; }
868 @media screen and ( max-width: 782px ) {
869 html { margin-top: 46px !important; }
870 * html body { margin-top: 46px !important; }
877 * Sets the display status of the admin bar.
879 * This can be called immediately upon plugin load. It does not need to be called
880 * from a function hooked to the {@see 'init'} action.
884 * @global bool $show_admin_bar
886 * @param bool $show Whether to allow the admin bar to show.
888 function show_admin_bar( $show ) {
889 global $show_admin_bar;
890 $show_admin_bar = (bool) $show;
894 * Determine whether the admin bar should be showing.
898 * @global bool $show_admin_bar
899 * @global string $pagenow
901 * @return bool Whether the admin bar should be showing.
903 function is_admin_bar_showing() {
904 global $show_admin_bar, $pagenow;
906 // For all these types of requests, we never want an admin bar.
907 if ( defined('XMLRPC_REQUEST') || defined('DOING_AJAX') || defined('IFRAME_REQUEST') )
914 // Integrated into the admin.
918 if ( ! isset( $show_admin_bar ) ) {
919 if ( ! is_user_logged_in() || 'wp-login.php' == $pagenow ) {
920 $show_admin_bar = false;
922 $show_admin_bar = _get_admin_bar_pref();
927 * Filters whether to show the admin bar.
929 * Returning false to this hook is the recommended way to hide the admin bar.
930 * The user's display preference is used for logged in users.
934 * @param bool $show_admin_bar Whether the admin bar should be shown. Default false.
936 $show_admin_bar = apply_filters( 'show_admin_bar', $show_admin_bar );
938 return $show_admin_bar;
942 * Retrieve the admin bar display preference of a user.
947 * @param string $context Context of this preference check. Defaults to 'front'. The 'admin'
948 * preference is no longer used.
949 * @param int $user Optional. ID of the user to check, defaults to 0 for current user.
950 * @return bool Whether the admin bar should be showing for this user.
952 function _get_admin_bar_pref( $context = 'front', $user = 0 ) {
953 $pref = get_user_option( "show_admin_bar_{$context}", $user );
954 if ( false === $pref )
957 return 'true' === $pref;