<!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-&gt;items as $userid =&gt; $user_object ) {
</span><del>-                        $roles = $user_object-&gt;roles;
-                        $role = array_shift( $roles );
</del><ins>+                        $role = reset( $user_object-&gt;roles );
</ins><span class="cx"> 
</span><span class="cx">                         if ( is_multisite() &amp;&amp; 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.' ) . ' &lt;a href=&quot;' . esc_url( get_admin_url( $blog['blog_id'], 'users.php' ) ) . '&quot;&gt;' . __( 'More' ) . '&lt;/a&gt;';
</span><span class="cx">                                                                 }
</span><del>-                                                                foreach ( $blogusers as $key =&gt; $val ) {
-                                                                        echo '&lt;a href=&quot;' . esc_url( admin_url( 'user-edit.php?user_id=' . $val-&gt;user_id ) ) . '&quot;&gt;' . esc_html( $val-&gt;user_login ) . '&lt;/a&gt; ';
</del><ins>+                                                                foreach ( $blogusers as $user_object ) {
+                                                                        echo '&lt;a href=&quot;' . esc_url( admin_url( 'user-edit.php?user_id=' . $user_object-&gt;ID ) ) . '&quot;&gt;' . esc_html( $user_object-&gt;user_login ) . '&lt;/a&gt; ';
</ins><span class="cx">                                                                         if ( 'list' != $mode )
</span><del>-                                                                                echo '( ' . $val-&gt;user_email . ' )';
</del><ins>+                                                                                echo '( ' . $user_object-&gt;user_email . ' )';
</ins><span class="cx">                                                                         echo '&lt;br /&gt;';
</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 '&lt;div id=&quot;blogedit_blogusers&quot; class=&quot;postbox&quot;&gt;&lt;h3 class=&quot;hndle&quot;&gt;&lt;span&gt;' . __( 'Site Users' ) . '&lt;/span&gt;&lt;/h3&gt;&lt;div class=&quot;inside&quot;&gt;';
</span><span class="cx">                                         echo '&lt;table class=&quot;form-table&quot;&gt;';
</span><span class="cx">                                         echo &quot;&lt;tr&gt;&lt;th&gt;&quot; . __( 'User' ) . &quot;&lt;/th&gt;&lt;th&gt;&quot; . __( 'Role' ) . &quot;&lt;/th&gt;&lt;th&gt;&quot; . __( 'Password' ) . &quot;&lt;/th&gt;&lt;th&gt;&quot; . __( 'Remove' ) . &quot;&lt;/th&gt;&lt;/tr&gt;&quot;;
</span><del>-                                        reset( $blogusers );
-                                        foreach ( (array) $blogusers as $key =&gt; $val ) {
-                                                if ( isset( $val-&gt;meta_value ) &amp;&amp; ! $val-&gt;meta_value )
-                                                        continue;
-                                                $t = @unserialize( $val-&gt;meta_value );
-                                                if ( is_array( $t ) ) {
-                                                        reset( $t );
-                                                        $existing_role = key( $t );
-                                                }
-                                                echo '&lt;tr&gt;&lt;td&gt;&lt;a href=&quot;user-edit.php?user_id=' . $val-&gt;user_id . '&quot;&gt;' . $val-&gt;user_login . '&lt;/a&gt;&lt;/td&gt;';
-                                                if ( $val-&gt;user_id != $current_user-&gt;data-&gt;ID ) {
</del><ins>+                                        foreach ( $blogusers as $user_id =&gt; $user_object ) {
+                                                $existing_role = reset( $user_object-&gt;roles );
+
+                                                echo '&lt;tr&gt;&lt;td&gt;&lt;a href=&quot;user-edit.php?user_id=' . $user_id . '&quot;&gt;' . $user_object-&gt;user_login . '&lt;/a&gt;&lt;/td&gt;';
+                                                if ( $user_id != $current_user-&gt;data-&gt;ID ) {
</ins><span class="cx">                                                         ?&gt;
</span><span class="cx">                                                         &lt;td&gt;
</span><del>-                                                                &lt;select name=&quot;role[&lt;?php echo $val-&gt;user_id ?&gt;]&quot; id=&quot;new_role_1&quot;&gt;&lt;?php
</del><ins>+                                                                &lt;select name=&quot;role[&lt;?php echo $user_id ?&gt;]&quot; id=&quot;new_role_1&quot;&gt;&lt;?php
</ins><span class="cx">                                                                         foreach ( $editblog_roles as $role =&gt; $role_assoc ){
</span><span class="cx">                                                                                 $name = translate_user_role( $role_assoc['name'] );
</span><span class="cx">                                                                                 echo '&lt;option ' . selected( $role, $existing_role, false ) . ' value=&quot;' . esc_attr( $role ) . '&quot;&gt;' . esc_html( $name ) . '&lt;/option&gt;';
</span><span class="lines">@@ -284,10 +279,10 @@
</span><span class="cx">                                                                 &lt;/select&gt;
</span><span class="cx">                                                         &lt;/td&gt;
</span><span class="cx">                                                         &lt;td&gt;
</span><del>-                                                                &lt;input type=&quot;text&quot; name=&quot;user_password[&lt;?php echo esc_attr( $val-&gt;user_id ) ?&gt;]&quot; /&gt;
</del><ins>+                                                                &lt;input type=&quot;text&quot; name=&quot;user_password[&lt;?php echo esc_attr( $user_id ) ?&gt;]&quot; /&gt;
</ins><span class="cx">                                                         &lt;/td&gt;
</span><span class="cx">                                                         &lt;?php
</span><del>-                                                        echo '&lt;td&gt;&lt;input title=&quot;' . __( 'Click to remove user' ) . '&quot; type=&quot;checkbox&quot; name=&quot;blogusers[' . esc_attr( $val-&gt;user_id ) . ']&quot; /&gt;&lt;/td&gt;';
</del><ins>+                                                        echo '&lt;td&gt;&lt;input title=&quot;' . __( 'Click to remove user' ) . '&quot; type=&quot;checkbox&quot; name=&quot;blogusers[' . esc_attr( $user_id ) . ']&quot; /&gt;&lt;/td&gt;';
</ins><span class="cx">                                                 } else {
</span><span class="cx">                                                         echo &quot;&lt;td&gt;&lt;strong&gt;&quot; . __ ( 'N/A' ) . &quot;&lt;/strong&gt;&lt;/td&gt;&lt;td&gt;&lt;strong&gt;&quot; . __ ( 'N/A' ) . &quot;&lt;/strong&gt;&lt;/td&gt;&lt;td&gt;&lt;strong&gt;&quot; . __( 'N/A' ) . &quot;&lt;/strong&gt;&lt;/td&gt;&quot;;
</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 ) &amp;&amp; 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-&gt;id = $this-&gt;ID;
</span><del>-                $this-&gt;_init_caps();
</del><ins>+                $this-&gt;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-&gt;query_vars = wp_parse_args( $query, array(
</span><del>-                                'search' =&gt; '', 'role' =&gt; '',
</del><ins>+                                'role' =&gt; '', 'blog_id' =&gt; $GLOBALS['blog_id'],
+                                'meta_key' =&gt; '', 'meta_value' =&gt; '', 'meta_compare' =&gt; '',
+                                'include' =&gt; array(), 'exclude' =&gt; array(),
+                                'search' =&gt; '',
+                                'orderby' =&gt; 'login', 'order' =&gt; 'ASC',
</ins><span class="cx">                                 'offset' =&gt; '', 'number' =&gt; '', 'count_total' =&gt; true,
</span><del>-                                'orderby' =&gt; 'login', 'order' =&gt; 'ASC',
-                                'meta_key' =&gt; '', 'meta_value' =&gt; '',
-                                'include' =&gt; array(), 'exclude' =&gt; array(),
</del><span class="cx">                                 'fields' =&gt; '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-&gt;prefix . 'capabilities';
</del><ins>+                if ( $blog_id ) {
+                        $cap_meta_query = array();
+                        $cap_meta_query['meta_key'] = $wpdb-&gt;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' =&gt; @$qv['meta_key'],
</span><span class="cx">                         'meta_value' =&gt; @$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-&gt;results as $userid )
</span><del>-                                $r[ $userid ] = new WP_User( $userid );
</del><ins>+                                $r[ $userid ] = new WP_User( $userid, '', $this-&gt;query_vars['blog_id'] );
</ins><span class="cx"> 
</span><span class="cx">                         $this-&gt;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-&gt;get_blog_prefix($id);
-        $users = $wpdb-&gt;get_results( &quot;SELECT user_id, user_id AS ID, user_login, display_name, user_email, meta_value FROM $wpdb-&gt;users, $wpdb-&gt;usermeta WHERE {$wpdb-&gt;users}.ID = {$wpdb-&gt;usermeta}.user_id AND meta_key = '{$blog_prefix}capabilities' ORDER BY {$wpdb-&gt;usermeta}.user_id&quot; );
-        return $users;
</del><ins>+        
+        return get_users( array( 'blog_id' =&gt; $id ) );
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> /**
</span></span></pre>
</div>
</div>

</body>
</html>