add_settings_error() WordPress Function

The add_settings_error() function is used to add settings errors and warnings to the WordPress admin. This function is used internally by the Settings API to add errors and warnings to the WordPress admin.

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.


Top ↑

Parameters

$setting

(string)(Required)Slug title of the setting to which this error applies.

$code

(string)(Required)Slug-name to identify the error. Used as part of 'id' attribute in HTML output.

$message

(string)(Required)The formatted message text to display to the user (will be shown inside styled <div> and <p> tags).

$type

(string)(Optional) Message type, controls HTML class. Possible values include 'error', 'success', 'warning', 'info'.

Default value: 'error'


Top ↑

Source

File: wp-admin/includes/template.php

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,
	);
}


Top ↑

Changelog

Changelog
VersionDescription
5.3.0Added warning and info as possible values for $type.
3.0.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.