Skip to content

Block Bindings: Support innerBlocks bindings on the Group and Column blocks - #15164

Draft
cbravobernal wants to merge 24 commits into
WordPress:trunkfrom
cbravobernal:add/inner-blocks-bindings
Draft

cbravobernal wants to merge 24 commits into
WordPress:trunkfrom
cbravobernal:add/inner-blocks-bindings

Conversation

@cbravobernal

@cbravobernal cbravobernal commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Trac ticket: https://core.trac.wordpress.org/ticket/66415

Lets a block bindings source supply the inner blocks of a Group or Column block through metadata.bindings.innerBlocks. Backports the server part of WordPress/gutenberg#85568. Replaces #12432, which backported an earlier design.

The source returns The block renders
Block markup Those blocks
'' Nothing inside
Anything else Its fallback inner blocks (the ones saved inside it)

How?

It's the same code as Gutenberg, with Core names, in a new wp-includes/block-bindings/inner-blocks.php. It hooks into block_bindings_source_value (last) and render_block. WP_Block doesn't change.

  • The value is sanitized with wp_kses_post(), unless the source returns false from the new block_bindings_sanitize_inner_blocks filter. Custom CSS is always removed.
  • The blocks replace the fallback inner blocks. A block without any gets them before the closing tag of its wrapper, found with WP_HTML_Processor.
  • A binding whose source call is already rendering is skipped, so sources that supply each other's markup can't loop forever. Nested bindings stop at 100 per outermost block.
  • __default pattern overrides bindings never expand to innerBlocks.
  • get_block_bindings_supported_attributes() adds innerBlocks to Group and Column. get_block_editor_settings() removes it for them, as the editor doesn't show these bindings yet.
  • excerpt_remove_blocks() renders the supplied blocks.

Changes since the last review

  • 51631a4: the code moved out of WP_Block into filters. There's no finally anymore, so after a caught exception, a later block with the same source call renders its fallback inner blocks for the rest of the request. The source is now asked for a source call that is already rendering, and its value is ignored.
  • 904d413: helpers used only once are inlined.
  • 94ae302: to keep the patch small, supplied blocks are no longer checked against allowedBlocks, parent and ancestor (saved post content isn't either), the budget filter is gone, and an empty legacy Group gets the blocks after its inner container.
  • ecc82ff: tests placement on markup the HTML API doesn't support, and excerpts with hidden supplied blocks. Removes two checks that never changed the result.

Testing

npm run test:php -- --group block-bindings. innerBlocks.php has the same tests as Gutenberg, plus the excerpt tests.

Use of AI Tools

AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus
Used for: porting the Gutenberg code and tests to Core, and this description. I led the design discussion and reviewed the code. The block bindings group (179 tests) passes locally. Look closely at the placement in _block_bindings_get_inner_content_with_slots() and at _excerpt_render_bound_inner_blocks().

🤖 Generated with Claude Code

@github-actions

This comment has been minimized.

@github-actions

Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

…n blocks.

A block bindings source can now supply the inner blocks of a Group or Column block through `metadata.bindings.innerBlocks`. The value is serialized block markup, which replaces the block's own inner blocks before they render. An empty string leaves the block without inner blocks, and any other value keeps its own.

The markup is sanitized with `wp_kses_post()`, as bound rich text already is, and its custom CSS is removed. Supplied blocks can't bind their own inner blocks, so that sources can't expand each other forever. The editor isn't offered `innerBlocks` yet, as it doesn't render these bindings.

Backports WordPress/gutenberg#85568.

Fixes #66415.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@cbravobernal
cbravobernal force-pushed the add/inner-blocks-bindings branch from e561be2 to 417cff4 Compare October 29, 2026 14:13
cbravobernal and others added 5 commits October 29, 2026 16:09
… has no blocks.

The property is declared as a `WP_Block_List`, so assigning an empty array
fails PHPStan's `assign.propertyType` check.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Bound inner blocks render inside `do_blocks()`, after `WP_Embed` has run its
`[embed]` shortcode on the content, like the synced pattern block does for
its own content.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Moves the explanations into docblocks, and tests that the embeds of the
value survive sanitizing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
cbravobernal and others added 2 commits November 10, 2026 11:51
…g request, and let trusted sources skip kses.

Ports the latest changes of the Gutenberg PR:

- A value is block markup when the first delimiter WP_Block_Processor
  finds, after whitespace-only HTML, opens a block, which matches what
  parse_blocks() reads as a block.
- Instead of removing the innerBlocks bindings of every supplied block,
  a binding is skipped, without asking its source, only while the inner
  blocks a source supplied for the same request render: the same source,
  arguments, and the context the source uses. Sources whose values bind
  each other's, directly or through content that loads as it renders,
  still can't render forever, and nested bindings that ask something
  else resolve.
- The `block_bindings_sanitize_inner_blocks` filter lets a source whose
  markup comes from trusted code keep it as supplied. Custom CSS is
  removed either way.
- The tests no longer assert with regular expressions.

See WordPress/gutenberg#85568.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
cbravobernal and others added 15 commits November 10, 2026 18:39
…value, and key requests by attributes too.

A block whose inner content held only block slots, with no wrapper
markup, crashed when its source supplied no inner blocks: the empty inner
content never reached the block instance, which rendered its old slots
against an empty list of inner blocks. The instance now gets its inner
content and HTML directly.

The request a binding is skipped for also includes the attributes of the
block, since a source may read them, like the pattern overrides source
reads the name of the block.

Co-Authored-By: Claude Mythos 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MCeAiscBeSgrKjrPgYBr1b
…ders a Group unchanged.

Co-Authored-By: Claude Mythos 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MCeAiscBeSgrKjrPgYBr1b
…n, compare requests regardless of key order, and place inner blocks in the last element.

Co-Authored-By: Claude Mythos 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MCeAisD5bTZvgFGutfYV55
…ad of walking the call stack.

`WP_Block::render()` now stops tracking the inner blocks a source supplied in a `finally` block, so a block that stops rendering with an exception is forgotten on the spot. The static method that walked `debug_backtrace()` to find such blocks on the next binding is gone. The exception test covers the new path: without the `finally`, it fails.

Co-Authored-By: Claude Mythos 5.1 <noreply@anthropic.com>
…up and Column blocks.

`get_block_editor_settings()` removed `innerBlocks` from every block type, so a block that added it through `block_bindings_supported_attributes` lost it in the editor. It now touches only the two block types Core adds the attribute to. A test registers such a block and checks that the editor still offers it.

Co-Authored-By: Claude Mythos 5.1 <noreply@anthropic.com>
…tead of a regex handler.

The embed test registered an embed handler with a regular expression. The `[embed]` shortcode and the bare URL both reach `wp_oembed_get()`, whose `pre_oembed_result` filter returns the test iframe before any provider lookup, so the test no longer needs one.

Co-Authored-By: Claude Mythos 5.1 <noreply@anthropic.com>
…accept.

A top-level supplied block fails when the bound block's `allowedBlocks` (block type or attribute) leaves it out, or when its own `parent` or `ancestor` leaves out the bound block. One failure rejects the whole value and the fallback inner blocks render. Nested blocks aren't checked.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nd block.

Same budget as Gutenberg: the `block_bindings_inner_blocks_budget` filter, 100 by default. It resets at the outermost bound block and counts every bound block that gets inner blocks below it. Once it's spent, the block keeps its own inner blocks.

Without it, a value whose bindings ask for it again with other arguments renders once for every order they can nest in.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`excerpt_remove_blocks()` renders a block bound for `innerBlocks` as on the front end, so the binding resolves with the same sanitizing and loop checks. Blocks the excerpt doesn't allow render nothing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…get.

A value the allowed blocks check rejects doesn't count against `block_bindings_inner_blocks_budget`, so a later allowed value at the same budget still renders.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…llowed blocks check.

The allowed blocks check skipped every supplied chunk without a block name, so a bound block with `allowedBlocks` rendered loose HTML it would reject as a block. HTML outside any block now counts as `core/freeform`, unless it is only whitespace.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A source can return other inner blocks for another block type, so two block types with the same binding and attributes are no longer the same request. Also tests that a `block_bindings_source_value` filter with the default priority can change the supplied inner blocks.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The code now lives in wp-includes/block-bindings/inner-blocks.php, the same functions as Gutenberg with Core names. It replaces the inner blocks on `block_bindings_source_value`, after the other callbacks, and stops tracking them on `render_block`. `WP_Block` is the same as on trunk.

A source call that is already rendering is still asked, and its value is ignored. The tests now match Gutenberg's, plus the excerpt tests.

See #66415.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The source call and the check against the source calls rendering move into _block_bindings_replace_inner_blocks(), and finding the wrapper closer moves into _block_bindings_split_at_wrapper_closer(). Same change as in Gutenberg.

See #66415.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Drop the allowedBlocks, parent and ancestor check (saved post content isn't checked either), the block_bindings_inner_blocks_budget filter (the budget stays at 100), and the special case for empty legacy Groups. Same change as in Gutenberg.

See #66415.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…es not support.

Also tests that excerpts leave out hidden blocks the source supplies, and removes two checks that never change the result: the null check after `WP_HTML_Processor::create_fragment()`, and the `blockVisibility` check in the excerpt filter, since `render_block()` already renders hidden blocks as nothing.

See #66415.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant