[wp-hackers] Using WP Transients for User Sessions

BenderisGreat greglancaster71 at gmail.com
Wed Oct 16 13:58:28 UTC 2013

Basically I am using transients to setup a timeout after users login, so
active users names will have a little green label by them.  After the time
period, that dot disappears.  However I know on a busy site transients can
be troublesome, so I setup (I think, I have no idea if I did this properly)
a delete_transient on logout. 

I am checking the database and I dont see anything being deleted from
wp_options, still has the same...


you get the idea.  So I am hoping someone more familiar with this can check
out my code here.  Now I should mention that the delete function APPEARS to
be working.  On logout, the user session label is immediately changed (vs it
staying on for 30 mins or so without the function).

Does this all look like its functioning properly?  Why am I not seeing the
hash delete from wp_options upon logout?

*add_action('wp', 'update_online_users_status');
function update_online_users_status(){


        if(($logged_in_users = get_transient('users_online')) === false)
$logged_in_users = array();

        $current_user = wp_get_current_user();
        $current_user = $current_user->ID;  
        $current_time = current_time('timestamp');

        if(!isset($logged_in_users[$current_user]) ||
($logged_in_users[$current_user] < ($current_time - (15 * 60)))){
            $logged_in_users[$current_user] = $current_time;
            set_transient('users_online', $logged_in_users, 30 * 60);

function is_user_online( $user_id ) {
    $logged_in_users = get_transient( 'users_online' );
    return isset( $logged_in_users[$user_id] ) && (
$logged_in_users[$user_id] >     ( current_time( 'timestamp' ) - ( 15 * 60 )
) );   

and on logout, its calling this:

*function clear_transient_on_logout() {
add_action('wp_logout', 'clear_transient_on_logout');*

View this message in context: http://wordpress-hackers.1065353.n5.nabble.com/Using-WP-Transients-for-User-Sessions-tp42547.html
Sent from the Wordpress Hackers mailing list archive at Nabble.com.

More information about the wp-hackers mailing list