Changeset 47987 for branches/5.1
- Timestamp:
- 06/10/2020 07:29:06 PM (5 years ago)
- Location:
- branches/5.1
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/5.1
-
branches/5.1/src/wp-includes/comment-template.php
r47918 r47987 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 $comment = get_comment( $comment_ID ); 595 $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. 592 $comment = get_comment( $comment_ID ); 593 594 if ( ! post_password_required( $comment->comment_post_ID ) ) { 595 $comment_text = strip_tags( str_replace( array( "\n", "\r" ), ' ', $comment->comment_content ) ); 596 } else { 597 $comment_text = __( 'Password protected' ); 598 } 599 600 /* translators: Maximum number of words used in a comment excerpt. */ 601 $comment_excerpt_length = intval( _x( '20', 'comment_excerpt_length' ) ); 602 603 /** 604 * Filters the maximum number of words used in the comment excerpt. 600 605 * 601 606 * @since 4.4.0 … … 603 608 * @param int $comment_excerpt_length The amount of words you want to display in the comment excerpt. 604 609 */ 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 } 610 $comment_excerpt_length = apply_filters( 'comment_excerpt_length', $comment_excerpt_length ); 611 612 $excerpt = wp_trim_words( $comment_text, $comment_excerpt_length, '…' ); 613 616 614 /** 617 615 * Filters the retrieved comment excerpt. … … 2312 2310 'must_log_in' => '<p class="must-log-in">' . sprintf( 2313 2311 /* translators: %s: login URL */ 2314 2312 __( 'You must be <a href="%s">logged in</a> to post a comment.' ), 2315 2313 wp_login_url( apply_filters( 'the_permalink', get_permalink( $post_id ), $post_id ) ) 2316 2314 ) . '</p>', … … 2318 2316 'logged_in_as' => '<p class="logged-in-as">' . sprintf( 2319 2317 /* translators: 1: edit user link, 2: accessibility text, 3: user name, 4: logout URL */ 2320 2318 __( '<a href="%1$s" aria-label="%2$s">Logged in as %3$s</a>. <a href="%4$s">Log out?</a>' ), 2321 2319 get_edit_user_link(), 2322 2320 /* translators: %s: user name */ -
branches/5.1/tests/phpunit/tests/blocks/render.php
r44261 r47987 264 264 } 265 265 266 public function test_render_latest_comments_on_password_protected_post() { 267 $post_id = self::factory()->post->create( 268 array( 269 'post_password' => 'password', 270 ) 271 ); 272 $comment_text = wp_generate_password( 10, false ); 273 self::factory()->comment->create( 274 array( 275 'comment_post_ID' => $post_id, 276 'comment_content' => $comment_text, 277 ) 278 ); 279 $comments = do_blocks( '<!-- wp:latest-comments {"commentsToShow":1,"displayExcerpt":true} /-->' ); 280 281 $this->assertNotContains( $comment_text, $comments ); 282 } 283 266 284 /** 267 285 * @ticket 45109
Note: See TracChangeset
for help on using the changeset viewer.