Skip to content

Commit e58e6a7

Browse files
authored
Merge pull request #145 from 10up/fix/block-allow-list-examples
2 parents 26db8d4 + 290ea84 commit e58e6a7

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

reference/03-Blocks/unregister-block.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ sidebar_position: 10
88
* [unregisterBlockType](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-blocks/#unregisterblocktype)
99

1010
## Unregister Use Case:
11-
Gutenberg comes with a lot of core blocks and this can be overwhelming for certain editors. Due to this situations arise where it is necessary to disable some blocks so that an editor can not access them when creating new pages and posts. Removing certain blocks can aid these editors by reducing cognitive load and confusion. This can be done using the `unregisterBlockType` function and passing in the blocks which should be disallowed within a `.js` file.
11+
Gutenberg comes with a lot of core blocks and this can be overwhelming for certain editors. Due to this situations arise where it is necessary to disable some blocks so that an editor can not access them when creating new pages and posts. Removing certain blocks can aid these editors by reducing cognitive load and confusion. This can be done using the `unregisterBlockType` function and passing in the blocks which should be disallowed within a `.js` file.
1212

1313
## Code Example:
14-
This example showcases how an array of blocks can be passed into a single function and looped through to disable multiple blocks at the same time.
14+
This example showcases how an array of blocks can be passed into a single function and looped through to disable multiple blocks at the same time.
1515

1616
`block-filters/unregister-blocks.js`
1717
```js
@@ -32,7 +32,7 @@ const disallowedBlocks = [
3232

3333
domReady(() => {
3434
const blocks = getBlockTypes();
35-
blocks.forEach(({ name }) {
35+
blocks.forEach(({ name }) => {
3636
if (disallowedBlocks.includes(name)) {
3737
unregisterBlockType(name);
3838
}
@@ -53,15 +53,15 @@ const allowedEmbedBlocks = ['vimeo', 'youtube'];
5353
domReady(() => {
5454
const embedVariations = getBlockVariations('core/embed');
5555
embedVariations.forEach(({name}) => {
56-
if (allowedEmbedBlocks.includes(name)) {
56+
if (!allowedEmbedBlocks.includes(name)) {
5757
unregisterBlockVariation('core/embed', name);
5858
}
5959
});
6060
});
6161
```
6262

6363
## Allow List:
64-
Opposite to the approach of `unregisterBlockType` would be to create a PHP allow list. In this scenario a developer would curate the specific blocks that they want to have shown to an editor. In these situations it is advised to always include common utility blocks such as: `core/block`, `core/missing`, `core/pattern`, `core/template-part` to prevent issues with the block editor.
64+
Opposite to the approach of `unregisterBlockType` would be to create a PHP allow list. In this scenario a developer would curate the specific blocks that they want to have shown to an editor. In these situations it is advised to always include common utility blocks such as: `core/block`, `core/missing`, `core/pattern`, `core/template-part` to prevent issues with the block editor.
6565

6666
:::caution
6767
When using an allow list it is advised to review WordPress releases for any changes in existing blocks. As an example WordPress 6.1 refactored the list block from one singular block to an inner blocks structure with a list item. Anyone that used an allow list at that point needed to go in and update it to include the core/list-item block.

0 commit comments

Comments
 (0)