Filters the allowed block types for the editor.
Parameters
$allowed_block_types
bool|string[]- Array of block type slugs, or boolean to enable/disable all.
Default true (all registered block types supported) $post
WP_Post- The post resource data.
Source
$allowed_block_types = apply_filters_deprecated( 'allowed_block_types', array( $allowed_block_types, $post ), '5.8.0', 'allowed_block_types_all' );
Changelog
Version | Description |
---|---|
5.8.0 | Use the 'allowed_block_types_all' filter instead. |
5.0.0 | Introduced. |
It would appear that as of WordPress 5.6 the
core-embed/*
blocks have all been replaced with Variations so this functionality now no longer works for all the various Embed “blocks”.When filtering for allowed block types, return the boolean for the post types you are not restricting. Otherwise, it won’t work as Nilambar’s example because
$allowed_block_types
is expecting an array or a boolean.This worked for me when filtering allowed blocks for a custom post type. You’ll want to substitute ‘myplugin’ with your namespace and the post types you’re filtering in the switch statement.
$allowed_block_types
to true no matter if someone else has used this hook to allow or forbid block-types for any other post-types. Returning the current value of$allowed_block_types
is the better option because when no one has ever used this hook,$allowed_block_types
will be true by default. If someone has used it$allowed_block_types
will be true, false or an array. Second of all the return statement in line 14 is unreachable and therefore unnecessary.This allows only paragraph block for post.