get_settings_errors [ WordPress Functions ]
| Parameters: |
|
| Returns: |
|
| Defined at: |
|
| Codex |
Fetch settings errors registered by add_settings_error()
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 admin_notices action hook)
Source
function get_settings_errors( $setting = '', $sanitize = false ) {
global $wp_settings_errors;
// If $sanitize is true, manually re-run the sanitizisation 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;
}Examples [ wp-snippets.com ]
Top Google Search Results
- Function Reference/get settings errors « WordPress Codex
Description. Fetch settings errors registered by add_settings_error(). Checks the $wp_settings_errors array for any errors declared during the current pageload ...
codex.wordpress.org - Function Reference/settings fields « WordPress Codex
Settings API: register_setting(), unregister_setting(), add_settings_field(), add_settings_section(), add_settings_error(), get_settings_errors(), settings_errors() ...
codex.wordpress.org - Function Reference/add settings error « WordPress Codex
Settings API: register_setting(), unregister_setting(), add_settings_field(), add_settings_section(), add_settings_error(), get_settings_errors(), settings_errors() ...
codex.wordpress.org - Using The Settings API: Part 1 - Create A Theme Options Page ...
Aug 23, 2011 ... Understand the function. I made sure to comment out the function well however it should be noted that the get_settings_errors() function will not ...
wp.tutsplus.com
