From 646a4fd1e9cba383bbd3b4104e9d55e4fa31e15e Mon Sep 17 00:00:00 2001 From: Andrew Nacin Date: Thu, 27 Sep 2012 03:39:40 +0000 Subject: [PATCH] XML-RPC: Add an if_not_modified_since argument to wp.editPost. Accepts a GMT date, which is used to compare to the current post_modified_gmt value for the post being edited. If the post has since been edited (as in, too old of a date was passed), the edit is rejected as overwriting a newer version. It is rejected with a HTTP 409 Conflict status code. (Fancy.) props koke, markoheinjen. Tests: [UT1049] see #21397. git-svn-id: http://core.svn.wordpress.org/trunk@22034 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/class-wp-xmlrpc-server.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/wp-includes/class-wp-xmlrpc-server.php b/wp-includes/class-wp-xmlrpc-server.php index b2e6c450e7..a6e98db857 100644 --- a/wp-includes/class-wp-xmlrpc-server.php +++ b/wp-includes/class-wp-xmlrpc-server.php @@ -1258,6 +1258,13 @@ class wp_xmlrpc_server extends IXR_Server { if ( empty( $post['ID'] ) ) return new IXR_Error( 404, __( 'Invalid post ID.' ) ); + if ( isset( $content_struct['if_not_modified_since'] ) ) { + // If the post has been modified since the date provided, return an error. + if ( mysql2date( 'U', $post['post_modified_gmt'] ) > $content_struct['if_not_modified_since']->getTimestamp() ) { + return new IXR_Error( 409, __( 'There is a revision of this post that is more recent.' ) ); + } + } + // convert the date field back to IXR form $post['post_date'] = $this->_convert_date( $post['post_date'] ); @@ -1475,7 +1482,7 @@ class wp_xmlrpc_server extends IXR_Server { if ( isset( $filter['order'] ) ) $query['order'] = $filter['order']; } - + if ( isset( $filter['s'] ) ) { $query['s'] = $filter['s']; }