You are here

function mailchimp_update_user in Mailchimp 7.2

Update a user in a given list.

1 call to mailchimp_update_user()
mailchimp_lists_execute_change in modules/mailchimp_lists/mailchimp_lists.module
Calls the appropriate API function, or adds to the queue, as appropriate.

File

./mailchimp.module, line 151
Mailchimp module.

Code

function mailchimp_update_user($list, $email, $merge_vars, $message = TRUE, $mcapi = NULL) {
  $success = FALSE;
  if ($mcapi || ($mcapi = mailchimp_get_api_object())) {
    $success = $mcapi
      ->listUpdateMember($list->mc_list_id, $email, $merge_vars);
    if ($success && $message) {
      drupal_set_message(t('You have updated your settings in %list.', array(
        '%list' => $list->label,
      )));
    }

    // Clear user cache:
    mailchimp_cache_clear_user($list->mc_list_id, $email);
    if ($success) {
      watchdog('mailchimp', '@email was updated in 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;
}