You are here

function simplenews_roles_user in Simplenews Roles 6.2

Same name and namespace in other branches
  1. 6 simplenews_roles.module \simplenews_roles_user()

Implementation of hook_user().

File

./simplenews_roles.module, line 250
Simplenews Roles module

Code

function simplenews_roles_user($op, &$edit, &$account, $category = NULL) {
  switch ($op) {
    case 'after_update':
    case 'insert':
      $newroles = array();

      // this array is not always set for all operations, hence the check
      if (is_array($edit['roles'])) {
        $newroles = array_keys($edit['roles']);
      }
      $oldroles = isset($account->roles) ? array_keys($account->roles) : array();
      $roles = array_unique(array_merge($newroles, $oldroles, array(
        DRUPAL_AUTHENTICATED_RID,
      )));
      foreach (variable_get('simplenews_roles_tids_rids', array()) as $tid => $rids) {
        if (count(array_intersect($rids, $roles)) > 0) {

          // if there are "new" roles for the user for this newsletter, then sync the user

          //simplenews_roles_update_subscriptions($tid, $rids);

          // TODO: sync func for one user.
          // Request a sync.
          variable_set('simplenews_roles_need_sync', TRUE);
        }
        else {

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