PluginProbe
Gutenify – Visual Site Builder Blocks & Starter Templates / 1.8.0
Gutenify – Visual Site Builder Blocks & Starter Templates v1.8.0
1.9.0 1.8.0 1.7.0 1.6.6 1.6.5 1.6.4 trunk 0.0.1 0.0.2 0.0.3 1.0.0 1.0.1 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 1.1.2 1.1.3 1.1.4 All 74 releases
gutenify / core / inc / blocks / class-slider-blocks.php

class-slider-blocks.php in Gutenify – Visual Site Builder Blocks & Starter Templates 1.8.0, at core/inc/blocks/class-slider-blocks.php

94 lines 3.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace gutenify;
3
4 defined( 'ABSPATH' ) || exit;
5
6 class Extend_Slider_Blocks {
7 public static function init() {
8 add_filter( 'gutenify_render_block', array( __CLASS__, 'render_block_slider' ), 10, 4 );
9 }
10
11 public static function render_block_slider( $block_content, $block, $instance, $block_id ) {
12 if ( empty( $block['blockName'] ) || ! in_array( $block['blockName'], array( 'gutenify/advance-slider', 'gutenify/post-carousel', 'gutenify/wc-product-carousel', 'gutenify/gallery-carousel', 'gutenify/slider', 'gutenify/slider-v2' ) ) ) {
13 return $block_content;
14 }
15
16 $constants = Helpers::plugin_constants();
17 $plugin_main_slug = $constants['plugin_main_slug'];
18 $plugin_main_camel_case_name = $constants['plugin_main_camel_case_name'];
19
20 $handle = $plugin_main_slug . '-swiper';
21 // wp_enqueue_style( $handle );
22 // wp_enqueue_script( $handle );
23
24 $slider_var = 'slider_' . str_replace( '-', '_', $block_id );
25
26 $has_navigation = ! ( isset( $block['attrs']['blockAdvanceOptions']['hasNavigation'] ) && false === $block['attrs']['blockAdvanceOptions']['hasNavigation'] );
27 $has_pagination = ! ( isset( $block['attrs']['blockAdvanceOptions']['hasPagination'] ) && false === $block['attrs']['blockAdvanceOptions']['hasPagination'] );
28 $columns = ! empty( $instance->attributes['blockAdvanceOptions']['columns'] ) ? absint( $instance->attributes['blockAdvanceOptions']['columns'] ) : 1;
29 $columns = ! empty( $block['attrs']['blockAdvanceOptions']['columns'] ) ? absint( $block['attrs']['blockAdvanceOptions']['columns'] ) : $columns;
30
31 $loop = ! empty( $instance->attributes['loop'] );
32 $loop = ! empty( $block['attrs']['blockAdvanceOptions']['loop'] ) ? ( $block['attrs']['blockAdvanceOptions']['loop'] ) : $loop;
33
34 $settings = array();
35
36 // For Posts
37 if ( in_array( $block['blockName'], array( 'gutenify/post-carousel', 'gutenify/wc-product-carousel', 'gutenify/gallery-carousel', 'gutenify/slider', 'gutenify/slider-v2' ) ) ) {
38 $has_navigation = ! ( isset( $block['attrs']['hasNavigation'] ) && false === $block['attrs']['hasNavigation'] );
39 $has_pagination = ! ( isset( $block['attrs']['hasPagination'] ) && false === $block['attrs']['hasPagination'] );
40
41 $columns = ! empty( $instance->attributes['columns'] ) ? absint( $instance->attributes['columns'] ) : 1;
42 $columns = ! empty( $block['attrs']['columns'] ) ? absint( $block['attrs']['columns'] ) : $columns;
43
44 $loop = ! empty( $instance->attributes['loop'] );
45 $loop = ! empty( $block['attrs']['loop'] ) ? ( $block['attrs']['loop'] ) : $loop;
46
47 $spaceBetween = ! empty( $block['attrs']['spaceBetween'] ) ? absint( $block['attrs']['spaceBetween'] ) : $instance->attributes['spaceBetween'];
48
49 $settings['spaceBetween'] = $spaceBetween;
50 $loop = true;
51 }
52
53 $settings['loop'] = $loop;
54 $settings['slidesPerView'] = $columns;
55
56 if ( true === $has_navigation ) {
57 $settings['navigation'] = array(
58 'nextEl' => '.' . $block_id . ' .swiper-button-next',
59 'prevEl' => '.' . $block_id . ' .swiper-button-prev',
60 );
61 }
62
63 if ( true === $has_pagination ) {
64 $settings['pagination'] = array(
65 'el' => '.' . $block_id . ' .swiper-pagination',
66 'clickable' => true,
67 );
68 }
69
70 $settings = apply_filters( 'gutenify/slider/settings', $settings, $block_id, $block, $instance );
71
72 // error_log( print_r( $settings, true ));
73 wp_add_inline_script(
74 $handle,
75 '
76 document.addEventListener("DOMContentLoaded", function() {
77 var swiperSelector = document.querySelector( ".' . $block_id . '" );
78 if ( swiperSelector ) {
79 var swiper = gutenifyAdvancedSliderInit( ".' . $block_id . '", ' . json_encode( $settings ) . ' );
80 }
81 });
82 '
83 );
84
85 $block_content = new \WP_HTML_Tag_Processor( $block_content );
86 $block_content->next_tag();
87 $block_content->add_class( 'swiper' );
88
89 return $block_content->get_updated_html();
90 }
91 }
92
93 Extend_Slider_Blocks::init();
94