Changeset 55086
- Timestamp:
- 01/18/2023 11:38:16 AM (5 months ago)
- Location:
- trunk
- Files:
-
- 5 added
- 17 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/edit-form-blocks.php
r54663 r55086 204 204 'ajaxUrl' => admin_url( 'admin-ajax.php' ), 205 205 ), 206 'supportsLayout' => WP_Theme_JSON_Resolver::theme_has_support(),206 'supportsLayout' => wp_theme_has_theme_json(), 207 207 'supportsTemplateMode' => current_theme_supports( 'block-templates' ), 208 208 -
trunk/src/wp-admin/site-editor.php
r54817 r55086 75 75 'defaultTemplateTypes' => $indexed_template_types, 76 76 'defaultTemplatePartAreas' => get_allowed_block_template_part_areas(), 77 'supportsLayout' => WP_Theme_JSON_Resolver::theme_has_support(),77 'supportsLayout' => wp_theme_has_theme_json(), 78 78 'supportsTemplatePartsMode' => ! wp_is_block_theme() && current_theme_supports( 'block-template-parts' ), 79 79 '__unstableHomeTemplate' => $home_template, -
trunk/src/wp-includes/block-editor.php
r54776 r55086 418 418 } 419 419 420 if ( WP_Theme_JSON_Resolver::theme_has_support() ) {420 if ( wp_theme_has_theme_json() ) { 421 421 $block_classes = array( 422 422 'css' => 'styles', -
trunk/src/wp-includes/block-patterns.php
r54263 r55086 140 140 } 141 141 142 if ( ! WP_Theme_JSON_Resolver::theme_has_support() ) {142 if ( ! wp_theme_has_theme_json() ) { 143 143 return; 144 144 } -
trunk/src/wp-includes/block-supports/layout.php
r54633 r55086 465 465 466 466 if ( 467 WP_Theme_JSON_Resolver::theme_has_support() ||467 wp_theme_has_theme_json() || 468 468 1 === preg_match( $group_with_inner_container_regex, $block_content ) || 469 469 ( isset( $block['attrs']['layout']['type'] ) && 'flex' === $block['attrs']['layout']['type'] ) … … 528 528 529 529 if ( 530 WP_Theme_JSON_Resolver::theme_has_support() ||530 wp_theme_has_theme_json() || 531 531 0 === preg_match( $image_with_align, $block_content, $matches ) 532 532 ) { -
trunk/src/wp-includes/block-template-utils.php
r54998 r55086 348 348 */ 349 349 function _add_block_template_info( $template_item ) { 350 if ( ! WP_Theme_JSON_Resolver::theme_has_support() ) {350 if ( ! wp_theme_has_theme_json() ) { 351 351 return $template_item; 352 352 } … … 371 371 */ 372 372 function _add_block_template_part_area_info( $template_info ) { 373 if ( WP_Theme_JSON_Resolver::theme_has_support() ) {373 if ( wp_theme_has_theme_json() ) { 374 374 $theme_data = WP_Theme_JSON_Resolver::get_theme_data( array(), array( 'with_supports' => false ) )->get_template_parts(); 375 375 } -
trunk/src/wp-includes/class-wp-theme-json-resolver.php
r55067 r55086 59 59 60 60 /** 61 * Whether or not the theme supports theme.json.62 *63 * @since 5.8.064 * @var bool65 */66 protected static $theme_has_support = null;67 68 /**69 61 * Container for data coming from the user. 70 62 * … … 296 288 */ 297 289 $theme_support_data = WP_Theme_JSON::get_from_editor_settings( get_default_block_editor_settings() ); 298 if ( ! static::theme_has_support() ) {290 if ( ! wp_theme_has_theme_json() ) { 299 291 if ( ! isset( $theme_support_data['settings']['color'] ) ) { 300 292 $theme_support_data['settings']['color'] = array(); … … 422 414 * Bail early if the theme does not support a theme.json. 423 415 * 424 * Since WP_Theme_JSON_Resolver::theme_has_support() only supports the active416 * Since wp_theme_has_theme_json() only supports the active 425 417 * theme, the extra condition for whether $theme is the active theme is 426 418 * present here. 427 419 */ 428 if ( $theme->get_stylesheet() === get_stylesheet() && ! static::theme_has_support() ) {420 if ( $theme->get_stylesheet() === get_stylesheet() && ! wp_theme_has_theme_json() ) { 429 421 return array(); 430 422 } … … 603 595 * @since 5.8.0 604 596 * @since 5.9.0 Added a check in the parent theme. 597 * @deprecated 6.2.0 Use wp_theme_has_theme_json() instead. 605 598 * 606 599 * @return bool 607 600 */ 608 601 public static function theme_has_support() { 609 if ( ! isset( static::$theme_has_support ) ) { 610 static::$theme_has_support = ( 611 static::get_file_path_from_theme( 'theme.json' ) !== '' || 612 static::get_file_path_from_theme( 'theme.json', true ) !== '' 613 ); 614 } 615 616 return static::$theme_has_support; 602 _deprecated_function( __METHOD__, '6.2.0', 'wp_theme_has_theme_json()' ); 603 604 return wp_theme_has_theme_json(); 617 605 } 618 606 … … 657 645 static::$user = null; 658 646 static::$user_custom_post_type_id = null; 659 static::$theme_has_support = null;660 647 static::$i18n_schema = null; 661 648 } -
trunk/src/wp-includes/default-filters.php
r54999 r55086 347 347 add_action( 'init', 'check_theme_switched', 99 ); 348 348 add_action( 'init', array( 'WP_Block_Supports', 'init' ), 22 ); 349 add_action( 'switch_theme', array( 'WP_Theme_JSON_Resolver', 'clean_cached_data' ));350 add_action( 'start_previewing_theme', array( 'WP_Theme_JSON_Resolver', 'clean_cached_data' ));349 add_action( 'switch_theme', 'wp_clean_theme_json_cache' ); 350 add_action( 'start_previewing_theme', 'wp_clean_theme_json_cache' ); 351 351 add_action( 'after_switch_theme', '_wp_menus_changed' ); 352 352 add_action( 'after_switch_theme', '_wp_sidebars_changed' ); -
trunk/src/wp-includes/global-styles-and-settings.php
r54703 r55086 103 103 $tree = WP_Theme_JSON_Resolver::get_merged_data(); 104 104 105 $supports_theme_json = WP_Theme_JSON_Resolver::theme_has_support();105 $supports_theme_json = wp_theme_has_theme_json(); 106 106 if ( empty( $types ) && ! $supports_theme_json ) { 107 107 $types = array( 'variables', 'presets', 'base-layout-styles' ); … … 185 185 } 186 186 187 $supports_theme_json = WP_Theme_JSON_Resolver::theme_has_support();187 $supports_theme_json = wp_theme_has_theme_json(); 188 188 189 189 $origins = array( 'default', 'theme', 'custom' ); … … 256 256 } 257 257 } 258 259 /** 260 * Checks whether a theme or its parent has a theme.json file. 261 * 262 * @since 6.2.0 263 * 264 * @return bool Returns true if theme or its parent has a theme.json file, false otherwise. 265 */ 266 function wp_theme_has_theme_json() { 267 /* 268 * By using the 'theme_json' group, this data is marked to be non-persistent across requests. 269 * @see `wp_cache_add_non_persistent_groups()`. 270 * 271 * The rationale for this is to make sure derived data from theme.json 272 * is always fresh from the potential modifications done via hooks 273 * that can use dynamic data (modify the stylesheet depending on some option, 274 * settings depending on user permissions, etc.). 275 * For some of the existing hooks to modify theme.json behavior: 276 * @see https://make.wordpress.org/core/2022/10/10/filters-for-theme-json-data/ 277 * 278 * A different alternative considered was to invalidate the cache upon certain 279 * events such as options add/update/delete, user meta, etc. 280 * It was judged not enough, hence this approach. 281 * @see https://github.com/WordPress/gutenberg/pull/45372 282 */ 283 $cache_group = 'theme_json'; 284 $cache_key = 'wp_theme_has_theme_json'; 285 $theme_has_support = wp_cache_get( $cache_key, $cache_group ); 286 287 /* 288 * $theme_has_support is stored as an int in the cache. 289 * 290 * The reason not to store it as a boolean is to avoid working 291 * with the $found parameter which apparently had some issues in some implementations 292 * @see https://developer.wordpress.org/reference/functions/wp_cache_get/ 293 * 294 * Ignore cache when `WP_DEBUG` is enabled, so it doesn't interfere with the theme 295 * developer's workflow. 296 * 297 * @todo Replace `WP_DEBUG` once an "in development mode" check is available in Core. 298 */ 299 if ( ! WP_DEBUG && is_int( $theme_has_support ) ) { 300 return (bool) $theme_has_support; 301 } 302 303 // Does the theme have its own theme.json? 304 $theme_has_support = is_readable( get_stylesheet_directory() . '/theme.json' ); 305 306 // Look up the parent if the child does not have a theme.json. 307 if ( ! $theme_has_support ) { 308 $theme_has_support = is_readable( get_template_directory() . '/theme.json' ); 309 } 310 311 $theme_has_support = $theme_has_support ? 1 : 0; 312 313 wp_cache_set( $cache_key, $theme_has_support, $cache_group ); 314 315 return (bool) $theme_has_support; 316 } 317 318 /** 319 * Cleans the caches under the theme_json group. 320 * 321 * @since 6.2.0 322 */ 323 function wp_clean_theme_json_cache() { 324 wp_cache_delete( 'wp_theme_has_theme_json', 'theme_json' ); 325 WP_Theme_JSON_Resolver::clean_cached_data(); 326 } -
trunk/src/wp-includes/load.php
r54944 r55086 754 754 ); 755 755 756 wp_cache_add_non_persistent_groups( array( 'counts', 'plugins' ) );756 wp_cache_add_non_persistent_groups( array( 'counts', 'plugins', 'theme_json' ) ); 757 757 } 758 758 -
trunk/src/wp-includes/ms-blogs.php
r54945 r55086 576 576 } 577 577 578 wp_cache_add_non_persistent_groups( array( 'counts', 'plugins' ) );578 wp_cache_add_non_persistent_groups( array( 'counts', 'plugins', 'theme_json' ) ); 579 579 } 580 580 } … … 667 667 } 668 668 669 wp_cache_add_non_persistent_groups( array( 'counts', 'plugins' ) );669 wp_cache_add_non_persistent_groups( array( 'counts', 'plugins', 'theme_json' ) ); 670 670 } 671 671 } -
trunk/src/wp-includes/script-loader.php
r55084 r55086 1621 1621 1622 1622 // Only load the default layout and margin styles for themes without theme.json file. 1623 if ( ! WP_Theme_JSON_Resolver::theme_has_support() ) {1623 if ( ! wp_theme_has_theme_json() ) { 1624 1624 $wp_edit_blocks_dependencies[] = 'wp-editor-classic-layout-styles'; 1625 1625 } … … 3668 3668 */ 3669 3669 function wp_enqueue_classic_theme_styles() { 3670 if ( ! WP_Theme_JSON_Resolver::theme_has_support() ) {3670 if ( ! wp_theme_has_theme_json() ) { 3671 3671 $suffix = wp_scripts_get_suffix(); 3672 3672 wp_register_style( 'classic-theme-styles', '/' . WPINC . "/css/classic-themes$suffix.css", array(), true ); … … 3686 3686 */ 3687 3687 function wp_add_editor_classic_theme_styles( $editor_settings ) { 3688 if ( WP_Theme_JSON_Resolver::theme_has_support() ) {3688 if ( wp_theme_has_theme_json() ) { 3689 3689 return $editor_settings; 3690 3690 } -
trunk/src/wp-includes/theme-templates.php
r54817 r55086 210 210 */ 211 211 function wp_enable_block_templates() { 212 if ( wp_is_block_theme() || WP_Theme_JSON_Resolver::theme_has_support() ) {212 if ( wp_is_block_theme() || wp_theme_has_theme_json() ) { 213 213 add_theme_support( 'block-templates' ); 214 214 } -
trunk/tests/phpunit/includes/abstract-testcase.php
r55019 r55086 402 402 ); 403 403 404 wp_cache_add_non_persistent_groups( array( 'counts', 'plugins' ) );404 wp_cache_add_non_persistent_groups( array( 'counts', 'plugins', 'theme_json' ) ); 405 405 } 406 406 -
trunk/tests/phpunit/tests/theme/themeDir.php
r54497 r55086 164 164 $expected = array( 165 165 'WordPress Default', 166 'Default Child Theme with no theme.json', 166 167 'Sandbox', 167 168 'Stylesheet Only', … … 178 179 'Block Theme', 179 180 'Block Theme Child Theme', 181 'Block Theme Child with no theme.json', 180 182 'Block Theme Child Theme With Fluid Typography', 181 183 'Block Theme [0.4.0]', -
trunk/tests/phpunit/tests/theme/wpThemeJsonResolver.php
r55067 r55086 111 111 112 112 // Reset data between tests. 113 WP_Theme_JSON_Resolver::clean_cached_data();113 wp_clean_theme_json_cache(); 114 114 parent::tear_down(); 115 115 } … … 377 377 */ 378 378 public function test_get_core_data( $should_fire_filter, $core_is_cached, $blocks_are_cached ) { 379 WP_Theme_JSON_Resolver::clean_cached_data();379 wp_clean_theme_json_cache(); 380 380 381 381 // If should cache core, then fire the method to cache it before running the tests. … … 430 430 ), 431 431 ); 432 }433 434 /**435 * @ticket 52991436 */437 public function test_switching_themes_recalculates_data() {438 // The "default" theme doesn't have theme.json support.439 switch_theme( 'default' );440 $default = WP_Theme_JSON_Resolver::theme_has_support();441 442 // Switch to a theme that does have support.443 switch_theme( 'block-theme' );444 $has_theme_json_support = WP_Theme_JSON_Resolver::theme_has_support();445 446 $this->assertFalse( $default );447 $this->assertTrue( $has_theme_json_support );448 432 } 449 433 … … 483 467 remove_theme_support( 'appearance-tools' ); 484 468 485 $this->assertFalse( WP_Theme_JSON_Resolver::theme_has_support() );469 $this->assertFalse( wp_theme_has_theme_json() ); 486 470 $this->assertTrue( $settings['typography']['lineHeight'] ); 487 471 $this->assertSame( $color_palette, $settings['color']['palette']['theme'] ); … … 644 628 for ( $i = 0; $i < 3; $i++ ) { 645 629 WP_Theme_JSON_Resolver::get_user_data_from_wp_global_styles( $theme ); 646 WP_Theme_JSON_Resolver::clean_cached_data();630 wp_clean_theme_json_cache(); 647 631 } 648 632 $this->assertSame( 0, $global_styles_query_count, 'Unexpected SQL queries detected for the wp_global_style post type prior to creation.' ); … … 657 641 for ( $i = 0; $i < 3; $i++ ) { 658 642 $new_user_cpt = WP_Theme_JSON_Resolver::get_user_data_from_wp_global_styles( $theme ); 659 WP_Theme_JSON_Resolver::clean_cached_data();643 wp_clean_theme_json_cache(); 660 644 $this->assertSameSets( $user_cpt, $new_user_cpt, "User CPTs do not match on run {$i}." ); 661 645 } … … 674 658 for ( $i = 0; $i < 3; $i++ ) { 675 659 WP_Theme_JSON_Resolver::get_user_data_from_wp_global_styles( $theme ); 676 WP_Theme_JSON_Resolver::clean_cached_data();660 wp_clean_theme_json_cache(); 677 661 } 678 662 $query_count = get_num_queries() - $query_count; -
trunk/tests/phpunit/tests/webfonts/wpThemeJsonWebfontsHandler.php
r53319 r55086 130 130 switch_theme( $theme_name ); 131 131 do_action( 'after_setup_theme' ); 132 WP_Theme_JSON_Resolver::clean_cached_data();132 wp_clean_theme_json_cache(); 133 133 do_action( 'wp_loaded' ); 134 134 do_action( 'wp_enqueue_scripts' );
Note: See TracChangeset
for help on using the changeset viewer.