PluginProbe
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment / 1.0.11
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment v1.0.11
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
firebox / Inc / Core / Blocks.php

Blocks.php in FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment 1.0.11, at Inc/Core/Blocks.php

138 lines 3.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @package FireBox
4 * @version 1.0.11 Free
5 *
6 * @author FirePlugins <info@fireplugins.com>
7 * @link https://www.fireplugins.com
8 * @copyright Copyright © 2022 FirePlugins All Rights Reserved
9 * @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
10 */
11
12 namespace FireBox\Core;
13
14 if (!defined('ABSPATH'))
15 {
16 exit; // Exit if accessed directly.
17 }
18
19 class Blocks
20 {
21 public function __construct()
22 {
23 if (!function_exists('register_block_type'))
24 {
25 return;
26 }
27
28 add_action('enqueue_block_editor_assets', [$this, 'blocks_assets']);
29
30 // Register categories
31 add_filter('block_categories_all', [$this, 'register_categories'], 10, 2);
32
33 $this->register_blocks();
34 }
35
36 /**
37 * Adds the `FireBox` and `FirePlugins` custom Gutenberg block categories
38 * to register all our blocks.
39 *
40 * @param array $categories
41 * @param WP_Block_Editor_Context $context
42 *
43 * @return array
44 */
45 public function register_categories($categories, $context)
46 {
47 // Add FireBox category
48 $categories = array_merge(
49 $categories,
50 array(
51 array(
52 'slug' => 'firebox',
53 'title' => firebox()->_('FB_PLUGIN_NAME')
54 ),
55 )
56 );
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 }
71
72 /**
73 * Initialize all blocks
74 *
75 * @return void
76 */
77 public function register_blocks()
78 {
79 $ds = DIRECTORY_SEPARATOR;
80
81 $base_dir = implode($ds, [__DIR__, 'Blocks']);
82
83 $files = array_diff(scandir($base_dir), ['.', '..', 'index.php', 'Block.php']);
84
85 $namespace = '\FireBox\Core\Blocks\\';
86
87 foreach ($files as $item)
88 {
89 // Check if this is a single file and load it
90 $file = implode($ds, [$base_dir, $item]);
91 if (is_file($file))
92 {
93 $this->registerBlock($namespace . rtrim($item, '.php'));
94 continue;
95 }
96
97 // If that's not a file, we assume it is a directory of files
98 $blocks = array_diff(scandir($file), ['.', '..', 'index.php']);
99
100 foreach ($blocks as $key => $block_name)
101 {
102 $class = $namespace . $item . '\\' . rtrim($block_name, '.php');
103 $this->registerBlock($class);
104 }
105 }
106 }
107
108 /**
109 * Registers the block.
110 *
111 * @param string $class
112 *
113 * @return void
114 */
115 private function registerBlock($class)
116 {
117 $block = new $class();
118 $block->register();
119 }
120
121 /**
122 * Blocks assets.
123 *
124 * - Extends functionality of the button/image blocks by allowing to trigger a popup.
125 * It also allows us to set custom CSS Classes to these blocks without triggering a popup.
126 */
127 public function blocks_assets()
128 {
129 wp_register_script(
130 'fb-blocks-extend',
131 FBOX_MEDIA_ADMIN_URL . 'js/fb_blocks_extend.js',
132 ['wp-i18n', 'wp-blocks', 'wp-editor', 'wp-components', 'wp-api-fetch'],
133 FBOX_VERSION,
134 true
135 );
136 wp_enqueue_script('fb-blocks-extend');
137 }
138 }