diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php
index 365c4f6..03d30b0 100644
|
a
|
b
|
class WP_REST_Comments_Controller extends WP_REST_Controller {
|
| 431 | 431 | } |
| 432 | 432 | |
| 433 | 433 | /* |
| 434 | | * Do not allow a comment to be created with an empty string for |
| | 434 | * Do not allow a comment to be created with missing or empty |
| 435 | 435 | * comment_content. See wp_handle_comment_submission(). |
| 436 | 436 | */ |
| 437 | | if ( '' === $prepared_comment['comment_content'] ) { |
| | 437 | if ( empty( $prepared_comment['comment_content'] ) ) { |
| 438 | 438 | return new WP_Error( 'rest_comment_content_invalid', __( 'Comment content is invalid.' ), array( 'status' => 400 ) ); |
| 439 | 439 | } |
| 440 | 440 | |
| … |
… |
class WP_REST_Comments_Controller extends WP_REST_Controller {
|
| 636 | 636 | return $prepared_args; |
| 637 | 637 | } |
| 638 | 638 | |
| | 639 | if ( isset( $prepared_args['comment_content'] ) && empty( $prepared_args['comment_content'] ) ) { |
| | 640 | return new WP_Error( 'rest_comment_content_invalid', __( 'Comment content is invalid.' ), array( 'status' => 400 ) ); |
| | 641 | } |
| | 642 | |
| 639 | 643 | $prepared_args['comment_ID'] = $id; |
| 640 | 644 | |
| 641 | 645 | $check_comment_lengths = wp_check_comment_data_max_lengths( $prepared_args ); |
| … |
… |
class WP_REST_Comments_Controller extends WP_REST_Controller {
|
| 1064 | 1068 | } |
| 1065 | 1069 | } |
| 1066 | 1070 | |
| 1067 | | // Require 'comment_content' unless only the 'comment_status' is being updated. |
| 1068 | | if ( ! empty( $prepared_comment ) && ! isset( $prepared_comment['comment_content'] ) ) { |
| 1069 | | return new WP_Error( 'rest_comment_content_required', __( 'Missing comment content.' ), array( 'status' => 400 ) ); |
| 1070 | | } |
| 1071 | | |
| 1072 | 1071 | /** |
| 1073 | 1072 | * Filters a comment after it is prepared for the database. |
| 1074 | 1073 | * |
diff --git a/tests/phpunit/tests/rest-api/rest-comments-controller.php b/tests/phpunit/tests/rest-api/rest-comments-controller.php
index e225cbc..a0d87ff 100644
|
a
|
b
|
class WP_Test_REST_Comments_Controller extends WP_Test_REST_Controller_Testcase
|
| 929 | 929 | $this->assertArrayHasKey( 'author_email', $data['data']['params'] ); |
| 930 | 930 | } |
| 931 | 931 | |
| 932 | | public function test_create_item_invalid_blank_content() { |
| | 932 | public function test_create_item_invalid_no_content() { |
| 933 | 933 | wp_set_current_user( 0 ); |
| 934 | 934 | |
| 935 | 935 | $params = array( |
| … |
… |
class WP_Test_REST_Comments_Controller extends WP_Test_REST_Controller_Testcase
|
| 937 | 937 | 'author_name' => 'Reverend Lovejoy', |
| 938 | 938 | 'author_email' => 'lovejoy@example.com', |
| 939 | 939 | 'author_url' => 'http://timothylovejoy.jr', |
| 940 | | 'content' => '', |
| 941 | 940 | ); |
| 942 | 941 | |
| 943 | 942 | $request = new WP_REST_Request( 'POST', '/wp/v2/comments' ); |
| … |
… |
class WP_Test_REST_Comments_Controller extends WP_Test_REST_Controller_Testcase
|
| 946 | 945 | |
| 947 | 946 | $response = $this->server->dispatch( $request ); |
| 948 | 947 | $this->assertErrorResponse( 'rest_comment_content_invalid', $response, 400 ); |
| | 948 | |
| | 949 | $params['content'] = ''; |
| | 950 | $request->set_body( wp_json_encode( $params ) ); |
| | 951 | $response = $this->server->dispatch( $request ); |
| | 952 | $this->assertErrorResponse( 'rest_comment_content_invalid', $response, 400 ); |
| 949 | 953 | } |
| 950 | 954 | |
| 951 | 955 | public function test_create_item_invalid_date() { |
| … |
… |
class WP_Test_REST_Comments_Controller extends WP_Test_REST_Controller_Testcase
|
| 1618 | 1622 | $this->assertEquals( '2014-11-07T10:14:25', $comment['date'] ); |
| 1619 | 1623 | } |
| 1620 | 1624 | |
| | 1625 | public function test_update_item_no_content() { |
| | 1626 | $post_id = $this->factory->post->create(); |
| | 1627 | |
| | 1628 | wp_set_current_user( self::$admin_id ); |
| | 1629 | |
| | 1630 | $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/comments/%d', self::$approved_id ) ); |
| | 1631 | $request->set_param( 'author_email', 'another@email.com' ); |
| | 1632 | |
| | 1633 | // Sending a request without content is fine. |
| | 1634 | $response = $this->server->dispatch( $request ); |
| | 1635 | $this->assertEquals( 200, $response->get_status() ); |
| | 1636 | |
| | 1637 | // Sending a request with empty comment is not fine. |
| | 1638 | $request->set_param( 'author_email', 'yetanother@email.com' ); |
| | 1639 | $request->set_param( 'content', '' ); |
| | 1640 | $response = $this->server->dispatch( $request ); |
| | 1641 | $this->assertErrorResponse( 'rest_comment_content_invalid', $response, 400 ); |
| | 1642 | } |
| | 1643 | |
| 1621 | 1644 | public function test_update_comment_status() { |
| 1622 | 1645 | wp_set_current_user( self::$admin_id ); |
| 1623 | 1646 | |