You are here

function simplenews_subscribe_user_action in Simplenews 6.2

Same name and namespace in other branches
  1. 6 simplenews_action/simplenews_action.module \simplenews_subscribe_user_action()

A configurable Drupal action. Subscribe the user to a newsletter hook = user: Subscribe this user to selected newsletter

Available context: $context['tid'] newsletter tid $context['name'] newsletter name

See also

simplenews_subscribe_user_action_form()

simplenews_subscribe_user_action_submit()

File

simplenews_action/simplenews_action.module, line 208
Provide actions for simplenews.

Code

function simplenews_subscribe_user_action(&$object, $context = array()) {
  if ($context['hook'] == 'user') {
    if (isset($context['tid'])) {

      // This action is only called in the context of user. User data is in $context.
      $account = $context['account'];
      simplenews_subscribe_user($account->mail, $context['tid'], FALSE, 'action');
      drupal_set_message(t('You have been subscribed to newsletter %newsletter.', array(
        '%newsletter' => $context['name'],
      )));
      watchdog('action', 'User %name subscribed to newsletter %newsletter.', array(
        '%name' => $account->name,
        '%newsletter' => $context['name'],
      ));
    }
  }
}