• 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.

Viewing 1 replies (of 1 total)
  • 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. 🙂

Viewing 1 replies (of 1 total)
  • The topic ‘Updating user status on login and logout.’ is closed to new replies.