5 * This code handles the building and rendering of the press bar.
9 * Instantiate the admin bar object and set it up as a global for access elsewhere.
11 * UNHOOKING THIS FUNCTION WILL NOT PROPERLY REMOVE THE ADMIN BAR.
12 * For that, use show_admin_bar(false) or the 'show_admin_bar' filter.
17 * @global WP_Admin_Bar $wp_admin_bar
19 * @return bool Whether the admin bar was successfully initialized.
21 function _wp_admin_bar_init() {
24 if ( ! is_admin_bar_showing() )
27 /* Load the admin bar class code ready for instantiation */
28 require_once( ABSPATH . WPINC . '/class-wp-admin-bar.php' );
30 /* Instantiate the admin bar */
33 * Filter the admin bar class to instantiate.
37 * @param string $wp_admin_bar_class Admin bar class to use. Default 'WP_Admin_Bar'.
39 $admin_bar_class = apply_filters( 'wp_admin_bar_class', 'WP_Admin_Bar' );
40 if ( class_exists( $admin_bar_class ) )
41 $wp_admin_bar = new $admin_bar_class;
45 $wp_admin_bar->initialize();
46 $wp_admin_bar->add_menus();
52 * Render the admin bar to the page based on the $wp_admin_bar->menu member var.
53 * This is called very late on the footer actions so that it will render after anything else being
54 * added to the footer.
56 * It includes the action "admin_bar_menu" which should be used to hook in and
57 * add new menus to the admin bar. That way you can be sure that you are adding at most optimal point,
58 * right before the admin bar is rendered. This also gives you access to the $post global, among others.
62 * @global WP_Admin_Bar $wp_admin_bar
64 function wp_admin_bar_render() {
67 if ( ! is_admin_bar_showing() || ! is_object( $wp_admin_bar ) )
71 * Load all necessary admin bar items.
73 * This is the hook used to add, remove, or manipulate admin bar items.
77 * @param WP_Admin_Bar $wp_admin_bar WP_Admin_Bar instance, passed by reference
79 do_action_ref_array( 'admin_bar_menu', array( &$wp_admin_bar ) );
82 * Fires before the admin bar is rendered.
86 do_action( 'wp_before_admin_bar_render' );
88 $wp_admin_bar->render();
91 * Fires after the admin bar is rendered.
95 do_action( 'wp_after_admin_bar_render' );
99 * Add the WordPress logo menu.
103 * @param WP_Admin_Bar $wp_admin_bar
105 function wp_admin_bar_wp_menu( $wp_admin_bar ) {
106 $wp_admin_bar->add_menu( array(
108 'title' => '<span class="ab-icon"></span><span class="screen-reader-text">' . __( 'About WordPress' ) . '</span>',
109 'href' => self_admin_url( 'about.php' ),
112 if ( is_user_logged_in() ) {
113 // Add "About WordPress" link
114 $wp_admin_bar->add_menu( array(
115 'parent' => 'wp-logo',
117 'title' => __('About WordPress'),
118 'href' => self_admin_url( 'about.php' ),
122 // Add WordPress.org link
123 $wp_admin_bar->add_menu( array(
124 'parent' => 'wp-logo-external',
126 'title' => __('WordPress.org'),
127 'href' => __('https://wordpress.org/'),
131 $wp_admin_bar->add_menu( array(
132 'parent' => 'wp-logo-external',
133 'id' => 'documentation',
134 'title' => __('Documentation'),
135 'href' => __('https://codex.wordpress.org/'),
139 $wp_admin_bar->add_menu( array(
140 'parent' => 'wp-logo-external',
141 'id' => 'support-forums',
142 'title' => __('Support Forums'),
143 'href' => __('https://wordpress.org/support/'),
147 $wp_admin_bar->add_menu( array(
148 'parent' => 'wp-logo-external',
150 'title' => __('Feedback'),
151 'href' => __('https://wordpress.org/support/forum/requests-and-feedback'),
156 * Add the sidebar toggle button.
160 * @param WP_Admin_Bar $wp_admin_bar
162 function wp_admin_bar_sidebar_toggle( $wp_admin_bar ) {
164 $wp_admin_bar->add_menu( array(
165 'id' => 'menu-toggle',
166 'title' => '<span class="ab-icon"></span><span class="screen-reader-text">' . __( 'Menu' ) . '</span>',
173 * Add the "My Account" item.
177 * @param WP_Admin_Bar $wp_admin_bar
179 function wp_admin_bar_my_account_item( $wp_admin_bar ) {
180 $user_id = get_current_user_id();
181 $current_user = wp_get_current_user();
182 $profile_url = get_edit_profile_url( $user_id );
187 $avatar = get_avatar( $user_id, 26 );
188 $howdy = sprintf( __('Howdy, %1$s'), $current_user->display_name );
189 $class = empty( $avatar ) ? '' : 'with-avatar';
191 $wp_admin_bar->add_menu( array(
192 'id' => 'my-account',
193 'parent' => 'top-secondary',
194 'title' => $howdy . $avatar,
195 'href' => $profile_url,
203 * Add the "My Account" submenu items.
207 * @param WP_Admin_Bar $wp_admin_bar
209 function wp_admin_bar_my_account_menu( $wp_admin_bar ) {
210 $user_id = get_current_user_id();
211 $current_user = wp_get_current_user();
212 $profile_url = get_edit_profile_url( $user_id );
217 $wp_admin_bar->add_group( array(
218 'parent' => 'my-account',
219 'id' => 'user-actions',
222 $user_info = get_avatar( $user_id, 64 );
223 $user_info .= "<span class='display-name'>{$current_user->display_name}</span>";
225 if ( $current_user->display_name !== $current_user->user_login )
226 $user_info .= "<span class='username'>{$current_user->user_login}</span>";
228 $wp_admin_bar->add_menu( array(
229 'parent' => 'user-actions',
231 'title' => $user_info,
232 'href' => $profile_url,
237 $wp_admin_bar->add_menu( array(
238 'parent' => 'user-actions',
239 'id' => 'edit-profile',
240 'title' => __( 'Edit My Profile' ),
241 'href' => $profile_url,
243 $wp_admin_bar->add_menu( array(
244 'parent' => 'user-actions',
246 'title' => __( 'Log Out' ),
247 'href' => wp_logout_url(),
252 * Add the "Site Name" menu.
256 * @param WP_Admin_Bar $wp_admin_bar
258 function wp_admin_bar_site_menu( $wp_admin_bar ) {
259 // Don't show for logged out users.
260 if ( ! is_user_logged_in() )
263 // Show only when the user is a member of this site, or they're a super admin.
264 if ( ! is_user_member_of_blog() && ! is_super_admin() )
267 $blogname = get_bloginfo('name');
270 $blogname = preg_replace( '#^(https?://)?(www.)?#', '', get_home_url() );
273 if ( is_network_admin() ) {
274 $blogname = sprintf( __('Network Admin: %s'), esc_html( get_current_site()->site_name ) );
275 } elseif ( is_user_admin() ) {
276 $blogname = sprintf( __('User Dashboard: %s'), esc_html( get_current_site()->site_name ) );
279 $title = wp_html_excerpt( $blogname, 40, '…' );
281 $wp_admin_bar->add_menu( array(
284 'href' => is_admin() ? home_url( '/' ) : admin_url(),
287 // Create submenu items.
290 // Add an option to visit the site.
291 $wp_admin_bar->add_menu( array(
292 'parent' => 'site-name',
294 'title' => __( 'Visit Site' ),
295 'href' => home_url( '/' ),
298 if ( is_blog_admin() && is_multisite() && current_user_can( 'manage_sites' ) ) {
299 $wp_admin_bar->add_menu( array(
300 'parent' => 'site-name',
302 'title' => __( 'Edit Site' ),
303 'href' => network_admin_url( 'site-info.php?id=' . get_current_blog_id() ),
308 // We're on the front end, link to the Dashboard.
309 $wp_admin_bar->add_menu( array(
310 'parent' => 'site-name',
312 'title' => __( 'Dashboard' ),
313 'href' => admin_url(),
316 // Add the appearance submenu items.
317 wp_admin_bar_appearance_menu( $wp_admin_bar );
322 * Adds the "Customize" link to the Toolbar.
326 * @param WP_Admin_Bar $wp_admin_bar WP_Admin_Bar instance.
328 function wp_admin_bar_customize_menu( $wp_admin_bar ) {
329 // Don't show for users who can't access the customizer or when in the admin.
330 if ( ! current_user_can( 'customize' ) || is_admin() ) {
334 $current_url = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
335 $customize_url = add_query_arg( 'url', urlencode( $current_url ), wp_customize_url() );
337 $wp_admin_bar->add_menu( array(
339 'title' => __( 'Customize' ),
340 'href' => $customize_url,
342 'class' => 'hide-if-no-customize',
345 add_action( 'wp_before_admin_bar_render', 'wp_customize_support_script' );
349 * Add the "My Sites/[Site Name]" menu and all submenus.
353 * @param WP_Admin_Bar $wp_admin_bar
355 function wp_admin_bar_my_sites_menu( $wp_admin_bar ) {
356 // Don't show for logged out users or single site mode.
357 if ( ! is_user_logged_in() || ! is_multisite() )
360 // Show only when the user has at least one site, or they're a super admin.
361 if ( count( $wp_admin_bar->user->blogs ) < 1 && ! is_super_admin() )
364 if ( $wp_admin_bar->user->active_blog ) {
365 $my_sites_url = get_admin_url( $wp_admin_bar->user->active_blog->blog_id, 'my-sites.php' );
367 $my_sites_url = admin_url( 'my-sites.php' );
370 $wp_admin_bar->add_menu( array(
372 'title' => __( 'My Sites' ),
373 'href' => $my_sites_url,
376 if ( is_super_admin() ) {
377 $wp_admin_bar->add_group( array(
378 'parent' => 'my-sites',
379 'id' => 'my-sites-super-admin',
382 $wp_admin_bar->add_menu( array(
383 'parent' => 'my-sites-super-admin',
384 'id' => 'network-admin',
385 'title' => __('Network Admin'),
386 'href' => network_admin_url(),
389 $wp_admin_bar->add_menu( array(
390 'parent' => 'network-admin',
391 'id' => 'network-admin-d',
392 'title' => __( 'Dashboard' ),
393 'href' => network_admin_url(),
395 $wp_admin_bar->add_menu( array(
396 'parent' => 'network-admin',
397 'id' => 'network-admin-s',
398 'title' => __( 'Sites' ),
399 'href' => network_admin_url( 'sites.php' ),
401 $wp_admin_bar->add_menu( array(
402 'parent' => 'network-admin',
403 'id' => 'network-admin-u',
404 'title' => __( 'Users' ),
405 'href' => network_admin_url( 'users.php' ),
407 $wp_admin_bar->add_menu( array(
408 'parent' => 'network-admin',
409 'id' => 'network-admin-t',
410 'title' => __( 'Themes' ),
411 'href' => network_admin_url( 'themes.php' ),
413 $wp_admin_bar->add_menu( array(
414 'parent' => 'network-admin',
415 'id' => 'network-admin-p',
416 'title' => __( 'Plugins' ),
417 'href' => network_admin_url( 'plugins.php' ),
422 $wp_admin_bar->add_group( array(
423 'parent' => 'my-sites',
424 'id' => 'my-sites-list',
426 'class' => is_super_admin() ? 'ab-sub-secondary' : '',
430 foreach ( (array) $wp_admin_bar->user->blogs as $blog ) {
431 switch_to_blog( $blog->userblog_id );
433 $blavatar = '<div class="blavatar"></div>';
435 $blogname = $blog->blogname;
438 $blogname = preg_replace( '#^(https?://)?(www.)?#', '', get_home_url() );
441 $menu_id = 'blog-' . $blog->userblog_id;
443 $wp_admin_bar->add_menu( array(
444 'parent' => 'my-sites-list',
446 'title' => $blavatar . $blogname,
447 'href' => admin_url(),
450 $wp_admin_bar->add_menu( array(
451 'parent' => $menu_id,
452 'id' => $menu_id . '-d',
453 'title' => __( 'Dashboard' ),
454 'href' => admin_url(),
457 if ( current_user_can( get_post_type_object( 'post' )->cap->create_posts ) ) {
458 $wp_admin_bar->add_menu( array(
459 'parent' => $menu_id,
460 'id' => $menu_id . '-n',
461 'title' => __( 'New Post' ),
462 'href' => admin_url( 'post-new.php' ),
466 if ( current_user_can( 'edit_posts' ) ) {
467 $wp_admin_bar->add_menu( array(
468 'parent' => $menu_id,
469 'id' => $menu_id . '-c',
470 'title' => __( 'Manage Comments' ),
471 'href' => admin_url( 'edit-comments.php' ),
475 $wp_admin_bar->add_menu( array(
476 'parent' => $menu_id,
477 'id' => $menu_id . '-v',
478 'title' => __( 'Visit Site' ),
479 'href' => home_url( '/' ),
482 restore_current_blog();
487 * Provide a shortlink.
491 * @param WP_Admin_Bar $wp_admin_bar
493 function wp_admin_bar_shortlink_menu( $wp_admin_bar ) {
494 $short = wp_get_shortlink( 0, 'query' );
495 $id = 'get-shortlink';
497 if ( empty( $short ) )
500 $html = '<input class="shortlink-input" type="text" readonly="readonly" value="' . esc_attr( $short ) . '" />';
502 $wp_admin_bar->add_menu( array(
504 'title' => __( 'Shortlink' ),
506 'meta' => array( 'html' => $html ),
511 * Provide an edit link for posts and terms.
515 * @global object $tag
516 * @global WP_Query $wp_the_query
518 * @param WP_Admin_Bar $wp_admin_bar
520 function wp_admin_bar_edit_menu( $wp_admin_bar ) {
521 global $tag, $wp_the_query;
524 $current_screen = get_current_screen();
527 if ( 'post' == $current_screen->base
528 && 'add' != $current_screen->action
529 && ( $post_type_object = get_post_type_object( $post->post_type ) )
530 && current_user_can( 'read_post', $post->ID )
531 && ( $post_type_object->public )
532 && ( $post_type_object->show_in_admin_bar ) )
534 if ( 'draft' == $post->post_status ) {
535 $preview_link = set_url_scheme( get_permalink( $post->ID ) );
536 /** This filter is documented in wp-admin/includes/meta-boxes.php */
537 $preview_link = apply_filters( 'preview_post_link', add_query_arg( 'preview', 'true', $preview_link ), $post );
538 $wp_admin_bar->add_menu( array(
540 'title' => $post_type_object->labels->view_item,
541 'href' => esc_url( $preview_link ),
542 'meta' => array( 'target' => 'wp-preview-' . $post->ID ),
545 $wp_admin_bar->add_menu( array(
547 'title' => $post_type_object->labels->view_item,
548 'href' => get_permalink( $post->ID )
551 } elseif ( 'edit-tags' == $current_screen->base
552 && isset( $tag ) && is_object( $tag )
553 && ( $tax = get_taxonomy( $tag->taxonomy ) )
556 $wp_admin_bar->add_menu( array(
558 'title' => $tax->labels->view_item,
559 'href' => get_term_link( $tag )
563 $current_object = $wp_the_query->get_queried_object();
565 if ( empty( $current_object ) )
568 if ( ! empty( $current_object->post_type )
569 && ( $post_type_object = get_post_type_object( $current_object->post_type ) )
570 && current_user_can( 'edit_post', $current_object->ID )
571 && $post_type_object->show_ui && $post_type_object->show_in_admin_bar
572 && $edit_post_link = get_edit_post_link( $current_object->ID ) )
574 $wp_admin_bar->add_menu( array(
576 'title' => $post_type_object->labels->edit_item,
577 'href' => $edit_post_link
579 } elseif ( ! empty( $current_object->taxonomy )
580 && ( $tax = get_taxonomy( $current_object->taxonomy ) )
581 && current_user_can( $tax->cap->edit_terms )
583 && $edit_term_link = get_edit_term_link( $current_object->term_id, $current_object->taxonomy ) )
585 $wp_admin_bar->add_menu( array(
587 'title' => $tax->labels->edit_item,
588 'href' => $edit_term_link
595 * Add "Add New" menu.
599 * @param WP_Admin_Bar $wp_admin_bar
601 function wp_admin_bar_new_content_menu( $wp_admin_bar ) {
604 $cpts = (array) get_post_types( array( 'show_in_admin_bar' => true ), 'objects' );
606 if ( isset( $cpts['post'] ) && current_user_can( $cpts['post']->cap->create_posts ) )
607 $actions[ 'post-new.php' ] = array( $cpts['post']->labels->name_admin_bar, 'new-post' );
609 if ( isset( $cpts['attachment'] ) && current_user_can( 'upload_files' ) )
610 $actions[ 'media-new.php' ] = array( $cpts['attachment']->labels->name_admin_bar, 'new-media' );
612 if ( current_user_can( 'manage_links' ) )
613 $actions[ 'link-add.php' ] = array( _x( 'Link', 'add new from admin bar' ), 'new-link' );
615 if ( isset( $cpts['page'] ) && current_user_can( $cpts['page']->cap->create_posts ) )
616 $actions[ 'post-new.php?post_type=page' ] = array( $cpts['page']->labels->name_admin_bar, 'new-page' );
618 unset( $cpts['post'], $cpts['page'], $cpts['attachment'] );
620 // Add any additional custom post types.
621 foreach ( $cpts as $cpt ) {
622 if ( ! current_user_can( $cpt->cap->create_posts ) )
625 $key = 'post-new.php?post_type=' . $cpt->name;
626 $actions[ $key ] = array( $cpt->labels->name_admin_bar, 'new-' . $cpt->name );
628 // Avoid clash with parent node and a 'content' post type.
629 if ( isset( $actions['post-new.php?post_type=content'] ) )
630 $actions['post-new.php?post_type=content'][1] = 'add-new-content';
632 if ( current_user_can( 'create_users' ) || current_user_can( 'promote_users' ) )
633 $actions[ 'user-new.php' ] = array( _x( 'User', 'add new from admin bar' ), 'new-user' );
638 $title = '<span class="ab-icon"></span><span class="ab-label">' . _x( 'New', 'admin bar menu group label' ) . '</span>';
640 $wp_admin_bar->add_menu( array(
641 'id' => 'new-content',
643 'href' => admin_url( current( array_keys( $actions ) ) ),
646 foreach ( $actions as $link => $action ) {
647 list( $title, $id ) = $action;
649 $wp_admin_bar->add_menu( array(
650 'parent' => 'new-content',
653 'href' => admin_url( $link )
659 * Add edit comments link with awaiting moderation count bubble.
663 * @param WP_Admin_Bar $wp_admin_bar
665 function wp_admin_bar_comments_menu( $wp_admin_bar ) {
666 if ( !current_user_can('edit_posts') )
669 $awaiting_mod = wp_count_comments();
670 $awaiting_mod = $awaiting_mod->moderated;
671 $awaiting_title = esc_attr( sprintf( _n( '%s comment awaiting moderation', '%s comments awaiting moderation', $awaiting_mod ), number_format_i18n( $awaiting_mod ) ) );
673 $icon = '<span class="ab-icon"></span>';
674 $title = '<span id="ab-awaiting-mod" class="ab-label awaiting-mod pending-count count-' . $awaiting_mod . '">' . number_format_i18n( $awaiting_mod ) . '</span>';
676 $wp_admin_bar->add_menu( array(
678 'title' => $icon . $title,
679 'href' => admin_url('edit-comments.php'),
680 'meta' => array( 'title' => $awaiting_title ),
685 * Add appearance submenu items to the "Site Name" menu.
689 * @param WP_Admin_Bar $wp_admin_bar
691 function wp_admin_bar_appearance_menu( $wp_admin_bar ) {
692 $wp_admin_bar->add_group( array( 'parent' => 'site-name', 'id' => 'appearance' ) );
694 if ( current_user_can( 'switch_themes' ) ) {
695 $wp_admin_bar->add_menu( array(
696 'parent' => 'appearance',
698 'title' => __( 'Themes' ),
699 'href' => admin_url( 'themes.php' ),
703 if ( ! current_user_can( 'edit_theme_options' ) ) {
707 if ( current_theme_supports( 'widgets' ) ) {
708 $wp_admin_bar->add_menu( array(
709 'parent' => 'appearance',
711 'title' => __( 'Widgets' ),
712 'href' => admin_url( 'widgets.php' ),
716 if ( current_theme_supports( 'menus' ) || current_theme_supports( 'widgets' ) )
717 $wp_admin_bar->add_menu( array( 'parent' => 'appearance', 'id' => 'menus', 'title' => __('Menus'), 'href' => admin_url('nav-menus.php') ) );
719 if ( current_theme_supports( 'custom-background' ) ) {
720 $wp_admin_bar->add_menu( array(
721 'parent' => 'appearance',
722 'id' => 'background',
723 'title' => __( 'Background' ),
724 'href' => admin_url( 'themes.php?page=custom-background' ),
726 'class' => 'hide-if-customize',
731 if ( current_theme_supports( 'custom-header' ) ) {
732 $wp_admin_bar->add_menu( array(
733 'parent' => 'appearance',
735 'title' => __( 'Header' ),
736 'href' => admin_url( 'themes.php?page=custom-header' ),
738 'class' => 'hide-if-customize',
746 * Provide an update link if theme/plugin/core updates are available.
750 * @param WP_Admin_Bar $wp_admin_bar
752 function wp_admin_bar_updates_menu( $wp_admin_bar ) {
754 $update_data = wp_get_update_data();
756 if ( !$update_data['counts']['total'] )
759 $title = '<span class="ab-icon"></span><span class="ab-label">' . number_format_i18n( $update_data['counts']['total'] ) . '</span>';
760 $title .= '<span class="screen-reader-text">' . $update_data['title'] . '</span>';
762 $wp_admin_bar->add_menu( array(
765 'href' => network_admin_url( 'update-core.php' ),
767 'title' => $update_data['title'],
777 * @param WP_Admin_Bar $wp_admin_bar
779 function wp_admin_bar_search_menu( $wp_admin_bar ) {
783 $form = '<form action="' . esc_url( home_url( '/' ) ) . '" method="get" id="adminbarsearch">';
784 $form .= '<input class="adminbar-input" name="s" id="adminbar-search" type="text" value="" maxlength="150" />';
785 $form .= '<label for="adminbar-search" class="screen-reader-text">' . __( 'Search' ) . '</label>';
786 $form .= '<input type="submit" class="adminbar-button" value="' . __('Search') . '"/>';
789 $wp_admin_bar->add_menu( array(
790 'parent' => 'top-secondary',
794 'class' => 'admin-bar-search',
801 * Add secondary menus.
805 * @param WP_Admin_Bar $wp_admin_bar
807 function wp_admin_bar_add_secondary_groups( $wp_admin_bar ) {
808 $wp_admin_bar->add_group( array(
809 'id' => 'top-secondary',
811 'class' => 'ab-top-secondary',
815 $wp_admin_bar->add_group( array(
816 'parent' => 'wp-logo',
817 'id' => 'wp-logo-external',
819 'class' => 'ab-sub-secondary',
825 * Style and scripts for the admin bar.
829 function wp_admin_bar_header() { ?>
830 <style type="text/css" media="print">#wpadminbar { display:none; }</style>
835 * Default admin bar callback.
839 function _admin_bar_bump_cb() { ?>
840 <style type="text/css" media="screen">
841 html { margin-top: 32px !important; }
842 * html body { margin-top: 32px !important; }
843 @media screen and ( max-width: 782px ) {
844 html { margin-top: 46px !important; }
845 * html body { margin-top: 46px !important; }
852 * Set the display status of the admin bar.
854 * This can be called immediately upon plugin load. It does not need to be called from a function hooked to the init action.
858 * @global WP_Admin_Bar $wp_admin_bar
860 * @param bool $show Whether to allow the admin bar to show.
862 function show_admin_bar( $show ) {
863 global $show_admin_bar;
864 $show_admin_bar = (bool) $show;
868 * Determine whether the admin bar should be showing.
872 * @global WP_Admin_Bar $wp_admin_bar
873 * @global string $pagenow
875 * @return bool Whether the admin bar should be showing.
877 function is_admin_bar_showing() {
878 global $show_admin_bar, $pagenow;
880 // For all these types of requests, we never want an admin bar.
881 if ( defined('XMLRPC_REQUEST') || defined('DOING_AJAX') || defined('IFRAME_REQUEST') )
884 // Integrated into the admin.
888 if ( ! isset( $show_admin_bar ) ) {
889 if ( ! is_user_logged_in() || 'wp-login.php' == $pagenow ) {
890 $show_admin_bar = false;
892 $show_admin_bar = _get_admin_bar_pref();
897 * Filter whether to show the admin bar.
899 * Returning false to this hook is the recommended way to hide the admin bar.
900 * The user's display preference is used for logged in users.
904 * @param bool $show_admin_bar Whether the admin bar should be shown. Default false.
906 $show_admin_bar = apply_filters( 'show_admin_bar', $show_admin_bar );
908 return $show_admin_bar;
912 * Retrieve the admin bar display preference of a user.
917 * @param string $context Context of this preference check. Defaults to 'front'. The 'admin'
918 * preference is no longer used.
919 * @param int $user Optional. ID of the user to check, defaults to 0 for current user.
920 * @return bool Whether the admin bar should be showing for this user.
922 function _get_admin_bar_pref( $context = 'front', $user = 0 ) {
923 $pref = get_user_option( "show_admin_bar_{$context}", $user );
924 if ( false === $pref )
927 return 'true' === $pref;