Question

The Professional WordPress Plugin Development book explains in detail how to properly use the Settings API, and it also demonstrates how to add Menus and Submenus, but unfortunately it doesn't provide any joined-up examples of this. Whilst I've managed to get most of it working, I can't figure out how to properly implement add_settings_error on custom Menu pages. Here is my code:

function settings_main_validate( $input ) {
$valid['text_string'] = preg_replace( '/[^a-zA-Z]/', '', $input['text_string'] );

if ( $valid['text_string'] != $input['text_string'] ) {
    //add_setting_error: $title, $id, $error_message, $class
    add_settings_error( 'fields_main_input', 'texterror', 'Incorrect value entered!', 'error' );
}   

return $valid;
}                  

The validation above will work great on setting rendered using add_options_page, but will not display the settings errors on pages rendered with add_menu_page.

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top