Make WordPress Core

Ticket #27526: 27526.2.diff

File 27526.2.diff, 1.4 KB (added by wonderboymusic, 10 years ago)
  • src/wp-includes/comment-template.php

     
    565565 */
    566566function get_comment_excerpt( $comment_ID = 0 ) {
    567567        $comment = get_comment( $comment_ID );
    568         $comment_text = strip_tags($comment->comment_content);
    569         $blah = explode(' ', $comment_text);
     568        $comment_text = strip_tags( str_replace( array( "\n", "\r" ), ' ', $comment->comment_content ) );
     569        $words = explode( ' ', $comment_text );
    570570
    571         if (count($blah) > 20) {
    572                 $k = 20;
    573                 $use_dotdotdot = 1;
    574         } else {
    575                 $k = count($blah);
    576                 $use_dotdotdot = 0;
     571        /**
     572         * Filter the amount of words used in the comment excerpt.
     573         *
     574         * @since 4.4.0
     575         *
     576         * @param int $comment_excerpt_length The amount of words you want to display in the comment excerpt.
     577         */
     578        $comment_excerpt_length = apply_filters( 'comment_excerpt_length', 20 );
     579
     580        $use_ellipsis = count( $words ) > $comment_excerpt_length;
     581        if ( $use_ellipsis ) {
     582                $words = array_slice( $words, 0, $comment_excerpt_length );
    577583        }
    578584
    579         $excerpt = '';
    580         for ($i=0; $i<$k; $i++) {
    581                 $excerpt .= $blah[$i] . ' ';
     585        $excerpt = trim( join( ' ', $words ) );
     586        if ( $use_ellipsis ) {
     587                $excerpt .= '&hellip;';
    582588        }
    583         $excerpt .= ($use_dotdotdot) ? '&hellip;' : '';
    584 
    585589        /**
    586590         * Filter the retrieved comment excerpt.
    587591         *