@@ -1293,7 +1293,7 @@ protected function process_blocks_custom_css( $css, $selector ) {
1293
1293
$ is_root_css = ( ! str_contains ( $ part , '{ ' ) );
1294
1294
if ( $ is_root_css ) {
1295
1295
// If the part doesn't contain braces, it applies to the root level.
1296
- $ processed_css .= trim ( $ selector ) . '{ ' . trim ( $ part ) . '} ' ;
1296
+ $ processed_css .= ' :root :where( ' . trim ( $ selector ) . ') { ' . trim ( $ part ) . '} ' ;
1297
1297
} else {
1298
1298
// If the part contains braces, it's a nested CSS rule.
1299
1299
$ part = explode ( '{ ' , str_replace ( '} ' , '' , $ part ) );
@@ -1305,7 +1305,8 @@ protected function process_blocks_custom_css( $css, $selector ) {
1305
1305
$ part_selector = str_starts_with ( $ nested_selector , ' ' )
1306
1306
? static ::scope_selector ( $ selector , $ nested_selector )
1307
1307
: static ::append_to_selector ( $ selector , $ nested_selector );
1308
- $ processed_css .= $ part_selector . '{ ' . trim ( $ css_value ) . '} ' ;
1308
+ $ final_selector = ":root :where( $ part_selector) " ;
1309
+ $ processed_css .= $ final_selector . '{ ' . trim ( $ css_value ) . '} ' ;
1309
1310
}
1310
1311
}
1311
1312
return $ processed_css ;
@@ -1322,6 +1323,7 @@ public function get_custom_css() {
1322
1323
$ block_custom_css = '' ;
1323
1324
$ block_nodes = $ this ->get_block_custom_css_nodes ();
1324
1325
foreach ( $ block_nodes as $ node ) {
1326
+ // The node selector will have its specificity set to 0-1-0 within process_blocks_custom_css.
1325
1327
$ block_custom_css .= $ this ->get_block_custom_css ( $ node ['css ' ], $ node ['selector ' ] );
1326
1328
}
1327
1329
@@ -1564,7 +1566,7 @@ protected function get_layout_styles( $block_metadata, $types = array() ) {
1564
1566
$ spacing_rule ['selector ' ]
1565
1567
);
1566
1568
} else {
1567
- $ format = static ::ROOT_BLOCK_SELECTOR === $ selector ? ':where( .%2$s) %3$s ' : ':where( %1$s-%2$s) %3$s ' ;
1569
+ $ format = static ::ROOT_BLOCK_SELECTOR === $ selector ? '.%2$s %3$s ' : '%1$s-%2$s %3$s ' ;
1568
1570
$ layout_selector = sprintf (
1569
1571
$ format ,
1570
1572
$ selector ,
@@ -2745,7 +2747,7 @@ static function ( $pseudo_selector ) use ( $selector ) {
2745
2747
}
2746
2748
2747
2749
// 2. Generate and append the rules that use the general selector.
2748
- $ block_rules .= static ::to_ruleset ( ":where( $ selector) " , $ declarations );
2750
+ $ block_rules .= static ::to_ruleset ( ":root : where( $ selector) " , $ declarations );
2749
2751
2750
2752
// 3. Generate and append the rules that use the duotone selector.
2751
2753
if ( isset ( $ block_metadata ['duotone ' ] ) && ! empty ( $ declarations_duotone ) ) {
@@ -2762,12 +2764,12 @@ static function ( $pseudo_selector ) use ( $selector ) {
2762
2764
2763
2765
// 5. Generate and append the feature level rulesets.
2764
2766
foreach ( $ feature_declarations as $ feature_selector => $ individual_feature_declarations ) {
2765
- $ block_rules .= static ::to_ruleset ( ":where( $ feature_selector) " , $ individual_feature_declarations );
2767
+ $ block_rules .= static ::to_ruleset ( ":root : where( $ feature_selector) " , $ individual_feature_declarations );
2766
2768
}
2767
2769
2768
2770
// 6. Generate and append the style variation rulesets.
2769
2771
foreach ( $ style_variation_declarations as $ style_variation_selector => $ individual_style_variation_declarations ) {
2770
- $ block_rules .= static ::to_ruleset ( $ style_variation_selector , $ individual_style_variation_declarations );
2772
+ $ block_rules .= static ::to_ruleset ( " :root :where( $ style_variation_selector) " , $ individual_style_variation_declarations );
2771
2773
}
2772
2774
2773
2775
return $ block_rules ;
@@ -2816,16 +2818,12 @@ public function get_root_layout_rules( $selector, $block_metadata ) {
2816
2818
$ css .= '.wp-site-blocks { padding-top: var(--wp--style--root--padding-top); padding-bottom: var(--wp--style--root--padding-bottom); } ' ;
2817
2819
// Right and left padding are applied to the first container with `.has-global-padding` class.
2818
2820
$ css .= '.has-global-padding { padding-right: var(--wp--style--root--padding-right); padding-left: var(--wp--style--root--padding-left); } ' ;
2819
- // Nested containers with `.has-global-padding` class do not get padding.
2820
- $ css .= '.has-global-padding :where(.has-global-padding:not(.wp-block-block)) { padding-right: 0; padding-left: 0; } ' ;
2821
2821
// Alignfull children of the container with left and right padding have negative margins so they can still be full width.
2822
2822
$ css .= '.has-global-padding > .alignfull { margin-right: calc(var(--wp--style--root--padding-right) * -1); margin-left: calc(var(--wp--style--root--padding-left) * -1); } ' ;
2823
- // The above rule is negated for alignfull children of nested containers.
2824
- $ css .= '.has-global-padding :where(.has-global-padding:not(.wp-block-block)) > .alignfull { margin-right: 0; margin-left: 0; } ' ;
2825
- // Some of the children of alignfull blocks without content width should also get padding: text blocks and non-alignfull container blocks.
2826
- $ css .= '.has-global-padding > .alignfull:where(:not(.has-global-padding):not(.is-layout-flex):not(.is-layout-grid)) > :where([class*="wp-block-"]:not(.alignfull):not([class*="__"]),.wp-block:not(.alignfull),p,h1,h2,h3,h4,h5,h6,ul,ol) { padding-right: var(--wp--style--root--padding-right); padding-left: var(--wp--style--root--padding-left); } ' ;
2827
- // The above rule also has to be negated for blocks inside nested `.has-global-padding` blocks.
2828
- $ css .= '.has-global-padding :where(.has-global-padding) > .alignfull:where(:not(.has-global-padding)) > :where([class*="wp-block-"]:not(.alignfull):not([class*="__"]),.wp-block:not(.alignfull),p,h1,h2,h3,h4,h5,h6,ul,ol) { padding-right: 0; padding-left: 0; } ' ;
2823
+ // Nested children of the container with left and right padding that are not wide or full aligned do not get padding.
2824
+ $ css .= '.has-global-padding :where(.has-global-padding:not(.wp-block-block, .alignfull, .alignwide)) { padding-right: 0; padding-left: 0; } ' ;
2825
+ // Nested children of the container with left and right padding that are not wide or full aligned do not get negative margin applied.
2826
+ $ css .= '.has-global-padding :where(.has-global-padding:not(.wp-block-block, .alignfull, .alignwide)) > .alignfull { margin-left: 0; margin-right: 0; } ' ;
2829
2827
}
2830
2828
2831
2829
$ css .= '.wp-site-blocks > .alignleft { float: left; margin-right: 2em; } ' ;
0 commit comments