PluginProbe
Ultimate Post Kit – Elementor Post Grid, Post Carousel, Post Slider & Blog Layout Widgets / trunk
Ultimate Post Kit – Elementor Post Grid, Post Carousel, Post Slider & Blog Layout Widgets vtrunk
4.5.4 4.2.1 4.2.2 4.2.3 4.5.0 4.5.2 4.5.3 4.2.0 4.1.18 4.1.17 4.1.16 4.1.15 4.1.14 4.1.13 4.1.12 4.1.11 4.1.10 4.1.9 4.1.8 4.0.9 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4 All 146 releases
ultimate-post-kit / modules / recent-comments / widgets / recent-comments.php

recent-comments.php in Ultimate Post Kit – Elementor Post Grid, Post Carousel, Post Slider & Blog Layout Widgets trunk, at modules/recent-comments/widgets/recent-comments.php

917 lines 22.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace UltimatePostKit\Modules\RecentComments\Widgets;
4
5 use Elementor\Controls_Manager;
6 use Elementor\Group_Control_Border;
7 use Elementor\Group_Control_Box_Shadow;
8 use Elementor\Group_Control_Typography;
9 use Elementor\Group_Control_Background;
10 use UltimatePostKit\Includes\Controls\SelectInput\Dynamic_Select;
11
12 use UltimatePostKit\Traits\Global_Widget_Controls;
13 use UltimatePostKit\Includes\Controls\GroupQuery\Group_Control_Query;
14 use WP_Comment_Query;
15
16 if (!defined('ABSPATH')) {
17 exit;
18 } // Exit if accessed directly
19
20 class Recent_Comments extends Group_Control_Query {
21
22 use Global_Widget_Controls;
23
24 private $_query = null;
25
26 public function get_name() {
27 return 'upk-recent-comments';
28 }
29
30 public function get_title() {
31 return BDTUPK . esc_html__('Recent Comments', 'ultimate-post-kit');
32 }
33
34 public function get_icon() {
35 return 'upk-widget-icon upk-icon-recent-comments';
36 }
37
38 public function get_categories() {
39 return ['ultimate-post-kit'];
40 }
41
42 public function get_keywords() {
43 return ['post', 'featured', 'blog', 'recent', 'news', 'classic', 'list'];
44 }
45
46 public function get_style_depends() {
47 if ($this->upk_is_edit_mode()) {
48 return ['upk-all-styles'];
49 } else {
50 return ['upk-recent-comments'];
51 }
52 }
53
54 public function get_custom_help_url() {
55 return 'https://youtu.be/_RFwr9Lx7Gs';
56 }
57
58
59 public function has_widget_inner_wrapper(): bool {
60 return ! \Elementor\Plugin::$instance->experiments->is_feature_active( 'e_optimized_markup' );
61 }
62
63
64 protected function register_controls() {
65 $this->start_controls_section(
66 'section_content_layout',
67 [
68 'label' => esc_html__('Layout', 'ultimate-post-kit'),
69 ]
70 );
71
72 $this->add_responsive_control(
73 'columns',
74 [
75 'label' => __('Columns', 'ultimate-post-kit'),
76 'type' => Controls_Manager::SELECT,
77 'default' => '1',
78 'tablet_default' => '1',
79 'mobile_default' => '1',
80 'options' => [
81 '1' => '1',
82 '2' => '2',
83 '3' => '3',
84 '4' => '4',
85 ],
86 'selectors' => [
87 '{{WRAPPER}} .upk-recent-comments' => 'grid-template-columns: repeat({{SIZE}}, 1fr);',
88 ],
89 ]
90 );
91
92 $this->add_responsive_control(
93 'row_gap',
94 [
95 'label' => esc_html__('Row Gap', 'ultimate-post-kit'),
96 'type' => Controls_Manager::SLIDER,
97 'default' => [
98 'size' => 30,
99 ],
100 'selectors' => [
101 '{{WRAPPER}} .upk-recent-comments' => 'grid-row-gap: {{SIZE}}{{UNIT}};',
102 ],
103 ]
104 );
105
106 $this->add_responsive_control(
107 'column_gap',
108 [
109 'label' => esc_html__('Column Gap', 'ultimate-post-kit'),
110 'type' => Controls_Manager::SLIDER,
111 'default' => [
112 'size' => 30,
113 ],
114 'selectors' => [
115 '{{WRAPPER}} .upk-recent-comments' => 'grid-column-gap: {{SIZE}}{{UNIT}};',
116 ],
117 'condition' => [
118 'columns!' => '1'
119 ]
120 ]
121 );
122
123 $this->add_responsive_control(
124 'content_alignment',
125 [
126 'label' => __('Alignment', 'ultimate-post-kit'),
127 'type' => Controls_Manager::CHOOSE,
128 'options' => [
129 'left' => [
130 'title' => __('Left', 'ultimate-post-kit'),
131 'icon' => 'eicon-text-align-left',
132 ],
133 'center' => [
134 'title' => __('Center', 'ultimate-post-kit'),
135 'icon' => 'eicon-text-align-center',
136 ],
137 'right' => [
138 'title' => __('Right', 'ultimate-post-kit'),
139 'icon' => 'eicon-text-align-right',
140 ],
141 ],
142 'selectors' => [
143 '{{WRAPPER}} .upk-recent-comments .upk-item' => 'text-align: {{VALUE}};',
144 ],
145 ]
146 );
147
148 $this->end_controls_section();
149
150 // Query Settings
151 $this->start_controls_section(
152 'section_post_query_builder',
153 [
154 'label' => __('Query', 'ultimate-post-kit'),
155 'tab' => Controls_Manager::TAB_CONTENT,
156 ]
157 );
158
159 $this->add_control(
160 'post_type',
161 [
162 'label' => __('Post Type', 'ultimate-post-kit'),
163 'type' => Controls_Manager::SELECT,
164 'default' => 'post',
165 'options' => $this->ultimate_post_kit_get_post_types(),
166 ]
167 );
168
169 $this->start_controls_tabs(
170 'tabs_posts_include_exclude'
171 );
172
173 $this->start_controls_tab(
174 'tab_posts_include',
175 [
176 'label' => __('Include', 'ultimate-post-kit'),
177 ]
178 );
179
180 $this->add_control(
181 'posts_include_by',
182 [
183 'label' => __('Include By', 'ultimate-post-kit'),
184 'type' => Controls_Manager::SELECT2,
185 'multiple' => true,
186 'label_block' => true,
187 'options' => [
188 'authors' => __('Authors', 'ultimate-post-kit'),
189 ]
190 ]
191 );
192
193 $this->add_control(
194 'posts_include_author_ids',
195 [
196 'label' => __('Authors', 'ultimate-post-kit'),
197 'type' => Dynamic_Select::TYPE,
198 'multiple' => true,
199 'label_block' => true,
200 'query_args' => [
201 'query' => 'authors',
202 ],
203 'condition' => [
204 'posts_include_by' => 'authors',
205 ]
206 ]
207 );
208
209
210 $this->end_controls_tab();
211
212 $this->start_controls_tab(
213 'tab_posts_exclude',
214 [
215 'label' => __('Exclude', 'ultimate-post-kit'),
216 ]
217 );
218
219 $this->add_control(
220 'posts_exclude_by',
221 [
222 'label' => __('Exclude By', 'ultimate-post-kit'),
223 'type' => Controls_Manager::SELECT2,
224 'multiple' => true,
225 'label_block' => true,
226 'options' => [
227 'authors' => __('Authors', 'ultimate-post-kit'),
228
229 ]
230 ]
231 );
232
233
234 $this->add_control(
235 'posts_exclude_author_ids',
236 [
237 'label' => __('Authors', 'ultimate-post-kit'),
238 'type' => Dynamic_Select::TYPE,
239 'multiple' => true,
240 'label_block' => true,
241 'query_args' => [
242 'query' => 'authors',
243 ],
244 'condition' => [
245 'posts_exclude_by' => 'authors',
246 ]
247 ]
248 );
249
250 $this->end_controls_tab();
251 $this->end_controls_tabs();
252
253 $this->add_control(
254 'number',
255 [
256 'label' => __('Limit', 'ultimate-post-kit'),
257 'description' => __('The maximum number of comments to return.', 'ultimate-post-kit'),
258 'type' => Controls_Manager::TEXT,
259 'default' => '4',
260 'separator' => 'before'
261 ]
262 );
263
264 $this->add_control(
265 'offset',
266 [
267 'label' => __('Offset', 'ultimate-post-kit'),
268 'description' => __(' The number of comments to pass over in the query.', 'ultimate-post-kit'),
269 'type' => Controls_Manager::TEXT,
270 ]
271 );
272
273 $this->add_control(
274 'parent',
275 [
276 'label' => __('Only Parent', 'ultimate-post-kit'),
277 'type' => Controls_Manager::SWITCHER,
278 ]
279 );
280
281 $this->add_control(
282 'status',
283 [
284 'label' => __('Status', 'ultimate-post-kit'),
285 'type' => Controls_Manager::SELECT,
286 'default' => 'approve',
287 'options' => [
288 'approve' => __('Approve', 'ultimate-post-kit'),
289 'hold' => __('Hold', 'ultimate-post-kit'),
290 'all' => __('All', 'ultimate-post-kit'),
291 ],
292 ]
293 );
294
295 $this->add_control(
296 'orderby',
297 [
298 'label' => __('Order By', 'ultimate-post-kit'),
299 'type' => Controls_Manager::SELECT,
300 'default' => 'comment_date',
301 'options' => [
302 'comment_author' => __('Author', 'ultimate-post-kit'),
303 'comment_approved' => __('Approved', 'ultimate-post-kit'),
304 'comment_date' => __('Date', 'ultimate-post-kit'),
305 'comment_content' => __('Content', 'ultimate-post-kit'),
306 'none' => __('Random', 'ultimate-post-kit'),
307 ],
308 ]
309 );
310
311 $this->add_control(
312 'order',
313 [
314 'label' => __('Order', 'ultimate-post-kit'),
315 'type' => Controls_Manager::SELECT,
316 'default' => 'desc',
317 'options' => [
318 'asc' => __('ASC', 'ultimate-post-kit'),
319 'desc' => __('DESC', 'ultimate-post-kit'),
320 ],
321 ]
322 );
323
324 $this->end_controls_section();
325
326 $this->start_controls_section(
327 'section_additional_settings',
328 [
329 'label' => esc_html__('Additional Settings', 'ultimate-post-kit'),
330 ]
331 );
332
333 $this->add_control(
334 'show_title',
335 [
336 'label' => esc_html__('Show Title', 'ultimate-post-kit'),
337 'type' => Controls_Manager::SWITCHER,
338 'default' => 'yes',
339 ]
340 );
341
342 $this->add_control(
343 'show_excerpt',
344 [
345 'label' => esc_html__('Show Text', 'ultimate-post-kit'),
346 'type' => Controls_Manager::SWITCHER,
347 'default' => 'yes',
348 'separator' => 'before'
349 ]
350 );
351
352 $this->add_control(
353 'excerpt_limit',
354 [
355 'label' => esc_html__('Text Limit', 'ultimate-post-kit'),
356 'type' => Controls_Manager::NUMBER,
357 'default' => 30,
358 'condition' => [
359 'show_excerpt' => 'yes'
360 ],
361 ]
362 );
363
364 $this->add_control(
365 'show_author',
366 [
367 'label' => esc_html__('Show Author', 'ultimate-post-kit'),
368 'type' => Controls_Manager::SWITCHER,
369 'default' => 'yes',
370 'separator' => 'before'
371 ]
372 );
373
374 $this->add_control(
375 'author_middle_text',
376 [
377 'label' => __( 'Author Middle Text', 'ultimate-post-kit' ),
378 'type' => Controls_Manager::TEXT,
379 'dynamic' => [
380 'active' => true,
381 ],
382 'default' => ' @ ',
383 'placeholder' => __( 'Enter your text', 'ultimate-post-kit' ),
384 'label_block' => false,
385 'condition' => [
386 'show_author' => 'yes',
387 'show_title' => 'yes',
388 ]
389 ]
390 );
391
392 $this->add_control(
393 'show_date',
394 [
395 'label' => esc_html__('Show Date', 'ultimate-post-kit'),
396 'type' => Controls_Manager::SWITCHER,
397 'default' => 'yes',
398 'separator' => 'before'
399 ]
400 );
401
402 $this->end_controls_section();
403
404 //Style
405 $this->start_controls_section(
406 'upk_section_style',
407 [
408 'label' => esc_html__('Items', 'ultimate-post-kit'),
409 'tab' => Controls_Manager::TAB_STYLE,
410 ]
411 );
412
413 $this->add_group_control(
414 Group_Control_Background::get_type(),
415 [
416 'name' => 'item_background',
417 'selector' => '{{WRAPPER}} .upk-recent-comments .upk-item',
418 ]
419 );
420
421 $this->add_group_control(
422 Group_Control_Border::get_type(),
423 [
424 'name' => 'item_border',
425 'selector' => '{{WRAPPER}} .upk-recent-comments .upk-item',
426 ]
427 );
428
429 $this->add_responsive_control(
430 'item_border_radius',
431 [
432 'label' => esc_html__('Border Radius', 'ultimate-post-kit'),
433 'type' => Controls_Manager::DIMENSIONS,
434 'size_units' => ['px', '%'],
435 'selectors' => [
436 '{{WRAPPER}} .upk-recent-comments .upk-item' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
437 ],
438 ]
439 );
440
441 $this->add_responsive_control(
442 'item_padding',
443 [
444 'label' => __('Padding', 'ultimate-post-kit'),
445 'type' => Controls_Manager::DIMENSIONS,
446 'size_units' => ['px', 'em', '%'],
447 'selectors' => [
448 '{{WRAPPER}} .upk-recent-comments .upk-item' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
449 ],
450 ]
451 );
452
453 $this->add_group_control(
454 Group_Control_Box_Shadow::get_type(),
455 [
456 'name' => 'item_box_shadow',
457 'selector' => '{{WRAPPER}} .upk-recent-comments .upk-item',
458 ]
459 );
460
461 $this->end_controls_section();
462
463 $this->start_controls_section(
464 'section_style_text',
465 [
466 'label' => esc_html__('Text', 'ultimate-post-kit'),
467 'tab' => Controls_Manager::TAB_STYLE,
468 'condition' => [
469 'show_excerpt' => 'yes'
470 ]
471 ]
472 );
473
474 $this->add_control(
475 'text_color',
476 [
477 'label' => esc_html__('Color', 'ultimate-post-kit'),
478 'type' => Controls_Manager::COLOR,
479 'selectors' => [
480 '{{WRAPPER}} .upk-recent-comments .upk-text' => 'color: {{VALUE}};',
481 ],
482 ]
483 );
484
485 $this->add_group_control(
486 Group_Control_Typography::get_type(),
487 [
488 'name' => 'text_typography',
489 'label' => esc_html__('Typography', 'ultimate-post-kit'),
490 'selector' => '{{WRAPPER}} .upk-recent-comments .upk-text',
491 ]
492 );
493
494 $this->end_controls_section();
495
496 $this->start_controls_section(
497 'section_style_meta',
498 [
499 'label' => esc_html__('Meta', 'ultimate-post-kit'),
500 'tab' => Controls_Manager::TAB_STYLE,
501 'conditions' => [
502 'relation' => 'or',
503 'terms' => [
504 [
505 'name' => 'show_author',
506 'value' => 'yes'
507 ],
508 [
509 'name' => 'show_date',
510 'value' => 'yes'
511 ],
512 [
513 'name' => 'show_title',
514 'value' => 'yes'
515 ]
516 ]
517 ],
518 ]
519 );
520
521 $this->add_responsive_control(
522 'meta_spacing',
523 [
524 'label' => esc_html__('Spacing', 'ultimate-post-kit'),
525 'type' => Controls_Manager::SLIDER,
526 'range' => [
527 'px' => [
528 'min' => 0,
529 'max' => 50,
530 ],
531 ],
532 'selectors' => [
533 '{{WRAPPER}} .upk-recent-comments .upk-meta' => 'margin-bottom: {{SIZE}}{{UNIT}};',
534 ],
535 ]
536 );
537
538 $this->start_controls_tabs('tabs_comments_meta_style');
539
540 $this->start_controls_tab(
541 'tab_comments_avatar',
542 [
543 'label' => esc_html__('Avatar', 'ultimate-post-kit'),
544 'condition' => [
545 'show_author' => 'yes'
546 ]
547 ]
548 );
549
550 $this->add_control(
551 'avatar_size',
552 [
553 'label' => __('Size', 'ultimate-post-kit'),
554 'type' => Controls_Manager::SELECT,
555 'default' => '48',
556 'options' => [
557 '16' => '16 X 16',
558 '24' => '24 X 24',
559 '48' => '48 X 48',
560 '64' => '64 X 64',
561 '80' => '80 X 80',
562 '90' => '90 X 90',
563 '100' => '100 X 100',
564 '120' => '120 X 120',
565 ],
566 'selectors' => [
567 '{{WRAPPER}} .upk-recent-comments .upk-meta .upk-avatar img' => 'min-width: {{VALUE}}px;',
568 ],
569 'condition' => [
570 'show_author' => 'yes'
571 ],
572 'render_type' => 'template'
573 ]
574 );
575
576 $this->add_group_control(
577 Group_Control_Border::get_type(),
578 [
579 'name' => 'avatar_border',
580 'selector' => '{{WRAPPER}} .upk-recent-comments .upk-meta .upk-avatar img',
581 'condition' => [
582 'show_author' => 'yes'
583 ]
584 ]
585 );
586
587 $this->add_responsive_control(
588 'avatar_border_radius',
589 [
590 'label' => esc_html__('Border Radius', 'ultimate-post-kit'),
591 'type' => Controls_Manager::DIMENSIONS,
592 'size_units' => ['px', '%'],
593 'selectors' => [
594 '{{WRAPPER}} .upk-recent-comments .upk-meta .upk-avatar img' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
595 ],
596 'condition' => [
597 'show_author' => 'yes'
598 ]
599 ]
600 );
601
602 $this->add_responsive_control(
603 'avatar_padding',
604 [
605 'label' => __('Padding', 'ultimate-post-kit'),
606 'type' => Controls_Manager::DIMENSIONS,
607 'size_units' => ['px', 'em', '%'],
608 'selectors' => [
609 '{{WRAPPER}} .upk-recent-comments .upk-meta .upk-avatar img' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
610 ],
611 'condition' => [
612 'show_author' => 'yes'
613 ]
614 ]
615 );
616
617 $this->add_responsive_control(
618 'avatar_margin',
619 [
620 'label' => __('Margin', 'ultimate-post-kit'),
621 'type' => Controls_Manager::DIMENSIONS,
622 'size_units' => ['px', 'em', '%'],
623 'selectors' => [
624 '{{WRAPPER}} .upk-recent-comments .upk-meta .upk-avatar' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
625 ],
626 'condition' => [
627 'show_author' => 'yes'
628 ]
629 ]
630 );
631
632 $this->add_group_control(
633 Group_Control_Box_Shadow::get_type(),
634 [
635 'name' => 'avatar_box_shadow',
636 'selector' => '{{WRAPPER}} .upk-recent-comments .upk-meta .upk-avatar img',
637 'condition' => [
638 'show_author' => 'yes'
639 ]
640 ]
641 );
642
643 $this->end_controls_tab();
644
645 $this->start_controls_tab(
646 'tab_comments_name',
647 [
648 'label' => esc_html__('Author Text', 'ultimate-post-kit'),
649 'condition' => [
650 'show_author' => 'yes'
651 ]
652 ]
653 );
654
655 $this->add_control(
656 'author_name_color',
657 [
658 'label' => esc_html__('Color', 'ultimate-post-kit'),
659 'type' => Controls_Manager::COLOR,
660 'selectors' => [
661 '{{WRAPPER}} .upk-recent-comments .upk-meta .upk-author-name' => 'color: {{VALUE}};',
662 ],
663 'condition' => [
664 'show_author' => 'yes'
665 ]
666 ]
667 );
668
669 $this->add_control(
670 'author_name_hover_color',
671 [
672 'label' => esc_html__('Hover Color', 'ultimate-post-kit'),
673 'type' => Controls_Manager::COLOR,
674 'selectors' => [
675 '{{WRAPPER}} .upk-recent-comments .upk-meta .upk-author-name:hover' => 'color: {{VALUE}};',
676 ],
677 'condition' => [
678 'show_author' => 'yes'
679 ]
680 ]
681 );
682
683 $this->add_group_control(
684 Group_Control_Typography::get_type(),
685 [
686 'name' => 'author_name_typography',
687 'label' => esc_html__('Typography', 'ultimate-post-kit'),
688 'selector' => '{{WRAPPER}} .upk-recent-comments .upk-meta .upk-author-name',
689 'condition' => [
690 'show_author' => 'yes'
691 ]
692 ]
693 );
694
695 $this->end_controls_tab();
696
697 $this->start_controls_tab(
698 'tab_comments_date',
699 [
700 'label' => esc_html__('Date', 'ultimate-post-kit'),
701 'condition' => [
702 'show_date' => 'yes'
703 ]
704 ]
705 );
706
707 $this->add_control(
708 'date_color',
709 [
710 'label' => esc_html__('Color', 'ultimate-post-kit'),
711 'type' => Controls_Manager::COLOR,
712 'selectors' => [
713 '{{WRAPPER}} .upk-recent-comments .upk-meta .upk-date' => 'color: {{VALUE}};',
714 ],
715 'condition' => [
716 'show_date' => 'yes'
717 ]
718 ]
719 );
720
721 $this->add_responsive_control(
722 'date_margin',
723 [
724 'label' => __('Margin', 'ultimate-post-kit'),
725 'type' => Controls_Manager::DIMENSIONS,
726 'size_units' => ['px', 'em', '%'],
727 'selectors' => [
728 '{{WRAPPER}} .upk-recent-comments .upk-meta .upk-date' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
729 ],
730 'condition' => [
731 'show_date' => 'yes'
732 ]
733 ]
734 );
735
736 $this->add_group_control(
737 Group_Control_Typography::get_type(),
738 [
739 'name' => 'date_typography',
740 'label' => esc_html__('Typography', 'ultimate-post-kit'),
741 'selector' => '{{WRAPPER}} .upk-recent-comments .upk-meta .upk-date',
742 'condition' => [
743 'show_date' => 'yes'
744 ]
745 ]
746 );
747
748 $this->end_controls_tab();
749
750 $this->end_controls_tabs();
751
752 $this->end_controls_section();
753 }
754
755 public function ultimate_post_kit_get_post_types($args = []) {
756
757 $post_type_args = [
758 'show_in_nav_menus' => true,
759 ];
760
761 if (!empty($args['post_type'])) {
762 $post_type_args['name'] = $args['post_type'];
763 }
764
765 $_post_types = get_post_types($post_type_args, 'objects');
766
767 $post_types = ['0' => esc_html__('All', 'ultimate-post-kit')];
768
769 foreach ($_post_types as $post_type => $object) {
770 $post_types[$post_type] = $object->label;
771 }
772
773 return $post_types;
774 }
775
776 public function get_html_output($output) {
777 $tags = [
778 'a' => ['href' => [], 'target' => [], 'class' => []],
779 'img' => ['src' => [], 'alt' => [], 'srcset' => [], 'height' => [], 'width' => [], 'loading' => []],
780 ];
781
782 if (isset($output)) {
783 echo wp_kses($output, $tags);
784 }
785 }
786
787 public function render() {
788 $settings = $this->get_settings_for_display();
789 global $post_id;
790 $query_args = [
791 'status' => $settings['status'],
792 'order' => $settings['order'],
793 'orderby' => $settings['orderby'],
794 'post_id' => $post_id,
795 'number' => $settings['number'],
796 'offset' => $settings['offset'],
797 'post_type' => $settings['post_type'],
798 ];
799
800 if ($settings['parent'] == 'yes') {
801 $query_args['parent'] = 0;
802 }
803 /**
804 * Set Authors
805 */
806 $include_users = [];
807 $exclude_users = [];
808 if (!empty($settings['posts_include_author_ids'])) {
809 if (in_array('authors', $settings['posts_include_by'])) {
810 $include_users = wp_parse_id_list($settings['posts_include_author_ids']);
811 }
812 }
813 if (!empty($settings['posts_exclude_author_ids'])) {
814 if (in_array('authors', $settings['posts_exclude_by'])) {
815 $exclude_users = wp_parse_id_list($settings['posts_exclude_author_ids']);
816 $include_users = array_diff($include_users, $exclude_users);
817 }
818 }
819 if (!empty($include_users)) {
820 $query_args['author__in'] = $include_users;
821 }
822
823 if (!empty($exclude_users)) {
824 $query_args['author__not_in'] = $exclude_users;;
825 }
826
827 $this->add_render_attribute('grid-wrap', 'class', 'upk-recent-comments');
828
829 if (isset($settings['upk_in_animation_show']) && ($settings['upk_in_animation_show'] == 'yes')) {
830 $this->add_render_attribute('grid-wrap', 'class', 'upk-in-animation');
831 if (isset($settings['upk_in_animation_delay']['size'])) {
832 $this->add_render_attribute('grid-wrap', 'data-in-animation-delay', $settings['upk_in_animation_delay']['size']);
833 }
834 }
835
836 $comments_query = new WP_Comment_Query;
837 $comments = $comments_query->query($query_args);
838 if ($comments) { ?>
839 <div <?php $this->print_render_attribute_string('grid-wrap'); ?>>
840 <?php
841 foreach ($comments as $comment) {
842 $title = get_the_title($comment->comment_post_ID);
843 $comment_id = absint( $comment->comment_ID );
844 $content = wp_trim_words($comment->comment_content, absint( $settings['excerpt_limit'] ));
845 $avatar = get_avatar($comment->comment_author_email, absint( $settings['avatar_size'] ));
846 $author = $comment->comment_author;
847 $date = get_comment_date('F j, Y \a\t g:i a', $comment_id);
848 $author_key = 'upk-author-' . $comment_id;
849 $show_author = ( 'yes' === $settings['show_author'] );
850 $show_title = ( 'yes' === $settings['show_title'] );
851 $show_date = ( 'yes' === $settings['show_date'] );
852 $show_link = $show_author || $show_title;
853
854 if ( $show_link ) {
855 $this->add_render_attribute(
856 $author_key,
857 [
858 'class' => 'upk-author-name',
859 'href' => esc_url( get_permalink( $comment->comment_post_ID ) . '#comment-' . $comment_id ),
860 'target' => '_blank'
861 ],
862 null,
863 true
864 );
865 }
866
867 ?>
868 <div class="upk-item">
869
870 <?php if ( $show_author || $show_date || $show_title ) : ?>
871 <div class="upk-meta upk-flex-inline upk-flex-middle">
872
873 <?php if ( $show_author ) : ?>
874 <div class="upk-avatar">
875 <?php $this->get_html_output($avatar); ?>
876 </div>
877 <?php endif; ?>
878
879 <div class="upk-author-info">
880 <?php if ( $show_link ) : ?>
881 <a <?php $this->print_render_attribute_string( $author_key ); ?>>
882 <?php if ( $show_author ) : ?>
883 <?php echo esc_html( $author ); ?>
884 <?php endif; ?>
885
886 <?php if ( $show_title ) : ?>
887 <?php if ( $show_author ) : ?>
888 <?php echo esc_html( $settings['author_middle_text'] ); ?>
889 <?php endif; ?>
890 <?php echo esc_html( $title ); ?>
891 <?php endif; ?>
892 </a>
893 <?php endif; ?>
894
895 <?php if ( $show_date ) : ?>
896 <div class="upk-date"><?php echo esc_html($date); ?></div>
897 <?php endif; ?>
898 </div>
899
900 </div>
901 <?php endif; ?>
902
903 <?php if ($settings['show_excerpt']) : ?>
904 <div class="upk-text"><?php echo wp_kses_post($content); ?></div>
905 <?php endif; ?>
906
907 </div>
908 <?php
909 }
910 echo '</div>';
911 wp_reset_postdata();
912 } else {
913 echo esc_html__('No Comments Found.', 'ultimate-post-kit');
914 }
915 }
916 }
917