Respect comment_date
and comment_date_gmt
params in wp_new_comment()
.
Props solarissmoke, oso96_2000. Fixes #14279. git-svn-id: https://develop.svn.wordpress.org/trunk@31615 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
1ee4d99972
commit
c1b30747d5
@ -2212,8 +2212,13 @@ function wp_new_comment( $commentdata ) {
|
||||
$commentdata['comment_author_IP'] = preg_replace( '/[^0-9a-fA-F:., ]/', '',$_SERVER['REMOTE_ADDR'] );
|
||||
$commentdata['comment_agent'] = isset( $_SERVER['HTTP_USER_AGENT'] ) ? substr( $_SERVER['HTTP_USER_AGENT'], 0, 254 ) : '';
|
||||
|
||||
$commentdata['comment_date'] = current_time('mysql');
|
||||
$commentdata['comment_date_gmt'] = current_time('mysql', 1);
|
||||
if ( empty( $commentdata['comment_date'] ) ) {
|
||||
$commentdata['comment_date'] = current_time('mysql');
|
||||
}
|
||||
|
||||
if ( empty( $commentdata['comment_date_gmt'] ) ) {
|
||||
$commentdata['comment_date_gmt'] = current_time( 'mysql', 1 );
|
||||
}
|
||||
|
||||
$commentdata = wp_filter_comment($commentdata);
|
||||
|
||||
|
@ -72,4 +72,44 @@ class Tests_Comment extends WP_UnitTestCase {
|
||||
|
||||
$this->assertSame( array(), $found );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 14279
|
||||
*/
|
||||
public function test_wp_new_comment_respects_dates() {
|
||||
// `wp_new_comment()` checks REMOTE_ADDR, so we fake it to avoid PHP notices.
|
||||
if ( isset( $_SERVER['REMOTE_ADDR'] ) ) {
|
||||
$remote_addr = $_SERVER['REMOTE_ADDR'];
|
||||
} else {
|
||||
$_SERVER['REMOTE_ADDR'] = '';
|
||||
}
|
||||
|
||||
$u = $this->factory->user->create();
|
||||
$post_id = $this->factory->post->create( array( 'post_author' => $u ) );
|
||||
|
||||
$data = array(
|
||||
'comment_post_ID' => $post_id,
|
||||
'comment_author' => rand_str(),
|
||||
'comment_author_url' => '',
|
||||
'comment_author_email' => '',
|
||||
'comment_type' => '',
|
||||
'comment_content' => rand_str(),
|
||||
'comment_date' => '2011-01-01 10:00:00',
|
||||
'comment_date_gmt' => '2011-01-01 10:00:00',
|
||||
);
|
||||
|
||||
$id = wp_new_comment( $data );
|
||||
|
||||
$comment = get_comment( $id );
|
||||
|
||||
$this->assertEquals( $data['comment_date'], $comment->comment_date );
|
||||
$this->assertEquals( $data['comment_date_gmt'], $comment->comment_date_gmt );
|
||||
|
||||
// Cleanup.
|
||||
if ( isset( $remote_addr ) ) {
|
||||
$_SERVER['REMOTE_ADDR'] = $remote_addr;
|
||||
} else {
|
||||
unset( $_SERVER['REMOTE_ADDR'] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user