Changeset 54805
- Timestamp:
- 11/11/2022 02:05:56 AM (2 years ago)
- Location:
- branches/6.1
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/6.1
-
branches/6.1/src/wp-includes/class-wp-theme-json.php
r54800 r54805 462 462 $class_name = ''; 463 463 464 // TODO: Replace array_key_exists() with isset() check once WordPress drops 465 // support for PHP 5.6. See https://core.trac.wordpress.org/ticket/57067. 464 466 if ( array_key_exists( $element, static::__EXPERIMENTAL_ELEMENT_CLASS_NAMES ) ) { 465 467 $class_name = static::__EXPERIMENTAL_ELEMENT_CLASS_NAMES[ $element ]; … … 520 522 foreach ( $nodes as $node ) { 521 523 foreach ( static::PRESETS_METADATA as $preset_metadata ) { 522 $path = array_merge( $node['path'], $preset_metadata['path'] ); 524 $path = $node['path']; 525 foreach ( $preset_metadata['path'] as $subpath ) { 526 $path[] = $subpath; 527 } 523 528 $preset = _wp_array_get( $this->theme_json, $path, null ); 524 529 if ( null !== $preset ) { … … 609 614 $styles_non_top_level = static::VALID_STYLES; 610 615 foreach ( array_keys( $styles_non_top_level ) as $section ) { 616 // array_key_exists() needs to be used instead of isset() because the value can be null. 611 617 if ( array_key_exists( $section, $styles_non_top_level ) && is_array( $styles_non_top_level[ $section ] ) ) { 612 618 foreach ( array_keys( $styles_non_top_level[ $section ] ) as $prop ) { … … 632 638 $schema_styles_elements[ $element ] = $styles_non_top_level; 633 639 640 // TODO: Replace array_key_exists() with isset() check once WordPress drops 641 // support for PHP 5.6. See https://core.trac.wordpress.org/ticket/57067. 634 642 if ( array_key_exists( $element, static::VALID_ELEMENT_PSEUDO_SELECTORS ) ) { 635 643 foreach ( static::VALID_ELEMENT_PSEUDO_SELECTORS[ $element ] as $pseudo_selector ) { … … 1274 1282 $selector = $metadata['selector']; 1275 1283 1276 $node = _wp_array_get( $this->theme_json, $metadata['path'], array() ); 1277 $declarations = array_merge( static::compute_preset_vars( $node, $origins ), static::compute_theme_vars( $node ) ); 1284 $node = _wp_array_get( $this->theme_json, $metadata['path'], array() ); 1285 $declarations = static::compute_preset_vars( $node, $origins ); 1286 $theme_vars_declarations = static::compute_theme_vars( $node ); 1287 foreach ( $theme_vars_declarations as $theme_vars_declaration ) { 1288 $declarations[] = $theme_vars_declaration; 1289 } 1278 1290 1279 1291 $stylesheet .= static::to_ruleset( $selector, $declarations ); … … 1602 1614 1603 1615 if ( is_array( $value ) ) { 1604 $new_prefix = $new_key . $token;1605 $ result = array_merge(1606 $result,1607 static::flatten_tree( $value, $new_prefix, $token )1608 );1616 $new_prefix = $new_key . $token; 1617 $flattened_subtree = static::flatten_tree( $value, $new_prefix, $token ); 1618 foreach ( $flattened_subtree as $subtree_key => $subtree_value ) { 1619 $result[ $subtree_key ] = $subtree_value; 1620 } 1609 1621 } else { 1610 1622 $result[ $new_key ] = $value; … … 1668 1680 $path_string = implode( '.', $value_path ); 1669 1681 if ( 1682 // TODO: Replace array_key_exists() with isset() check once WordPress drops 1683 // support for PHP 5.6. See https://core.trac.wordpress.org/ticket/57067. 1670 1684 array_key_exists( $path_string, static::PROTECTED_PROPERTIES ) && 1671 1685 _wp_array_get( $settings, static::PROTECTED_PROPERTIES[ $path_string ], null ) === null … … 1743 1757 * For example: { "ref": "style.color.background" } => "#fff". 1744 1758 */ 1745 if ( is_array( $value ) && array_key_exists( 'ref', $value) ) {1759 if ( is_array( $value ) && isset( $value['ref'] ) ) { 1746 1760 $value_path = explode( '.', $value['ref'] ); 1747 1761 $ref_value = _wp_array_get( $theme_json, $value_path ); … … 1751 1765 } 1752 1766 1753 if ( is_array( $ref_value ) && array_key_exists( 'ref', $ref_value) ) {1767 if ( is_array( $ref_value ) && isset( $ref_value['ref'] ) ) { 1754 1768 $path_string = json_encode( $path ); 1755 1769 $ref_value_string = json_encode( $ref_value ); … … 1887 1901 1888 1902 // Handle any pseudo selectors for the element. 1903 // TODO: Replace array_key_exists() with isset() check once WordPress drops 1904 // support for PHP 5.6. See https://core.trac.wordpress.org/ticket/57067. 1889 1905 if ( array_key_exists( $element, static::VALID_ELEMENT_PSEUDO_SELECTORS ) ) { 1890 1906 foreach ( static::VALID_ELEMENT_PSEUDO_SELECTORS[ $element ] as $pseudo_selector ) { … … 1906 1922 } 1907 1923 1908 $nodes = array_merge( $nodes, static::get_block_nodes( $theme_json ) ); 1924 $block_nodes = static::get_block_nodes( $theme_json ); 1925 foreach ( $block_nodes as $block_node ) { 1926 $nodes[] = $block_node; 1927 } 1909 1928 1910 1929 /** … … 1983 2002 1984 2003 // Handle any pseudo selectors for the element. 2004 // TODO: Replace array_key_exists() with isset() check once WordPress drops 2005 // support for PHP 5.6. See https://core.trac.wordpress.org/ticket/57067. 1985 2006 if ( array_key_exists( $element, static::VALID_ELEMENT_PSEUDO_SELECTORS ) ) { 1986 2007 foreach ( static::VALID_ELEMENT_PSEUDO_SELECTORS[ $element ] as $pseudo_selector ) { … … 2036 2057 // support features use the same custom selector. 2037 2058 if ( isset( $feature_declarations[ $feature_selector ] ) ) { 2038 $feature_declarations[ $feature_selector ] = array_merge( $feature_declarations[ $feature_selector ], $new_feature_declarations ); 2059 foreach ( $new_feature_declarations as $new_feature_declaration ) { 2060 $feature_declarations[ $feature_selector ][] = $feature_declaration; 2061 } 2039 2062 } else { 2040 2063 $feature_declarations[ $feature_selector ] = $new_feature_declarations; … … 2060 2083 $element_pseudo_allowed = array(); 2061 2084 2085 // TODO: Replace array_key_exists() with isset() check once WordPress drops 2086 // support for PHP 5.6. See https://core.trac.wordpress.org/ticket/57067. 2062 2087 if ( array_key_exists( $current_element, static::VALID_ELEMENT_PSEUDO_SELECTORS ) ) { 2063 2088 $element_pseudo_allowed = static::VALID_ELEMENT_PSEUDO_SELECTORS[ $current_element ]; … … 2085 2110 */ 2086 2111 if ( $pseudo_selector && isset( $node[ $pseudo_selector ] ) && 2112 // TODO: Replace array_key_exists() with isset() check once WordPress drops 2113 // support for PHP 5.6. See https://core.trac.wordpress.org/ticket/57067. 2087 2114 array_key_exists( $current_element, static::VALID_ELEMENT_PSEUDO_SELECTORS ) 2088 2115 && in_array( $pseudo_selector, static::VALID_ELEMENT_PSEUDO_SELECTORS[ $current_element ], true ) … … 2284 2311 $slugs_global = static::get_default_slugs( $this->theme_json, array( 'settings' ) ); 2285 2312 foreach ( $nodes as $node ) { 2286 $slugs_node = static::get_default_slugs( $this->theme_json, $node['path'] );2287 $slugs = array_merge_recursive( $slugs_global, $slugs_node );2288 2289 2313 // Replace the spacing.units. 2290 $path = array_merge( $node['path'], array( 'spacing', 'units' ) ); 2314 $path = $node['path']; 2315 $path[] = 'spacing'; 2316 $path[] = 'units'; 2317 2291 2318 $content = _wp_array_get( $incoming_data, $path, null ); 2292 2319 if ( isset( $content ) ) { … … 2299 2326 2300 2327 foreach ( static::VALID_ORIGINS as $origin ) { 2301 $base_path = array_merge( $node['path'], $preset['path'] ); 2302 $path = array_merge( $base_path, array( $origin ) ); 2303 $content = _wp_array_get( $incoming_data, $path, null ); 2328 $base_path = $node['path']; 2329 foreach ( $preset['path'] as $leaf ) { 2330 $base_path[] = $leaf; 2331 } 2332 2333 $path = $base_path; 2334 $path[] = $origin; 2335 2336 $content = _wp_array_get( $incoming_data, $path, null ); 2304 2337 if ( ! isset( $content ) ) { 2305 2338 continue; … … 2307 2340 2308 2341 if ( 'theme' === $origin && $preset['use_default_names'] ) { 2309 foreach ( $content as &$item ) {2310 if ( ! array_key_exists( 'name', $item) ) {2342 foreach ( $content as $key => $item ) { 2343 if ( ! isset( $item['name'] ) ) { 2311 2344 $name = static::get_name_from_defaults( $item['slug'], $base_path ); 2312 2345 if ( null !== $name ) { 2313 $ item['name'] = $name;2346 $content[ $key ]['name'] = $name; 2314 2347 } 2315 2348 } … … 2323 2356 _wp_array_set( $this->theme_json, $path, $content ); 2324 2357 } else { 2358 $slugs_node = static::get_default_slugs( $this->theme_json, $node['path'] ); 2359 $slugs = array_merge_recursive( $slugs_global, $slugs_node ); 2360 2325 2361 $slugs_for_preset = _wp_array_get( $slugs, $preset['path'], array() ); 2326 2362 $content = static::filter_slugs( $content, $slugs_for_preset ); … … 2435 2471 2436 2472 foreach ( static::PRESETS_METADATA as $metadata ) { 2437 $path = array_merge( $node_path, $metadata['path'], array( 'default' ) ); 2473 $path = $node_path; 2474 foreach ( $metadata['path'] as $leaf ) { 2475 $path[] = $leaf; 2476 } 2477 $path[] = 'default'; 2478 2438 2479 $preset = _wp_array_get( $data, $path, null ); 2439 2480 if ( ! isset( $preset ) ) { … … 2464 2505 */ 2465 2506 protected function get_name_from_defaults( $slug, $base_path ) { 2466 $path = array_merge( $base_path, array( 'default' ) ); 2507 $path = $base_path; 2508 $path[] = 'default'; 2467 2509 $default_content = _wp_array_get( $this->theme_json, $path, null ); 2468 2510 if ( ! $default_content ) { … … 2540 2582 * or insecure styles here. 2541 2583 */ 2584 // TODO: Replace array_key_exists() with isset() check once WordPress drops 2585 // support for PHP 5.6. See https://core.trac.wordpress.org/ticket/57067. 2542 2586 if ( array_key_exists( $current_element, static::VALID_ELEMENT_PSEUDO_SELECTORS ) ) { 2543 2587 foreach ( static::VALID_ELEMENT_PSEUDO_SELECTORS[ $current_element ] as $pseudo_selector ) { … … 2594 2638 foreach ( static::PRESETS_METADATA as $preset_metadata ) { 2595 2639 foreach ( static::VALID_ORIGINS as $origin ) { 2596 $path_with_origin = array_merge( $preset_metadata['path'], array( $origin ) ); 2597 $presets = _wp_array_get( $input, $path_with_origin, null ); 2640 $path_with_origin = $preset_metadata['path']; 2641 $path_with_origin[] = $origin; 2642 $presets = _wp_array_get( $input, $path_with_origin, null ); 2598 2643 if ( null === $presets ) { 2599 2644 continue; … … 2840 2885 foreach ( $nodes as $node ) { 2841 2886 foreach ( static::PRESETS_METADATA as $preset_metadata ) { 2842 $path = array_merge( $node['path'], $preset_metadata['path'] ); 2887 $path = $node['path']; 2888 foreach ( $preset_metadata['path'] as $preset_metadata_path ) { 2889 $path[] = $preset_metadata_path; 2890 } 2843 2891 $preset = _wp_array_get( $output, $path, null ); 2844 2892 if ( null === $preset ) { … … 2874 2922 $all_opt_ins_are_set = true; 2875 2923 foreach ( static::APPEARANCE_TOOLS_OPT_INS as $opt_in_path ) { 2876 $full_path = array_merge( $node['path'], $opt_in_path ); 2924 $full_path = $node['path']; 2925 foreach ( $opt_in_path as $opt_in_path_item ) { 2926 $full_path[] = $opt_in_path_item; 2927 } 2877 2928 // Use "unset prop" as a marker instead of "null" because 2878 2929 // "null" can be a valid value for some props (e.g. blockGap). … … 2885 2936 2886 2937 if ( $all_opt_ins_are_set ) { 2887 _wp_array_set( $output, array_merge( $node['path'], array( 'appearanceTools' ) ), true ); 2938 $node_path_with_appearance_tools = $node['path']; 2939 $node_path_with_appearance_tools[] = 'appearanceTools'; 2940 _wp_array_set( $output, $node_path_with_appearance_tools, true ); 2888 2941 foreach ( static::APPEARANCE_TOOLS_OPT_INS as $opt_in_path ) { 2889 $full_path = array_merge( $node['path'], $opt_in_path ); 2942 $full_path = $node['path']; 2943 foreach ( $opt_in_path as $opt_in_path_item ) { 2944 $full_path[] = $opt_in_path_item; 2945 } 2890 2946 // Use "unset prop" as a marker instead of "null" because 2891 2947 // "null" can be a valid value for some props (e.g. blockGap). … … 3038 3094 } 3039 3095 3040 $spacing_sizes = array_merge( $below_sizes, $above_sizes ); 3096 $spacing_sizes = $below_sizes; 3097 foreach ( $above_sizes as $above_sizes_item ) { 3098 $spacing_sizes[] = $above_sizes_item; 3099 } 3041 3100 3042 3101 // If there are 7 or less steps in the scale revert to numbers for labels instead of t-shirt sizes. -
branches/6.1/tests/phpunit/tests/theme/wpThemeJson.php
r54446 r54805 10 10 * 11 11 * @group themes 12 * 13 * @covers WP_Theme_JSON 12 14 */ 13 14 15 class Tests_Theme_wpThemeJson extends WP_UnitTestCase { 15 16
Note: See TracChangeset
for help on using the changeset viewer.