82 if ( ! is_admin_bar_showing() || ! is_object( $wp_admin_bar ) ) { |
82 if ( ! is_admin_bar_showing() || ! is_object( $wp_admin_bar ) ) { |
83 return; |
83 return; |
84 } |
84 } |
85 |
85 |
86 /** |
86 /** |
87 * Load all necessary admin bar items. |
87 * Loads all necessary admin bar items. |
88 * |
88 * |
89 * This is the hook used to add, remove, or manipulate admin bar items. |
89 * This is the hook used to add, remove, or manipulate admin bar items. |
90 * |
90 * |
91 * @since 3.1.0 |
91 * @since 3.1.0 |
92 * |
92 * |
93 * @param WP_Admin_Bar $wp_admin_bar WP_Admin_Bar instance, passed by reference |
93 * @param WP_Admin_Bar $wp_admin_bar The WP_Admin_Bar instance, passed by reference. |
94 */ |
94 */ |
95 do_action_ref_array( 'admin_bar_menu', array( &$wp_admin_bar ) ); |
95 do_action_ref_array( 'admin_bar_menu', array( &$wp_admin_bar ) ); |
96 |
96 |
97 /** |
97 /** |
98 * Fires before the admin bar is rendered. |
98 * Fires before the admin bar is rendered. |
112 |
112 |
113 $rendered = true; |
113 $rendered = true; |
114 } |
114 } |
115 |
115 |
116 /** |
116 /** |
117 * Add the WordPress logo menu. |
117 * Adds the WordPress logo menu. |
118 * |
118 * |
119 * @since 3.3.0 |
119 * @since 3.3.0 |
120 * |
120 * |
121 * @param WP_Admin_Bar $wp_admin_bar |
121 * @param WP_Admin_Bar $wp_admin_bar The WP_Admin_Bar instance. |
122 */ |
122 */ |
123 function wp_admin_bar_wp_menu( $wp_admin_bar ) { |
123 function wp_admin_bar_wp_menu( $wp_admin_bar ) { |
124 if ( current_user_can( 'read' ) ) { |
124 if ( current_user_can( 'read' ) ) { |
125 $about_url = self_admin_url( 'about.php' ); |
125 $about_url = self_admin_url( 'about.php' ); |
126 } elseif ( is_multisite() ) { |
126 } elseif ( is_multisite() ) { |
215 ); |
215 ); |
216 } |
216 } |
217 } |
217 } |
218 |
218 |
219 /** |
219 /** |
220 * Add the "My Account" item. |
220 * Adds the "My Account" item. |
221 * |
221 * |
222 * @since 3.3.0 |
222 * @since 3.3.0 |
223 * |
223 * |
224 * @param WP_Admin_Bar $wp_admin_bar |
224 * @param WP_Admin_Bar $wp_admin_bar The WP_Admin_Bar instance. |
225 */ |
225 */ |
226 function wp_admin_bar_my_account_item( $wp_admin_bar ) { |
226 function wp_admin_bar_my_account_item( $wp_admin_bar ) { |
227 $user_id = get_current_user_id(); |
227 $user_id = get_current_user_id(); |
228 $current_user = wp_get_current_user(); |
228 $current_user = wp_get_current_user(); |
229 |
229 |
256 ) |
256 ) |
257 ); |
257 ); |
258 } |
258 } |
259 |
259 |
260 /** |
260 /** |
261 * Add the "My Account" submenu items. |
261 * Adds the "My Account" submenu items. |
262 * |
262 * |
263 * @since 3.1.0 |
263 * @since 3.1.0 |
264 * |
264 * |
265 * @param WP_Admin_Bar $wp_admin_bar |
265 * @param WP_Admin_Bar $wp_admin_bar The WP_Admin_Bar instance. |
266 */ |
266 */ |
267 function wp_admin_bar_my_account_menu( $wp_admin_bar ) { |
267 function wp_admin_bar_my_account_menu( $wp_admin_bar ) { |
268 $user_id = get_current_user_id(); |
268 $user_id = get_current_user_id(); |
269 $current_user = wp_get_current_user(); |
269 $current_user = wp_get_current_user(); |
270 |
270 |
326 ) |
326 ) |
327 ); |
327 ); |
328 } |
328 } |
329 |
329 |
330 /** |
330 /** |
331 * Add the "Site Name" menu. |
331 * Adds the "Site Name" menu. |
332 * |
332 * |
333 * @since 3.3.0 |
333 * @since 3.3.0 |
334 * |
334 * |
335 * @param WP_Admin_Bar $wp_admin_bar |
335 * @param WP_Admin_Bar $wp_admin_bar The WP_Admin_Bar instance. |
336 */ |
336 */ |
337 function wp_admin_bar_site_menu( $wp_admin_bar ) { |
337 function wp_admin_bar_site_menu( $wp_admin_bar ) { |
338 // Don't show for logged out users. |
338 // Don't show for logged out users. |
339 if ( ! is_user_logged_in() ) { |
339 if ( ! is_user_logged_in() ) { |
340 return; |
340 return; |
407 wp_admin_bar_appearance_menu( $wp_admin_bar ); |
407 wp_admin_bar_appearance_menu( $wp_admin_bar ); |
408 } |
408 } |
409 } |
409 } |
410 |
410 |
411 /** |
411 /** |
|
412 * Adds the "Edit site" link to the Toolbar. |
|
413 * |
|
414 * @since 5.9.0 |
|
415 * |
|
416 * @param WP_Admin_Bar $wp_admin_bar The WP_Admin_Bar instance. |
|
417 */ |
|
418 function wp_admin_bar_edit_site_menu( $wp_admin_bar ) { |
|
419 // Don't show if a block theme is not activated. |
|
420 if ( ! wp_is_block_theme() ) { |
|
421 return; |
|
422 } |
|
423 |
|
424 // Don't show for users who can't edit theme options or when in the admin. |
|
425 if ( ! current_user_can( 'edit_theme_options' ) || is_admin() ) { |
|
426 return; |
|
427 } |
|
428 |
|
429 $wp_admin_bar->add_node( |
|
430 array( |
|
431 'id' => 'site-editor', |
|
432 'title' => __( 'Edit site' ), |
|
433 'href' => admin_url( 'site-editor.php' ), |
|
434 ) |
|
435 ); |
|
436 } |
|
437 |
|
438 /** |
412 * Adds the "Customize" link to the Toolbar. |
439 * Adds the "Customize" link to the Toolbar. |
413 * |
440 * |
414 * @since 4.3.0 |
441 * @since 4.3.0 |
415 * |
442 * |
416 * @param WP_Admin_Bar $wp_admin_bar WP_Admin_Bar instance. |
443 * @param WP_Admin_Bar $wp_admin_bar The WP_Admin_Bar instance. |
417 * @global WP_Customize_Manager $wp_customize |
444 * @global WP_Customize_Manager $wp_customize |
418 */ |
445 */ |
419 function wp_admin_bar_customize_menu( $wp_admin_bar ) { |
446 function wp_admin_bar_customize_menu( $wp_admin_bar ) { |
420 global $wp_customize; |
447 global $wp_customize; |
|
448 |
|
449 // Don't show if a block theme is activated and no plugins use the customizer. |
|
450 if ( wp_is_block_theme() && ! has_action( 'customize_register' ) ) { |
|
451 return; |
|
452 } |
421 |
453 |
422 // Don't show for users who can't access the customizer or when in the admin. |
454 // Don't show for users who can't access the customizer or when in the admin. |
423 if ( ! current_user_can( 'customize' ) || is_admin() ) { |
455 if ( ! current_user_can( 'customize' ) || is_admin() ) { |
424 return; |
456 return; |
425 } |
457 } |
453 ); |
485 ); |
454 add_action( 'wp_before_admin_bar_render', 'wp_customize_support_script' ); |
486 add_action( 'wp_before_admin_bar_render', 'wp_customize_support_script' ); |
455 } |
487 } |
456 |
488 |
457 /** |
489 /** |
458 * Add the "My Sites/[Site Name]" menu and all submenus. |
490 * Adds the "My Sites/[Site Name]" menu and all submenus. |
459 * |
491 * |
460 * @since 3.1.0 |
492 * @since 3.1.0 |
461 * |
493 * |
462 * @param WP_Admin_Bar $wp_admin_bar |
494 * @param WP_Admin_Bar $wp_admin_bar The WP_Admin_Bar instance. |
463 */ |
495 */ |
464 function wp_admin_bar_my_sites_menu( $wp_admin_bar ) { |
496 function wp_admin_bar_my_sites_menu( $wp_admin_bar ) { |
465 // Don't show for logged out users or single site mode. |
497 // Don't show for logged out users or single site mode. |
466 if ( ! is_user_logged_in() || ! is_multisite() ) { |
498 if ( ! is_user_logged_in() || ! is_multisite() ) { |
467 return; |
499 return; |
577 'class' => current_user_can( 'manage_network' ) ? 'ab-sub-secondary' : '', |
609 'class' => current_user_can( 'manage_network' ) ? 'ab-sub-secondary' : '', |
578 ), |
610 ), |
579 ) |
611 ) |
580 ); |
612 ); |
581 |
613 |
|
614 /** |
|
615 * Filters whether to show the site icons in toolbar. |
|
616 * |
|
617 * Returning false to this hook is the recommended way to hide site icons in the toolbar. |
|
618 * A truthy return may have negative performance impact on large multisites. |
|
619 * |
|
620 * @since 6.0.0 |
|
621 * |
|
622 * @param bool $show_site_icons Whether site icons should be shown in the toolbar. Default true. |
|
623 */ |
|
624 $show_site_icons = apply_filters( 'wp_admin_bar_show_site_icons', true ); |
|
625 |
582 foreach ( (array) $wp_admin_bar->user->blogs as $blog ) { |
626 foreach ( (array) $wp_admin_bar->user->blogs as $blog ) { |
583 switch_to_blog( $blog->userblog_id ); |
627 switch_to_blog( $blog->userblog_id ); |
584 |
628 |
585 if ( has_site_icon() ) { |
629 if ( true === $show_site_icons && has_site_icon() ) { |
586 $blavatar = sprintf( |
630 $blavatar = sprintf( |
587 '<img class="blavatar" src="%s" srcset="%s 2x" alt="" width="16" height="16" />', |
631 '<img class="blavatar" src="%s" srcset="%s 2x" alt="" width="16" height="16"%s />', |
588 esc_url( get_site_icon_url( 16 ) ), |
632 esc_url( get_site_icon_url( 16 ) ), |
589 esc_url( get_site_icon_url( 32 ) ) |
633 esc_url( get_site_icon_url( 32 ) ), |
|
634 ( wp_lazy_loading_enabled( 'img', 'site_icon_in_toolbar' ) ? ' loading="lazy"' : '' ) |
590 ); |
635 ); |
591 } else { |
636 } else { |
592 $blavatar = '<div class="blavatar"></div>'; |
637 $blavatar = '<div class="blavatar"></div>'; |
593 } |
638 } |
594 |
639 |
663 restore_current_blog(); |
708 restore_current_blog(); |
664 } |
709 } |
665 } |
710 } |
666 |
711 |
667 /** |
712 /** |
668 * Provide a shortlink. |
713 * Provides a shortlink. |
669 * |
714 * |
670 * @since 3.1.0 |
715 * @since 3.1.0 |
671 * |
716 * |
672 * @param WP_Admin_Bar $wp_admin_bar |
717 * @param WP_Admin_Bar $wp_admin_bar The WP_Admin_Bar instance. |
673 */ |
718 */ |
674 function wp_admin_bar_shortlink_menu( $wp_admin_bar ) { |
719 function wp_admin_bar_shortlink_menu( $wp_admin_bar ) { |
675 $short = wp_get_shortlink( 0, 'query' ); |
720 $short = wp_get_shortlink( 0, 'query' ); |
676 $id = 'get-shortlink'; |
721 $id = 'get-shortlink'; |
677 |
722 |
690 ) |
735 ) |
691 ); |
736 ); |
692 } |
737 } |
693 |
738 |
694 /** |
739 /** |
695 * Provide an edit link for posts and terms. |
740 * Provides an edit link for posts and terms. |
696 * |
741 * |
697 * @since 3.1.0 |
742 * @since 3.1.0 |
698 * @since 5.5.0 Added a "View Post" link on Comments screen for a single post. |
743 * @since 5.5.0 Added a "View Post" link on Comments screen for a single post. |
699 * |
744 * |
700 * @global WP_Term $tag |
745 * @global WP_Term $tag |
701 * @global WP_Query $wp_the_query WordPress Query object. |
746 * @global WP_Query $wp_the_query WordPress Query object. |
702 * @global int $user_id The ID of the user being edited. Not to be confused with the |
747 * @global int $user_id The ID of the user being edited. Not to be confused with the |
703 * global $user_ID, which contains the ID of the current user. |
748 * global $user_ID, which contains the ID of the current user. |
704 * @global int $post_id The ID of the post when editing comments for a single post. |
749 * @global int $post_id The ID of the post when editing comments for a single post. |
705 * |
750 * |
706 * @param WP_Admin_Bar $wp_admin_bar |
751 * @param WP_Admin_Bar $wp_admin_bar The WP_Admin_Bar instance. |
707 */ |
752 */ |
708 function wp_admin_bar_edit_menu( $wp_admin_bar ) { |
753 function wp_admin_bar_edit_menu( $wp_admin_bar ) { |
709 global $tag, $wp_the_query, $user_id, $post_id; |
754 global $tag, $wp_the_query, $user_id, $post_id; |
710 |
755 |
711 if ( is_admin() ) { |
756 if ( is_admin() ) { |
943 ) |
988 ) |
944 ); |
989 ); |
945 } |
990 } |
946 |
991 |
947 /** |
992 /** |
948 * Add appearance submenu items to the "Site Name" menu. |
993 * Adds appearance submenu items to the "Site Name" menu. |
949 * |
994 * |
950 * @since 3.1.0 |
995 * @since 3.1.0 |
951 * |
996 * |
952 * @param WP_Admin_Bar $wp_admin_bar |
997 * @param WP_Admin_Bar $wp_admin_bar The WP_Admin_Bar instance. |
953 */ |
998 */ |
954 function wp_admin_bar_appearance_menu( $wp_admin_bar ) { |
999 function wp_admin_bar_appearance_menu( $wp_admin_bar ) { |
955 $wp_admin_bar->add_group( |
1000 $wp_admin_bar->add_group( |
956 array( |
1001 array( |
957 'parent' => 'site-name', |
1002 'parent' => 'site-name', |
1116 ) |
1161 ) |
1117 ); |
1162 ); |
1118 } |
1163 } |
1119 |
1164 |
1120 /** |
1165 /** |
1121 * Add secondary menus. |
1166 * Adds secondary menus. |
1122 * |
1167 * |
1123 * @since 3.3.0 |
1168 * @since 3.3.0 |
1124 * |
1169 * |
1125 * @param WP_Admin_Bar $wp_admin_bar |
1170 * @param WP_Admin_Bar $wp_admin_bar The WP_Admin_Bar instance. |
1126 */ |
1171 */ |
1127 function wp_admin_bar_add_secondary_groups( $wp_admin_bar ) { |
1172 function wp_admin_bar_add_secondary_groups( $wp_admin_bar ) { |
1128 $wp_admin_bar->add_group( |
1173 $wp_admin_bar->add_group( |
1129 array( |
1174 array( |
1130 'id' => 'top-secondary', |
1175 'id' => 'top-secondary', |
1156 <style<?php echo $type_attr; ?> media="print">#wpadminbar { display:none; }</style> |
1201 <style<?php echo $type_attr; ?> media="print">#wpadminbar { display:none; }</style> |
1157 <?php |
1202 <?php |
1158 } |
1203 } |
1159 |
1204 |
1160 /** |
1205 /** |
1161 * Default admin bar callback. |
1206 * Prints default admin bar callback. |
1162 * |
1207 * |
1163 * @since 3.1.0 |
1208 * @since 3.1.0 |
1164 */ |
1209 */ |
1165 function _admin_bar_bump_cb() { |
1210 function _admin_bar_bump_cb() { |
1166 $type_attr = current_theme_supports( 'html5', 'style' ) ? '' : ' type="text/css"'; |
1211 $type_attr = current_theme_supports( 'html5', 'style' ) ? '' : ' type="text/css"'; |
1167 ?> |
1212 ?> |
1168 <style<?php echo $type_attr; ?> media="screen"> |
1213 <style<?php echo $type_attr; ?> media="screen"> |
1169 html { margin-top: 32px !important; } |
1214 html { margin-top: 32px !important; } |
1170 * html body { margin-top: 32px !important; } |
|
1171 @media screen and ( max-width: 782px ) { |
1215 @media screen and ( max-width: 782px ) { |
1172 html { margin-top: 46px !important; } |
1216 html { margin-top: 46px !important; } |
1173 * html body { margin-top: 46px !important; } |
|
1174 } |
1217 } |
1175 </style> |
1218 </style> |
1176 <?php |
1219 <?php |
1177 } |
1220 } |
1178 |
1221 |
1201 * Conditional Tags} article in the Theme Developer Handbook. |
1244 * Conditional Tags} article in the Theme Developer Handbook. |
1202 * |
1245 * |
1203 * @since 3.1.0 |
1246 * @since 3.1.0 |
1204 * |
1247 * |
1205 * @global bool $show_admin_bar |
1248 * @global bool $show_admin_bar |
1206 * @global string $pagenow |
1249 * @global string $pagenow The filename of the current screen. |
1207 * |
1250 * |
1208 * @return bool Whether the admin bar should be showing. |
1251 * @return bool Whether the admin bar should be showing. |
1209 */ |
1252 */ |
1210 function is_admin_bar_showing() { |
1253 function is_admin_bar_showing() { |
1211 global $show_admin_bar, $pagenow; |
1254 global $show_admin_bar, $pagenow; |