44 |
49 |
45 return true; |
50 return true; |
46 } |
51 } |
47 |
52 |
48 /** |
53 /** |
49 * Render the admin bar to the page based on the $wp_admin_bar->menu member var. |
54 * Renders the admin bar to the page based on the $wp_admin_bar->menu member var. |
50 * This is called very late on the footer actions so that it will render after anything else being |
55 * |
51 * added to the footer. |
56 * This is called very late on the footer actions so that it will render after |
52 * |
57 * anything else being added to the footer. |
53 * It includes the action "admin_bar_menu" which should be used to hook in and |
58 * |
54 * add new menus to the admin bar. That way you can be sure that you are adding at most optimal point, |
59 * It includes the {@see 'admin_bar_menu'} action which should be used to hook in and |
55 * right before the admin bar is rendered. This also gives you access to the $post global, among others. |
60 * add new menus to the admin bar. That way you can be sure that you are adding at most |
56 * |
61 * optimal point, right before the admin bar is rendered. This also gives you access to |
57 * @since 3.1.0 |
62 * the `$post` global, among others. |
|
63 * |
|
64 * @since 3.1.0 |
|
65 * |
|
66 * @global WP_Admin_Bar $wp_admin_bar |
58 */ |
67 */ |
59 function wp_admin_bar_render() { |
68 function wp_admin_bar_render() { |
60 global $wp_admin_bar; |
69 global $wp_admin_bar; |
61 |
70 |
62 if ( ! is_admin_bar_showing() || ! is_object( $wp_admin_bar ) ) |
71 if ( ! is_admin_bar_showing() || ! is_object( $wp_admin_bar ) ) |
63 return false; |
72 return; |
64 |
73 |
65 /** |
74 /** |
66 * Load all necessary admin bar items. |
75 * Load all necessary admin bar items. |
67 * |
76 * |
68 * This is the hook used to add, remove, or manipulate admin bar items. |
77 * This is the hook used to add, remove, or manipulate admin bar items. |
96 * @since 3.3.0 |
105 * @since 3.3.0 |
97 * |
106 * |
98 * @param WP_Admin_Bar $wp_admin_bar |
107 * @param WP_Admin_Bar $wp_admin_bar |
99 */ |
108 */ |
100 function wp_admin_bar_wp_menu( $wp_admin_bar ) { |
109 function wp_admin_bar_wp_menu( $wp_admin_bar ) { |
101 $wp_admin_bar->add_menu( array( |
110 if ( current_user_can( 'read' ) ) { |
|
111 $about_url = self_admin_url( 'about.php' ); |
|
112 } elseif ( is_multisite() ) { |
|
113 $about_url = get_dashboard_url( get_current_user_id(), 'about.php' ); |
|
114 } else { |
|
115 $about_url = false; |
|
116 } |
|
117 |
|
118 $wp_logo_menu_args = array( |
102 'id' => 'wp-logo', |
119 'id' => 'wp-logo', |
103 'title' => '<span class="ab-icon"></span><span class="screen-reader-text">' . __( 'About WordPress' ) . '</span>', |
120 'title' => '<span class="ab-icon"></span><span class="screen-reader-text">' . __( 'About WordPress' ) . '</span>', |
104 'href' => self_admin_url( 'about.php' ), |
121 'href' => $about_url, |
105 ) ); |
122 ); |
106 |
123 |
107 if ( is_user_logged_in() ) { |
124 // Set tabindex="0" to make sub menus accessible when no URL is available. |
|
125 if ( ! $about_url ) { |
|
126 $wp_logo_menu_args['meta'] = array( |
|
127 'tabindex' => 0, |
|
128 ); |
|
129 } |
|
130 |
|
131 $wp_admin_bar->add_menu( $wp_logo_menu_args ); |
|
132 |
|
133 if ( $about_url ) { |
108 // Add "About WordPress" link |
134 // Add "About WordPress" link |
109 $wp_admin_bar->add_menu( array( |
135 $wp_admin_bar->add_menu( array( |
110 'parent' => 'wp-logo', |
136 'parent' => 'wp-logo', |
111 'id' => 'about', |
137 'id' => 'about', |
112 'title' => __('About WordPress'), |
138 'title' => __('About WordPress'), |
113 'href' => self_admin_url( 'about.php' ), |
139 'href' => $about_url, |
114 ) ); |
140 ) ); |
115 } |
141 } |
116 |
142 |
117 // Add WordPress.org link |
143 // Add WordPress.org link |
118 $wp_admin_bar->add_menu( array( |
144 $wp_admin_bar->add_menu( array( |
172 * @param WP_Admin_Bar $wp_admin_bar |
198 * @param WP_Admin_Bar $wp_admin_bar |
173 */ |
199 */ |
174 function wp_admin_bar_my_account_item( $wp_admin_bar ) { |
200 function wp_admin_bar_my_account_item( $wp_admin_bar ) { |
175 $user_id = get_current_user_id(); |
201 $user_id = get_current_user_id(); |
176 $current_user = wp_get_current_user(); |
202 $current_user = wp_get_current_user(); |
177 $profile_url = get_edit_profile_url( $user_id ); |
|
178 |
203 |
179 if ( ! $user_id ) |
204 if ( ! $user_id ) |
180 return; |
205 return; |
181 |
206 |
|
207 if ( current_user_can( 'read' ) ) { |
|
208 $profile_url = get_edit_profile_url( $user_id ); |
|
209 } elseif ( is_multisite() ) { |
|
210 $profile_url = get_dashboard_url( $user_id, 'profile.php' ); |
|
211 } else { |
|
212 $profile_url = false; |
|
213 } |
|
214 |
182 $avatar = get_avatar( $user_id, 26 ); |
215 $avatar = get_avatar( $user_id, 26 ); |
183 $howdy = sprintf( __('Howdy, %1$s'), $current_user->display_name ); |
216 /* translators: %s: current user's display name */ |
|
217 $howdy = sprintf( __( 'Howdy, %s' ), '<span class="display-name">' . $current_user->display_name . '</span>' ); |
184 $class = empty( $avatar ) ? '' : 'with-avatar'; |
218 $class = empty( $avatar ) ? '' : 'with-avatar'; |
185 |
219 |
186 $wp_admin_bar->add_menu( array( |
220 $wp_admin_bar->add_menu( array( |
187 'id' => 'my-account', |
221 'id' => 'my-account', |
188 'parent' => 'top-secondary', |
222 'parent' => 'top-secondary', |
202 * @param WP_Admin_Bar $wp_admin_bar |
236 * @param WP_Admin_Bar $wp_admin_bar |
203 */ |
237 */ |
204 function wp_admin_bar_my_account_menu( $wp_admin_bar ) { |
238 function wp_admin_bar_my_account_menu( $wp_admin_bar ) { |
205 $user_id = get_current_user_id(); |
239 $user_id = get_current_user_id(); |
206 $current_user = wp_get_current_user(); |
240 $current_user = wp_get_current_user(); |
207 $profile_url = get_edit_profile_url( $user_id ); |
|
208 |
241 |
209 if ( ! $user_id ) |
242 if ( ! $user_id ) |
210 return; |
243 return; |
|
244 |
|
245 if ( current_user_can( 'read' ) ) { |
|
246 $profile_url = get_edit_profile_url( $user_id ); |
|
247 } elseif ( is_multisite() ) { |
|
248 $profile_url = get_dashboard_url( $user_id, 'profile.php' ); |
|
249 } else { |
|
250 $profile_url = false; |
|
251 } |
211 |
252 |
212 $wp_admin_bar->add_group( array( |
253 $wp_admin_bar->add_group( array( |
213 'parent' => 'my-account', |
254 'parent' => 'my-account', |
214 'id' => 'user-actions', |
255 'id' => 'user-actions', |
215 ) ); |
256 ) ); |
227 'href' => $profile_url, |
268 'href' => $profile_url, |
228 'meta' => array( |
269 'meta' => array( |
229 'tabindex' => -1, |
270 'tabindex' => -1, |
230 ), |
271 ), |
231 ) ); |
272 ) ); |
232 $wp_admin_bar->add_menu( array( |
273 |
233 'parent' => 'user-actions', |
274 if ( false !== $profile_url ) { |
234 'id' => 'edit-profile', |
275 $wp_admin_bar->add_menu( array( |
235 'title' => __( 'Edit My Profile' ), |
276 'parent' => 'user-actions', |
236 'href' => $profile_url, |
277 'id' => 'edit-profile', |
237 ) ); |
278 'title' => __( 'Edit My Profile' ), |
|
279 'href' => $profile_url, |
|
280 ) ); |
|
281 } |
|
282 |
238 $wp_admin_bar->add_menu( array( |
283 $wp_admin_bar->add_menu( array( |
239 'parent' => 'user-actions', |
284 'parent' => 'user-actions', |
240 'id' => 'logout', |
285 'id' => 'logout', |
241 'title' => __( 'Log Out' ), |
286 'title' => __( 'Log Out' ), |
242 'href' => wp_logout_url(), |
287 'href' => wp_logout_url(), |
254 // Don't show for logged out users. |
299 // Don't show for logged out users. |
255 if ( ! is_user_logged_in() ) |
300 if ( ! is_user_logged_in() ) |
256 return; |
301 return; |
257 |
302 |
258 // Show only when the user is a member of this site, or they're a super admin. |
303 // Show only when the user is a member of this site, or they're a super admin. |
259 if ( ! is_user_member_of_blog() && ! is_super_admin() ) |
304 if ( ! is_user_member_of_blog() && ! current_user_can( 'manage_network' ) ) { |
260 return; |
305 return; |
|
306 } |
261 |
307 |
262 $blogname = get_bloginfo('name'); |
308 $blogname = get_bloginfo('name'); |
263 |
309 |
264 if ( ! $blogname ) { |
310 if ( ! $blogname ) { |
265 $blogname = preg_replace( '#^(https?://)?(www.)?#', '', get_home_url() ); |
311 $blogname = preg_replace( '#^(https?://)?(www.)?#', '', get_home_url() ); |
266 } |
312 } |
267 |
313 |
268 if ( is_network_admin() ) { |
314 if ( is_network_admin() ) { |
269 $blogname = sprintf( __('Network Admin: %s'), esc_html( get_current_site()->site_name ) ); |
315 /* translators: %s: site name */ |
|
316 $blogname = sprintf( __( 'Network Admin: %s' ), esc_html( get_network()->site_name ) ); |
270 } elseif ( is_user_admin() ) { |
317 } elseif ( is_user_admin() ) { |
271 $blogname = sprintf( __('Global Dashboard: %s'), esc_html( get_current_site()->site_name ) ); |
318 /* translators: %s: site name */ |
|
319 $blogname = sprintf( __( 'User Dashboard: %s' ), esc_html( get_network()->site_name ) ); |
272 } |
320 } |
273 |
321 |
274 $title = wp_html_excerpt( $blogname, 40, '…' ); |
322 $title = wp_html_excerpt( $blogname, 40, '…' ); |
275 |
323 |
276 $wp_admin_bar->add_menu( array( |
324 $wp_admin_bar->add_menu( array( |
277 'id' => 'site-name', |
325 'id' => 'site-name', |
278 'title' => $title, |
326 'title' => $title, |
279 'href' => is_admin() ? home_url( '/' ) : admin_url(), |
327 'href' => ( is_admin() || ! current_user_can( 'read' ) ) ? home_url( '/' ) : admin_url(), |
280 ) ); |
328 ) ); |
281 |
329 |
282 // Create submenu items. |
330 // Create submenu items. |
283 |
331 |
284 if ( is_admin() ) { |
332 if ( is_admin() ) { |
312 wp_admin_bar_appearance_menu( $wp_admin_bar ); |
360 wp_admin_bar_appearance_menu( $wp_admin_bar ); |
313 } |
361 } |
314 } |
362 } |
315 |
363 |
316 /** |
364 /** |
|
365 * Adds the "Customize" link to the Toolbar. |
|
366 * |
|
367 * @since 4.3.0 |
|
368 * |
|
369 * @param WP_Admin_Bar $wp_admin_bar WP_Admin_Bar instance. |
|
370 * @global WP_Customize_Manager $wp_customize |
|
371 */ |
|
372 function wp_admin_bar_customize_menu( $wp_admin_bar ) { |
|
373 global $wp_customize; |
|
374 |
|
375 // Don't show for users who can't access the customizer or when in the admin. |
|
376 if ( ! current_user_can( 'customize' ) || is_admin() ) { |
|
377 return; |
|
378 } |
|
379 |
|
380 // Don't show if the user cannot edit a given customize_changeset post currently being previewed. |
|
381 if ( is_customize_preview() && $wp_customize->changeset_post_id() && ! current_user_can( get_post_type_object( 'customize_changeset' )->cap->edit_post, $wp_customize->changeset_post_id() ) ) { |
|
382 return; |
|
383 } |
|
384 |
|
385 $current_url = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; |
|
386 if ( is_customize_preview() && $wp_customize->changeset_uuid() ) { |
|
387 $current_url = remove_query_arg( 'customize_changeset_uuid', $current_url ); |
|
388 } |
|
389 |
|
390 $customize_url = add_query_arg( 'url', urlencode( $current_url ), wp_customize_url() ); |
|
391 if ( is_customize_preview() ) { |
|
392 $customize_url = add_query_arg( array( 'changeset_uuid' => $wp_customize->changeset_uuid() ), $customize_url ); |
|
393 } |
|
394 |
|
395 $wp_admin_bar->add_menu( array( |
|
396 'id' => 'customize', |
|
397 'title' => __( 'Customize' ), |
|
398 'href' => $customize_url, |
|
399 'meta' => array( |
|
400 'class' => 'hide-if-no-customize', |
|
401 ), |
|
402 ) ); |
|
403 add_action( 'wp_before_admin_bar_render', 'wp_customize_support_script' ); |
|
404 } |
|
405 |
|
406 /** |
317 * Add the "My Sites/[Site Name]" menu and all submenus. |
407 * Add the "My Sites/[Site Name]" menu and all submenus. |
318 * |
408 * |
319 * @since 3.1.0 |
409 * @since 3.1.0 |
320 * |
410 * |
321 * @param WP_Admin_Bar $wp_admin_bar |
411 * @param WP_Admin_Bar $wp_admin_bar |
358 'parent' => 'network-admin', |
449 'parent' => 'network-admin', |
359 'id' => 'network-admin-d', |
450 'id' => 'network-admin-d', |
360 'title' => __( 'Dashboard' ), |
451 'title' => __( 'Dashboard' ), |
361 'href' => network_admin_url(), |
452 'href' => network_admin_url(), |
362 ) ); |
453 ) ); |
363 $wp_admin_bar->add_menu( array( |
454 |
364 'parent' => 'network-admin', |
455 if ( current_user_can( 'manage_sites' ) ) { |
365 'id' => 'network-admin-s', |
456 $wp_admin_bar->add_menu( array( |
366 'title' => __( 'Sites' ), |
457 'parent' => 'network-admin', |
367 'href' => network_admin_url( 'sites.php' ), |
458 'id' => 'network-admin-s', |
368 ) ); |
459 'title' => __( 'Sites' ), |
369 $wp_admin_bar->add_menu( array( |
460 'href' => network_admin_url( 'sites.php' ), |
370 'parent' => 'network-admin', |
461 ) ); |
371 'id' => 'network-admin-u', |
462 } |
372 'title' => __( 'Users' ), |
463 |
373 'href' => network_admin_url( 'users.php' ), |
464 if ( current_user_can( 'manage_network_users' ) ) { |
374 ) ); |
465 $wp_admin_bar->add_menu( array( |
375 $wp_admin_bar->add_menu( array( |
466 'parent' => 'network-admin', |
376 'parent' => 'network-admin', |
467 'id' => 'network-admin-u', |
377 'id' => 'network-admin-t', |
468 'title' => __( 'Users' ), |
378 'title' => __( 'Themes' ), |
469 'href' => network_admin_url( 'users.php' ), |
379 'href' => network_admin_url( 'themes.php' ), |
470 ) ); |
380 ) ); |
471 } |
381 $wp_admin_bar->add_menu( array( |
472 |
382 'parent' => 'network-admin', |
473 if ( current_user_can( 'manage_network_themes' ) ) { |
383 'id' => 'network-admin-p', |
474 $wp_admin_bar->add_menu( array( |
384 'title' => __( 'Plugins' ), |
475 'parent' => 'network-admin', |
385 'href' => network_admin_url( 'plugins.php' ), |
476 'id' => 'network-admin-t', |
386 ) ); |
477 'title' => __( 'Themes' ), |
|
478 'href' => network_admin_url( 'themes.php' ), |
|
479 ) ); |
|
480 } |
|
481 |
|
482 if ( current_user_can( 'manage_network_plugins' ) ) { |
|
483 $wp_admin_bar->add_menu( array( |
|
484 'parent' => 'network-admin', |
|
485 'id' => 'network-admin-p', |
|
486 'title' => __( 'Plugins' ), |
|
487 'href' => network_admin_url( 'plugins.php' ), |
|
488 ) ); |
|
489 } |
|
490 |
|
491 if ( current_user_can( 'manage_network_options' ) ) { |
|
492 $wp_admin_bar->add_menu( array( |
|
493 'parent' => 'network-admin', |
|
494 'id' => 'network-admin-o', |
|
495 'title' => __( 'Settings' ), |
|
496 'href' => network_admin_url( 'settings.php' ), |
|
497 ) ); |
|
498 } |
387 } |
499 } |
388 |
500 |
389 // Add site links |
501 // Add site links |
390 $wp_admin_bar->add_group( array( |
502 $wp_admin_bar->add_group( array( |
391 'parent' => 'my-sites', |
503 'parent' => 'my-sites', |
392 'id' => 'my-sites-list', |
504 'id' => 'my-sites-list', |
393 'meta' => array( |
505 'meta' => array( |
394 'class' => is_super_admin() ? 'ab-sub-secondary' : '', |
506 'class' => current_user_can( 'manage_network' ) ? 'ab-sub-secondary' : '', |
395 ), |
507 ), |
396 ) ); |
508 ) ); |
397 |
509 |
398 foreach ( (array) $wp_admin_bar->user->blogs as $blog ) { |
510 foreach ( (array) $wp_admin_bar->user->blogs as $blog ) { |
399 switch_to_blog( $blog->userblog_id ); |
511 switch_to_blog( $blog->userblog_id ); |
406 $blogname = preg_replace( '#^(https?://)?(www.)?#', '', get_home_url() ); |
518 $blogname = preg_replace( '#^(https?://)?(www.)?#', '', get_home_url() ); |
407 } |
519 } |
408 |
520 |
409 $menu_id = 'blog-' . $blog->userblog_id; |
521 $menu_id = 'blog-' . $blog->userblog_id; |
410 |
522 |
411 $wp_admin_bar->add_menu( array( |
523 if ( current_user_can( 'read' ) ) { |
412 'parent' => 'my-sites-list', |
524 $wp_admin_bar->add_menu( array( |
413 'id' => $menu_id, |
525 'parent' => 'my-sites-list', |
414 'title' => $blavatar . $blogname, |
526 'id' => $menu_id, |
415 'href' => admin_url(), |
527 'title' => $blavatar . $blogname, |
416 ) ); |
528 'href' => admin_url(), |
417 |
529 ) ); |
418 $wp_admin_bar->add_menu( array( |
530 |
419 'parent' => $menu_id, |
531 $wp_admin_bar->add_menu( array( |
420 'id' => $menu_id . '-d', |
532 'parent' => $menu_id, |
421 'title' => __( 'Dashboard' ), |
533 'id' => $menu_id . '-d', |
422 'href' => admin_url(), |
534 'title' => __( 'Dashboard' ), |
423 ) ); |
535 'href' => admin_url(), |
|
536 ) ); |
|
537 } else { |
|
538 $wp_admin_bar->add_menu( array( |
|
539 'parent' => 'my-sites-list', |
|
540 'id' => $menu_id, |
|
541 'title' => $blavatar . $blogname, |
|
542 'href' => home_url(), |
|
543 ) ); |
|
544 } |
424 |
545 |
425 if ( current_user_can( get_post_type_object( 'post' )->cap->create_posts ) ) { |
546 if ( current_user_can( get_post_type_object( 'post' )->cap->create_posts ) ) { |
426 $wp_admin_bar->add_menu( array( |
547 $wp_admin_bar->add_menu( array( |
427 'parent' => $menu_id, |
548 'parent' => $menu_id, |
428 'id' => $menu_id . '-n', |
549 'id' => $menu_id . '-n', |
494 && ( $post_type_object = get_post_type_object( $post->post_type ) ) |
618 && ( $post_type_object = get_post_type_object( $post->post_type ) ) |
495 && current_user_can( 'read_post', $post->ID ) |
619 && current_user_can( 'read_post', $post->ID ) |
496 && ( $post_type_object->public ) |
620 && ( $post_type_object->public ) |
497 && ( $post_type_object->show_in_admin_bar ) ) |
621 && ( $post_type_object->show_in_admin_bar ) ) |
498 { |
622 { |
499 if( 'draft' == $post->post_status ) { |
623 if ( 'draft' == $post->post_status ) { |
500 $preview_link = set_url_scheme( get_permalink( $post->ID ) ); |
624 $preview_link = get_preview_post_link( $post ); |
501 /** This filter is documented in wp-admin/includes/meta-boxes.php */ |
|
502 $preview_link = apply_filters( 'preview_post_link', add_query_arg( 'preview', 'true', $preview_link ), $post ); |
|
503 $wp_admin_bar->add_menu( array( |
625 $wp_admin_bar->add_menu( array( |
504 'id' => 'preview', |
626 'id' => 'preview', |
505 'title' => $post_type_object->labels->view_item, |
627 'title' => $post_type_object->labels->view_item, |
506 'href' => esc_url( $preview_link ), |
628 'href' => esc_url( $preview_link ), |
507 'meta' => array( 'target' => 'wp-preview-' . $post->ID ), |
629 'meta' => array( 'target' => 'wp-preview-' . $post->ID ), |
511 'id' => 'view', |
633 'id' => 'view', |
512 'title' => $post_type_object->labels->view_item, |
634 'title' => $post_type_object->labels->view_item, |
513 'href' => get_permalink( $post->ID ) |
635 'href' => get_permalink( $post->ID ) |
514 ) ); |
636 ) ); |
515 } |
637 } |
516 } elseif ( 'edit-tags' == $current_screen->base |
638 } elseif ( 'edit' == $current_screen->base |
517 && isset( $tag ) && is_object( $tag ) |
639 && ( $post_type_object = get_post_type_object( $current_screen->post_type ) ) |
|
640 && ( $post_type_object->public ) |
|
641 && ( $post_type_object->show_in_admin_bar ) |
|
642 && ( get_post_type_archive_link( $post_type_object->name ) ) |
|
643 && ! ( 'post' === $post_type_object->name && 'posts' === get_option( 'show_on_front' ) ) ) |
|
644 { |
|
645 $wp_admin_bar->add_node( array( |
|
646 'id' => 'archive', |
|
647 'title' => $post_type_object->labels->view_items, |
|
648 'href' => get_post_type_archive_link( $current_screen->post_type ) |
|
649 ) ); |
|
650 } elseif ( 'term' == $current_screen->base |
|
651 && isset( $tag ) && is_object( $tag ) && ! is_wp_error( $tag ) |
518 && ( $tax = get_taxonomy( $tag->taxonomy ) ) |
652 && ( $tax = get_taxonomy( $tag->taxonomy ) ) |
519 && $tax->public ) |
653 && $tax->public ) |
520 { |
654 { |
521 $wp_admin_bar->add_menu( array( |
655 $wp_admin_bar->add_menu( array( |
522 'id' => 'view', |
656 'id' => 'view', |
523 'title' => $tax->labels->view_item, |
657 'title' => $tax->labels->view_item, |
524 'href' => get_term_link( $tag ) |
658 'href' => get_term_link( $tag ) |
525 ) ); |
659 ) ); |
|
660 } elseif ( 'user-edit' == $current_screen->base |
|
661 && isset( $user_id ) |
|
662 && ( $user_object = get_userdata( $user_id ) ) |
|
663 && $user_object->exists() |
|
664 && $view_link = get_author_posts_url( $user_object->ID ) ) |
|
665 { |
|
666 $wp_admin_bar->add_menu( array( |
|
667 'id' => 'view', |
|
668 'title' => __( 'View User' ), |
|
669 'href' => $view_link, |
|
670 ) ); |
526 } |
671 } |
527 } else { |
672 } else { |
528 $current_object = $wp_the_query->get_queried_object(); |
673 $current_object = $wp_the_query->get_queried_object(); |
529 |
674 |
530 if ( empty( $current_object ) ) |
675 if ( empty( $current_object ) ) |
531 return; |
676 return; |
532 |
677 |
533 if ( ! empty( $current_object->post_type ) |
678 if ( ! empty( $current_object->post_type ) |
534 && ( $post_type_object = get_post_type_object( $current_object->post_type ) ) |
679 && ( $post_type_object = get_post_type_object( $current_object->post_type ) ) |
535 && current_user_can( 'edit_post', $current_object->ID ) |
680 && current_user_can( 'edit_post', $current_object->ID ) |
536 && $post_type_object->show_ui && $post_type_object->show_in_admin_bar |
681 && $post_type_object->show_in_admin_bar |
537 && $edit_post_link = get_edit_post_link( $current_object->ID ) ) |
682 && $edit_post_link = get_edit_post_link( $current_object->ID ) ) |
538 { |
683 { |
539 $wp_admin_bar->add_menu( array( |
684 $wp_admin_bar->add_menu( array( |
540 'id' => 'edit', |
685 'id' => 'edit', |
541 'title' => $post_type_object->labels->edit_item, |
686 'title' => $post_type_object->labels->edit_item, |
542 'href' => $edit_post_link |
687 'href' => $edit_post_link |
543 ) ); |
688 ) ); |
544 } elseif ( ! empty( $current_object->taxonomy ) |
689 } elseif ( ! empty( $current_object->taxonomy ) |
545 && ( $tax = get_taxonomy( $current_object->taxonomy ) ) |
690 && ( $tax = get_taxonomy( $current_object->taxonomy ) ) |
546 && current_user_can( $tax->cap->edit_terms ) |
691 && current_user_can( 'edit_term', $current_object->term_id ) |
547 && $tax->show_ui |
|
548 && $edit_term_link = get_edit_term_link( $current_object->term_id, $current_object->taxonomy ) ) |
692 && $edit_term_link = get_edit_term_link( $current_object->term_id, $current_object->taxonomy ) ) |
549 { |
693 { |
550 $wp_admin_bar->add_menu( array( |
694 $wp_admin_bar->add_menu( array( |
551 'id' => 'edit', |
695 'id' => 'edit', |
552 'title' => $tax->labels->edit_item, |
696 'title' => $tax->labels->edit_item, |
553 'href' => $edit_term_link |
697 'href' => $edit_term_link |
|
698 ) ); |
|
699 } elseif ( is_a( $current_object, 'WP_User' ) |
|
700 && current_user_can( 'edit_user', $current_object->ID ) |
|
701 && $edit_user_link = get_edit_user_link( $current_object->ID ) ) |
|
702 { |
|
703 $wp_admin_bar->add_menu( array( |
|
704 'id' => 'edit', |
|
705 'title' => __( 'Edit User' ), |
|
706 'href' => $edit_user_link, |
554 ) ); |
707 ) ); |
555 } |
708 } |
556 } |
709 } |
557 } |
710 } |
558 |
711 |
631 if ( !current_user_can('edit_posts') ) |
785 if ( !current_user_can('edit_posts') ) |
632 return; |
786 return; |
633 |
787 |
634 $awaiting_mod = wp_count_comments(); |
788 $awaiting_mod = wp_count_comments(); |
635 $awaiting_mod = $awaiting_mod->moderated; |
789 $awaiting_mod = $awaiting_mod->moderated; |
636 $awaiting_title = esc_attr( sprintf( _n( '%s comment awaiting moderation', '%s comments awaiting moderation', $awaiting_mod ), number_format_i18n( $awaiting_mod ) ) ); |
790 $awaiting_text = sprintf( _n( '%s comment awaiting moderation', '%s comments awaiting moderation', $awaiting_mod ), number_format_i18n( $awaiting_mod ) ); |
637 |
791 |
638 $icon = '<span class="ab-icon"></span>'; |
792 $icon = '<span class="ab-icon"></span>'; |
639 $title = '<span id="ab-awaiting-mod" class="ab-label awaiting-mod pending-count count-' . $awaiting_mod . '">' . number_format_i18n( $awaiting_mod ) . '</span>'; |
793 $title = '<span class="ab-label awaiting-mod pending-count count-' . $awaiting_mod . '" aria-hidden="true">' . number_format_i18n( $awaiting_mod ) . '</span>'; |
|
794 $title .= '<span class="screen-reader-text">' . $awaiting_text . '</span>'; |
640 |
795 |
641 $wp_admin_bar->add_menu( array( |
796 $wp_admin_bar->add_menu( array( |
642 'id' => 'comments', |
797 'id' => 'comments', |
643 'title' => $icon . $title, |
798 'title' => $icon . $title, |
644 'href' => admin_url('edit-comments.php'), |
799 'href' => admin_url('edit-comments.php'), |
645 'meta' => array( 'title' => $awaiting_title ), |
|
646 ) ); |
800 ) ); |
647 } |
801 } |
648 |
802 |
649 /** |
803 /** |
650 * Add appearance submenu items to the "Site Name" menu. |
804 * Add appearance submenu items to the "Site Name" menu. |
653 * |
807 * |
654 * @param WP_Admin_Bar $wp_admin_bar |
808 * @param WP_Admin_Bar $wp_admin_bar |
655 */ |
809 */ |
656 function wp_admin_bar_appearance_menu( $wp_admin_bar ) { |
810 function wp_admin_bar_appearance_menu( $wp_admin_bar ) { |
657 $wp_admin_bar->add_group( array( 'parent' => 'site-name', 'id' => 'appearance' ) ); |
811 $wp_admin_bar->add_group( array( 'parent' => 'site-name', 'id' => 'appearance' ) ); |
658 |
|
659 $current_url = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; |
|
660 $customize_url = add_query_arg( 'url', urlencode( $current_url ), wp_customize_url() ); |
|
661 |
812 |
662 if ( current_user_can( 'switch_themes' ) ) { |
813 if ( current_user_can( 'switch_themes' ) ) { |
663 $wp_admin_bar->add_menu( array( |
814 $wp_admin_bar->add_menu( array( |
664 'parent' => 'appearance', |
815 'parent' => 'appearance', |
665 'id' => 'themes', |
816 'id' => 'themes', |
666 'title' => __( 'Themes' ), |
817 'title' => __( 'Themes' ), |
667 'href' => admin_url( 'themes.php' ), |
818 'href' => admin_url( 'themes.php' ), |
668 'meta' => array( |
819 ) ); |
669 'class' => 'hide-if-customize', |
|
670 ), |
|
671 ) ); |
|
672 |
|
673 if ( current_user_can( 'customize' ) ) { |
|
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 } |
820 } |
698 |
821 |
699 if ( ! current_user_can( 'edit_theme_options' ) ) { |
822 if ( ! current_user_can( 'edit_theme_options' ) ) { |
700 return; |
823 return; |
701 } |
824 } |
704 $wp_admin_bar->add_menu( array( |
827 $wp_admin_bar->add_menu( array( |
705 'parent' => 'appearance', |
828 'parent' => 'appearance', |
706 'id' => 'widgets', |
829 'id' => 'widgets', |
707 'title' => __( 'Widgets' ), |
830 'title' => __( 'Widgets' ), |
708 'href' => admin_url( 'widgets.php' ), |
831 'href' => admin_url( 'widgets.php' ), |
709 'meta' => array( |
832 ) ); |
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 } |
833 } |
726 |
834 |
727 if ( current_theme_supports( 'menus' ) || current_theme_supports( 'widgets' ) ) |
835 if ( current_theme_supports( 'menus' ) || current_theme_supports( 'widgets' ) ) |
728 $wp_admin_bar->add_menu( array( 'parent' => 'appearance', 'id' => 'menus', 'title' => __('Menus'), 'href' => admin_url('nav-menus.php') ) ); |
836 $wp_admin_bar->add_menu( array( 'parent' => 'appearance', 'id' => 'menus', 'title' => __('Menus'), 'href' => admin_url('nav-menus.php') ) ); |
729 |
837 |
735 'href' => admin_url( 'themes.php?page=custom-background' ), |
843 'href' => admin_url( 'themes.php?page=custom-background' ), |
736 'meta' => array( |
844 'meta' => array( |
737 'class' => 'hide-if-customize', |
845 'class' => 'hide-if-customize', |
738 ), |
846 ), |
739 ) ); |
847 ) ); |
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 } |
848 } |
753 |
849 |
754 if ( current_theme_supports( 'custom-header' ) ) { |
850 if ( current_theme_supports( 'custom-header' ) ) { |
755 $wp_admin_bar->add_menu( array( |
851 $wp_admin_bar->add_menu( array( |
756 'parent' => 'appearance', |
852 'parent' => 'appearance', |
901 /** |
987 /** |
902 * Determine whether the admin bar should be showing. |
988 * Determine whether the admin bar should be showing. |
903 * |
989 * |
904 * @since 3.1.0 |
990 * @since 3.1.0 |
905 * |
991 * |
|
992 * @global bool $show_admin_bar |
|
993 * @global string $pagenow |
|
994 * |
906 * @return bool Whether the admin bar should be showing. |
995 * @return bool Whether the admin bar should be showing. |
907 */ |
996 */ |
908 function is_admin_bar_showing() { |
997 function is_admin_bar_showing() { |
909 global $show_admin_bar, $pagenow; |
998 global $show_admin_bar, $pagenow; |
910 |
999 |
911 // For all these types of requests, we never want an admin bar. |
1000 // For all these types of requests, we never want an admin bar. |
912 if ( defined('XMLRPC_REQUEST') || defined('DOING_AJAX') || defined('IFRAME_REQUEST') ) |
1001 if ( defined('XMLRPC_REQUEST') || defined('DOING_AJAX') || defined('IFRAME_REQUEST') ) |
913 return false; |
1002 return false; |
|
1003 |
|
1004 if ( is_embed() ) { |
|
1005 return false; |
|
1006 } |
914 |
1007 |
915 // Integrated into the admin. |
1008 // Integrated into the admin. |
916 if ( is_admin() ) |
1009 if ( is_admin() ) |
917 return true; |
1010 return true; |
918 |
1011 |