| 1 |
<?php |
| 2 |
/** |
| 3 |
* @package FireBox |
| 4 |
* @version 3.1.8 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 |
if (wp_next_scheduled($this->tracking_hook)) |
| 57 |
{ |
| 58 |
return; |
| 59 |
} |
| 60 |
|
| 61 |
// Schedule event to run weekly from now |
| 62 |
wp_schedule_event(time(), 'weekly', $this->tracking_hook); |
| 63 |
} |
| 64 |
|
| 65 |
public function track() |
| 66 |
{ |
| 67 |
// Abort if site URL contains "fireplugins.test", "fireplugins.com", or "fireboxwp.com" |
| 68 |
$site_url = home_url(); |
| 69 |
if (strpos($site_url, 'fireplugins.test') !== false || strpos($site_url, 'fireplugins.com') !== false || strpos($site_url, 'fireboxwp.com') !== false) |
| 70 |
{ |
| 71 |
return; |
| 72 |
} |
| 73 |
|
| 74 |
$tracking = new UsageTracking(); |
| 75 |
|
| 76 |
wp_remote_post(self::API_URL, [ |
| 77 |
'sslverify' => false, |
| 78 |
'timeout' => 5, |
| 79 |
'redirection' => 5, |
| 80 |
'httpversion' => '1.1', |
| 81 |
'blocking' => true, |
| 82 |
'body' => $tracking->getData(), |
| 83 |
'headers' => [ |
| 84 |
'User-Agent' => $tracking->get_user_agent(), |
| 85 |
], |
| 86 |
]); |
| 87 |
} |
| 88 |
|
| 89 |
public function stop() |
| 90 |
{ |
| 91 |
$timestamp = wp_next_scheduled($this->tracking_hook); |
| 92 |
|
| 93 |
if ($timestamp) |
| 94 |
{ |
| 95 |
wp_unschedule_event($timestamp, $this->tracking_hook); |
| 96 |
} |
| 97 |
} |
| 98 |
} |