Make WordPress Core


Ignore:
Timestamp:
05/03/2024 04:45:20 AM (9 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-css-rules-store.php

    r55819 r58089  
    122122     *
    123123     * @since 6.1.0
     124     * @since 6.6.0 Added the $rules_group parameter.
    124125     *
    125126     * @param string $selector The CSS selector.
     127     * @param string $rules_group A parent CSS selector in the case of nested CSS, or a CSS nested @rule,
     128     *                            such as `@media (min-width: 80rem)` or `@layer module`.
    126129     * @return WP_Style_Engine_CSS_Rule|void Returns a WP_Style_Engine_CSS_Rule object,
    127130     *                                       or void if the selector is empty.
    128131     */
    129     public function add_rule( $selector ) {
    130         $selector = trim( $selector );
     132    public function add_rule( $selector, $rules_group = '' ) {
     133        $selector    = $selector ? trim( $selector ) : '';
     134        $rules_group = $rules_group ? trim( $rules_group ) : '';
    131135
    132136        // Bail early if there is no selector.
    133137        if ( empty( $selector ) ) {
    134138            return;
     139        }
     140
     141        if ( ! empty( $rules_group ) ) {
     142            if ( empty( $this->rules[ "$rules_group $selector" ] ) ) {
     143                $this->rules[ "$rules_group $selector" ] = new WP_Style_Engine_CSS_Rule( $selector, array(), $rules_group );
     144            }
     145            return $this->rules[ "$rules_group $selector" ];
    135146        }
    136147
Note: See TracChangeset for help on using the changeset viewer.