Warning: This function has been deprecated.

sanitize_user_object() WordPress Function

The sanitize_user_object() function is used to sanitize a user object before it is displayed on the front end of a WordPress site. This function ensures that all user data is safe and secure, and that no sensitive information is displayed to unauthorized users.

sanitize_user_object( object|array $user, string $context = 'display' ) #

Sanitize every user field.


Description

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


Top ↑

Parameters

$user

(object|array)(Required)The user object or array.

$context

(string)(Optional) How to sanitize user fields.

Default value: 'display'


Top ↑

Return

(object|array) The now sanitized user object or array (will be the same type as $user).


Top ↑

Source

File: wp-includes/deprecated.php

function sanitize_user_object($user, $context = 'display') {
	_deprecated_function( __FUNCTION__, '3.3.0' );

	if ( is_object($user) ) {
		if ( !isset($user->ID) )
			$user->ID = 0;
		if ( ! ( $user instanceof WP_User ) ) {
			$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;
}


Top ↑

Changelog

Changelog
VersionDescription
3.3.0This function has been deprecated.
2.3.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More