I have been trying to register again the logout of the users in my website, but it seems to not work anymore.
the following code is the one i am working on right now
function user_last_logout(){
update_user_meta( get_current_user_id(), '_last_logout', time() );
}
add_action( 'wp_logout', 'user_last_logout', 10, 1 );
CodePudding user response:
get_current_user_id()
in your case returns 0, since your function is called after logout.
You can do this instead
function user_last_logout($user_id){
update_user_meta( $user_id, '_last_logout', time() );
}
add_action( 'wp_logout', 'user_last_logout', 10, 1 );
as wp_logout passes the logged out user id.