From e6ce714219774422f3ae754d2607098fbd60f466 Mon Sep 17 00:00:00 2001 From: Gary Pendergast Date: Wed, 21 Dec 2016 05:13:36 +0000 Subject: [PATCH] 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 --- .../endpoints/class-wp-rest-comments-controller.php | 9 ++++++++- wp-includes/version.php | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php b/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php index 94d75cf42a..bd0c920c0f 100644 --- a/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php +++ b/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php @@ -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 ) ); } diff --git a/wp-includes/version.php b/wp-includes/version.php index 4cf8134f11..00ef2f560e 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -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.