diff --git a/wp-includes/comment-template.php b/wp-includes/comment-template.php index a4372269ad..3ae8a8b1d3 100644 --- a/wp-includes/comment-template.php +++ b/wp-includes/comment-template.php @@ -591,28 +591,28 @@ function comment_date( $d = '', $comment_ID = 0 ) { * @return string The maybe truncated comment with 20 words or less. */ function get_comment_excerpt( $comment_ID = 0 ) { - $comment = get_comment( $comment_ID ); - $comment_text = strip_tags( str_replace( array( "\n", "\r" ), ' ', $comment->comment_content ) ); - $words = explode( ' ', $comment_text ); + $comment = get_comment( $comment_ID ); + + if ( ! post_password_required( $comment->comment_post_ID ) ) { + $comment_text = strip_tags( str_replace( array( "\n", "\r" ), ' ', $comment->comment_content ) ); + } else { + $comment_text = __( 'Password protected' ); + } + + /* translators: Maximum number of words used in a comment excerpt. */ + $comment_excerpt_length = intval( _x( '20', 'comment_excerpt_length' ) ); /** - * Filters the amount of words used in the comment excerpt. + * Filters the maximum number of words used in the comment excerpt. * * @since 4.4.0 * * @param int $comment_excerpt_length The amount of words you want to display in the comment excerpt. */ - $comment_excerpt_length = apply_filters( 'comment_excerpt_length', 20 ); + $comment_excerpt_length = apply_filters( 'comment_excerpt_length', $comment_excerpt_length ); - $use_ellipsis = count( $words ) > $comment_excerpt_length; - if ( $use_ellipsis ) { - $words = array_slice( $words, 0, $comment_excerpt_length ); - } + $excerpt = wp_trim_words( $comment_text, $comment_excerpt_length, '…' ); - $excerpt = trim( join( ' ', $words ) ); - if ( $use_ellipsis ) { - $excerpt .= '…'; - } /** * Filters the retrieved comment excerpt. * @@ -2311,13 +2311,13 @@ function comment_form( $args = array(), $post_id = null ) { /** This filter is documented in wp-includes/link-template.php */ 'must_log_in' => '

' . sprintf( /* translators: %s: login URL */ - __( 'You must be logged in to post a comment.' ), + __( 'You must be logged in to post a comment.' ), wp_login_url( apply_filters( 'the_permalink', get_permalink( $post_id ), $post_id ) ) ) . '

', /** This filter is documented in wp-includes/link-template.php */ 'logged_in_as' => '

' . sprintf( /* translators: 1: edit user link, 2: accessibility text, 3: user name, 4: logout URL */ - __( 'Logged in as %3$s. Log out?' ), + __( 'Logged in as %3$s. Log out?' ), get_edit_user_link(), /* translators: %s: user name */ esc_attr( sprintf( __( 'Logged in as %s. Edit your profile.' ), $user_identity ) ),