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 am writing a plugin and I decided to have multiple pages for different options of the plugin (for clarity's sake). Doing a single option was a piece of cake, but I'm encountering difficulties when having multiple pages.

All of my options are in an array registered as:

register_setting( 'plugin_options', 'options', 'validator' );

As I said, having only one page was easy. Create the form, submit the form and boom, options saved. Now that I have multiple pages, it seems that Wordpress replaces the option array entirely, regardless of the fact that there might be some other values that I don't want to touch. I tried several options and then googled to finally find this solutions on Otto's website:

function plugin_options_validate($input) {
    $options = get_option('plugin_options');
    $options['text_string'] = trim($input['text_string']);
    if(!preg_match('/^[a-z0-9]{32}$/i', $options['text_string'])) {
        $options['text_string'] = '';
    return $options;

Seems it just won't work either, and I'm not really sure why.

My actual train of though for a solution is:

  1. Fetch actual options;
  2. Run a foreach arrray to change values if I find identical keys in options and input array;
  3. Return the values and voila!

But I'm hitting a wall. I have many options that are set via checkboxes, and when I uncheck thoses, form won't submit the name of the checkbox, therefore, I can't properly go through my array.

I guess what I'm asking is... HOW can I make a callback to register_settings that will take any options of any kind (input, checkbox, etc), and will not destroy the values already saved in the array that aren't touched by the options I'm saving at that moment.

Any help with this? Thanks !

share|improve this question
Before going in-depth with an answer: did you happen to search the site to see if any of the current Settings API questions would answer your question? –  Chip Bennett Feb 3 '12 at 20:28
I did :) Actually, I found my answer into tabs for option pages, I'll update my question and close the topic ! :) –  Jean-Philippe Murray Feb 3 '12 at 22:00
(Just not sure where I can close the topic though...) –  Jean-Philippe Murray Feb 3 '12 at 22:04
You don't actually close topics; instead, you accept the answer that best resolves your problem, by clicking the checkmark that appears next to that answer. (Post your answer, and you'll see what I mean.) –  Chip Bennett Feb 4 '12 at 17:35
Sweet, thanks for the tips :) –  Jean-Philippe Murray Feb 4 '12 at 21:26
add comment

1 Answer

up vote 0 down vote accepted

Ok, after searching a while, I've found out that the "easy" solution to my problem would be to start by creating tabs (like in the appearence menu) and option sections. While I'm still no expert in that matter, I followed this 3 part guide that explains pretty much everything related to the matter. I just had to adjust to a plugin, since he wrote his guide having themes in mind !

Thanks to anyone who took time to read !

share|improve this answer
add comment

Your Answer


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.