From 23d8bce6dc155d62c421ddc88f8c20d883a3dfd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9?= <583546+oandregal@users.noreply.github.com> Date: Wed, 1 Mar 2023 17:04:21 +0100 Subject: [PATCH] Port changes from core --- lib/class-wp-theme-json-gutenberg.php | 51 ++++++++++++++------------- 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/lib/class-wp-theme-json-gutenberg.php b/lib/class-wp-theme-json-gutenberg.php index 4d688bb5b8b83c..f891b1651205d4 100644 --- a/lib/class-wp-theme-json-gutenberg.php +++ b/lib/class-wp-theme-json-gutenberg.php @@ -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; } @@ -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; } @@ -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. *