settings_errors
函数
settings_errors ( $setting = '', $sanitize = false, $hide_on_update = false )
- 参数
-
-
(string)
$setting
Optional slug title of a specific setting whose errors you want.- Required: 否
- Default: (empty)
-
(bool)
$sanitize
Whether to re-sanitize the setting value before returning errors.- Required: 否
- Default: false
-
(bool)
$hide_on_update
If set to true errors will not be shown if the settings page has already been submitted.- Required: 否
- Default: false
-
(string)
- 定义位置
-
-
wp-admin/includes/template.php
, line 1927
-
wp-admin/includes/template.php
- 引入
- 3.0.0
- 弃用
- –
显示由add_settings_error()注册的设置错误。
是Settings API的一部分。为通过get_settings_errors()检索的每个错误输出一个div。
在提交基于Settings API的设置页面后,会自动调用该功能。错误应该在register_setting()中定义的设置的验证回调函数中添加。
$sanitize选项被传入get_settings_errors(),并将在其当前值上重新运行设置消毒。
$hide_on_update选项将导致错误只在设置页面首次加载时显示。如果用户已经保存了新的值,它将被隐藏,以避免重复提交后默认错误报告中已经显示的信息。这对于在用户到达设置页面时显示一般的错误是很有用的,比如缺少设置。
function settings_errors( $setting = '', $sanitize = false, $hide_on_update = false ) { if ( $hide_on_update && ! empty( $_GET['settings-updated'] ) ) { return; } $settings_errors = get_settings_errors( $setting, $sanitize ); if ( empty( $settings_errors ) ) { return; } $output = ''; foreach ( $settings_errors as $key => $details ) { if ( 'updated' === $details['type'] ) { $details['type'] = 'success'; } if ( in_array( $details['type'], array( 'error', 'success', 'warning', 'info' ), true ) ) { $details['type'] = 'notice-' . $details['type']; } $css_id = sprintf( 'setting-error-%s', esc_attr( $details['code'] ) ); $css_class = sprintf( 'notice %s settings-error is-dismissible', esc_attr( $details['type'] ) ); $output .= "n"; $output .= "n"; } echo $output; }{$details['message']}
"; $output .= "
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。