How to display admin error notice if settings saved succesfully?

Ok, I think I have an idea what is going on.

  1. The list of notices to display is retrieved by get_settings_errors() ( source ).

  2. This function reads notices from global $wp_settings_errors unless there is settings_errors transient set, which trumps global var.

  3. When settings are saved there is check for no setting errors and if so Settings saved. notice is generated. After that (in either case) errors are saved into settings_errors transient (I assume to preserve them on redirect) ( source ) .

Basically no matter what notices you generate in your code – they will be ignored when transient is set and it is always going to be set after saving settings.

As for me it would make sense to concatenate transient with global variable rather than making it exclusive or choice.

And I guess to display custom notices when transient is set I will need to mess with that transient, which is probably not worth the trouble.

Leave a Comment