Advertisement
gitlez

YA: Displaying Maximum Number of Online Users

Apr 15th, 2012
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.55 KB | None | 0 0
  1. <?php
  2.  
  3. // If $users is an array:
  4.  
  5. function wpwhosonline_list_authors() {
  6.     $users = wpwhosonline_recents();
  7.     $maxNumUsers = 50; // The maximum number of users you wish to display
  8.     $users = array_slice($users, 0, $maxNumUsers);
  9.     $html = '<ul id="wpwhosonline-">';
  10.  
  11.     foreach( $users as $user ) {
  12.         $last_online_ts = get_user_meta( $user->ID, 'wpwhosonline_timestamp', true );
  13.         $item = wpwhosonline_user( $last_online_ts, $user );
  14.         $class = wpwhosonline_class( $last_online_ts );
  15.         $html .= '<li id="wpwhosonline' . $user->ID . '" class="wpwhosonline-row ' . $class . '" data-wpwhosonline="' .
  16.         esc_attr( $last_online_ts ) . '">' . $item . '</li>';
  17.     }
  18.     $html .= '</ul>';
  19.     echo $html;
  20. }
  21.  
  22.  
  23.  
  24. // If $users is not an array
  25.  
  26. function wpwhosonline_list_authors() {
  27.     $users = wpwhosonline_recents();
  28.     $maxNumUsers = 50; // The maximum number of users you wish to display
  29.     $html = '<ul id="wpwhosonline-">';
  30.     $i = 0;
  31.     foreach( $users as $user ) {
  32.         $last_online_ts = get_user_meta( $user->ID, 'wpwhosonline_timestamp', true );
  33.         $item = wpwhosonline_user( $last_online_ts, $user );
  34.         $class = wpwhosonline_class( $last_online_ts );
  35.         $html .= '<li id="wpwhosonline' . $user->ID . '" class="wpwhosonline-row ' . $class . '" data-wpwhosonline="' .
  36.         esc_attr( $last_online_ts ) . '">' . $item . '</li>';
  37.         if($i++ === $maxNumUsers){
  38.             echo $html . '</ul>';
  39.             return true;
  40.         }
  41.     }
  42.     $html .= '</ul>';
  43.     echo $html;
  44. }
  45.  
  46. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement