close
Skip to content

Feature : Recursive allowedBlocks rule in InnerBlocks#74581

Open
Vrishabhsk wants to merge 3 commits intoWordPress:trunkfrom
Vrishabhsk:add/recursive-allowedBlocks
Open

Feature : Recursive allowedBlocks rule in InnerBlocks#74581
Vrishabhsk wants to merge 3 commits intoWordPress:trunkfrom
Vrishabhsk:add/recursive-allowedBlocks

Conversation

@Vrishabhsk
Copy link
Copy Markdown
Contributor

@Vrishabhsk Vrishabhsk commented Jan 13, 2026

What?

Why?

  • Reduces effort to define allowedBlocks for each nested block in an InnerBlock by inheriting parent's rule.
  • Allows wider restriction on block usage with minimal effort.

How?

  • New boolean attribute for InnerBlocks : inheritAllowedBlocks
  • When added as true, the canInsertBlockTypeUnmemoized function checks if the block is to be allowed or not.
  • The function calls the new getInheritedAllowedBlocks function internally to verify the parent-child relation.
  • The block is then visible / hidden based on that.

Testing Instructions

  1. Create a block that uses InnerBlock
  2. Set the allowedBlocks to the following
const ALLOWED_BLOCKS = [
	'core/heading',
	'core/group'
];

<InnerBlocks
	allowedBlocks={ ALLOWED_BLOCKS }
	template={ [
		[ 'core/paragraph', {
			placeholder: __( 'Add content here. Only allowed blocks can be inserted...', 'inherit-allowed-blocks-demo' )
		} ],
	] }
	renderAppender={ InnerBlocks.ButtonBlockAppender }
/>
  1. Use the block in the editor, and add a Group block, select the orientation, then you can add Paragraph element
  2. Modify the InnerBlocks as follows:
<InnerBlocks
	allowedBlocks={ ALLOWED_BLOCKS }
	template={ [
		[ 'core/paragraph', {
			placeholder: __( 'Add content here. Only allowed blocks can be inserted...', 'inherit-allowed-blocks-demo' )
		} ],
	] }
        inheritAllowedBlocks={ true }
	renderAppender={ InnerBlocks.ButtonBlockAppender }
/>
  1. Follow the step 3 again and now you won't be able to add Paragraph element within the Group block.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Jan 13, 2026

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: Vrishabhsk <vrishabhsk@git.wordpress.org>
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
Co-authored-by: eric-michel <ytfeldrawkcab@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@Mamaduka
Copy link
Copy Markdown
Member

Thanks for contributing, @Vrishabhsk!

Is there a corresponding issue on this repo for this request? I would also recommend avoiding linking private issues here.

@Vrishabhsk
Copy link
Copy Markdown
Contributor Author

Oh my bad @Mamaduka. Completely overlooked by me.

Here's the original issue : #72803

@Mamaduka Mamaduka added [Type] Enhancement A suggestion for improvement. [Feature] Block API API that allows to express the block paradigm. labels Jan 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Feature] Block API API that allows to express the block paradigm. [Package] Block editor /packages/block-editor [Type] Enhancement A suggestion for improvement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Option to make AllowedBlocks setting recursive

2 participants