PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / 11.0.4
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress v11.0.4
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
acymailing / back / dynamics / sendinblue / list.php

list.php in AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress 11.0.4, at back/dynamics/sendinblue/list.php

74 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 class SendinblueList extends SendinblueClass
4 {
5 public function getListExternalSendingMethod(&$listId, $mailId, $createIfNotExists = true)
6 {
7 $brevoLists = $this->config->get('list_sendinblue', '[]');
8 $brevoLists = json_decode($brevoLists, true);
9
10 if (!empty($brevoLists[$mailId])) {
11 $listId = $brevoLists[$mailId];
12
13 return;
14 }
15
16 if (!$createIfNotExists) return;
17
18 $listId = $this->createList('list_for_acym_mail_'.$mailId);
19
20 $brevoLists[$mailId] = $listId;
21 $this->config->saveConfig(['list_sendinblue' => json_encode($brevoLists)]);
22 }
23
24 public function createList($name)
25 {
26 $data = [
27 'name' => $name,
28 'folderId' => intval($this->getFolderId()),
29 ];
30
31 $response = $this->callApiSendingMethod('contacts/lists', $data, $this->headers, 'POST');
32
33 // The folder Id is saved in the config but the user removed it from Sendinblue, recreate a folder
34 if (!empty($response['message']) && $response['message'] === 'Folder ID does not exist') {
35 $this->config->saveConfig(['sendinblue_folder_id' => 0]);
36
37 return $this->createList($name);
38 }
39
40 return $response['id'];
41 }
42
43 public function getFolderId()
44 {
45 $folderId = $this->config->get('sendinblue_folder_id', 0);
46 if (!empty($folderId)) return $folderId;
47
48 $data = [
49 'name' => 'AcyMailing Integration',
50 ];
51
52 $response = $this->callApiSendingMethod('contacts/folders', $data, $this->headers, 'POST');
53
54 // The API key may be wrong
55 if (empty($response['id'])) return 0;
56
57 $this->config->saveConfig(['sendinblue_folder_id' => $response['id']]);
58
59 return $response['id'];
60 }
61
62 public function deleteList($mailId): bool
63 {
64 $listId = 0;
65 $this->getListExternalSendingMethod($listId, $mailId, false);
66
67 if (empty($listId)) return false;
68
69 $this->callApiSendingMethod(plgAcymSendinblue::SENDING_METHOD_API_URL.'contacts/lists/'.$listId, [], $this->headers, 'DELETE');
70
71 return true;
72 }
73 }
74