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

Duplicate color appear in palette #336

Open
timkingbu opened this issue Apr 13, 2023 · 0 comments
Open

Duplicate color appear in palette #336

timkingbu opened this issue Apr 13, 2023 · 0 comments
Assignees
Labels
🔌 BU Blocks 💡 Bug ✅ Needs backend ⚙️ Plugin 🔥 Product bug A bug which is not directly related to a custom child theme.

Comments

@timkingbu
Copy link

timkingbu commented Apr 13, 2023

If colors are added via add_theme_support( 'editor-color-palette', array(...) ); to get them to appear in core blocks and add_filter( 'block_editor_settings' function() ); so that they appear in BU Blocks they are merged in the color palette but duplicate colors are not removed.

Screenshot 2023-04-13 at 1 17 28 PM

The specific code block is

if ( themeOptions && ! themeOptions.some( v => defaultColors.includes( v ) ) ) {
const newColors = defaultColors.concat( themeOptions );
// Update both the editor settings and general settings so that when a color
// is chosen, the value is one of those expected by the component.
updateEditorSettings( { colors: newColors } );
// In WordPress 5.2 and alter, the settings should be updated outside of the
// editor too, through updateSettings.
if ( 'undefined' !== typeof updateSettings ) {
updateSettings( { colors: newColors } );
}
}
— the .some() function is in place to handle this but is intended for arrays, but the colors are a json object.

Suggested code update is to replace const newColors = defaultColors.concat( themeOptions ); with:

const combinedColors = defaultColors.concat( themeOptions );
const newColors = [... new Set(combinedColors.map(JSON.stringify))].map(JSON.parse);
@timkingbu timkingbu added 🔥 Product bug A bug which is not directly related to a custom child theme. ✅ Needs backend 💡 Bug 🔌 BU Blocks ⚙️ Plugin labels Apr 13, 2023
@timkingbu timkingbu self-assigned this Apr 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🔌 BU Blocks 💡 Bug ✅ Needs backend ⚙️ Plugin 🔥 Product bug A bug which is not directly related to a custom child theme.
Projects
None yet
Development

No branches or pull requests

1 participant