PluginProbe
Elementor Website Builder – more than just a page builder / 3.5.2
Elementor Website Builder – more than just a page builder v3.5.2
4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 4.0.7 All 451 releases
elementor / includes / widgets / image-carousel.php

image-carousel.php in Elementor Website Builder – more than just a page builder 3.5.2, at includes/widgets/image-carousel.php

873 lines 20.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Elementor;
3
4 if ( ! defined( 'ABSPATH' ) ) {
5 exit; // Exit if accessed directly.
6 }
7
8 use Elementor\Core\Kits\Documents\Tabs\Global_Colors;
9
10 /**
11 * Elementor image carousel widget.
12 *
13 * Elementor widget that displays a set of images in a rotating carousel or
14 * slider.
15 *
16 * @since 1.0.0
17 */
18 class Widget_Image_Carousel extends Widget_Base {
19
20 /**
21 * Get widget name.
22 *
23 * Retrieve image carousel widget name.
24 *
25 * @since 1.0.0
26 * @access public
27 *
28 * @return string Widget name.
29 */
30 public function get_name() {
31 return 'image-carousel';
32 }
33
34 /**
35 * Get widget title.
36 *
37 * Retrieve image carousel widget title.
38 *
39 * @since 1.0.0
40 * @access public
41 *
42 * @return string Widget title.
43 */
44 public function get_title() {
45 return esc_html__( 'Image Carousel', 'elementor' );
46 }
47
48 /**
49 * Get widget icon.
50 *
51 * Retrieve image carousel widget icon.
52 *
53 * @since 1.0.0
54 * @access public
55 *
56 * @return string Widget icon.
57 */
58 public function get_icon() {
59 return 'eicon-slider-push';
60 }
61
62 /**
63 * Get widget keywords.
64 *
65 * Retrieve the list of keywords the widget belongs to.
66 *
67 * @since 2.1.0
68 * @access public
69 *
70 * @return array Widget keywords.
71 */
72 public function get_keywords() {
73 return [ 'image', 'photo', 'visual', 'carousel', 'slider' ];
74 }
75
76 /**
77 * Register image carousel widget controls.
78 *
79 * Adds different input fields to allow the user to change and customize the widget settings.
80 *
81 * @since 3.1.0
82 * @access protected
83 */
84 protected function register_controls() {
85 $this->start_controls_section(
86 'section_image_carousel',
87 [
88 'label' => esc_html__( 'Image Carousel', 'elementor' ),
89 ]
90 );
91
92 $this->add_control(
93 'carousel',
94 [
95 'label' => esc_html__( 'Add Images', 'elementor' ),
96 'type' => Controls_Manager::GALLERY,
97 'default' => [],
98 'show_label' => false,
99 'dynamic' => [
100 'active' => true,
101 ],
102 ]
103 );
104
105 $this->add_group_control(
106 Group_Control_Image_Size::get_type(),
107 [
108 'name' => 'thumbnail', // Usage: `{name}_size` and `{name}_custom_dimension`, in this case `thumbnail_size` and `thumbnail_custom_dimension`.
109 'separator' => 'none',
110 ]
111 );
112
113 $slides_to_show = range( 1, 10 );
114 $slides_to_show = array_combine( $slides_to_show, $slides_to_show );
115
116 $this->add_responsive_control(
117 'slides_to_show',
118 [
119 'label' => esc_html__( 'Slides to Show', 'elementor' ),
120 'type' => Controls_Manager::SELECT,
121 'options' => [
122 '' => esc_html__( 'Default', 'elementor' ),
123 ] + $slides_to_show,
124 'frontend_available' => true,
125 'render_type' => 'template',
126 'selectors' => [
127 '{{WRAPPER}}' => '--e-image-carousel-slides-to-show: {{VALUE}}',
128 ],
129 ]
130 );
131
132 $this->add_responsive_control(
133 'slides_to_scroll',
134 [
135 'label' => esc_html__( 'Slides to Scroll', 'elementor' ),
136 'type' => Controls_Manager::SELECT,
137 'description' => esc_html__( 'Set how many slides are scrolled per swipe.', 'elementor' ),
138 'options' => [
139 '' => esc_html__( 'Default', 'elementor' ),
140 ] + $slides_to_show,
141 'condition' => [
142 'slides_to_show!' => '1',
143 ],
144 'frontend_available' => true,
145 ]
146 );
147
148 $this->add_control(
149 'image_stretch',
150 [
151 'label' => esc_html__( 'Image Stretch', 'elementor' ),
152 'type' => Controls_Manager::SELECT,
153 'default' => 'no',
154 'options' => [
155 'no' => esc_html__( 'No', 'elementor' ),
156 'yes' => esc_html__( 'Yes', 'elementor' ),
157 ],
158 ]
159 );
160
161 $this->add_control(
162 'navigation',
163 [
164 'label' => esc_html__( 'Navigation', 'elementor' ),
165 'type' => Controls_Manager::SELECT,
166 'default' => 'both',
167 'options' => [
168 'both' => esc_html__( 'Arrows and Dots', 'elementor' ),
169 'arrows' => esc_html__( 'Arrows', 'elementor' ),
170 'dots' => esc_html__( 'Dots', 'elementor' ),
171 'none' => esc_html__( 'None', 'elementor' ),
172 ],
173 'frontend_available' => true,
174 ]
175 );
176
177 $this->add_control(
178 'link_to',
179 [
180 'label' => esc_html__( 'Link', 'elementor' ),
181 'type' => Controls_Manager::SELECT,
182 'default' => 'none',
183 'options' => [
184 'none' => esc_html__( 'None', 'elementor' ),
185 'file' => esc_html__( 'Media File', 'elementor' ),
186 'custom' => esc_html__( 'Custom URL', 'elementor' ),
187 ],
188 ]
189 );
190
191 $this->add_control(
192 'link',
193 [
194 'label' => esc_html__( 'Link', 'elementor' ),
195 'type' => Controls_Manager::URL,
196 'placeholder' => esc_html__( 'https://your-link.com', 'elementor' ),
197 'condition' => [
198 'link_to' => 'custom',
199 ],
200 'show_label' => false,
201 ]
202 );
203
204 $this->add_control(
205 'open_lightbox',
206 [
207 'label' => esc_html__( 'Lightbox', 'elementor' ),
208 'type' => Controls_Manager::SELECT,
209 'default' => 'default',
210 'options' => [
211 'default' => esc_html__( 'Default', 'elementor' ),
212 'yes' => esc_html__( 'Yes', 'elementor' ),
213 'no' => esc_html__( 'No', 'elementor' ),
214 ],
215 'condition' => [
216 'link_to' => 'file',
217 ],
218 ]
219 );
220
221 $this->add_control(
222 'caption_type',
223 [
224 'label' => esc_html__( 'Caption', 'elementor' ),
225 'type' => Controls_Manager::SELECT,
226 'default' => '',
227 'options' => [
228 '' => esc_html__( 'None', 'elementor' ),
229 'title' => esc_html__( 'Title', 'elementor' ),
230 'caption' => esc_html__( 'Caption', 'elementor' ),
231 'description' => esc_html__( 'Description', 'elementor' ),
232 ],
233 ]
234 );
235
236 $this->add_control(
237 'view',
238 [
239 'label' => esc_html__( 'View', 'elementor' ),
240 'type' => Controls_Manager::HIDDEN,
241 'default' => 'traditional',
242 ]
243 );
244
245 $this->end_controls_section();
246
247 $this->start_controls_section(
248 'section_additional_options',
249 [
250 'label' => esc_html__( 'Additional Options', 'elementor' ),
251 ]
252 );
253
254 $this->add_control(
255 'autoplay',
256 [
257 'label' => esc_html__( 'Autoplay', 'elementor' ),
258 'type' => Controls_Manager::SELECT,
259 'default' => 'yes',
260 'options' => [
261 'yes' => esc_html__( 'Yes', 'elementor' ),
262 'no' => esc_html__( 'No', 'elementor' ),
263 ],
264 'frontend_available' => true,
265 ]
266 );
267
268 $this->add_control(
269 'pause_on_hover',
270 [
271 'label' => esc_html__( 'Pause on Hover', 'elementor' ),
272 'type' => Controls_Manager::SELECT,
273 'default' => 'yes',
274 'options' => [
275 'yes' => esc_html__( 'Yes', 'elementor' ),
276 'no' => esc_html__( 'No', 'elementor' ),
277 ],
278 'condition' => [
279 'autoplay' => 'yes',
280 ],
281 'render_type' => 'none',
282 'frontend_available' => true,
283 ]
284 );
285
286 $this->add_control(
287 'pause_on_interaction',
288 [
289 'label' => esc_html__( 'Pause on Interaction', 'elementor' ),
290 'type' => Controls_Manager::SELECT,
291 'default' => 'yes',
292 'options' => [
293 'yes' => esc_html__( 'Yes', 'elementor' ),
294 'no' => esc_html__( 'No', 'elementor' ),
295 ],
296 'condition' => [
297 'autoplay' => 'yes',
298 ],
299 'frontend_available' => true,
300 ]
301 );
302
303 $this->add_control(
304 'autoplay_speed',
305 [
306 'label' => esc_html__( 'Autoplay Speed', 'elementor' ),
307 'type' => Controls_Manager::NUMBER,
308 'default' => 5000,
309 'condition' => [
310 'autoplay' => 'yes',
311 ],
312 'render_type' => 'none',
313 'frontend_available' => true,
314 ]
315 );
316
317 // Loop requires a re-render so no 'render_type = none'
318 $this->add_control(
319 'infinite',
320 [
321 'label' => esc_html__( 'Infinite Loop', 'elementor' ),
322 'type' => Controls_Manager::SELECT,
323 'default' => 'yes',
324 'options' => [
325 'yes' => esc_html__( 'Yes', 'elementor' ),
326 'no' => esc_html__( 'No', 'elementor' ),
327 ],
328 'frontend_available' => true,
329 ]
330 );
331
332 $this->add_control(
333 'effect',
334 [
335 'label' => esc_html__( 'Effect', 'elementor' ),
336 'type' => Controls_Manager::SELECT,
337 'default' => 'slide',
338 'options' => [
339 'slide' => esc_html__( 'Slide', 'elementor' ),
340 'fade' => esc_html__( 'Fade', 'elementor' ),
341 ],
342 'condition' => [
343 'slides_to_show' => '1',
344 ],
345 'frontend_available' => true,
346 ]
347 );
348
349 $this->add_control(
350 'speed',
351 [
352 'label' => esc_html__( 'Animation Speed', 'elementor' ),
353 'type' => Controls_Manager::NUMBER,
354 'default' => 500,
355 'render_type' => 'none',
356 'frontend_available' => true,
357 ]
358 );
359
360 $this->add_control(
361 'direction',
362 [
363 'label' => esc_html__( 'Direction', 'elementor' ),
364 'type' => Controls_Manager::SELECT,
365 'default' => 'ltr',
366 'options' => [
367 'ltr' => esc_html__( 'Left', 'elementor' ),
368 'rtl' => esc_html__( 'Right', 'elementor' ),
369 ],
370 ]
371 );
372
373 $this->end_controls_section();
374
375 $this->start_controls_section(
376 'section_style_navigation',
377 [
378 'label' => esc_html__( 'Navigation', 'elementor' ),
379 'tab' => Controls_Manager::TAB_STYLE,
380 'condition' => [
381 'navigation' => [ 'arrows', 'dots', 'both' ],
382 ],
383 ]
384 );
385
386 $this->add_control(
387 'heading_style_arrows',
388 [
389 'label' => esc_html__( 'Arrows', 'elementor' ),
390 'type' => Controls_Manager::HEADING,
391 'separator' => 'before',
392 'condition' => [
393 'navigation' => [ 'arrows', 'both' ],
394 ],
395 ]
396 );
397
398 $this->add_control(
399 'arrows_position',
400 [
401 'label' => esc_html__( 'Position', 'elementor' ),
402 'type' => Controls_Manager::SELECT,
403 'default' => 'inside',
404 'options' => [
405 'inside' => esc_html__( 'Inside', 'elementor' ),
406 'outside' => esc_html__( 'Outside', 'elementor' ),
407 ],
408 'prefix_class' => 'elementor-arrows-position-',
409 'condition' => [
410 'navigation' => [ 'arrows', 'both' ],
411 ],
412 ]
413 );
414
415 $this->add_control(
416 'arrows_size',
417 [
418 'label' => esc_html__( 'Size', 'elementor' ),
419 'type' => Controls_Manager::SLIDER,
420 'range' => [
421 'px' => [
422 'min' => 20,
423 'max' => 60,
424 ],
425 ],
426 'selectors' => [
427 '{{WRAPPER}} .elementor-swiper-button.elementor-swiper-button-prev, {{WRAPPER}} .elementor-swiper-button.elementor-swiper-button-next' => 'font-size: {{SIZE}}{{UNIT}};',
428 ],
429 'condition' => [
430 'navigation' => [ 'arrows', 'both' ],
431 ],
432 ]
433 );
434
435 $this->add_control(
436 'arrows_color',
437 [
438 'label' => esc_html__( 'Color', 'elementor' ),
439 'type' => Controls_Manager::COLOR,
440 'selectors' => [
441 '{{WRAPPER}} .elementor-swiper-button.elementor-swiper-button-prev, {{WRAPPER}} .elementor-swiper-button.elementor-swiper-button-next' => 'color: {{VALUE}};',
442 '{{WRAPPER}} .elementor-swiper-button.elementor-swiper-button-prev svg, {{WRAPPER}} .elementor-swiper-button.elementor-swiper-button-next svg' => 'fill: {{VALUE}};',
443 ],
444 'condition' => [
445 'navigation' => [ 'arrows', 'both' ],
446 ],
447 ]
448 );
449
450 $this->add_control(
451 'heading_style_dots',
452 [
453 'label' => esc_html__( 'Dots', 'elementor' ),
454 'type' => Controls_Manager::HEADING,
455 'separator' => 'before',
456 'condition' => [
457 'navigation' => [ 'dots', 'both' ],
458 ],
459 ]
460 );
461
462 $this->add_control(
463 'dots_position',
464 [
465 'label' => esc_html__( 'Position', 'elementor' ),
466 'type' => Controls_Manager::SELECT,
467 'default' => 'outside',
468 'options' => [
469 'outside' => esc_html__( 'Outside', 'elementor' ),
470 'inside' => esc_html__( 'Inside', 'elementor' ),
471 ],
472 'prefix_class' => 'elementor-pagination-position-',
473 'condition' => [
474 'navigation' => [ 'dots', 'both' ],
475 ],
476 ]
477 );
478
479 $this->add_control(
480 'dots_size',
481 [
482 'label' => esc_html__( 'Size', 'elementor' ),
483 'type' => Controls_Manager::SLIDER,
484 'range' => [
485 'px' => [
486 'min' => 5,
487 'max' => 10,
488 ],
489 ],
490 'selectors' => [
491 '{{WRAPPER}} .swiper-pagination-bullet' => 'width: {{SIZE}}{{UNIT}}; height: {{SIZE}}{{UNIT}};',
492 ],
493 'condition' => [
494 'navigation' => [ 'dots', 'both' ],
495 ],
496 ]
497 );
498
499 $this->add_control(
500 'dots_color',
501 [
502 'label' => esc_html__( 'Color', 'elementor' ),
503 'type' => Controls_Manager::COLOR,
504 'selectors' => [
505 '{{WRAPPER}} .swiper-pagination-bullet' => 'background: {{VALUE}};',
506 ],
507 'condition' => [
508 'navigation' => [ 'dots', 'both' ],
509 ],
510 ]
511 );
512
513 $this->end_controls_section();
514
515 $this->start_controls_section(
516 'section_style_image',
517 [
518 'label' => esc_html__( 'Image', 'elementor' ),
519 'tab' => Controls_Manager::TAB_STYLE,
520 ]
521 );
522
523 $this->add_responsive_control(
524 'gallery_vertical_align',
525 [
526 'label' => esc_html__( 'Vertical Align', 'elementor' ),
527 'type' => Controls_Manager::CHOOSE,
528 'options' => [
529 'flex-start' => [
530 'title' => esc_html__( 'Start', 'elementor' ),
531 'icon' => 'eicon-v-align-top',
532 ],
533 'center' => [
534 'title' => esc_html__( 'Center', 'elementor' ),
535 'icon' => 'eicon-v-align-middle',
536 ],
537 'flex-end' => [
538 'title' => esc_html__( 'End', 'elementor' ),
539 'icon' => 'eicon-v-align-bottom',
540 ],
541 ],
542 'condition' => [
543 'slides_to_show!' => '1',
544 ],
545 'selectors' => [
546 '{{WRAPPER}} .swiper-wrapper' => 'display: flex; align-items: {{VALUE}};',
547 ],
548 ]
549 );
550
551 $this->add_control(
552 'image_spacing',
553 [
554 'label' => esc_html__( 'Spacing', 'elementor' ),
555 'type' => Controls_Manager::SELECT,
556 'options' => [
557 '' => esc_html__( 'Default', 'elementor' ),
558 'custom' => esc_html__( 'Custom', 'elementor' ),
559 ],
560 'default' => '',
561 'condition' => [
562 'slides_to_show!' => '1',
563 ],
564 ]
565 );
566
567 $this->add_control(
568 'image_spacing_custom',
569 [
570 'label' => esc_html__( 'Image Spacing', 'elementor' ),
571 'type' => Controls_Manager::SLIDER,
572 'range' => [
573 'px' => [
574 'max' => 100,
575 ],
576 ],
577 'default' => [
578 'size' => 20,
579 ],
580 'show_label' => false,
581 'condition' => [
582 'image_spacing' => 'custom',
583 'slides_to_show!' => '1',
584 ],
585 'frontend_available' => true,
586 'render_type' => 'none',
587 'separator' => 'after',
588 ]
589 );
590
591 $this->add_group_control(
592 Group_Control_Border::get_type(),
593 [
594 'name' => 'image_border',
595 'selector' => '{{WRAPPER}} .elementor-image-carousel-wrapper .elementor-image-carousel .swiper-slide-image',
596 ]
597 );
598
599 $this->add_control(
600 'image_border_radius',
601 [
602 'label' => esc_html__( 'Border Radius', 'elementor' ),
603 'type' => Controls_Manager::DIMENSIONS,
604 'size_units' => [ 'px', '%' ],
605 'selectors' => [
606 '{{WRAPPER}} .elementor-image-carousel-wrapper .elementor-image-carousel .swiper-slide-image' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
607 ],
608 ]
609 );
610
611 $this->end_controls_section();
612
613 $this->start_controls_section(
614 'section_caption',
615 [
616 'label' => esc_html__( 'Caption', 'elementor' ),
617 'tab' => Controls_Manager::TAB_STYLE,
618 'condition' => [
619 'caption_type!' => '',
620 ],
621 ]
622 );
623
624 $this->add_control(
625 'caption_align',
626 [
627 'label' => esc_html__( 'Alignment', 'elementor' ),
628 'type' => Controls_Manager::CHOOSE,
629 'options' => [
630 'left' => [
631 'title' => esc_html__( 'Left', 'elementor' ),
632 'icon' => 'eicon-text-align-left',
633 ],
634 'center' => [
635 'title' => esc_html__( 'Center', 'elementor' ),
636 'icon' => 'eicon-text-align-center',
637 ],
638 'right' => [
639 'title' => esc_html__( 'Right', 'elementor' ),
640 'icon' => 'eicon-text-align-right',
641 ],
642 'justify' => [
643 'title' => esc_html__( 'Justified', 'elementor' ),
644 'icon' => 'eicon-text-align-justify',
645 ],
646 ],
647 'default' => 'center',
648 'selectors' => [
649 '{{WRAPPER}} .elementor-image-carousel-caption' => 'text-align: {{VALUE}};',
650 ],
651 ]
652 );
653
654 $this->add_control(
655 'caption_text_color',
656 [
657 'label' => esc_html__( 'Text Color', 'elementor' ),
658 'type' => Controls_Manager::COLOR,
659 'default' => '',
660 'selectors' => [
661 '{{WRAPPER}} .elementor-image-carousel-caption' => 'color: {{VALUE}};',
662 ],
663 ]
664 );
665
666 $this->add_group_control(
667 Group_Control_Typography::get_type(),
668 [
669 'name' => 'caption_typography',
670 'global' => [
671 'default' => Global_Colors::COLOR_ACCENT,
672 ],
673 'selector' => '{{WRAPPER}} .elementor-image-carousel-caption',
674 ]
675 );
676
677 $this->add_group_control(
678 Group_Control_Text_Shadow::get_type(),
679 [
680 'name' => 'caption_shadow',
681 'selector' => '{{WRAPPER}} .elementor-image-carousel-caption',
682 ]
683 );
684
685 $this->end_controls_section();
686
687 }
688
689 /**
690 * Render image carousel widget output on the frontend.
691 *
692 * Written in PHP and used to generate the final HTML.
693 *
694 * @since 1.0.0
695 * @access protected
696 */
697 protected function render() {
698 $settings = $this->get_settings_for_display();
699
700 if ( empty( $settings['carousel'] ) ) {
701 return;
702 }
703
704 $slides = [];
705
706 foreach ( $settings['carousel'] as $index => $attachment ) {
707 $image_url = Group_Control_Image_Size::get_attachment_image_src( $attachment['id'], 'thumbnail', $settings );
708
709 if ( ! $image_url && isset( $attachment['url'] ) ) {
710 $image_url = $attachment['url'];
711 }
712
713 $image_html = '<img class="swiper-slide-image" src="' . esc_attr( $image_url ) . '" alt="' . esc_attr( Control_Media::get_image_alt( $attachment ) ) . '" />';
714
715 $link_tag = '';
716
717 $link = $this->get_link_url( $attachment, $settings );
718
719 if ( $link ) {
720 $link_key = 'link_' . $index;
721
722 $this->add_lightbox_data_attributes( $link_key, $attachment['id'], $settings['open_lightbox'], $this->get_id() );
723
724 if ( Plugin::$instance->editor->is_edit_mode() ) {
725 $this->add_render_attribute( $link_key, [
726 'class' => 'elementor-clickable',
727 ] );
728 }
729
730 $this->add_link_attributes( $link_key, $link );
731
732 $link_tag = '<a ' . $this->get_render_attribute_string( $link_key ) . '>';
733 }
734
735 $image_caption = $this->get_image_caption( $attachment );
736
737 $slide_html = '<div class="swiper-slide">' . $link_tag . '<figure class="swiper-slide-inner">' . $image_html;
738
739 if ( ! empty( $image_caption ) ) {
740 $slide_html .= '<figcaption class="elementor-image-carousel-caption">' . wp_kses_post( $image_caption ) . '</figcaption>';
741 }
742
743 $slide_html .= '</figure>';
744
745 if ( $link ) {
746 $slide_html .= '</a>';
747 }
748
749 $slide_html .= '</div>';
750
751 $slides[] = $slide_html;
752
753 }
754
755 if ( empty( $slides ) ) {
756 return;
757 }
758
759 $this->add_render_attribute( [
760 'carousel' => [
761 'class' => 'elementor-image-carousel swiper-wrapper',
762 ],
763 'carousel-wrapper' => [
764 'class' => 'elementor-image-carousel-wrapper swiper-container',
765 'dir' => $settings['direction'],
766 ],
767 ] );
768
769 $show_dots = ( in_array( $settings['navigation'], [ 'dots', 'both' ] ) );
770 $show_arrows = ( in_array( $settings['navigation'], [ 'arrows', 'both' ] ) );
771
772 if ( 'yes' === $settings['image_stretch'] ) {
773 $this->add_render_attribute( 'carousel', 'class', 'swiper-image-stretch' );
774 }
775
776 $slides_count = count( $settings['carousel'] );
777
778 ?>
779 <div <?php $this->print_render_attribute_string( 'carousel-wrapper' ); ?>>
780 <div <?php $this->print_render_attribute_string( 'carousel' ); ?>>
781 <?php // PHPCS - $slides contains the slides content, all the relevent content is escaped above. ?>
782 <?php echo implode( '', $slides ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
783 </div>
784 <?php if ( 1 < $slides_count ) : ?>
785 <?php if ( $show_dots ) : ?>
786 <div class="swiper-pagination"></div>
787 <?php endif; ?>
788 <?php if ( $show_arrows ) : ?>
789 <div class="elementor-swiper-button elementor-swiper-button-prev">
790 <?php $this->render_swiper_button( 'previous' ); ?>
791 <span class="elementor-screen-only"><?php echo esc_html__( 'Previous', 'elementor' ); ?></span>
792 </div>
793 <div class="elementor-swiper-button elementor-swiper-button-next">
794 <?php $this->render_swiper_button( 'next' ); ?>
795 <span class="elementor-screen-only"><?php echo esc_html__( 'Next', 'elementor' ); ?></span>
796 </div>
797 <?php endif; ?>
798 <?php endif; ?>
799 </div>
800 <?php
801 }
802
803 /**
804 * Retrieve image carousel link URL.
805 *
806 * @since 1.0.0
807 * @access private
808 *
809 * @param array $attachment
810 * @param object $instance
811 *
812 * @return array|string|false An array/string containing the attachment URL, or false if no link.
813 */
814 private function get_link_url( $attachment, $instance ) {
815 if ( 'none' === $instance['link_to'] ) {
816 return false;
817 }
818
819 if ( 'custom' === $instance['link_to'] ) {
820 if ( empty( $instance['link']['url'] ) ) {
821 return false;
822 }
823
824 return $instance['link'];
825 }
826
827 return [
828 'url' => wp_get_attachment_url( $attachment['id'] ),
829 ];
830 }
831
832 /**
833 * Retrieve image carousel caption.
834 *
835 * @since 1.2.0
836 * @access private
837 *
838 * @param array $attachment
839 *
840 * @return string The caption of the image.
841 */
842 private function get_image_caption( $attachment ) {
843 $caption_type = $this->get_settings_for_display( 'caption_type' );
844
845 if ( empty( $caption_type ) ) {
846 return '';
847 }
848
849 $attachment_post = get_post( $attachment['id'] );
850
851 if ( 'caption' === $caption_type ) {
852 return $attachment_post->post_excerpt;
853 }
854
855 if ( 'title' === $caption_type ) {
856 return $attachment_post->post_title;
857 }
858
859 return $attachment_post->post_content;
860 }
861
862 private function render_swiper_button( $type ) {
863 $direction = 'next' === $type ? 'right' : 'left';
864
865 $icon_value = 'eicon-chevron-' . $direction;
866
867 Icons_Manager::render_icon( [
868 'library' => 'eicons',
869 'value' => $icon_value,
870 ], [ 'aria-hidden' => 'true' ] );
871 }
872 }
873