Support » Plugin: Contact Form 7 » Get User ID when form is submitted

  • Resolved myCred

    (@designbymerovingi)


    I am using the wpcf7_mail_sent action hook to detect successful form submissions and would like to know how I could get the ID of the user that submits the form (if they are logged in).

    Before version 4.8, this was pretty straight forward:

    function detect_cf_submission() {
    
    	if ( is_user_logged_in() ) {
    
    		$user_id = get_current_user_id();
    
    		// do something...
    
    	}
    
    }
    add_action( 'wpcf7_mail_sent', 'detect_cf_submission' );

    However as of version 4.8, is_user_logged_in() will always return false and get_current_user_id() will always return zero, even if the form is submitted by someone who is logged in on the website.

    Can anyone shed some light on what exactly got changed and why?

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Get User ID when form is submitted’ is closed to new replies.