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
This commit is contained in:
parent
3a9bc32949
commit
e49c8b425c
@ -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' ) );
|
||||
|
||||
|
@ -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 );
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user