On this page
add_settings_error( string $setting, string $code, string $message, string $type = 'error' )
Registers a settings error to be displayed to the user.
Description
Part of the Settings API. Use this to show messages to users about settings validation problems, missing settings or anything else.
Settings errors should be added inside the $sanitize_callback function defined in register_setting() for a given setting to give feedback about the submission.
By default messages will show immediately after the submission that generated the error.
Additional calls to settings_errors() can be used to show errors even when the settings page is first accessed.
Parameters
$settingstring Required-
Slug title of the setting to which this error applies.
$codestring Required-
Slug-name to identify the error. Used as part of
'id'attribute in HTML output. $messagestring Required-
The formatted message text to display to the user (will be shown inside styled
<div>and<p>tags). $typestring Optional-
Message type, controls HTML class. Possible values include
'error','success','warning','info'. Default'error'.Default:
'error'
Source
File: wp-admin/includes/template.php. View all references
function add_settings_error( $setting, $code, $message, $type = 'error' ) {
global $wp_settings_errors;
$wp_settings_errors[] = array(
'setting' => $setting,
'code' => $code,
'message' => $message,
'type' => $type,
);
}
Related
Used By
| Used By | Description |
|---|---|
| WP_Privacy_Requests_Table::process_bulk_action() wp-admin/includes/class-wp-privacy-requests-table.php | Process bulk actions. |
| _wp_personal_data_handle_actions() wp-admin/includes/privacy-tools.php | Handle list table actions. |
| sanitize_option() wp-includes/formatting.php | Sanitizes various option values based on the nature of the option. |
Changelog
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/add_settings_error