Make WordPress Core

Ticket #27526: 27526-4.diff

File 27526-4.diff, 1.5 KB (added by dannydehaan, 12 years ago)

27526-2 - Fix in excerpt length with \n or \r. Fix for "trailing space"

  • wp-includes/comment-template.php

    diff --git a/wp-includes/comment-template.php b/wp-includes/comment-template.php
    index b87844b..4fc4941 100644
    a b function comment_date( $d = '', $comment_ID = 0 ) { 
    506506 */
    507507function get_comment_excerpt( $comment_ID = 0 ) {
    508508        $comment = get_comment( $comment_ID );
    509         $comment_text = strip_tags($comment->comment_content);
    510         $blah = explode(' ', $comment_text);
    511         if (count($blah) > 20) {
    512                 $k = 20;
    513                 $use_dotdotdot = 1;
     509        $comment_text = strip_tags( str_replace( array( "\n", "\r" ), ' ', $comment->comment_content ) );
     510        $words = explode( ' ', $comment_text );
     511        $excerpt = '';
     512        $excerpt_parts = array();
     513
     514        /**
     515         * Filter the amount of words used in the comment excerpt.
     516         *
     517         * @since 3.9
     518         *
     519         * @param int $comment_excerpt_length The amount of words you want to display in the comment excerpt.
     520         */
     521        $comment_excerpt_length = apply_filters( 'comment_excerpt_length', 20 );
     522
     523        if ( count( $words ) > $comment_excerpt_length ) {
     524                $k = $comment_excerpt_length;
     525                $use_ellipsis = 1;
    514526        } else {
    515                 $k = count($blah);
    516                 $use_dotdotdot = 0;
     527                $k = count( $words );
     528                $use_ellipsis = 0;
    517529        }
    518         $excerpt = '';
    519         for ($i=0; $i<$k; $i++) {
    520                 $excerpt .= $blah[$i] . ' ';
     530
     531        for ( $i = 0; $i < $k; $i++ ) {
     532                $excerpt_parts[] = $words[ $i ];
    521533        }
    522         $excerpt .= ($use_dotdotdot) ? '&hellip;' : '';
     534
     535        $excerpt = implode( ' ', $excerpt_parts );
     536        $excerpt .= ( 1 === $use_ellipsis ? '&hellip;' : '' );
     537
    523538        return apply_filters('get_comment_excerpt', $excerpt);
    524539}
    525540