restrict core blocks to inner blocks of specified parent blocks. blocks blocks blocks

This commit is contained in:
2025-12-09 22:40:44 +00:00
parent 7d1beee2da
commit b16bd77355
7 changed files with 260 additions and 131 deletions

View File

@@ -19,13 +19,44 @@ add_filter( 'block_categories_all' , function ( $categories ) {
return $categories;
});
// add_action('init', function () {
// $blocks = glob(get_theme_file_path('resources/blocks/*/block.json'));
// foreach ($blocks as $block_json) {
// register_block_type($block_json, [
// 'render_callback' => function ($attributes, $content, $block) {
// $slug = basename($block->name);
// $view = "blocks.{$slug}.render";
// if (\Roots\view()->exists($view)) {
// return \Roots\view($view, [
// 'attributes' => $attributes,
// 'content' => $content,
// 'block' => $block,
// ]);
// }
// return $content;
// }
// ]);
// }
// });
add_action('allowed_block_types_all', function(){
$blocks = block_all();
$blacklist = array_diff($blocks, block_whitelist());
$blocks = array_keys( \WP_Block_Type_Registry::get_instance()->get_all_registered() );
$blacklist = array_diff(block_blacklist(), block_whitelist());
return array_values( array_diff( $blocks, $blacklist ) );
}, 100, 2);
function block_blacklist()
{
$file = file_get_contents(get_theme_file_path("resources/json/core-block-blacklist.json"));
$json = json_decode($file);
return $json;
}
function block_whitelist()
{
$file = file_get_contents(get_theme_file_path("resources/json/core-block-whitelist.json"));