diff --git a/wp-admin/includes/default-list-tables.php b/wp-admin/includes/default-list-tables.php
index 6fa228eded..845d922960 100644
--- a/wp-admin/includes/default-list-tables.php
+++ b/wp-admin/includes/default-list-tables.php
@@ -1794,8 +1794,7 @@ class WP_Users_Table extends WP_List_Table {
$style = '';
foreach ( $this->items as $userid => $user_object ) {
- $roles = $user_object->roles;
- $role = array_shift( $roles );
+ $role = reset( $user_object->roles );
if ( is_multisite() && empty( $role ) )
continue;
@@ -2791,10 +2790,10 @@ class WP_Sites_Table extends WP_List_Table {
$blogusers = array_slice( $blogusers, 0, 5 );
$blogusers_warning = __( 'Only showing first 5 users.' ) . ' ' . __( 'More' ) . '';
}
- foreach ( $blogusers as $key => $val ) {
- echo '' . esc_html( $val->user_login ) . ' ';
+ foreach ( $blogusers as $user_object ) {
+ echo '' . esc_html( $user_object->user_login ) . ' ';
if ( 'list' != $mode )
- echo '( ' . $val->user_email . ' )';
+ echo '( ' . $user_object->user_email . ' )';
echo '
';
}
if ( $blogusers_warning != '' )
diff --git a/wp-admin/network/sites.php b/wp-admin/network/sites.php
index 818e41df91..eaeac03f82 100644
--- a/wp-admin/network/sites.php
+++ b/wp-admin/network/sites.php
@@ -258,24 +258,19 @@ switch ( $action ) {
// Site users
$blogusers = get_users_of_blog( $id );
+
if ( is_array( $blogusers ) ) {
echo '
" . __( 'User' ) . " | " . __( 'Role' ) . " | " . __( 'Password' ) . " | " . __( 'Remove' ) . " | |||
---|---|---|---|---|---|---|
' . $val->user_login . ' | '; - if ( $val->user_id != $current_user->data->ID ) { + foreach ( $blogusers as $user_id => $user_object ) { + $existing_role = reset( $user_object->roles ); + + echo '||||||
' . $user_object->user_login . ' | '; + if ( $user_id != $current_user->data->ID ) { ?>- | - + | '; + echo ''; } else { echo " | " . __ ( 'N/A' ) . " | " . __ ( 'N/A' ) . " | " . __( 'N/A' ) . " | "; } diff --git a/wp-includes/capabilities.php b/wp-includes/capabilities.php index 7d20b1e84c..e35c9b34bf 100644 --- a/wp-includes/capabilities.php +++ b/wp-includes/capabilities.php @@ -471,9 +471,10 @@ class WP_User { * * @param int|string $id User's ID or username * @param int $name Optional. User's username + * @param int $blog_id Optional Blog ID, defaults to current blog. * @return WP_User */ - function WP_User( $id, $name = '' ) { + function WP_User( $id, $name = '', $blog_id = '' ) { if ( empty( $id ) && empty( $name ) ) return; @@ -496,7 +497,7 @@ class WP_User { } $this->id = $this->ID; - $this->_init_caps(); + $this->for_blog( $blog_id ); } /** diff --git a/wp-includes/functions.php b/wp-includes/functions.php index 51dc9ba951..7ea31f86a9 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -4225,6 +4225,8 @@ function _wp_search_sql($string, $cols) { * @since 3.1.0 * * @param array $queries An array of queries + * @param string $meta_id_column The column that holds the object id + * @param string $table Which meta table to look in * @return string */ function _wp_meta_sql( $queries, $meta_id_column, $table ) { diff --git a/wp-includes/user.php b/wp-includes/user.php index 5f37bb644f..cdfefd3a9d 100644 --- a/wp-includes/user.php +++ b/wp-includes/user.php @@ -374,11 +374,12 @@ class WP_User_Query { function __construct( $query = null ) { if ( !empty( $query ) ) { $this->query_vars = wp_parse_args( $query, array( - 'search' => '', 'role' => '', - 'offset' => '', 'number' => '', 'count_total' => true, - 'orderby' => 'login', 'order' => 'ASC', - 'meta_key' => '', 'meta_value' => '', + 'role' => '', 'blog_id' => $GLOBALS['blog_id'], + 'meta_key' => '', 'meta_value' => '', 'meta_compare' => '', 'include' => array(), 'exclude' => array(), + 'search' => '', + 'orderby' => 'login', 'order' => 'ASC', + 'offset' => '', 'number' => '', 'count_total' => true, 'fields' => 'all', ) ); @@ -444,22 +445,22 @@ class WP_User_Query { } $role = trim( $qv['role'] ); + $blog_id = absint( $qv['blog_id'] ); $meta_queries = array(); - $cap_meta_query = array(); - $cap_meta_key = $wpdb->prefix . 'capabilities'; + if ( $blog_id ) { + $cap_meta_query = array(); + $cap_meta_query['meta_key'] = $wpdb->get_blog_prefix( $blog_id ) . 'capabilities'; - if ( $role || is_multisite() ) - $cap_meta_query['meta_key'] = $cap_meta_key; + if ( $role ) { + $cap_meta_query['meta_value'] = $role; + $cap_meta_query['meta_compare'] = 'like'; + } - if ( $role ) { - $cap_meta_query['meta_value'] = $role; - $cap_meta_query['meta_compare'] = 'like'; + $meta_queries[] = $cap_meta_query; } - $meta_queries[] = $cap_meta_query; - $meta_queries[] = array( 'meta_key' => @$qv['meta_key'], 'meta_value' => @$qv['meta_key'], @@ -506,7 +507,7 @@ class WP_User_Query { $r = array(); foreach ( $this->results as $userid ) - $r[ $userid ] = new WP_User( $userid ); + $r[ $userid ] = new WP_User( $userid, '', $this->query_vars['blog_id'] ); $this->results = $r; } @@ -564,7 +565,7 @@ function get_users( $args ) { * multi-blog feature. * * @since 2.2.0 - * @uses $wpdb WordPress database object for queries + * @uses get_users() for queries * @uses $blog_id The Blog id of the blog for those that use more than one blog * * @param int $id Blog ID. @@ -572,11 +573,11 @@ function get_users( $args ) { */ function get_users_of_blog( $id = '' ) { global $wpdb, $blog_id; + if ( empty($id) ) $id = (int) $blog_id; - $blog_prefix = $wpdb->get_blog_prefix($id); - $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" ); - return $users; + + return get_users( array( 'blog_id' => $id ) ); } /**