function mailchimp_get_memberinfo in Mailchimp 7.4
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.3 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
object Member info object, empty if there is no valid info.
7 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.
- 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.
- mailchimp_lists_field_formatter_view in modules/
mailchimp_lists/ includes/ mailchimp_lists.field.inc - Implements hook_field_formatter_view().
- mailchimp_process_webhook in ./
mailchimp.module - Process a webhook post from Mailchimp.
File
- ./
mailchimp.module, line 490 - 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 = new stdClass();
/* @var \Mailchimp\MailchimpLists $mc_lists */
$mc_lists = mailchimp_get_api_object('MailchimpLists');
try {
if (!$mc_lists) {
throw new MailchimpException('Cannot get member info without Mailchimp API. Check API key has been entered.');
}
try {
$memberinfo = $mc_lists
->getMemberInfo($list_id, $email);
cache_set($list_id . '-' . $email, $memberinfo, 'cache_mailchimp', CACHE_TEMPORARY);
} catch (Exception $e) {
// Throw exception only for errors other than member not found.
if ($e
->getCode() != 404) {
throw new Exception($e
->getMessage(), $e
->getCode(), $e);
}
}
} 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;
}