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 c129ef6e130c4..bd7861c34782b 100644 --- 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 @@ -574,21 +574,12 @@ public function create_item( $request ) { ); } - // Do not allow comments to be created with a non-default type. - if ( ! empty( $request['type'] ) && 'comment' !== $request['type'] ) { - return new WP_Error( - 'rest_invalid_comment_type', - __( 'Cannot create a comment with that type.' ), - array( 'status' => 400 ) - ); - } - $prepared_comment = $this->prepare_item_for_database( $request ); if ( is_wp_error( $prepared_comment ) ) { return $prepared_comment; } - $prepared_comment['comment_type'] = 'comment'; + $prepared_comment['comment_type'] = isset( $request['type'] ) ? $request['type'] : 'comment'; if ( ! isset( $prepared_comment['comment_content'] ) ) { $prepared_comment['comment_content'] = ''; @@ -657,6 +648,7 @@ public function create_item( $request ) { } $prepared_comment['comment_approved'] = wp_allow_comment( $prepared_comment, true ); + $prepared_comment['comment_approved'] = isset( $request['comment_approved'] ) ? $request['comment_approved'] : $prepared_comment['comment_approved']; if ( is_wp_error( $prepared_comment['comment_approved'] ) ) { $error_code = $prepared_comment['comment_approved']->get_error_code(); diff --git a/tests/phpunit/tests/rest-api/rest-comments-controller.php b/tests/phpunit/tests/rest-api/rest-comments-controller.php index ee42906c61796..b79e913752073 100644 --- a/tests/phpunit/tests/rest-api/rest-comments-controller.php +++ b/tests/phpunit/tests/rest-api/rest-comments-controller.php @@ -1592,7 +1592,8 @@ public function test_create_comment_with_invalid_type() { $request->set_body( wp_json_encode( $params ) ); $response = rest_get_server()->dispatch( $request ); - $this->assertErrorResponse( 'rest_invalid_comment_type', $response, 400 ); + $this->assertFalse( is_wp_error( $response ) ); + $this->assertSame( 201, $response->get_status() ); } public function test_create_comment_invalid_email() {