PluginProbe
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment / 3.1.11
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment v3.1.11
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 / FB / Boxes.php

Boxes.php in FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment 3.1.11, at Inc/Core/FB/Boxes.php

158 lines 3.1 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.11 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\FB;
13
14 if (!defined('ABSPATH'))
15 {
16 exit; // Exit if accessed directly.
17 }
18
19 use FPFramework\Libs\Registry;
20 use FireBox\Core\Helpers\BoxHelper;
21
22 class Boxes
23 {
24 /**
25 * Render boxes
26 *
27 * @return string
28 */
29 public function render()
30 {
31 if (!$boxes = BoxHelper::getAllBoxes())
32 {
33 return;
34 }
35
36 // Session-dependent conditions (Pageviews, Time on Site) are stamped and evaluated
37 // in the browser, so the stamper must run on every page — not just pages where a
38 // campaign renders — for the pageview counter and session start to stay accurate.
39 //
40 // On pages where a campaign does render, the full runtime already contains the
41 // stamper, so only the standalone ~1 KB script is needed elsewhere. The priority
42 // runs late, after the per-box enqueues added from Box::render().
43 if (BoxHelper::sessionConditionsInUse($boxes))
44 {
45 add_action('wp_enqueue_scripts', function()
46 {
47 if (!wp_script_is('firebox-main', 'enqueued'))
48 {
49 wp_enqueue_script('firebox-session-stamp');
50 }
51 }, 100);
52 }
53
54 return $this->renderAll($boxes);
55 }
56
57 /**
58 * Renders all boxes
59 *
60 * @param array $boxes
61 *
62 * @return string
63 */
64 public function renderAll($boxes)
65 {
66 $html = '';
67
68 if ($boxes instanceof \WP_Query)
69 {
70 if (!$boxes->have_posts())
71 {
72 return;
73 }
74
75 // Backup global state
76 global $post, $authordata;
77 $originalPost = $post;
78 $originalAuthorData = $authordata;
79
80 // Setup the post data for our custom query
81 while ($boxes->have_posts())
82 {
83 $boxes->the_post();
84
85 global $post;
86
87 $this->prepare($post);
88
89 // If the mode is embed, abort.
90 if ($post->params->get('mode') == 'embed')
91 {
92 continue;
93 }
94
95 $html .= $this->get_output($post);
96 }
97
98 // Reset post data
99 wp_reset_postdata();
100
101 // Restore global state
102 $post = $originalPost;
103 $authordata = $originalAuthorData;
104 }
105 else if (is_array($boxes))
106 {
107 foreach ($boxes as $box)
108 {
109 $this->prepare($box);
110
111 // If the mode is embed, abort.
112 if ($box->params->get('mode') == 'embed')
113 {
114 continue;
115 }
116
117 $html .= $this->get_output($box);
118 }
119 }
120
121 return $html;
122 }
123
124 /**
125 * Prepares the box by setting its meta settings.
126 *
127 * @param object $box
128 *
129 * @return void
130 */
131 private function prepare(&$box)
132 {
133 $meta = BoxHelper::getMeta($box->ID);
134 $box->params = new Registry($meta);
135 }
136
137 /**
138 * Returns the box output
139 *
140 * @param object $box
141 *
142 * @return string
143 */
144 private function get_output($box)
145 {
146 $logged_and_admin = (is_user_logged_in() && current_user_can('edit_fireboxes'));
147
148 $testmode = $box->params->get('testmode', false);
149
150 // if box is in test mode only logged-in admin users can see it.
151 if ($testmode == '1' && !$logged_and_admin)
152 {
153 return '';
154 }
155
156 return firebox()->box->setBox($box)->render();
157 }
158 }