<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[35790] trunk: Show user_login in Dashboard user dropdowns.</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/35790">35790</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/35790","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>boonebgorges</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2015-12-06 20:56:11 +0000 (Sun, 06 Dec 2015)</dd>
</dl>
<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>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 <a href="https://core.trac.wordpress.org/ticket/31251">#31251</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpadminexportphp">trunk/src/wp-admin/export.php</a></li>
<li><a href="#trunksrcwpadminincludesajaxactionsphp">trunk/src/wp-admin/includes/ajax-actions.php</a></li>
<li><a href="#trunksrcwpadminincludesclasswppostslisttablephp">trunk/src/wp-admin/includes/class-wp-posts-list-table.php</a></li>
<li><a href="#trunksrcwpadminincludesmetaboxesphp">trunk/src/wp-admin/includes/meta-boxes.php</a></li>
<li><a href="#trunksrcwpadminusersphp">trunk/src/wp-admin/users.php</a></li>
<li><a href="#trunksrcwpincludesuserphp">trunk/src/wp-includes/user.php</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li><a href="#trunktestsphpunittestsuserwpDropdownUsersphp">trunk/tests/phpunit/tests/user/wpDropdownUsers.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpadminexportphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-admin/export.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/export.php 2015-12-06 20:31:04 UTC (rev 35789)
+++ trunk/src/wp-admin/export.php 2015-12-06 20:56:11 UTC (rev 35790)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -177,8 +177,13 @@
</span><span class="cx" style="display: block; padding: 0 10px"> <label><span class="label-responsive"><?php _e( 'Authors:' ); ?></span>
</span><span class="cx" style="display: block; padding: 0 10px"> <?php
</span><span class="cx" style="display: block; padding: 0 10px"> $authors = $wpdb->get_col( "SELECT DISTINCT post_author FROM {$wpdb->posts} WHERE post_type = 'post'" );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- wp_dropdown_users( array( 'include' => $authors, 'name' => 'post_author', 'multi' => true, 'show_option_all' => __('All') ) );
- ?>
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ wp_dropdown_users( array(
+ 'include' => $authors,
+ 'name' => 'post_author',
+ 'multi' => true,
+ 'show_option_all' => __( 'All' ),
+ 'show' => 'display_name_with_login',
+ ) ); ?>
</ins><span class="cx" style="display: block; padding: 0 10px"> </label>
</span><span class="cx" style="display: block; padding: 0 10px"> </li>
</span><span class="cx" style="display: block; padding: 0 10px"> <li>
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -214,8 +219,13 @@
</span><span class="cx" style="display: block; padding: 0 10px"> <label><span class="label-responsive"><?php _e( 'Authors:' ); ?></span>
</span><span class="cx" style="display: block; padding: 0 10px"> <?php
</span><span class="cx" style="display: block; padding: 0 10px"> $authors = $wpdb->get_col( "SELECT DISTINCT post_author FROM {$wpdb->posts} WHERE post_type = 'page'" );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- wp_dropdown_users( array( 'include' => $authors, 'name' => 'page_author', 'multi' => true, 'show_option_all' => __('All') ) );
- ?>
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ wp_dropdown_users( array(
+ 'include' => $authors,
+ 'name' => 'page_author',
+ 'multi' => true,
+ 'show_option_all' => __( 'All' ),
+ 'show' => 'display_name_with_login',
+ ) ); ?>
</ins><span class="cx" style="display: block; padding: 0 10px"> </label>
</span><span class="cx" style="display: block; padding: 0 10px"> </li>
</span><span class="cx" style="display: block; padding: 0 10px"> <li>
</span></span></pre></div>
<a id="trunksrcwpadminincludesajaxactionsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-admin/includes/ajax-actions.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/includes/ajax-actions.php 2015-12-06 20:31:04 UTC (rev 35789)
+++ trunk/src/wp-admin/includes/ajax-actions.php 2015-12-06 20:56:11 UTC (rev 35790)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -289,7 +289,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> foreach ( $users as $user ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $return[] = array(
</span><span class="cx" style="display: block; padding: 0 10px"> /* translators: 1: user_login, 2: user_email */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'label' => sprintf( __( '%1$s (%2$s)' ), $user->user_login, $user->user_email ),
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'label' => sprintf( _x( '%1$s (%2$s)', 'user autocomplete result' ), $user->user_login, $user->user_email ),
</ins><span class="cx" style="display: block; padding: 0 10px"> 'value' => $user->$field,
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre></div>
<a id="trunksrcwpadminincludesclasswppostslisttablephp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-admin/includes/class-wp-posts-list-table.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/includes/class-wp-posts-list-table.php 2015-12-06 20:31:04 UTC (rev 35789)
+++ trunk/src/wp-admin/includes/class-wp-posts-list-table.php 2015-12-06 20:56:11 UTC (rev 35790)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1335,7 +1335,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'name' => 'post_author',
</span><span class="cx" style="display: block; padding: 0 10px"> 'class'=> 'authors',
</span><span class="cx" style="display: block; padding: 0 10px"> 'multi' => 1,
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'echo' => 0
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'echo' => 0,
+ 'show' => 'display_name_with_login',
</ins><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px"> if ( $bulk )
</span><span class="cx" style="display: block; padding: 0 10px"> $users_opt['show_option_none'] = __( '— No Change —' );
</span></span></pre></div>
<a id="trunksrcwpadminincludesmetaboxesphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-admin/includes/meta-boxes.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/includes/meta-boxes.php 2015-12-06 20:31:04 UTC (rev 35789)
+++ trunk/src/wp-admin/includes/meta-boxes.php 2015-12-06 20:56:11 UTC (rev 35790)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -742,7 +742,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'who' => 'authors',
</span><span class="cx" style="display: block; padding: 0 10px"> 'name' => 'post_author_override',
</span><span class="cx" style="display: block; padding: 0 10px"> 'selected' => empty($post->ID) ? $user_ID : $post->post_author,
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'include_selected' => true
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'include_selected' => true,
+ 'show' => 'display_name_with_login',
</ins><span class="cx" style="display: block; padding: 0 10px"> ) );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span></span></pre></div>
<a id="trunksrcwpadminusersphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-admin/users.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/users.php 2015-12-06 20:31:04 UTC (rev 35789)
+++ trunk/src/wp-admin/users.php 2015-12-06 20:56:11 UTC (rev 35790)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -270,7 +270,11 @@
</span><span class="cx" style="display: block; padding: 0 10px"> <?php _e('Delete all content.'); ?></label></li>
</span><span class="cx" style="display: block; padding: 0 10px"> <li><input type="radio" id="delete_option1" name="delete_option" value="reassign" />
</span><span class="cx" style="display: block; padding: 0 10px"> <?php echo '<label for="delete_option1">' . __( 'Attribute all content to:' ) . '</label> ';
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- wp_dropdown_users( array( 'name' => 'reassign_user', 'exclude' => array_diff( $userids, array($current_user->ID) ) ) ); ?></li>
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ wp_dropdown_users( array(
+ 'name' => 'reassign_user',
+ 'exclude' => array_diff( $userids, array( $current_user->ID ) ),
+ 'show' => 'display_name_with_login',
+ ) ); ?></li>
</ins><span class="cx" style="display: block; padding: 0 10px"> </ul></fieldset>
</span><span class="cx" style="display: block; padding: 0 10px"> <?php endif;
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span></span></pre></div>
<a id="trunksrcwpincludesuserphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/user.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/user.php 2015-12-06 20:31:04 UTC (rev 35789)
+++ trunk/src/wp-includes/user.php 2015-12-06 20:56:11 UTC (rev 35790)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -870,6 +870,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * The available arguments are as follows:
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 2.3.0
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 4.5.0 Added the 'display_name_with_login' value for 'show'.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @global int $blog_id
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -896,9 +897,11 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * Default empty.
</span><span class="cx" style="display: block; padding: 0 10px"> * @type bool|int $multi Whether to skip the ID attribute on the 'select' element.
</span><span class="cx" style="display: block; padding: 0 10px"> * Accepts 1|true or 0|false. Default 0|false.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @type string $show User table column to display. If the selected item is empty
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @type string $show User data to display. If the selected item is empty
</ins><span class="cx" style="display: block; padding: 0 10px"> * then the 'user_login' will be displayed in parentheses.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Accepts user fields. Default 'display_name'.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Accepts any user field, or 'display_name_with_login' to show
+ * the display name with user_login in parentheses.
+ * Default 'display_name'.
</ins><span class="cx" style="display: block; padding: 0 10px"> * @type int|bool $echo Whether to echo or return the drop-down. Accepts 1|true (echo)
</span><span class="cx" style="display: block; padding: 0 10px"> * or 0|false (return). Default 1|true.
</span><span class="cx" style="display: block; padding: 0 10px"> * @type int $selected Which user ID should be selected. Default 0.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -927,14 +930,24 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $defaults['selected'] = is_author() ? get_query_var( 'author' ) : 0;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $r = wp_parse_args( $args, $defaults );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $show = $r['show'];
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ $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;
+
</ins><span class="cx" style="display: block; padding: 0 10px"> $show_option_all = $r['show_option_all'];
</span><span class="cx" style="display: block; padding: 0 10px"> $show_option_none = $r['show_option_none'];
</span><span class="cx" style="display: block; padding: 0 10px"> $option_none_value = $r['option_none_value'];
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $query_args = wp_array_slice_assoc( $r, array( 'blog_id', 'include', 'exclude', 'orderby', 'order', 'who' ) );
- $query_args['fields'] = array( 'ID', 'user_login', $show );
-
</del><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Filter the query arguments for the user drop-down.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -966,21 +979,32 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $output .= "\t<option value='" . esc_attr( $option_none_value ) . "'$_selected>$show_option_none</option>\n";
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $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;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 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;
+ }
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $display = ! empty( $user->$show ) ? $user->$show : '('. $user->user_login . ')';
- $output .= "\t<option value='$user->ID'$_selected>" . esc_html( $display ) . "</option>\n";
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ if ( ! $found_selected ) {
+ $users[] = get_userdata( $r['selected'] );
+ }
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( $r['include_selected'] && ! $found_selected && ( $r['selected'] > 0 ) ) {
- $user = get_userdata( $r['selected'] );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 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 . ')';
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> $_selected = selected( $user->ID, $r['selected'], false );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $display = ! empty( $user->$show ) ? $user->$show : '('. $user->user_login . ')';
</del><span class="cx" style="display: block; padding: 0 10px"> $output .= "\t<option value='$user->ID'$_selected>" . esc_html( $display ) . "</option>\n";
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span></span></pre></div>
<a id="trunktestsphpunittestsuserwpDropdownUsersphp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: trunk/tests/phpunit/tests/user/wpDropdownUsers.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/user/wpDropdownUsers.php (rev 0)
+++ trunk/tests/phpunit/tests/user/wpDropdownUsers.php 2015-12-06 20:56:11 UTC (rev 35790)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,113 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+
+/**
+ * Test functions in wp-includes/user.php
+ *
+ * @group user
+ */
+class Tests_User_WpDropdownUsers extends WP_UnitTestCase {
+
+ /**
+ * @ticket 31251
+ */
+ public function test_default_value_of_show_should_be_display_name() {
+
+ // create a user with a different display_name
+ $u = $this->factory->user->create( array(
+ 'user_login' => 'foo',
+ 'display_name' => 'Foo Person'
+ ) );
+
+ $found = wp_dropdown_users( array(
+ 'echo' => false
+ ) );
+
+ $expected = "<option value='$u'>Foo Person</option>";
+
+ $this->assertContains( $expected, $found );
+ }
+
+ /**
+ * @ticket 31251
+ */
+ public function test_show_should_display_display_name_show_is_specified_as_empty() {
+
+ // create a user with a different display_name
+ $u = $this->factory->user->create( array(
+ 'user_login' => 'foo',
+ 'display_name' => 'Foo Person'
+ ) );
+
+ // Get the result of a non-default, but acceptable input for 'show' parameter to wp_dropdown_users().
+ $found = wp_dropdown_users( array(
+ 'echo' => false,
+ 'show' => ''
+ ) );
+
+ $expected = "<option value='$u'>Foo Person</option>";
+
+ $this->assertContains( $expected, $found );
+ }
+
+ /**
+ * @ticket 31251
+ */
+ public function test_show_should_display_user_property_when_the_value_of_show_is_a_valid_user_property() {
+
+ // create a user with a different display_name
+ $u = $this->factory->user->create( array(
+ 'user_login' => 'foo',
+ 'display_name' => 'Foo Person'
+ ) );
+
+ // Get the result of a non-default, but acceptable input for 'show' parameter to wp_dropdown_users().
+ $found = wp_dropdown_users( array(
+ 'echo' => false,
+ 'show' => 'user_login'
+ ) );
+
+ $expected = "<option value='$u'>foo</option>";
+
+ $this->assertContains( $expected, $found );
+ }
+
+ /**
+ * @ticket 31251
+ */
+ public function test_show_display_name_with_login() {
+
+ // create a user with a different display_name
+ $u = $this->factory->user->create( array(
+ 'user_login' => 'foo',
+ 'display_name' => 'Foo Person'
+ ) );
+
+ // Get the result of a non-default, but acceptable input for 'show' parameter to wp_dropdown_users().
+ $found = wp_dropdown_users( array(
+ 'echo' => false,
+ 'show' => 'display_name_with_login'
+ ) );
+
+ $expected = "<option value='$u'>Foo Person (foo)</option>";
+
+ $this->assertContains( $expected, $found );
+ }
+
+ /**
+ * @ticket 31251
+ */
+ public function test_include_selected() {
+ $users = self::factory()->user->create_many( 2 );
+
+ $found = wp_dropdown_users( array(
+ 'echo' => false,
+ 'include' => $users[0],
+ 'selected' => $users[1],
+ 'include_selected' => true,
+ 'show' => 'user_login',
+ ) );
+
+ $user1 = get_userdata( $users[1] );
+ $this->assertContains( $user1->user_login, $found );
+ }
+}
</ins></span></pre>
</div>
</div>
</body>
</html>