返回介绍

get_settings_errors()

发布于 2017-09-11 00:09:05 字数 3310 浏览 1029 评论 0 收藏 0

get_settings_errors( string $setting = '',  boolean $sanitize = false )

Fetch settings errors registered by add_settings_error()


description

Checks the $wp_settings_errors array for any errors declared during the current pageload and returns them.

If changes were just submitted ($_GET[‘settings-updated’]) and settings errors were saved to the ‘settings_errors’ transient then those errors will be returned instead. This is used to pass errors back across pageloads.

Use the $sanitize argument to manually re-sanitize the option before returning errors. This is useful if you have errors or notices you want to show even when the user hasn’t submitted data (i.e. when they first load an options page, or in the ‘admin_notices’ action hook).


参数

$setting

(string) (Optional) slug title of a specific setting who's errors you want.

Default value: ''

$sanitize

(boolean) (Optional) Whether to re-sanitize the setting value before returning errors.

Default value: false


返回值

(array) Array of settings errors


源代码

File: wp-admin/includes/template.php

function get_settings_errors( $setting = '', $sanitize = false ) {
	global $wp_settings_errors;

	/*
	 * If $sanitize is true, manually re-run the sanitization for this option
	 * This allows the $sanitize_callback from register_setting() to run, adding
	 * any settings errors you want to show by default.
	 */
	if ( $sanitize )
		sanitize_option( $setting, get_option( $setting ) );

	// If settings were passed back from options.php then use them.
	if ( isset( $_GET['settings-updated'] ) && $_GET['settings-updated'] && get_transient( 'settings_errors' ) ) {
		$wp_settings_errors = array_merge( (array) $wp_settings_errors, get_transient( 'settings_errors' ) );
		delete_transient( 'settings_errors' );
	}

	// Check global in case errors have been added on this pageload.
	if ( ! count( $wp_settings_errors ) )
		return array();

	// Filter the results to those of a specific setting if one was set.
	if ( $setting ) {
		$setting_errors = array();
		foreach ( (array) $wp_settings_errors as $key => $details ) {
			if ( $setting == $details['setting'] )
				$setting_errors[] = $wp_settings_errors[$key];
		}
		return $setting_errors;
	}

	return $wp_settings_errors;
}

更新日志

Versiondescription
3.0.0Introduced.

相关函数

Uses

  • wp-includes/formatting.php: sanitize_option()
  • wp-includes/option.php: get_transient()
  • wp-includes/option.php: delete_transient()
  • wp-includes/option.php: get_option()

Used By

  • wp-admin/includes/template.php: settings_errors()

User Contributed Notes

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文