I've installed the Mailchimp plugin and added a field to my user profile called field_mailchimp_test
and I'm attempting to subscribe all current Drupal users to this list programmatically (since it seems this feature was taken out of the 7.3 branch for whatever reason).
I attempted this code:
function module_mailchimp_subscribe() {
$users = entity_load('user');
foreach ($users as $key => $user) {
if ($user->uid != 1 && !empty($user->mail)) {
$edit = array(
'field_mailchimp_test' => array(
'und' => array(
0 => array(
'value' => true
)
)
)
);
var_dump(user_save($user, $edit)); exit;
}
}
}
Which returns a user object with the field_mailchimp_test
field set to true, which I would think would subscribe them, but when checking the users page and/or var_dump
ing the user object, the field is no longer set to true.
So my question is either what is wrong with my code that it's not subscribing users, or what is a different (easier/more sensical) way of doing this?