apply_filters( 'allowed_block_types_all', bool|string[] $allowed_block_types, WP_Block_Editor_Context $block_editor_context )

Filters the allowed block types for all editor types.


Parameters

$allowed_block_types bool|string[]
Array of block type slugs, or boolean to enable/disable all.
Default true (all registered block types supported).
$block_editor_context WP_Block_Editor_Context
The current block editor context.

Top ↑

Source

File: wp-includes/block-editor.php. View all references

$allowed_block_types = apply_filters( 'allowed_block_types_all', $allowed_block_types, $block_editor_context );


Top ↑

Changelog

Changelog
Version Description
5.8.0 Introduced.

Top ↑

User Contributed Notes

  1. Skip to note 2 content
    Contributed by thejaydip

    Basic Example

    function wpdocs_allowed_block_types ( $block_editor_context, $editor_context ) {
    	if ( ! empty( $editor_context->post ) ) {
    		return array(
    			'core/paragraph',
    			'core/heading',
    			'core/list',
    		);
    	}
    
    	return $block_editor_context;
    }
    
    add_filter( 'allowed_block_types_all', 'wpdocs_allowed_block_types', 10, 2 );
  2. Skip to note 3 content
    Contributed by xandercalvert

    How it can be used to filter for multiple post types in the same function. This filters the custom post types of ‘sponsors’, ‘news’ and ‘faqs’ to only allow the core Gutenberg blocks listed.

    function wpdocs_allowed_post_type_blocks( $allowed_block_types, $editor_context ) {
    	if ( 'sponsors' === $editor_context->post->post_type ) {
    		return array(
    			'core/paragraph',
    		);
    	}
    
    	if ( 'news' === $editor_context->post->post_type ) {
    		return array(
    			'core/paragraph',
    			'core/list',
    			'core/image',
    			'core/buttons',
    			'core/quote',
    		);
    	}
    
    	if ( 'faqs' === $editor_context->post->post_type ) {
    		return array(
    			'core/paragraph',
    			'core/list',
    			'core/image',
    			'core/buttons',
    		);
    	}
    
    	return $blocks;
    }
    
    add_filter( 'allowed_block_types_all', 'wpdocs_allowed_post_type_blocks', 10, 2 );

You must log in before being able to contribute a note or feedback.