wp-includes/block-supports/layout.php:499Generates the CSS corresponding to the provided layout.
$selectorstring$layoutarray$has_block_gap_supportbooloptionalfalse$gap_valuestring|string[]|nulloptionalnull$should_skip_gap_serializationbooloptionalfalse$fallback_gap_valuestring|arrayoptional'0.5em'$block_spacingarray|nulloptionalnull$optionsarrayoptionalarray()$viewport_overridesarray
$rules_groupstring|nulldefault: null
$has_block_gap_overridebooldefault: false
stringfunction wp_get_layout_style( $selector, $layout, $has_block_gap_support = false, $gap_value = null, $should_skip_gap_serialization = false, $fallback_gap_value = '0.5em', $block_spacing = null, $options = array() ) { $base_layout = is_array( $layout ) ? $layout : array(); $viewport_overrides = $options['viewport_overrides'] ?? null; $layout_for_styles = null === $viewport_overrides ? $base_layout : array_replace( $base_layout, $viewport_overrides ); $layout_type = $base_layout['type'] ?? 'default'; $rules_group = $options['rules_group'] ?? null; $has_block_gap_override = ! empty( $options['has_block_gap_override'] ); $should_output_block_gap = null === $viewport_overrides || $has_block_gap_override; /* * Viewport styles only store changed fields. If a field is present with null, * the user cleared a value inherited from the default viewport, so check * whether the key exists rather than whether the value is truthy. */ $has_viewport_property_override = static function ( $property ) use ( $viewport_overrides ) { return array_key_exists( $property, $viewport_overrides ); }; $layout_styles = array(); if ( 'default' === $layout_type ) { if ( $has_block_gap_support && $should_output_block_gap ) { if ( is_array( $gap_value ) ) { $gap_value = $gap_value['top'] ?? null; } if ( null !== $gap_value && ! $should_skip_gap_serialization ) { // Get spacing CSS variable from preset value if provided. if ( is_string( $gap_value ) && str_contains( $gap_value, 'var:preset|spacing|' ) ) { $index_to_splice = strrpos( $gap_value, '|' ) + 1; $slug = _wp_to_kebab_case( substr( $gap_value, $index_to_splice ) ); $gap_value = "var(--wp--preset--spacing--$slug)"; } array_push( $layout_styles, array( 'selector' => "$selector > *", 'declarations' => array( 'margin-block-start' => '0', 'margin-block-end' => '0', ), ), array( 'selector' => "$selector > * + *", 'declarations' => array( 'margin-block-start' => $gap_value, 'margin-block-end' => '0', ), ) ); } } } elseif ( 'constrained' === $layout_type ) { $content_size = $layout_for_styles['contentSize'] ?? ''; $wide_size = $layout_for_styles['wideSize'] ?? ''; $justify_content = $layout_for_styles['justifyContent'] ?? 'center'; // Check if viewport-specific ("override") values exist. Null values are valid and mean the user cleared a value inherited from the default viewport. $has_justify_content_override = null !== $viewport_overrides && $has_viewport_property_override( 'justifyContent' ); $has_content_size_override = null !== $viewport_overrides && $has_viewport_property_override( 'contentSize' ); $has_wide_size_override = null !== $viewport_overrides && $has_viewport_property_override( 'wideSize' ); /* * Styles should be output either if there are no viewport overrides (this is the default case), or if the user has set a new viewport-specific * value for contentSize or wideSize. If a viewport clears a custom constrained size, reset to the global layout variable. */ $should_output_constrained_sizes = null === $viewport_overrides || $has_content_size_override || $has_wide_size_override; $is_resetting_constrained_sizes = null !== $viewport_overrides && ( ( $has_content_size_override && ! $content_size ) || ( $has_wide_size_override && ! $wide_size ) ); // If a viewport clears a custom constrained size, reset to the global layout variable. $all_max_width_value = $content_size ? $content_size : ( $wide_size && ! $has_content_size_override ? $wide_size : 'var(--wp--style--global--content-size, none)' ); $wide_max_width_value = $wide_size ? $wide_size : ( $content_size && ! $has_wide_size_override ? $content_size : 'var(--wp--style--global--wide-size, none)' );Introduced in 5.9.0. 2 changes between 6.7.7 and 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
$options added.verified against source$fallback_gap_value retyped from string to string|array.verified against sourcesrc/wp-includes/block-supports/layout.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.