function mailchimp_subscribe_user in Mailchimp 7.2
Subscribe a user to a given list.
2 calls to mailchimp_subscribe_user()
- mailchimp_lists_execute_change in modules/
mailchimp_lists/ mailchimp_lists.module - Calls the appropriate API function, or adds to the queue, as appropriate.
- mailchimp_lists_rules_action_user_subscribe_list in modules/
mailchimp_lists/ mailchimp_lists.rules.inc - Action callback: Subscribe a user to a list.
File
- ./
mailchimp.module, line 100 - Mailchimp module.
Code
function mailchimp_subscribe_user($list, $email, $merge_vars, $message = TRUE, $mcapi = NULL) {
$success = FALSE;
if ($mcapi || ($mcapi = mailchimp_get_api_object())) {
$double_optin = $list->settings['doublein'];
$success = $mcapi
->listSubscribe($list->mc_list_id, $email, $merge_vars, 'html', $double_optin, TRUE);
if ($message && $success && $double_optin) {
drupal_set_message(t('You have chosen to subscribe to %list. An email will be sent to your address. Click the link in the email to confirm the subscription.', array(
'%list' => $list->label,
)));
}
elseif ($message && $success) {
drupal_set_message(t('You have subscribed to %list.', array(
'%list' => $list->label,
)));
}
// Clear user cache, just in case there's some cruft leftover:
mailchimp_cache_clear_user($list->mc_list_id, $email);
if ($success) {
module_invoke_all('mailchimp_subscribe_user', $list, $email, $merge_vars);
watchdog('mailchimp', '@email was subscribed to list @list.', array(
'@email' => $merge_vars['EMAIL'],
'@list' => $list->label,
), WATCHDOG_NOTICE);
}
else {
watchdog('mailchimp', 'A problem occurred subscribing @email to list @list. Message: @msg', array(
'@email' => $merge_vars['EMAIL'],
'@list' => $list->label,
'@msg' => $mcapi->errorMessage,
), WATCHDOG_WARNING);
}
}
return $success;
}