Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all articles
Browse latest Browse all 8245

amybill1978 on "delete_user_meta function with wp_clear_auth_cookie?"

$
0
0

So I have a little hack I made to add the user's PHPSESSID to the wp_usermeta table when a user logs in (which is working perfectly). I've been trying for several hours to delete the same info when a user logs out, and can't seem to get the dang thing to work. I'm wondering now if the wp user object isn't available anymore after you click logout? I read elsewhere that I should be able to use wp_clear_auth_cookie(), but no luck there either. Any insights would be great.

function create_session_id($user_login){

    if(!session_id()) {
            	session_start();
		$user_obj = get_user_by('login', $user_login );
		$user_id = $user_obj->ID;
		$session_id = session_id();
		add_user_meta( $user_id, 'session_id', $session_id);
	}else{
		$user_obj = get_user_by('login', $user_login );
		$user_id = $user_obj->ID;
		$session_id = session_id();
		add_user_meta( $user_id, 'session_id', $session_id);
	}
}
add_action('wp_login', 'create_session_id');

function delete_session_id(){

		$current_user = wp_get_current_user();
		$user_id = $current_user->ID;
		delete_user_meta( $user_id, 'session_id', '');
}
add_action('wp_clear_auth_cookie()', 'delete_session_id');

Viewing all articles
Browse latest Browse all 8245

Trending Articles