In my admin panel, if I use a sanitizing callback register_setting() and the field does not pass through my custom validation, I've been preventing the database from updating by using return FALSE; and adding an error with add_settings_error().

How do I return the invalid values back to the form fields that the user submitted, so that they don't have to start all over again?

1 Answer 1


This a really good question - my suggestion is to use transients. For instance, in your validation callback:

     //Perform validation checks

     if( $valid ){
        //If settings validate
        return $validate_settings;

     //Otherwise add settings error
     add_settings_error('my-plug-in-settings','error-with-xyz', 'I fell over','error');

     //And add the failed settings to a transient
     set_transient( 'my-plug-in-settings-invalid', $settings, 60);

     return false;

Then on your settings page, if the options have been validated - check for the transient, and use the 'failed' settings, if they are found:

    if( isset($_GET['settings-updated']) && $_GET['settings-updated'] && get_transient('my-plug-in-settings-invalid') ){
        $options_to_display  = get_transient('my-plug-in-settings-invalid');

        $options_to_display = get_option('my-plug-in-settings');
  • is there any way to do this without using the db?
    – Dave Kiss
    May 13, 2012 at 4:18
  • @DaveKiss - I don't think so, but is there any reason you don't want to use the db? May 13, 2012 at 18:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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