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/Controllers/Users/Subscription.php +37 -20 10.0.1 → 11.1.0 View file →
@@ -1,15 +1,16 @@
1 1 <?php
2 2
3 3 namespace AcyMailing\Controllers\Users;
4 4
5 -use AcyMailing\Classes\ListClass;
6 5 use AcyMailing\Classes\UserClass;
7 6
8 7 trait Subscription
9 8 {
10 - public function resetSubscription()
9 + public function resetSubscription(): void
11 10 {
11 + wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token');
12 +
12 13 $userId = acym_getVar('int', 'userId');
13 14
14 15 if (empty($userId)) {
15 16 $this->listing();
@@ -21,16 +22,21 @@
21 22 if (!$userClass->hasUserAccess($userId)) {
22 23 die('Access denied for subscription reset of this user');
23 24 }
24 25
25 - $list = acym_getVar('int', 'acym__entity_select__selected');
26 - $userClass->resetSubscription($userId, [$list]);
26 + $lists = json_decode(acym_getVar('string', 'acym__entity_select__selected', '[]'), true);
27 + if (empty($lists)) {
28 + $lists = [];
29 + }
30 + $userClass->resetSubscription([$userId], $lists);
27 31
28 32 $this->edit();
29 33 }
30 34
31 - public function unsubscribeUser()
35 + public function unsubscribeUser(): void
32 36 {
37 + wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token');
38 +
33 39 $userId = acym_getVar('int', 'userId');
34 40 if (empty($userId)) {
35 41 $this->listing();
36 42
@@ -41,20 +47,21 @@
41 47 if (!$userClass->hasUserAccess($userId)) {
42 48 die('Access denied for unsubscribing this user');
43 49 }
44 50
45 - $lists = json_decode(acym_getVar('string', 'acym__entity_select__selected', '{}'));
46 - if (!is_array($lists)) {
47 - $lists = (array)$lists;
51 + $lists = json_decode(acym_getVar('string', 'acym__entity_select__selected', '[]'), true);
52 + if (empty($lists)) {
53 + $lists = [];
48 54 }
55 + $userClass->unsubscribe([$userId], $lists);
49 56
50 - $userClass->unsubscribe($userId, $lists);
51 -
52 57 $this->edit();
53 58 }
54 59
55 - public function unsubscribeUserFromAll()
60 + public function unsubscribeUserFromAll(): void
56 61 {
62 + wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token');
63 +
57 64 $userId = acym_getVar('int', 'userId');
58 65
59 66 if (empty($userId)) {
60 67 $this->listing();
@@ -74,15 +81,17 @@
74 81 $lists[] = $oneList->list_id;
75 82 }
76 83 }
77 84
78 - $userClass->unsubscribe($userId, $lists);
85 + $userClass->unsubscribe([$userId], $lists);
79 86
80 87 $this->edit();
81 88 }
82 89
83 - public function resubscribeUserToAll()
90 + public function resubscribeUserToAll(): void
84 91 {
92 + wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token');
93 +
85 94 $userId = acym_getVar('int', 'userId');
86 95 if (empty($userId)) {
87 96 $this->listing();
88 97
@@ -101,18 +110,21 @@
101 110 $lists[] = $oneList->list_id;
102 111 }
103 112 }
104 113
105 - $userClass->subscribe($userId, $lists);
114 + $userClass->subscribe([$userId], $lists);
106 115
107 116 $this->edit();
108 117 }
109 118
110 - public function subscribeUser($returnOnEdit = true, $frontCreation = false)
119 + public function subscribeUser(bool $returnOnEdit = true, array $lists = [], bool $frontCreation = false): void
111 120 {
121 + // Called as a task (no argument) → require a CSRF token. Internal calls from apply() are already token-checked.
122 + if (func_num_args() === 0) {
123 + wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token');
124 + }
125 +
112 126 $userId = acym_getVar('int', 'userId');
113 - $lists = json_decode(acym_getVar('string', 'acym__entity_select__selected', '{}'));
114 -
115 127 if (empty($userId)) {
116 128 $this->listing();
117 129
118 130 return;
@@ -122,12 +134,17 @@
122 134 if (!$frontCreation && !$userClass->hasUserAccess($userId)) {
123 135 die('Access denied for subscribing this user');
124 136 }
125 137
126 - if (!is_array($lists)) {
127 - $lists = (array)$lists;
138 + // Can be called from the user's edition page when re-subscribing to a list
139 + if (empty($lists)) {
140 + $lists = json_decode(acym_getVar('string', 'acym__entity_select__selected', '[]'), true);
141 + if (empty($lists)) {
142 + $lists = [];
143 + }
128 144 }
129 - $userClass->subscribe($userId, $lists);
145 +
146 + $userClass->subscribe([$userId], $lists);
130 147
131 148 if ($returnOnEdit) {
132 149 $this->edit();
133 150 }