WordPress.org

Make WordPress Core

Ticket #7977: 7977.diff

File 7977.diff, 1.6 KB (added by wojtek.szkutnik, 8 years ago)
  • wp-includes/user.php

     
    336336 * @uses $blog_id The Blog id of the blog for those that use more than one blog
    337337 *
    338338 * @param int $id Blog ID.
     339 * @param string $sort_field optional Sort Field. user_login, user_id
    339340 * @return array List of users that are part of that Blog ID
    340341 */
    341 function get_users_of_blog( $id = '' ) {
    342         global $wpdb, $blog_id;
     342function get_users_of_blog( $id = '', $sort_field = 'user_id' ) {
     343        global $wpdb;
     344        $possible_sort_fields = array( 'user_login', 'user_id' );
     345       
    343346        if ( empty($id) )
    344                 $id = (int) $blog_id;
     347                $id = (int) $wpdb->blog_id;
     348               
     349        if ( ! in_array( $sort_field, $possible_sort_fields ) )
     350                $sort_field = 'user_id';
     351       
     352        $orders = Array(
     353                                        'user_login' => "{$wpdb->users}.user_login",
     354                                        'user_id' => "{$wpdb->usermeta}.user_id",
     355                                        );
     356       
     357        $order = $orders[$sort_field];
    345358        $blog_prefix = $wpdb->get_blog_prefix($id);
    346         $users = $wpdb->get_results( "SELECT user_id, user_id AS 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 = '{$blog_prefix}capabilities' ORDER BY {$wpdb->usermeta}.user_id" );
     359        $users = $wpdb->get_results( "SELECT user_id, user_id AS ID, user_login, display_name, user_email, meta_value FROM $wpdb->users, $wpdb->usermeta WHERE {$wpdb->users}.user_login != '' AND {$wpdb->users}.ID = {$wpdb->usermeta}.user_id AND meta_key = '{$blog_prefix}capabilities' ORDER BY {$order}" );
    347360        return $users;
    348361}
    349362