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

settings.color.duotone = null does not validate against theme.json schema #40383

Closed
mrwweb opened this issue Apr 15, 2022 · 3 comments
Closed
Labels
[Feature] Colors Color management [Type] Developer Documentation Documentation for developers [Type] Question Questions about the design or development of the editor.

Comments

@mrwweb
Copy link

mrwweb commented Apr 15, 2022

Description

After reviewing a number of issues including #31764, #33295, #35931, and #38299, I believe that the following two theme.json values are required to fully disable the custom duotone feature:

  1. settings.color.duotone: null removes the SVG filters output in the body field. Setting this property to an empty array ([]) does not work.
  2. settings.color.customDuotone: removes the UI toolbar control in combination with the first change

However, when I try to validate my theme.json, there is an error for settings.color.duotone: null:

None is not a type of 'array'

Prior to WordPress 5.9.3, the null value also seemed to cause a PHP error, but I believe that has been resolved.

So first: Is this the correct way to fully disable duotone support with theme.json.

If so:

  1. The schema needs to be updated to allow null for settings.color.duotone -OR- using [] as the value for that setting should prevent the SVG filters from being output
  2. The official way to remove duotone should be documented

Step-by-step reproduction instructions

Validate the following theme.json file:

{
	"$schema": "https://schemas.wp.org/trunk/theme.json",
	"version": 2,
	"settings": {
		"color": {
			"duotone": null,
			"customDuotone": false
		}
	}
}

Screenshots, screen recording, code snippet

No response

Environment info

WordPress 5.9.3

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

Yes

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

No

@skorasaurus skorasaurus added [Type] Developer Documentation Documentation for developers [Feature] Colors Color management [Type] Question Questions about the design or development of the editor. labels Apr 15, 2022
@Humanify-nl
Copy link

I have encountered the same problem.

The output of SVG duotones in head also is affected by this. Passing an empty array to disable duotone will still generate them. Null generates error.

I had to resort to using the php function to remove these.
remove_action( 'wp_body_open', 'wp_global_styles_render_svg_filters' );

comzeradd added a commit to greenpeace/planet4-master-theme that referenced this issue Jun 15, 2022
Ref: https://jira.greenpeace.org/browse/PLANET-6811
Ref: WordPress/gutenberg#40383

---

Our current `theme.json` option doesn't work in 6.0.
You will probably see a validation error in your editor, because `null`
is not yet reflected in the official schema, but it does seem to work
without issues.
comzeradd added a commit to greenpeace/planet4-master-theme that referenced this issue Jun 15, 2022
Ref: https://jira.greenpeace.org/browse/PLANET-6811
Ref: WordPress/gutenberg#40383

---

Our current `theme.json` option doesn't work in 6.0.
You will probably see a validation error in your editor, because `null`
is not yet reflected in the official schema, but it does seem to work
without issues.
@ajlende
Copy link
Contributor

ajlende commented Nov 9, 2022

Is this the correct way to fully disable duotone support with theme.json.

This is the correct way to disable duotone filters

// theme.json
{
	"settings": {
		"color": {
			// This clears the duotone palette for the theme
			"duotone": [],
			// This removes the default duotone filters from the UI
			"defaultDuotone": false,
			// This disables the ability to set a custom duotone filter
			"customDuotone": false
		}
	}
}

Using all three options for colors and gradients in the same way will disable those features, respectively.

Even after all of that, there will still be the SVGs for the default filters output at the beginning of the body. Default colors, gradients, filters, etc. are always output to support block patterns which may use these default swatches. If you aren't worried about that, you can disable just the SVG generation by removing some filters.

// Removes generation from core
remove_action( 'wp_body_open', 'wp_global_styles_render_svg_filters' );
// Removes generation from the gutenberg plugin
remove_action( 'wp_body_open', 'gutenberg_global_styles_render_svg_filters' );

Finally, null is an invalid option for duotone, colors and gradients, so the theme.json schema is correct. If setting duotone to null was disabling something more, it is unintended behavior and may change in the future.

Hopefully that clarifies things. Keep an eye on #38299 for changes to the SVG generation for default filters. I'd like a better solution for block patterns rather than always including all of the defaults, and that issue is where updates on that problem will be posted.

@ajlende ajlende closed this as completed Nov 9, 2022
@mrwweb
Copy link
Author

mrwweb commented Nov 9, 2022

Thanks for this very good answer, @ajlende. I can confirm that even in WP 6.1, the null behavior still works, but I can switch to the PHP filter from now on. Appreciate you providing the reasoning behind that as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Colors Color management [Type] Developer Documentation Documentation for developers [Type] Question Questions about the design or development of the editor.
Projects
None yet
Development

No branches or pull requests

4 participants