<!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>[15620] trunk/wp-includes/author-template.php: Clean up wp_list_authors().</title>
</head>
<body>
<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/15620">15620</a></dd>
<dt>Author</dt> <dd>scribu</dd>
<dt>Date</dt> <dd>2010-09-15 19:52:25 +0000 (Wed, 15 Sep 2010)</dd>
</dl>
<h3>Log Message</h3>
<pre>Clean up wp_list_authors(). See <a href="http://trac.wordpress.org/ticket/10329">#10329</a></pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpincludesauthortemplatephp">trunk/wp-includes/author-template.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpincludesauthortemplatephp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/author-template.php (15619 => 15620)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/author-template.php        2010-09-15 09:24:11 UTC (rev 15619)
+++ trunk/wp-includes/author-template.php        2010-09-15 19:52:25 UTC (rev 15620)
</span><span class="lines">@@ -257,7 +257,7 @@
</span><span class="cx"> * echoing.</li>
</span><span class="cx"> * <li>style (string) ('list'): Whether to display list of authors in list form
</span><span class="cx"> * or as a string.</li>
</span><del>- * <li>html (bool) (true): Whether to list the items in html for or plaintext.
</del><ins>+ * <li>html (bool) (true): Whether to list the items in html form or plaintext.
</ins><span class="cx"> * </li>
</span><span class="cx"> * </ul>
</span><span class="cx"> *
</span><span class="lines">@@ -270,101 +270,94 @@
</span><span class="cx">         global $wpdb;
</span><span class="cx">
</span><span class="cx">         $defaults = array(
</span><ins>+                'orderby' => 'name', 'order' => 'ASC', 'number' => '',
</ins><span class="cx">                 'optioncount' => false, 'exclude_admin' => true,
</span><span class="cx">                 'show_fullname' => false, 'hide_empty' => true,
</span><span class="cx">                 'feed' => '', 'feed_image' => '', 'feed_type' => '', 'echo' => true,
</span><span class="cx">                 'style' => 'list', 'html' => true
</span><span class="cx">         );
</span><span class="cx">
</span><del>-        $r = wp_parse_args( $args, $defaults );
-        extract($r, EXTR_SKIP);
</del><ins>+        $args = wp_parse_args( $args, $defaults );
+        extract( $args, EXTR_SKIP );
+
</ins><span class="cx">         $return = '';
</span><span class="cx">
</span><del>-        /** @todo Move select to get_authors(). */
-        $users = get_users();
-        $author_ids = array();
-        foreach ( (array) $users as $user )
-                $author_ids[] = $user->user_id;
-        if ( count($author_ids) > 0 ) {
-                $author_ids = implode(',', $author_ids );
-                $authors = $wpdb->get_results( "SELECT ID, user_nicename from $wpdb->users WHERE ID IN($author_ids) " . ($exclude_admin ? "AND user_login <> 'admin' " : '') . "ORDER BY display_name" );
-        } else {
-                $authors = array();
-        }
</del><ins>+        $authors = get_users( wp_array_slice_assoc( $args, array( 'orderby', 'order', 'number' ) ) );
</ins><span class="cx">
</span><span class="cx">         $author_count = array();
</span><span class="cx">         foreach ( (array) $wpdb->get_results("SELECT DISTINCT post_author, COUNT(ID) AS count FROM $wpdb->posts WHERE post_type = 'post' AND " . get_private_posts_cap_sql( 'post' ) . " GROUP BY post_author") as $row )
</span><span class="cx">                 $author_count[$row->post_author] = $row->count;
</span><span class="cx">
</span><del>-        foreach ( (array) $authors as $author ) {
</del><ins>+        foreach ( $authors as $author ) {
</ins><span class="cx">
</span><del>-                $link = '';
</del><ins>+                if ( $exclude_admin && 'admin' == $author->display_name )
+                        continue;
</ins><span class="cx">
</span><del>-                $author = get_userdata( $author->ID );
-                $posts = (isset($author_count[$author->ID])) ? $author_count[$author->ID] : 0;
-                $name = $author->display_name;
</del><ins>+                $posts = isset( $author_count[$author->ID] ) ? $author_count[$author->ID] : 0;
</ins><span class="cx">
</span><del>-                if ( $show_fullname && ($author->first_name != '' && $author->last_name != '') )
</del><ins>+                if ( !$posts && $hide_empty )
+                        continue;
+
+                $link = '';
+
+                if ( $show_fullname && $author->first_name && $author->last_name )
</ins><span class="cx">                         $name = "$author->first_name $author->last_name";
</span><ins>+                else
+                        $name = $author->display_name;
</ins><span class="cx">
</span><del>-                if( !$html ) {
-                        if ( $posts == 0 ) {
-                                if ( ! $hide_empty )
-                                        $return .= $name . ', ';
-                        } else
-                                $return .= $name . ', ';
</del><ins>+                if ( !$html ) {
+                        $return .= $name . ', ';
</ins><span class="cx">
</span><del>-                        // No need to go further to process HTML.
-                        continue;
</del><ins>+                        continue; // No need to go further to process HTML.
</ins><span class="cx">                 }
</span><span class="cx">
</span><del>-                if ( !($posts == 0 && $hide_empty) && 'list' == $style )
</del><ins>+                if ( 'list' == $style ) {
</ins><span class="cx">                         $return .= '<li>';
</span><del>-                if ( $posts == 0 ) {
-                        if ( ! $hide_empty )
-                                $link = $name;
-                } else {
-                        $link = '<a href="' . get_author_posts_url($author->ID, $author->user_nicename) . '" title="' . esc_attr( sprintf(__("Posts by %s"), $author->display_name) ) . '">' . $name . '</a>';
</del><ins>+                }
</ins><span class="cx">
</span><del>-                        if ( (! empty($feed_image)) || (! empty($feed)) ) {
-                                $link .= ' ';
-                                if (empty($feed_image))
-                                        $link .= '(';
-                                $link .= '<a href="' . get_author_feed_link($author->ID) . '"';
</del><ins>+                $link = '<a href="' . get_author_posts_url( $author->ID, $author->user_nicename ) . '" title="' . esc_attr( sprintf(__("Posts by %s"), $author->display_name) ) . '">' . $name . '</a>';
</ins><span class="cx">
</span><del>-                                if ( !empty($feed) ) {
-                                        $title = ' title="' . esc_attr($feed) . '"';
-                                        $alt = ' alt="' . esc_attr($feed) . '"';
-                                        $name = $feed;
-                                        $link .= $title;
-                                }
</del><ins>+                if ( !empty( $feed_image ) || !empty( $feed ) ) {
+                        $link .= ' ';
+                        if ( empty( $feed_image ) ) {
+                                $link .= '(';
+                        }
</ins><span class="cx">
</span><del>-                                $link .= '>';
</del><ins>+                        $link .= '<a href="' . get_author_feed_link( $author->ID ) . '"';
</ins><span class="cx">
</span><del>-                                if ( !empty($feed_image) )
-                                        $link .= "<img src=\"" . esc_url($feed_image) . "\" style=\"border: none;\"$alt$title" . ' />';
-                                else
-                                        $link .= $name;
</del><ins>+                        $alt = $title = '';
+                        if ( !empty( $feed ) ) {
+                                $title = ' title="' . esc_attr( $feed ) . '"';
+                                $alt = ' alt="' . esc_attr( $feed ) . '"';
+                                $name = $feed;
+                                $link .= $title;
+                        }
</ins><span class="cx">
</span><del>-                                $link .= '</a>';
</del><ins>+                        $link .= '>';
</ins><span class="cx">
</span><del>-                                if ( empty($feed_image) )
-                                        $link .= ')';
-                        }
</del><ins>+                        if ( !empty( $feed_image ) )
+                                $link .= '<img src="' . esc_url( $feed_image ) . '" style="border: none;"' . $alt . $title . ' />';
+                        else
+                                $link .= $name;
</ins><span class="cx">
</span><del>-                        if ( $optioncount )
-                                $link .= ' ('. $posts . ')';
</del><ins>+                        $link .= '</a>';
</ins><span class="cx">
</span><ins>+                        if ( empty( $feed_image ) )
+                                $link .= ')';
</ins><span class="cx">                 }
</span><span class="cx">
</span><del>-                if ( $posts || ! $hide_empty )
-                        $return .= $link . ( ( 'list' == $style ) ? '</li>' : ', ' );
</del><ins>+                if ( $optioncount )
+                        $link .= ' ('. $posts . ')';
+
+                $return .= $link;
+                $return .= ( 'list' == $style ) ? '</li>' : ', ';
</ins><span class="cx">         }
</span><span class="cx">
</span><del>-        $return = trim($return, ', ');
</del><ins>+        $return = rtrim($return, ', ');
</ins><span class="cx">
</span><del>-        if ( ! $echo )
</del><ins>+        if ( !$echo )
</ins><span class="cx">                 return $return;
</span><ins>+
</ins><span class="cx">         echo $return;
</span><span class="cx"> }
</span><span class="cx">
</span></span></pre>
</div>
</div>
</body>
</html>