You are here

function simplenews_roles_user_update in Simplenews Roles 7

Implements hook_user_update().

Check synchronized lists depending on users roles. @todo If a site contains many newsletters this adds currently too much weight to a user_update.

File

./simplenews_roles.module, line 120
Synchronize user subscriptions based on user roles membership.

Code

function simplenews_roles_user_update(&$edit, $account, $category) {
  $roles = array_keys($account->roles);
  foreach (variable_get('simplenews_roles_tids_rids', array()) as $tid => $rids) {
    if (count(array_intersect($rids, $roles)) > 0) {

      // If the user has one or more roles that matches the current subscription, subscribe.
      simplenews_subscribe_user($account->mail, $tid, FALSE, 'simplenews_roles');
    }
    else {

      // If the user has no role that matches the current subscription, unsubscribe.
      simplenews_unsubscribe_user($account->mail, $tid, FALSE);
    }
  }
}