WordPress开发者和主题制作者的搜索引擎



add_settings_error ›

Since3.0.0
已弃用n/a
add_settings_error ( $setting, $code, $message, $type = 'error' )
参数: (4)
  • (string) $setting Slug title of the setting to which this error applies.
    Required: Yes
  • (string) $code Slug-name to identify the error. Used as part of 'id' attribute in HTML output.
    Required: Yes
  • (string) $message The formatted message text to display to the user (will be shown inside styled `<div>` and `<p>` tags).
    Required: Yes
  • (string) $type Optional. Message type, controls HTML class. Possible values include 'error', 'success', 'warning', 'info'. Default 'error'.
    Required: No
    默认: 'error'
定义在:
文档:
Change Log:
  • 5.3.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.



源码

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