Get user’s ID on logout

I think I figured this one out.

I had misread this answer and hooked the function I wrote to wp_clear_auth_cookie (actually a function itself!) instead of clear_auth_cookie (the real hook), so that wasn’t working. But now using the real hook, I think it might be. Correct me if I’m wrong.

Below is the function with the hook.

function users_last_login() {
    $cur_login = current_time(timestamp, 0);
    $userinfo = wp_get_current_user();
    update_user_meta( $userinfo->ID, 'last_login', $cur_login );
}
add_action('clear_auth_cookie', 'users_last_login', 10);