Support » Plugins and Hacks » Hacks » add_settings_error() not working unless I call settings_errors()

  • In my plugin, I add a an option to the options page as follows:

    add_settings_field('sbs_gig_lastfm_key',__('Last FM Key','sbs_gig'),'sbs_gig_lastfm_key','sbs_gig','sbs_gig_main');

    and the validation function looks like this:

    function sbs_gig_validate_options( $input ) {
    // Create our array for storing the validated options
        $valid = array();
        // Loop through each of the incoming options
        foreach( $input as $key => $value ) {
            // Check to see if the current option has a value. If so, process it.
            if( isset( $input[$key] ) ) {
                // Strip all HTML and PHP tags and properly handle quoted strings
                $valid[$key] = strip_tags( stripslashes( $input[ $key ] ) );
                if ($key=='lastfmkey') {
                    if (!sbs_gig_verify_lastfm($valid[$key])) {
                        add_settings_error('sbs_gig_lastfm_key','lastfmkey_error',__('Please enter a valid Last FM API Key','error'));
                    else {
            } // end if
        } // end foreach
        // Return the array processing any additional functions filtered by this action
        return $valid;

    From what I’ve read, the error I add via add_settings_error() should be displayed automatically, but it’s not. I have to explicitly call settings_error() to get the error to display. Can anyone suggest why?

Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘add_settings_error() not working unless I call settings_errors()’ is closed to new replies.