Changeset 47988 for branches/5.0/src/wp-includes/comment-template.php
- Timestamp:
- 06/10/2020 07:31:08 PM (5 years ago)
- Location:
- branches/5.0
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/5.0
-
branches/5.0/src/wp-includes/comment-template.php
r43827 r47988 570 570 571 571 /** 572 * Retrieve the excerpt of the current comment. 573 * 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. 572 * Retrieves the excerpt of the given comment. 573 * 574 * Returns a maximum of 20 words with an ellipsis appended if necessary. 577 575 * 578 576 * @since 1.5.0 … … 581 579 * @param int|WP_Comment $comment_ID WP_Comment or ID of the comment for which to get the excerpt. 582 580 * Default current comment. 583 * @return string The maybe truncated comment with 20 words or less.581 * @return string The possibly truncated comment excerpt. 584 582 */ 585 583 function get_comment_excerpt( $comment_ID = 0 ) { 586 584 $comment = get_comment( $comment_ID ); 587 $comment_text = strip_tags( str_replace( array( "\n", "\r" ), ' ', $comment->comment_content ) ); 588 $words = explode( ' ', $comment_text ); 589 590 /** 591 * Filters the amount of words used in the comment excerpt. 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' ) ); 594 595 /** 596 * Filters the maximum number of words used in the comment excerpt. 592 597 * 593 598 * @since 4.4.0 … … 595 600 * @param int $comment_excerpt_length The amount of words you want to display in the comment excerpt. 596 601 */ 597 $comment_excerpt_length = apply_filters( 'comment_excerpt_length', 20 ); 598 599 $use_ellipsis = count( $words ) > $comment_excerpt_length; 600 if ( $use_ellipsis ) { 601 $words = array_slice( $words, 0, $comment_excerpt_length ); 602 } 603 604 $excerpt = trim( join( ' ', $words ) ); 605 if ( $use_ellipsis ) { 606 $excerpt .= '…'; 607 } 602 $comment_excerpt_length = apply_filters( 'comment_excerpt_length', $comment_excerpt_length ); 603 604 $excerpt = wp_trim_words( $comment_text, $comment_excerpt_length, '…' ); 605 608 606 /** 609 607 * Filters the retrieved comment excerpt.
Note: See TracChangeset
for help on using the changeset viewer.