From 14c270e4fa9e6569a6a998a8b4c75701bea6b6b8 Mon Sep 17 00:00:00 2001 From: Ella <4710635+ellatrix@users.noreply.github.com> Date: Thu, 14 Nov 2024 14:06:12 +0100 Subject: [PATCH] Comments controller: fix issue where comments are allowed when closed (#66976) Unlinked contributors: xavier-lc. Co-authored-by: ellatrix Co-authored-by: Mamaduka --- ...-gutenberg-rest-comment-controller-6-8.php | 20 ++++--------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/lib/compat/wordpress-6.8/class-gutenberg-rest-comment-controller-6-8.php b/lib/compat/wordpress-6.8/class-gutenberg-rest-comment-controller-6-8.php index 981b9dbd84031..60b45b1a63ade 100644 --- a/lib/compat/wordpress-6.8/class-gutenberg-rest-comment-controller-6-8.php +++ b/lib/compat/wordpress-6.8/class-gutenberg-rest-comment-controller-6-8.php @@ -10,6 +10,10 @@ class Gutenberg_REST_Comment_Controller_6_8 extends WP_REST_Comments_Controller { public function create_item_permissions_check( $request ) { + if ( empty( $request['comment_type'] ) || 'comment' === $request['comment_type'] ) { + return parent::create_item_permissions_check( $request ); + } + if ( ! is_user_logged_in() ) { if ( get_option( 'comment_registration' ) ) { return new WP_Error( @@ -90,14 +94,6 @@ public function create_item_permissions_check( $request ) { ); } - if ( 'draft' === $post->post_status && 'comment' === $request['comment_type'] ) { - return new WP_Error( - 'rest_comment_draft_post', - __( 'Sorry, you are not allowed to create a comment on this post.' ), - array( 'status' => 403 ) - ); - } - if ( 'trash' === $post->post_status ) { return new WP_Error( 'rest_comment_trash_post', @@ -114,14 +110,6 @@ public function create_item_permissions_check( $request ) { ); } - if ( ! comments_open( $post->ID ) && 'comment' === $request['comment_type'] ) { - return new WP_Error( - 'rest_comment_closed', - __( 'Sorry, comments are closed for this item.' ), - array( 'status' => 403 ) - ); - } - return true; } }