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/FB/Boxes.php +65 -77 1.0.0 → 3.1.14 View file →
@@ -1,12 +1,12 @@
1 1 <?php
2 2 /**
3 3 * @package FireBox
4 - * @version 1.0.0 Free
4 + * @version 3.1.14 Free
5 5 *
6 6 * @author FirePlugins <[email protected]>
7 7 * @link https://www.fireplugins.com
8 - * @copyright Copyright © 2021 FirePlugins All Rights Reserved
8 + * @copyright Copyright © 2026 FirePlugins All Rights Reserved
9 9 * @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
10 10 */
11 11
12 12 namespace FireBox\Core\FB;
@@ -21,51 +21,38 @@
21 21
22 22 class Boxes
23 23 {
24 24 /**
25 - * A box instance
25 + * Render boxes
26 26 *
27 - * @var Box
27 + * @return string
28 28 */
29 - protected $box;
30 -
31 - /**
32 - * Factory
33 - *
34 - * @var Factory
35 - */
36 - protected $factory;
37 -
38 - public function __construct($box = null, $factory = null)
29 + public function render()
39 30 {
40 - if (!$factory)
31 + if (!$boxes = BoxHelper::getAllBoxes())
41 32 {
42 - $factory = new \FPFramework\Base\Factory();
33 + return;
43 34 }
44 - $this->factory = $factory;
45 35
46 - if (!$box)
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))
47 44 {
48 - $box = new \FireBox\Core\FB\Box(null, $this->factory);
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);
49 52 }
50 - $this->box = $box;
51 - }
52 53
53 - /**
54 - * Render boxes
55 - *
56 - * @return string
57 - */
58 - public function render()
59 - {
60 - $boxes_query = BoxHelper::getAllBoxesWPQuery();
61 -
62 - if (!method_exists($boxes_query, 'have_posts') || (method_exists($boxes_query, 'have_posts') && !$boxes_query->have_posts()))
63 - {
64 - return;
65 - }
66 -
67 - return $this->renderAll($boxes_query);
54 + return $this->renderAll($boxes);
68 55 }
69 56
70 57 /**
71 58 * Renders all boxes
@@ -76,33 +63,62 @@
76 63 */
77 64 public function renderAll($boxes)
78 65 {
79 66 $html = '';
80 -
81 - // handle WP_Query boxes loop
82 - if (isset($boxes->posts))
67 +
68 + if ($boxes instanceof \WP_Query)
83 69 {
84 - foreach ($boxes->posts as $box)
70 + if (!$boxes->have_posts())
85 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 + {
86 83 $boxes->the_post();
87 84
88 - $this->prepare($box);
85 + global $post;
89 86
90 - $html .= $this->get_output($box);
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);
91 96 }
92 - wp_reset_query();
97 +
98 + // Reset post data
99 + wp_reset_postdata();
100 +
101 + // Restore global state
102 + $post = $originalPost;
103 + $authordata = $originalAuthorData;
93 104 }
94 - else
95 - // handle boxes array
105 + else if (is_array($boxes))
96 106 {
97 107 foreach ($boxes as $box)
98 108 {
99 109 $this->prepare($box);
110 +
111 + // If the mode is embed, abort.
112 + if ($box->params->get('mode') == 'embed')
113 + {
114 + continue;
115 + }
100 116
101 117 $html .= $this->get_output($box);
102 118 }
103 119 }
104 -
120 +
105 121 return $html;
106 122 }
107 123
108 124 /**
@@ -113,10 +129,9 @@
113 129 * @return void
114 130 */
115 131 private function prepare(&$box)
116 132 {
117 - // get meta options for box
118 - $meta = get_post_meta($box->ID, 'fpframework_meta_settings', true);
133 + $meta = BoxHelper::getMeta($box->ID);
119 134 $box->params = new Registry($meta);
120 135 }
121 136
122 137 /**
@@ -127,9 +142,9 @@
127 142 * @return string
128 143 */
129 144 private function get_output($box)
130 145 {
131 - $logged_and_admin = (is_user_logged_in() && current_user_can('manage_options'));
146 + $logged_and_admin = (is_user_logged_in() && current_user_can('edit_fireboxes'));
132 147
133 148 $testmode = $box->params->get('testmode', false);
134 149
135 150 // if box is in test mode only logged-in admin users can see it.
@@ -137,34 +152,7 @@
137 152 {
138 153 return '';
139 154 }
140 155
141 - return $this->box->render($box);
142 - }
143 -
144 - /**
145 - * Return the box
146 - *
147 - * @return Box
148 - */
149 - public function getBox()
150 - {
151 - return $this->box;
152 - }
153 -
154 - /**
155 - * Set the box
156 - *
157 - * @param Box $box
158 - *
159 - * @return Box
160 - */
161 - public function setBox($box)
162 - {
163 - if (!$box)
164 - {
165 - return;
166 - }
167 -
168 - $this->box = $box;
156 + return firebox()->box->setBox($box)->render();
169 157 }
170 158 }