wppaste
WordPress

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

Since
5.8.0, 6.3.0, 6.3.0, 6.6.0
Source
wp-includes/block-supports/layout.php:570
Renders the layout config to the block wrapper.

Compatibility

WordPress
since 6.6.0
PHP
7.4–8.6-dev
  • 6.7.10
  • 6.8.11
  • 6.9.10
  • 7.0.7
  • 7.1.3

Present in every tracked release (6.7.10 to 7.1.3), 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_render_layout_support_flag() 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
Moderate

Only touches the object cache, via wp_cache_get().

Scaling
Scales with input

The body loops, so the work grows with what you pass in.

Instructions
128–209

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 473.

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

  • cacheobject cachewp_cache_get()one call below wp_render_layout_support_flag()
  • hookthird-party callbacksapply_filters()one call below wp_render_layout_support_flag()

Further down the call graph this can also reach option, 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 · 12 distinct outcomes

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

WhenInstructionsCalls it makes
block_has_support() && !isset($value) && ->next_tag() && !empty($fallback_layout) && !isset($used_layout) && !isset($global_settings) && empty($value) && current_theme_supports()128–138::WP_Block_Type_Registry(), ->get_registered(), block_has_support(), rules_group(), ->next_tag(), wp_get_global_settings(), wp_get_layout_definitions(), sanitize_title(), wp_unique_prefixed_id(), current_theme_supports(), explode(), end(), ->get_updated_html()
block_has_support() && !isset($value) && ->next_tag() && !empty($fallback_layout) && !isset($used_layout) && !isset($global_settings) && empty($value) && current_theme_supports() && is_string($class_attribute) && $class_attribute136–146::WP_Block_Type_Registry(), ->get_registered(), block_has_support(), rules_group(), ->next_tag(), wp_get_global_settings(), wp_get_layout_definitions(), sanitize_title(), wp_unique_prefixed_id(), current_theme_supports(), explode(), end(), ->get_attribute(), ->get_updated_html()
block_has_support() && !isset($value) && !empty($fallback_layout) && !isset($used_layout) && !isset($global_settings) && empty($value) && current_theme_supports()137–149::WP_Block_Type_Registry(), ->get_registered(), block_has_support(), rules_group(), ->next_tag(), wp_get_global_settings(), wp_get_layout_definitions(), sanitize_title(), wp_unique_prefixed_id(), current_theme_supports(), explode(), end(), ->get_attribute(), ->next_tag(), ->get_updated_html()
block_has_support() && !isset($value) && !empty($fallback_layout) && !isset($used_layout) && !isset($global_settings) && empty($value) && current_theme_supports() && is_string($first_chunk)140–146::WP_Block_Type_Registry(), ->get_registered(), block_has_support(), rules_group(), ->next_tag(), wp_get_global_settings(), wp_get_layout_definitions(), sanitize_title(), wp_unique_prefixed_id(), current_theme_supports(), explode(), end(), selector(), ->next_tag(), ->get_updated_html()
block_has_support() && !isset($value) && !empty($fallback_layout) && !isset($used_layout) && !isset($global_settings) && empty($value) && current_theme_supports() && is_string($first_chunk) && is_string($class_attribute) && $class_attribute148–154::WP_Block_Type_Registry(), ->get_registered(), block_has_support(), rules_group(), ->next_tag(), wp_get_global_settings(), wp_get_layout_definitions(), sanitize_title(), wp_unique_prefixed_id(), current_theme_supports(), explode(), end(), selector(), ->next_tag(), ->get_attribute(), ->get_updated_html()
block_has_support() && !isset($value) && !empty($fallback_layout) && !isset($used_layout) && !isset($global_settings) && empty($value) && current_theme_supports() && is_string($first_chunk)149–157::WP_Block_Type_Registry(), ->get_registered(), block_has_support(), rules_group(), ->next_tag(), wp_get_global_settings(), wp_get_layout_definitions(), sanitize_title(), wp_unique_prefixed_id(), current_theme_supports(), explode(), end(), selector(), ->next_tag(), ->get_attribute(), ->next_tag(), ->get_updated_html()
block_has_support() && !isset($value) && ->next_tag() && !empty($fallback_layout) && !isset($used_layout) && !isset($global_settings) && empty($value) && !current_theme_supports() && !is_array($gap_value)178–190::WP_Block_Type_Registry(), ->get_registered(), block_has_support(), rules_group(), ->next_tag(), wp_get_global_settings(), wp_get_layout_definitions(), sanitize_title(), wp_unique_prefixed_id(), current_theme_supports(), wp_should_skip_block_supports_serialization(), wp_get_layout_style(), explode(), end(), ->get_updated_html()
block_has_support() && !isset($value) && ->next_tag() && !empty($fallback_layout) && !isset($used_layout) && !isset($global_settings) && empty($value) && !current_theme_supports() && !is_array($gap_value) && is_string($class_attribute) && $class_attribute186–198::WP_Block_Type_Registry(), ->get_registered(), block_has_support(), rules_group(), ->next_tag(), wp_get_global_settings(), wp_get_layout_definitions(), sanitize_title(), wp_unique_prefixed_id(), current_theme_supports(), wp_should_skip_block_supports_serialization(), wp_get_layout_style(), explode(), end(), ->get_attribute(), ->get_updated_html()
block_has_support() && !isset($value) && !empty($fallback_layout) && !isset($used_layout) && !isset($global_settings) && empty($value) && !current_theme_supports() && !is_array($gap_value)187–201::WP_Block_Type_Registry(), ->get_registered(), block_has_support(), rules_group(), ->next_tag(), wp_get_global_settings(), wp_get_layout_definitions(), sanitize_title(), wp_unique_prefixed_id(), current_theme_supports(), wp_should_skip_block_supports_serialization(), wp_get_layout_style(), explode(), end(), ->get_attribute(), ->next_tag(), ->get_updated_html()
block_has_support() && !isset($value) && !empty($fallback_layout) && !isset($used_layout) && !isset($global_settings) && empty($value) && !current_theme_supports() && !is_array($gap_value) && is_string($first_chunk)190–198::WP_Block_Type_Registry(), ->get_registered(), block_has_support(), rules_group(), ->next_tag(), wp_get_global_settings(), wp_get_layout_definitions(), sanitize_title(), wp_unique_prefixed_id(), current_theme_supports(), wp_should_skip_block_supports_serialization(), wp_get_layout_style(), explode(), end(), selector(), ->next_tag(), ->get_updated_html()
block_has_support() && !isset($value) && !empty($fallback_layout) && !isset($used_layout) && !isset($global_settings) && empty($value) && !current_theme_supports() && !is_array($gap_value) && is_string($first_chunk) && is_string($class_attribute) && $class_attribute198–206::WP_Block_Type_Registry(), ->get_registered(), block_has_support(), rules_group(), ->next_tag(), wp_get_global_settings(), wp_get_layout_definitions(), sanitize_title(), wp_unique_prefixed_id(), current_theme_supports(), wp_should_skip_block_supports_serialization(), wp_get_layout_style(), explode(), end(), selector(), ->next_tag(), ->get_attribute(), ->get_updated_html()
block_has_support() && !isset($value) && !empty($fallback_layout) && !isset($used_layout) && !isset($global_settings) && empty($value) && !current_theme_supports() && !is_array($gap_value) && is_string($first_chunk)199–209::WP_Block_Type_Registry(), ->get_registered(), block_has_support(), rules_group(), ->next_tag(), wp_get_global_settings(), wp_get_layout_definitions(), sanitize_title(), wp_unique_prefixed_id(), current_theme_supports(), wp_should_skip_block_supports_serialization(), wp_get_layout_style(), explode(), end(), selector(), ->next_tag(), ->get_attribute(), ->next_tag(), ->get_updated_html()

