<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; }
#msg ul, pre { overflow: auto; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<title>[15566] trunk: call get_users() from get_users_of_blog()</title>
</head>
<body>
<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/15566">15566</a></dd>
<dt>Author</dt> <dd>scribu</dd>
<dt>Date</dt> <dd>2010-09-05 14:35:55 +0000 (Sun, 05 Sep 2010)</dd>
</dl>
<h3>Log Message</h3>
<pre>call get_users() from get_users_of_blog()</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpadminincludesdefaultlisttablesphp">trunk/wp-admin/includes/default-list-tables.php</a></li>
<li><a href="#trunkwpadminnetworksitesphp">trunk/wp-admin/network/sites.php</a></li>
<li><a href="#trunkwpincludescapabilitiesphp">trunk/wp-includes/capabilities.php</a></li>
<li><a href="#trunkwpincludesfunctionsphp">trunk/wp-includes/functions.php</a></li>
<li><a href="#trunkwpincludesuserphp">trunk/wp-includes/user.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpadminincludesdefaultlisttablesphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/default-list-tables.php (15565 => 15566)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/default-list-tables.php        2010-09-05 13:31:33 UTC (rev 15565)
+++ trunk/wp-admin/includes/default-list-tables.php        2010-09-05 14:35:55 UTC (rev 15566)
</span><span class="lines">@@ -1794,8 +1794,7 @@
</span><span class="cx">
</span><span class="cx">                 $style = '';
</span><span class="cx">                 foreach ( $this->items as $userid => $user_object ) {
</span><del>-                        $roles = $user_object->roles;
-                        $role = array_shift( $roles );
</del><ins>+                        $role = reset( $user_object->roles );
</ins><span class="cx">
</span><span class="cx">                         if ( is_multisite() && empty( $role ) )
</span><span class="cx">                                 continue;
</span><span class="lines">@@ -2791,10 +2790,10 @@
</span><span class="cx">                                                                         $blogusers = array_slice( $blogusers, 0, 5 );
</span><span class="cx">                                                                         $blogusers_warning = __( 'Only showing first 5 users.' ) . ' <a href="' . esc_url( get_admin_url( $blog['blog_id'], 'users.php' ) ) . '">' . __( 'More' ) . '</a>';
</span><span class="cx">                                                                 }
</span><del>-                                                                foreach ( $blogusers as $key => $val ) {
-                                                                        echo '<a href="' . esc_url( admin_url( 'user-edit.php?user_id=' . $val->user_id ) ) . '">' . esc_html( $val->user_login ) . '</a> ';
</del><ins>+                                                                foreach ( $blogusers as $user_object ) {
+                                                                        echo '<a href="' . esc_url( admin_url( 'user-edit.php?user_id=' . $user_object->ID ) ) . '">' . esc_html( $user_object->user_login ) . '</a> ';
</ins><span class="cx">                                                                         if ( 'list' != $mode )
</span><del>-                                                                                echo '( ' . $val->user_email . ' )';
</del><ins>+                                                                                echo '( ' . $user_object->user_email . ' )';
</ins><span class="cx">                                                                         echo '<br />';
</span><span class="cx">                                                                 }
</span><span class="cx">                                                                 if ( $blogusers_warning != '' )
</span></span></pre></div>
<a id="trunkwpadminnetworksitesphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/network/sites.php (15565 => 15566)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/network/sites.php        2010-09-05 13:31:33 UTC (rev 15565)
+++ trunk/wp-admin/network/sites.php        2010-09-05 14:35:55 UTC (rev 15566)
</span><span class="lines">@@ -258,24 +258,19 @@
</span><span class="cx">
</span><span class="cx">                                 // Site users
</span><span class="cx">                                 $blogusers = get_users_of_blog( $id );
</span><ins>+
</ins><span class="cx">                                 if ( is_array( $blogusers ) ) {
</span><span class="cx">                                         echo '<div id="blogedit_blogusers" class="postbox"><h3 class="hndle"><span>' . __( 'Site Users' ) . '</span></h3><div class="inside">';
</span><span class="cx">                                         echo '<table class="form-table">';
</span><span class="cx">                                         echo "<tr><th>" . __( 'User' ) . "</th><th>" . __( 'Role' ) . "</th><th>" . __( 'Password' ) . "</th><th>" . __( 'Remove' ) . "</th></tr>";
</span><del>-                                        reset( $blogusers );
-                                        foreach ( (array) $blogusers as $key => $val ) {
-                                                if ( isset( $val->meta_value ) && ! $val->meta_value )
-                                                        continue;
-                                                $t = @unserialize( $val->meta_value );
-                                                if ( is_array( $t ) ) {
-                                                        reset( $t );
-                                                        $existing_role = key( $t );
-                                                }
-                                                echo '<tr><td><a href="user-edit.php?user_id=' . $val->user_id . '">' . $val->user_login . '</a></td>';
-                                                if ( $val->user_id != $current_user->data->ID ) {
</del><ins>+                                        foreach ( $blogusers as $user_id => $user_object ) {
+                                                $existing_role = reset( $user_object->roles );
+
+                                                echo '<tr><td><a href="user-edit.php?user_id=' . $user_id . '">' . $user_object->user_login . '</a></td>';
+                                                if ( $user_id != $current_user->data->ID ) {
</ins><span class="cx">                                                         ?>
</span><span class="cx">                                                         <td>
</span><del>-                                                                <select name="role[<?php echo $val->user_id ?>]" id="new_role_1"><?php
</del><ins>+                                                                <select name="role[<?php echo $user_id ?>]" id="new_role_1"><?php
</ins><span class="cx">                                                                         foreach ( $editblog_roles as $role => $role_assoc ){
</span><span class="cx">                                                                                 $name = translate_user_role( $role_assoc['name'] );
</span><span class="cx">                                                                                 echo '<option ' . selected( $role, $existing_role, false ) . ' value="' . esc_attr( $role ) . '">' . esc_html( $name ) . '</option>';
</span><span class="lines">@@ -284,10 +279,10 @@
</span><span class="cx">                                                                 </select>
</span><span class="cx">                                                         </td>
</span><span class="cx">                                                         <td>
</span><del>-                                                                <input type="text" name="user_password[<?php echo esc_attr( $val->user_id ) ?>]" />
</del><ins>+                                                                <input type="text" name="user_password[<?php echo esc_attr( $user_id ) ?>]" />
</ins><span class="cx">                                                         </td>
</span><span class="cx">                                                         <?php
</span><del>-                                                        echo '<td><input title="' . __( 'Click to remove user' ) . '" type="checkbox" name="blogusers[' . esc_attr( $val->user_id ) . ']" /></td>';
</del><ins>+                                                        echo '<td><input title="' . __( 'Click to remove user' ) . '" type="checkbox" name="blogusers[' . esc_attr( $user_id ) . ']" /></td>';
</ins><span class="cx">                                                 } else {
</span><span class="cx">                                                         echo "<td><strong>" . __ ( 'N/A' ) . "</strong></td><td><strong>" . __ ( 'N/A' ) . "</strong></td><td><strong>" . __( 'N/A' ) . "</strong></td>";
</span><span class="cx">                                                 }
</span></span></pre></div>
<a id="trunkwpincludescapabilitiesphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/capabilities.php (15565 => 15566)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/capabilities.php        2010-09-05 13:31:33 UTC (rev 15565)
+++ trunk/wp-includes/capabilities.php        2010-09-05 14:35:55 UTC (rev 15566)
</span><span class="lines">@@ -471,9 +471,10 @@
</span><span class="cx">          *
</span><span class="cx">          * @param int|string $id User's ID or username
</span><span class="cx">          * @param int $name Optional. User's username
</span><ins>+         * @param int $blog_id Optional Blog ID, defaults to current blog.
</ins><span class="cx">          * @return WP_User
</span><span class="cx">          */
</span><del>-        function WP_User( $id, $name = '' ) {
</del><ins>+        function WP_User( $id, $name = '', $blog_id = '' ) {
</ins><span class="cx">
</span><span class="cx">                 if ( empty( $id ) && empty( $name ) )
</span><span class="cx">                         return;
</span><span class="lines">@@ -496,7 +497,7 @@
</span><span class="cx">                 }
</span><span class="cx">
</span><span class="cx">                 $this->id = $this->ID;
</span><del>-                $this->_init_caps();
</del><ins>+                $this->for_blog( $blog_id );
</ins><span class="cx">         }
</span><span class="cx">
</span><span class="cx">         /**
</span></span></pre></div>
<a id="trunkwpincludesfunctionsphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/functions.php (15565 => 15566)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/functions.php        2010-09-05 13:31:33 UTC (rev 15565)
+++ trunk/wp-includes/functions.php        2010-09-05 14:35:55 UTC (rev 15566)
</span><span class="lines">@@ -4225,6 +4225,8 @@
</span><span class="cx"> * @since 3.1.0
</span><span class="cx"> *
</span><span class="cx"> * @param array $queries An array of queries
</span><ins>+ * @param string $meta_id_column The column that holds the object id
+ * @param string $table Which meta table to look in
</ins><span class="cx"> * @return string
</span><span class="cx"> */
</span><span class="cx"> function _wp_meta_sql( $queries, $meta_id_column, $table ) {
</span></span></pre></div>
<a id="trunkwpincludesuserphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/user.php (15565 => 15566)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/user.php        2010-09-05 13:31:33 UTC (rev 15565)
+++ trunk/wp-includes/user.php        2010-09-05 14:35:55 UTC (rev 15566)
</span><span class="lines">@@ -374,11 +374,12 @@
</span><span class="cx">         function __construct( $query = null ) {
</span><span class="cx">                 if ( !empty( $query ) ) {
</span><span class="cx">                         $this->query_vars = wp_parse_args( $query, array(
</span><del>-                                'search' => '', 'role' => '',
</del><ins>+                                'role' => '', 'blog_id' => $GLOBALS['blog_id'],
+                                'meta_key' => '', 'meta_value' => '', 'meta_compare' => '',
+                                'include' => array(), 'exclude' => array(),
+                                'search' => '',
+                                'orderby' => 'login', 'order' => 'ASC',
</ins><span class="cx">                                 'offset' => '', 'number' => '', 'count_total' => true,
</span><del>-                                'orderby' => 'login', 'order' => 'ASC',
-                                'meta_key' => '', 'meta_value' => '',
-                                'include' => array(), 'exclude' => array(),
</del><span class="cx">                                 'fields' => 'all',
</span><span class="cx">                         ) );
</span><span class="cx">
</span><span class="lines">@@ -444,22 +445,22 @@
</span><span class="cx">                 }
</span><span class="cx">
</span><span class="cx">                 $role = trim( $qv['role'] );
</span><ins>+                $blog_id = absint( $qv['blog_id'] );
</ins><span class="cx">
</span><span class="cx">                 $meta_queries = array();
</span><span class="cx">
</span><del>-                $cap_meta_query = array();
-                $cap_meta_key = $wpdb->prefix . 'capabilities';
</del><ins>+                if ( $blog_id ) {
+                        $cap_meta_query = array();
+                        $cap_meta_query['meta_key'] = $wpdb->get_blog_prefix( $blog_id ) . 'capabilities';
</ins><span class="cx">
</span><del>-                if ( $role || is_multisite() )
-                        $cap_meta_query['meta_key'] = $cap_meta_key;
</del><ins>+                        if ( $role ) {
+                                $cap_meta_query['meta_value'] = $role;
+                                $cap_meta_query['meta_compare'] = 'like';
+                        }
</ins><span class="cx">
</span><del>-                if ( $role ) {
-                        $cap_meta_query['meta_value'] = $role;
-                        $cap_meta_query['meta_compare'] = 'like';
</del><ins>+                        $meta_queries[] = $cap_meta_query;
</ins><span class="cx">                 }
</span><span class="cx">
</span><del>-                $meta_queries[] = $cap_meta_query;
-
</del><span class="cx">                 $meta_queries[] = array(
</span><span class="cx">                         'meta_key' => @$qv['meta_key'],
</span><span class="cx">                         'meta_value' => @$qv['meta_key'],
</span><span class="lines">@@ -506,7 +507,7 @@
</span><span class="cx">
</span><span class="cx">                         $r = array();
</span><span class="cx">                         foreach ( $this->results as $userid )
</span><del>-                                $r[ $userid ] = new WP_User( $userid );
</del><ins>+                                $r[ $userid ] = new WP_User( $userid, '', $this->query_vars['blog_id'] );
</ins><span class="cx">
</span><span class="cx">                         $this->results = $r;
</span><span class="cx">                 }
</span><span class="lines">@@ -564,7 +565,7 @@
</span><span class="cx"> * multi-blog feature.
</span><span class="cx"> *
</span><span class="cx"> * @since 2.2.0
</span><del>- * @uses $wpdb WordPress database object for queries
</del><ins>+ * @uses get_users() for queries
</ins><span class="cx"> * @uses $blog_id The Blog id of the blog for those that use more than one blog
</span><span class="cx"> *
</span><span class="cx"> * @param int $id Blog ID.
</span><span class="lines">@@ -572,11 +573,11 @@
</span><span class="cx"> */
</span><span class="cx"> function get_users_of_blog( $id = '' ) {
</span><span class="cx">         global $wpdb, $blog_id;
</span><ins>+
</ins><span class="cx">         if ( empty($id) )
</span><span class="cx">                 $id = (int) $blog_id;
</span><del>-        $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;
</del><ins>+        
+        return get_users( array( 'blog_id' => $id ) );
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span></span></pre>
</div>
</div>
</body>
</html>