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

Latest Posts: Don't remove transparent background color style #39488

Closed
wants to merge 1 commit into from

Conversation

t-hamano
Copy link
Contributor

Fix: #39402

What?

This PR prevents the transparent background color style from being removed in the rendering of the content.

Why?

In RichText, when an inline text color is specified, a transparent background color style (background-color:rgba(0, 0, 0, 0)) is generated at the same time.
This is to disable the browser's default style (yellow for Chrome), since highlighted text is wrapped with a mark tag.

However, this background color is sanitized by wp_kes_post, and the browser's default style is restored.
This is because parentheses are not allowed as CSS values inside wp_kses_post, except for calc and var.

This part:
https://github.com/WordPress/wordpress-develop/blob/34d46cd5013c6433bb0e4d2b447abe162e6521d1/src/wp-includes/kses.php#L2514-L2521

How?

This PR temporarily hooks safecss_filter_attr_allow_css filter and adds a transparent background color as valid CSS.
If you know of any other appropriate methods, please advise me.

Testing Instructions

  • Create post, and highlight a portion of text in any text color.
  • Insert the "Latest Post" block into any page.
  • Activate "Post content" from "Post content settings".
  • Select "Full post"
  • Verify that the highlighted text keeps transparent background color style on the front-end.

Screenshots or screencast

2e8162561c11e839c356556496c04d0b.mp4

@t-hamano t-hamano added [Type] Bug An existing feature does not function as intended [Block] Latest Posts Affects the Latest Posts Block labels Mar 16, 2022
@Mamaduka
Copy link
Member

Thanks for the PR, @t-hamano.

I think it might be better if we solve this by updating safecss_filter_attr and supporting rgba.

cc @SergeyBiryukov, @peterwilsoncc

@t-hamano
Copy link
Contributor Author

Yes, I've done this to minimize the scope of impact this time, but it might be better to add support to safecss_filter_attr, as similar problems may occur in the future.

@peterwilsoncc
Copy link
Contributor

I agree, it would be preferable to use the filter.

It would also be quite nice to get the support in to WP 6.0, a filter will make the migration easier.

@t-hamano
Copy link
Contributor Author

@Mamaduka
@peterwilsoncc

Sorry for the delay in addressing this PR.
I have submitted a ticket to core and attached a patch to fix it.
https://core.trac.wordpress.org/ticket/56391

Therefore, I would like to close this PR.

@t-hamano t-hamano closed this Aug 16, 2022
@t-hamano t-hamano deleted the fix/block-latest-post branch August 17, 2022 10:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Latest Posts Affects the Latest Posts Block [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Issue with block latest posts when I use a link with a highlight (inline)
3 participants