WordPress函数文档add_settings_error()

注册添加一个设置错误提示信息 描述 Register a settings error to be displ…

注册添加一个设置错误提示信息

描述

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.

用法

<?php add_settings_error$setting$code$message$type ?>

参数

$setting

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

默认值: None

$code

(string) (必填) Slug-name to identify the error. Used as part of ‘id’ attribute in HTML output. A prefix of ‘setting-error-‘ will be added to the string in $code and assigned to the ‘id’ attribute of the outermost <div> for this error.

默认值: None

$message

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

默认值: None

$type

(string) (可选) The type of message it is. $type will be add an HTML class of the same name of the outermost <div>. To add multiple classes separate them with a space.

  • error
  • updated

默认值: ‘error’

返回值

(void) 

This function does not return a value.

示例

注意

The problem only occurs when I use add_menu_page() or add_submenu_page(). The validation errors are not shown.

A simple work around is to add settings_errors() to my options page, which will make the notification box show… However, seems like a dirty fix

历史

添加于 版本: 3.0

源文件

add_settings_error() 函数的代码位于 wp-admin/includes/template.php.

相关

Settings API:
register_setting(),
unregister_setting(),
add_settings_field(),
add_settings_section(),
add_settings_error(),
get_settings_errors(),
settings_errors()

  • 原文:http://codex.wordpress.org/Function_Reference/add_settings_error
类别:WordPress函数文档

本文收集自互联网,转载请注明来源。
如有侵权,请联系 wper_net@163.com 删除。

评论 (0)COMMENT