PluginProbe
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment / 2.1.39
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment v2.1.39
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 +105 -20 1.0.52.1.39 View file →
@@ -1,12 +1,12 @@
1 1 <?php
2 2 /**
3 3 * @package FireBox
4 - * @version 1.0.5 Free
4 + * @version 2.1.39 Free
5 5 *
6 6 * @author FirePlugins <info@fireplugins.com>
7 7 * @link https://www.fireplugins.com
8 - * @copyright Copyright © 2021 FirePlugins All Rights Reserved
8 + * @copyright Copyright © 2025 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,36 +19,121 @@
19 19 class Blocks
20 20 {
21 21 public function __construct()
22 22 {
23 - $this->init();
23 + if (!function_exists('register_block_type'))
24 + {
25 + return;
26 + }
27 +
28 + add_action('enqueue_block_assets', [$this, 'blocks_assets']);
29 +
30 + // Register categories
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 + }
40 +
41 + $this->register_blocks();
24 42 }
25 43
44 + /**
45 + * Adds the `FireBox` and `FirePlugins` custom Gutenberg block categories
46 + * to register all our blocks.
47 + *
48 + * @param array $categories
49 + * @param WP_Block_Editor_Context $context
50 + *
51 + * @return array
52 + */
53 + public function register_categories($categories, $context)
54 + {
55 + return array_merge(
56 + $categories,
57 + [
58 + [
59 + 'slug' => 'firebox',
60 + 'title' => 'FireBox'
61 + ]
62 + ]
63 + );
64 + }
65 +
26 66 /**
27 67 * Initialize all blocks
28 68 *
29 69 * @return void
30 70 */
31 - public function init()
71 + public function register_blocks()
32 72 {
33 - $blocks = \scandir(dirname(__FILE__) . '/Blocks');
73 + $ds = DIRECTORY_SEPARATOR;
74 +
75 + $base_dir = implode($ds, [__DIR__, 'Blocks']);
76 +
77 + $files = array_diff(scandir($base_dir), ['.', '..', '.DS_Store', 'index.php', 'Block.php']);
78 +
79 + $namespace = '\FireBox\Core\Blocks\\';
34 80
35 - foreach ($blocks as $block_file_name)
36 - {
37 - if (!$ext = pathinfo($block_file_name, PATHINFO_EXTENSION))
81 + foreach ($files as $item)
82 + {
83 + // Check if this is a single file and load it
84 + $file = implode($ds, [$base_dir, $item]);
85 +
86 + if (!is_file($file))
38 87 {
39 - continue;
40 - }
88 + continue;
89 + }
41 90
42 - $class = '\FireBox\Core\Blocks\\' . basename($block_file_name, '.php');
91 + $class_name = preg_replace('/.php$/', '', $item);
92 +
93 + $class = $namespace . $class_name;
94 +
95 + $block = new $class();
96 + $block->register();
97 + }
98 + }
43 99
44 - if (!class_exists($class))
45 - {
46 - continue;
47 - }
48 -
49 - new $class();
50 - }
51 -
100 + /**
101 + * Blocks assets.
102 + *
103 + * - Extends functionality of the button/image blocks by allowing to trigger a popup.
104 + * It also allows us to set custom CSS Classes to these blocks without triggering a popup.
105 + */
106 + public function blocks_assets()
107 + {
108 + if (!is_admin())
109 + {
110 + return;
111 + }
112 +
113 + wp_enqueue_script(
114 + 'fb-blocks-extend',
115 + FBOX_MEDIA_ADMIN_URL . 'js/fb_blocks_extend.js',
116 + ['wp-i18n', 'wp-blocks', 'wp-editor', 'wp-components', 'wp-api-fetch', 'lodash'],
117 + FBOX_VERSION,
118 + true
119 + );
120 +
121 + // Enqueue block editor style only in Gutenberg editor
122 + if (function_exists('get_current_screen'))
123 + {
124 + $screen = get_current_screen();
125 + if ($screen->is_block_editor)
126 + {
127 + if (get_post_type() === 'firebox')
128 + {
129 + wp_enqueue_style(
130 + 'firebox-block-editor',
131 + FBOX_MEDIA_ADMIN_URL . 'css/block-editor.css',
132 + [],
133 + FBOX_VERSION
134 + );
135 + }
136 + }
137 + }
52 138 }
53 -
54 139 }