Make WordPress Core


Ignore:
Timestamp:
05/03/2024 04:45:20 AM (13 months ago)
Author:
isabel_brison
Message:

Editor: add Style Engine support for nested CSS rules.

Adds support for passing a $rules_group string to wp_style_engine_get_stylesheet_from_css_rules(), so rules can be nested under a media query, layer or other rule.

Props isabel_brison, ramonopoly.
Fixes #61099.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/style-engine/class-wp-style-engine-processor.php

    r56574 r58089  
    5959     *
    6060     * @since 6.1.0
     61     * @since 6.6.0 Added support for rules_group.
    6162     *
    6263     * @param WP_Style_Engine_CSS_Rule|WP_Style_Engine_CSS_Rule[] $css_rules A single, or an array of,
     
    7172
    7273        foreach ( $css_rules as $rule ) {
    73             $selector = $rule->get_selector();
     74            $selector    = $rule->get_selector();
     75            $rules_group = $rule->get_rules_group();
     76
     77            /**
     78             * If there is a rules_group and it already exists in the css_rules array,
     79             * add the rule to it.
     80             * Otherwise, create a new entry for the rules_group.
     81             */
     82            if ( ! empty( $rules_group ) ) {
     83                if ( isset( $this->css_rules[ "$rules_group $selector" ] ) ) {
     84                    $this->css_rules[ "$rules_group $selector" ]->add_declarations( $rule->get_declarations() );
     85                    continue;
     86                }
     87                $this->css_rules[ "$rules_group $selector" ] = $rule;
     88                continue;
     89            }
     90
     91            // If the selector already exists, add the declarations to it.
    7492            if ( isset( $this->css_rules[ $selector ] ) ) {
    7593                $this->css_rules[ $selector ]->add_declarations( $rule->get_declarations() );
     
    118136        $css = '';
    119137        foreach ( $this->css_rules as $rule ) {
     138            // See class WP_Style_Engine_CSS_Rule for the get_css method.
    120139            $css .= $rule->get_css( $options['prettify'] );
    121140            $css .= $options['prettify'] ? "\n" : '';
Note: See TracChangeset for help on using the changeset viewer.