Make WordPress Core


Ignore:
Timestamp:
02/02/2023 06:50:54 PM (23 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/script-loader.php

    r55179 r55192  
    24562456
    24572457/**
     2458 * Enqueues the global styles custom css defined via theme.json.
     2459 *
     2460 * @since 6.2.0
     2461 */
     2462function wp_enqueue_global_styles_custom_css() {
     2463    if ( ! wp_is_block_theme() ) {
     2464        return;
     2465    }
     2466
     2467    // Don't enqueue Customizer's custom CSS separately.
     2468    remove_action( 'wp_head', 'wp_custom_css_cb', 101 );
     2469
     2470    $custom_css  = wp_get_custom_css();
     2471    $custom_css .= wp_get_global_styles_custom_css();
     2472
     2473    if ( ! empty( $custom_css ) ) {
     2474        wp_add_inline_style( 'global-styles', $custom_css );
     2475    }
     2476}
     2477
     2478/**
    24582479 * Renders the SVG filters supplied by theme.json.
    24592480 *
Note: See TracChangeset for help on using the changeset viewer.