This body has more branch combinations than are worth enumerating, so the table covers the outcomes found first rather than every one that exists.

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev473128–20974
8.5473128–20974
8.4473128–209749 fewer instructions than PHP 8.3
8.3482128–21274
8.2482128–21274
8.1482128–2127414 fewer instructions than PHP 7.4
7.4496128–21374

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 · 13

Show all 13

Source code

function wp_render_layout_support_flag( $block_content, $block ) {	$block_type            = WP_Block_Type_Registry::get_instance()->get_registered( $block['blockName'] );	$block_supports_layout = block_has_support( $block_type, 'layout', false ) || block_has_support( $block_type, '__experimentalLayout', false );	$child_layout          = isset( $block['attrs']['style']['layout'] ) ? $block['attrs']['style']['layout'] : null; 	if ( ! $block_supports_layout && ! $child_layout ) {		return $block_content;	} 	$outer_class_names = array(); 	// Child layout specific logic.	if ( $child_layout ) {		$container_content_class   = wp_unique_prefixed_id( 'wp-container-content-' );		$child_layout_declarations = array();		$child_layout_styles       = array(); 		$self_stretch = isset( $child_layout['selfStretch'] ) ? $child_layout['selfStretch'] : null; 		if ( 'fixed' === $self_stretch && isset( $child_layout['flexSize'] ) ) {			$child_layout_declarations['flex-basis'] = $child_layout['flexSize'];			$child_layout_declarations['box-sizing'] = 'border-box';		} elseif ( 'fill' === $self_stretch ) {			$child_layout_declarations['flex-grow'] = '1';		} 		if ( isset( $child_layout['columnSpan'] ) ) {			$column_span                              = $child_layout['columnSpan'];			$child_layout_declarations['grid-column'] = "span $column_span";		}		if ( isset( $child_layout['rowSpan'] ) ) {			$row_span                              = $child_layout['rowSpan'];			$child_layout_declarations['grid-row'] = "span $row_span";		}		$child_layout_styles[] = array(			'selector'     => ".$container_content_class",			'declarations' => $child_layout_declarations,		); 		/*		 * If columnSpan is set, and the parent grid is responsive, i.e. if it has a minimumColumnWidth set,		 * the columnSpan should be removed on small grids. If there's a minimumColumnWidth, the grid is responsive.		 * But if the minimumColumnWidth value wasn't changed, it won't be set. In that case, if columnCount doesn't		 * exist, we can assume that the grid is responsive.		 */		if ( isset( $child_layout['columnSpan'] ) && ( isset( $block['parentLayout']['minimumColumnWidth'] ) || ! isset( $block['parentLayout']['columnCount'] ) ) ) {			$column_span_number  = floatval( $child_layout['columnSpan'] );			$parent_column_width = isset( $block['parentLayout']['minimumColumnWidth'] ) ? $block['parentLayout']['minimumColumnWidth'] : '12rem';			$parent_column_value = floatval( $parent_column_width );			$parent_column_unit  = explode( $parent_column_value, $parent_column_width ); 			/*			 * If there is no unit, the width has somehow been mangled so we reset both unit and value			 * to defaults.			 * Additionally, the unit should be one of px, rem or em, so that also needs to be checked.			 */			if ( count( $parent_column_unit ) <= 1 ) {				$parent_column_unit  = 'rem';				$parent_column_value = 12;			} else {				$parent_column_unit = $parent_column_unit[1]; 				if ( ! in_array( $parent_column_unit, array( 'px', 'rem', 'em' ), true ) ) {					$parent_column_unit = 'rem';				}			} 			/*			 * A default gap value is used for this computation because custom gap values may not be			 * viable to use in the computation of the container query value.			 */			$default_gap_value     = 'px' === $parent_column_unit ? 24 : 1.5;			$container_query_value = $column_span_number * $parent_column_value + ( $column_span_number - 1 ) * $default_gap_value;			$container_query_value = $container_query_value . $parent_column_unit; 			$child_layout_styles[] = array(				'rules_group'  => "@container (max-width: $container_query_value )",				'selector'     => ".$container_content_class",				'declarations' => array(					'grid-column' => '1/-1',

Changelog

Introduced in 5.8.0. Unchanged from 6.7.10 through 7.1.3.

  1. 6.7.10
  2. 6.8.11
  3. 6.9.10
  4. 7.0.7
  5. 7.1.3

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

6.6.0
Removed duplicate container class from layout styles.from the docblock
6.3.0
Check for layout support via the layout key with fallback to __experimentalLayout.from the docblock
6.3.0
Adds compound class to layout wrapper for global spacing styles.from the docblock
5.8.0
Introduced.from the docblock

About this page

Parsed data
Generated from the wordpress-develop 6.7.10 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.