-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Description
The KSES filters prevent applying some block variation styles via the Global Styles sidebar in the site editor.
These filters are only registered when a user doesn't have the unfiltered_html capability (which is the case for multisite regular admins).
When these filters are active, some changes to the block variation property are reverted back to their previous value.
Looking at the HTTP request to the global-styles endpoint, the PUT request includes the block variation changes but the response doesn't.
After doing some debugging, I noticed this happens because of this line. After removing the validation, the save worked as expected. This change was introduced in the context of this PR, which seems to fix a similar issue.
Comparing the input and output of that line it seems that it removes properties when it shouldn't:
Given input
array (
'elements' =>
array (
'heading' =>
array (
'color' =>
array (
'text' => 'var(--wp--preset--color--theme-2)',
),
),
'button' =>
array (
':hover' =>
array (
'color' =>
array (
'background' => 'color-mix(in srgb, var(--wp--preset--color--theme-4) 85%, #FFF)',
'text' => 'var(--wp--preset--color--theme-3)',
),
),
'color' =>
array (
'background' => 'var(--wp--preset--color--theme-4)',
'text' => 'var(--wp--preset--color--theme-3)',
),
),
),
'color' =>
array (
'background' => 'var(--wp--preset--color--theme-3)',
'text' => 'var(--wp--preset--color--theme-4)',
),
'blocks' =>
array (
'core/separator' =>
array (
'color' =>
array (
'text' => 'color-mix(in srgb, currentColor 25%, transparent)',
),
),
),
)
Output generated
array (
0 =>
array (
'name' => 'background-color',
'value' => 'var(--wp--preset--color--theme-3)',
),
1 =>
array (
'name' => 'color',
'value' => 'var(--wp--preset--color--theme-4)',
),
)
Step-by-step reproduction instructions
- Activate latest Gutenberg on a multisite install, or test with a user not having the unfiltered_html capability, or enable the KSES filters with add_action( 'init', 'kses_init_filters' );
- Install the Assembler theme
- Go to Appearance > Editor
- Apply this pattern on your site (just to be sure you follow the same steps): https://gist.github.com/richtabor/e25d9e316e51f39495425c86b425a49e
- Open the Global Styles panel
- Select a style variation (e.g. "Noir")
- Save it
- Notice the style variation card is not highlighted
- Click on it again
- Notice that the Save button is enabled
- Click Save and notice that some elements are not saved
- Repeat the save and notice that the same elements are not saved