wppaste
WordPress

wp_restore_group_inner_container( string $block_content, array $block ): string

Since
5.8.0, 6.6.1
Source
wp-includes/block-supports/layout.php:1465
For themes without theme.json file, make sure to restore the inner div for the group block to avoid breaking styles relying on that div.

Compatibility

WordPress
since 6.6.1
PHP
7.4–8.6-dev
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.

Parameters

$block_contentstring
Rendered block content.
$blockarray
Block object.

Return value

string
Filtered block content.

Performance profile

How much work a call to wp_restore_group_inner_container() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.

Cost class
Trivial

Touches nothing outside its own arguments.

Scaling
Constant

No loop in the body: the same number of instructions runs whatever you pass in.

Instructions
9

Executed per call on PHP 8.5. The body compiles to 108.

Plugin surface
None

Nothing here hands control to plugin code.

Called by
0

Nothing in core calls this; the cost is only what you spend yourself.

What it touches

  • hookthird-party callbacksapply_filters()one call below wp_restore_group_inner_container()

Further down the call graph this can also reach option, cache, serialize, transient and query. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.

What one call costs · 1 distinct outcome

One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_restore_group_inner_container() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
always9none

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev108914
8.5108914
8.41089146 fewer instructions than PHP 8.3
8.3114914
8.2114914
8.1114914
7.4114914

An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.

Uses · 3

Source code

function wp_restore_group_inner_container( $block_content, $block ) {	$tag_name                         = $block['attrs']['tagName'] ?? 'div';	$group_with_inner_container_regex = sprintf(		'/(^\s*<%1$s\b[^>]*wp-block-group(\s|")[^>]*>)(\s*<div\b[^>]*wp-block-group__inner-container(\s|")[^>]*>)((.|\S|\s)*)/U',		preg_quote( $tag_name, '/' )	); 	if (		wp_theme_has_theme_json() ||		1 === preg_match( $group_with_inner_container_regex, $block_content ) ||		( isset( $block['attrs']['layout']['type'] ) && ( 'flex' === $block['attrs']['layout']['type'] || 'grid' === $block['attrs']['layout']['type'] ) )	) {		return $block_content;	} 	/*	 * This filter runs after the layout classnames have been added to the block, so they	 * have to be removed from the outer wrapper and then added to the inner.	 */	$layout_classes = array();	$processor      = new WP_HTML_Tag_Processor( $block_content ); 	if ( $processor->next_tag( array( 'class_name' => 'wp-block-group' ) ) ) {		foreach ( $processor->class_list() as $class_name ) {			if ( str_contains( $class_name, 'is-layout-' ) ) {				$layout_classes[] = $class_name;				$processor->remove_class( $class_name );			}		}	} 	$content_without_layout_classes = $processor->get_updated_html();	$replace_regex                  = sprintf(		'/(^\s*<%1$s\b[^>]*wp-block-group[^>]*>)(.*)(<\/%1$s>\s*$)/ms',		preg_quote( $tag_name, '/' )	);	$updated_content                = preg_replace_callback(		$replace_regex,		static function ( $matches ) {			return $matches[1] . '<div class="wp-block-group__inner-container">' . $matches[2] . '</div>' . $matches[3];		},		$content_without_layout_classes	); 	// Add layout classes to inner wrapper.	if ( ! empty( $layout_classes ) ) {		$processor = new WP_HTML_Tag_Processor( $updated_content );		if ( $processor->next_tag( array( 'class_name' => 'wp-block-group__inner-container' ) ) ) {			foreach ( $layout_classes as $class_name ) {				$processor->add_class( $class_name );			}		}		$updated_content = $processor->get_updated_html();	}	return $updated_content;}

Changelog

Introduced in 5.8.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

6.6.1
Removed inner container from Grid variations.from the docblock
5.8.0
Introduced.from the docblock

About this page

Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-includes/block-supports/layout.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.