Advertisements

get_settings_errors

Definition:
function get_settings_errors( $setting = '', $sanitize = FALSE ) {}

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.

Parameters

  • string $setting: Optional slug title of a specific setting who’s errors you want.
  • boolean $sanitize: Whether to re-sanitize the setting value before returning errors.

Return values

returns:Array of settings errors

Source code

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

	// Ignore transients if $sanitize is true, we dont' want the old values anyway

	if ( isset($_GET['settings-updated']) && $_GET['settings-updated'] && get_transient('settings_errors') ) {

		$settings_errors = get_transient('settings_errors');

		delete_transient('settings_errors');

	// Otherwise check global in case validation has been run on this pageload

	} elseif ( count( $wp_settings_errors ) ) {

		$settings_errors = $wp_settings_errors;

	} else {

		return;

	}



	// Filter the results to those of a specific setting if one was set

	if ( $setting ) {

		foreach ( (array) $settings_errors as $key => $details )

			if ( $setting != $details['setting'] )

				unset( $settings_errors[$key] );

	}

	return $settings_errors;

}

1683

Advertisements

No comments yet... Be the first to leave a reply!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: