Open ddryo opened 3 years ago
Hey there! Thanks for opening this issue. In case it's helpful, you might find this plugin easier to use to manage various blocks in the meantime globally: https://wordpress.org/plugins/block-manager/ You could also use the built in Block Manager to hide these blocks.
@annezazu
Thank you very much. However, I want to force the FSE block to be turned off on a theme I sell, not on my own site. So, installing a plugin is not a desirable solution.
The only way to do this is to use the 'allowed_block_types_all' hook. Is there any good way to avoid using this hook?
I have stubmled upon this on my blog as well using the Go theme
even though the search in the block directory happens as shown by the console:
https://.../wp-json/wp/v2/block-directory/search?term=team&_locale=user
shows:
[{
"name": "block\/team-member",
"title": "Team Member",
"description": "Present your team members beautifully & gain instant credibility.",
"id": "team-member-block",
...
}
}, {
"name": "straightvisions\/twitch-stream",
...
}]
Ah ha thank you for clarifying @ddryo - I'm going to leave this issue open as this seems to be something to address. cc @ryelle in case she has thoughts as someone who worked on the block directory implementation.
This isn't inherently a problem with the block directory - the issue is that when you set the allowed blocks list to a list of blocks, it's assumed that you only want those blocks so anything that doesn't match, including from the block directory, is filtered out.
If it is difficult to solve this problem, I would like to see a hook added that allows you to specify 'disallowed blocks' instead of 'allowed blocks'.
I agree that this would be a better solution for disabling specific blocks.
The following code solved the problem I am personally having.
import { addFilter } from '@wordpress/hooks';
addFilter('blocks.registerBlockType', 'my-theme/filter-blocks', function (settings, name) {
const fseBlocks = [
'core/loginout',
'core/page-list',
'core/post-content',
'core/post-date',
'core/post-excerpt',
'core/post-featured-image',
'core/post-terms',
'core/post-title',
'core/post-template',
'core/query-loop',
'core/query',
'core/query-pagination',
'core/query-pagination-next',
'core/query-pagination-numbers',
'core/query-pagination-previous',
'core/query-title',
'core/site-logo',
'core/site-title',
'core/site-tagline',
];
if (-1 !== fseBlocks.indexOf(name)) {
return {};
}
return settings;
});
By changing to the above code instead of using 'allowed_block_types_all'
, I was able to successfully turn off certain blocks but keep the search from the block directory enabled.
However, I think it would be useful to have a hook to specify the "disallowed blocks", so I will leave the issue open.
Is there an existing issue for this?
Have you tried deactivating all plugins except Gutenberg?
Have you tried replicating the bug using a default theme e.g. Twenty Twenty?
Description
Using the
'allowed_block_types_all'
hook will prevent searching from the Block Directory when searching for blocks.The reason we are using the
'allowed_block_types_all'
hook is that we want to turn off the block for full site editing, which was added in 5.8.If it is difficult to solve this problem, I would like to see a hook added that allows you to specify 'disallowed blocks' instead of 'allowed blocks'.
Translated with www.DeepL.com/Translator (free version)
Step-by-step reproduction instructions
Expected Behavior
Current Behavior
Screenshots or screen recording (optional)
No response
Code snippet (optional)
No response
WordPress Information
No response
Gutenberg Information
No response
What browsers are you seeing the problem on?
No response
Device Information
No response
Operating System Information
No response