PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.6.6
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.6.6
1.6.6 1.6.5 1.6.4 1.6.3 1.6.2 1.6.1 1.6.0 1.5.4 1.5.5 1.5.3 1.5.2 1.5.1 1.5.0 1.4.2 1.4.1 1.4.0 1.3.28 1.3.27 1.3.26 1.3.25 1.3.23 1.3.22 1.3.21 1.3.20 1.3.19 All 49 releases
fluent-cart / app / Services / WpMetaHelper.php

WpMetaHelper.php in FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler 1.6.6, at app/Services/WpMetaHelper.php

132 lines 3.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentCart\App\Services;
4
5 use FluentCart\Api\StoreSettings;
6 use FluentCart\App\Services\DateTime\DateFormatter;
7 use FluentCart\Framework\Support\Arr;
8
9 if (!defined('ABSPATH')) {
10 exit;
11 }
12
13 /**
14 * Entry MetaDat
15 * @since 1.0.0
16 */
17 class WpMetaHelper
18 {
19 protected $entry;
20 protected $userId;
21 protected $queryVars = null;
22 protected $user;
23
24 public function __construct($entry)
25 {
26 $this->entry = $entry;
27 $this->userId = Arr::get($entry, 'user_id', null);
28 }
29
30 public function getWPValues($key)
31 {
32 switch ($key) {
33 case 'user_id':
34 return $this->userId;
35 case 'user_first_name':
36 $user = $this->getUser();
37 if (!$user) {
38 return '';
39 }
40 return $user->user_firstname;
41 case 'user_last_name':
42 $user = $this->getUser();
43 if (!$user) {
44 return '';
45 }
46 return $user->user_lastname;
47 case 'user_display_name':
48 $user = $this->getUser();
49 if (!$user) {
50 return '';
51 }
52 return $user->display_name;
53 case 'user_email':
54 $user = $this->getUser();
55 if (!$user) {
56 return '';
57 }
58 return $user->user_email;
59 case 'user_url':
60 $user = $this->getUser();
61 if (!$user) {
62 return '';
63 }
64 return $user->user_url;
65 case 'site_title':
66 return get_bloginfo('name');
67 case 'site_url':
68 return get_bloginfo('url');
69 case 'admin_email':
70 return get_bloginfo('admin_email');
71 case 'store_logo';
72 return $this->getStoreLogo();
73 default:
74 return '';
75 break;
76 }
77 }
78
79 public function getuserMeta($key)
80 {
81 $meta = get_user_meta($this->userId, $key, true);
82 if (is_array($meta)) {
83 return implode(', ', $meta);
84 }
85 return $meta;
86 }
87
88 public function getOtherData($key)
89 {
90 // wp_date(), not current_time(): current_time() is gmdate() underneath,
91 // so it renders the store's format with English month and weekday
92 // names -- '14. October 2026' on a German store, which is the exact
93 // half-translated string DateFormatter exists to remove. wp_date()
94 // with no timestamp is the same instant in the same site timezone,
95 // only localized. The format comes from DateFormatter so these two
96 // shortcodes follow date_time_format_source like every other date.
97 if ($key == 'date') {
98 return wp_date(DateFormatter::dateFormat());
99 }
100
101 if ($key == 'time') {
102 return wp_date(DateFormatter::timeFormat());
103 }
104 if ($key == 'user_ip') {
105 return $this->entry->ip_address;
106 }
107
108 return '';
109 }
110
111 protected function getUser()
112 {
113 if ($this->user) {
114 return $this->user;
115 }
116 $this->user = get_user_by('ID', $this->userId);
117 return $this->user;
118 }
119
120 public function getStoreLogo(): string
121 {
122 $storeSettings = new StoreSettings();
123 $logoPath = $storeSettings->get('store_logo');
124 if (isset($logoPath) && !empty($logoPath)) {
125 $html = '<img src="' . Arr::get($logoPath, 'url') . '" alt="Store Logo" style="max-height: 70px;">';
126 } else {
127 $html = '';
128 }
129
130 return $html;
131 }
132 }