CF7 get_current_user_id() not working in filter

[ad_1]

I’m trying to get the logged-in user information (current user id) inside a CF7 filter like this:

function wpcf7_preload($tag, $unused) {
$user_id = get_current_user_id();
// do something with $user_id…
return $tag;
}
add_filter( ‘wpcf7_form_tag‘, ‘wpcf7_preload’, 10, 2);

Doesn’t matter if the a user is logged in or not, $user_id always is 0! Same problem inside the “wpcf7_before_send_mail” filter.
On the other hand the form tag “user_login” and “user_id” work as desired. Does anyone know, why “get_current_user_id()” does not work?

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer