@@ -569,42 +569,40 @@ function comment_date( $d = '', $comment_ID = 0 ) {
569569}
570570
571571/**
572- * Retrieve the excerpt of the current comment.
572+ * Retrieves the excerpt of the given comment.
573573 *
574- * Will cut each word and only output the first 20 words with '…' at the end.
575- * If the word count is less than 20, then no truncating is done and no '…'
576- * will appear.
574+ * Returns a maximum of 20 words with an ellipsis appended if necessary.
577575 *
578576 * @since 1.5.0
579577 * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object.
580578 *
581579 * @param int|WP_Comment $comment_ID WP_Comment or ID of the comment for which to get the excerpt.
582580 * Default current comment.
583- * @return string The maybe truncated comment with 20 words or less .
581+ * @return string The possibly truncated comment excerpt .
584582 */
585583function get_comment_excerpt ( $ comment_ID = 0 ) {
586584 $ comment = get_comment ( $ comment_ID );
587- $ comment_text = strip_tags ( str_replace ( array ( "\n" , "\r" ), ' ' , $ comment ->comment_content ) );
588- $ words = explode ( ' ' , $ comment_text );
585+
586+ if ( ! post_password_required ( $ comment ->comment_post_ID ) ) {
587+ $ comment_text = strip_tags ( str_replace ( array ( "\n" , "\r" ), ' ' , $ comment ->comment_content ) );
588+ } else {
589+ $ comment_text = __ ( 'Password protected ' );
590+ }
591+
592+ /* translators: Maximum number of words used in a comment excerpt. */
593+ $ comment_excerpt_length = intval ( _x ( '20 ' , 'comment_excerpt_length ' ) );
589594
590595 /**
591- * Filters the amount of words used in the comment excerpt.
596+ * Filters the maximum number of words used in the comment excerpt.
592597 *
593598 * @since 4.4.0
594599 *
595600 * @param int $comment_excerpt_length The amount of words you want to display in the comment excerpt.
596601 */
597- $ comment_excerpt_length = apply_filters ( 'comment_excerpt_length ' , 20 );
602+ $ comment_excerpt_length = apply_filters ( 'comment_excerpt_length ' , $ comment_excerpt_length );
598603
599- $ use_ellipsis = count ( $ words ) > $ comment_excerpt_length ;
600- if ( $ use_ellipsis ) {
601- $ words = array_slice ( $ words , 0 , $ comment_excerpt_length );
602- }
604+ $ excerpt = wp_trim_words ( $ comment_text , $ comment_excerpt_length , '… ' );
603605
604- $ excerpt = trim ( join ( ' ' , $ words ) );
605- if ( $ use_ellipsis ) {
606- $ excerpt .= '… ' ;
607- }
608606 /**
609607 * Filters the retrieved comment excerpt.
610608 *
0 commit comments