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/Core/wordpress/message.php +50 -12 10.1.4 → 11.1.0 View file →
@@ -1,9 +1,15 @@
1 1 <?php
2 2
3 +defined('ABSPATH') || die('Restricted Access');
4 +
3 5 use AcyMailing\Helpers\HeaderHelper;
4 6
5 -function acym_enqueueMessage($message, $type = 'success', $addNotification = true)
7 +/**
8 + * @param array|string $message The message to display
9 + * @param string $type The type (success, error, warning, info, message, notice)
10 + */
11 +function acym_enqueueMessage($message, string $type = 'success', bool $addNotification = true, array $addDashboardNotification = [], bool $addHeaderNotification = true): void
6 12 {
7 13 $type = str_replace(['notice', 'message'], ['info', 'success'], $type);
8 14 $message = is_array($message) ? implode('<br/>', $message) : $message;
9 15
@@ -21,29 +27,61 @@
21 27 } else {
22 28 $handledTypes[] = 'success';
23 29 }
24 30
25 - if (in_array($type, $handledTypes)) {
26 - acym_session();
27 - if (empty($_SESSION['acymessage'.$type]) || !in_array($message, $_SESSION['acymessage'.$type])) {
31 + if (in_array($type, $handledTypes) && $addHeaderNotification) {
32 + $messages = acym_getVar('array', 'acymessage'.$type, [], 'SESSION', ACYM_ALLOWHTML);
33 +
34 + if (empty($messages) || !in_array($message, $messages)) {
28 35 if (empty($notification->id)) {
29 - $_SESSION['acymessage'.$type][] = $message;
36 + $messages[] = $message;
30 37 } else {
31 - $_SESSION['acymessage'.$type][$notification->id] = $message;
38 + $messages[$notification->id] = $message;
32 39 }
33 40 }
41 +
42 + acym_setSession('acymessage'.$type, $messages);
34 43 }
35 44
36 - return true;
45 + if (!empty($addDashboardNotification)) {
46 + $config = acym_config();
47 + $notRemindable = json_decode($config->get('remindme'), true);
48 + $existingNotifications = json_decode($config->get('dashboard_notif', '[]'), true);
49 +
50 + foreach ($addDashboardNotification as &$dashboardNotification) {
51 + if (in_array($dashboardNotification['name'], $notRemindable)) {
52 + continue;
53 + }
54 + $dashboardNotification['date'] = time();
55 + $dashboardNotification['level'] = $type;
56 + $dashboardNotification['message'] = $message;
57 +
58 + $found = false;
59 + foreach ($existingNotifications as &$existingNotification) {
60 + if ($existingNotification['name'] === $dashboardNotification['name']) {
61 + $existingNotification = $dashboardNotification;
62 + $found = true;
63 + break;
64 + }
65 + }
66 + if (!$found) {
67 + $existingNotifications[] = $dashboardNotification;
68 + }
69 + }
70 +
71 + $config->saveConfig(['dashboard_notif' => json_encode($existingNotifications)], false);
72 + }
37 73 }
38 74
39 -function acym_displayMessages()
75 +function acym_displayMessages(): void
40 76 {
41 77 $types = ['success', 'info', 'warning', 'error'];
42 - acym_session();
43 78 foreach ($types as $type) {
44 - if (empty($_SESSION['acymessage'.$type])) continue;
79 + $messages = acym_getVar('array', 'acymessage'.$type, [], 'SESSION', ACYM_ALLOWHTML);
80 + if (empty($messages)) {
81 + continue;
82 + }
45 83
46 - acym_display($_SESSION['acymessage'.$type], $type);
47 - unset($_SESSION['acymessage'.$type]);
84 + acym_display($messages, $type);
85 + acym_setSession('acymessage'.$type, null, true);
48 86 }
49 87 }