Make WordPress Core


Ignore:
Timestamp:
02/02/2023 06:50:54 PM (22 months ago)
Author:
flixos90
Message:

Editor: Add support for custom CSS in global styles.

This changeset introduces functions wp_get_global_styles_custom_css() and wp_enqueue_global_styles_custom_css(), which allow accessing and enqueuing custom CSS added via global styles.

Custom CSS via global styles is handled separately from custom CSS via the Customizer. If a site uses both features, the custom CSS from both sources will be loaded. The global styles custom CSS is then loaded after the Customizer custom CSS, so if there are any conflicts between the rules, the global styles take precedence.

Similarly to e.g. [55185], the result is cached in a non-persistent cache, except when WP_DEBUG is on to avoid interrupting the theme developer's workflow.

Props glendaviesnz, oandregal, ntsekouras, mamaduka, davidbaumwald, hellofromtonya, flixos90.
Fixes #57536.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/block-editor.php

    r55181 r55192  
    411411            $global_styles[]      = $block_classes;
    412412        }
     413
     414        /*
     415         * Add the custom CSS as a separate stylesheet so any invalid CSS
     416         * entered by users does not break other global styles.
     417         */
     418        $editor_settings['styles'][] = array(
     419            'css'            => wp_get_global_styles_custom_css(),
     420            '__unstableType' => 'user',
     421            'isGlobalStyles' => true,
     422        );
    413423    } else {
    414424        // If there is no `theme.json` file, ensure base layout styles are still available.
Note: See TracChangeset for help on using the changeset viewer.