Ticket #10329: author-template.diff
| File author-template.diff, 4.2 KB (added by takaitra, 3 years ago) |
|---|
-
author-template.php
245 245 * or as a string.</li> 246 246 * <li>html (bool) (true): Whether to list the items in html for or plaintext. 247 247 * </li> 248 * <li>sort_by (string) ('name'): The sort order of the list. Can be 249 * alphabetical ('name') or by number of posts ('post_count').</li> 250 * <li>count_limit (int) (-1): When passed a positive integer, limit the list 251 * to this number of authors.</li> 248 252 * </ul> 249 253 * 250 254 * @link http://codex.wordpress.org/Template_Tags/wp_list_authors … … 259 263 'optioncount' => false, 'exclude_admin' => true, 260 264 'show_fullname' => false, 'hide_empty' => true, 261 265 'feed' => '', 'feed_image' => '', 'feed_type' => '', 'echo' => true, 262 'style' => 'list', 'html' => true 266 'style' => 'list', 'html' => true, 'sort_by' => 'name', 267 'count_limit' => -1 263 268 ); 264 269 265 270 $r = wp_parse_args( $args, $defaults ); 266 271 extract($r, EXTR_SKIP); 267 272 $return = ''; 268 273 269 /** @todo Move select to get_authors(). */ 270 $authors = $wpdb->get_results("SELECT ID, user_nicename from $wpdb->users " . ($exclude_admin ? "WHERE user_login <> 'admin' " : '') . "ORDER BY display_name"); 274 if ( $show_fullname ) { 275 $author_name_field = "CASE 276 WHEN TRIM(CONCAT_WS(' ', COALESCE(meta_first_name.meta_value, ''), COALESCE(meta_last_name.meta_value, ''))) <> '' 277 THEN 278 TRIM(CONCAT_WS(' ', COALESCE(meta_first_name.meta_value, ''), COALESCE(meta_last_name.meta_value, ''))) 279 ELSE 280 $wpdb->users.display_name 281 END"; 282 $author_name_join = " 283 LEFT JOIN $wpdb->usermeta as meta_first_name ON meta_first_name.user_id = $wpdb->users.ID AND meta_first_name.meta_key = 'first_name' 284 LEFT JOIN $wpdb->usermeta as meta_last_name ON meta_last_name.user_id = $wpdb->users.ID AND meta_last_name.meta_key = 'last_name' 285 "; 286 } else { 287 $author_name_field = "$wpdb->users.display_name"; 288 $author_name_join = ""; 289 } 271 290 272 $author_count = array(); 273 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) { 274 $author_count[$row->post_author] = $row->count; 291 if ( $sort_by == 'name' ) { 292 $author_sort = 'ORDER BY author_name'; 293 } else { 294 $author_sort = 'ORDER BY author_count DESC'; 275 295 } 276 296 297 $count_limit = intval( $count_limit ); 298 if ( $count_limit > 0 ) { 299 $author_limit = "LIMIT $count_limit"; 300 } else { 301 $author_limit = ''; 302 } 303 304 $authors = $wpdb->get_results(" 305 SELECT $wpdb->users.ID, $wpdb->users.user_nicename, COUNT($wpdb->posts.ID) as author_count, $author_name_field as author_name 306 FROM $wpdb->users 307 " . ( !$hide_empty ? "LEFT " : '' ) . "JOIN $wpdb->posts ON $wpdb->posts.post_author = $wpdb->users.ID 308 $author_name_join 309 WHERE ($wpdb->posts.post_type = 'post' OR $wpdb->posts.post_type IS NULL) 310 AND ($wpdb->posts.post_status = 'publish' OR $wpdb->posts.post_status = 'private' OR $wpdb->posts.post_status IS NULL) " . 311 ( $exclude_admin ? "AND $wpdb->users.user_login <> 'admin' " : '' ) . " 312 GROUP BY $wpdb->users.ID 313 $author_sort 314 $author_limit 315 "); 316 277 317 foreach ( (array) $authors as $author ) { 278 318 279 319 $link = ''; 280 320 281 $author = get_userdata( $author->ID ); 282 $posts = (isset($author_count[$author->ID])) ? $author_count[$author->ID] : 0; 283 $name = $author->display_name; 321 $posts = $author->author_count; 322 $name = $author->author_name; 284 323 285 if ( $show_fullname && ($author->first_name != '' && $author->last_name != '') )286 $name = "$author->first_name $author->last_name";287 288 324 if( !$html ) { 289 325 if ( $posts == 0 ) { 290 326 if ( ! $hide_empty ) … … 302 338 if ( ! $hide_empty ) 303 339 $link = $name; 304 340 } else { 305 $link = '<a href="' . get_author_posts_url($author->ID, $author->user_nicename) . '" title="' . esc_attr( sprintf(__("Posts by %s"), $author-> display_name) ) . '">' . $name . '</a>';341 $link = '<a href="' . get_author_posts_url($author->ID, $author->user_nicename) . '" title="' . esc_attr( sprintf(__("Posts by %s"), $author->author_name) ) . '">' . $name . '</a>'; 306 342 307 343 if ( (! empty($feed_image)) || (! empty($feed)) ) { 308 344 $link .= ' ';