function mailchimp_lists_load_user_mergevars in Mailchimp 7.2
Get the relevant merge vars for the given user for the given list.
@account $account @mailchimp_list $list @array null $interest_groups
Return value
<array> mergevars array formatted for the MCAPI
5 calls to mailchimp_lists_load_user_mergevars()
- mailchimp_lists_cron in modules/
mailchimp_lists/ mailchimp_lists.module - Implements hook_cron().
- mailchimp_lists_process_subscribe_form_choices in modules/
mailchimp_lists/ mailchimp_lists.module - Processor for various list form submissions.
- mailchimp_lists_queue_existing in modules/
mailchimp_lists/ mailchimp_lists.module - Queue existing users in a list. Optionally, queue users to remove.
- mailchimp_lists_rules_action_user_subscribe_list in modules/
mailchimp_lists/ mailchimp_lists.rules.inc - Action callback: Subscribe a user to a list.
- _mailchimp_lists_build_update_mergevars in modules/
mailchimp_lists/ mailchimp_lists.module - Helper function for mailchimp_lists_user_sync().
File
- modules/
mailchimp_lists/ mailchimp_lists.module, line 767 - Mailchimp lists module.
Code
function mailchimp_lists_load_user_mergevars($account, $list, $interest_groups = NULL) {
$values = array();
// Grab the saved list merge vars and filter out unset values:
if (!empty($list->settings['mergefields'])) {
$mergevars = array_filter($list->settings['mergefields']);
// We have to filter one-by-one, since an array_flip would munch any
// duplicate values.
foreach ($mergevars as $name => $token) {
// Match with token values:
$replaced = module_invoke_all('mailchimp_lists_merge_values', array(
$token => $name,
), $account, $list);
// Only populate our merge variables if the replacement was successful,
// some configured tokens might not always be available.
if (isset($replaced[$name])) {
$values[$name] = $replaced[$name];
}
}
// Always add email:
$values += array(
'EMAIL' => $account->mail,
);
}
// Format interest groups if present:
if (!empty($interest_groups)) {
$values['GROUPINGS'] = _mailchimp_lists_reformat_groupings($interest_groups);
}
return $values;
}