PluginProbe
Easy Elements for Elementor – Addons & Website Templates / 1.2.7
Easy Elements for Elementor – Addons & Website Templates v1.2.7
1.5.3 1.5.2 1.5.1 1.5.0 1.4.9 1.4.6 1.4.7 1.4.8 1.4.5 1.4.4 1.4.3 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 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 All 47 releases
easy-elements / widgets / faq / faq.php

faq.php in Easy Elements for Elementor – Addons & Website Templates 1.2.7, at widgets/faq/faq.php

658 lines 18.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Easyel\EasyElements\Widgets;
3 use Elementor\Controls_Manager;
4 use Elementor\Repeater;
5 use Elementor\Icons_Manager;
6 use Elementor\Group_Control_Background;
7
8 if ( ! defined( 'ABSPATH' ) ) {
9 exit;
10 }
11
12 class Easyel_FAQ_Accordion_Widget extends \Elementor\Widget_Base {
13
14 public function get_name() {
15 return 'eel-faq-accordion';
16 }
17
18 public function get_title() {
19 return esc_html__( 'Accordion', 'easy-elements' );
20 }
21
22 public function get_icon() {
23 return 'easyicon easyelIcon-faq-1';
24 }
25
26 public function get_categories() {
27 return [ 'easyelements_category' ];
28 }
29
30 public function get_keywords() {
31 return [ 'faq', 'accordion', 'question', 'answer', 'text' ];
32 }
33
34 public function get_style_depends() {
35 return [
36 'eel-faq-accordion',
37 ];
38 }
39
40 public function get_script_depends() {
41 return [
42 'eel-faq-accordion',
43 ];
44 }
45
46
47 protected function register_controls() {
48 $this->start_controls_section(
49 'section_faq_content',
50 [ 'label' => esc_html__( 'FAQ Items', 'easy-elements' ) ]
51 );
52
53 $repeater = new Repeater();
54
55 $repeater->add_control( 'title', [
56 'label' => esc_html__( 'Question', 'easy-elements' ),
57 'type' => Controls_Manager::TEXT,
58 'label_block' => true,
59 'default' => esc_html__( 'What is Easy Elements?', 'easy-elements' ),
60 ] );
61
62 $repeater->add_control( 'description', [
63 'label' => esc_html__( 'Answer', 'easy-elements' ),
64 'type' => Controls_Manager::TEXTAREA,
65 'default' => esc_html__( 'Easy Elements is a best plugin for Elementor.', 'easy-elements' ),
66 ] );
67
68 $repeater->add_control( 'active_toggle', [
69 'label' => esc_html__( 'Active by Default', 'easy-elements' ),
70 'type' => Controls_Manager::SWITCHER,
71 'label_on' => esc_html__( 'Yes', 'easy-elements' ),
72 'label_off' => esc_html__( 'No', 'easy-elements' ),
73 'return_value' => 'yes',
74 'default' => 'no',
75 ] );
76
77 $this->add_control( 'faq_items', [
78 'label' => esc_html__( 'FAQ List', 'easy-elements' ),
79 'type' => Controls_Manager::REPEATER,
80 'fields' => $repeater->get_controls(),
81 'default' => [
82 [
83 'title' => esc_html__( 'What is Easy Elements?', 'easy-elements' ),
84 'description' => esc_html__( 'Easy Elements is a custom Elementor addon plugin that offers useful widgets.', 'easy-elements' ),
85 ],
86 [
87 'title' => esc_html__( 'Does it work with Elementor Free?', 'easy-elements' ),
88 'description' => esc_html__( 'Yes, it fully supports Elementor Free version without requiring Elementor Pro.', 'easy-elements' ),
89 ],
90 [
91 'title' => esc_html__( 'How to install Easy Elements?', 'easy-elements' ),
92 'description' => esc_html__( 'Upload the plugin via WordPress Dashboard or FTP and activate it.', 'easy-elements' ),
93 ],
94 [
95 'title' => esc_html__( 'What widgets are included?', 'easy-elements' ),
96 'description' => esc_html__( 'Widgets include logo grid, testimonials, CTA sections, pricing tables, and more.', 'easy-elements' ),
97 ],
98 [
99 'title' => esc_html__( 'How do I get support or updates?', 'easy-elements' ),
100 'description' => esc_html__( 'Support and updates are available via the official website or marketplace.', 'easy-elements' ),
101 ],
102 ],
103 'title_field' => '{{{ title }}}',
104 ] );
105
106 $this->add_control( 'title_tag', [
107 'label' => esc_html__( 'Title HTML Tag', 'easy-elements' ),
108 'type' => Controls_Manager::SELECT,
109 'default' => 'h4',
110 'options' => [
111 'h1' => 'H1',
112 'h2' => 'H2',
113 'h3' => 'H3',
114 'h4' => 'H4',
115 'h5' => 'H5',
116 'h6' => 'H6',
117 'div' => 'div',
118 'span' => 'span',
119 'p' => 'p',
120 ],
121 ] );
122
123 $this->add_control( 'icon_open', [
124 'label' => esc_html__( 'Open Icon', 'easy-elements' ),
125 'type' => Controls_Manager::ICONS,
126 'default' => [ '' ],
127 ] );
128
129 $this->add_control( 'icon_close', [
130 'label' => esc_html__( 'Close Icon', 'easy-elements' ),
131 'type' => Controls_Manager::ICONS,
132 'default' => [ '' ],
133 ] );
134
135 $this->add_control(
136 'icon_position',
137 [
138 'label' => esc_html__( 'Position', 'easy-elements' ),
139 'type' => \Elementor\Controls_Manager::CHOOSE,
140 'options' => [
141 'row-reverse' => [
142 'title' => esc_html__( 'Left', 'easy-elements' ),
143 'icon' => 'eicon-h-align-left',
144 ],
145 'row' => [
146 'title' => esc_html__( 'Right', 'easy-elements' ),
147 'icon' => 'eicon-h-align-right',
148 ],
149 ],
150 'default' => 'row',
151 'toggle' => true,
152 'selectors' => [
153 '{{WRAPPER}} .eel-faq-question' => 'flex-direction: {{VALUE}}; justify-content: left;',
154 ],
155 ]
156 );
157
158 $this->add_control( 'open_all_toggle', [
159 'label' => esc_html__( 'Open All FAQs by Default', 'easy-elements' ),
160 'type' => Controls_Manager::SWITCHER,
161 'label_on' => esc_html__( 'Yes', 'easy-elements' ),
162 'label_off' => esc_html__( 'No', 'easy-elements' ),
163 'return_value' => 'yes',
164 'default' => 'no',
165 ] );
166
167 $this->add_control( 'enable_sticky', [
168 'label' => esc_html__( 'Enable Sticky', 'easy-elements' ),
169 'type' => Controls_Manager::SWITCHER,
170 'label_on' => esc_html__( 'Yes', 'easy-elements' ),
171 'label_off' => esc_html__( 'No', 'easy-elements' ),
172 'return_value' => 'yes',
173 'default' => 'no',
174 'condition' => [
175 'open_all_toggle' => 'yes',
176 ],
177 ] );
178
179 $this->add_control( 'enable_faq_schema', [
180 'label' => esc_html__( 'Enable FAQ Schema', 'easy-elements' ),
181 'type' => Controls_Manager::SWITCHER,
182 'label_on' => esc_html__( 'Yes', 'easy-elements' ),
183 'label_off' => esc_html__( 'No', 'easy-elements' ),
184 'return_value' => 'yes',
185 'default' => 'no',
186 ] );
187
188 $this->end_controls_section();
189
190 $this->start_controls_section(
191 'item_box_style_section',
192 [
193 'label' => esc_html__( 'Items', 'easy-elements' ),
194 'tab' => Controls_Manager::TAB_STYLE,
195 ]
196 );
197
198 $this->start_controls_tabs( 'item_style_tabs' );
199
200 $this->start_controls_tab(
201 'item_style_normal',
202 [
203 'label' => esc_html__( 'Normal', 'easy-elements' ),
204 ]
205 );
206
207 $this->add_group_control(
208 Group_Control_Background::get_type(),
209 [
210 'name' => 'faq_background',
211 'label' => esc_html__( 'Background Type', 'easy-elements' ),
212 'types' => [ 'classic', 'gradient' ],
213 'selector' => '{{WRAPPER}} .eel-faq-item',
214 ]
215 );
216
217 // Border Radius
218 $this->add_responsive_control( 'item_border_radius', [
219 'label' => esc_html__( 'Border Radius', 'easy-elements' ),
220 'type' => Controls_Manager::DIMENSIONS,
221 'size_units' => [ 'px', '%', 'em' ],
222 'selectors' => [
223 '{{WRAPPER}} .eel-faq-item' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
224 ],
225 ] );
226
227 // Border
228 $this->add_group_control( \Elementor\Group_Control_Border::get_type(), [
229 'name' => 'item_border',
230 'label' => esc_html__( 'Border', 'easy-elements' ),
231 'selector' => '{{WRAPPER}} .eel-faq-item',
232 ] );
233
234 $this->add_responsive_control(
235 'item_padding',
236 [
237 'label' => esc_html__('Padding', 'easy-elements'),
238 'type' => Controls_Manager::DIMENSIONS,
239 'size_units' => ['px'],
240 'selectors' => [
241 '{{WRAPPER}} .eel-faq-item' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
242 ],
243 ]
244 );
245
246 // Shadow
247 $this->add_group_control( \Elementor\Group_Control_Box_Shadow::get_type(), [
248 'name' => 'item_shadow',
249 'label' => esc_html__( 'Box Shadow', 'easy-elements' ),
250 'selector' => '{{WRAPPER}} .eel-faq-item',
251 ] );
252
253 $this->add_responsive_control(
254 'item_margin',
255 [
256 'label' => esc_html__('Items Space', 'easy-elements'),
257 'type' => Controls_Manager::SLIDER,
258 'size_units' => ['px'],
259 'selectors' => [
260 '{{WRAPPER}} .eel-faq-accordion' => 'gap: {{SIZE}}{{UNIT}};',
261 ],
262 ]
263 );
264 $this->end_controls_tab();
265
266 $this->start_controls_tab(
267 'item_style_hover',
268 [
269 'label' => esc_html__( 'Hover', 'easy-elements' ),
270 ]
271 );
272 $this->add_group_control(
273 \Elementor\Group_Control_Background::get_type(),
274 [
275 'name' => 'item_bg_hover',
276 'types' => [ 'classic', 'gradient' ],
277 'selector' => '{{WRAPPER}} .eel-faq-item:hover',
278 ]
279 );
280
281 $this->add_group_control(
282 \Elementor\Group_Control_Border::get_type(),
283 [
284 'name' => 'item_border_hover',
285 'selector' => '{{WRAPPER}} .eel-faq-item:hover',
286 ]
287 );
288
289 $this->add_group_control(
290 \Elementor\Group_Control_Box_Shadow::get_type(),
291 [
292 'name' => 'item_shadow_hover',
293 'selector' => '{{WRAPPER}} .eel-faq-item:hover',
294 ]
295 );
296 $this->end_controls_tab();
297
298 $this->start_controls_tab(
299 'item_style_active',
300 [
301 'label' => esc_html__( 'Active', 'easy-elements' ),
302 ]
303 );
304 $this->add_group_control(
305 \Elementor\Group_Control_Background::get_type(),
306 [
307 'name' => 'item_bg_active',
308 'types' => [ 'classic', 'gradient' ],
309 'selector' => '{{WRAPPER}} .eel-faq-item.active',
310 ]
311 );
312
313 $this->add_group_control(
314 \Elementor\Group_Control_Border::get_type(),
315 [
316 'name' => 'item_border_active',
317 'selector' => '{{WRAPPER}} .eel-faq-item.active',
318 ]
319 );
320
321 $this->add_group_control(
322 \Elementor\Group_Control_Box_Shadow::get_type(),
323 [
324 'name' => 'item_shadow_active',
325 'selector' => '{{WRAPPER}} .eel-faq-item.active',
326 ]
327 );
328
329 $this->end_controls_tab();
330 $this->end_controls_tabs();
331
332 $this->end_controls_section();
333
334 $this->start_controls_section(
335 'title_style_section',
336 [
337 'label' => esc_html__( 'Title', 'easy-elements' ),
338 'tab' => Controls_Manager::TAB_STYLE,
339 ]
340 );
341
342 $this->start_controls_tabs( 'title_style_tabs' );
343
344 $this->start_controls_tab(
345 'title_style_normal',
346 [
347 'label' => esc_html__( 'Normal', 'easy-elements' ),
348 ]
349 );
350
351 // Title Color
352 $this->add_control( 'title_color', [
353 'label' => esc_html__( 'Color', 'easy-elements' ),
354 'type' => Controls_Manager::COLOR,
355 'selectors' => [
356 '{{WRAPPER}} .eel-faq-title' => 'color: {{VALUE}};',
357 ],
358 ] );
359
360 // Title Typography
361 $this->add_group_control( \Elementor\Group_Control_Typography::get_type(), [
362 'name' => 'title_typography',
363 'label' => esc_html__( 'Typography', 'easy-elements' ),
364 'selector' => '{{WRAPPER}} .eel-faq-title',
365 ] );
366 $this->end_controls_tab();
367
368 $this->start_controls_tab(
369 'title_style_hover',
370 [
371 'label' => esc_html__( 'Hover', 'easy-elements' ),
372 ]
373 );
374 $this->add_control( 'title_color_hover', [
375 'label' => esc_html__( 'Color', 'easy-elements' ),
376 'type' => Controls_Manager::COLOR,
377 'selectors' => [
378 '{{WRAPPER}} .eel-faq-item:hover .eel-faq-title' => 'color: {{VALUE}};',
379 ],
380 ] );
381 $this->end_controls_tab();
382 $this->start_controls_tab(
383 'title_style_active',
384 [
385 'label' => esc_html__( 'Active', 'easy-elements' ),
386 ]
387 );
388 $this->add_control( 'title_color_active', [
389 'label' => esc_html__( 'Color', 'easy-elements' ),
390 'type' => Controls_Manager::COLOR,
391 'selectors' => [
392 '{{WRAPPER}} .eel-faq-item.active .eel-faq-title' => 'color: {{VALUE}};',
393 ],
394 ] );
395 $this->end_controls_tab();
396 $this->end_controls_tabs();
397 $this->end_controls_section();
398
399 $this->start_controls_section(
400 'description_style_section',
401 [
402 'label' => esc_html__( 'Description', 'easy-elements' ),
403 'tab' => Controls_Manager::TAB_STYLE,
404 ]
405 );
406
407 $this->start_controls_tabs( 'description_style_tabs' );
408
409 $this->start_controls_tab(
410 'description_style_normal',
411 [
412 'label' => esc_html__( 'Normal', 'easy-elements' ),
413 ]
414 );
415
416 // Description Color
417 $this->add_control( 'description_color', [
418 'label' => esc_html__( 'Color', 'easy-elements' ),
419 'type' => Controls_Manager::COLOR,
420 'selectors' => [
421 '{{WRAPPER}} .eel-faq-answer' => 'color: {{VALUE}};',
422 ],
423 ] );
424
425 // Description Typography
426 $this->add_group_control( \Elementor\Group_Control_Typography::get_type(), [
427 'name' => 'description_typography',
428 'label' => esc_html__( 'Typography', 'easy-elements' ),
429 'selector' => '{{WRAPPER}} .eel-faq-answer',
430 ] );
431
432 $this->end_controls_tab();
433
434 $this->start_controls_tab(
435 'description_style_hover',
436 [
437 'label' => esc_html__( 'Hover', 'easy-elements' ),
438 ]
439 );
440
441 $this->add_control( 'description_color_hover', [
442 'label' => esc_html__( 'Color', 'easy-elements' ),
443 'type' => Controls_Manager::COLOR,
444 'selectors' => [
445 '{{WRAPPER}} .eel-faq-item:hover .eel-faq-answer' => 'color: {{VALUE}};',
446 ],
447 ] );
448 $this->end_controls_tab();
449
450 $this->start_controls_tab(
451 'description_style_active',
452 [
453 'label' => esc_html__( 'Active', 'easy-elements' ),
454 ]
455 );
456
457 $this->add_control( 'description_color_active', [
458 'label' => esc_html__( 'Color', 'easy-elements' ),
459 'type' => Controls_Manager::COLOR,
460 'selectors' => [
461 '{{WRAPPER}} .eel-faq-item.active .eel-faq-answer' => 'color: {{VALUE}};',
462 ],
463 ] );
464
465 $this->end_controls_tab();
466 $this->end_controls_tabs();
467
468 $this->end_controls_section();
469
470 $this->start_controls_section(
471 'icon_style_section',
472 [
473 'label' => esc_html__( 'Accordion Icon', 'easy-elements' ),
474 'tab' => Controls_Manager::TAB_STYLE,
475 ]
476 );
477
478 $this->start_controls_tabs( 'icon_style_tabs' );
479 $this->start_controls_tab(
480 'icon_style_normal',
481 [
482 'label' => esc_html__( 'Normal', 'easy-elements' ),
483 ]
484 );
485
486 $this->add_control( 'icon_color', [
487 'label' => esc_html__( 'Color', 'easy-elements' ),
488 'type' => Controls_Manager::COLOR,
489 'selectors' => [
490 '{{WRAPPER}} .eel-faq-icon, {{WRAPPER}} .eel-faq-icon svg' => 'color: {{VALUE}}; fill: {{VALUE}};',
491 ],
492 ] );
493
494 $this->add_responsive_control(
495 'icon_position_y',
496 [
497 'label' => esc_html__( 'Vertical Position', 'easy-elements' ),
498 'type' => \Elementor\Controls_Manager::SLIDER,
499 'size_units' => [ 'px', '%' ],
500 'range' => [
501 'px' => [
502 'min' => -100,
503 'max' => 100,
504 'step' => 1,
505 ],
506 '%' => [
507 'min' => -100,
508 'max' => 100,
509 ],
510 ],
511 'default' => [
512 'unit' => 'px',
513 'size' => 0,
514 ],
515 'selectors' => [
516 '{{WRAPPER}} .eel-faq-icon' => 'transform: translateY({{SIZE}}{{UNIT}});',
517 ],
518 ]
519 );
520 $this->end_controls_tab();
521
522 $this->start_controls_tab(
523 'icon_style_hover',
524 [
525 'label' => esc_html__( 'Hover', 'easy-elements' ),
526 ]
527 );
528 $this->add_control( 'icon_color_hover', [
529 'label' => esc_html__( 'Color', 'easy-elements' ),
530 'type' => Controls_Manager::COLOR,
531 'selectors' => [
532 '{{WRAPPER}} .eel-faq-item:hover .eel-faq-icon, {{WRAPPER}} .eel-faq-item:hover .eel-faq-icon svg path' => 'color: {{VALUE}}; fill: {{VALUE}};',
533 ],
534 ] );
535 $this->end_controls_tab();
536
537 $this->start_controls_tab(
538 'icon_style_active',
539 [
540 'label' => esc_html__( 'Active', 'easy-elements' ),
541 ]
542 );
543
544 $this->add_control( 'icon_color_active', [
545 'label' => esc_html__( 'Color', 'easy-elements' ),
546 'type' => Controls_Manager::COLOR,
547 'selectors' => [
548 '{{WRAPPER}} .eel-faq-item.active .eel-faq-icon, {{WRAPPER}} .eel-faq-item.active .eel-faq-icon svg path' => 'color: {{VALUE}}; fill: {{VALUE}};',
549 ],
550 ] );
551
552 $this->add_responsive_control(
553 'icon_position_y_active',
554 [
555 'label' => esc_html__( 'Vertical Position', 'easy-elements' ),
556 'type' => \Elementor\Controls_Manager::SLIDER,
557 'size_units' => [ 'px', '%' ],
558 'range' => [
559 'px' => [
560 'min' => -100,
561 'max' => 100,
562 'step' => 1,
563 ],
564 '%' => [
565 'min' => -100,
566 'max' => 100,
567 ],
568 ],
569 'default' => [
570 'unit' => 'px',
571 'size' => 0,
572 ],
573 'selectors' => [
574 '{{WRAPPER}} .eel-faq-item.active .eel-faq-icon' => 'transform: translateY({{SIZE}}{{UNIT}});',
575 ],
576 ]
577 );
578
579 $this->end_controls_tab();
580 $this->end_controls_tabs();
581 $this->end_controls_section();
582 }
583
584
585 protected function render() {
586 $settings = $this->get_settings_for_display();
587 if ( empty( $settings['faq_items'] ) ) return;
588
589 $title_tag = tag_escape( $settings['title_tag'] ?? 'h4' );
590 $open_all_class = ( $settings['open_all_toggle'] === 'yes' ) ? 'eel-faq-open-all' : '';
591 $enable_sticky = ( $settings['enable_sticky'] === 'yes' ) ? 'eel-faq-sticky' : '';
592
593
594 // FAQ Schema Output
595 if ( isset( $settings['enable_faq_schema'] ) && $settings['enable_faq_schema'] === 'yes' && ! empty( $settings['faq_items'] ) ) {
596
597 $schema = [
598 '@context' => 'https://schema.org',
599 '@type' => 'FAQPage',
600 'mainEntity' => array_map( function ( $item ) {
601 return [
602 '@type' => 'Question',
603 'name' => isset( $item['title'] ) ? wp_strip_all_tags( $item['title'] ) : '',
604 'acceptedAnswer' => [
605 '@type' => 'Answer',
606 'text' => isset( $item['description'] ) ? wp_kses_post( $item['description'] ) : '',
607 ],
608 ];
609 }, $settings['faq_items'] ),
610 ];
611
612 echo '<script type="application/ld+json">' . wp_json_encode( $schema, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES ) . '</script>';
613 }
614
615 ?>
616
617 <div class="eel-faq-accordion <?php echo esc_attr( $open_all_class ); ?> <?php echo esc_attr( $enable_sticky ); ?>" id="<?php echo esc_attr( $this->get_id() ); ?>">
618 <?php foreach ( $settings['faq_items'] as $index => $item ) :
619 $is_active = ( ! empty( $item['active_toggle'] ) && $item['active_toggle'] === 'yes' ) ? 'active' : '';
620 $title = isset( $item['title'] ) ? $item['title'] : '';
621 $description = isset( $item['description'] ) ? $item['description'] : '';
622 $icon_open = isset( $settings['icon_open'] ) ? $settings['icon_open'] : array();
623 $icon_close = isset( $settings['icon_close'] ) ? $settings['icon_close'] : array();
624 ?>
625 <div class="eel-faq-item <?php echo esc_attr( $is_active ); ?>">
626 <div class="eel-faq-question">
627 <<?php echo esc_html( $title_tag ); ?> class="eel-faq-title" tabindex="0">
628 <?php echo esc_html( $title ); ?>
629 </<?php echo esc_html( $title_tag ); ?>>
630 <span class="eel-faq-icon eel-faq-icon-open">
631 <?php
632 if ( ! empty( $icon_open ) && ! empty( $icon_open['value'] ) ) {
633 Icons_Manager::render_icon( $icon_open, [ 'aria-hidden' => 'true' ] );
634 } else {
635 echo '<i class="unicon-close" aria-hidden="true"></i>';
636 }
637 ?>
638 </span>
639 <span class="eel-faq-icon eel-faq-icon-close">
640 <?php
641 if ( ! empty( $icon_close ) && ! empty( $icon_close['value'] ) ) {
642 Icons_Manager::render_icon( $icon_close, [ 'aria-hidden' => 'true' ] );
643 } else {
644 echo '<i class="unicon-add" aria-hidden="true"></i>';
645 }
646 ?>
647 </span>
648 </div>
649 <div class="eel-faq-answer">
650 <?php echo wp_kses_post( $description ); ?>
651 </div>
652 </div>
653 <?php endforeach; ?>
654 </div>
655 <?php
656 }
657 }
658 ?>