PluginProbe
Easy Elements for Elementor – Addons & Website Templates / 1.3.9
Easy Elements for Elementor – Addons & Website Templates v1.3.9
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 / post-meta / post-meta.php

post-meta.php in Easy Elements for Elementor – Addons & Website Templates 1.3.9, at widgets/post-meta/post-meta.php

893 lines 27.0 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\Widget_Base;
5 use Elementor\Group_Control_Typography;
6 use Elementor\Group_Control_Text_Shadow;
7 use Elementor\Group_Control_Border;
8 use Elementor\Group_Control_Box_Shadow;
9 use Elementor\Core\Kits\Documents\Tabs\Global_Colors;
10 use Elementor\Core\Kits\Documents\Tabs\Global_Typography;
11
12 if ( ! defined( 'ABSPATH' ) ) {
13 exit;
14 }
15
16 class Easyel_Free_Post_Meta_Widget extends \Elementor\Widget_Base {
17
18 public function get_name() {
19 return 'eel-post-meta';
20 }
21
22 public function get_title() {
23 return __( 'Post Meta', 'easy-elements' );
24 }
25
26 public function get_icon() {
27 return 'easyicon easyelIcon-meta';
28 }
29
30 public function get_categories() {
31 return [ 'easyelements_category' ];
32 }
33
34 public function get_keywords() {
35 return [ 'post', 'meta', 'author', 'date', 'category', 'comments', 'blog' ];
36 }
37
38 public function get_style_depends() {
39 return [
40 'eel-post-meta',
41 ];
42 }
43
44
45 protected function register_controls() {
46 // Content Tab
47 $this->register_content_controls();
48
49 // Style Tab
50 $this->register_style_controls();
51
52
53 }
54
55 protected function register_content_controls() {
56 // General Settings Section
57 $this->start_controls_section(
58 'section_general',
59 [
60 'label' => esc_html__( 'General', 'easy-elements' ),
61 'tab' => Controls_Manager::TAB_CONTENT,
62 ]
63 );
64
65 $this->add_control(
66 'page_type',
67 [
68 'label' => esc_html__( 'Page Type', 'easy-elements' ),
69 'type' => Controls_Manager::SELECT,
70 'default' => 'current',
71 'options' => [
72 'current' => esc_html__( 'Current Page', 'easy-elements' ),
73 'archive' => esc_html__( 'Archive Page', 'easy-elements' ),
74 'single' => esc_html__( 'Single Post/Page', 'easy-elements' ),
75 'home' => esc_html__( 'Home Page', 'easy-elements' ),
76 ],
77 'description' => esc_html__( 'Select which page type to display meta for', 'easy-elements' ),
78 ]
79 );
80
81 $this->add_control(
82 'show_meta',
83 [
84 'label' => esc_html__( 'Show Meta', 'easy-elements' ),
85 'type' => Controls_Manager::SELECT2,
86 'multiple' => true,
87 'options' => [
88 'date' => esc_html__( 'Date', 'easy-elements' ),
89 'author' => esc_html__( 'Author', 'easy-elements' ),
90 'category' => esc_html__( 'Category', 'easy-elements' ),
91 'comments' => esc_html__( 'Comments', 'easy-elements' ),
92 ],
93 'default' => ['date', 'author'],
94 'label_block' => true,
95 'separator' => 'before',
96 ]
97 );
98
99 $this->end_controls_section();
100
101 // Date Settings Section
102 $this->start_controls_section(
103 'section_date',
104 [
105 'label' => esc_html__( 'Date', 'easy-elements' ),
106 'tab' => Controls_Manager::TAB_CONTENT,
107 ]
108 );
109
110 $this->add_control(
111 'show_date_icon',
112 [
113 'label' => esc_html__( 'Show Icon', 'easy-elements' ),
114 'type' => Controls_Manager::SWITCHER,
115 'label_on' => esc_html__( 'Yes', 'easy-elements' ),
116 'label_off' => esc_html__( 'No', 'easy-elements' ),
117 'default' => 'yes',
118 ]
119 );
120
121 $this->add_control(
122 'date_icon',
123 [
124 'label' => esc_html__( 'Icon', 'easy-elements' ),
125 'type' => Controls_Manager::ICONS,
126 'condition' => [
127 'show_date_icon' => 'yes',
128 ],
129 ]
130 );
131
132 $this->add_control(
133 'date_format',
134 [
135 'label' => esc_html__( 'Date Format', 'easy-elements' ),
136 'type' => Controls_Manager::SELECT,
137 'default' => 'default',
138 'options' => [
139 'default' => esc_html__( 'Default', 'easy-elements' ),
140 'F j, Y' => esc_html__( 'January 1, 2024', 'easy-elements' ),
141 'j F Y' => esc_html__( '1 January 2024', 'easy-elements' ),
142 'Y-m-d' => esc_html__( '2024-01-01', 'easy-elements' ),
143 'm/d/Y' => esc_html__( '01/01/2024 (US)', 'easy-elements' ),
144 'd/m/Y' => esc_html__( '01/01/2024 (EU)', 'easy-elements' ),
145 'custom' => esc_html__( 'Custom', 'easy-elements' ),
146 ],
147 'separator' => 'before',
148 ]
149 );
150
151 $this->add_control(
152 'custom_date_format',
153 [
154 'label' => esc_html__( 'Custom Format', 'easy-elements' ),
155 'type' => Controls_Manager::TEXT,
156 'default' => 'F j, Y',
157 'description' => esc_html__( 'Enter a custom date format. See PHP date() function documentation.', 'easy-elements' ),
158 'condition' => [
159 'date_format' => 'custom',
160 ],
161 ]
162 );
163
164 $this->end_controls_section();
165
166 // Author Settings Section
167 $this->start_controls_section(
168 'section_author',
169 [
170 'label' => esc_html__( 'Author', 'easy-elements' ),
171 'tab' => Controls_Manager::TAB_CONTENT,
172 ]
173 );
174
175 $this->add_control(
176 'show_author_icon',
177 [
178 'label' => esc_html__( 'Show Icon', 'easy-elements' ),
179 'type' => Controls_Manager::SWITCHER,
180 'label_on' => esc_html__( 'Yes', 'easy-elements' ),
181 'label_off' => esc_html__( 'No', 'easy-elements' ),
182 'default' => 'yes',
183 ]
184 );
185
186 $this->add_control(
187 'author_icon',
188 [
189 'label' => esc_html__( 'Icon', 'easy-elements' ),
190 'type' => Controls_Manager::ICONS,
191 'condition' => [
192 'show_author_icon' => 'yes',
193 ],
194 ]
195 );
196
197 $this->add_control(
198 'show_by_label',
199 [
200 'label' => esc_html__( 'Show "By" Label', 'easy-elements' ),
201 'type' => Controls_Manager::SWITCHER,
202 'label_on' => esc_html__( 'Yes', 'easy-elements' ),
203 'label_off' => esc_html__( 'No', 'easy-elements' ),
204 'return_value' => 'yes',
205 'default' => 'yes',
206 'separator' => 'before',
207 ]
208 );
209
210 $this->add_control(
211 'author_link_enable',
212 [
213 'label' => esc_html__( 'Author Link', 'easy-elements' ),
214 'type' => Controls_Manager::SWITCHER,
215 'label_on' => esc_html__( 'Yes', 'easy-elements' ),
216 'label_off' => esc_html__( 'No', 'easy-elements' ),
217 'return_value' => 'yes',
218 'default' => '',
219 ]
220 );
221
222 $this->end_controls_section();
223
224 // Category Settings Section
225 $this->start_controls_section(
226 'section_category',
227 [
228 'label' => esc_html__( 'Category', 'easy-elements' ),
229 'tab' => Controls_Manager::TAB_CONTENT,
230 ]
231 );
232
233 $this->add_control(
234 'show_category_icon',
235 [
236 'label' => esc_html__( 'Show Icon', 'easy-elements' ),
237 'type' => Controls_Manager::SWITCHER,
238 'label_on' => esc_html__( 'Yes', 'easy-elements' ),
239 'label_off' => esc_html__( 'No', 'easy-elements' ),
240 'default' => 'yes',
241 ]
242 );
243
244 $this->add_control(
245 'category_icon',
246 [
247 'label' => esc_html__( 'Icon', 'easy-elements' ),
248 'type' => Controls_Manager::ICONS,
249 'condition' => [
250 'show_category_icon' => 'yes',
251 ],
252 ]
253 );
254
255 $this->add_control(
256 'category_separator',
257 [
258 'label' => esc_html__( 'Separator', 'easy-elements' ),
259 'type' => Controls_Manager::TEXT,
260 'default' => ', ',
261 'description' => esc_html__( 'Separator between categories', 'easy-elements' ),
262 'separator' => 'before',
263 ]
264 );
265
266 $this->end_controls_section();
267
268 // Comments Settings Section
269 $this->start_controls_section(
270 'section_comments',
271 [
272 'label' => esc_html__( 'Comments', 'easy-elements' ),
273 'tab' => Controls_Manager::TAB_CONTENT,
274 ]
275 );
276
277 $this->add_control(
278 'show_comments_icon',
279 [
280 'label' => esc_html__( 'Show Icon', 'easy-elements' ),
281 'type' => Controls_Manager::SWITCHER,
282 'label_on' => esc_html__( 'Yes', 'easy-elements' ),
283 'label_off' => esc_html__( 'No', 'easy-elements' ),
284 'default' => 'yes',
285 ]
286 );
287
288 $this->add_control(
289 'comments_icon',
290 [
291 'label' => esc_html__( 'Icon', 'easy-elements' ),
292 'type' => Controls_Manager::ICONS,
293 'condition' => [
294 'show_comments_icon' => 'yes',
295 ],
296 ]
297 );
298
299 $this->add_control(
300 'comments_text',
301 [
302 'label' => esc_html__( 'Comments Text', 'easy-elements' ),
303 'type' => Controls_Manager::SELECT,
304 'default' => 'default',
305 'options' => [
306 'default' => esc_html__( 'Default (Comment/Comments)', 'easy-elements' ),
307 'custom' => esc_html__( 'Custom', 'easy-elements' ),
308 ],
309 'separator' => 'before',
310 ]
311 );
312
313 $this->add_control(
314 'custom_comments_text',
315 [
316 'label' => esc_html__( 'Custom Text', 'easy-elements' ),
317 'type' => Controls_Manager::TEXT,
318 'default' => 'Comment',
319 /* translators: %s: Number of comments */
320 'description' => esc_html__( 'Use %s for the number', 'easy-elements' ),
321 'condition' => [
322 'comments_text' => 'custom',
323 ],
324 ]
325 );
326
327 $this->end_controls_section();
328
329 // Separator Settings Section
330 $this->start_controls_section(
331 'section_separator',
332 [
333 'label' => esc_html__( 'Separator', 'easy-elements' ),
334 'tab' => Controls_Manager::TAB_CONTENT,
335 ]
336 );
337
338 $this->add_control(
339 'eel_separator',
340 [
341 'label' => esc_html__( 'Enable Separator', 'easy-elements' ),
342 'type' => Controls_Manager::SWITCHER,
343 'label_on' => esc_html__( 'Yes', 'easy-elements' ),
344 'label_off' => esc_html__( 'No', 'easy-elements' ),
345 'default' => '',
346 ]
347 );
348
349 $this->add_control(
350 'separator_type',
351 [
352 'label' => esc_html__( 'Separator Type', 'easy-elements' ),
353 'type' => Controls_Manager::SELECT,
354 'default' => 'line',
355 'options' => [
356 'dot' => esc_html__( 'Dot', 'easy-elements' ),
357 'line' => esc_html__( 'Line', 'easy-elements' ),
358 ],
359 'condition' => [
360 'eel_separator' => 'yes',
361 ],
362 ]
363 );
364
365 $this->end_controls_section();
366 }
367
368 protected function register_style_controls() {
369 // Meta Container Style
370 $this->start_controls_section(
371 'section_meta_style',
372 [
373 'label' => esc_html__( 'Meta Container', 'easy-elements' ),
374 'tab' => Controls_Manager::TAB_STYLE,
375 ]
376 );
377
378 $this->add_responsive_control(
379 'meta_margin',
380 [
381 'label' => esc_html__( 'Margin', 'easy-elements' ),
382 'type' => Controls_Manager::DIMENSIONS,
383 'size_units' => [ 'px', 'em', '%' ],
384 'selectors' => [
385 '{{WRAPPER}} .eel--blog-meta' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
386 ],
387 ]
388 );
389
390 $this->add_responsive_control(
391 'meta_padding',
392 [
393 'label' => esc_html__( 'Padding', 'easy-elements' ),
394 'type' => Controls_Manager::DIMENSIONS,
395 'size_units' => [ 'px', 'em', '%' ],
396 'selectors' => [
397 '{{WRAPPER}} .eel--blog-meta' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
398 ],
399 ]
400 );
401
402 $this->add_group_control(
403 Group_Control_Border::get_type(),
404 [
405 'name' => 'meta_border',
406 'label' => esc_html__( 'Border', 'easy-elements' ),
407 'selector' => '{{WRAPPER}} .eel--blog-meta',
408 ]
409 );
410
411 $this->add_control(
412 'meta_border_radius',
413 [
414 'label' => esc_html__( 'Border Radius', 'easy-elements' ),
415 'type' => Controls_Manager::DIMENSIONS,
416 'size_units' => [ 'px', '%' ],
417 'selectors' => [
418 '{{WRAPPER}} .eel--blog-meta' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
419 ],
420 ]
421 );
422
423 $this->add_group_control(
424 Group_Control_Box_Shadow::get_type(),
425 [
426 'name' => 'meta_box_shadow',
427 'label' => esc_html__( 'Box Shadow', 'easy-elements' ),
428 'selector' => '{{WRAPPER}} .eel--blog-meta',
429 ]
430 );
431
432 $this->end_controls_section();
433
434 // Meta Items Style
435 $this->start_controls_section(
436 'section_meta_items_style',
437 [
438 'label' => esc_html__( 'Meta Items', 'easy-elements' ),
439 'tab' => Controls_Manager::TAB_STYLE,
440 ]
441 );
442
443 $this->add_control(
444 'meta_text_color',
445 [
446 'label' => esc_html__( 'Text Color', 'easy-elements' ),
447 'type' => Controls_Manager::COLOR,
448 'global' => [
449 'default' => Global_Colors::COLOR_TEXT,
450 ],
451 'selectors' => [
452 '{{WRAPPER}} .eel--blog-meta li, {{WRAPPER}} .eel--blog-meta li *' => 'color: {{VALUE}};',
453 ],
454 ]
455 );
456
457 $this->add_group_control(
458 Group_Control_Typography::get_type(),
459 [
460 'name' => 'meta_typography',
461 'label' => esc_html__( 'Typography', 'easy-elements' ),
462 'global' => [
463 'default' => Global_Typography::TYPOGRAPHY_TEXT,
464 ],
465 'selector' => '{{WRAPPER}} .eel--blog-meta li',
466 ]
467 );
468
469 $this->add_responsive_control(
470 'meta_items_spacing',
471 [
472 'label' => esc_html__( 'Margin Right', 'easy-elements' ),
473 'type' => Controls_Manager::SLIDER,
474 'size_units' => [ 'px', 'em' ],
475 'range' => [
476 'px' => [
477 'min' => 0,
478 'max' => 50,
479 ],
480 ],
481 'selectors' => [
482 '{{WRAPPER}} .eel--blog-meta li' => 'margin-right: {{SIZE}}{{UNIT}};',
483 ],
484 ]
485 );
486
487 $this->add_responsive_control(
488 'meta_items_spacing_left',
489 [
490 'label' => esc_html__( 'Padding Left', 'easy-elements' ),
491 'type' => Controls_Manager::SLIDER,
492 'size_units' => [ 'px', 'em' ],
493 'range' => [
494 'px' => [
495 'min' => 0,
496 'max' => 50,
497 ],
498 ],
499 'selectors' => [
500 '{{WRAPPER}} .eel--separator--line li + li' => 'padding-left: {{SIZE}}{{UNIT}};',
501 ],
502 ]
503 );
504
505 $this->end_controls_section();
506
507 // Icons Style
508 $this->start_controls_section(
509 'section_icons_style',
510 [
511 'label' => esc_html__( 'Icons', 'easy-elements' ),
512 'tab' => Controls_Manager::TAB_STYLE,
513 ]
514 );
515
516 $this->add_control(
517 'icon_color',
518 [
519 'label' => esc_html__( 'Icon Color', 'easy-elements' ),
520 'type' => Controls_Manager::COLOR,
521 'selectors' => [
522 '{{WRAPPER}} .eel--blog-meta i, {{WRAPPER}} .eel--blog-meta svg' => 'color: {{VALUE}};',
523 '{{WRAPPER}} .eel--blog-meta svg path' => 'fill: {{VALUE}};',
524 ],
525 ]
526 );
527
528 $this->add_control(
529 'icon_size',
530 [
531 'label' => esc_html__( 'Icon Size', 'easy-elements' ),
532 'type' => Controls_Manager::SLIDER,
533 'size_units' => [ 'px', 'em' ],
534 'range' => [
535 'px' => [
536 'min' => 10,
537 'max' => 50,
538 ],
539 ],
540 'selectors' => [
541 '{{WRAPPER}} .eel--blog-meta i, {{WRAPPER}} .eel--blog-meta svg' => 'font-size: {{SIZE}}{{UNIT}}; width: {{SIZE}}{{UNIT}}; height: {{SIZE}}{{UNIT}};',
542 ],
543 ]
544 );
545
546 $this->add_responsive_control(
547 'meta_icon_offset',
548 [
549 'label' => esc_html__( 'Icon Offset Vertical', 'easy-elements' ),
550 'type' => Controls_Manager::SLIDER,
551 'size_units' => [ 'px' ],
552 'range' => [
553 'px' => [
554 'min' => -50,
555 'max' => 100,
556 ],
557 ],
558 'selectors' => [
559 '{{WRAPPER}} .eel--blog-meta svg, {{WRAPPER}} .eel--blog-meta i' => 'top: {{SIZE}}{{UNIT}}; position: relative;',
560 ],
561 ]
562 );
563
564 $this->add_control(
565 'icon_spacing',
566 [
567 'label' => esc_html__( 'Icon Spacing', 'easy-elements' ),
568 'type' => Controls_Manager::SLIDER,
569 'size_units' => [ 'px', 'em' ],
570 'range' => [
571 'px' => [
572 'min' => 0,
573 'max' => 20,
574 ],
575 ],
576 'selectors' => [
577 '{{WRAPPER}} .eel--blog-meta i, {{WRAPPER}} .eel--blog-meta svg' => 'margin-right: {{SIZE}}{{UNIT}};',
578 ],
579 ]
580 );
581
582 $this->end_controls_section();
583
584 // Separator Style
585 $this->start_controls_section(
586 'section_separator_style',
587 [
588 'label' => esc_html__( 'Separator', 'easy-elements' ),
589 'tab' => Controls_Manager::TAB_STYLE,
590 'condition' => [
591 'eel_separator' => 'yes',
592 ],
593 ]
594 );
595
596 $this->add_control(
597 'separator_color',
598 [
599 'label' => esc_html__( 'Separator Color', 'easy-elements' ),
600 'type' => Controls_Manager::COLOR,
601 'selectors' => [
602 '{{WRAPPER}} .eel--separator--yes li + li::before' => 'background-color: {{VALUE}};',
603 ],
604 ]
605 );
606
607 $this->add_control(
608 'separator_size',
609 [
610 'label' => esc_html__( 'Separator Size', 'easy-elements' ),
611 'type' => Controls_Manager::SLIDER,
612 'size_units' => [ 'px' ],
613 'range' => [
614 'px' => [
615 'min' => 1,
616 'max' => 20,
617 ],
618 ],
619 'selectors' => [
620 '{{WRAPPER}} .eel--separator--yes li + li::before' => 'width: {{SIZE}}{{UNIT}}; height: {{SIZE}}{{UNIT}};',
621 ],
622 'condition' => [
623 'separator_type' => 'dot',
624 ],
625 ]
626 );
627
628 $this->add_responsive_control(
629 'separator_offset',
630 [
631 'label' => esc_html__( 'Separator Offset', 'easy-elements' ),
632 'type' => Controls_Manager::SLIDER,
633 'size_units' => [ 'px' ],
634 'range' => [
635 'px' => [
636 'min' => -50,
637 'max' => 100,
638 ],
639 ],
640 'selectors' => [
641 '{{WRAPPER}} .eel--separator--yes li + li::before' => 'top: {{SIZE}}{{UNIT}};',
642 ],
643 'condition' => [
644 'separator_type' => 'dot',
645 ],
646 ]
647 );
648
649 $this->end_controls_section();
650
651 // Links Style
652 $this->start_controls_section(
653 'section_links_style',
654 [
655 'label' => esc_html__( 'Links', 'easy-elements' ),
656 'tab' => Controls_Manager::TAB_STYLE,
657 ]
658 );
659
660 $this->start_controls_tabs( 'links_style_tabs' );
661
662 $this->start_controls_tab(
663 'links_normal_tab',
664 [
665 'label' => esc_html__( 'Normal', 'easy-elements' ),
666 ]
667 );
668
669 $this->add_control(
670 'links_color',
671 [
672 'label' => esc_html__( 'Color', 'easy-elements' ),
673 'type' => Controls_Manager::COLOR,
674 'selectors' => [
675 '{{WRAPPER}} .eel--blog-meta a' => 'color: {{VALUE}};',
676 ],
677 ]
678 );
679
680 $this->end_controls_tab();
681
682 $this->start_controls_tab(
683 'links_hover_tab',
684 [
685 'label' => esc_html__( 'Hover', 'easy-elements' ),
686 ]
687 );
688
689 $this->add_control(
690 'links_hover_color',
691 [
692 'label' => esc_html__( 'Color', 'easy-elements' ),
693 'type' => Controls_Manager::COLOR,
694 'selectors' => [
695 '{{WRAPPER}} .eel--blog-meta a:hover' => 'color: {{VALUE}};',
696 ],
697 ]
698 );
699
700 $this->end_controls_tab();
701
702 $this->end_controls_tabs();
703
704 $this->end_controls_section();
705 }
706
707 protected function render_blog_meta( $settings ) {
708 if ( empty( $settings['show_meta'] ) || ! is_array( $settings['show_meta'] ) ) {
709 return;
710 }
711
712 $show_meta = $settings['show_meta'];
713 $eel_separator = (! empty($settings['eel_separator']) && $settings['eel_separator'] == 'yes') ? 'eel--separator--yes' : '';
714 $page_type = ! empty($settings['page_type']) ? $settings['page_type'] : 'current';
715 $separator_type = ! empty($settings['separator_type']) ? $settings['separator_type'] : 'dot';
716
717 // Check if we should display meta based on page type
718 if (!$this->should_display_meta($page_type)) {
719 return;
720 }
721
722 ?>
723 <ul class="eel--blog-meta <?php echo esc_attr($eel_separator . ' eel--separator--' . $separator_type); ?>">
724 <?php if ( in_array( 'date', $show_meta ) ) : ?>
725 <li class="eel--blog-date">
726 <?php
727 if ( ! empty($settings['show_date_icon']) && $settings['show_date_icon'] === 'yes' ) {
728 if ( empty($settings['date_icon']) || empty($settings['date_icon']['value']) ) {
729 echo '<i class="unicon-calendar"></i>';
730 } else {
731 \Elementor\Icons_Manager::render_icon( $settings['date_icon'], [ 'aria-hidden' => 'true' ] );
732 }
733 }
734
735 $date_format = ! empty($settings['date_format']) ? $settings['date_format'] : 'default';
736
737 if ($date_format === 'custom' && ! empty($settings['custom_date_format'])) {
738 // Custom format
739 echo esc_html( get_the_date($settings['custom_date_format']) );
740 } elseif ($date_format !== 'default') {
741 // Predefined formats
742 echo esc_html( get_the_date($date_format) );
743 } else {
744 // Default WordPress date format
745 echo esc_html( get_the_date() );
746 }
747 ?>
748 </li>
749 <?php endif; ?>
750
751 <?php if ( in_array( 'author', $show_meta ) ) : ?>
752 <li class="eel--blog-author">
753 <?php
754 if ( ! empty($settings['show_author_icon']) && $settings['show_author_icon'] === 'yes' ) {
755 if ( empty($settings['author_icon']) || empty($settings['author_icon']['value']) ) {
756 echo '<i class="unicon-user"></i>';
757 } else {
758 \Elementor\Icons_Manager::render_icon( $settings['author_icon'], [ 'aria-hidden' => 'true' ] );
759 }
760 }
761
762 if ( ! empty($settings['show_by_label']) && $settings['show_by_label'] === 'yes' ) {
763 echo '<em class="eel--meta-by">' . esc_html__( 'By', 'easy-elements' ) . '</em> ';
764 }
765
766 // Get author information - more reliable method
767 global $post;
768 $author_id = 0;
769 $author_name = '';
770
771 // Try multiple methods to get author data
772 if ( $post && isset($post->post_author) ) {
773 $author_id = $post->post_author;
774 } elseif ( get_the_ID() ) {
775 $author_id = get_post_field( 'post_author', get_the_ID() );
776 }
777
778 if ( $author_id ) {
779 $author_name = get_the_author_meta( 'display_name', $author_id );
780 $author_url = get_author_posts_url( $author_id );
781
782 if ( ! empty($settings['author_link_enable']) && $settings['author_link_enable'] === 'yes' ) {
783 echo '<a class="eel--meta-author" href="' . esc_url( $author_url ) . '">' . esc_html( $author_name ) . '</a>';
784 } else {
785 echo '<span class="eel--meta-author">' . esc_html( $author_name ) . '</span>';
786 }
787 } else {
788 // Fallback if no author data
789 echo '<span class="eel--meta-author">' . esc_html__( 'Unknown Author', 'easy-elements' ) . '</span>';
790 }
791 ?>
792 </li>
793 <?php endif; ?>
794
795 <?php if ( in_array( 'category', $show_meta ) ) : ?>
796 <li class="eel--blog-cat">
797 <?php
798 if ( ! empty($settings['show_category_icon']) && $settings['show_category_icon'] === 'yes' ) {
799 if ( empty($settings['category_icon']) || empty($settings['category_icon']['value']) ) {
800 echo '<i class="unicon-folder"></i>';
801 } else {
802 \Elementor\Icons_Manager::render_icon( $settings['category_icon'], [ 'aria-hidden' => 'true' ] );
803 }
804 }
805
806 $separator = ! empty($settings['category_separator']) ? $settings['category_separator'] : ', ';
807 $post_id = null;
808
809 if ( \Elementor\Plugin::$instance->editor->is_edit_mode() ) {
810 // Try to get the preview post ID
811 $post_id = \Elementor\Plugin::$instance->preview->get_post_id();
812 // If not a real post, fallback to a sample post with categories
813 if ( ! $post_id || get_post_type($post_id) !== 'post' ) {
814 $sample = get_posts([
815 'numberposts' => 1,
816 'category__not_in' => get_option('default_category'), // avoid Uncategorized
817 'post_status' => 'publish',
818 ]);
819 if ( ! empty($sample) ) {
820 $post_id = $sample[0]->ID;
821 }
822 }
823 } else {
824 $post_id = get_the_ID();
825 }
826
827 $categories = get_the_category($post_id);
828 if ( ! empty( $categories ) ) {
829 $cat_links = [];
830 foreach ( $categories as $cat ) {
831 $cat_links[] = '<a href="' . esc_url( get_category_link( $cat->term_id ) ) . '">' . esc_html( $cat->name ) . '</a>';
832 }
833 echo implode( $separator, $cat_links ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
834 }
835 ?>
836 </li>
837 <?php endif; ?>
838
839 <?php if ( in_array( 'comments', $show_meta ) ) : ?>
840 <li class="eel--blog-comments">
841 <?php
842 if ( ! empty($settings['show_comments_icon']) && $settings['show_comments_icon'] === 'yes' ) {
843 if ( empty($settings['comments_icon']) || empty($settings['comments_icon']['value']) ) {
844 echo '<i class="unicon-forum"></i>';
845 } else {
846 \Elementor\Icons_Manager::render_icon( $settings['comments_icon'], [ 'aria-hidden' => 'true' ] );
847 }
848 }
849
850 $comments_number = get_comments_number();
851 $comments_text = ! empty($settings['comments_text']) ? $settings['comments_text'] : 'default';
852
853 if ($comments_text === 'custom' && ! empty($settings['custom_comments_text'])) {
854 $text = str_replace('%s', $comments_number, $settings['custom_comments_text']);
855 $text = $comments_number . ' ' . $text;
856 } else {
857 $text = $comments_number . ' ' . _n( 'Comment', 'Comments', $comments_number, 'easy-elements' );
858 }
859
860 echo '<a href="' . esc_url( get_comments_link() ) . '">' . esc_html( $text ) . '</a>';
861 ?>
862 </li>
863 <?php endif; ?>
864 </ul>
865 <?php
866 }
867
868 /**
869 * Check if meta should be displayed based on page type
870 */
871 protected function should_display_meta($page_type) {
872 switch ($page_type) {
873 case 'archive':
874 return is_archive() || is_category() || is_tag() || is_author() || is_date() || is_tax();
875
876 case 'single':
877 return is_single() || is_page();
878
879 case 'home':
880 return is_home() || is_front_page();
881
882 case 'current':
883 default:
884 return true; // Always show for current page type
885 }
886 }
887
888 protected function render() {
889 $settings = $this->get_settings_for_display();
890 $this->render_blog_meta( $settings );
891 }
892 }
893