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

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

385 lines 8.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 __( '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 /**
76 * Register image gallery widget controls.
77 *
78 * Adds different input fields to allow the user to change and customize the widget settings.
79 *
80 * @since 3.1.0
81 * @access protected
82 */
83 protected function register_controls() {
84 $this->start_controls_section(
85 'section_gallery',
86 [
87 'label' => __( 'Image Gallery', 'elementor' ),
88 ]
89 );
90
91 $this->add_control(
92 'wp_gallery',
93 [
94 'label' => __( 'Add Images', 'elementor' ),
95 'type' => Controls_Manager::GALLERY,
96 'show_label' => false,
97 'dynamic' => [
98 'active' => true,
99 ],
100 ]
101 );
102
103 $this->add_group_control(
104 Group_Control_Image_Size::get_type(),
105 [
106 'name' => 'thumbnail', // Usage: `{name}_size` and `{name}_custom_dimension`, in this case `thumbnail_size` and `thumbnail_custom_dimension`.
107 'exclude' => [ 'custom' ],
108 'separator' => 'none',
109 ]
110 );
111
112 $gallery_columns = range( 1, 10 );
113 $gallery_columns = array_combine( $gallery_columns, $gallery_columns );
114
115 $this->add_control(
116 'gallery_columns',
117 [
118 'label' => __( 'Columns', 'elementor' ),
119 'type' => Controls_Manager::SELECT,
120 'default' => 4,
121 'options' => $gallery_columns,
122 ]
123 );
124
125 $this->add_control(
126 'gallery_link',
127 [
128 'label' => __( 'Link', 'elementor' ),
129 'type' => Controls_Manager::SELECT,
130 'default' => 'file',
131 'options' => [
132 'file' => __( 'Media File', 'elementor' ),
133 'attachment' => __( 'Attachment Page', 'elementor' ),
134 'none' => __( 'None', 'elementor' ),
135 ],
136 ]
137 );
138
139 $this->add_control(
140 'open_lightbox',
141 [
142 'label' => __( 'Lightbox', 'elementor' ),
143 'type' => Controls_Manager::SELECT,
144 'default' => 'default',
145 'options' => [
146 'default' => __( 'Default', 'elementor' ),
147 'yes' => __( 'Yes', 'elementor' ),
148 'no' => __( 'No', 'elementor' ),
149 ],
150 'condition' => [
151 'gallery_link' => 'file',
152 ],
153 ]
154 );
155
156 $this->add_control(
157 'gallery_rand',
158 [
159 'label' => __( 'Order By', 'elementor' ),
160 'type' => Controls_Manager::SELECT,
161 'options' => [
162 '' => __( 'Default', 'elementor' ),
163 'rand' => __( 'Random', 'elementor' ),
164 ],
165 'default' => '',
166 ]
167 );
168
169 $this->add_control(
170 'view',
171 [
172 'label' => __( 'View', 'elementor' ),
173 'type' => Controls_Manager::HIDDEN,
174 'default' => 'traditional',
175 ]
176 );
177
178 $this->end_controls_section();
179
180 $this->start_controls_section(
181 'section_gallery_images',
182 [
183 'label' => __( 'Images', 'elementor' ),
184 'tab' => Controls_Manager::TAB_STYLE,
185 ]
186 );
187
188 $this->add_control(
189 'image_spacing',
190 [
191 'label' => __( 'Spacing', 'elementor' ),
192 'type' => Controls_Manager::SELECT,
193 'options' => [
194 '' => __( 'Default', 'elementor' ),
195 'custom' => __( 'Custom', 'elementor' ),
196 ],
197 'prefix_class' => 'gallery-spacing-',
198 'default' => '',
199 ]
200 );
201
202 $columns_margin = is_rtl() ? '0 0 -{{SIZE}}{{UNIT}} -{{SIZE}}{{UNIT}};' : '0 -{{SIZE}}{{UNIT}} -{{SIZE}}{{UNIT}} 0;';
203 $columns_padding = is_rtl() ? '0 0 {{SIZE}}{{UNIT}} {{SIZE}}{{UNIT}};' : '0 {{SIZE}}{{UNIT}} {{SIZE}}{{UNIT}} 0;';
204
205 $this->add_control(
206 'image_spacing_custom',
207 [
208 'label' => __( 'Image Spacing', 'elementor' ),
209 'type' => Controls_Manager::SLIDER,
210 'show_label' => false,
211 'range' => [
212 'px' => [
213 'max' => 100,
214 ],
215 ],
216 'default' => [
217 'size' => 15,
218 ],
219 'selectors' => [
220 '{{WRAPPER}} .gallery-item' => 'padding:' . $columns_padding,
221 '{{WRAPPER}} .gallery' => 'margin: ' . $columns_margin,
222 ],
223 'condition' => [
224 'image_spacing' => 'custom',
225 ],
226 ]
227 );
228
229 $this->add_group_control(
230 Group_Control_Border::get_type(),
231 [
232 'name' => 'image_border',
233 'selector' => '{{WRAPPER}} .gallery-item img',
234 'separator' => 'before',
235 ]
236 );
237
238 $this->add_control(
239 'image_border_radius',
240 [
241 'label' => __( 'Border Radius', 'elementor' ),
242 'type' => Controls_Manager::DIMENSIONS,
243 'size_units' => [ 'px', '%' ],
244 'selectors' => [
245 '{{WRAPPER}} .gallery-item img' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
246 ],
247 ]
248 );
249
250 $this->end_controls_section();
251
252 $this->start_controls_section(
253 'section_caption',
254 [
255 'label' => __( 'Caption', 'elementor' ),
256 'tab' => Controls_Manager::TAB_STYLE,
257 ]
258 );
259
260 $this->add_control(
261 'gallery_display_caption',
262 [
263 'label' => __( 'Display', 'elementor' ),
264 'type' => Controls_Manager::SELECT,
265 'default' => '',
266 'options' => [
267 '' => __( 'Show', 'elementor' ),
268 'none' => __( 'Hide', 'elementor' ),
269 ],
270 'selectors' => [
271 '{{WRAPPER}} .gallery-item .gallery-caption' => 'display: {{VALUE}};',
272 ],
273 ]
274 );
275
276 $this->add_control(
277 'align',
278 [
279 'label' => __( 'Alignment', 'elementor' ),
280 'type' => Controls_Manager::CHOOSE,
281 'options' => [
282 'left' => [
283 'title' => __( 'Left', 'elementor' ),
284 'icon' => 'eicon-text-align-left',
285 ],
286 'center' => [
287 'title' => __( 'Center', 'elementor' ),
288 'icon' => 'eicon-text-align-center',
289 ],
290 'right' => [
291 'title' => __( 'Right', 'elementor' ),
292 'icon' => 'eicon-text-align-right',
293 ],
294 'justify' => [
295 'title' => __( 'Justified', 'elementor' ),
296 'icon' => 'eicon-text-align-justify',
297 ],
298 ],
299 'default' => 'center',
300 'selectors' => [
301 '{{WRAPPER}} .gallery-item .gallery-caption' => 'text-align: {{VALUE}};',
302 ],
303 'condition' => [
304 'gallery_display_caption' => '',
305 ],
306 ]
307 );
308
309 $this->add_control(
310 'text_color',
311 [
312 'label' => __( 'Text Color', 'elementor' ),
313 'type' => Controls_Manager::COLOR,
314 'default' => '',
315 'selectors' => [
316 '{{WRAPPER}} .gallery-item .gallery-caption' => 'color: {{VALUE}};',
317 ],
318 'condition' => [
319 'gallery_display_caption' => '',
320 ],
321 ]
322 );
323
324 $this->add_group_control(
325 Group_Control_Typography::get_type(),
326 [
327 'name' => 'typography',
328 'global' => [
329 'default' => Global_Typography::TYPOGRAPHY_ACCENT,
330 ],
331 'selector' => '{{WRAPPER}} .gallery-item .gallery-caption',
332 'condition' => [
333 'gallery_display_caption' => '',
334 ],
335 ]
336 );
337
338 $this->end_controls_section();
339 }
340
341 /**
342 * Render image gallery widget output on the frontend.
343 *
344 * Written in PHP and used to generate the final HTML.
345 *
346 * @since 1.0.0
347 * @access protected
348 */
349 protected function render() {
350 $settings = $this->get_settings_for_display();
351
352 if ( ! $settings['wp_gallery'] ) {
353 return;
354 }
355
356 $ids = wp_list_pluck( $settings['wp_gallery'], 'id' );
357
358 $this->add_render_attribute( 'shortcode', 'ids', implode( ',', $ids ) );
359 $this->add_render_attribute( 'shortcode', 'size', $settings['thumbnail_size'] );
360
361 if ( $settings['gallery_columns'] ) {
362 $this->add_render_attribute( 'shortcode', 'columns', $settings['gallery_columns'] );
363 }
364
365 if ( $settings['gallery_link'] ) {
366 $this->add_render_attribute( 'shortcode', 'link', $settings['gallery_link'] );
367 }
368
369 if ( ! empty( $settings['gallery_rand'] ) ) {
370 $this->add_render_attribute( 'shortcode', 'orderby', $settings['gallery_rand'] );
371 }
372 ?>
373 <div class="elementor-image-gallery">
374 <?php
375 add_filter( 'wp_get_attachment_link', [ $this, 'add_lightbox_data_to_image_link' ], 10, 2 );
376
377 echo do_shortcode( '[gallery ' . $this->get_render_attribute_string( 'shortcode' ) . ']' );
378
379 remove_filter( 'wp_get_attachment_link', [ $this, 'add_lightbox_data_to_image_link' ] );
380 ?>
381 </div>
382 <?php
383 }
384 }
385