簡體   English   中英

如何在數據庫中保存用戶的最后一次注銷時間?

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

我一直試圖在我的網站上再次注冊用戶的注銷,但它似乎不再起作用了。

以下代碼是我現在正在處理的代碼

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()在您的情況下返回 0,因為您的函數是在注銷后調用的。

你可以這樣做

function user_last_logout($user_id){
  update_user_meta( $user_id, '_last_logout', time() );
} 
add_action( 'wp_logout', 'user_last_logout', 10, 1 ); 

當 wp_logout 傳遞注銷的用戶 ID 時。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM