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

Custom CSS not saving #46651

Closed
dsas opened this issue Dec 19, 2022 · 5 comments
Closed

Custom CSS not saving #46651

dsas opened this issue Dec 19, 2022 · 5 comments
Labels
Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json [Priority] High Used to indicate top priority items that need quick attention [Type] Bug An existing feature does not function as intended

Comments

@dsas
Copy link
Contributor

dsas commented Dec 19, 2022

Description

Custom CSS is being reverted when pressing save.

Step-by-step reproduction instructions

  1. Make DISALLOW_UNFILTERED_HTML defined and truthy, e.g. by adding config: { "DISALLOW_UNFILTERED_HTML": true }, to the top level in .wp-env.json and starting with wp-env
  2. Open the site editor
  3. Open the global styles sidebar
  4. Click the new 'Custom CSS' feature at the bottom of the page
  5. Paste some style rule in like h1.wp-block-heading { text-decoration:underline; color: orange; }
  6. Notice that the editor to the left now makes headings orange and underlined ✅
  7. Press Save and then Save again once the pre-save prompt has loaded

Screenshots, screen recording, code snippet

Screen.Capture.on.2022-12-19.at.13-09-07.mp4

The save HTTP request included the css values:

{
	"id": 6,
	"styles": {
		"blocks": {<CUT_FOR_BREVITY>},
		"color": {
			"gradient": "var(--wp--preset--gradient--base-secondary-base) no-repeat"
		},
		"css": "h1.wp-block-heading { text-decoration:underline; color: orange; }",
		
		"typography": {
			"fontFamily": "var(--wp--preset--font-family--dm-sans)"
		}
	}
}

The response however did not include a "css" property.

Environment info

Using the wp-env from Gutenberg 14.8.01-rc.1, can also reproduce on current trunk (1b5994a)

With DISALLOW_UNFILTERED_HTML, or presumably admin on multisite install or using any role with edit_theme_options but w/o unfiltered_html

Please confirm that you have searched existing issues in the repo.

Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

Yes

@dsas dsas added the Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json label Dec 19, 2022
@dsas dsas added this to the Gutenberg 14.8 milestone Dec 19, 2022
@dsas dsas added the [Type] Bug An existing feature does not function as intended label Dec 19, 2022
@priethor priethor added the [Priority] High Used to indicate top priority items that need quick attention label Dec 19, 2022
@glendaviesnz
Copy link
Contributor

Looking at putting custom css behind an experimental flag until this is resolved.

@glendaviesnz
Copy link
Contributor

This feature has been moved behind an experimental flag for now.

At the moment a valid canUserUseUnfilteredHTML selector is not available in the site editor as the current selector is tied to the current post. To resolve this issue we need to add a way to reliably determine if the user has unfiltered HTML capabilities in the site editor context.

@mmtr
Copy link
Contributor

mmtr commented Dec 20, 2022

To resolve this issue we need to add a way to reliably determine if the user has unfiltered HTML capabilities in the site editor context.

@glendaviesnz I think we need to consider the KSES filters as well.

Right now, the Custom CSS feature within Global Styles doesn't work when the KSES filters are active for users with the unfiltered_html capability, as opposed to the Custom CSS feature within the Customizer.

These filters are only registered when a user doesn't have the unfiltered_html capability (which is the case for multisite regular admins), but can be enabled manually as well.

You can follow these instructions to observe the differences:

  1. Enable the KSES filters with add_action( 'init', 'kses_init_filters' );
  2. Activate the Twenty Twenty-One theme
  3. Go to Appearance > Customize > Additional CSS
  4. Add some CSS code
  5. Save the changes
  6. ✅ Note how the CSS code is correctly saved
  7. Now activate the Twenty Twenty-Three theme
  8. Go to Appearance > Editor
  9. Open the Styles sidebar
  10. Select "Custom CSS"
  11. Add some CSS code
  12. Save the changes
  13. ⚠️ Note how the changes are reverted

So I think the new Custom CSS feature within Global Styles should still work when the KSES filters are active.

@ndiego
Copy link
Member

ndiego commented Jan 25, 2023

@mmtr @Mamaduka Just checking in on this issue. Can this be closed now that #46815 is merged?

@Mamaduka
Copy link
Member

Yes, we can close this one. Also related PR #47062.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json [Priority] High Used to indicate top priority items that need quick attention [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

No branches or pull requests

7 participants