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
This commit is contained in:
Joe Hoyle 2016-11-10 03:35:30 +00:00
parent 0e2dd4d85f
commit f325af9caa
2 changed files with 7 additions and 8 deletions

View File

@ -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.
*

View File

@ -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.