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:955
Renders the layout config to the block wrapper.

Compatibility

WordPress
since 6.6.0
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_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
163–276

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

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, query and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.

What one call costs · 17 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() && !$global_settings && !$style_attr && !$block && ->next_tag() && !empty($fallback_layout) && !isset($used_layout) && empty($value) && current_theme_supports() && !$class_attribute163–172::WP_Block_Type_Registry(), ->get_registered(), block_has_support(), wp_get_global_settings(), ::WP_Theme_JSON(), wp_get_layout_child_values(), array_intersect_key(), wp_unique_id_from_values(), wp_get_child_layout_style_rules(), wp_style_engine_get_stylesheet_from_css_rules(), layout(), ->next_tag(), wp_get_layout_definitions(), current_theme_supports(), explode(), ->get_updated_html()
block_has_support() && !$global_settings && !$style_attr && !$block && ->next_tag() && !empty($fallback_layout) && !isset($used_layout) && empty($value) && current_theme_supports() && !$class_attribute167–176::WP_Block_Type_Registry(), ->get_registered(), block_has_support(), wp_get_global_settings(), ::WP_Theme_JSON(), wp_get_layout_child_values(), array_intersect_key(), wp_unique_id_from_values(), wp_get_child_layout_style_rules(), wp_style_engine_get_stylesheet_from_css_rules(), layout(), ->next_tag(), wp_get_layout_definitions(), current_theme_supports(), explode(), end(), ->get_updated_html()
block_has_support() && !$global_settings && !$style_attr && !$block && ->next_tag() && !empty($fallback_layout) && !isset($used_layout) && empty($value) && current_theme_supports() && $class_attribute && is_string($class_attribute)171–180::WP_Block_Type_Registry(), ->get_registered(), block_has_support(), wp_get_global_settings(), ::WP_Theme_JSON(), wp_get_layout_child_values(), array_intersect_key(), wp_unique_id_from_values(), wp_get_child_layout_style_rules(), wp_style_engine_get_stylesheet_from_css_rules(), layout(), ->next_tag(), wp_get_layout_definitions(), current_theme_supports(), explode(), ->get_attribute(), ->get_updated_html()
block_has_support() && !$global_settings && !$style_attr && !$block && !empty($fallback_layout) && !isset($used_layout) && empty($value) && current_theme_supports() && $class_attribute172–183::WP_Block_Type_Registry(), ->get_registered(), block_has_support(), wp_get_global_settings(), ::WP_Theme_JSON(), wp_get_layout_child_values(), array_intersect_key(), wp_unique_id_from_values(), wp_get_child_layout_style_rules(), wp_style_engine_get_stylesheet_from_css_rules(), layout(), ->next_tag(), wp_get_layout_definitions(), current_theme_supports(), explode(), ->get_attribute(), ->next_tag(), ->get_updated_html()
block_has_support() && !$global_settings && !$style_attr && !$block && ->next_tag() && !empty($fallback_layout) && !isset($used_layout) && empty($value) && current_theme_supports() && $class_attribute && is_string($class_attribute)175–184::WP_Block_Type_Registry(), ->get_registered(), block_has_support(), wp_get_global_settings(), ::WP_Theme_JSON(), wp_get_layout_child_values(), array_intersect_key(), wp_unique_id_from_values(), wp_get_child_layout_style_rules(), wp_style_engine_get_stylesheet_from_css_rules(), layout(), ->next_tag(), wp_get_layout_definitions(), current_theme_supports(), explode(), end(), ->get_attribute(), ->get_updated_html()
block_has_support() && !$global_settings && !$style_attr && !$block && !empty($fallback_layout) && !isset($used_layout) && empty($value) && current_theme_supports() && $class_attribute176–187::WP_Block_Type_Registry(), ->get_registered(), block_has_support(), wp_get_global_settings(), ::WP_Theme_JSON(), wp_get_layout_child_values(), array_intersect_key(), wp_unique_id_from_values(), wp_get_child_layout_style_rules(), wp_style_engine_get_stylesheet_from_css_rules(), layout(), ->next_tag(), wp_get_layout_definitions(), current_theme_supports(), explode(), end(), ->get_attribute(), ->next_tag(), ->get_updated_html()
block_has_support() && !$global_settings && !$style_attr && !$block && !empty($fallback_layout) && !isset($used_layout) && empty($value) && current_theme_supports() && is_string($first_chunk) && !$class_attribute182–193::WP_Block_Type_Registry(), ->get_registered(), block_has_support(), wp_get_global_settings(), ::WP_Theme_JSON(), wp_get_layout_child_values(), array_intersect_key(), wp_unique_id_from_values(), wp_get_child_layout_style_rules(), wp_style_engine_get_stylesheet_from_css_rules(), layout(), ->next_tag(), wp_get_layout_definitions(), current_theme_supports(), explode(), wp_get_layout_style(), ->next_tag(), array_reverse(), ->get_updated_html()
block_has_support() && !$global_settings && !$style_attr && !$block && !empty($fallback_layout) && !isset($used_layout) && empty($value) && current_theme_supports() && is_string($first_chunk) && !$class_attribute186–197::WP_Block_Type_Registry(), ->get_registered(), block_has_support(), wp_get_global_settings(), ::WP_Theme_JSON(), wp_get_layout_child_values(), array_intersect_key(), wp_unique_id_from_values(), wp_get_child_layout_style_rules(), wp_style_engine_get_stylesheet_from_css_rules(), layout(), ->next_tag(), wp_get_layout_definitions(), current_theme_supports(), explode(), end(), wp_get_layout_style(), ->next_tag(), array_reverse(), ->get_updated_html()
block_has_support() && !$global_settings && !$style_attr && !$block && !empty($fallback_layout) && !isset($used_layout) && empty($value) && current_theme_supports() && is_string($first_chunk) && $class_attribute && is_string($class_attribute)190–201::WP_Block_Type_Registry(), ->get_registered(), block_has_support(), wp_get_global_settings(), ::WP_Theme_JSON(), wp_get_layout_child_values(), array_intersect_key(), wp_unique_id_from_values(), wp_get_child_layout_style_rules(), wp_style_engine_get_stylesheet_from_css_rules(), layout(), ->next_tag(), wp_get_layout_definitions(), current_theme_supports(), explode(), wp_get_layout_style(), ->next_tag(), array_reverse(), ->get_attribute(), ->get_updated_html()
block_has_support() && !$global_settings && !$style_attr && !$block && !empty($fallback_layout) && !isset($used_layout) && empty($value) && current_theme_supports() && is_string($first_chunk) && $class_attribute191–204::WP_Block_Type_Registry(), ->get_registered(), block_has_support(), wp_get_global_settings(), ::WP_Theme_JSON(), wp_get_layout_child_values(), array_intersect_key(), wp_unique_id_from_values(), wp_get_child_layout_style_rules(), wp_style_engine_get_stylesheet_from_css_rules(), layout(), ->next_tag(), wp_get_layout_definitions(), current_theme_supports(), explode(), wp_get_layout_style(), ->next_tag(), array_reverse(), ->get_attribute(), ->next_tag(), ->get_updated_html()
block_has_support() && !$global_settings && !$style_attr && !$block && !empty($fallback_layout) && !isset($used_layout) && empty($value) && current_theme_supports() && is_string($first_chunk) && $class_attribute && is_string($class_attribute)194–205::WP_Block_Type_Registry(), ->get_registered(), block_has_support(), wp_get_global_settings(), ::WP_Theme_JSON(), wp_get_layout_child_values(), array_intersect_key(), wp_unique_id_from_values(), wp_get_child_layout_style_rules(), wp_style_engine_get_stylesheet_from_css_rules(), layout(), ->next_tag(), wp_get_layout_definitions(), current_theme_supports(), explode(), end(), wp_get_layout_style(), ->next_tag(), array_reverse(), ->get_attribute(), ->get_updated_html()
block_has_support() && !$global_settings && !$style_attr && !$block && !empty($fallback_layout) && !isset($used_layout) && empty($value) && current_theme_supports() && is_string($first_chunk) && $class_attribute195–208::WP_Block_Type_Registry(), ->get_registered(), block_has_support(), wp_get_global_settings(), ::WP_Theme_JSON(), wp_get_layout_child_values(), array_intersect_key(), wp_unique_id_from_values(), wp_get_child_layout_style_rules(), wp_style_engine_get_stylesheet_from_css_rules(), layout(), ->next_tag(), wp_get_layout_definitions(), current_theme_supports(), explode(), end(), wp_get_layout_style(), ->next_tag(), array_reverse(), ->get_attribute(), ->next_tag(), ->get_updated_html()
5 further outcomes, up to 276 instructions
block_has_support() && !$global_settings && !$style_attr && !$block && ->next_tag() && !empty($fallback_layout) && !isset($used_layout) && empty($value) && !current_theme_supports() && $global_styles !== null && $global_block_gap_value === null && array_keys() && empty($style) && empty($outer_class_names) && !$class_attribute247–252::WP_Block_Type_Registry(), ->get_registered(), block_has_support(), wp_get_global_settings(), ::WP_Theme_JSON(), wp_get_layout_child_values(), array_intersect_key(), wp_unique_id_from_values(), wp_get_child_layout_style_rules(), wp_style_engine_get_stylesheet_from_css_rules(), layout(), ->next_tag(), wp_get_layout_definitions(), current_theme_supports(), wp_sanitize_block_gap_value(), wp_should_skip_block_supports_serialization(), array_keys(), sanitize_title(), wp_unique_id_from_values(), wp_get_layout_style(), explode(), ->get_updated_html()
block_has_support() && !$global_settings && !$style_attr && !$block && ->next_tag() && !empty($fallback_layout) && !isset($used_layout) && empty($value) && !current_theme_supports() && $global_styles !== null && $global_block_gap_value === null && array_keys() && empty($style) && empty($outer_class_names) && $class_attribute && is_string($class_attribute)255–260::WP_Block_Type_Registry(), ->get_registered(), block_has_support(), wp_get_global_settings(), ::WP_Theme_JSON(), wp_get_layout_child_values(), array_intersect_key(), wp_unique_id_from_values(), wp_get_child_layout_style_rules(), wp_style_engine_get_stylesheet_from_css_rules(), layout(), ->next_tag(), wp_get_layout_definitions(), current_theme_supports(), wp_sanitize_block_gap_value(), wp_should_skip_block_supports_serialization(), array_keys(), sanitize_title(), wp_unique_id_from_values(), wp_get_layout_style(), explode(), ->get_attribute(), ->get_updated_html()
block_has_support() && !$global_settings && !$style_attr && !$block && !empty($fallback_layout) && !isset($used_layout) && empty($value) && !current_theme_supports() && $global_styles !== null && $global_block_gap_value === null && array_keys() && empty($style) && empty($outer_class_names) && $class_attribute256–263::WP_Block_Type_Registry(), ->get_registered(), block_has_support(), wp_get_global_settings(), ::WP_Theme_JSON(), wp_get_layout_child_values(), array_intersect_key(), wp_unique_id_from_values(), wp_get_child_layout_style_rules(), wp_style_engine_get_stylesheet_from_css_rules(), layout(), ->next_tag(), wp_get_layout_definitions(), current_theme_supports(), wp_sanitize_block_gap_value(), wp_should_skip_block_supports_serialization(), array_keys(), sanitize_title(), wp_unique_id_from_values(), wp_get_layout_style(), explode(), ->get_attribute(), ->next_tag(), ->get_updated_html()
block_has_support() && !$global_settings && !$style_attr && !$block && !empty($fallback_layout) && !isset($used_layout) && empty($value) && !current_theme_supports() && $global_styles !== null && $global_block_gap_value === null && array_keys() && empty($style) && empty($outer_class_names) && is_string($first_chunk) && array_reverse() && !$class_attribute266–267::WP_Block_Type_Registry(), ->get_registered(), block_has_support(), wp_get_global_settings(), ::WP_Theme_JSON(), wp_get_layout_child_values(), array_intersect_key(), wp_unique_id_from_values(), wp_get_child_layout_style_rules(), wp_style_engine_get_stylesheet_from_css_rules(), layout(), ->next_tag(), wp_get_layout_definitions(), current_theme_supports(), wp_sanitize_block_gap_value(), wp_should_skip_block_supports_serialization(), array_keys(), sanitize_title(), wp_unique_id_from_values(), wp_get_layout_style(), explode(), wp_get_layout_style(), ->next_tag(), array_reverse(), ->get_updated_html()
block_has_support() && !$global_settings && !$style_attr && !$block && !empty($fallback_layout) && !isset($used_layout) && empty($value) && !current_theme_supports() && $global_styles !== null && $global_block_gap_value === null && array_keys() && empty($style) && empty($outer_class_names) && is_string($first_chunk) && array_reverse() && $class_attribute && !is_string($class_attribute)275–276::WP_Block_Type_Registry(), ->get_registered(), block_has_support(), wp_get_global_settings(), ::WP_Theme_JSON(), wp_get_layout_child_values(), array_intersect_key(), wp_unique_id_from_values(), wp_get_child_layout_style_rules(), wp_style_engine_get_stylesheet_from_css_rules(), layout(), ->next_tag(), wp_get_layout_definitions(), current_theme_supports(), wp_sanitize_block_gap_value(), wp_should_skip_block_supports_serialization(), array_keys(), sanitize_title(), wp_unique_id_from_values(), wp_get_layout_style(), explode(), wp_get_layout_style(), ->next_tag(), array_reverse(), ->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-dev624163–2761093 fewer instructions than PHP 8.5
8.5627163–276109
8.4627163–27610913 fewer instructions than PHP 8.3
8.3640167–280109
8.2640167–2801091 more instruction than PHP 8.1
8.1639167–2801091 fewer instruction than PHP 7.4
7.4640167–280109

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

Show all 22

Source code

function wp_render_layout_support_flag( $block_content, $block ) {	static $global_styles = null; 	$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 );	$style_attr            = $block['attrs']['style'] ?? array();	/*	 * A block with no layout support and no style attribute at all cannot	 * produce layout output, so return before resolving global settings.	 *	 * Resolving settings is not read-only: on a cold cache it queries the	 * user's `wp_global_styles` post, which fires `the_posts`. A callback on	 * that hook that renders blocks re-enters this filter, and the content it	 * renders at that point is the global styles post itself, which parses to a	 * single block with no name and no attributes. Without this return that	 * block resolves settings again and the recursion has no base case.	 */	if ( ! $block_supports_layout && empty( $style_attr ) ) {		return $block_content;	} 	$global_settings          = wp_get_global_settings();	$viewport_settings        = $global_settings['viewport'] ?? null;	$responsive_media_queries = WP_Theme_JSON::get_viewport_media_queries( $viewport_settings );	$child_layout             = $style_attr['layout'] ?? null; 	/*	 * Collect responsive viewport child layout overrides so that a block with	 * only responsive child layout (no base child layout) is still processed.	 */	$viewport_child_layouts = array();	foreach ( $responsive_media_queries as $breakpoint => $media_query ) {		$viewport_child = wp_get_layout_child_values( $style_attr[ $breakpoint ]['layout'] ?? null ); 		if ( ! empty( $viewport_child ) ) {			$viewport_child_layouts[ $breakpoint ] = array(				'media_query'  => $media_query,				'child_layout' => $viewport_child,			);		}	} 	if ( ! $block_supports_layout && ! $child_layout && empty( $viewport_child_layouts ) ) {		return $block_content;	} 	$outer_class_names = array(); 	// Child layout specific logic.	if ( $child_layout || ! empty( $viewport_child_layouts ) ) {		$base_child_layout = wp_get_layout_child_values( $child_layout );		$parent_layout     = $block['parentLayout'] ?? array();		/*		 * Generates a unique class for child block layout styles.		 *		 * To ensure consistent class generation across different page renders,		 * only properties that affect layout styling are used. These properties		 * come from `$block['attrs']['style']['layout']`, viewport overrides in		 * `$block['attrs']['style'][$breakpoint]['layout']`, and `$block['parentLayout']`.		 *		 * As long as these properties coincide, the generated class will be the same.		 */		$container_content_hash_input = array(			'layout'       => $base_child_layout,			'parentLayout' => array_intersect_key(				$parent_layout,				array_flip( array( 'minimumColumnWidth', 'columnCount' ) )			),		); 		foreach ( $viewport_child_layouts as $breakpoint => $viewport_data ) {			$container_content_hash_input[ $breakpoint ] = $viewport_data['child_layout'];		} 		$container_content_class = wp_unique_id_from_values(			$container_content_hash_input,			'wp-container-content-'		); 		$child_layout_styles = wp_get_child_layout_style_rules( ".$container_content_class", $base_child_layout, $parent_layout );

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.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 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.