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

目录

描述

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.

add_settings_error() 描述

用法

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

add_settings_error() 用法

参数

$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'

add_settings_error() 参数

返回值

(void) 

This function does not return a value.

add_settings_error() 返回值

示例

add_settings_error() 示例

注意

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

add_settings_error() 注意

历史

添加于 版本: 3.0

add_settings_error() 历史

源文件

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

add_settings_error() 源文件

相关