Skip to content

Commit 7aff1a4

Browse files
authored
Merge pull request #8 from happyprime/fix/updates-for-6.1
6.1 release branch
2 parents 2f40f08 + 6e2eedd commit 7aff1a4

8 files changed

Lines changed: 1835 additions & 2199 deletions

File tree

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ If you find something we missed, [please let us know](https://github.com/happypr
2020

2121
## Changelog
2222

23+
### 1.2.0
24+
25+
* Update the list of blocks unregistered to include latest from Gutenberg and WordPress.
26+
* Update `wordpress/scripts` to 24.6.0.
27+
* Refactor how the list of blocks is managed to make future maintenance easier. Props @huubl.
28+
* Only unregister blocks that are registered. Props @huubl.
29+
2330
### 1.1.1
2431

2532
* Unregister core comment blocks in the editor.

build/index.asset.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<?php return array('dependencies' => array('wp-blocks', 'wp-dom-ready'), 'version' => 'f7caf480d7863b302b62');
1+
<?php return array('dependencies' => array('wp-blocks', 'wp-dom-ready'), 'version' => '105d3c0577a1f1b9d0cf');

build/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 1765 additions & 2157 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@
1818
},
1919
"homepage": "https://github.com/happyprime/turn-comments-off#readme",
2020
"devDependencies": {
21-
"@wordpress/scripts": "^23.3.0"
21+
"@wordpress/scripts": "^24.6.0"
2222
}
2323
}

plugin.php

Lines changed: 39 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/**
33
* Plugin Name: Turn Comments Off
44
* Description: Turn comments off everywhere in WordPress.
5-
* Version: 1.1.1
5+
* Version: 1.2.0
66
* Plugin URI: https://github.com/happyprime/turn-comments-off/
77
* Author: Happy Prime
88
* Author URI: https://happyprime.co
@@ -51,7 +51,7 @@
5151

5252
// Remove comment blocks from the editor. (Twice to be sure!)
5353
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 );
5555

5656
// And disable all comment related views in the admin.
5757
add_filter( 'wp_count_comments', __NAMESPACE__ . '\filter_wp_count_comments' );
@@ -109,39 +109,50 @@ function unregister_comment_blocks_javascript() {
109109
*
110110
* @since 1.1.0
111111
*/
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+
}
137148
}
138149

139150
/**
140151
* Remove the "Comments" and Settings -> Discussion menus from the
141152
* side menu in the dashboard.
142153
*/
143154
function remove_comments_menu_page() {
144-
remove_menu_page('edit-comments.php');
155+
remove_menu_page( 'edit-comments.php' );
145156
remove_submenu_page( 'options-general.php', 'options-discussion.php' );
146157
}
147158

readme.txt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
Contributors: happyprime, jeremyfelt, slocker, philcable, wpgirl369
33
Tags: comments
44
Requires at least: 5.9
5-
Tested up to: 6.0
6-
Stable tag: 1.1.1
5+
Tested up to: 6.1
6+
Stable tag: 1.2.0
77
License: GPLv2 or later
88
Requires PHP: 5.6
99

@@ -27,6 +27,13 @@ If you find something we missed, [please let us know](https://github.com/happypr
2727

2828
## Changelog
2929

30+
### 1.2.0
31+
32+
* Update the list of blocks unregistered to include latest from Gutenberg and WordPress.
33+
* Update `wordpress/scripts` to 24.6.0.
34+
* Refactor how the list of blocks is managed to make future maintenance easier. Props [@huubl](https://profiles.wordpress.org/huubl/).
35+
* Only unregister blocks that are registered. Props [@huubl](https://profiles.wordpress.org/huubl/).
36+
3037
### 1.1.1
3138

3239
* Unregister core comment blocks in the editor.

src/index.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,36 @@
1-
import { unregisterBlockType } from '@wordpress/blocks';
2-
import { getBlockType } from '@wordpress/blocks';
1+
import { getBlockType, unregisterBlockType } from '@wordpress/blocks';
32
import domReady from '@wordpress/dom-ready';
43

54
// Unregister comment-related blocks provided by WordPress core.
65
domReady( () => {
76
const blocks = [
8-
// Blocks that will usually show as available on posts and pages.
9-
'core/latest-comments',
10-
'core/comments-query-loop',
11-
'core/post-comments-form',
7+
'core/comments',
8+
'core/comments-query-loop', // Replaced by core/comments in Gutenberg 13.7.
129

13-
// Blocks used inside the comments query loop block.
10+
'core/comment-author-avatar',
1411
'core/comment-author-name',
1512
'core/comment-content',
1613
'core/comment-date',
1714
'core/comment-edit-link',
1815
'core/comment-reply-link',
1916
'core/comment-template',
17+
2018
'core/comments-pagination',
2119
'core/comments-pagination-next',
2220
'core/comments-pagination-numbers',
2321
'core/comments-pagination-previous',
2422
'core/comments-title',
23+
24+
'core/latest-comments',
25+
26+
'core/post-comment',
2527
'core/post-comments-count',
28+
'core/post-comments-form',
2629
'core/post-comments-link',
2730
];
2831

29-
blocks.forEach( function ( block ) {
30-
if ( getBlockType( block ) ) {
32+
blocks.forEach( ( block ) => {
33+
if ( undefined !== getBlockType( block ) ) {
3134
unregisterBlockType( block );
3235
}
3336
} );

0 commit comments

Comments
 (0)