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/Frontend.php +117 -103 1.0.11 → 3.1.14 View file →
@@ -1,12 +1,12 @@
1 1 <?php
2 2 /**
3 3 * @package FireBox
4 - * @version 1.0.11 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 © 2022 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;
@@ -15,10 +15,8 @@
15 15 {
16 16 exit; // Exit if accessed directly.
17 17 }
18 18
19 -use FPFramework\Libs\Registry;
20 -
21 19 class Frontend
22 20 {
23 21 public function __construct()
24 22 {
@@ -27,40 +25,102 @@
27 25 {
28 26 return;
29 27 }
30 28
31 - $this->init_dependencies();
29 + // Keep FireBox assets out of WP Rocket's JS delay/defer/minify and CSS optimizations
30 + new \FireBox\Core\Libs\WPRocket();
32 31
33 - $this->render();
32 + wp_register_script(
33 + 'firebox-main',
34 + FBOX_MEDIA_PUBLIC_URL . 'js/firebox.js',
35 + [],
36 + FBOX_VERSION,
37 + ['in_footer' => true, 'strategy' => 'defer']
38 + );
39 +
40 + // The session stamper on its own, for pages where no campaign renders but a
41 + // campaign elsewhere depends on the session cookies staying accurate.
42 + wp_register_script(
43 + 'firebox-session-stamp',
44 + FBOX_MEDIA_PUBLIC_URL . 'js/session-stamp.js',
45 + [],
46 + FBOX_VERSION,
47 + ['in_footer' => true, 'strategy' => 'defer']
48 + );
49 +
50 + /**
51 + * The session stamper writes the cookies PHP reads back
52 + * (FPFramework\Base\Factory\Session), so it has to name and scope them
53 + * the same way. Attached to both handles because either one can carry
54 + * the stamper: it is bundled into the runtime and also ships alone.
55 + */
56 + $scope = wp_json_encode([
57 + 'name_prefix' => \FPFramework\Helpers\CookieScope::name(''),
58 + 'path' => \FPFramework\Helpers\CookieScope::path(),
59 + 'domain' => \FPFramework\Helpers\CookieScope::domain()
60 + ]);
61 +
62 + foreach (['firebox-main', 'firebox-session-stamp'] as $handle)
63 + {
64 + wp_add_inline_script($handle, 'window.fpfCookieScope = ' . $scope . ';', 'before');
65 + }
66 +
67 + // Prepare Gutenberg Blocks that contain attributes by FireBox
68 + new \FireBox\Core\FB\BoxBlocksParser();
69 +
70 + /**
71 + * Event that runs before any rendering of popups.
72 + */
73 + do_action('firebox/boxes/before_render');
74 +
75 + // Run Actions
76 + \FireBox\Core\Helpers\Actions::run();
77 +
78 + add_action('template_redirect', [$this, 'render']);
79 +
80 + add_action('wp_enqueue_scripts', [$this, 'enqueueEmbedStylesEarly']);
81 +
82 + /**
83 + * Event that runs after popups have been rendered.
84 + */
85 + do_action('firebox/boxes/after_render');
34 86 }
35 -
87 +
36 88 /**
37 - * Initializes the dependencies
38 - *
89 + * Enqueues the embed-mode campaign CSS early (wp_enqueue_scripts, before wp_head closes)
90 + * when the currently queried post/page contains an Embed Campaign block. This avoids a
91 + * flash of unstyled content, since renderEmbed() otherwise only enqueues this CSS later,
92 + * during content rendering.
93 + *
39 94 * @return void
40 95 */
41 - private function init_dependencies()
96 + public function enqueueEmbedStylesEarly()
42 97 {
43 - /**
44 - * Event that runs before any rendering of popups.
45 - */
46 - do_action('firebox/boxes/before_render');
98 + $post = get_queried_object();
47 99
48 - $actions = [];
100 + if (!($post instanceof \WP_Post))
101 + {
102 + return;
103 + }
49 104
50 -
105 + if (!has_block('firebox/embed', $post))
106 + {
107 + return;
108 + }
51 109
52 - // Initialize Sounds
53 - $actions[] = new \FireBox\Core\FB\Actions\Sounds();
54 -
55 - // Make actions filterable
56 - $actions = apply_filters('firebox/actions/box/edit', $actions);
57 -
58 - // Run actions
59 - new \FireBox\Core\FB\Actions\ActionsBase($actions);
110 + wp_enqueue_style(
111 + 'firebox',
112 + FBOX_MEDIA_PUBLIC_URL . 'css/firebox.css',
113 + [],
114 + FBOX_VERSION
115 + );
60 116
61 - // Prepare Gutenberg Blocks that contain attributes by FireBox
62 - new \FireBox\Core\FB\BoxBlocksParser();
117 + wp_enqueue_style(
118 + 'fb-block-embed-campaign',
119 + FBOX_MEDIA_PUBLIC_URL . 'css/blocks/embed-campaign.css',
120 + [],
121 + FBOX_VERSION
122 + );
63 123 }
64 124
65 125 /**
66 126 * Renders all boxes on front-end
@@ -66,9 +126,9 @@
66 126 * Renders all boxes on front-end
67 127 *
68 128 * @return void
69 129 */
70 - private function render()
130 + public function render()
71 131 {
72 132 if ($this->checkForBoxPreview())
73 133 {
74 134 return;
@@ -73,105 +133,59 @@
73 133 {
74 134 return;
75 135 }
76 136
77 - if ($this->checkForBoxTemplatePreview())
137 + // Don't render the popup if previewing with third party page builders
138 + if (!$this->canRenderInEditors())
78 139 {
79 140 return;
80 141 }
81 142
82 - // increment session counter
83 - \FPFramework\Libs\Functions::incrementSession();
84 -
85 143 /**
86 144 * Adds all boxes at the end of page.
87 145 */
88 - add_action('wp', function() {
89 - firebox()->boxes->render();
90 - });
91 -
92 - /**
93 - * Event that runs after popups have been rendered.
94 - */
95 - do_action('firebox/boxes/after_render');
146 + firebox()->boxes->render();
96 147 }
97 148
98 149 /**
99 - * Check if we are previewing a box and do not show other boxes.
150 + * Don't render when previewing with third party page builders.
100 151 *
101 152 * @return boolean
102 153 */
103 - private function checkForBoxPreview()
154 + private function canRenderInEditors()
104 155 {
105 - $previewer = new Previewer();
106 - return $previewer->init();
107 - }
108 -
109 - /**
110 - * Check if we are previewing a box template and do not show other boxes.
111 - *
112 - * @return boolean
113 - */
114 - private function checkForBoxTemplatePreview()
115 - {
116 - // Preview a box template
117 - if (!isset($_GET['firebox_preview_template']))
156 + // Don't render the popup if previewing with Elementor
157 + if (class_exists('\Elementor\Plugin') &&
158 + property_exists(\Elementor\Plugin::$instance, 'preview') &&
159 + method_exists(\Elementor\Plugin::$instance->preview, 'is_preview_mode') &&
160 + \Elementor\Plugin::$instance->preview->is_preview_mode()
161 + )
118 162 {
119 - return false;
163 + return;
120 164 }
121 165
122 - $preview_box = sanitize_text_field($_GET['firebox_preview_template']);
123 - $this->render_template(base64_decode($preview_box));
124 - return true;
125 - }
126 -
127 - /**
128 - * Render template content
129 - *
130 - * @param string $template_alias
131 - *
132 - * @return void
133 - */
134 - private function render_template($template_alias)
135 - {
136 - $templates = firebox()->library;
137 -
138 - if (!$box = $templates->find($template_alias))
166 + // Don't render the popup if previewing with Beaver Builder
167 + if (class_exists('\FLBuilderModel') && method_exists('\FLBuilderModel', 'is_builder_active') && \FLBuilderModel::is_builder_active())
139 168 {
140 169 return;
141 170 }
142 171
143 - $box->params = new Registry($box->params);
144 -
145 - // Remove Publishing Assignments
146 - foreach ($box->params as $key => $value)
172 + // Don't render the popup if previewing with Bricks Builder
173 + if (function_exists('bricks_is_builder') && bricks_is_builder())
147 174 {
148 - if (strpos($key, 'assign') !== false)
149 - {
150 - $box->params->remove($key);
151 - }
175 + return;
152 176 }
153 - $box->params->remove('assignments');
177 +
178 + return true;
179 + }
154 180
155 - // Set id to 999999 for making front-end script happy
156 - $box->ID = 999999;
157 -
158 - // Enable Test Mode to prevent cookies
159 - $box->params->set('testmode', true);
160 -
161 - /**
162 - * Some popups may require a trigger method override for the Template preview.
163 - *
164 - * i.e. AdBlock popups should not require an AdBlocker for the Template preview
165 - * to display the popup.
166 - */
167 - if (isset($box->custom_fields->override_trigger_method) && $box->custom_fields->override_trigger_method !== 'inherit')
168 - {
169 - $box->params->set('triggermethod', $box->custom_fields->override_trigger_method);
170 - }
171 -
172 - // Disable Statistics to prevent impressions from being tracked into the database
173 - $box->stats = 0;
174 -
175 - return firebox()->box->render($box);
181 + /**
182 + * Check if we are previewing a box and do not show other boxes.
183 + *
184 + * @return boolean
185 + */
186 + private function checkForBoxPreview()
187 + {
188 + $previewer = new Previewer();
189 + return $previewer->init();
176 190 }
177 -}
191 +}