Make WordPress Core


Ignore:
File:
1 edited

Legend:

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

    r17100 r15148  
    103103                $authordata = get_userdata( $user_id );
    104104
    105         // Keys used as object vars cannot have dashes.
    106         $field = str_replace('-', '', $field);
    107105        $field = strtolower($field);
    108106        $user_field = "user_$field";
     
    214212
    215213/**
    216  * Retrieve the URL to the author page for the user with the ID provided.
     214 * Retrieve the URL to the author page of the author of the current post.
    217215 *
    218216 * @since 2.1.0
     
    226224
    227225        if ( empty($link) ) {
    228                 $file = home_url( '/' );
     226                $file = home_url() . '/';
    229227                $link = $file . '?author=' . $auth_ID;
    230228        } else {
     
    235233                }
    236234                $link = str_replace('%author%', $author_nicename, $link);
    237                 $link = home_url( user_trailingslashit( $link ) );
     235                $link = home_url() . trailingslashit($link);
    238236        }
    239237
     
    260258 * <li>style (string) ('list'): Whether to display list of authors in list form
    261259 * or as a string.</li>
    262  * <li>html (bool) (true): Whether to list the items in html form or plaintext.
     260 * <li>html (bool) (true): Whether to list the items in html for or plaintext.
    263261 * </li>
    264262 * </ul>
     
    273271
    274272        $defaults = array(
    275                 'orderby' => 'name', 'order' => 'ASC', 'number' => '',
    276273                'optioncount' => false, 'exclude_admin' => true,
    277274                'show_fullname' => false, 'hide_empty' => true,
     
    280277        );
    281278
    282         $args = wp_parse_args( $args, $defaults );
    283         extract( $args, EXTR_SKIP );
    284 
     279        $r = wp_parse_args( $args, $defaults );
     280        extract($r, EXTR_SKIP);
    285281        $return = '';
    286282
    287         $query_args = wp_array_slice_assoc( $args, array( 'orderby', 'order', 'number' ) );
    288         $query_args['fields'] = 'ids';
    289         $authors = get_users( $query_args );
     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        }
    290294
    291295        $author_count = array();
     
    293297                $author_count[$row->post_author] = $row->count;
    294298
    295         foreach ( $authors as $author_id ) {
    296                 $author = get_userdata( $author_id );
    297 
    298                 if ( $exclude_admin && 'admin' == $author->display_name )
     299        foreach ( (array) $authors as $author ) {
     300
     301                $link = '';
     302
     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                        $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.
    299318                        continue;
    300 
    301                 $posts = isset( $author_count[$author->ID] ) ? $author_count[$author->ID] : 0;
    302 
    303                 if ( !$posts && $hide_empty )
    304                         continue;
    305 
    306                 $link = '';
    307 
    308                 if ( $show_fullname && $author->first_name && $author->last_name )
    309                         $name = "$author->first_name $author->last_name";
    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.
    317319                }
    318320
    319                 if ( 'list' == $style ) {
     321                if ( !($posts == 0 && $hide_empty) && 'list' == $style )
    320322                        $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 .= ')';
     353                        }
     354
     355                        if ( $optioncount )
     356                                $link .= ' ('. $posts . ')';
     357
    321358                }
    322359
    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 .= '(';
    329                         }
    330 
    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 .= ')';
    352                 }
    353 
    354                 if ( $optioncount )
    355                         $link .= ' ('. $posts . ')';
    356 
    357                 $return .= $link;
    358                 $return .= ( 'list' == $style ) ? '</li>' : ', ';
    359         }
    360 
    361         $return = rtrim($return, ', ');
    362 
    363         if ( !$echo )
     360                if ( $posts || ! $hide_empty )
     361                        $return .= $link . ( ( 'list' == $style ) ? '</li>' : ', ' );
     362        }
     363
     364        $return = trim($return, ', ');
     365
     366        if ( ! $echo )
    364367                return $return;
    365 
    366368        echo $return;
    367369}
Note: See TracChangeset for help on using the changeset viewer.