Editor: Ensure latest comments can only be viewed from public posts.

This brings the changes from [47984] to the 5.2 branch.
Props: poena, xknown.

Built from https://develop.svn.wordpress.org/branches/5.2@47986


git-svn-id: http://core.svn.wordpress.org/branches/5.2@47754 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
whyisjake 2020-06-10 19:26:53 +00:00
parent 0d6541c100
commit 8e6550737f
1 changed files with 15 additions and 15 deletions

View File

@ -592,27 +592,27 @@ function comment_date( $d = '', $comment_ID = 0 ) {
*/ */
function get_comment_excerpt( $comment_ID = 0 ) { function get_comment_excerpt( $comment_ID = 0 ) {
$comment = get_comment( $comment_ID ); $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 ) ); $comment_text = strip_tags( str_replace( array( "\n", "\r" ), ' ', $comment->comment_content ) );
$words = explode( ' ', $comment_text ); } 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 * @since 4.4.0
* *
* @param int $comment_excerpt_length The amount of words you want to display in the comment excerpt. * @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; $excerpt = wp_trim_words( $comment_text, $comment_excerpt_length, '…' );
if ( $use_ellipsis ) {
$words = array_slice( $words, 0, $comment_excerpt_length );
}
$excerpt = trim( join( ' ', $words ) );
if ( $use_ellipsis ) {
$excerpt .= '…';
}
/** /**
* Filters the retrieved comment excerpt. * Filters the retrieved comment excerpt.
* *