hooks – wp_get_current_user Not working

I am using the wp_get_current_user () It works inside a hook that is triggered before the email is sent from contactform7. The function works, but the main problem is that the function does not return to the current user, if I provide the user ID manually, the function works, otherwise it does not.

The function –

add_action (& # 39; wpcf7_before_send_mail & # 39 ;, & # 39; ccdit & # 39 ;, 10.1);
ccdit function ($ cf7) {
try{
$ wpcf7 = WPCF7_ContactForm :: get_current ();
$ u = wp_get_current_user ();

if ($ wpcf7-> id () == 505) {
if (is_user_has_role (& # 39; phone_verified & # 39;) == false) {
$ u-> add_role (& # 39; phone_verified & # 39;);
}
}
}
capture (exception $ e) {
throw new exception ($ e.Message);
}
}


function is_user_has_role ($ role, $ user_id = null) {
if (is_numeric ($ user_id)) {
$ user = get_userdata ($ user_id);
}
else {
$ user = wp_get_current_user ();
}

yes (! empty ($ user)) {
return in_array ($ role, (array) $ user-> roles);
}
plus
{
false return;
}
}

I tried many things to make it work but it does not work.