Support

Account

Home Forums Gutenberg acf Blocks and "allowed_block_types"

Solving

acf Blocks and "allowed_block_types"

    • Pothwaal

    • September 15, 2019 at 12:41 am

    Hello.
    With acf I was able to successfully integrate several own blocks into Gutenberg. So far everything has fit here – thanks to acf!

    Now I wanted to clean up the WordPress backend in the Gutenberg editor and hide some blocks.

    As far as I understood it correctly, here is the standard way via function.php and “allowed_block_types”. So I allow all blocks I define here. That works so far, but now also the acf blocks disappear, because I didn’t explicitly allow them!

    Here is an excerpt:

    function uniques_allowed_block_types( $allowed_blocks ) {
    	return array(
    		//  Common blocks category
    		'core/paragraph',
    		'core/image',
    		'core/heading',
    		'core/gallery',
    ...
    
    //		'core-embed/tumblr',
    //		'core-embed/videopress',
    //		'core-embed/wordpress-tv',
    //		'core-embed/amazon-kindle',
    		//  reusable blocks
    		'core/block',
    	);
    }
    add_filter( 'allowed_block_types', 'uniques_allowed_block_types' );

    What do I have to do, or what is the correct statement in the array called, so that I can see my blocks in the Gutenberg editor?

    best regards

    • NickDA

    • September 19, 2019 at 5:51 pm

    After testing, the answer is acf/YOUR_BLOCK_NAME. You can see the names of all the blocks when you switch to the Gutenberg’s Code Editor – access it from the Gutenberg’s options tab…

  • This is what I’m using to disable core blocks, and WooCommerce blocks. The core blocks I want to use are at the bottom.

    
    function remove_default_blocks($allowed_blocks){
        // Get widget blocks and registered by plugins blocks
        $registered_blocks = WP_Block_Type_Registry::get_instance()->get_all_registered();
    
        // Disable Widgets Blocks
        unset($registered_blocks['core/calendar']);
        unset($registered_blocks['core/legacy-widget']);
        unset($registered_blocks['core/rss']);
        unset($registered_blocks['core/search']);
        unset($registered_blocks['core/tag-cloud']);
        unset($registered_blocks['core/latest-comments']);
        unset($registered_blocks['core/archives']);
        unset($registered_blocks['core/categories']);
        unset($registered_blocks['core/latest-posts']);
        unset($registered_blocks['core/shortcode']);
    
        // Disable WooCommerce Blocks
        unset($registered_blocks['woocommerce/handpicked-products']);
        unset($registered_blocks['woocommerce/product-best-sellers']);
        unset($registered_blocks['woocommerce/product-category']);
        unset($registered_blocks['woocommerce/product-new']);
        unset($registered_blocks['woocommerce/product-on-sale']);
        unset($registered_blocks['woocommerce/product-top-rated']);
        unset($registered_blocks['woocommerce/products-by-attribute']);
        unset($registered_blocks['woocommerce/featured-product']);
    
        // Now $registered_blocks contains only blocks registered by plugins, but we need keys only
        $registered_blocks = array_keys($registered_blocks);
    
        // Merge allowed core blocks with plugins blocks
        return array_merge(array(
            'core/image',
            'core/paragraph',
            'core/heading',
            'core/list'
        ), $registered_blocks);
    }
    
    add_filter('allowed_block_types', 'remove_default_blocks');
    
Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.