WordPress.org

Make WordPress Core

Ticket #7977: import-usability-sorting.diff

File import-usability-sorting.diff, 2.2 KB (added by tott, 5 years ago)

revised diff with only sorting and limit to indexed values

  • wp-includes/user.php

     
    226226 * @uses $blog_id The Blog id of the blog for those that use more than one blog 
    227227 * 
    228228 * @param int $id Blog ID. 
     229 * @param string $sort_field optional Sort Field. user_login, user_id 
    229230 * @return array List of users that are part of that Blog ID 
    230231 */ 
    231 function get_users_of_blog( $id = '' ) { 
    232         global $wpdb, $blog_id; 
     232function get_users_of_blog( $id = '', $sort_field = 'user_id' ) { 
     233    global $wpdb; 
     234    $possible_sort_fields = array( 'user_login', 'user_id' ); 
    233235        if ( empty($id) ) 
    234                 $id = (int) $blog_id; 
    235         $users = $wpdb->get_results( "SELECT user_id, user_login, display_name, user_email, meta_value FROM $wpdb->users, $wpdb->usermeta WHERE " . $wpdb->users . ".ID = " . $wpdb->usermeta . ".user_id AND meta_key = '" . $wpdb->prefix . "capabilities' ORDER BY {$wpdb->usermeta}.user_id" ); 
    236         return $users; 
     236                $id = (int) $wpdb->blogid; 
     237     
     238    if ( ! in_array( $sort_field, $possible_sort_fields ) ) 
     239        $sort_field = 'user_id'; 
     240 
     241    switch( $sort_field ) { 
     242    case 'user_login': 
     243        $order = "{$wpdb->users}.user_login"; 
     244        break; 
     245    case 'user_id': 
     246        $order = "{$wpdb->usermeta}.user_id"; 
     247        break;  
     248    } 
     249    $users = $wpdb->get_results( "SELECT user_id, user_login, display_name, user_email, meta_value FROM $wpdb->users, $wpdb->usermeta WHERE {$wpdb->users}.user_login != '' && {$wpdb->users}.ID = {$wpdb->usermeta}.user_id AND meta_key = '{$wpdb->prefix}capabilities' ORDER BY {$order}" ); 
     250    return $users; 
    237251} 
    238252 
    239253// 
  • wp-admin/import/wordpress.php

     
    251251                // keep track of $n => $author name 
    252252                echo '<input type="hidden" name="author_in['.intval($n).']" value="'.htmlspecialchars($author).'" />'; 
    253253 
    254                 $users = get_users_of_blog(); 
     254                $users = get_users_of_blog( null, 'user_login' ); 
    255255?><select name="user_select[<?php echo $n; ?>]"> 
    256256        <option value="0"><?php _e('- Select -'); ?></option> 
    257257        <?php