diff -r 3d4e9c994f10 -r a86126ab1dd4 wp/wp-includes/class-walker-comment.php --- a/wp/wp-includes/class-walker-comment.php Tue Oct 22 16:11:46 2019 +0200 +++ b/wp/wp-includes/class-walker-comment.php Tue Dec 15 13:49:49 2020 +0100 @@ -161,7 +161,7 @@ * @see Walker::start_el() * @see wp_list_comments() * @global int $comment_depth - * @global WP_Comment $comment + * @global WP_Comment $comment Global comment object. * * @param string $output Used to append additional content. Passed by reference. * @param WP_Comment $comment Comment data object. @@ -181,7 +181,11 @@ return; } - if ( ( 'pingback' == $comment->comment_type || 'trackback' == $comment->comment_type ) && $args['short_ping'] ) { + if ( 'comment' === $comment->comment_type ) { + add_filter( 'comment_text', array( $this, 'filter_comment_text' ), 40, 2 ); + } + + if ( ( 'pingback' === $comment->comment_type || 'trackback' === $comment->comment_type ) && $args['short_ping'] ) { ob_start(); $this->ping( $comment, $depth, $args ); $output .= ob_get_clean(); @@ -194,6 +198,10 @@ $this->comment( $comment, $depth, $args ); $output .= ob_get_clean(); } + + if ( 'comment' === $comment->comment_type ) { + remove_filter( 'comment_text', array( $this, 'filter_comment_text' ), 40, 2 ); + } } /** @@ -216,7 +224,7 @@ $output .= ob_get_clean(); return; } - if ( 'div' == $args['style'] ) { + if ( 'div' === $args['style'] ) { $output .= "\n"; } else { $output .= "\n"; @@ -235,7 +243,7 @@ * @param array $args An array of arguments. */ protected function ping( $comment, $depth, $args ) { - $tag = ( 'div' == $args['style'] ) ? 'div' : 'li'; + $tag = ( 'div' === $args['style'] ) ? 'div' : 'li'; ?> < id="comment-" >
@@ -245,6 +253,29 @@ } /** + * Filters the comment text. + * + * Removes links from the pending comment's text if the commenter did not consent + * to the comment cookies. + * + * @since 5.4.2 + * + * @param string $comment_text Text of the current comment. + * @param WP_Comment|null $comment The comment object. Null if not found. + * @return string Filtered text of the current comment. + */ + public function filter_comment_text( $comment_text, $comment ) { + $commenter = wp_get_current_commenter(); + $show_pending_links = ! empty( $commenter['comment_author'] ); + + if ( $comment && '0' == $comment->comment_approved && ! $show_pending_links ) { + $comment_text = wp_kses( $comment_text, array() ); + } + + return $comment_text; + } + + /** * Outputs a single comment. * * @since 3.6.0 @@ -256,7 +287,7 @@ * @param array $args An array of arguments. */ protected function comment( $comment, $depth, $args ) { - if ( 'div' == $args['style'] ) { + if ( 'div' === $args['style'] ) { $tag = 'div'; $add_below = 'comment'; } else { @@ -264,29 +295,37 @@ $add_below = 'div-comment'; } - $commenter = wp_get_current_commenter(); + $commenter = wp_get_current_commenter(); + $show_pending_links = isset( $commenter['comment_author'] ) && $commenter['comment_author']; + if ( $commenter['comment_author_email'] ) { $moderation_note = __( 'Your comment is awaiting moderation.' ); } else { $moderation_note = __( 'Your comment is awaiting moderation. This is a preview, your comment will be visible after it has been approved.' ); } - ?> < has_children ? 'parent' : '', $comment ); ?> id="comment-"> - +
says:' ), - sprintf( '%s', get_comment_author_link( $comment ) ) - ); + $comment_author = get_comment_author_link( $comment ); + + if ( '0' == $comment->comment_approved && ! $show_pending_links ) { + $comment_author = get_comment_author( $comment ); + } + + printf( + /* translators: %s: Comment author link. */ + __( '%s says:' ), + sprintf( '%s', $comment_author ) + ); ?>
comment_approved ) : ?> @@ -296,7 +335,7 @@ < id="comment-" has_children ? 'parent' : '', $comment ); ?>>
@@ -368,14 +408,21 @@
says:' ), - sprintf( '%s', get_comment_author_link( $comment ) ) - ); + $comment_author = get_comment_author_link( $comment ); + + if ( '0' == $comment->comment_approved && ! $show_pending_links ) { + $comment_author = get_comment_author( $comment ); + } + + printf( + /* translators: %s: Comment author link. */ + __( '%s says:' ), + sprintf( '%s', $comment_author ) + ); ?>
@@ -383,7 +430,7 @@ @@ -401,18 +448,20 @@
'div-comment', - 'depth' => $depth, - 'max_depth' => $args['max_depth'], - 'before' => '
', - 'after' => '
', + if ( '1' == $comment->comment_approved || $show_pending_links ) { + comment_reply_link( + array_merge( + $args, + array( + 'add_below' => 'div-comment', + 'depth' => $depth, + 'max_depth' => $args['max_depth'], + 'before' => '
', + 'after' => '
', + ) ) - ) - ); + ); + } ?>