php – Gutenberg Blocks and get_option() for styling

Question

I’m creating a Gutenberg block and I’m trying to customize a button’s style (background color, text color, etc.) and it’s inner text with hexcode set in an options menu.

What’s the best way to access options in the database for wp.blocks.registerBlockType?

wp.blocks.registerBlockType('plugin/block', {
  title: 'Button',
  icon: 'analytics',
  category: 'common',
  edit: function () {
    return <h1>Button</h1>
  },
  save: function () {
    return (
      <button style="background-color: {get_option('button-color')}">
        {get_option('button-text')}
      </button>)
  },
})

Trying this just leads to a blank screen on the editor.

0
Soveric Eric 9 months 2021-11-26T03:44:41-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse