From d3010280799c450bc3ddb117a8cc371b962a8c7d Mon Sep 17 00:00:00 2001 From: adamsilverstein Date: Sun, 21 Sep 2025 21:22:01 -0600 Subject: [PATCH 1/4] Enable empty block comments --- .../rest-api/endpoints/class-wp-rest-comments-controller.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 a0b68759f9942..6017695ea13fb 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 @@ -859,8 +859,8 @@ public function update_item( $request ) { if ( is_wp_error( $prepared_args ) ) { return $prepared_args; } - - if ( isset( $prepared_args['comment_content'] ) && empty( $prepared_args['comment_content'] ) ) { + $is_block_comment = isset( $prepared_args['type'] ) && 'block_comment' === $prepared_args['type']; + if ( ! $is_block_comment && isset( $prepared_args['comment_content'] ) && empty( $prepared_args['comment_content'] ) ) { return new WP_Error( 'rest_comment_content_invalid', __( 'Invalid comment content.' ), From 42587f9db638d6429bc8603a2f0156dff610d1ab Mon Sep 17 00:00:00 2001 From: adamsilverstein Date: Mon, 22 Sep 2025 08:42:43 -0600 Subject: [PATCH 2/4] try using check_is_comment_content_allowed for updates --- .../rest-api/endpoints/class-wp-rest-comments-controller.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) 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 6017695ea13fb..04ca858598c9f 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 @@ -859,8 +859,7 @@ public function update_item( $request ) { if ( is_wp_error( $prepared_args ) ) { return $prepared_args; } - $is_block_comment = isset( $prepared_args['type'] ) && 'block_comment' === $prepared_args['type']; - if ( ! $is_block_comment && isset( $prepared_args['comment_content'] ) && empty( $prepared_args['comment_content'] ) ) { + if ( ! $this->check_is_comment_content_allowed( $prepared_args ) ) { return new WP_Error( 'rest_comment_content_invalid', __( 'Invalid comment content.' ), From 885ef271ab95e8e01ddfb941a3b19ff0017e72a4 Mon Sep 17 00:00:00 2001 From: "K. Adam White" Date: Mon, 29 Sep 2025 11:12:41 -0400 Subject: [PATCH 3/4] 64049: Add failing test for updating comment to empty --- .../rest-api/rest-comments-controller.php | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/phpunit/tests/rest-api/rest-comments-controller.php b/tests/phpunit/tests/rest-api/rest-comments-controller.php index 0bfe4e778d870..90192a2e247a0 100644 --- a/tests/phpunit/tests/rest-api/rest-comments-controller.php +++ b/tests/phpunit/tests/rest-api/rest-comments-controller.php @@ -2493,6 +2493,30 @@ public function test_update_item_no_content() { $this->assertErrorResponse( 'rest_comment_content_invalid', $response, 400 ); } + /** + * @ticket 64049 + */ + public function test_update_item_no_content_allow_empty_comment_filter() { + $post_id = self::factory()->post->create(); + + wp_set_current_user( self::$admin_id ); + + $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/comments/%d', self::$approved_id ) ); + $request->set_param( 'author_email', 'another@email.com' ); + + // Sending a request without content is fine. + $response = rest_get_server()->dispatch( $request ); + $this->assertSame( 200, $response->get_status() ); + + // Sending a request with empty comment is not fine. + $request->set_param( 'author_email', 'yetanother@email.com' ); + $request->set_param( 'content', '' ); + add_filter( 'allow_empty_comment', '__return_true' ); + $response = rest_get_server()->dispatch( $request ); + remove_filter( 'allow_empty_comment', '__return_true' ); + $this->assertSame( 200, $response->get_status() ); + } + public function test_update_item_no_change() { $comment = get_comment( self::$approved_id ); From 96de3d9d50662f6a9165b846fd77872dd2761d03 Mon Sep 17 00:00:00 2001 From: "K. Adam White" Date: Mon, 29 Sep 2025 16:44:49 -0400 Subject: [PATCH 4/4] 64049: Skip content-emptiness check if content key is not present in comment object Permits patch updates which modify non-content values without incorrectly failing a partial object for having "empty" content --- .../rest-api/endpoints/class-wp-rest-comments-controller.php | 4 ++++ 1 file changed, 4 insertions(+) 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 04ca858598c9f..0714a9ebfb108 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 @@ -1902,6 +1902,10 @@ public function check_comment_author_email( $value, $request, $param ) { * @return bool True if the content is allowed, false otherwise. */ protected function check_is_comment_content_allowed( $prepared_comment ) { + if ( ! isset( $prepared_comment['comment_content'] ) ) { + return true; + } + $check = wp_parse_args( $prepared_comment, array(