Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Button block with gradient background fails to validate on multisite #17938

Closed
mmtr opened this issue Oct 14, 2019 · 3 comments
Closed

Button block with gradient background fails to validate on multisite #17938

mmtr opened this issue Oct 14, 2019 · 3 comments
Assignees
Labels
[Block] Buttons Affects the Buttons Block [Feature] Multisite Anything related to the specific experience of using a multisite [Type] Bug An existing feature does not function as intended

Comments

@mmtr
Copy link
Contributor

mmtr commented Oct 14, 2019

Describe the bug
Button blocks set with a gradient background are considered invalid blocks by the editor when loaded on a multisite WordPress install, due to the KSES filters registered on those environments.

Screen Shot 2019-10-14 at 18 14 44

Content generated by `save` function:

<div class="wp-block-button"><a class="wp-block-button__link has-background" style="background:linear-gradient(135deg, rgba(6, 147, 227, 1) 0%, rgb(155, 81, 224) 100%)">test21</a></div>

Content retrieved from post body:

<div class="wp-block-button"><a class="wp-block-button__link has-background" style="background:linear-gradient(135deg,rgba(6,147,227,1) 0%,rgb(155,81,224) 100%);">test21</a></div>

The only difference between the content generated by the save function and the one retrieved from DB are the missing whitespaces on the style attribute.

Those whitespaces are removed by the wp_kses_hair function which is executed by the KSES filters triggered when saving the post. These filters are only registered when a user doesn't have the unfiltered_html capability (which is the case for multisite regular admins).

To reproduce

  1. Run Gutenberg master on a multisite install, or test with a user not having the unfiltered_html capability.
  2. Add a new post.
  3. Insert a button block.
  4. Set a gradient background on the button.
  5. Save or publish the post.
  6. Reload the editor.
  7. Note how the button block is marked as invalid.

Expected behavior
The button should remain valid.

@mmtr mmtr added [Type] Bug An existing feature does not function as intended [Feature] Multisite Anything related to the specific experience of using a multisite [Block] Buttons Affects the Buttons Block labels Oct 14, 2019
@jorgefilipecosta jorgefilipecosta self-assigned this Oct 14, 2019
@jorgefilipecosta
Copy link
Member

jorgefilipecosta commented Oct 14, 2019

Hi @mmtr,
Thank you for reporting this issue.
I submitted a PR to fix the spacing problem: #17940.
But we have another problem, for contributor rules our inline style is totally removed.
This happens because WP core has logic to only accept style rules with () inside for url(...):
https://github.com/WordPress/wordpress-develop/blob/master/src/wp-includes/kses.php#L2264-L2271

It seems we can not have a simple temporary workaround in the plugin because although we can use safe_style_css to add new accepted style properties there is no filter to remove this logic from being applied.
I will try to submit a fix in WP core, to address the contributor problem.

@mmtr
Copy link
Contributor Author

mmtr commented Oct 15, 2019

Thanks @jorgefilipecosta!

@jorgefilipecosta
Copy link
Member

Closing this issue as the core patch was merged, the problem should be fixed on the next WordPress release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Buttons Affects the Buttons Block [Feature] Multisite Anything related to the specific experience of using a multisite [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

No branches or pull requests

2 participants