Skip to content

[Block-API] Add Support for Limiting Block Usage Within Parent#70103

Open
sarthaknagoshe2002 wants to merge 1 commit intoWordPress:trunkfrom
sarthaknagoshe2002:block-api/uniquewithin
Open

[Block-API] Add Support for Limiting Block Usage Within Parent#70103
sarthaknagoshe2002 wants to merge 1 commit intoWordPress:trunkfrom
sarthaknagoshe2002:block-api/uniquewithin

Conversation

@sarthaknagoshe2002
Copy link
Copy Markdown
Contributor

@sarthaknagoshe2002 sarthaknagoshe2002 commented May 12, 2025

What?

Introduces the ability to Limit Block Usage Within Parent, allowing a block (e.g., a "Login" button) to appear only once within the parent block.
Closes #38958

Why?

WordPress currently supports limiting a block’s usage to once per post/page via supports: { multiple: false }. But this limitation is too broad for nuanced layout structures. This enhancement allows greater design flexibility and cleaner content authoring by preventing UI redundancy within defined structural boundaries.

Example Use Case

  • You have multiple Navigation blocks on a page (e.g., header and footer).
  • You want to only allow one "Login" block per Navigation, not per page.
  • With this feature, you can enforce that constraint per context, avoiding duplicate actions in a single section.

How?

  • Add a new meta uniqueWithin which can be set to true or false.
  • Prevent redundant insertion, dragging & duplication of block if it already exists in a parent.

Testing Instructions

  1. Register a test block with uniqueWithin: true.
  2. Add two Navigation blocks to a post/page.
  3. Try inserting the limited block into both — it should work once per Navigation.
  4. Try inserting a second one in the same Navigation.

@github-actions
Copy link
Copy Markdown

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: sarthaknagoshe2002 <sarthaknagoshe2002@git.wordpress.org>
Co-authored-by: luisherranz <luisherranz@git.wordpress.org>
Co-authored-by: fabiankaegy <fabiankaegy@git.wordpress.org>

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

@t-hamano t-hamano added [Feature] Block API API that allows to express the block paradigm. [Feature] Nested / Inner Blocks Anything related to the experience of nested/inner blocks inside a larger container, like Group or P [Type] New API New API to be used by plugin developers or package users. labels May 13, 2025
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. [Feature] Nested / Inner Blocks Anything related to the experience of nested/inner blocks inside a larger container, like Group or P [Type] New API New API to be used by plugin developers or package users.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add ability to restrict block to only be used once within inner blocks area

2 participants