Advertisement
Guest User

Untitled

a guest
May 27th, 2015
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function vf_get_user() {
  2.    global $current_user, $wp_roles;
  3.  
  4.    if (!function_exists('get_currentuserinfo'))
  5.       require_once ABSPATH . WPINC . '/pluggable.php';
  6.    get_currentuserinfo();
  7.  
  8.    $user = array();
  9.    if ($current_user->ID != '') {
  10.       $user['uniqueid'] = $current_user->ID;
  11.       $user['name'] = $current_user->display_name;
  12.       $user['email'] = $current_user->user_email;
  13.       $user['photourl'] = ''; //
  14.       $user['wp_nonce'] = wp_create_nonce('log-out');
  15.  
  16.       // Do some fudgery to grab the photo url.
  17.       try {
  18.          $avatar = new SimpleXMLElement(get_avatar($current_user->ID));
  19.          if (isset($avatar['src']))
  20.             $user['photourl'] = (string)$avatar['src'];
  21.       } catch (Exception $Ex) {
  22.       }
  23.  
  24.       // Add the user's roles to the SSO.
  25.       if (isset($current_user->roles)) {
  26.          if (!isset( $wp_roles ) )
  27.             $wp_roles = new WP_Roles();
  28.  
  29.          $role_names = $wp_roles->role_names;
  30.  
  31.          $roles = array();
  32.          foreach ((array)$current_user->roles as $role_slug) {
  33.             // Add the role slug.
  34.             $roles[] = $role_slug;
  35.  
  36.             // Add the role name if it's different from the slug.
  37.             if (isset($role_names[$role_slug])) {
  38.                $role_name = $role_names[$role_slug];
  39.                if (strcasecmp($role_name, $role_slug) !== 0) {
  40.                   $roles[] = str_replace(',', ' ', $role_name);
  41.                }
  42.             }
  43.          }
  44.  
  45.          $user['roles'] = implode(',', array_unique($roles));
  46.       } else {
  47.          $user['roles'] = null;
  48.       }
  49. //      $user['_user'] = $current_user;
  50.    }
  51.  
  52.    // Allow other plugins to modify the user.
  53.    $user = apply_filters('vf_get_user', $user);
  54.  
  55.    return $user;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement