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_typesbool|string[]
Array of block type slugs, or boolean to enable/disable all.
Default true (all registered block types supported).
$block_editor_contextWP_Block_Editor_Context
The current block editor context.

Source

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

Changelog

VersionDescription
5.8.0Introduced.

User Contributed Notes

  1. Skip to note 4 content

    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 $allowed_block_types;
    }
    
    add_filter( 'allowed_block_types_all', 'wpdocs_allowed_post_type_blocks', 10, 2 );
  2. Skip to note 6 content

    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 );

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