Changeset 58466 for trunk/src/wp-includes/class-wp-theme-json.php
- Timestamp:
- 06/24/2024 08:49:52 AM (13 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-theme-json.php
r58444 r58466 744 744 * 745 745 * @since 5.8.0 746 * @since 6.6.0 Key spacingScale by origin, and Pre-generate the 747 * spacingSizes from spacingScale.746 * @since 6.6.0 Key spacingScale by origin, and Pre-generate the spacingSizes from spacingScale. 747 * Added unwrapping of shared block style variations into block type variations if registered. 748 748 * 749 749 * @param array $theme_json A structure that follows the theme.json schema. … … 760 760 $valid_element_names = array_keys( static::ELEMENTS ); 761 761 $valid_variations = static::get_valid_block_style_variations(); 762 $this->theme_json = static::unwrap_shared_block_style_variations( $this->theme_json, $valid_variations ); 762 763 $this->theme_json = static::sanitize( $this->theme_json, $valid_block_names, $valid_element_names, $valid_variations ); 763 764 $this->theme_json = static::maybe_opt_in_into_settings( $this->theme_json ); … … 801 802 _wp_array_set( $this->theme_json, $sizes_path, $merged_spacing_sizes ); 802 803 } 804 } 805 806 /** 807 * Unwraps shared block style variations. 808 * 809 * It takes the shared variations (styles.variations.variationName) and 810 * applies them to all the blocks that have the given variation registered 811 * (styles.blocks.blockType.variations.variationName). 812 * 813 * For example, given the `core/paragraph` and `core/group` blocks have 814 * registered the `section-a` style variation, and given the following input: 815 * 816 * { 817 * "styles": { 818 * "variations": { 819 * "section-a": { "color": { "background": "backgroundColor" } } 820 * } 821 * } 822 * } 823 * 824 * It returns the following output: 825 * 826 * { 827 * "styles": { 828 * "blocks": { 829 * "core/paragraph": { 830 * "variations": { 831 * "section-a": { "color": { "background": "backgroundColor" } } 832 * }, 833 * }, 834 * "core/group": { 835 * "variations": { 836 * "section-a": { "color": { "background": "backgroundColor" } } 837 * } 838 * } 839 * } 840 * } 841 * } 842 * 843 * @since 6.6.0 844 * 845 * @param array $theme_json A structure that follows the theme.json schema. 846 * @param array $valid_variations Valid block style variations. 847 * @return array Theme json data with shared variation definitions unwrapped under appropriate block types. 848 */ 849 private static function unwrap_shared_block_style_variations( $theme_json, $valid_variations ) { 850 if ( empty( $theme_json['styles']['variations'] ) || empty( $valid_variations ) ) { 851 return $theme_json; 852 } 853 854 $new_theme_json = $theme_json; 855 $variations = $new_theme_json['styles']['variations']; 856 857 foreach ( $valid_variations as $block_type => $registered_variations ) { 858 foreach ( $registered_variations as $variation_name ) { 859 $block_level_data = $new_theme_json['styles']['blocks'][ $block_type ]['variations'][ $variation_name ] ?? array(); 860 $top_level_data = $variations[ $variation_name ] ?? array(); 861 $merged_data = array_replace_recursive( $top_level_data, $block_level_data ); 862 if ( ! empty( $merged_data ) ) { 863 _wp_array_set( $new_theme_json, array( 'styles', 'blocks', $block_type, 'variations', $variation_name ), $merged_data ); 864 } 865 } 866 } 867 868 unset( $new_theme_json['styles']['variations'] ); 869 870 return $new_theme_json; 803 871 } 804 872 … … 967 1035 $schema['settings']['blocks'] = $schema_settings_blocks; 968 1036 $schema['settings']['typography']['fontFamilies'] = static::schema_in_root_and_per_origin( static::FONT_FAMILY_SCHEMA ); 969 970 /*971 * Shared block style variations can be registered from the theme.json data so we can't972 * validate them against pre-registered block style variations.973 */974 $schema['styles']['blocks']['variations'] = null;975 1037 976 1038 // Remove anything that's not present in the schema.
Note: See TracChangeset
for help on using the changeset viewer.