allowed_block_types
最后更新于:2021-11-25 19:59:33
apply_filters_deprecated( ‘allowed_block_types’, bool|array $allowed_block_types, GC_Post $post )
Filters the allowed block types for the editor.
参数
- $allowed_block_types
-
(bool|array)
Array of block type slugs, or boolean to enable/disable all. Default true (all registered block types supported) - $post
-
(GC_Post)
The post resource data.
源文件
文件: gc-includes/block-editor.php
function myplugin_allowed_block_types( $allowed_block_types, $post ) { switch( $post->post_type ) { case 'my_cpt_1': return array( 'core/paragraph' ); break; case 'my_cpt_2': return array( 'core/paragraph', 'core/heading' ); break; default: return true; } return $allowed_block_types; } add_filter( 'allowed_block_types', 'myplugin_allowed_block_types', 10, 2 );