PluginProbe
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment / 3.1.13
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment v3.1.13
3.1.13 3.1.12 3.1.11 3.1.10 3.1.9 3.1.8 3.1.7 trunk 1.0.0 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 All 122 releases
firebox / Inc / Core / UsageTracking / SendUsage.php

SendUsage.php in FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment 3.1.13, at Inc/Core/UsageTracking/SendUsage.php

135 lines 3.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @package FireBox
4 * @version 3.1.13 Free
5 *
6 * @author FirePlugins <info@fireplugins.com>
7 * @link https://www.fireplugins.com
8 * @copyright Copyright © 2026 FirePlugins All Rights Reserved
9 * @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
10 */
11
12 namespace FireBox\Core\UsageTracking;
13
14 if (!defined('ABSPATH'))
15 {
16 exit; // Exit if accessed directly.
17 }
18
19 class SendUsage
20 {
21 /**
22 * The hook name to send the tracking data.
23 *
24 * @var string
25 */
26 private $tracking_hook = 'firebox_usage_tracking';
27
28 /**
29 * API URL to send the tracking data.
30 *
31 * @var string
32 */
33 const API_URL = 'https://usage.fireboxwp.com/wp-json/usage-tracking/v1/track';
34
35 public function __construct()
36 {
37 // Add the tracking action
38 add_action($this->tracking_hook, [$this, 'track']);
39 }
40
41 public function maybeStart()
42 {
43 // Start only if usage tracking is enabled in settings
44 $settings = get_option('firebox_settings');
45
46 if (!isset($settings['usage_tracking']))
47 {
48 return;
49 }
50
51 if (!$settings['usage_tracking'])
52 {
53 return;
54 }
55
56 /**
57 * A network is one install, so it reports once. Without this every site
58 * that opts in sends its own weekly payload for the same install.
59 */
60 if (is_multisite() && !$this->isTrackingSite())
61 {
62 return;
63 }
64
65 if (wp_next_scheduled($this->tracking_hook))
66 {
67 return;
68 }
69
70 // Schedule event to run weekly from now
71 wp_schedule_event(time(), 'weekly', $this->tracking_hook);
72 }
73
74 /**
75 * Whether this site is the one that reports for the network.
76 *
77 * The first site to opt in claims it, so a network whose main site never
78 * enables tracking still reports. The claim is released by stop().
79 *
80 * @return bool
81 */
82 private function isTrackingSite()
83 {
84 $claimed = (int) get_site_option('firebox_usage_tracking_site', 0);
85
86 if ($claimed && get_site($claimed))
87 {
88 return $claimed === get_current_blog_id();
89 }
90
91 update_site_option('firebox_usage_tracking_site', get_current_blog_id());
92
93 return true;
94 }
95
96 public function track()
97 {
98 // Abort if site URL contains "fireplugins.test", "fireplugins.com", or "fireboxwp.com"
99 $site_url = home_url();
100 if (strpos($site_url, 'fireplugins.test') !== false || strpos($site_url, 'fireplugins.com') !== false || strpos($site_url, 'fireboxwp.com') !== false)
101 {
102 return;
103 }
104
105 $tracking = new UsageTracking();
106
107 wp_remote_post(self::API_URL, [
108 'sslverify' => false,
109 'timeout' => 5,
110 'redirection' => 5,
111 'httpversion' => '1.1',
112 'blocking' => true,
113 'body' => $tracking->getData(),
114 'headers' => [
115 'User-Agent' => $tracking->get_user_agent(),
116 ],
117 ]);
118 }
119
120 public function stop()
121 {
122 $timestamp = wp_next_scheduled($this->tracking_hook);
123
124 if ($timestamp)
125 {
126 wp_unschedule_event($timestamp, $this->tracking_hook);
127 }
128
129 // Release the network claim so another site can report.
130 if (is_multisite() && (int) get_site_option('firebox_usage_tracking_site', 0) === get_current_blog_id())
131 {
132 delete_site_option('firebox_usage_tracking_site');
133 }
134 }
135 }