diff --git a/wp-admin/includes/default-list-tables.php b/wp-admin/includes/default-list-tables.php index 973fe3de35..c05fe6dfe3 100644 --- a/wp-admin/includes/default-list-tables.php +++ b/wp-admin/includes/default-list-tables.php @@ -2777,51 +2777,33 @@ class WP_MS_Users_Table extends WP_List_Table { } function prepare_items() { - global $s, $mode, $wpdb; + $usersearch = isset( $_REQUEST['s'] ) ? $_REQUEST['s'] : ''; - $mode = ( empty( $_REQUEST['mode'] ) ) ? 'list' : $_REQUEST['mode']; + $users_per_page = $this->get_items_per_page( 'ms_users_per_page' ); - $per_page = $this->get_items_per_page( 'ms_users_per_page' ); + $paged = $this->get_pagenum(); - $pagenum = $this->get_pagenum(); + $args = array( + 'number' => $users_per_page, + 'offset' => ( $paged-1 ) * $users_per_page, + 'search' => $usersearch, + 'blog_id' => 0 + ); - $s = isset( $_REQUEST['s'] ) ? stripslashes( trim( $_REQUEST[ 's' ] ) ) : ''; - $like_s = esc_sql( like_escape( $s ) ); + if ( isset( $_REQUEST['orderby'] ) ) + $args['orderby'] = $_REQUEST['orderby']; - $query = "SELECT * FROM {$wpdb->users}"; + if ( isset( $_REQUEST['order'] ) ) + $args['order'] = $_REQUEST['order']; - if ( !empty( $like_s ) ) { - $query .= " WHERE user_login LIKE '%$like_s%' OR user_email LIKE '%$like_s%'"; - } - - $order_by = isset( $_REQUEST['orderby'] ) ? $_REQUEST['orderby'] : 'id'; - if ( $order_by == 'email' ) { - $query .= ' ORDER BY user_email '; - } elseif ( $order_by == 'login' ) { - $query .= ' ORDER BY user_login '; - } elseif ( $order_by == 'name' ) { - $query .= ' ORDER BY display_name '; - } elseif ( $order_by == 'registered' ) { - $query .= ' ORDER BY user_registered '; - } else { - $order_by = 'id'; - $query .= ' ORDER BY ID '; - } - - $order = ( isset( $_REQUEST['order'] ) && 'DESC' == strtoupper( $_REQUEST['order'] ) ) ? 'DESC' : 'ASC'; - $query .= $order; - - $total = $wpdb->get_var( str_replace( 'SELECT *', 'SELECT COUNT( ID )', $query ) ); - - $query .= " LIMIT " . intval( ( $pagenum - 1 ) * $per_page ) . ", " . intval( $per_page ); - - $this->items = $wpdb->get_results( $query, ARRAY_A ); - - $num_pages = ceil( $total / $per_page ); + // Query the user IDs for this page + $wp_user_search = new WP_User_Query( $args ); + $this->items = $wp_user_search->get_results(); + $this->set_pagination_args( array( - 'total_items' => $total, - 'per_page' => $per_page, + 'total_items' => $wp_user_search->get_total(), + 'per_page' => $users_per_page, ) ); } @@ -2882,7 +2864,7 @@ class WP_MS_Users_Table extends WP_List_Table { $status_list = array( 'spam' => 'site-spammed', 'deleted' => 'site-deleted' ); foreach ( $status_list as $status => $col ) { - if ( $user[$status] ) + if ( $user->$status ) $class = $col; } @@ -2896,25 +2878,25 @@ class WP_MS_Users_Table extends WP_List_Table { switch ( $column_name ) { case 'cb': ?>