function get_recently_active_users( $limit = null, $page = 1 ) {
global $wpdb;
if ( $limit && $page )
$pag_sql = $wpdb->prepare( \" LIMIT %d, %d\", intval( ( $page - 1 ) * $limit), intval( $limit ) );
$paged_users = $wpdb->get_results( $wpdb->prepare(
\"SELECT DISTINCT um.user_id FROM \" . $wpdb->base_prefix . \"usermeta um
LEFT JOIN \" . $wpdb->base_prefix . \"users u
ON u.ID = um.user_id
WHERE um.meta_key = \'last_activity\'
AND u.spam = 0 AND u.deleted = 0 AND u.user_status = 0
AND DATE_ADD( FROM_UNIXTIME(um.meta_value), INTERVAL 10 HOUR ) >= NOW()
ORDER BY FROM_UNIXTIME(um.meta_value) DESC{$pag_sql}\" ) );
return $paged_users;
}