wp_get_child_layout_style_rules( string $selector, array $child_layout, array $parent_layout = array(), array|null $viewport_overrides = null ): array
- Since
- 7.1.0
- Source
wp-includes/block-supports/layout.php:109
Compatibility
- WordPress
- since 7.1.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in 1 of the 5 tracked releases, added in 7.1.0, and compiles on PHP 7.4 through 8.6-dev.
Parameters
$selectorstring- CSS selector.
$child_layoutarray- Child layout values.
$parent_layoutarrayoptional- Parent layout values.Default:
array() $viewport_overridesarray|nulloptional- Child viewport layout overrides to emit.Default:
null
Return value
array- Child layout style rules.
Performance profile
How much work a call to wp_get_child_layout_style_rules() 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
- Scaling
- Constant
- Instructions
- 4
- Plugin surface
- None
- Called by
- 1
Touches nothing outside its own arguments.
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5. The body compiles to 248.
Nothing here hands control to plugin code.
1 place in core call this, so the cost is paid more often than your own code shows.
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_get_child_layout_style_rules() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 4 | none |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 247 | 4 | 55 | 1 fewer instruction than PHP 8.5 |
| 8.5 | 248 | 4 | 55 | |
| 8.4 | 248 | 4 | 55 | 3 fewer instructions than PHP 8.3 |
| 8.3 | 251 | 4 | 55 | |
| 8.2 | 251 | 4 | 55 | |
| 8.1 | 251 | 4 | 55 | |
| 7.4 | 251 | 4 | 55 |
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.
Used by · 1
- wp_render_layout_support_flag()Renders the layout config to the block wrapper.
Source code
function wp_get_child_layout_style_rules( $selector, $child_layout, $parent_layout = array(), $viewport_overrides = null ) { $base_child_layout = is_array( $child_layout ) ? $child_layout : array(); $viewport_overrides = is_array( $viewport_overrides ) ? $viewport_overrides : null; $child_layout = null === $viewport_overrides ? $base_child_layout : array_replace( $base_child_layout, $viewport_overrides ); $child_layout_declarations = array(); $child_layout_styles = array(); $has_viewport_property_override = static function ( $property ) use ( $viewport_overrides ) { return array_key_exists( $property, $viewport_overrides ); }; $self_stretch = $child_layout['selfStretch'] ?? null; $base_self_stretch = $base_child_layout['selfStretch'] ?? null; /* * These are the serialized `selfStretch` values. `max` used to be called * "Fixed" in the UI, but was renamed and replaced by `fixedNoShrink`. */ $flex_child_layout_values = array( 'fit' => 'fit', 'grow' => 'fill', 'max' => 'fixed', 'fixed' => 'fixedNoShrink', ); $flex_size_values = array( $flex_child_layout_values['max'], $flex_child_layout_values['fixed'], ); if ( null === $viewport_overrides || $has_viewport_property_override( 'selfStretch' ) || $has_viewport_property_override( 'flexSize' ) ) { if ( null !== $viewport_overrides && ( $flex_child_layout_values['fit'] === $self_stretch || $flex_child_layout_values['grow'] === $self_stretch ) && in_array( $base_self_stretch, $flex_size_values, true ) && isset( $base_child_layout['flexSize'] ) ) { $child_layout_declarations['flex-basis'] = 'unset'; if ( $flex_child_layout_values['fixed'] === $base_self_stretch ) { $child_layout_declarations['flex-shrink'] = 'unset'; } } if ( in_array( $self_stretch, $flex_size_values, true ) && isset( $child_layout['flexSize'] ) ) { $child_layout_declarations['flex-basis'] = $child_layout['flexSize']; if ( $flex_child_layout_values['fixed'] === $self_stretch ) { $child_layout_declarations['flex-shrink'] = '0'; } elseif ( null !== $viewport_overrides && $flex_child_layout_values['fixed'] === $base_self_stretch ) { $child_layout_declarations['flex-shrink'] = 'unset'; } $child_layout_declarations['box-sizing'] = 'border-box'; } elseif ( $flex_child_layout_values['grow'] === $self_stretch ) { $child_layout_declarations['flex-grow'] = '1'; } } $column_start = $child_layout['columnStart'] ?? null; $column_span = $child_layout['columnSpan'] ?? null; if ( null === $viewport_overrides || $has_viewport_property_override( 'columnStart' ) || $has_viewport_property_override( 'columnSpan' ) ) { if ( $column_start && $column_span ) { $child_layout_declarations['grid-column'] = "$column_start / span $column_span"; } elseif ( $column_start ) { $child_layout_declarations['grid-column'] = "$column_start"; } elseif ( $column_span ) { $child_layout_declarations['grid-column'] = "span $column_span"; } } $row_start = $child_layout['rowStart'] ?? null; $row_span = $child_layout['rowSpan'] ?? null; if ( null === $viewport_overrides || $has_viewport_property_override( 'rowStart' ) || $has_viewport_property_override( 'rowSpan' ) ) { if ( $row_start && $row_span ) { $child_layout_declarations['grid-row'] = "$row_start / span $row_span"; } elseif ( $row_start ) { $child_layout_declarations['grid-row'] = "$row_start"; } elseif ( $row_span ) { $child_layout_declarations['grid-row'] = "span $row_span"; } } if ( ! empty( $child_layout_declarations ) ) { $child_layout_styles[] = array( 'selector' => $selector,Changelog
Introduced in 7.1.0.
Signature, return type and hooks compared across 1 parsed release.
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.