PluginProbe
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment / 2.0.16
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment v2.0.16
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
← All changes | Inc/Core/Blocks.php +89 -40 trunk2.0.16 View file →
@@ -1,12 +1,12 @@
1 1 <?php
2 2 /**
3 3 * @package FireBox
4 - * @version 3.1.13 Free
4 + * @version 2.0.16 Free
5 5 *
6 6 * @author FirePlugins <info@fireplugins.com>
7 7 * @link https://www.fireplugins.com
8 - * @copyright Copyright © 2026 FirePlugins All Rights Reserved
8 + * @copyright Copyright © 2023 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;
@@ -19,12 +19,25 @@
19 19 class Blocks
20 20 {
21 21 public function __construct()
22 22 {
23 - add_action('enqueue_block_assets', [$this, 'blocks_assets']);
23 + if (!function_exists('register_block_type'))
24 + {
25 + return;
26 + }
24 27
28 + add_action('enqueue_block_editor_assets', [$this, 'blocks_assets']);
29 +
25 30 // Register categories
26 - add_filter('block_categories_all', [$this, 'register_categories'], 10, 2);
31 + global $wp_version;
32 + if (version_compare($wp_version, '5.8', '>='))
33 + {
34 + add_action('block_categories_all', [$this, 'register_categories'], 10, 2);
35 + }
36 + else
37 + {
38 + add_action('block_categories', [$this, 'register_categories'], 10, 2);
39 + }
27 40
28 41 $this->register_blocks();
29 42 }
30 43
@@ -38,17 +51,31 @@
38 51 * @return array
39 52 */
40 53 public function register_categories($categories, $context)
41 54 {
42 - return array_merge(
55 + // Add FireBox category
56 + $categories = array_merge(
43 57 $categories,
44 - [
45 - [
46 - 'slug' => 'firebox',
47 - 'title' => 'FireBox'
48 - ]
49 - ]
58 + array(
59 + array(
60 + 'slug' => 'firebox',
61 + 'title' => firebox()->_('FB_PLUGIN_NAME')
62 + ),
63 + )
50 64 );
65 +
66 + // Add FirePlugins category
67 + $categories = array_merge(
68 + $categories,
69 + array(
70 + array(
71 + 'slug' => 'fireplugins',
72 + 'title' => fpframework()->_('FPF_NAME')
73 + ),
74 + )
75 + );
76 +
77 + return $categories;
51 78 }
52 79
53 80 /**
54 81 * Initialize all blocks
@@ -57,21 +84,13 @@
57 84 */
58 85 public function register_blocks()
59 86 {
60 87 $ds = DIRECTORY_SEPARATOR;
61 -
88 +
62 89 $base_dir = implode($ds, [__DIR__, 'Blocks']);
63 -
64 - $cache_key = 'firebox_block_files';
65 - $files = wp_cache_get($cache_key, 'firebox');
66 -
67 - if ($files === false)
68 - {
69 - $files = array_diff(scandir($base_dir), ['.', '..', '.DS_Store', 'index.php', 'Block.php']);
70 -
71 - wp_cache_set($cache_key, $files, 'firebox', HOUR_IN_SECONDS);
72 - }
73 -
90 +
91 + $files = array_diff(scandir($base_dir), ['.', '..', '.DS_Store', 'index.php', 'Block.php']);
92 +
74 93 $namespace = '\FireBox\Core\Blocks\\';
75 94
76 95 foreach ($files as $item)
77 96 {
@@ -76,21 +95,38 @@
76 95 foreach ($files as $item)
77 96 {
78 97 // Check if this is a single file and load it
79 98 $file = implode($ds, [$base_dir, $item]);
99 + if (is_file($file))
100 + {
101 + $class_name = preg_replace('/.php$/', '', $item);
102 + $this->registerBlock($namespace . $class_name);
103 + continue;
104 + }
105 +
106 + // If that's not a file, we assume it is a directory of files
107 + $blocks = array_diff(scandir($file), ['.', '..', 'index.php']);
80 108
81 - if (!is_file($file))
82 - {
83 - continue;
109 + foreach ($blocks as $key => $block_name)
110 + {
111 + $class_name = preg_replace('/.php$/', '', $block_name);
112 + $class = $namespace . $item . '\\' . $class_name;
113 + $this->registerBlock($class);
84 114 }
115 + }
116 + }
85 117
86 - $class_name = preg_replace('/.php$/', '', $item);
87 -
88 - $class = $namespace . $class_name;
89 -
90 - $block = new $class();
91 - $block->register();
92 - }
118 + /**
119 + * Registers the block.
120 + *
121 + * @param string $class
122 + *
123 + * @return void
124 + */
125 + private function registerBlock($class)
126 + {
127 + $block = new $class();
128 + $block->register();
93 129 }
94 130
95 131 /**
96 132 * Blocks assets.
@@ -99,18 +135,31 @@
99 135 * It also allows us to set custom CSS Classes to these blocks without triggering a popup.
100 136 */
101 137 public function blocks_assets()
102 138 {
103 - if (!is_admin())
104 - {
105 - return;
106 - }
107 -
108 139 wp_enqueue_script(
109 140 'fb-blocks-extend',
110 - FBOX_MEDIA_ADMIN_URL . 'js/blocks/fb_blocks_extend.js',
111 - ['wp-i18n', 'wp-blocks', 'wp-editor', 'wp-components', 'wp-api-fetch', 'lodash'],
141 + FBOX_MEDIA_ADMIN_URL . 'js/fb_blocks_extend.js',
142 + ['wp-i18n', 'wp-blocks', 'wp-editor', 'wp-components', 'wp-api-fetch'],
112 143 FBOX_VERSION,
113 144 true
114 145 );
146 +
147 + // Enqueue block editor style only in Gutenberg editor
148 + if (function_exists('get_current_screen'))
149 + {
150 + $screen = get_current_screen();
151 + if ($screen->is_block_editor)
152 + {
153 + if (get_post_type() === 'firebox')
154 + {
155 + wp_enqueue_style(
156 + 'firebox-block-editor',
157 + FBOX_MEDIA_ADMIN_URL . 'css/block-editor.css',
158 + [],
159 + FBOX_VERSION
160 + );
161 + }
162 + }
163 + }
115 164 }
116 165 }