Skip to content

Commit 57ad9f1

Browse files
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
1 parent 97790af commit 57ad9f1

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/wp-includes/script-loader.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2300,8 +2300,9 @@ function wp_enqueue_global_styles() {
23002300
);
23012301

23022302
$stylesheet = null;
2303+
$transient_name = 'global_styles_' . get_stylesheet();
23032304
if ( $can_use_cache ) {
2304-
$cache = get_transient( 'global_styles' );
2305+
$cache = get_transient( $transient_name );
23052306
if ( $cache ) {
23062307
$stylesheet = $cache;
23072308
}
@@ -2313,7 +2314,7 @@ function wp_enqueue_global_styles() {
23132314
$stylesheet = $theme_json->get_stylesheet();
23142315

23152316
if ( $can_use_cache ) {
2316-
set_transient( 'global_styles', $stylesheet, MINUTE_IN_SECONDS );
2317+
set_transient( $transient_name, $stylesheet, MINUTE_IN_SECONDS );
23172318
}
23182319
}
23192320

0 commit comments

Comments
 (0)