diff --git a/lib/class-wp-theme-json-gutenberg.php b/lib/class-wp-theme-json-gutenberg.php index a67964ba345174..1ee24f86969baa 100644 --- a/lib/class-wp-theme-json-gutenberg.php +++ b/lib/class-wp-theme-json-gutenberg.php @@ -1092,7 +1092,7 @@ public function get_stylesheet( $types = array( 'variables', 'styles', 'presets' */ public function get_custom_css() { // Add the global styles root CSS. - $stylesheet = _wp_array_get( $this->theme_json, array( 'styles', 'css' ) ); + $stylesheet = _wp_array_get( $this->theme_json, array( 'styles', 'css' ), '' ); // Add the global styles block CSS. if ( isset( $this->theme_json['styles']['blocks'] ) ) { diff --git a/lib/compat/wordpress-6.2/block-editor-settings.php b/lib/compat/wordpress-6.2/block-editor-settings.php index b2eebb572e20f8..2fd8dc1e2f6bb8 100644 --- a/lib/compat/wordpress-6.2/block-editor-settings.php +++ b/lib/compat/wordpress-6.2/block-editor-settings.php @@ -16,7 +16,7 @@ function gutenberg_get_block_editor_settings_6_2( $settings ) { if ( wp_theme_has_theme_json() ) { // Add the custom CSS as separate style sheet so any invalid CSS entered by users does not break other global styles. $settings['styles'][] = array( - 'css' => get_global_styles_custom_css(), + 'css' => gutenberg_get_global_styles_custom_css(), '__unstableType' => 'user', 'isGlobalStyles' => true, ); diff --git a/lib/compat/wordpress-6.2/get-global-styles-and-settings.php b/lib/compat/wordpress-6.2/get-global-styles-and-settings.php index 74632d49a32570..e02a0466a0b98f 100644 --- a/lib/compat/wordpress-6.2/get-global-styles-and-settings.php +++ b/lib/compat/wordpress-6.2/get-global-styles-and-settings.php @@ -64,10 +64,10 @@ function wp_theme_has_theme_json_clean_cache() { * * @return string */ -function get_global_styles_custom_css() { +function gutenberg_get_global_styles_custom_css() { // Ignore cache when `WP_DEBUG` is enabled, so it doesn't interfere with the theme developers workflow. - $can_use_cached = empty( $types ) && ! WP_DEBUG; - $cache_key = 'gutenberg_get_global_custom_css_stylesheet'; + $can_use_cached = ! WP_DEBUG; + $cache_key = 'gutenberg_get_global_custom_css'; $cache_group = 'theme_json'; if ( $can_use_cached ) { $cached = wp_cache_get( $cache_key, $cache_group ); @@ -76,20 +76,18 @@ function get_global_styles_custom_css() { } } - $tree = WP_Theme_JSON_Resolver_Gutenberg::get_merged_data(); - $supports_theme_json = wp_theme_has_theme_json(); - - if ( ! $supports_theme_json ) { - return; + if ( ! wp_theme_has_theme_json() ) { + return ''; } + $tree = WP_Theme_JSON_Resolver_Gutenberg::get_merged_data(); $stylesheet = $tree->get_custom_css(); if ( $can_use_cached ) { wp_cache_set( $cache_key, $stylesheet, $cache_group ); } - return $stylesheet; + return $stylesheet; } /** @@ -227,6 +225,7 @@ function _gutenberg_clean_theme_json_caches() { wp_cache_delete( 'gutenberg_get_global_stylesheet', 'theme_json' ); wp_cache_delete( 'gutenberg_get_global_settings_custom', 'theme_json' ); wp_cache_delete( 'gutenberg_get_global_settings_theme', 'theme_json' ); + wp_cache_delete( 'gutenberg_get_global_custom_css', 'theme_json' ); WP_Theme_JSON_Resolver_Gutenberg::clean_cached_data(); } diff --git a/lib/compat/wordpress-6.2/script-loader.php b/lib/compat/wordpress-6.2/script-loader.php index 5f72151bd78160..05c2019cbd4f64 100644 --- a/lib/compat/wordpress-6.2/script-loader.php +++ b/lib/compat/wordpress-6.2/script-loader.php @@ -174,15 +174,18 @@ function( $settings ) { * @since 6.2.0 */ function gutenberg_enqueue_global_styles_custom_css() { - $custom_css = get_global_styles_custom_css(); - $is_block_theme = wp_is_block_theme(); - if ( $custom_css && $is_block_theme ) { - ?> - -