Skip to content

Commit

Permalink
Merge pull request #2 from SebKay/users
Browse files Browse the repository at this point in the history
Users
  • Loading branch information
SebKay authored Jun 16, 2020
2 parents b42c121 + 1395597 commit 0701857
Show file tree
Hide file tree
Showing 2 changed files with 161 additions and 1 deletion.
2 changes: 1 addition & 1 deletion composer.json
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",
Expand Down
160 changes: 160 additions & 0 deletions src/User.php
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;
}
}

0 comments on commit 0701857

Please sign in to comment.