Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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"]

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?

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

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?

share|improve this answer
    
Can I automate the creation/updating of the options for this using Wordpress settings register? <input type="text" id="company_name0" name="wpv_settings[layouts][0][name]" value="<?php echo $wpv_settings[layouts][0][name]; ?>" class="regular-text" /> –  WDuffy Jun 20 '12 at 8:52
    
Works great Jessica thanks –  WDuffy Jun 21 '12 at 15:35
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.