Ticket #43857: 43857.8.diff
| File 43857.8.diff, 7.3 KB (added by , 7 years ago) |
|---|
-
src/wp-comments-post.php
diff --git src/wp-comments-post.php src/wp-comments-post.php index 5c33e87fd3..f5af7a1a90 100644
do_action( 'set_comment_cookies', $comment, $user, $cookies_consent ); 56 56 57 57 $location = empty( $_POST['redirect_to'] ) ? get_comment_link( $comment ) : $_POST['redirect_to'] . '#comment-' . $comment->comment_ID; 58 58 59 /** 60 * Add specific query arguments to display the awaiting moderation message 61 * to users who refused to use comment cookies. 62 */ 63 if ( ! $cookies_consent && 'unapproved' === wp_get_comment_status( $comment ) ) { 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 59 73 /** 60 74 * Filters the location URI to send the commenter after posting. 61 75 * -
src/wp-includes/class-walker-comment.php
diff --git src/wp-includes/class-walker-comment.php src/wp-includes/class-walker-comment.php index 5bfcac0ed3..096194bcee 100644
class Walker_Comment extends Walker { 263 263 $tag = 'li'; 264 264 $add_below = 'div-comment'; 265 265 } 266 267 $current_commenter = wp_get_current_commenter(); 266 268 ?> 267 269 <<?php echo $tag; ?> <?php comment_class( $this->has_children ? 'parent' : '', $comment ); ?> id="comment-<?php comment_ID(); ?>"> 268 270 <?php if ( 'div' != $args['style'] ) : ?> … … class Walker_Comment extends Walker { 282 284 ?> 283 285 </div> 284 286 <?php if ( '0' == $comment->comment_approved ) : ?> 285 <em class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.' ); ?></em> 286 <br /> 287 <em class="comment-awaiting-moderation"> 288 <?php 289 esc_html_e( 'Your comment is awaiting moderation.' ); 290 291 if ( ! $current_commenter['comment_author_email'] ) { 292 echo ' '; 293 esc_html_e( 'This message is only shown when a new comment was posted.' ); 294 } 295 ?> 296 </em> 297 <br /> 287 298 <?php endif; ?> 288 299 289 300 <div class="comment-meta commentmetadata"><a href="<?php echo esc_url( get_comment_link( $comment, $args ) ); ?>"> … … class Walker_Comment extends Walker { 344 355 * @param array $args An array of arguments. 345 356 */ 346 357 protected function html5_comment( $comment, $depth, $args ) { 347 $tag = ( 'div' === $args['style'] ) ? 'div' : 'li'; 358 $tag = ( 'div' === $args['style'] ) ? 'div' : 'li'; 359 $current_commenter = wp_get_current_commenter(); 348 360 ?> 349 361 <<?php echo $tag; ?> id="comment-<?php comment_ID(); ?>" <?php comment_class( $this->has_children ? 'parent' : '', $comment ); ?>> 350 362 <article id="div-comment-<?php comment_ID(); ?>" class="comment-body"> … … class Walker_Comment extends Walker { 376 388 </div><!-- .comment-metadata --> 377 389 378 390 <?php if ( '0' == $comment->comment_approved ) : ?> 379 <p class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.' ); ?></p> 391 <p class="comment-awaiting-moderation"> 392 <?php 393 esc_html_e( 'Your comment is awaiting moderation.' ); 394 395 if ( ! $current_commenter['comment_author_email'] ) { 396 echo ' '; 397 esc_html_e( 'This message is only shown when a new comment was posted.' ); 398 } 399 ?> 400 </p> 380 401 <?php endif; ?> 381 402 </footer><!-- .comment-meta --> 382 403 -
src/wp-includes/comment-template.php
diff --git src/wp-includes/comment-template.php src/wp-includes/comment-template.php index 918238f7fa..59c1cfc19f 100644
function comments_template( $file = '/comments.php', $separate_comments = false 1350 1350 */ 1351 1351 $comment_author_email = $commenter['comment_author_email']; 1352 1352 1353 /** 1354 * Set the comment's author email for unapproved commenters who refused 1355 * to use comment cookies. 1356 */ 1357 if ( ! $comment_author_email ) { 1358 $comment_author_email = wp_get_unapproved_commenter_email(); 1359 } 1360 1353 1361 /* 1354 1362 * The url of the current comment author escaped for use in attributes. 1355 1363 */ … … function get_comment_reply_link( $args = array(), $comment = null, $post = null 1690 1698 1691 1699 $link = sprintf( 1692 1700 "<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'], 1701 esc_url( 1702 add_query_arg( 1703 array( 1704 'replytocom' => $comment->comment_ID, 1705 'unapproved' => false, 1706 'moderation-hash' => false, 1707 ) 1708 ) 1709 ) . '#' . $args['respond_id'], 1694 1710 $data_attribute_string, 1695 1711 esc_attr( sprintf( $args['reply_to_text'], $comment->comment_author ) ), 1696 1712 $args['reply_text'] … … function wp_list_comments( $args = array(), $comments = null ) { 2058 2074 $commenter = wp_get_current_commenter(); 2059 2075 if ( $commenter['comment_author_email'] ) { 2060 2076 $comment_args['include_unapproved'] = $commenter['comment_author_email']; 2077 } else { 2078 $comment_author_email = wp_get_unapproved_commenter_email(); 2079 2080 if ( $comment_author_email ) { 2081 $comment_args['include_unapproved'] = $comment_author_email; 2082 } 2061 2083 } 2062 2084 } 2063 2085 -
src/wp-includes/comment.php
diff --git src/wp-includes/comment.php src/wp-includes/comment.php index e95d395cce..d54de99951 100644
function wp_get_current_commenter() { 1768 1768 return apply_filters( 'wp_get_current_commenter', compact( 'comment_author', 'comment_author_email', 'comment_author_url' ) ); 1769 1769 } 1770 1770 1771 /** 1772 * Get unapproved commenter's email. 1773 * 1774 * Used when a commenter did not consent to use comment cookies. 1775 * 1776 * @since 5.1.0 1777 * 1778 * @return string The unapproved commenter's email. 1779 */ 1780 function wp_get_unapproved_commenter_email() { 1781 $commenter_email = ''; 1782 1783 if ( isset( $_GET['unapproved'] ) && isset( $_GET['moderation-hash'] ) ) { 1784 $comment = get_comment( $_GET['unapproved'] ); 1785 1786 if ( hash_equals( $_GET['moderation-hash'], wp_hash( $comment->comment_date_gmt ) ) ) { 1787 $commenter_email = $comment->comment_author_email; 1788 } 1789 } 1790 1791 return $commenter_email; 1792 } 1793 1771 1794 /** 1772 1795 * Inserts a comment into the database. 1773 1796 * -
tests/phpunit/tests/comment/commentsTemplate.php
diff --git tests/phpunit/tests/comment/commentsTemplate.php tests/phpunit/tests/comment/commentsTemplate.php index 2b22d2d268..a81d732510 100644
class Tests_Comment_CommentsTemplate extends WP_UnitTestCase { 831 831 return $commenter; 832 832 } 833 833 834 /** 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 834 868 /** 835 869 * @ticket 35378 836 870 */