admin管理员组文章数量:1278985
I have installed and want to provide only OpenStreetMap based blocks (which I installed additionally) and remove the coblocks/map
block.
add_filter( 'allowed_block_types_all', 'myplugin_allowed_block_types', 0 );
function myplugin_allowed_block_types( $allowed_blocks )
{
$block_types = WP_Block_Type_Registry::get_instance()->get_all_registered();
if (!isset($block_types['coblocks/map'])) {
wp_die('Block not found to unset');
}
unset($block_types['coblocks/map']);
return array_keys($block_types);
}
This dies with Block not found to unset
Actually the code works without that check, but I am wondering if there are other blocks which are not in the registry but still work and would be disabled with my code.
So essentially I am asking why get_all_registered
does not have some blocks which are still there and how I can remove only specific blocks if I can not reliably fetch a list of all blocks.
I have installed https://github/godaddy-wordpress/coblocks and want to provide only OpenStreetMap based blocks (which I installed additionally) and remove the coblocks/map
block.
add_filter( 'allowed_block_types_all', 'myplugin_allowed_block_types', 0 );
function myplugin_allowed_block_types( $allowed_blocks )
{
$block_types = WP_Block_Type_Registry::get_instance()->get_all_registered();
if (!isset($block_types['coblocks/map'])) {
wp_die('Block not found to unset');
}
unset($block_types['coblocks/map']);
return array_keys($block_types);
}
This dies with Block not found to unset
Actually the code works without that check, but I am wondering if there are other blocks which are not in the registry but still work and would be disabled with my code.
So essentially I am asking why get_all_registered
does not have some blocks which are still there and how I can remove only specific blocks if I can not reliably fetch a list of all blocks.
1 Answer
Reset to default 2You'll want to target the block specifically via javascript. Brief example:
wp.domReady(function() {
wp.blocks.unregisterBlockType( 'coblocks/map' );
});
Save that to a js file and enqueue it via your custom function: add_action('enqueue_block_editor_assets', 'your_custom_enqueue_fucntion')
本文标签: Disable only one Gutenberg block programaticallycoblockmaps not listed in blocks
版权声明:本文标题:Disable only one Gutenberg block programaticallycoblockmaps not listed in blocks 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741241276a2364026.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
inserter
is set tofalse
in its supports section – Tom J Nowell ♦ Commented Oct 12, 2021 at 15:27wp_die
, this might kill other block based areas or post types e.g. the widget block areas – Tom J Nowell ♦ Commented Oct 12, 2021 at 15:28