PluginProbe
Elementor Website Builder – more than just a page builder / 3.22.3
Elementor Website Builder – more than just a page builder v3.22.3
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.22.3, at includes/widgets/image-gallery.php

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