【问题标题】:Retrieve theme colors array inside Javascsipt在Javascript中检索主题颜色数组
【发布时间】:2019-08-23 12:52:59
【问题描述】:

我正在寻找一种方法来检索您可以使用 add_theme_support('editor-color-palette', [...]); 在主题中设置的颜色对象数组;

不知何故,我在文档中找不到有关如何在自定义块中检索主题颜色的任何信息。

<ColorPalette
    onChange={ value => onChange(index, 'color', value) }
/>

我需要 onChange 回调中的颜色数组将十六进制颜色转换为我在 php 中使用函数 getColorObjectByColorValue(themeColorsArray, callbackValueHexColor) 设置的 slug 颜色名称

非常感谢您的帮助!

编辑: 找到了解决方案。 wp.​​core 中有一个名为 select 的函数。使用此功能,您可以检索编辑器核心对象。要获得颜色,请执行以下操作:

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

【问题讨论】:

    标签: wordpress wordpress-gutenberg color-palette


    【解决方案1】:

    仅供未来的读者参考,感谢@tobiasegli 的回答

     <ColorPalette
        colors={wp.data.select( "core/editor" ).getEditorSettings().colors }
        label={'bg color'}
        value={ color }
        onChange={ ( color ) => setState( { color } ) }
        />
    

    【讨论】:

      猜你喜欢
      • 2022-11-13
      • 2011-07-12
      • 1970-01-01
      • 1970-01-01
      • 2012-06-12
      • 2019-03-07
      • 2021-03-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多