Changeset 61564
- Timestamp:
- 01/30/2026 02:09:32 AM (3 weeks ago)
- Location:
- trunk
- Files:
-
- 3 edited
-
src/wp-includes/block-supports/block-style-variations.php (modified) (1 diff)
-
src/wp-includes/class-wp-theme-json.php (modified) (6 diffs)
-
tests/phpunit/tests/theme/wpThemeJson.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/block-supports/block-style-variations.php
r59549 r61564 143 143 144 144 $config = array( 145 'version' => WP_Theme_JSON::LATEST_SCHEMA, 146 'styles' => array( 145 'version' => WP_Theme_JSON::LATEST_SCHEMA, 146 'settings' => array( 147 'spacing' => array( 148 'blockGap' => true, 149 ), 150 ), 151 'styles' => array( 147 152 'elements' => $elements_data, 148 153 'blocks' => $blocks_data, -
trunk/src/wp-includes/class-wp-theme-json.php
r61473 r61564 1616 1616 $has_block_gap_support = isset( $this->theme_json['settings']['spacing']['blockGap'] ); 1617 1617 $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. 1618 $node = _wp_array_get( $this->theme_json, $block_metadata['path'], array() );1618 $node = $options['node'] ?? _wp_array_get( $this->theme_json, $block_metadata['path'], array() ); 1619 1619 $layout_definitions = wp_get_layout_definitions(); 1620 1620 $layout_selector_pattern = '/^[a-zA-Z0-9\-\.\,\ *+>:\(\)]*$/'; // Allow alphanumeric classnames, spaces, wildcard, sibling, child combinator and pseudo class selectors. … … 2357 2357 } 2358 2358 2359 /*2360 * Look up protected properties, keyed by value path.2361 * Skip protected properties that are explicitly set to `null`.2362 */2363 $path_string = implode( '.', $value_path );2364 if (2365 isset( static::PROTECTED_PROPERTIES[ $path_string ] ) &&2366 _wp_array_get( $settings, static::PROTECTED_PROPERTIES[ $path_string ], null ) === null2367 ) {2368 continue;2369 }2370 2371 2359 // Calculates fluid typography rules where available. 2372 2360 if ( 'font-size' === $css_property ) { … … 2812 2800 2813 2801 // If there are style variations, generate the declarations for them, including any feature selectors the block may have. 2814 $style_variation_declarations = array(); 2815 $style_variation_custom_css = array(); 2802 $style_variation_declarations = array(); 2803 $style_variation_custom_css = array(); 2804 $style_variation_layout_metadata = array(); 2816 2805 if ( ! empty( $block_metadata['variations'] ) ) { 2817 2806 foreach ( $block_metadata['variations'] as $style_variation ) { … … 2852 2841 if ( isset( $style_variation_node['css'] ) ) { 2853 2842 $style_variation_custom_css[ $style_variation['selector'] ] = $this->process_blocks_custom_css( $style_variation_node['css'], $style_variation['selector'] ); 2843 } 2844 2845 // Store variation metadata and node for layout styles generation. 2846 // Only store if the variation has blockGap defined. 2847 if ( isset( $style_variation_node['spacing']['blockGap'] ) ) { 2848 // Append block selector to the variation selector for proper targeting. 2849 $variation_metadata_with_selector = $style_variation; 2850 $variation_metadata_with_selector['selector'] = $style_variation['selector'] . $block_metadata['css']; 2851 $style_variation_layout_metadata[ $style_variation['selector'] ] = array( 2852 'metadata' => $variation_metadata_with_selector, 2853 'node' => $style_variation_node, 2854 ); 2854 2855 } 2855 2856 } … … 3005 3006 foreach ( $style_variation_declarations as $style_variation_selector => $individual_style_variation_declarations ) { 3006 3007 $block_rules .= static::to_ruleset( ":root :where($style_variation_selector)", $individual_style_variation_declarations ); 3008 if ( isset( $style_variation_layout_metadata[ $style_variation_selector ] ) ) { 3009 $variation_data = $style_variation_layout_metadata[ $style_variation_selector ]; 3010 $block_rules .= $this->get_layout_styles( $variation_data['metadata'], array( 'node' => $variation_data['node'] ) ); 3011 } 3007 3012 if ( isset( $style_variation_custom_css[ $style_variation_selector ] ) ) { 3008 3013 $block_rules .= $style_variation_custom_css[ $style_variation_selector ]; … … 3080 3085 } 3081 3086 3082 // Block gap styles will be output unless explicitly set to `null`. See static::PROTECTED_PROPERTIES.3087 // Block gap styles will be output unless explicitly set to `null`. 3083 3088 if ( isset( $this->theme_json['settings']['spacing']['blockGap'] ) ) { 3084 3089 $block_gap_value = static::get_property_value( $this->theme_json, array( 'styles', 'spacing', 'blockGap' ) ); -
trunk/tests/phpunit/tests/theme/wpThemeJson.php
r61473 r61564 4732 4732 } 4733 4733 4734 /** 4735 * Tests that block style variations with blockGap generate proper layout styles. 4736 * 4737 * @ticket 64533 4738 */ 4739 public function test_get_styles_for_block_with_style_variations_and_block_gap() { 4740 register_block_style( 4741 'core/group', 4742 array( 4743 'name' => 'withGap', 4744 'label' => 'With Gap', 4745 ) 4746 ); 4747 4748 $theme_json = new WP_Theme_JSON( 4749 array( 4750 'version' => WP_Theme_JSON::LATEST_SCHEMA, 4751 'settings' => array( 4752 'spacing' => array( 4753 'blockGap' => true, 4754 ), 4755 ), 4756 'styles' => array( 4757 'blocks' => array( 4758 'core/group' => array( 4759 'variations' => array( 4760 'withGap' => array( 4761 'color' => array( 4762 'background' => 'tomato', 4763 ), 4764 'spacing' => array( 4765 'blockGap' => '5rem', 4766 ), 4767 ), 4768 ), 4769 ), 4770 ), 4771 ), 4772 ) 4773 ); 4774 4775 $metadata = array( 4776 'name' => 'core/group', 4777 'path' => array( 'styles', 'blocks', 'core/group' ), 4778 'selector' => '.wp-block-group', 4779 'css' => '.wp-block-group', 4780 'variations' => array( 4781 array( 4782 'path' => array( 'styles', 'blocks', 'core/group', 'variations', 'withGap' ), 4783 'selector' => '.is-style-withGap.wp-block-group', 4784 ), 4785 ), 4786 ); 4787 4788 $actual_styles = $theme_json->get_styles_for_block( $metadata ); 4789 4790 unregister_block_style( 'core/group', 'withGap' ); 4791 4792 $expected = ':root :where(.is-style-withGap.wp-block-group){background-color: tomato;}:root :where(.is-style-withGap.wp-block-group.wp-block-group-is-layout-flow) > :first-child{margin-block-start: 0;}:root :where(.is-style-withGap.wp-block-group.wp-block-group-is-layout-flow) > :last-child{margin-block-end: 0;}:root :where(.is-style-withGap.wp-block-group.wp-block-group-is-layout-flow) > *{margin-block-start: 5rem;margin-block-end: 0;}:root :where(.is-style-withGap.wp-block-group.wp-block-group-is-layout-constrained) > :first-child{margin-block-start: 0;}:root :where(.is-style-withGap.wp-block-group.wp-block-group-is-layout-constrained) > :last-child{margin-block-end: 0;}:root :where(.is-style-withGap.wp-block-group.wp-block-group-is-layout-constrained) > *{margin-block-start: 5rem;margin-block-end: 0;}:root :where(.is-style-withGap.wp-block-group.wp-block-group-is-layout-flex){gap: 5rem;}:root :where(.is-style-withGap.wp-block-group.wp-block-group-is-layout-grid){gap: 5rem;}'; 4793 $this->assertSame( $expected, $actual_styles ); 4794 } 4795 4734 4796 public function test_block_style_variations() { 4735 4797 wp_set_current_user( static::$administrator_id );
Note: See TracChangeset
for help on using the changeset viewer.