• I have had a look for a solution but haven’t found any tutorials or example for my use-case.

    I understand that that block setting are saved in the front end, in the markup.

    However, I have a situation where I want to develop a block without a settings page, but it needs to pass some data ( API key & secret ) to the back end as it is unsafe for those elements to be exposed in markup.

    So I’m thinking to build these is the block side bar and on save post the keys to be saved into the options table ( as you would with a settings page ).

    However I’m unclear if there is a standard / secure way of doing this ( secure I’m not too worried about as I assume that in the backend I would sanitize and check capabilities just as I would in a standard jQuery ajax call )

    Thanks

Viewing 4 replies - 1 through 4 (of 4 total)
  • I think you can use shortcodes for this purpose. Have you considered using it?
    You can create your custom gutenberg block, but I think it is more easy with shortcodes

    Thread Starter Alan Fuller

    (@alanfuller)

    The question is about blocks not shortcodes. Thanks for your input but not relevant to the issue at hand.

    Thread Starter Alan Fuller

    (@alanfuller)

    Yes the question is a specific about developing a custom block. ( so ACF is not appropriate )

    Just to clarify I will re-phrase the question.

    When developing a custom block for a plugin, there are plenty of methods documented for saving attributes and post meta. However there is no documented method of saving generic options e.g. API keys, that would normally be saved into the options table via a settings page. However when developing such a block, if there are only a couple of generic options (e.g an external service API key ) it is not great UI to have to jump to settings page, but better UI to have those settings in inspector controls.

    However I can not find a standard method documented for updating the options. I have found talk of a REST API end point for options – which seems to have been not progressed. I can of course either build my own custom REST API endpoint for the specific options, of simply use jQuery ajax to update them (probably the simplest )

    There are of course security issues that need addressing as someone with block edit rights may not have manage_options rights and the UI needs to cater for this.

    BEFORE I roll my own custom solution, I’m asking, have I missed any ‘standard and secure’ methods for updating options table from inspector controls?

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Block Sidebar and saving data to the database (options)’ is closed to new replies.