|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace OOPWP; |
| 4 | + |
| 5 | +class User |
| 6 | +{ |
| 7 | + protected $id; |
| 8 | + |
| 9 | + /** |
| 10 | + * Set up |
| 11 | + * |
| 12 | + * @param integer $id |
| 13 | + */ |
| 14 | + public function __construct(int $id) |
| 15 | + { |
| 16 | + $this->id = ($id ?: -1); |
| 17 | + } |
| 18 | + |
| 19 | + /** |
| 20 | + * The ID |
| 21 | + * |
| 22 | + * @return int |
| 23 | + */ |
| 24 | + public function id() |
| 25 | + { |
| 26 | + return $this->id; |
| 27 | + } |
| 28 | + |
| 29 | + /** |
| 30 | + * Get WP_User object |
| 31 | + * |
| 32 | + * @return WP_User |
| 33 | + */ |
| 34 | + protected function getUser() |
| 35 | + { |
| 36 | + return \get_user_by('id', $this->id()); |
| 37 | + } |
| 38 | + |
| 39 | + /** |
| 40 | + * Get meta |
| 41 | + * |
| 42 | + * @param string $key |
| 43 | + * @return mixed |
| 44 | + */ |
| 45 | + public function meta(string $key) |
| 46 | + { |
| 47 | + return \get_user_meta($this->id, $key, true); |
| 48 | + } |
| 49 | + |
| 50 | + /** |
| 51 | + * Get first name |
| 52 | + * |
| 53 | + * @return string |
| 54 | + */ |
| 55 | + public function firstName() |
| 56 | + { |
| 57 | + return $this->meta('first_name'); |
| 58 | + } |
| 59 | + |
| 60 | + /** |
| 61 | + * Get last name |
| 62 | + * |
| 63 | + * @return string |
| 64 | + */ |
| 65 | + public function lastName() |
| 66 | + { |
| 67 | + return $this->meta('last_name'); |
| 68 | + } |
| 69 | + |
| 70 | + /** |
| 71 | + * Get full name |
| 72 | + * |
| 73 | + * @return string |
| 74 | + */ |
| 75 | + public function fullName() |
| 76 | + { |
| 77 | + return \trim("{$this->firstName()} {$this->lastName()}"); |
| 78 | + } |
| 79 | + |
| 80 | + /** |
| 81 | + * Get nickname |
| 82 | + * |
| 83 | + * @return string |
| 84 | + */ |
| 85 | + public function nickname() |
| 86 | + { |
| 87 | + return $this->meta('nickname'); |
| 88 | + } |
| 89 | + |
| 90 | + /** |
| 91 | + * Get biographical info |
| 92 | + * |
| 93 | + * @return string |
| 94 | + */ |
| 95 | + public function description() |
| 96 | + { |
| 97 | + return \apply_filters('the_content', $this->meta('description')); |
| 98 | + } |
| 99 | + |
| 100 | + /** |
| 101 | + * Get username |
| 102 | + * |
| 103 | + * @return string |
| 104 | + */ |
| 105 | + public function username() |
| 106 | + { |
| 107 | + return $this->getUser()->data->user_login; |
| 108 | + } |
| 109 | + |
| 110 | + /** |
| 111 | + * Get nicename |
| 112 | + * * A URL friendly version of username() |
| 113 | + * |
| 114 | + * @return string |
| 115 | + */ |
| 116 | + public function nicename() |
| 117 | + { |
| 118 | + return $this->getUser()->data->user_nicename; |
| 119 | + } |
| 120 | + |
| 121 | + /** |
| 122 | + * Get display name |
| 123 | + * |
| 124 | + * @return string |
| 125 | + */ |
| 126 | + public function displayName() |
| 127 | + { |
| 128 | + return $this->getUser()->data->display_name; |
| 129 | + } |
| 130 | + |
| 131 | + /** |
| 132 | + * Get email address |
| 133 | + * |
| 134 | + * @return string |
| 135 | + */ |
| 136 | + public function email() |
| 137 | + { |
| 138 | + return $this->getUser()->data->user_email; |
| 139 | + } |
| 140 | + |
| 141 | + /** |
| 142 | + * Get website URL |
| 143 | + * |
| 144 | + * @return string |
| 145 | + */ |
| 146 | + public function url() |
| 147 | + { |
| 148 | + return $this->getUser()->data->user_url; |
| 149 | + } |
| 150 | + |
| 151 | + /** |
| 152 | + * Get registration date |
| 153 | + * |
| 154 | + * @return string |
| 155 | + */ |
| 156 | + public function registredDate() |
| 157 | + { |
| 158 | + return $this->getUser()->data->user_registered; |
| 159 | + } |
| 160 | +} |
0 commit comments