-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from SebKay/users
Users
- Loading branch information
Showing
2 changed files
with
161 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "sebkay/oop-wp", | ||
"version" : "1.0.0", | ||
"version" : "1.1.0", | ||
"authors": [ | ||
{ | ||
"name": "Seb Kay", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
<?php | ||
|
||
namespace OOPWP; | ||
|
||
class User | ||
{ | ||
protected $id; | ||
|
||
/** | ||
* Set up | ||
* | ||
* @param integer $id | ||
*/ | ||
public function __construct(int $id) | ||
{ | ||
$this->id = ($id ?: -1); | ||
} | ||
|
||
/** | ||
* The ID | ||
* | ||
* @return int | ||
*/ | ||
public function id() | ||
{ | ||
return $this->id; | ||
} | ||
|
||
/** | ||
* Get WP_User object | ||
* | ||
* @return WP_User | ||
*/ | ||
protected function getUser() | ||
{ | ||
return \get_user_by('id', $this->id()); | ||
} | ||
|
||
/** | ||
* Get meta | ||
* | ||
* @param string $key | ||
* @return mixed | ||
*/ | ||
public function meta(string $key) | ||
{ | ||
return \get_user_meta($this->id, $key, true); | ||
} | ||
|
||
/** | ||
* Get first name | ||
* | ||
* @return string | ||
*/ | ||
public function firstName() | ||
{ | ||
return $this->meta('first_name'); | ||
} | ||
|
||
/** | ||
* Get last name | ||
* | ||
* @return string | ||
*/ | ||
public function lastName() | ||
{ | ||
return $this->meta('last_name'); | ||
} | ||
|
||
/** | ||
* Get full name | ||
* | ||
* @return string | ||
*/ | ||
public function fullName() | ||
{ | ||
return \trim("{$this->firstName()} {$this->lastName()}"); | ||
} | ||
|
||
/** | ||
* Get nickname | ||
* | ||
* @return string | ||
*/ | ||
public function nickname() | ||
{ | ||
return $this->meta('nickname'); | ||
} | ||
|
||
/** | ||
* Get biographical info | ||
* | ||
* @return string | ||
*/ | ||
public function description() | ||
{ | ||
return \apply_filters('the_content', $this->meta('description')); | ||
} | ||
|
||
/** | ||
* Get username | ||
* | ||
* @return string | ||
*/ | ||
public function username() | ||
{ | ||
return $this->getUser()->data->user_login; | ||
} | ||
|
||
/** | ||
* Get nicename | ||
* * A URL friendly version of username() | ||
* | ||
* @return string | ||
*/ | ||
public function nicename() | ||
{ | ||
return $this->getUser()->data->user_nicename; | ||
} | ||
|
||
/** | ||
* Get display name | ||
* | ||
* @return string | ||
*/ | ||
public function displayName() | ||
{ | ||
return $this->getUser()->data->display_name; | ||
} | ||
|
||
/** | ||
* Get email address | ||
* | ||
* @return string | ||
*/ | ||
public function email() | ||
{ | ||
return $this->getUser()->data->user_email; | ||
} | ||
|
||
/** | ||
* Get website URL | ||
* | ||
* @return string | ||
*/ | ||
public function url() | ||
{ | ||
return $this->getUser()->data->user_url; | ||
} | ||
|
||
/** | ||
* Get registration date | ||
* | ||
* @return string | ||
*/ | ||
public function registredDate() | ||
{ | ||
return $this->getUser()->data->user_registered; | ||
} | ||
} |