Hi again,
As Mailpoet field integration and subscribe process seems to be broken atm, here’s the code I use to keep this functionnality working on CF7 forms.
First, insert this shortcode on the CF7 form :
[checkbox your-subscription default:1 "Subscribe to our newsletter"]
Then add the following code on “functions.php” (replace “your-email”, “your-firstname”, “your-lastname” and “your-subscription” with the field names used on the form) :
function get_mailing_lists() {
$model = WYSIJA::get('list','model');
$lists = $model->get(array('name','list_id'), array('is_enabled'=>1));
$datas = array();
foreach($lists as $list) { $datas[] = $list['list_id']; }
return $datas;
}
function add_subscriber_from_contact_form() {
$cf7 = WPCF7_Submission::get_instance()
if($cf7) { $form_data = $cf7->get_posted_data(); }
$user_data = array(
'email' => $form_data['your-email'],
'firstname' => $form_data['your-firstname'],
'lastname' => $form_data['your-lastname'],
);
$list_data = array(
'user' => $user_data,
'user_list' => array('list_ids' => get_mailing_lists()),
);
if(!empty($form_data['your-subscription'])) {
$user_helper = &WYSIJA::get('user','helper');
$user_helper->addSubscriber($list_data);
}
}
add_action('wpcf7_mail_sent', 'add_subscriber_from_contact_form');
Hope it helps!