PluginProbe ʕ •ᴥ•ʔ
Hostinger Reach – AI-Powered Email Marketing for WordPress / 1.7.2
Hostinger Reach – AI-Powered Email Marketing for WordPress v1.7.2
1.7.2 1.7.1 1.7.0 1.6.0 1.5.9 1.5.8 1.5.7 1.5.6 1.5.5 1.5.4 1.5.3 1.5.2 1.5.1 1.5.0 1.4.12 1.4.11 1.4.10 1.4.9 1.4.8 1.4.7 trunk 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6
hostinger-reach / vendor / hostinger / hostinger-wp-amplitude / src / ActionDispatcher.php
hostinger-reach / vendor / hostinger / hostinger-wp-amplitude / src Last commit date
ActionDispatcher.php 1 month ago AmplitudeLoader.php 1 month ago AmplitudeManager.php 1 month ago Rest.php 1 month ago
ActionDispatcher.php
78 lines
1 <?php
2
3 namespace Hostinger\Amplitude;
4
5 use Hostinger\Amplitude\AmplitudeManager;
6 use Hostinger\WpHelper\Config;
7 use Hostinger\WpHelper\Requests\Client;
8 use Hostinger\WpHelper\Utils as Helper;
9
10 class ActionDispatcher
11 {
12 private const TRANSIENT_KEY = 'hostinger_login_data';
13 private const EXPIRATION_TIME_SECONDS = 10800; // 3 hours
14 private const AMPLITUDE_LOGIN_ACTION = 'wordpress.autologin.success';
15
16 private Config $configHandler;
17 private Client $client;
18 private Helper $helper;
19
20 public function __construct(
21 Helper $helper,
22 Config $configHandler,
23 Client $client
24 ) {
25 $this->helper = $helper;
26 $this->configHandler = $configHandler;
27 $this->client = $client;
28
29 add_action('hostinger_autologin_user_logged_in', [ $this, 'userAlreadyLoggedIn' ]);
30 add_action('hostinger_autologin', [ $this, 'handleAutoLogin' ]);
31 add_action('wp_logout', [ $this, 'clearLoginData' ]);
32 }
33
34 public function handleAutoLogin(array $data): void
35 {
36 $this->processLoginData($data);
37 $this->loginEvent($this->helper, $this->configHandler, $this->client, 'new_login');
38 }
39
40 public function userAlreadyLoggedIn(array $data): void
41 {
42 $this->processLoginData($data);
43 $this->loginEvent($this->helper, $this->configHandler, $this->client, 'logged_in');
44 }
45
46
47 public function processLoginData(array $data): void
48 {
49 $sanitized_data = $this->sanitizeLoginData($data);
50 set_transient(self::TRANSIENT_KEY, $sanitized_data, self::EXPIRATION_TIME_SECONDS);
51 }
52
53 public function loginEvent(Helper $helper, Config $config, Client $client, string $status): void
54 {
55 $amplitudeManager = new AmplitudeManager($helper, $config, $client);
56 $params = [
57 'action' => self::AMPLITUDE_LOGIN_ACTION,
58 'status' => $status,
59 ];
60
61 $amplitudeManager->sendRequest($amplitudeManager::AMPLITUDE_ENDPOINT, $params);
62 }
63
64 private function sanitizeLoginData(array $data): array
65 {
66 if (! is_array($data)) {
67 return [];
68 }
69
70 return array_map('sanitize_text_field', $data);
71 }
72
73 public function clearLoginData(): void
74 {
75 delete_transient(self::TRANSIENT_KEY);
76 }
77 }
78