sanitize_user_object

Sanitize every user field.

Description

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

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

Returns (object|array)

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

Parameters (2)

0. $user (object|array)
The User Object or Array
1. $context — Optional. (string) => 'display'
Optional, default is display.. How to sanitize user fields.

Usage

  1. if ( !function_exists( 'sanitize_user_object' ) ) { 
  2. require_once ABSPATH . WPINC . '/deprecated.php'; 
  3.  
  4. // The User Object or Array 
  5. $user = null; 
  6.  
  7. // Optional, default is 'display'. How to sanitize user fields. 
  8. $context = 'display'; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = sanitize_user_object($user, $context); 
  12.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/deprecated.php  
  1. function sanitize_user_object($user, $context = 'display') { 
  2. _deprecated_function( __FUNCTION__, '3.3.0' ); 
  3.  
  4. if ( is_object($user) ) { 
  5. if ( !isset($user->ID) ) 
  6. $user->ID = 0; 
  7. if ( ! ( $user instanceof WP_User ) ) { 
  8. $vars = get_object_vars($user); 
  9. foreach ( array_keys($vars) as $field ) { 
  10. if ( is_string($user->$field) || is_numeric($user->$field) ) 
  11. $user->$field = sanitize_user_field($field, $user->$field, $user->ID, $context); 
  12. $user->filter = $context; 
  13. } else { 
  14. if ( !isset($user['ID']) ) 
  15. $user['ID'] = 0; 
  16. foreach ( array_keys($user) as $field ) 
  17. $user[$field] = sanitize_user_field($field, $user[$field], $user['ID'], $context); 
  18. $user['filter'] = $context; 
  19.  
  20. return $user;