53 } |
53 } |
54 |
54 |
55 /** |
55 /** |
56 * Renders the admin bar to the page based on the $wp_admin_bar->menu member var. |
56 * Renders the admin bar to the page based on the $wp_admin_bar->menu member var. |
57 * |
57 * |
58 * This is called very late on the footer actions so that it will render after |
58 * This is called very early on the {@see 'wp_body_open'} action so that it will render |
59 * anything else being added to the footer. |
59 * before anything else being added to the page body. |
|
60 * |
|
61 * For backward compatibility with themes not using the 'wp_body_open' action, |
|
62 * the function is also called late on {@see 'wp_footer'}. |
60 * |
63 * |
61 * It includes the {@see 'admin_bar_menu'} action which should be used to hook in and |
64 * It includes the {@see 'admin_bar_menu'} action which should be used to hook in and |
62 * add new menus to the admin bar. That way you can be sure that you are adding at most |
65 * add new menus to the admin bar. That way you can be sure that you are adding at most |
63 * optimal point, right before the admin bar is rendered. This also gives you access to |
66 * optimal point, right before the admin bar is rendered. This also gives you access to |
64 * the `$post` global, among others. |
67 * the `$post` global, among others. |
65 * |
68 * |
66 * @since 3.1.0 |
69 * @since 3.1.0 |
|
70 * @since 5.4.0 Called on 'wp_body_open' action first, with 'wp_footer' as a fallback. |
67 * |
71 * |
68 * @global WP_Admin_Bar $wp_admin_bar |
72 * @global WP_Admin_Bar $wp_admin_bar |
69 */ |
73 */ |
70 function wp_admin_bar_render() { |
74 function wp_admin_bar_render() { |
71 global $wp_admin_bar; |
75 global $wp_admin_bar; |
|
76 static $rendered = false; |
|
77 |
|
78 if ( $rendered ) { |
|
79 return; |
|
80 } |
72 |
81 |
73 if ( ! is_admin_bar_showing() || ! is_object( $wp_admin_bar ) ) { |
82 if ( ! is_admin_bar_showing() || ! is_object( $wp_admin_bar ) ) { |
74 return; |
83 return; |
75 } |
84 } |
76 |
85 |
129 $wp_logo_menu_args['meta'] = array( |
140 $wp_logo_menu_args['meta'] = array( |
130 'tabindex' => 0, |
141 'tabindex' => 0, |
131 ); |
142 ); |
132 } |
143 } |
133 |
144 |
134 $wp_admin_bar->add_menu( $wp_logo_menu_args ); |
145 $wp_admin_bar->add_node( $wp_logo_menu_args ); |
135 |
146 |
136 if ( $about_url ) { |
147 if ( $about_url ) { |
137 // Add "About WordPress" link |
148 // Add "About WordPress" link. |
138 $wp_admin_bar->add_menu( |
149 $wp_admin_bar->add_node( |
139 array( |
150 array( |
140 'parent' => 'wp-logo', |
151 'parent' => 'wp-logo', |
141 'id' => 'about', |
152 'id' => 'about', |
142 'title' => __( 'About WordPress' ), |
153 'title' => __( 'About WordPress' ), |
143 'href' => $about_url, |
154 'href' => $about_url, |
144 ) |
155 ) |
145 ); |
156 ); |
146 } |
157 } |
147 |
158 |
148 // Add WordPress.org link |
159 // Add WordPress.org link. |
149 $wp_admin_bar->add_menu( |
160 $wp_admin_bar->add_node( |
150 array( |
161 array( |
151 'parent' => 'wp-logo-external', |
162 'parent' => 'wp-logo-external', |
152 'id' => 'wporg', |
163 'id' => 'wporg', |
153 'title' => __( 'WordPress.org' ), |
164 'title' => __( 'WordPress.org' ), |
154 'href' => __( 'https://wordpress.org/' ), |
165 'href' => __( 'https://wordpress.org/' ), |
155 ) |
166 ) |
156 ); |
167 ); |
157 |
168 |
158 // Add codex link |
169 // Add Codex link. |
159 $wp_admin_bar->add_menu( |
170 $wp_admin_bar->add_node( |
160 array( |
171 array( |
161 'parent' => 'wp-logo-external', |
172 'parent' => 'wp-logo-external', |
162 'id' => 'documentation', |
173 'id' => 'documentation', |
163 'title' => __( 'Documentation' ), |
174 'title' => __( 'Documentation' ), |
164 'href' => __( 'https://codex.wordpress.org/' ), |
175 'href' => __( 'https://codex.wordpress.org/' ), |
165 ) |
176 ) |
166 ); |
177 ); |
167 |
178 |
168 // Add forums link |
179 // Add forums link. |
169 $wp_admin_bar->add_menu( |
180 $wp_admin_bar->add_node( |
170 array( |
181 array( |
171 'parent' => 'wp-logo-external', |
182 'parent' => 'wp-logo-external', |
172 'id' => 'support-forums', |
183 'id' => 'support-forums', |
173 'title' => __( 'Support' ), |
184 'title' => __( 'Support' ), |
174 'href' => __( 'https://wordpress.org/support/' ), |
185 'href' => __( 'https://wordpress.org/support/' ), |
175 ) |
186 ) |
176 ); |
187 ); |
177 |
188 |
178 // Add feedback link |
189 // Add feedback link. |
179 $wp_admin_bar->add_menu( |
190 $wp_admin_bar->add_node( |
180 array( |
191 array( |
181 'parent' => 'wp-logo-external', |
192 'parent' => 'wp-logo-external', |
182 'id' => 'feedback', |
193 'id' => 'feedback', |
183 'title' => __( 'Feedback' ), |
194 'title' => __( 'Feedback' ), |
184 'href' => __( 'https://wordpress.org/support/forum/requests-and-feedback' ), |
195 'href' => __( 'https://wordpress.org/support/forum/requests-and-feedback' ), |
227 } else { |
238 } else { |
228 $profile_url = false; |
239 $profile_url = false; |
229 } |
240 } |
230 |
241 |
231 $avatar = get_avatar( $user_id, 26 ); |
242 $avatar = get_avatar( $user_id, 26 ); |
232 /* translators: %s: current user's display name */ |
243 /* translators: %s: Current user's display name. */ |
233 $howdy = sprintf( __( 'Howdy, %s' ), '<span class="display-name">' . $current_user->display_name . '</span>' ); |
244 $howdy = sprintf( __( 'Howdy, %s' ), '<span class="display-name">' . $current_user->display_name . '</span>' ); |
234 $class = empty( $avatar ) ? '' : 'with-avatar'; |
245 $class = empty( $avatar ) ? '' : 'with-avatar'; |
235 |
246 |
236 $wp_admin_bar->add_menu( |
247 $wp_admin_bar->add_node( |
237 array( |
248 array( |
238 'id' => 'my-account', |
249 'id' => 'my-account', |
239 'parent' => 'top-secondary', |
250 'parent' => 'top-secondary', |
240 'title' => $howdy . $avatar, |
251 'title' => $howdy . $avatar, |
241 'href' => $profile_url, |
252 'href' => $profile_url, |
294 ), |
305 ), |
295 ) |
306 ) |
296 ); |
307 ); |
297 |
308 |
298 if ( false !== $profile_url ) { |
309 if ( false !== $profile_url ) { |
299 $wp_admin_bar->add_menu( |
310 $wp_admin_bar->add_node( |
300 array( |
311 array( |
301 'parent' => 'user-actions', |
312 'parent' => 'user-actions', |
302 'id' => 'edit-profile', |
313 'id' => 'edit-profile', |
303 'title' => __( 'Edit My Profile' ), |
314 'title' => __( 'Edit Profile' ), |
304 'href' => $profile_url, |
315 'href' => $profile_url, |
305 ) |
316 ) |
306 ); |
317 ); |
307 } |
318 } |
308 |
319 |
309 $wp_admin_bar->add_menu( |
320 $wp_admin_bar->add_node( |
310 array( |
321 array( |
311 'parent' => 'user-actions', |
322 'parent' => 'user-actions', |
312 'id' => 'logout', |
323 'id' => 'logout', |
313 'title' => __( 'Log Out' ), |
324 'title' => __( 'Log Out' ), |
314 'href' => wp_logout_url(), |
325 'href' => wp_logout_url(), |
339 if ( ! $blogname ) { |
350 if ( ! $blogname ) { |
340 $blogname = preg_replace( '#^(https?://)?(www.)?#', '', get_home_url() ); |
351 $blogname = preg_replace( '#^(https?://)?(www.)?#', '', get_home_url() ); |
341 } |
352 } |
342 |
353 |
343 if ( is_network_admin() ) { |
354 if ( is_network_admin() ) { |
344 /* translators: %s: site name */ |
355 /* translators: %s: Site title. */ |
345 $blogname = sprintf( __( 'Network Admin: %s' ), esc_html( get_network()->site_name ) ); |
356 $blogname = sprintf( __( 'Network Admin: %s' ), esc_html( get_network()->site_name ) ); |
346 } elseif ( is_user_admin() ) { |
357 } elseif ( is_user_admin() ) { |
347 /* translators: %s: site name */ |
358 /* translators: %s: Site title. */ |
348 $blogname = sprintf( __( 'User Dashboard: %s' ), esc_html( get_network()->site_name ) ); |
359 $blogname = sprintf( __( 'User Dashboard: %s' ), esc_html( get_network()->site_name ) ); |
349 } |
360 } |
350 |
361 |
351 $title = wp_html_excerpt( $blogname, 40, '…' ); |
362 $title = wp_html_excerpt( $blogname, 40, '…' ); |
352 |
363 |
353 $wp_admin_bar->add_menu( |
364 $wp_admin_bar->add_node( |
354 array( |
365 array( |
355 'id' => 'site-name', |
366 'id' => 'site-name', |
356 'title' => $title, |
367 'title' => $title, |
357 'href' => ( is_admin() || ! current_user_can( 'read' ) ) ? home_url( '/' ) : admin_url(), |
368 'href' => ( is_admin() || ! current_user_can( 'read' ) ) ? home_url( '/' ) : admin_url(), |
358 ) |
369 ) |
360 |
371 |
361 // Create submenu items. |
372 // Create submenu items. |
362 |
373 |
363 if ( is_admin() ) { |
374 if ( is_admin() ) { |
364 // Add an option to visit the site. |
375 // Add an option to visit the site. |
365 $wp_admin_bar->add_menu( |
376 $wp_admin_bar->add_node( |
366 array( |
377 array( |
367 'parent' => 'site-name', |
378 'parent' => 'site-name', |
368 'id' => 'view-site', |
379 'id' => 'view-site', |
369 'title' => __( 'Visit Site' ), |
380 'title' => __( 'Visit Site' ), |
370 'href' => home_url( '/' ), |
381 'href' => home_url( '/' ), |
371 ) |
382 ) |
372 ); |
383 ); |
373 |
384 |
374 if ( is_blog_admin() && is_multisite() && current_user_can( 'manage_sites' ) ) { |
385 if ( is_blog_admin() && is_multisite() && current_user_can( 'manage_sites' ) ) { |
375 $wp_admin_bar->add_menu( |
386 $wp_admin_bar->add_node( |
376 array( |
387 array( |
377 'parent' => 'site-name', |
388 'parent' => 'site-name', |
378 'id' => 'edit-site', |
389 'id' => 'edit-site', |
379 'title' => __( 'Edit Site' ), |
390 'title' => __( 'Edit Site' ), |
380 'href' => network_admin_url( 'site-info.php?id=' . get_current_blog_id() ), |
391 'href' => network_admin_url( 'site-info.php?id=' . get_current_blog_id() ), |
381 ) |
392 ) |
382 ); |
393 ); |
383 } |
394 } |
384 } elseif ( current_user_can( 'read' ) ) { |
395 } elseif ( current_user_can( 'read' ) ) { |
385 // We're on the front end, link to the Dashboard. |
396 // We're on the front end, link to the Dashboard. |
386 $wp_admin_bar->add_menu( |
397 $wp_admin_bar->add_node( |
387 array( |
398 array( |
388 'parent' => 'site-name', |
399 'parent' => 'site-name', |
389 'id' => 'dashboard', |
400 'id' => 'dashboard', |
390 'title' => __( 'Dashboard' ), |
401 'title' => __( 'Dashboard' ), |
391 'href' => admin_url(), |
402 'href' => admin_url(), |
479 'parent' => 'my-sites', |
492 'parent' => 'my-sites', |
480 'id' => 'my-sites-super-admin', |
493 'id' => 'my-sites-super-admin', |
481 ) |
494 ) |
482 ); |
495 ); |
483 |
496 |
484 $wp_admin_bar->add_menu( |
497 $wp_admin_bar->add_node( |
485 array( |
498 array( |
486 'parent' => 'my-sites-super-admin', |
499 'parent' => 'my-sites-super-admin', |
487 'id' => 'network-admin', |
500 'id' => 'network-admin', |
488 'title' => __( 'Network Admin' ), |
501 'title' => __( 'Network Admin' ), |
489 'href' => network_admin_url(), |
502 'href' => network_admin_url(), |
490 ) |
503 ) |
491 ); |
504 ); |
492 |
505 |
493 $wp_admin_bar->add_menu( |
506 $wp_admin_bar->add_node( |
494 array( |
507 array( |
495 'parent' => 'network-admin', |
508 'parent' => 'network-admin', |
496 'id' => 'network-admin-d', |
509 'id' => 'network-admin-d', |
497 'title' => __( 'Dashboard' ), |
510 'title' => __( 'Dashboard' ), |
498 'href' => network_admin_url(), |
511 'href' => network_admin_url(), |
499 ) |
512 ) |
500 ); |
513 ); |
501 |
514 |
502 if ( current_user_can( 'manage_sites' ) ) { |
515 if ( current_user_can( 'manage_sites' ) ) { |
503 $wp_admin_bar->add_menu( |
516 $wp_admin_bar->add_node( |
504 array( |
517 array( |
505 'parent' => 'network-admin', |
518 'parent' => 'network-admin', |
506 'id' => 'network-admin-s', |
519 'id' => 'network-admin-s', |
507 'title' => __( 'Sites' ), |
520 'title' => __( 'Sites' ), |
508 'href' => network_admin_url( 'sites.php' ), |
521 'href' => network_admin_url( 'sites.php' ), |
509 ) |
522 ) |
510 ); |
523 ); |
511 } |
524 } |
512 |
525 |
513 if ( current_user_can( 'manage_network_users' ) ) { |
526 if ( current_user_can( 'manage_network_users' ) ) { |
514 $wp_admin_bar->add_menu( |
527 $wp_admin_bar->add_node( |
515 array( |
528 array( |
516 'parent' => 'network-admin', |
529 'parent' => 'network-admin', |
517 'id' => 'network-admin-u', |
530 'id' => 'network-admin-u', |
518 'title' => __( 'Users' ), |
531 'title' => __( 'Users' ), |
519 'href' => network_admin_url( 'users.php' ), |
532 'href' => network_admin_url( 'users.php' ), |
520 ) |
533 ) |
521 ); |
534 ); |
522 } |
535 } |
523 |
536 |
524 if ( current_user_can( 'manage_network_themes' ) ) { |
537 if ( current_user_can( 'manage_network_themes' ) ) { |
525 $wp_admin_bar->add_menu( |
538 $wp_admin_bar->add_node( |
526 array( |
539 array( |
527 'parent' => 'network-admin', |
540 'parent' => 'network-admin', |
528 'id' => 'network-admin-t', |
541 'id' => 'network-admin-t', |
529 'title' => __( 'Themes' ), |
542 'title' => __( 'Themes' ), |
530 'href' => network_admin_url( 'themes.php' ), |
543 'href' => network_admin_url( 'themes.php' ), |
531 ) |
544 ) |
532 ); |
545 ); |
533 } |
546 } |
534 |
547 |
535 if ( current_user_can( 'manage_network_plugins' ) ) { |
548 if ( current_user_can( 'manage_network_plugins' ) ) { |
536 $wp_admin_bar->add_menu( |
549 $wp_admin_bar->add_node( |
537 array( |
550 array( |
538 'parent' => 'network-admin', |
551 'parent' => 'network-admin', |
539 'id' => 'network-admin-p', |
552 'id' => 'network-admin-p', |
540 'title' => __( 'Plugins' ), |
553 'title' => __( 'Plugins' ), |
541 'href' => network_admin_url( 'plugins.php' ), |
554 'href' => network_admin_url( 'plugins.php' ), |
542 ) |
555 ) |
543 ); |
556 ); |
544 } |
557 } |
545 |
558 |
546 if ( current_user_can( 'manage_network_options' ) ) { |
559 if ( current_user_can( 'manage_network_options' ) ) { |
547 $wp_admin_bar->add_menu( |
560 $wp_admin_bar->add_node( |
548 array( |
561 array( |
549 'parent' => 'network-admin', |
562 'parent' => 'network-admin', |
550 'id' => 'network-admin-o', |
563 'id' => 'network-admin-o', |
551 'title' => __( 'Settings' ), |
564 'title' => __( 'Settings' ), |
552 'href' => network_admin_url( 'settings.php' ), |
565 'href' => network_admin_url( 'settings.php' ), |
553 ) |
566 ) |
554 ); |
567 ); |
555 } |
568 } |
556 } |
569 } |
557 |
570 |
558 // Add site links |
571 // Add site links. |
559 $wp_admin_bar->add_group( |
572 $wp_admin_bar->add_group( |
560 array( |
573 array( |
561 'parent' => 'my-sites', |
574 'parent' => 'my-sites', |
562 'id' => 'my-sites-list', |
575 'id' => 'my-sites-list', |
563 'meta' => array( |
576 'meta' => array( |
578 } |
591 } |
579 |
592 |
580 $menu_id = 'blog-' . $blog->userblog_id; |
593 $menu_id = 'blog-' . $blog->userblog_id; |
581 |
594 |
582 if ( current_user_can( 'read' ) ) { |
595 if ( current_user_can( 'read' ) ) { |
583 $wp_admin_bar->add_menu( |
596 $wp_admin_bar->add_node( |
584 array( |
597 array( |
585 'parent' => 'my-sites-list', |
598 'parent' => 'my-sites-list', |
586 'id' => $menu_id, |
599 'id' => $menu_id, |
587 'title' => $blavatar . $blogname, |
600 'title' => $blavatar . $blogname, |
588 'href' => admin_url(), |
601 'href' => admin_url(), |
589 ) |
602 ) |
590 ); |
603 ); |
591 |
604 |
592 $wp_admin_bar->add_menu( |
605 $wp_admin_bar->add_node( |
593 array( |
606 array( |
594 'parent' => $menu_id, |
607 'parent' => $menu_id, |
595 'id' => $menu_id . '-d', |
608 'id' => $menu_id . '-d', |
596 'title' => __( 'Dashboard' ), |
609 'title' => __( 'Dashboard' ), |
597 'href' => admin_url(), |
610 'href' => admin_url(), |
598 ) |
611 ) |
599 ); |
612 ); |
600 } else { |
613 } else { |
601 $wp_admin_bar->add_menu( |
614 $wp_admin_bar->add_node( |
602 array( |
615 array( |
603 'parent' => 'my-sites-list', |
616 'parent' => 'my-sites-list', |
604 'id' => $menu_id, |
617 'id' => $menu_id, |
605 'title' => $blavatar . $blogname, |
618 'title' => $blavatar . $blogname, |
606 'href' => home_url(), |
619 'href' => home_url(), |
607 ) |
620 ) |
608 ); |
621 ); |
609 } |
622 } |
610 |
623 |
611 if ( current_user_can( get_post_type_object( 'post' )->cap->create_posts ) ) { |
624 if ( current_user_can( get_post_type_object( 'post' )->cap->create_posts ) ) { |
612 $wp_admin_bar->add_menu( |
625 $wp_admin_bar->add_node( |
613 array( |
626 array( |
614 'parent' => $menu_id, |
627 'parent' => $menu_id, |
615 'id' => $menu_id . '-n', |
628 'id' => $menu_id . '-n', |
616 'title' => get_post_type_object( 'post' )->labels->new_item, |
629 'title' => get_post_type_object( 'post' )->labels->new_item, |
617 'href' => admin_url( 'post-new.php' ), |
630 'href' => admin_url( 'post-new.php' ), |
618 ) |
631 ) |
619 ); |
632 ); |
620 } |
633 } |
621 |
634 |
622 if ( current_user_can( 'edit_posts' ) ) { |
635 if ( current_user_can( 'edit_posts' ) ) { |
623 $wp_admin_bar->add_menu( |
636 $wp_admin_bar->add_node( |
624 array( |
637 array( |
625 'parent' => $menu_id, |
638 'parent' => $menu_id, |
626 'id' => $menu_id . '-c', |
639 'id' => $menu_id . '-c', |
627 'title' => __( 'Manage Comments' ), |
640 'title' => __( 'Manage Comments' ), |
628 'href' => admin_url( 'edit-comments.php' ), |
641 'href' => admin_url( 'edit-comments.php' ), |
629 ) |
642 ) |
630 ); |
643 ); |
631 } |
644 } |
632 |
645 |
633 $wp_admin_bar->add_menu( |
646 $wp_admin_bar->add_node( |
634 array( |
647 array( |
635 'parent' => $menu_id, |
648 'parent' => $menu_id, |
636 'id' => $menu_id . '-v', |
649 'id' => $menu_id . '-v', |
637 'title' => __( 'Visit Site' ), |
650 'title' => __( 'Visit Site' ), |
638 'href' => home_url( '/' ), |
651 'href' => home_url( '/' ), |
674 * Provide an edit link for posts and terms. |
687 * Provide an edit link for posts and terms. |
675 * |
688 * |
676 * @since 3.1.0 |
689 * @since 3.1.0 |
677 * |
690 * |
678 * @global WP_Term $tag |
691 * @global WP_Term $tag |
679 * @global WP_Query $wp_the_query |
692 * @global WP_Query $wp_the_query WordPress Query object. |
680 * @global int $user_id The ID of the user being edited. Not to be confused with the |
693 * @global int $user_id The ID of the user being edited. Not to be confused with the |
681 * global $user_ID, which contains the ID of the current user. |
694 * global $user_ID, which contains the ID of the current user. |
|
695 * @global int $post_id The ID of the post when editing comments for a single post. |
682 * |
696 * |
683 * @param WP_Admin_Bar $wp_admin_bar |
697 * @param WP_Admin_Bar $wp_admin_bar |
684 */ |
698 */ |
685 function wp_admin_bar_edit_menu( $wp_admin_bar ) { |
699 function wp_admin_bar_edit_menu( $wp_admin_bar ) { |
686 global $tag, $wp_the_query, $user_id; |
700 global $tag, $wp_the_query, $user_id, $post_id; |
687 |
701 |
688 if ( is_admin() ) { |
702 if ( is_admin() ) { |
689 $current_screen = get_current_screen(); |
703 $current_screen = get_current_screen(); |
690 $post = get_post(); |
704 $post = get_post(); |
691 |
705 $post_type_object = null; |
692 if ( 'post' == $current_screen->base |
706 |
693 && 'add' != $current_screen->action |
707 if ( 'post' === $current_screen->base ) { |
694 && ( $post_type_object = get_post_type_object( $post->post_type ) ) |
708 $post_type_object = get_post_type_object( $post->post_type ); |
|
709 } elseif ( 'edit' === $current_screen->base ) { |
|
710 $post_type_object = get_post_type_object( $current_screen->post_type ); |
|
711 } elseif ( 'edit-comments' === $current_screen->base && $post_id ) { |
|
712 $post = get_post( $post_id ); |
|
713 if ( $post ) { |
|
714 $post_type_object = get_post_type_object( $post->post_type ); |
|
715 } |
|
716 } |
|
717 |
|
718 if ( ( 'post' === $current_screen->base || 'edit-comments' === $current_screen->base ) |
|
719 && 'add' !== $current_screen->action |
|
720 && ( $post_type_object ) |
695 && current_user_can( 'read_post', $post->ID ) |
721 && current_user_can( 'read_post', $post->ID ) |
696 && ( $post_type_object->public ) |
722 && ( $post_type_object->public ) |
697 && ( $post_type_object->show_in_admin_bar ) ) { |
723 && ( $post_type_object->show_in_admin_bar ) ) { |
698 if ( 'draft' == $post->post_status ) { |
724 if ( 'draft' === $post->post_status ) { |
699 $preview_link = get_preview_post_link( $post ); |
725 $preview_link = get_preview_post_link( $post ); |
700 $wp_admin_bar->add_menu( |
726 $wp_admin_bar->add_node( |
701 array( |
727 array( |
702 'id' => 'preview', |
728 'id' => 'preview', |
703 'title' => $post_type_object->labels->view_item, |
729 'title' => $post_type_object->labels->view_item, |
704 'href' => esc_url( $preview_link ), |
730 'href' => esc_url( $preview_link ), |
705 'meta' => array( 'target' => 'wp-preview-' . $post->ID ), |
731 'meta' => array( 'target' => 'wp-preview-' . $post->ID ), |
706 ) |
732 ) |
707 ); |
733 ); |
708 } else { |
734 } else { |
709 $wp_admin_bar->add_menu( |
735 $wp_admin_bar->add_node( |
710 array( |
736 array( |
711 'id' => 'view', |
737 'id' => 'view', |
712 'title' => $post_type_object->labels->view_item, |
738 'title' => $post_type_object->labels->view_item, |
713 'href' => get_permalink( $post->ID ), |
739 'href' => get_permalink( $post->ID ), |
714 ) |
740 ) |
715 ); |
741 ); |
716 } |
742 } |
717 } elseif ( 'edit' == $current_screen->base |
743 } elseif ( 'edit' === $current_screen->base |
718 && ( $post_type_object = get_post_type_object( $current_screen->post_type ) ) |
744 && ( $post_type_object ) |
719 && ( $post_type_object->public ) |
745 && ( $post_type_object->public ) |
720 && ( $post_type_object->show_in_admin_bar ) |
746 && ( $post_type_object->show_in_admin_bar ) |
721 && ( get_post_type_archive_link( $post_type_object->name ) ) |
747 && ( get_post_type_archive_link( $post_type_object->name ) ) |
722 && ! ( 'post' === $post_type_object->name && 'posts' === get_option( 'show_on_front' ) ) ) { |
748 && ! ( 'post' === $post_type_object->name && 'posts' === get_option( 'show_on_front' ) ) ) { |
723 $wp_admin_bar->add_node( |
749 $wp_admin_bar->add_node( |
725 'id' => 'archive', |
751 'id' => 'archive', |
726 'title' => $post_type_object->labels->view_items, |
752 'title' => $post_type_object->labels->view_items, |
727 'href' => get_post_type_archive_link( $current_screen->post_type ), |
753 'href' => get_post_type_archive_link( $current_screen->post_type ), |
728 ) |
754 ) |
729 ); |
755 ); |
730 } elseif ( 'term' == $current_screen->base |
756 } elseif ( 'term' === $current_screen->base && isset( $tag ) && is_object( $tag ) && ! is_wp_error( $tag ) ) { |
731 && isset( $tag ) && is_object( $tag ) && ! is_wp_error( $tag ) |
757 $tax = get_taxonomy( $tag->taxonomy ); |
732 && ( $tax = get_taxonomy( $tag->taxonomy ) ) |
758 if ( is_taxonomy_viewable( $tax ) ) { |
733 && is_taxonomy_viewable( $tax ) ) { |
759 $wp_admin_bar->add_node( |
734 $wp_admin_bar->add_menu( |
760 array( |
735 array( |
761 'id' => 'view', |
736 'id' => 'view', |
762 'title' => $tax->labels->view_item, |
737 'title' => $tax->labels->view_item, |
763 'href' => get_term_link( $tag ), |
738 'href' => get_term_link( $tag ), |
764 ) |
739 ) |
765 ); |
740 ); |
766 } |
741 } elseif ( 'user-edit' == $current_screen->base |
767 } elseif ( 'user-edit' === $current_screen->base && isset( $user_id ) ) { |
742 && isset( $user_id ) |
768 $user_object = get_userdata( $user_id ); |
743 && ( $user_object = get_userdata( $user_id ) ) |
769 $view_link = get_author_posts_url( $user_object->ID ); |
744 && $user_object->exists() |
770 if ( $user_object->exists() && $view_link ) { |
745 && $view_link = get_author_posts_url( $user_object->ID ) ) { |
771 $wp_admin_bar->add_node( |
746 $wp_admin_bar->add_menu( |
772 array( |
747 array( |
773 'id' => 'view', |
748 'id' => 'view', |
774 'title' => __( 'View User' ), |
749 'title' => __( 'View User' ), |
775 'href' => $view_link, |
750 'href' => $view_link, |
776 ) |
751 ) |
777 ); |
752 ); |
778 } |
753 } |
779 } |
754 } else { |
780 } else { |
755 $current_object = $wp_the_query->get_queried_object(); |
781 $current_object = $wp_the_query->get_queried_object(); |
756 |
782 |
757 if ( empty( $current_object ) ) { |
783 if ( empty( $current_object ) ) { |
758 return; |
784 return; |
759 } |
785 } |
760 |
786 |
761 if ( ! empty( $current_object->post_type ) |
787 if ( ! empty( $current_object->post_type ) ) { |
762 && ( $post_type_object = get_post_type_object( $current_object->post_type ) ) |
788 $post_type_object = get_post_type_object( $current_object->post_type ); |
763 && current_user_can( 'edit_post', $current_object->ID ) |
789 $edit_post_link = get_edit_post_link( $current_object->ID ); |
764 && $post_type_object->show_in_admin_bar |
790 if ( $post_type_object |
765 && $edit_post_link = get_edit_post_link( $current_object->ID ) ) { |
791 && $edit_post_link |
766 $wp_admin_bar->add_menu( |
792 && current_user_can( 'edit_post', $current_object->ID ) |
767 array( |
793 && $post_type_object->show_in_admin_bar ) { |
768 'id' => 'edit', |
794 $wp_admin_bar->add_node( |
769 'title' => $post_type_object->labels->edit_item, |
795 array( |
770 'href' => $edit_post_link, |
796 'id' => 'edit', |
771 ) |
797 'title' => $post_type_object->labels->edit_item, |
772 ); |
798 'href' => $edit_post_link, |
773 } elseif ( ! empty( $current_object->taxonomy ) |
799 ) |
774 && ( $tax = get_taxonomy( $current_object->taxonomy ) ) |
800 ); |
775 && current_user_can( 'edit_term', $current_object->term_id ) |
801 } |
776 && $edit_term_link = get_edit_term_link( $current_object->term_id, $current_object->taxonomy ) ) { |
802 } elseif ( ! empty( $current_object->taxonomy ) ) { |
777 $wp_admin_bar->add_menu( |
803 $tax = get_taxonomy( $current_object->taxonomy ); |
778 array( |
804 $edit_term_link = get_edit_term_link( $current_object->term_id, $current_object->taxonomy ); |
779 'id' => 'edit', |
805 if ( $tax && $edit_term_link && current_user_can( 'edit_term', $current_object->term_id ) ) { |
780 'title' => $tax->labels->edit_item, |
806 $wp_admin_bar->add_node( |
781 'href' => $edit_term_link, |
807 array( |
782 ) |
808 'id' => 'edit', |
783 ); |
809 'title' => $tax->labels->edit_item, |
784 } elseif ( is_a( $current_object, 'WP_User' ) |
810 'href' => $edit_term_link, |
785 && current_user_can( 'edit_user', $current_object->ID ) |
811 ) |
786 && $edit_user_link = get_edit_user_link( $current_object->ID ) ) { |
812 ); |
787 $wp_admin_bar->add_menu( |
813 } |
788 array( |
814 } elseif ( is_a( $current_object, 'WP_User' ) && current_user_can( 'edit_user', $current_object->ID ) ) { |
789 'id' => 'edit', |
815 $edit_user_link = get_edit_user_link( $current_object->ID ); |
790 'title' => __( 'Edit User' ), |
816 if ( $edit_user_link ) { |
791 'href' => $edit_user_link, |
817 $wp_admin_bar->add_node( |
792 ) |
818 array( |
793 ); |
819 'id' => 'edit', |
|
820 'title' => __( 'Edit User' ), |
|
821 'href' => $edit_user_link, |
|
822 ) |
|
823 ); |
|
824 } |
794 } |
825 } |
795 } |
826 } |
796 } |
827 } |
797 |
828 |
798 /** |
829 /** |
847 return; |
878 return; |
848 } |
879 } |
849 |
880 |
850 $title = '<span class="ab-icon"></span><span class="ab-label">' . _x( 'New', 'admin bar menu group label' ) . '</span>'; |
881 $title = '<span class="ab-icon"></span><span class="ab-label">' . _x( 'New', 'admin bar menu group label' ) . '</span>'; |
851 |
882 |
852 $wp_admin_bar->add_menu( |
883 $wp_admin_bar->add_node( |
853 array( |
884 array( |
854 'id' => 'new-content', |
885 'id' => 'new-content', |
855 'title' => $title, |
886 'title' => $title, |
856 'href' => admin_url( current( array_keys( $actions ) ) ), |
887 'href' => admin_url( current( array_keys( $actions ) ) ), |
857 ) |
888 ) |
858 ); |
889 ); |
859 |
890 |
860 foreach ( $actions as $link => $action ) { |
891 foreach ( $actions as $link => $action ) { |
861 list( $title, $id ) = $action; |
892 list( $title, $id ) = $action; |
862 |
893 |
863 $wp_admin_bar->add_menu( |
894 $wp_admin_bar->add_node( |
864 array( |
895 array( |
865 'parent' => 'new-content', |
896 'parent' => 'new-content', |
866 'id' => $id, |
897 'id' => $id, |
867 'title' => $title, |
898 'title' => $title, |
868 'href' => admin_url( $link ), |
899 'href' => admin_url( $link ), |
884 } |
915 } |
885 |
916 |
886 $awaiting_mod = wp_count_comments(); |
917 $awaiting_mod = wp_count_comments(); |
887 $awaiting_mod = $awaiting_mod->moderated; |
918 $awaiting_mod = $awaiting_mod->moderated; |
888 $awaiting_text = sprintf( |
919 $awaiting_text = sprintf( |
889 /* translators: %s: number of comments in moderation */ |
920 /* translators: %s: Number of comments. */ |
890 _n( '%s Comment in moderation', '%s Comments in moderation', $awaiting_mod ), |
921 _n( '%s Comment in moderation', '%s Comments in moderation', $awaiting_mod ), |
891 number_format_i18n( $awaiting_mod ) |
922 number_format_i18n( $awaiting_mod ) |
892 ); |
923 ); |
893 |
924 |
894 $icon = '<span class="ab-icon"></span>'; |
925 $icon = '<span class="ab-icon"></span>'; |
895 $title = '<span class="ab-label awaiting-mod pending-count count-' . $awaiting_mod . '" aria-hidden="true">' . number_format_i18n( $awaiting_mod ) . '</span>'; |
926 $title = '<span class="ab-label awaiting-mod pending-count count-' . $awaiting_mod . '" aria-hidden="true">' . number_format_i18n( $awaiting_mod ) . '</span>'; |
896 $title .= '<span class="screen-reader-text comments-in-moderation-text">' . $awaiting_text . '</span>'; |
927 $title .= '<span class="screen-reader-text comments-in-moderation-text">' . $awaiting_text . '</span>'; |
897 |
928 |
898 $wp_admin_bar->add_menu( |
929 $wp_admin_bar->add_node( |
899 array( |
930 array( |
900 'id' => 'comments', |
931 'id' => 'comments', |
901 'title' => $icon . $title, |
932 'title' => $icon . $title, |
902 'href' => admin_url( 'edit-comments.php' ), |
933 'href' => admin_url( 'edit-comments.php' ), |
903 ) |
934 ) |
933 if ( ! current_user_can( 'edit_theme_options' ) ) { |
964 if ( ! current_user_can( 'edit_theme_options' ) ) { |
934 return; |
965 return; |
935 } |
966 } |
936 |
967 |
937 if ( current_theme_supports( 'widgets' ) ) { |
968 if ( current_theme_supports( 'widgets' ) ) { |
938 $wp_admin_bar->add_menu( |
969 $wp_admin_bar->add_node( |
939 array( |
970 array( |
940 'parent' => 'appearance', |
971 'parent' => 'appearance', |
941 'id' => 'widgets', |
972 'id' => 'widgets', |
942 'title' => __( 'Widgets' ), |
973 'title' => __( 'Widgets' ), |
943 'href' => admin_url( 'widgets.php' ), |
974 'href' => admin_url( 'widgets.php' ), |
944 ) |
975 ) |
945 ); |
976 ); |
946 } |
977 } |
947 |
978 |
948 if ( current_theme_supports( 'menus' ) || current_theme_supports( 'widgets' ) ) { |
979 if ( current_theme_supports( 'menus' ) || current_theme_supports( 'widgets' ) ) { |
949 $wp_admin_bar->add_menu( |
980 $wp_admin_bar->add_node( |
950 array( |
981 array( |
951 'parent' => 'appearance', |
982 'parent' => 'appearance', |
952 'id' => 'menus', |
983 'id' => 'menus', |
953 'title' => __( 'Menus' ), |
984 'title' => __( 'Menus' ), |
954 'href' => admin_url( 'nav-menus.php' ), |
985 'href' => admin_url( 'nav-menus.php' ), |
955 ) |
986 ) |
956 ); |
987 ); |
957 } |
988 } |
958 |
989 |
959 if ( current_theme_supports( 'custom-background' ) ) { |
990 if ( current_theme_supports( 'custom-background' ) ) { |
960 $wp_admin_bar->add_menu( |
991 $wp_admin_bar->add_node( |
961 array( |
992 array( |
962 'parent' => 'appearance', |
993 'parent' => 'appearance', |
963 'id' => 'background', |
994 'id' => 'background', |
964 'title' => __( 'Background' ), |
995 'title' => __( 'Background' ), |
965 'href' => admin_url( 'themes.php?page=custom-background' ), |
996 'href' => admin_url( 'themes.php?page=custom-background' ), |
1105 * Style and scripts for the admin bar. |
1136 * Style and scripts for the admin bar. |
1106 * |
1137 * |
1107 * @since 3.1.0 |
1138 * @since 3.1.0 |
1108 */ |
1139 */ |
1109 function wp_admin_bar_header() { |
1140 function wp_admin_bar_header() { |
|
1141 $type_attr = current_theme_supports( 'html5', 'style' ) ? '' : ' type="text/css"'; |
1110 ?> |
1142 ?> |
1111 <style type="text/css" media="print">#wpadminbar { display:none; }</style> |
1143 <style<?php echo $type_attr; ?> media="print">#wpadminbar { display:none; }</style> |
1112 <?php |
1144 <?php |
1113 } |
1145 } |
1114 |
1146 |
1115 /** |
1147 /** |
1116 * Default admin bar callback. |
1148 * Default admin bar callback. |
1117 * |
1149 * |
1118 * @since 3.1.0 |
1150 * @since 3.1.0 |
1119 */ |
1151 */ |
1120 function _admin_bar_bump_cb() { |
1152 function _admin_bar_bump_cb() { |
1121 |
1153 $type_attr = current_theme_supports( 'html5', 'style' ) ? '' : ' type="text/css"'; |
1122 ?> |
1154 ?> |
1123 <style type="text/css" media="screen"> |
1155 <style<?php echo $type_attr; ?> media="screen"> |
1124 html { margin-top: 32px !important; } |
1156 html { margin-top: 32px !important; } |
1125 * html body { margin-top: 32px !important; } |
1157 * html body { margin-top: 32px !important; } |
1126 @media screen and ( max-width: 782px ) { |
1158 @media screen and ( max-width: 782px ) { |
1127 html { margin-top: 46px !important; } |
1159 html { margin-top: 46px !important; } |
1128 * html body { margin-top: 46px !important; } |
1160 * html body { margin-top: 46px !important; } |