Toolbar: Add `View User` and `Edit User` links to the admin toolbar to ease navigation between a user's archives and the user editing screen.

Props georgestephanis, lessbloat, johnbillion

Fixes #20307


git-svn-id: https://develop.svn.wordpress.org/trunk@41159 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
John Blackbourn 2017-07-26 16:44:34 +00:00
parent e6028d9c6c
commit c6c413403d
1 changed files with 21 additions and 1 deletions

View File

@ -598,7 +598,7 @@ function wp_admin_bar_shortlink_menu( $wp_admin_bar ) {
* @param WP_Admin_Bar $wp_admin_bar
*/
function wp_admin_bar_edit_menu( $wp_admin_bar ) {
global $tag, $wp_the_query;
global $tag, $wp_the_query, $user_id;
if ( is_admin() ) {
$current_screen = get_current_screen();
@ -648,6 +648,17 @@ function wp_admin_bar_edit_menu( $wp_admin_bar ) {
'title' => $tax->labels->view_item,
'href' => get_term_link( $tag )
) );
} elseif ( 'user-edit' == $current_screen->base
&& isset( $user_id )
&& ( $user_object = get_userdata( $user_id ) )
&& $user_object->exists()
&& $view_link = get_author_posts_url( $user_object->ID ) )
{
$wp_admin_bar->add_menu( array(
'id' => 'view',
'title' => __( 'View User' ),
'href' => $view_link,
) );
}
} else {
$current_object = $wp_the_query->get_queried_object();
@ -676,6 +687,15 @@ function wp_admin_bar_edit_menu( $wp_admin_bar ) {
'title' => $tax->labels->edit_item,
'href' => $edit_term_link
) );
} elseif ( is_a( $current_object, 'WP_User' )
&& current_user_can( 'edit_user', $current_object->ID )
&& $edit_user_link = get_edit_user_link( $current_object->ID ) )
{
$wp_admin_bar->add_menu( array(
'id' => 'edit',
'title' => __( 'Edit User' ),
'href' => $edit_user_link,
) );
}
}
}