PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / 10.10.2
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress v10.10.2
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 / Core / wordpress / message.php

message.php in AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress 10.10.2, at back/Core/wordpress/message.php

77 lines 2.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 use AcyMailing\Helpers\HeaderHelper;
4
5 function acym_enqueueMessage($message, string $type = 'success', bool $addNotification = true, array $addDashboardNotification = [], bool $addHeaderNotification = true): void
6 {
7 $type = str_replace(['notice', 'message'], ['info', 'success'], $type);
8 $message = is_array($message) ? implode('<br/>', $message) : $message;
9
10 $notification = new stdClass();
11 $notification->message = $message;
12 $notification->date = time();
13 $notification->read = false;
14 $notification->level = $type;
15
16 $handledTypes = ['info', 'warning', 'error'];
17
18 if ($addNotification && acym_isAdmin()) {
19 $helperHeader = new HeaderHelper();
20 $notification->id = $helperHeader->addNotification($notification);
21 } else {
22 $handledTypes[] = 'success';
23 }
24
25 if (in_array($type, $handledTypes) && $addHeaderNotification) {
26 acym_session();
27 if (empty($_SESSION['acymessage'.$type]) || !in_array($message, $_SESSION['acymessage'.$type])) {
28 if (empty($notification->id)) {
29 $_SESSION['acymessage'.$type][] = $message;
30 } else {
31 $_SESSION['acymessage'.$type][$notification->id] = $message;
32 }
33 }
34 }
35
36 if (!empty($addDashboardNotification)) {
37 $config = acym_config();
38 $notRemindable = json_decode($config->get('remindme'), true);
39 $existingNotifications = json_decode($config->get('dashboard_notif', '[]'), true);
40
41 foreach ($addDashboardNotification as &$dashboardNotification) {
42 if (in_array($dashboardNotification['name'], $notRemindable)) {
43 continue;
44 }
45 $dashboardNotification['date'] = time();
46 $dashboardNotification['level'] = $type;
47 $dashboardNotification['message'] = $message;
48
49 $found = false;
50 foreach ($existingNotifications as &$existingNotification) {
51 if ($existingNotification['name'] === $dashboardNotification['name']) {
52 $existingNotification = $dashboardNotification;
53 $found = true;
54 break;
55 }
56 }
57 if (!$found) {
58 $existingNotifications[] = $dashboardNotification;
59 }
60 }
61
62 $config->saveConfig(['dashboard_notif' => json_encode($existingNotifications)], false);
63 }
64 }
65
66 function acym_displayMessages(): void
67 {
68 $types = ['success', 'info', 'warning', 'error'];
69 acym_session();
70 foreach ($types as $type) {
71 if (empty($_SESSION['acymessage'.$type])) continue;
72
73 acym_display($_SESSION['acymessage'.$type], $type);
74 unset($_SESSION['acymessage'.$type]);
75 }
76 }
77