Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/wp-includes/block-supports/block-style-variations.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,13 @@ function wp_render_block_style_variation_support_styles( $parsed_block ) {
);

$config = array(
'version' => WP_Theme_JSON::LATEST_SCHEMA,
'styles' => array(
'version' => WP_Theme_JSON_Gutenberg::LATEST_SCHEMA,
'settings' => array(
'spacing' => array(
'blockGap' => true,
),
),
'styles' => array(
'elements' => $elements_data,
'blocks' => $blocks_data,
),
Expand Down
37 changes: 21 additions & 16 deletions src/wp-includes/class-wp-theme-json.php
Original file line number Diff line number Diff line change
Expand Up @@ -1615,7 +1615,7 @@ protected function get_layout_styles( $block_metadata, $options = array() ) {
$selector = $block_metadata['selector'] ?? '';
$has_block_gap_support = isset( $this->theme_json['settings']['spacing']['blockGap'] );
$has_fallback_gap_support = ! $has_block_gap_support; // This setting isn't useful yet: it exists as a placeholder for a future explicit fallback gap styles support.
$node = _wp_array_get( $this->theme_json, $block_metadata['path'], array() );
$node = $options['node'] ?? _wp_array_get( $this->theme_json, $block_metadata['path'], array() );
$layout_definitions = wp_get_layout_definitions();
$layout_selector_pattern = '/^[a-zA-Z0-9\-\.\,\ *+>:\(\)]*$/'; // Allow alphanumeric classnames, spaces, wildcard, sibling, child combinator and pseudo class selectors.

Expand Down Expand Up @@ -2356,18 +2356,6 @@ protected static function compute_style_properties( $styles, $settings = array()
continue;
}

/*
* Look up protected properties, keyed by value path.
* Skip protected properties that are explicitly set to `null`.
*/
$path_string = implode( '.', $value_path );
if (
isset( static::PROTECTED_PROPERTIES[ $path_string ] ) &&
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PROTECTED_PROPERTIES should be removed altogether because it's not used anymore. I'm not sure if it's OK to remove outright - as I'm doing in WordPress/gutenberg#74529 - or if there's a way to deprecate it or something. In case some third party is extending the class and for some reason using that const?

_wp_array_get( $settings, static::PROTECTED_PROPERTIES[ $path_string ], null ) === null
) {
continue;
}

// Calculates fluid typography rules where available.
if ( 'font-size' === $css_property ) {
/*
Expand Down Expand Up @@ -2811,8 +2799,9 @@ public function get_styles_for_block( $block_metadata ) {
$is_root_selector = static::ROOT_BLOCK_SELECTOR === $selector;

// If there are style variations, generate the declarations for them, including any feature selectors the block may have.
$style_variation_declarations = array();
$style_variation_custom_css = array();
$style_variation_declarations = array();
$style_variation_custom_css = array();
$style_variation_layout_metadata = array();
if ( ! empty( $block_metadata['variations'] ) ) {
foreach ( $block_metadata['variations'] as $style_variation ) {
$style_variation_node = _wp_array_get( $this->theme_json, $style_variation['path'], array() );
Expand Down Expand Up @@ -2852,6 +2841,18 @@ static function ( $split_selector ) use ( $clean_style_variation_selector ) {
if ( isset( $style_variation_node['css'] ) ) {
$style_variation_custom_css[ $style_variation['selector'] ] = $this->process_blocks_custom_css( $style_variation_node['css'], $style_variation['selector'] );
}

// Store variation metadata and node for layout styles generation.
// Only store if the variation has blockGap defined.
if ( isset( $style_variation_node['spacing']['blockGap'] ) ) {
// Append block selector to the variation selector for proper targeting.
$variation_metadata_with_selector = $style_variation;
$variation_metadata_with_selector['selector'] = $style_variation['selector'] . $block_metadata['css'];
$style_variation_layout_metadata[ $style_variation['selector'] ] = array(
'metadata' => $variation_metadata_with_selector,
'node' => $style_variation_node,
);
}
}
}
/*
Expand Down Expand Up @@ -3004,6 +3005,10 @@ static function ( $pseudo_selector ) use ( $selector ) {
// 6. Generate and append the style variation rulesets.
foreach ( $style_variation_declarations as $style_variation_selector => $individual_style_variation_declarations ) {
$block_rules .= static::to_ruleset( ":root :where($style_variation_selector)", $individual_style_variation_declarations );
if ( isset( $style_variation_layout_metadata[ $style_variation_selector ] ) ) {
$variation_data = $style_variation_layout_metadata[ $style_variation_selector ];
$block_rules .= $this->get_layout_styles( $variation_data['metadata'], array( 'node' => $variation_data['node'] ) );
}
if ( isset( $style_variation_custom_css[ $style_variation_selector ] ) ) {
$block_rules .= $style_variation_custom_css[ $style_variation_selector ];
}
Expand Down Expand Up @@ -3079,7 +3084,7 @@ public function get_root_layout_rules( $selector, $block_metadata, $options = ar
$css .= '.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }';
}

// Block gap styles will be output unless explicitly set to `null`. See static::PROTECTED_PROPERTIES.
// Block gap styles will be output unless explicitly set to `null`.
if ( isset( $this->theme_json['settings']['spacing']['blockGap'] ) ) {
$block_gap_value = static::get_property_value( $this->theme_json, array( 'styles', 'spacing', 'blockGap' ) );
$css .= ":where(.wp-site-blocks) > * { margin-block-start: $block_gap_value; margin-block-end: 0; }";
Expand Down
Loading