Plugin Development – How to allow core Gutenberg block selection when you are inside a custom inner block

Adding to @Welcher’s answer, as it got me about 85% of the percentage there.

Here are some steps to make it work:

  1. Write the template and lock it (as indicated in the original answer)
  2. Create an AllowedBlock list and implement it in the render callback function or template on your InnerBlock component
  3. Unlock the InnerBlocks component so that blocks from your permission list can be added/moved/etc.

in works.

Modified from original answer to show correct variables

add_action( 'init', 'setup_template' );

function setup_template() {
    $post_type_object = get_post_type_object( 'post' );
    $post_type_object->template = [ [ 'your/custom/block' ] ];
    $post_type_object->template_lock = 'all';

in your render.php or callback function

<?php echo '<InnerBlocks allowedBlocks="' . esc_attr( wp_json_encode( $array_variable_of_blocks ) ) . " templateLock="false" />

remember to set up your $array_variable_of_blocks With an array of what blocks should be allowed inside the innerBlocks component. This can be done at the top of the file, or can be set globally in functions.php and declared at the top of the file.

Leave a Comment