Changeset 58328
- Timestamp:
- 06/04/2024 11:53:37 AM (3 months ago)
- Location:
- trunk
- Files:
-
- 34 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/block-editor.php
r56736 r58328 815 815 * 816 816 * @since 6.2.0 817 * @since 6.6.0 Add support for 'editor-spacing-sizes' theme support. 817 818 * 818 819 * @return array The classic theme supports settings. … … 845 846 } 846 847 848 $spacing_sizes = current( (array) get_theme_support( 'editor-spacing-sizes' ) ); 849 if ( false !== $spacing_sizes ) { 850 $theme_settings['spacingSizes'] = $spacing_sizes; 851 } 852 847 853 return $theme_settings; 848 854 } -
trunk/src/wp-includes/class-wp-theme-json-data.php
r58185 r58328 40 40 * @param string $origin The origin of the data: default, theme, user. 41 41 */ 42 public function __construct( $data = array( ), $origin = 'theme' ) {42 public function __construct( $data = array( 'version' => WP_Theme_JSON::LATEST_SCHEMA ), $origin = 'theme' ) { 43 43 $this->origin = $origin; 44 44 $this->theme_json = new WP_Theme_JSON( $data, $this->origin ); -
trunk/src/wp-includes/class-wp-theme-json-resolver.php
r58265 r58328 221 221 * @since 5.9.0 Theme supports have been inlined and the `$theme_support_data` argument removed. 222 222 * @since 6.0.0 Added an `$options` parameter to allow the theme data to be returned without theme supports. 223 * @since 6.6.0 Add support for 'default-font-sizes' and 'default-spacing-sizes' theme supports. 223 224 * 224 225 * @param array $deprecated Deprecated. Not used. … … 244 245 $theme_json_data = static::translate( $theme_json_data, $wp_theme->get( 'TextDomain' ) ); 245 246 } else { 246 $theme_json_data = array( );247 $theme_json_data = array( 'version' => WP_Theme_JSON::LATEST_SCHEMA ); 247 248 } 248 249 … … 311 312 $theme_support_data['settings']['color']['defaultGradients'] = $default_gradients; 312 313 314 if ( ! isset( $theme_support_data['settings']['typography'] ) ) { 315 $theme_support_data['settings']['typography'] = array(); 316 } 317 $default_font_sizes = false; 318 if ( current_theme_supports( 'default-font-sizes' ) ) { 319 $default_font_sizes = true; 320 } 321 if ( ! isset( $theme_support_data['settings']['typography']['fontSizes'] ) ) { 322 // If the theme does not have any font sizes, we still want to show the core one. 323 $default_font_sizes = true; 324 } 325 $theme_support_data['settings']['typography']['defaultFontSizes'] = $default_font_sizes; 326 327 if ( ! isset( $theme_support_data['settings']['spacing'] ) ) { 328 $theme_support_data['settings']['spacing'] = array(); 329 } 330 $default_spacing_sizes = false; 331 if ( current_theme_supports( 'default-spacing-sizes' ) ) { 332 $default_spacing_sizes = true; 333 } 334 if ( ! isset( $theme_support_data['settings']['spacing']['spacingSizes'] ) ) { 335 // If the theme does not have any spacing sizes, we still want to show the core one. 336 $default_spacing_sizes = true; 337 } 338 $theme_support_data['settings']['spacing']['defaultSpacingSizes'] = $default_spacing_sizes; 339 313 340 if ( ! isset( $theme_support_data['settings']['shadow'] ) ) { 314 341 $theme_support_data['settings']['shadow'] = array(); … … 360 387 } 361 388 362 $config = array( 'version' => 2);389 $config = array( 'version' => WP_Theme_JSON::LATEST_SCHEMA ); 363 390 foreach ( $blocks as $block_name => $block_type ) { 364 391 if ( isset( $block_type->supports['__experimentalStyle'] ) ) { … … 495 522 * 496 523 * @since 5.9.0 524 * @since 6.6.0 The 'isGlobalStylesUserThemeJSON' flag is left on the user data. 497 525 * 498 526 * @return WP_Theme_JSON Entity that holds styles for user data. … … 532 560 $decoded_data['isGlobalStylesUserThemeJSON'] 533 561 ) { 534 unset( $decoded_data['isGlobalStylesUserThemeJSON'] );535 562 $config = $decoded_data; 536 563 } … … 538 565 539 566 /** This filter is documented in wp-includes/class-wp-theme-json-resolver.php */ 540 $theme_json = apply_filters( 'wp_theme_json_data_user', new WP_Theme_JSON_Data( $config, 'custom' ) ); 541 static::$user = $theme_json->get_theme_json(); 567 $theme_json = apply_filters( 'wp_theme_json_data_user', new WP_Theme_JSON_Data( $config, 'custom' ) ); 568 $config = $theme_json->get_data(); 569 570 // Needs to be set for schema migrations of user data. 571 $config['isGlobalStylesUserThemeJSON'] = true; 572 573 static::$user = new WP_Theme_JSON( $config, 'custom' ); 542 574 543 575 return static::$user; … … 587 619 $result->merge( static::get_core_data() ); 588 620 if ( 'default' === $origin ) { 589 $result->set_spacing_sizes();590 621 return $result; 591 622 } … … 598 629 $result->merge( static::get_theme_data() ); 599 630 if ( 'theme' === $origin ) { 600 $result->set_spacing_sizes();601 631 return $result; 602 632 } 603 633 604 634 $result->merge( static::get_user_data() ); 605 $result->set_spacing_sizes();606 635 607 636 return $result; -
trunk/src/wp-includes/class-wp-theme-json-schema.php
r56753 r58328 36 36 * 37 37 * @since 5.9.0 38 * @since 6.6.0 Migrate up to v3. 38 39 * 39 40 * @param array $theme_json The structure to migrate. … … 48 49 } 49 50 50 if ( 1 === $theme_json['version'] ) { 51 $theme_json = self::migrate_v1_to_v2( $theme_json ); 51 // Migrate each version in order starting with the current version. 52 switch ( $theme_json['version'] ) { 53 case 1: 54 $theme_json = self::migrate_v1_to_v2( $theme_json ); 55 // no break 56 case 2: 57 $theme_json = self::migrate_v2_to_v3( $theme_json ); 58 // no break 52 59 } 53 60 … … 81 88 // Set the new version. 82 89 $new['version'] = 2; 90 91 return $new; 92 } 93 94 /** 95 * Migrates from v2 to v3. 96 * 97 * - Sets settings.typography.defaultFontSizes to false. 98 * 99 * @since 6.6.0 100 * 101 * @param array $old Data to migrate. 102 * 103 * @return array Data with defaultFontSizes set to false. 104 */ 105 private static function migrate_v2_to_v3( $old ) { 106 // Copy everything. 107 $new = $old; 108 109 // Set the new version. 110 $new['version'] = 3; 111 112 /* 113 * Remaining changes do not need to be applied to the custom origin, 114 * as they should take on the value of the theme origin. 115 */ 116 if ( 117 isset( $new['isGlobalStylesUserThemeJSON'] ) && 118 true === $new['isGlobalStylesUserThemeJSON'] 119 ) { 120 return $new; 121 } 122 123 /* 124 * Even though defaultFontSizes and defaultSpacingSizes are new 125 * settings, we need to migrate them as they each control 126 * PRESETS_METADATA prevent_override values which were previously 127 * hardcoded to false. This only needs to happen when the theme provides 128 * fontSizes or spacingSizes as they could match the default ones and 129 * affect the generated CSS. 130 */ 131 if ( isset( $old['settings']['typography']['fontSizes'] ) ) { 132 if ( ! isset( $new['settings'] ) ) { 133 $new['settings'] = array(); 134 } 135 if ( ! isset( $new['settings']['typography'] ) ) { 136 $new['settings']['typography'] = array(); 137 } 138 $new['settings']['typography']['defaultFontSizes'] = false; 139 } 140 141 /* 142 * Similarly to defaultFontSizes, we need to migrate defaultSpacingSizes 143 * as it controls the PRESETS_METADATA prevent_override which was 144 * previously hardcoded to false. This only needs to happen when the 145 * theme provided spacing sizes via spacingSizes or spacingScale. 146 */ 147 if ( 148 isset( $old['settings']['spacing']['spacingSizes'] ) || 149 isset( $old['settings']['spacing']['spacingScale'] ) 150 ) { 151 if ( ! isset( $new['settings'] ) ) { 152 $new['settings'] = array(); 153 } 154 if ( ! isset( $new['settings']['spacing'] ) ) { 155 $new['settings']['spacing'] = array(); 156 } 157 $new['settings']['spacing']['defaultSpacingSizes'] = false; 158 } 159 160 /* 161 * In v3 spacingSizes is merged with the generated spacingScale sizes 162 * instead of completely replacing them. The v3 behavior is what was 163 * documented for the v2 schema, but the code never actually did work 164 * that way. Instead of surprising users with a behavior change two 165 * years after the fact at the same time as a v3 update is introduced, 166 * we'll continue using the "bugged" behavior for v2 themes. And treat 167 * the "bug fix" as a breaking change for v3. 168 */ 169 if ( isset( $old['settings']['spacing']['spacingSizes'] ) ) { 170 unset( $new['settings']['spacing']['spacingScale'] ); 171 } 83 172 84 173 return $new; -
trunk/src/wp-includes/class-wp-theme-json.php
r58314 r58328 124 124 * @since 6.2.0 Added 'shadow' presets. 125 125 * @since 6.3.0 Replaced value_func for duotone with `null`. Custom properties are handled by class-wp-duotone.php. 126 * @since 6.6.0 Added the `dimensions.aspectRatios` & `dimensions.defaultAspectRatios` preset. 126 * @since 6.6.0 Added the `dimensions.aspectRatios` and `dimensions.defaultAspectRatios` presets. 127 * Updated the 'prevent_override' value for font size presets to use 'typography.defaultFontSizes' 128 * and spacing size presets to use `spacing.defaultSpacingSizes`. 127 129 * @var array 128 130 */ … … 170 172 array( 171 173 'path' => array( 'typography', 'fontSizes' ), 172 'prevent_override' => false,174 'prevent_override' => array( 'typography', 'defaultFontSizes' ), 173 175 'use_default_names' => true, 174 176 'value_func' => 'wp_get_typography_font_size_value', … … 188 190 array( 189 191 'path' => array( 'spacing', 'spacingSizes' ), 190 'prevent_override' => false,192 'prevent_override' => array( 'spacing', 'defaultSpacingSizes' ), 191 193 'use_default_names' => true, 192 194 'value_key' => 'size', … … 379 381 * @since 6.5.0 Added support for `layout.allowCustomContentAndWideSize`, 380 382 * `background.backgroundSize` and `dimensions.aspectRatio`. 381 * @since 6.6.0 Added support for `dimensions.aspectRatios` and `dimensions.defaultAspectRatios`. 383 * @since 6.6.0 Added support for 'dimensions.aspectRatios', 'dimensions.defaultAspectRatios', 384 * 'typography.defaultFontSizes', and 'spacing.defaultSpacingSizes'. 382 385 * @var array 383 386 */ … … 434 437 ), 435 438 'spacing' => array( 436 'customSpacingSize' => null, 437 'spacingSizes' => null, 438 'spacingScale' => null, 439 'blockGap' => null, 440 'margin' => null, 441 'padding' => null, 442 'units' => null, 439 'customSpacingSize' => null, 440 'defaultSpacingSizes' => null, 441 'spacingSizes' => null, 442 'spacingScale' => null, 443 'blockGap' => null, 444 'margin' => null, 445 'padding' => null, 446 'units' => null, 443 447 ), 444 448 'shadow' => array( … … 447 451 ), 448 452 'typography' => array( 449 'fluid' => null, 450 'customFontSize' => null, 451 'dropCap' => null, 452 'fontFamilies' => null, 453 'fontSizes' => null, 454 'fontStyle' => null, 455 'fontWeight' => null, 456 'letterSpacing' => null, 457 'lineHeight' => null, 458 'textAlign' => null, 459 'textColumns' => null, 460 'textDecoration' => null, 461 'textTransform' => null, 462 'writingMode' => null, 453 'fluid' => null, 454 'customFontSize' => null, 455 'defaultFontSizes' => null, 456 'dropCap' => null, 457 'fontFamilies' => null, 458 'fontSizes' => null, 459 'fontStyle' => null, 460 'fontWeight' => null, 461 'letterSpacing' => null, 462 'lineHeight' => null, 463 'textAlign' => null, 464 'textColumns' => null, 465 'textDecoration' => null, 466 'textTransform' => null, 467 'writingMode' => null, 463 468 ), 464 469 ); … … 729 734 * @since 5.8.0 730 735 * @since 5.9.0 Changed value from 1 to 2. 736 * @since 6.6.0 Changed value from 2 to 3. 731 737 * @var int 732 738 */ 733 const LATEST_SCHEMA = 2;739 const LATEST_SCHEMA = 3; 734 740 735 741 /** … … 737 743 * 738 744 * @since 5.8.0 745 * @since 6.6.0 Key spacingScale by origin, and Pre-generate the 746 * spacingSizes from spacingScale. 739 747 * 740 748 * @param array $theme_json A structure that follows the theme.json schema. … … 742 750 * One of 'default', 'theme', or 'custom'. Default 'theme'. 743 751 */ 744 public function __construct( $theme_json = array( ), $origin = 'theme' ) {752 public function __construct( $theme_json = array( 'version' => WP_Theme_JSON::LATEST_SCHEMA ), $origin = 'theme' ) { 745 753 if ( ! in_array( $origin, static::VALID_ORIGINS, true ) ) { 746 754 $origin = 'theme'; … … 751 759 $valid_element_names = array_keys( static::ELEMENTS ); 752 760 $valid_variations = static::get_valid_block_style_variations(); 753 $th eme_json= static::sanitize( $this->theme_json, $valid_block_names, $valid_element_names, $valid_variations );754 $this->theme_json = static::maybe_opt_in_into_settings( $th eme_json );761 $this->theme_json = static::sanitize( $this->theme_json, $valid_block_names, $valid_element_names, $valid_variations ); 762 $this->theme_json = static::maybe_opt_in_into_settings( $this->theme_json ); 755 763 756 764 // Internally, presets are keyed by origin. … … 770 778 } 771 779 } 780 } 781 782 // In addition to presets, spacingScale (which generates presets) is also keyed by origin. 783 $scale_path = array( 'settings', 'spacing', 'spacingScale' ); 784 $spacing_scale = _wp_array_get( $this->theme_json, $scale_path, null ); 785 if ( null !== $spacing_scale ) { 786 // If the spacingScale is not already keyed by origin. 787 if ( empty( array_intersect( array_keys( $spacing_scale ), static::VALID_ORIGINS ) ) ) { 788 _wp_array_set( $this->theme_json, $scale_path, array( $origin => $spacing_scale ) ); 789 } 790 } 791 792 // Pre-generate the spacingSizes from spacingScale. 793 $scale_path = array( 'settings', 'spacing', 'spacingScale', $origin ); 794 $spacing_scale = _wp_array_get( $this->theme_json, $scale_path, null ); 795 if ( isset( $spacing_scale ) ) { 796 $sizes_path = array( 'settings', 'spacing', 'spacingSizes', $origin ); 797 $spacing_sizes = _wp_array_get( $this->theme_json, $sizes_path, array() ); 798 $spacing_scale_sizes = static::compute_spacing_sizes( $spacing_scale ); 799 $merged_spacing_sizes = static::merge_spacing_sizes( $spacing_scale_sizes, $spacing_sizes ); 800 _wp_array_set( $this->theme_json, $sizes_path, $merged_spacing_sizes ); 772 801 } 773 802 } … … 2915 2944 $incoming_data = $incoming->get_raw_data(); 2916 2945 $this->theme_json = array_replace_recursive( $this->theme_json, $incoming_data ); 2946 2947 /* 2948 * Recompute all the spacing sizes based on the new hierarchy of data. In the constructor 2949 * spacingScale and spacingSizes are both keyed by origin and VALID_ORIGINS is ordered, so 2950 * we can allow partial spacingScale data to inherit missing data from earlier layers when 2951 * computing the spacing sizes. 2952 * 2953 * This happens before the presets are merged to ensure that default spacing sizes can be 2954 * removed from the theme origin if $prevent_override is true. 2955 */ 2956 $flattened_spacing_scale = array(); 2957 foreach ( static::VALID_ORIGINS as $origin ) { 2958 $scale_path = array( 'settings', 'spacing', 'spacingScale', $origin ); 2959 2960 // Apply the base spacing scale to the current layer. 2961 $base_spacing_scale = _wp_array_get( $this->theme_json, $scale_path, array() ); 2962 $flattened_spacing_scale = array_replace( $flattened_spacing_scale, $base_spacing_scale ); 2963 2964 $spacing_scale = _wp_array_get( $incoming_data, $scale_path, null ); 2965 if ( ! isset( $spacing_scale ) ) { 2966 continue; 2967 } 2968 2969 // Allow partial scale settings by merging with lower layers. 2970 $flattened_spacing_scale = array_replace( $flattened_spacing_scale, $spacing_scale ); 2971 2972 // Generate and merge the scales for this layer. 2973 $sizes_path = array( 'settings', 'spacing', 'spacingSizes', $origin ); 2974 $spacing_sizes = _wp_array_get( $incoming_data, $sizes_path, array() ); 2975 $spacing_scale_sizes = static::compute_spacing_sizes( $flattened_spacing_scale ); 2976 $merged_spacing_sizes = static::merge_spacing_sizes( $spacing_scale_sizes, $spacing_sizes ); 2977 2978 _wp_array_set( $incoming_data, $sizes_path, $merged_spacing_sizes ); 2979 } 2917 2980 2918 2981 /* … … 2952 3015 2953 3016 // Replace the presets. 2954 foreach ( static::PRESETS_METADATA as $preset ) { 2955 $override_preset = ! static::get_metadata_boolean( $this->theme_json['settings'], $preset['prevent_override'], true ); 3017 foreach ( static::PRESETS_METADATA as $preset_metadata ) { 3018 $prevent_override = $preset_metadata['prevent_override']; 3019 if ( is_array( $prevent_override ) ) { 3020 $prevent_override = _wp_array_get( $this->theme_json['settings'], $preset_metadata['prevent_override'] ); 3021 } 2956 3022 2957 3023 foreach ( static::VALID_ORIGINS as $origin ) { 2958 3024 $base_path = $node['path']; 2959 foreach ( $preset ['path'] as $leaf ) {3025 foreach ( $preset_metadata['path'] as $leaf ) { 2960 3026 $base_path[] = $leaf; 2961 3027 } … … 2969 3035 } 2970 3036 2971 if ( 'theme' === $origin && $preset['use_default_names'] ) { 3037 // Set names for theme presets based on the slug if they are not set and can use default names. 3038 if ( 'theme' === $origin && $preset_metadata['use_default_names'] ) { 2972 3039 foreach ( $content as $key => $item ) { 2973 3040 if ( ! isset( $item['name'] ) ) { … … 2980 3047 } 2981 3048 2982 if ( 2983 ( 'theme' !== $origin ) || 2984 ( 'theme' === $origin && $override_preset ) 2985 ) { 2986 _wp_array_set( $this->theme_json, $path, $content ); 2987 } else { 2988 $slugs_node = static::get_default_slugs( $this->theme_json, $node['path'] ); 2989 $slugs = array_merge_recursive( $slugs_global, $slugs_node ); 2990 2991 $slugs_for_preset = _wp_array_get( $slugs, $preset['path'], array() ); 2992 $content = static::filter_slugs( $content, $slugs_for_preset ); 2993 _wp_array_set( $this->theme_json, $path, $content ); 3049 // Filter out default slugs from theme presets when defaults should not be overridden. 3050 if ( 'theme' === $origin && $prevent_override ) { 3051 $slugs_node = static::get_default_slugs( $this->theme_json, $node['path'] ); 3052 $preset_global = _wp_array_get( $slugs_global, $preset_metadata['path'], array() ); 3053 $preset_node = _wp_array_get( $slugs_node, $preset_metadata['path'], array() ); 3054 $preset_slugs = array_merge_recursive( $preset_global, $preset_node ); 3055 3056 $content = static::filter_slugs( $content, $preset_slugs ); 2994 3057 } 3058 3059 _wp_array_set( $this->theme_json, $path, $content ); 2995 3060 } 2996 3061 } … … 3529 3594 } 3530 3595 $theme_settings['settings']['spacing']['padding'] = $settings['enableCustomSpacing']; 3596 } 3597 3598 if ( isset( $settings['spacingSizes'] ) ) { 3599 if ( ! isset( $theme_settings['settings']['spacing'] ) ) { 3600 $theme_settings['settings']['spacing'] = array(); 3601 } 3602 $theme_settings['settings']['spacing']['spacingSizes'] = $settings['spacingSizes']; 3531 3603 } 3532 3604 … … 3704 3776 * 3705 3777 * @since 6.1.0 3778 * @deprecated 6.6.0 3779 * 3780 * @param string $origin Optional. What source of data to set the spacing sizes for. 3781 * One of 'default', 'theme', or 'custom'. Default 'default'. 3706 3782 * 3707 3783 * @return null|void 3708 3784 */ 3709 3785 public function set_spacing_sizes() { 3786 _deprecated_function( __METHOD__, '6.6.0' ); 3787 3710 3788 $spacing_scale = isset( $this->theme_json['settings']['spacing']['spacingScale'] ) 3711 3789 ? $this->theme_json['settings']['spacing']['spacingScale'] … … 3741 3819 } 3742 3820 3821 $spacing_sizes = static::compute_spacing_sizes( $spacing_scale ); 3822 3823 // If there are 7 or fewer steps in the scale revert to numbers for labels instead of t-shirt sizes. 3824 if ( $spacing_scale['steps'] <= 7 ) { 3825 for ( $spacing_sizes_count = 0; $spacing_sizes_count < count( $spacing_sizes ); $spacing_sizes_count++ ) { 3826 $spacing_sizes[ $spacing_sizes_count ]['name'] = (string) ( $spacing_sizes_count + 1 ); 3827 } 3828 } 3829 3830 _wp_array_set( $this->theme_json, array( 'settings', 'spacing', 'spacingSizes', 'default' ), $spacing_sizes ); 3831 } 3832 3833 /** 3834 * Merges two sets of spacing size presets. 3835 * 3836 * @since 6.6.0 3837 * 3838 * @param array $base The base set of spacing sizes. 3839 * @param array $incoming The set of spacing sizes to merge with the base. Duplicate slugs will override the base values. 3840 * @return array The merged set of spacing sizes. 3841 */ 3842 private static function merge_spacing_sizes( $base, $incoming ) { 3843 // Preserve the order if there are no base (spacingScale) values. 3844 if ( empty( $base ) ) { 3845 return $incoming; 3846 } 3847 $merged = array(); 3848 foreach ( $base as $item ) { 3849 $merged[ $item['slug'] ] = $item; 3850 } 3851 foreach ( $incoming as $item ) { 3852 $merged[ $item['slug'] ] = $item; 3853 } 3854 ksort( $merged, SORT_NUMERIC ); 3855 return array_values( $merged ); 3856 } 3857 3858 /** 3859 * Generates a set of spacing sizes by starting with a medium size and 3860 * applying an operator with an increment value to generate the rest of the 3861 * sizes outward from the medium size. The medium slug is '50' with the rest 3862 * of the slugs being 10 apart. The generated names use t-shirt sizing. 3863 * 3864 * Example: 3865 * 3866 * $spacing_scale = array( 3867 * 'steps' => 4, 3868 * 'mediumStep' => 16, 3869 * 'unit' => 'px', 3870 * 'operator' => '+', 3871 * 'increment' => 2, 3872 * ); 3873 * $spacing_sizes = static::compute_spacing_sizes( $spacing_scale ); 3874 * // -> array( 3875 * // array( 'name' => 'Small', 'slug' => '40', 'size' => '14px' ), 3876 * // array( 'name' => 'Medium', 'slug' => '50', 'size' => '16px' ), 3877 * // array( 'name' => 'Large', 'slug' => '60', 'size' => '18px' ), 3878 * // array( 'name' => 'X-Large', 'slug' => '70', 'size' => '20px' ), 3879 * // ) 3880 * 3881 * @since 6.6.0 3882 * 3883 * @param array $spacing_scale { 3884 * The spacing scale values. All are required. 3885 * 3886 * @type int $steps The number of steps in the scale. (up to 10 steps are supported.) 3887 * @type float $mediumStep The middle value that gets the slug '50'. (For even number of steps, this becomes the first middle value.) 3888 * @type string $unit The CSS unit to use for the sizes. 3889 * @type string $operator The mathematical operator to apply to generate the other sizes. Either '+' or '*'. 3890 * @type float $increment The value used with the operator to generate the other sizes. 3891 * } 3892 * @return array The spacing sizes presets or an empty array if some spacing scale values are missing or invalid. 3893 */ 3894 private static function compute_spacing_sizes( $spacing_scale ) { 3895 /* 3896 * This condition is intentionally missing some checks on ranges for the values in order to 3897 * keep backwards compatibility with the previous implementation. 3898 */ 3899 if ( 3900 ! isset( $spacing_scale['steps'] ) || 3901 ! is_numeric( $spacing_scale['steps'] ) || 3902 0 === $spacing_scale['steps'] || 3903 ! isset( $spacing_scale['mediumStep'] ) || 3904 ! is_numeric( $spacing_scale['mediumStep'] ) || 3905 ! isset( $spacing_scale['unit'] ) || 3906 ! isset( $spacing_scale['operator'] ) || 3907 ( '+' !== $spacing_scale['operator'] && '*' !== $spacing_scale['operator'] ) || 3908 ! isset( $spacing_scale['increment'] ) || 3909 ! is_numeric( $spacing_scale['increment'] ) 3910 ) { 3911 return array(); 3912 } 3913 3743 3914 $unit = '%' === $spacing_scale['unit'] ? '%' : sanitize_title( $spacing_scale['unit'] ); 3744 3915 $current_step = $spacing_scale['mediumStep']; … … 3823 3994 } 3824 3995 3825 // If there are 7 or fewer steps in the scale revert to numbers for labels instead of t-shirt sizes. 3826 if ( $spacing_scale['steps'] <= 7 ) { 3827 for ( $spacing_sizes_count = 0; $spacing_sizes_count < count( $spacing_sizes ); $spacing_sizes_count++ ) { 3828 $spacing_sizes[ $spacing_sizes_count ]['name'] = (string) ( $spacing_sizes_count + 1 ); 3829 } 3830 } 3831 3832 _wp_array_set( $this->theme_json, array( 'settings', 'spacing', 'spacingSizes', 'default' ), $spacing_sizes ); 3996 return $spacing_sizes; 3833 3997 } 3834 3998 -
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-font-faces-controller.php
r57868 r58328 19 19 * @var int 20 20 */ 21 const LATEST_THEME_JSON_VERSION_SUPPORTED = 2;21 const LATEST_THEME_JSON_VERSION_SUPPORTED = 3; 22 22 23 23 /** -
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-font-families-controller.php
r57548 r58328 21 21 * @var int 22 22 */ 23 const LATEST_THEME_JSON_VERSION_SUPPORTED = 2;23 const LATEST_THEME_JSON_VERSION_SUPPORTED = 3; 24 24 25 25 /** -
trunk/src/wp-includes/theme.json
r58314 r58328 1 1 { 2 2 "$schema": "https://schemas.wp.org/trunk/theme.json", 3 "version": 2,3 "version": 3, 4 4 "settings": { 5 5 "appearanceTools": false, … … 266 266 "padding": false, 267 267 "customSpacingSize": true, 268 "defaultSpacingSizes": true, 268 269 "units": [ "px", "em", "rem", "vh", "vw", "%" ], 269 270 "spacingScale": { … … 277 278 "typography": { 278 279 "customFontSize": true, 280 "defaultFontSizes": true, 279 281 "dropCap": true, 280 282 "fontSizes": [ -
trunk/src/wp-includes/theme.php
r58213 r58328 2643 2643 * @since 6.5.0 The `appearance-tools` feature enables a few design tools for blocks, 2644 2644 * see `WP_Theme_JSON::APPEARANCE_TOOLS_OPT_INS` for a complete list. 2645 * @since 6.6.0 The `editor-spacing-sizes` feature was added. 2645 2646 * 2646 2647 * @global array $_wp_theme_features … … 2670 2671 * - 'editor-gradient-presets' 2671 2672 * - 'editor-font-sizes' 2673 * - 'editor-spacing-sizes' 2672 2674 * - 'editor-styles' 2673 2675 * - 'featured-content' … … 4228 4230 ); 4229 4231 register_theme_feature( 4232 'editor-spacing-sizes', 4233 array( 4234 'type' => 'array', 4235 'description' => __( 'Custom spacing sizes if defined by the theme.' ), 4236 'show_in_rest' => array( 4237 'schema' => array( 4238 'items' => array( 4239 'type' => 'object', 4240 'properties' => array( 4241 'name' => array( 4242 'type' => 'string', 4243 ), 4244 'size' => array( 4245 'type' => 'string', 4246 ), 4247 'slug' => array( 4248 'type' => 'string', 4249 ), 4250 ), 4251 ), 4252 ), 4253 ), 4254 ) 4255 ); 4256 register_theme_feature( 4230 4257 'editor-styles', 4231 4258 array( -
trunk/tests/phpunit/data/themedir1/block-theme-child-with-fluid-layout/theme.json
r57336 r58328 1 1 { 2 2 "$schema": "https://schemas.wp.org/trunk/theme.json", 3 "version": 2,3 "version": 3, 4 4 "settings": { 5 5 "appearanceTools": true, -
trunk/tests/phpunit/data/themedir1/block-theme-child-with-fluid-typography-config/theme.json
r57336 r58328 1 1 { 2 2 "$schema": "https://schemas.wp.org/trunk/theme.json", 3 "version": 2,3 "version": 3, 4 4 "settings": { 5 5 "appearanceTools": true, -
trunk/tests/phpunit/data/themedir1/block-theme-child-with-fluid-typography/theme.json
r57336 r58328 1 1 { 2 2 "$schema": "https://schemas.wp.org/trunk/theme.json", 3 "version": 2,3 "version": 3, 4 4 "settings": { 5 5 "appearanceTools": true, -
trunk/tests/phpunit/data/themedir1/block-theme-child/styles/variation-a.json
r57662 r58328 1 1 { 2 "version": 2,2 "version": 3, 3 3 "settings": { 4 4 "blocks": { -
trunk/tests/phpunit/data/themedir1/block-theme-child/styles/variation-b.json
r55231 r58328 1 1 { 2 "version": 2,2 "version": 3, 3 3 "settings": { 4 4 "blocks": { -
trunk/tests/phpunit/data/themedir1/block-theme-child/theme.json
r57662 r58328 1 1 { 2 2 "$schema": "https://schemas.wp.org/trunk/theme.json", 3 "version": 2,3 "version": 3, 4 4 "settings": { 5 5 "color": { -
trunk/tests/phpunit/data/themedir1/block-theme-deprecated-path/styles/variation.json
r53416 r58328 1 1 { 2 "version": 2,3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 2 "version": 3, 3 "settings": { 4 "color": { 5 "palette": [ 6 { 7 "slug": "foreground", 8 "color": "#3F67C6", 9 "name": "Foreground" 10 } 11 ] 12 } 13 }, 14 "styles": { 15 "blocks": { 16 "core/post-title": { 17 "typography": { 18 "fontWeight": "700" 19 } 20 } 21 } 22 } 23 23 } -
trunk/tests/phpunit/data/themedir1/block-theme-with-hooked-blocks/theme.json
r56759 r58328 1 1 { 2 2 "$schema": "https://schemas.wp.org/trunk/theme.json", 3 "version": 2,3 "version": 3, 4 4 "templateParts": [ 5 5 { -
trunk/tests/phpunit/data/themedir1/block-theme/styles/variation-a.json
r57662 r58328 1 1 { 2 "version": 2,2 "version": 3, 3 3 "settings": { 4 4 "blocks": { -
trunk/tests/phpunit/data/themedir1/block-theme/styles/variation-b.json
r58262 r58328 1 1 { 2 "version": 2,2 "version": 3, 3 3 "settings": { 4 4 "blocks": { -
trunk/tests/phpunit/data/themedir1/block-theme/styles/variation.json
r54036 r58328 1 1 { 2 "version": 2,2 "version": 3, 3 3 "title": "Block theme variation", 4 4 "settings": { -
trunk/tests/phpunit/data/themedir1/block-theme/theme.json
r57885 r58328 1 1 { 2 2 "$schema": "https://schemas.wp.org/trunk/theme.json", 3 "version": 2,3 "version": 3, 4 4 "title": "Block theme", 5 5 "settings": { -
trunk/tests/phpunit/data/themedir1/empty-fontface-theme/theme.json
r57336 r58328 1 1 { 2 2 "$schema": "https://schemas.wp.org/trunk/theme.json", 3 "version": 2, 4 "customTemplates": [ 5 { 6 "name": "blank", 7 "title": "Blank", 8 "postTypes": [ 9 "page", 10 "post" 11 ] 12 } 13 ], 14 "settings": { 15 "appearanceTools": true, 16 "color": { 17 "duotone": [], 18 "gradients": [], 19 "palette": [] 3 "version": 3, 4 "customTemplates": [ 5 { 6 "name": "blank", 7 "title": "Blank", 8 "postTypes": [ "page", "post" ] 9 } 10 ], 11 "settings": { 12 "appearanceTools": true, 13 "color": { 14 "duotone": [], 15 "gradients": [], 16 "palette": [] 17 }, 18 "custom": {}, 19 "spacing": { 20 "units": [ "%", "px", "em", "rem", "vh", "vw" ] 21 }, 22 "typography": { 23 "dropCap": false, 24 "fontFamilies": [ 25 { 26 "fontFamily": "Roboto", 27 "name": "Roboto", 28 "slug": "roboto", 29 "fontFace": [] 30 } 31 ], 32 "fontSizes": [ 33 { 34 "size": "1rem", 35 "slug": "small" 36 }, 37 { 38 "size": "1.125rem", 39 "slug": "medium" 40 }, 41 { 42 "size": "1.75rem", 43 "slug": "large" 44 }, 45 { 46 "size": "clamp(1.75rem, 3vw, 2.25rem)", 47 "slug": "x-large" 48 } 49 ] 50 }, 51 "layout": { 52 "contentSize": "650px", 53 "wideSize": "1000px" 54 } 20 55 }, 21 "custom": {}, 22 "spacing": { 23 "units": [ 24 "%", 25 "px", 26 "em", 27 "rem", 28 "vh", 29 "vw" 30 ] 56 "styles": { 57 "blocks": {}, 58 "color": { 59 "background": "var(--wp--preset--color--background)", 60 "text": "var(--wp--preset--color--foreground)" 61 }, 62 "elements": {}, 63 "spacing": { 64 "blockGap": "1.5rem" 65 }, 66 "typography": { 67 "fontFamily": "var(--wp--preset--font-family--system-font)", 68 "lineHeight": "var(--wp--custom--typography--line-height--normal)", 69 "fontSize": "var(--wp--preset--font-size--medium)" 70 } 31 71 }, 32 "typography": { 33 "dropCap": false, 34 "fontFamilies": [ 72 "templateParts": [ 35 73 { 36 "fontFamily": "Roboto", 37 "name": "Roboto", 38 "slug": "roboto", 39 "fontFace": [] 74 "name": "header", 75 "title": "Header", 76 "area": "header" 40 77 } 41 ], 42 "fontSizes": [ 43 { 44 "size": "1rem", 45 "slug": "small" 46 }, 47 { 48 "size": "1.125rem", 49 "slug": "medium" 50 }, 51 { 52 "size": "1.75rem", 53 "slug": "large" 54 }, 55 { 56 "size": "clamp(1.75rem, 3vw, 2.25rem)", 57 "slug": "x-large" 58 } 59 ] 60 }, 61 "layout": { 62 "contentSize": "650px", 63 "wideSize": "1000px" 64 } 65 }, 66 "styles": { 67 "blocks": {}, 68 "color": { 69 "background": "var(--wp--preset--color--background)", 70 "text": "var(--wp--preset--color--foreground)" 71 }, 72 "elements": {}, 73 "spacing": { 74 "blockGap": "1.5rem" 75 }, 76 "typography": { 77 "fontFamily": "var(--wp--preset--font-family--system-font)", 78 "lineHeight": "var(--wp--custom--typography--line-height--normal)", 79 "fontSize": "var(--wp--preset--font-size--medium)" 80 } 81 }, 82 "templateParts": [ 83 { 84 "name": "header", 85 "title": "Header", 86 "area": "header" 87 } 88 ] 78 ] 89 79 } -
trunk/tests/phpunit/data/themedir1/fonts-block-theme/styles/variation-duplicate-fonts.json
r56500 r58328 1 1 { 2 "version": 2,2 "version": 3, 3 3 "title": "Variation: duplicate fonts", 4 4 "settings": { -
trunk/tests/phpunit/data/themedir1/fonts-block-theme/styles/variation-new-font-family.json
r57788 r58328 1 1 { 2 "version": 2,2 "version": 3, 3 3 "title": "Variation: new font family", 4 4 "settings": { -
trunk/tests/phpunit/data/themedir1/fonts-block-theme/styles/variation-new-font-variations.json
r56500 r58328 1 1 { 2 "version": 2,2 "version": 3, 3 3 "title": "Variation: new font variations", 4 4 "settings": { -
trunk/tests/phpunit/data/themedir1/fonts-block-theme/styles/variation-no-fonts.json
r56500 r58328 1 1 { 2 "version": 2,2 "version": 3, 3 3 "title": "Variation - no fonts", 4 4 "styles": { -
trunk/tests/phpunit/data/themedir1/fonts-block-theme/theme.json
r57336 r58328 1 1 { 2 2 "$schema": "https://schemas.wp.org/trunk/theme.json", 3 "version": 2,3 "version": 3, 4 4 "settings": { 5 5 "appearanceTools": true, -
trunk/tests/phpunit/tests/fonts/font-library/wpRestFontFacesController.php
r57548 r58328 624 624 return array( 625 625 array( 1 ), 626 array( 3),626 array( 4 ), 627 627 ); 628 628 } -
trunk/tests/phpunit/tests/fonts/font-library/wpRestFontFamiliesController.php
r57987 r58328 432 432 return array( 433 433 array( 1 ), 434 array( 3),434 array( 4 ), 435 435 ); 436 436 } -
trunk/tests/phpunit/tests/rest-api/rest-global-styles-controller.php
r58262 r58328 151 151 $expected = array( 152 152 array( 153 'version' => 2,153 'version' => WP_Theme_JSON::LATEST_SCHEMA, 154 154 'settings' => array( 155 155 'blocks' => array( … … 172 172 ), 173 173 array( 174 'version' => 2,174 'version' => WP_Theme_JSON::LATEST_SCHEMA, 175 175 'settings' => array( 176 176 'blocks' => array( … … 217 217 ), 218 218 array( 219 'version' => 2,219 'version' => WP_Theme_JSON::LATEST_SCHEMA, 220 220 'title' => 'Block theme variation', 221 221 'settings' => array( -
trunk/tests/phpunit/tests/rest-api/rest-themes-controller.php
r58282 r58328 420 420 $this->assertArrayHasKey( 'editor-font-sizes', $theme_supports ); 421 421 $this->assertArrayHasKey( 'editor-gradient-presets', $theme_supports ); 422 $this->assertArrayHasKey( 'editor-spacing-sizes', $theme_supports ); 422 423 $this->assertArrayHasKey( 'editor-styles', $theme_supports ); 423 424 $this->assertArrayHasKey( 'formats', $theme_supports ); … … 427 428 $this->assertArrayHasKey( 'title-tag', $theme_supports ); 428 429 $this->assertArrayHasKey( 'wp-block-styles', $theme_supports ); 429 $this->assertCount( 2 3, $theme_supports, 'There should be 23 theme supports' );430 $this->assertCount( 24, $theme_supports, 'There should be 23 theme supports' ); 430 431 } 431 432 -
trunk/tests/phpunit/tests/theme/wpThemeJson.php
r58314 r58328 3301 3301 $theme = new WP_Theme_JSON( 3302 3302 array( 3303 'version' => 2,3303 'version' => WP_Theme_JSON::LATEST_SCHEMA, 3304 3304 'settings' => array( 3305 3305 'color' => array( … … 3322 3322 $user = new WP_Theme_JSON( 3323 3323 array( 3324 'version' => 2,3324 'version' => WP_Theme_JSON::LATEST_SCHEMA, 3325 3325 'settings' => array( 3326 3326 'color' => array( … … 3346 3346 $actual = $theme->get_data(); 3347 3347 $expected = array( 3348 'version' => 2,3348 'version' => WP_Theme_JSON::LATEST_SCHEMA, 3349 3349 'settings' => array( 3350 3350 'color' => array( … … 3379 3379 $theme = new WP_Theme_JSON( 3380 3380 array( 3381 'version' => 2,3381 'version' => WP_Theme_JSON::LATEST_SCHEMA, 3382 3382 'settings' => array( 3383 3383 'color' => array( … … 3401 3401 $actual = $theme->get_data(); 3402 3402 $expected = array( 3403 'version' => 2,3403 'version' => WP_Theme_JSON::LATEST_SCHEMA, 3404 3404 'settings' => array( 3405 3405 'color' => array( … … 3429 3429 $user = new WP_Theme_JSON( 3430 3430 array( 3431 'version' => 2,3431 'version' => WP_Theme_JSON::LATEST_SCHEMA, 3432 3432 'settings' => array( 3433 3433 'color' => array( … … 3452 3452 $actual = $user->get_data(); 3453 3453 $expected = array( 3454 'version' => 2,3454 'version' => WP_Theme_JSON::LATEST_SCHEMA, 3455 3455 'settings' => array( 3456 3456 'color' => array( … … 3478 3478 */ 3479 3479 public function test_export_data_deals_with_empty_data() { 3480 $theme _v2= new WP_Theme_JSON(3481 array( 3482 'version' => 2,3480 $theme = new WP_Theme_JSON( 3481 array( 3482 'version' => WP_Theme_JSON::LATEST_SCHEMA, 3483 3483 ), 3484 3484 'theme' 3485 3485 ); 3486 $actual_v2 = $theme_v2->get_data(); 3487 $expected_v2 = array( 'version' => 2 ); 3488 $this->assertEqualSetsWithIndex( $expected_v2, $actual_v2 ); 3489 3490 $theme_v1 = new WP_Theme_JSON( 3491 array( 3492 'version' => 1, 3493 ), 3494 'theme' 3495 ); 3496 $actual_v1 = $theme_v1->get_data(); 3497 $expected_v1 = array( 'version' => 2 ); 3498 $this->assertEqualSetsWithIndex( $expected_v1, $actual_v1 ); 3486 $actual = $theme->get_data(); 3487 $expected = array( 'version' => WP_Theme_JSON::LATEST_SCHEMA ); 3488 $this->assertEqualSetsWithIndex( $expected, $actual ); 3499 3489 } 3500 3490 … … 3505 3495 $theme = new WP_Theme_JSON( 3506 3496 array( 3507 'version' => 2,3497 'version' => WP_Theme_JSON::LATEST_SCHEMA, 3508 3498 'settings' => array( 3509 3499 'appearanceTools' => true, … … 3519 3509 $actual = $theme->get_data(); 3520 3510 $expected = array( 3521 'version' => 2,3511 'version' => WP_Theme_JSON::LATEST_SCHEMA, 3522 3512 'settings' => array( 3523 3513 'appearanceTools' => true, … … 3539 3529 $theme = new WP_Theme_JSON( 3540 3530 array( 3541 'version' => 2,3531 'version' => WP_Theme_JSON::LATEST_SCHEMA, 3542 3532 'settings' => array( 3543 3533 'useRootPaddingAwareAlignments' => true, … … 3553 3543 $actual = $theme->get_data(); 3554 3544 $expected = array( 3555 'version' => 2,3545 'version' => WP_Theme_JSON::LATEST_SCHEMA, 3556 3546 'settings' => array( 3557 3547 'useRootPaddingAwareAlignments' => true, … … 3645 3635 $theme_json = new WP_Theme_JSON( 3646 3636 array( 3647 'version' => 2,3637 'version' => WP_Theme_JSON::LATEST_SCHEMA, 3648 3638 'styles' => array( 3649 3639 'color' => array( … … 3730 3720 $theme_json = new WP_Theme_JSON( 3731 3721 array( 3732 'version' => 2,3722 'version' => WP_Theme_JSON::LATEST_SCHEMA, 3733 3723 'styles' => array( 3734 3724 'color' => array( … … 3768 3758 $theme_json = new WP_Theme_JSON( 3769 3759 array( 3770 'version' => 2,3760 'version' => WP_Theme_JSON::LATEST_SCHEMA, 3771 3761 'styles' => array( 3772 3762 'color' => array( … … 3805 3795 $theme_json = new WP_Theme_JSON( 3806 3796 array( 3807 'version' => 2,3797 'version' => WP_Theme_JSON::LATEST_SCHEMA, 3808 3798 'styles' => array( 3809 3799 'color' => array( … … 3831 3821 $theme_json = new WP_Theme_JSON( 3832 3822 array( 3833 'version' => 2,3823 'version' => WP_Theme_JSON::LATEST_SCHEMA, 3834 3824 'styles' => array( 3835 3825 'spacing' => array( … … 3868 3858 $theme_json = new WP_Theme_JSON( 3869 3859 array( 3870 'version' => 2,3860 'version' => WP_Theme_JSON::LATEST_SCHEMA, 3871 3861 'styles' => array( 3872 3862 'spacing' => array( … … 3901 3891 $theme_json = new WP_Theme_JSON( 3902 3892 array( 3903 'version' => 2,3893 'version' => WP_Theme_JSON::LATEST_SCHEMA, 3904 3894 'settings' => array( 3905 3895 'layout' => array( … … 3932 3922 $theme_json = new WP_Theme_JSON( 3933 3923 array( 3934 'version' => 2,3924 'version' => WP_Theme_JSON::LATEST_SCHEMA, 3935 3925 'settings' => array( 3936 3926 'appearanceTools' => true, … … 3955 3945 $theme_json = new WP_Theme_JSON( 3956 3946 array( 3957 'version' => 2,3947 'version' => WP_Theme_JSON::LATEST_SCHEMA, 3958 3948 'styles' => array( 3959 3949 'spacing' => array( … … 3974 3964 $actual = $theme_json->get_raw_data(); 3975 3965 $expected = array( 3976 'version' => 2,3966 'version' => WP_Theme_JSON::LATEST_SCHEMA, 3977 3967 'styles' => array( 3978 3968 'spacing' => array( … … 3998 3988 $theme_json = new WP_Theme_JSON( 3999 3989 array( 4000 'version' => 2,3990 'version' => WP_Theme_JSON::LATEST_SCHEMA, 4001 3991 'styles' => array( 4002 3992 'blocks' => array( … … 4022 4012 $sanitized_theme_json = $theme_json->get_raw_data(); 4023 4013 $expected = array( 4024 'version' => 2,4014 'version' => WP_Theme_JSON::LATEST_SCHEMA, 4025 4015 'styles' => array( 4026 4016 'blocks' => array( … … 4051 4041 $theme_json = new WP_Theme_JSON( 4052 4042 array( 4053 'version' => 2,4043 'version' => WP_Theme_JSON::LATEST_SCHEMA, 4054 4044 'styles' => array( 4055 4045 'blocks' => array( … … 4135 4125 $theme_json = new WP_Theme_JSON( 4136 4126 array( 4137 'version' => '2',4127 'version' => WP_Theme_JSON::LATEST_SCHEMA, 4138 4128 'badKey2' => 'I am Evil!', 4139 4129 'settings' => array( … … 4203 4193 4204 4194 $expected_sanitized = array( 4205 'version' => '2',4195 'version' => WP_Theme_JSON::LATEST_SCHEMA, 4206 4196 'settings' => array( 4207 4197 'typography' => array( … … 4272 4262 $theme_json = new WP_Theme_JSON( 4273 4263 array( 4274 'version' => 2,4264 'version' => WP_Theme_JSON::LATEST_SCHEMA, 4275 4265 'styles' => array( 4276 4266 'blocks' => array( … … 4320 4310 $theme_json = new WP_Theme_JSON( 4321 4311 array( 4322 'version' => 2,4312 'version' => WP_Theme_JSON::LATEST_SCHEMA, 4323 4313 'styles' => array( 4324 4314 'blocks' => array( … … 4474 4464 $theme_json = new WP_Theme_JSON( 4475 4465 array( 4476 'version' => 2,4466 'version' => WP_Theme_JSON::LATEST_SCHEMA, 4477 4467 'settings' => array( 4478 4468 'spacing' => array( … … 4480 4470 ), 4481 4471 ), 4482 ) 4483 );4484 4485 $theme_json->set_spacing_sizes(); 4472 ), 4473 'default' 4474 ); 4475 4486 4476 $this->assertSame( $expected_output, _wp_array_get( $theme_json->get_raw_data(), array( 'settings', 'spacing', 'spacingSizes', 'default' ) ) ); 4487 4477 } … … 4506 4496 'expected_output' => array( 4507 4497 array( 4508 'name' => ' 1',4498 'name' => 'Medium', 4509 4499 'slug' => '50', 4510 4500 'size' => '4rem', … … 4522 4512 'expected_output' => array( 4523 4513 array( 4524 'name' => ' 1',4514 'name' => 'Medium', 4525 4515 'slug' => '50', 4526 4516 'size' => '4rem', 4527 4517 ), 4528 4518 array( 4529 'name' => ' 2',4519 'name' => 'Large', 4530 4520 'slug' => '60', 4531 4521 'size' => '5.5rem', … … 4543 4533 'expected_output' => array( 4544 4534 array( 4545 'name' => ' 1',4535 'name' => 'Small', 4546 4536 'slug' => '40', 4547 4537 'size' => '2.5rem', 4548 4538 ), 4549 4539 array( 4550 'name' => ' 2',4540 'name' => 'Medium', 4551 4541 'slug' => '50', 4552 4542 'size' => '4rem', 4553 4543 ), 4554 4544 array( 4555 'name' => ' 3',4545 'name' => 'Large', 4556 4546 'slug' => '60', 4557 4547 'size' => '5.5rem', … … 4569 4559 'expected_output' => array( 4570 4560 array( 4571 'name' => ' 1',4561 'name' => 'Small', 4572 4562 'slug' => '40', 4573 4563 'size' => '2.5rem', 4574 4564 ), 4575 4565 array( 4576 'name' => ' 2',4566 'name' => 'Medium', 4577 4567 'slug' => '50', 4578 4568 'size' => '4rem', 4579 4569 ), 4580 4570 array( 4581 'name' => ' 3',4571 'name' => 'Large', 4582 4572 'slug' => '60', 4583 4573 'size' => '5.5rem', 4584 4574 ), 4585 4575 array( 4586 'name' => ' 4',4576 'name' => 'X-Large', 4587 4577 'slug' => '70', 4588 4578 'size' => '7rem', … … 4600 4590 'expected_output' => array( 4601 4591 array( 4602 'name' => ' 1',4592 'name' => 'Small', 4603 4593 'slug' => '40', 4604 4594 'size' => '2.5rem', 4605 4595 ), 4606 4596 array( 4607 'name' => ' 2',4597 'name' => 'Medium', 4608 4598 'slug' => '50', 4609 4599 'size' => '5rem', 4610 4600 ), 4611 4601 array( 4612 'name' => ' 3',4602 'name' => 'Large', 4613 4603 'slug' => '60', 4614 4604 'size' => '7.5rem', 4615 4605 ), 4616 4606 array( 4617 'name' => ' 4',4607 'name' => 'X-Large', 4618 4608 'slug' => '70', 4619 4609 'size' => '10rem', 4620 4610 ), 4621 4611 array( 4622 'name' => ' 5',4612 'name' => '2X-Large', 4623 4613 'slug' => '80', 4624 4614 'size' => '12.5rem', … … 4636 4626 'expected_output' => array( 4637 4627 array( 4638 'name' => ' 1',4628 'name' => 'X-Small', 4639 4629 'slug' => '30', 4640 4630 'size' => '0.67rem', 4641 4631 ), 4642 4632 array( 4643 'name' => ' 2',4633 'name' => 'Small', 4644 4634 'slug' => '40', 4645 4635 'size' => '1rem', 4646 4636 ), 4647 4637 array( 4648 'name' => ' 3',4638 'name' => 'Medium', 4649 4639 'slug' => '50', 4650 4640 'size' => '1.5rem', 4651 4641 ), 4652 4642 array( 4653 'name' => ' 4',4643 'name' => 'Large', 4654 4644 'slug' => '60', 4655 4645 'size' => '2.25rem', 4656 4646 ), 4657 4647 array( 4658 'name' => ' 5',4648 'name' => 'X-Large', 4659 4649 'slug' => '70', 4660 4650 'size' => '3.38rem', … … 4672 4662 'expected_output' => array( 4673 4663 array( 4674 'name' => ' 1',4664 'name' => 'X-Small', 4675 4665 'slug' => '30', 4676 4666 'size' => '0.09rem', 4677 4667 ), 4678 4668 array( 4679 'name' => ' 2',4669 'name' => 'Small', 4680 4670 'slug' => '40', 4681 4671 'size' => '0.38rem', 4682 4672 ), 4683 4673 array( 4684 'name' => ' 3',4674 'name' => 'Medium', 4685 4675 'slug' => '50', 4686 4676 'size' => '1.5rem', 4687 4677 ), 4688 4678 array( 4689 'name' => ' 4',4679 'name' => 'Large', 4690 4680 'slug' => '60', 4691 4681 'size' => '6rem', 4692 4682 ), 4693 4683 array( 4694 'name' => ' 5',4684 'name' => 'X-Large', 4695 4685 'slug' => '70', 4696 4686 'size' => '24rem', … … 4763 4753 */ 4764 4754 public function test_set_spacing_sizes_when_invalid( $spacing_scale, $expected_output ) { 4765 $this->expectException( Exception::class );4766 $this->expectExceptionMessage( 'Some of the theme.json settings.spacing.spacingScale values are invalid' );4767 4768 4755 $theme_json = new WP_Theme_JSON( 4769 4756 array( 4770 'version' => 2,4757 'version' => WP_Theme_JSON::LATEST_SCHEMA, 4771 4758 'settings' => array( 4772 4759 'spacing' => array( … … 4774 4761 ), 4775 4762 ), 4776 ) 4777 ); 4778 4779 // Ensure PHPUnit 10 compatibility. 4780 set_error_handler( 4781 static function ( $errno, $errstr ) { 4782 restore_error_handler(); 4783 throw new Exception( $errstr, $errno ); 4784 }, 4785 E_ALL 4786 ); 4787 4788 $theme_json->set_spacing_sizes(); 4789 4790 restore_error_handler(); 4763 ), 4764 'default' 4765 ); 4791 4766 4792 4767 $this->assertSame( $expected_output, _wp_array_get( $theme_json->get_raw_data(), array( 'settings', 'spacing', 'spacingSizes', 'default' ) ) ); … … 4810 4785 'unit' => 'rem', 4811 4786 ), 4812 'expected_output' => null,4787 'expected_output' => array(), 4813 4788 ), 4814 4789 'non numeric increment' => array( … … 4820 4795 'unit' => 'rem', 4821 4796 ), 4822 'expected_output' => null,4797 'expected_output' => array(), 4823 4798 ), 4824 4799 'non numeric steps' => array( … … 4830 4805 'unit' => 'rem', 4831 4806 ), 4832 'expected_output' => null,4807 'expected_output' => array(), 4833 4808 ), 4834 4809 'non numeric medium step' => array( … … 4840 4815 'unit' => 'rem', 4841 4816 ), 4842 'expected_output' => null,4817 'expected_output' => array(), 4843 4818 ), 4844 4819 'missing unit value' => array( … … 4849 4824 'mediumStep' => 4, 4850 4825 ), 4851 'expected_output' => null,4826 'expected_output' => array(), 4852 4827 ), 4853 4828 ); -
trunk/tests/phpunit/tests/theme/wpThemeJsonSchema.php
r57662 r58328 42 42 ), 43 43 'typography' => array( 44 'fontSizes' => array( 45 array( 46 'name' => 'Small', 47 'slug' => 'small', 48 'size' => 12, 49 ), 50 array( 51 'name' => 'Normal', 52 'slug' => 'normal', 53 'size' => 16, 54 ), 55 ), 44 56 'fontStyle' => false, 45 57 'fontWeight' => false, … … 127 139 ), 128 140 'typography' => array( 129 'fontStyle' => false, 130 'fontWeight' => false, 131 'letterSpacing' => false, 132 'textDecoration' => false, 133 'textTransform' => false, 141 'defaultFontSizes' => false, 142 'fontSizes' => array( 143 array( 144 'name' => 'Small', 145 'slug' => 'small', 146 'size' => 12, 147 ), 148 array( 149 'name' => 'Normal', 150 'slug' => 'normal', 151 'size' => 16, 152 ), 153 ), 154 'fontStyle' => false, 155 'fontWeight' => false, 156 'letterSpacing' => false, 157 'textDecoration' => false, 158 'textTransform' => false, 134 159 ), 135 160 'blocks' => array( … … 186 211 $this->assertEqualSetsWithIndex( $expected, $actual ); 187 212 } 213 214 public function test_migrate_v2_to_latest() { 215 $theme_json_v2 = array( 216 'version' => 2, 217 'settings' => array( 218 'typography' => array( 219 'fontSizes' => array( 220 array( 221 'name' => 'Small', 222 'slug' => 'small', 223 'size' => 12, 224 ), 225 array( 226 'name' => 'Normal', 227 'slug' => 'normal', 228 'size' => 16, 229 ), 230 ), 231 ), 232 'spacing' => array( 233 'spacingSizes' => array( 234 array( 235 'name' => 'Small', 236 'slug' => 20, 237 'size' => '20px', 238 ), 239 array( 240 'name' => 'Large', 241 'slug' => 80, 242 'size' => '80px', 243 ), 244 ), 245 ), 246 ), 247 ); 248 249 $actual = WP_Theme_JSON_Schema::migrate( $theme_json_v2 ); 250 251 $expected = array( 252 'version' => WP_Theme_JSON::LATEST_SCHEMA, 253 'settings' => array( 254 'typography' => array( 255 'defaultFontSizes' => false, 256 'fontSizes' => array( 257 array( 258 'name' => 'Small', 259 'slug' => 'small', 260 'size' => 12, 261 ), 262 array( 263 'name' => 'Normal', 264 'slug' => 'normal', 265 'size' => 16, 266 ), 267 ), 268 ), 269 'spacing' => array( 270 'defaultSpacingSizes' => false, 271 'spacingSizes' => array( 272 array( 273 'name' => 'Small', 274 'slug' => 20, 275 'size' => '20px', 276 ), 277 array( 278 'name' => 'Large', 279 'slug' => 80, 280 'size' => '80px', 281 ), 282 ), 283 ), 284 ), 285 ); 286 287 $this->assertEqualSetsWithIndex( $expected, $actual ); 288 } 188 289 } -
trunk/tests/qunit/fixtures/wp-api-generated.js
r58326 r58328 7856 7856 "description": "Version of the theme.json schema used for the typography settings.", 7857 7857 "type": "integer", 7858 "default": 2,7858 "default": 3, 7859 7859 "minimum": 2, 7860 "maximum": 2,7860 "maximum": 3, 7861 7861 "required": false 7862 7862 }, … … 7925 7925 "description": "Version of the theme.json schema used for the typography settings.", 7926 7926 "type": "integer", 7927 "default": 2,7927 "default": 3, 7928 7928 "minimum": 2, 7929 "maximum": 2,7929 "maximum": 3, 7930 7930 "required": false 7931 7931 }, … … 8058 8058 "description": "Version of the theme.json schema used for the typography settings.", 8059 8059 "type": "integer", 8060 "default": 2,8060 "default": 3, 8061 8061 "minimum": 2, 8062 "maximum": 2,8062 "maximum": 3, 8063 8063 "required": false 8064 8064 },
Note: See TracChangeset
for help on using the changeset viewer.