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