|
2 | 2 | /** |
3 | 3 | * Plugin Name: Turn Comments Off |
4 | 4 | * Description: Turn comments off everywhere in WordPress. |
5 | | - * Version: 1.1.1 |
| 5 | + * Version: 1.2.0 |
6 | 6 | * Plugin URI: https://github.com/happyprime/turn-comments-off/ |
7 | 7 | * Author: Happy Prime |
8 | 8 | * Author URI: https://happyprime.co |
|
51 | 51 |
|
52 | 52 | // Remove comment blocks from the editor. (Twice to be sure!) |
53 | 53 | add_action( 'enqueue_block_editor_assets', __NAMESPACE__ . '\unregister_comment_blocks_javascript' ); |
54 | | -add_filter( 'allowed_block_types_all', __NAMESPACE__ . '\unregister_comment_blocks', 99, 1 ); |
| 54 | +add_action( 'init', __NAMESPACE__ . '\unregister_comment_blocks', 99 ); |
55 | 55 |
|
56 | 56 | // And disable all comment related views in the admin. |
57 | 57 | add_filter( 'wp_count_comments', __NAMESPACE__ . '\filter_wp_count_comments' ); |
@@ -109,39 +109,50 @@ function unregister_comment_blocks_javascript() { |
109 | 109 | * |
110 | 110 | * @since 1.1.0 |
111 | 111 | */ |
112 | | -function unregister_comment_blocks( $allowed_blocks ) { |
113 | | - |
114 | | - // get all the registered blocks |
115 | | - $blocks = \WP_Block_Type_Registry::get_instance()->get_all_registered(); |
116 | | - |
117 | | - // disable comment blocks |
118 | | - unset( $blocks[ 'core/comment-author-name' ] ); |
119 | | - unset( $blocks[ 'core/comment-content' ] ); |
120 | | - unset( $blocks[ 'core/comment-date' ] ); |
121 | | - unset( $blocks[ 'core/comment-edit-link' ] ); |
122 | | - unset( $blocks[ 'core/comment-reply-link' ] ); |
123 | | - unset( $blocks[ 'core/comment-template' ] ); |
124 | | - unset( $blocks[ 'core/comments-pagination' ] ); |
125 | | - unset( $blocks[ 'core/comments-pagination-next' ] ); |
126 | | - unset( $blocks[ 'core/comments-pagination-numbers' ] ); |
127 | | - unset( $blocks[ 'core/comments-pagination-previous' ] ); |
128 | | - unset( $blocks[ 'core/comments-query-loop' ] ); |
129 | | - unset( $blocks[ 'core/comments-title' ] ); |
130 | | - unset( $blocks[ 'core/latest-comments' ] ); |
131 | | - unset( $blocks[ 'core/post-comments-form' ] ); |
132 | | - unset( $blocks[ 'core/post-comments-count' ] ); // Gutenberg only. |
133 | | - unset( $blocks[ 'core/post-comments-link' ] ); // Gutenberg only. |
134 | | - |
135 | | - // return the new list of allowed blocks |
136 | | - return array_keys( $blocks ); |
| 112 | +function unregister_comment_blocks() { |
| 113 | + |
| 114 | + // Retrieve all registered blocks. |
| 115 | + $registered_blocks = \WP_Block_Type_Registry::get_instance()->get_all_registered(); |
| 116 | + |
| 117 | + $blocks = [ |
| 118 | + 'core/comments', |
| 119 | + 'core/comments-query-loop', // Replaced by core/comments in Gutenberg 13.7. |
| 120 | + |
| 121 | + 'core/comment-author-avatar', |
| 122 | + 'core/comment-author-name', |
| 123 | + 'core/comment-content', |
| 124 | + 'core/comment-date', |
| 125 | + 'core/comment-edit-link', |
| 126 | + 'core/comment-reply-link', |
| 127 | + 'core/comment-template', |
| 128 | + |
| 129 | + 'core/comments-pagination', |
| 130 | + 'core/comments-pagination-next', |
| 131 | + 'core/comments-pagination-numbers', |
| 132 | + 'core/comments-pagination-previous', |
| 133 | + 'core/comments-title', |
| 134 | + |
| 135 | + 'core/latest-comments', |
| 136 | + |
| 137 | + 'core/post-comment', |
| 138 | + 'core/post-comments-count', |
| 139 | + 'core/post-comments-form', |
| 140 | + 'core/post-comments-link', |
| 141 | + ]; |
| 142 | + |
| 143 | + foreach ( $blocks as $block ) { |
| 144 | + if ( isset( $registered_blocks[ $block ] ) ) { |
| 145 | + unregister_block_type( $block ); |
| 146 | + } |
| 147 | + } |
137 | 148 | } |
138 | 149 |
|
139 | 150 | /** |
140 | 151 | * Remove the "Comments" and Settings -> Discussion menus from the |
141 | 152 | * side menu in the dashboard. |
142 | 153 | */ |
143 | 154 | function remove_comments_menu_page() { |
144 | | - remove_menu_page('edit-comments.php'); |
| 155 | + remove_menu_page( 'edit-comments.php' ); |
145 | 156 | remove_submenu_page( 'options-general.php', 'options-discussion.php' ); |
146 | 157 | } |
147 | 158 |
|
|
0 commit comments