XML-RPC: calculate the proper offset for GMT in wp.newPost
, mw.newPost
, and mw.editPost
when post_date
is set, wp.editComment
when comment_date
is set. post|comment_date
is assumed to be GMT. This is only true if the timezone string for the site matches GMT.
Adds unit tests for each. Props smerriman, justdaiv, wonderboymusic. Fixes #30429. git-svn-id: https://develop.svn.wordpress.org/trunk@34681 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
16e0cc873b
commit
948ab018d2
@ -1324,8 +1324,8 @@ class wp_xmlrpc_server extends IXR_Server {
|
||||
}
|
||||
|
||||
if ( ! empty( $dateCreated ) ) {
|
||||
$post_data['post_date'] = get_date_from_gmt( iso8601_to_datetime( $dateCreated ) );
|
||||
$post_data['post_date_gmt'] = iso8601_to_datetime( $dateCreated, 'GMT' );
|
||||
$post_data['post_date'] = iso8601_to_datetime( $dateCreated );
|
||||
$post_data['post_date_gmt'] = get_gmt_from_date( $post_data['post_date'] );
|
||||
}
|
||||
|
||||
if ( ! isset( $post_data['ID'] ) )
|
||||
@ -3395,8 +3395,8 @@ class wp_xmlrpc_server extends IXR_Server {
|
||||
if ( !empty( $content_struct['date_created_gmt'] ) ) {
|
||||
// We know this is supposed to be GMT, so we're going to slap that Z on there by force
|
||||
$dateCreated = rtrim( $content_struct['date_created_gmt']->getIso(), 'Z' ) . 'Z';
|
||||
$comment_date = get_date_from_gmt(iso8601_to_datetime($dateCreated));
|
||||
$comment_date_gmt = iso8601_to_datetime($dateCreated, 'GMT');
|
||||
$comment_date = iso8601_to_datetime( $dateCreated );
|
||||
$comment_date_gmt = get_gmt_from_date( $comment_date );
|
||||
}
|
||||
|
||||
if ( isset($content_struct['content']) )
|
||||
@ -4960,8 +4960,8 @@ class wp_xmlrpc_server extends IXR_Server {
|
||||
$dateCreated = $content_struct['dateCreated']->getIso();
|
||||
|
||||
if ( !empty( $dateCreated ) ) {
|
||||
$post_date = get_date_from_gmt(iso8601_to_datetime($dateCreated));
|
||||
$post_date_gmt = iso8601_to_datetime($dateCreated, 'GMT');
|
||||
$post_date = iso8601_to_datetime( $dateCreated );
|
||||
$post_date_gmt = get_gmt_from_date( $post_date );
|
||||
} else {
|
||||
$post_date = '';
|
||||
$post_date_gmt = '';
|
||||
@ -5314,8 +5314,8 @@ class wp_xmlrpc_server extends IXR_Server {
|
||||
$dateCreated = $content_struct['dateCreated']->getIso();
|
||||
|
||||
if ( !empty( $dateCreated ) ) {
|
||||
$post_date = get_date_from_gmt(iso8601_to_datetime($dateCreated));
|
||||
$post_date_gmt = iso8601_to_datetime($dateCreated, 'GMT');
|
||||
$post_date = iso8601_to_datetime( $dateCreated );
|
||||
$post_date_gmt = get_gmt_from_date( $post_date, 'GMT' );
|
||||
} else {
|
||||
$post_date = $postdata['post_date'];
|
||||
$post_date_gmt = $postdata['post_date_gmt'];
|
||||
|
@ -229,4 +229,30 @@ class Tests_XMLRPC_mw_editPost extends WP_XMLRPC_UnitTestCase {
|
||||
$this->assertInstanceOf( 'IXR_Error', $result );
|
||||
$this->assertEquals( $result->code, 401 );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 30429
|
||||
*/
|
||||
function test_post_date_timezone_conversion() {
|
||||
$tz = get_option( 'timezone_string' );
|
||||
update_option( 'timezone_string', 'America/New_York' );
|
||||
|
||||
$editor_id = $this->make_user_by_role( 'editor' );
|
||||
|
||||
$post_id = $this->factory->post->create( array(
|
||||
'post_author' => $editor_id
|
||||
) );
|
||||
|
||||
$date_string = '1984-01-11 05:00:00';
|
||||
$result = $this->myxmlrpcserver->mw_editPost( array( $post_id, 'editor', 'editor', array(
|
||||
'dateCreated' => new IXR_Date( mysql2date( 'Ymd\TH:i:s', $date_string, false ) ),
|
||||
) ) );
|
||||
|
||||
$fetched_post = get_post( $post_id );
|
||||
|
||||
update_option( 'timezone_string', $tz );
|
||||
|
||||
$this->assertTrue( $result );
|
||||
$this->assertEquals( $date_string, $fetched_post->post_date );
|
||||
}
|
||||
}
|
||||
|
@ -180,4 +180,27 @@ class Tests_XMLRPC_mw_newPost extends WP_XMLRPC_UnitTestCase {
|
||||
$this->assertEquals( 'draft', $out->post_status );
|
||||
$this->assertEquals( '0000-00-00 00:00:00', $out->post_date_gmt );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 30429
|
||||
*/
|
||||
function test_post_date_timezone_conversion() {
|
||||
$tz = get_option( 'timezone_string' );
|
||||
update_option( 'timezone_string', 'America/New_York' );
|
||||
|
||||
$this->make_user_by_role( 'editor' );
|
||||
$date_string = '1984-01-11 05:00:00';
|
||||
$post = array(
|
||||
'title' => 'test',
|
||||
'post_content' => 'test',
|
||||
'dateCreated' => new IXR_Date( mysql2date( 'Ymd\TH:i:s', $date_string, false ) )
|
||||
);
|
||||
$result = $this->myxmlrpcserver->mw_newPost( array( 1, 'editor', 'editor', $post ) );
|
||||
$fetched_post = get_post( $result );
|
||||
|
||||
update_option( 'timezone_string', $tz );
|
||||
|
||||
$this->assertStringMatchesFormat( '%d', $result );
|
||||
$this->assertEquals( $date_string , $fetched_post->post_date );
|
||||
}
|
||||
}
|
||||
|
@ -69,4 +69,36 @@ class Tests_XMLRPC_wp_editComment extends WP_XMLRPC_UnitTestCase {
|
||||
|
||||
$this->assertEquals( 'trash', get_comment( $comment_id )->comment_approved );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 30429
|
||||
*/
|
||||
function test_post_date_timezone_conversion() {
|
||||
$tz = get_option( 'timezone_string' );
|
||||
update_option( 'timezone_string', 'America/New_York' );
|
||||
|
||||
$this->make_user_by_role( 'administrator' );
|
||||
$post_id = $this->factory->post->create();
|
||||
|
||||
$comment_data = array(
|
||||
'comment_post_ID' => $post_id,
|
||||
'comment_author' => 'Test commenter',
|
||||
'comment_author_url' => 'http://example.com/',
|
||||
'comment_author_email' => 'example@example.com',
|
||||
'comment_content' => rand_str( 100 ),
|
||||
'comment_approved' => '1',
|
||||
);
|
||||
$comment_id = wp_insert_comment( $comment_data );
|
||||
|
||||
$date_string = '1984-01-11 05:00:00';
|
||||
$result = $this->myxmlrpcserver->wp_editComment( array( 1, 'administrator', 'administrator', $comment_id, array(
|
||||
'date_created_gmt' => new IXR_Date( mysql2date( 'Ymd\TH:i:s', $date_string, false ) )
|
||||
) ) );
|
||||
$fetched_comment = get_comment( $comment_id );
|
||||
|
||||
update_option( 'timezone_string', $tz );
|
||||
|
||||
$this->assertTrue( $result );
|
||||
$this->assertEquals( $date_string, $fetched_comment->comment_date );
|
||||
}
|
||||
}
|
@ -383,4 +383,22 @@ class Tests_XMLRPC_wp_newPost extends WP_XMLRPC_UnitTestCase {
|
||||
$this->assertEquals( $date_string , $fetched_post->post_date_gmt );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 30429
|
||||
*/
|
||||
function test_post_date_timezone_conversion() {
|
||||
$tz = get_option( 'timezone_string' );
|
||||
update_option( 'timezone_string', 'America/New_York' );
|
||||
|
||||
$this->make_user_by_role( 'author' );
|
||||
$date_string = '1984-01-11 05:00:00';
|
||||
$post = array( 'post_title' => 'test', 'post_content' => 'test', 'post_date' => $date_string );
|
||||
$result = $this->myxmlrpcserver->wp_newPost( array( 1, 'author', 'author', $post ) );
|
||||
$fetched_post = get_post( $result );
|
||||
|
||||
update_option( 'timezone_string', $tz );
|
||||
|
||||
$this->assertStringMatchesFormat( '%d', $result );
|
||||
$this->assertEquals( $date_string , $fetched_post->post_date );
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user