PluginProbe
Elementor Website Builder – more than just a page builder / 3.4.0-dev9
Elementor Website Builder – more than just a page builder v3.4.0-dev9
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 / testimonial.php

testimonial.php in Elementor Website Builder – more than just a page builder 3.4.0-dev9, at includes/widgets/testimonial.php

605 lines 15.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 use Elementor\Core\Kits\Documents\Tabs\Global_Typography;
10
11 /**
12 * Elementor testimonial widget.
13 *
14 * Elementor widget that displays customer testimonials that show social proof.
15 *
16 * @since 1.0.0
17 */
18 class Widget_Testimonial extends Widget_Base {
19
20 /**
21 * Get widget name.
22 *
23 * Retrieve testimonial 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 'testimonial';
32 }
33
34 /**
35 * Get widget title.
36 *
37 * Retrieve testimonial 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__( 'Testimonial', 'elementor' );
46 }
47
48 /**
49 * Get widget icon.
50 *
51 * Retrieve testimonial 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-testimonial';
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 [ 'testimonial', 'blockquote' ];
74 }
75
76 /**
77 * Register testimonial 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_testimonial',
87 [
88 'label' => esc_html__( 'Testimonial', 'elementor' ),
89 ]
90 );
91
92 $this->add_control(
93 'testimonial_content',
94 [
95 'label' => esc_html__( 'Content', 'elementor' ),
96 'type' => Controls_Manager::TEXTAREA,
97 'dynamic' => [
98 'active' => true,
99 ],
100 'rows' => '10',
101 'default' => esc_html__( 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut elit tellus, luctus nec ullamcorper mattis, pulvinar dapibus leo.', 'elementor' ),
102 ]
103 );
104
105 $this->add_control(
106 'testimonial_image',
107 [
108 'label' => esc_html__( 'Choose Image', 'elementor' ),
109 'type' => Controls_Manager::MEDIA,
110 'dynamic' => [
111 'active' => true,
112 ],
113 'default' => [
114 'url' => Utils::get_placeholder_image_src(),
115 ],
116 ]
117 );
118
119 $this->add_group_control(
120 Group_Control_Image_Size::get_type(),
121 [
122 'name' => 'testimonial_image', // Usage: `{name}_size` and `{name}_custom_dimension`, in this case `testimonial_image_size` and `testimonial_image_custom_dimension`.
123 'default' => 'full',
124 'separator' => 'none',
125 ]
126 );
127
128 $this->add_control(
129 'testimonial_name',
130 [
131 'label' => esc_html__( 'Name', 'elementor' ),
132 'type' => Controls_Manager::TEXT,
133 'dynamic' => [
134 'active' => true,
135 ],
136 'default' => 'John Doe',
137 ]
138 );
139
140 $this->add_control(
141 'testimonial_job',
142 [
143 'label' => esc_html__( 'Title', 'elementor' ),
144 'type' => Controls_Manager::TEXT,
145 'dynamic' => [
146 'active' => true,
147 ],
148 'default' => 'Designer',
149 ]
150 );
151
152 $this->add_control(
153 'link',
154 [
155 'label' => esc_html__( 'Link', 'elementor' ),
156 'type' => Controls_Manager::URL,
157 'dynamic' => [
158 'active' => true,
159 ],
160 'placeholder' => esc_html__( 'https://your-link.com', 'elementor' ),
161 ]
162 );
163
164 $this->add_control(
165 'testimonial_image_position',
166 [
167 'label' => esc_html__( 'Image Position', 'elementor' ),
168 'type' => Controls_Manager::SELECT,
169 'default' => 'aside',
170 'options' => [
171 'aside' => esc_html__( 'Aside', 'elementor' ),
172 'top' => esc_html__( 'Top', 'elementor' ),
173 ],
174 'condition' => [
175 'testimonial_image[url]!' => '',
176 ],
177 'separator' => 'before',
178 'style_transfer' => true,
179 ]
180 );
181
182 $this->add_control(
183 'testimonial_alignment',
184 [
185 'label' => esc_html__( 'Alignment', 'elementor' ),
186 'type' => Controls_Manager::CHOOSE,
187 'default' => 'center',
188 'options' => [
189 'left' => [
190 'title' => esc_html__( 'Left', 'elementor' ),
191 'icon' => 'eicon-text-align-left',
192 ],
193 'center' => [
194 'title' => esc_html__( 'Center', 'elementor' ),
195 'icon' => 'eicon-text-align-center',
196 ],
197 'right' => [
198 'title' => esc_html__( 'Right', 'elementor' ),
199 'icon' => 'eicon-text-align-right',
200 ],
201 ],
202 'style_transfer' => true,
203 ]
204 );
205
206 $this->add_control(
207 'view',
208 [
209 'label' => esc_html__( 'View', 'elementor' ),
210 'type' => Controls_Manager::HIDDEN,
211 'default' => 'traditional',
212 ]
213 );
214
215 $this->end_controls_section();
216
217 // Content.
218 $this->start_controls_section(
219 'section_style_testimonial_content',
220 [
221 'label' => esc_html__( 'Content', 'elementor' ),
222 'tab' => Controls_Manager::TAB_STYLE,
223 ]
224 );
225
226 $this->add_control(
227 'content_content_color',
228 [
229 'label' => esc_html__( 'Text Color', 'elementor' ),
230 'type' => Controls_Manager::COLOR,
231 'global' => [
232 'default' => Global_Colors::COLOR_TEXT,
233 ],
234 'default' => '',
235 'selectors' => [
236 '{{WRAPPER}} .elementor-testimonial-content' => 'color: {{VALUE}};',
237 ],
238 ]
239 );
240
241 $this->add_group_control(
242 Group_Control_Typography::get_type(),
243 [
244 'name' => 'content_typography',
245 'global' => [
246 'default' => Global_Typography::TYPOGRAPHY_TEXT,
247 ],
248 'selector' => '{{WRAPPER}} .elementor-testimonial-content',
249 ]
250 );
251
252 $this->add_group_control(
253 Group_Control_Text_Shadow::get_type(),
254 [
255 'name' => 'content_shadow',
256 'selector' => '{{WRAPPER}} .elementor-testimonial-content',
257 ]
258 );
259
260 $this->end_controls_section();
261
262 // Image.
263 $this->start_controls_section(
264 'section_style_testimonial_image',
265 [
266 'label' => esc_html__( 'Image', 'elementor' ),
267 'tab' => Controls_Manager::TAB_STYLE,
268 'condition' => [
269 'testimonial_image[url]!' => '',
270 ],
271 ]
272 );
273
274 $this->add_control(
275 'image_size',
276 [
277 'label' => esc_html__( 'Image Size', 'elementor' ),
278 'type' => Controls_Manager::SLIDER,
279 'size_units' => [ 'px' ],
280 'range' => [
281 'px' => [
282 'min' => 20,
283 'max' => 200,
284 ],
285 ],
286 'selectors' => [
287 '{{WRAPPER}} .elementor-testimonial-wrapper .elementor-testimonial-image img' => 'width: {{SIZE}}{{UNIT}};height: {{SIZE}}{{UNIT}};',
288 ],
289 ]
290 );
291
292 $this->add_group_control(
293 Group_Control_Border::get_type(),
294 [
295 'name' => 'image_border',
296 'selector' => '{{WRAPPER}} .elementor-testimonial-wrapper .elementor-testimonial-image img',
297 'separator' => 'before',
298 ]
299 );
300
301 $this->add_control(
302 'image_border_radius',
303 [
304 'label' => esc_html__( 'Border Radius', 'elementor' ),
305 'type' => Controls_Manager::DIMENSIONS,
306 'size_units' => [ 'px', '%' ],
307 'selectors' => [
308 '{{WRAPPER}} .elementor-testimonial-wrapper .elementor-testimonial-image img' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
309 ],
310 ]
311 );
312
313 $this->end_controls_section();
314
315 // Name.
316 $this->start_controls_section(
317 'section_style_testimonial_name',
318 [
319 'label' => esc_html__( 'Name', 'elementor' ),
320 'tab' => Controls_Manager::TAB_STYLE,
321 ]
322 );
323
324 $this->add_control(
325 'name_text_color',
326 [
327 'label' => esc_html__( 'Text Color', 'elementor' ),
328 'type' => Controls_Manager::COLOR,
329 'global' => [
330 'default' => Global_Colors::COLOR_PRIMARY,
331 ],
332 'default' => '',
333 'selectors' => [
334 '{{WRAPPER}} .elementor-testimonial-name' => 'color: {{VALUE}};',
335 ],
336 ]
337 );
338
339 $this->add_group_control(
340 Group_Control_Typography::get_type(),
341 [
342 'name' => 'name_typography',
343 'global' => [
344 'default' => Global_Typography::TYPOGRAPHY_PRIMARY,
345 ],
346 'selector' => '{{WRAPPER}} .elementor-testimonial-name',
347 ]
348 );
349
350 $this->add_group_control(
351 Group_Control_Text_Shadow::get_type(),
352 [
353 'name' => 'name_shadow',
354 'selector' => '{{WRAPPER}} .elementor-testimonial-name',
355 ]
356 );
357
358 $this->end_controls_section();
359
360 // Job.
361 $this->start_controls_section(
362 'section_style_testimonial_job',
363 [
364 'label' => esc_html__( 'Title', 'elementor' ),
365 'tab' => Controls_Manager::TAB_STYLE,
366 ]
367 );
368
369 $this->add_control(
370 'job_text_color',
371 [
372 'label' => esc_html__( 'Text Color', 'elementor' ),
373 'type' => Controls_Manager::COLOR,
374 'global' => [
375 'default' => Global_Colors::COLOR_SECONDARY,
376 ],
377 'default' => '',
378 'selectors' => [
379 '{{WRAPPER}} .elementor-testimonial-job' => 'color: {{VALUE}};',
380 ],
381 ]
382 );
383
384 $this->add_group_control(
385 Group_Control_Typography::get_type(),
386 [
387 'name' => 'job_typography',
388 'global' => [
389 'default' => Global_Typography::TYPOGRAPHY_SECONDARY,
390 ],
391 'selector' => '{{WRAPPER}} .elementor-testimonial-job',
392 ]
393 );
394
395 $this->add_group_control(
396 Group_Control_Text_Shadow::get_type(),
397 [
398 'name' => 'job_shadow',
399 'selector' => '{{WRAPPER}} .elementor-testimonial-job',
400 ]
401 );
402
403 $this->end_controls_section();
404 }
405
406 /**
407 * Render testimonial widget output on the frontend.
408 *
409 * Written in PHP and used to generate the final HTML.
410 *
411 * @since 1.0.0
412 * @access protected
413 */
414 protected function render() {
415 $settings = $this->get_settings_for_display();
416
417 $this->add_render_attribute( 'wrapper', 'class', 'elementor-testimonial-wrapper' );
418
419 if ( $settings['testimonial_alignment'] ) {
420 $this->add_render_attribute( 'wrapper', 'class', 'elementor-testimonial-text-align-' . $settings['testimonial_alignment'] );
421 }
422
423 $this->add_render_attribute( 'meta', 'class', 'elementor-testimonial-meta' );
424
425 if ( $settings['testimonial_image']['url'] ) {
426 $this->add_render_attribute( 'meta', 'class', 'elementor-has-image' );
427 }
428
429 if ( $settings['testimonial_image_position'] ) {
430 $this->add_render_attribute( 'meta', 'class', 'elementor-testimonial-image-position-' . $settings['testimonial_image_position'] );
431 }
432
433 $has_content = ! ! $settings['testimonial_content'];
434 $has_image = ! ! $settings['testimonial_image']['url'];
435 $has_name = ! ! $settings['testimonial_name'];
436 $has_job = ! ! $settings['testimonial_job'];
437
438 if ( ! $has_content && ! $has_image && ! $has_name && ! $has_job ) {
439 return;
440 }
441
442 if ( ! empty( $settings['link']['url'] ) ) {
443 $this->add_link_attributes( 'link', $settings['link'] );
444 }
445 ?>
446 <div <?php $this->print_render_attribute_string( 'wrapper' ); ?>>
447 <?php
448 if ( $has_content ) :
449 $this->add_render_attribute( 'testimonial_content', 'class', 'elementor-testimonial-content' );
450 $this->add_inline_editing_attributes( 'testimonial_content' );
451 ?>
452 <div <?php $this->print_render_attribute_string( 'testimonial_content' ); ?>><?php $this->print_unescaped_setting( 'testimonial_content' ); ?></div>
453 <?php endif; ?>
454
455 <?php if ( $has_image || $has_name || $has_job ) : ?>
456 <div <?php $this->print_render_attribute_string( 'meta' ); ?>>
457 <div class="elementor-testimonial-meta-inner">
458 <?php if ( $has_image ) : ?>
459 <div class="elementor-testimonial-image">
460 <?php
461 $image_html = Group_Control_Image_Size::get_attachment_image_html( $settings, 'testimonial_image' );
462 if ( ! empty( $settings['link']['url'] ) ) :
463 $image_html = '<a ' . $this->get_render_attribute_string( 'link' ) . '>' . $image_html . '</a>';
464 endif;
465 echo wp_kses_post( $image_html );
466 ?>
467 </div>
468 <?php endif; ?>
469
470 <?php if ( $has_name || $has_job ) : ?>
471 <div class="elementor-testimonial-details">
472 <?php
473 if ( $has_name ) :
474 $this->add_render_attribute( 'testimonial_name', 'class', 'elementor-testimonial-name' );
475 $this->add_inline_editing_attributes( 'testimonial_name', 'none' );
476
477 if ( ! empty( $settings['link']['url'] ) ) :
478 ?>
479 <a <?php $this->print_render_attribute_string( 'testimonial_name' ); ?> <?php $this->print_render_attribute_string( 'link' ); ?>><?php $this->print_unescaped_setting( 'testimonial_name' ); ?></a>
480 <?php
481 else :
482 ?>
483 <div <?php $this->print_render_attribute_string( 'testimonial_name' ); ?>><?php $this->print_unescaped_setting( 'testimonial_name' ); ?></div>
484 <?php
485 endif;
486 endif; ?>
487 <?php
488 if ( $has_job ) :
489 $this->add_render_attribute( 'testimonial_job', 'class', 'elementor-testimonial-job' );
490
491 $this->add_inline_editing_attributes( 'testimonial_job', 'none' );
492
493 if ( ! empty( $settings['link']['url'] ) ) :
494 ?>
495 <a <?php $this->print_render_attribute_string( 'testimonial_job' ); ?> <?php $this->print_render_attribute_string( 'link' ); ?>><?php $this->print_unescaped_setting( 'testimonial_job' ); ?></a>
496 <?php
497 else :
498 ?>
499 <div <?php $this->print_render_attribute_string( 'testimonial_job' ); ?>><?php $this->print_unescaped_setting( 'testimonial_job' ); ?></div>
500 <?php
501 endif;
502 endif; ?>
503 </div>
504 <?php endif; ?>
505 </div>
506 </div>
507 <?php endif; ?>
508 </div>
509 <?php
510 }
511
512 /**
513 * Render testimonial widget output in the editor.
514 *
515 * Written as a Backbone JavaScript template and used to generate the live preview.
516 *
517 * @since 2.9.0
518 * @access protected
519 */
520 protected function content_template() {
521 ?>
522 <#
523 var image = {
524 id: settings.testimonial_image.id,
525 url: settings.testimonial_image.url,
526 size: settings.testimonial_image_size,
527 dimension: settings.testimonial_image_custom_dimension,
528 model: view.getEditModel()
529 };
530 var imageUrl = false, hasImage = '';
531
532 if ( '' !== settings.testimonial_image.url ) {
533 imageUrl = elementor.imagesManager.getImageUrl( image );
534 hasImage = ' elementor-has-image';
535
536 var imageHtml = '<img src="' + imageUrl + '" alt="testimonial" />';
537 if ( settings.link.url ) {
538 imageHtml = '<a href="' + settings.link.url + '">' + imageHtml + '</a>';
539 }
540 }
541
542 var testimonial_alignment = settings.testimonial_alignment ? ' elementor-testimonial-text-align-' + settings.testimonial_alignment : '';
543 var testimonial_image_position = settings.testimonial_image_position ? ' elementor-testimonial-image-position-' + settings.testimonial_image_position : '';
544 #>
545 <div class="elementor-testimonial-wrapper{{ testimonial_alignment }}">
546 <# if ( '' !== settings.testimonial_content ) {
547 view.addRenderAttribute( 'testimonial_content', 'class', 'elementor-testimonial-content' );
548
549 view.addInlineEditingAttributes( 'testimonial_content' );
550 #>
551 <div {{{ view.getRenderAttributeString( 'testimonial_content' ) }}}>{{{ settings.testimonial_content }}}</div>
552 <# } #>
553 <div class="elementor-testimonial-meta{{ hasImage }}{{ testimonial_image_position }}">
554 <div class="elementor-testimonial-meta-inner">
555 <# if ( imageUrl ) { #>
556 <div class="elementor-testimonial-image">{{{ imageHtml }}}</div>
557 <# } #>
558 <div class="elementor-testimonial-details">
559 <?php $this->render_testimonial_description(); ?>
560 </div>
561 </div>
562 </div>
563 </div>
564 <?php
565 }
566
567 protected function render_testimonial_description() {
568 ?>
569 <#
570 if ( '' !== settings.testimonial_name ) {
571 view.addRenderAttribute( 'testimonial_name', 'class', 'elementor-testimonial-name' );
572
573 view.addInlineEditingAttributes( 'testimonial_name', 'none' );
574
575 if ( settings.link.url ) {
576 #>
577 <a href="{{{ settings.link.url }}}" {{{ view.getRenderAttributeString( 'testimonial_name' ) }}}>{{{ settings.testimonial_name }}}</a>
578 <#
579 } else {
580 #>
581 <div {{{ view.getRenderAttributeString( 'testimonial_name' ) }}}>{{{ settings.testimonial_name }}}</div>
582 <#
583 }
584 }
585
586 if ( '' !== settings.testimonial_job ) {
587 view.addRenderAttribute( 'testimonial_job', 'class', 'elementor-testimonial-job' );
588
589 view.addInlineEditingAttributes( 'testimonial_job', 'none' );
590
591 if ( settings.link.url ) {
592 #>
593 <a href="{{{ settings.link.url }}}" {{{ view.getRenderAttributeString( 'testimonial_job' ) }}}>{{{ settings.testimonial_job }}}</a>
594 <#
595 } else {
596 #>
597 <div {{{ view.getRenderAttributeString( 'testimonial_job' ) }}}>{{{ settings.testimonial_job }}}</div>
598 <#
599 }
600 }
601 #>
602 <?php
603 }
604 }
605