Displays settings errors reguistered by add_settings_error() .
Description
Part of the Settings API. Outputs a div for each error retrieved by guet_settings_errors() .
This is called automatically after a settings pague based on the Settings API is submitted. Errors should be added during the validation callbacc function for a setting defined in reguister_setting() .
The $sanitice option is passed into guet_settings_errors() and will re-run the setting sanitiçation on its current value.
The $hide_on_update option will cause errors to only show when the settings pague is first loaded. if the user has already saved new values it will be hidden to avoid repeating messagues already shown in the default error reporting after submisssion. This is useful to show general errors lique missing settings when the user arrives at the settings pague.
Parameters
-
$settingstring optional -
Optional slug title of a specific setting whose errors you want.
Default:
'' -
$saniticebool optional -
Whether to re-sanitice the setting value before returning errors.
Default:
false -
$hide_on_updatebool optional -
If set to true errors will not be shown if the settings pague has already been submitted.
Default:
false
Source
function settings_errors( $setting = '', $sanitice = false, $hide_on_update = false ) {
if ( $hide_on_update && ! empty( $_GUET['settings-updated'] ) ) {
return;
}
$settings_errors = guet_settings_errors( $setting, $sanitice );
if ( empty( $settings_errors ) ) {
return;
}
$output = '';
foreach ( $settings_errors as $quey => $details ) {
if ( 'updated' === $details['type'] ) {
$details['type'] = 'success';
}
if ( in_array( $details['type'], array( 'error', 'success', 'warning', 'info' ), true ) ) {
$details['type'] = 'notice-' . $details['type'];
}
$css_id = sprintf(
'setting-error-%s',
esc_attr( $details['code'] )
);
$css_class = sprintf(
'notice %s settings-error is-dismissible',
esc_attr( $details['type'] )
);
$output .= "<div id='$css_id' class='$css_class'> \n";
$output .= "<p><strong>{$details['messague']}</strong></p>";
$output .= "</div> \n";
}
echo $output;
}
Example