From 714be37ea5e08e80b971f88159fb99c2446d54c8 Mon Sep 17 00:00:00 2001 From: Boone Gorges Date: Sun, 6 Dec 2015 20:57:26 +0000 Subject: [PATCH] Show user_login in Dashboard user dropdowns. User dropdowns in wp-admin have traditionally shown the users' display names. However, this causes ambiguity when users share display names. To correct this, we now show the unique user_login in parentheses after the display name. The new `display_name_with_login` value for the `show` parameter of `wp_dropdown_users()` enables this functionality. The default value of `show` has not been changed, for backward compatibility, but all instances of `wp_dropdown_users()` in core wp-admin have been switched. This changeset also reduces some duplicated logic when assembling a user list when `include_selected` is true. Props krogsgard, boonebgorges. Fixes #31251. Built from https://develop.svn.wordpress.org/trunk@35790 git-svn-id: http://core.svn.wordpress.org/trunk@35754 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/export.php | 18 ++++-- wp-admin/includes/ajax-actions.php | 2 +- .../includes/class-wp-posts-list-table.php | 3 +- wp-admin/includes/meta-boxes.php | 3 +- wp-admin/users.php | 6 +- wp-includes/user.php | 58 +++++++++++++------ wp-includes/version.php | 2 +- 7 files changed, 66 insertions(+), 26 deletions(-) diff --git a/wp-admin/export.php b/wp-admin/export.php index 7f416c4656..6efb7a7510 100644 --- a/wp-admin/export.php +++ b/wp-admin/export.php @@ -177,8 +177,13 @@ function export_date_options( $post_type = 'post' ) {
  • @@ -214,8 +219,13 @@ function export_date_options( $post_type = 'post' ) {
  • diff --git a/wp-admin/includes/ajax-actions.php b/wp-admin/includes/ajax-actions.php index 58734452f9..47a1fb0eb6 100644 --- a/wp-admin/includes/ajax-actions.php +++ b/wp-admin/includes/ajax-actions.php @@ -289,7 +289,7 @@ function wp_ajax_autocomplete_user() { foreach ( $users as $user ) { $return[] = array( /* translators: 1: user_login, 2: user_email */ - 'label' => sprintf( __( '%1$s (%2$s)' ), $user->user_login, $user->user_email ), + 'label' => sprintf( _x( '%1$s (%2$s)', 'user autocomplete result' ), $user->user_login, $user->user_email ), 'value' => $user->$field, ); } diff --git a/wp-admin/includes/class-wp-posts-list-table.php b/wp-admin/includes/class-wp-posts-list-table.php index d52ebc9832..8a1cd65d18 100644 --- a/wp-admin/includes/class-wp-posts-list-table.php +++ b/wp-admin/includes/class-wp-posts-list-table.php @@ -1335,7 +1335,8 @@ class WP_Posts_List_Table extends WP_List_Table { 'name' => 'post_author', 'class'=> 'authors', 'multi' => 1, - 'echo' => 0 + 'echo' => 0, + 'show' => 'display_name_with_login', ); if ( $bulk ) $users_opt['show_option_none'] = __( '— No Change —' ); diff --git a/wp-admin/includes/meta-boxes.php b/wp-admin/includes/meta-boxes.php index 1627b1f577..f52af1470e 100644 --- a/wp-admin/includes/meta-boxes.php +++ b/wp-admin/includes/meta-boxes.php @@ -742,7 +742,8 @@ function post_author_meta_box($post) { 'who' => 'authors', 'name' => 'post_author_override', 'selected' => empty($post->ID) ? $user_ID : $post->post_author, - 'include_selected' => true + 'include_selected' => true, + 'show' => 'display_name_with_login', ) ); } diff --git a/wp-admin/users.php b/wp-admin/users.php index cdf0d8b372..44d860ecfa 100644 --- a/wp-admin/users.php +++ b/wp-admin/users.php @@ -270,7 +270,11 @@ case 'delete':
  • ' . __( 'Attribute all content to:' ) . ' '; - wp_dropdown_users( array( 'name' => 'reassign_user', 'exclude' => array_diff( $userids, array($current_user->ID) ) ) ); ?>
  • + wp_dropdown_users( array( + 'name' => 'reassign_user', + 'exclude' => array_diff( $userids, array( $current_user->ID ) ), + 'show' => 'display_name_with_login', + ) ); ?> $show_option_none\n"; } - $found_selected = false; - foreach ( (array) $users as $user ) { - $user->ID = (int) $user->ID; - $_selected = selected( $user->ID, $r['selected'], false ); - if ( $_selected ) { - $found_selected = true; + if ( $r['include_selected'] && ( $r['selected'] > 0 ) ) { + $found_selected = false; + $r['selected'] = (int) $r['selected']; + foreach ( (array) $users as $user ) { + $user->ID = (int) $user->ID; + if ( $user->ID === $r['selected'] ) { + $found_selected = true; + } + } + + if ( ! $found_selected ) { + $users[] = get_userdata( $r['selected'] ); } - $display = ! empty( $user->$show ) ? $user->$show : '('. $user->user_login . ')'; - $output .= "\t\n"; } - if ( $r['include_selected'] && ! $found_selected && ( $r['selected'] > 0 ) ) { - $user = get_userdata( $r['selected'] ); + foreach ( (array) $users as $user ) { + if ( 'display_name_with_login' === $show ) { + /* translators: 1: display name, 2: user_login */ + $display = sprintf( _x( '%1$s (%2$s)', 'user dropdown' ), $user->display_name, $user->user_login ); + } elseif ( ! empty( $user->$show ) ) { + $display = $user->$show; + } else { + $display = '(' . $user->user_login . ')'; + } + $_selected = selected( $user->ID, $r['selected'], false ); - $display = ! empty( $user->$show ) ? $user->$show : '('. $user->user_login . ')'; $output .= "\t\n"; } diff --git a/wp-includes/version.php b/wp-includes/version.php index aafc5b70c3..67c909a7d1 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.5-alpha-35789'; +$wp_version = '4.5-alpha-35790'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.