Make WordPress Core

Ticket #49956: 49956.2.patch

File 49956.2.patch, 6.7 KB (added by imath, 5 years ago)
  • src/wp-content/themes/twentynineteen/classes/class-twentynineteen-walker-comment.php

    diff --git src/wp-content/themes/twentynineteen/classes/class-twentynineteen-walker-comment.php src/wp-content/themes/twentynineteen/classes/class-twentynineteen-walker-comment.php
    index 829bb515b7..6a758e3a48 100644
    class TwentyNineteen_Walker_Comment extends Walker_Comment { 
    2525         */
    2626        protected function html5_comment( $comment, $depth, $args ) {
    2727
    28                 $tag = ( 'div' === $args['style'] ) ? 'div' : 'li';
     28                $tag                = ( 'div' === $args['style'] ) ? 'div' : 'li';
     29                $commenter          = wp_get_current_commenter();
     30                $show_pending_links = isset( $commenter['comment_author'] ) && $commenter['comment_author'];
    2931
    3032                ?>
    3133                <<?php echo $tag; ?> id="comment-<?php comment_ID(); ?>" <?php comment_class( $this->has_children ? 'parent' : '', $comment ); ?>>
    class TwentyNineteen_Walker_Comment extends Walker_Comment { 
    3436                                        <div class="comment-author vcard">
    3537                                                <?php
    3638                                                $comment_author_url = get_comment_author_url( $comment );
     39                                                if ( '0' == $comment->comment_approved && ! $show_pending_links ) {
     40                                                        $comment_author_url = '';
     41                                                }
     42
    3743                                                $comment_author     = get_comment_author( $comment );
    3844                                                $avatar             = get_avatar( $comment, $args['avatar_size'] );
    3945                                                if ( 0 != $args['avatar_size'] ) {
    class TwentyNineteen_Walker_Comment extends Walker_Comment { 
    8995                                        </div><!-- .comment-metadata -->
    9096
    9197                                        <?php
    92                                         $commenter = wp_get_current_commenter();
    9398                                        if ( $commenter['comment_author_email'] ) {
    9499                                                $moderation_note = __( 'Your comment is awaiting moderation.', 'twentynineteen' );
    95100                                        } else {
    96                                                 $moderation_note = __( 'Your comment is awaiting moderation. This is a preview, your comment will be visible after it has been approved.', 'twentynineteen' );
     101                                                $moderation_note    = __( 'Your comment is awaiting moderation. This is a preview, your comment will be visible after it has been approved.', 'twentynineteen' );
    97102                                        }
    98103                                        ?>
    99104
  • src/wp-includes/class-walker-comment.php

    diff --git src/wp-includes/class-walker-comment.php src/wp-includes/class-walker-comment.php
    index 7325fd0a6a..3073ce8536 100644
    class Walker_Comment extends Walker { 
    181181                        return;
    182182                }
    183183
     184                if ( 'comment' === $comment->comment_type ) {
     185                        add_filter( 'comment_text', array( $this, 'comment_text' ), 40, 2 );
     186                }
     187
    184188                if ( ( 'pingback' == $comment->comment_type || 'trackback' == $comment->comment_type ) && $args['short_ping'] ) {
    185189                        ob_start();
    186190                        $this->ping( $comment, $depth, $args );
    class Walker_Comment extends Walker { 
    194198                        $this->comment( $comment, $depth, $args );
    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
    199207        /**
    class Walker_Comment extends Walker { 
    244252                <?php
    245253        }
    246254
     255        /**
     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 = isset( $commenter['comment_author'] ) && $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
    247275        /**
    248276         * Outputs a single comment.
    249277         *
    class Walker_Comment extends Walker { 
    264292                        $add_below = 'div-comment';
    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.' );
    270299                } else {
    class Walker_Comment extends Walker { 
    282311                                echo get_avatar( $comment, $args['avatar_size'] );}
    283312                        ?>
    284313                        <?php
     314                                $comment_author = get_comment_author_link( $comment );
     315                                if ( '0' == $comment->comment_approved && ! $show_pending_links ) {
     316                                        $comment_author = get_comment_author( $comment );
     317                                }
     318
    285319                                printf(
    286320                                        /* translators: %s: Comment author link. */
    287321                                        __( '%s <span class="says">says:</span>' ),
    288                                         sprintf( '<cite class="fn">%s</cite>', get_comment_author_link( $comment ) )
     322                                        sprintf( '<cite class="fn">%s</cite>', $comment_author )
    289323                                );
    290324                        ?>
    291325                </div>
    class Walker_Comment extends Walker { 
    354388        protected function html5_comment( $comment, $depth, $args ) {
    355389                $tag = ( 'div' === $args['style'] ) ? 'div' : 'li';
    356390
    357                 $commenter = wp_get_current_commenter();
     391                $commenter          = wp_get_current_commenter();
     392                $show_pending_links = isset( $commenter['comment_author'] ) && $commenter['comment_author'];
    358393                if ( $commenter['comment_author_email'] ) {
    359394                        $moderation_note = __( 'Your comment is awaiting moderation.' );
    360395                } else {
    class Walker_Comment extends Walker { 
    372407                                                }
    373408                                                ?>
    374409                                                <?php
     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
    375415                                                        printf(
    376416                                                                /* translators: %s: Comment author link. */
    377417                                                                __( '%s <span class="says">says:</span>' ),
    378                                                                 sprintf( '<b class="fn">%s</b>', get_comment_author_link( $comment ) )
     418                                                                sprintf( '<b class="fn">%s</b>', $comment_author )
    379419                                                        );
    380420                                                ?>
    381421                                        </div><!-- .comment-author -->
  • src/wp-includes/comment.php

    diff --git src/wp-includes/comment.php src/wp-includes/comment.php
    index 8648a89a0f..9139bb1b7c 100644
    function wp_get_unapproved_comment_author_email() { 
    18471847                $comment    = get_comment( $comment_id );
    18481848
    18491849                if ( $comment && hash_equals( $_GET['moderation-hash'], wp_hash( $comment->comment_date_gmt ) ) ) {
    1850                         $commenter_email = $comment->comment_author_email;
     1850                        // The comment will only be viewable by the comment author for 1 minute.
     1851                        $comment_timestamp = strtotime( $comment->comment_date_gmt . '+1 minute' );
     1852                        $current_timestamp = strtotime( current_time( 'mysql', 1 ) );
     1853
     1854                        if ( $current_timestamp < $comment_timestamp ) {
     1855                                $commenter_email = $comment->comment_author_email;
     1856                        }
    18511857                }
    18521858        }
    18531859