WordPress.org

Make WordPress Core

Changeset 36215


Ignore:
Timestamp:
01/07/2016 03:54:05 AM (4 years ago)
Author:
boonebgorges
Message:

Allow comment agent and author IP to be set via wp_update_comment().

Props adamsilverstein, welcher.
Fixes #35276.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/comment.php

    r36139 r36215  
    19401940    $comment_ID = $data['comment_ID'];
    19411941    $comment_post_ID = $data['comment_post_ID'];
    1942     $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' );
     1942    $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' );
    19431943    $data = wp_array_slice_assoc( $data, $keys );
    19441944    $rval = $wpdb->update( $wpdb->comments, $data, compact( 'comment_ID' ) );
  • trunk/tests/phpunit/tests/comment.php

    r36119 r36215  
    637637        $this->assertTrue( $draft_comment_status );
    638638    }
     639
     640    /**
     641     * @ticket 35276
     642     */
     643    public function test_wp_update_comment_author_id_and_agent() {
     644
     645        $default_data = array(
     646            'comment_post_ID'      => self::$post_id,
     647            'comment_author'       => rand_str(),
     648            'comment_author_IP'    => '192.168.0.1',
     649            'comment_agent'        => 'WRONG_AGENT',
     650            'comment_author_url'   => '',
     651            'comment_author_email' => '',
     652            'comment_type'         => '',
     653            'comment_content'      => rand_str(),
     654        );
     655
     656        $comment_id = wp_new_comment( $default_data );
     657
     658        // Confirm that the IP and Agent are correct on initial save.
     659        $save = get_comment( $comment_id );
     660        $this->assertSame( $default_data['comment_author_IP'], $save->comment_author_IP );
     661        $this->assertSame( $default_data['comment_agent'], $save->comment_agent );
     662
     663        // Update the comment.
     664        wp_update_comment( array(
     665            'comment_ID'        => $comment_id,
     666            'comment_author_IP' => '111.111.1.1',
     667            'comment_agent'     => 'SHIELD_AGENT',
     668        ) );
     669
     670        // Retrieve and check the new values.
     671        $updated = get_comment( $comment_id );
     672        $this->assertSame( '111.111.1.1', $updated->comment_author_IP );
     673        $this->assertSame( 'SHIELD_AGENT', $updated->comment_agent );
     674    }
    639675}
Note: See TracChangeset for help on using the changeset viewer.