Make WordPress Core

Ticket #43857: 43857.9.diff

File 43857.9.diff, 4.8 KB (added by azaozz, 6 years ago)
  • src/wp-comments-post.php

     
    5757$location = empty( $_POST['redirect_to'] ) ? get_comment_link( $comment ) : $_POST['redirect_to'] . '#comment-' . $comment->comment_ID;
    5858
    5959/**
     60 * Add specific query arguments to display the awaiting moderation message
     61 * to users who refused to use comment cookies.
     62 */
     63if ( 'unapproved' === wp_get_comment_status( $comment ) && ! empty( $comment->comment_author_email ) ) {
     64        $location = add_query_arg(
     65                array(
     66                        'unapproved'      => $comment->comment_ID,
     67                        'moderation-hash' => wp_hash( $comment->comment_date_gmt ),
     68                ),
     69                $location
     70        );
     71}
     72
     73/**
    6074 * Filters the location URI to send the commenter after posting.
    6175 *
    6276 * @since 2.0.5
  • src/wp-includes/comment-template.php

     
    13721372
    13731373        if ( $user_ID ) {
    13741374                $comment_args['include_unapproved'] = array( $user_ID );
    1375         } elseif ( ! empty( $comment_author_email ) ) {
    1376                 $comment_args['include_unapproved'] = array( $comment_author_email );
     1375        } else {
     1376                $unapproved_email = wp_get_unapproved_comment_author_email();
     1377
     1378                if ( ! empty( $unapproved_email ) ) {
     1379                        $comment_args['include_unapproved'] = array( $unapproved_email );
     1380                }
    13771381        }
    13781382
    13791383        $per_page = 0;
     
    16911695                $link = sprintf(
    16921696                        "<a rel='nofollow' class='comment-reply-link' href='%s' %s aria-label='%s'>%s</a>",
    16931697                        esc_url( add_query_arg( 'replytocom', $comment->comment_ID ) ) . '#' . $args['respond_id'],
     1698                        esc_url(
     1699                                add_query_arg(
     1700                                        array(
     1701                                                'replytocom'      => $comment->comment_ID,
     1702                                                'unapproved'      => false,
     1703                                                'moderation-hash' => false,
     1704                                        )
     1705                                )
     1706                        ) . '#' . $args['respond_id'],
    16941707                        $data_attribute_string,
    16951708                        esc_attr( sprintf( $args['reply_to_text'], $comment->comment_author ) ),
    16961709                        $args['reply_text']
     
    20552068                                if ( is_user_logged_in() ) {
    20562069                                        $comment_args['include_unapproved'] = get_current_user_id();
    20572070                                } else {
    2058                                         $commenter = wp_get_current_commenter();
    2059                                         if ( $commenter['comment_author_email'] ) {
    2060                                                 $comment_args['include_unapproved'] = $commenter['comment_author_email'];
     2071                                        $unapproved_email = wp_get_unapproved_comment_author_email();
     2072
     2073                                        if ( ! empty( $unapproved_email ) ) {
     2074                                                $comment_args['include_unapproved'] = array( $unapproved_email );
    20612075                                        }
    20622076                                }
    20632077
  • src/wp-includes/comment.php

     
    17691769}
    17701770
    17711771/**
     1772 * Get unapproved comment author's email.
     1773 *
     1774 * Used to allow the commenter to see their pending comment.
     1775 *
     1776 * @since 5.1.0
     1777 *
     1778 * @return string The unapproved comment author's email (when supplied).
     1779 */
     1780function wp_get_unapproved_comment_author_email() {
     1781        $commenter_email = '';
     1782
     1783        if ( ! empty( $_GET['unapproved'] ) && ! empty( $_GET['moderation-hash'] ) ) {
     1784                $comment_id = (int) $_GET['unapproved'];
     1785                $comment = get_comment( $comment_id );
     1786
     1787                if ( $comment && hash_equals( $_GET['moderation-hash'], wp_hash( $comment->comment_date_gmt ) ) ) {
     1788                        $commenter_email = $comment->comment_author_email;
     1789                }
     1790        }
     1791
     1792        return $commenter_email;
     1793}
     1794
     1795/**
    17721796 * Inserts a comment into the database.
    17731797 *
    17741798 * @since 2.0.0
  • tests/phpunit/tests/comment/commentsTemplate.php

     
    832832        }
    833833
    834834        /**
     835         * @ticket 43857
     836         */
     837        public function test_comments_list_should_include_just_posted_unapproved_comment() {
     838                $now = time();
     839                $p   = self::factory()->post->create();
     840                $c   = self::factory()->comment->create(
     841                        array(
     842                                'comment_post_ID'  => $p,
     843                                'comment_content'  => '1',
     844                                'comment_approved' => '0',
     845                                'comment_date_gmt' => date( 'Y-m-d H:i:s', $now ),
     846                                'comment_author_email' => 'foo@bar.mail',
     847                        )
     848                );
     849                $comment = get_comment( $c );
     850
     851                $this->go_to( add_query_arg(
     852                        array(
     853                                'unapproved'      => $comment->comment_ID,
     854                                'moderation-hash' => wp_hash( $comment->comment_date_gmt ),
     855                        ),
     856                        get_comment_link( $comment )
     857                ) );
     858
     859                $found = get_echo( 'comments_template' );
     860
     861                // Find the found comment in the markup.
     862                preg_match( '|id="comment-([0-9]+)|', $found, $matches );
     863
     864                $found_cid = (int) $matches[1];
     865                $this->assertSame( $c, $found_cid );
     866        }
     867
     868        /**
    835869         * @ticket 35378
    836870         */
    837871        public function test_hierarchy_should_be_ignored_when_threading_is_disabled() {