diff --git a/src/wp-includes/class-wp-xmlrpc-server.php b/src/wp-includes/class-wp-xmlrpc-server.php index e8a70ff206..bad5c47844 100644 --- a/src/wp-includes/class-wp-xmlrpc-server.php +++ b/src/wp-includes/class-wp-xmlrpc-server.php @@ -1102,6 +1102,21 @@ class wp_xmlrpc_server extends IXR_Server { if ( ! $user = $this->login( $username, $password ) ) return $this->error; + // convert the date field back to IXR form + if ( isset( $content_struct['post_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 ( $content_struct['post_date_gmt'] == '0000-00-00 00:00:00' || isset( $content_struct['post_date'] ) ) { + unset( $content_struct['post_date_gmt'] ); + } else { + $content_struct['post_date_gmt'] = $this->_convert_date( $content_struct['post_date_gmt'] ); + } + } + /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ do_action( 'xmlrpc_call', 'wp.newPost' ); diff --git a/tests/phpunit/tests/xmlrpc/wp/newPost.php b/tests/phpunit/tests/xmlrpc/wp/newPost.php index 1b775e56fb..4071391261 100644 --- a/tests/phpunit/tests/xmlrpc/wp/newPost.php +++ b/tests/phpunit/tests/xmlrpc/wp/newPost.php @@ -305,4 +305,28 @@ class Tests_XMLRPC_wp_newPost extends WP_XMLRPC_UnitTestCase { $this->assertEquals( 401, $result2->code ); } + /** + * @ticket 28601 + */ + function test_invalid_post_date_does_not_fatal() { + $this->make_user_by_role( 'author' ); + $date_string = '2014-01-01 10:10:10'; + $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 ); + $this->assertStringMatchesFormat( '%d', $result ); + } + + /** + * @ticket 28601 + */ + function test_invalid_post_date_gmt_does_not_fatal() { + $this->make_user_by_role( 'author' ); + $date_string = 'invalid date'; + $post = array( 'post_title' => 'test', 'post_content' => 'test', 'post_date_gmt' => $date_string ); + $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'author', 'author', $post ) ); + $fetched_post = get_post( $result ); + $this->assertStringMatchesFormat( '%d', $result ); + } + }