wpseek.com
A WordPress-centric search engine for devs and theme authors
settings_errors › WordPress Function
Since3.0.0
Deprecatedn/a
› settings_errors ( $setting = '', $sanitize = false, $hide_on_update = false )
| Parameters: (3) |
|
| Defined at: |
|
| Codex: | |
| Change Log: |
|
Displays settings errors registered by add_settings_error().
Part of the Settings API. Outputs a div for each error retrieved by get_settings_errors(). This is called automatically after a settings page based on the Settings API is submitted. Errors should be added during the validation callback function for a setting defined in register_setting(). The $sanitize option is passed into get_settings_errors() and will re-run the setting sanitization on its current value. The $hide_on_update option will cause errors to only show when the settings page is first loaded. if the user has already saved new values it will be hidden to avoid repeating messages already shown in the default error reporting after submission. This is useful to show general errors like missing settings when the user arrives at the settings page.Related Functions: get_settings_errors, add_settings_error, settings_fields, is_error, do_settings_fields
Source
function settings_errors( $setting = '', $sanitize = false, $hide_on_update = false ) {
if ( $hide_on_update && ! empty( $_GET['settings-updated'] ) ) {
return;
}
$settings_errors = get_settings_errors( $setting, $sanitize );
if ( empty( $settings_errors ) ) {
return;
}
foreach ( $settings_errors as $key => $details ) {
$type = trim( $details['type'] );
if ( 'updated' === $type ) {
$type = 'success';
}
$additional_classes = array( 'settings-error' );
/*
* Backward compatibility: `wp_admin_notice()` generates the admin notice
* CSS classes based on the passed message type. For example, 'error',
* 'success', 'warning', 'info'. Custom types will be treated as
* additional classes and appended to the end of the CSS classes.
*/
if ( ! in_array( $type, array( 'error', 'success', 'warning', 'info' ), true ) ) {
$additional_classes = array_merge( $additional_classes, explode( ' ', $type ) );
$type = '';
}
/*
* Note that the setting error code contains underscores, for example:
* `settings_updated`. This will build a CSS ID selector that contains
* underscores, which are currently not allowed by the WordPress CSS
* Coding Standards. Kept for backwards compatibility.
*/
$css_id = sprintf(
'setting-error-%s',
$details['code'],
);
wp_admin_notice(
"<strong>{$details['message']}</strong>",
array(
'type' => $type,
'code' => $details['code'],
'id' => $css_id,
'paragraph_wrap' => true,
'dismissible' => true,
'additional_classes' => $additional_classes,
)
);
}
}