From c6c413403dc47aa12287d63e0d2cfc0bebf0a930 Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Wed, 26 Jul 2017 16:44:34 +0000 Subject: [PATCH] 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 --- src/wp-includes/admin-bar.php | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/admin-bar.php b/src/wp-includes/admin-bar.php index 7ff55febe2..4bd49ed89a 100644 --- a/src/wp-includes/admin-bar.php +++ b/src/wp-includes/admin-bar.php @@ -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, + ) ); } } }