setup_userdata

Set up global user vars.

Description

setup_userdata( (string) $for_user_id = '' ); 

Used by wp_set_current_user() for back compat. Might be deprecated in the future.

Parameters (1)

0. $for_user_id — Optional. (string) => ''
User ID to set up global data.

Usage

  1. if ( !function_exists( 'setup_userdata' ) ) { 
  2. require_once ABSPATH . WPINC . '/user.php'; 
  3.  
  4. // Optional. User ID to set up global data. 
  5. $for_user_id = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = setup_userdata($for_user_id); 
  9.  

Defined (1)

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

/wp-includes/user.php  
  1. function setup_userdata($for_user_id = '') { 
  2. global $user_login, $userdata, $user_level, $user_ID, $user_email, $user_url, $user_identity; 
  3.  
  4. if ( '' == $for_user_id ) 
  5. $for_user_id = get_current_user_id(); 
  6. $user = get_userdata( $for_user_id ); 
  7.  
  8. if ( ! $user ) { 
  9. $user_ID = 0; 
  10. $user_level = 0; 
  11. $userdata = null; 
  12. $user_login = $user_email = $user_url = $user_identity = ''; 
  13. return; 
  14.  
  15. $user_ID = (int) $user->ID; 
  16. $user_level = (int) $user->user_level; 
  17. $userdata = $user; 
  18. $user_login = $user->user_login; 
  19. $user_email = $user->user_email; 
  20. $user_url = $user->user_url; 
  21. $user_identity = $user->display_name;