我有一个用例,在使用javascript加载页面后,我们需要更新Gutenberg全局调色板。我知道add_theme_support('editor-color-palette', ...)
PHP选项,但是在这种情况下不起作用。
似乎应该可以使用以下方法来分派动作:
wp.data.dispatch( 'core/editor' ).updateEditorSettings( {colors: [{name: 'test', slug: 'test', color: '#00FF00'}]} );
这可以更新编辑器设置,可以使用以下方法确认:
wp.data.select( "core/editor" ).getEditorSettings()
但是,UI不会重新呈现以显示更新的调色板选项。
是否有一种方法可以使用更新的编辑器设置触发块重新渲染?
根据Github上的此问题,现在称为updateSettings
。
wp.data.dispatch('core/block-editor').updateSettings({
colors: [{name: 'test', slug: 'test', color: '#00FF00'}]
})