PluginProbe
ووسلام – همگام سازی ووکامرس و باسلام / 1.10.18
ووسلام – همگام سازی ووکامرس و باسلام v1.10.18
1.10.18 1.10.17 1.10.15 1.10.14 1.10.13 1.10.12 1.10.10 1.10.9 1.10.8 1.10.7 1.10.6 1.10.5 1.10.4 1.10.3 1.10.2 1.10.1 1.10.0 1.9.2 1.9.1 1.9.0 1.8.8 1.8.5 1.8.6 1.8.7 1.8.4 All 51 releases
sync-basalam / includes / Utilities / TicketFlashNotice.php

TicketFlashNotice.php in ووسلام – همگام سازی ووکامرس و باسلام 1.10.18, at includes/Utilities/TicketFlashNotice.php

53 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace SyncBasalam\Utilities;
4
5 defined('ABSPATH') || exit;
6
7 /**
8 * Carries one ticket-flow message across an admin redirect.
9 */
10 class TicketFlashNotice
11 {
12 private const TRANSIENT_PREFIX = 'sync_basalam_ticket_flash_';
13 private const ALLOWED_TYPES = ['success', 'error', 'warning', 'info'];
14
15 public static function push(string $message, string $type = 'error'): void
16 {
17 $userId = get_current_user_id();
18 if ($userId <= 0) return;
19
20 $type = in_array($type, self::ALLOWED_TYPES, true) ? $type : 'info';
21 set_transient(
22 self::TRANSIENT_PREFIX . $userId,
23 [
24 'message' => wp_strip_all_tags($message),
25 'type' => $type,
26 ],
27 2 * MINUTE_IN_SECONDS
28 );
29 }
30
31 public static function pull(): ?array
32 {
33 $userId = get_current_user_id();
34 if ($userId <= 0) return null;
35
36 $key = self::TRANSIENT_PREFIX . $userId;
37 $notice = get_transient($key);
38 if ($notice === false) return null;
39
40 delete_transient($key);
41 if (!is_array($notice) || empty($notice['message'])) return null;
42
43 $type = isset($notice['type']) && in_array($notice['type'], self::ALLOWED_TYPES, true)
44 ? $notice['type']
45 : 'info';
46
47 return [
48 'message' => (string) $notice['message'],
49 'type' => $type,
50 ];
51 }
52 }
53