PluginProbe
Elementor Website Builder – more than just a page builder / 3.25.8
Elementor Website Builder – more than just a page builder v3.25.8
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-gallery.php

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

455 lines 10.9 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 use Elementor\Core\Kits\Documents\Tabs\Global_Typography;
5
6 if ( ! defined( 'ABSPATH' ) ) {
7 exit; // Exit if accessed directly.
8 }
9
10 /**
11 * Elementor image gallery widget.
12 *
13 * Elementor widget that displays a set of images in an aligned grid.
14 *
15 * @since 1.0.0
16 */
17 class Widget_Image_Gallery extends Widget_Base {
18
19 /**
20 * Get widget name.
21 *
22 * Retrieve image gallery widget name.
23 *
24 * @since 1.0.0
25 * @access public
26 *
27 * @return string Widget name.
28 */
29 public function get_name() {
30 return 'image-gallery';
31 }
32
33 /**
34 * Get widget title.
35 *
36 * Retrieve image gallery widget title.
37 *
38 * @since 1.0.0
39 * @access public
40 *
41 * @return string Widget title.
42 */
43 public function get_title() {
44 return esc_html__( 'Basic Gallery', 'elementor' );
45 }
46
47 /**
48 * Get widget icon.
49 *
50 * Retrieve image gallery widget icon.
51 *
52 * @since 1.0.0
53 * @access public
54 *
55 * @return string Widget icon.
56 */
57 public function get_icon() {
58 return 'eicon-gallery-grid';
59 }
60
61 /**
62 * Get widget keywords.
63 *
64 * Retrieve the list of keywords the widget belongs to.
65 *
66 * @since 2.1.0
67 * @access public
68 *
69 * @return array Widget keywords.
70 */
71 public function get_keywords() {
72 return [ 'image', 'photo', 'visual', 'gallery' ];
73 }
74
75 protected function is_dynamic_content(): bool {
76 return false;
77 }
78
79 /**
80 * Get style dependencies.
81 *
82 * Retrieve the list of style dependencies the widget requires.
83 *
84 * @since 3.24.0
85 * @access public
86 *
87 * @return array Widget style dependencies.
88 */
89 public function get_style_depends(): array {
90 return [ 'widget-image-gallery' ];
91 }
92
93 /**
94 * Get widget upsale data.
95 *
96 * Retrieve the widget promotion data.
97 *
98 * @since 3.18.0
99 * @access protected
100 *
101 * @return array Widget promotion data.
102 */
103 protected function get_upsale_data() {
104 return [
105 'condition' => ! Utils::has_pro(),
106 'image' => esc_url( ELEMENTOR_ASSETS_URL . 'images/go-pro.svg' ),
107 'image_alt' => esc_attr__( 'Upgrade', 'elementor' ),
108 'description' => esc_html__( 'Use interesting masonry layouts and other overlay features with Elementor\'s Pro Gallery widget.', 'elementor' ),
109 'upgrade_url' => esc_url( 'https://go.elementor.com/go-pro-basic-gallery-widget/' ),
110 'upgrade_text' => esc_html__( 'Upgrade Now', 'elementor' ),
111 ];
112 }
113
114 /**
115 * Register image gallery widget controls.
116 *
117 * Adds different input fields to allow the user to change and customize the widget settings.
118 *
119 * @since 3.1.0
120 * @access protected
121 */
122 protected function register_controls() {
123 $this->start_controls_section(
124 'section_gallery',
125 [
126 'label' => esc_html__( 'Basic Gallery', 'elementor' ),
127 ]
128 );
129
130 $this->add_control(
131 'wp_gallery',
132 [
133 'label' => esc_html__( 'Add Images', 'elementor' ),
134 'type' => Controls_Manager::GALLERY,
135 'show_label' => false,
136 'dynamic' => [
137 'active' => true,
138 ],
139 ]
140 );
141
142 $this->add_group_control(
143 Group_Control_Image_Size::get_type(),
144 [
145 'name' => 'thumbnail', // Usage: `{name}_size` and `{name}_custom_dimension`, in this case `thumbnail_size` and `thumbnail_custom_dimension`.
146 'exclude' => [ 'custom' ],
147 ]
148 );
149
150 $gallery_columns = range( 1, 10 );
151 $gallery_columns = array_combine( $gallery_columns, $gallery_columns );
152
153 $this->add_control(
154 'gallery_columns',
155 [
156 'label' => esc_html__( 'Columns', 'elementor' ),
157 'type' => Controls_Manager::SELECT,
158 'default' => 4,
159 'options' => $gallery_columns,
160 ]
161 );
162
163 $this->add_control(
164 'gallery_display_caption',
165 [
166 'label' => esc_html__( 'Caption', 'elementor' ),
167 'type' => Controls_Manager::SELECT,
168 'default' => '',
169 'options' => [
170 'none' => esc_html__( 'None', 'elementor' ),
171 '' => esc_html__( 'Attachment Caption', 'elementor' ),
172 ],
173 'selectors' => [
174 '{{WRAPPER}} .gallery-item .gallery-caption' => 'display: {{VALUE}};',
175 ],
176 ]
177 );
178
179 $this->add_control(
180 'gallery_link',
181 [
182 'label' => esc_html__( 'Link', 'elementor' ),
183 'type' => Controls_Manager::SELECT,
184 'default' => 'file',
185 'options' => [
186 'file' => esc_html__( 'Media File', 'elementor' ),
187 'attachment' => esc_html__( 'Attachment Page', 'elementor' ),
188 'none' => esc_html__( 'None', 'elementor' ),
189 ],
190 ]
191 );
192
193 $this->add_control(
194 'open_lightbox',
195 [
196 'label' => esc_html__( 'Lightbox', 'elementor' ),
197 'type' => Controls_Manager::SELECT,
198 'description' => sprintf(
199 /* translators: 1: Link open tag, 2: Link close tag. */
200 esc_html__( 'Manage your site’s lightbox settings in the %1$sLightbox panel%2$s.', 'elementor' ),
201 '<a href="javascript: $e.run( \'panel/global/open\' ).then( () => $e.route( \'panel/global/settings-lightbox\' ) )">',
202 '</a>'
203 ),
204 'default' => 'default',
205 'options' => [
206 'default' => esc_html__( 'Default', 'elementor' ),
207 'yes' => esc_html__( 'Yes', 'elementor' ),
208 'no' => esc_html__( 'No', 'elementor' ),
209 ],
210 'condition' => [
211 'gallery_link' => 'file',
212 ],
213 ]
214 );
215
216 $this->add_control(
217 'gallery_rand',
218 [
219 'label' => esc_html__( 'Order By', 'elementor' ),
220 'type' => Controls_Manager::SELECT,
221 'options' => [
222 '' => esc_html__( 'Default', 'elementor' ),
223 'rand' => esc_html__( 'Random', 'elementor' ),
224 ],
225 'default' => '',
226 ]
227 );
228
229 $this->end_controls_section();
230
231 $this->start_controls_section(
232 'section_gallery_images',
233 [
234 'label' => esc_html__( 'Images', 'elementor' ),
235 'tab' => Controls_Manager::TAB_STYLE,
236 ]
237 );
238
239 $this->add_control(
240 'image_spacing',
241 [
242 'label' => esc_html__( 'Spacing', 'elementor' ),
243 'type' => Controls_Manager::SELECT,
244 'options' => [
245 '' => esc_html__( 'Default', 'elementor' ),
246 'custom' => esc_html__( 'Custom', 'elementor' ),
247 ],
248 'prefix_class' => 'gallery-spacing-',
249 'default' => '',
250 ]
251 );
252
253 $columns_margin = is_rtl() ? '0 0 -{{SIZE}}{{UNIT}} -{{SIZE}}{{UNIT}};' : '0 -{{SIZE}}{{UNIT}} -{{SIZE}}{{UNIT}} 0;';
254 $columns_padding = is_rtl() ? '0 0 {{SIZE}}{{UNIT}} {{SIZE}}{{UNIT}};' : '0 {{SIZE}}{{UNIT}} {{SIZE}}{{UNIT}} 0;';
255
256 $this->add_control(
257 'image_spacing_custom',
258 [
259 'label' => esc_html__( 'Custom Spacing', 'elementor' ),
260 'type' => Controls_Manager::SLIDER,
261 'size_units' => [ 'px', 'em', 'rem', 'custom' ],
262 'range' => [
263 'px' => [
264 'max' => 100,
265 ],
266 'em' => [
267 'max' => 10,
268 ],
269 'rem' => [
270 'max' => 10,
271 ],
272 ],
273 'default' => [
274 'size' => 15,
275 ],
276 'selectors' => [
277 '{{WRAPPER}} .gallery-item' => 'padding:' . $columns_padding,
278 '{{WRAPPER}} .gallery' => 'margin: ' . $columns_margin,
279 ],
280 'condition' => [
281 'image_spacing' => 'custom',
282 ],
283 ]
284 );
285
286 $this->add_group_control(
287 Group_Control_Border::get_type(),
288 [
289 'name' => 'image_border',
290 'selector' => '{{WRAPPER}} .gallery-item img',
291 'separator' => 'before',
292 ]
293 );
294
295 $this->add_responsive_control(
296 'image_border_radius',
297 [
298 'label' => esc_html__( 'Border Radius', 'elementor' ),
299 'type' => Controls_Manager::DIMENSIONS,
300 'size_units' => [ 'px', '%', 'em', 'rem', 'custom' ],
301 'selectors' => [
302 '{{WRAPPER}} .gallery-item img' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
303 ],
304 ]
305 );
306
307 $this->end_controls_section();
308
309 $this->start_controls_section(
310 'section_caption',
311 [
312 'label' => esc_html__( 'Caption', 'elementor' ),
313 'tab' => Controls_Manager::TAB_STYLE,
314 'condition' => [
315 'gallery_display_caption' => '',
316 ],
317 ]
318 );
319
320 $this->add_responsive_control(
321 'align',
322 [
323 'label' => esc_html__( 'Alignment', 'elementor' ),
324 'type' => Controls_Manager::CHOOSE,
325 'options' => [
326 'left' => [
327 'title' => esc_html__( 'Left', 'elementor' ),
328 'icon' => 'eicon-text-align-left',
329 ],
330 'center' => [
331 'title' => esc_html__( 'Center', 'elementor' ),
332 'icon' => 'eicon-text-align-center',
333 ],
334 'right' => [
335 'title' => esc_html__( 'Right', 'elementor' ),
336 'icon' => 'eicon-text-align-right',
337 ],
338 'justify' => [
339 'title' => esc_html__( 'Justified', 'elementor' ),
340 'icon' => 'eicon-text-align-justify',
341 ],
342 ],
343 'default' => 'center',
344 'selectors' => [
345 '{{WRAPPER}} .gallery-item .gallery-caption' => 'text-align: {{VALUE}};',
346 ],
347 'condition' => [
348 'gallery_display_caption' => '',
349 ],
350 ]
351 );
352
353 $this->add_control(
354 'text_color',
355 [
356 'label' => esc_html__( 'Text Color', 'elementor' ),
357 'type' => Controls_Manager::COLOR,
358 'default' => '',
359 'selectors' => [
360 '{{WRAPPER}} .gallery-item .gallery-caption' => 'color: {{VALUE}};',
361 ],
362 'condition' => [
363 'gallery_display_caption' => '',
364 ],
365 ]
366 );
367
368 $this->add_group_control(
369 Group_Control_Typography::get_type(),
370 [
371 'name' => 'typography',
372 'global' => [
373 'default' => Global_Typography::TYPOGRAPHY_ACCENT,
374 ],
375 'selector' => '{{WRAPPER}} .gallery-item .gallery-caption',
376 'condition' => [
377 'gallery_display_caption' => '',
378 ],
379 ]
380 );
381
382 $this->add_group_control(
383 Group_Control_Text_Shadow::get_type(),
384 [
385 'name' => 'caption_shadow',
386 'selector' => '{{WRAPPER}} .gallery-item .gallery-caption',
387 'condition' => [
388 'gallery_display_caption' => '',
389 ],
390 ]
391 );
392
393 $this->add_responsive_control(
394 'caption_space',
395 [
396 'label' => esc_html__( 'Spacing', 'elementor' ),
397 'type' => Controls_Manager::SLIDER,
398 'size_units' => [ 'px', '%', 'em', 'rem', 'custom' ],
399 'selectors' => [
400 '{{WRAPPER}} .gallery-item .gallery-caption' => 'margin-block-start: {{SIZE}}{{UNIT}};',
401 ],
402 'condition' => [
403 'gallery_display_caption' => '',
404 ],
405 ]
406 );
407
408 $this->end_controls_section();
409 }
410
411 /**
412 * Render image gallery widget output on the frontend.
413 *
414 * Written in PHP and used to generate the final HTML.
415 *
416 * @since 1.0.0
417 * @access protected
418 */
419 protected function render() {
420 $settings = $this->get_settings_for_display();
421
422 if ( ! $settings['wp_gallery'] ) {
423 return;
424 }
425
426 $ids = wp_list_pluck( $settings['wp_gallery'], 'id' );
427
428 $this->add_render_attribute( 'shortcode', 'ids', implode( ',', $ids ) );
429 $this->add_render_attribute( 'shortcode', 'size', $settings['thumbnail_size'] );
430
431 if ( $settings['gallery_columns'] ) {
432 $this->add_render_attribute( 'shortcode', 'columns', $settings['gallery_columns'] );
433 }
434
435 if ( $settings['gallery_link'] ) {
436 $this->add_render_attribute( 'shortcode', 'link', $settings['gallery_link'] );
437 }
438
439 if ( ! empty( $settings['gallery_rand'] ) ) {
440 $this->add_render_attribute( 'shortcode', 'orderby', $settings['gallery_rand'] );
441 }
442 ?>
443 <div class="elementor-image-gallery">
444 <?php
445 add_filter( 'wp_get_attachment_link', [ $this, 'add_lightbox_data_to_image_link' ], 10, 2 );
446
447 echo do_shortcode( '[gallery ' . $this->get_render_attribute_string( 'shortcode' ) . ']' );
448
449 remove_filter( 'wp_get_attachment_link', [ $this, 'add_lightbox_data_to_image_link' ] );
450 ?>
451 </div>
452 <?php
453 }
454 }
455