PluginProbe
Easy Elements for Elementor – Addons & Website Templates / 1.5.3
Easy Elements for Elementor – Addons & Website Templates v1.5.3
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.5.3, at widgets/post-meta/post-meta.php

958 lines 28.7 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' => 'yes',
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 'easyel_post_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 // Was scoped to ".eel--separator--line li + li" so dot/no-separator
501 // layouts couldn't control padding-left at all. Broadened to every
502 // secondary li so the control works regardless of separator type.
503 '{{WRAPPER}} .eel--blog-meta li + li' => 'padding-left: {{SIZE}}{{UNIT}};',
504 ],
505 ]
506 );
507
508 $this->end_controls_section();
509
510 // Icons Style
511 $this->start_controls_section(
512 'section_icons_style',
513 [
514 'label' => esc_html__( 'Icons', 'easy-elements' ),
515 'tab' => Controls_Manager::TAB_STYLE,
516 ]
517 );
518
519 $this->add_control(
520 'icon_color',
521 [
522 'label' => esc_html__( 'Icon Color', 'easy-elements' ),
523 'type' => Controls_Manager::COLOR,
524 'selectors' => [
525 '{{WRAPPER}} .eel--blog-meta i, {{WRAPPER}} .eel--blog-meta svg' => 'color: {{VALUE}};',
526 '{{WRAPPER}} .eel--blog-meta svg path' => 'fill: {{VALUE}};',
527 ],
528 ]
529 );
530
531 $this->add_control(
532 'icon_size',
533 [
534 'label' => esc_html__( 'Icon Size', 'easy-elements' ),
535 'type' => Controls_Manager::SLIDER,
536 'size_units' => [ 'px', 'em' ],
537 'range' => [
538 'px' => [
539 'min' => 10,
540 'max' => 50,
541 ],
542 ],
543 'selectors' => [
544 '{{WRAPPER}} .eel--blog-meta i, {{WRAPPER}} .eel--blog-meta svg' => 'font-size: {{SIZE}}{{UNIT}}; width: {{SIZE}}{{UNIT}}; height: {{SIZE}}{{UNIT}};',
545 ],
546 ]
547 );
548
549 $this->add_responsive_control(
550 'meta_icon_offset',
551 [
552 'label' => esc_html__( 'Icon Offset Vertical', 'easy-elements' ),
553 'type' => Controls_Manager::SLIDER,
554 'size_units' => [ 'px' ],
555 'range' => [
556 'px' => [
557 'min' => -50,
558 'max' => 100,
559 ],
560 ],
561 'selectors' => [
562 '{{WRAPPER}} .eel--blog-meta svg, {{WRAPPER}} .eel--blog-meta i' => 'top: {{SIZE}}{{UNIT}}; position: relative;',
563 ],
564 ]
565 );
566
567 $this->add_control(
568 'icon_spacing',
569 [
570 'label' => esc_html__( 'Icon Spacing', 'easy-elements' ),
571 'type' => Controls_Manager::SLIDER,
572 'size_units' => [ 'px', 'em' ],
573 'range' => [
574 'px' => [
575 'min' => 0,
576 'max' => 20,
577 ],
578 ],
579 'selectors' => [
580 '{{WRAPPER}} .eel--blog-meta i, {{WRAPPER}} .eel--blog-meta svg' => 'margin-right: {{SIZE}}{{UNIT}};',
581 ],
582 ]
583 );
584
585 $this->end_controls_section();
586
587 // Separator Style
588 $this->start_controls_section(
589 'section_separator_style',
590 [
591 'label' => esc_html__( 'Separator', 'easy-elements' ),
592 'tab' => Controls_Manager::TAB_STYLE,
593 'condition' => [
594 'eel_separator' => 'yes',
595 ],
596 ]
597 );
598
599 $this->add_control(
600 'separator_color',
601 [
602 'label' => esc_html__( 'Separator Color', 'easy-elements' ),
603 'type' => Controls_Manager::COLOR,
604 'selectors' => [
605 '{{WRAPPER}} .eel--separator--yes li + li::before' => 'background-color: {{VALUE}};',
606 ],
607 ]
608 );
609
610 // Dot size (round dot — width = height).
611 $this->add_control(
612 'separator_size',
613 [
614 'label' => esc_html__( 'Dot Size', 'easy-elements' ),
615 'type' => Controls_Manager::SLIDER,
616 'size_units' => [ 'px' ],
617 'range' => [
618 'px' => [
619 'min' => 1,
620 'max' => 20,
621 ],
622 ],
623 'selectors' => [
624 '{{WRAPPER}} .eel--separator--dot li + li::before' => 'width: {{SIZE}}{{UNIT}}; height: {{SIZE}}{{UNIT}};',
625 ],
626 'condition' => [
627 'separator_type' => 'dot',
628 ],
629 ]
630 );
631
632 // Line thickness (width).
633 $this->add_control(
634 'separator_line_thickness',
635 [
636 'label' => esc_html__( 'Line Thickness', 'easy-elements' ),
637 'type' => Controls_Manager::SLIDER,
638 'size_units' => [ 'px' ],
639 'range' => [
640 'px' => [
641 'min' => 1,
642 'max' => 10,
643 ],
644 ],
645 'selectors' => [
646 '{{WRAPPER}} .eel--separator--line li + li::before' => 'width: {{SIZE}}{{UNIT}};',
647 ],
648 'condition' => [
649 'separator_type' => 'line',
650 ],
651 ]
652 );
653
654 // Line height (length).
655 $this->add_control(
656 'separator_line_height',
657 [
658 'label' => esc_html__( 'Line Height', 'easy-elements' ),
659 'type' => Controls_Manager::SLIDER,
660 'size_units' => [ 'px' ],
661 'range' => [
662 'px' => [
663 'min' => 1,
664 'max' => 40,
665 ],
666 ],
667 'selectors' => [
668 '{{WRAPPER}} .eel--separator--line li + li::before' => 'height: {{SIZE}}{{UNIT}};',
669 ],
670 'condition' => [
671 'separator_type' => 'line',
672 ],
673 ]
674 );
675
676 // Vertical offset — works for BOTH dot and line types now.
677 $this->add_responsive_control(
678 'separator_offset',
679 [
680 'label' => esc_html__( 'Vertical Offset', 'easy-elements' ),
681 'type' => Controls_Manager::SLIDER,
682 'size_units' => [ 'px' ],
683 'range' => [
684 'px' => [
685 'min' => -50,
686 'max' => 100,
687 ],
688 ],
689 'selectors' => [
690 '{{WRAPPER}} .eel--separator--yes li + li::before' => 'top: {{SIZE}}{{UNIT}};',
691 ],
692 ]
693 );
694
695 // Horizontal offset — new control to position the separator left/right.
696 $this->add_responsive_control(
697 'separator_offset_horizontal',
698 [
699 'label' => esc_html__( 'Horizontal Offset', 'easy-elements' ),
700 'type' => Controls_Manager::SLIDER,
701 'size_units' => [ 'px' ],
702 'range' => [
703 'px' => [
704 'min' => -50,
705 'max' => 100,
706 ],
707 ],
708 'selectors' => [
709 '{{WRAPPER}} .eel--separator--yes li + li::before' => 'left: {{SIZE}}{{UNIT}};',
710 ],
711 ]
712 );
713
714 $this->end_controls_section();
715
716 // Links Style
717 $this->start_controls_section(
718 'section_links_style',
719 [
720 'label' => esc_html__( 'Links', 'easy-elements' ),
721 'tab' => Controls_Manager::TAB_STYLE,
722 ]
723 );
724
725 $this->start_controls_tabs( 'links_style_tabs' );
726
727 $this->start_controls_tab(
728 'links_normal_tab',
729 [
730 'label' => esc_html__( 'Normal', 'easy-elements' ),
731 ]
732 );
733
734 $this->add_control(
735 'links_color',
736 [
737 'label' => esc_html__( 'Color', 'easy-elements' ),
738 'type' => Controls_Manager::COLOR,
739 'selectors' => [
740 '{{WRAPPER}} .eel--blog-meta a' => 'color: {{VALUE}};',
741 ],
742 ]
743 );
744
745 $this->end_controls_tab();
746
747 $this->start_controls_tab(
748 'links_hover_tab',
749 [
750 'label' => esc_html__( 'Hover', 'easy-elements' ),
751 ]
752 );
753
754 $this->add_control(
755 'links_hover_color',
756 [
757 'label' => esc_html__( 'Color', 'easy-elements' ),
758 'type' => Controls_Manager::COLOR,
759 'selectors' => [
760 '{{WRAPPER}} .eel--blog-meta a:hover' => 'color: {{VALUE}};',
761 ],
762 ]
763 );
764
765 $this->end_controls_tab();
766
767 $this->end_controls_tabs();
768
769 $this->end_controls_section();
770 }
771
772 protected function render_blog_meta( $settings ) {
773 if ( empty( $settings['show_meta'] ) || ! is_array( $settings['show_meta'] ) ) {
774 return;
775 }
776
777 $show_meta = $settings['show_meta'];
778 $eel_separator = (! empty($settings['eel_separator']) && $settings['eel_separator'] == 'yes') ? 'eel--separator--yes' : '';
779 $page_type = ! empty($settings['page_type']) ? $settings['page_type'] : 'current';
780 $separator_type = ! empty($settings['separator_type']) ? $settings['separator_type'] : 'dot';
781
782 // Check if we should display meta based on page type
783 if (!$this->should_display_meta($page_type)) {
784 return;
785 }
786
787 ?>
788 <ul class="eel--blog-meta <?php echo esc_attr($eel_separator . ' eel--separator--' . $separator_type); ?>">
789 <?php if ( in_array( 'date', $show_meta ) ) : ?>
790 <li class="eel--blog-date">
791 <?php
792 if ( ! empty($settings['show_date_icon']) && $settings['show_date_icon'] === 'yes' ) {
793 if ( empty($settings['date_icon']) || empty($settings['date_icon']['value']) ) {
794 echo '<i class="unicon-calendar"></i>';
795 } else {
796 \Elementor\Icons_Manager::render_icon( $settings['date_icon'], [ 'aria-hidden' => 'true' ] );
797 }
798 }
799
800 $date_format = ! empty($settings['date_format']) ? $settings['date_format'] : 'default';
801
802 if ($date_format === 'custom' && ! empty($settings['custom_date_format'])) {
803 // Custom format
804 echo esc_html( get_the_date($settings['custom_date_format']) );
805 } elseif ($date_format !== 'default') {
806 // Predefined formats
807 echo esc_html( get_the_date($date_format) );
808 } else {
809 // Default WordPress date format
810 echo esc_html( get_the_date() );
811 }
812 ?>
813 </li>
814 <?php endif; ?>
815
816 <?php if ( in_array( 'author', $show_meta ) ) : ?>
817 <li class="eel--blog-author">
818 <?php
819 if ( ! empty($settings['show_author_icon']) && $settings['show_author_icon'] === 'yes' ) {
820 if ( empty($settings['author_icon']) || empty($settings['author_icon']['value']) ) {
821 echo '<i class="unicon-user"></i>';
822 } else {
823 \Elementor\Icons_Manager::render_icon( $settings['author_icon'], [ 'aria-hidden' => 'true' ] );
824 }
825 }
826
827 if ( ! empty($settings['show_by_label']) && $settings['show_by_label'] === 'yes' ) {
828 echo '<em class="eel--meta-by">' . esc_html__( 'By', 'easy-elements' ) . '</em> ';
829 }
830
831 // Get author information - more reliable method
832 global $post;
833 $author_id = 0;
834 $author_name = '';
835
836 // Try multiple methods to get author data
837 if ( $post && isset($post->post_author) ) {
838 $author_id = $post->post_author;
839 } elseif ( get_the_ID() ) {
840 $author_id = get_post_field( 'post_author', get_the_ID() );
841 }
842
843 if ( $author_id ) {
844 $author_name = get_the_author_meta( 'display_name', $author_id );
845 $author_url = get_author_posts_url( $author_id );
846
847 if ( ! empty($settings['author_link_enable']) && $settings['author_link_enable'] === 'yes' ) {
848 echo '<a class="eel--meta-author" href="' . esc_url( $author_url ) . '">' . esc_html( $author_name ) . '</a>';
849 } else {
850 echo '<span class="eel--meta-author">' . esc_html( $author_name ) . '</span>';
851 }
852 } else {
853 // Fallback if no author data
854 echo '<span class="eel--meta-author">' . esc_html__( 'Unknown Author', 'easy-elements' ) . '</span>';
855 }
856 ?>
857 </li>
858 <?php endif; ?>
859
860 <?php if ( in_array( 'category', $show_meta ) ) : ?>
861 <li class="eel--blog-cat">
862 <?php
863 if ( ! empty($settings['show_category_icon']) && $settings['show_category_icon'] === 'yes' ) {
864 if ( empty($settings['category_icon']) || empty($settings['category_icon']['value']) ) {
865 echo '<i class="unicon-folder"></i>';
866 } else {
867 \Elementor\Icons_Manager::render_icon( $settings['category_icon'], [ 'aria-hidden' => 'true' ] );
868 }
869 }
870
871 $separator = ! empty($settings['category_separator']) ? $settings['category_separator'] : ', ';
872 $post_id = null;
873
874 if ( \Elementor\Plugin::$instance->editor->is_edit_mode() ) {
875 // Try to get the preview post ID
876 $post_id = \Elementor\Plugin::$instance->preview->get_post_id();
877 // If not a real post, fallback to a sample post with categories
878 if ( ! $post_id || get_post_type($post_id) !== 'post' ) {
879 $sample = get_posts([
880 'numberposts' => 1,
881 'category__not_in' => get_option('default_category'), // avoid Uncategorized
882 'post_status' => 'publish',
883 ]);
884 if ( ! empty($sample) ) {
885 $post_id = $sample[0]->ID;
886 }
887 }
888 } else {
889 $post_id = get_the_ID();
890 }
891
892 $categories = get_the_category($post_id);
893 if ( ! empty( $categories ) ) {
894 $cat_links = [];
895 foreach ( $categories as $cat ) {
896 $cat_links[] = '<a href="' . esc_url( get_category_link( $cat->term_id ) ) . '">' . esc_html( $cat->name ) . '</a>';
897 }
898 echo implode( $separator, $cat_links ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
899 }
900 ?>
901 </li>
902 <?php endif; ?>
903
904 <?php if ( in_array( 'comments', $show_meta ) ) : ?>
905 <li class="eel--blog-comments">
906 <?php
907 if ( ! empty($settings['show_comments_icon']) && $settings['show_comments_icon'] === 'yes' ) {
908 if ( empty($settings['comments_icon']) || empty($settings['comments_icon']['value']) ) {
909 echo '<i class="unicon-forum"></i>';
910 } else {
911 \Elementor\Icons_Manager::render_icon( $settings['comments_icon'], [ 'aria-hidden' => 'true' ] );
912 }
913 }
914
915 $comments_number = get_comments_number();
916 $comments_text = ! empty($settings['comments_text']) ? $settings['comments_text'] : 'default';
917
918 if ($comments_text === 'custom' && ! empty($settings['custom_comments_text'])) {
919 $text = str_replace('%s', $comments_number, $settings['custom_comments_text']);
920 $text = $comments_number . ' ' . $text;
921 } else {
922 $text = $comments_number . ' ' . _n( 'Comment', 'Comments', $comments_number, 'easy-elements' );
923 }
924
925 echo '<a href="' . esc_url( get_comments_link() ) . '">' . esc_html( $text ) . '</a>';
926 ?>
927 </li>
928 <?php endif; ?>
929 </ul>
930 <?php
931 }
932
933 /**
934 * Check if meta should be displayed based on page type
935 */
936 protected function should_display_meta($page_type) {
937 switch ($page_type) {
938 case 'archive':
939 return is_archive() || is_category() || is_tag() || is_author() || is_date() || is_tax();
940
941 case 'single':
942 return is_single() || is_page();
943
944 case 'home':
945 return is_home() || is_front_page();
946
947 case 'current':
948 default:
949 return true; // Always show for current page type
950 }
951 }
952
953 protected function render() {
954 $settings = $this->get_settings_for_display();
955 $this->render_blog_meta( $settings );
956 }
957 }
958