implement CiviCRM's double opt-in feature for newsletter
This commit is contained in:
parent
675b682e0e
commit
4ff060884a
6 changed files with 67 additions and 13 deletions
|
@ -484,8 +484,29 @@ function civicrm_api3_twingle_donation_Submit($params) {
|
|||
$result_values['organization'] = $organisation_id;
|
||||
}
|
||||
|
||||
// If usage of double opt-in is selected, use MailingEventSubscribe.create to add contact to newsletter groups
|
||||
// defined in the profile
|
||||
$result_values['newsletter']['double_opt_in'] = ($profile->getAttribute('double_opt_in')) ? 'true' : 'false';
|
||||
if ($profile->getAttribute('double_opt_in') &&
|
||||
!empty($params['newsletter']) &&
|
||||
!empty($groups = $profile->getAttribute('newsletter_groups'))) {
|
||||
$group_memberships = array_column(civicrm_api3('GroupContact', 'get', array (
|
||||
'sequential' => 1,
|
||||
'contact_id' => $contact_id
|
||||
))['values'], 'group_id');
|
||||
foreach ($groups as $group_id) {
|
||||
if (!in_array($group_id, $group_memberships)) {
|
||||
$result_values['newsletter'][][$group_id] = civicrm_api3('MailingEventSubscribe', 'create', array(
|
||||
'email' => $params['user_email'],
|
||||
'group_id' => (int) $group_id,
|
||||
'contact_id' => $contact_id,
|
||||
));
|
||||
} else {
|
||||
$result_values['newsletter'][] = $group_id;
|
||||
}
|
||||
}
|
||||
// If requested, add contact to newsletter groups defined in the profile.
|
||||
if (!empty($params['newsletter']) && !empty($groups = $profile->getAttribute('newsletter_groups'))) {
|
||||
} elseif (!empty($params['newsletter']) && !empty($groups = $profile->getAttribute('newsletter_groups'))) {
|
||||
foreach ($groups as $group_id) {
|
||||
civicrm_api3('GroupContact', 'create', array(
|
||||
'group_id' => $group_id,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue