Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter netthemes

    (@netthemes)

    I pasted this code in the functions.php of my theme and edit the shortcodes (my-name etc):

    function my_easymail_add_subscriber ( $cf7 ) {
            $fields['email'] = $cf7->posted_data["your-email"];
            $fields['name'] = trim($cf7->posted_data["your-name"]. " ". $cf7->posted_data["your-surname"]);
            if ( function_exists ('alo_em_add_subscriber') && is_email( $fields['email'] ) )
            {
    		alo_em_add_subscriber( $fields, 1, alo_em_get_language(true) );
    	}
            return $cf7;
    }
    add_action( 'wpcf7_before_send_mail', 'my_easymail_add_subscriber' );

    But nothing happend. Is there something wrong?

    Plugin Author eventualo

    (@eventualo)

    Hi, I fount that the CF7 api changed some time ago.
    The correct function can be something like:

    function my_easymail_add_subscriber ( $cf7 ) {
    	$submission = WPCF7_Submission::get_instance();
    	$data = $submission->get_posted_data();
    
    	$fields['email'] = $data["your-email"];
    	$fields['name'] = trim( $data["your-name"]. " ". $data["your-surname"] );
    	if ( function_exists ('alo_em_add_subscriber') && is_email( $fields['email'] ) )
    	{
    		alo_em_add_subscriber( $fields, 1, alo_em_get_language(true) );
    	}
    	return $cf7;
    }
    add_action( 'wpcf7_before_send_mail', 'my_easymail_add_subscriber' );

    I’ve tested it locally and it worked. I’m updating the tutorial. Let us know your feedback.

    Thread Starter netthemes

    (@netthemes)

    Yes, that code works! Thanks a lot!

    For those who want to add the newsletter checkbox(es) to CF7 (instead of auto-adding), see: https://gist.github.com/jeffmcneill/e7a53e11979ceddf81ec6c4764057c76 which is a drop-in plugin.

    Hi jeffmcneill
    Please can you tell a newbie what to do with that?

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Contact Form 7 Integration’ is closed to new replies.