On this page
sanitize_user_object( object|array $user, string $context = 'display' ): object|array
This function has been deprecated.
Sanitize every user field.
Description
If the context is ‘raw’, then the user object or array will get minimal santization of the int fields.
Parameters
$userobject|array Required-
The user object or array.
$contextstring Optional-
How to sanitize user fields. Default
'display'.Default:
'display'
Return
object|array The now sanitized user object or array (will be the same type as $user).
Source
File: wp-includes/deprecated.php. View all references
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;
}
Related
Uses
| Uses | Description |
|---|---|
| sanitize_user_field() wp-includes/user.php | Sanitizes user field based on context. |
| _deprecated_function() wp-includes/functions.php | Marks a function as deprecated and inform when it has been used. |
Changelog
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/sanitize_user_object