wordpress函数add_settings_error()
注册要显示给用户的设置错误。
Register a settings error to be displayed to the user.
说明(Description)
设置API的一部分。使用此选项可向用户显示有关设置验证问题、缺少设置或其他任何内容的消息。
应在给定设置的register_setting()中定义的$sanitize_回调函数中添加设置错误,以提供有关提交的反馈。
默认情况下,消息将在生成错误的提交后立即显示。对settings_errors()的其他调用可用于显示错误,即使首次访问设置页也是如此。
参数(Parameters)
参数 | 类型 | 必填 | 说明 |
---|---|---|---|
$setting | (string) | 必需 | 应用此错误的设置的Slug标题。 |
$code | (string) | 必需 | 用于识别错误的Slug名称。在HTML输出中用作“id”属性的一部分。 |
$message | (string) | 必需 | 要显示给用户的格式化消息文本(将显示在styled
和 标记中)。 |
$type | (string) | 可选 | 消息类型,控件HTML类。可能的值包括“error”、“success”、“warning”、“info”。 |
返回(Return)
无返回值
源码
更新版本 | 源码位置 | 使用 | 被使用 |
---|---|---|---|
5.3.0 | wp-admin/includes/template.php:1723 | 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.
*
* @since 3.0.0
*
* @global array $wp_settings_errors Storage array of errors registered during this pageload
*
* @param string $setting Slug title of the setting to which this error applies
* @param string $code Slug-name to identify the error. Used as part of 'id' attribute in HTML output.
* @param string $message The formatted message text to display to the user (will be shown inside styled
* `` and `` tags).
* @param string $type Optional. Message type, controls HTML class. Accepts 'error' or 'updated'.
* Default 'error'.
*/
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
);
}
版权声明:原创作品,未经允许不得转载,否则将追究法律责任。
本站资源有的自互联网收集整理,如果侵犯了您的合法权益,请联系本站我们会及时删除。
本站资源仅供研究、学习交流之用,若使用商业用途,请购买正版授权,否则产生的一切后果将由下载用户自行承担。
本文链接:子佩工作室https://zptheme.com/5484.html
许可协议:《署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0)》许可协议授权
本站资源有的自互联网收集整理,如果侵犯了您的合法权益,请联系本站我们会及时删除。
本站资源仅供研究、学习交流之用,若使用商业用途,请购买正版授权,否则产生的一切后果将由下载用户自行承担。
本文链接:子佩工作室https://zptheme.com/5484.html
许可协议:《署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0)》许可协议授权