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
This commit is contained in:
parent
2cd2cb6e17
commit
714be37ea5
|
@ -177,8 +177,13 @@ function export_date_options( $post_type = 'post' ) {
|
||||||
<label><span class="label-responsive"><?php _e( 'Authors:' ); ?></span>
|
<label><span class="label-responsive"><?php _e( 'Authors:' ); ?></span>
|
||||||
<?php
|
<?php
|
||||||
$authors = $wpdb->get_col( "SELECT DISTINCT post_author FROM {$wpdb->posts} WHERE post_type = 'post'" );
|
$authors = $wpdb->get_col( "SELECT DISTINCT post_author FROM {$wpdb->posts} WHERE post_type = 'post'" );
|
||||||
wp_dropdown_users( array( 'include' => $authors, 'name' => 'post_author', 'multi' => true, 'show_option_all' => __('All') ) );
|
wp_dropdown_users( array(
|
||||||
?>
|
'include' => $authors,
|
||||||
|
'name' => 'post_author',
|
||||||
|
'multi' => true,
|
||||||
|
'show_option_all' => __( 'All' ),
|
||||||
|
'show' => 'display_name_with_login',
|
||||||
|
) ); ?>
|
||||||
</label>
|
</label>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
|
@ -214,8 +219,13 @@ function export_date_options( $post_type = 'post' ) {
|
||||||
<label><span class="label-responsive"><?php _e( 'Authors:' ); ?></span>
|
<label><span class="label-responsive"><?php _e( 'Authors:' ); ?></span>
|
||||||
<?php
|
<?php
|
||||||
$authors = $wpdb->get_col( "SELECT DISTINCT post_author FROM {$wpdb->posts} WHERE post_type = 'page'" );
|
$authors = $wpdb->get_col( "SELECT DISTINCT post_author FROM {$wpdb->posts} WHERE post_type = 'page'" );
|
||||||
wp_dropdown_users( array( 'include' => $authors, 'name' => 'page_author', 'multi' => true, 'show_option_all' => __('All') ) );
|
wp_dropdown_users( array(
|
||||||
?>
|
'include' => $authors,
|
||||||
|
'name' => 'page_author',
|
||||||
|
'multi' => true,
|
||||||
|
'show_option_all' => __( 'All' ),
|
||||||
|
'show' => 'display_name_with_login',
|
||||||
|
) ); ?>
|
||||||
</label>
|
</label>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
|
|
|
@ -289,7 +289,7 @@ function wp_ajax_autocomplete_user() {
|
||||||
foreach ( $users as $user ) {
|
foreach ( $users as $user ) {
|
||||||
$return[] = array(
|
$return[] = array(
|
||||||
/* translators: 1: user_login, 2: user_email */
|
/* 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,
|
'value' => $user->$field,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1335,7 +1335,8 @@ class WP_Posts_List_Table extends WP_List_Table {
|
||||||
'name' => 'post_author',
|
'name' => 'post_author',
|
||||||
'class'=> 'authors',
|
'class'=> 'authors',
|
||||||
'multi' => 1,
|
'multi' => 1,
|
||||||
'echo' => 0
|
'echo' => 0,
|
||||||
|
'show' => 'display_name_with_login',
|
||||||
);
|
);
|
||||||
if ( $bulk )
|
if ( $bulk )
|
||||||
$users_opt['show_option_none'] = __( '— No Change —' );
|
$users_opt['show_option_none'] = __( '— No Change —' );
|
||||||
|
|
|
@ -742,7 +742,8 @@ function post_author_meta_box($post) {
|
||||||
'who' => 'authors',
|
'who' => 'authors',
|
||||||
'name' => 'post_author_override',
|
'name' => 'post_author_override',
|
||||||
'selected' => empty($post->ID) ? $user_ID : $post->post_author,
|
'selected' => empty($post->ID) ? $user_ID : $post->post_author,
|
||||||
'include_selected' => true
|
'include_selected' => true,
|
||||||
|
'show' => 'display_name_with_login',
|
||||||
) );
|
) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -270,7 +270,11 @@ case 'delete':
|
||||||
<?php _e('Delete all content.'); ?></label></li>
|
<?php _e('Delete all content.'); ?></label></li>
|
||||||
<li><input type="radio" id="delete_option1" name="delete_option" value="reassign" />
|
<li><input type="radio" id="delete_option1" name="delete_option" value="reassign" />
|
||||||
<?php echo '<label for="delete_option1">' . __( 'Attribute all content to:' ) . '</label> ';
|
<?php echo '<label for="delete_option1">' . __( 'Attribute all content to:' ) . '</label> ';
|
||||||
wp_dropdown_users( array( 'name' => 'reassign_user', 'exclude' => array_diff( $userids, array($current_user->ID) ) ) ); ?></li>
|
wp_dropdown_users( array(
|
||||||
|
'name' => 'reassign_user',
|
||||||
|
'exclude' => array_diff( $userids, array( $current_user->ID ) ),
|
||||||
|
'show' => 'display_name_with_login',
|
||||||
|
) ); ?></li>
|
||||||
</ul></fieldset>
|
</ul></fieldset>
|
||||||
<?php endif;
|
<?php endif;
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -870,6 +870,7 @@ function setup_userdata($for_user_id = '') {
|
||||||
* The available arguments are as follows:
|
* The available arguments are as follows:
|
||||||
*
|
*
|
||||||
* @since 2.3.0
|
* @since 2.3.0
|
||||||
|
* @since 4.5.0 Added the 'display_name_with_login' value for 'show'.
|
||||||
*
|
*
|
||||||
* @global int $blog_id
|
* @global int $blog_id
|
||||||
*
|
*
|
||||||
|
@ -896,9 +897,11 @@ function setup_userdata($for_user_id = '') {
|
||||||
* Default empty.
|
* Default empty.
|
||||||
* @type bool|int $multi Whether to skip the ID attribute on the 'select' element.
|
* @type bool|int $multi Whether to skip the ID attribute on the 'select' element.
|
||||||
* Accepts 1|true or 0|false. Default 0|false.
|
* Accepts 1|true or 0|false. Default 0|false.
|
||||||
* @type string $show User table column to display. If the selected item is empty
|
* @type string $show User data to display. If the selected item is empty
|
||||||
* then the 'user_login' will be displayed in parentheses.
|
* then the 'user_login' will be displayed in parentheses.
|
||||||
* Accepts user fields. Default 'display_name'.
|
* Accepts any user field, or 'display_name_with_login' to show
|
||||||
|
* the display name with user_login in parentheses.
|
||||||
|
* Default 'display_name'.
|
||||||
* @type int|bool $echo Whether to echo or return the drop-down. Accepts 1|true (echo)
|
* @type int|bool $echo Whether to echo or return the drop-down. Accepts 1|true (echo)
|
||||||
* or 0|false (return). Default 1|true.
|
* or 0|false (return). Default 1|true.
|
||||||
* @type int $selected Which user ID should be selected. Default 0.
|
* @type int $selected Which user ID should be selected. Default 0.
|
||||||
|
@ -927,14 +930,24 @@ function wp_dropdown_users( $args = '' ) {
|
||||||
$defaults['selected'] = is_author() ? get_query_var( 'author' ) : 0;
|
$defaults['selected'] = is_author() ? get_query_var( 'author' ) : 0;
|
||||||
|
|
||||||
$r = wp_parse_args( $args, $defaults );
|
$r = wp_parse_args( $args, $defaults );
|
||||||
$show = $r['show'];
|
|
||||||
|
$query_args = wp_array_slice_assoc( $r, array( 'blog_id', 'include', 'exclude', 'orderby', 'order', 'who' ) );
|
||||||
|
|
||||||
|
$fields = array( 'ID', 'user_login' );
|
||||||
|
|
||||||
|
$show = ! empty( $r['show'] ) ? $r['show'] : 'display_name';
|
||||||
|
if ( 'display_name_with_login' === $show ) {
|
||||||
|
$fields[] = 'display_name';
|
||||||
|
} else {
|
||||||
|
$fields[] = $show;
|
||||||
|
}
|
||||||
|
|
||||||
|
$query_args['fields'] = $fields;
|
||||||
|
|
||||||
$show_option_all = $r['show_option_all'];
|
$show_option_all = $r['show_option_all'];
|
||||||
$show_option_none = $r['show_option_none'];
|
$show_option_none = $r['show_option_none'];
|
||||||
$option_none_value = $r['option_none_value'];
|
$option_none_value = $r['option_none_value'];
|
||||||
|
|
||||||
$query_args = wp_array_slice_assoc( $r, array( 'blog_id', 'include', 'exclude', 'orderby', 'order', 'who' ) );
|
|
||||||
$query_args['fields'] = array( 'ID', 'user_login', $show );
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Filter the query arguments for the user drop-down.
|
* Filter the query arguments for the user drop-down.
|
||||||
*
|
*
|
||||||
|
@ -966,21 +979,32 @@ function wp_dropdown_users( $args = '' ) {
|
||||||
$output .= "\t<option value='" . esc_attr( $option_none_value ) . "'$_selected>$show_option_none</option>\n";
|
$output .= "\t<option value='" . esc_attr( $option_none_value ) . "'$_selected>$show_option_none</option>\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( $r['include_selected'] && ( $r['selected'] > 0 ) ) {
|
||||||
$found_selected = false;
|
$found_selected = false;
|
||||||
|
$r['selected'] = (int) $r['selected'];
|
||||||
foreach ( (array) $users as $user ) {
|
foreach ( (array) $users as $user ) {
|
||||||
$user->ID = (int) $user->ID;
|
$user->ID = (int) $user->ID;
|
||||||
$_selected = selected( $user->ID, $r['selected'], false );
|
if ( $user->ID === $r['selected'] ) {
|
||||||
if ( $_selected ) {
|
|
||||||
$found_selected = true;
|
$found_selected = true;
|
||||||
}
|
}
|
||||||
$display = ! empty( $user->$show ) ? $user->$show : '('. $user->user_login . ')';
|
|
||||||
$output .= "\t<option value='$user->ID'$_selected>" . esc_html( $display ) . "</option>\n";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $r['include_selected'] && ! $found_selected && ( $r['selected'] > 0 ) ) {
|
if ( ! $found_selected ) {
|
||||||
$user = get_userdata( $r['selected'] );
|
$users[] = 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 );
|
$_selected = selected( $user->ID, $r['selected'], false );
|
||||||
$display = ! empty( $user->$show ) ? $user->$show : '('. $user->user_login . ')';
|
|
||||||
$output .= "\t<option value='$user->ID'$_selected>" . esc_html( $display ) . "</option>\n";
|
$output .= "\t<option value='$user->ID'$_selected>" . esc_html( $display ) . "</option>\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @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.
|
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||||
|
|
Loading…
Reference in New Issue