wp/wp-includes/admin-bar.php
changeset 5 5e2f62d02dcd
parent 0 d970ebf37754
child 7 cf61fcea0001
equal deleted inserted replaced
4:346c88efed21 5:5e2f62d02dcd
    20 
    20 
    21 	if ( ! is_admin_bar_showing() )
    21 	if ( ! is_admin_bar_showing() )
    22 		return false;
    22 		return false;
    23 
    23 
    24 	/* Load the admin bar class code ready for instantiation */
    24 	/* Load the admin bar class code ready for instantiation */
    25 	require( ABSPATH . WPINC . '/class-wp-admin-bar.php' );
    25 	require_once( ABSPATH . WPINC . '/class-wp-admin-bar.php' );
    26 
    26 
    27 	/* Instantiate the admin bar */
    27 	/* Instantiate the admin bar */
       
    28 
       
    29 	/**
       
    30 	 * Filter the admin bar class to instantiate.
       
    31 	 *
       
    32 	 * @since 3.1.0
       
    33 	 *
       
    34 	 * @param string $wp_admin_bar_class Admin bar class to use. Default 'WP_Admin_Bar'.
       
    35 	 */
    28 	$admin_bar_class = apply_filters( 'wp_admin_bar_class', 'WP_Admin_Bar' );
    36 	$admin_bar_class = apply_filters( 'wp_admin_bar_class', 'WP_Admin_Bar' );
    29 	if ( class_exists( $admin_bar_class ) )
    37 	if ( class_exists( $admin_bar_class ) )
    30 		$wp_admin_bar = new $admin_bar_class;
    38 		$wp_admin_bar = new $admin_bar_class;
    31 	else
    39 	else
    32 		return false;
    40 		return false;
    34 	$wp_admin_bar->initialize();
    42 	$wp_admin_bar->initialize();
    35 	$wp_admin_bar->add_menus();
    43 	$wp_admin_bar->add_menus();
    36 
    44 
    37 	return true;
    45 	return true;
    38 }
    46 }
    39 // Don't remove. Wrong way to disable.
       
    40 add_action( 'template_redirect', '_wp_admin_bar_init', 0 );
       
    41 add_action( 'admin_init', '_wp_admin_bar_init' );
       
    42 
    47 
    43 /**
    48 /**
    44  * Render the admin bar to the page based on the $wp_admin_bar->menu member var.
    49  * Render the admin bar to the page based on the $wp_admin_bar->menu member var.
    45  * This is called very late on the footer actions so that it will render after anything else being
    50  * This is called very late on the footer actions so that it will render after anything else being
    46  * added to the footer.
    51  * added to the footer.
    55 	global $wp_admin_bar;
    60 	global $wp_admin_bar;
    56 
    61 
    57 	if ( ! is_admin_bar_showing() || ! is_object( $wp_admin_bar ) )
    62 	if ( ! is_admin_bar_showing() || ! is_object( $wp_admin_bar ) )
    58 		return false;
    63 		return false;
    59 
    64 
       
    65 	/**
       
    66 	 * Load all necessary admin bar items.
       
    67 	 *
       
    68 	 * This is the hook used to add, remove, or manipulate admin bar items.
       
    69 	 *
       
    70 	 * @since 3.1.0
       
    71 	 *
       
    72 	 * @param WP_Admin_Bar $wp_admin_bar WP_Admin_Bar instance, passed by reference
       
    73 	 */
    60 	do_action_ref_array( 'admin_bar_menu', array( &$wp_admin_bar ) );
    74 	do_action_ref_array( 'admin_bar_menu', array( &$wp_admin_bar ) );
    61 
    75 
       
    76 	/**
       
    77 	 * Fires before the admin bar is rendered.
       
    78 	 *
       
    79 	 * @since 3.1.0
       
    80 	 */
    62 	do_action( 'wp_before_admin_bar_render' );
    81 	do_action( 'wp_before_admin_bar_render' );
    63 
    82 
    64 	$wp_admin_bar->render();
    83 	$wp_admin_bar->render();
    65 
    84 
       
    85 	/**
       
    86 	 * Fires after the admin bar is rendered.
       
    87 	 *
       
    88 	 * @since 3.1.0
       
    89 	 */
    66 	do_action( 'wp_after_admin_bar_render' );
    90 	do_action( 'wp_after_admin_bar_render' );
    67 }
    91 }
    68 add_action( 'wp_footer', 'wp_admin_bar_render', 1000 );
       
    69 add_action( 'in_admin_header', 'wp_admin_bar_render', 0 );
       
    70 
    92 
    71 /**
    93 /**
    72  * Add the WordPress logo menu.
    94  * Add the WordPress logo menu.
    73  *
    95  *
    74  * @since 3.3.0
    96  * @since 3.3.0
    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  *
   141 	$profile_url  = get_edit_profile_url( $user_id );
   177 	$profile_url  = get_edit_profile_url( $user_id );
   142 
   178 
   143 	if ( ! $user_id )
   179 	if ( ! $user_id )
   144 		return;
   180 		return;
   145 
   181 
   146 	$avatar = get_avatar( $user_id, 16 );
   182 	$avatar = get_avatar( $user_id, 26 );
   147 	$howdy  = sprintf( __('Howdy, %1$s'), $current_user->display_name );
   183 	$howdy  = sprintf( __('Howdy, %1$s'), $current_user->display_name );
   148 	$class  = empty( $avatar ) ? '' : 'with-avatar';
   184 	$class  = empty( $avatar ) ? '' : 'with-avatar';
   149 
   185 
   150 	$wp_admin_bar->add_menu( array(
   186 	$wp_admin_bar->add_menu( array(
   151 		'id'        => 'my-account',
   187 		'id'        => 'my-account',
   152 		'parent'    => 'top-secondary',
   188 		'parent'    => 'top-secondary',
   153 		'title'     => $howdy . $avatar,
   189 		'title'     => $howdy . $avatar,
   154 		'href'      => $profile_url,
   190 		'href'      => $profile_url,
   155 		'meta'      => array(
   191 		'meta'      => array(
   156 			'class'     => $class,
   192 			'class'     => $class,
   157 			'title'     => __('My Account'),
       
   158 		),
   193 		),
   159 	) );
   194 	) );
   160 }
   195 }
   161 
   196 
   162 /**
   197 /**
   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, '&hellip;' );
   274 	$title = wp_html_excerpt( $blogname, 40, '&hellip;' );
   241 
   275 
   242 	$wp_admin_bar->add_menu( array(
   276 	$wp_admin_bar->add_menu( array(
   293 
   327 
   294 	// Show only when the user has at least one site, or they're a super admin.
   328 	// Show only when the user has at least one site, or they're a super admin.
   295 	if ( count( $wp_admin_bar->user->blogs ) < 1 && ! is_super_admin() )
   329 	if ( count( $wp_admin_bar->user->blogs ) < 1 && ! is_super_admin() )
   296 		return;
   330 		return;
   297 
   331 
       
   332 	if ( $wp_admin_bar->user->active_blog ) {
       
   333 		$my_sites_url = get_admin_url( $wp_admin_bar->user->active_blog->blog_id, 'my-sites.php' );
       
   334 	} else {
       
   335 		$my_sites_url = admin_url( 'my-sites.php' );
       
   336 	}
       
   337 
   298 	$wp_admin_bar->add_menu( array(
   338 	$wp_admin_bar->add_menu( array(
   299 		'id'    => 'my-sites',
   339 		'id'    => 'my-sites',
   300 		'title' => __( 'My Sites' ),
   340 		'title' => __( 'My Sites' ),
   301 		'href'  => admin_url( 'my-sites.php' ),
   341 		'href'  => $my_sites_url,
   302 	) );
   342 	) );
   303 
   343 
   304 	if ( is_super_admin() ) {
   344 	if ( is_super_admin() ) {
   305 		$wp_admin_bar->add_group( array(
   345 		$wp_admin_bar->add_group( array(
   306 			'parent' => 'my-sites',
   346 			'parent' => 'my-sites',
   358 	foreach ( (array) $wp_admin_bar->user->blogs as $blog ) {
   398 	foreach ( (array) $wp_admin_bar->user->blogs as $blog ) {
   359 		switch_to_blog( $blog->userblog_id );
   399 		switch_to_blog( $blog->userblog_id );
   360 
   400 
   361 		$blavatar = '<div class="blavatar"></div>';
   401 		$blavatar = '<div class="blavatar"></div>';
   362 
   402 
   363 		$blogname = empty( $blog->blogname ) ? $blog->domain : $blog->blogname;
   403 		$blogname = $blog->blogname;
       
   404 
       
   405 		if ( ! $blogname ) {
       
   406 			$blogname = preg_replace( '#^(https?://)?(www.)?#', '', get_home_url() );
       
   407 		}
       
   408 
   364 		$menu_id  = 'blog-' . $blog->userblog_id;
   409 		$menu_id  = 'blog-' . $blog->userblog_id;
   365 
   410 
   366 		$wp_admin_bar->add_menu( array(
   411 		$wp_admin_bar->add_menu( array(
   367 			'parent'    => 'my-sites-list',
   412 			'parent'    => 'my-sites-list',
   368 			'id'        => $menu_id,
   413 			'id'        => $menu_id,
   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 
   545 
   604 
   546 	$wp_admin_bar->add_menu( array(
   605 	$wp_admin_bar->add_menu( array(
   547 		'id'    => 'new-content',
   606 		'id'    => 'new-content',
   548 		'title' => $title,
   607 		'title' => $title,
   549 		'href'  => admin_url( current( array_keys( $actions ) ) ),
   608 		'href'  => admin_url( current( array_keys( $actions ) ) ),
   550 		'meta'  => array(
       
   551 			'title' => _x( 'Add New', 'admin bar menu group label' ),
       
   552 		),
       
   553 	) );
   609 	) );
   554 
   610 
   555 	foreach ( $actions as $link => $action ) {
   611 	foreach ( $actions as $link => $action ) {
   556 		list( $title, $id ) = $action;
   612 		list( $title, $id ) = $action;
   557 
   613 
   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  *
   669 	if ( is_admin() )
   815 	if ( is_admin() )
   670 		return;
   816 		return;
   671 
   817 
   672 	$form  = '<form action="' . esc_url( home_url( '/' ) ) . '" method="get" id="adminbarsearch">';
   818 	$form  = '<form action="' . esc_url( home_url( '/' ) ) . '" method="get" id="adminbarsearch">';
   673 	$form .= '<input class="adminbar-input" name="s" id="adminbar-search" type="text" value="" maxlength="150" />';
   819 	$form .= '<input class="adminbar-input" name="s" id="adminbar-search" type="text" value="" maxlength="150" />';
       
   820 	$form .= '<label for="adminbar-search" class="screen-reader-text">' . __( 'Search' ) . '</label>';
   674 	$form .= '<input type="submit" class="adminbar-button" value="' . __('Search') . '"/>';
   821 	$form .= '<input type="submit" class="adminbar-button" value="' . __('Search') . '"/>';
   675 	$form .= '</form>';
   822 	$form .= '</form>';
   676 
   823 
   677 	$wp_admin_bar->add_menu( array(
   824 	$wp_admin_bar->add_menu( array(
   678 		'parent' => 'top-secondary',
   825 		'parent' => 'top-secondary',
   724  *
   871  *
   725  * @since 3.1.0
   872  * @since 3.1.0
   726  */
   873  */
   727 function _admin_bar_bump_cb() { ?>
   874 function _admin_bar_bump_cb() { ?>
   728 <style type="text/css" media="screen">
   875 <style type="text/css" media="screen">
   729 	html { margin-top: 28px !important; }
   876 	html { margin-top: 32px !important; }
   730 	* html body { margin-top: 28px !important; }
   877 	* html body { margin-top: 32px !important; }
       
   878 	@media screen and ( max-width: 782px ) {
       
   879 		html { margin-top: 46px !important; }
       
   880 		* html body { margin-top: 46px !important; }
       
   881 	}
   731 </style>
   882 </style>
   732 <?php
   883 <?php
   733 }
   884 }
   734 
   885 
   735 /**
   886 /**
   771 		} else {
   922 		} else {
   772 			$show_admin_bar = _get_admin_bar_pref();
   923 			$show_admin_bar = _get_admin_bar_pref();
   773 		}
   924 		}
   774 	}
   925 	}
   775 
   926 
       
   927 	/**
       
   928 	 * Filter whether to show the admin bar.
       
   929 	 *
       
   930 	 * Returning false to this hook is the recommended way to hide the admin bar.
       
   931 	 * The user's display preference is used for logged in users.
       
   932 	 *
       
   933 	 * @since 3.1.0
       
   934 	 *
       
   935 	 * @param bool $show_admin_bar Whether the admin bar should be shown. Default false.
       
   936 	 */
   776 	$show_admin_bar = apply_filters( 'show_admin_bar', $show_admin_bar );
   937 	$show_admin_bar = apply_filters( 'show_admin_bar', $show_admin_bar );
   777 
   938 
   778 	return $show_admin_bar;
   939 	return $show_admin_bar;
   779 }
   940 }
   780 
   941