From 52aa1804e4445966cd02ca0d9e2d63202ae7cbc2 Mon Sep 17 00:00:00 2001 From: Peter Westwood Date: Thu, 10 Jul 2014 14:16:20 +0000 Subject: [PATCH] XMLRPC: Restore support in wp.newPost for dates to be supplied in the structured dateTime.iso8601 format as well as still supporting dates specified as strings. Fixes #28601. git-svn-id: https://develop.svn.wordpress.org/trunk@29063 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/class-wp-xmlrpc-server.php | 4 ++-- tests/phpunit/tests/xmlrpc/wp/newPost.php | 26 ++++++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/wp-includes/class-wp-xmlrpc-server.php b/src/wp-includes/class-wp-xmlrpc-server.php index bad5c47844..97783b7d41 100644 --- a/src/wp-includes/class-wp-xmlrpc-server.php +++ b/src/wp-includes/class-wp-xmlrpc-server.php @@ -1103,13 +1103,13 @@ class wp_xmlrpc_server extends IXR_Server { return $this->error; // convert the date field back to IXR form - if ( isset( $content_struct['post_date'] ) ) { + if ( isset( $content_struct['post_date'] ) && ! is_a( $content_struct['post_date'], 'IXR_Date' ) ) { $content_struct['post_date'] = $this->_convert_date( $content_struct['post_date'] ); } // ignore the existing GMT date if it is empty or a non-GMT date was supplied in $content_struct, // since _insert_post will ignore the non-GMT date if the GMT date is set - if ( isset( $content_struct['post_date_gmt'] ) ) { + if ( isset( $content_struct['post_date_gmt'] ) && ! is_a( $content_struct['post_date_gmt'], 'IXR_Date' ) ) { if ( $content_struct['post_date_gmt'] == '0000-00-00 00:00:00' || isset( $content_struct['post_date'] ) ) { unset( $content_struct['post_date_gmt'] ); } else { diff --git a/tests/phpunit/tests/xmlrpc/wp/newPost.php b/tests/phpunit/tests/xmlrpc/wp/newPost.php index e7bd8c015c..bcab61fa9c 100644 --- a/tests/phpunit/tests/xmlrpc/wp/newPost.php +++ b/tests/phpunit/tests/xmlrpc/wp/newPost.php @@ -357,4 +357,30 @@ class Tests_XMLRPC_wp_newPost extends WP_XMLRPC_UnitTestCase { $this->assertEquals( $date_string , $fetched_post->post_date_gmt ); } + /** + * @ticket 28601 + */ + function test_valid_IXR_post_date() { + $this->make_user_by_role( 'author' ); + $date_string = '1984-01-11 05:00:00'; + $post = array( 'post_title' => 'test', 'post_content' => 'test', 'post_date' => new IXR_Date( mysql2date( 'Ymd\TH:i:s', $date_string, false ) ) ); + $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'author', 'author', $post ) ); + $fetched_post = get_post( $result ); + $this->assertStringMatchesFormat( '%d', $result ); + $this->assertEquals( $date_string , $fetched_post->post_date ); + } + + /** + * @ticket 28601 + */ + function test_valid_IXR_post_date_gmt() { + $this->make_user_by_role( 'author' ); + $date_string = '1984-01-11 05:00:00'; + $post = array( 'post_title' => 'test', 'post_content' => 'test', 'post_date_gmt' => new IXR_Date( mysql2date( 'Ymd\TH:i:s', $date_string, false ) ) ); + $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'author', 'author', $post ) ); + $fetched_post = get_post( $result ); + $this->assertStringMatchesFormat( '%d', $result ); + $this->assertEquals( $date_string , $fetched_post->post_date_gmt ); + } + }