You are here

function simplenews_user_presave in Simplenews 7.2

Same name and namespace in other branches
  1. 8.2 simplenews.module \simplenews_user_presave()
  2. 8 simplenews.module \simplenews_user_presave()
  3. 7 simplenews.module \simplenews_user_presave()
  4. 3.x simplenews.module \simplenews_user_presave()

Implements hook_user_presave().

User data (mail, status, language) is synchronized with subscriber. This function handles existing user account, simplenews_user_insert takes care of new accounts.

See also

simplenews_user_insert()

File

./simplenews.module, line 1121
Simplenews node handling, sent email, newsletter block and general hooks

Code

function simplenews_user_presave(&$edit, $account, $newsletter) {
  switch ($newsletter) {
    case 'account':

      // We only process existing accounts.
      if (!empty($account->uid)) {
        $subscriber = simplenews_subscriber_load_by_uid($account->uid);
        if ($subscriber) {

          // Update mail, status and language if they are changed.
          if (isset($edit['mail'])) {
            $subscriber->mail = $edit['mail'];
          }
          if (isset($edit['status']) && variable_get('simplenews_sync_account', TRUE)) {
            $subscriber->activated = $edit['status'];
          }
          if (isset($edit['language'])) {
            $subscriber->language = $edit['language'];
          }
          simplenews_subscriber_save($subscriber);
        }
      }
      break;
  }
}