You can add a custom script to the admin panel using the admin_enqueue_scripts
action.
Here is an example of how you can restrict existing blocks to only be included inside certain blocks:
const restrictEditorParentBlocks = (settings, name) => {
const TEXT_EDITOR_BLOCKS = [
'core/heading',
'core/image',
'core/list',
'core/paragraph',
'core/shortcode',
'core/embed',
];
if (TEXT_EDITOR_BLOCKS.includes(name)) {
settings.parent = ['example/my-custom-block-that-needs-text-editor-blocks']
}
console.log(settings, name)
return settings
}
wp.hooks.addFilter(
'blocks.registerBlockType',
'your-project-name/restrict-parent-blocks',
restrictEditorParentBlocks
);
This will disable them for the page, but allow them inside the specified parent blocks.
(see settings.parent
assignment)