REST API: Allow sending an empty or no-op comment update.

In general, updates that don't actually change anything should succeed. [39371] added tests for other object types, and this commit fixes empty updates for comments and adds the missing test.

Merges [39597] to the 4.7 branch.

Props jnylen0.
Fixes #38700.


Built from https://develop.svn.wordpress.org/branches/4.7@39628


git-svn-id: http://core.svn.wordpress.org/branches/4.7@39568 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Gary Pendergast 2016-12-21 05:13:36 +00:00
parent 45e03c2576
commit e6ce714219
2 changed files with 9 additions and 2 deletions

View File

@ -664,6 +664,13 @@ class WP_REST_Comments_Controller extends WP_REST_Controller {
return $prepared_args;
}
if ( ! empty( $prepared_args['comment_post_ID'] ) ) {
$post = get_post( $prepared_args['comment_post_ID'] );
if ( empty( $post ) ) {
return new WP_Error( 'rest_comment_invalid_post_id', __( 'Invalid post ID.' ), array( 'status' => 403 ) );
}
}
if ( empty( $prepared_args ) && isset( $request['status'] ) ) {
// Only the comment status is being changed.
$change = $this->handle_status_param( $request['status'], $id );
@ -690,7 +697,7 @@ class WP_REST_Comments_Controller extends WP_REST_Controller {
$updated = wp_update_comment( wp_slash( (array) $prepared_args ) );
if ( 0 === $updated ) {
if ( false === $updated ) {
return new WP_Error( 'rest_comment_failed_edit', __( 'Updating comment failed.' ), array( 'status' => 500 ) );
}

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.7.1-alpha-39627';
$wp_version = '4.7.1-alpha-39628';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.