PluginProbe
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment / 3.1.10
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment v3.1.10
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 / Frontend.php

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

189 lines 4.4 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.10 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;
13
14 if (!defined('ABSPATH'))
15 {
16 exit; // Exit if accessed directly.
17 }
18
19 class Frontend
20 {
21 public function __construct()
22 {
23 // ensure we run only on front-end
24 if (is_admin())
25 {
26 return;
27 }
28
29 wp_register_script(
30 'firebox-main',
31 FBOX_MEDIA_PUBLIC_URL . 'js/firebox.js',
32 [],
33 FBOX_VERSION,
34 ['in_footer' => true, 'strategy' => 'defer']
35 );
36
37 // The session stamper on its own, for pages where no campaign renders but a
38 // campaign elsewhere depends on the session cookies staying accurate.
39 wp_register_script(
40 'firebox-session-stamp',
41 FBOX_MEDIA_PUBLIC_URL . 'js/session-stamp.js',
42 [],
43 FBOX_VERSION,
44 ['in_footer' => true, 'strategy' => 'defer']
45 );
46
47 /**
48 * The session stamper writes the cookies PHP reads back
49 * (FPFramework\Base\Factory\Session), so it has to name and scope them
50 * the same way. Attached to both handles because either one can carry
51 * the stamper: it is bundled into the runtime and also ships alone.
52 */
53 $scope = wp_json_encode([
54 'name_prefix' => \FPFramework\Helpers\CookieScope::name(''),
55 'path' => \FPFramework\Helpers\CookieScope::path(),
56 'domain' => \FPFramework\Helpers\CookieScope::domain()
57 ]);
58
59 foreach (['firebox-main', 'firebox-session-stamp'] as $handle)
60 {
61 wp_add_inline_script($handle, 'window.fpfCookieScope = ' . $scope . ';', 'before');
62 }
63
64 // Prepare Gutenberg Blocks that contain attributes by FireBox
65 new \FireBox\Core\FB\BoxBlocksParser();
66
67 /**
68 * Event that runs before any rendering of popups.
69 */
70 do_action('firebox/boxes/before_render');
71
72 // Run Actions
73 \FireBox\Core\Helpers\Actions::run();
74
75 add_action('template_redirect', [$this, 'render']);
76
77 add_action('wp_enqueue_scripts', [$this, 'enqueueEmbedStylesEarly']);
78
79 /**
80 * Event that runs after popups have been rendered.
81 */
82 do_action('firebox/boxes/after_render');
83 }
84
85 /**
86 * Enqueues the embed-mode campaign CSS early (wp_enqueue_scripts, before wp_head closes)
87 * when the currently queried post/page contains an Embed Campaign block. This avoids a
88 * flash of unstyled content, since renderEmbed() otherwise only enqueues this CSS later,
89 * during content rendering.
90 *
91 * @return void
92 */
93 public function enqueueEmbedStylesEarly()
94 {
95 $post = get_queried_object();
96
97 if (!($post instanceof \WP_Post))
98 {
99 return;
100 }
101
102 if (!has_block('firebox/embed', $post))
103 {
104 return;
105 }
106
107 wp_enqueue_style(
108 'firebox',
109 FBOX_MEDIA_PUBLIC_URL . 'css/firebox.css',
110 [],
111 FBOX_VERSION
112 );
113
114 wp_enqueue_style(
115 'fb-block-embed-campaign',
116 FBOX_MEDIA_PUBLIC_URL . 'css/blocks/embed-campaign.css',
117 [],
118 FBOX_VERSION
119 );
120 }
121
122 /**
123 * Renders all boxes on front-end
124 *
125 * @return void
126 */
127 public function render()
128 {
129 if ($this->checkForBoxPreview())
130 {
131 return;
132 }
133
134 // Don't render the popup if previewing with third party page builders
135 if (!$this->canRenderInEditors())
136 {
137 return;
138 }
139
140 /**
141 * Adds all boxes at the end of page.
142 */
143 firebox()->boxes->render();
144 }
145
146 /**
147 * Don't render when previewing with third party page builders.
148 *
149 * @return boolean
150 */
151 private function canRenderInEditors()
152 {
153 // Don't render the popup if previewing with Elementor
154 if (class_exists('\Elementor\Plugin') &&
155 property_exists(\Elementor\Plugin::$instance, 'preview') &&
156 method_exists(\Elementor\Plugin::$instance->preview, 'is_preview_mode') &&
157 \Elementor\Plugin::$instance->preview->is_preview_mode()
158 )
159 {
160 return;
161 }
162
163 // Don't render the popup if previewing with Beaver Builder
164 if (class_exists('\FLBuilderModel') && method_exists('\FLBuilderModel', 'is_builder_active') && \FLBuilderModel::is_builder_active())
165 {
166 return;
167 }
168
169 // Don't render the popup if previewing with Bricks Builder
170 if (function_exists('bricks_is_builder') && bricks_is_builder())
171 {
172 return;
173 }
174
175 return true;
176 }
177
178 /**
179 * Check if we are previewing a box and do not show other boxes.
180 *
181 * @return boolean
182 */
183 private function checkForBoxPreview()
184 {
185 $previewer = new Previewer();
186 return $previewer->init();
187 }
188 }
189