<!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->id ); // TODO: ROLE SYSTEM
-        if ( $post->post_author && !in_array($post->post_author, $authors) )
-                $authors[] = $post->post_author;
-        if ( ( $authors && count( $authors ) > 1 ) || is_super_admin() )
</del><ins>+        $_editable_user_ids = get_editable_user_ids( $current_user->id, true, $post_type ); // TODO: ROLE SYSTEM
+        if ( $post->post_author && !in_array($post->post_author, $_editable_user_ids) )
+                $_editable_user_ids[] = $post->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->post_type ); // TODO: ROLE SYSTEM
-        if ( $post->post_author && !in_array($post->post_author, $authors) )
-                $authors[] = $post->post_author;
</del><ins>+        global $user_ID, $_editable_user_ids;
+
</ins><span class="cx"> ?>
</span><span class="cx"> <label class="screen-reader-text" for="post_author_override"><?php _e('Author'); ?></label><?php wp_dropdown_users( array('include' => $authors, 'name' => 'post_author_override', 'selected' => empty($post->ID) ? $user_ID : $post->post_author) ); ?>
</span><span class="cx"> <?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->get_blog_prefix() . 'user_level';
-        else
-                $level_key = $wpdb->get_blog_prefix() . 'capabilities'; // wpmu site admins don't have user_levels
-
-        $query = $wpdb->prepare("SELECT user_id FROM $wpdb->usermeta WHERE meta_key = %s", $level_key);
-        if ( $exclude_zeros )
-                $query .= " AND meta_value != '0'";
-
-        return $wpdb->get_col( $query );
</del><ins>+        return get_users( array('fields' => '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->query_from .= " INNER JOIN $wpdb->usermeta ON $wpdb->users.ID = $wpdb->usermeta.user_id";
</span><del>-                        $this->query_where .= $wpdb->prepare(" AND $wpdb->usermeta.meta_key = '{$wpdb->prefix}capabilities' AND $wpdb->usermeta.meta_value LIKE %s", '%' . $role . '%');
-                } elseif ( is_multisite() ) {
-                        $level_key = $wpdb->prefix . 'capabilities'; // wpmu site admins don't have user_levels
-                        $this->query_from .= ", $wpdb->usermeta";
-                        $this->query_where .= " AND $wpdb->users.ID = $wpdb->usermeta.user_id AND meta_key = '{$level_key}'";
</del><ins>+                        $this->query_where .= $wpdb->prepare( " AND $wpdb->usermeta.meta_key = %s", $wpdb->prefix . 'capabilities' );
</ins><span class="cx">                 }
</span><span class="cx">
</span><ins>+                if ( $role ) {
+                        $this->query_where .= $wpdb->prepare( " AND $wpdb->usermeta.meta_value LIKE %s", '%' . 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>