Skip to content

Commit

Permalink
Port changes from core
Browse files Browse the repository at this point in the history
  • Loading branch information
oandregal committed Mar 1, 2023
1 parent 0e13057 commit 23d8bce
Showing 1 changed file with 27 additions and 24 deletions.
51 changes: 27 additions & 24 deletions lib/class-wp-theme-json-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -3008,18 +3008,9 @@ protected static function remove_insecure_settings( $input ) {
}
}

foreach ( static::INDIRECT_PROPERTIES_METADATA as $property => $paths ) {
foreach ( $paths as $path ) {
$value = _wp_array_get( $input, $path, array() );
if (
isset( $value ) &&
! is_array( $value ) &&
static::is_safe_css_declaration( $property, $value )
) {
_wp_array_set( $output, $path, $value );
}
}
}
// Ensure indirect properties not included in any `PRESETS_METADATA` value are allowed.
static::remove_indirect_properties( $input, $output );

return $output;
}

Expand Down Expand Up @@ -3051,18 +3042,7 @@ protected static function remove_insecure_styles( $input ) {
}

// Ensure indirect properties not handled by `compute_style_properties` are allowed.
foreach ( static::INDIRECT_PROPERTIES_METADATA as $property => $paths ) {
foreach ( $paths as $path ) {
$value = _wp_array_get( $input, $path, array() );
if (
isset( $value ) &&
! is_array( $value ) &&
static::is_safe_css_declaration( $property, $value )
) {
_wp_array_set( $output, $path, $value );
}
}
}
static::remove_indirect_properties( $input, $output );

return $output;
}
Expand All @@ -3082,6 +3062,29 @@ protected static function is_safe_css_declaration( $property_name, $property_val
return ! empty( trim( $filtered ) );
}

/**
* Removes indirect properties from the given input node and
* sets in the given output node.
*
* @since 6.2.0
*
* @param array $input Node to process.
* @param array $output The processed node. Passed by reference.
*/
private static function remove_indirect_properties( $input, &$output ) {
foreach ( static::INDIRECT_PROPERTIES_METADATA as $property => $paths ) {
foreach ( $paths as $path ) {
$value = _wp_array_get( $input, $path );
if (
is_string( $value ) &&
static::is_safe_css_declaration( $property, $value )
) {
_wp_array_set( $output, $path, $value );
}
}
}
}

/**
* Returns the raw data.
*
Expand Down

0 comments on commit 23d8bce

Please sign in to comment.