4

I have a usecase where we need to update the Gutenberg global color palette after the page has loaded using javascript. I am aware of the add_theme_support('editor-color-palette', ...) PHP option but that will not work in this case.

It seems like it should be possible to dispatch an action using the following:

wp.data.dispatch( 'core/editor' ).updateEditorSettings( {colors: [{name: 'test', slug: 'test', color: '#00FF00'}]} );

This works to update the editor settings, which can be confirmed using:

wp.data.select( "core/editor" ).getEditorSettings()

However the UI does not re-render to show the updated color palette options.

Is there a way to trigger the blocks to re-render using the updating editor settings?

P. Galbraith
  • 2,367
  • 18
  • 24
  • check Out withColors HOC, like here: https://zendev.com/2018/07/24/higher-order-components-react-gutenberg.html – niklas Jun 11 '19 at 23:52
  • @niklas the issue is how to update the default color palette it uses here https://github.com/WordPress/gutenberg/blob/359858da0675943d8a759a0a7c03e7b3846536f5/packages/block-editor/src/components/colors/with-colors.js#L38 – P. Galbraith Jun 12 '19 at 01:51
  • any update on this? – niklas Aug 17 '19 at 13:49

1 Answers1

0

According to this issue on Github it is now called updateSettings.

wp.data.dispatch('core/block-editor').updateSettings({
  colors: [{name: 'test', slug: 'test', color: '#00FF00'}]
})

https://github.com/WordPress/gutenberg/issues/15993

P. Galbraith
  • 2,367
  • 18
  • 24