PluginProbe
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment / 3.1.9
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment v3.1.9
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.9, at Inc/Core/FB/Boxes.php

151 lines 2.8 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.9 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 // by the frontend runtime, so it must load on every page — not just pages where a
38 // campaign renders — for the pageview counter and session start to stay accurate.
39 if (BoxHelper::sessionConditionsInUse($boxes))
40 {
41 add_action('wp_enqueue_scripts', function()
42 {
43 wp_enqueue_script('firebox-main');
44 });
45 }
46
47 return $this->renderAll($boxes);
48 }
49
50 /**
51 * Renders all boxes
52 *
53 * @param array $boxes
54 *
55 * @return string
56 */
57 public function renderAll($boxes)
58 {
59 $html = '';
60
61 if ($boxes instanceof \WP_Query)
62 {
63 if (!$boxes->have_posts())
64 {
65 return;
66 }
67
68 // Backup global state
69 global $post, $authordata;
70 $originalPost = $post;
71 $originalAuthorData = $authordata;
72
73 // Setup the post data for our custom query
74 while ($boxes->have_posts())
75 {
76 $boxes->the_post();
77
78 global $post;
79
80 $this->prepare($post);
81
82 // If the mode is embed, abort.
83 if ($post->params->get('mode') == 'embed')
84 {
85 continue;
86 }
87
88 $html .= $this->get_output($post);
89 }
90
91 // Reset post data
92 wp_reset_postdata();
93
94 // Restore global state
95 $post = $originalPost;
96 $authordata = $originalAuthorData;
97 }
98 else if (is_array($boxes))
99 {
100 foreach ($boxes as $box)
101 {
102 $this->prepare($box);
103
104 // If the mode is embed, abort.
105 if ($box->params->get('mode') == 'embed')
106 {
107 continue;
108 }
109
110 $html .= $this->get_output($box);
111 }
112 }
113
114 return $html;
115 }
116
117 /**
118 * Prepares the box by setting its meta settings.
119 *
120 * @param object $box
121 *
122 * @return void
123 */
124 private function prepare(&$box)
125 {
126 $meta = BoxHelper::getMeta($box->ID);
127 $box->params = new Registry($meta);
128 }
129
130 /**
131 * Returns the box output
132 *
133 * @param object $box
134 *
135 * @return string
136 */
137 private function get_output($box)
138 {
139 $logged_and_admin = (is_user_logged_in() && current_user_can('edit_fireboxes'));
140
141 $testmode = $box->params->get('testmode', false);
142
143 // if box is in test mode only logged-in admin users can see it.
144 if ($testmode == '1' && !$logged_and_admin)
145 {
146 return '';
147 }
148
149 return firebox()->box->setBox($box)->render();
150 }
151 }