Changeset 58703
- Timestamp:
- 07/10/2024 06:17:44 AM (4 weeks 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_styles), 536 536 '__unstableType' => 'user', 537 537 'isGlobalStyles' => true, -
trunk/src/wp-includes/class-wp-theme-json.php
r58685 r58703 1424 1424 } 1425 1425 1426 1427 1428 1429 1430 1431 1426 1432 return $stylesheet; 1427 1433 } … … 1468 1474 * 1469 1475 * @since 6.2.0 1476 1470 1477 * 1471 1478 * @return string The global styles custom CSS. 1472 1479 */ 1473 1480 public function get_custom_css() { 1481 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 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 6316 6317 6318 6319 6320 6321 6322 6323 6324 6325 6326 6327 6328 6329 6330 6331 6332 6333 6334 6335 6336 6337 6338 6339 6340 6341 6342 6343 6344 6345 6346 6347 6348 6349 6350 6351 6352 6353 6354 6355 6356 6357 6358 6359 6360 6361 6362 6363 6364 6365 6366 6367 6368 6369 6370 6371 6372 6373 6374 6375 6376 6377 6378 6379 6380 6381 6382 6383 6384 6385 6386 6387 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 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 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.