WordPress.org

Ready to get started?Download WordPress

Forums

Updating user status on login and logout. (2 posts)

  1. JohnDH
    Member
    Posted 5 years ago #

    I am trying to incorporate a functionality of being able to see who is online/logged in on my website. I am making use of the user_status field in the wp_users table by switching to a text field. Currently I have 2 snippets of code one in wp-login.php under "case 'logout'":

    $con = mysql_connect('server','admin_name','password');
    $databasename='database';
    mysql_select_db($databasename, $con);
    $query = 'UPDATE wp_users SET user_status="Offline" WHERE user_login="'.$_SERVER['USER_AUTH'].'"';  //I've also tried $_POST['user_login']
    mysql_query($query);

    and in user.php under function wp_signon:

    if ( is_wp_error($user) )
    		return $user;
    
    $con = mysql_connect('server','admin_name','password');
    $databasename='database';
    mysql_select_db($databasename, $con);
    $query = 'UPDATE wp_users SET user_status="Online" WHERE user_login="'.$_POST['user_login'].'"';
    mysql_query($query);
    
    wp_set_auth_cookie($user->ID, $credentials['remember'], $secure_cookie);
    do_action('wp_login', $credentials['user_login']);
    return $user;

    Neither one seem to update the user_status field. I've run the query in the command line on the database as [UPDATE wp_users SET user_status="Online" WHERE user_login="john_doe"] and it works so I'm thinking it has to do with I'm not using the correct item where $_POST['user_login'] is at. If anyone has any ideas or suggestion it would be greatly appreciated.

  2. asechrest
    Member
    Posted 5 years ago #

    This is far beyond my current coding ability but have you checked out plugins to see how they might do it?

    It sounds like you're looking for some different functionality than the plugin I use to show who's currently online, but maybe it'll help. The plugin is WP-UserOnline.

    If this doesn't help at all, sorry to waste your time. :)

Topic Closed

This topic has been closed to new replies.

About this Topic