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

Issues with getEditorSettings to access theme default color or gradient palette #59171

Closed
simom opened this issue Feb 19, 2024 · 4 comments
Closed
Labels
Needs Technical Feedback Needs testing from a developer perspective. [Type] Bug An existing feature does not function as intended

Comments

@simom
Copy link

simom commented Feb 19, 2024

Description

I'm trying to read the theme color palette in a custom block using the editorStore.
If there are no custom user colors, it returns the theme's default colors array (which is the expected behavior).
However, if the user defines a custom color, it only returns the user's custom color without including all the theme defaults.
Is this a bug, or is there another way to access this data?

In the with-colors.js component on Gutenberg there is a useSettings function, that appears to be private that read from:

'color.palette.custom',
'color.palette.theme',
'color.palette.default'

Step-by-step reproduction instructions

import { store as editorStore } from '@wordpress/editor';
const { getEditorSettings } = select(editorStore);
const colors = getEditorSettings().colors;

Screenshots, screen recording, code snippet

No response

Environment info

  • WordPress 6.4.3
  • Default TT4 theme

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

@simom simom added the [Type] Bug An existing feature does not function as intended label Feb 19, 2024
@simom simom changed the title Issues with getEditorSettings to access theme default color or gradient default palette Issues with getEditorSettings to access theme default color or gradient palette Feb 19, 2024
@Mamaduka
Copy link
Member

The useSettings is a new hook and will ship with WP 6.5. Meanwhile, you can use the useSetting hook, imported from the @wordpress/block-editor package.

@Mamaduka Mamaduka added the Needs Technical Feedback Needs testing from a developer perspective. label Feb 19, 2024
@simom
Copy link
Author

simom commented Feb 19, 2024

thank you @Mamaduka for the information!

By the way, concerning the first question for the const colors = getEditorSettings().colors is it the expected behavior to return only the user custom color if defined?

@Mamaduka
Copy link
Member

@simom, IIRC, that's the correct behavior; those settings are coming from the server when the editor loads - https://github.com/WordPress/wordpress-develop/blob/6.4/src/wp-includes/block-editor.php#L555-L565.

@simom
Copy link
Author

simom commented Feb 19, 2024

Ok thank you for your help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Technical Feedback Needs testing from a developer perspective. [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

No branches or pull requests

2 participants