Make WordPress Core


Ignore:
Timestamp:
06/02/2020 08:24:59 PM (4 years ago)
Author:
whyisjake
Message:

Comments: Ensure that unmoderated comments won't be search indexed.

After a comment is submitted, only allow a brief window where the comment is live on the site.

This brings the changes from [47887] to the 5.4 branch.

Fixes #49956.
Props: jonkolbert, ayeshrajans, Asif2BD, peterwilsoncc, imath, audrasjb, jonoaldersonwp, whyisjake.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/5.4/src/wp-includes/class-walker-comment.php

    r46391 r47888  
    180180            $output .= ob_get_clean();
    181181            return;
     182        }
     183
     184        if ( 'comment' === $comment->comment_type ) {
     185            add_filter( 'comment_text', array( $this, 'comment_text' ), 40, 2 );
    182186        }
    183187
     
    195199            $output .= ob_get_clean();
    196200        }
     201
     202        if ( 'comment' === $comment->comment_type ) {
     203            remove_filter( 'comment_text', array( $this, 'comment_text' ), 40, 2 );
     204        }
    197205    }
    198206
     
    246254
    247255    /**
     256     * Remove links from the pending comment's text if the commenter has not consent to the comment cookie.
     257     *
     258     * @since 5.4.2
     259     *
     260     * @param string          $comment_text Text of the current comment.
     261     * @param WP_Comment|null $comment      The comment object.
     262     * @return string                       Text of the current comment.
     263     */
     264    function comment_text( $comment_text, $comment ) {
     265        $commenter          = wp_get_current_commenter();
     266        $show_pending_links = ! empty( $commenter['comment_author'] );
     267
     268        if ( '0' == $comment->comment_approved && ! $show_pending_links ) {
     269            return wp_kses( $comment_text, array() );
     270        }
     271
     272        return $comment_text;
     273    }
     274
     275    /**
    248276     * Outputs a single comment.
    249277     *
     
    265293        }
    266294
    267         $commenter = wp_get_current_commenter();
     295        $commenter          = wp_get_current_commenter();
     296        $show_pending_links = isset( $commenter['comment_author'] ) && $commenter['comment_author'];
    268297        if ( $commenter['comment_author_email'] ) {
    269298            $moderation_note = __( 'Your comment is awaiting moderation.' );
     
    280309            <?php
    281310            if ( 0 != $args['avatar_size'] ) {
    282                 echo get_avatar( $comment, $args['avatar_size'] );}
     311                echo get_avatar( $comment, $args['avatar_size'] );
     312            }
    283313            ?>
    284314            <?php
    285                 printf(
    286                     /* translators: %s: Comment author link. */
    287                     __( '%s <span class="says">says:</span>' ),
    288                     sprintf( '<cite class="fn">%s</cite>', get_comment_author_link( $comment ) )
    289                 );
     315            $comment_author = get_comment_author_link( $comment );
     316            if ( '0' == $comment->comment_approved && ! $show_pending_links ) {
     317                $comment_author = get_comment_author( $comment );
     318            }
     319            printf(
     320                /* translators: %s: Comment author link. */
     321                __( '%s <span class="says">says:</span>' ),
     322                sprintf( '<cite class="fn">%s</cite>', $comment_author )
     323            );
    290324            ?>
    291325        </div>
     
    355389        $tag = ( 'div' === $args['style'] ) ? 'div' : 'li';
    356390
    357         $commenter = wp_get_current_commenter();
     391        $commenter          = wp_get_current_commenter();
     392        $show_pending_links = ! empty( $commenter['comment_author'] );
    358393        if ( $commenter['comment_author_email'] ) {
    359394            $moderation_note = __( 'Your comment is awaiting moderation.' );
     
    373408                        ?>
    374409                        <?php
    375                             printf(
    376                                 /* translators: %s: Comment author link. */
    377                                 __( '%s <span class="says">says:</span>' ),
    378                                 sprintf( '<b class="fn">%s</b>', get_comment_author_link( $comment ) )
    379                             );
     410                        $comment_author = get_comment_author_link( $comment );
     411                        if ( '0' == $comment->comment_approved && ! $show_pending_links ) {
     412                            $comment_author = get_comment_author( $comment );
     413                        }
     414                        printf(
     415                            /* translators: %s: Comment author link. */
     416                            __( '%s <span class="says">says:</span>' ),
     417                            sprintf( '<b class="fn">%s</b>', $comment_author )
     418                        );
    380419                        ?>
    381420                    </div><!-- .comment-author -->
     
    403442
    404443                <?php
    405                 comment_reply_link(
    406                     array_merge(
    407                         $args,
    408                         array(
    409                             'add_below' => 'div-comment',
    410                             'depth'     => $depth,
    411                             'max_depth' => $args['max_depth'],
    412                             'before'    => '<div class="reply">',
    413                             'after'     => '</div>',
     444                if ( '1' == $comment->comment_approved || $show_pending_links ) {
     445                    comment_reply_link(
     446                        array_merge(
     447                            $args,
     448                            array(
     449                                'add_below' => 'div-comment',
     450                                'depth'     => $depth,
     451                                'max_depth' => $args['max_depth'],
     452                                'before'    => '<div class="reply">',
     453                                'after'     => '</div>',
     454                            )
    414455                        )
    415                     )
    416                 );
     456                    );
     457                }
    417458                ?>
    418459            </article><!-- .comment-body -->
Note: See TracChangeset for help on using the changeset viewer.