From f325af9caacb8950c7d341b339c7f6a821b496cd Mon Sep 17 00:00:00 2001 From: Joe Hoyle Date: Thu, 10 Nov 2016 03:35:30 +0000 Subject: [PATCH] REST API: Allow updating a comment without the content present. For all resources in the REST API, sending partial updates is supported. This fixes needing to _always_ specify comment content. Props jnylen. Fixes #38720. Built from https://develop.svn.wordpress.org/trunk@39196 git-svn-id: http://core.svn.wordpress.org/trunk@39136 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- .../endpoints/class-wp-rest-comments-controller.php | 13 ++++++------- wp-includes/version.php | 2 +- 2 files changed, 7 insertions(+), 8 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 365c4f61ff..03d30b0e7a 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 @@ -431,10 +431,10 @@ class WP_REST_Comments_Controller extends WP_REST_Controller { } /* - * Do not allow a comment to be created with an empty string for + * Do not allow a comment to be created with missing or empty * comment_content. See wp_handle_comment_submission(). */ - if ( '' === $prepared_comment['comment_content'] ) { + if ( empty( $prepared_comment['comment_content'] ) ) { return new WP_Error( 'rest_comment_content_invalid', __( 'Comment content is invalid.' ), array( 'status' => 400 ) ); } @@ -636,6 +636,10 @@ class WP_REST_Comments_Controller extends WP_REST_Controller { return $prepared_args; } + if ( isset( $prepared_args['comment_content'] ) && empty( $prepared_args['comment_content'] ) ) { + return new WP_Error( 'rest_comment_content_invalid', __( 'Comment content is invalid.' ), array( 'status' => 400 ) ); + } + $prepared_args['comment_ID'] = $id; $check_comment_lengths = wp_check_comment_data_max_lengths( $prepared_args ); @@ -1064,11 +1068,6 @@ class WP_REST_Comments_Controller extends WP_REST_Controller { } } - // Require 'comment_content' unless only the 'comment_status' is being updated. - if ( ! empty( $prepared_comment ) && ! isset( $prepared_comment['comment_content'] ) ) { - return new WP_Error( 'rest_comment_content_required', __( 'Missing comment content.' ), array( 'status' => 400 ) ); - } - /** * Filters a comment after it is prepared for the database. * diff --git a/wp-includes/version.php b/wp-includes/version.php index 1a2a0a2ace..3e20c58dce 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.7-beta2-39195'; +$wp_version = '4.7-beta2-39196'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.