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 '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 * Filter 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 * Render the admin bar to the page based on the $wp_admin_bar->menu member var.
55 * This is called very late on the footer actions so that it will render after anything else being
56 * added to the footer.
58 * It includes the action "admin_bar_menu" which should be used to hook in and
59 * add new menus to the admin bar. That way you can be sure that you are adding at most optimal point,
60 * right before the admin bar is rendered. This also gives you access to the $post global, among others.
64 * @global WP_Admin_Bar $wp_admin_bar
66 function wp_admin_bar_render() {
69 if ( ! is_admin_bar_showing() || ! is_object( $wp_admin_bar ) )
73 * Load all necessary admin bar items.
75 * This is the hook used to add, remove, or manipulate admin bar items.
79 * @param WP_Admin_Bar $wp_admin_bar WP_Admin_Bar instance, passed by reference
81 do_action_ref_array( 'admin_bar_menu', array( &$wp_admin_bar ) );
84 * Fires before the admin bar is rendered.
88 do_action( 'wp_before_admin_bar_render' );
90 $wp_admin_bar->render();
93 * Fires after the admin bar is rendered.
97 do_action( 'wp_after_admin_bar_render' );
101 * Add the WordPress logo menu.
105 * @param WP_Admin_Bar $wp_admin_bar
107 function wp_admin_bar_wp_menu( $wp_admin_bar ) {
108 $wp_admin_bar->add_menu( array(
110 'title' => '<span class="ab-icon"></span><span class="screen-reader-text">' . __( 'About WordPress' ) . '</span>',
111 'href' => self_admin_url( 'about.php' ),
114 if ( is_user_logged_in() ) {
115 // Add "About WordPress" link
116 $wp_admin_bar->add_menu( array(
117 'parent' => 'wp-logo',
119 'title' => __('About WordPress'),
120 'href' => self_admin_url( 'about.php' ),
124 // Add WordPress.org link
125 $wp_admin_bar->add_menu( array(
126 'parent' => 'wp-logo-external',
128 'title' => __('WordPress.org'),
129 'href' => __('https://wordpress.org/'),
133 $wp_admin_bar->add_menu( array(
134 'parent' => 'wp-logo-external',
135 'id' => 'documentation',
136 'title' => __('Documentation'),
137 'href' => __('https://codex.wordpress.org/'),
141 $wp_admin_bar->add_menu( array(
142 'parent' => 'wp-logo-external',
143 'id' => 'support-forums',
144 'title' => __('Support Forums'),
145 'href' => __('https://wordpress.org/support/'),
149 $wp_admin_bar->add_menu( array(
150 'parent' => 'wp-logo-external',
152 'title' => __('Feedback'),
153 'href' => __('https://wordpress.org/support/forum/requests-and-feedback'),
158 * Add the sidebar toggle button.
162 * @param WP_Admin_Bar $wp_admin_bar
164 function wp_admin_bar_sidebar_toggle( $wp_admin_bar ) {
166 $wp_admin_bar->add_menu( array(
167 'id' => 'menu-toggle',
168 'title' => '<span class="ab-icon"></span><span class="screen-reader-text">' . __( 'Menu' ) . '</span>',
175 * Add the "My Account" item.
179 * @param WP_Admin_Bar $wp_admin_bar
181 function wp_admin_bar_my_account_item( $wp_admin_bar ) {
182 $user_id = get_current_user_id();
183 $current_user = wp_get_current_user();
188 if ( current_user_can( 'read' ) ) {
189 $profile_url = get_edit_profile_url( $user_id );
190 } elseif ( is_multisite() ) {
191 $profile_url = get_dashboard_url( $user_id, 'profile.php' );
193 $profile_url = false;
196 $avatar = get_avatar( $user_id, 26 );
197 $howdy = sprintf( __('Howdy, %1$s'), $current_user->display_name );
198 $class = empty( $avatar ) ? '' : 'with-avatar';
200 $wp_admin_bar->add_menu( array(
201 'id' => 'my-account',
202 'parent' => 'top-secondary',
203 'title' => $howdy . $avatar,
204 'href' => $profile_url,
212 * Add the "My Account" submenu items.
216 * @param WP_Admin_Bar $wp_admin_bar
218 function wp_admin_bar_my_account_menu( $wp_admin_bar ) {
219 $user_id = get_current_user_id();
220 $current_user = wp_get_current_user();
225 if ( current_user_can( 'read' ) ) {
226 $profile_url = get_edit_profile_url( $user_id );
227 } elseif ( is_multisite() ) {
228 $profile_url = get_dashboard_url( $user_id, 'profile.php' );
230 $profile_url = false;
233 $wp_admin_bar->add_group( array(
234 'parent' => 'my-account',
235 'id' => 'user-actions',
238 $user_info = get_avatar( $user_id, 64 );
239 $user_info .= "<span class='display-name'>{$current_user->display_name}</span>";
241 if ( $current_user->display_name !== $current_user->user_login )
242 $user_info .= "<span class='username'>{$current_user->user_login}</span>";
244 $wp_admin_bar->add_menu( array(
245 'parent' => 'user-actions',
247 'title' => $user_info,
248 'href' => $profile_url,
254 if ( false !== $profile_url ) {
255 $wp_admin_bar->add_menu( array(
256 'parent' => 'user-actions',
257 'id' => 'edit-profile',
258 'title' => __( 'Edit My Profile' ),
259 'href' => $profile_url,
263 $wp_admin_bar->add_menu( array(
264 'parent' => 'user-actions',
266 'title' => __( 'Log Out' ),
267 'href' => wp_logout_url(),
272 * Add the "Site Name" menu.
276 * @param WP_Admin_Bar $wp_admin_bar
278 function wp_admin_bar_site_menu( $wp_admin_bar ) {
279 // Don't show for logged out users.
280 if ( ! is_user_logged_in() )
283 // Show only when the user is a member of this site, or they're a super admin.
284 if ( ! is_user_member_of_blog() && ! is_super_admin() )
287 $blogname = get_bloginfo('name');
290 $blogname = preg_replace( '#^(https?://)?(www.)?#', '', get_home_url() );
293 if ( is_network_admin() ) {
294 $blogname = sprintf( __('Network Admin: %s'), esc_html( get_current_site()->site_name ) );
295 } elseif ( is_user_admin() ) {
296 $blogname = sprintf( __('User Dashboard: %s'), esc_html( get_current_site()->site_name ) );
299 $title = wp_html_excerpt( $blogname, 40, '…' );
301 $wp_admin_bar->add_menu( array(
304 'href' => ( is_admin() || ! current_user_can( 'read' ) ) ? home_url( '/' ) : admin_url(),
307 // Create submenu items.
310 // Add an option to visit the site.
311 $wp_admin_bar->add_menu( array(
312 'parent' => 'site-name',
314 'title' => __( 'Visit Site' ),
315 'href' => home_url( '/' ),
318 if ( is_blog_admin() && is_multisite() && current_user_can( 'manage_sites' ) ) {
319 $wp_admin_bar->add_menu( array(
320 'parent' => 'site-name',
322 'title' => __( 'Edit Site' ),
323 'href' => network_admin_url( 'site-info.php?id=' . get_current_blog_id() ),
327 } else if ( current_user_can( 'read' ) ) {
328 // We're on the front end, link to the Dashboard.
329 $wp_admin_bar->add_menu( array(
330 'parent' => 'site-name',
332 'title' => __( 'Dashboard' ),
333 'href' => admin_url(),
336 // Add the appearance submenu items.
337 wp_admin_bar_appearance_menu( $wp_admin_bar );
342 * Adds the "Customize" link to the Toolbar.
346 * @param WP_Admin_Bar $wp_admin_bar WP_Admin_Bar instance.
348 function wp_admin_bar_customize_menu( $wp_admin_bar ) {
349 // Don't show for users who can't access the customizer or when in the admin.
350 if ( ! current_user_can( 'customize' ) || is_admin() ) {
354 $current_url = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
355 $customize_url = add_query_arg( 'url', urlencode( $current_url ), wp_customize_url() );
357 $wp_admin_bar->add_menu( array(
359 'title' => __( 'Customize' ),
360 'href' => $customize_url,
362 'class' => 'hide-if-no-customize',
365 add_action( 'wp_before_admin_bar_render', 'wp_customize_support_script' );
369 * Add the "My Sites/[Site Name]" menu and all submenus.
373 * @param WP_Admin_Bar $wp_admin_bar
375 function wp_admin_bar_my_sites_menu( $wp_admin_bar ) {
376 // Don't show for logged out users or single site mode.
377 if ( ! is_user_logged_in() || ! is_multisite() )
380 // Show only when the user has at least one site, or they're a super admin.
381 if ( count( $wp_admin_bar->user->blogs ) < 1 && ! is_super_admin() )
384 if ( $wp_admin_bar->user->active_blog ) {
385 $my_sites_url = get_admin_url( $wp_admin_bar->user->active_blog->blog_id, 'my-sites.php' );
387 $my_sites_url = admin_url( 'my-sites.php' );
390 $wp_admin_bar->add_menu( array(
392 'title' => __( 'My Sites' ),
393 'href' => $my_sites_url,
396 if ( is_super_admin() ) {
397 $wp_admin_bar->add_group( array(
398 'parent' => 'my-sites',
399 'id' => 'my-sites-super-admin',
402 $wp_admin_bar->add_menu( array(
403 'parent' => 'my-sites-super-admin',
404 'id' => 'network-admin',
405 'title' => __('Network Admin'),
406 'href' => network_admin_url(),
409 $wp_admin_bar->add_menu( array(
410 'parent' => 'network-admin',
411 'id' => 'network-admin-d',
412 'title' => __( 'Dashboard' ),
413 'href' => network_admin_url(),
415 $wp_admin_bar->add_menu( array(
416 'parent' => 'network-admin',
417 'id' => 'network-admin-s',
418 'title' => __( 'Sites' ),
419 'href' => network_admin_url( 'sites.php' ),
421 $wp_admin_bar->add_menu( array(
422 'parent' => 'network-admin',
423 'id' => 'network-admin-u',
424 'title' => __( 'Users' ),
425 'href' => network_admin_url( 'users.php' ),
427 $wp_admin_bar->add_menu( array(
428 'parent' => 'network-admin',
429 'id' => 'network-admin-t',
430 'title' => __( 'Themes' ),
431 'href' => network_admin_url( 'themes.php' ),
433 $wp_admin_bar->add_menu( array(
434 'parent' => 'network-admin',
435 'id' => 'network-admin-p',
436 'title' => __( 'Plugins' ),
437 'href' => network_admin_url( 'plugins.php' ),
439 $wp_admin_bar->add_menu( array(
440 'parent' => 'network-admin',
441 'id' => 'network-admin-o',
442 'title' => __( 'Settings' ),
443 'href' => network_admin_url( 'settings.php' ),
448 $wp_admin_bar->add_group( array(
449 'parent' => 'my-sites',
450 'id' => 'my-sites-list',
452 'class' => is_super_admin() ? 'ab-sub-secondary' : '',
456 foreach ( (array) $wp_admin_bar->user->blogs as $blog ) {
457 switch_to_blog( $blog->userblog_id );
459 $blavatar = '<div class="blavatar"></div>';
461 $blogname = $blog->blogname;
464 $blogname = preg_replace( '#^(https?://)?(www.)?#', '', get_home_url() );
467 $menu_id = 'blog-' . $blog->userblog_id;
469 $wp_admin_bar->add_menu( array(
470 'parent' => 'my-sites-list',
472 'title' => $blavatar . $blogname,
473 'href' => admin_url(),
476 $wp_admin_bar->add_menu( array(
477 'parent' => $menu_id,
478 'id' => $menu_id . '-d',
479 'title' => __( 'Dashboard' ),
480 'href' => admin_url(),
483 if ( current_user_can( get_post_type_object( 'post' )->cap->create_posts ) ) {
484 $wp_admin_bar->add_menu( array(
485 'parent' => $menu_id,
486 'id' => $menu_id . '-n',
487 'title' => __( 'New Post' ),
488 'href' => admin_url( 'post-new.php' ),
492 if ( current_user_can( 'edit_posts' ) ) {
493 $wp_admin_bar->add_menu( array(
494 'parent' => $menu_id,
495 'id' => $menu_id . '-c',
496 'title' => __( 'Manage Comments' ),
497 'href' => admin_url( 'edit-comments.php' ),
501 $wp_admin_bar->add_menu( array(
502 'parent' => $menu_id,
503 'id' => $menu_id . '-v',
504 'title' => __( 'Visit Site' ),
505 'href' => home_url( '/' ),
508 restore_current_blog();
513 * Provide a shortlink.
517 * @param WP_Admin_Bar $wp_admin_bar
519 function wp_admin_bar_shortlink_menu( $wp_admin_bar ) {
520 $short = wp_get_shortlink( 0, 'query' );
521 $id = 'get-shortlink';
523 if ( empty( $short ) )
526 $html = '<input class="shortlink-input" type="text" readonly="readonly" value="' . esc_attr( $short ) . '" />';
528 $wp_admin_bar->add_menu( array(
530 'title' => __( 'Shortlink' ),
532 'meta' => array( 'html' => $html ),
537 * Provide an edit link for posts and terms.
541 * @global WP_Term $tag
542 * @global WP_Query $wp_the_query
544 * @param WP_Admin_Bar $wp_admin_bar
546 function wp_admin_bar_edit_menu( $wp_admin_bar ) {
547 global $tag, $wp_the_query;
550 $current_screen = get_current_screen();
553 if ( 'post' == $current_screen->base
554 && 'add' != $current_screen->action
555 && ( $post_type_object = get_post_type_object( $post->post_type ) )
556 && current_user_can( 'read_post', $post->ID )
557 && ( $post_type_object->public )
558 && ( $post_type_object->show_in_admin_bar ) )
560 if ( 'draft' == $post->post_status ) {
561 $draft_link = set_url_scheme( get_permalink( $post->ID ) );
562 $preview_link = get_preview_post_link( $post, array(), $draft_link );
563 $wp_admin_bar->add_menu( array(
565 'title' => $post_type_object->labels->view_item,
566 'href' => esc_url( $preview_link ),
567 'meta' => array( 'target' => 'wp-preview-' . $post->ID ),
570 $wp_admin_bar->add_menu( array(
572 'title' => $post_type_object->labels->view_item,
573 'href' => get_permalink( $post->ID )
576 } elseif ( 'edit-tags' == $current_screen->base
577 && isset( $tag ) && is_object( $tag )
578 && ( $tax = get_taxonomy( $tag->taxonomy ) )
581 $wp_admin_bar->add_menu( array(
583 'title' => $tax->labels->view_item,
584 'href' => get_term_link( $tag )
588 $current_object = $wp_the_query->get_queried_object();
590 if ( empty( $current_object ) )
593 if ( ! empty( $current_object->post_type )
594 && ( $post_type_object = get_post_type_object( $current_object->post_type ) )
595 && current_user_can( 'edit_post', $current_object->ID )
596 && $post_type_object->show_in_admin_bar
597 && $edit_post_link = get_edit_post_link( $current_object->ID ) )
599 $wp_admin_bar->add_menu( array(
601 'title' => $post_type_object->labels->edit_item,
602 'href' => $edit_post_link
604 } elseif ( ! empty( $current_object->taxonomy )
605 && ( $tax = get_taxonomy( $current_object->taxonomy ) )
606 && current_user_can( $tax->cap->edit_terms )
607 && $edit_term_link = get_edit_term_link( $current_object->term_id, $current_object->taxonomy ) )
609 $wp_admin_bar->add_menu( array(
611 'title' => $tax->labels->edit_item,
612 'href' => $edit_term_link
619 * Add "Add New" menu.
623 * @param WP_Admin_Bar $wp_admin_bar
625 function wp_admin_bar_new_content_menu( $wp_admin_bar ) {
628 $cpts = (array) get_post_types( array( 'show_in_admin_bar' => true ), 'objects' );
630 if ( isset( $cpts['post'] ) && current_user_can( $cpts['post']->cap->create_posts ) )
631 $actions[ 'post-new.php' ] = array( $cpts['post']->labels->name_admin_bar, 'new-post' );
633 if ( isset( $cpts['attachment'] ) && current_user_can( 'upload_files' ) )
634 $actions[ 'media-new.php' ] = array( $cpts['attachment']->labels->name_admin_bar, 'new-media' );
636 if ( current_user_can( 'manage_links' ) )
637 $actions[ 'link-add.php' ] = array( _x( 'Link', 'add new from admin bar' ), 'new-link' );
639 if ( isset( $cpts['page'] ) && current_user_can( $cpts['page']->cap->create_posts ) )
640 $actions[ 'post-new.php?post_type=page' ] = array( $cpts['page']->labels->name_admin_bar, 'new-page' );
642 unset( $cpts['post'], $cpts['page'], $cpts['attachment'] );
644 // Add any additional custom post types.
645 foreach ( $cpts as $cpt ) {
646 if ( ! current_user_can( $cpt->cap->create_posts ) )
649 $key = 'post-new.php?post_type=' . $cpt->name;
650 $actions[ $key ] = array( $cpt->labels->name_admin_bar, 'new-' . $cpt->name );
652 // Avoid clash with parent node and a 'content' post type.
653 if ( isset( $actions['post-new.php?post_type=content'] ) )
654 $actions['post-new.php?post_type=content'][1] = 'add-new-content';
656 if ( current_user_can( 'create_users' ) || current_user_can( 'promote_users' ) )
657 $actions[ 'user-new.php' ] = array( _x( 'User', 'add new from admin bar' ), 'new-user' );
662 $title = '<span class="ab-icon"></span><span class="ab-label">' . _x( 'New', 'admin bar menu group label' ) . '</span>';
664 $wp_admin_bar->add_menu( array(
665 'id' => 'new-content',
667 'href' => admin_url( current( array_keys( $actions ) ) ),
670 foreach ( $actions as $link => $action ) {
671 list( $title, $id ) = $action;
673 $wp_admin_bar->add_menu( array(
674 'parent' => 'new-content',
677 'href' => admin_url( $link )
683 * Add edit comments link with awaiting moderation count bubble.
687 * @param WP_Admin_Bar $wp_admin_bar
689 function wp_admin_bar_comments_menu( $wp_admin_bar ) {
690 if ( !current_user_can('edit_posts') )
693 $awaiting_mod = wp_count_comments();
694 $awaiting_mod = $awaiting_mod->moderated;
695 $awaiting_title = esc_attr( sprintf( _n( '%s comment awaiting moderation', '%s comments awaiting moderation', $awaiting_mod ), number_format_i18n( $awaiting_mod ) ) );
697 $icon = '<span class="ab-icon"></span>';
698 $title = '<span id="ab-awaiting-mod" class="ab-label awaiting-mod pending-count count-' . $awaiting_mod . '">' . number_format_i18n( $awaiting_mod ) . '</span>';
700 $wp_admin_bar->add_menu( array(
702 'title' => $icon . $title,
703 'href' => admin_url('edit-comments.php'),
704 'meta' => array( 'title' => $awaiting_title ),
709 * Add appearance submenu items to the "Site Name" menu.
713 * @param WP_Admin_Bar $wp_admin_bar
715 function wp_admin_bar_appearance_menu( $wp_admin_bar ) {
716 $wp_admin_bar->add_group( array( 'parent' => 'site-name', 'id' => 'appearance' ) );
718 if ( current_user_can( 'switch_themes' ) ) {
719 $wp_admin_bar->add_menu( array(
720 'parent' => 'appearance',
722 'title' => __( 'Themes' ),
723 'href' => admin_url( 'themes.php' ),
727 if ( ! current_user_can( 'edit_theme_options' ) ) {
731 if ( current_theme_supports( 'widgets' ) ) {
732 $wp_admin_bar->add_menu( array(
733 'parent' => 'appearance',
735 'title' => __( 'Widgets' ),
736 'href' => admin_url( 'widgets.php' ),
740 if ( current_theme_supports( 'menus' ) || current_theme_supports( 'widgets' ) )
741 $wp_admin_bar->add_menu( array( 'parent' => 'appearance', 'id' => 'menus', 'title' => __('Menus'), 'href' => admin_url('nav-menus.php') ) );
743 if ( current_theme_supports( 'custom-background' ) ) {
744 $wp_admin_bar->add_menu( array(
745 'parent' => 'appearance',
746 'id' => 'background',
747 'title' => __( 'Background' ),
748 'href' => admin_url( 'themes.php?page=custom-background' ),
750 'class' => 'hide-if-customize',
755 if ( current_theme_supports( 'custom-header' ) ) {
756 $wp_admin_bar->add_menu( array(
757 'parent' => 'appearance',
759 'title' => __( 'Header' ),
760 'href' => admin_url( 'themes.php?page=custom-header' ),
762 'class' => 'hide-if-customize',
770 * Provide an update link if theme/plugin/core updates are available.
774 * @param WP_Admin_Bar $wp_admin_bar
776 function wp_admin_bar_updates_menu( $wp_admin_bar ) {
778 $update_data = wp_get_update_data();
780 if ( !$update_data['counts']['total'] )
783 $title = '<span class="ab-icon"></span><span class="ab-label">' . number_format_i18n( $update_data['counts']['total'] ) . '</span>';
784 $title .= '<span class="screen-reader-text">' . $update_data['title'] . '</span>';
786 $wp_admin_bar->add_menu( array(
789 'href' => network_admin_url( 'update-core.php' ),
791 'title' => $update_data['title'],
801 * @param WP_Admin_Bar $wp_admin_bar
803 function wp_admin_bar_search_menu( $wp_admin_bar ) {
807 $form = '<form action="' . esc_url( home_url( '/' ) ) . '" method="get" id="adminbarsearch">';
808 $form .= '<input class="adminbar-input" name="s" id="adminbar-search" type="text" value="" maxlength="150" />';
809 $form .= '<label for="adminbar-search" class="screen-reader-text">' . __( 'Search' ) . '</label>';
810 $form .= '<input type="submit" class="adminbar-button" value="' . __('Search') . '"/>';
813 $wp_admin_bar->add_menu( array(
814 'parent' => 'top-secondary',
818 'class' => 'admin-bar-search',
825 * Add secondary menus.
829 * @param WP_Admin_Bar $wp_admin_bar
831 function wp_admin_bar_add_secondary_groups( $wp_admin_bar ) {
832 $wp_admin_bar->add_group( array(
833 'id' => 'top-secondary',
835 'class' => 'ab-top-secondary',
839 $wp_admin_bar->add_group( array(
840 'parent' => 'wp-logo',
841 'id' => 'wp-logo-external',
843 'class' => 'ab-sub-secondary',
849 * Style and scripts for the admin bar.
853 function wp_admin_bar_header() { ?>
854 <style type="text/css" media="print">#wpadminbar { display:none; }</style>
859 * Default admin bar callback.
863 function _admin_bar_bump_cb() { ?>
864 <style type="text/css" media="screen">
865 html { margin-top: 32px !important; }
866 * html body { margin-top: 32px !important; }
867 @media screen and ( max-width: 782px ) {
868 html { margin-top: 46px !important; }
869 * html body { margin-top: 46px !important; }
876 * Set the display status of the admin bar.
878 * This can be called immediately upon plugin load. It does not need to be called from a function hooked to the init action.
882 * @global WP_Admin_Bar $wp_admin_bar
884 * @param bool $show Whether to allow the admin bar to show.
886 function show_admin_bar( $show ) {
887 global $show_admin_bar;
888 $show_admin_bar = (bool) $show;
892 * Determine whether the admin bar should be showing.
896 * @global WP_Admin_Bar $wp_admin_bar
897 * @global string $pagenow
899 * @return bool Whether the admin bar should be showing.
901 function is_admin_bar_showing() {
902 global $show_admin_bar, $pagenow;
904 // For all these types of requests, we never want an admin bar.
905 if ( defined('XMLRPC_REQUEST') || defined('DOING_AJAX') || defined('IFRAME_REQUEST') )
912 // Integrated into the admin.
916 if ( ! isset( $show_admin_bar ) ) {
917 if ( ! is_user_logged_in() || 'wp-login.php' == $pagenow ) {
918 $show_admin_bar = false;
920 $show_admin_bar = _get_admin_bar_pref();
925 * Filter whether to show the admin bar.
927 * Returning false to this hook is the recommended way to hide the admin bar.
928 * The user's display preference is used for logged in users.
932 * @param bool $show_admin_bar Whether the admin bar should be shown. Default false.
934 $show_admin_bar = apply_filters( 'show_admin_bar', $show_admin_bar );
936 return $show_admin_bar;
940 * Retrieve the admin bar display preference of a user.
945 * @param string $context Context of this preference check. Defaults to 'front'. The 'admin'
946 * preference is no longer used.
947 * @param int $user Optional. ID of the user to check, defaults to 0 for current user.
948 * @return bool Whether the admin bar should be showing for this user.
950 function _get_admin_bar_pref( $context = 'front', $user = 0 ) {
951 $pref = get_user_option( "show_admin_bar_{$context}", $user );
952 if ( false === $pref )
955 return 'true' === $pref;