PluginProbe
GutenBee – Gutenberg Blocks / 2.20.2
GutenBee – Gutenberg Blocks v2.20.2
2.20.3 2.20.2 2.19.1 2.2.0 2.20.0 2.20.1 2.3.0 2.3.2 2.4.0 2.5.0 2.6.0 2.6.1 2.6.2 2.7.0 2.8.0 2.8.1 2.9.0 trunk 1.0.0 2.0.9 2.1.0 2.10.0 2.10.1 2.10.2 2.10.3 All 49 releases
gutenbee / gutenbee.php

gutenbee.php in GutenBee – Gutenberg Blocks 2.20.2, at gutenbee.php

587 lines 18.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugin Name: GutenBee
4 * Plugin URI: https://www.cssigniter.com/plugins/gutenbee/
5 * Description: Premium Blocks for WordPress
6 * Author: The CSSIgniter Team
7 * Author URI: https://www.cssigniter.com
8 * License: GPLv2 or later
9 * Version: 2.20.2
10 * Text Domain: gutenbee
11 * Domain Path: /languages
12 *
13 * GutenBee is free software: you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation, either version 2 of the License, or
16 * any later version.
17 *
18 * GutenBee is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with GutenBee. If not, see <http://www.gnu.org/licenses/>.
25 *
26 */
27
28 if ( ! defined( 'GUTENBEE_PLUGIN_VERSION' ) ) {
29 define( 'GUTENBEE_PLUGIN_VERSION', '2.20.2' );
30 }
31
32 if ( ! defined( 'GUTENBEE_PLUGIN_DIR' ) ) {
33 define( 'GUTENBEE_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
34 }
35
36 if ( ! defined( 'GUTENBEE_PLUGIN_DIR_URL' ) ) {
37 define( 'GUTENBEE_PLUGIN_DIR_URL', plugin_dir_url( __FILE__ ) );
38 }
39
40 add_action( 'enqueue_block_assets', 'gutenbee_enqueue_editor_assets' );
41 function gutenbee_enqueue_editor_assets() {
42 if ( ! is_admin() ) {
43 return;
44 }
45
46
47 wp_enqueue_script( 'gutenbee', untrailingslashit( GUTENBEE_PLUGIN_DIR_URL ) . '/build/gutenbee.build.js', array(
48 'wp-components',
49 'wp-blocks',
50 'wp-element',
51 'wp-block-editor',
52 'wp-data',
53 'wp-date',
54 'wp-i18n',
55 'wp-compose',
56 'wp-keycodes',
57 'wp-html-entities',
58 'wp-server-side-render',
59 'wp-dom',
60 'lodash',
61 'react',
62 'react-dom',
63 'jquery',
64 ), GUTENBEE_PLUGIN_VERSION, true );
65
66 wp_localize_script( 'gutenbee', '__GUTENBEE_SETTINGS__', array_merge( gutenbee_get_settings(), array(
67 'plugin' => array(
68 'settings' => array(
69 'active_animation-controls' => gutenbee_get_settings()['active_animation-controls'],
70 ),
71 ),
72 'blocks' => array(
73 'post_types' => array(
74 'excluded_post_types' => apply_filters( 'gutenbee_block_post_types_excluded_post_types', array(
75 'attachment',
76 'wp_block',
77 'elementor_library',
78 'wp_template',
79 'maxslider_slider',
80 'ignition-gsection',
81 'nav_menu_item',
82 'wp_template_part',
83 'wp_navigation',
84 ) ),
85 ),
86 ),
87 ) ) );
88
89 wp_enqueue_style( 'gutenbee-editor', untrailingslashit( GUTENBEE_PLUGIN_DIR_URL ) . '/build/gutenbee.build.css', array(
90 'wp-edit-blocks',
91 'dashicons',
92 ), GUTENBEE_PLUGIN_VERSION );
93 }
94
95 add_action( 'wp_enqueue_scripts', 'gutenbee_enqueue_frontend_block_assets' );
96 function gutenbee_enqueue_frontend_block_assets() {
97 $gutenbee_settings = gutenbee_get_settings();
98 $maps_api_key = $gutenbee_settings['google_maps_api_key'];
99
100 $enqueue_css = false;
101 $enqueue_js = false;
102 $enqueue_maps_api = false;
103
104 foreach ( gutenbee_get_blocks_info() as $block_name => $block_info ) {
105 if ( has_block( $block_name ) || gutenbee_has_block_in_reusable( $block_name ) ) {
106 if ( ! $enqueue_css && $block_info['enqueue_css'] ) {
107 $enqueue_css = true;
108 }
109 if ( ! $enqueue_js && $block_info['enqueue_js'] ) {
110 $enqueue_js = true;
111 }
112 if ( 'gutenbee/google-maps' === $block_name ) {
113 $enqueue_maps_api = true;
114 }
115 }
116 }
117
118 if ( $maps_api_key && apply_filters( 'gutenbee_enqueue_google_maps_api', $enqueue_maps_api ) ) {
119 wp_enqueue_script( 'gutenbee-google-maps', 'https://maps.googleapis.com/maps/api/js?key=' . $maps_api_key .'&v=weekly&libraries=marker', array(), GUTENBEE_PLUGIN_VERSION, true );
120 }
121
122 if ( apply_filters( 'gutenbee_enqueue_frontend_styles', $enqueue_css ) ) {
123 wp_enqueue_style( 'gutenbee', untrailingslashit( GUTENBEE_PLUGIN_DIR_URL ) . '/build/gutenbee.scripts.css', array(), GUTENBEE_PLUGIN_VERSION );
124 }
125
126 if ( apply_filters( 'gutenbee_enqueue_frontend_scripts', $enqueue_js ) ) {
127 wp_enqueue_script( 'gutenbee-scripts', untrailingslashit( GUTENBEE_PLUGIN_DIR_URL ) . '/build/gutenbee.scripts.js', array(
128 'jquery',
129 ), GUTENBEE_PLUGIN_VERSION, true );
130
131 wp_localize_script( 'gutenbee-scripts', 'gutenbeeStrings', apply_filters( 'gutenbee_strings', array(
132 'image_comparison_before_label' => esc_html__( 'Before', 'gutenbee' ),
133 'image_comparison_after_label' => esc_html__( 'After', 'gutenbee' ),
134 ) ) );
135 }
136
137 if ( $gutenbee_settings['active_animation-controls'] ) {
138 wp_enqueue_style( 'gutenbee-animations', untrailingslashit( GUTENBEE_PLUGIN_DIR_URL ) . '/build/gutenbee.animations.css', array(), GUTENBEE_PLUGIN_VERSION );
139 wp_enqueue_script( 'gutenbee-animations', untrailingslashit( GUTENBEE_PLUGIN_DIR_URL ) . '/build/gutenbee.animations.js', array(), GUTENBEE_PLUGIN_VERSION, true );
140 }
141 }
142
143 add_action( 'admin_enqueue_scripts', 'gutenbee_admin_assets' );
144
145 function gutenbee_admin_assets() {
146 wp_enqueue_style( 'gutenbee-admin-styles', untrailingslashit( GUTENBEE_PLUGIN_DIR_URL ) . '/assets/css/admin.css', array(
147 'wp-color-picker',
148 ), GUTENBEE_PLUGIN_VERSION );
149 wp_enqueue_script( 'gutenbee-admin-scripts', untrailingslashit( GUTENBEE_PLUGIN_DIR_URL ) . '/assets/js/admin.js', array(
150 'wp-color-picker',
151 ), GUTENBEE_PLUGIN_VERSION, true );
152 }
153
154 // GutenBee's block category
155 global $wp_version;
156
157 // TODO: Remove the 'block_categories' filter when WordPress reaches 5.9
158 if ( version_compare( $wp_version, '5.8', '<' ) ) {
159 add_filter( 'block_categories', 'gutenbee_block_categories', 10, 2 );
160 } else {
161 add_filter( 'block_categories_all', 'gutenbee_block_categories', 10, 2 );
162 }
163 function gutenbee_block_categories( $categories, $post ) {
164 return array_merge( $categories, array(
165 array(
166 'slug' => 'gutenbee',
167 'title' => __( 'GutenBee', 'gutenbee' ),
168 ),
169 ) );
170 }
171
172 /**
173 * Returns a list of settings names and their corresponding labels.
174 * Note that the list may not contain all blocks. E.g. google-maps
175 *
176 * @return array
177 */
178 function gutenbee_get_setting_block_names() {
179 // Setting keys here for each block MUST be the same slugs
180 // used in the block's registration definition (check each block's
181 // index.js file, after `gutenbee/XYZ`, XYZ is the block's key).
182 return array(
183 'accordion' => __( 'Accordion Block', 'gutenbee' ),
184 'banner' => __( 'Banner Block', 'gutenbee' ),
185 'buttons' => __( 'Button Block', 'gutenbee' ),
186 'container' => __( 'Container Block', 'gutenbee' ),
187 'countdown' => __( 'Countdown Block', 'gutenbee' ),
188 'countup' => __( 'Countup Block', 'gutenbee' ),
189 'divider' => __( 'Divider Block', 'gutenbee' ),
190 'food-menu' => __( 'Food Menu Block', 'gutenbee' ),
191 'heading' => __( 'Heading Block', 'gutenbee' ),
192 'icon' => __( 'Icon Block', 'gutenbee' ),
193 'iconbox' => __( 'Icon Box Block', 'gutenbee' ),
194 'icon-list' => __( 'Icon List Block', 'gutenbee' ),
195 'image' => __( 'Image Block', 'gutenbee' ),
196 'imagebox' => __( 'Image Box Block', 'gutenbee' ),
197 'image-comparison' => __( 'Image Comparison Block', 'gutenbee' ),
198 'justified-gallery' => __( 'Justified Gallery Block', 'gutenbee' ),
199 'paragraph' => __( 'Paragraph Block', 'gutenbee' ),
200 'post-types' => __( 'Post Types Block', 'gutenbee' ),
201 'progress-bar' => __( 'Progress Bar Block', 'gutenbee' ),
202 'review' => __( 'Review Block', 'gutenbee' ),
203 'spacer' => __( 'Spacer Block', 'gutenbee' ),
204 'slideshow' => __( 'Slideshow Block', 'gutenbee' ),
205 'tab-slider' => __( 'Tab Slider Block', 'gutenbee' ),
206 'tabs' => __( 'Tabs Block', 'gutenbee' ),
207 'testimonial' => __( 'Testimonial Block', 'gutenbee' ),
208 'video' => __( 'Video Block', 'gutenbee' ),
209 'video-embed' => __( 'Video Embed Block', 'gutenbee' ),
210 );
211 }
212
213 /**
214 * Returns a list of blocks and information about them.
215 *
216 * @return array
217 */
218 function gutenbee_get_blocks_info() {
219 return array(
220 'gutenbee/accordion' => array(
221 'label' => __( 'Accordion Block', 'gutenbee' ),
222 'enqueue_js' => true,
223 'enqueue_css' => true,
224 ),
225 'gutenbee/banner' => array(
226 'label' => __( 'Banner Block', 'gutenbee' ),
227 'enqueue_js' => true,
228 'enqueue_css' => true,
229 ),
230 'gutenbee/button' => array(
231 'label' => __( 'Button Block', 'gutenbee' ),
232 'enqueue_js' => false,
233 'enqueue_css' => true,
234 ),
235 'gutenbee/buttons' => array(
236 'label' => __( 'Buttons Block', 'gutenbee' ),
237 'enqueue_js' => false,
238 'enqueue_css' => true,
239 ),
240 'gutenbee/container' => array(
241 'label' => __( 'Container Block', 'gutenbee' ),
242 'enqueue_js' => true,
243 'enqueue_css' => true,
244 ),
245 'gutenbee/column' => array(
246 'label' => __( 'Column Block', 'gutenbee' ),
247 'enqueue_js' => false,
248 'enqueue_css' => true,
249 ),
250 'gutenbee/countdown' => array(
251 'label' => __( 'Countdown Block', 'gutenbee' ),
252 'enqueue_js' => true,
253 'enqueue_css' => true,
254 ),
255 'gutenbee/countup' => array(
256 'label' => __( 'Countup Block', 'gutenbee' ),
257 'enqueue_js' => true,
258 'enqueue_css' => true,
259 ),
260 'gutenbee/divider' => array(
261 'label' => __( 'Divider Block', 'gutenbee' ),
262 'enqueue_js' => true,
263 'enqueue_css' => true,
264 ),
265 'gutenbee/google-maps' => array(
266 'label' => __( 'Google Map Block', 'gutenbee' ),
267 'enqueue_js' => true,
268 'enqueue_css' => true,
269 ),
270 'gutenbee/heading' => array(
271 'label' => __( 'Heading Block', 'gutenbee' ),
272 'enqueue_js' => false,
273 'enqueue_css' => true,
274 ),
275 'gutenbee/icon' => array(
276 'label' => __( 'Icon Block', 'gutenbee' ),
277 'enqueue_js' => false,
278 'enqueue_css' => true,
279 ),
280 'gutenbee/iconbox' => array(
281 'label' => __( 'Icon Box Block', 'gutenbee' ),
282 'enqueue_js' => false,
283 'enqueue_css' => true,
284 ),
285 'gutenbee/icon-list' => array(
286 'label' => __( 'Icon List Block', 'gutenbee' ),
287 'enqueue_js' => false,
288 'enqueue_css' => true,
289 ),
290 'gutenbee/image' => array(
291 'label' => __( 'Image Block', 'gutenbee' ),
292 'enqueue_js' => false,
293 'enqueue_css' => true,
294 ),
295 'gutenbee/imagebox' => array(
296 'label' => __( 'Image Box Block', 'gutenbee' ),
297 'enqueue_js' => false,
298 'enqueue_css' => true,
299 ),
300 'gutenbee/image-comparison' => array(
301 'label' => __( 'Image Comparison Block', 'gutenbee' ),
302 'enqueue_js' => true,
303 'enqueue_css' => true,
304 ),
305 'gutenbee/justified-gallery' => array(
306 'label' => __( 'Justified Gallery Block', 'gutenbee' ),
307 'enqueue_js' => true,
308 'enqueue_css' => true,
309 ),
310 'gutenbee/paragraph' => array(
311 'label' => __( 'Paragraph Block', 'gutenbee' ),
312 'enqueue_js' => false,
313 'enqueue_css' => true,
314 ),
315 'gutenbee/post-types' => array(
316 'label' => __( 'Post Types Block', 'gutenbee' ),
317 'enqueue_js' => true,
318 'enqueue_css' => true,
319 ),
320 'gutenbee/progress-bar' => array(
321 'label' => __( 'Progress Block', 'gutenbee' ),
322 'enqueue_js' => false,
323 'enqueue_css' => true,
324 ),
325 'gutenbee/review' => array(
326 'label' => __( 'Review Block', 'gutenbee' ),
327 'enqueue_js' => false,
328 'enqueue_css' => true,
329 ),
330 'gutenbee/slideshow' => array(
331 'label' => __( 'Slideshow Block', 'gutenbee' ),
332 'enqueue_js' => true,
333 'enqueue_css' => true,
334 ),
335 'gutenbee/spacer' => array(
336 'label' => __( 'Spacer Block', 'gutenbee' ),
337 'enqueue_js' => true,
338 'enqueue_css' => true,
339 ),
340 // 'gutenbee/tab-slider' => array(
341 // 'label' => __( 'Tab Slider Block', 'gutenbee' ),
342 // 'enqueue_js' => true,
343 // 'enqueue_css' => true,
344 // ),
345 'gutenbee/tabs' => array(
346 'label' => __( 'Tabs Block', 'gutenbee' ),
347 'enqueue_js' => true,
348 'enqueue_css' => true,
349 ),
350 'gutenbee/testimonial' => array(
351 'label' => __( 'Testimonial Block', 'gutenbee' ),
352 'enqueue_js' => false,
353 'enqueue_css' => true,
354 ),
355 'gutenbee/video' => array(
356 'label' => __( 'Video Block', 'gutenbee' ),
357 'enqueue_js' => false,
358 'enqueue_css' => true,
359 ),
360 'gutenbee/video-embed' => array(
361 'label' => __( 'Video Embed Block', 'gutenbee' ),
362 'enqueue_js' => true,
363 'enqueue_css' => true,
364 ),
365 'gutenbee/food-menu' => array(
366 'label' => __( 'Food Menu', 'gutenbee' ),
367 'enqueue_js' => false,
368 'enqueue_css' => true,
369 ),
370 );
371 }
372
373 /**
374 * Returns the plugin's settings array.
375 *
376 * @return array
377 */
378 function gutenbee_get_settings() {
379 $settings = get_option( 'gutenbee_settings' );
380 $general_settings = get_option( 'gutenbee_general_settings' );
381
382 if ( $settings && $general_settings ) {
383 $settings = array_merge( $settings, $general_settings );
384 } elseif ( $general_settings ) {
385 $settings = $general_settings;
386 }
387
388 $settings = gutenbee_validate_settings( $settings );
389
390 /**
391 * Filters the plugin's settings values.
392 *
393 * @since 2.6.2
394 *
395 * @param array $settings
396 *
397 * @hooked ignition_module_accommodation_add_cpt_to_array - 10
398 */
399 $settings = apply_filters( 'gutenbee_settings', $settings );
400
401 return $settings;
402 }
403
404 /**
405 * Makes sure there are no undefined indexes in the settings array.
406 * Use before using a setting value. Eleminates the need for isset() before using.
407 *
408 * @param $settings
409 *
410 * @return array
411 */
412 function gutenbee_validate_settings( $settings ) {
413 $defaults = array(
414 'active_google-maps' => 1,
415 'google_maps_api_key' => '',
416 'active_high-contrast' => 0,
417 'high-contrast-color' => '#ffff00',
418 'active_editor-width' => 0,
419 'editor-width-value' => 680,
420 'active_animation-controls' => 1,
421 );
422
423 foreach ( gutenbee_get_setting_block_names() as $id => $name ) {
424 $defaults[ 'active_' . $id ] = 1;
425 }
426
427 $settings = wp_parse_args( $settings, $defaults );
428
429 $settings['theme_supports']['post-types'] = gutenbee_block_post_types_get_theme_support();
430 $settings['theme_supports']['container'] = gutenbee_block_container_get_theme_support();
431
432 return $settings;
433 }
434
435 /**
436 * Returns the appropriate page(d) query variable to use in custom loops (needed for pagination).
437 *
438 * @uses get_query_var()
439 *
440 * @param int $default_return The default page number to return, if no query vars are set.
441 *
442 * @return int The appropriate paged value if found, else 0.
443 */
444 function gutenbee_get_page_var( $default_return = 0 ) {
445 $paged = get_query_var( 'paged', false );
446 $page = get_query_var( 'page', false );
447
448 if ( false === $paged && false === $page ) {
449 return $default_return;
450 }
451
452 return max( $paged, $page );
453 }
454
455
456 /**
457 * Returns the HTML classes needed depending on the number of columns passed.
458 *
459 * @param int $columns Number of columns.
460 * @param array $attributes Optional. Array of block attributes.
461 *
462 * @return mixed|void
463 */
464 function gutenbee_get_columns_classes( $columns, $attributes = array() ) {
465 switch ( intval( $columns ) ) {
466 case 1:
467 $classes = 'columns-1';
468 break;
469 case 2:
470 $classes = 'columns-2';
471 break;
472 case 3:
473 $classes = 'columns-3';
474 break;
475 case 4:
476 default:
477 $classes = 'columns-4';
478 break;
479 }
480
481 return apply_filters( 'gutenbee_get_columns_classes', $classes, (int) $columns, $attributes );
482 }
483
484 function gutenbee_get_template_part( $block, $slug, $name = '', $args = array() ) {
485 $templates = array();
486 $name = (string) $name;
487 if ( '' !== $name ) {
488 $templates[] = "{$slug}-{$name}.php";
489 }
490
491 $templates[] = "{$slug}.php";
492
493 $located = gutenbee_locate_template( $block, $templates, $args );
494
495 if ( ! empty( $located ) ) {
496 include $located;
497 }
498 }
499
500 function gutenbee_locate_template( $block, $templates, $args ) {
501 $plugin_path = plugin_dir_path( __FILE__ );
502
503 // The templates path in the plugin, i.e. defaults/fallback. E.g. src/blocks/post-types/templates/
504 $default_path = trailingslashit( trailingslashit( $plugin_path ) . "inc/blocks/{$block}/templates" );
505
506 // The templates path in the theme. E.g. gutenbee/
507 $theme_path = apply_filters( 'gutenbee_locate_template_theme_path', "gutenbee/{$block}", $block );
508 $theme_path = trailingslashit( $theme_path );
509
510 $theme_templates = array();
511 foreach ( $templates as $template ) {
512 $theme_templates[] = $theme_path . $template;
513 }
514
515 // Try to find a theme-overridden template.
516 $located = locate_template( $theme_templates, false );
517
518 $located = apply_filters( 'gutenbee_locate_template', $located, $block, $theme_templates, $templates, $theme_path, $default_path, $args );
519
520 if ( empty( $located ) ) {
521 // Nope. Try the plugin templates instead.
522 foreach ( $templates as $template ) {
523 if ( file_exists( $default_path . $template ) ) {
524 $located = $default_path . $template;
525 break;
526 }
527 }
528 }
529
530 return $located;
531 }
532
533 /**
534 * Checks the content for existence of blocks by $block_name inside reusable blocks.
535 *
536 * @link https://github.com/WordPress/gutenberg/issues/18272#issuecomment-566179633
537 *
538 * @param string $block_name
539 * @param int|false $id Optional. Post ID. Defaults to the ID of the global $post object.
540 *
541 * @return bool
542 */
543 function gutenbee_has_block_in_reusable( $block_name, $id = false ) {
544 $id = ( ! $id ) ? get_the_ID() : $id;
545 if ( $id ) {
546 if ( has_block( 'core/block', $id ) ) {
547 // Check for reusable blocks
548 $content = get_post_field( 'post_content', $id );
549 $blocks = parse_blocks( $content );
550
551 if ( ! is_array( $blocks ) || empty( $blocks ) ) {
552 return false;
553 }
554
555 foreach ( $blocks as $block ) {
556 if ( 'core/block' === $block['blockName'] && ! empty( $block['attrs']['ref'] ) ) {
557 if ( has_block( $block_name, $block['attrs']['ref'] ) ) {
558 return true;
559 }
560 }
561 }
562 }
563 }
564
565 return false;
566 }
567
568 add_filter( 'plugin_action_links_gutenbee/gutenbee.php', 'gutenbee_settings_link' );
569 function gutenbee_settings_link( $links ) {
570 $action_links = array(
571 'settings' => '<a href="' . admin_url( 'admin.php?page=gutenbee' ) . '" aria-label="' . esc_attr__( 'View GutenBee settings', 'gutenbee' ) . '">' . esc_html__( 'Settings', 'gutenbee' ) . '</a>',
572 );
573
574 return array_merge( $action_links, $links );
575 }
576
577 add_filter( 'excerpt_allowed_blocks', 'gutenbee_filter_excerpt_allowed_blocks' );
578 function gutenbee_filter_excerpt_allowed_blocks( $allowed_blocks ) {
579 $allowed_blocks = array_merge( $allowed_blocks, array( 'gutenbee/paragraph' ) );
580
581 return $allowed_blocks;
582 }
583
584 require_once untrailingslashit( dirname( __FILE__ ) ) . '/inc/options.php';
585 require_once untrailingslashit( dirname( __FILE__ ) ) . '/inc/blocks/container/block.php';
586 require_once untrailingslashit( dirname( __FILE__ ) ) . '/inc/blocks/post-types/block.php';
587