Changeset 58987
- Timestamp:
- 09/04/2024 02:22:16 PM (6 weeks ago)
- Location:
- branches/6.6
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/6.6
-
branches/6.6/src/wp-includes/class-wp-theme-json.php
r58986 r58987 1440 1440 $processed_css = ''; 1441 1441 1442 if ( empty( $css ) ) { 1443 return $processed_css; 1444 } 1445 1442 1446 // Split CSS nested rules. 1443 1447 $parts = explode( '&', $css ); 1444 1448 foreach ( $parts as $part ) { 1449 if ( empty( $part ) ) { 1450 continue; 1451 } 1445 1452 $is_root_css = ( ! str_contains( $part, '{' ) ); 1446 1453 if ( $is_root_css ) { … … 1455 1462 $nested_selector = $part[0]; 1456 1463 $css_value = $part[1]; 1457 $part_selector = str_starts_with( $nested_selector, ' ' ) 1464 1465 /* 1466 * Handle pseudo elements such as ::before, ::after etc. Regex will also 1467 * capture any leading combinator such as >, +, or ~, as well as spaces. 1468 * This allows pseudo elements as descendants e.g. `.parent ::before`. 1469 */ 1470 $matches = array(); 1471 $has_pseudo_element = preg_match( '/([>+~\s]*::[a-zA-Z-]+)/', $nested_selector, $matches ); 1472 $pseudo_part = $has_pseudo_element ? $matches[1] : ''; 1473 $nested_selector = $has_pseudo_element ? str_replace( $pseudo_part, '', $nested_selector ) : $nested_selector; 1474 1475 // Finalize selector and re-append pseudo element if required. 1476 $part_selector = str_starts_with( $nested_selector, ' ' ) 1458 1477 ? static::scope_selector( $selector, $nested_selector ) 1459 1478 : static::append_to_selector( $selector, $nested_selector ); 1460 $final_selector = ":root :where($part_selector)"; 1461 $processed_css .= $final_selector . '{' . trim( $css_value ) . '}';} 1479 $final_selector = ":root :where($part_selector)$pseudo_part"; 1480 1481 $processed_css .= $final_selector . '{' . trim( $css_value ) . '}'; 1482 } 1462 1483 } 1463 1484 return $processed_css; -
branches/6.6/tests/phpunit/tests/theme/wpThemeJson.php
r58986 r58987 5154 5154 /** 5155 5155 * @ticket 61165 5156 * @ticket 61769 5156 5157 * 5157 5158 * @dataProvider data_process_blocks_custom_css … … 5181 5182 return array( 5182 5183 // Simple CSS without any nested selectors. 5184 'empty css' => array( 5185 'input' => array( 5186 'selector' => '.foo', 5187 'css' => '', 5188 ), 5189 'expected' => '', 5190 ), 5183 5191 'no nested selectors' => array( 5184 5192 'input' => array( … … 5196 5204 'expected' => ':root :where(.foo){color: red; margin: auto;}:root :where(.foo.one){color: blue;}:root :where(.foo .two){color: green;}', 5197 5205 ), 5206 'no root styles' => array( 5207 'input' => array( 5208 'selector' => '.foo', 5209 'css' => '&::before{color: red;}', 5210 ), 5211 'expected' => ':root :where(.foo)::before{color: red;}', 5212 ), 5198 5213 // CSS with pseudo elements. 5199 5214 'with pseudo elements' => array( … … 5202 5217 'css' => 'color: red; margin: auto; &::before{color: blue;} & ::before{color: green;} &.one::before{color: yellow;} & .two::before{color: purple;}', 5203 5218 ), 5204 'expected' => ':root :where(.foo){color: red; margin: auto;}:root :where(.foo ::before){color: blue;}:root :where(.foo ::before){color: green;}:root :where(.foo.one::before){color: yellow;}:root :where(.foo .two::before){color: purple;}',5219 'expected' => ':root :where(.foo){color: red; margin: auto;}:root :where(.foo)::before{color: blue;}:root :where(.foo) ::before{color: green;}:root :where(.foo.one)::before{color: yellow;}:root :where(.foo .two)::before{color: purple;}', 5205 5220 ), 5206 5221 // CSS with multiple root selectors. … … 5210 5225 'css' => 'color: red; margin: auto; &.one{color: blue;} & .two{color: green;} &::before{color: yellow;} & ::before{color: purple;} &.three::before{color: orange;} & .four::before{color: skyblue;}', 5211 5226 ), 5212 'expected' => ':root :where(.foo, .bar){color: red; margin: auto;}:root :where(.foo.one, .bar.one){color: blue;}:root :where(.foo .two, .bar .two){color: green;}:root :where(.foo ::before, .bar::before){color: yellow;}:root :where(.foo ::before, .bar ::before){color: purple;}:root :where(.foo.three::before, .bar.three::before){color: orange;}:root :where(.foo .four::before, .bar .four::before){color: skyblue;}',5227 'expected' => ':root :where(.foo, .bar){color: red; margin: auto;}:root :where(.foo.one, .bar.one){color: blue;}:root :where(.foo .two, .bar .two){color: green;}:root :where(.foo, .bar)::before{color: yellow;}:root :where(.foo, .bar) ::before{color: purple;}:root :where(.foo.three, .bar.three)::before{color: orange;}:root :where(.foo .four, .bar .four)::before{color: skyblue;}', 5213 5228 ), 5214 5229 );
Note: See TracChangeset
for help on using the changeset viewer.