Limit Gutenberg blocks available to users to choose from

I am using the allowed_block_types_all filter to choose certain blocks the users can choose from. I have just added one here as an example. This works fine but my issue comes in when trying to choose embeds.

add_filter( 'allowed_block_types_all', 'usr_allowed_block_types' );
function usr_allowed_block_types( $allowed_blocks ) {
  return array(
    'core/paragraph',
    'core-embed/twitter'
  );
}

I see the paragraph but not twitter. If I add core/embed then I get ALL embeds which I really don't want.

Solutions

In the functions. php file I added

add_filter( 'allowed_block_types_all', 'func_allowed_block_types' );
function func_allowed_block_types( $allowed_blocks ) {
 
    return array(
        'core/embed'
    );
}

Then in my plugin I added this JS to the javascript file to enable only the embed blocks I wanted (Twitter, youTube and Vimeo)

wp.domReady( function() {
    const allowedEmbedBlocks = [
        'twitter','youtube', 'vimeo'
    ];

    wp.blocks.getBlockType( 'core/embed' ).variations.forEach( function( blockVariation ) {
        if (
            allowedEmbedBlocks.indexOf( blockVariation.name ) === -1
        ) {
            wp.blocks.unregisterBlockVariation( 'core/embed', blockVariation.name );
        }
    } );
} );

Similar questions

Wordpress - customized pages with blocks - prohibit google seo index of blocks
I'm using Wordpress and WooCommerce for my online shop. With the theme I'm using you can customize the product-category pages by adding "blocks". So if I want to have a text on the top of a product category page I simply create a block page, lets say its called "category-info". I can customize this block just as a normal Wordpress page. The block w...
Class cannot be found, but it's available in the file, I get: Fatal Error: Uncaught Error: Class 'Blocks\Base\Activation' not found
Class cannot be found, but the declaration is correct. Here is my code: I use composer, so I can use namespaces. Here is an image of my folder structure: In my opinion, the class Activation should be found and executed, but somehow WordPress can't find it? I have checked the names and copy-pasted them, just to be sure they're the same. I marked lin...
Blocks available in Magento
I'm trying to access magento from wordpress. Here below is the simple code I used to access magento sidebar cart. I'm looking for a full list/documentation of available block codes like "cart_sidebar", "header", etc.,
I can't choose the custom taxonomy in my custom post type on Gutenberg
I'm new here and in Wordpress Development. I have a custom post type that works with a custom taxonomy. In the classic editor, I can choose the category or add new if I want, but when I'm on Gutenberg the option doesn't show it. Thanks]1
Choose tagName group block Gutenberg
I'm learning to use and develop some custom blocks in gutenberg. I was wondering and trying to add my custom section tag block, but then i looked up to the group core block code. Am i right thinking this means ther should be a select that allow you to choose the tag? Also i tried modifing the code in the editor from to And it works! It doesn't brea...
Give users a maximum upload capacity; limit the number of files a user can upload OR limit the number of files per upload
I'm using the Media Library on the front end of my website and I'd like to stop users from being able to spam my server by uploading an unlimited number of files. As such, I'd like to do one or maybe all of the below: None of these are bullet-proof but they'd hopefully make such "spamming" a difficulty. Thanks in advance,

Also ask

We use cookies to deliver the best possible experience on our website. By continuing to use this site, accepting or closing this box, you consent to our use of cookies. To learn more, visit our privacy policy .