From 57ad9f16dff35a879e856566489266472589ea04 Mon Sep 17 00:00:00 2001 From: Jorge Costa Date: Thu, 16 Sep 2021 18:03:04 +0000 Subject: [PATCH] Block editor: Cache global stylesheet by theme key. Global styles are used in a few different contexts (front, editor, customizer, the theme directory). In the last two contexts, it's important that switching themes immediately refreshes the global stylesheet, to avoid situations in which the styles of the previous theme load with the new one. This was brought up at WordPress/gutenberg#34531 (customizer) and at meta.trac.wordpress.org/ticket/5818 (theme directory). This commit makes sure the stylesheet is regenerated upon switching themes. Props oandregal, dd32. See #53175. git-svn-id: https://develop.svn.wordpress.org/trunk@51819 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/script-loader.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/wp-includes/script-loader.php b/src/wp-includes/script-loader.php index 9e0d5cb721..0a6ce2637c 100644 --- a/src/wp-includes/script-loader.php +++ b/src/wp-includes/script-loader.php @@ -2300,8 +2300,9 @@ function wp_enqueue_global_styles() { ); $stylesheet = null; + $transient_name = 'global_styles_' . get_stylesheet(); if ( $can_use_cache ) { - $cache = get_transient( 'global_styles' ); + $cache = get_transient( $transient_name ); if ( $cache ) { $stylesheet = $cache; } @@ -2313,7 +2314,7 @@ function wp_enqueue_global_styles() { $stylesheet = $theme_json->get_stylesheet(); if ( $can_use_cache ) { - set_transient( 'global_styles', $stylesheet, MINUTE_IN_SECONDS ); + set_transient( $transient_name, $stylesheet, MINUTE_IN_SECONDS ); } }