function mailchimp_get_memberinfo in Mailchimp 7.3
Same name and namespace in other branches
- 8 mailchimp.module \mailchimp_get_memberinfo()
- 7.5 mailchimp.module \mailchimp_get_memberinfo()
- 7.2 mailchimp.module \mailchimp_get_memberinfo()
- 7.4 mailchimp.module \mailchimp_get_memberinfo()
- 2.x mailchimp.module \mailchimp_get_memberinfo()
Get the MailChimp member info for a given email address and list.
Results are cached in the cache_mailchimp bin which is cleared by the MailChimp web hooks system when needed.
Parameters
string $list_id: The MailChimp list ID to get member info for.
string $email: The MailChimp user email address to load member info for.
bool $reset: Set to TRUE if member info should not be loaded from cache.
Return value
array Member info array, empty if there is no valid info.
9 calls to mailchimp_get_memberinfo()
- MailchimpListsTestCase::testGetMemberInfo in modules/
mailchimp_lists/ tests/ mailchimp_lists.test - Tests retrieval of member info for a list and email address.
- MailchimpListsTestCase::testUnsubscribe in modules/
mailchimp_lists/ tests/ mailchimp_lists.test - Tests unsubscribing a member from a list.
- MailchimpListsTestCase::testUpdateMember in modules/
mailchimp_lists/ tests/ mailchimp_lists.test - Tests updating a list member.
- mailchimp_interest_groups_form_elements in ./
mailchimp.module - Helper function to generate form elements for a list's interest groups.
- mailchimp_is_subscribed in ./
mailchimp.module - Check if the given email is subscribed to the given list.
File
- ./
mailchimp.module, line 304 - Mailchimp module.
Code
function mailchimp_get_memberinfo($list_id, $email, $reset = FALSE) {
$cache = $reset ? NULL : cache_get($list_id . '-' . $email, 'cache_mailchimp');
// Return cached lists:
if ($cache) {
return $cache->data;
}
// Query lists from the MCAPI and store in cache:
$memberinfo = array();
$mcapi = mailchimp_get_api_object();
try {
if (!$mcapi) {
throw new MailchimpException('Cannot get member info without MailChimp API. Check API key has been entered.');
}
$result = $mcapi->lists
->memberInfo($list_id, array(
array(
'email' => $email,
),
));
if ($result['success_count']) {
$memberinfo = reset($result['data']);
cache_set($list_id . '-' . $email, $memberinfo, 'cache_mailchimp', CACHE_TEMPORARY);
}
} catch (Exception $e) {
watchdog('mailchimp', 'An error occurred requesting memberinfo for @email in list @list. "%message"', array(
'@email' => $email,
'@list' => $list_id,
'%message' => $e
->getMessage(),
), WATCHDOG_ERROR);
}
return $memberinfo;
}