• Resolved hugomilan

    (@hugomilan)


    Hi,

    I’m trying to obtain the user id when a form is submitted but I always obtain id 0. I’m sure I’m logged in. A minimal example code, which can be added to the functions.php is:

    add_action('wpcf7_before_send_mail', function($cfdata) {
        $user_id = get_current_user_id();
        error_log("User_id:" . $user_id);
        return $cfdata;
    });

    I also tried sending in the username together with the form and on obtaining the user id from get_user_by("user_login", $formdata['username']); but that didn’t work either.

    My goal here is to use contact form 7 to update an user profile and then send the updated information to them by e-mail. That’s why I need the user id. I’m not an expert in wordpress but I have some experience with code.

    Does anyone know a solution?
    Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘get_current_user_id() and wpcf7_before_send_mail()’ is closed to new replies.