Ticket #3567: 3567.author-template.php.diff

File 3567.author-template.php.diff, 4.4 kB (added by rob1n, 2 years ago)

wp_list_authors()

  • wp-includes/author-template.php

    old new  
    180180        else 
    181181                parse_str($args, $r); 
    182182 
    183         $defaults = array('optioncount' => false, 'exclude_admin' => true, 'show_fullname' => false, 'hide_empty' => true, 
    184                 'feed' => '', 'feed_image' => ''); 
     183        $defaults = array( 
     184                'optioncount' => false,  
     185                'exclude_admin' => true,  
     186                'show_fullname' => false,  
     187                'hide_empty' => true,  
     188                'feed' => '',  
     189                'feed_image' => '',  
     190                'format' => 'html',  
     191                'before' => '',  
     192                'after' => '' 
     193        ); 
     194         
    185195        $r = array_merge($defaults, $r); 
    186196        extract($r); 
    187197         
     
    192202        foreach ((array) $wpdb->get_results("SELECT DISTINCT post_author, COUNT(ID) AS count FROM $wpdb->posts WHERE post_status = 'publish' GROUP BY post_author") as $row) { 
    193203                $author_count[$row->post_author] = $row->count; 
    194204        } 
    195  
    196         foreach ( (array) $authors as $author ) { 
    197                 $author = get_userdata( $author->ID ); 
     205         
     206        // Set up $output variable 
     207        $output = ''; 
     208         
     209        foreach ((array) $authors as $author) { 
     210                // Set up some variables 
     211                $author = get_userdata($author->ID); 
    198212                $posts = (isset($author_count[$author->ID])) ? $author_count[$author->ID] : 0; 
    199213                $name = $author->nickname; 
    200  
    201                 if ( $show_fullname && ($author->first_name != '' && $author->last_name != '') ) 
    202                         $name = "$author->first_name $author->last_name"; 
    203  
    204                 if ( !($posts == 0 && $hide_empty) ) 
    205                         echo "<li>"; 
    206                 if ( $posts == 0 ) { 
    207                         if ( !$hide_empty ) 
    208                                 $link = $name; 
     214                 
     215                // Show their full name, and make sure first/last aren't blank 
     216                if ($show_fullname && (!empty($author->first_name) && !empty($author->last_name))) { 
     217                        $name = $author->first_name . ' ' . $author->last_name; 
     218                } 
     219                 
     220                // Skip "empty" users when we don't want to show them 
     221                if ($hide_empty && $posts == 0) { 
     222                        continue; 
     223                } 
     224                 
     225                $output .= "\t"; 
     226                 
     227                // Start out with different formats, depending on $format 
     228                switch ($format) { 
     229                        case 'html': 
     230                                $output .= '<li>'; 
     231                                break; 
     232                } 
     233                 
     234                // Put the before stuff on 
     235                $output .= $before; 
     236                 
     237                // By now, we've skipped empty users if !$hide_empty 
     238                // so just put in their name in place of a link 
     239                if ($posts == 0) { 
     240                        $output .= $name; 
     241                // Got posts, add on link 
    209242                } else { 
    210                         $link = '<a href="' . get_author_posts_url($author->ID, $author->user_nicename) . '" title="' . sprintf(__("Posts by %s"), attribute_escape($author->display_name)) . '">' . $name . '</a>'; 
    211  
    212                         if ( (! empty($feed_image)) || (! empty($feed)) ) { 
    213                                 $link .= ' '; 
    214                                 if (empty($feed_image)) 
    215                                         $link .= '('; 
    216                                 $link .= '<a href="' . get_author_rss_link(0, $author->ID, $author->user_nicename) . '"'; 
    217  
    218                                 if ( !empty($feed) ) { 
    219                                         $title = ' title="' . $feed . '"'; 
    220                                         $alt = ' alt="' . $feed . '"'; 
    221                                         $name = $feed; 
    222                                         $link .= $title; 
     243                        // Add author's page link 
     244                        $output .= '<a href="' . get_author_posts_url($author->ID, $author->user_nicename) . '" '  
     245                                . sprintf(__('Posts by %s'), attribute_escape($author->display_name)) . '">' . $name . '</a>'; 
     246                         
     247                        // Either got a feed text or feed image 
     248                        if (!empty($feed) || !empty($feed_image)) { 
     249                                $output .= ' '; 
     250                                 
     251                                // If we're using text feed link 
     252                                if (empty($feed_image)) { 
     253                                        $output .= '(<a href="' . get_author_rss_link(0, $author->ID, $author->user_nicename) . '" title="' . attribute_escape($feed) . '">' . $feed . '</a>)'; 
     254                                // Okay, we're using an image link 
     255                                } else { 
     256                                        $output .= '<a href="' . get_author_rss_link(0, $author->ID, $author->user_nicename) . '" title="' . attribute_escape($feed) . '"><img src="' . $feed_image . '" alt="' . $feed . '" title="' . $feed . '" /></a>'; 
    223257                                } 
    224  
    225                                 $link .= '>'; 
    226  
    227                                 if ( !empty($feed_image) ) 
    228                                         $link .= "<img src=\"$feed_image\" border=\"0\"$alt$title" . ' />'; 
    229                                 else 
    230                                         $link .= $name; 
    231  
    232                                 $link .= '</a>'; 
    233  
    234                                 if ( empty($feed_image) ) 
    235                                         $link .= ')'; 
    236258                        } 
    237  
    238                         if ( $optioncount ) 
    239                                 $link .= ' ('. $posts . ')'; 
    240  
    241259                } 
    242  
    243                 if ( !($posts == 0 && $hide_empty) ) 
    244                         echo "$link</li>"; 
     260                 
     261                // Put the after on the line 
     262                $output .= $after; 
     263                 
     264                // Add the end tag, based on format 
     265                switch ($format) { 
     266                        case 'html': 
     267                                $output .= '</li>'; 
     268                                break; 
     269                } 
     270                 
     271                // Add a newline 
     272                $output .= "\n"; 
    245273        } 
     274         
     275        // Echo our output 
     276        echo $output; 
    246277} 
    247278 
    248279?>