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 $preview_link = get_preview_post_link( $post );
562 $wp_admin_bar->add_menu( array(
564 'title' => $post_type_object->labels->view_item,
565 'href' => esc_url( $preview_link ),
566 'meta' => array( 'target' => 'wp-preview-' . $post->ID ),
569 $wp_admin_bar->add_menu( array(
571 'title' => $post_type_object->labels->view_item,
572 'href' => get_permalink( $post->ID )
575 } elseif ( 'term' == $current_screen->base
576 && isset( $tag ) && is_object( $tag ) && ! is_wp_error( $tag )
577 && ( $tax = get_taxonomy( $tag->taxonomy ) )
580 $wp_admin_bar->add_menu( array(
582 'title' => $tax->labels->view_item,
583 'href' => get_term_link( $tag )
587 $current_object = $wp_the_query->get_queried_object();
589 if ( empty( $current_object ) )
592 if ( ! empty( $current_object->post_type )
593 && ( $post_type_object = get_post_type_object( $current_object->post_type ) )
594 && current_user_can( 'edit_post', $current_object->ID )
595 && $post_type_object->show_in_admin_bar
596 && $edit_post_link = get_edit_post_link( $current_object->ID ) )
598 $wp_admin_bar->add_menu( array(
600 'title' => $post_type_object->labels->edit_item,
601 'href' => $edit_post_link
603 } elseif ( ! empty( $current_object->taxonomy )
604 && ( $tax = get_taxonomy( $current_object->taxonomy ) )
605 && current_user_can( $tax->cap->edit_terms )
606 && $edit_term_link = get_edit_term_link( $current_object->term_id, $current_object->taxonomy ) )
608 $wp_admin_bar->add_menu( array(
610 'title' => $tax->labels->edit_item,
611 'href' => $edit_term_link
618 * Add "Add New" menu.
622 * @param WP_Admin_Bar $wp_admin_bar
624 function wp_admin_bar_new_content_menu( $wp_admin_bar ) {
627 $cpts = (array) get_post_types( array( 'show_in_admin_bar' => true ), 'objects' );
629 if ( isset( $cpts['post'] ) && current_user_can( $cpts['post']->cap->create_posts ) )
630 $actions[ 'post-new.php' ] = array( $cpts['post']->labels->name_admin_bar, 'new-post' );
632 if ( isset( $cpts['attachment'] ) && current_user_can( 'upload_files' ) )
633 $actions[ 'media-new.php' ] = array( $cpts['attachment']->labels->name_admin_bar, 'new-media' );
635 if ( current_user_can( 'manage_links' ) )
636 $actions[ 'link-add.php' ] = array( _x( 'Link', 'add new from admin bar' ), 'new-link' );
638 if ( isset( $cpts['page'] ) && current_user_can( $cpts['page']->cap->create_posts ) )
639 $actions[ 'post-new.php?post_type=page' ] = array( $cpts['page']->labels->name_admin_bar, 'new-page' );
641 unset( $cpts['post'], $cpts['page'], $cpts['attachment'] );
643 // Add any additional custom post types.
644 foreach ( $cpts as $cpt ) {
645 if ( ! current_user_can( $cpt->cap->create_posts ) )
648 $key = 'post-new.php?post_type=' . $cpt->name;
649 $actions[ $key ] = array( $cpt->labels->name_admin_bar, 'new-' . $cpt->name );
651 // Avoid clash with parent node and a 'content' post type.
652 if ( isset( $actions['post-new.php?post_type=content'] ) )
653 $actions['post-new.php?post_type=content'][1] = 'add-new-content';
655 if ( current_user_can( 'create_users' ) || current_user_can( 'promote_users' ) )
656 $actions[ 'user-new.php' ] = array( _x( 'User', 'add new from admin bar' ), 'new-user' );
661 $title = '<span class="ab-icon"></span><span class="ab-label">' . _x( 'New', 'admin bar menu group label' ) . '</span>';
663 $wp_admin_bar->add_menu( array(
664 'id' => 'new-content',
666 'href' => admin_url( current( array_keys( $actions ) ) ),
669 foreach ( $actions as $link => $action ) {
670 list( $title, $id ) = $action;
672 $wp_admin_bar->add_menu( array(
673 'parent' => 'new-content',
676 'href' => admin_url( $link )
682 * Add edit comments link with awaiting moderation count bubble.
686 * @param WP_Admin_Bar $wp_admin_bar
688 function wp_admin_bar_comments_menu( $wp_admin_bar ) {
689 if ( !current_user_can('edit_posts') )
692 $awaiting_mod = wp_count_comments();
693 $awaiting_mod = $awaiting_mod->moderated;
694 $awaiting_text = sprintf( _n( '%s comment awaiting moderation', '%s comments awaiting moderation', $awaiting_mod ), number_format_i18n( $awaiting_mod ) );
696 $icon = '<span class="ab-icon"></span>';
697 $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>';
698 $title .= '<span class="screen-reader-text">' . $awaiting_text . '</span>';
700 $wp_admin_bar->add_menu( array(
702 'title' => $icon . $title,
703 'href' => admin_url('edit-comments.php'),
708 * Add appearance submenu items to the "Site Name" menu.
712 * @param WP_Admin_Bar $wp_admin_bar
714 function wp_admin_bar_appearance_menu( $wp_admin_bar ) {
715 $wp_admin_bar->add_group( array( 'parent' => 'site-name', 'id' => 'appearance' ) );
717 if ( current_user_can( 'switch_themes' ) ) {
718 $wp_admin_bar->add_menu( array(
719 'parent' => 'appearance',
721 'title' => __( 'Themes' ),
722 'href' => admin_url( 'themes.php' ),
726 if ( ! current_user_can( 'edit_theme_options' ) ) {
730 if ( current_theme_supports( 'widgets' ) ) {
731 $wp_admin_bar->add_menu( array(
732 'parent' => 'appearance',
734 'title' => __( 'Widgets' ),
735 'href' => admin_url( 'widgets.php' ),
739 if ( current_theme_supports( 'menus' ) || current_theme_supports( 'widgets' ) )
740 $wp_admin_bar->add_menu( array( 'parent' => 'appearance', 'id' => 'menus', 'title' => __('Menus'), 'href' => admin_url('nav-menus.php') ) );
742 if ( current_theme_supports( 'custom-background' ) ) {
743 $wp_admin_bar->add_menu( array(
744 'parent' => 'appearance',
745 'id' => 'background',
746 'title' => __( 'Background' ),
747 'href' => admin_url( 'themes.php?page=custom-background' ),
749 'class' => 'hide-if-customize',
754 if ( current_theme_supports( 'custom-header' ) ) {
755 $wp_admin_bar->add_menu( array(
756 'parent' => 'appearance',
758 'title' => __( 'Header' ),
759 'href' => admin_url( 'themes.php?page=custom-header' ),
761 'class' => 'hide-if-customize',
769 * Provide an update link if theme/plugin/core updates are available.
773 * @param WP_Admin_Bar $wp_admin_bar
775 function wp_admin_bar_updates_menu( $wp_admin_bar ) {
777 $update_data = wp_get_update_data();
779 if ( !$update_data['counts']['total'] )
782 $title = '<span class="ab-icon"></span><span class="ab-label">' . number_format_i18n( $update_data['counts']['total'] ) . '</span>';
783 $title .= '<span class="screen-reader-text">' . $update_data['title'] . '</span>';
785 $wp_admin_bar->add_menu( array(
788 'href' => network_admin_url( 'update-core.php' ),
790 'title' => $update_data['title'],
800 * @param WP_Admin_Bar $wp_admin_bar
802 function wp_admin_bar_search_menu( $wp_admin_bar ) {
806 $form = '<form action="' . esc_url( home_url( '/' ) ) . '" method="get" id="adminbarsearch">';
807 $form .= '<input class="adminbar-input" name="s" id="adminbar-search" type="text" value="" maxlength="150" />';
808 $form .= '<label for="adminbar-search" class="screen-reader-text">' . __( 'Search' ) . '</label>';
809 $form .= '<input type="submit" class="adminbar-button" value="' . __('Search') . '"/>';
812 $wp_admin_bar->add_menu( array(
813 'parent' => 'top-secondary',
817 'class' => 'admin-bar-search',
824 * Add secondary menus.
828 * @param WP_Admin_Bar $wp_admin_bar
830 function wp_admin_bar_add_secondary_groups( $wp_admin_bar ) {
831 $wp_admin_bar->add_group( array(
832 'id' => 'top-secondary',
834 'class' => 'ab-top-secondary',
838 $wp_admin_bar->add_group( array(
839 'parent' => 'wp-logo',
840 'id' => 'wp-logo-external',
842 'class' => 'ab-sub-secondary',
848 * Style and scripts for the admin bar.
852 function wp_admin_bar_header() { ?>
853 <style type="text/css" media="print">#wpadminbar { display:none; }</style>
858 * Default admin bar callback.
862 function _admin_bar_bump_cb() { ?>
863 <style type="text/css" media="screen">
864 html { margin-top: 32px !important; }
865 * html body { margin-top: 32px !important; }
866 @media screen and ( max-width: 782px ) {
867 html { margin-top: 46px !important; }
868 * html body { margin-top: 46px !important; }
875 * Set the display status of the admin bar.
877 * This can be called immediately upon plugin load. It does not need to be called from a function hooked to the init action.
881 * @global bool $show_admin_bar
883 * @param bool $show Whether to allow the admin bar to show.
885 function show_admin_bar( $show ) {
886 global $show_admin_bar;
887 $show_admin_bar = (bool) $show;
891 * Determine whether the admin bar should be showing.
895 * @global bool $show_admin_bar
896 * @global string $pagenow
898 * @return bool Whether the admin bar should be showing.
900 function is_admin_bar_showing() {
901 global $show_admin_bar, $pagenow;
903 // For all these types of requests, we never want an admin bar.
904 if ( defined('XMLRPC_REQUEST') || defined('DOING_AJAX') || defined('IFRAME_REQUEST') )
911 // Integrated into the admin.
915 if ( ! isset( $show_admin_bar ) ) {
916 if ( ! is_user_logged_in() || 'wp-login.php' == $pagenow ) {
917 $show_admin_bar = false;
919 $show_admin_bar = _get_admin_bar_pref();
924 * Filter whether to show the admin bar.
926 * Returning false to this hook is the recommended way to hide the admin bar.
927 * The user's display preference is used for logged in users.
931 * @param bool $show_admin_bar Whether the admin bar should be shown. Default false.
933 $show_admin_bar = apply_filters( 'show_admin_bar', $show_admin_bar );
935 return $show_admin_bar;
939 * Retrieve the admin bar display preference of a user.
944 * @param string $context Context of this preference check. Defaults to 'front'. The 'admin'
945 * preference is no longer used.
946 * @param int $user Optional. ID of the user to check, defaults to 0 for current user.
947 * @return bool Whether the admin bar should be showing for this user.
949 function _get_admin_bar_pref( $context = 'front', $user = 0 ) {
950 $pref = get_user_option( "show_admin_bar_{$context}", $user );
951 if ( false === $pref )
954 return 'true' === $pref;