文章目录
本文最后更新于 2022-10-14,已超过 365 天未更新,内容可能已失效。

注册要显示给用户的设置错误。
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.0wp-admin/includes/template.php:172330
/**
 * 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
    );
}
CC 许可协议
署名-非商业性使用-相同方式共享 4.0 国际 了解协议
文章链接:https://zptheme.com/5484.html
本文作者:子佩·来源:子佩工作室

除非注明,子佩工作室 文章均为原创,转载请以链接形式标明本文地址。

相关推荐

登录后即可发表评论

社交账号登录

全部评论 (0)