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.


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;

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;

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;
  • 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

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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