Changeset 45505 for trunk/src/wp-includes/comment-template.php
- Timestamp:
- 06/08/2019 06:41:08 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/comment-template.php
r45496 r45505 578 578 579 579 /** 580 * Retrieve the excerpt of the current comment. 581 * 582 * Will cut each word and only output the first 20 words with '…' at the end. 583 * If the word count is less than 20, then no truncating is done and no '…' 584 * will appear. 580 * Retrieves the excerpt of the given comment. 581 * 582 * Returns a maximum of 20 words with an ellipsis appended if necessary. 585 583 * 586 584 * @since 1.5.0 … … 589 587 * @param int|WP_Comment $comment_ID WP_Comment or ID of the comment for which to get the excerpt. 590 588 * Default current comment. 591 * @return string The maybe truncated comment with 20 words or less.589 * @return string The possibly truncated comment excerpt. 592 590 */ 593 591 function get_comment_excerpt( $comment_ID = 0 ) { 594 592 $comment = get_comment( $comment_ID ); 595 593 $comment_text = strip_tags( str_replace( array( "\n", "\r" ), ' ', $comment->comment_content ) ); 596 $words = explode( ' ', $comment_text ); 597 598 /** 599 * Filters the amount of words used in the comment excerpt. 594 595 /* translators: Maximum number of words used in a comment excerpt. */ 596 $comment_excerpt_length = intval( _x( '20', 'comment_excerpt_length' ) ); 597 598 /** 599 * Filters the maximum number of words used in the comment excerpt. 600 600 * 601 601 * @since 4.4.0 … … 603 603 * @param int $comment_excerpt_length The amount of words you want to display in the comment excerpt. 604 604 */ 605 $comment_excerpt_length = apply_filters( 'comment_excerpt_length', 20 ); 606 607 $use_ellipsis = count( $words ) > $comment_excerpt_length; 608 if ( $use_ellipsis ) { 609 $words = array_slice( $words, 0, $comment_excerpt_length ); 610 } 611 612 $excerpt = trim( join( ' ', $words ) ); 613 if ( $use_ellipsis ) { 614 $excerpt .= '…'; 615 } 605 $comment_excerpt_length = apply_filters( 'comment_excerpt_length', $comment_excerpt_length ); 606 607 $excerpt = wp_trim_words( $comment_text, $comment_excerpt_length, '…' ); 608 616 609 /** 617 610 * Filters the retrieved comment excerpt.
Note: See TracChangeset
for help on using the changeset viewer.