| @@ -1,8 +1,8 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | 3 | * @package FireBox |
| 4 | - * @version 3.1.7 Free | |
| 4 | + * @version 3.1.14 Free | |
| 5 | 5 | * |
| 6 | 6 | * @author FirePlugins <[email protected]> |
| 7 | 7 | * @link https://www.fireplugins.com |
| 8 | 8 | * @copyright Copyright © 2026 FirePlugins All Rights Reserved |
| @@ -25,16 +25,46 @@ | ||
| 25 | 25 | { |
| 26 | 26 | return; |
| 27 | 27 | } |
| 28 | 28 | |
| 29 | + // Keep FireBox assets out of WP Rocket's JS delay/defer/minify and CSS optimizations | |
| 30 | + new \FireBox\Core\Libs\WPRocket(); | |
| 31 | + | |
| 29 | 32 | wp_register_script( |
| 30 | 33 | 'firebox-main', |
| 31 | 34 | FBOX_MEDIA_PUBLIC_URL . 'js/firebox.js', |
| 32 | 35 | [], |
| 33 | 36 | FBOX_VERSION, |
| 34 | - true | |
| 37 | + ['in_footer' => true, 'strategy' => 'defer'] | |
| 35 | 38 | ); |
| 36 | 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 | + | |
| 37 | 67 | // Prepare Gutenberg Blocks that contain attributes by FireBox |
| 38 | 68 | new \FireBox\Core\FB\BoxBlocksParser(); |
| 39 | 69 | |
| 40 | 70 | /** |
| @@ -46,13 +76,52 @@ | ||
| 46 | 76 | \FireBox\Core\Helpers\Actions::run(); |
| 47 | 77 | |
| 48 | 78 | add_action('template_redirect', [$this, 'render']); |
| 49 | 79 | |
| 80 | + add_action('wp_enqueue_scripts', [$this, 'enqueueEmbedStylesEarly']); | |
| 81 | + | |
| 50 | 82 | /** |
| 51 | 83 | * Event that runs after popups have been rendered. |
| 52 | 84 | */ |
| 53 | 85 | do_action('firebox/boxes/after_render'); |
| 54 | 86 | } |
| 87 | + | |
| 88 | + /** | |
| 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 | + * | |
| 94 | + * @return void | |
| 95 | + */ | |
| 96 | + public function enqueueEmbedStylesEarly() | |
| 97 | + { | |
| 98 | + $post = get_queried_object(); | |
| 99 | + | |
| 100 | + if (!($post instanceof \WP_Post)) | |
| 101 | + { | |
| 102 | + return; | |
| 103 | + } | |
| 104 | + | |
| 105 | + if (!has_block('firebox/embed', $post)) | |
| 106 | + { | |
| 107 | + return; | |
| 108 | + } | |
| 109 | + | |
| 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 | + ); | |
| 123 | + } | |
| 55 | 124 | |
| 56 | 125 | /** |
| 57 | 126 | * Renders all boxes on front-end |
| 58 | 127 | * |
| @@ -69,11 +138,8 @@ | ||
| 69 | 138 | if (!$this->canRenderInEditors()) |
| 70 | 139 | { |
| 71 | 140 | return; |
| 72 | 141 | } |
| 73 | - | |
| 74 | - // increment session counter | |
| 75 | - \FPFramework\Libs\Functions::incrementSession(); | |
| 76 | 142 | |
| 77 | 143 | /** |
| 78 | 144 | * Adds all boxes at the end of page. |
| 79 | 145 | */ |