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 trying to add/ update additional values to an option created with the Settings API. I'm trying to do this with my validation callback function, but I'm not getting very far. Here is my code:

function tccl_settings_option_validate( $input ) {
    add_option( 'tccl_settings_option', $input );
}

This is causing a pretty big error. How should I be doing this?

What I would like to do is use the validation callback to add values to the option array without overwriting it.

share|improve this question

3 Answers 3

up vote 2 down vote accepted

Get the option, modify only the values you need to modify in it, then return the results.

function tccl_settings_option_validate( $input ) {
    $options = get_option('tccl_settings_option');
    // modify $options using data from $input as needed
    return $options;
}
share|improve this answer

On your tccl_settings_option_validate function you need to:

  • get an array of all existing options.
  • update only the changed.
  • return that array.

    so something like:

    function tccl_settings_option_validate( $input ) {
    
    //do regular validation stuff
    //...
    //...
    
    //get all options
    $options = get_option(THEMENAME . '_settings');
    //update only the neede options
    foreach ($input as $key => $value){
        $options[$key] = $value;
    }
    //return all options
    return $options;
    }
    
share|improve this answer

you don't have to save the option, that's done for you. your validation function should check input then return something.

function tccl_settings_option_validate( $input ) {
    // do some checking/formatting/whatever of $input
    // and then
    return $input;
}
share|improve this answer
    
But that will overwrite the whole option. I would like to add further values to the option array. –  jnthnclrk Jul 25 '11 at 17:29

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.