Storage of array in settings

I’m creating a plugin that will store some simple layouts to be used in shortcodes.

The shortcode usage will be similar to [shortcode layout="name"]

Read More

With this mind I’ll need to store each layout in the array as a key/value setup

Key = layout name

Value = layout markup

I’d like to store these in settings however I’m not sure how to go about it. How can I create a settings page that allows addition and editing. Normally my settings pages use code as follows and automatically wires into the api.

<input type="text" id="company_name" name="wpv_settings[company_name]" value="<?php echo $wpv_settings['company_name']; ?>" class="regular-text" />

However, I can’t find how to go about this when the setting is an array of key/values.

Can anyone point me in the right direction of how this would be done?

Related posts

Leave a Reply

1 comment

  1. Since the layout names are dynamic, perhaps it’s better to store them in a numerically indexed nested array? Something like:

    wpv_settings[layouts][0][name] = $key
    wpv_settings[layouts][0][markup] = $value
    
    wpv_settings[layouts][1][name] = $key
    wpv_settings[layouts][1][markup] = $value
    

    …etc?