daily pastebin goal
50%
SHARE
TWEET

Untitled

a guest Nov 22nd, 2011 221 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. add_action('wp', 'update_online_users_status');
  2. function update_online_users_status(){
  3.  
  4.   if(is_user_logged_in()){
  5.  
  6.     // get the online users list
  7.     if(($logged_in_users = get_transient('users_online')) === false) $logged_in_users = array();
  8.  
  9.     $current_user = wp_get_current_user();
  10.     $current_user = $current_user->ID;  
  11.     $current_time = current_time('timestamp');
  12.  
  13.     if(!isset($logged_in_users[$current_user]) || ($logged_in_users[$current_user] < ($current_time - ($time_limit * 60)))){
  14.       $logged_in_users[$current_user] = $current_time;
  15.       set_transient('users_online', $logged_in_users, 30 * 60);
  16.     }
  17.  
  18.   }
  19. }
  20.  
  21.  
  22. // use this function to check if a user is online
  23. // pass the user ID
  24. // example, for the author page:
  25. //      if(is_user_online(get_query_var('author'))) echo 'user is online';
  26.  
  27. function is_user_online($user_id) {
  28.  
  29.   // get the online users list
  30.   $logged_in_users = get_transient('users_online');
  31.  
  32.   // online, if (s)he is in the list and last activity was less than 15 minutes ago
  33.   return isset($logged_in_users[$user_id]) && $logged_in_users[$user_id > (current_time('timestamp') - (15 * 60));
  34. }
  35.  
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top