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.

Been playing around with the Settings API and found that messages (for success or errors) are only displayed when a settings page is hooked into WordPress menu via add_options_page(). Anything else will not work e.g. add_dashboard_page(). Would like to know if this is true? Sample code I tried with is the answer containing the "RegisteredSettingsTest" class at Where to hook register_settings for Settings API when also want to update options outside of Settings API?

share|improve this question
add comment

2 Answers

Thanks Chip (excellent Settings API tutorial) and t31os (great snippet of code for quick testing) for both your suggestions.

I did some further digging and found that the default messages can indeed be displayed if I hook into any menu but only if the function settings_errors() is called.

For example, modifying t31os code as follows:

<div class="wrap">
  <h2>Test</h2>
  <?php settings_errors(); ?>
  <form action="options.php" method="post">

Custom error messages can also be added by calling the add_settings_error() function for displaying success or failure message by specifying the $type parameter as either 'error' or 'updated'.

share|improve this answer
    
this had me stumped for a while too! using settings_errors(); did the trick, thanks for posting a follow up Jesse! –  CommentLuv Jul 21 '11 at 19:30
add comment

I use Settings API integration with my Theme,use add_theme_page(), and have no problem displaying admin notices.

I suspect that it is a problem with your code rather than a Settings API limitation.

Can you post your actual code, so we can help you resolve any code-related issues?

EDIT

You may need to output your admin notices explicitly. For example, here is what I use in my settings page markup function:

<?php if ( isset( $_GET['settings-updated'] ) ) {
    echo "<div class='updated'><p>Theme settings updated successfully.</p></div>";
} ?>

I assume you could do something similar for error notices, as well.

share|improve this answer
    
See updated answer. –  Chip Bennett Jul 1 '11 at 12:45
    
The code I used can be found at pastebin. Apologies if I am not clear enough. What I observe is if I hooked into a menu via add_options_page() and save the settings, a "Settings saved" message will be displayed. However, if I changed the code to use add_theme_page() or add_dashboard_page(), then the default "Settings saved" message will not appear. –  Jesse van Couten Jul 1 '11 at 12:52
    
Right... did you add code as per the example above? You have to add it explicitly to your settings page markup function. –  Chip Bennett Jul 1 '11 at 13:02
    
I'm flattered you used my test code to build on top of, Chip is correct that you'll need to add the notice yourself explicitly. Best of luck with your settings page Jesse.. :) –  t31os Jul 1 '11 at 16:54
add comment

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.