-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathWPUser.php
More file actions
40 lines (31 loc) · 1.01 KB
/
WPUser.php
File metadata and controls
40 lines (31 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
namespace lewiscowles\wordpress\auth;
use lewiscowles\auth\SystemUserInterface;
class WPUser implements SystemUserInterface {
protected $Pk;
public function __construct() {
if(!function_exists('get_current_user_id') ||
!function_exists('current_user_can') ||
!function_exists('wp_authenticate') ||
!function_exists('wp_logout') ||
!function_exists('is_user_logged_in')) {
throw new \RuntimeException("Required To Use Inside WordPress");
}
$this->Pk = \get_current_user_id();
}
public function hasCapability(string $capability) : bool {
return \current_user_can($capability);
}
public function isLoggedIn() : bool {
return \is_user_logged_in();
}
public function getPK() : string {
return $this->Pk;
}
public function login(string $username, string $password) {
\wp_authenticate($username, $password);
}
public function logout() {
\wp_logout();
}
}