PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / 11.1.0
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress v11.1.0
11.1.1 11.1.0 11.0.5 11.0.4 11.0.3 11.0.2 11.0.1 11.0.0 10.11.1 10.11.0 10.10.2 10.10.1 10.10.0 10.9.1 trunk 10.0.0 10.0.1 10.1.0 10.1.1 10.1.2 10.1.3 10.1.4 10.2.0 10.2.1 10.2.2 All 62 releases
← All changes | back/dynamics/subscription/SubscriptionAutomationTriggers.php +72 -0 10.1.2 → 11.1.0 View file →
@@ -1,0 +1,72 @@
1 +<?php
2 +
3 +use AcyMailing\Classes\FollowupClass;
4 +use AcyMailing\Classes\AutomationClass;
5 +use AcyMailing\Helpers\ScenarioHelper;
6 +
7 +trait SubscriptionAutomationTriggers
8 +{
9 + private $subscribeTrigger = 'user_subscribe';
10 + private $unsubscribeTrigger = 'user_unsubscribe';
11 +
12 + private $triggers = [
13 + 'user_subscribe' => 'ACYM_WHEN_USER_SUBSCRIBES',
14 + 'user_unsubscribe' => 'ACYM_WHEN_USER_UNSUBSCRIBES',
15 + ];
16 +
17 + protected function initAutomationTriggers(): void
18 + {
19 + foreach ($this->triggers as $key => $name) {
20 + $this->automationTriggers['user'][$key] = acym_translation($name);
21 + }
22 + }
23 +
24 + public function displayTriggerOptions(string $fieldName): void
25 + {
26 + echo '<input type="hidden" name="'.esc_attr($fieldName.'[]').'" value="">';
27 + }
28 +
29 + public function onAcymExecuteTrigger(&$step, &$execute, &$data)
30 + {
31 + if (empty($data['userId'])) return;
32 +
33 + foreach ($this->triggers as $identifier => $name) {
34 + if (empty($step->triggers[$identifier])) continue;
35 +
36 + $execute = true;
37 + break;
38 + }
39 + }
40 +
41 + public function onAcymDeclareSummary_triggers(object $automation): void
42 + {
43 + if (!empty($automation->triggers[$this->subscribeTrigger])) {
44 + $automation->triggers[$this->subscribeTrigger] = acym_translation('ACYM_WHEN_USER_SUBSCRIBES');
45 + }
46 +
47 + if (!empty($automation->triggers[$this->unsubscribeTrigger])) {
48 + $automation->triggers[$this->unsubscribeTrigger] = acym_translation('ACYM_WHEN_USER_UNSUBSCRIBES');
49 + }
50 + }
51 +
52 + public function onAcymAfterUserSubscribe(&$user, $lists)
53 + {
54 + $automationClass = new AutomationClass();
55 + $automationClass->trigger($this->subscribeTrigger, ['userId' => $user->id]);
56 +
57 + $scenarioHelper = new ScenarioHelper();
58 + $scenarioHelper->trigger($this->subscribeTrigger, ['userId' => $user->id]);
59 +
60 + $followupClass = new FollowupClass();
61 + $followupClass->addFollowupEmailsQueue($this->subscribeTrigger, $user->id, ['sub_lists' => $lists]);
62 + }
63 +
64 + public function onAcymAfterUserUnsubscribe(&$user, $lists)
65 + {
66 + $automationClass = new AutomationClass();
67 + $automationClass->trigger($this->unsubscribeTrigger, ['userId' => $user->id]);
68 +
69 + $scenarioHelper = new ScenarioHelper();
70 + $scenarioHelper->trigger($this->unsubscribeTrigger, ['userId' => $user->id]);
71 + }
72 +}