PluginProbe
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment / 3.1.14
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment v3.1.14
3.1.14 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 All 123 releases
← All changes | Inc/Core/Analytics/Ajax/Main.php +118 -33 3.1.7 → 3.1.14 View file →
@@ -1,8 +1,8 @@
1 1 <?php
2 2 /**
3 3 * @package FireBox
4 - * @version 3.1.7 Free
4 + * @version 3.1.14 Free
5 5 *
6 6 * @author FirePlugins <[email protected]>
7 7 * @link https://www.fireplugins.com
8 8 * @copyright Copyright © 2026 FirePlugins All Rights Reserved
@@ -22,27 +22,20 @@
22 22
23 23 public function __construct()
24 24 {
25 25 add_action('wp_ajax_firebox_analytics_stats', [$this, 'firebox_analytics_stats']);
26 - add_action('wp_ajax_nopriv_firebox_analytics_stats', [$this, 'firebox_analytics_stats']);
27 26
28 27 add_action('wp_ajax_firebox_analytics_get_campaigns', [$this, 'firebox_analytics_get_campaigns']);
29 - add_action('wp_ajax_nopriv_firebox_analytics_get_campaigns', [$this, 'firebox_analytics_get_campaigns']);
30 28
31 29 add_action('wp_ajax_firebox_analytics_get_dropdown_campaigns', [$this, 'firebox_analytics_get_dropdown_campaigns']);
32 - add_action('wp_ajax_nopriv_firebox_analytics_get_dropdown_campaigns', [$this, 'firebox_analytics_get_dropdown_campaigns']);
33 30
34 31 add_action('wp_ajax_firebox_delete_campaign', [$this, 'firebox_delete_campaign']);
35 - add_action('wp_ajax_nopriv_firebox_delete_campaign', [$this, 'firebox_delete_campaign']);
36 32
37 33 add_action('wp_ajax_firebox_duplicate_campaign', [$this, 'firebox_duplicate_campaign']);
38 - add_action('wp_ajax_nopriv_firebox_duplicate_campaign', [$this, 'firebox_duplicate_campaign']);
39 34
40 35 add_action('wp_ajax_firebox_analytics_get_charts_data', [$this, 'firebox_analytics_get_charts_data']);
41 - add_action('wp_ajax_nopriv_firebox_analytics_get_charts_data', [$this, 'firebox_analytics_get_charts_data']);
42 36
43 37 add_action('wp_ajax_firebox_analytics_get_trending_templates', [$this, 'firebox_analytics_get_trending_templates']);
44 - add_action('wp_ajax_nopriv_firebox_analytics_get_trending_templates', [$this, 'firebox_analytics_get_trending_templates']);
45 38 }
46 39
47 40 /**
48 41 * Analytics Counts
@@ -73,10 +66,8 @@
73 66 return;
74 67 }
75 68
76 69 $selected_campaign = isset($_POST['selected_campaign']) && !empty($_POST['selected_campaign']) ? intval(wp_unslash($_POST['selected_campaign'])) : '';
77 -
78 - $data = new \FireBox\Core\Analytics\Data($start_date, $end_date);
79 70
80 71 $metrics = [
81 72 'views',
82 73 'clicks',
@@ -92,15 +83,37 @@
92 83 'value' => [$selected_campaign]
93 84 ];
94 85 }
95 86
87 + $cache_key = 'firebox_analytics_' . md5(serialize([
88 + 'stats',
89 + $metrics,
90 + $filters,
91 + $start_date,
92 + $end_date
93 + ]));
94 +
95 + $cache_ttl = $this->getAnalyticsCacheTtl($end_date);
96 +
97 + if ($cache_ttl)
98 + {
99 + $cached = get_transient($cache_key);
100 + if ($cached !== false)
101 + {
102 + echo wp_json_encode($cached);
103 + wp_die();
104 + }
105 + }
106 +
107 + $data = new \FireBox\Core\Analytics\Data($start_date, $end_date);
108 +
96 109 // Use new fluent interface
97 110 $data->metrics($metrics)->filters($filters);
98 111
99 112 // Get current period data
100 113 $currentData = $data->getData('count');
114 +
101 115
102 -
103 116
104 117 // Calculate previous period data
105 118 $start_date_ts = strtotime($start_date);
106 119 $end_date_ts = strtotime($end_date);
@@ -114,40 +127,39 @@
114 127 'revenue' => 0,
115 128 'view_through_revenue' => 0,
116 129 'conversion_through_revenue' => 0
117 130 ];
118 -
131 +
119 132 if ($previousPeriodDates = $this->getPreviousPeriodDates($start_date, $days_between))
120 133 {
121 134 $previousData = new \FireBox\Core\Analytics\Data($previousPeriodDates[0], $previousPeriodDates[1]);
122 -
123 - $metrics = [
135 +
136 + $previousMetrics = [
124 137 'views',
125 138 'conversions',
126 139 'conversionrate',
127 140
128 141 ];
129 -
130 - $filters = [];
131 - if ($selected_campaign)
132 - {
133 - $filters['campaign'] = [
134 - 'value' => [$selected_campaign]
135 - ];
136 - }
137 -
142 +
138 143 // Use new fluent interface
139 - $previousData->metrics($metrics)->filters($filters);
144 + $previousData->metrics($previousMetrics)->filters($filters);
140 145
141 146 $previousPeriodData = $previousData->getData('count');
147 +
142 148
143 -
144 149 }
145 150
146 - echo wp_json_encode([
151 + $response = [
147 152 'current' => $currentData,
148 153 'previous' => $previousPeriodData
149 - ]);
154 + ];
155 +
156 + if ($cache_ttl)
157 + {
158 + set_transient($cache_key, $response, $cache_ttl);
159 + }
160 +
161 + echo wp_json_encode($response);
150 162 wp_die();
151 163 }
152 164
153 165 /**
@@ -306,10 +318,8 @@
306 318 }
307 319 }
308 320
309 321 $selected_campaign = isset($_POST['selected_campaign']) && !empty($_POST['selected_campaign']) ? intval(wp_unslash($_POST['selected_campaign'])) : '';
310 -
311 - $data = new \FireBox\Core\Analytics\Data($start_date, $end_date);
312 322
313 323 $metrics = [
314 324 'views',
315 325 'clicks',
@@ -327,8 +337,31 @@
327 337 ]
328 338 ];
329 339 }
330 340
341 + $cache_key = 'firebox_analytics_' . md5(serialize([
342 + 'charts',
343 + $metrics,
344 + $filters,
345 + $filter,
346 + $start_date,
347 + $end_date
348 + ]));
349 +
350 + $cache_ttl = $this->getAnalyticsCacheTtl($end_date);
351 +
352 + if ($cache_ttl)
353 + {
354 + $cached = get_transient($cache_key);
355 + if ($cached !== false)
356 + {
357 + echo wp_json_encode($cached);
358 + wp_die();
359 + }
360 + }
361 +
362 + $data = new \FireBox\Core\Analytics\Data($start_date, $end_date);
363 +
331 364 // Use new fluent interface
332 365 $data->metrics($metrics)->filters($filters);
333 366
334 367 $chartData = $data->getData($filter);
@@ -336,13 +369,20 @@
336 369 $revenueBreakdownByLabel = [];
337 370
338 371
339 372
340 - echo wp_json_encode([
373 + $response = [
341 374 'labels' => $labels,
342 375 'data' => $chartData,
343 376 'revenue_breakdown' => $revenueBreakdownByLabel
344 - ]);
377 + ];
378 +
379 + if ($cache_ttl)
380 + {
381 + set_transient($cache_key, $response, $cache_ttl);
382 + }
383 +
384 + echo wp_json_encode($response);
345 385 wp_die();
346 386 }
347 387
348 388 /**
@@ -429,8 +469,21 @@
429 469 {
430 470 return;
431 471 }
432 472
473 + /**
474 + * "delete_fireboxes" is a global capability, so on its own it would authorise
475 + * deleting any post in the site. Confirm the target really is a campaign and
476 + * that this user may delete this specific one.
477 + */
478 + if (!self::userCanActOnCampaign($id, 'delete_post'))
479 + {
480 + echo wp_json_encode([
481 + 'error' => true
482 + ]);
483 + wp_die();
484 + }
485 +
433 486 $error = false;
434 487
435 488 if (!wp_delete_post($id, true))
436 489 {
@@ -468,8 +521,20 @@
468 521 {
469 522 return;
470 523 }
471 524
525 + /**
526 + * Same reasoning as firebox_delete_campaign(): without this a global capability
527 + * would allow duplicating — and therefore reading — any post in the site.
528 + */
529 + if (!self::userCanActOnCampaign($id, 'edit_post'))
530 + {
531 + echo wp_json_encode([
532 + 'error' => true
533 + ]);
534 + wp_die();
535 + }
536 +
472 537 $error = false;
473 538
474 539 if (!\FireBox\Core\Helpers\BoxHelper::duplicateBox($id))
475 540 {
@@ -474,9 +539,9 @@
474 539 if (!\FireBox\Core\Helpers\BoxHelper::duplicateBox($id))
475 540 {
476 541 $error = true;
477 542 }
478 -
543 +
479 544 echo wp_json_encode([
480 545 'error' => $error
481 546 ]);
482 547 wp_die();
@@ -482,8 +547,28 @@
482 547 wp_die();
483 548 }
484 549
485 550 /**
551 + * Returns whether the given ID is a campaign the current user may act on.
552 + *
553 + * @param int $id Post ID.
554 + * @param string $capability Meta capability to check, i.e. edit_post/delete_post.
555 + *
556 + * @return bool
557 + */
558 + private static function userCanActOnCampaign($id, $capability)
559 + {
560 + $id = (int) $id;
561 +
562 + if (!$id || get_post_type($id) !== 'firebox')
563 + {
564 + return false;
565 + }
566 +
567 + return current_user_can($capability, $id);
568 + }
569 +
570 + /**
486 571 * Retrieve trending templates.
487 572 *
488 573 * @return void
489 574 */
@@ -552,5 +637,5 @@
552 637 $data->metrics($metrics)->filters($filters);
553 638
554 639 return $data->getData('count');
555 640 }
556 -}
641 +}