|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace EventEspresso\core\domain\entities\routing\data_nodes\core; |
|
4
|
|
|
|
|
5
|
|
|
use EventEspresso\core\services\json\JsonDataNode; |
|
6
|
|
|
use EventEspresso\core\services\json\JsonDataNodeValidator; |
|
7
|
|
|
use WP_User; |
|
8
|
|
|
use GraphQLRelay\Relay; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* Class CurrentUser |
|
12
|
|
|
* |
|
13
|
|
|
* @package EventEspresso\core\domain\entities\routing\data_nodes |
|
14
|
|
|
* @author Brent Christensen |
|
15
|
|
|
* @since $VID:$ |
|
16
|
|
|
*/ |
|
17
|
|
|
class CurrentUser extends JsonDataNode |
|
18
|
|
|
{ |
|
19
|
|
|
const NODE_NAME = 'currentUser'; |
|
20
|
|
|
|
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* JsonDataNodeHandler constructor. |
|
24
|
|
|
* |
|
25
|
|
|
* @param JsonDataNodeValidator $validator |
|
26
|
|
|
*/ |
|
27
|
|
|
public function __construct(JsonDataNodeValidator $validator) |
|
28
|
|
|
{ |
|
29
|
|
|
if (! class_exists('WPGraphQL')) { |
|
30
|
|
|
require_once EE_THIRD_PARTY . 'wp-graphql/wp-graphql.php'; |
|
31
|
|
|
} |
|
32
|
|
|
parent::__construct($validator); |
|
33
|
|
|
$this->setNodeName(CurrentUser::NODE_NAME); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @inheritDoc |
|
38
|
|
|
*/ |
|
39
|
|
|
public function initialize() |
|
40
|
|
|
{ |
|
41
|
|
|
$current_user = wp_get_current_user(); |
|
42
|
|
|
if (! $current_user instanceof WP_User) { |
|
|
|
|
|
|
43
|
|
|
$current_user = new WP_User(); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
$this->addData('id', Relay::toGlobalId('user', $current_user->ID)); |
|
47
|
|
|
$this->addData('databaseId', $current_user->ID); |
|
48
|
|
|
$this->addData('description', $current_user->description); |
|
49
|
|
|
$this->addData('email', $current_user->user_email); |
|
50
|
|
|
$this->addData('firstName', $current_user->first_name); |
|
51
|
|
|
$this->addData('lastName', $current_user->last_name); |
|
52
|
|
|
$this->addData('locale', get_user_locale($current_user->ID)); |
|
53
|
|
|
$this->addData('name', $current_user->display_name); |
|
54
|
|
|
$this->addData('nicename', $current_user->user_nicename); |
|
55
|
|
|
$this->addData('nickname', $current_user->nickname); |
|
56
|
|
|
$this->addData('username', $current_user->user_login); |
|
57
|
|
|
$this->addData('__typename', 'User'); |
|
58
|
|
|
$this->setInitialized(true); |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
|