Make WordPress Core


Ignore:
Timestamp:
01/21/2019 01:33:50 AM (8 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/src/wp-includes/comment-template.php

    r44457 r44659  
    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 ( $unapproved_email ) {
     1379                        $comment_args['include_unapproved'] = array( $unapproved_email );
     1380                }
    13771381        }
    13781382
    … …  
    16911695                $link = sprintf(
    16921696                        "<a rel='nofollow' class='comment-reply-link' href='%s' %s aria-label='%s'>%s</a>",
    1693                         esc_url( add_query_arg( 'replytocom', $comment->comment_ID ) ) . '#' . $args['respond_id'],
     1697                        esc_url(
     1698                                add_query_arg(
     1699                                        array(
     1700                                                'replytocom'      => $comment->comment_ID,
     1701                                                'unapproved'      => false,
     1702                                                'moderation-hash' => false,
     1703                                        )
     1704                                )
     1705                        ) . '#' . $args['respond_id'],
    16941706                        $data_attribute_string,
    16951707                        esc_attr( sprintf( $args['reply_to_text'], $comment->comment_author ) ),
    … …  
    18331845
    18341846        $style = isset( $_GET['replytocom'] ) ? '' : ' style="display:none;"';
    1835         $link  = esc_html( remove_query_arg( 'replytocom' ) ) . '#respond';
     1847        $link  = esc_html( remove_query_arg( array( 'replytocom', 'unapproved', 'moderation-hash' ) ) ) . '#respond';
    18361848
    18371849        $formatted_link = '<a rel="nofollow" id="cancel-comment-reply-link" href="' . $link . '"' . $style . '>' . $text . '</a>';
    … …  
    20562068                                        $comment_args['include_unapproved'] = get_current_user_id();
    20572069                                } else {
    2058                                         $commenter = wp_get_current_commenter();
    2059                                         if ( $commenter['comment_author_email'] ) {
    2060                                                 $comment_args['include_unapproved'] = $commenter['comment_author_email'];
     2070                                        $unapproved_email = wp_get_unapproved_comment_author_email();
     2071
     2072                                        if ( $unapproved_email ) {
     2073                                                $comment_args['include_unapproved'] = array( $unapproved_email );
    20612074                                        }
    20622075                                }
Note: See TracChangeset for help on using the changeset viewer.