Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7760515
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T13:54:31+00:00 2026-06-01T13:54:31+00:00

For all expert WP Theme devs, when using multiple update_option() is there a way

  • 0

For all expert WP Theme devs, when using multiple update_option() is there a way to test if any of the updates did not work (whether by connection error or by validation) and so it will throw an error?

And if there was an error is it possible for all previous update_option() codes to be disregarded?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T13:54:32+00:00Added an answer on June 1, 2026 at 1:54 pm

    update_option() returns false if the update fails for any reason. However, it also returns false for when an option is already set to the value you are trying to to update it to.

    So, you would be best to first check if the option needs updating or exists using get_option and then if it needs to be updated, update it.

    If your option fails your validation test, then just break out of whatever validation function you are using. You could throw a Wp_Error, but that seems too invasive. I tend to use the add_settings_error and display the error to my users that way.

    To roll back any of your previous update_option calls would require that you store the previous values in an array, and if then iterate back over them if you need to restore your options.

    Generally I use one options table entry to handle things like theme options, or plugin options. Nothing worse than getting a theme that pollutes my options table with a new option for each and every setting.

    Edit:

    The following is how I handle options validation for my theme options and plugins pages. Its Class based, so you will have to swap out some of the vars if you are using a procedural approach.

    public function theme_options_validate( $input ) {
    
        if ($_POST['option_page'] != $this->themename.'_options') {
            add_settings_error($this->themename.'_theme_options', 'badadmin', __('<h3><strong>Smack your hands!</strong></h3> - You don\'t appear to be an admin! Nothing was saved.', $this->textDom), 'error');
            return $input;
        }
    
        if ( empty($_POST) && !wp_verify_nonce($_POST[$this->themename.'_options'],'theme_options_validate') ) {
            add_settings_error($this->themename.'_theme_options', 'badadmin', __('<h3><strong>Smack your hands!</strong></h3> - You don\'t appear to be an admin! Nothing was saved.', $this->textDom), 'error');
            return $input;
        }
    
        //begin validation - first get existing options - if any
        $init_themeoptions = get_option( $this->themename.'_theme_options' );
        //create an array to store new options in
        $newInput = array();
    
        //check to see if the author param has been set
        if($input[$this->shortname.'_meta-author'] !== '') {
            $newInput[$this->shortname.'_meta-author'] =  wp_filter_nohtml_kses( $input[$this->shortname.'_meta-author] );
        }else{
            add_settings_error($this->themename.'_theme_options', 'emptydata', __('Oops - Author cant be empty'.', $this->textDom), 'error');
        }
    
        //finally we see if any errors have been generated
        if(get_settings_errors($this->themename.'_theme_options')){
            //if there are errors, we return our original theme options if they exist, otherwise we return the input data
            //this clause handles the situation where you have no theme options because its your themes first run
            if($init_themeoptions != false) {
                return $init_themeoptions;
            }else{
                return $input;
            }
        }
    
        //if there were no errors we return the sanitized $newInput array and indicate successful save of data using settings error class, but 
        //we don't use the error attribute, which isnt all that intuitiive
        add_settings_error($this->themename.'_theme_options', 'updated', __('<em>Success! </em> '.ucfirst($this->themename).' Theme Options updated!', $this->textDom), 'updated');
        return $newInput;
    }
    

    To show settings errors in your theme options ui add the following line to where you generate your options form;

    settings_errors( $this->themename.'_theme_options' );
    

    And yes, the options table exists already. What I was meaning that instead of generating a new entry into the options table for each of your theme options, you wrap them all up in one option entry. This also makes it easier to validate the options data.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm not expert in CSS in any way; I know it to some extent
Is there any Delphi expert or similar that allows me to automatically find all
Is there a way to export all of TFS 2008 Groups and Permissions for
I'm a C++ expert, but not at all for C#. I created a Dictionary<string,
Hi there dear gurus and expert coders. i am not gonna start with im
I'm currently creating an installer using INNO and I'm no pascal expert. Is there
I'm not a security expert by any means, but I favor creating REST-style web
I am not at all an expert in database design, so I will put
All Rails expert sites say not to store ActiveRecords in the Session. However, I
Is there a way to restore all escreen screens and window configurations on emacs

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.