mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-06-28 22:30:04 +00:00
Editor: Preserve block style variations when securing theme.
Adds the ability to process block style variations to the `remove_insecure_properties` function of theme json class. Props dsas, ramonopoly. Fixes #59108. git-svn-id: https://develop.svn.wordpress.org/trunk@56502 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -2821,6 +2821,7 @@ class WP_Theme_JSON {
|
||||
* Removes insecure data from theme.json.
|
||||
*
|
||||
* @since 5.9.0
|
||||
* @since 6.3.1 Preserves global styles block variations when securing styles.
|
||||
*
|
||||
* @param array $theme_json Structure to sanitize.
|
||||
* @return array Sanitized structure.
|
||||
@@ -2879,6 +2880,20 @@ class WP_Theme_JSON {
|
||||
if ( ! empty( $output ) ) {
|
||||
_wp_array_set( $sanitized, $metadata['path'], $output );
|
||||
}
|
||||
|
||||
if ( isset( $metadata['variations'] ) ) {
|
||||
foreach ( $metadata['variations'] as $variation ) {
|
||||
$variation_input = _wp_array_get( $theme_json, $variation['path'], array() );
|
||||
if ( empty( $variation_input ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$variation_output = static::remove_insecure_styles( $variation_input );
|
||||
if ( ! empty( $variation_output ) ) {
|
||||
_wp_array_set( $sanitized, $variation['path'], $variation_output );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$setting_nodes = static::get_setting_nodes( $theme_json );
|
||||
|
||||
@@ -3869,6 +3869,85 @@ class Tests_Theme_wpThemeJson extends WP_UnitTestCase {
|
||||
);
|
||||
}
|
||||
|
||||
public function test_block_style_variations() {
|
||||
wp_set_current_user( static::$administrator_id );
|
||||
|
||||
$expected = array(
|
||||
'version' => WP_Theme_JSON::LATEST_SCHEMA,
|
||||
'styles' => array(
|
||||
'blocks' => array(
|
||||
'core/button' => array(
|
||||
'color' => array(
|
||||
'background' => 'blue',
|
||||
),
|
||||
'variations' => array(
|
||||
'outline' => array(
|
||||
'color' => array(
|
||||
'background' => 'purple',
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
$actual = WP_Theme_JSON::remove_insecure_properties( $expected );
|
||||
|
||||
$this->assertSameSetsWithIndex( $expected, $actual );
|
||||
}
|
||||
|
||||
public function test_block_style_variations_with_invalid_properties() {
|
||||
wp_set_current_user( static::$administrator_id );
|
||||
|
||||
$partially_invalid_variation = array(
|
||||
'version' => WP_Theme_JSON::LATEST_SCHEMA,
|
||||
'styles' => array(
|
||||
'blocks' => array(
|
||||
'core/button' => array(
|
||||
'color' => array(
|
||||
'background' => 'blue',
|
||||
),
|
||||
'variations' => array(
|
||||
'outline' => array(
|
||||
'color' => array(
|
||||
'background' => 'purple',
|
||||
),
|
||||
'invalid' => array(
|
||||
'value' => 'should be stripped',
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
$expected = array(
|
||||
'version' => WP_Theme_JSON::LATEST_SCHEMA,
|
||||
'styles' => array(
|
||||
'blocks' => array(
|
||||
'core/button' => array(
|
||||
'color' => array(
|
||||
'background' => 'blue',
|
||||
),
|
||||
'variations' => array(
|
||||
'outline' => array(
|
||||
'color' => array(
|
||||
'background' => 'purple',
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
$actual = WP_Theme_JSON::remove_insecure_properties( $partially_invalid_variation );
|
||||
|
||||
$this->assertSameSetsWithIndex( $expected, $actual );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 56611
|
||||
* @ticket 58548
|
||||
|
||||
Reference in New Issue
Block a user