Ticket #43857: 43857.10.diff
File 43857.10.diff, 5.1 KB (added by , 6 years ago) |
---|
-
src/wp-comments-post.php
diff --git src/wp-comments-post.php src/wp-comments-post.php index 5c33e87fd3..fe03cb7296 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 // Add specific query arguments to display the awaiting moderation message. 60 if ( 'unapproved' === wp_get_comment_status( $comment ) && ! empty( $comment->comment_author_email ) ) { 61 $location = add_query_arg( 62 array( 63 'unapproved' => $comment->comment_ID, 64 'moderation-hash' => wp_hash( $comment->comment_date_gmt ), 65 ), 66 $location 67 ); 68 } 69 59 70 /** 60 71 * Filters the location URI to send the commenter after posting. 61 72 * -
src/wp-includes/comment-template.php
diff --git src/wp-includes/comment-template.php src/wp-includes/comment-template.php index 918238f7fa..a501d09142 100644
function comments_template( $file = '/comments.php', $separate_comments = false 1372 1372 1373 1373 if ( $user_ID ) { 1374 1374 $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 } 1377 1381 } 1378 1382 1379 1383 $per_page = 0; … … function get_comment_reply_link( $args = array(), $comment = null, $post = null 1690 1694 1691 1695 $link = sprintf( 1692 1696 "<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'], 1694 1706 $data_attribute_string, 1695 1707 esc_attr( sprintf( $args['reply_to_text'], $comment->comment_author ) ), 1696 1708 $args['reply_text'] … … function wp_list_comments( $args = array(), $comments = null ) { 2055 2067 if ( is_user_logged_in() ) { 2056 2068 $comment_args['include_unapproved'] = get_current_user_id(); 2057 2069 } 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 ( ! empty( $unapproved_email ) ) { 2073 $comment_args['include_unapproved'] = array( $unapproved_email ); 2061 2074 } 2062 2075 } 2063 2076 -
src/wp-includes/comment.php
diff --git src/wp-includes/comment.php src/wp-includes/comment.php index e95d395cce..14e72604a8 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 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 */ 1780 function 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 1771 1795 /** 1772 1796 * Inserts a comment into the database. 1773 1797 * -
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 */