Changeset 56502
- Timestamp:
- 09/01/2023 02:51:55 AM (15 months ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-theme-json.php
r56414 r56502 2822 2822 * 2823 2823 * @since 5.9.0 2824 * @since 6.3.1 Preserves global styles block variations when securing styles. 2824 2825 * 2825 2826 * @param array $theme_json Structure to sanitize. … … 2879 2880 if ( ! empty( $output ) ) { 2880 2881 _wp_array_set( $sanitized, $metadata['path'], $output ); 2882 } 2883 2884 if ( isset( $metadata['variations'] ) ) { 2885 foreach ( $metadata['variations'] as $variation ) { 2886 $variation_input = _wp_array_get( $theme_json, $variation['path'], array() ); 2887 if ( empty( $variation_input ) ) { 2888 continue; 2889 } 2890 2891 $variation_output = static::remove_insecure_styles( $variation_input ); 2892 if ( ! empty( $variation_output ) ) { 2893 _wp_array_set( $sanitized, $variation['path'], $variation_output ); 2894 } 2895 } 2881 2896 } 2882 2897 } -
trunk/tests/phpunit/tests/theme/wpThemeJson.php
r56101 r56502 3870 3870 } 3871 3871 3872 public function test_block_style_variations() { 3873 wp_set_current_user( static::$administrator_id ); 3874 3875 $expected = array( 3876 'version' => WP_Theme_JSON::LATEST_SCHEMA, 3877 'styles' => array( 3878 'blocks' => array( 3879 'core/button' => array( 3880 'color' => array( 3881 'background' => 'blue', 3882 ), 3883 'variations' => array( 3884 'outline' => array( 3885 'color' => array( 3886 'background' => 'purple', 3887 ), 3888 ), 3889 ), 3890 ), 3891 ), 3892 ), 3893 ); 3894 3895 $actual = WP_Theme_JSON::remove_insecure_properties( $expected ); 3896 3897 $this->assertSameSetsWithIndex( $expected, $actual ); 3898 } 3899 3900 public function test_block_style_variations_with_invalid_properties() { 3901 wp_set_current_user( static::$administrator_id ); 3902 3903 $partially_invalid_variation = array( 3904 'version' => WP_Theme_JSON::LATEST_SCHEMA, 3905 'styles' => array( 3906 'blocks' => array( 3907 'core/button' => array( 3908 'color' => array( 3909 'background' => 'blue', 3910 ), 3911 'variations' => array( 3912 'outline' => array( 3913 'color' => array( 3914 'background' => 'purple', 3915 ), 3916 'invalid' => array( 3917 'value' => 'should be stripped', 3918 ), 3919 ), 3920 ), 3921 ), 3922 ), 3923 ), 3924 ); 3925 3926 $expected = array( 3927 'version' => WP_Theme_JSON::LATEST_SCHEMA, 3928 'styles' => array( 3929 'blocks' => array( 3930 'core/button' => array( 3931 'color' => array( 3932 'background' => 'blue', 3933 ), 3934 'variations' => array( 3935 'outline' => array( 3936 'color' => array( 3937 'background' => 'purple', 3938 ), 3939 ), 3940 ), 3941 ), 3942 ), 3943 ), 3944 ); 3945 3946 $actual = WP_Theme_JSON::remove_insecure_properties( $partially_invalid_variation ); 3947 3948 $this->assertSameSetsWithIndex( $expected, $actual ); 3949 } 3950 3872 3951 /** 3873 3952 * @ticket 56611
Note: See TracChangeset
for help on using the changeset viewer.