• Resolved reinhardsanz

    (@reinhardsanz)


    When developing a plugin, is it safe to store some custom data within the “metadata” attribute of a block definition. Or is there a risk of my value being overwritten?

    I would not touch existing metadata values but just add my own under a new key.

    • This topic was modified 1 month, 2 weeks ago by reinhardsanz.
    • This topic was modified 1 month, 2 weeks ago by reinhardsanz. Reason: Add image for context
Viewing 2 replies - 1 through 2 (of 2 total)
  • Hello there,

    It is generally safe to store custom data in the “metadata” attribute of a block definition with proper namespacing and care. However, be mindful of potential conflicts or changes in the WordPress ecosystem. Using custom block attributes or similar alternatives may provide a more reliable and maintainable approach in the long run.

    Instead of metadata, you could define custom attributes for the block. These are intended for block-specific data and are less likely to be altered or overwritten inadvertently. Example of adding custom attributes:

    const myBlock = {
    name: 'my-plugin/my-block',
    attributes: {
    myCustomAttribute: {
    type: 'string',
    default: 'defaultValue'
    }
    },
    // other block settings
    };

    We hope you find this helpful, cheers.

    Thread Starter reinhardsanz

    (@reinhardsanz)

    Thanks for the info! ??

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.