Changeset 55192 for trunk/src/wp-includes/global-styles-and-settings.php
- Timestamp:
- 02/02/2023 06:50:54 PM (22 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/global-styles-and-settings.php
r55185 r55192 219 219 220 220 $stylesheet = $styles_variables . $styles_rest; 221 if ( $can_use_cached ) { 222 wp_cache_set( $cache_key, $stylesheet, $cache_group ); 223 } 224 225 return $stylesheet; 226 } 227 228 /** 229 * Gets the global styles custom css from theme.json. 230 * 231 * @since 6.2.0 232 * 233 * @return string Stylesheet. 234 */ 235 function wp_get_global_styles_custom_css() { 236 if ( ! wp_theme_has_theme_json() ) { 237 return ''; 238 } 239 /* 240 * Ignore cache when `WP_DEBUG` is enabled, so it doesn't interfere with the theme 241 * developer's workflow. 242 * 243 * @todo Replace `WP_DEBUG` once an "in development mode" check is available in Core. 244 */ 245 $can_use_cached = ! WP_DEBUG; 246 247 /* 248 * By using the 'theme_json' group, this data is marked to be non-persistent across requests. 249 * @see `wp_cache_add_non_persistent_groups()`. 250 * 251 * The rationale for this is to make sure derived data from theme.json 252 * is always fresh from the potential modifications done via hooks 253 * that can use dynamic data (modify the stylesheet depending on some option, 254 * settings depending on user permissions, etc.). 255 * See some of the existing hooks to modify theme.json behavior: 256 * @see https://make.wordpress.org/core/2022/10/10/filters-for-theme-json-data/ 257 * 258 * A different alternative considered was to invalidate the cache upon certain 259 * events such as options add/update/delete, user meta, etc. 260 * It was judged not enough, hence this approach. 261 * @see https://github.com/WordPress/gutenberg/pull/45372 262 */ 263 $cache_key = 'wp_get_global_styles_custom_css'; 264 $cache_group = 'theme_json'; 265 if ( $can_use_cached ) { 266 $cached = wp_cache_get( $cache_key, $cache_group ); 267 if ( $cached ) { 268 return $cached; 269 } 270 } 271 272 $tree = WP_Theme_JSON_Resolver::get_merged_data(); 273 $stylesheet = $tree->get_custom_css(); 274 221 275 if ( $can_use_cached ) { 222 276 wp_cache_set( $cache_key, $stylesheet, $cache_group ); … … 370 424 wp_cache_delete( 'wp_get_global_settings_custom', 'theme_json' ); 371 425 wp_cache_delete( 'wp_get_global_settings_theme', 'theme_json' ); 426 wp_cache_delete( 'wp_get_global_styles_custom_css', 'theme_json' ); 372 427 WP_Theme_JSON_Resolver::clean_cached_data(); 373 428 }
Note: See TracChangeset
for help on using the changeset viewer.