web/wp-includes/admin-bar.php
changeset 204 09a1c134465b
parent 194 32102edaa81b
equal deleted inserted replaced
203:f507feede89a 204:09a1c134465b
   339 		'meta'   => array(
   339 		'meta'   => array(
   340 			'class' => is_super_admin() ? 'ab-sub-secondary' : '',
   340 			'class' => is_super_admin() ? 'ab-sub-secondary' : '',
   341 		),
   341 		),
   342 	) );
   342 	) );
   343 
   343 
   344 	$blue_wp_logo_url = includes_url('images/wpmini-blue.png');
       
   345 
       
   346 	foreach ( (array) $wp_admin_bar->user->blogs as $blog ) {
   344 	foreach ( (array) $wp_admin_bar->user->blogs as $blog ) {
   347 		// @todo Replace with some favicon lookup.
   345 		switch_to_blog( $blog->userblog_id );
   348 		//$blavatar = '<img src="' . esc_url( blavatar_url( blavatar_domain( $blog->siteurl ), 'img', 16, $blue_wp_logo_url ) ) . '" alt="Blavatar" width="16" height="16" />';
   346 
   349 		$blavatar = '<img src="' . esc_url($blue_wp_logo_url) . '" alt="' . esc_attr__( 'Blavatar' ) . '" width="16" height="16" class="blavatar"/>';
   347 		$blavatar = '<div class="blavatar"></div>';
   350 
   348 
   351 		$blogname = empty( $blog->blogname ) ? $blog->domain : $blog->blogname;
   349 		$blogname = empty( $blog->blogname ) ? $blog->domain : $blog->blogname;
   352 		$menu_id  = 'blog-' . $blog->userblog_id;
   350 		$menu_id  = 'blog-' . $blog->userblog_id;
   353 
   351 
   354 		$wp_admin_bar->add_menu( array(
   352 		$wp_admin_bar->add_menu( array(
   355 			'parent'    => 'my-sites-list',
   353 			'parent'    => 'my-sites-list',
   356 			'id'        => $menu_id,
   354 			'id'        => $menu_id,
   357 			'title'     => $blavatar . $blogname,
   355 			'title'     => $blavatar . $blogname,
   358 			'href'      => get_admin_url( $blog->userblog_id ),
   356 			'href'      => admin_url(),
   359 		) );
   357 		) );
   360 
   358 
   361 		$wp_admin_bar->add_menu( array(
   359 		$wp_admin_bar->add_menu( array(
   362 			'parent' => $menu_id,
   360 			'parent' => $menu_id,
   363 			'id'     => $menu_id . '-d',
   361 			'id'     => $menu_id . '-d',
   364 			'title'  => __( 'Dashboard' ),
   362 			'title'  => __( 'Dashboard' ),
   365 			'href'   => get_admin_url( $blog->userblog_id ),
   363 			'href'   => admin_url(),
   366 		) );
   364 		) );
   367 
   365 
   368 		if ( current_user_can_for_blog( $blog->userblog_id, 'edit_posts' ) ) {
   366 		if ( current_user_can( get_post_type_object( 'post' )->cap->create_posts ) ) {
   369 			$wp_admin_bar->add_menu( array(
   367 			$wp_admin_bar->add_menu( array(
   370 				'parent' => $menu_id,
   368 				'parent' => $menu_id,
   371 				'id'     => $menu_id . '-n',
   369 				'id'     => $menu_id . '-n',
   372 				'title'  => __( 'New Post' ),
   370 				'title'  => __( 'New Post' ),
   373 				'href'   => get_admin_url( $blog->userblog_id, 'post-new.php' ),
   371 				'href'   => admin_url( 'post-new.php' ),
   374 			) );
   372 			) );
       
   373 		}
       
   374 
       
   375 		if ( current_user_can( 'edit_posts' ) ) {
   375 			$wp_admin_bar->add_menu( array(
   376 			$wp_admin_bar->add_menu( array(
   376 				'parent' => $menu_id,
   377 				'parent' => $menu_id,
   377 				'id'     => $menu_id . '-c',
   378 				'id'     => $menu_id . '-c',
   378 				'title'  => __( 'Manage Comments' ),
   379 				'title'  => __( 'Manage Comments' ),
   379 				'href'   => get_admin_url( $blog->userblog_id, 'edit-comments.php' ),
   380 				'href'   => admin_url( 'edit-comments.php' ),
   380 			) );
   381 			) );
   381 		}
   382 		}
   382 
   383 
   383 		$wp_admin_bar->add_menu( array(
   384 		$wp_admin_bar->add_menu( array(
   384 			'parent' => $menu_id,
   385 			'parent' => $menu_id,
   385 			'id'     => $menu_id . '-v',
   386 			'id'     => $menu_id . '-v',
   386 			'title'  => __( 'Visit Site' ),
   387 			'title'  => __( 'Visit Site' ),
   387 			'href'   => get_home_url( $blog->userblog_id, '/' ),
   388 			'href'   => home_url( '/' ),
   388 		) );
   389 		) );
       
   390 
       
   391 		restore_current_blog();
   389 	}
   392 	}
   390 }
   393 }
   391 
   394 
   392 /**
   395 /**
   393  * Provide a shortlink.
   396  * Provide a shortlink.
   415  * Provide an edit link for posts and terms.
   418  * Provide an edit link for posts and terms.
   416  *
   419  *
   417  * @since 3.1.0
   420  * @since 3.1.0
   418  */
   421  */
   419 function wp_admin_bar_edit_menu( $wp_admin_bar ) {
   422 function wp_admin_bar_edit_menu( $wp_admin_bar ) {
   420 	global $post, $tag, $wp_the_query;
   423 	global $tag, $wp_the_query;
   421 
   424 
   422 	if ( is_admin() ) {
   425 	if ( is_admin() ) {
   423 		$current_screen = get_current_screen();
   426 		$current_screen = get_current_screen();
       
   427 		$post = get_post();
   424 
   428 
   425 		if ( 'post' == $current_screen->base
   429 		if ( 'post' == $current_screen->base
   426 			&& 'add' != $current_screen->action
   430 			&& 'add' != $current_screen->action
   427 			&& ( $post_type_object = get_post_type_object( $post->post_type ) )
   431 			&& ( $post_type_object = get_post_type_object( $post->post_type ) )
   428 			&& current_user_can( $post_type_object->cap->read_post, $post->ID )
   432 			&& current_user_can( $post_type_object->cap->read_post, $post->ID )
   429 			&& ( $post_type_object->public ) )
   433 			&& ( $post_type_object->public )
       
   434 			&& ( $post_type_object->show_in_admin_bar ) )
   430 		{
   435 		{
   431 			$wp_admin_bar->add_menu( array(
   436 			$wp_admin_bar->add_menu( array(
   432 				'id' => 'view',
   437 				'id' => 'view',
   433 				'title' => $post_type_object->labels->view_item,
   438 				'title' => $post_type_object->labels->view_item,
   434 				'href' => get_permalink( $post->ID )
   439 				'href' => get_permalink( $post->ID )
   451 			return;
   456 			return;
   452 
   457 
   453 		if ( ! empty( $current_object->post_type )
   458 		if ( ! empty( $current_object->post_type )
   454 			&& ( $post_type_object = get_post_type_object( $current_object->post_type ) )
   459 			&& ( $post_type_object = get_post_type_object( $current_object->post_type ) )
   455 			&& current_user_can( $post_type_object->cap->edit_post, $current_object->ID )
   460 			&& current_user_can( $post_type_object->cap->edit_post, $current_object->ID )
   456 			&& ( $post_type_object->show_ui || 'attachment' == $current_object->post_type ) )
   461 			&& $post_type_object->show_ui && $post_type_object->show_in_admin_bar )
   457 		{
   462 		{
   458 			$wp_admin_bar->add_menu( array(
   463 			$wp_admin_bar->add_menu( array(
   459 				'id' => 'edit',
   464 				'id' => 'edit',
   460 				'title' => $post_type_object->labels->edit_item,
   465 				'title' => $post_type_object->labels->edit_item,
   461 				'href' => get_edit_post_link( $current_object->ID )
   466 				'href' => get_edit_post_link( $current_object->ID )
   482 function wp_admin_bar_new_content_menu( $wp_admin_bar ) {
   487 function wp_admin_bar_new_content_menu( $wp_admin_bar ) {
   483 	$actions = array();
   488 	$actions = array();
   484 
   489 
   485 	$cpts = (array) get_post_types( array( 'show_in_admin_bar' => true ), 'objects' );
   490 	$cpts = (array) get_post_types( array( 'show_in_admin_bar' => true ), 'objects' );
   486 
   491 
   487 	if ( isset( $cpts['post'] ) && current_user_can( $cpts['post']->cap->edit_posts ) ) {
   492 	if ( isset( $cpts['post'] ) && current_user_can( $cpts['post']->cap->create_posts ) )
   488 		$actions[ 'post-new.php' ] = array( $cpts['post']->labels->name_admin_bar, 'new-post' );
   493 		$actions[ 'post-new.php' ] = array( $cpts['post']->labels->name_admin_bar, 'new-post' );
   489 		unset( $cpts['post'] );
   494 
   490 	}
   495 	if ( isset( $cpts['attachment'] ) && current_user_can( 'upload_files' ) )
   491 
   496 		$actions[ 'media-new.php' ] = array( $cpts['attachment']->labels->name_admin_bar, 'new-media' );
   492 	if ( current_user_can( 'upload_files' ) )
       
   493 		$actions[ 'media-new.php' ] = array( _x( 'Media', 'add new from admin bar' ), 'new-media' );
       
   494 
   497 
   495 	if ( current_user_can( 'manage_links' ) )
   498 	if ( current_user_can( 'manage_links' ) )
   496 		$actions[ 'link-add.php' ] = array( _x( 'Link', 'add new from admin bar' ), 'new-link' );
   499 		$actions[ 'link-add.php' ] = array( _x( 'Link', 'add new from admin bar' ), 'new-link' );
   497 
   500 
   498 	if ( isset( $cpts['page'] ) && current_user_can( $cpts['page']->cap->edit_posts ) ) {
   501 	if ( isset( $cpts['page'] ) && current_user_can( $cpts['page']->cap->create_posts ) )
   499 		$actions[ 'post-new.php?post_type=page' ] = array( $cpts['page']->labels->name_admin_bar, 'new-page' );
   502 		$actions[ 'post-new.php?post_type=page' ] = array( $cpts['page']->labels->name_admin_bar, 'new-page' );
   500 		unset( $cpts['page'] );
   503 
   501 	}
   504 	unset( $cpts['post'], $cpts['page'], $cpts['attachment'] );
   502 
   505 
   503 	// Add any additional custom post types.
   506 	// Add any additional custom post types.
   504 	foreach ( $cpts as $cpt ) {
   507 	foreach ( $cpts as $cpt ) {
   505 		if ( ! current_user_can( $cpt->cap->edit_posts ) )
   508 		if ( ! current_user_can( $cpt->cap->create_posts ) )
   506 			continue;
   509 			continue;
   507 
   510 
   508 		$key = 'post-new.php?post_type=' . $cpt->name;
   511 		$key = 'post-new.php?post_type=' . $cpt->name;
   509 		$actions[ $key ] = array( $cpt->labels->name_admin_bar, 'new-' . $cpt->name );
   512 		$actions[ $key ] = array( $cpt->labels->name_admin_bar, 'new-' . $cpt->name );
   510 	}
   513 	}
       
   514 	// Avoid clash with parent node and a 'content' post type.
       
   515 	if ( isset( $actions['post-new.php?post_type=content'] ) )
       
   516 		$actions['post-new.php?post_type=content'][1] = 'add-new-content';
   511 
   517 
   512 	if ( current_user_can( 'create_users' ) || current_user_can( 'promote_users' ) )
   518 	if ( current_user_can( 'create_users' ) || current_user_can( 'promote_users' ) )
   513 		$actions[ 'user-new.php' ] = array( _x( 'User', 'add new from admin bar' ), 'new-user' );
   519 		$actions[ 'user-new.php' ] = array( _x( 'User', 'add new from admin bar' ), 'new-user' );
   514 
   520 
   515 	if ( ! $actions )
   521 	if ( ! $actions )
   612 
   618 
   613 	if ( !$update_data['counts']['total'] )
   619 	if ( !$update_data['counts']['total'] )
   614 		return;
   620 		return;
   615 
   621 
   616 	$title = '<span class="ab-icon"></span><span class="ab-label">' . number_format_i18n( $update_data['counts']['total'] ) . '</span>';
   622 	$title = '<span class="ab-icon"></span><span class="ab-label">' . number_format_i18n( $update_data['counts']['total'] ) . '</span>';
       
   623 	$title .= '<span class="screen-reader-text">' . $update_data['title'] . '</span>';
   617 
   624 
   618 	$wp_admin_bar->add_menu( array(
   625 	$wp_admin_bar->add_menu( array(
   619 		'id'    => 'updates',
   626 		'id'    => 'updates',
   620 		'title' => $title,
   627 		'title' => $title,
   621 		'href'  => network_admin_url( 'update-core.php' ),
   628 		'href'  => network_admin_url( 'update-core.php' ),
   633 function wp_admin_bar_search_menu( $wp_admin_bar ) {
   640 function wp_admin_bar_search_menu( $wp_admin_bar ) {
   634 	if ( is_admin() )
   641 	if ( is_admin() )
   635 		return;
   642 		return;
   636 
   643 
   637 	$form  = '<form action="' . esc_url( home_url( '/' ) ) . '" method="get" id="adminbarsearch">';
   644 	$form  = '<form action="' . esc_url( home_url( '/' ) ) . '" method="get" id="adminbarsearch">';
   638 	$form .= '<input class="adminbar-input" name="s" id="adminbar-search" tabindex="10" type="text" value="" maxlength="150" />';
   645 	$form .= '<input class="adminbar-input" name="s" id="adminbar-search" type="text" value="" maxlength="150" />';
   639 	$form .= '<input type="submit" class="adminbar-button" value="' . __('Search') . '"/>';
   646 	$form .= '<input type="submit" class="adminbar-button" value="' . __('Search') . '"/>';
   640 	$form .= '</form>';
   647 	$form .= '</form>';
   641 
   648 
   642 	$wp_admin_bar->add_menu( array(
   649 	$wp_admin_bar->add_menu( array(
   643 		'parent' => 'top-secondary',
   650 		'parent' => 'top-secondary',
   721  */
   728  */
   722 function is_admin_bar_showing() {
   729 function is_admin_bar_showing() {
   723 	global $show_admin_bar, $pagenow;
   730 	global $show_admin_bar, $pagenow;
   724 
   731 
   725 	// For all these types of requests, we never want an admin bar.
   732 	// For all these types of requests, we never want an admin bar.
   726 	if ( defined('XMLRPC_REQUEST') || defined('APP_REQUEST') || defined('DOING_AJAX') || defined('IFRAME_REQUEST') )
   733 	if ( defined('XMLRPC_REQUEST') || defined('DOING_AJAX') || defined('IFRAME_REQUEST') )
   727 		return false;
   734 		return false;
   728 
   735 
   729 	// Integrated into the admin.
   736 	// Integrated into the admin.
   730 	if ( is_admin() )
   737 	if ( is_admin() )
   731 		return true;
   738 		return true;