Ticket #5407: 5407_2.diff
| File 5407_2.diff, 4.6 KB (added by , 18 years ago) |
|---|
-
wp-includes/author-template.php
442 442 $r = wp_parse_args( $args, $defaults ); 443 443 extract($r, EXTR_SKIP); 444 444 445 $exclude_admin = $exclude_admin ? "WHERE user_login <> 'admin'" : ''; 446 445 447 $return = ''; 446 448 447 /** @todo Move select to get_authors(). */ 448 $authors = $wpdb->get_results("SELECT ID, user_nicename from $wpdb->users " . ($exclude_admin ? "WHERE user_login <> 'admin' " : '') . "ORDER BY display_name"); 449 $authors = (array) $wpdb->get_results(" 450 SELECT $wpdb->users.ID, user_nicename, display_name, COUNT($wpdb->posts.ID) AS posts 451 FROM $wpdb->users " . (!$hide_empty ? 'LEFT' : '') . " JOIN $wpdb->posts 452 ON $wpdb->posts.post_author = $wpdb->users.ID AND post_type = 'post' AND " . get_private_posts_cap_sql( 'post' ) . " 453 $exclude_admin 454 GROUP BY post_author 455 ORDER BY display_name"); 449 456 450 $author_count = array(); 451 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) { 452 $author_count[$row->post_author] = $row->count; 453 } 457 if ( empty($authors) ) return false; 454 458 455 foreach ( (array) $authors as $author ) { 456 $author = get_userdata( $author->ID ); 457 $posts = (isset($author_count[$author->ID])) ? $author_count[$author->ID] : 0; 458 $name = $author->display_name; 459 if ( $show_fullname ) { 460 $user_ids = $wpdb->get_col(null); 459 461 460 if ( $show_fullname && ($author->first_name != '' && $author->last_name != '') ) 461 $name = "$author->first_name $author->last_name"; 462 $meta = (array) $wpdb->get_results(" 463 SELECT user_id, meta_key, meta_value 464 FROM $wpdb->usermeta 465 WHERE user_id IN (" . join(',', $user_ids) . ") AND (meta_key = 'first_name' OR meta_key = 'last_name') 466 ORDER BY meta_key, meta_value, user_id"); 462 467 463 if ( !($posts == 0 && $hide_empty) ) 464 $return .= '<li>'; 465 if ( $posts == 0 ) { 466 if ( !$hide_empty ) 467 $link = $name; 468 } else { 469 $link = '<a href="' . get_author_posts_url($author->ID, $author->user_nicename) . '" title="' . sprintf(__("Posts by %s"), attribute_escape($author->display_name)) . '">' . $name . '</a>'; 468 $user_meta = array(); 469 foreach ($meta as $v) 470 $user_meta[$v->user_id][$v->meta_key] = $v->meta_value; 471 } 470 472 471 if ( (! empty($feed_image)) || (! empty($feed)) ) { 472 $link .= ' '; 473 if (empty($feed_image)) 474 $link .= '('; 475 $link .= '<a href="' . get_author_rss_link(0, $author->ID, $author->user_nicename) . '"'; 473 foreach ($authors as $author) { 474 $name = $author->display_name; 475 if ( $show_fullname && !empty($user_meta[$author->ID]['first_name']) && !empty($user_meta[$author->ID]['last_name']) ) 476 $name = trim($user_meta[$author->ID]['first_name'] . ' ' . $user_meta[$author->ID]['last_name']); 476 477 477 if ( !empty($feed)) {478 $title = ' title="' . $feed . '"';479 $alt = ' alt="' . $feed . '"';480 $name = $feed;481 $link .= $title;482 }478 if ( $hide_empty && 0 == $author->posts ) { 479 $return .= '<li>' . $name . '</li>'; 480 continue; 481 } 482 $return .= '<li>'; 483 $link = '<a href="' . get_author_posts_url($author->ID, $author->user_nicename) . '" title="' . sprintf(__("Posts by %s"), attribute_escape($author->display_name)) . '">' . $name . '</a>'; 483 484 484 $link .= '>'; 485 if ( (! empty($feed_image)) || (! empty($feed)) ) { 486 $link .= ' '; 487 if (empty($feed_image)) 488 $link .= '('; 489 $link .= '<a href="' . get_author_rss_link(0, $author->ID, $author->user_nicename) . '"'; 485 490 486 if ( !empty($feed_image) ) 487 $link .= "<img src=\"$feed_image\" border=\"0\"$alt$title" . ' />'; 488 else 489 $link .= $name; 491 if ( !empty($feed) ) { 492 $title = ' title="' . $feed . '"'; 493 $alt = ' alt="' . $feed . '"'; 494 $name = $feed; 495 $link .= $title; 496 } 490 497 491 $link .= '</a>';498 $link .= '>'; 492 499 493 if ( empty($feed_image) ) 494 $link .= ')'; 495 } 500 if ( !empty($feed_image) ) 501 $link .= "<img src=\"$feed_image\" border=\"0\"$alt$title" . ' />'; 502 else 503 $link .= $name; 496 504 497 if ( $optioncount ) 498 $link .= ' ('. $posts . ')'; 505 $link .= '</a>'; 499 506 507 if ( empty($feed_image) ) 508 $link .= ')'; 500 509 } 501 510 502 if ( !($posts == 0 && $hide_empty) ) 503 $return .= $link . '</li>'; 511 if ( $optioncount ) 512 $link .= ' ('. $author->posts . ')'; 513 514 $return .= $link . '</li>'; 504 515 } 516 505 517 if ( !$echo ) 506 518 return $return; 507 519 echo $return;