Make WordPress Core

Changeset 56812


Ignore:
Timestamp:
10/10/2023 03:41:38 AM (3 years ago)
Author:
isabel_brison
Message:

Editor: fix incorrect block custom CSS output.

Fixes output of block custom CSS when multiple rules require a descendant selector.

Props wildworks, mikachan.
Fixes #59499.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-theme-json.php

    r56778 r56812  
    11471147                $parts = explode( '&', $css );
    11481148                foreach ( $parts as $part ) {
    1149                         $processed_css .= ( ! str_contains( $part, '{' ) )
    1150                                 ? trim( $selector ) . '{' . trim( $part ) . '}' // If the part doesn't contain braces, it applies to the root level.
    1151                                 : trim( $selector . $part ); // Prepend the selector, which effectively replaces the "&" character.
     1149                        $is_root_css = ( ! str_contains( $part, '{' ) );
     1150                        if ( $is_root_css ) {
     1151                                // If the part doesn't contain braces, it applies to the root level.
     1152                                $processed_css .= trim( $selector ) . '{' . trim( $part ) . '}';
     1153                        } else {
     1154                                // If the part contains braces, it's a nested CSS rule.
     1155                                $part = explode( '{', str_replace( '}', '', $part ) );
     1156                                if ( count( $part ) !== 2 ) {
     1157                                        continue;
     1158                                }
     1159                                $nested_selector = $part[0];
     1160                                $css_value       = $part[1];
     1161                                $part_selector   = str_starts_with( $nested_selector, ' ' )
     1162                                        ? static::scope_selector( $selector, $nested_selector )
     1163                                        : static::append_to_selector( $selector, $nested_selector );
     1164                                $processed_css  .= $part_selector . '{' . trim( $css_value ) . '}';
     1165                        }
    11521166                }
    11531167                return $processed_css;
Note: See TracChangeset for help on using the changeset viewer.