PluginProbe
MailPoet – Newsletters, Email Marketing, and Automation / 3.89.4
MailPoet – Newsletters, Email Marketing, and Automation v3.89.4
5.38.0 5.37.0 5.36.1 5.36.0 5.35.1 5.35.0 5.34.3 5.34.2 5.34.1 5.34.0 5.33.1 5.33.0 5.32.0 5.31.0 5.30.0 5.29.0 5.28.1 5.28.0 5.27.0 5.26.0 5.26.1 5.25.0 5.24.0 4.43.0 4.43.1 All 542 releases
mailpoet / lib / Subscribers / Source.php

Source.php in MailPoet – Newsletters, Email Marketing, and Automation 3.89.4, at lib/Subscribers/Source.php

44 lines 1.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace MailPoet\Subscribers;
4
5 if (!defined('ABSPATH')) exit;
6
7
8 use MailPoet\Models\Subscriber;
9
10 class Source {
11
12 const FORM = 'form';
13 const IMPORTED = 'imported';
14 const ADMINISTRATOR = 'administrator';
15 const API = 'api';
16 const WORDPRESS_USER = 'wordpress_user';
17 const WOOCOMMERCE_USER = 'woocommerce_user';
18 const WOOCOMMERCE_CHECKOUT = 'woocommerce_checkout';
19 const UNKNOWN = 'unknown';
20
21 private static $allowedSources = [
22 Source::FORM,
23 Source::IMPORTED,
24 Source::ADMINISTRATOR,
25 Source::API,
26 Source::WORDPRESS_USER,
27 Source::WOOCOMMERCE_USER,
28 Source::WOOCOMMERCE_CHECKOUT,
29 Source::UNKNOWN,
30 ];
31
32 public static function setSource(Subscriber $subscriber, $source) {
33 if ((isset($subscriber->source)) && ($subscriber->source !== Source::UNKNOWN)) {
34 // we don't want to override source
35 return $subscriber;
36 }
37 if (!in_array($source, Source::$allowedSources)) {
38 throw new \InvalidArgumentException('Invalid source "' . $source . '""');
39 }
40 $subscriber->set('source', $source);
41 return $subscriber;
42 }
43 }
44