Updating user status on login and logout.
-
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
SETuser_status
=”Online” WHEREuser_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.
- The topic ‘Updating user status on login and logout.’ is closed to new replies.