PluginProbe ʕ •ᴥ•ʔ
FrontBlocks for Gutenberg/GeneratePress / trunk
FrontBlocks for Gutenberg/GeneratePress vtrunk
trunk 0.2.0 0.2.1 0.2.2 0.2.3 0.2.4 0.2.5 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.1.0 1.2.0 1.2.1 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 ci-artifacts
frontblocks / includes / Frontend / Carousel.php
frontblocks / includes / Frontend Last commit date
Animations.php 1 month ago BackButton.php 7 months ago BeforeAfter.php 1 month ago BlockPatterns.php 4 months ago Carousel.php 1 week ago ColumnsSameHeight.php 1 week ago ContainerEdgeAlignment.php 1 month ago Counter.php 1 month ago DownloadButton.php 1 week ago Events.php 1 month ago FaqSchema.php 1 week ago FluidTypography.php 1 month ago Gallery.php 8 months ago GravityFormsInline.php 1 month ago Headline.php 1 month ago InsertPost.php 1 month ago ProductCategories.php 1 month ago ReadingProgress.php 7 months ago ReadingTime.php 8 months ago ShapeAnimations.php 1 month ago StackedImages.php 4 months ago StickyColumn.php 1 month ago SvgUpload.php 1 month ago Testimonials.php 8 months ago TextAnimation.php 1 month ago UserText.php 1 month ago
Carousel.php
644 lines
1 <?php
2 /**
3 * Carousel module for FrontBlocks.
4 *
5 * @package FrontBlocks
6 * @author David Perez <david@close.technology>
7 * @copyright 2023 Closemarketing
8 * @version 1.0
9 */
10
11 namespace FrontBlocks\Frontend;
12
13 defined( 'ABSPATH' ) || exit;
14
15 /**
16 * Carousel class.
17 *
18 * @since 1.0.0
19 */
20 class Carousel {
21
22 /**
23 * Constructor.
24 */
25 public function __construct() {
26 $this->init_hooks();
27 }
28
29 /**
30 * Initialize hooks.
31 *
32 * @return void
33 */
34 private function init_hooks() {
35 add_action( 'init', array( $this, 'register_frontend_assets' ) );
36 add_action( 'enqueue_block_editor_assets', array( $this, 'enqueue_block_editor_assets' ) );
37 add_action( 'enqueue_block_assets', array( $this, 'enqueue_block_canvas_assets' ) );
38 add_filter( 'render_block_generateblocks/grid', array( $this, 'add_custom_attributes_to_grid_block' ), 10, 2 );
39 add_filter( 'render_block_generateblocks/element', array( $this, 'add_custom_attributes_to_element_block' ), 10, 2 );
40 add_filter( 'render_block_core/group', array( $this, 'add_custom_attributes_to_core_group_block' ), 10, 2 );
41 add_filter( 'render_block_core/query', array( $this, 'add_custom_attributes_to_query_block' ), 10, 2 );
42 add_action( 'init', array( $this, 'register_custom_attributes' ), 5 );
43 }
44
45 /**
46 * Register frontend carousel assets for conditional enqueueing.
47 *
48 * @return void
49 */
50 public function register_frontend_assets() {
51 // Assets are registered in Plugin_Main::register_scripts().
52 // This method exists as a hook point for any additional registration needs.
53 }
54
55 /**
56 * Enqueue carousel frontend assets when a carousel block is detected.
57 *
58 * @return void
59 */
60 private function enqueue_carousel_assets() {
61 if ( ! wp_style_is( 'frontblocks-carousel', 'enqueued' ) ) {
62 wp_enqueue_style( 'frontblocks-carousel' );
63 }
64 if ( ! wp_script_is( 'frontblocks-carousel-custom', 'enqueued' ) ) {
65 wp_enqueue_script( 'frontblocks-carousel-custom' );
66 }
67 }
68
69 /**
70 * Enqueue carousel CSS in the editor canvas (iframe).
71 *
72 * @return void
73 */
74 public function enqueue_block_canvas_assets() {
75 if ( ! is_admin() ) {
76 return;
77 }
78 wp_enqueue_style(
79 'frontblocks-carousel-editor',
80 FRBL_PLUGIN_URL . 'assets/carousel/frontblocks-carousel-editor.css',
81 array(),
82 FRBL_VERSION
83 );
84 }
85
86 /**
87 * Enqueue block editor assets.
88 *
89 * @return void
90 */
91 public function enqueue_block_editor_assets() {
92 wp_enqueue_script(
93 'frontblocks-advanced-option',
94 FRBL_PLUGIN_URL . 'assets/carousel/frontblocks-advanced-option.js',
95 array( 'wp-blocks', 'wp-element', 'wp-components', 'wp-data', 'wp-edit-post' ),
96 FRBL_VERSION,
97 true
98 );
99
100 // Set script translations for JavaScript.
101 wp_set_script_translations(
102 'frontblocks-advanced-option',
103 'frontblocks'
104 );
105 }
106
107 /**
108 * Add custom attributes to grid block.
109 *
110 * @param string $block_content Block content.
111 * @param array $block Block attributes.
112 * @return string
113 */
114 public function add_custom_attributes_to_grid_block( $block_content, $block ) {
115 $attrs = $block['attrs'] ?? array();
116 $custom_option = isset( $attrs['frblGridOption'] ) ? sanitize_text_field( $attrs['frblGridOption'] ) : '';
117 $items_to_view = isset( $attrs['frblItemsToView'] ) ? (int) $attrs['frblItemsToView'] : 4;
118 $laptop_to_view = isset( $attrs['frblLaptopToView'] ) ? (int) $attrs['frblLaptopToView'] : 3;
119 $tablet_to_view = isset( $attrs['frblTabletToView'] ) ? (int) $attrs['frblTabletToView'] : 2;
120 $responsive_to_view = isset( $attrs['frblResponsiveToView'] ) ? (int) $attrs['frblResponsiveToView'] : 1;
121 $autoplay = isset( $attrs['frblAutoplay'] ) ? ( (int) $attrs['frblAutoplay'] * 1000 ) : '';
122 $gap = isset( $attrs['frblGap'] ) && '' !== $attrs['frblGap'] ? (int) $attrs['frblGap'] : 20;
123 $rewind = isset( $attrs['frblRewind'] ) ? (bool) $attrs['frblRewind'] : true;
124 $buttons = isset( $attrs['frblButtons'] ) ? sanitize_text_field( $attrs['frblButtons'] ) : 'arrows';
125 $button_color = isset( $attrs['frblButtonColor'] ) ? sanitize_text_field( $attrs['frblButtonColor'] ) : '';
126 $button_bg_color = isset( $attrs['frblButtonBgColor'] ) ? sanitize_text_field( $attrs['frblButtonBgColor'] ) : '';
127 $buttons_position = isset( $attrs['frblButtonsPosition'] ) ? sanitize_text_field( $attrs['frblButtonsPosition'] ) : 'side';
128 $arrow_left_url = isset( $attrs['frblArrowLeftUrl'] ) ? esc_url_raw( $attrs['frblArrowLeftUrl'] ) : '';
129 $arrow_right_url = isset( $attrs['frblArrowRightUrl'] ) ? esc_url_raw( $attrs['frblArrowRightUrl'] ) : '';
130 $disable_on_desktop = isset( $attrs['frblDisableOnDesktop'] ) ? (bool) $attrs['frblDisableOnDesktop'] : false;
131
132 // Add data attributes to the wrapper div if carousel is enabled.
133 if ( 'carousel' === $custom_option || 'slider' === $custom_option ) {
134 $attributes = '';
135 if ( 'slider' === $custom_option ) {
136 $attributes .= ' data-rewind="' . esc_attr( $rewind ) . '"';
137 }
138
139 // Add data attributes and the 'frontblocks-carousel' class to the first div in the block content.
140 $block_content = preg_replace(
141 '/<div([^>]*)class="([^"]*gb-grid-wrapper[^"]*)"([^>]*)>/',
142 '<div$1class="$2 frontblocks-carousel"$3' .
143 ' data-type="' . esc_attr( $custom_option ) . '"' .
144 ' data-view="' . esc_attr( $items_to_view ) . '"' .
145 ' data-laptop-view="' . esc_attr( $laptop_to_view ) . '"' .
146 ' data-tablet-view="' . esc_attr( $tablet_to_view ) . '"' .
147 ' data-mobile-view="' . esc_attr( $responsive_to_view ) . '"' .
148 ' data-autoplay="' . esc_attr( $autoplay ) . '"' .
149 ' data-gap="' . esc_attr( $gap ) . '"' .
150 ' data-buttons="' . esc_attr( $buttons ) . '"' .
151 ' data-buttons-color="' . esc_attr( $button_color ) . '"' .
152 ' data-buttons-background-color="' . esc_attr( $button_bg_color ) . '"' .
153 ' data-buttons-position="' . esc_attr( $buttons_position ) . '"' .
154 ( $arrow_left_url ? ' data-arrow-left-url="' . esc_url( $arrow_left_url ) . '"' : '' ) .
155 ( $arrow_right_url ? ' data-arrow-right-url="' . esc_url( $arrow_right_url ) . '"' : '' ) .
156 ' data-disable-on-desktop="' . esc_attr( $disable_on_desktop ? 'true' : 'false' ) . '"' .
157 $attributes .
158 '>',
159 $block_content,
160 1 // Only replace the first occurrence.
161 );
162
163 $this->enqueue_carousel_assets();
164 }
165
166 return $block_content;
167 }
168
169 /**
170 * Add custom attributes to element block.
171 *
172 * @param string $block_content Block content.
173 * @param array $block Block attributes.
174 * @return string
175 */
176 public function add_custom_attributes_to_element_block( $block_content, $block ) {
177 $attrs = $block['attrs'] ?? array();
178
179 // Check if this element has grid display.
180 $styles = $attrs['styles'] ?? array();
181 $display = $styles['display'] ?? '';
182
183 // Only process if it's a grid element.
184 if ( 'grid' !== $display ) {
185 return $block_content;
186 }
187
188 $custom_option = isset( $attrs['frblGridOption'] ) ? sanitize_text_field( $attrs['frblGridOption'] ) : '';
189 $items_to_view = isset( $attrs['frblItemsToView'] ) ? (int) $attrs['frblItemsToView'] : 4;
190 $laptop_to_view = isset( $attrs['frblLaptopToView'] ) ? (int) $attrs['frblLaptopToView'] : 3;
191 $tablet_to_view = isset( $attrs['frblTabletToView'] ) ? (int) $attrs['frblTabletToView'] : 2;
192 $responsive_to_view = isset( $attrs['frblResponsiveToView'] ) ? (int) $attrs['frblResponsiveToView'] : 1;
193 $autoplay = isset( $attrs['frblAutoplay'] ) ? ( (int) $attrs['frblAutoplay'] * 1000 ) : '';
194 $gap = isset( $attrs['frblGap'] ) && '' !== $attrs['frblGap'] ? (int) $attrs['frblGap'] : 20;
195 $rewind = isset( $attrs['frblRewind'] ) ? (bool) $attrs['frblRewind'] : true;
196 $buttons = isset( $attrs['frblButtons'] ) ? sanitize_text_field( $attrs['frblButtons'] ) : 'arrows';
197 $button_color = isset( $attrs['frblButtonColor'] ) ? sanitize_text_field( $attrs['frblButtonColor'] ) : '';
198 $button_bg_color = isset( $attrs['frblButtonBgColor'] ) ? sanitize_text_field( $attrs['frblButtonBgColor'] ) : '';
199 $buttons_position = isset( $attrs['frblButtonsPosition'] ) ? sanitize_text_field( $attrs['frblButtonsPosition'] ) : 'side';
200 $arrow_left_url = isset( $attrs['frblArrowLeftUrl'] ) ? esc_url_raw( $attrs['frblArrowLeftUrl'] ) : '';
201 $arrow_right_url = isset( $attrs['frblArrowRightUrl'] ) ? esc_url_raw( $attrs['frblArrowRightUrl'] ) : '';
202 $disable_on_desktop = isset( $attrs['frblDisableOnDesktop'] ) ? (bool) $attrs['frblDisableOnDesktop'] : false;
203
204 // Add data attributes to the wrapper div if carousel is enabled.
205 if ( 'carousel' === $custom_option || 'slider' === $custom_option ) {
206 $attributes = '';
207 if ( 'slider' === $custom_option ) {
208 $attributes .= ' data-rewind="' . esc_attr( $rewind ) . '"';
209 }
210
211 // Add data attributes and the 'frontblocks-carousel' class to the first div in the block content.
212 $block_content = preg_replace(
213 '/<div([^>]*)class="([^"]*gb-element-[^"]*)"([^>]*)>/',
214 '<div$1class="$2 frontblocks-carousel"$3' .
215 ' data-type="' . esc_attr( $custom_option ) . '"' .
216 ' data-view="' . esc_attr( $items_to_view ) . '"' .
217 ' data-laptop-view="' . esc_attr( $laptop_to_view ) . '"' .
218 ' data-tablet-view="' . esc_attr( $tablet_to_view ) . '"' .
219 ' data-mobile-view="' . esc_attr( $responsive_to_view ) . '"' .
220 ' data-autoplay="' . esc_attr( $autoplay ) . '"' .
221 ' data-gap="' . esc_attr( $gap ) . '"' .
222 ' data-buttons="' . esc_attr( $buttons ) . '"' .
223 ' data-buttons-color="' . esc_attr( $button_color ) . '"' .
224 ' data-buttons-background-color="' . esc_attr( $button_bg_color ) . '"' .
225 ' data-buttons-position="' . esc_attr( $buttons_position ) . '"' .
226 ( $arrow_left_url ? ' data-arrow-left-url="' . esc_url( $arrow_left_url ) . '"' : '' ) .
227 ( $arrow_right_url ? ' data-arrow-right-url="' . esc_url( $arrow_right_url ) . '"' : '' ) .
228 ' data-disable-on-desktop="' . esc_attr( $disable_on_desktop ? 'true' : 'false' ) . '"' .
229 $attributes .
230 '>',
231 $block_content,
232 1 // Only replace the first occurrence.
233 );
234
235 $this->enqueue_carousel_assets();
236 }
237
238 return $block_content;
239 }
240
241 /**
242 * Add custom attributes to core/group block.
243 *
244 * @param string $block_content Block content.
245 * @param array $block Block attributes.
246 * @return string
247 */
248 public function add_custom_attributes_to_core_group_block( $block_content, $block ) {
249 $attrs = $block['attrs'] ?? array();
250
251 // Check if this group has grid layout.
252 $layout = $attrs['layout'] ?? array();
253 $layout_type = $layout['type'] ?? '';
254
255 // Only process if it's a grid layout.
256 if ( 'grid' !== $layout_type ) {
257 return $block_content;
258 }
259
260 $custom_option = isset( $attrs['frblGridOption'] ) ? sanitize_text_field( $attrs['frblGridOption'] ) : '';
261 $items_to_view = isset( $attrs['frblItemsToView'] ) ? (int) $attrs['frblItemsToView'] : 4;
262 $laptop_to_view = isset( $attrs['frblLaptopToView'] ) ? (int) $attrs['frblLaptopToView'] : 3;
263 $tablet_to_view = isset( $attrs['frblTabletToView'] ) ? (int) $attrs['frblTabletToView'] : 2;
264 $responsive_to_view = isset( $attrs['frblResponsiveToView'] ) ? (int) $attrs['frblResponsiveToView'] : 1;
265 $autoplay = isset( $attrs['frblAutoplay'] ) ? ( (int) $attrs['frblAutoplay'] * 1000 ) : '';
266 $gap = isset( $attrs['frblGap'] ) && '' !== $attrs['frblGap'] ? (int) $attrs['frblGap'] : 20;
267 $rewind = isset( $attrs['frblRewind'] ) ? (bool) $attrs['frblRewind'] : true;
268 $buttons = isset( $attrs['frblButtons'] ) ? sanitize_text_field( $attrs['frblButtons'] ) : 'arrows';
269 $button_color = isset( $attrs['frblButtonColor'] ) ? sanitize_text_field( $attrs['frblButtonColor'] ) : '';
270 $button_bg_color = isset( $attrs['frblButtonBgColor'] ) ? sanitize_text_field( $attrs['frblButtonBgColor'] ) : '';
271 $buttons_position = isset( $attrs['frblButtonsPosition'] ) ? sanitize_text_field( $attrs['frblButtonsPosition'] ) : 'side';
272 $arrow_left_url = isset( $attrs['frblArrowLeftUrl'] ) ? esc_url_raw( $attrs['frblArrowLeftUrl'] ) : '';
273 $arrow_right_url = isset( $attrs['frblArrowRightUrl'] ) ? esc_url_raw( $attrs['frblArrowRightUrl'] ) : '';
274 $disable_on_desktop = isset( $attrs['frblDisableOnDesktop'] ) ? (bool) $attrs['frblDisableOnDesktop'] : false;
275
276 // Add data attributes to the wrapper div if carousel is enabled.
277 if ( 'carousel' === $custom_option || 'slider' === $custom_option ) {
278 $attributes = '';
279 if ( 'slider' === $custom_option ) {
280 $attributes .= ' data-rewind="' . esc_attr( $rewind ) . '"';
281 }
282
283 // Add data attributes and the 'frontblocks-carousel' class to the first div in the block content.
284 $block_content = preg_replace(
285 '/<div([^>]*)class="([^"]*wp-block-group[^"]*)"([^>]*)>/',
286 '<div$1class="$2 frontblocks-carousel"$3' .
287 ' data-type="' . esc_attr( $custom_option ) . '"' .
288 ' data-view="' . esc_attr( $items_to_view ) . '"' .
289 ' data-laptop-view="' . esc_attr( $laptop_to_view ) . '"' .
290 ' data-tablet-view="' . esc_attr( $tablet_to_view ) . '"' .
291 ' data-mobile-view="' . esc_attr( $responsive_to_view ) . '"' .
292 ' data-autoplay="' . esc_attr( $autoplay ) . '"' .
293 ' data-gap="' . esc_attr( $gap ) . '"' .
294 ' data-buttons="' . esc_attr( $buttons ) . '"' .
295 ' data-buttons-color="' . esc_attr( $button_color ) . '"' .
296 ' data-buttons-background-color="' . esc_attr( $button_bg_color ) . '"' .
297 ' data-buttons-position="' . esc_attr( $buttons_position ) . '"' .
298 ( $arrow_left_url ? ' data-arrow-left-url="' . esc_url( $arrow_left_url ) . '"' : '' ) .
299 ( $arrow_right_url ? ' data-arrow-right-url="' . esc_url( $arrow_right_url ) . '"' : '' ) .
300 ' data-disable-on-desktop="' . esc_attr( $disable_on_desktop ? 'true' : 'false' ) . '"' .
301 $attributes .
302 '>',
303 $block_content,
304 1 // Only replace the first occurrence.
305 );
306
307 $this->enqueue_carousel_assets();
308 }
309
310 return $block_content;
311 }
312
313 /**
314 * Add custom attributes to core/query block.
315 *
316 * @param string $block_content Block content.
317 * @param array $block Block attributes.
318 * @return string
319 */
320 public function add_custom_attributes_to_query_block( $block_content, $block ) {
321 $attrs = $block['attrs'] ?? array();
322 $custom_option = isset( $attrs['frblGridOption'] ) ? sanitize_text_field( $attrs['frblGridOption'] ) : '';
323
324 if ( 'carousel' !== $custom_option && 'slider' !== $custom_option ) {
325 return $block_content;
326 }
327
328 $items_to_view = isset( $attrs['frblItemsToView'] ) ? (int) $attrs['frblItemsToView'] : 4;
329 $laptop_to_view = isset( $attrs['frblLaptopToView'] ) ? (int) $attrs['frblLaptopToView'] : 3;
330 $tablet_to_view = isset( $attrs['frblTabletToView'] ) ? (int) $attrs['frblTabletToView'] : 2;
331 $responsive_to_view = isset( $attrs['frblResponsiveToView'] ) ? (int) $attrs['frblResponsiveToView'] : 1;
332 $autoplay = isset( $attrs['frblAutoplay'] ) ? ( (int) $attrs['frblAutoplay'] * 1000 ) : '';
333 $gap = isset( $attrs['frblGap'] ) && '' !== $attrs['frblGap'] ? (int) $attrs['frblGap'] : 20;
334 $rewind = isset( $attrs['frblRewind'] ) ? (bool) $attrs['frblRewind'] : true;
335 $buttons = isset( $attrs['frblButtons'] ) ? sanitize_text_field( $attrs['frblButtons'] ) : 'arrows';
336 $button_color = isset( $attrs['frblButtonColor'] ) ? sanitize_text_field( $attrs['frblButtonColor'] ) : '';
337 $button_bg_color = isset( $attrs['frblButtonBgColor'] ) ? sanitize_text_field( $attrs['frblButtonBgColor'] ) : '';
338 $buttons_position = isset( $attrs['frblButtonsPosition'] ) ? sanitize_text_field( $attrs['frblButtonsPosition'] ) : 'side';
339 $arrow_left_url = isset( $attrs['frblArrowLeftUrl'] ) ? esc_url_raw( $attrs['frblArrowLeftUrl'] ) : '';
340 $arrow_right_url = isset( $attrs['frblArrowRightUrl'] ) ? esc_url_raw( $attrs['frblArrowRightUrl'] ) : '';
341 $disable_on_desktop = isset( $attrs['frblDisableOnDesktop'] ) ? (bool) $attrs['frblDisableOnDesktop'] : false;
342
343 $extra = '';
344 if ( 'slider' === $custom_option ) {
345 $extra .= ' data-rewind="' . esc_attr( $rewind ) . '"';
346 }
347
348 $block_content = preg_replace(
349 '/<ul([^>]*)class="([^"]*wp-block-post-template[^"]*)"([^>]*)>/',
350 '<ul$1class="$2 frontblocks-carousel"$3' .
351 ' data-type="' . esc_attr( $custom_option ) . '"' .
352 ' data-view="' . esc_attr( $items_to_view ) . '"' .
353 ' data-laptop-view="' . esc_attr( $laptop_to_view ) . '"' .
354 ' data-tablet-view="' . esc_attr( $tablet_to_view ) . '"' .
355 ' data-mobile-view="' . esc_attr( $responsive_to_view ) . '"' .
356 ' data-autoplay="' . esc_attr( $autoplay ) . '"' .
357 ' data-gap="' . esc_attr( $gap ) . '"' .
358 ' data-buttons="' . esc_attr( $buttons ) . '"' .
359 ' data-buttons-color="' . esc_attr( $button_color ) . '"' .
360 ' data-buttons-background-color="' . esc_attr( $button_bg_color ) . '"' .
361 ' data-buttons-position="' . esc_attr( $buttons_position ) . '"' .
362 ( $arrow_left_url ? ' data-arrow-left-url="' . esc_url( $arrow_left_url ) . '"' : '' ) .
363 ( $arrow_right_url ? ' data-arrow-right-url="' . esc_url( $arrow_right_url ) . '"' : '' ) .
364 ' data-disable-on-desktop="' . esc_attr( $disable_on_desktop ? 'true' : 'false' ) . '"' .
365 $extra .
366 '>',
367 $block_content,
368 1
369 );
370
371 $this->enqueue_carousel_assets();
372
373 return $block_content;
374 }
375
376 /**
377 * Register custom attributes for blocks.
378 *
379 * @return void
380 */
381 public function register_custom_attributes() {
382 // Register attributes before GenerateBlocks registers its blocks.
383 add_filter(
384 'generateblocks_blocks_registered_block',
385 array( $this, 'register_custom_attributes_for_grid_block' ),
386 9,
387 2
388 );
389
390 // Register attributes for core/query block.
391 add_filter( 'register_block_type_args', array( $this, 'register_query_block_attributes' ), 10, 2 );
392
393 // Register attributes from frontend side too.
394 add_action(
395 'enqueue_block_editor_assets',
396 array( $this, 'add_inline_script_for_attributes' )
397 );
398 }
399
400 /**
401 * Register custom attributes for GenerateBlocks Grid and Element blocks.
402 *
403 * @param array $block_args The block arguments.
404 * @param string $block_type The name of the block.
405 * @return array Modified block arguments.
406 */
407 public function register_custom_attributes_for_grid_block( $block_args, $block_type ) {
408 if ( 'generateblocks/grid' !== $block_type && 'generateblocks/element' !== $block_type ) {
409 return $block_args;
410 }
411
412 $block_args['attributes']['frblGridOption'] = array(
413 'type' => 'string',
414 'default' => 'none',
415 );
416 $block_args['attributes']['frblItemsToView'] = array(
417 'type' => 'string',
418 'default' => '4',
419 );
420 $block_args['attributes']['frblLaptopToView'] = array(
421 'type' => 'string',
422 'default' => '3',
423 );
424 $block_args['attributes']['frblTabletToView'] = array(
425 'type' => 'string',
426 'default' => '2',
427 );
428 $block_args['attributes']['frblResponsiveToView'] = array(
429 'type' => 'string',
430 'default' => '1',
431 );
432 $block_args['attributes']['frblAutoplay'] = array(
433 'type' => 'string',
434 'default' => '',
435 );
436 $block_args['attributes']['frblGap'] = array(
437 'type' => 'string',
438 'default' => '20',
439 );
440 $block_args['attributes']['frblRewind'] = array(
441 'type' => 'boolean',
442 'default' => true,
443 );
444 $block_args['attributes']['frblButtons'] = array(
445 'type' => 'string',
446 'default' => 'arrows',
447 );
448 $block_args['attributes']['frblButtonColor'] = array(
449 'type' => 'string',
450 'default' => '',
451 );
452 $block_args['attributes']['frblButtonBgColor'] = array(
453 'type' => 'string',
454 'default' => '',
455 );
456 $block_args['attributes']['frblButtonsPosition'] = array(
457 'type' => 'string',
458 'default' => 'side',
459 );
460 $block_args['attributes']['frblArrowLeftUrl'] = array(
461 'type' => 'string',
462 'default' => '',
463 );
464 $block_args['attributes']['frblArrowRightUrl'] = array(
465 'type' => 'string',
466 'default' => '',
467 );
468 $block_args['attributes']['frblDisableOnDesktop'] = array(
469 'type' => 'boolean',
470 'default' => false,
471 );
472
473 return $block_args;
474 }
475
476 /**
477 * Register custom attributes for core/query block.
478 *
479 * @param array $args Block type arguments.
480 * @param string $block_type Block type name.
481 * @return array
482 */
483 public function register_query_block_attributes( $args, $block_type ) {
484 if ( 'core/query' !== $block_type ) {
485 return $args;
486 }
487
488 if ( ! isset( $args['attributes'] ) ) {
489 $args['attributes'] = array();
490 }
491
492 $args['attributes']['frblGridOption'] = array(
493 'type' => 'string',
494 'default' => 'none',
495 );
496 $args['attributes']['frblItemsToView'] = array(
497 'type' => 'string',
498 'default' => '4',
499 );
500 $args['attributes']['frblLaptopToView'] = array(
501 'type' => 'string',
502 'default' => '3',
503 );
504 $args['attributes']['frblTabletToView'] = array(
505 'type' => 'string',
506 'default' => '2',
507 );
508 $args['attributes']['frblResponsiveToView'] = array(
509 'type' => 'string',
510 'default' => '1',
511 );
512 $args['attributes']['frblAutoplay'] = array(
513 'type' => 'string',
514 'default' => '',
515 );
516 $args['attributes']['frblGap'] = array(
517 'type' => 'string',
518 'default' => '20',
519 );
520 $args['attributes']['frblRewind'] = array(
521 'type' => 'boolean',
522 'default' => true,
523 );
524 $args['attributes']['frblButtons'] = array(
525 'type' => 'string',
526 'default' => 'arrows',
527 );
528 $args['attributes']['frblButtonColor'] = array(
529 'type' => 'string',
530 'default' => '',
531 );
532 $args['attributes']['frblButtonBgColor'] = array(
533 'type' => 'string',
534 'default' => '',
535 );
536 $args['attributes']['frblButtonsPosition'] = array(
537 'type' => 'string',
538 'default' => 'side',
539 );
540 $args['attributes']['frblArrowLeftUrl'] = array(
541 'type' => 'string',
542 'default' => '',
543 );
544 $args['attributes']['frblArrowRightUrl'] = array(
545 'type' => 'string',
546 'default' => '',
547 );
548 $args['attributes']['frblDisableOnDesktop'] = array(
549 'type' => 'boolean',
550 'default' => false,
551 );
552
553 return $args;
554 }
555
556 /**
557 * Add inline script for block attributes.
558 *
559 * @return void
560 */
561 public function add_inline_script_for_attributes() {
562 wp_add_inline_script(
563 'wp-blocks',
564 "
565 wp.hooks.addFilter(
566 'blocks.registerBlockType',
567 'frontblocks/grid-attributes',
568 function( settings, name ) {
569 if ( name !== 'generateblocks/grid' && name !== 'generateblocks/element' && name !== 'core/group' && name !== 'core/query' ) {
570 return settings;
571 }
572
573 settings.attributes = {
574 ...settings.attributes,
575 frblGridOption: {
576 type: 'string',
577 default: 'none'
578 },
579 frblItemsToView: {
580 type: 'string',
581 default: '4'
582 },
583 frblLaptopToView: {
584 type: 'string',
585 default: '3'
586 },
587 frblTabletToView: {
588 type: 'string',
589 default: '2'
590 },
591 frblResponsiveToView: {
592 type: 'string',
593 default: '1'
594 },
595 frblAutoplay: {
596 type: 'string',
597 default: ''
598 },
599 frblGap: {
600 type: 'string',
601 default: '20'
602 },
603 frblButtons: {
604 type: 'string',
605 default: 'arrows'
606 },
607 frblButtonsPosition: {
608 type: 'string',
609 default: 'side'
610 },
611 frblButtonColor: {
612 type: 'string',
613 default: ''
614 },
615 frblButtonBgColor: {
616 type: 'string',
617 default: ''
618 },
619 frblArrowLeftUrl: {
620 type: 'string',
621 default: ''
622 },
623 frblArrowRightUrl: {
624 type: 'string',
625 default: ''
626 },
627 frblRewind: {
628 type: 'boolean',
629 default: true
630 },
631 frblDisableOnDesktop: {
632 type: 'boolean',
633 default: false
634 }
635 };
636
637 return settings;
638 }
639 );
640 "
641 );
642 }
643 }
644