| @@ -1,12 +1,12 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | 3 | * @package FireBox |
| 4 | - * @version 1.1.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 © 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,8 +25,46 @@ | ||
| 27 | 25 | { |
| 28 | 26 | return; |
| 29 | 27 | } |
| 30 | 28 | |
| 29 | + // Keep FireBox assets out of WP Rocket's JS delay/defer/minify and CSS optimizations | |
| 30 | + new \FireBox\Core\Libs\WPRocket(); | |
| 31 | + | |
| 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 | + | |
| 31 | 67 | // Prepare Gutenberg Blocks that contain attributes by FireBox |
| 32 | 68 | new \FireBox\Core\FB\BoxBlocksParser(); |
| 33 | 69 | |
| 34 | 70 | /** |
| @@ -35,37 +71,56 @@ | ||
| 35 | 71 | * Event that runs before any rendering of popups. |
| 36 | 72 | */ |
| 37 | 73 | do_action('firebox/boxes/before_render'); |
| 38 | 74 | |
| 39 | - $this->render(); | |
| 75 | + // Run Actions | |
| 76 | + \FireBox\Core\Helpers\Actions::run(); | |
| 40 | 77 | |
| 41 | - $this->init_dependencies(); | |
| 78 | + add_action('template_redirect', [$this, 'render']); | |
| 42 | 79 | |
| 80 | + add_action('wp_enqueue_scripts', [$this, 'enqueueEmbedStylesEarly']); | |
| 81 | + | |
| 43 | 82 | /** |
| 44 | 83 | * Event that runs after popups have been rendered. |
| 45 | 84 | */ |
| 46 | 85 | do_action('firebox/boxes/after_render'); |
| 47 | 86 | } |
| 48 | - | |
| 87 | + | |
| 49 | 88 | /** |
| 50 | - * Initializes the dependencies | |
| 51 | - * | |
| 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 | + * | |
| 52 | 94 | * @return void |
| 53 | 95 | */ |
| 54 | - private function init_dependencies() | |
| 96 | + public function enqueueEmbedStylesEarly() | |
| 55 | 97 | { |
| 56 | - $actions = []; | |
| 98 | + $post = get_queried_object(); | |
| 99 | + | |
| 100 | + if (!($post instanceof \WP_Post)) | |
| 101 | + { | |
| 102 | + return; | |
| 103 | + } | |
| 57 | 104 | |
| 58 | - | |
| 105 | + if (!has_block('firebox/embed', $post)) | |
| 106 | + { | |
| 107 | + return; | |
| 108 | + } | |
| 59 | 109 | |
| 60 | - // Initialize Sounds | |
| 61 | - $actions[] = new \FireBox\Core\FB\Actions\Sounds(); | |
| 62 | - | |
| 63 | - // Make actions filterable | |
| 64 | - $actions = apply_filters('firebox/actions/box/edit', $actions); | |
| 65 | - | |
| 66 | - // Run actions | |
| 67 | - 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 | + ); | |
| 116 | + | |
| 117 | + wp_enqueue_style( | |
| 118 | + 'fb-block-embed-campaign', | |
| 119 | + FBOX_MEDIA_PUBLIC_URL . 'css/blocks/embed-campaign.css', | |
| 120 | + [], | |
| 121 | + FBOX_VERSION | |
| 122 | + ); | |
| 68 | 123 | } |
| 69 | 124 | |
| 70 | 125 | /** |
| 71 | 126 | * Renders all boxes on front-end |
| @@ -71,9 +126,9 @@ | ||
| 71 | 126 | * Renders all boxes on front-end |
| 72 | 127 | * |
| 73 | 128 | * @return void |
| 74 | 129 | */ |
| 75 | - private function render() | |
| 130 | + public function render() | |
| 76 | 131 | { |
| 77 | 132 | if ($this->checkForBoxPreview()) |
| 78 | 133 | { |
| 79 | 134 | return; |
| @@ -78,20 +133,53 @@ | ||
| 78 | 133 | { |
| 79 | 134 | return; |
| 80 | 135 | } |
| 81 | 136 | |
| 82 | - // increment session counter | |
| 83 | - \FPFramework\Libs\Functions::incrementSession(); | |
| 84 | - | |
| 137 | + // Don't render the popup if previewing with third party page builders | |
| 138 | + if (!$this->canRenderInEditors()) | |
| 139 | + { | |
| 140 | + return; | |
| 141 | + } | |
| 142 | + | |
| 85 | 143 | /** |
| 86 | 144 | * Adds all boxes at the end of page. |
| 87 | 145 | */ |
| 88 | - add_action('wp', function() { | |
| 89 | - firebox()->boxes->render(); | |
| 90 | - }); | |
| 146 | + firebox()->boxes->render(); | |
| 91 | 147 | } |
| 92 | 148 | |
| 93 | 149 | /** |
| 150 | + * Don't render when previewing with third party page builders. | |
| 151 | + * | |
| 152 | + * @return boolean | |
| 153 | + */ | |
| 154 | + private function canRenderInEditors() | |
| 155 | + { | |
| 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 | + ) | |
| 162 | + { | |
| 163 | + return; | |
| 164 | + } | |
| 165 | + | |
| 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()) | |
| 168 | + { | |
| 169 | + return; | |
| 170 | + } | |
| 171 | + | |
| 172 | + // Don't render the popup if previewing with Bricks Builder | |
| 173 | + if (function_exists('bricks_is_builder') && bricks_is_builder()) | |
| 174 | + { | |
| 175 | + return; | |
| 176 | + } | |
| 177 | + | |
| 178 | + return true; | |
| 179 | + } | |
| 180 | + | |
| 181 | + /** | |
| 94 | 182 | * Check if we are previewing a box and do not show other boxes. |
| 95 | 183 | * |
| 96 | 184 | * @return boolean |
| 97 | 185 | */ |
| @@ -99,5 +187,5 @@ | ||
| 99 | 187 | { |
| 100 | 188 | $previewer = new Previewer(); |
| 101 | 189 | return $previewer->init(); |
| 102 | 190 | } |
| 103 | -} | |
| 191 | +} | |