Make WordPress Core


Ignore:
Timestamp:
01/21/2019 01:33:50 AM (6 years ago)
Author:
pento
Message:

Comments: Show the "awaiting moderation" message when comment cookies are disabled.

The "Your comment is awaiting moderation." message relied upon the comment author cookie being set. However, since it's now possible to opt-out of that cookie, submitting a comment won't show the comment preview when the comment is placed in moderation.

To avoid this issue, we now include a hash in the redirect URL, allowing the site to identify that a preview of the moderated comment should be displayed.

Props imath, tomdxw, birgire, lakenh, azaozz, pento.
Fixes #43857.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/comment/commentsTemplate.php

    r43571 r44659  
    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(
     852            add_query_arg(
     853                array(
     854                    'unapproved'      => $comment->comment_ID,
     855                    'moderation-hash' => wp_hash( $comment->comment_date_gmt ),
     856                ),
     857                get_comment_link( $comment )
     858            )
     859        );
     860
     861        $found = get_echo( 'comments_template' );
     862
     863        // Find the found comment in the markup.
     864        preg_match( '|id="comment-([0-9]+)|', $found, $matches );
     865
     866        $found_cid = (int) $matches[1];
     867        $this->assertSame( $c, $found_cid );
     868    }
     869
     870    /**
    835871     * @ticket 35378
    836872     */
Note: See TracChangeset for help on using the changeset viewer.