From e49c8b425c308f359d03a243496c1d170422ede2 Mon Sep 17 00:00:00 2001 From: Boone Gorges Date: Thu, 7 Jan 2016 03:54:05 +0000 Subject: [PATCH] Allow comment agent and author IP to be set via `wp_update_comment()`. Props adamsilverstein, welcher. Fixes #35276. git-svn-id: https://develop.svn.wordpress.org/trunk@36215 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/comment.php | 2 +- tests/phpunit/tests/comment.php | 36 +++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/comment.php b/src/wp-includes/comment.php index 3354d2b72d..41c586c60f 100644 --- a/src/wp-includes/comment.php +++ b/src/wp-includes/comment.php @@ -1939,7 +1939,7 @@ function wp_update_comment($commentarr) { $comment_ID = $data['comment_ID']; $comment_post_ID = $data['comment_post_ID']; - $keys = array( 'comment_post_ID', 'comment_content', 'comment_author', 'comment_author_email', 'comment_approved', 'comment_karma', 'comment_author_url', 'comment_date', 'comment_date_gmt', 'comment_type', 'comment_parent', 'user_id' ); + $keys = array( 'comment_post_ID', 'comment_content', 'comment_author', 'comment_author_email', 'comment_approved', 'comment_karma', 'comment_author_url', 'comment_date', 'comment_date_gmt', 'comment_type', 'comment_parent', 'user_id', 'comment_agent', 'comment_author_IP' ); $data = wp_array_slice_assoc( $data, $keys ); $rval = $wpdb->update( $wpdb->comments, $data, compact( 'comment_ID' ) ); diff --git a/tests/phpunit/tests/comment.php b/tests/phpunit/tests/comment.php index 83868810f7..e4f50b1fe6 100644 --- a/tests/phpunit/tests/comment.php +++ b/tests/phpunit/tests/comment.php @@ -636,4 +636,40 @@ class Tests_Comment extends WP_UnitTestCase { $this->assertTrue( $draft_comment_status ); } + + /** + * @ticket 35276 + */ + public function test_wp_update_comment_author_id_and_agent() { + + $default_data = array( + 'comment_post_ID' => self::$post_id, + 'comment_author' => rand_str(), + 'comment_author_IP' => '192.168.0.1', + 'comment_agent' => 'WRONG_AGENT', + 'comment_author_url' => '', + 'comment_author_email' => '', + 'comment_type' => '', + 'comment_content' => rand_str(), + ); + + $comment_id = wp_new_comment( $default_data ); + + // Confirm that the IP and Agent are correct on initial save. + $save = get_comment( $comment_id ); + $this->assertSame( $default_data['comment_author_IP'], $save->comment_author_IP ); + $this->assertSame( $default_data['comment_agent'], $save->comment_agent ); + + // Update the comment. + wp_update_comment( array( + 'comment_ID' => $comment_id, + 'comment_author_IP' => '111.111.1.1', + 'comment_agent' => 'SHIELD_AGENT', + ) ); + + // Retrieve and check the new values. + $updated = get_comment( $comment_id ); + $this->assertSame( '111.111.1.1', $updated->comment_author_IP ); + $this->assertSame( 'SHIELD_AGENT', $updated->comment_agent ); + } }