I have MailChimp Lists and Signup sub-modules enabled to allow users to subscribe to MailChimp lists via their Drupal user accounts.

In the settings for user profile MC list signup (/admin/config/people/accounts/fields/field_mailchimp_subscription) the default values (which state "The default value for this field, used when creating new content.") is set to subscribe users to a list.

If the user un-checks those boxes to not subscribe to the given list (thus overriding the default) and saves their account, the user is not subscribed to the list as intended. However, if any system bulk process (i.e. VBO or Rules) is used to edit the User account, the defaults for MC Lists are used, thus overriding the users's original choices.

I believe this is a bug, as the user's selections should not be overridden on account updates to comply with defaults. Is anyone else seeing this issue besides me?

Comments

nwehner created an issue.

BarisW’s picture

I see the same happening after a long debugging session. I wanted to unsubscribe users when cancelling their accounts, so I wrote the following piece of code:

<?php
/**
 * Implements hook_user_cancel().
 */
function MYMODULE_user_cancel($edit, $account, $method) {
  if ($lists = mailchimp_get_lists()) {
    $list = reset($lists);
    mailchimp_unsubscribe_member($list->id, $account->mail, TRUE);
  }
}
?>

When cancelling the user I see them being removed from the mailchimp list. However, a second later, they are re-added again.

BarisW’s picture

This happens in _mailchimp_lists_field_postsave().

BarisW’s picture

I 'fixed' it by leaving the default value empty, and subscribe users by default using the following code:

<?php
/**
 * Implements hook_user_insert().
 */
function MYMODULE_user_insert(&$edit, $account, $category) {
  if ($lists = mailchimp_get_lists()) {
    $list = reset($lists);
    mailchimp_subscribe($list->id, $account->mail);
  }
}
?>

However, it would be better if the Mailchimp module only uses the default value when creating new users, not updating existing users.

robriley78’s picture

I have an issue whereby the default value is ignored on creating new users. It was working but appears to have just stopped. I've just updated to 7.56 core and 7.49 module but the problem persists. Originally we had it configured so so MC field was hidden from the user registration form but still had the default value of subscribed and it worked fine. Now the only way it (sort of) works is if I expose it on the user registration form - the box is ticked. However if I hide it from the user registration form and sign up as a test user, I'm not subscribed by default. I've tried changing permissions and other settings but not getting anywhere.

Is this a known issue? The strange thing is why it was working fine for so long and just stopped. Maybe something at the MC end changed?

Thanks in advance.

robriley78’s picture

Ok there's a nice rules integration for this in my case so I just set the default of the field to off, created a rule to react after saving a new user account and set the action "Subscribe or unsubscribe entity from a MailChimp list". Seems to work well.