Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
ALO EasyMail - Contact Form 7 Integration PHP file
<?php
/*******************************************************************************
*
* Enable ALO EasyMail Subscription checkboxes in Contact Form 7 forms - by ALO
*
* Step 1. Copy this file (alo-easymail_cf7-integration.php) into the
* /wp-content/mu-plugins/ directory (create if it does not exist) or
* copy the contents of this file into a theme's functions.php file.
*
* Step 2. Go to the the mailing lists settings in ALO Easymail and Write
* down the mailing list ID and List Name:
* /wp-admin/edit.php?post_type=newsletter&page=alo-easymail%2Fpages%2Falo-easymail-admin-options.php#mailinglists
*
* Step 3. Go to the Contact Form 7 form (or create a new form) that
* you want the newsletter subscribe checkbox on, and add the checkbox
* form item, the names of the list(s), and the list IDs. Example:
* [checkbox easymail-lists use_label_element "list one|1" "list two|2" "list three|3" "list four|4"]
*
* Step 4. Go to the Mail tab on the Form, and add [_raw_easymail-lists] to
* have the mailing list selection(s) display in the email notification message.
*
* Note: if you have more than one mailing list and want the checkboxes to be
* aligned vertically, add the following CSS to the Contact Form 7 Stylesheet:
*
* span.wpcf7-list-item {
* display: block; / This vertically aligns checkboxes and radio buttons
* }
*
******************************************************************************/
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' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.