简体   繁体   中英

How to save the last logout time of a user in the database?

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 ); 

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM