You are here

public function SubscriptionManager::isSubscribed in Simplenews 8

Same name and namespace in other branches
  1. 8.2 src/Subscription/SubscriptionManager.php \Drupal\simplenews\Subscription\SubscriptionManager::isSubscribed()
  2. 3.x src/Subscription/SubscriptionManager.php \Drupal\simplenews\Subscription\SubscriptionManager::isSubscribed()

Check if the email address is subscribed to the given mailing list.

@todo Caching should be done in simplenews_load_user_by_mail().

Parameters

string $mail: The email address to be checked.

string $newsletter_id: The mailing list id.

Return value

bool TRUE if the email address is subscribed; otherwise false.

Overrides SubscriptionManagerInterface::isSubscribed

File

src/Subscription/SubscriptionManager.php, line 204

Class

SubscriptionManager
Default subscription manager.

Namespace

Drupal\simplenews\Subscription

Code

public function isSubscribed($mail, $newsletter_id) {
  if (!isset($this->subscribedCache[$mail][$newsletter_id])) {
    $subscriber = simplenews_subscriber_load_by_mail($mail);

    // Check that a subscriber was found, he is active and subscribed to the
    // requested newsletter_id.
    $this->subscribedCache[$mail][$newsletter_id] = $subscriber && $subscriber
      ->getStatus() && $subscriber
      ->isSubscribed($newsletter_id);
  }
  return $this->subscribedCache[$mail][$newsletter_id];
}