function sanitize_user_object($user, $context = 'display') {}

Sanitize every user field.
If the context is ‘raw’, then the user object or array will get minimal santization of the int fields.


  • object|array $user: The User Object or Array
  • string $context: Optional, default is ‘display’. How to sanitize user fields.

Return values

returns:The now sanitized User Object or Array (will be the same type as $user)

Source code

function sanitize_user_object($user, $context = 'display') {

	if ( is_object($user) ) {

		if ( !isset($user->ID) )

			$user->ID = 0;

		if ( isset($user->data) )

			$vars = get_object_vars( $user->data );


			$vars = get_object_vars($user);

		foreach ( array_keys($vars) as $field ) {

			if ( is_string($user->$field) || is_numeric($user->$field) )

				$user->$field = sanitize_user_field($field, $user->$field, $user->ID, $context);


		$user->filter = $context;

	} else {

		if ( !isset($user['ID']) )

			$user['ID'] = 0;

		foreach ( array_keys($user) as $field )

			$user[$field] = sanitize_user_field($field, $user[$field], $user['ID'], $context);

		$user['filter'] = $context;


	return $user;



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: Logo

You are commenting using your 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: