Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
417cff4
Block Bindings: Support `innerBlocks` bindings on the Group and Colum…
cbravobernal Oct 29, 2026
818d554
Block Bindings: Keep `$inner_blocks` a `WP_Block_List` when a binding…
cbravobernal Oct 29, 2026
253c907
Block Bindings: Render `[embed]` shortcodes in bound inner blocks.
cbravobernal Oct 29, 2026
9200865
Block Bindings: Split the inner blocks bindings into named methods.
cbravobernal Oct 30, 2026
14c554d
Block Bindings: Use block comments in the inner blocks bindings tests.
cbravobernal Oct 30, 2026
c7e2952
Block Bindings: Remove inline comments from the inner blocks bindings…
cbravobernal Oct 30, 2026
a3771cc
Merge remote-tracking branch 'origin/trunk' into add/inner-blocks-bin…
cbravobernal Nov 10, 2026
d4819c0
Block Bindings: Skip only innerBlocks bindings that repeat a renderin…
cbravobernal Nov 10, 2026
cc235e1
Block Bindings: Keep inner blocks bindings from crashing on an empty …
cbravobernal Nov 10, 2026
fba872e
Block Bindings: Assert that the default pattern overrides binding ren…
cbravobernal Nov 10, 2026
0d3ce3a
Block Bindings: Forget blocks that stopped rendering with an exceptio…
cbravobernal Nov 11, 2026
1159d28
Block Bindings: Forget supplied inner blocks in a finally block inste…
cbravobernal Nov 11, 2026
d011bed
Block Bindings: Keep `innerBlocks` out of the editor only for the Gro…
cbravobernal Nov 11, 2026
d5155c3
Block Bindings: Supply the test embed through `pre_oembed_result` ins…
cbravobernal Nov 11, 2026
3664fd1
Block Bindings: Reject supplied inner blocks the bound block doesn't …
cbravobernal Nov 22, 2026
0d3af1a
Block Bindings: Limit how many blocks get inner blocks inside one bou…
cbravobernal Nov 23, 2026
3823482
Block Bindings: Show the supplied inner blocks in automatic excerpts.
cbravobernal Nov 22, 2026
ea65b90
Block Bindings: Test that a rejected value spends no inner blocks bud…
cbravobernal Nov 26, 2026
afbe803
Block Bindings: Count HTML outside blocks as a Classic block in the a…
cbravobernal Nov 27, 2026
09eff41
Block Bindings: Key inner blocks requests by block name too.
cbravobernal Nov 28, 2026
51631a4
Block Bindings: Move inner blocks bindings out of WP_Block into filters.
cbravobernal Nov 29, 2026
904d413
Block Bindings: Inline the inner blocks helpers used only once.
cbravobernal Nov 29, 2026
94ae302
Block Bindings: Make inner blocks bindings smaller.
cbravobernal Nov 29, 2026
ecc82ff
Block Bindings: Test inner blocks placement on markup the HTML API do…
cbravobernal Nov 29, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/wp-includes/block-bindings.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ function get_block_bindings_source( string $source_name ) {
* @since 6.9.0
* @since 7.1.0 Added support for the List Item block.
* @since 7.2.0 Added support for the Icon block.
* @since 7.3.0 Added support for the inner blocks of the Group and Column blocks.
*
* @param string $block_type The block type whose supported attributes are being retrieved.
* @return array The list of block attributes that are supported by block bindings.
Expand All @@ -153,6 +154,8 @@ function get_block_bindings_supported_attributes( $block_type ) {
'core/navigation-link' => array( 'url' ),
'core/navigation-submenu' => array( 'url' ),
'core/icon' => array( 'icon' ),
'core/group' => array( 'innerBlocks' ),
'core/column' => array( 'innerBlocks' ),
);

$supported_block_attributes =
Expand Down
274 changes: 274 additions & 0 deletions src/wp-includes/block-bindings/inner-blocks.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,274 @@
<?php
/**
* Inner blocks bindings: a block bindings source supplies the inner blocks of a
* block, through `metadata.bindings.innerBlocks`.
*
* Block markup replaces the fallback inner blocks, the ones saved inside the
* block. An empty string leaves the block empty. Any other value renders the
* fallback inner blocks. The Group and Column blocks support it, through
* `get_block_bindings_supported_attributes()`, and other blocks opt in through
* the `block_bindings_supported_attributes` filter.
*
* @since 7.3.0
* @package WordPress
* @subpackage Block Bindings
*/

/**
* Determines whether a source value supplies inner blocks: an empty string, or
* markup whose first block delimiter, after any whitespace, opens a block.
*
* @since 7.3.0
* @access private
*
* @param mixed $value The value of the source.
* @return bool Whether the value supplies inner blocks.
*/
function _block_bindings_is_inner_blocks_value( $value ) {
if ( '' === $value ) {
return true;
}
if ( ! is_string( $value ) ) {
return false;
}

$processor = new WP_Block_Processor( $value );
while ( $processor->next_token() ) {
if ( $processor->is_html() && ! $processor->is_non_whitespace_html() ) {
continue;
}
return ! $processor->is_html() && $processor->opens_block();
}
return false;
}

/**
* Stops tracking a bound block, and the ones rendering inside it, once it has
* rendered.
*
* A block that throws never reaches this filter and stays tracked. If something
* catches the exception, later bound blocks count as nested for the rest of the
* page load. Nothing loops or renders unsanitized because of it.
*
* @since 7.3.0
* @access private
*
* @global array[] $wp_block_bindings_rendering_inner_blocks The bound blocks whose supplied inner blocks are rendering, with their source calls.
*
* @param string $block_content The rendered block.
* @param array $parsed_block The parsed block.
* @param WP_Block $instance The block instance.
* @return string The rendered block.
*/
function _block_bindings_forget_rendered_inner_blocks( $block_content, $parsed_block, $instance ) {
global $wp_block_bindings_rendering_inner_blocks;
foreach ( (array) $wp_block_bindings_rendering_inner_blocks as $index => $rendering ) {
if ( $rendering['bound_block'] === $instance ) {
$wp_block_bindings_rendering_inner_blocks = array_slice( $wp_block_bindings_rendering_inner_blocks, 0, $index );
break;
}
}
return $block_content;
}
add_filter( 'render_block', '_block_bindings_forget_rendered_inner_blocks', 10, 3 );

/**
* Parses the inner blocks a source supplies.
*
* The markup never went through the sanitizing on save, so it is sanitized with
* `wp_kses_post()`. Embeds expand as in post content.
*
* @since 7.3.0
* @access private
*
* @global WP_Embed $wp_embed WordPress Embed object.
*
* @param string $markup The serialized blocks.
* @param string $source_name The name of the source.
* @param array $source_args The arguments of the binding.
* @param WP_Block $block_instance The block instance.
* @return array[] The parsed blocks.
*/
function _block_bindings_parse_bound_inner_blocks( $markup, $source_name, $source_args, $block_instance ) {
global $wp_embed;

/**
* Filters whether the inner blocks a source supplies are sanitized with
* `wp_kses_post()`. A source whose markup comes from code, not from users,
* may return false. Custom CSS is removed either way.
*
* @since 7.3.0
*
* @param bool $sanitize Whether to sanitize the markup. Default true.
* @param string $source_name The name of the source.
* @param array $source_args The arguments of the binding.
* @param WP_Block $block_instance The block whose inner blocks the source supplies.
*/
if ( apply_filters( 'block_bindings_sanitize_inner_blocks', true, $source_name, $source_args, $block_instance ) ) {
$markup = wp_kses_post( $markup );
}
if ( $wp_embed instanceof WP_Embed ) {
$markup = $wp_embed->run_shortcode( $markup );
$markup = $wp_embed->autoembed( $markup );
}

return _block_bindings_strip_custom_css( parse_blocks( $markup ) );
}

/**
* Removes the custom CSS of the supplied blocks and their inner blocks. Only
* users who can edit CSS may add it, and the author of the value is unknown.
*
* @since 7.3.0
* @access private
*
* @param array[] $blocks The parsed blocks.
* @return array[] The parsed blocks.
*/
function _block_bindings_strip_custom_css( $blocks ) {
foreach ( $blocks as &$block ) {
if ( isset( $block['attrs']['style'] ) ) {
$block['attrs']['style'] = wp_strip_custom_css_from_style_array( $block['attrs']['style'] );
if ( empty( $block['attrs']['style'] ) ) {
unset( $block['attrs']['style'] );
}
}
$block['innerBlocks'] = _block_bindings_strip_custom_css( $block['innerBlocks'] );
}
return $blocks;
}

/**
* Returns the inner content of a block with slots for the given number of inner
* blocks.
*
* The slots replace the fallback inner blocks and the HTML between them. A block
* without any gets them before the closing tag of its wrapper, the last
* top-level element of its markup.
*
* @since 7.3.0
* @access private
*
* @param array $inner_content The inner content of the block.
* @param int $count The number of inner blocks.
* @return array|null The inner content, or null if there's no wrapper to put
* the inner blocks in.
*/
function _block_bindings_get_inner_content_with_slots( $inner_content, $count ) {
if ( ! is_array( $inner_content ) ) {
return null;
}

$slots = array_fill( 0, $count, null );
$own_slots = array_keys( $inner_content, null, true );
if ( $own_slots ) {
return array_merge( array_slice( $inner_content, 0, $own_slots[0] ), $slots, array_slice( $inner_content, end( $own_slots ) + 1 ) );
}

$processor = WP_HTML_Processor::create_fragment( implode( '', $inner_content ) );
$tokens = array();
$wrapper_depth = null;
$closer_index = null;
while ( $processor->next_token() ) {
$tokens[] = $processor->serialize_token();
if ( '#tag' !== $processor->get_token_type() ) {
continue;
}
if ( null === $wrapper_depth && ! $processor->is_tag_closer() ) {
$wrapper_depth = $processor->get_current_depth();
} elseif ( $processor->is_tag_closer() && $processor->get_current_depth() === $wrapper_depth - 1 ) {
$closer_index = count( $tokens ) - 1;
}
}
if ( null === $closer_index || null !== $processor->get_last_error() || $processor->paused_at_incomplete_token() ) {
return null;
}

$before = implode( '', array_slice( $tokens, 0, $closer_index ) );
$after = implode( '', array_slice( $tokens, $closer_index ) );
return array_merge( array( $before ), $slots, array( $after ) );
}

/**
* Replaces the inner blocks of a bound block with the ones its source supplies.
*
* Runs last on the value `WP_Block::process_block_bindings()` resolves for
* `innerBlocks`, and returns null so it never becomes an attribute. Only the
* block's own binding counts, not the one `__default` expands to.
*
* The block renders its fallback inner blocks when the inner blocks supplied
* for the same source call are rendering, so sources that supply each other's
* markup can't loop forever. A source call is the source, the arguments of the
* binding, the context the source uses, and the name and attributes of the
* block, with its keys sorted. Other nested bindings resolve, up to 100 bound
* blocks inside the outermost one, since a value could otherwise ask for itself
* again with other arguments in every order.
*
* @since 7.3.0
* @access private
*
* @global array[] $wp_block_bindings_rendering_inner_blocks The bound blocks whose supplied inner blocks are rendering, with their source calls.
* @global int $wp_block_bindings_inner_blocks_budget_spent How many bound blocks got inner blocks inside the outermost one.
*
* @param mixed $value The value of the source.
* @param string $source_name The name of the source.
* @param array $source_args The arguments of the binding.
* @param WP_Block $block_instance The block instance.
* @param string $attribute_name The name of the bound attribute.
* @return mixed The value, or null for `innerBlocks`.
*/
function _block_bindings_replace_inner_blocks( $value, $source_name, $source_args, $block_instance, $attribute_name ) {
global $wp_block_bindings_rendering_inner_blocks, $wp_block_bindings_inner_blocks_budget_spent;

if ( 'innerBlocks' !== $attribute_name ) {
return $value;
}

$own_binding_source = $block_instance->parsed_block['attrs']['metadata']['bindings']['innerBlocks']['source'] ?? null;
if ( $own_binding_source !== $source_name || ! _block_bindings_is_inner_blocks_value( $value ) ) {
return null;
}

$source = get_block_bindings_source( $source_name );
$context = array();
foreach ( $source ? (array) $source->uses_context : array() as $context_name ) {
if ( array_key_exists( $context_name, $block_instance->context ) ) {
$context[ $context_name ] = $block_instance->context[ $context_name ];
}
}
$source_call = array( $source_name, $source_args, $context, $block_instance->name, $block_instance->attributes );
wp_recursive_ksort( $source_call );
foreach ( (array) $wp_block_bindings_rendering_inner_blocks as $rendering ) {
if ( $rendering['source_call'] === $source_call ) {
return null;
}
}

$is_nested = ! empty( $wp_block_bindings_rendering_inner_blocks );
if ( $is_nested && (int) $wp_block_bindings_inner_blocks_budget_spent >= 100 ) {
return null;
}

$blocks = _block_bindings_parse_bound_inner_blocks( $value, $source_name, $source_args, $block_instance );
$inner_content = _block_bindings_get_inner_content_with_slots( $block_instance->parsed_block['innerContent'] ?? null, count( $blocks ) );
if ( null === $inner_content ) {
return null;
}

$block_instance->parsed_block['innerBlocks'] = $blocks;
$block_instance->parsed_block['innerContent'] = $inner_content;
$block_instance->parsed_block['innerHTML'] = implode( '', array_filter( $inner_content, 'is_string' ) );
$block_instance->inner_blocks = new WP_Block_List( array() );
$block_instance->inner_content = $inner_content;
$block_instance->inner_html = $block_instance->parsed_block['innerHTML'];
$block_instance->refresh_parsed_block_dependents();

$wp_block_bindings_inner_blocks_budget_spent = $is_nested ? (int) $wp_block_bindings_inner_blocks_budget_spent + 1 : 0;
$wp_block_bindings_rendering_inner_blocks[] = array(
'bound_block' => $block_instance,
'source_call' => $source_call,
);

return null;
}
add_filter( 'block_bindings_source_value', '_block_bindings_replace_inner_blocks', PHP_INT_MAX, 5 );
5 changes: 5 additions & 0 deletions src/wp-includes/block-editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,8 @@ function wp_get_post_content_block_attributes() {
* Returns the contextualized block editor settings for a selected editor context.
*
* @since 5.8.0
* @since 7.3.0 Leaves `innerBlocks` out of the attributes that block bindings support
* on the Group and Column blocks, as the editor doesn't render its bindings yet.
*
* @param array $custom_settings Custom settings to use with the given editor type.
* @param WP_Block_Editor_Context $block_editor_context The current block editor context.
Expand All @@ -503,6 +505,9 @@ function get_block_editor_settings( array $custom_settings, $block_editor_contex
$editor_settings['__experimentalBlockBindingsSupportedAttributes'] = array();
foreach ( array_keys( WP_Block_Type_Registry::get_instance()->get_all_registered() ) as $block_type ) {
$supported_block_attributes = get_block_bindings_supported_attributes( $block_type );
if ( in_array( $block_type, array( 'core/group', 'core/column' ), true ) ) {
$supported_block_attributes = array_values( array_diff( $supported_block_attributes, array( 'innerBlocks' ) ) );
}
if ( ! empty( $supported_block_attributes ) ) {
$editor_settings['__experimentalBlockBindingsSupportedAttributes'][ $block_type ] = $supported_block_attributes;
}
Expand Down
38 changes: 37 additions & 1 deletion src/wp-includes/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -2262,6 +2262,7 @@ function filter_block_core_template_part_attributes( $attribute_value, $attribut
* this function renders the blocks that are most likely to contain such text.
*
* @since 5.0.0
* @since 7.3.0 Renders the inner blocks that block bindings supply.
*
* @param string $content The content to parse.
* @return string The parsed and filtered content.
Expand Down Expand Up @@ -2331,6 +2332,11 @@ function excerpt_remove_blocks( $content ) {
}

if ( in_array( $block['blockName'], $allowed_blocks, true ) ) {
if ( isset( $block['attrs']['metadata']['bindings']['innerBlocks'] ) && in_array( 'innerBlocks', get_block_bindings_supported_attributes( $block['blockName'] ), true ) ) {
$output .= _excerpt_render_bound_inner_blocks( $block, $allowed_blocks );
continue;
}

if ( ! empty( $block['innerBlocks'] ) ) {
if ( in_array( $block['blockName'], $allowed_wrapper_blocks, true ) ) {
$output .= _excerpt_render_inner_blocks( $block, $allowed_blocks );
Expand Down Expand Up @@ -2381,6 +2387,7 @@ function excerpt_remove_footnotes( $content ) {
* for generating an excerpt.
*
* @since 5.8.0
* @since 7.3.0 Renders the inner blocks that block bindings supply.
* @access private
*
* @param array $parsed_block The parsed block.
Expand All @@ -2403,7 +2410,9 @@ function _excerpt_render_inner_blocks( $parsed_block, $allowed_blocks ) {
continue;
}

if ( empty( $inner_block['innerBlocks'] ) ) {
if ( isset( $inner_block['attrs']['metadata']['bindings']['innerBlocks'] ) && in_array( 'innerBlocks', get_block_bindings_supported_attributes( $inner_block['blockName'] ), true ) ) {
$output .= _excerpt_render_bound_inner_blocks( $inner_block, $allowed_blocks );
} elseif ( empty( $inner_block['innerBlocks'] ) ) {
$output .= render_block( $inner_block );
} else {
$output .= _excerpt_render_inner_blocks( $inner_block, $allowed_blocks );
Expand All @@ -2413,6 +2422,33 @@ function _excerpt_render_inner_blocks( $parsed_block, $allowed_blocks ) {
return $output;
}

/**
* Renders a block whose inner blocks a block bindings source supplies, for
* generating an excerpt.
*
* The block renders as on the front end, so its binding resolves with the same
* rules, and the blocks the excerpt doesn't allow render nothing.
*
* @since 7.3.0
* @access private
*
* @param array $parsed_block The parsed block.
* @param array $allowed_blocks The list of allowed blocks.
* @return string The rendered block.
*/
function _excerpt_render_bound_inner_blocks( $parsed_block, $allowed_blocks ) {
$skip_disallowed_blocks = static function ( $pre_render, $block ) use ( $allowed_blocks ) {
return in_array( $block['blockName'], $allowed_blocks, true ) ? $pre_render : '';
};

add_filter( 'pre_render_block', $skip_disallowed_blocks, 10, 2 );
try {
return render_block( $parsed_block );
} finally {
remove_filter( 'pre_render_block', $skip_disallowed_blocks );
}
}

/**
* Renders a single block into a HTML string.
*
Expand Down
1 change: 1 addition & 0 deletions src/wp-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,7 @@
require ABSPATH . WPINC . '/class-wp-classic-to-block-menu-converter.php';
require ABSPATH . WPINC . '/class-wp-navigation-fallback.php';
require ABSPATH . WPINC . '/block-bindings.php';
require ABSPATH . WPINC . '/block-bindings/inner-blocks.php';
require ABSPATH . WPINC . '/block-bindings/pattern-overrides.php';
require ABSPATH . WPINC . '/block-bindings/post-data.php';
require ABSPATH . WPINC . '/block-bindings/post-meta.php';
Expand Down
Loading
Loading