Created
March 28, 2013 13:14
-
-
Save aristath/5263041 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Return HTML for a single blog user for the widget. | |
* | |
* @uses apply_filters() Calls 'wpwhosonline_author_link' on the author link element | |
* @return string HTML for the user row | |
*/ | |
function wpwhosonline_user( $last_online_ts, $user ) { | |
$avatar = get_avatar( $user->user_email, 32 ); | |
$name = $user->display_name; | |
$link = '<a href="/members/' . get_author_posts_url( $user->ID, $user->user_nicename ) . '" title="' . esc_attr( sprintf(__("Posts by %s"), $user->display_name) ) . '">' . $name . '</a>'; | |
$link = apply_filters( 'wpwhosonline_author_link', $link, $user ); | |
// this should always exist; we queried using this meta | |
if ( ! $last_online_ts ) { | |
continue; | |
} | |
$now = time(); | |
if ( $now - $last_online_ts < 120 ) { | |
$last_online = 'Online now!'; | |
} else { | |
$last_online = human_time_diff( $now, $last_online_ts ) . ' ago'; | |
} | |
$last_online_title = date_i18n( get_option('date_format') . ' ' . get_option('time_format'), $last_online_ts ); | |
if ( $last_online ) { | |
$last_online = '<span title="Last online: ' . esc_attr( $last_online_title ) . '">' . $last_online . '</a>'; | |
} | |
return $avatar . $link . '<br>' . $last_online; | |
} | |
function wpwhosonline_class( $lastonline ) { | |
$diff = time() - $lastonline; | |
if( $diff > 7200 ) { | |
return 'wpwhosonline-ancient'; | |
} elseif( $diff > 600 ) { | |
return 'wpwhosonline-recent'; | |
} else { | |
return 'wpwhosonline-active'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment