<!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>[15539] trunk: use get_users() in get_editable_user_ids() and cache result.</title>
</head>
<body>

<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/15539">15539</a></dd>
<dt>Author</dt> <dd>scribu</dd>
<dt>Date</dt> <dd>2010-08-27 00:18:57 +0000 (Fri, 27 Aug 2010)</dd>
</dl>

<h3>Log Message</h3>
<pre>use get_users() in get_editable_user_ids() and cache result. See <a href="http://trac.wordpress.org/ticket/14572">#14572</a></pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpadmineditformadvancedphp">trunk/wp-admin/edit-form-advanced.php</a></li>
<li><a href="#trunkwpadminincludesmetaboxesphp">trunk/wp-admin/includes/meta-boxes.php</a></li>
<li><a href="#trunkwpadminincludesuserphp">trunk/wp-admin/includes/user.php</a></li>
<li><a href="#trunkwpincludesuserphp">trunk/wp-includes/user.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpadmineditformadvancedphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/edit-form-advanced.php (15538 => 15539)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/edit-form-advanced.php        2010-08-26 22:11:04 UTC (rev 15538)
+++ trunk/wp-admin/edit-form-advanced.php        2010-08-27 00:18:57 UTC (rev 15539)
</span><span class="lines">@@ -149,10 +149,11 @@
</span><span class="cx">         add_meta_box('slugdiv', __('Slug'), 'post_slug_meta_box', $post_type, 'normal', 'core');
</span><span class="cx"> 
</span><span class="cx"> if ( post_type_supports($post_type, 'author') ) {
</span><del>-        $authors = get_editable_user_ids( $current_user-&gt;id ); // TODO: ROLE SYSTEM
-        if ( $post-&gt;post_author &amp;&amp; !in_array($post-&gt;post_author, $authors) )
-                $authors[] = $post-&gt;post_author;
-        if ( ( $authors &amp;&amp; count( $authors ) &gt; 1 ) || is_super_admin() )
</del><ins>+        $_editable_user_ids = get_editable_user_ids( $current_user-&gt;id, true, $post_type ); // TODO: ROLE SYSTEM
+        if ( $post-&gt;post_author &amp;&amp; !in_array($post-&gt;post_author, $_editable_user_ids) )
+                $_editable_user_ids[] = $post-&gt;post_author;
+
+        if ( !empty($_editable_user_ids) || is_super_admin() )
</ins><span class="cx">                 add_meta_box('authordiv', __('Author'), 'post_author_meta_box', $post_type, 'normal', 'core');
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkwpadminincludesmetaboxesphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/meta-boxes.php (15538 => 15539)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/meta-boxes.php        2010-08-26 22:11:04 UTC (rev 15538)
+++ trunk/wp-admin/includes/meta-boxes.php        2010-08-27 00:18:57 UTC (rev 15539)
</span><span class="lines">@@ -505,10 +505,8 @@
</span><span class="cx">  * @param object $post
</span><span class="cx">  */
</span><span class="cx"> function post_author_meta_box($post) {
</span><del>-        global $user_ID;
-        $authors = get_editable_user_ids( get_current_user_id(), true, $post-&gt;post_type ); // TODO: ROLE SYSTEM
-        if ( $post-&gt;post_author &amp;&amp; !in_array($post-&gt;post_author, $authors) )
-                $authors[] = $post-&gt;post_author;
</del><ins>+        global $user_ID, $_editable_user_ids;
+
</ins><span class="cx"> ?&gt;
</span><span class="cx"> &lt;label class=&quot;screen-reader-text&quot; for=&quot;post_author_override&quot;&gt;&lt;?php _e('Author'); ?&gt;&lt;/label&gt;&lt;?php wp_dropdown_users( array('include' =&gt; $authors, 'name' =&gt; 'post_author_override', 'selected' =&gt; empty($post-&gt;ID) ? $user_ID : $post-&gt;post_author) ); ?&gt;
</span><span class="cx"> &lt;?php
</span></span></pre></div>
<a id="trunkwpadminincludesuserphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/user.php (15538 => 15539)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/user.php        2010-08-26 22:11:04 UTC (rev 15538)
+++ trunk/wp-admin/includes/user.php        2010-08-27 00:18:57 UTC (rev 15539)
</span><span class="lines">@@ -240,12 +240,15 @@
</span><span class="cx">  * @since unknown
</span><span class="cx">  *
</span><span class="cx">  * @param int $user_id User ID.
</span><del>- * @param bool $exclude_zeros Optional, default is true. Whether to exclude zeros.
- * @return unknown
</del><ins>+ * @param bool $deprecated Not used.
+ * @return array
</ins><span class="cx">  */
</span><del>-function get_editable_user_ids( $user_id, $exclude_zeros = true, $post_type = 'post' ) {
</del><ins>+function get_editable_user_ids( $user_id, $deprecated = true, $post_type = 'post' ) {
</ins><span class="cx">         global $wpdb;
</span><span class="cx"> 
</span><ins>+        if ( !$deprecated )
+                _deprecated_argument( __FUNCTION__, '3.1.0' );
+
</ins><span class="cx">         $user = new WP_User( $user_id );
</span><span class="cx">         $post_type_obj = get_post_type_object($post_type);
</span><span class="cx"> 
</span><span class="lines">@@ -256,16 +259,7 @@
</span><span class="cx">                         return array();
</span><span class="cx">         }
</span><span class="cx"> 
</span><del>-        if ( !is_multisite() )
-                $level_key = $wpdb-&gt;get_blog_prefix() . 'user_level';
-        else
-                $level_key = $wpdb-&gt;get_blog_prefix() . 'capabilities'; // wpmu site admins don't have user_levels
-
-        $query = $wpdb-&gt;prepare(&quot;SELECT user_id FROM $wpdb-&gt;usermeta WHERE meta_key = %s&quot;, $level_key);
-        if ( $exclude_zeros )
-                $query .= &quot; AND meta_value != '0'&quot;;
-
-        return $wpdb-&gt;get_col( $query );
</del><ins>+        return get_users( array('fields' =&gt; 'ids') );
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> /**
</span></span></pre></div>
<a id="trunkwpincludesuserphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/user.php (15538 => 15539)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/user.php        2010-08-26 22:11:04 UTC (rev 15538)
+++ trunk/wp-includes/user.php        2010-08-27 00:18:57 UTC (rev 15539)
</span><span class="lines">@@ -434,15 +434,16 @@
</span><span class="cx">                 }
</span><span class="cx"> 
</span><span class="cx">                 $role = trim( $qv['role'] );
</span><del>-                if ( $role ) {
</del><ins>+
+                if ( $role || is_multisite() ) {
</ins><span class="cx">                         $this-&gt;query_from .= &quot; INNER JOIN $wpdb-&gt;usermeta ON $wpdb-&gt;users.ID = $wpdb-&gt;usermeta.user_id&quot;;
</span><del>-                        $this-&gt;query_where .= $wpdb-&gt;prepare(&quot; AND $wpdb-&gt;usermeta.meta_key = '{$wpdb-&gt;prefix}capabilities' AND $wpdb-&gt;usermeta.meta_value LIKE %s&quot;, '%' . $role . '%');
-                } elseif ( is_multisite() ) {
-                        $level_key = $wpdb-&gt;prefix . 'capabilities'; // wpmu site admins don't have user_levels
-                        $this-&gt;query_from .= &quot;, $wpdb-&gt;usermeta&quot;;
-                        $this-&gt;query_where .= &quot; AND $wpdb-&gt;users.ID = $wpdb-&gt;usermeta.user_id AND meta_key = '{$level_key}'&quot;;
</del><ins>+                        $this-&gt;query_where .= $wpdb-&gt;prepare( &quot; AND $wpdb-&gt;usermeta.meta_key = %s&quot;, $wpdb-&gt;prefix . 'capabilities' );
</ins><span class="cx">                 }
</span><span class="cx"> 
</span><ins>+                if ( $role ) {
+                        $this-&gt;query_where .= $wpdb-&gt;prepare( &quot; AND $wpdb-&gt;usermeta.meta_value LIKE %s&quot;, '%' . like_escape( $role ) . '%' );
+                }
+
</ins><span class="cx">                 $meta_key = trim( $qv['meta_key'] );
</span><span class="cx">                 $meta_value = trim( $qv['meta_value'] );
</span><span class="cx">                 if ( $meta_key ) {
</span></span></pre>
</div>
</div>

</body>
</html>