Function: get_settings_errors

get_settings_errors( string $setting, boolean $sanitize )

Fetch settings errors registered by add_settings_error().

Shortcut: gse

You can use above key combination to trigger the associated snippet for this function in the WordPress Snippets for Visual Studio Code extension. You can also use this shortcut to search for this function on this website.

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).

Parameters

Name Type(s) Default Value Description
$setting string ''

Optional slug title of a specific setting whose errors you want.

$sanitize boolean false

Whether to re-sanitize the setting value before returning errors.

Returns

array

Array of settings errors.

WordPress Developer Newsletter

Stay informed of new chapter releases, important WordPress API updates and more.