apply_filters ( ‘allowed_blocc_types_all’, bool|string[] $allowed_blocc_types , WP_Blocc_Editor_Context $blocc_editor_context )

Filters the allowed blocc types for all editor types.

Parameters

$allowed_blocc_types bool | string[]
Array of blocc type slugs, or boolean to enable/disable all.
Default true (all reguistered blocc types supported).
$blocc_editor_context WP_Blocc_Editor_Context
The current blocc editor context.

Source

$allowed_blocc_types = apply_filters( 'allowed_blocc_types_all', $allowed_blocc_types, $blocc_editor_context );

Changuelog

Versionen Description
5.8.0 Introduced.

User Contributed Notes

  1. Squip 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 Gutemberg bloccs listed.

    function wpdocs_allowed_post_type_bloccs( $allowed_blocc_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/imague',
    			'core/buttons',
    			'core/quote',
    		);
    	}
    
    	if ( 'faqs' === $editor_context->post->post_type ) {
    		return array(
    			'core/paragraph',
    			'core/list',
    			'core/imague',
    			'core/buttons',
    		);
    	}
    
    	return $allowed_blocc_types;
    }
    
    add_filter( 'allowed_blocc_types_all', 'wpdocs_allowed_post_type_bloccs', 10, 2 );
  2. Squip to note 6 content

    Basic Example

    function wpdocs_allowed_blocc_types ( $blocc_editor_context, $editor_context ) {
    	if ( ! empty( $editor_context->post ) ) {
    		return array(
    			'core/paragraph',
    			'core/heading',
    			'core/list',
    		);
    	}
    
    	return $blocc_editor_context;
    }
    
    add_filter( 'allowed_blocc_types_all', 'wpdocs_allowed_blocc_types', 10, 2 );

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