1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
class ClassyUser extends ClassyBasis { |
|
|
|
|
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Current user id |
7
|
|
|
* @var int |
8
|
|
|
*/ |
9
|
|
|
public $ID; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* User posts url |
13
|
|
|
* @var string |
14
|
|
|
*/ |
15
|
|
|
public $link; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* User login (example: anrw) |
19
|
|
|
* @var string |
20
|
|
|
*/ |
21
|
|
|
public $user_login; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* User full name |
25
|
|
|
* @var string |
26
|
|
|
*/ |
27
|
|
|
public $name; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* It's basically sanitized version of user login, used for permalinks |
31
|
|
|
* @var string |
32
|
|
|
*/ |
33
|
|
|
public $user_nicename; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* User email |
37
|
|
|
* @var string |
38
|
|
|
*/ |
39
|
|
|
public $user_email; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Human-Friendly name, like: Andrew Tolochka |
43
|
|
|
* @var string |
44
|
|
|
*/ |
45
|
|
|
public $display_name; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* User password hash |
49
|
|
|
* @var string |
50
|
|
|
*/ |
51
|
|
|
private $user_pass; |
|
|
|
|
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Stores current post object |
55
|
|
|
* @var object |
56
|
|
|
*/ |
57
|
|
|
private $object; |
|
|
|
|
58
|
|
|
|
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Main constructor function. Requires user id |
62
|
|
|
* @param int $uid |
63
|
|
|
*/ |
64
|
|
|
public function __construct($uid = null) { |
65
|
|
|
$this->ID = $this->verify_id($uid); |
66
|
|
|
|
67
|
|
|
$this->init(); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
private function verify_id($uid) { |
71
|
|
|
return $uid; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Initialises Instance based on provided post id |
76
|
|
|
*/ |
77
|
|
|
private function init() { |
78
|
|
|
$object = (array) $this->get_object(); |
79
|
|
|
|
80
|
|
|
$this->import($object); |
81
|
|
|
|
82
|
|
|
if (isset($this->first_name) && isset($this->last_name)) { |
83
|
|
|
$this->name = $this->first_name . ' ' . $this->last_name; |
|
|
|
|
84
|
|
|
} else { |
85
|
|
|
$this->name = 'Anonymous'; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Returns user object |
92
|
|
|
* |
93
|
|
|
* @return object |
94
|
|
|
*/ |
95
|
|
|
private function get_object() { |
|
|
|
|
96
|
|
|
return get_userdata($this->ID); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Returns user first name |
101
|
|
|
* |
102
|
|
|
* @return string |
103
|
|
|
*/ |
104
|
|
|
public function first_name() { |
105
|
|
|
|
106
|
|
|
return $this->first_name; |
107
|
|
|
|
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Returns user display name |
112
|
|
|
* |
113
|
|
|
* @return string |
114
|
|
|
*/ |
115
|
|
|
public function display_name() { |
116
|
|
|
|
117
|
|
|
return $this->display_name; |
118
|
|
|
|
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* Returns user full name |
123
|
|
|
* |
124
|
|
|
* @return string |
125
|
|
|
*/ |
126
|
|
|
public function name() { |
127
|
|
|
|
128
|
|
|
return $this->name; |
129
|
|
|
|
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* Returns user user_login |
134
|
|
|
* |
135
|
|
|
* @return string |
136
|
|
|
*/ |
137
|
|
|
public function user_login() { |
138
|
|
|
|
139
|
|
|
return $this->user_login; |
140
|
|
|
|
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* Returns user email |
145
|
|
|
* |
146
|
|
|
* @return string |
147
|
|
|
*/ |
148
|
|
|
public function email() { |
149
|
|
|
|
150
|
|
|
return $this->user_email; |
151
|
|
|
|
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* Returns author posts url |
156
|
|
|
* |
157
|
|
|
* @return string |
158
|
|
|
*/ |
159
|
|
|
public function link() { |
160
|
|
|
if ( !$this->link ) { |
161
|
|
|
$this->link = get_author_posts_url($this->ID); |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
return $this->link; |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
} |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.