0

Is it possible to unregister or unset an error that has been added using add_settings_error? What I am trying to do is run some unit tests on my settings validation function, but I'd like to reset any errors that may have been added in previous tests in the teardown function.

Thx.

0

If you look at the source of add_settings_error(), you will see that the errors are stored in the $wp_settings_errors global. So in your tearDown() function, you can do this:

$GLOBALS['wp_settings_errors'] = array();

Also, don't forget to call parent::tearDown(). I sometimes forget, and it can lead to strange behavior. ;-)

  • Works like a charm! Next time I'll go straight to the WordPress source instead of performing random Google searches. Cheers! – donnapep Feb 28 '15 at 2:17

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.