Changeset 52232 for trunk/src/wp-includes/class-wp-theme-json.php
- Timestamp:
- 11/23/2021 05:38:45 AM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-theme-json.php
r52062 r52232 52 52 */ 53 53 const VALID_ORIGINS = array( 54 ' core',54 'default', 55 55 'theme', 56 56 'user', … … 221 221 ), 222 222 'color' => array( 223 'background' => null, 224 'custom' => null, 225 'customDuotone' => null, 226 'customGradient' => null, 227 'duotone' => null, 228 'gradients' => null, 229 'link' => null, 230 'palette' => null, 231 'text' => null, 223 'background' => null, 224 'custom' => null, 225 'customDuotone' => null, 226 'customGradient' => null, 227 'defaultGradients' => null, 228 'defaultPalette' => null, 229 'duotone' => null, 230 'gradients' => null, 231 'link' => null, 232 'palette' => null, 233 'text' => null, 232 234 ), 233 235 'custom' => null, … … 325 327 * @param array $theme_json A structure that follows the theme.json schema. 326 328 * @param string $origin Optional. What source of data this object represents. 327 * One of ' core', 'theme', or 'user'. Default 'theme'.329 * One of 'default', 'theme', or 'user'. Default 'theme'. 328 330 */ 329 331 public function __construct( $theme_json = array(), $origin = 'theme' ) { … … 344 346 $preset = _wp_array_get( $this->theme_json, $path, null ); 345 347 if ( null !== $preset ) { 346 _wp_array_set( $this->theme_json, $path, array( $origin => $preset ) ); 348 if ( 'user' !== $origin || isset( $preset[0] ) ) { 349 _wp_array_set( $this->theme_json, $path, array( $origin => $preset ) ); 350 } 347 351 } 348 352 } … … 1473 1477 $output = array(); 1474 1478 foreach ( self::PRESETS_METADATA as $preset_metadata ) { 1475 $presets = _wp_array_get( $input, $preset_metadata['path'], null ); 1476 if ( null === $presets ) { 1477 continue; 1478 } 1479 1480 $escaped_preset = array(); 1481 foreach ( $presets as $preset ) { 1482 if ( 1483 esc_attr( esc_html( $preset['name'] ) ) === $preset['name'] && 1484 sanitize_html_class( $preset['slug'] ) === $preset['slug'] 1485 ) { 1486 $value = null; 1487 if ( isset( $preset_metadata['value_key'] ) ) { 1488 $value = $preset[ $preset_metadata['value_key'] ]; 1489 } elseif ( 1490 isset( $preset_metadata['value_func'] ) && 1491 is_callable( $preset_metadata['value_func'] ) 1479 foreach ( self::VALID_ORIGINS as $origin ) { 1480 $path_with_origin = array_merge( $preset_metadata['path'], array( $origin ) ); 1481 $presets = _wp_array_get( $input, $path_with_origin, null ); 1482 if ( null === $presets ) { 1483 continue; 1484 } 1485 1486 $escaped_preset = array(); 1487 foreach ( $presets as $preset ) { 1488 if ( 1489 esc_attr( esc_html( $preset['name'] ) ) === $preset['name'] && 1490 sanitize_html_class( $preset['slug'] ) === $preset['slug'] 1492 1491 ) { 1493 $value = call_user_func( $preset_metadata['value_func'], $preset ); 1494 } 1495 1496 $preset_is_valid = true; 1497 foreach ( $preset_metadata['properties'] as $property ) { 1498 if ( ! self::is_safe_css_declaration( $property, $value ) ) { 1499 $preset_is_valid = false; 1500 break; 1492 $value = null; 1493 if ( isset( $preset_metadata['value_key'] ) ) { 1494 $value = $preset[ $preset_metadata['value_key'] ]; 1495 } elseif ( 1496 isset( $preset_metadata['value_func'] ) && 1497 is_callable( $preset_metadata['value_func'] ) 1498 ) { 1499 $value = call_user_func( $preset_metadata['value_func'], $preset ); 1500 } 1501 1502 $preset_is_valid = true; 1503 foreach ( $preset_metadata['properties'] as $property ) { 1504 if ( ! self::is_safe_css_declaration( $property, $value ) ) { 1505 $preset_is_valid = false; 1506 break; 1507 } 1508 } 1509 1510 if ( $preset_is_valid ) { 1511 $escaped_preset[] = $preset; 1501 1512 } 1502 1513 } 1503 1504 if ( $preset_is_valid ) {1505 $escaped_preset[] = $preset;1506 }1507 1514 } 1508 } 1509 1510 if ( ! empty( $escaped_preset ) ) { 1511 _wp_array_set( $output, $preset_metadata['path'], $escaped_preset ); 1512 } 1513 } 1514 1515 1516 if ( ! empty( $escaped_preset ) ) { 1517 _wp_array_set( $output, $path_with_origin, $escaped_preset ); 1518 } 1519 } 1520 } 1515 1521 return $output; 1516 1522 }
Note: See TracChangeset
for help on using the changeset viewer.