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
|
|
|
* It's basically sanitized version of user login, used for permalinks |
25
|
|
|
* @var string |
26
|
|
|
*/ |
27
|
|
|
public $user_nicename; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* User email |
31
|
|
|
* @var string |
32
|
|
|
*/ |
33
|
|
|
public $user_email; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Human-Friendly name, like: Andrew Tolochka |
37
|
|
|
* @var string |
38
|
|
|
*/ |
39
|
|
|
public $display_name; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* User password hash |
43
|
|
|
* @var string |
44
|
|
|
*/ |
45
|
|
|
private $user_pass; |
|
|
|
|
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Stores current post object |
49
|
|
|
* @var object |
50
|
|
|
*/ |
51
|
|
|
private $object; |
|
|
|
|
52
|
|
|
|
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Main constructor function. Requires user id |
56
|
|
|
* @param int $uid |
57
|
|
|
*/ |
58
|
|
|
public function __construct($uid = null) { |
59
|
|
|
$this->ID = $this->verify_id($uid); |
60
|
|
|
|
61
|
|
|
$this->init(); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
private function verify_id($uid) { |
65
|
|
|
return $uid; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Initialises Instance based on provided post id |
70
|
|
|
*/ |
71
|
|
|
private function init() { |
72
|
|
|
$object = (array) $this->get_object(); |
73
|
|
|
|
74
|
|
|
$this->import($object); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Returns user object |
79
|
|
|
* |
80
|
|
|
* @return object |
81
|
|
|
*/ |
82
|
|
|
private function get_object() { |
|
|
|
|
83
|
|
|
return get_userdata($this->ID); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Returns user first name |
88
|
|
|
* |
89
|
|
|
* @return string |
90
|
|
|
*/ |
91
|
|
|
public function first_name() { |
92
|
|
|
|
93
|
|
|
return $this->first_name; |
|
|
|
|
94
|
|
|
|
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Returns user display name |
99
|
|
|
* |
100
|
|
|
* @return string |
101
|
|
|
*/ |
102
|
|
|
public function display_name() { |
103
|
|
|
|
104
|
|
|
return $this->display_name; |
105
|
|
|
|
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* Returns user full name |
110
|
|
|
* |
111
|
|
|
* @return string |
112
|
|
|
*/ |
113
|
|
|
public function full_name() { |
114
|
|
|
|
115
|
|
|
return $this->first_name . ' ' . $this->last_name; |
|
|
|
|
116
|
|
|
|
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* Returns user user_login |
121
|
|
|
* |
122
|
|
|
* @return string |
123
|
|
|
*/ |
124
|
|
|
public function user_login() { |
125
|
|
|
|
126
|
|
|
return $this->user_login; |
127
|
|
|
|
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* Returns user email |
132
|
|
|
* |
133
|
|
|
* @return string |
134
|
|
|
*/ |
135
|
|
|
public function email() { |
136
|
|
|
|
137
|
|
|
return $this->user_email; |
138
|
|
|
|
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* Returns author posts url |
143
|
|
|
* |
144
|
|
|
* @return string |
145
|
|
|
*/ |
146
|
|
|
public function link() { |
147
|
|
|
if ( !$this->link ) { |
148
|
|
|
$this->link = get_author_posts_url($this->ID); |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
return $this->link; |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
} |
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.