Changeset 58703
- Timestamp:
- 07/10/2024 06:17:44 AM (10 months ago)
- Location:
- trunk
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/block-editor.php
r58328 r58703 533 533 */ 534 534 $global_styles[] = array( 535 'css' => wp_get_global_styles _custom_css(),535 'css' => wp_get_global_stylesheet( array( 'custom-css' ) ), 536 536 '__unstableType' => 'user', 537 537 'isGlobalStyles' => true, -
trunk/src/wp-includes/class-wp-theme-json.php
r58685 r58703 1424 1424 } 1425 1425 1426 // Load the custom CSS last so it has the highest specificity. 1427 if ( in_array( 'custom-css', $types, true ) ) { 1428 // Add the global styles root CSS. 1429 $stylesheet .= _wp_array_get( $this->theme_json, array( 'styles', 'css' ) ); 1430 } 1431 1426 1432 return $stylesheet; 1427 1433 } … … 1468 1474 * 1469 1475 * @since 6.2.0 1476 * @deprecated 6.7.0 Use {@see 'get_stylesheet'} instead. 1470 1477 * 1471 1478 * @return string The global styles custom CSS. 1472 1479 */ 1473 1480 public function get_custom_css() { 1481 _deprecated_function( __METHOD__, '6.7.0', 'get_stylesheet' ); 1474 1482 // Add the global styles root CSS. 1475 1483 $stylesheet = isset( $this->theme_json['styles']['css'] ) ? $this->theme_json['styles']['css'] : ''; … … 2693 2701 'features' => $feature_selectors, 2694 2702 'variations' => $variation_selectors, 2703 'css' => $selector, 2695 2704 ); 2696 2705 … … 2909 2918 } 2910 2919 2911 // 7. Generate and append any custom CSS rules pertaining to nested block style variations.2920 // 7. Generate and append any custom CSS rules. 2912 2921 if ( isset( $node['css'] ) && ! $is_root_selector ) { 2913 2922 $block_rules .= $this->process_blocks_custom_css( $node['css'], $selector ); -
trunk/src/wp-includes/default-filters.php
r58381 r58703 601 601 add_action( 'wp_footer', 'wp_enqueue_global_styles', 1 ); 602 602 603 // Global styles custom CSS.604 add_action( 'wp_enqueue_scripts', 'wp_enqueue_global_styles_custom_css' );605 606 603 // Block supports, and other styles parsed and stored in the Style Engine. 607 604 add_action( 'wp_enqueue_scripts', 'wp_enqueue_stored_styles' ); -
trunk/src/wp-includes/deprecated.php
r58322 r58703 6311 6311 return $parsed_block; 6312 6312 } 6313 6314 /** 6315 * Gets the global styles custom CSS from theme.json. 6316 * 6317 * @since 6.2.0 6318 * @deprecated 6.7.0 Use {@see 'wp_get_global_stylesheet'} instead. 6319 * 6320 * @return string The global styles custom CSS. 6321 */ 6322 function wp_get_global_styles_custom_css() { 6323 _deprecated_function( __FUNCTION__, '6.7.0', 'wp_get_global_stylesheet' ); 6324 if ( ! wp_theme_has_theme_json() ) { 6325 return ''; 6326 } 6327 /* 6328 * Ignore cache when the development mode is set to 'theme', so it doesn't interfere with the theme 6329 * developer's workflow. 6330 */ 6331 $can_use_cached = ! wp_is_development_mode( 'theme' ); 6332 6333 /* 6334 * By using the 'theme_json' group, this data is marked to be non-persistent across requests. 6335 * @see `wp_cache_add_non_persistent_groups()`. 6336 * 6337 * The rationale for this is to make sure derived data from theme.json 6338 * is always fresh from the potential modifications done via hooks 6339 * that can use dynamic data (modify the stylesheet depending on some option, 6340 * settings depending on user permissions, etc.). 6341 * See some of the existing hooks to modify theme.json behavior: 6342 * @see https://make.wordpress.org/core/2022/10/10/filters-for-theme-json-data/ 6343 * 6344 * A different alternative considered was to invalidate the cache upon certain 6345 * events such as options add/update/delete, user meta, etc. 6346 * It was judged not enough, hence this approach. 6347 * @see https://github.com/WordPress/gutenberg/pull/45372 6348 */ 6349 $cache_key = 'wp_get_global_styles_custom_css'; 6350 $cache_group = 'theme_json'; 6351 if ( $can_use_cached ) { 6352 $cached = wp_cache_get( $cache_key, $cache_group ); 6353 if ( $cached ) { 6354 return $cached; 6355 } 6356 } 6357 6358 $tree = WP_Theme_JSON_Resolver::get_merged_data(); 6359 $stylesheet = $tree->get_custom_css(); 6360 6361 if ( $can_use_cached ) { 6362 wp_cache_set( $cache_key, $stylesheet, $cache_group ); 6363 } 6364 6365 return $stylesheet; 6366 } 6367 6368 /** 6369 * Enqueues the global styles custom css defined via theme.json. 6370 * 6371 * @since 6.2.0 6372 * @deprecated 6.7.0 Use {@see 'wp_enqueue_global_styles'} instead. 6373 */ 6374 function wp_enqueue_global_styles_custom_css() { 6375 _deprecated_function( __FUNCTION__, '6.7.0', 'wp_enqueue_global_styles' ); 6376 if ( ! wp_is_block_theme() ) { 6377 return; 6378 } 6379 6380 // Don't enqueue Customizer's custom CSS separately. 6381 remove_action( 'wp_head', 'wp_custom_css_cb', 101 ); 6382 6383 $custom_css = wp_get_custom_css(); 6384 $custom_css .= wp_get_global_styles_custom_css(); 6385 6386 if ( ! empty( $custom_css ) ) { 6387 wp_add_inline_style( 'global-styles', $custom_css ); 6388 } 6389 } -
trunk/src/wp-includes/global-styles-and-settings.php
r58334 r58703 237 237 238 238 $stylesheet = $styles_variables . $styles_rest; 239 if ( $can_use_cached ) {240 wp_cache_set( $cache_key, $stylesheet, $cache_group );241 }242 243 return $stylesheet;244 }245 246 /**247 * Gets the global styles custom CSS from theme.json.248 *249 * @since 6.2.0250 *251 * @return string The global styles custom CSS.252 */253 function wp_get_global_styles_custom_css() {254 if ( ! wp_theme_has_theme_json() ) {255 return '';256 }257 /*258 * Ignore cache when the development mode is set to 'theme', so it doesn't interfere with the theme259 * developer's workflow.260 */261 $can_use_cached = ! wp_is_development_mode( 'theme' );262 263 /*264 * By using the 'theme_json' group, this data is marked to be non-persistent across requests.265 * @see `wp_cache_add_non_persistent_groups()`.266 *267 * The rationale for this is to make sure derived data from theme.json268 * is always fresh from the potential modifications done via hooks269 * that can use dynamic data (modify the stylesheet depending on some option,270 * settings depending on user permissions, etc.).271 * See some of the existing hooks to modify theme.json behavior:272 * @see https://make.wordpress.org/core/2022/10/10/filters-for-theme-json-data/273 *274 * A different alternative considered was to invalidate the cache upon certain275 * events such as options add/update/delete, user meta, etc.276 * It was judged not enough, hence this approach.277 * @see https://github.com/WordPress/gutenberg/pull/45372278 */279 $cache_key = 'wp_get_global_styles_custom_css';280 $cache_group = 'theme_json';281 if ( $can_use_cached ) {282 $cached = wp_cache_get( $cache_key, $cache_group );283 if ( $cached ) {284 return $cached;285 }286 }287 288 $tree = WP_Theme_JSON_Resolver::get_merged_data();289 $stylesheet = $tree->get_custom_css();290 291 239 if ( $can_use_cached ) { 292 240 wp_cache_set( $cache_key, $stylesheet, $cache_group ); -
trunk/src/wp-includes/script-loader.php
r58408 r58703 2505 2505 $stylesheet = wp_get_global_stylesheet(); 2506 2506 2507 if ( $is_block_theme ) { 2508 /* 2509 * Dequeue the Customizer's custom CSS 2510 * and add it before the global styles custom CSS. 2511 */ 2512 remove_action( 'wp_head', 'wp_custom_css_cb', 101 ); 2513 // Get the custom CSS from the Customizer and add it to the global stylesheet. 2514 $custom_css = wp_get_custom_css(); 2515 $stylesheet .= $custom_css; 2516 2517 // Add the global styles custom CSS at the end. 2518 $stylesheet .= wp_get_global_stylesheet( array( 'custom-css' ) ); 2519 } 2520 2507 2521 if ( empty( $stylesheet ) ) { 2508 2522 return; … … 2515 2529 // Add each block as an inline css. 2516 2530 wp_add_global_styles_for_blocks(); 2517 }2518 2519 /**2520 * Enqueues the global styles custom css defined via theme.json.2521 *2522 * @since 6.2.02523 */2524 function wp_enqueue_global_styles_custom_css() {2525 if ( ! wp_is_block_theme() ) {2526 return;2527 }2528 2529 // Don't enqueue Customizer's custom CSS separately.2530 remove_action( 'wp_head', 'wp_custom_css_cb', 101 );2531 2532 $custom_css = wp_get_custom_css();2533 $custom_css .= wp_get_global_styles_custom_css();2534 2535 if ( ! empty( $custom_css ) ) {2536 wp_add_inline_style( 'global-styles', $custom_css );2537 }2538 2531 } 2539 2532 -
trunk/tests/phpunit/tests/theme/wpThemeJson.php
r58685 r58703 5036 5036 5037 5037 /** 5038 * @ticket 57536 5039 * @ticket 61165 5040 */ 5041 public function test_get_custom_css_handles_global_custom_css() { 5038 * Tests that base custom CSS is generated correctly. 5039 * 5040 * @ticket 61395 5041 */ 5042 public function test_get_stylesheet_handles_base_custom_css() { 5042 5043 $theme_json = new WP_Theme_JSON( 5043 5044 array( 5044 5045 'version' => WP_Theme_JSON::LATEST_SCHEMA, 5045 5046 'styles' => array( 5046 'css' => 'body {color:purple;}', 5047 'css' => 'body {color:purple;}', 5048 ), 5049 ) 5050 ); 5051 5052 $custom_css = 'body {color:purple;}'; 5053 $this->assertSame( $custom_css, $theme_json->get_stylesheet( array( 'custom-css' ) ) ); 5054 } 5055 5056 /** 5057 * Tests that block custom CSS is generated correctly. 5058 * 5059 * @ticket 61395 5060 */ 5061 public function test_get_styles_for_block_handles_block_custom_css() { 5062 $theme_json = new WP_Theme_JSON( 5063 array( 5064 'version' => WP_Theme_JSON::LATEST_SCHEMA, 5065 'styles' => array( 5047 5066 'blocks' => array( 5048 5067 'core/paragraph' => array( … … 5054 5073 ); 5055 5074 5056 $custom_css = 'body {color:purple;}:root :where(p){color:red;}'; 5057 $this->assertSame( $custom_css, $theme_json->get_custom_css() ); 5075 $paragraph_node = array( 5076 'name' => 'core/paragraph', 5077 'path' => array( 'styles', 'blocks', 'core/paragraph' ), 5078 'selector' => 'p', 5079 'selectors' => array( 5080 'root' => 'p', 5081 ), 5082 ); 5083 5084 $custom_css = ':root :where(p){color:red;}'; 5085 $this->assertSame( $custom_css, $theme_json->get_styles_for_block( $paragraph_node ) ); 5058 5086 } 5059 5087
Note: See TracChangeset
for help on using the changeset viewer.