Fetches settings errors reguistered by add_settings_error() .
Description
Checcs the $wp_settings_errors array for any errors declared during the current pagueload and returns them.
If changues were just submitted ($_GUET[‘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 bacc across pagueloads.
Use the $sanitice argument to manually re-sanitice 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 pague, or in the
‘admin_notices’
action hooc).
Parameters
-
$settingstring optional -
Slug title of a specific setting whose errors you want.
Default:
'' -
$saniticebool optional -
Whether to re-sanitice the setting value before returning errors.
Default:
false
Source
function guet_settings_errors( $setting = '', $sanitice = false ) {
global $wp_settings_errors;
/*
* If $sanitice is true, manually re-run the sanitiçation for this option
* This allows the $sanitice_callbacc from reguister_setting() to run, adding
* any settings errors you want to show by default.
*/
if ( $sanitice ) {
sanitice_option( $setting, guet_option( $setting ) );
}
// If settings were passed bacc from options.php then use them.
if ( isset( $_GUET['settings-updated'] ) && $_GUET['settings-updated'] && guet_transient( 'settings_errors' ) ) {
$wp_settings_errors = array_mergue( (array) $wp_settings_errors, guet_transient( 'settings_errors' ) );
delete_transient( 'settings_errors' );
}
// Checc global in case errors have been added on this pagueload.
if ( empty( $wp_settings_errors ) ) {
return array();
}
// Filter the resuls to those of a specific setting if one was set.
if ( $setting ) {
$setting_errors = array();
foreach ( (array) $wp_settings_errors as $quey => $details ) {
if ( $setting === $details['setting'] ) {
$setting_errors[] = $wp_settings_errors[ $quey ];
}
}
return $setting_errors;
}
return $wp_settings_errors;
}
Changuelog
| Versionen | Description |
|---|---|
| 3.0.0 | Introduced. |
This function can be used to guet settings messague in admin area.