PluginProbe
Bricksable for Bricks Builder / 1.3.0
Bricksable for Bricks Builder v1.3.0
1.2.9 1.3.0 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.4.2 1.4.3 1.4.31 1.4.32 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 All 132 releases
bricksable / includes / elements / element-tilt-image.php

element-tilt-image.php in Bricksable for Bricks Builder 1.3.0, at includes/elements/element-tilt-image.php

747 lines 24.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) {
4 exit; // Exit if accessed directly.
5 }
6
7 class Bricksable_Tilt_Image extends \Bricks\Element {
8 public $category = 'bricksable';
9 public $name = 'ba-tilt-image';
10 public $icon = 'ti-image';
11 public $css_selector = '.ba-tilt-image-wrapper img';
12 public $scripts = array( 'bricksableTiltImage' );
13
14 public function get_label() {
15 return esc_html__( 'Tilt Image', 'bricksable' );
16 }
17 public function set_control_groups() {
18 $this->control_groups['image'] = array(
19 'title' => esc_html__( 'Image', 'bricksable' ),
20 'tab' => 'content',
21 );
22 $this->control_groups['tilt_settings'] = array(
23 'title' => esc_html__( 'Tilt Settings', 'bricksable' ),
24 'tab' => 'content',
25 );
26 $this->control_groups['tilt_alignment'] = array(
27 'title' => esc_html__( 'Alignment', 'bricksable' ),
28 'tab' => 'style',
29 );
30 $this->control_groups['overlay'] = array(
31 'title' => esc_html__( 'Overlay Content', 'bricksable' ),
32 'tab' => 'content',
33 );
34 $this->control_groups['overlay_style'] = array(
35 'title' => esc_html__( 'Overlay', 'bricksable' ),
36 'tab' => 'style',
37 );
38 unset( $this->control_groups['_typography'] );
39 }
40
41 public function set_controls() {
42 $this->controls['_gradient']['css'][0]['selector'] = '.ba-tilt-image-wrapper';
43 $this->controls['_border']['css'][] =
44 array(
45 'property' => 'border',
46 'selector' => '.ba-tilt-image-wrapper:before',
47 );
48 array(
49 'property' => 'border',
50 'selector' => '.ba-tilt-image-wrapper img',
51 );
52
53 $this->controls['image'] = array(
54 'tab' => 'content',
55 'group' => 'image',
56 'type' => 'image',
57 );
58 // Link To.
59 $this->controls['linkToSeparator'] = array(
60 'tab' => 'content',
61 'group' => 'image',
62 'type' => 'separator',
63 'label' => esc_html__( 'Link To', 'bricksable' ),
64 );
65
66 $this->controls['link'] = array(
67 'tab' => 'content',
68 'group' => 'image',
69 'type' => 'select',
70 'options' => array(
71 'lightbox' => esc_html__( 'Lightbox', 'bricksable' ),
72 'attachment' => esc_html__( 'Attachment Page', 'bricksable' ),
73 'media' => esc_html__( 'Media File', 'bricksable' ),
74 'url' => esc_html__( 'Other (URL)', 'bricksable' ),
75 ),
76 'placeholder' => esc_html__( 'None', 'bricksable' ),
77 );
78
79 $this->controls['url'] = array(
80 'tab' => 'content',
81 'group' => 'image',
82 'label' => esc_html__( 'Link type', 'bricksable' ),
83 'type' => 'link',
84 'required' => array( 'link', '=', 'url' ),
85 );
86
87 // Alignment.
88 $this->controls['tilt_textAlign'] = array(
89 'tab' => 'style',
90 'group' => 'tilt_alignment',
91 'label' => esc_html__( 'Text align', 'bricksable' ),
92 'type' => 'text-align',
93 'css' => array(
94 array(
95 'property' => 'text-align',
96 'selector' => '.ba-tilt-image-wrapper .image-overlay-content',
97 ),
98 array(
99 'property' => 'text-align',
100 'selector' => '.ba-tilt-image-wrapper .ba-tilt-image-overlay-caption',
101 ),
102 ),
103 'default' => 'center',
104 'placeholder' => esc_html__( 'Center', 'bricksable' ),
105 'inline' => true,
106 );
107
108 $this->controls['tilt_verticalAlign'] = array(
109 'tab' => 'style',
110 'group' => 'tilt_alignment',
111 'label' => esc_html__( 'Vertical align', 'bricksable' ),
112 'type' => 'select',
113 'options' => $this->control_options['alignItems'],
114 'css' => array(
115 array(
116 'property' => 'align-items',
117 'selector' => '.ba-tilt-image-wrapper .image-overlay-wrapper',
118 ),
119 ),
120 'inline' => true,
121 'default' => 'center',
122 'placeholder' => esc_html__( 'Center', 'bricksable' ),
123 );
124
125 // Overlay.
126 $this->controls['imageOverlayShowHover'] = array(
127 'tab' => 'content',
128 'group' => 'overlay',
129 'label' => esc_html__( 'Only show overlay on hover', 'bricksable' ),
130 'type' => 'checkbox',
131 'inline' => true,
132 'description' => esc_html__( 'Set your overlay in the style tab (Gradient/Overlay).', 'bricksable' ),
133 );
134
135 // Title & Caption.
136
137 $this->controls['title_caption_separator'] = array(
138 'tab' => 'content',
139 'group' => 'overlay',
140 'type' => 'separator',
141 'label' => esc_html__( 'Title & Caption', 'bricksable' ),
142 );
143
144 $this->controls['overlay_title'] = array(
145 'tab' => 'content',
146 'group' => 'overlay',
147 'label' => esc_html__( 'Title Type', 'bricksable' ),
148 'type' => 'select',
149 'options' => array(
150 'none' => esc_html__( 'No title', 'bricksable' ),
151 'attachment' => esc_html__( 'Attachment', 'bricksable' ),
152 'custom' => esc_html__( 'Custom', 'bricksable' ),
153 ),
154 'inline' => true,
155 'placeholder' => esc_html__( 'No title', 'bricksable' ),
156 );
157
158 $this->controls['overlay_title_custom'] = array(
159 'tab' => 'content',
160 'group' => 'overlay',
161 'label' => esc_html__( 'Overlay Title', 'bricksable' ),
162 'type' => 'text',
163 'spellcheck' => true,
164 'inlineEditing' => true,
165 'hasDynamicData' => 'text',
166 'required' => array( 'overlay_title', '=', 'custom' ),
167 );
168
169 $this->controls['overlay_title_tag'] = array(
170 'tab' => 'content',
171 'group' => 'overlay',
172 'label' => esc_html__( 'Title Tag', 'bricksable' ),
173 'type' => 'select',
174 'options' => array(
175 'h1' => esc_html__( 'Heading 1 (h1)', 'bricksable' ),
176 'h2' => esc_html__( 'Heading 2 (h2)', 'bricksable' ),
177 'h3' => esc_html__( 'Heading 3 (h3)', 'bricksable' ),
178 'h4' => esc_html__( 'Heading 4 (h4)', 'bricksable' ),
179 'h5' => esc_html__( 'Heading 5 (h5)', 'bricksable' ),
180 'h6' => esc_html__( 'Heading 6 (h6)', 'bricksable' ),
181 ),
182 'clearable' => false,
183 'pasteStyles' => false,
184 'default' => 'h3',
185 'inline' => true,
186 'required' => array( 'overlay_title', '!=', 'none' ),
187 );
188
189 $this->controls['overlay_caption'] = array(
190 'tab' => 'content',
191 'group' => 'overlay',
192 'label' => esc_html__( 'Caption Type', 'bricksable' ),
193 'type' => 'select',
194 'options' => array(
195 'none' => esc_html__( 'No caption', 'bricksable' ),
196 'attachment' => esc_html__( 'Attachment', 'bricksable' ),
197 'custom' => esc_html__( 'Custom', 'bricksable' ),
198 ),
199 'inline' => true,
200 'placeholder' => esc_html__( 'No caption', 'bricksable' ),
201 );
202
203 $this->controls['overlay_caption_custom'] = array(
204 'tab' => 'content',
205 'group' => 'overlay',
206 'label' => esc_html__( 'Custom caption', 'bricksable' ),
207 'type' => 'text',
208 'placeholder' => esc_html__( 'Here goes your caption ...', 'bricksable' ),
209 'required' => array( 'overlay_caption', '=', 'custom' ),
210 );
211
212 $this->controls['overlayShowHover'] = array(
213 'tab' => 'content',
214 'group' => 'overlay',
215 'label' => esc_html__( 'Only show on hover', 'bricksable' ),
216 'type' => 'checkbox',
217 'inline' => true,
218 );
219
220 $this->controls['overlay_icon_separator'] = array(
221 'tab' => 'content',
222 'group' => 'overlay',
223 'label' => esc_html__( 'Icon', 'bricksable' ),
224 'type' => 'separator',
225 'inline' => true,
226 'small' => true,
227 );
228
229 $this->controls['overlay_icon'] = array(
230 'tab' => 'content',
231 'group' => 'overlay',
232 'label' => esc_html__( 'Icon', 'bricksable' ),
233 'type' => 'icon',
234 'inline' => true,
235 'small' => true,
236 );
237
238 $this->controls['overlay_translatez'] = array(
239 'tab' => 'style',
240 'group' => 'overlay_style',
241 'label' => esc_html__( 'Overlay Content Distance', 'bricksable' ),
242 'type' => 'slider',
243 'css' => array(
244 array(
245 'property' => 'transform:translateZ',
246 'selector' => '.image-overlay-wrapper',
247 ),
248 ),
249 'units' => array(
250 'px' => array(
251 'min' => 1,
252 'max' => 200,
253 'step' => 1,
254 ),
255 ),
256 'default' => '50px',
257 'description' => esc_html__( 'Adjust the distance between the image and the overlay content.', 'bricksable' ),
258 );
259
260 $this->controls['overlay_title_typography'] = array(
261 'tab' => 'style',
262 'group' => 'overlay_style',
263 'label' => esc_html__( 'Title Typography', 'bricksable' ),
264 'type' => 'typography',
265 'css' => array(
266 array(
267 'property' => 'font',
268 'selector' => '.ba-tilt-image-overlay-title',
269 ),
270 ),
271 'inline' => true,
272 'small' => true,
273 'required' => array( 'overlay_title', '!=', '' ),
274 );
275
276 $this->controls['overlay_caption_typography'] = array(
277 'tab' => 'style',
278 'group' => 'overlay_style',
279 'label' => esc_html__( 'Caption Typography', 'bricksable' ),
280 'type' => 'typography',
281 'css' => array(
282 array(
283 'property' => 'font',
284 'selector' => '.ba-tilt-image-caption',
285 ),
286 ),
287 'inline' => true,
288 'small' => true,
289 'required' => array( 'overlay_title', '!=', '' ),
290 );
291
292 $this->controls['overlay_style_icon_separator'] = array(
293 'tab' => 'style',
294 'group' => 'overlay_style',
295 'label' => esc_html__( 'Icon', 'bricksable' ),
296 'type' => 'separator',
297 'inline' => true,
298 'small' => true,
299 );
300
301 $this->controls['overlay_icon_border'] = array(
302 'tab' => 'style',
303 'group' => 'overlay_style',
304 'label' => esc_html__( 'Icon border', 'bricksable' ),
305 'type' => 'border',
306 'css' => array(
307 array(
308 'property' => 'border',
309 'selector' => '.image-overlay-wrapper .overlay-icon',
310 ),
311 ),
312 'inline' => true,
313 'small' => true,
314 'required' => array( 'overlay_icon', '!=', '' ),
315 );
316
317 $this->controls['overlay_icon_boxshadow'] = array(
318 'tab' => 'style',
319 'group' => 'overlay_style',
320 'label' => esc_html__( 'Icon box shadow', 'bricksable' ),
321 'type' => 'box-shadow',
322 'css' => array(
323 array(
324 'property' => 'box-shadow',
325 'selector' => '.image-overlay-wrapper .overlay-icon',
326 ),
327 ),
328 'inline' => true,
329 'small' => true,
330 'required' => array( 'overlay_icon', '!=', '' ),
331 );
332
333 $this->controls['overlay_icon_height'] = array(
334 'tab' => 'style',
335 'group' => 'overlay_style',
336 'label' => esc_html__( 'Icon height', 'bricksable' ),
337 'type' => 'number',
338 'unit' => 'px',
339 'css' => array(
340 array(
341 'property' => 'line-height',
342 'selector' => '.image-overlay-wrapper .overlay-icon',
343 ),
344 ),
345 'inline' => true,
346 'small' => true,
347 'required' => array( 'overlay_icon', '!=', '' ),
348 );
349
350 $this->controls['overlay_icon_width'] = array(
351 'tab' => 'style',
352 'group' => 'overlay_style',
353 'label' => esc_html__( 'Icon width', 'bricksable' ),
354 'type' => 'number',
355 'unit' => 'px',
356 'css' => array(
357 array(
358 'property' => 'width',
359 'selector' => '.image-overlay-wrapper .overlay-icon',
360 ),
361 ),
362 'inline' => true,
363 'small' => true,
364 'required' => array( 'overlay_icon', '!=', '' ),
365 );
366
367 $this->controls['overlay_icon_typography'] = array(
368 'tab' => 'style',
369 'group' => 'overlay_style',
370 'label' => esc_html__( 'Icon typography', 'bricksable' ),
371 'type' => 'typography',
372 'exclude' => array(
373 'font-family',
374 'font-weight',
375 'text-align',
376 'text-transform',
377 'line-height',
378 'letter-spacing',
379 ),
380 'css' => array(
381 array(
382 'property' => 'font',
383 'selector' => '.image-overlay-wrapper .overlay-icon',
384 ),
385 ),
386 'inline' => true,
387 'small' => true,
388 'required' => array( 'overlay_icon', '!=', '' ),
389 );
390
391 // Tilt Settings.
392 $this->controls['tilt_reverse'] = array(
393 'tab' => 'content',
394 'group' => 'tilt_settings',
395 'label' => esc_html__( 'Reverse', 'bricksable' ),
396 'type' => 'checkbox',
397 'inline' => true,
398 'description' => esc_html__( 'Reverse the tilt direction.', 'bricksable' ),
399 );
400 $this->controls['tilt_max'] = array(
401 'tab' => 'content',
402 'group' => 'tilt_settings',
403 'label' => esc_html__( 'Tilt rotation', 'bricksable' ),
404 'type' => 'slider',
405 'unitless' => true,
406 'min' => 10,
407 'max' => 100,
408 'step' => '1',
409 'default' => 40,
410 );
411
412 $this->controls['tilt_speed'] = array(
413 'tab' => 'content',
414 'group' => 'tilt_settings',
415 'label' => esc_html__( 'Tilt Speed', 'bricksable' ),
416 'type' => 'slider',
417 'unitless' => true,
418 'min' => 200,
419 'max' => 2000,
420 'step' => '100',
421 'default' => 1000,
422 );
423
424 $this->controls['tilt_perspective'] = array(
425 'tab' => 'content',
426 'group' => 'tilt_settings',
427 'label' => esc_html__( 'Tilt Perspective', 'bricksable' ),
428 'type' => 'slider',
429 'unitless' => true,
430 'min' => 200,
431 'max' => 1200,
432 'step' => '100',
433 'default' => 1000,
434 );
435
436 $this->controls['tilt_scale'] = array(
437 'tab' => 'content',
438 'group' => 'tilt_settings',
439 'label' => esc_html__( 'Tilt Scale', 'bricksable' ),
440 'type' => 'slider',
441 'unitless' => true,
442 'min' => 1,
443 'max' => 2,
444 'step' => '0.01',
445 'default' => 1,
446 );
447
448 $this->controls['tilt_glare'] = array(
449 'tab' => 'content',
450 'group' => 'tilt_settings',
451 'label' => esc_html__( 'Use glare', 'bricksable' ),
452 'type' => 'checkbox',
453 'inline' => true,
454 'description' => esc_html__( 'Setting this option will enable a glare effect.', 'bricksable' ),
455 );
456
457 $this->controls['tilt_max_glare'] = array(
458 'tab' => 'content',
459 'group' => 'tilt_settings',
460 'label' => esc_html__( 'Max Glare', 'bricksable' ),
461 'type' => 'slider',
462 'unitless' => true,
463 'min' => 0.1,
464 'max' => 1,
465 'step' => '0.01',
466 'default' => 0.8,
467 'required' => array( 'tilt_glare', '=', true ),
468 );
469 }
470
471 public function enqueue_scripts() {
472 if ( '' === get_option( 'bricksable_combine_minify_js' ) || false === get_option( 'bricksable_combine_minify_js' ) ) {
473 wp_enqueue_script( 'ba-tilt-image' );
474 wp_localize_script(
475 'ba-tilt-image',
476 'bricksableTiltImageData',
477 array(
478 'tiltImageInstances' => array(),
479 )
480 );
481 }
482 }
483
484 public function get_normalized_image_settings( $settings ) {
485 if ( ! isset( $settings['image'] ) ) {
486 $settings['image'] = array(
487 'id' => 0,
488 'url' => '',
489 );
490 return $settings;
491 }
492
493 $image = $settings['image'];
494
495 if ( isset( $image['useDynamicData']['name'] ) ) {
496 $images = $this->render_dynamic_data_tag( $image['useDynamicData']['name'] );
497 $image['id'] = empty( $images ) ? 0 : $images[0];
498 } else {
499 $image['id'] = isset( $image['id'] ) ? $image['id'] : 0;
500 }
501
502 // Image Size.
503 $image['size'] = isset( $image['size'] ) ? $settings['image']['size'] : BRICKS_DEFAULT_IMAGE_SIZE;
504
505 // Image URL.
506 if ( ! isset( $image['url'] ) ) {
507 $image['url'] = wp_get_attachment_image_url( $image['id'], $image['size'] );
508 }
509
510 $settings['image'] = $image;
511
512 return $settings;
513 }
514
515 public function render() {
516 $settings = $this->settings;
517 $settings = $this->get_normalized_image_settings( $settings );
518
519 $tilt_max = isset( $settings['tilt_max'] ) ? intval( $settings['tilt_max'] ) : 40;
520 $tilt_speed = isset( $settings['tilt_speed'] ) ? intval( $settings['tilt_speed'] ) : 1000;
521 $tilt_perspective = isset( $settings['tilt_perspective'] ) ? intval( $settings['tilt_perspective'] ) : 1000;
522 $tilt_scale = isset( $settings['tilt_scale'] ) ? round( $settings['tilt_scale'], 1 ) : 1;
523 $tilt_glare = isset( $settings['tilt_glare'] ) ? true : false;
524 $tilt_maxglare = isset( $settings['tilt_max_glare'] ) ? round( $settings['tilt_max_glare'], 1 ) : 1;
525 $tilt_reverse = isset( $settings['tilt_reverse'] ) ? true : false;
526
527 $tilt_options = array(
528 'max' => $tilt_max,
529 'speed' => $tilt_speed,
530 'perspective' => $tilt_perspective,
531 'scale' => $tilt_scale,
532 'glare' => $tilt_glare,
533 'max-glare' => $tilt_maxglare,
534 'reverse' => $tilt_reverse,
535 );
536
537 // Dynamic Data is empty.
538 if ( isset( $settings['image']['useDynamicData']['name'] ) ) {
539
540 if ( empty( $settings['image']['id'] ) ) {
541
542 if ( 'ACF' === $settings['image']['useDynamicData']['group'] && ! class_exists( 'ACF' ) ) {
543 $message = esc_html__( 'Can\'t render element, as the selected ACF field is not available. Please activate ACF or edit the element to select different data.', 'bricksable' );
544 } elseif ( '{featured_image}' === $settings['image']['useDynamicData']['name'] ) {
545 $message = esc_html__( 'No featured image set.', 'bricksable' );
546 } else {
547 /* translators: 1: Data 2: Dynamic Value */
548 $message = esc_html__( 'Dynamic Data %1$s (%2$s) is empty.', 'bricksable' );
549 }
550
551 $this->set_attribute( 'ba-no-image-wrapper', 'class', 'ba-tilt-image-wrapper' );
552 $this->set_attribute( 'ba-no-image-wrapper', 'id', esc_attr( 'ba-tilt-image-' . $this->id ) );
553 $this->set_attribute( 'ba-no-image-wrapper', 'data-ba-bricks-tilt-image-options', wp_json_encode( $tilt_options ) );
554
555 echo '<div ' . $this->render_attributes( 'ba-no-image-wrapper' ) . '>'; //phpcs:ignore
556
557 return $this->render_element_placeholder(
558 array(
559 'icon-class' => 'ti-image',
560 'text' => sprintf(
561 $message,
562 $settings['image']['useDynamicData']['label'],
563 $settings['image']['useDynamicData']['group']
564 ),
565 )
566 );
567 //phpcs:ignore
568 echo '</div>';
569
570 }
571 } else {
572 // Image id is empty or doesn't exist.
573 // No image.
574 if ( empty( $settings['image']['id'] ) ) {
575 $this->set_attribute( 'ba-no-image-wrapper', 'class', 'ba-tilt-image-wrapper' );
576 $this->set_attribute( 'ba-no-image-wrapper', 'id', esc_attr( 'ba-tilt-image-' . $this->id ) );
577 $this->set_attribute( 'ba-no-image-wrapper', 'data-ba-bricks-tilt-image-options', wp_json_encode( $tilt_options ) );
578
579 echo '<div ' . $this->render_attributes( 'ba-no-image-wrapper' ) . '>'; //phpcs:ignore
580
581 return $this->render_element_placeholder(
582 array(
583 'icon-class' => 'ti-image',
584 'text' => esc_html__( 'No image selected.', 'bricksable' ),
585 )
586 );
587 //phpcs:ignore
588 echo '</div>';
589 }
590
591 // Return if image ID does not exist.
592 if ( ! wp_get_attachment_image_src( $settings['image']['id'] ) ) {
593 return $this->render_element_placeholder(
594 array(
595 'icon-class' => 'ti-image',
596 /* translators: 1: Image ID */
597 'text' => sprintf( esc_html__( 'Image ID (%s) no longer exist. Please select another image.', 'bricksable' ), $settings['image']['id'] ),
598 )
599 );
600 }
601 }
602
603 // Render.
604 $image_atts = array();
605 $image_atts['id'] = 'image-' . $settings['image']['id'];
606
607 $image_wrapper_classes = array( 'ba-tilt-image-wrapper' );
608 $img_classes = array( 'post-thumbnail', 'css-filter' );
609
610 if ( isset( $settings['overlayShowHover'] ) ) {
611 $image_wrapper_classes[] = 'ba-tilt-image-show-hover';
612 }
613
614 if ( isset( $settings['imageOverlayShowHover'] ) ) {
615 $image_wrapper_classes[] = 'ba-tilt-image-overlay-hover';
616 }
617
618 if ( isset( $settings['link'] ) && 'lightbox' === $settings['link'] ) {
619 $image_wrapper_classes[] = 'bricks-lightbox';
620
621 $image_src = $settings['image']['id'] ? wp_get_attachment_image_src( $settings['image']['id'], 'full' ) : array(
622 \Bricks\Builder::get_template_placeholder_image(),
623 800,
624 600,
625 );
626 $this->set_attribute( 'image-wrapper', 'data-bricks-lightbox-source="' . $image_src[0] . '"' );
627 $this->set_attribute( 'image-wrapper', 'data-bricks-lightbox-width="' . $image_src[1] . '"' );
628 $this->set_attribute( 'image-wrapper', 'data-bricks-lightbox-height="' . $image_src[2] . '"' );
629 }
630
631 $img_classes[] = 'size-' . $settings['image']['size'];
632 $image_atts['class'] = join( ' ', $img_classes );
633
634 // Title.
635 $show_title = isset( $settings['overlay_title'] ) ? $settings['overlay_title'] : 'none';
636
637 if ( 'none' === $show_title ) {
638 $image_title = false;
639 } elseif ( 'custom' === $show_title && isset( $settings['overlay_title_custom'] ) ) {
640 $image_title = trim( $settings['overlay_title_custom'] );
641 } else {
642 $image_data = get_post( $settings['image']['id'] );
643 $image_title = $image_data ? $image_data->post_title : '';
644 }
645
646 // Caption.
647 $show_caption = isset( $settings['overlay_caption'] ) ? $settings['overlay_caption'] : 'none';
648
649 if ( 'none' === $show_caption ) {
650 $image_caption = false;
651 } elseif ( 'custom' === $show_caption && isset( $settings['overlay_caption_custom'] ) ) {
652 $image_caption = trim( $settings['overlay_caption_custom'] );
653 } else {
654 $image_data = get_post( $settings['image']['id'] );
655 $image_caption = $image_data ? $image_data->post_excerpt : '';
656 }
657
658 $this->set_attribute( 'image-wrapper', 'data-ba-bricks-tilt-image-options', wp_json_encode( $tilt_options ) );
659
660 $this->set_attribute( 'image-wrapper', 'class', $image_wrapper_classes );
661 $this->set_attribute( 'image-wrapper', 'id', esc_attr( 'ba-tilt-image-' . $this->id ) );
662 $this->set_attribute( 'image-wrapper', 'data-tilt' );
663 $this->set_attribute( 'image-wrapper', 'data-tilt-max="' . $tilt_max . '"' );
664 $this->set_attribute( 'image-wrapper', 'data-tilt-speed="' . $tilt_speed . '"' );
665 $this->set_attribute( 'image-wrapper', 'data-tilt-perspective="' . $tilt_perspective . '"' );
666 $this->set_attribute( 'image-wrapper', 'data-tilt-scale="' . $tilt_scale . '"' );
667 $this->set_attribute( 'image-wrapper', $settings['tilt_glare'] ? ' data-tilt-glare' : '' );
668 $this->set_attribute( 'image-wrapper', 'data-tilt-max-glare="' . $tilt_maxglare . '"' );
669 $this->set_attribute( 'image-wrapper', 'data-tilt-reverse="' . $tilt_reverse . '"' );
670
671 echo '<figure ' . $this->render_attributes( 'image-wrapper' ) . '>'; //phpcs:ignore
672
673 $close_a_tag = false;
674
675 if ( isset( $settings['link'] ) && 'media' === $settings['link'] ) {
676 $close_a_tag = true;
677
678 echo '<a href="' . esc_url( wp_get_attachment_url( $settings['image']['id'] ) ) . '" target="_blank">';
679 }
680
681 if ( isset( $settings['link'] ) && 'attachment' === $settings['link'] ) {
682 echo '<a href="' . esc_url( get_permalink( $settings['image']['id'] ) ) . '" target="_blank">';
683 }
684
685 if ( isset( $settings['link'] ) && 'url' === $settings['link'] && isset( $settings['url'] ) ) {
686 $close_a_tag = true;
687
688 // Link.
689 $this->set_link_attributes( 'a', $settings['url'] );
690
691 echo '<a ' . $this->render_attributes( 'a' ) . '>'; //phpcs:ignore
692 }
693
694 // Lazy load atts set via 'wp_get_attachment_image_attributes' filter.
695 if ( isset( $settings['image']['id'] ) ) {
696 echo wp_get_attachment_image( $settings['image']['id'], $settings['image']['size'], false, $image_atts );
697 } elseif ( ! empty( $settings['image']['url'] ) ) {
698 echo '<img src="' . esc_url( $settings['image']['url'] ) . '">';
699 }
700
701 if ( 'none' !== $show_title || 'none' !== $show_caption || isset( $settings['overlay_icon']['icon'] ) ) {
702 $overlay_title_tag = isset( $settings['overlay_title_tag'] ) ? esc_html( $settings['overlay_title_tag'] ) : 'h3';
703 $overlay_title_classes = array(
704 'ba-tilt-image-overlay-title',
705 'bricks-heading',
706 'bricks-heading-' . $overlay_title_tag,
707 );
708 $this->set_attribute( 'overlay_title', $overlay_title_tag );
709 $this->set_attribute( 'overlay_title', 'class', $overlay_title_classes );
710 if ( isset( $settings['overlay_icon']['icon'] ) ) {
711 $icon_classes = array( 'overlay-icon', $settings['overlay_icon']['icon'], 'icon' );
712 $this->set_attribute( 'overlay-icon-wrapper', 'class', 'overlay-icon-wrapper' );
713 $this->set_attribute( 'overlay-icon', 'class', $icon_classes );
714 }
715
716 $overlay_title_output = '<' . $this->render_attributes( 'overlay_title' ) . '>' . esc_html( $image_title ) . '</' . $overlay_title_tag . '>';
717
718 $this->set_attribute( 'image-overlay-wrapper', 'class', 'image-overlay-wrapper' );
719 $this->set_attribute( 'image-overlay-content', 'class', 'image-overlay-content' );
720
721 echo '<div ' . $this->render_attributes( 'image-overlay-wrapper' ) . '>'; //phpcs:ignore
722 echo '<div ' . $this->render_attributes( 'image-overlay-content' ) . '>'; //phpcs:ignore
723 if ( isset( $settings['overlay_icon']['icon'] ) ) {
724 echo '<div ' . $this->render_attributes( 'overlay-icon-wrapper' ) . '>'; //phpcs:ignore
725 echo '<i ' . $this->render_attributes( 'overlay-icon' ) . '></i>'; //phpcs:ignore
726 echo '</div>';
727 }
728 if ( $image_title ) {
729 //phpcs:ignore
730 echo $overlay_title_output;
731 }
732 if ( $image_caption ) {
733 echo '<figcaption class="ba-tilt-image-overlay-caption">' . esc_html( $image_caption ) . '</figcaption>';
734 }
735 echo '</div>';
736 echo '</div>';
737 }
738
739 if ( $close_a_tag ) {
740 echo '</a>';
741 }
742
743 echo '</figure>';
744
745 }
746 }
747