wp/wp-includes/admin-bar.php
changeset 21 48c4eec2b7e6
parent 19 3d72ae0968f4
child 22 8c2e4d02f4ef
equal deleted inserted replaced
20:7b1b88e27a20 21:48c4eec2b7e6
    39 	 *
    39 	 *
    40 	 * @param string $wp_admin_bar_class Admin bar class to use. Default 'WP_Admin_Bar'.
    40 	 * @param string $wp_admin_bar_class Admin bar class to use. Default 'WP_Admin_Bar'.
    41 	 */
    41 	 */
    42 	$admin_bar_class = apply_filters( 'wp_admin_bar_class', 'WP_Admin_Bar' );
    42 	$admin_bar_class = apply_filters( 'wp_admin_bar_class', 'WP_Admin_Bar' );
    43 	if ( class_exists( $admin_bar_class ) ) {
    43 	if ( class_exists( $admin_bar_class ) ) {
    44 		$wp_admin_bar = new $admin_bar_class;
    44 		$wp_admin_bar = new $admin_bar_class();
    45 	} else {
    45 	} else {
    46 		return false;
    46 		return false;
    47 	}
    47 	}
    48 
    48 
    49 	$wp_admin_bar->initialize();
    49 	$wp_admin_bar->initialize();
    60  *
    60  *
    61  * For backward compatibility with themes not using the 'wp_body_open' action,
    61  * For backward compatibility with themes not using the 'wp_body_open' action,
    62  * the function is also called late on {@see 'wp_footer'}.
    62  * the function is also called late on {@see 'wp_footer'}.
    63  *
    63  *
    64  * 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
    65  * 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. This also gives you access to the `$post` global,
    66  * optimal point, right before the admin bar is rendered. This also gives you access to
    66  * among others.
    67  * the `$post` global, among others.
       
    68  *
    67  *
    69  * @since 3.1.0
    68  * @since 3.1.0
    70  * @since 5.4.0 Called on 'wp_body_open' action first, with 'wp_footer' as a fallback.
    69  * @since 5.4.0 Called on 'wp_body_open' action first, with 'wp_footer' as a fallback.
    71  *
    70  *
    72  * @global WP_Admin_Bar $wp_admin_bar
    71  * @global WP_Admin_Bar $wp_admin_bar
    84 	}
    83 	}
    85 
    84 
    86 	/**
    85 	/**
    87 	 * Loads all necessary admin bar items.
    86 	 * Loads all necessary admin bar items.
    88 	 *
    87 	 *
    89 	 * This is the hook used to add, remove, or manipulate admin bar items.
    88 	 * This hook can add, remove, or manipulate admin bar items. The priority
       
    89 	 * determines the placement for new items, and changes to existing items
       
    90 	 * would require a high priority. To remove or manipulate existing nodes
       
    91 	 * without a specific priority, use `wp_before_admin_bar_render`.
    90 	 *
    92 	 *
    91 	 * @since 3.1.0
    93 	 * @since 3.1.0
    92 	 *
    94 	 *
    93 	 * @param WP_Admin_Bar $wp_admin_bar The WP_Admin_Bar instance, passed by reference.
    95 	 * @param WP_Admin_Bar $wp_admin_bar The WP_Admin_Bar instance, passed by reference.
    94 	 */
    96 	 */
   120  *
   122  *
   121  * @param WP_Admin_Bar $wp_admin_bar The WP_Admin_Bar instance.
   123  * @param WP_Admin_Bar $wp_admin_bar The WP_Admin_Bar instance.
   122  */
   124  */
   123 function wp_admin_bar_wp_menu( $wp_admin_bar ) {
   125 function wp_admin_bar_wp_menu( $wp_admin_bar ) {
   124 	if ( current_user_can( 'read' ) ) {
   126 	if ( current_user_can( 'read' ) ) {
   125 		$about_url = self_admin_url( 'about.php' );
   127 		$about_url      = self_admin_url( 'about.php' );
       
   128 		$contribute_url = self_admin_url( 'contribute.php' );
   126 	} elseif ( is_multisite() ) {
   129 	} elseif ( is_multisite() ) {
   127 		$about_url = get_dashboard_url( get_current_user_id(), 'about.php' );
   130 		$about_url      = get_dashboard_url( get_current_user_id(), 'about.php' );
       
   131 		$contribute_url = get_dashboard_url( get_current_user_id(), 'contribute.php' );
   128 	} else {
   132 	} else {
   129 		$about_url = false;
   133 		$about_url      = false;
       
   134 		$contribute_url = false;
   130 	}
   135 	}
   131 
   136 
   132 	$wp_logo_menu_args = array(
   137 	$wp_logo_menu_args = array(
   133 		'id'    => 'wp-logo',
   138 		'id'    => 'wp-logo',
   134 		'title' => '<span class="ab-icon" aria-hidden="true"></span><span class="screen-reader-text">' . __( 'About WordPress' ) . '</span>',
   139 		'title' => '<span class="ab-icon" aria-hidden="true"></span><span class="screen-reader-text">' .
       
   140 				/* translators: Hidden accessibility text. */
       
   141 				__( 'About WordPress' ) .
       
   142 			'</span>',
   135 		'href'  => $about_url,
   143 		'href'  => $about_url,
       
   144 		'meta'  => array(
       
   145 			'menu_title' => __( 'About WordPress' ),
       
   146 		),
   136 	);
   147 	);
   137 
   148 
   138 	// Set tabindex="0" to make sub menus accessible when no URL is available.
   149 	// Set tabindex="0" to make sub menus accessible when no URL is available.
   139 	if ( ! $about_url ) {
   150 	if ( ! $about_url ) {
   140 		$wp_logo_menu_args['meta'] = array(
   151 		$wp_logo_menu_args['meta'] = array(
   154 				'href'   => $about_url,
   165 				'href'   => $about_url,
   155 			)
   166 			)
   156 		);
   167 		);
   157 	}
   168 	}
   158 
   169 
       
   170 	if ( $contribute_url ) {
       
   171 		// Add contribute link.
       
   172 		$wp_admin_bar->add_node(
       
   173 			array(
       
   174 				'parent' => 'wp-logo',
       
   175 				'id'     => 'contribute',
       
   176 				'title'  => __( 'Get Involved' ),
       
   177 				'href'   => $contribute_url,
       
   178 			)
       
   179 		);
       
   180 	}
       
   181 
   159 	// Add WordPress.org link.
   182 	// Add WordPress.org link.
   160 	$wp_admin_bar->add_node(
   183 	$wp_admin_bar->add_node(
   161 		array(
   184 		array(
   162 			'parent' => 'wp-logo-external',
   185 			'parent' => 'wp-logo-external',
   163 			'id'     => 'wporg',
   186 			'id'     => 'wporg',
   170 	$wp_admin_bar->add_node(
   193 	$wp_admin_bar->add_node(
   171 		array(
   194 		array(
   172 			'parent' => 'wp-logo-external',
   195 			'parent' => 'wp-logo-external',
   173 			'id'     => 'documentation',
   196 			'id'     => 'documentation',
   174 			'title'  => __( 'Documentation' ),
   197 			'title'  => __( 'Documentation' ),
   175 			'href'   => __( 'https://wordpress.org/support/' ),
   198 			'href'   => __( 'https://wordpress.org/documentation/' ),
       
   199 		)
       
   200 	);
       
   201 
       
   202 	// Add learn link.
       
   203 	$wp_admin_bar->add_node(
       
   204 		array(
       
   205 			'parent' => 'wp-logo-external',
       
   206 			'id'     => 'learn',
       
   207 			'title'  => __( 'Learn WordPress' ),
       
   208 			'href'   => 'https://learn.wordpress.org/',
   176 		)
   209 		)
   177 	);
   210 	);
   178 
   211 
   179 	// Add forums link.
   212 	// Add forums link.
   180 	$wp_admin_bar->add_node(
   213 	$wp_admin_bar->add_node(
   207 function wp_admin_bar_sidebar_toggle( $wp_admin_bar ) {
   240 function wp_admin_bar_sidebar_toggle( $wp_admin_bar ) {
   208 	if ( is_admin() ) {
   241 	if ( is_admin() ) {
   209 		$wp_admin_bar->add_node(
   242 		$wp_admin_bar->add_node(
   210 			array(
   243 			array(
   211 				'id'    => 'menu-toggle',
   244 				'id'    => 'menu-toggle',
   212 				'title' => '<span class="ab-icon" aria-hidden="true"></span><span class="screen-reader-text">' . __( 'Menu' ) . '</span>',
   245 				'title' => '<span class="ab-icon" aria-hidden="true"></span><span class="screen-reader-text">' .
       
   246 						/* translators: Hidden accessibility text. */
       
   247 						__( 'Menu' ) .
       
   248 					'</span>',
   213 				'href'  => '#',
   249 				'href'  => '#',
   214 			)
   250 			)
   215 		);
   251 		);
   216 	}
   252 	}
   217 }
   253 }
   249 			'id'     => 'my-account',
   285 			'id'     => 'my-account',
   250 			'parent' => 'top-secondary',
   286 			'parent' => 'top-secondary',
   251 			'title'  => $howdy . $avatar,
   287 			'title'  => $howdy . $avatar,
   252 			'href'   => $profile_url,
   288 			'href'   => $profile_url,
   253 			'meta'   => array(
   289 			'meta'   => array(
   254 				'class' => $class,
   290 				'class'      => $class,
       
   291 				/* translators: %s: Current user's display name. */
       
   292 				'menu_title' => sprintf( __( 'Howdy, %s' ), $current_user->display_name ),
       
   293 				'tabindex'   => ( false !== $profile_url ) ? '' : 0,
   255 			),
   294 			),
   256 		)
   295 		)
   257 	);
   296 	);
   258 }
   297 }
   259 
   298 
   292 
   331 
   293 	if ( $current_user->display_name !== $current_user->user_login ) {
   332 	if ( $current_user->display_name !== $current_user->user_login ) {
   294 		$user_info .= "<span class='username'>{$current_user->user_login}</span>";
   333 		$user_info .= "<span class='username'>{$current_user->user_login}</span>";
   295 	}
   334 	}
   296 
   335 
       
   336 	if ( false !== $profile_url ) {
       
   337 		$user_info .= "<span class='display-name edit-profile'>" . __( 'Edit Profile' ) . '</span>';
       
   338 	}
       
   339 
   297 	$wp_admin_bar->add_node(
   340 	$wp_admin_bar->add_node(
   298 		array(
   341 		array(
   299 			'parent' => 'user-actions',
   342 			'parent' => 'user-actions',
   300 			'id'     => 'user-info',
   343 			'id'     => 'user-info',
   301 			'title'  => $user_info,
   344 			'title'  => $user_info,
   302 			'href'   => $profile_url,
   345 			'href'   => $profile_url,
   303 			'meta'   => array(
   346 		)
   304 				'tabindex' => -1,
   347 	);
   305 			),
       
   306 		)
       
   307 	);
       
   308 
       
   309 	if ( false !== $profile_url ) {
       
   310 		$wp_admin_bar->add_node(
       
   311 			array(
       
   312 				'parent' => 'user-actions',
       
   313 				'id'     => 'edit-profile',
       
   314 				'title'  => __( 'Edit Profile' ),
       
   315 				'href'   => $profile_url,
       
   316 			)
       
   317 		);
       
   318 	}
       
   319 
   348 
   320 	$wp_admin_bar->add_node(
   349 	$wp_admin_bar->add_node(
   321 		array(
   350 		array(
   322 			'parent' => 'user-actions',
   351 			'parent' => 'user-actions',
   323 			'id'     => 'logout',
   352 			'id'     => 'logout',
   364 	$wp_admin_bar->add_node(
   393 	$wp_admin_bar->add_node(
   365 		array(
   394 		array(
   366 			'id'    => 'site-name',
   395 			'id'    => 'site-name',
   367 			'title' => $title,
   396 			'title' => $title,
   368 			'href'  => ( is_admin() || ! current_user_can( 'read' ) ) ? home_url( '/' ) : admin_url(),
   397 			'href'  => ( is_admin() || ! current_user_can( 'read' ) ) ? home_url( '/' ) : admin_url(),
       
   398 			'meta'  => array(
       
   399 				'menu_title' => $title,
       
   400 			),
   369 		)
   401 		)
   370 	);
   402 	);
   371 
   403 
   372 	// Create submenu items.
   404 	// Create submenu items.
   373 
   405 
   385 		if ( is_blog_admin() && is_multisite() && current_user_can( 'manage_sites' ) ) {
   417 		if ( is_blog_admin() && is_multisite() && current_user_can( 'manage_sites' ) ) {
   386 			$wp_admin_bar->add_node(
   418 			$wp_admin_bar->add_node(
   387 				array(
   419 				array(
   388 					'parent' => 'site-name',
   420 					'parent' => 'site-name',
   389 					'id'     => 'edit-site',
   421 					'id'     => 'edit-site',
   390 					'title'  => __( 'Edit Site' ),
   422 					'title'  => __( 'Manage Site' ),
   391 					'href'   => network_admin_url( 'site-info.php?id=' . get_current_blog_id() ),
   423 					'href'   => network_admin_url( 'site-info.php?id=' . get_current_blog_id() ),
   392 				)
   424 				)
   393 			);
   425 			);
   394 		}
   426 		}
   395 	} elseif ( current_user_can( 'read' ) ) {
   427 	} elseif ( current_user_can( 'read' ) ) {
   403 			)
   435 			)
   404 		);
   436 		);
   405 
   437 
   406 		// Add the appearance submenu items.
   438 		// Add the appearance submenu items.
   407 		wp_admin_bar_appearance_menu( $wp_admin_bar );
   439 		wp_admin_bar_appearance_menu( $wp_admin_bar );
       
   440 
       
   441 		// Add a Plugins link.
       
   442 		if ( current_user_can( 'activate_plugins' ) ) {
       
   443 			$wp_admin_bar->add_node(
       
   444 				array(
       
   445 					'parent' => 'site-name',
       
   446 					'id'     => 'plugins',
       
   447 					'title'  => __( 'Plugins' ),
       
   448 					'href'   => admin_url( 'plugins.php' ),
       
   449 				)
       
   450 			);
       
   451 		}
   408 	}
   452 	}
   409 }
   453 }
   410 
   454 
   411 /**
   455 /**
   412  * Adds the "Edit site" link to the Toolbar.
   456  * Adds the "Edit site" link to the Toolbar.
   413  *
   457  *
   414  * @since 5.9.0
   458  * @since 5.9.0
       
   459  * @since 6.3.0 Added `$_wp_current_template_id` global for editing of current template directly from the admin bar.
       
   460  * @since 6.6.0 Added the `canvas` query arg to the Site Editor link.
       
   461  *
       
   462  * @global string $_wp_current_template_id
   415  *
   463  *
   416  * @param WP_Admin_Bar $wp_admin_bar The WP_Admin_Bar instance.
   464  * @param WP_Admin_Bar $wp_admin_bar The WP_Admin_Bar instance.
   417  */
   465  */
   418 function wp_admin_bar_edit_site_menu( $wp_admin_bar ) {
   466 function wp_admin_bar_edit_site_menu( $wp_admin_bar ) {
       
   467 	global $_wp_current_template_id;
       
   468 
   419 	// Don't show if a block theme is not activated.
   469 	// Don't show if a block theme is not activated.
   420 	if ( ! wp_is_block_theme() ) {
   470 	if ( ! wp_is_block_theme() ) {
   421 		return;
   471 		return;
   422 	}
   472 	}
   423 
   473 
   428 
   478 
   429 	$wp_admin_bar->add_node(
   479 	$wp_admin_bar->add_node(
   430 		array(
   480 		array(
   431 			'id'    => 'site-editor',
   481 			'id'    => 'site-editor',
   432 			'title' => __( 'Edit site' ),
   482 			'title' => __( 'Edit site' ),
   433 			'href'  => admin_url( 'site-editor.php' ),
   483 			'href'  => add_query_arg(
       
   484 				array(
       
   485 					'postType' => 'wp_template',
       
   486 					'postId'   => $_wp_current_template_id,
       
   487 					'canvas'   => 'edit',
       
   488 				),
       
   489 				admin_url( 'site-editor.php' )
       
   490 			),
   434 		)
   491 		)
   435 	);
   492 	);
   436 }
   493 }
   437 
   494 
   438 /**
   495 /**
   439  * Adds the "Customize" link to the Toolbar.
   496  * Adds the "Customize" link to the Toolbar.
   440  *
   497  *
   441  * @since 4.3.0
   498  * @since 4.3.0
   442  *
   499  *
   443  * @param WP_Admin_Bar $wp_admin_bar The WP_Admin_Bar instance.
       
   444  * @global WP_Customize_Manager $wp_customize
   500  * @global WP_Customize_Manager $wp_customize
       
   501  *
       
   502  * @param WP_Admin_Bar $wp_admin_bar The WP_Admin_Bar instance.
   445  */
   503  */
   446 function wp_admin_bar_customize_menu( $wp_admin_bar ) {
   504 function wp_admin_bar_customize_menu( $wp_admin_bar ) {
   447 	global $wp_customize;
   505 	global $wp_customize;
   448 
   506 
   449 	// Don't show if a block theme is activated and no plugins use the customizer.
   507 	// Don't show if a block theme is activated and no plugins use the customizer.
   722 
   780 
   723 	if ( empty( $short ) ) {
   781 	if ( empty( $short ) ) {
   724 		return;
   782 		return;
   725 	}
   783 	}
   726 
   784 
   727 	$html = '<input class="shortlink-input" type="text" readonly="readonly" value="' . esc_attr( $short ) . '" />';
   785 	$html = '<input class="shortlink-input" type="text" readonly="readonly" value="' . esc_attr( $short ) . '" aria-label="' . __( 'Shortlink' ) . '" />';
   728 
   786 
   729 	$wp_admin_bar->add_node(
   787 	$wp_admin_bar->add_node(
   730 		array(
   788 		array(
   731 			'id'    => $id,
   789 			'id'    => $id,
   732 			'title' => __( 'Shortlink' ),
   790 			'title' => __( 'Shortlink' ),
   807 					'href'  => get_post_type_archive_link( $current_screen->post_type ),
   865 					'href'  => get_post_type_archive_link( $current_screen->post_type ),
   808 				)
   866 				)
   809 			);
   867 			);
   810 		} elseif ( 'term' === $current_screen->base && isset( $tag ) && is_object( $tag ) && ! is_wp_error( $tag ) ) {
   868 		} elseif ( 'term' === $current_screen->base && isset( $tag ) && is_object( $tag ) && ! is_wp_error( $tag ) ) {
   811 			$tax = get_taxonomy( $tag->taxonomy );
   869 			$tax = get_taxonomy( $tag->taxonomy );
   812 			if ( is_taxonomy_viewable( $tax ) ) {
   870 			if ( is_term_publicly_viewable( $tag ) ) {
   813 				$wp_admin_bar->add_node(
   871 				$wp_admin_bar->add_node(
   814 					array(
   872 					array(
   815 						'id'    => 'view',
   873 						'id'    => 'view',
   816 						'title' => $tax->labels->view_item,
   874 						'title' => $tax->labels->view_item,
   817 						'href'  => get_term_link( $tag ),
   875 						'href'  => get_term_link( $tag ),
   863 						'title' => $tax->labels->edit_item,
   921 						'title' => $tax->labels->edit_item,
   864 						'href'  => $edit_term_link,
   922 						'href'  => $edit_term_link,
   865 					)
   923 					)
   866 				);
   924 				);
   867 			}
   925 			}
   868 		} elseif ( is_a( $current_object, 'WP_User' ) && current_user_can( 'edit_user', $current_object->ID ) ) {
   926 		} elseif ( $current_object instanceof WP_User && current_user_can( 'edit_user', $current_object->ID ) ) {
   869 			$edit_user_link = get_edit_user_link( $current_object->ID );
   927 			$edit_user_link = get_edit_user_link( $current_object->ID );
   870 			if ( $edit_user_link ) {
   928 			if ( $edit_user_link ) {
   871 				$wp_admin_bar->add_node(
   929 				$wp_admin_bar->add_node(
   872 					array(
   930 					array(
   873 						'id'    => 'edit',
   931 						'id'    => 'edit',
   882 
   940 
   883 /**
   941 /**
   884  * Adds "Add New" menu.
   942  * Adds "Add New" menu.
   885  *
   943  *
   886  * @since 3.1.0
   944  * @since 3.1.0
       
   945  * @since 6.5.0 Added a New Site link for network installations.
   887  *
   946  *
   888  * @param WP_Admin_Bar $wp_admin_bar The WP_Admin_Bar instance.
   947  * @param WP_Admin_Bar $wp_admin_bar The WP_Admin_Bar instance.
   889  */
   948  */
   890 function wp_admin_bar_new_content_menu( $wp_admin_bar ) {
   949 function wp_admin_bar_new_content_menu( $wp_admin_bar ) {
   891 	$actions = array();
   950 	$actions = array();
   937 	$wp_admin_bar->add_node(
   996 	$wp_admin_bar->add_node(
   938 		array(
   997 		array(
   939 			'id'    => 'new-content',
   998 			'id'    => 'new-content',
   940 			'title' => $title,
   999 			'title' => $title,
   941 			'href'  => admin_url( current( array_keys( $actions ) ) ),
  1000 			'href'  => admin_url( current( array_keys( $actions ) ) ),
       
  1001 			'meta'  => array(
       
  1002 				'menu_title' => _x( 'New', 'admin bar menu group label' ),
       
  1003 			),
   942 		)
  1004 		)
   943 	);
  1005 	);
   944 
  1006 
   945 	foreach ( $actions as $link => $action ) {
  1007 	foreach ( $actions as $link => $action ) {
   946 		list( $title, $id ) = $action;
  1008 		list( $title, $id ) = $action;
   952 				'title'  => $title,
  1014 				'title'  => $title,
   953 				'href'   => admin_url( $link ),
  1015 				'href'   => admin_url( $link ),
   954 			)
  1016 			)
   955 		);
  1017 		);
   956 	}
  1018 	}
       
  1019 
       
  1020 	if ( is_multisite() && current_user_can( 'create_sites' ) ) {
       
  1021 		$wp_admin_bar->add_node(
       
  1022 			array(
       
  1023 				'parent' => 'new-content',
       
  1024 				'id'     => 'add-new-site',
       
  1025 				'title'  => _x( 'Site', 'add new from admin bar' ),
       
  1026 				'href'   => network_admin_url( 'site-new.php' ),
       
  1027 			)
       
  1028 		);
       
  1029 	}
   957 }
  1030 }
   958 
  1031 
   959 /**
  1032 /**
   960  * Adds edit comments link with awaiting moderation count bubble.
  1033  * Adds edit comments link with awaiting moderation count bubble.
   961  *
  1034  *
   969 	}
  1042 	}
   970 
  1043 
   971 	$awaiting_mod  = wp_count_comments();
  1044 	$awaiting_mod  = wp_count_comments();
   972 	$awaiting_mod  = $awaiting_mod->moderated;
  1045 	$awaiting_mod  = $awaiting_mod->moderated;
   973 	$awaiting_text = sprintf(
  1046 	$awaiting_text = sprintf(
   974 		/* translators: %s: Number of comments. */
  1047 		/* translators: Hidden accessibility text. %s: Number of comments. */
   975 		_n( '%s Comment in moderation', '%s Comments in moderation', $awaiting_mod ),
  1048 		_n( '%s Comment in moderation', '%s Comments in moderation', $awaiting_mod ),
   976 		number_format_i18n( $awaiting_mod )
  1049 		number_format_i18n( $awaiting_mod )
   977 	);
  1050 	);
   978 
  1051 
   979 	$icon   = '<span class="ab-icon" aria-hidden="true"></span>';
  1052 	$icon   = '<span class="ab-icon" aria-hidden="true"></span>';
  1044 	if ( current_theme_supports( 'custom-background' ) ) {
  1117 	if ( current_theme_supports( 'custom-background' ) ) {
  1045 		$wp_admin_bar->add_node(
  1118 		$wp_admin_bar->add_node(
  1046 			array(
  1119 			array(
  1047 				'parent' => 'appearance',
  1120 				'parent' => 'appearance',
  1048 				'id'     => 'background',
  1121 				'id'     => 'background',
  1049 				'title'  => __( 'Background' ),
  1122 				'title'  => _x( 'Background', 'custom background' ),
  1050 				'href'   => admin_url( 'themes.php?page=custom-background' ),
  1123 				'href'   => admin_url( 'themes.php?page=custom-background' ),
  1051 				'meta'   => array(
  1124 				'meta'   => array(
  1052 					'class' => 'hide-if-customize',
  1125 					'class' => 'hide-if-customize',
  1053 				),
  1126 				),
  1054 			)
  1127 			)
  1058 	if ( current_theme_supports( 'custom-header' ) ) {
  1131 	if ( current_theme_supports( 'custom-header' ) ) {
  1059 		$wp_admin_bar->add_node(
  1132 		$wp_admin_bar->add_node(
  1060 			array(
  1133 			array(
  1061 				'parent' => 'appearance',
  1134 				'parent' => 'appearance',
  1062 				'id'     => 'header',
  1135 				'id'     => 'header',
  1063 				'title'  => __( 'Header' ),
  1136 				'title'  => _x( 'Header', 'custom image header' ),
  1064 				'href'   => admin_url( 'themes.php?page=custom-header' ),
  1137 				'href'   => admin_url( 'themes.php?page=custom-header' ),
  1065 				'meta'   => array(
  1138 				'meta'   => array(
  1066 					'class' => 'hide-if-customize',
  1139 					'class' => 'hide-if-customize',
  1067 				),
  1140 				),
  1068 			)
  1141 			)
  1069 		);
  1142 		);
  1070 	}
  1143 	}
  1071 
       
  1072 }
  1144 }
  1073 
  1145 
  1074 /**
  1146 /**
  1075  * Provides an update link if theme/plugin/core updates are available.
  1147  * Provides an update link if theme/plugin/core updates are available.
  1076  *
  1148  *
  1085 	if ( ! $update_data['counts']['total'] ) {
  1157 	if ( ! $update_data['counts']['total'] ) {
  1086 		return;
  1158 		return;
  1087 	}
  1159 	}
  1088 
  1160 
  1089 	$updates_text = sprintf(
  1161 	$updates_text = sprintf(
  1090 		/* translators: %s: Total number of updates available. */
  1162 		/* translators: Hidden accessibility text. %s: Total number of updates available. */
  1091 		_n( '%s update available', '%s updates available', $update_data['counts']['total'] ),
  1163 		_n( '%s update available', '%s updates available', $update_data['counts']['total'] ),
  1092 		number_format_i18n( $update_data['counts']['total'] )
  1164 		number_format_i18n( $update_data['counts']['total'] )
  1093 	);
  1165 	);
  1094 
  1166 
  1095 	$icon   = '<span class="ab-icon" aria-hidden="true"></span>';
  1167 	$icon   = '<span class="ab-icon" aria-hidden="true"></span>';
  1117 		return;
  1189 		return;
  1118 	}
  1190 	}
  1119 
  1191 
  1120 	$form  = '<form action="' . esc_url( home_url( '/' ) ) . '" method="get" id="adminbarsearch">';
  1192 	$form  = '<form action="' . esc_url( home_url( '/' ) ) . '" method="get" id="adminbarsearch">';
  1121 	$form .= '<input class="adminbar-input" name="s" id="adminbar-search" type="text" value="" maxlength="150" />';
  1193 	$form .= '<input class="adminbar-input" name="s" id="adminbar-search" type="text" value="" maxlength="150" />';
  1122 	$form .= '<label for="adminbar-search" class="screen-reader-text">' . __( 'Search' ) . '</label>';
  1194 	$form .= '<label for="adminbar-search" class="screen-reader-text">' .
       
  1195 			/* translators: Hidden accessibility text. */
       
  1196 			__( 'Search' ) .
       
  1197 		'</label>';
  1123 	$form .= '<input type="submit" class="adminbar-button" value="' . __( 'Search' ) . '" />';
  1198 	$form .= '<input type="submit" class="adminbar-button" value="' . __( 'Search' ) . '" />';
  1124 	$form .= '</form>';
  1199 	$form .= '</form>';
  1125 
  1200 
  1126 	$wp_admin_bar->add_node(
  1201 	$wp_admin_bar->add_node(
  1127 		array(
  1202 		array(
  1189 		)
  1264 		)
  1190 	);
  1265 	);
  1191 }
  1266 }
  1192 
  1267 
  1193 /**
  1268 /**
  1194  * Prints style and scripts for the admin bar.
  1269  * Enqueues inline style to hide the admin bar when printing.
  1195  *
  1270  *
  1196  * @since 3.1.0
  1271  * @since 6.4.0
  1197  */
  1272  */
  1198 function wp_admin_bar_header() {
  1273 function wp_enqueue_admin_bar_header_styles() {
  1199 	$type_attr = current_theme_supports( 'html5', 'style' ) ? '' : ' type="text/css"';
  1274 	// Back-compat for plugins that disable functionality by unhooking this action.
  1200 	?>
  1275 	$action = is_admin() ? 'admin_head' : 'wp_head';
  1201 <style<?php echo $type_attr; ?> media="print">#wpadminbar { display:none; }</style>
  1276 	if ( ! has_action( $action, 'wp_admin_bar_header' ) ) {
  1202 	<?php
  1277 		return;
  1203 }
  1278 	}
  1204 
  1279 	remove_action( $action, 'wp_admin_bar_header' );
  1205 /**
  1280 
  1206  * Prints default admin bar callback.
  1281 	wp_add_inline_style( 'admin-bar', '@media print { #wpadminbar { display:none; } }' );
  1207  *
  1282 }
  1208  * @since 3.1.0
  1283 
  1209  */
  1284 /**
  1210 function _admin_bar_bump_cb() {
  1285  * Enqueues inline bump styles to make room for the admin bar.
  1211 	$type_attr = current_theme_supports( 'html5', 'style' ) ? '' : ' type="text/css"';
  1286  *
  1212 	?>
  1287  * @since 6.4.0
  1213 <style<?php echo $type_attr; ?> media="screen">
  1288  */
  1214 	html { margin-top: 32px !important; }
  1289 function wp_enqueue_admin_bar_bump_styles() {
  1215 	@media screen and ( max-width: 782px ) {
  1290 	if ( current_theme_supports( 'admin-bar' ) ) {
  1216 		html { margin-top: 46px !important; }
  1291 		$admin_bar_args  = get_theme_support( 'admin-bar' );
  1217 	}
  1292 		$header_callback = $admin_bar_args[0]['callback'];
  1218 </style>
  1293 	}
  1219 	<?php
  1294 
       
  1295 	if ( empty( $header_callback ) ) {
       
  1296 		$header_callback = '_admin_bar_bump_cb';
       
  1297 	}
       
  1298 
       
  1299 	if ( '_admin_bar_bump_cb' !== $header_callback ) {
       
  1300 		return;
       
  1301 	}
       
  1302 
       
  1303 	// Back-compat for plugins that disable functionality by unhooking this action.
       
  1304 	if ( ! has_action( 'wp_head', $header_callback ) ) {
       
  1305 		return;
       
  1306 	}
       
  1307 	remove_action( 'wp_head', $header_callback );
       
  1308 
       
  1309 	$css = '
       
  1310 		@media screen { html { margin-top: 32px !important; } }
       
  1311 		@media screen and ( max-width: 782px ) { html { margin-top: 46px !important; } }
       
  1312 	';
       
  1313 	wp_add_inline_style( 'admin-bar', $css );
  1220 }
  1314 }
  1221 
  1315 
  1222 /**
  1316 /**
  1223  * Sets the display status of the admin bar.
  1317  * Sets the display status of the admin bar.
  1224  *
  1318  *