I have a code to get username and writes it to a log file when you logout of wordpress but it has stopped working when i updated my wordpress core to 5.7.
When you log out the username is no longer written to the file. Maybe something wrong with my hook. This is my code:
function get_username(){
if(is_user_logged_in()){
$active_user = wp_get_current_user();
$username = $active_user->user_login;
$username = "User's username: ".$username;
log_file_setup($username);
}
}
add_action('wp_logout', 'get_username',1);
2
Answers
I think i got it
i changed the hook from:
to
Any other suggestions are welcome
You can use
clear_auth_cookie
function to get username.Or you can use
template_redirect