PluginProbe
bBlocks – Essential Gutenberg Blocks & Patterns Collection / 2.0.38
bBlocks – Essential Gutenberg Blocks & Patterns Collection v2.0.38
2.1.8 2.1.7 2.1.6 2.1.5 2.1.4 2.1.3 2.1.2 2.1.1 2.1.0 2.0.43 2.0.42 2.0.41 2.0.40 2.0.39 2.0.38 trunk 1.0 1.1 1.2 1.3 1.4 1.5 1.5.1 1.5.2 1.5.3 All 108 releases
b-blocks / plugin.php

plugin.php in bBlocks – Essential Gutenberg Blocks & Patterns Collection 2.0.38, at plugin.php

346 lines 12.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Plugin Name: bBlocks
5 * Description: Gutenberg Blocks Collection and Page Builder.
6 * Version: 2.0.38
7 * Author: bPlugins
8 * Author URI: https://bplugins.com
9 * License: GPLv3
10 * License URI: https://www.gnu.org/licenses/gpl-3.0.txt
11 * Text Domain: b-blocks
12 */
13 // ABS PATH
14 if ( !defined( 'ABSPATH' ) ) {
15 exit;
16 }
17 if ( function_exists( 'b_blocks_fs' ) ) {
18 register_activation_hook( __FILE__, function () {
19 if ( is_plugin_active( 'b-blocks/plugin.php' ) ) {
20 deactivate_plugins( 'b-blocks/plugin.php' );
21 }
22 if ( is_plugin_active( 'b-blocks-pro/plugin.php' ) ) {
23 deactivate_plugins( 'b-blocks-pro/plugin.php' );
24 }
25 } );
26 } else {
27 // Constant
28 define( 'B_BLOCKS_VERSION', ( isset( $_SERVER['HTTP_HOST'] ) && ('localhost' === $_SERVER['HTTP_HOST'] || 'murdwahid.local' === $_SERVER['HTTP_HOST']) ? time() : '2.0.38' ) );
29 define( 'B_BLOCKS_DIR_PATH', plugin_dir_path( __FILE__ ) );
30 define( 'B_BLOCKS_DIR_URL', plugin_dir_url( __FILE__ ) );
31 define( 'B_BLOCKS_HAS_PRO', 'b-blocks-pro/plugin.php' === plugin_basename( __FILE__ ) );
32 define( 'B_BLOCKS_BUILD', B_BLOCKS_DIR_URL . 'build/' );
33 define( 'B_BLOCKS_ASSETS', B_BLOCKS_DIR_URL . 'assets/' );
34 if ( !function_exists( 'b_blocks_fs' ) ) {
35 // Create a helper function for easy SDK access.
36 function b_blocks_fs() {
37 global $b_blocks_fs;
38 if ( !isset( $b_blocks_fs ) ) {
39 // Include Freemius SDK.
40 require_once dirname( __FILE__ ) . '/freemius/start.php';
41 $b_blocks_fs = fs_dynamic_init( array(
42 'id' => '12845',
43 'slug' => 'b-blocks',
44 'premium_slug' => 'b-blocks-pro',
45 'type' => 'plugin',
46 'public_key' => 'pk_d6426b344df4918bc066a7a0b4719',
47 'is_premium' => false,
48 'premium_suffix' => 'Pro',
49 'has_addons' => false,
50 'has_paid_plans' => true,
51 'trial' => array(
52 'days' => 7,
53 'is_require_payment' => true,
54 ),
55 'menu' => array(
56 'slug' => 'b-blocks',
57 'first-path' => 'admin.php?page=b-blocks',
58 'contact' => false,
59 'support' => false,
60 ),
61 'is_live' => true,
62 'is_org_compliant' => true,
63 ) );
64 }
65 return $b_blocks_fs;
66 }
67
68 // Init Freemius.
69 b_blocks_fs();
70 // Signal that SDK was initiated.
71 do_action( 'b_blocks_fs_loaded' );
72 }
73 // Generate Styles
74 class BBlocksStyleGenerator {
75 public static $styles = [];
76
77 public static function addStyle( $selector, $styles ) {
78 if ( array_key_exists( $selector, self::$styles ) ) {
79 self::$styles[$selector] = wp_parse_args( self::$styles[$selector], $styles );
80 } else {
81 self::$styles[$selector] = $styles;
82 }
83 }
84
85 public static function renderStyle() {
86 $output = '';
87 foreach ( self::$styles as $selector => $style ) {
88 $new = '';
89 foreach ( $style as $property => $value ) {
90 if ( $value == '' ) {
91 $new .= "{$property} ;";
92 } else {
93 $new .= " {$property}: {$value};";
94 }
95 }
96 $output .= "{$selector} { {$new} }";
97 }
98 return $output;
99 }
100
101 }
102
103 // Require files
104 require_once B_BLOCKS_DIR_PATH . 'includes/Dashboard.php';
105 require_once B_BLOCKS_DIR_PATH . 'includes/EnqueueScripts.php';
106 require_once B_BLOCKS_DIR_PATH . 'includes/Utils.php';
107 require_once B_BLOCKS_DIR_PATH . 'includes/GetCSS.php';
108 require_once B_BLOCKS_DIR_PATH . 'includes/Ajax.php';
109 require_once B_BLOCKS_DIR_PATH . 'includes/posts/Posts.php';
110 require_once B_BLOCKS_DIR_PATH . 'includes/Templates/Templates.php';
111 require_once B_BLOCKS_DIR_PATH . 'includes/blocks/LoginForm.php';
112 require_once B_BLOCKS_DIR_PATH . 'includes/blocks/cursor.php';
113 require_once B_BLOCKS_DIR_PATH . 'includes/Ai.php';
114 require_once B_BLOCKS_DIR_PATH . 'includes/ApiKeys.php';
115 require_once B_BLOCKS_DIR_PATH . 'includes/blocks/form/FormHandler.php';
116 // License Activation
117 if ( file_exists( B_BLOCKS_DIR_PATH . 'includes/LicenseActivation.php' ) && B_BLOCKS_HAS_PRO ) {
118 require_once B_BLOCKS_DIR_PATH . 'includes/LicenseActivation.php';
119 }
120 class BBlocks {
121 protected static $_instance = null;
122
123 function __construct() {
124 add_action( 'init', [$this, 'onInit'] );
125 add_action( 'wp_ajax_bBlocksPipeChecker', [$this, 'bBlocksPipeChecker'] );
126 add_action( 'wp_ajax_nopriv_bBlocksPipeChecker', [$this, 'bBlocksPipeChecker'] );
127 add_action( 'admin_init', [$this, 'registerSettings'] );
128 add_action( 'rest_api_init', [$this, 'registerSettings'] );
129 add_filter( 'block_categories_all', [$this, 'registerCategories'] );
130 add_filter( 'upload_mimes', [$this, 'uploadMimes'] );
131 add_filter(
132 'wp_check_filetype_and_ext',
133 [$this, 'wpCheckFiletypeAndExt'],
134 10,
135 5
136 );
137 add_action( 'wp_ajax_b-blocks-enable-svg-mime-type', [$this, 'enableSvgMimeType'] );
138 add_filter(
139 'plugin_row_meta',
140 [$this, 'pluginRowMeta'],
141 10,
142 2
143 );
144 }
145
146 function pluginRowMeta( $plugin_meta, $plugin_file ) {
147 if ( strpos( $plugin_file, 'b-blocks' ) !== false && time() < strtotime( '2025-12-06' ) ) {
148 $new_links = array(
149 'deal' => "<a href='https://bblockswp.com/pricing/?from=plugins.php' target='_blank' style='font-weight: 600; color: #ff7a00;'>🎉 Black Friday Sale - Get up to 40% OFF Now!</a>",
150 );
151 $plugin_meta = array_merge( $plugin_meta, $new_links );
152 }
153 return $plugin_meta;
154 }
155
156 public static function instance() {
157 if ( self::$_instance === null ) {
158 self::$_instance = new self();
159 }
160 return self::$_instance;
161 }
162
163 function bBlocksPipeChecker() {
164 $nonce = sanitize_text_field( wp_unslash( $_POST['_wpnonce'] ?? null ) );
165 if ( !wp_verify_nonce( $nonce, 'wp_ajax' ) ) {
166 wp_send_json_error( 'Invalid Request' );
167 }
168 wp_send_json_success( [
169 'isPipe' => BBlocks\Inc\Utils::isPro(),
170 ] );
171 }
172
173 function onInit() {
174 $disabledBlocks = get_option( 'bBlocksDisabledBlocks', [] );
175 $disabledBlocks = ( is_array( $disabledBlocks ) ? $disabledBlocks : [] );
176 $premiumBlocks = ( BBlocks\Inc\Utils::isPro() ? [] : [
177 'b-blocks/logo-slider',
178 'b-blocks/content-ticker',
179 'b-blocks/image-hotspot',
180 'b-blocks/stacked-cards'
181 ] );
182 // Add dependent blocks
183 if ( in_array( 'b-blocks/row', $disabledBlocks ) && !in_array( 'b-blocks/column', $disabledBlocks ) ) {
184 $disabledBlocks[] = 'b-blocks/column';
185 }
186 if ( in_array( 'b-blocks/services', $disabledBlocks ) && !in_array( 'b-blocks/service', $disabledBlocks ) ) {
187 $disabledBlocks[] = 'b-blocks/service';
188 }
189 $blocks = [
190 'alert',
191 'advanced-image',
192 'animated-text',
193 'advanced-tabs',
194 'button',
195 'button-group',
196 'breadcrumb',
197 'cards',
198 'chart',
199 'column',
200 'container',
201 'content-ticker',
202 'countdown',
203 'counters',
204 // 'data-table',
205 'carousel',
206 'carousel-slide',
207 'dual-color-heading',
208 'emoji-stack-separator',
209 'facebook-embed',
210 'facebook-page',
211 'feature-boxes',
212 'flip-boxes',
213 'gif',
214 'form-builder',
215 'html',
216 'icon-box',
217 'image-comparison',
218 'image-gallery',
219 'image-hotspot',
220 'image-scroller',
221 'info-box',
222 'input-field',
223 'logo-slider',
224 'lottie-player',
225 'list',
226 'mailto',
227 'navigation',
228 'news-ticker',
229 'posts',
230 'price-lists',
231 'pricing-table',
232 'qr-code',
233 'row',
234 'section-heading',
235 'skill-bar',
236 'service',
237 'services',
238 'shape-divider',
239 'slider',
240 'scroll-to-top',
241 'social-share',
242 'star-rating',
243 'stacked-cards',
244 'svg-draw',
245 'table-of-content',
246 'td-viewer',
247 'team-members',
248 'testimonials',
249 'toggle-content',
250 'accordion-block',
251 'video',
252 'text-path',
253 ];
254 foreach ( $blocks as $block ) {
255 if ( !in_array( "b-blocks/{$block}", $disabledBlocks ) && !in_array( "b-blocks/{$block}", $premiumBlocks ) ) {
256 register_block_type( __DIR__ . "/build/{$block}" );
257 wp_deregister_script( "b-blocks-{$block}-editor-script" );
258 }
259 }
260 }
261
262 function registerSettings() {
263 register_setting( 'bBlocksUtils', 'bBlocksUtils', [
264 'show_in_rest' => [
265 'name' => 'bBlocksUtils',
266 'schema' => [
267 'type' => 'string',
268 ],
269 ],
270 'type' => 'string',
271 'default' => wp_json_encode( [
272 'nonce' => wp_create_nonce( 'wp_ajax' ),
273 ] ),
274 'sanitize_callback' => 'sanitize_text_field',
275 ] );
276 }
277
278 function registerCategories( $categories ) {
279 return array_merge( [[
280 'slug' => 'bBlocks',
281 'title' => __( 'bBlocks', 'b-blocks' ),
282 ]], $categories );
283 }
284
285 // Register categories
286 //Allow some additional file types for upload
287 function uploadMimes( $mimes ) {
288 $mimes['glb'] = 'model/gltf-binary';
289 // 3D Viewer
290 $mimes['gltf'] = 'model/gltf-binary';
291 // 3D Viewer
292 $mimes['json'] = 'application/json';
293 // Lottie Player
294 $mimes['lottie'] = 'application/json';
295 // Lottie Player
296 if ( get_transient( 'b-blocks-enable-svg-mime-type' ) === 'true' ) {
297 $mimes['svg'] = 'image/svg+xml';
298 }
299 return $mimes;
300 }
301
302 function wpCheckFiletypeAndExt(
303 $data,
304 $file,
305 $filename,
306 $mimes,
307 $real_mime = null
308 ) {
309 // If file extension is 2 or more
310 $f_sp = explode( '.', $filename );
311 $f_exp_count = count( $f_sp );
312 if ( $f_exp_count <= 1 ) {
313 return $data;
314 } else {
315 $f_name = $f_sp[0];
316 $ext = $f_sp[$f_exp_count - 1];
317 }
318 if ( $ext == 'glb' || $ext == 'gltf' ) {
319 // 3D Viewer
320 $type = 'model/gltf-binary';
321 $proper_filename = '';
322 return compact( 'ext', 'type', 'proper_filename' );
323 } else {
324 if ( $ext == 'json' || $ext === 'lottie' ) {
325 // Lottie Player
326 $type = 'application/json';
327 $proper_filename = '';
328 return compact( 'ext', 'type', 'proper_filename' );
329 } else {
330 return $data;
331 }
332 }
333 }
334
335 public function enableSvgMimeType() {
336 if ( !wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['_wpnonce'] ?? null ) ), 'wp_ajax' ) ) {
337 wp_send_json_error();
338 }
339 set_transient( 'b-blocks-enable-svg-mime-type', 'true', 80 );
340 wp_send_json_success();
341 }
342
343 }
344
345 BBlocks::instance();
346 }