Skip to content

Commit

Permalink
Minor updates to get_global_styles_custom_css
Browse files Browse the repository at this point in the history
  • Loading branch information
Mamaduka committed Jan 30, 2023
1 parent e99246d commit 0f82606
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
2 changes: 1 addition & 1 deletion lib/compat/wordpress-6.2/block-editor-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
Expand Down
15 changes: 7 additions & 8 deletions lib/compat/wordpress-6.2/get-global-styles-and-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand All @@ -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 ) {
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;
}

/**
Expand Down Expand Up @@ -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();
}

Expand Down
4 changes: 2 additions & 2 deletions lib/compat/wordpress-6.2/script-loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ function gutenberg_enqueue_global_styles_custom_css() {
// Don't enqueue Customizer's custom CSS separately.
remove_action( 'wp_head', 'wp_custom_css_cb', 101 );

$custom_css = wp_get_custom_css();
$custom_css .= get_global_styles_custom_css();
$custom_css = wp_get_custom_css();
$custom_css .= gutenberg_get_global_styles_custom_css();

if ( ! empty( $custom_css ) ) {
wp_add_inline_style( 'global-styles', $custom_css );
Expand Down

0 comments on commit 0f82606

Please sign in to comment.