Skip to content

Commit

Permalink
Comments: Rename Walker_Comment::comment_text() to `::filter_commen…
Browse files Browse the repository at this point in the history
…t_text()` for clarity.

Ensure the comment object is not null before checking its status.

Follow-up to [47887].

Merges [47889] to the 5.4 branch.
See #49956.

git-svn-id: https://develop.svn.wordpress.org/branches/5.4@47890 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information
SergeyBiryukov committed Jun 2, 2020
1 parent 187fdd9 commit bfb382e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
27 changes: 17 additions & 10 deletions src/wp-includes/class-walker-comment.php
Expand Up @@ -182,7 +182,7 @@ public function start_el( &$output, $comment, $depth = 0, $args = array(), $id =
}

if ( 'comment' === $comment->comment_type ) {
add_filter( 'comment_text', array( $this, 'comment_text' ), 40, 2 );
add_filter( 'comment_text', array( $this, 'filter_comment_text' ), 40, 2 );
}

if ( ( 'pingback' == $comment->comment_type || 'trackback' == $comment->comment_type ) && $args['short_ping'] ) {
Expand All @@ -200,7 +200,7 @@ public function start_el( &$output, $comment, $depth = 0, $args = array(), $id =
}

if ( 'comment' === $comment->comment_type ) {
remove_filter( 'comment_text', array( $this, 'comment_text' ), 40, 2 );
remove_filter( 'comment_text', array( $this, 'filter_comment_text' ), 40, 2 );
}
}

Expand Down Expand Up @@ -253,20 +253,23 @@ protected function ping( $comment, $depth, $args ) {
}

/**
* Remove links from the pending comment's text if the commenter has not consent to the comment cookie.
* 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.
* @return string 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.
*/
function comment_text( $comment_text, $comment ) {
public function filter_comment_text( $comment_text, $comment ) {
$commenter = wp_get_current_commenter();
$show_pending_links = ! empty( $commenter['comment_author'] );

if ( '0' == $comment->comment_approved && ! $show_pending_links ) {
return wp_kses( $comment_text, array() );
if ( $comment && '0' == $comment->comment_approved && ! $show_pending_links ) {
$comment_text = wp_kses( $comment_text, array() );
}

return $comment_text;
Expand Down Expand Up @@ -294,12 +297,12 @@ protected function comment( $comment, $depth, $args ) {

$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.' );
}

?>
<<?php echo $tag; ?> <?php comment_class( $this->has_children ? 'parent' : '', $comment ); ?> id="comment-<?php comment_ID(); ?>">
<?php if ( 'div' != $args['style'] ) : ?>
Expand All @@ -313,9 +316,11 @@ protected function comment( $comment, $depth, $args ) {
?>
<?php
$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 <span class="says">says:</span>' ),
Expand Down Expand Up @@ -390,12 +395,12 @@ protected function html5_comment( $comment, $depth, $args ) {

$commenter = wp_get_current_commenter();
$show_pending_links = ! empty( $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.' );
}

?>
<<?php echo $tag; ?> id="comment-<?php comment_ID(); ?>" <?php comment_class( $this->has_children ? 'parent' : '', $comment ); ?>>
<article id="div-comment-<?php comment_ID(); ?>" class="comment-body">
Expand All @@ -408,9 +413,11 @@ protected function html5_comment( $comment, $depth, $args ) {
?>
<?php
$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 <span class="says">says:</span>' ),
Expand Down
2 changes: 1 addition & 1 deletion src/wp-includes/comment-template.php
Expand Up @@ -1016,7 +1016,7 @@ function comment_text( $comment_ID = 0, $args = array() ) {
* @see Walker_Comment::comment()
*
* @param string $comment_text Text of the current comment.
* @param WP_Comment|null $comment The comment object.
* @param WP_Comment|null $comment The comment object. Null if not found.
* @param array $args An array of arguments.
*/
echo apply_filters( 'comment_text', $comment_text, $comment, $args );
Expand Down

0 comments on commit bfb382e

Please sign in to comment.