函数原型
get_settings_errors( string $setting = ”, bool $sanitize = false ): array
函数描述
Fetches settings errors registered by add_settings_error() .
是否弃用
未弃用
函数参数
-
$setting
string
Optional - Slug title of a specific setting whose errors you want.
Default:
'' -
$sanitize
bool
Optional - Whether to re-sanitize the setting value before returning errors.
Default:
false
函数返回值
array Array of settings errors.
settingstringSlug title of the setting to which this error applies.codestringSlug-name to identify the error. Used as part of'id'attribute in HTML output.messagestringThe formatted message text to display to the user (will be shown inside styled<div>and<p>tags).typestringOptional. Message type, controls HTML class. Possible values include'error','success','warning','info'. Default'error'.
函数位置
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 ( empty( $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;
}
源码链接
变更日志
| Version | Description |
|---|---|
| 3.0.0 | Introduced. |

