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