Changeset 50977
- Timestamp:
- 05/24/2021 06:56:09 PM (4 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-theme-json.php
r50973 r50977 1018 1018 * @param WP_Theme_JSON $incoming Data to merge. 1019 1019 */ 1020 public function merge( $incoming ) {1020 public function merge( $incoming, $update_or_remove = 'remove' ) { 1021 1021 $incoming_data = $incoming->get_raw_data(); 1022 $existing_data = $this->theme_json; 1023 1024 // The array_replace_recursive algorithm merges at the leaf level. 1025 // For leaf values that are arrays it will use the numeric indexes for replacement. 1022 1026 $this->theme_json = array_replace_recursive( $this->theme_json, $incoming_data ); 1023 1027 1024 /* 1025 * The array_replace_recursive algorithm merges at the leaf level. 1026 * For leaf values that are arrays it will use the numeric indexes for replacement. 1027 * In those cases, what we want is to use the incoming value, if it exists. 1028 * 1029 * These are the cases that have array values at the leaf levels. 1030 */ 1031 $properties = array(); 1032 $properties[] = array( 'color', 'palette' ); 1033 $properties[] = array( 'color', 'gradients' ); 1034 $properties[] = array( 'custom' ); 1035 $properties[] = array( 'spacing', 'units' ); 1036 $properties[] = array( 'typography', 'fontSizes' ); 1037 $properties[] = array( 'typography', 'fontFamilies' ); 1028 // There are a few cases in which we want to merge things differently 1029 // from what array_replace_recursive does. 1030 1031 // Some incoming properties should replace the existing. 1032 $to_replace = array(); 1033 $to_replace[] = array( 'custom' ); 1034 $to_replace[] = array( 'spacing', 'units' ); 1035 $to_replace[] = array( 'typography', 'fontSizes' ); 1036 $to_replace[] = array( 'typography', 'fontFamilies' ); 1037 1038 // Some others should be appended to the existing. 1039 // If the slug is the same than an existing element, 1040 // the $update_or_remove param is used to decide 1041 // what to do with the existing element: 1042 // either remove it and append the incoming, 1043 // or update it with the incoming. 1044 $to_append = array(); 1045 $to_append[] = array( 'color', 'duotone' ); 1046 $to_append[] = array( 'color', 'gradients' ); 1047 $to_append[] = array( 'color', 'palette' ); 1038 1048 1039 1049 $nodes = self::get_setting_nodes( $this->theme_json ); 1040 1050 foreach ( $nodes as $metadata ) { 1041 foreach ( $ properties as $property_path) {1042 $path = array_merge( $metadata['path'], $p roperty_path);1051 foreach ( $to_replace as $path_to_replace ) { 1052 $path = array_merge( $metadata['path'], $path_to_replace ); 1043 1053 $node = _wp_array_get( $incoming_data, $path, array() ); 1044 1054 if ( ! empty( $node ) ) { 1045 1055 _wp_array_set( $this->theme_json, $path, $node ); 1046 1056 } 1057 } 1058 foreach ( $to_append as $path_to_append ) { 1059 $path = array_merge( $metadata['path'], $path_to_append ); 1060 $incoming_node = _wp_array_get( $incoming_data, $path, array() ); 1061 $existing_node = _wp_array_get( $existing_data, $path, array() ); 1062 1063 if ( empty( $incoming_node ) && empty( $existing_node ) ) { 1064 continue; 1065 } 1066 1067 $index_table = array(); 1068 $existing_slugs = array(); 1069 $merged = array(); 1070 foreach ( $existing_node as $key => $value ) { 1071 $index_table[ $value['slug'] ] = $key; 1072 $existing_slugs[] = $value['slug']; 1073 $merged[ $key ] = $value; 1074 } 1075 1076 $to_remove = array(); 1077 foreach ( $incoming_node as $value ) { 1078 if ( ! in_array( $value['slug'], $existing_slugs, true ) ) { 1079 $merged[] = $value; 1080 } elseif ( 'update' === $update_or_remove ) { 1081 $merged[ $index_table[ $value['slug'] ] ] = $value; 1082 } else { 1083 $merged[] = $value; 1084 $to_remove[] = $index_table[ $value['slug'] ]; 1085 } 1086 } 1087 1088 // Remove the duplicated values and pack the sparsed array. 1089 foreach ( $to_remove as $index ) { 1090 unset( $merged[ $index ] ); 1091 } 1092 $merged = array_values( $merged ); 1093 1094 _wp_array_set( $this->theme_json, $path, $merged ); 1047 1095 } 1048 1096 } -
trunk/src/wp-includes/theme.json
r50959 r50977 51 51 "name": "Vivid cyan blue to vivid purple", 52 52 "gradient": "linear-gradient(135deg,rgba(6,147,227,1) 0%,rgb(155,81,224) 100%)", 53 "slug": "vivid-cyan-blue-to-vivid-purple" 53 "slug": "vivid-cyan-blue-to-vivid-purple", 54 "origin": "core" 54 55 }, 55 56 { 56 57 "name": "Light green cyan to vivid green cyan", 57 58 "gradient": "linear-gradient(135deg,rgb(122,220,180) 0%,rgb(0,208,130) 100%)", 58 "slug": "light-green-cyan-to-vivid-green-cyan" 59 "slug": "light-green-cyan-to-vivid-green-cyan", 60 "origin": "core" 59 61 }, 60 62 { 61 63 "name": "Luminous vivid amber to luminous vivid orange", 62 64 "gradient": "linear-gradient(135deg,rgba(252,185,0,1) 0%,rgba(255,105,0,1) 100%)", 63 "slug": "luminous-vivid-amber-to-luminous-vivid-orange" 65 "slug": "luminous-vivid-amber-to-luminous-vivid-orange", 66 "origin": "core" 64 67 }, 65 68 { 66 69 "name": "Luminous vivid orange to vivid red", 67 70 "gradient": "linear-gradient(135deg,rgba(255,105,0,1) 0%,rgb(207,46,46) 100%)", 68 "slug": "luminous-vivid-orange-to-vivid-red" 71 "slug": "luminous-vivid-orange-to-vivid-red", 72 "origin": "core" 69 73 }, 70 74 { 71 75 "name": "Very light gray to cyan bluish gray", 72 76 "gradient": "linear-gradient(135deg,rgb(238,238,238) 0%,rgb(169,184,195) 100%)", 73 "slug": "very-light-gray-to-cyan-bluish-gray" 77 "slug": "very-light-gray-to-cyan-bluish-gray", 78 "origin": "core" 74 79 }, 75 80 { 76 81 "name": "Cool to warm spectrum", 77 82 "gradient": "linear-gradient(135deg,rgb(74,234,220) 0%,rgb(151,120,209) 20%,rgb(207,42,186) 40%,rgb(238,44,130) 60%,rgb(251,105,98) 80%,rgb(254,248,76) 100%)", 78 "slug": "cool-to-warm-spectrum" 83 "slug": "cool-to-warm-spectrum", 84 "origin": "core" 79 85 }, 80 86 { 81 87 "name": "Blush light purple", 82 88 "gradient": "linear-gradient(135deg,rgb(255,206,236) 0%,rgb(152,150,240) 100%)", 83 "slug": "blush-light-purple" 89 "slug": "blush-light-purple", 90 "origin": "core" 84 91 }, 85 92 { 86 93 "name": "Blush bordeaux", 87 94 "gradient": "linear-gradient(135deg,rgb(254,205,165) 0%,rgb(254,45,45) 50%,rgb(107,0,62) 100%)", 88 "slug": "blush-bordeaux" 95 "slug": "blush-bordeaux", 96 "origin": "core" 89 97 }, 90 98 { 91 99 "name": "Luminous dusk", 92 100 "gradient": "linear-gradient(135deg,rgb(255,203,112) 0%,rgb(199,81,192) 50%,rgb(65,88,208) 100%)", 93 "slug": "luminous-dusk" 101 "slug": "luminous-dusk", 102 "origin": "core" 94 103 }, 95 104 { 96 105 "name": "Pale ocean", 97 106 "gradient": "linear-gradient(135deg,rgb(255,245,203) 0%,rgb(182,227,212) 50%,rgb(51,167,181) 100%)", 98 "slug": "pale-ocean" 107 "slug": "pale-ocean", 108 "origin": "core" 99 109 }, 100 110 { 101 111 "name": "Electric grass", 102 112 "gradient": "linear-gradient(135deg,rgb(202,248,128) 0%,rgb(113,206,126) 100%)", 103 "slug": "electric-grass" 113 "slug": "electric-grass", 114 "origin": "core" 104 115 }, 105 116 { 106 117 "name": "Midnight", 107 118 "gradient": "linear-gradient(135deg,rgb(2,3,129) 0%,rgb(40,116,252) 100%)", 108 "slug": "midnight" 119 "slug": "midnight", 120 "origin": "core" 109 121 } 110 122 ], … … 114 126 "name": "Black", 115 127 "slug": "black", 116 "color": "#000000" 128 "color": "#000000", 129 "origin": "core" 117 130 }, 118 131 { 119 132 "name": "Cyan bluish gray", 120 133 "slug": "cyan-bluish-gray", 121 "color": "#abb8c3" 134 "color": "#abb8c3", 135 "origin": "core" 122 136 }, 123 137 { 124 138 "name": "White", 125 139 "slug": "white", 126 "color": "#ffffff" 140 "color": "#ffffff", 141 "origin": "core" 127 142 }, 128 143 { 129 144 "name": "Pale pink", 130 145 "slug": "pale-pink", 131 "color": "#f78da7" 146 "color": "#f78da7", 147 "origin": "core" 132 148 }, 133 149 { 134 150 "name": "Vivid red", 135 151 "slug": "vivid-red", 136 "color": "#cf2e2e" 152 "color": "#cf2e2e", 153 "origin": "core" 137 154 }, 138 155 { 139 156 "name": "Luminous vivid orange", 140 157 "slug": "luminous-vivid-orange", 141 "color": "#ff6900" 158 "color": "#ff6900", 159 "origin": "core" 142 160 }, 143 161 { 144 162 "name": "Luminous vivid amber", 145 163 "slug": "luminous-vivid-amber", 146 "color": "#fcb900" 164 "color": "#fcb900", 165 "origin": "core" 147 166 }, 148 167 { 149 168 "name": "Light green cyan", 150 169 "slug": "light-green-cyan", 151 "color": "#7bdcb5" 170 "color": "#7bdcb5", 171 "origin": "core" 152 172 }, 153 173 { 154 174 "name": "Vivid green cyan", 155 175 "slug": "vivid-green-cyan", 156 "color": "#00d084" 176 "color": "#00d084", 177 "origin": "core" 157 178 }, 158 179 { 159 180 "name": "Pale cyan blue", 160 181 "slug": "pale-cyan-blue", 161 "color": "#8ed1fc" 182 "color": "#8ed1fc", 183 "origin": "core" 162 184 }, 163 185 { 164 186 "name": "Vivid cyan blue", 165 187 "slug": "vivid-cyan-blue", 166 "color": "#0693e3" 188 "color": "#0693e3", 189 "origin": "core" 167 190 }, 168 191 { 169 192 "name": "Vivid purple", 170 193 "slug": "vivid-purple", 171 "color": "#9b51e0" 194 "color": "#9b51e0", 195 "origin": "core" 172 196 } 173 197 ] -
trunk/tests/phpunit/tests/theme/wpThemeJson.php
r50973 r50977 410 410 'palette' => array( 411 411 array( 412 'slug' => 'red', 413 'color' => 'red', 414 ), 415 array( 416 'slug' => 'green', 417 'color' => 'green', 418 ), 419 array( 412 420 'slug' => 'blue', 413 421 'color' => 'blue',
Note: See TracChangeset
for help on using the changeset viewer.