I'm not using the full settings api, just this code:

register_setting( 'my_options', 'my_options', 'my_options_validate' );

Then my validation:

  $options = get_option('my_options');


    add_settings_error( 'my_options', 'settings_updated', 'error_message_here', 'error');


  return $options;

But on postback no errors are displayed. So my questions are:

does simply setting an error message result in its display? do I have to use the full settings api to have errors displayed? do I have do anything to disable the "settings updated" message on postback?

I've tried using settings_errors but no errors show.

  • Exactly what kind of errors are you hoping to show? Unless your setting error_found somewhere ( missing $? ) then Wordpress will simply return a WP_Error object or null on a call, or it'll output to the browser that the user has arrived somewhere they shouldn't
    – Tom J Nowell
    Nov 18 '11 at 10:59

No, you need to add a call to settings_errors

 * Displays all messages registered to 'your-settings-error-slug'
function your_admin_notices_action() {
    settings_errors( 'your-settings-error-slug' );
add_action( 'admin_notices', 'your_admin_notices_action' );

Else the errors you added will not be displayed. You may also want to check that error_found is true. It is not a wordpress constant I recognize, so I assume it is part of your code ( and hasn't been set ) ( also, it's missing a $ at the start? ).

There is also the possibility that no errors have occurred, or that your validation is allowing invalid cases to pass through.

  • Thanks, Tom. error_found is pseudo code standing in for a real error. I'm also wondering how I can cancel the normal save settings process if I find errors?
    – mos fetish
    Nov 20 '11 at 22:19
  • I don't know if you can other than possibly a wp_redirect followed by a die(), but that sounds terribly hackish
    – Tom J Nowell
    Nov 22 '11 at 11:04

I had a similar issue when I was developing my ArticleForge WordPress plugin. I did not want to allow erroneous input to enter the database, but yet I wanted to give the user a chance to correct their input. So, after much creative process, I did devise a method that works. You don't have to do a wp_redirect or a die(). The main gist of it is that you switch out the users input during validation with that of the existing options and return those values instead.

You can check out my blog post for a detailed description of the process I followed.

  • 1
    Please add the solution as an answer. A good answer should not rely on an external link.
    – fuxia
    Aug 29 '13 at 14:59
  • I realized that but it's a huge chunk of text spanning multiple pages.
    – Borgboy
    Aug 29 '13 at 15:53

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.