WordPress at a glance

add_settings_error() WP 1.0

Register a settings error to be displayed to the user

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.

  • Global. Array. $wp_settings_errors Storage array of errors registered during this pageload

No Hooks.

Return

Nothing (null).

Usage

add_settings_error( $setting, $code, $message, $type );
$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)
Message type, controls HTML class. Accepts 'error' or 'updated'.
Default: 'error'

Code of add_settings_error: wp-admin/includes/template.php VER 5.0

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

Related Functions

From category: Settings API

No comments
    Hello, !     Log In . Register