Skip to content

Commit

Permalink
[N/A] Disable Comment-related blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
bd-viget committed Jan 6, 2025
1 parent a03ad09 commit ad3249c
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ public function __construct() {

// Remove REST API comments.
$this->disable_rest_api_comments();

// Remove comment blocks.
$this->remove_comment_blocks();
}

/**
Expand Down Expand Up @@ -134,4 +137,45 @@ function ( array $endpoints ): array {
}
);
}

/**
* Remove comment blocks.
*
* @return void
*/
private function remove_comment_blocks(): void {
add_filter(
'allowed_block_types_all',
function ( array|bool $allowed_block_types, \WP_Block_Editor_Context $context ): array|bool {
if ( ! is_array( $allowed_block_types ) ) {
$allowed_block_types = array_keys( \WP_Block_Type_Registry::get_instance()->get_all_registered() );
}

$removed_blocks = [
'core/comment-template',
'core/post-comment',
'core/post-comments-count',
'core/post-comments-form',
'core/post-comments-link',
'core/latest-comments',
'core/comments',
'core/comments-title',
'core/comments-pagination',
'core/comments-pagination-next',
'core/comments-pagination-previous',
'core/comments-pagination-numbers',
'core/comment-author-name',
'core/comment-author-avatar',
'core/comment-content',
'core/comment-date',
'core/comment-edit-link',
'core/comment-reply-link',
];

return array_values( array_diff( $allowed_block_types, $removed_blocks ) );
},
10,
2
);
}
}
1 change: 0 additions & 1 deletion wp-content/themes/wp-starter/inc/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ function ( array|bool $allowed_block_types, WP_Block_Editor_Context $context ):
'core/audio',
'core/calendar',
'core/html',
'core/latest-comments',
'core/latest-posts',
'core/more',
'core/nextpage',
Expand Down

0 comments on commit ad3249c

Please sign in to comment.