我有一个用例,在使用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不会重新呈现以显示更新的调色板选项。
是否可以使用更新的编辑器设置来触发重新渲染块?
答案 0 :(得分:0)
根据Github上的此问题,现在称为updateSettings
。
wp.data.dispatch('core/block-editor').updateSettings({
colors: [{name: 'test', slug: 'test', color: '#00FF00'}]
})