Ticket #5407: 5407.diff
| File 5407.diff, 4.6 KB (added by , 18 years ago) |
|---|
-
wp-includes/author-template.php
372 372 $r = wp_parse_args( $args, $defaults ); 373 373 extract($r, EXTR_SKIP); 374 374 375 $exclude_admin = $exclude_admin ? "WHERE user_login <> 'admin'" : ''; 376 375 377 $return = ''; 376 378 377 // TODO: Move select to get_authors(). 378 $authors = $wpdb->get_results("SELECT ID, user_nicename from $wpdb->users " . ($exclude_admin ? "WHERE user_login <> 'admin' " : '') . "ORDER BY display_name"); 379 $authors = (array) $wpdb->get_results(" 380 SELECT $wpdb->users.ID, user_nicename, display_name, COUNT($wpdb->posts.ID) AS posts 381 FROM $wpdb->users " . (!$hide_empty ? 'LEFT' : '') . " JOIN $wpdb->posts 382 ON $wpdb->posts.post_author = $wpdb->users.ID AND post_type = 'post' AND " . get_private_posts_cap_sql( 'post' ) . " 383 $exclude_admin 384 GROUP BY post_author 385 ORDER BY display_name"); 379 386 380 $author_count = array(); 381 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) { 382 $author_count[$row->post_author] = $row->count; 383 } 387 if ( empty($authors) ) return false; 384 388 385 foreach ( (array) $authors as $author ) { 386 $author = get_userdata( $author->ID ); 387 $posts = (isset($author_count[$author->ID])) ? $author_count[$author->ID] : 0; 388 $name = $author->display_name; 389 if ( $show_fullname ) { 390 $user_ids = $wpdb->get_col(null); 389 391 390 if ( $show_fullname && ($author->first_name != '' && $author->last_name != '') ) 391 $name = "$author->first_name $author->last_name"; 392 $meta = (array) $wpdb->get_results(" 393 SELECT user_id, meta_key, meta_value 394 FROM $wpdb->usermeta 395 WHERE user_id IN (" . join(',', $user_ids) . ") AND (meta_key = 'first_name' OR meta_key = 'last_name') 396 ORDER BY meta_key, meta_value, user_id"); 392 397 393 if ( !($posts == 0 && $hide_empty) ) 394 $return .= '<li>'; 395 if ( $posts == 0 ) { 396 if ( !$hide_empty ) 397 $link = $name; 398 } else { 399 $link = '<a href="' . get_author_posts_url($author->ID, $author->user_nicename) . '" title="' . sprintf(__("Posts by %s"), attribute_escape($author->display_name)) . '">' . $name . '</a>'; 398 $user_meta = array(); 399 foreach ($meta as $v) 400 $user_meta[$v->user_id][$v->meta_key] = $v->meta_value; 401 } 400 402 401 if ( (! empty($feed_image)) || (! empty($feed)) ) { 402 $link .= ' '; 403 if (empty($feed_image)) 404 $link .= '('; 405 $link .= '<a href="' . get_author_rss_link(0, $author->ID, $author->user_nicename) . '"'; 403 foreach ($authors as $author) { 404 $name = $author->display_name; 405 if ( $show_fullname && !empty($user_meta[$author->ID]['first_name']) && !empty($user_meta[$author->ID]['last_name']) ) 406 $name = trim($user_meta[$author->ID]['first_name'] . ' ' . $user_meta[$author->ID]['last_name']); 406 407 407 if ( !empty($feed)) {408 $title = ' title="' . $feed . '"';409 $alt = ' alt="' . $feed . '"';410 $name = $feed;411 $link .= $title;412 }408 if ( $hide_empty && 0 == $author->posts ) { 409 $return .= '<li>' . $name . '</li>'; 410 continue; 411 } 412 $return .= '<li>'; 413 $link = '<a href="' . get_author_posts_url($author->ID, $author->user_nicename) . '" title="' . sprintf(__("Posts by %s"), attribute_escape($author->display_name)) . '">' . $name . '</a>'; 413 414 414 $link .= '>'; 415 if ( (! empty($feed_image)) || (! empty($feed)) ) { 416 $link .= ' '; 417 if (empty($feed_image)) 418 $link .= '('; 419 $link .= '<a href="' . get_author_rss_link(0, $author->ID, $author->user_nicename) . '"'; 415 420 416 if ( !empty($feed_image) ) 417 $link .= "<img src=\"$feed_image\" border=\"0\"$alt$title" . ' />'; 418 else 419 $link .= $name; 421 if ( !empty($feed) ) { 422 $title = ' title="' . $feed . '"'; 423 $alt = ' alt="' . $feed . '"'; 424 $name = $feed; 425 $link .= $title; 426 } 420 427 421 $link .= '</a>';428 $link .= '>'; 422 429 423 if ( empty($feed_image) ) 424 $link .= ')'; 425 } 430 if ( !empty($feed_image) ) 431 $link .= "<img src=\"$feed_image\" border=\"0\"$alt$title" . ' />'; 432 else 433 $link .= $name; 426 434 427 if ( $optioncount ) 428 $link .= ' ('. $posts . ')'; 435 $link .= '</a>'; 429 436 437 if ( empty($feed_image) ) 438 $link .= ')'; 430 439 } 431 440 432 if ( !($posts == 0 && $hide_empty) ) 433 $return .= $link . '</li>'; 441 if ( $optioncount ) 442 $link .= ' ('. $author->posts . ')'; 443 444 $return .= $link . '</li>'; 434 445 } 446 435 447 if ( !$echo ) 436 448 return $return; 437 449 echo $return;