Skip to content

Commit

Permalink
Comments controller: fix issue where comments are allowed when closed (
Browse files Browse the repository at this point in the history
…#66976)

Unlinked contributors: xavier-lc.

Co-authored-by: ellatrix <[email protected]>
Co-authored-by: Mamaduka <[email protected]>
  • Loading branch information
3 people authored and priethor committed Nov 14, 2024
1 parent cefe14b commit 14c270e
Showing 1 changed file with 4 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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',
Expand All @@ -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;
}
}
Expand Down

0 comments on commit 14c270e

Please sign in to comment.