76 * @param WP_Admin_Bar $wp_admin_bar |
98 * @param WP_Admin_Bar $wp_admin_bar |
77 */ |
99 */ |
78 function wp_admin_bar_wp_menu( $wp_admin_bar ) { |
100 function wp_admin_bar_wp_menu( $wp_admin_bar ) { |
79 $wp_admin_bar->add_menu( array( |
101 $wp_admin_bar->add_menu( array( |
80 'id' => 'wp-logo', |
102 'id' => 'wp-logo', |
81 'title' => '<span class="ab-icon"></span>', |
103 'title' => '<span class="ab-icon"></span><span class="screen-reader-text">' . __( 'About WordPress' ) . '</span>', |
82 'href' => self_admin_url( 'about.php' ), |
104 'href' => self_admin_url( 'about.php' ), |
83 'meta' => array( |
|
84 'title' => __('About WordPress'), |
|
85 ), |
|
86 ) ); |
105 ) ); |
87 |
106 |
88 if ( is_user_logged_in() ) { |
107 if ( is_user_logged_in() ) { |
89 // Add "About WordPress" link |
108 // Add "About WordPress" link |
90 $wp_admin_bar->add_menu( array( |
109 $wp_admin_bar->add_menu( array( |
91 'parent' => 'wp-logo', |
110 'parent' => 'wp-logo', |
92 'id' => 'about', |
111 'id' => 'about', |
93 'title' => __('About WordPress'), |
112 'title' => __('About WordPress'), |
94 'href' => self_admin_url( 'about.php' ), |
113 'href' => self_admin_url( 'about.php' ), |
95 ) ); |
114 ) ); |
96 } |
115 } |
97 |
116 |
98 // Add WordPress.org link |
117 // Add WordPress.org link |
99 $wp_admin_bar->add_menu( array( |
118 $wp_admin_bar->add_menu( array( |
100 'parent' => 'wp-logo-external', |
119 'parent' => 'wp-logo-external', |
101 'id' => 'wporg', |
120 'id' => 'wporg', |
102 'title' => __('WordPress.org'), |
121 'title' => __('WordPress.org'), |
103 'href' => __('http://wordpress.org/'), |
122 'href' => __('https://wordpress.org/'), |
104 ) ); |
123 ) ); |
105 |
124 |
106 // Add codex link |
125 // Add codex link |
107 $wp_admin_bar->add_menu( array( |
126 $wp_admin_bar->add_menu( array( |
108 'parent' => 'wp-logo-external', |
127 'parent' => 'wp-logo-external', |
109 'id' => 'documentation', |
128 'id' => 'documentation', |
110 'title' => __('Documentation'), |
129 'title' => __('Documentation'), |
111 'href' => __('http://codex.wordpress.org/'), |
130 'href' => __('https://codex.wordpress.org/'), |
112 ) ); |
131 ) ); |
113 |
132 |
114 // Add forums link |
133 // Add forums link |
115 $wp_admin_bar->add_menu( array( |
134 $wp_admin_bar->add_menu( array( |
116 'parent' => 'wp-logo-external', |
135 'parent' => 'wp-logo-external', |
117 'id' => 'support-forums', |
136 'id' => 'support-forums', |
118 'title' => __('Support Forums'), |
137 'title' => __('Support Forums'), |
119 'href' => __('http://wordpress.org/support/'), |
138 'href' => __('https://wordpress.org/support/'), |
120 ) ); |
139 ) ); |
121 |
140 |
122 // Add feedback link |
141 // Add feedback link |
123 $wp_admin_bar->add_menu( array( |
142 $wp_admin_bar->add_menu( array( |
124 'parent' => 'wp-logo-external', |
143 'parent' => 'wp-logo-external', |
125 'id' => 'feedback', |
144 'id' => 'feedback', |
126 'title' => __('Feedback'), |
145 'title' => __('Feedback'), |
127 'href' => __('http://wordpress.org/support/forum/requests-and-feedback'), |
146 'href' => __('https://wordpress.org/support/forum/requests-and-feedback'), |
128 ) ); |
147 ) ); |
|
148 } |
|
149 |
|
150 /** |
|
151 * Add the sidebar toggle button. |
|
152 * |
|
153 * @since 3.8.0 |
|
154 * |
|
155 * @param WP_Admin_Bar $wp_admin_bar |
|
156 */ |
|
157 function wp_admin_bar_sidebar_toggle( $wp_admin_bar ) { |
|
158 if ( is_admin() ) { |
|
159 $wp_admin_bar->add_menu( array( |
|
160 'id' => 'menu-toggle', |
|
161 'title' => '<span class="ab-icon"></span><span class="screen-reader-text">' . __( 'Menu' ) . '</span>', |
|
162 'href' => '#', |
|
163 ) ); |
|
164 } |
129 } |
165 } |
130 |
166 |
131 /** |
167 /** |
132 * Add the "My Account" item. |
168 * Add the "My Account" item. |
133 * |
169 * |
214 * @since 3.3.0 |
249 * @since 3.3.0 |
215 * |
250 * |
216 * @param WP_Admin_Bar $wp_admin_bar |
251 * @param WP_Admin_Bar $wp_admin_bar |
217 */ |
252 */ |
218 function wp_admin_bar_site_menu( $wp_admin_bar ) { |
253 function wp_admin_bar_site_menu( $wp_admin_bar ) { |
219 global $current_site; |
|
220 |
|
221 // Don't show for logged out users. |
254 // Don't show for logged out users. |
222 if ( ! is_user_logged_in() ) |
255 if ( ! is_user_logged_in() ) |
223 return; |
256 return; |
224 |
257 |
225 // Show only when the user is a member of this site, or they're a super admin. |
258 // Show only when the user is a member of this site, or they're a super admin. |
226 if ( ! is_user_member_of_blog() && ! is_super_admin() ) |
259 if ( ! is_user_member_of_blog() && ! is_super_admin() ) |
227 return; |
260 return; |
228 |
261 |
229 $blogname = get_bloginfo('name'); |
262 $blogname = get_bloginfo('name'); |
230 |
263 |
231 if ( empty( $blogname ) ) |
264 if ( ! $blogname ) { |
232 $blogname = preg_replace( '#^(https?://)?(www.)?#', '', get_home_url() ); |
265 $blogname = preg_replace( '#^(https?://)?(www.)?#', '', get_home_url() ); |
|
266 } |
233 |
267 |
234 if ( is_network_admin() ) { |
268 if ( is_network_admin() ) { |
235 $blogname = sprintf( __('Network Admin: %s'), esc_html( $current_site->site_name ) ); |
269 $blogname = sprintf( __('Network Admin: %s'), esc_html( get_current_site()->site_name ) ); |
236 } elseif ( is_user_admin() ) { |
270 } elseif ( is_user_admin() ) { |
237 $blogname = sprintf( __('Global Dashboard: %s'), esc_html( $current_site->site_name ) ); |
271 $blogname = sprintf( __('Global Dashboard: %s'), esc_html( get_current_site()->site_name ) ); |
238 } |
272 } |
239 |
273 |
240 $title = wp_html_excerpt( $blogname, 40, '…' ); |
274 $title = wp_html_excerpt( $blogname, 40, '…' ); |
241 |
275 |
242 $wp_admin_bar->add_menu( array( |
276 $wp_admin_bar->add_menu( array( |
449 && ( $post_type_object = get_post_type_object( $post->post_type ) ) |
494 && ( $post_type_object = get_post_type_object( $post->post_type ) ) |
450 && current_user_can( 'read_post', $post->ID ) |
495 && current_user_can( 'read_post', $post->ID ) |
451 && ( $post_type_object->public ) |
496 && ( $post_type_object->public ) |
452 && ( $post_type_object->show_in_admin_bar ) ) |
497 && ( $post_type_object->show_in_admin_bar ) ) |
453 { |
498 { |
454 $wp_admin_bar->add_menu( array( |
499 if( 'draft' == $post->post_status ) { |
455 'id' => 'view', |
500 $preview_link = set_url_scheme( get_permalink( $post->ID ) ); |
456 'title' => $post_type_object->labels->view_item, |
501 /** This filter is documented in wp-admin/includes/meta-boxes.php */ |
457 'href' => get_permalink( $post->ID ) |
502 $preview_link = apply_filters( 'preview_post_link', add_query_arg( 'preview', 'true', $preview_link ), $post ); |
458 ) ); |
503 $wp_admin_bar->add_menu( array( |
|
504 'id' => 'preview', |
|
505 'title' => $post_type_object->labels->view_item, |
|
506 'href' => esc_url( $preview_link ), |
|
507 'meta' => array( 'target' => 'wp-preview-' . $post->ID ), |
|
508 ) ); |
|
509 } else { |
|
510 $wp_admin_bar->add_menu( array( |
|
511 'id' => 'view', |
|
512 'title' => $post_type_object->labels->view_item, |
|
513 'href' => get_permalink( $post->ID ) |
|
514 ) ); |
|
515 } |
459 } elseif ( 'edit-tags' == $current_screen->base |
516 } elseif ( 'edit-tags' == $current_screen->base |
460 && isset( $tag ) && is_object( $tag ) |
517 && isset( $tag ) && is_object( $tag ) |
461 && ( $tax = get_taxonomy( $tag->taxonomy ) ) |
518 && ( $tax = get_taxonomy( $tag->taxonomy ) ) |
462 && $tax->public ) |
519 && $tax->public ) |
463 { |
520 { |
474 return; |
531 return; |
475 |
532 |
476 if ( ! empty( $current_object->post_type ) |
533 if ( ! empty( $current_object->post_type ) |
477 && ( $post_type_object = get_post_type_object( $current_object->post_type ) ) |
534 && ( $post_type_object = get_post_type_object( $current_object->post_type ) ) |
478 && current_user_can( 'edit_post', $current_object->ID ) |
535 && current_user_can( 'edit_post', $current_object->ID ) |
479 && $post_type_object->show_ui && $post_type_object->show_in_admin_bar ) |
536 && $post_type_object->show_ui && $post_type_object->show_in_admin_bar |
|
537 && $edit_post_link = get_edit_post_link( $current_object->ID ) ) |
480 { |
538 { |
481 $wp_admin_bar->add_menu( array( |
539 $wp_admin_bar->add_menu( array( |
482 'id' => 'edit', |
540 'id' => 'edit', |
483 'title' => $post_type_object->labels->edit_item, |
541 'title' => $post_type_object->labels->edit_item, |
484 'href' => get_edit_post_link( $current_object->ID ) |
542 'href' => $edit_post_link |
485 ) ); |
543 ) ); |
486 } elseif ( ! empty( $current_object->taxonomy ) |
544 } elseif ( ! empty( $current_object->taxonomy ) |
487 && ( $tax = get_taxonomy( $current_object->taxonomy ) ) |
545 && ( $tax = get_taxonomy( $current_object->taxonomy ) ) |
488 && current_user_can( $tax->cap->edit_terms ) |
546 && current_user_can( $tax->cap->edit_terms ) |
489 && $tax->show_ui ) |
547 && $tax->show_ui |
|
548 && $edit_term_link = get_edit_term_link( $current_object->term_id, $current_object->taxonomy ) ) |
490 { |
549 { |
491 $wp_admin_bar->add_menu( array( |
550 $wp_admin_bar->add_menu( array( |
492 'id' => 'edit', |
551 'id' => 'edit', |
493 'title' => $tax->labels->edit_item, |
552 'title' => $tax->labels->edit_item, |
494 'href' => get_edit_term_link( $current_object->term_id, $current_object->taxonomy ) |
553 'href' => $edit_term_link |
495 ) ); |
554 ) ); |
496 } |
555 } |
497 } |
556 } |
498 } |
557 } |
499 |
558 |
598 * @param WP_Admin_Bar $wp_admin_bar |
654 * @param WP_Admin_Bar $wp_admin_bar |
599 */ |
655 */ |
600 function wp_admin_bar_appearance_menu( $wp_admin_bar ) { |
656 function wp_admin_bar_appearance_menu( $wp_admin_bar ) { |
601 $wp_admin_bar->add_group( array( 'parent' => 'site-name', 'id' => 'appearance' ) ); |
657 $wp_admin_bar->add_group( array( 'parent' => 'site-name', 'id' => 'appearance' ) ); |
602 |
658 |
603 if ( current_user_can( 'switch_themes' ) || current_user_can( 'edit_theme_options' ) ) |
|
604 $wp_admin_bar->add_menu( array( 'parent' => 'appearance', 'id' => 'themes', 'title' => __('Themes'), 'href' => admin_url('themes.php') ) ); |
|
605 |
|
606 if ( ! current_user_can( 'edit_theme_options' ) ) |
|
607 return; |
|
608 |
|
609 $current_url = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; |
659 $current_url = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; |
610 $wp_admin_bar->add_menu( array( |
660 $customize_url = add_query_arg( 'url', urlencode( $current_url ), wp_customize_url() ); |
611 'parent' => 'appearance', |
661 |
612 'id' => 'customize', |
662 if ( current_user_can( 'switch_themes' ) ) { |
613 'title' => __('Customize'), |
663 $wp_admin_bar->add_menu( array( |
614 'href' => add_query_arg( 'url', urlencode( $current_url ), wp_customize_url() ), |
664 'parent' => 'appearance', |
615 'meta' => array( |
665 'id' => 'themes', |
616 'class' => 'hide-if-no-customize', |
666 'title' => __( 'Themes' ), |
617 ), |
667 'href' => admin_url( 'themes.php' ), |
618 ) ); |
668 'meta' => array( |
619 add_action( 'wp_before_admin_bar_render', 'wp_customize_support_script' ); |
669 'class' => 'hide-if-customize', |
620 |
670 ), |
621 if ( current_theme_supports( 'widgets' ) ) |
671 ) ); |
622 $wp_admin_bar->add_menu( array( 'parent' => 'appearance', 'id' => 'widgets', 'title' => __('Widgets'), 'href' => admin_url('widgets.php') ) ); |
672 |
623 |
673 if ( current_user_can( 'customize' ) ) { |
624 if ( current_theme_supports( 'menus' ) || current_theme_supports( 'widgets' ) ) |
674 $wp_admin_bar->add_menu( array( |
|
675 'parent' => 'appearance', |
|
676 'id' => 'customize-themes', |
|
677 'title' => __( 'Themes' ), |
|
678 'href' => add_query_arg( urlencode( 'autofocus[section]' ), 'themes', $customize_url ), // urlencode() needed due to #16859 |
|
679 'meta' => array( |
|
680 'class' => 'hide-if-no-customize', |
|
681 ), |
|
682 ) ); |
|
683 } |
|
684 } |
|
685 |
|
686 if ( current_user_can( 'customize' ) ) { |
|
687 $wp_admin_bar->add_menu( array( |
|
688 'parent' => 'appearance', |
|
689 'id' => 'customize', |
|
690 'title' => __('Customize'), |
|
691 'href' => $customize_url, |
|
692 'meta' => array( |
|
693 'class' => 'hide-if-no-customize', |
|
694 ), |
|
695 ) ); |
|
696 add_action( 'wp_before_admin_bar_render', 'wp_customize_support_script' ); |
|
697 } |
|
698 |
|
699 if ( ! current_user_can( 'edit_theme_options' ) ) { |
|
700 return; |
|
701 } |
|
702 |
|
703 if ( current_theme_supports( 'widgets' ) ) { |
|
704 $wp_admin_bar->add_menu( array( |
|
705 'parent' => 'appearance', |
|
706 'id' => 'widgets', |
|
707 'title' => __( 'Widgets' ), |
|
708 'href' => admin_url( 'widgets.php' ), |
|
709 'meta' => array( |
|
710 'class' => 'hide-if-customize', |
|
711 ), |
|
712 ) ); |
|
713 |
|
714 if ( current_user_can( 'customize' ) ) { |
|
715 $wp_admin_bar->add_menu( array( |
|
716 'parent' => 'appearance', |
|
717 'id' => 'customize-widgets', |
|
718 'title' => __( 'Widgets' ), |
|
719 'href' => add_query_arg( urlencode( 'autofocus[panel]' ), 'widgets', $customize_url ), // urlencode() needed due to #16859 |
|
720 'meta' => array( |
|
721 'class' => 'hide-if-no-customize', |
|
722 ), |
|
723 ) ); |
|
724 } |
|
725 } |
|
726 |
|
727 if ( current_theme_supports( 'menus' ) || current_theme_supports( 'widgets' ) ) |
625 $wp_admin_bar->add_menu( array( 'parent' => 'appearance', 'id' => 'menus', 'title' => __('Menus'), 'href' => admin_url('nav-menus.php') ) ); |
728 $wp_admin_bar->add_menu( array( 'parent' => 'appearance', 'id' => 'menus', 'title' => __('Menus'), 'href' => admin_url('nav-menus.php') ) ); |
626 |
729 |
627 if ( current_theme_supports( 'custom-background' ) ) |
730 if ( current_theme_supports( 'custom-background' ) ) { |
628 $wp_admin_bar->add_menu( array( 'parent' => 'appearance', 'id' => 'background', 'title' => __('Background'), 'href' => admin_url('themes.php?page=custom-background') ) ); |
731 $wp_admin_bar->add_menu( array( |
629 |
732 'parent' => 'appearance', |
630 if ( current_theme_supports( 'custom-header' ) ) |
733 'id' => 'background', |
631 $wp_admin_bar->add_menu( array( 'parent' => 'appearance', 'id' => 'header', 'title' => __('Header'), 'href' => admin_url('themes.php?page=custom-header') ) ); |
734 'title' => __( 'Background' ), |
|
735 'href' => admin_url( 'themes.php?page=custom-background' ), |
|
736 'meta' => array( |
|
737 'class' => 'hide-if-customize', |
|
738 ), |
|
739 ) ); |
|
740 |
|
741 if ( current_user_can( 'customize' ) ) { |
|
742 $wp_admin_bar->add_menu( array( |
|
743 'parent' => 'appearance', |
|
744 'id' => 'customize-background', |
|
745 'title' => __( 'Background' ), |
|
746 'href' => add_query_arg( urlencode( 'autofocus[control]' ), 'background_image', $customize_url ), // urlencode() needed due to #16859 |
|
747 'meta' => array( |
|
748 'class' => 'hide-if-no-customize', |
|
749 ), |
|
750 ) ); |
|
751 } |
|
752 } |
|
753 |
|
754 if ( current_theme_supports( 'custom-header' ) ) { |
|
755 $wp_admin_bar->add_menu( array( |
|
756 'parent' => 'appearance', |
|
757 'id' => 'header', |
|
758 'title' => __( 'Header' ), |
|
759 'href' => admin_url( 'themes.php?page=custom-header' ), |
|
760 'meta' => array( |
|
761 'class' => 'hide-if-customize', |
|
762 ), |
|
763 ) ); |
|
764 |
|
765 if ( current_user_can( 'customize' ) ) { |
|
766 $wp_admin_bar->add_menu( array( |
|
767 'parent' => 'appearance', |
|
768 'id' => 'customize-header', |
|
769 'title' => __( 'Header' ), |
|
770 'href' => add_query_arg( urlencode( 'autofocus[control]' ), 'header_image', $customize_url ), // urlencode() needed due to #16859 |
|
771 'meta' => array( |
|
772 'class' => 'hide-if-no-customize', |
|
773 ), |
|
774 ) ); |
|
775 } |
|
776 } |
|
777 |
632 } |
778 } |
633 |
779 |
634 /** |
780 /** |
635 * Provide an update link if theme/plugin/core updates are available. |
781 * Provide an update link if theme/plugin/core updates are available. |
636 * |
782 * |