From 4b10def07eca3e39a5b262e80d98c5e5d920ed44 Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Thu, 29 Oct 2015 21:28:39 +0000 Subject: [PATCH] Correctly populate the `user_id` field for comments when a user submits a comment while logged in. Props imath Fixes #34493 git-svn-id: https://develop.svn.wordpress.org/trunk@35435 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/comment-functions.php | 3 ++- tests/phpunit/tests/comment-submission.php | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/comment-functions.php b/src/wp-includes/comment-functions.php index 6b055d1d22..e1975f62e6 100644 --- a/src/wp-includes/comment-functions.php +++ b/src/wp-includes/comment-functions.php @@ -2742,6 +2742,7 @@ function wp_handle_comment_submission( $comment_data ) { $comment_author = $user->display_name; $comment_author_email = $user->user_email; $comment_author_url = $user->user_url; + $user_id = $user->ID; if ( current_user_can( 'unfiltered_html' ) ) { if ( ! isset( $comment_data['_wp_unfiltered_html_comment'] ) || ! wp_verify_nonce( $comment_data['_wp_unfiltered_html_comment'], 'unfiltered-html-comment_' . $comment_post_ID ) @@ -2778,7 +2779,7 @@ function wp_handle_comment_submission( $comment_data ) { 'comment_content', 'comment_type', 'comment_parent', - 'user_ID' + 'user_id' ); $comment_id = wp_new_comment( wp_slash( $commentdata ) ); diff --git a/tests/phpunit/tests/comment-submission.php b/tests/phpunit/tests/comment-submission.php index 548b77b609..b12d7f7e88 100644 --- a/tests/phpunit/tests/comment-submission.php +++ b/tests/phpunit/tests/comment-submission.php @@ -176,6 +176,7 @@ class Tests_Comment_Submission extends WP_UnitTestCase { $this->assertSame( $user->display_name, $comment->comment_author ); $this->assertSame( $user->user_email, $comment->comment_author_email ); $this->assertSame( $user->user_url, $comment->comment_author_url ); + $this->assertSame( $user->ID, intval( $comment->user_id ) ); } @@ -198,6 +199,7 @@ class Tests_Comment_Submission extends WP_UnitTestCase { $this->assertSame( 'Comment Author', $comment->comment_author ); $this->assertSame( 'comment@example.org', $comment->comment_author_email ); $this->assertSame( 'http://user.example.org', $comment->comment_author_url ); + $this->assertSame( '0', $comment->user_id ); }