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 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');

  if(error_found){

    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.

share|improve this question
    
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

2 Answers 2

up vote 0 down vote accepted

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.

share|improve this answer
    
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.

share|improve this answer
1  
Please add the solution as an answer. A good answer should not rely on an external link. –  toscho 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

 
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.