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

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

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