Skip to content

Instantly share code, notes, and snippets.

@groucho75
Last active June 11, 2016 01:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save groucho75/1d44d76304ed6e2774a7a8c55a156fc0 to your computer and use it in GitHub Desktop.
Save groucho75/1d44d76304ed6e2774a7a8c55a156fc0 to your computer and use it in GitHub Desktop.
ALO-CF7 Integration - Updated
function my_easymail_add_subscriber ( $cf7 ) {
$submission = WPCF7_Submission::get_instance();
$data = $submission->get_posted_data();
$fields['email'] = $data["your-email"];
$fields['name'] = $data["your-name"];
if ( function_exists ('alo_em_add_subscriber') && is_email( $fields['email'] ) )
{
alo_em_add_subscriber( $fields, 1, alo_em_get_language(true) );
$subscriber = alo_em_get_subscriber( $fields['email'] );
if ( ! empty( $data["easymail-lists"][0] ) ) {
foreach( $data["easymail-lists"] as $list_id ) {
alo_em_add_subscriber_to_list ( $subscriber->ID, $list_id );
}
}
}
return $cf7;
}
add_action( 'wpcf7_before_send_mail', 'my_easymail_add_subscriber' );
@groucho75
Copy link
Author

Hi Jeff, first of all thanks a lot for your contribute :)
I hope the above code should be ok for you.

After adding it in /mu-plugins folder or in your theme functions.php, you have to setup the form created with CF7:

  1. Add a checkboxes element inside form. The name must be easymail-lists to match the above script. So something like:

[checkbox easymail-lists use_label_element "list one|1" list two|2" "list three|3" "list four|4"]

use the pipe (http://contactform7.com/selectable-recipient-with-pipes/) to set the lists: the list name - the pipe - the EasyMail list ID.
It's important that the IDs match with EasyMail mailing list IDs you can find them in plugin settings.

  1. In your form email you can use [_raw_easymail-lists] to show the selected list labels. Otherwise the standard [easymail-lists] shows the IDs.

I hope it helps.

@jeffmcneill
Copy link

jeffmcneill commented Jun 11, 2016

Hi Alo,

Great work. I integrated the instructions with the file and added . The file can be dropped into /wp-content/plugins/ and it just works (both for single installs and for multisite). This should help all the other folks who have the same desire to integrate with CF7.

See: https://gist.github.com/jeffmcneill/e7a53e11979ceddf81ec6c4764057c76

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment