Make WordPress Core


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/author-template.php

    r15148 r17100  
    103103        $authordata = get_userdata( $user_id );
    104104
     105    // Keys used as object vars cannot have dashes.
     106    $field = str_replace('-', '', $field);
    105107    $field = strtolower($field);
    106108    $user_field = "user_$field";
     
    212214
    213215/**
    214  * Retrieve the URL to the author page of the author of the current post.
     216 * Retrieve the URL to the author page for the user with the ID provided.
    215217 *
    216218 * @since 2.1.0
     
    224226
    225227    if ( empty($link) ) {
    226         $file = home_url() . '/';
     228        $file = home_url( '/' );
    227229        $link = $file . '?author=' . $auth_ID;
    228230    } else {
     
    233235        }
    234236        $link = str_replace('%author%', $author_nicename, $link);
    235         $link = home_url() . trailingslashit($link);
     237        $link = home_url( user_trailingslashit( $link ) );
    236238    }
    237239
     
    258260 * <li>style (string) ('list'): Whether to display list of authors in list form
    259261 * or as a string.</li>
    260  * <li>html (bool) (true): Whether to list the items in html for or plaintext.
     262 * <li>html (bool) (true): Whether to list the items in html form or plaintext.
    261263 * </li>
    262264 * </ul>
     
    271273
    272274    $defaults = array(
     275        'orderby' => 'name', 'order' => 'ASC', 'number' => '',
    273276        'optioncount' => false, 'exclude_admin' => true,
    274277        'show_fullname' => false, 'hide_empty' => true,
     
    277280    );
    278281
    279     $r = wp_parse_args( $args, $defaults );
    280     extract($r, EXTR_SKIP);
     282    $args = wp_parse_args( $args, $defaults );
     283    extract( $args, EXTR_SKIP );
     284
    281285    $return = '';
    282286
    283     /** @todo Move select to get_authors(). */
    284     $users = get_users_of_blog();
    285     $author_ids = array();
    286     foreach ( (array) $users as $user )
    287         $author_ids[] = $user->user_id;
    288     if ( count($author_ids) > 0  ) {
    289         $author_ids = implode(',', $author_ids );
    290         $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" );
    291     } else {
    292         $authors = array();
    293     }
     287    $query_args = wp_array_slice_assoc( $args, array( 'orderby', 'order', 'number' ) );
     288    $query_args['fields'] = 'ids';
     289    $authors = get_users( $query_args );
    294290
    295291    $author_count = array();
     
    297293        $author_count[$row->post_author] = $row->count;
    298294
    299     foreach ( (array) $authors as $author ) {
     295    foreach ( $authors as $author_id ) {
     296        $author = get_userdata( $author_id );
     297
     298        if ( $exclude_admin && 'admin' == $author->display_name )
     299            continue;
     300
     301        $posts = isset( $author_count[$author->ID] ) ? $author_count[$author->ID] : 0;
     302
     303        if ( !$posts && $hide_empty )
     304            continue;
    300305
    301306        $link = '';
    302307
    303         $author = get_userdata( $author->ID );
    304         $posts = (isset($author_count[$author->ID])) ? $author_count[$author->ID] : 0;
    305         $name = $author->display_name;
    306 
    307         if ( $show_fullname && ($author->first_name != '' && $author->last_name != '') )
     308        if ( $show_fullname && $author->first_name && $author->last_name )
    308309            $name = "$author->first_name $author->last_name";
    309 
    310         if( !$html ) {
    311             if ( $posts == 0 ) {
    312                 if ( ! $hide_empty )
    313                     $return .= $name . ', ';
    314             } else
    315                 $return .= $name . ', ';
    316 
    317             // No need to go further to process HTML.
    318             continue;
     310        else
     311            $name = $author->display_name;
     312
     313        if ( !$html ) {
     314            $return .= $name . ', ';
     315
     316            continue; // No need to go further to process HTML.
    319317        }
    320318
    321         if ( !($posts == 0 && $hide_empty) && 'list' == $style )
     319        if ( 'list' == $style ) {
    322320            $return .= '<li>';
    323         if ( $posts == 0 ) {
    324             if ( ! $hide_empty )
    325                 $link = $name;
    326         } else {
    327             $link = '<a href="' . get_author_posts_url($author->ID, $author->user_nicename) . '" title="' . esc_attr( sprintf(__("Posts by %s"), $author->display_name) ) . '">' . $name . '</a>';
    328 
    329             if ( (! empty($feed_image)) || (! empty($feed)) ) {
    330                 $link .= ' ';
    331                 if (empty($feed_image))
    332                     $link .= '(';
    333                 $link .= '<a href="' . get_author_feed_link($author->ID) . '"';
    334 
    335                 if ( !empty($feed) ) {
    336                     $title = ' title="' . esc_attr($feed) . '"';
    337                     $alt = ' alt="' . esc_attr($feed) . '"';
    338                     $name = $feed;
    339                     $link .= $title;
    340                 }
    341 
    342                 $link .= '>';
    343 
    344                 if ( !empty($feed_image) )
    345                     $link .= "<img src=\"" . esc_url($feed_image) . "\" style=\"border: none;\"$alt$title" . ' />';
    346                 else
    347                     $link .= $name;
    348 
    349                 $link .= '</a>';
    350 
    351                 if ( empty($feed_image) )
    352                     $link .= ')';
     321        }
     322
     323        $link = '<a href="' . get_author_posts_url( $author->ID, $author->user_nicename ) . '" title="' . esc_attr( sprintf(__("Posts by %s"), $author->display_name) ) . '">' . $name . '</a>';
     324
     325        if ( !empty( $feed_image ) || !empty( $feed ) ) {
     326            $link .= ' ';
     327            if ( empty( $feed_image ) ) {
     328                $link .= '(';
    353329            }
    354330
    355             if ( $optioncount )
    356                 $link .= ' ('. $posts . ')';
    357 
     331            $link .= '<a href="' . get_author_feed_link( $author->ID ) . '"';
     332
     333            $alt = $title = '';
     334            if ( !empty( $feed ) ) {
     335                $title = ' title="' . esc_attr( $feed ) . '"';
     336                $alt = ' alt="' . esc_attr( $feed ) . '"';
     337                $name = $feed;
     338                $link .= $title;
     339            }
     340
     341            $link .= '>';
     342
     343            if ( !empty( $feed_image ) )
     344                $link .= '<img src="' . esc_url( $feed_image ) . '" style="border: none;"' . $alt . $title . ' />';
     345            else
     346                $link .= $name;
     347
     348            $link .= '</a>';
     349
     350            if ( empty( $feed_image ) )
     351                $link .= ')';
    358352        }
    359353
    360         if ( $posts || ! $hide_empty )
    361             $return .= $link . ( ( 'list' == $style ) ? '</li>' : ', ' );
     354        if ( $optioncount )
     355            $link .= ' ('. $posts . ')';
     356
     357        $return .= $link;
     358        $return .= ( 'list' == $style ) ? '</li>' : ', ';
    362359    }
    363360
    364     $return = trim($return, ', ');
    365 
    366     if ( ! $echo )
     361    $return = rtrim($return, ', ');
     362
     363    if ( !$echo )
    367364        return $return;
     365
    368366    echo $return;
    369367}
Note: See TracChangeset for help on using the changeset viewer.