我找到了一个解决方案,另一个人给了我第二个更好的解决方案。该对话可在此处找到:Getting User email on logout. wp_logout
以下是两种解决方案:
解决方案1:
add_action( \'clear_auth_cookie\', \'mmd_JudgeLogoutCheck\', 10,0); <<<< ADD THIS INSTEAD
///add_action( \'wp_logout\', \'mmd_JudgeLogoutCheck\', 10,0); <<<<< REMOVE THIS
function mmd_JudgeLogoutCheck()
{
$current_user = wp_get_current_user();
if ( in_array( \'judge\', (array) $current_user->roles ) )
{
mmd_StoreJudgeStatus($current_user->user_email, JUDGE_LOGGED_OUT, 0);
}
}
解决方案2:更好。因为它不会干扰woocommerce注销功能。
add_action( \'wp_logout\', \'mmd_JudgeLogoutCheck\', 10,1); <<< NOTE PASSING 1 PARAMETER
function mmd_JudgeLogoutCheck($user_id)
{
$current_user = get_userdata($user_id);
if ( (in_array( \'judge\', (array) $current_user->roles ))
{
mmd_StoreJudgeStatus($current_user->user_email, JUDGE_LOGGED_OUT, 0);
}
}