<!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>[17088] trunk: Add 'who' arg to wp_dropdown_users() and get_users().</title>
</head>
<body>
<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/17088">17088</a></dd>
<dt>Author</dt> <dd>ryan</dd>
<dt>Date</dt> <dd>2010-12-20 17:25:39 +0000 (Mon, 20 Dec 2010)</dd>
</dl>
<h3>Log Message</h3>
<pre>Add 'who' arg to wp_dropdown_users() and get_users(). Add' hide_if_only_one_author' argument to get_users(). Query only authors (user level greater than 0) when who => author is passed. Query only authors for author meta box and quick edit dropdowns. Props scribu. fixes <a href="http://trac.wordpress.org/ticket/15871">#15871</a></pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpadminincludesclasswppostslisttablephp">trunk/wp-admin/includes/class-wp-posts-list-table.php</a></li>
<li><a href="#trunkwpadminincludesmetaboxesphp">trunk/wp-admin/includes/meta-boxes.php</a></li>
<li><a href="#trunkwpincludesmetaphp">trunk/wp-includes/meta.php</a></li>
<li><a href="#trunkwpincludesuserphp">trunk/wp-includes/user.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpadminincludesclasswppostslisttablephp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/class-wp-posts-list-table.php (17087 => 17088)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/class-wp-posts-list-table.php        2010-12-20 16:48:19 UTC (rev 17087)
+++ trunk/wp-admin/includes/class-wp-posts-list-table.php        2010-12-20 17:25:39 UTC (rev 17088)
</span><span class="lines">@@ -757,7 +757,6 @@
</span><span class="cx">                                 <?php touch_time( 1, 1, 4, 1 ); ?>
</span><span class="cx">                         </div>
</span><span class="cx">                         <br class="clear" />
</span><del>-
</del><span class="cx">         <?php endif; // $bulk
</span><span class="cx">
</span><span class="cx">                 if ( post_type_supports( $screen->post_type, 'author' ) ) :
</span><span class="lines">@@ -765,6 +764,8 @@
</span><span class="cx">
</span><span class="cx">                         if ( is_super_admin() || current_user_can( $post_type_object->cap->edit_others_posts ) ) :
</span><span class="cx">                                 $users_opt = array(
</span><ins>+                                        'hide_if_only_one_author' => true,
+                                        'who' => 'authors',
</ins><span class="cx">                                         'name' => 'post_author',
</span><span class="cx">                                         'class'=> 'authors',
</span><span class="cx">                                         'multi' => 1,
</span><span class="lines">@@ -772,10 +773,13 @@
</span><span class="cx">                                 );
</span><span class="cx">                                 if ( $bulk )
</span><span class="cx">                                         $users_opt['show_option_none'] = __( '&mdash; No Change &mdash;' );
</span><del>-                                $authors_dropdown = '<label>';
-                                $authors_dropdown .= '<span class="title">' . __( 'Author' ) . '</span>';
-                                $authors_dropdown .= wp_dropdown_users( $users_opt );
-                                $authors_dropdown .= '</label>';
</del><ins>+
+                                if ( $authors = wp_dropdown_users( $users_opt ) ) :
+                                        $authors_dropdown = '<label>';
+                                        $authors_dropdown .= '<span class="title">' . __( 'Author' ) . '</span>';
+                                        $authors_dropdown .= $authors;
+                                        $authors_dropdown .= '</label>';
+                                endif;
</ins><span class="cx">                         endif; // authors
</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 (17087 => 17088)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/meta-boxes.php        2010-12-20 16:48:19 UTC (rev 17087)
+++ trunk/wp-admin/includes/meta-boxes.php        2010-12-20 17:25:39 UTC (rev 17088)
</span><span class="lines">@@ -530,11 +530,11 @@
</span><span class="cx"> */
</span><span class="cx"> function post_author_meta_box($post) {
</span><span class="cx">         global $user_ID;
</span><del>-
</del><span class="cx"> ?>
</span><span class="cx"> <label class="screen-reader-text" for="post_author_override"><?php _e('Author'); ?></label>
</span><span class="cx"> <?php
</span><span class="cx">         wp_dropdown_users( array(
</span><ins>+                'who' => 'authors',
</ins><span class="cx">                 'name' => 'post_author_override',
</span><span class="cx">                 'selected' => empty($post->ID) ? $user_ID : $post->post_author
</span><span class="cx">         ) );
</span></span></pre></div>
<a id="trunkwpincludesmetaphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/meta.php (17087 => 17088)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/meta.php        2010-12-20 16:48:19 UTC (rev 17087)
+++ trunk/wp-includes/meta.php        2010-12-20 17:25:39 UTC (rev 17088)
</span><span class="lines">@@ -433,6 +433,11 @@
</span><span class="cx">                 } else {
</span><span class="cx">                         $meta_compare_string = '%s';
</span><span class="cx">                 }
</span><ins>+
+                // @todo Temporary hack to support empty values. Do not use outside of core.
+                if ( '_wp_zero_value' == $meta_value )
+                        $meta_value = 0;
+
</ins><span class="cx">                 $where .= $wpdb->prepare( " AND CAST($alias.meta_value AS {$meta_type}) {$meta_compare} {$meta_compare_string}", $meta_value );
</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 (17087 => 17088)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/user.php        2010-12-20 16:48:19 UTC (rev 17087)
+++ trunk/wp-includes/user.php        2010-12-20 17:25:39 UTC (rev 17088)
</span><span class="lines">@@ -481,10 +481,18 @@
</span><span class="cx">                         $this->query_where .= $this->get_search_sql( $search, $search_columns, $wild );
</span><span class="cx">                 }
</span><span class="cx">
</span><ins>+                $blog_id = absint( $qv['blog_id'] );
+
+                if ( 'authors' == $qv['who'] && $blog_id ) {
+                        $qv['meta_key'] = $wpdb->get_blog_prefix( $blog_id ) . 'user_level';
+                        $qv['meta_value'] = '_wp_zero_value'; // Hack to pass '0'
+                        $qv['meta_compare'] = '!=';
+                        $qv['blog_id'] = $blog_id = 0; // Prevent extra meta query
+                }
+
</ins><span class="cx">                 _parse_meta_query( $qv );
</span><span class="cx">
</span><span class="cx">                 $role = trim( $qv['role'] );
</span><del>-                $blog_id = absint( $qv['blog_id'] );
</del><span class="cx">
</span><span class="cx">                 if ( $blog_id && ( $role || is_multisite() ) ) {
</span><span class="cx">                         $cap_meta_query = array();
</span><span class="lines">@@ -929,6 +937,7 @@
</span><span class="cx"> * <ol>
</span><span class="cx"> * <li>show_option_all - Text to show all and whether HTML option exists.</li>
</span><span class="cx"> * <li>show_option_none - Text for show none and whether HTML option exists.</li>
</span><ins>+ * <li>hide_if_only_one_author - Don't create the dropdown if there is only one user.</li>
</ins><span class="cx"> * <li>orderby - SQL order by clause for what order the users appear. Default is 'display_name'.</li>
</span><span class="cx"> * <li>order - Default is 'ASC'. Can also be 'DESC'.</li>
</span><span class="cx"> * <li>include - User IDs to include.</li>
</span><span class="lines">@@ -941,6 +950,7 @@
</span><span class="cx"> * <li>id - Default is the value of the 'name' parameter. ID attribute of select element.</li>
</span><span class="cx"> * <li>class - Class attribute of select element.</li>
</span><span class="cx"> * <li>blog_id - ID of blog (Multisite only). Defaults to ID of current blog.</li>
</span><ins>+ * <li>who - Which users to query. Currently only 'authors' is supported. Default is all users.</li>
</ins><span class="cx"> * </ol>
</span><span class="cx"> *
</span><span class="cx"> * @since 2.3.0
</span><span class="lines">@@ -950,14 +960,13 @@
</span><span class="cx"> * @return string|null Null on display. String of HTML content on retrieve.
</span><span class="cx"> */
</span><span class="cx"> function wp_dropdown_users( $args = '' ) {
</span><del>-        global $wpdb;
</del><span class="cx">         $defaults = array(
</span><del>-                'show_option_all' => '', 'show_option_none' => '',
</del><ins>+                'show_option_all' => '', 'show_option_none' => '', 'hide_if_only_one_author' => '',
</ins><span class="cx">                 'orderby' => 'display_name', 'order' => 'ASC',
</span><span class="cx">                 'include' => '', 'exclude' => '', 'multi' => 0,
</span><span class="cx">                 'show' => 'display_name', 'echo' => 1,
</span><del>-                'selected' => 0, 'name' => 'user', 'class' => '', 'blog_id' => $GLOBALS['blog_id'],
-                'id' => '',
</del><ins>+                'selected' => 0, 'name' => 'user', 'class' => '', 'id' => '',
+                'blog_id' => $GLOBALS['blog_id'], 'who' => ''
</ins><span class="cx">         );
</span><span class="cx">
</span><span class="cx">         $defaults['selected'] = is_author() ? get_query_var( 'author' ) : 0;
</span><span class="lines">@@ -965,13 +974,12 @@
</span><span class="cx">         $r = wp_parse_args( $args, $defaults );
</span><span class="cx">         extract( $r, EXTR_SKIP );
</span><span class="cx">
</span><del>-        $query_args = wp_array_slice_assoc( $r, array( 'blog_id', 'include', 'exclude', 'orderby', 'order' ) );
</del><ins>+        $query_args = wp_array_slice_assoc( $r, array( 'blog_id', 'include', 'exclude', 'orderby', 'order', 'who' ) );
</ins><span class="cx">         $query_args['fields'] = array( 'ID', $show );
</span><del>-
</del><span class="cx">         $users = get_users( $query_args );
</span><span class="cx">
</span><span class="cx">         $output = '';
</span><del>-        if ( !empty($users) ) {
</del><ins>+        if ( !empty($users) && ( empty($hide_if_only_one_author) || count($users) > 1 ) ) {
</ins><span class="cx">                 $name = esc_attr( $name );
</span><span class="cx">                 if ( $multi && ! $id )
</span><span class="cx">                         $id = '';
</span></span></pre>
</div>
</div>
</body>
</html>