Changeset 47986
- Timestamp:
- 06/10/2020 07:25:25 PM (3 years ago)
- Location:
- branches/5.2
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/5.2
-
branches/5.2/src/wp-includes/comment-template.php
r47917 r47986 592 592 */ 593 593 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. 594 $comment = get_comment( $comment_ID ); 595 596 if ( ! post_password_required( $comment->comment_post_ID ) ) { 597 $comment_text = strip_tags( str_replace( array( "\n", "\r" ), ' ', $comment->comment_content ) ); 598 } else { 599 $comment_text = __( 'Password protected' ); 600 } 601 602 /* translators: Maximum number of words used in a comment excerpt. */ 603 $comment_excerpt_length = intval( _x( '20', 'comment_excerpt_length' ) ); 604 605 /** 606 * Filters the maximum number of words used in the comment excerpt. 600 607 * 601 608 * @since 4.4.0 … … 603 610 * @param int $comment_excerpt_length The amount of words you want to display in the comment excerpt. 604 611 */ 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 } 612 $comment_excerpt_length = apply_filters( 'comment_excerpt_length', $comment_excerpt_length ); 613 614 $excerpt = wp_trim_words( $comment_text, $comment_excerpt_length, '…' ); 615 616 616 /** 617 617 * Filters the retrieved comment excerpt. … … 2312 2312 'must_log_in' => '<p class="must-log-in">' . sprintf( 2313 2313 /* translators: %s: login URL */ 2314 2314 __( 'You must be <a href="%s">logged in</a> to post a comment.' ), 2315 2315 wp_login_url( apply_filters( 'the_permalink', get_permalink( $post_id ), $post_id ) ) 2316 2316 ) . '</p>', … … 2318 2318 'logged_in_as' => '<p class="logged-in-as">' . sprintf( 2319 2319 /* translators: 1: edit user link, 2: accessibility text, 3: user name, 4: logout URL */ 2320 2320 __( '<a href="%1$s" aria-label="%2$s">Logged in as %3$s</a>. <a href="%4$s">Log out?</a>' ), 2321 2321 get_edit_user_link(), 2322 2322 /* translators: %s: user name */ -
branches/5.2/tests/phpunit/tests/blocks/render.php
r45139 r47986 290 290 } 291 291 292 public function test_render_latest_comments_on_password_protected_post() { 293 $post_id = self::factory()->post->create( 294 array( 295 'post_password' => 'password', 296 ) 297 ); 298 $comment_text = wp_generate_password( 10, false ); 299 self::factory()->comment->create( 300 array( 301 'comment_post_ID' => $post_id, 302 'comment_content' => $comment_text, 303 ) 304 ); 305 $comments = do_blocks( '<!-- wp:latest-comments {"commentsToShow":1,"displayExcerpt":true} /-->' ); 306 307 $this->assertNotContains( $comment_text, $comments ); 308 } 309 292 310 /** 293 311 * @ticket 45109
Note: See TracChangeset
for help on using the changeset viewer.