Skip to content

Instantly share code, notes, and snippets.

@ringmaster
Created August 27, 2012 19:14
Show Gist options
  • Select an option

  • Save ringmaster/3491426 to your computer and use it in GitHub Desktop.

Select an option

Save ringmaster/3491426 to your computer and use it in GitHub Desktop.
User::identify()
/**
* Check for the existence of a cookie, and return a user object of the user, if successful
* @return User user object, or false if no valid cookie exists
*/
public static function identify()
{
$out = false;
// Let plugins set the user
if ( $out = Plugins::filter('user_identify', $out) ) {
self::$identity = $out;
}
// If we have a user_id for this user in their session, use it to get the user object
if ( isset( $_SESSION['user_id'] ) ) {
if ( $user = self::get_by_id( intval( $_SESSION['user_id'] ) ) ) {
// Cache the user in the static variable
self::$identity = $user;
$out = $user;
}
}
// Is the logged-in user cached?
if ( $out instanceof User ) {
// is this user acting as another user?
if ( isset( $_SESSION['sudo'] ) ) {
// if so, let's return that user data instead
$out = self::get_by_id( intval( $_SESSION['sudo'] ) );
}
}
else {
$out = self::anonymous();
}
return $out;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment