PluginProbe
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment / 1.0.0
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment v1.0.0
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 / FireBox.php

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

119 lines 2.3 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.0 Free
5 *
6 * @author FirePlugins <info@fireplugins.com>
7 * @link https://www.fireplugins.com
8 * @copyright Copyright © 2021 FirePlugins All Rights Reserved
9 * @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
10 */
11
12 namespace FireBox\Core\Blocks;
13
14 if (!defined('ABSPATH'))
15 {
16 exit; // Exit if accessed directly.
17 }
18
19 class FireBox
20 {
21 public function __construct()
22 {
23 if (!$this->canRun())
24 {
25 return;
26 }
27
28 // set custom gutenberg block category
29 add_filter('block_categories', [$this, 'set_custom_block_category'], 10, 2);
30
31 // load gutenberg block js
32 add_action('admin_enqueue_scripts', [$this, 'registerMedia']);
33
34 // register gutenberg block type
35 register_block_type('fireplugins/firebox', array(
36 'editor_script' => 'fb-gutenberg-block',
37 ));
38 }
39
40 /**
41 * Whether we can run
42 *
43 * @return boolean
44 */
45 private function canRun()
46 {
47 if (!current_user_can('manage_options') || !current_user_can('edit_posts') || !current_user_can('edit_pages'))
48 {
49 return false;
50 }
51
52 global $pagenow;
53 if (!in_array($pagenow, ['post.php', 'post-new.php', 'index.php']))
54 {
55 return false;
56 }
57
58 return true;
59 }
60
61 /**
62 * Adds custom gutenberg block category
63 *
64 * @param array $categories
65 * @param object $post
66 *
67 * @return array
68 */
69 public function set_custom_block_category($categories, $post)
70 {
71 // check fireplugins does not exist
72 foreach ($categories as $cat)
73 {
74 if ($cat['slug'] == 'fireplugins')
75 {
76 return $categories;
77 }
78 }
79
80 return array_merge(
81 $categories,
82 array(
83 array(
84 'slug' => 'fireplugins',
85 'title' => fpframework()->_('FPF_NAME')
86 ),
87 )
88 );
89 }
90
91 /**
92 * Adds block media
93 *
94 * @return void
95 */
96 public function registerMedia()
97 {
98 // load gutenberg block js
99 wp_register_script(
100 'fb-gutenberg-block',
101 FBOX_MEDIA_ADMIN_URL . 'js/fb_gutenberg_block.js',
102 ['wp-i18n', 'wp-blocks', 'wp-editor', 'wp-components', 'wp-api-fetch'],
103 FBOX_VERSION,
104 false
105 );
106 wp_enqueue_script( 'fb-gutenberg-block' );
107
108 // load gutenberg block button extend js
109 wp_register_script(
110 'fb-admin-block-button-extend',
111 FBOX_MEDIA_ADMIN_URL . 'js/fb_block_button_extend.js',
112 [],
113 FBOX_VERSION,
114 false
115 );
116 wp_enqueue_script( 'fb-admin-block-button-extend' );
117 }
118
119 }