You are here

function _mailchimp_load_user_list_mergevars in Mailchimp 7

Same name and namespace in other branches
  1. 5.2 mailchimp.module \_mailchimp_load_user_list_mergevars()
  2. 5 mailchimp.module \_mailchimp_load_user_list_mergevars()
  3. 6.2 mailchimp.module \_mailchimp_load_user_list_mergevars()
  4. 6 mailchimp.module \_mailchimp_load_user_list_mergevars()

Get the relevant merge vars for the given user for the given list

5 calls to _mailchimp_load_user_list_mergevars()
mailchimp_cron in ./mailchimp.module
Implements hook_cron().
mailchimp_subscribe_auth_form_submit in ./mailchimp.module
Submit handler to add users to lists when editing/creating a user
mailchimp_user_insert in ./mailchimp.module
Implements hook_user_insert().
mailchimp_user_update in ./mailchimp.module
Implements hook_user_update().
_mailchimp_subscribe_anon_form in ./mailchimp.module
Helper function to return form elements for a single anon newsletter

File

./mailchimp.module, line 763
Mailchimp module.

Code

function _mailchimp_load_user_list_mergevars($account, $list_id) {
  $values = array();
  $lists = variable_get('mailchimp_lists', array());
  $list = $lists[$list_id];

  // grab the saved list merge vars and filter out unset values
  if (!empty($list->mergevars)) {
    $mergevars = array_filter($list->mergevars);
    $mergevars = array_flip($mergevars);

    // match with token values
    $values = token_generate('user', $mergevars, array(
      'user' => $account,
    ));

    // strip out any HTML, profile at least, seems to allow it in text fields.
    foreach ($values as $key => $value) {
      $values[$key] = strip_tags($value);
    }

    // always add email
    $values += array(
      'EMAIL' => $account->mail,
    );
  }
  return $values;
}