Changeset 55950
- Timestamp:
- 06/20/2023 05:52:32 PM (17 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-theme-json.php
r55945 r55950 796 796 * @since 5.8.0 797 797 * @since 6.1.0 Added append position. 798 * @since 6.3.0 Removed append position parameter. 798 799 * 799 800 * @param string $selector Original selector. 800 801 * @param string $to_append Selector to append. 801 * @param string $position A position sub-selector should be appended. Default 'right'.802 802 * @return string The new selector. 803 803 */ 804 protected static function append_to_selector( $selector, $to_append , $position = 'right') {804 protected static function append_to_selector( $selector, $to_append ) { 805 805 if ( ! str_contains( $selector, ',' ) ) { 806 return 'right' === $position ? $selector . $to_append : $to_append . $selector;806 return $selector . $to_append; 807 807 } 808 808 $new_selectors = array(); 809 809 $selectors = explode( ',', $selector ); 810 810 foreach ( $selectors as $sel ) { 811 $new_selectors[] = 'right' === $position ? $sel . $to_append : $to_append . $sel; 811 $new_selectors[] = $sel . $to_append; 812 } 813 return implode( ',', $new_selectors ); 814 } 815 816 /** 817 * Prepends a sub-selector to an existing one. 818 * 819 * Given the compounded $selector "h1, h2, h3" 820 * and the $to_prepend selector ".some-class " the result will be 821 * ".some-class h1, .some-class h2, .some-class h3". 822 * 823 * @since 6.3.0 824 * 825 * @param string $selector Original selector. 826 * @param string $to_prepend Selector to prepend. 827 * @return string The new selector. 828 */ 829 protected static function prepend_to_selector( $selector, $to_prepend ) { 830 if ( ! str_contains( $selector, ',' ) ) { 831 return $to_prepend . $selector; 832 } 833 $new_selectors = array(); 834 $selectors = explode( ',', $selector ); 835 foreach ( $selectors as $sel ) { 836 $new_selectors[] = $to_prepend . $sel; 812 837 } 813 838 return implode( ',', $new_selectors ); … … 901 926 break; 902 927 } 903 $element_selector[] = static:: append_to_selector( $el_selector, $selector . ' ', 'left' );928 $element_selector[] = static::prepend_to_selector( $el_selector, $selector . ' ' ); 904 929 } 905 930 static::$blocks_metadata[ $block_name ]['elements'][ $el_name ] = implode( ',', $element_selector ); … … 1538 1563 foreach ( $preset_metadata['classes'] as $class => $property ) { 1539 1564 foreach ( $slugs as $slug ) { 1540 $css_var = static::replace_slug_in_string( $preset_metadata['css_vars'], $slug ); 1541 $class_name = static::replace_slug_in_string( $class, $slug ); 1542 $stylesheet .= static::to_ruleset( 1543 static::append_to_selector( $selector, $class_name ), 1565 $css_var = static::replace_slug_in_string( $preset_metadata['css_vars'], $slug ); 1566 $class_name = static::replace_slug_in_string( $class, $slug ); 1567 1568 // $selector is often empty, so we can save ourselves the `append_to_selector()` call then. 1569 $new_selector = '' === $selector ? $class_name : static::append_to_selector( $selector, $class_name ); 1570 $stylesheet .= static::to_ruleset( 1571 $new_selector, 1544 1572 array( 1545 1573 array(
Note: See TracChangeset
for help on using the changeset viewer.