| 1 |
<?php |
| 2 |
/** |
| 3 |
* @package FireBox |
| 4 |
* @version 3.1.7 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 |
true |
| 35 |
); |
| 36 |
|
| 37 |
// Prepare Gutenberg Blocks that contain attributes by FireBox |
| 38 |
new \FireBox\Core\FB\BoxBlocksParser(); |
| 39 |
|
| 40 |
/** |
| 41 |
* Event that runs before any rendering of popups. |
| 42 |
*/ |
| 43 |
do_action('firebox/boxes/before_render'); |
| 44 |
|
| 45 |
// Run Actions |
| 46 |
\FireBox\Core\Helpers\Actions::run(); |
| 47 |
|
| 48 |
add_action('template_redirect', [$this, 'render']); |
| 49 |
|
| 50 |
/** |
| 51 |
* Event that runs after popups have been rendered. |
| 52 |
*/ |
| 53 |
do_action('firebox/boxes/after_render'); |
| 54 |
} |
| 55 |
|
| 56 |
/** |
| 57 |
* Renders all boxes on front-end |
| 58 |
* |
| 59 |
* @return void |
| 60 |
*/ |
| 61 |
public function render() |
| 62 |
{ |
| 63 |
if ($this->checkForBoxPreview()) |
| 64 |
{ |
| 65 |
return; |
| 66 |
} |
| 67 |
|
| 68 |
// Don't render the popup if previewing with third party page builders |
| 69 |
if (!$this->canRenderInEditors()) |
| 70 |
{ |
| 71 |
return; |
| 72 |
} |
| 73 |
|
| 74 |
// increment session counter |
| 75 |
\FPFramework\Libs\Functions::incrementSession(); |
| 76 |
|
| 77 |
/** |
| 78 |
* Adds all boxes at the end of page. |
| 79 |
*/ |
| 80 |
firebox()->boxes->render(); |
| 81 |
} |
| 82 |
|
| 83 |
/** |
| 84 |
* Don't render when previewing with third party page builders. |
| 85 |
* |
| 86 |
* @return boolean |
| 87 |
*/ |
| 88 |
private function canRenderInEditors() |
| 89 |
{ |
| 90 |
// Don't render the popup if previewing with Elementor |
| 91 |
if (class_exists('\Elementor\Plugin') && |
| 92 |
property_exists(\Elementor\Plugin::$instance, 'preview') && |
| 93 |
method_exists(\Elementor\Plugin::$instance->preview, 'is_preview_mode') && |
| 94 |
\Elementor\Plugin::$instance->preview->is_preview_mode() |
| 95 |
) |
| 96 |
{ |
| 97 |
return; |
| 98 |
} |
| 99 |
|
| 100 |
// Don't render the popup if previewing with Beaver Builder |
| 101 |
if (class_exists('\FLBuilderModel') && method_exists('\FLBuilderModel', 'is_builder_active') && \FLBuilderModel::is_builder_active()) |
| 102 |
{ |
| 103 |
return; |
| 104 |
} |
| 105 |
|
| 106 |
// Don't render the popup if previewing with Bricks Builder |
| 107 |
if (function_exists('bricks_is_builder') && bricks_is_builder()) |
| 108 |
{ |
| 109 |
return; |
| 110 |
} |
| 111 |
|
| 112 |
return true; |
| 113 |
} |
| 114 |
|
| 115 |
/** |
| 116 |
* Check if we are previewing a box and do not show other boxes. |
| 117 |
* |
| 118 |
* @return boolean |
| 119 |
*/ |
| 120 |
private function checkForBoxPreview() |
| 121 |
{ |
| 122 |
$previewer = new Previewer(); |
| 123 |
return $previewer->init(); |
| 124 |
} |
| 125 |
} |
| 126 |
|