简体   繁体   English

如何在数据库中保存用户的最后一次注销时间?

[英]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. get_current_user_id()在您的情况下返回 0,因为您的函数是在注销后调用的。

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.当 wp_logout 传递注销的用户 ID 时。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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