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

@ -591,28 +591,28 @@ function comment_date( $d = '', $comment_ID = 0 ) {
* @return string The maybe truncated comment with 20 words or less. * @return string The maybe truncated comment with 20 words or less.
*/ */
function get_comment_excerpt( $comment_ID = 0 ) { function get_comment_excerpt( $comment_ID = 0 ) {
$comment = get_comment( $comment_ID ); $comment = get_comment( $comment_ID );
$comment_text = strip_tags( str_replace( array( "\n", "\r" ), ' ', $comment->comment_content ) );
$words = explode( ' ', $comment_text ); 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 * @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.
* *
@ -2311,13 +2311,13 @@ function comment_form( $args = array(), $post_id = null ) {
/** This filter is documented in wp-includes/link-template.php */ /** This filter is documented in wp-includes/link-template.php */
'must_log_in' => '<p class="must-log-in">' . sprintf( 'must_log_in' => '<p class="must-log-in">' . sprintf(
/* translators: %s: login URL */ /* translators: %s: login URL */
__( 'You must be <a href="%s">logged in</a> to post a comment.' ), __( 'You must be <a href="%s">logged in</a> to post a comment.' ),
wp_login_url( apply_filters( 'the_permalink', get_permalink( $post_id ), $post_id ) ) wp_login_url( apply_filters( 'the_permalink', get_permalink( $post_id ), $post_id ) )
) . '</p>', ) . '</p>',
/** This filter is documented in wp-includes/link-template.php */ /** This filter is documented in wp-includes/link-template.php */
'logged_in_as' => '<p class="logged-in-as">' . sprintf( 'logged_in_as' => '<p class="logged-in-as">' . sprintf(
/* translators: 1: edit user link, 2: accessibility text, 3: user name, 4: logout URL */ /* translators: 1: edit user link, 2: accessibility text, 3: user name, 4: logout URL */
__( '<a href="%1$s" aria-label="%2$s">Logged in as %3$s</a>. <a href="%4$s">Log out?</a>' ), __( '<a href="%1$s" aria-label="%2$s">Logged in as %3$s</a>. <a href="%4$s">Log out?</a>' ),
get_edit_user_link(), get_edit_user_link(),
/* translators: %s: user name */ /* translators: %s: user name */
esc_attr( sprintf( __( 'Logged in as %s. Edit your profile.' ), $user_identity ) ), esc_attr( sprintf( __( 'Logged in as %s. Edit your profile.' ), $user_identity ) ),