用Java更新Gutenberg全局调色板

问题描述 投票:4回答:1

我有一个用例,在使用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不会重新呈现以显示更新的调色板选项。

是否有一种方法可以使用更新的编辑器设置触发块重新渲染?

wordpress wordpress-gutenberg
1个回答
0
投票

根据Github上的此问题,现在称为updateSettings

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

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

© www.soinside.com 2019 - 2024. All rights reserved.