]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-includes/admin-bar.php
WordPress 4.3.1
[autoinstalls/wordpress.git] / wp-includes / admin-bar.php
1 <?php
2 /**
3  * Admin Bar
4  *
5  * This code handles the building and rendering of the press bar.
6  */
7
8 /**
9  * Instantiate the admin bar object and set it up as a global for access elsewhere.
10  *
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.
13  *
14  * @since 3.1.0
15  * @access private
16  *
17  * @global WP_Admin_Bar $wp_admin_bar
18  *
19  * @return bool Whether the admin bar was successfully initialized.
20  */
21 function _wp_admin_bar_init() {
22         global $wp_admin_bar;
23
24         if ( ! is_admin_bar_showing() )
25                 return false;
26
27         /* Load the admin bar class code ready for instantiation */
28         require_once( ABSPATH . WPINC . '/class-wp-admin-bar.php' );
29
30         /* Instantiate the admin bar */
31
32         /**
33          * Filter the admin bar class to instantiate.
34          *
35          * @since 3.1.0
36          *
37          * @param string $wp_admin_bar_class Admin bar class to use. Default 'WP_Admin_Bar'.
38          */
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;
42         else
43                 return false;
44
45         $wp_admin_bar->initialize();
46         $wp_admin_bar->add_menus();
47
48         return true;
49 }
50
51 /**
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.
55  *
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.
59  *
60  * @since 3.1.0
61  *
62  * @global WP_Admin_Bar $wp_admin_bar
63  */
64 function wp_admin_bar_render() {
65         global $wp_admin_bar;
66
67         if ( ! is_admin_bar_showing() || ! is_object( $wp_admin_bar ) )
68                 return;
69
70         /**
71          * Load all necessary admin bar items.
72          *
73          * This is the hook used to add, remove, or manipulate admin bar items.
74          *
75          * @since 3.1.0
76          *
77          * @param WP_Admin_Bar $wp_admin_bar WP_Admin_Bar instance, passed by reference
78          */
79         do_action_ref_array( 'admin_bar_menu', array( &$wp_admin_bar ) );
80
81         /**
82          * Fires before the admin bar is rendered.
83          *
84          * @since 3.1.0
85          */
86         do_action( 'wp_before_admin_bar_render' );
87
88         $wp_admin_bar->render();
89
90         /**
91          * Fires after the admin bar is rendered.
92          *
93          * @since 3.1.0
94          */
95         do_action( 'wp_after_admin_bar_render' );
96 }
97
98 /**
99  * Add the WordPress logo menu.
100  *
101  * @since 3.3.0
102  *
103  * @param WP_Admin_Bar $wp_admin_bar
104  */
105 function wp_admin_bar_wp_menu( $wp_admin_bar ) {
106         $wp_admin_bar->add_menu( array(
107                 'id'    => 'wp-logo',
108                 'title' => '<span class="ab-icon"></span><span class="screen-reader-text">' . __( 'About WordPress' ) . '</span>',
109                 'href'  => self_admin_url( 'about.php' ),
110         ) );
111
112         if ( is_user_logged_in() ) {
113                 // Add "About WordPress" link
114                 $wp_admin_bar->add_menu( array(
115                         'parent' => 'wp-logo',
116                         'id'     => 'about',
117                         'title'  => __('About WordPress'),
118                         'href'   => self_admin_url( 'about.php' ),
119                 ) );
120         }
121
122         // Add WordPress.org link
123         $wp_admin_bar->add_menu( array(
124                 'parent'    => 'wp-logo-external',
125                 'id'        => 'wporg',
126                 'title'     => __('WordPress.org'),
127                 'href'      => __('https://wordpress.org/'),
128         ) );
129
130         // Add codex link
131         $wp_admin_bar->add_menu( array(
132                 'parent'    => 'wp-logo-external',
133                 'id'        => 'documentation',
134                 'title'     => __('Documentation'),
135                 'href'      => __('https://codex.wordpress.org/'),
136         ) );
137
138         // Add forums link
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/'),
144         ) );
145
146         // Add feedback link
147         $wp_admin_bar->add_menu( array(
148                 'parent'    => 'wp-logo-external',
149                 'id'        => 'feedback',
150                 'title'     => __('Feedback'),
151                 'href'      => __('https://wordpress.org/support/forum/requests-and-feedback'),
152         ) );
153 }
154
155 /**
156  * Add the sidebar toggle button.
157  *
158  * @since 3.8.0
159  *
160  * @param WP_Admin_Bar $wp_admin_bar
161  */
162 function wp_admin_bar_sidebar_toggle( $wp_admin_bar ) {
163         if ( is_admin() ) {
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>',
167                         'href'  => '#',
168                 ) );
169         }
170 }
171
172 /**
173  * Add the "My Account" item.
174  *
175  * @since 3.3.0
176  *
177  * @param WP_Admin_Bar $wp_admin_bar
178  */
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 );
183
184         if ( ! $user_id )
185                 return;
186
187         $avatar = get_avatar( $user_id, 26 );
188         $howdy  = sprintf( __('Howdy, %1$s'), $current_user->display_name );
189         $class  = empty( $avatar ) ? '' : 'with-avatar';
190
191         $wp_admin_bar->add_menu( array(
192                 'id'        => 'my-account',
193                 'parent'    => 'top-secondary',
194                 'title'     => $howdy . $avatar,
195                 'href'      => $profile_url,
196                 'meta'      => array(
197                         'class'     => $class,
198                 ),
199         ) );
200 }
201
202 /**
203  * Add the "My Account" submenu items.
204  *
205  * @since 3.1.0
206  *
207  * @param WP_Admin_Bar $wp_admin_bar
208  */
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 );
213
214         if ( ! $user_id )
215                 return;
216
217         $wp_admin_bar->add_group( array(
218                 'parent' => 'my-account',
219                 'id'     => 'user-actions',
220         ) );
221
222         $user_info  = get_avatar( $user_id, 64 );
223         $user_info .= "<span class='display-name'>{$current_user->display_name}</span>";
224
225         if ( $current_user->display_name !== $current_user->user_login )
226                 $user_info .= "<span class='username'>{$current_user->user_login}</span>";
227
228         $wp_admin_bar->add_menu( array(
229                 'parent' => 'user-actions',
230                 'id'     => 'user-info',
231                 'title'  => $user_info,
232                 'href'   => $profile_url,
233                 'meta'   => array(
234                         'tabindex' => -1,
235                 ),
236         ) );
237         $wp_admin_bar->add_menu( array(
238                 'parent' => 'user-actions',
239                 'id'     => 'edit-profile',
240                 'title'  => __( 'Edit My Profile' ),
241                 'href' => $profile_url,
242         ) );
243         $wp_admin_bar->add_menu( array(
244                 'parent' => 'user-actions',
245                 'id'     => 'logout',
246                 'title'  => __( 'Log Out' ),
247                 'href'   => wp_logout_url(),
248         ) );
249 }
250
251 /**
252  * Add the "Site Name" menu.
253  *
254  * @since 3.3.0
255  *
256  * @param WP_Admin_Bar $wp_admin_bar
257  */
258 function wp_admin_bar_site_menu( $wp_admin_bar ) {
259         // Don't show for logged out users.
260         if ( ! is_user_logged_in() )
261                 return;
262
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() )
265                 return;
266
267         $blogname = get_bloginfo('name');
268
269         if ( ! $blogname ) {
270                 $blogname = preg_replace( '#^(https?://)?(www.)?#', '', get_home_url() );
271         }
272
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 ) );
277         }
278
279         $title = wp_html_excerpt( $blogname, 40, '&hellip;' );
280
281         $wp_admin_bar->add_menu( array(
282                 'id'    => 'site-name',
283                 'title' => $title,
284                 'href'  => is_admin() ? home_url( '/' ) : admin_url(),
285         ) );
286
287         // Create submenu items.
288
289         if ( is_admin() ) {
290                 // Add an option to visit the site.
291                 $wp_admin_bar->add_menu( array(
292                         'parent' => 'site-name',
293                         'id'     => 'view-site',
294                         'title'  => __( 'Visit Site' ),
295                         'href'   => home_url( '/' ),
296                 ) );
297
298                 if ( is_blog_admin() && is_multisite() && current_user_can( 'manage_sites' ) ) {
299                         $wp_admin_bar->add_menu( array(
300                                 'parent' => 'site-name',
301                                 'id'     => 'edit-site',
302                                 'title'  => __( 'Edit Site' ),
303                                 'href'   => network_admin_url( 'site-info.php?id=' . get_current_blog_id() ),
304                         ) );
305                 }
306
307         } else {
308                 // We're on the front end, link to the Dashboard.
309                 $wp_admin_bar->add_menu( array(
310                         'parent' => 'site-name',
311                         'id'     => 'dashboard',
312                         'title'  => __( 'Dashboard' ),
313                         'href'   => admin_url(),
314                 ) );
315
316                 // Add the appearance submenu items.
317                 wp_admin_bar_appearance_menu( $wp_admin_bar );
318         }
319 }
320
321 /**
322  * Adds the "Customize" link to the Toolbar.
323  *
324  * @since 4.3.0
325  *
326  * @param WP_Admin_Bar $wp_admin_bar WP_Admin_Bar instance.
327  */
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() ) {
331                 return;
332         }
333
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() );
336
337         $wp_admin_bar->add_menu( array(
338                 'id'     => 'customize',
339                 'title'  => __( 'Customize' ),
340                 'href'   => $customize_url,
341                 'meta'   => array(
342                         'class' => 'hide-if-no-customize',
343                 ),
344         ) );
345         add_action( 'wp_before_admin_bar_render', 'wp_customize_support_script' );
346 }
347
348 /**
349  * Add the "My Sites/[Site Name]" menu and all submenus.
350  *
351  * @since 3.1.0
352  *
353  * @param WP_Admin_Bar $wp_admin_bar
354  */
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() )
358                 return;
359
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() )
362                 return;
363
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' );
366         } else {
367                 $my_sites_url = admin_url( 'my-sites.php' );
368         }
369
370         $wp_admin_bar->add_menu( array(
371                 'id'    => 'my-sites',
372                 'title' => __( 'My Sites' ),
373                 'href'  => $my_sites_url,
374         ) );
375
376         if ( is_super_admin() ) {
377                 $wp_admin_bar->add_group( array(
378                         'parent' => 'my-sites',
379                         'id'     => 'my-sites-super-admin',
380                 ) );
381
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(),
387                 ) );
388
389                 $wp_admin_bar->add_menu( array(
390                         'parent' => 'network-admin',
391                         'id'     => 'network-admin-d',
392                         'title'  => __( 'Dashboard' ),
393                         'href'   => network_admin_url(),
394                 ) );
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' ),
400                 ) );
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' ),
406                 ) );
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' ),
412                 ) );
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' ),
418                 ) );
419         }
420
421         // Add site links
422         $wp_admin_bar->add_group( array(
423                 'parent' => 'my-sites',
424                 'id'     => 'my-sites-list',
425                 'meta'   => array(
426                         'class' => is_super_admin() ? 'ab-sub-secondary' : '',
427                 ),
428         ) );
429
430         foreach ( (array) $wp_admin_bar->user->blogs as $blog ) {
431                 switch_to_blog( $blog->userblog_id );
432
433                 $blavatar = '<div class="blavatar"></div>';
434
435                 $blogname = $blog->blogname;
436
437                 if ( ! $blogname ) {
438                         $blogname = preg_replace( '#^(https?://)?(www.)?#', '', get_home_url() );
439                 }
440
441                 $menu_id  = 'blog-' . $blog->userblog_id;
442
443                 $wp_admin_bar->add_menu( array(
444                         'parent'    => 'my-sites-list',
445                         'id'        => $menu_id,
446                         'title'     => $blavatar . $blogname,
447                         'href'      => admin_url(),
448                 ) );
449
450                 $wp_admin_bar->add_menu( array(
451                         'parent' => $menu_id,
452                         'id'     => $menu_id . '-d',
453                         'title'  => __( 'Dashboard' ),
454                         'href'   => admin_url(),
455                 ) );
456
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' ),
463                         ) );
464                 }
465
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' ),
472                         ) );
473                 }
474
475                 $wp_admin_bar->add_menu( array(
476                         'parent' => $menu_id,
477                         'id'     => $menu_id . '-v',
478                         'title'  => __( 'Visit Site' ),
479                         'href'   => home_url( '/' ),
480                 ) );
481
482                 restore_current_blog();
483         }
484 }
485
486 /**
487  * Provide a shortlink.
488  *
489  * @since 3.1.0
490  *
491  * @param WP_Admin_Bar $wp_admin_bar
492  */
493 function wp_admin_bar_shortlink_menu( $wp_admin_bar ) {
494         $short = wp_get_shortlink( 0, 'query' );
495         $id = 'get-shortlink';
496
497         if ( empty( $short ) )
498                 return;
499
500         $html = '<input class="shortlink-input" type="text" readonly="readonly" value="' . esc_attr( $short ) . '" />';
501
502         $wp_admin_bar->add_menu( array(
503                 'id' => $id,
504                 'title' => __( 'Shortlink' ),
505                 'href' => $short,
506                 'meta' => array( 'html' => $html ),
507         ) );
508 }
509
510 /**
511  * Provide an edit link for posts and terms.
512  *
513  * @since 3.1.0
514  *
515  * @global object   $tag
516  * @global WP_Query $wp_the_query
517  *
518  * @param WP_Admin_Bar $wp_admin_bar
519  */
520 function wp_admin_bar_edit_menu( $wp_admin_bar ) {
521         global $tag, $wp_the_query;
522
523         if ( is_admin() ) {
524                 $current_screen = get_current_screen();
525                 $post = get_post();
526
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 ) )
533                 {
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(
539                                         'id' => 'preview',
540                                         'title' => $post_type_object->labels->view_item,
541                                         'href' => esc_url( $preview_link ),
542                                         'meta' => array( 'target' => 'wp-preview-' . $post->ID ),
543                                 ) );
544                         } else {
545                                 $wp_admin_bar->add_menu( array(
546                                         'id' => 'view',
547                                         'title' => $post_type_object->labels->view_item,
548                                         'href' => get_permalink( $post->ID )
549                                 ) );
550                         }
551                 } elseif ( 'edit-tags' == $current_screen->base
552                         && isset( $tag ) && is_object( $tag )
553                         && ( $tax = get_taxonomy( $tag->taxonomy ) )
554                         && $tax->public )
555                 {
556                         $wp_admin_bar->add_menu( array(
557                                 'id' => 'view',
558                                 'title' => $tax->labels->view_item,
559                                 'href' => get_term_link( $tag )
560                         ) );
561                 }
562         } else {
563                 $current_object = $wp_the_query->get_queried_object();
564
565                 if ( empty( $current_object ) )
566                         return;
567
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 ) )
573                 {
574                         $wp_admin_bar->add_menu( array(
575                                 'id' => 'edit',
576                                 'title' => $post_type_object->labels->edit_item,
577                                 'href' => $edit_post_link
578                         ) );
579                 } elseif ( ! empty( $current_object->taxonomy )
580                         && ( $tax = get_taxonomy( $current_object->taxonomy ) )
581                         && current_user_can( $tax->cap->edit_terms )
582                         && $tax->show_ui
583                         && $edit_term_link = get_edit_term_link( $current_object->term_id, $current_object->taxonomy ) )
584                 {
585                         $wp_admin_bar->add_menu( array(
586                                 'id' => 'edit',
587                                 'title' => $tax->labels->edit_item,
588                                 'href' => $edit_term_link
589                         ) );
590                 }
591         }
592 }
593
594 /**
595  * Add "Add New" menu.
596  *
597  * @since 3.1.0
598  *
599  * @param WP_Admin_Bar $wp_admin_bar
600  */
601 function wp_admin_bar_new_content_menu( $wp_admin_bar ) {
602         $actions = array();
603
604         $cpts = (array) get_post_types( array( 'show_in_admin_bar' => true ), 'objects' );
605
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' );
608
609         if ( isset( $cpts['attachment'] ) && current_user_can( 'upload_files' ) )
610                 $actions[ 'media-new.php' ] = array( $cpts['attachment']->labels->name_admin_bar, 'new-media' );
611
612         if ( current_user_can( 'manage_links' ) )
613                 $actions[ 'link-add.php' ] = array( _x( 'Link', 'add new from admin bar' ), 'new-link' );
614
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' );
617
618         unset( $cpts['post'], $cpts['page'], $cpts['attachment'] );
619
620         // Add any additional custom post types.
621         foreach ( $cpts as $cpt ) {
622                 if ( ! current_user_can( $cpt->cap->create_posts ) )
623                         continue;
624
625                 $key = 'post-new.php?post_type=' . $cpt->name;
626                 $actions[ $key ] = array( $cpt->labels->name_admin_bar, 'new-' . $cpt->name );
627         }
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';
631
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' );
634
635         if ( ! $actions )
636                 return;
637
638         $title = '<span class="ab-icon"></span><span class="ab-label">' . _x( 'New', 'admin bar menu group label' ) . '</span>';
639
640         $wp_admin_bar->add_menu( array(
641                 'id'    => 'new-content',
642                 'title' => $title,
643                 'href'  => admin_url( current( array_keys( $actions ) ) ),
644         ) );
645
646         foreach ( $actions as $link => $action ) {
647                 list( $title, $id ) = $action;
648
649                 $wp_admin_bar->add_menu( array(
650                         'parent'    => 'new-content',
651                         'id'        => $id,
652                         'title'     => $title,
653                         'href'      => admin_url( $link )
654                 ) );
655         }
656 }
657
658 /**
659  * Add edit comments link with awaiting moderation count bubble.
660  *
661  * @since 3.1.0
662  *
663  * @param WP_Admin_Bar $wp_admin_bar
664  */
665 function wp_admin_bar_comments_menu( $wp_admin_bar ) {
666         if ( !current_user_can('edit_posts') )
667                 return;
668
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 ) ) );
672
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>';
675
676         $wp_admin_bar->add_menu( array(
677                 'id'    => 'comments',
678                 'title' => $icon . $title,
679                 'href'  => admin_url('edit-comments.php'),
680                 'meta'  => array( 'title' => $awaiting_title ),
681         ) );
682 }
683
684 /**
685  * Add appearance submenu items to the "Site Name" menu.
686  *
687  * @since 3.1.0
688  *
689  * @param WP_Admin_Bar $wp_admin_bar
690  */
691 function wp_admin_bar_appearance_menu( $wp_admin_bar ) {
692         $wp_admin_bar->add_group( array( 'parent' => 'site-name', 'id' => 'appearance' ) );
693
694         if ( current_user_can( 'switch_themes' ) ) {
695                 $wp_admin_bar->add_menu( array(
696                         'parent' => 'appearance',
697                         'id'     => 'themes',
698                         'title'  => __( 'Themes' ),
699                         'href'   => admin_url( 'themes.php' ),
700                 ) );
701         }
702
703         if ( ! current_user_can( 'edit_theme_options' ) ) {
704                 return;
705         }
706
707         if ( current_theme_supports( 'widgets' )  ) {
708                 $wp_admin_bar->add_menu( array(
709                         'parent' => 'appearance',
710                         'id'     => 'widgets',
711                         'title'  => __( 'Widgets' ),
712                         'href'   => admin_url( 'widgets.php' ),
713                 ) );
714         }
715
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') ) );
718
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' ),
725                         'meta'   => array(
726                                 'class' => 'hide-if-customize',
727                         ),
728                 ) );
729         }
730
731         if ( current_theme_supports( 'custom-header' ) ) {
732                 $wp_admin_bar->add_menu( array(
733                         'parent' => 'appearance',
734                         'id'     => 'header',
735                         'title'  => __( 'Header' ),
736                         'href'   => admin_url( 'themes.php?page=custom-header' ),
737                         'meta'   => array(
738                                 'class' => 'hide-if-customize',
739                         ),
740                 ) );
741         }
742
743 }
744
745 /**
746  * Provide an update link if theme/plugin/core updates are available.
747  *
748  * @since 3.1.0
749  *
750  * @param WP_Admin_Bar $wp_admin_bar
751  */
752 function wp_admin_bar_updates_menu( $wp_admin_bar ) {
753
754         $update_data = wp_get_update_data();
755
756         if ( !$update_data['counts']['total'] )
757                 return;
758
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>';
761
762         $wp_admin_bar->add_menu( array(
763                 'id'    => 'updates',
764                 'title' => $title,
765                 'href'  => network_admin_url( 'update-core.php' ),
766                 'meta'  => array(
767                         'title' => $update_data['title'],
768                 ),
769         ) );
770 }
771
772 /**
773  * Add search form.
774  *
775  * @since 3.3.0
776  *
777  * @param WP_Admin_Bar $wp_admin_bar
778  */
779 function wp_admin_bar_search_menu( $wp_admin_bar ) {
780         if ( is_admin() )
781                 return;
782
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') . '"/>';
787         $form .= '</form>';
788
789         $wp_admin_bar->add_menu( array(
790                 'parent' => 'top-secondary',
791                 'id'     => 'search',
792                 'title'  => $form,
793                 'meta'   => array(
794                         'class'    => 'admin-bar-search',
795                         'tabindex' => -1,
796                 )
797         ) );
798 }
799
800 /**
801  * Add secondary menus.
802  *
803  * @since 3.3.0
804  *
805  * @param WP_Admin_Bar $wp_admin_bar
806  */
807 function wp_admin_bar_add_secondary_groups( $wp_admin_bar ) {
808         $wp_admin_bar->add_group( array(
809                 'id'     => 'top-secondary',
810                 'meta'   => array(
811                         'class' => 'ab-top-secondary',
812                 ),
813         ) );
814
815         $wp_admin_bar->add_group( array(
816                 'parent' => 'wp-logo',
817                 'id'     => 'wp-logo-external',
818                 'meta'   => array(
819                         'class' => 'ab-sub-secondary',
820                 ),
821         ) );
822 }
823
824 /**
825  * Style and scripts for the admin bar.
826  *
827  * @since 3.1.0
828  */
829 function wp_admin_bar_header() { ?>
830 <style type="text/css" media="print">#wpadminbar { display:none; }</style>
831 <?php
832 }
833
834 /**
835  * Default admin bar callback.
836  *
837  * @since 3.1.0
838  */
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; }
846         }
847 </style>
848 <?php
849 }
850
851 /**
852  * Set the display status of the admin bar.
853  *
854  * This can be called immediately upon plugin load. It does not need to be called from a function hooked to the init action.
855  *
856  * @since 3.1.0
857  *
858  * @global WP_Admin_Bar $wp_admin_bar
859  *
860  * @param bool $show Whether to allow the admin bar to show.
861  */
862 function show_admin_bar( $show ) {
863         global $show_admin_bar;
864         $show_admin_bar = (bool) $show;
865 }
866
867 /**
868  * Determine whether the admin bar should be showing.
869  *
870  * @since 3.1.0
871  *
872  * @global WP_Admin_Bar $wp_admin_bar
873  * @global string       $pagenow
874  *
875  * @return bool Whether the admin bar should be showing.
876  */
877 function is_admin_bar_showing() {
878         global $show_admin_bar, $pagenow;
879
880         // For all these types of requests, we never want an admin bar.
881         if ( defined('XMLRPC_REQUEST') || defined('DOING_AJAX') || defined('IFRAME_REQUEST') )
882                 return false;
883
884         // Integrated into the admin.
885         if ( is_admin() )
886                 return true;
887
888         if ( ! isset( $show_admin_bar ) ) {
889                 if ( ! is_user_logged_in() || 'wp-login.php' == $pagenow ) {
890                         $show_admin_bar = false;
891                 } else {
892                         $show_admin_bar = _get_admin_bar_pref();
893                 }
894         }
895
896         /**
897          * Filter whether to show the admin bar.
898          *
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.
901          *
902          * @since 3.1.0
903          *
904          * @param bool $show_admin_bar Whether the admin bar should be shown. Default false.
905          */
906         $show_admin_bar = apply_filters( 'show_admin_bar', $show_admin_bar );
907
908         return $show_admin_bar;
909 }
910
911 /**
912  * Retrieve the admin bar display preference of a user.
913  *
914  * @since 3.1.0
915  * @access private
916  *
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.
921  */
922 function _get_admin_bar_pref( $context = 'front', $user = 0 ) {
923         $pref = get_user_option( "show_admin_bar_{$context}", $user );
924         if ( false === $pref )
925                 return true;
926
927         return 'true' === $pref;
928 }