Forum Replies Created

Viewing 1 replies (of 1 total)
  • I had the same problem.

    The quick-fix is to save the logged user ID in a global variable while in the init hook, and then check if it’s not zero in your wpcf7_before_send_mail hook :

    add_action(‘init’,function(){
    $GLOBALS[‘wpcf7_author_id’] = wp_get_current_user()->ID;
    });

    add_action( ‘wpcf7_before_send_mail’, function($contact_form ){
    if($GLOBALS[‘wpcf7_author_id’] != 0){
    // code for logged user
    }
    });

    That solved the problem for me.

    I don’t know why is_user_logged_in() is not working in the wpcf7_before_send_mail hook, but I suspect whether other part of the code mess with it before or something in relation with hook order. Not sure.

Viewing 1 replies (of 1 total)