Make WordPress Core


Ignore:
Timestamp:
02/03/2023 06:23:55 PM (16 months ago)
Author:
flixos90
Message:

Editor: Add missing WP_Theme_JSON::process_blocks_custom_css() method.

Follow up to [55192].

Props aristath, mamaduka, mukesh27, hellofromtonya.
Fixes #57621.

File:
1 edited

Legend:

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

    r55192 r55216  
    10081008
    10091009    /**
     1010     * Processes the CSS, to apply nesting.
     1011     *
     1012     * @since 6.2.0
     1013     *
     1014     * @param string $css      The CSS to process.
     1015     * @param string $selector The selector to nest.
     1016     * @return string The processed CSS.
     1017     */
     1018    protected function process_blocks_custom_css( $css, $selector ) {
     1019        $processed_css = '';
     1020
     1021        // Split CSS nested rules.
     1022        $parts = explode( '&', $css );
     1023        foreach ( $parts as $part ) {
     1024            $processed_css .= ( ! str_contains( $part, '{' ) )
     1025                ? trim( $selector ) . '{' . trim( $part ) . '}' // If the part doesn't contain braces, it applies to the root level.
     1026                : trim( $selector . $part ); // Prepend the selector, which effectively replaces the "&" character.
     1027        }
     1028        return $processed_css;
     1029    }
     1030
     1031    /**
    10101032     * Returns the global styles custom css.
    10111033     *
    10121034     * @since 6.2.0
    10131035     *
    1014      * @return string
     1036     * @return string The global styles custom CSS.
    10151037     */
    10161038    public function get_custom_css() {
Note: See TracChangeset for help on using the changeset viewer.