I’m writing a function to allow only some custom blocks – essentially I want to register all the blocks, then based on a database table of ‘selected’ blocks disallow any other custom block.
I can use allowed_block_types
to make an array of allowed blocks, but it wipes all the core ones, is there a way to either get a reliable list of core blocks, or only add a filter for plugin/theme registered blocks? Or possibly, allow all block
categories then my own block category is filtered?
4 s
AFAIK there is only one way to remove blocks from Gutenberg – you have to use allowed_block_types
filter.
Unfortunately Gutenberg developers are not very familiar with WordPress hooks and filters, so they created a little monster with this one. So instead of passing a list of core blocks in there, they pass true
to enable all blocks. That way you’re unable to obtain the list of all blocks registered.
So if you want to disable just one block, then you have to get all blocks bu yourself…
Here’s the list of core blocks:
- core/shortcode
- core/image
- core/gallery
- core/heading
- core/quote
- core/embed
- core/list
- core/separator
- core/more
- core/button
- core/pullquote
- core/table
- core/preformatted
- core/code
- core/html
- core/freeform
- core/latest-posts
- core/categories
- core/cover (previously
core/cover-image
) - core/text-columns
- core/verse
- core/video
- core/audio
- core/block
-
core/paragraph
-
core-embed/twitter
- core-embed/youtube
- core-embed/facebook
- core-embed/instagram
- core-embed/wordpress
- core-embed/soundcloud
- core-embed/spotify
- core-embed/flickr
- core-embed/vimeo
- core-embed/animoto
- core-embed/cloudup
- core-embed/collegehumor
- core-embed/dailymotion
- core-embed/funnyordie
- core-embed/hulu
- core-embed/imgur
- core-embed/issuu
- core-embed/kickstarter
- core-embed/meetup-com
- core-embed/mixcloud
- core-embed/photobucket
- core-embed/polldaddy
- core-embed/reddit
- core-embed/reverbnation
- core-embed/screencast
- core-embed/scribd
- core-embed/slideshare
- core-embed/smugmug
- core-embed/speaker
- core-embed/ted
- core-embed/tumblr
- core-embed/videopress
- core-embed/wordpress-tv
On the other hand…
It’s a lot easier to unregister given block in JS… In there you can use:
wp.blocks.unregisterBlockType( 'core/verse' );