WordPress.org

Make WordPress Core

Changeset 35790


Ignore:
Timestamp:
12/06/2015 08:56:11 PM (5 years ago)
Author:
boonebgorges
Message:

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.

Location:
trunk
Files:
1 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/export.php

    r35316 r35790  
    178178        <?php
    179179        $authors = $wpdb->get_col( "SELECT DISTINCT post_author FROM {$wpdb->posts} WHERE post_type = 'post'" );
    180         wp_dropdown_users( array( 'include' => $authors, 'name' => 'post_author', 'multi' => true, 'show_option_all' => __('All') ) );
    181         ?>
     180        wp_dropdown_users( array(
     181            'include' => $authors,
     182            'name' => 'post_author',
     183            'multi' => true,
     184            'show_option_all' => __( 'All' ),
     185            'show' => 'display_name_with_login',
     186        ) ); ?>
    182187        </label>
    183188    </li>
     
    215220        <?php
    216221        $authors = $wpdb->get_col( "SELECT DISTINCT post_author FROM {$wpdb->posts} WHERE post_type = 'page'" );
    217         wp_dropdown_users( array( 'include' => $authors, 'name' => 'page_author', 'multi' => true, 'show_option_all' => __('All') ) );
    218         ?>
     222        wp_dropdown_users( array(
     223            'include' => $authors,
     224            'name' => 'page_author',
     225            'multi' => true,
     226            'show_option_all' => __( 'All' ),
     227            'show' => 'display_name_with_login',
     228        ) ); ?>
    219229        </label>
    220230    </li>
  • trunk/src/wp-admin/includes/ajax-actions.php

    r35760 r35790  
    290290        $return[] = array(
    291291            /* translators: 1: user_login, 2: user_email */
    292             'label' => sprintf( __( '%1$s (%2$s)' ), $user->user_login, $user->user_email ),
     292            'label' => sprintf( _x( '%1$s (%2$s)', 'user autocomplete result' ), $user->user_login, $user->user_email ),
    293293            'value' => $user->$field,
    294294        );
  • trunk/src/wp-admin/includes/class-wp-posts-list-table.php

    r35683 r35790  
    13361336                    'class'=> 'authors',
    13371337                    'multi' => 1,
    1338                     'echo' => 0
     1338                    'echo' => 0,
     1339                    'show' => 'display_name_with_login',
    13391340                );
    13401341                if ( $bulk )
  • trunk/src/wp-admin/includes/meta-boxes.php

    r35609 r35790  
    743743        'name' => 'post_author_override',
    744744        'selected' => empty($post->ID) ? $user_ID : $post->post_author,
    745         'include_selected' => true
     745        'include_selected' => true,
     746        'show' => 'display_name_with_login',
    746747    ) );
    747748}
  • trunk/src/wp-admin/users.php

    r35558 r35790  
    271271            <li><input type="radio" id="delete_option1" name="delete_option" value="reassign" />
    272272            <?php echo '<label for="delete_option1">' . __( 'Attribute all content to:' ) . '</label> ';
    273             wp_dropdown_users( array( 'name' => 'reassign_user', 'exclude' => array_diff( $userids, array($current_user->ID) ) ) ); ?></li>
     273            wp_dropdown_users( array(
     274                'name' => 'reassign_user',
     275                'exclude' => array_diff( $userids, array( $current_user->ID ) ),
     276                'show' => 'display_name_with_login',
     277            ) ); ?></li>
    274278        </ul></fieldset>
    275279    <?php endif;
  • trunk/src/wp-includes/user.php

    r35772 r35790  
    871871 *
    872872 * @since 2.3.0
     873 * @since 4.5.0 Added the 'display_name_with_login' value for 'show'.
    873874 *
    874875 * @global int  $blog_id
     
    897898 *     @type bool|int     $multi                   Whether to skip the ID attribute on the 'select' element.
    898899 *                                                 Accepts 1|true or 0|false. Default 0|false.
    899  *     @type string       $show                    User table column to display. If the selected item is empty
     900 *     @type string       $show                    User data to display. If the selected item is empty
    900901 *                                                 then the 'user_login' will be displayed in parentheses.
    901  *                                                 Accepts user fields. Default 'display_name'.
     902 *                                                 Accepts any user field, or 'display_name_with_login' to show
     903 *                                                 the display name with user_login in parentheses.
     904 *                                                 Default 'display_name'.
    902905 *     @type int|bool     $echo                    Whether to echo or return the drop-down. Accepts 1|true (echo)
    903906 *                                                 or 0|false (return). Default 1|true.
     
    928931
    929932    $r = wp_parse_args( $args, $defaults );
    930     $show = $r['show'];
     933
     934    $query_args = wp_array_slice_assoc( $r, array( 'blog_id', 'include', 'exclude', 'orderby', 'order', 'who' ) );
     935
     936    $fields = array( 'ID', 'user_login' );
     937
     938    $show = ! empty( $r['show'] ) ? $r['show'] : 'display_name';
     939    if ( 'display_name_with_login' === $show ) {
     940        $fields[] = 'display_name';
     941    } else {
     942        $fields[] = $show;
     943    }
     944
     945    $query_args['fields'] = $fields;
     946
    931947    $show_option_all = $r['show_option_all'];
    932948    $show_option_none = $r['show_option_none'];
    933949    $option_none_value = $r['option_none_value'];
    934 
    935     $query_args = wp_array_slice_assoc( $r, array( 'blog_id', 'include', 'exclude', 'orderby', 'order', 'who' ) );
    936     $query_args['fields'] = array( 'ID', 'user_login', $show );
    937950
    938951    /**
     
    967980        }
    968981
    969         $found_selected = false;
     982        if ( $r['include_selected'] && ( $r['selected'] > 0 ) ) {
     983            $found_selected = false;
     984            $r['selected'] = (int) $r['selected'];
     985            foreach ( (array) $users as $user ) {
     986                $user->ID = (int) $user->ID;
     987                if ( $user->ID === $r['selected'] ) {
     988                    $found_selected = true;
     989                }
     990            }
     991
     992            if ( ! $found_selected ) {
     993                $users[] = get_userdata( $r['selected'] );
     994            }
     995        }
     996
    970997        foreach ( (array) $users as $user ) {
    971             $user->ID = (int) $user->ID;
     998            if ( 'display_name_with_login' === $show ) {
     999                /* translators: 1: display name, 2: user_login */
     1000                $display = sprintf( _x( '%1$s (%2$s)', 'user dropdown' ), $user->display_name, $user->user_login );
     1001            } elseif ( ! empty( $user->$show ) ) {
     1002                $display = $user->$show;
     1003            } else {
     1004                $display = '(' . $user->user_login . ')';
     1005            }
     1006
    9721007            $_selected = selected( $user->ID, $r['selected'], false );
    973             if ( $_selected ) {
    974                 $found_selected = true;
    975             }
    976             $display = ! empty( $user->$show ) ? $user->$show : '('. $user->user_login . ')';
    977             $output .= "\t<option value='$user->ID'$_selected>" . esc_html( $display ) . "</option>\n";
    978         }
    979 
    980         if ( $r['include_selected'] && ! $found_selected && ( $r['selected'] > 0 ) ) {
    981             $user = get_userdata( $r['selected'] );
    982             $_selected = selected( $user->ID, $r['selected'], false );
    983             $display = ! empty( $user->$show ) ? $user->$show : '('. $user->user_login . ')';
    9841008            $output .= "\t<option value='$user->ID'$_selected>" . esc_html( $display ) . "</option>\n";
    9851009        }
Note: See TracChangeset for help on using the changeset viewer.