PluginProbe
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses / 2.7.7
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses v2.7.7
2.10.0 2.10.01 2.9.1 2.9.0 2.8.1 2.8.0 2.7.7 2.7.5 2.7.0 2.6.01 2.6.0 2.5.0 2.4.01 trunk 1.0.90 1.0.91 1.0.92 1.0.93 1.0.94 1.0.95 1.0.96 1.0.97 1.0.98 1.0.99 1.1.0 All 77 releases
fluent-community / app / Models / User.php

User.php in FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses 2.7.7, at app/Models/User.php

796 lines 25.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentCommunity\App\Models;
4
5 use FluentCommunity\App\Functions\Utility;
6 use FluentCommunity\App\Services\FeedsHelper;
7 use FluentCommunity\App\Services\Helper;
8 use FluentCommunity\App\Services\ProfileHelper;
9 use FluentCommunity\Framework\Support\Arr;
10 use FluentCommunity\Modules\Course\Model\Course;
11 use FluentCommunityPro\App\Models\Follow;
12 use FluentCrm\App\Models\Subscriber;
13
14 /**
15 * User Model - DB Model for WordPress Users Table
16 *
17 * Database Model
18 *
19 * @package FluentCommunity\App\Models
20 *
21 * @version 1.0.0
22 *
23 * @property int $ID
24 * @property string $user_login
25 * @property string $user_pass
26 * @property string $user_nicename
27 * @property string $user_email
28 * @property string $user_url
29 * @property string $user_registered
30 * @property string $user_activation_key
31 * @property int $user_status
32 * @property string $display_name
33 * @property-read string $photo
34 * @property-read XProfile|null $xprofile
35 * @property string|null $username
36 */
37 class User extends Model
38 {
39 protected $table = 'users';
40
41 protected $primaryKey = 'ID';
42
43 protected $hidden = [ 'user_pass', 'user_activation_key' ];
44
45 protected $appends = [ 'photo' ];
46
47 public $timestamps = false;
48
49 protected $searchable = [
50 'display_name',
51 'user_email',
52 ];
53
54 public function scopeSearchBy($query, $search)
55 {
56 if ($search) {
57 $fields = $this->searchable;
58 $query->where(function ($query) use ($fields, $search) {
59 $query->where(array_shift($fields), 'LIKE', "%$search%");
60 foreach ($fields as $field) {
61 $query->orWhere($field, 'LIKE', "$search%");
62 }
63 });
64 }
65
66 return $query;
67 }
68
69 public function scopeMentionBy($query, $search)
70 {
71 if ($search) {
72 $fields = [
73 'display_name',
74 'user_login',
75 ];
76 $query->where(function ($query) use ($fields, $search) {
77 $query->where(array_shift($fields), 'LIKE', "$search%");
78 foreach ($fields as $field) {
79 $query->orWhere($field, 'LIKE', "$search%");
80 }
81 });
82 }
83
84 return $query;
85 }
86
87 /**
88 * Accessor to get dynamic photo attribute
89 * @return string
90 */
91 public function getPhotoAttribute()
92 {
93 if ($photo = get_user_meta($this->ID, '_fcom_user_photo', true)) { // phpcs:ignore Squiz.PHP.DisallowMultipleAssignments.FoundInControlStructure
94 return $photo;
95 }
96
97 if ($contact = $this->getContact()) { // phpcs:ignore Squiz.PHP.DisallowMultipleAssignments.FoundInControlStructure
98 return $contact->photo;
99 }
100
101 if (empty($this->attributes['user_email'])) {
102 if (defined('FLUENTCRM')) {
103 $contact = Subscriber::where('user_id', $this->ID)->first();
104 if ($contact) {
105 return $contact->photo;
106 }
107 }
108 return '';
109 }
110
111 if (Utility::getPrivacySetting('enable_gravatar') != 'yes') {
112 return apply_filters('fluent_community/default_avatar', FLUENT_COMMUNITY_PLUGIN_URL . 'assets/images/placeholder.png', $this->ID);
113 }
114
115 $hash = md5(strtolower(trim($this->attributes['user_email'])));
116
117 /**
118 * Gravatar URL by Email
119 *
120 * @return string $gravatar url of the gravatar image
121 */
122 $name = $this->attributes['display_name'];
123
124 $fallback = '';
125 if ($name) {
126 $fallback = '&d=https%3A%2F%2Fui-avatars.com%2Fapi%2F' . urlencode($name) . '/128';
127 }
128
129 return apply_filters('fluent_crm/get_avatar',
130 "https://www.gravatar.com/avatar/{$hash}?s=128" . $fallback,
131 $this->attributes['user_email']
132 );
133 }
134
135 public function getIsVerifiedAttribute()
136 {
137 return $this->isVerified();
138 }
139
140 public function getContact()
141 {
142 if (!defined('FLUENTCRM')) {
143 return null;
144 }
145
146 if ($this->user_email) {
147 return Subscriber::where('user_id', $this->ID)
148 ->orWhere('email', $this->user_email)
149 ->first();
150 }
151
152 return Subscriber::where('user_id', $this->ID)
153 ->first();
154 }
155
156 public function xprofile()
157 {
158 return $this->belongsTo(XProfile::class, 'ID', 'user_id');
159 }
160
161 // Relationship: Users this user follows
162 public function follows()
163 {
164 return $this->hasMany(Follow::class, 'follower_id', 'ID');
165
166 }
167
168 // Relationship: Users following this user
169 public function followers()
170 {
171 return $this->hasMany(Follow::class, 'followed_id', 'ID');
172 }
173
174 public function usermeta()
175 {
176 return $this->hasMany(UserMeta::class, 'user_id', 'ID');
177 }
178
179 public function messages()
180 {
181 return $this->hasMany(\FluentMessaging\App\Models\Message::class, 'user_id', 'ID');
182 }
183
184 public function getGeneralData()
185 {
186 $user = get_user_by('ID', $this->ID);
187
188 $fullName = '';
189 if ($user->first_name || $user->last_name) {
190 $fullName = trim($user->first_name . ' ' . $user->last_name);
191 }
192
193 if (!$fullName) {
194 $fullName = $user->display_name;
195 }
196
197 $contact = $this->getContact();
198
199 return [
200 'is_contact' => (bool)$contact,
201 'first_name' => $user->first_name,
202 'last_name' => $user->last_name,
203 'full_name' => $fullName,
204 'display_name' => $fullName,
205 'bio' => $user->description,
206 'website' => $user->user_url,
207 'id' => $user->ID,
208 'user_id' => $user->ID,
209 'created_at' => $user->user_registered,
210 'photo' => $this->photo,
211 'username' => $this->username,
212 'is_verified' => $this->isVerified(),
213 ];
214 }
215
216 public function spaces()
217 {
218 return $this->belongsToMany(BaseSpace::class, 'fcom_space_user', 'user_id', 'space_id')
219 ->withPivot([ 'role', 'status', 'created_at' ]);
220 }
221
222 public function courses()
223 {
224 return $this->belongsToMany(Course::class, 'fcom_space_user', 'user_id', 'space_id')
225 ->withPivot([ 'role', 'created_at' ]);
226 }
227
228 public function notificationSubscriptions()
229 {
230 return $this->hasMany(NotificationSubscription::class, 'user_id');
231 }
232
233 public function space_pivot()
234 {
235 return $this->belongsTo(SpaceUserPivot::class, 'ID', 'user_id')->withoutGlobalScopes();
236 }
237
238 public function notification_records()
239 {
240 return $this->hasMany(NotificationSubscriber::class, 'user_id', 'ID')->withoutGlobalScopes();
241 }
242
243 public function crm_contact()
244 {
245 return $this->belongsTo(Contact::class, 'ID', 'user_id')->withoutGlobalScopes();
246 }
247
248 public function community_role()
249 {
250 return $this->belongsTo(Meta::class, 'ID', 'object_id')
251 ->where('object_type', 'user')
252 ->where('meta_key', '_user_community_roles');
253 }
254
255 public function updateCustomData($updateData, $removeSrc = false)
256 {
257 if (isset($updateData['first_name']) && Utility::getPrivacySetting('enable_user_sync') === 'yes') {
258 $firstName = sanitize_text_field($updateData['first_name']);
259 $lastName = sanitize_text_field($updateData['last_name']);
260
261 $userData = [
262 'first_name' => $firstName,
263 'last_name' => $lastName,
264 'display_name' => trim($firstName . ' ' . $lastName),
265 'description' => isset($updateData['short_description']) ? sanitize_textarea_field($updateData['short_description']) : '',
266 'user_url' => isset($updateData['website']) ? esc_url($updateData['website']) : '',
267 'ID' => $this->ID,
268 ];
269
270 wp_update_user($userData);
271
272 if ($contact = $this->getContact()) { // phpcs:ignore Squiz.PHP.DisallowMultipleAssignments.FoundInControlStructure
273 $contact->fill(array_filter([
274 'first_name' => $firstName,
275 'last_name' => $lastName,
276 ]));
277
278 $dirtyFields = $contact->getDirty();
279 if ($dirtyFields) {
280 $contact->save();
281 do_action('fluent_crm/contact_updated', $contact, $dirtyFields);
282 }
283
284 }
285 }
286
287 return $this;
288 }
289
290 public function getDisplayName()
291 {
292 $user = get_user_by('ID', $this->ID);
293 $name = '';
294 if ($user->first_name || $user->last_name) {
295 $name = trim($user->first_name . ' ' . $user->last_name);
296 }
297 if ($name) {
298 return $name;
299 }
300
301 return $user->display_name;
302 }
303
304 public function getCustomMeta($key, $default = null)
305 {
306 $exist = Meta::where('object_type', 'user')
307 ->where('object_id', $this->ID)
308 ->where('meta_key', $key)
309 ->first();
310
311 if ($exist && $exist->value) {
312 return $exist->value;
313 }
314
315 return $default;
316 }
317
318 public function updateCustomMeta($key, $value)
319 {
320 $exist = Meta::where('object_type', 'user')
321 ->where('object_id', $this->ID)
322 ->where('meta_key', $key)
323 ->first();
324
325 if ($exist) {
326 $exist->value = $value;
327 $exist->save();
328 return $exist;
329 }
330
331 return Meta::create([
332 'object_type' => 'user',
333 'object_id' => $this->ID,
334 'meta_key' => $key, // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key
335 'value' => $value,
336 ]);
337 }
338
339 public function isNotMemberOfAnySpace()
340 {
341 return $this->spaces()->count() == 0;
342 }
343
344 public function getSpaceIds($cached = true)
345 {
346 if ($cached) {
347 $ids = get_user_meta($this->ID, '_fcom_space_ids', true);
348 if (!$ids || !is_array($ids)) {
349 $ids = [];
350 }
351 return $ids;
352 }
353
354 $this->cacheAccessSpaces();
355
356 return get_user_meta($this->ID, '_fcom_space_ids', true);
357 }
358
359 public function getJoinedSpaceIds()
360 {
361 $globalRoles = $this->getCommunityRoles();
362
363 if (array_intersect($globalRoles, [ 'admin', 'moderator' ])) {
364 return BaseSpace::onlyMain()->pluck('id')->toArray();
365 }
366
367 return BaseSpace::onlyMain()->whereHas('members', function ($query) {
368 $query->where('user_id', $this->ID)
369 ->where('status', 'active');
370 })->pluck('id')->toArray();
371 }
372
373 public function getCommunityRoles()
374 {
375 if (Helper::isSuperAdmin($this->ID)) {
376 return [ 'admin' ];
377 }
378
379 return (array)$this->getCustomMeta('_user_community_roles', []);
380 }
381
382 public function isCommunityAdmin()
383 {
384 return in_array('admin', $this->getCommunityRoles());
385 }
386
387 public function isCommunityModerator()
388 {
389 return (bool)array_intersect([ 'moderator', 'admin' ], $this->getCommunityRoles());
390 }
391
392 public function hasCommunityModeratorAccess()
393 {
394 $permissions = $this->getPermissions(true);
395
396 return Arr::isTrue($permissions, 'community_moderator');
397 }
398
399 public function hasCommunityAdminAccess()
400 {
401 $permissions = $this->getPermissions(true);
402
403 return Arr::isTrue($permissions, 'community_admin');
404 }
405
406 public function hasCourseCreatorAccess()
407 {
408 $permissions = $this->getPermissions(true);
409
410 return Arr::isTrue($permissions, 'course_creator');
411 }
412
413 public function isSpaceModerator()
414 {
415 return $this->hasCourseCreatorAccess() || $this->hasCommunityModeratorAccess();
416 }
417
418 public function hasSpaceManageAccess()
419 {
420 $permissions = array_filter($this->getPermissions(true));
421
422 return (bool)array_intersect([ 'community_admin', 'course_admin' ], array_keys($permissions));
423 }
424
425 public function getSpaceRole($space)
426 {
427 $globalRoles = $this->getCommunityRoles();
428
429 if ($globalRoles) {
430 if (in_array('admin', $globalRoles)) {
431 return 'admin';
432 }
433 }
434
435 if ($space) {
436 $membership = $space->getMembership($this->ID);
437
438 if ($membership) {
439 $role = $membership->pivot->role;
440 $status = $membership->pivot->status;
441
442 if ($role != 'member') {
443 return $role;
444 }
445
446 if (!in_array('moderator', $globalRoles)) {
447 if ($status == 'pending') {
448 return 'pending';
449 }
450 return $role;
451 }
452 }
453 }
454
455 if (in_array('moderator', $globalRoles)) {
456 return 'moderator';
457 }
458
459 return '';
460 }
461
462 public function cacheAccessSpaces()
463 {
464 $globalRoles = $this->getCommunityRoles();
465
466 if (array_intersect($globalRoles, [ 'admin', 'moderator' ])) {
467 $spaces = BaseSpace::onlyMain()->get();
468 } else {
469 $spaces = BaseSpace::onlyMain()->where(function ($spaceQuery) {
470 $spaceQuery->whereHas('members', function ($memberQuery) {
471 $memberQuery->where('user_id', $this->ID)
472 ->where('status', 'active');
473 })->orWhere('privacy', 'public');
474 })->get();
475 }
476
477 $spaceIds = $spaces->pluck('id')->toArray();
478
479 update_user_meta($this->ID, '_fcom_space_ids', $spaceIds);
480
481 return $spaces;
482 }
483
484 protected function getRolePermissions($roles)
485 {
486 if (!$roles) {
487 return apply_filters('fluent_community/user/permissions', [
488 'read' => true,
489 ], $roles, $this);
490 }
491
492 $isAdmin = in_array('admin', $roles);
493 $isModerator = (bool)array_intersect($roles, [ 'admin', 'moderator' ]);
494
495 $permissions = [
496 'admin' => $isAdmin,
497 'super_admin' => Helper::isSuperAdmin(),
498 'community_admin' => $isAdmin,
499 'community_moderator' => $isModerator,
500 'delete_any_feed' => $isModerator,
501 'edit_any_feed' => $isModerator,
502 'delete_any_comment' => $isModerator,
503 'edit_any_comment' => $isModerator,
504 'read' => true,
505 ];
506
507 if ($isAdmin || in_array('course_admin', $roles)) {
508 $permissions['course_creator'] = true;
509 $permissions['course_admin'] = true;
510 } elseif (in_array('course_creator', $roles)) {
511 $permissions['course_creator'] = true;
512 }
513
514 return apply_filters('fluent_community/user/permissions', $permissions, $roles, $this);
515 }
516
517 public function getPermissions($cached = true)
518 {
519 static $permissions = [];
520
521 if ($cached && isset($permissions[$this->ID])) {
522 return $permissions[$this->ID];
523 }
524
525 $roles = $this->getCommunityRoles();
526
527 return $permissions[$this->ID] = $this->getRolePermissions($roles);
528 }
529
530 public function getSpacePermissions($space)
531 {
532 if (!$space) {
533 return [];
534 }
535
536 $role = $this->getSpaceRole($space);
537
538 $hasDocuments = defined('FLUENT_COMMUNITY_PRO') && Arr::get($space->settings, 'document_library') == 'yes';
539 $hasMediaGallery = defined('FLUENT_COMMUNITY_PRO') && Arr::get($space->settings, 'media_gallery') == 'yes';
540
541 $isRestrictedPost = Arr::get($space->settings, 'restricted_post_only') == 'yes';
542
543 $documentAccess = Arr::get($space->settings, 'document_access');
544 $mediaAccess = Arr::get($space->settings, 'media_access');
545
546 if (!$role) {
547 $permissions = [
548 'can_create_post' => false,
549 'registered' => true,
550 'can_comment' => false,
551 'can_view_posts' => true,
552 'can_view_members' => $space->canViewMembers($this),
553 'is_pending' => false,
554 'is_non_member' => true,
555 'can_view_info' => $space->privacy !== 'secret',
556 'can_view_documents' => $hasDocuments && in_array($documentAccess, [ 'everybody', 'logged_in' ]),
557 'can_view_media' => $hasMediaGallery && in_array($mediaAccess, [ 'everybody', 'logged_in' ]),
558 ];
559
560 if ($space->privacy === 'secret' || $space->privacy === 'private') {
561 $permissions['can_view_posts'] = false;
562 $permissions['can_view_members'] = false;
563 $permissions['can_view_documents'] = false;
564 $permissions['can_view_media'] = false;
565 }
566 } elseif ($role == 'pending') {
567 $permissions = [
568 'can_create_post' => false,
569 'registered' => true,
570 'can_view_posts' => true,
571 'can_comment' => false,
572 'can_view_members' => $space->canViewMembers($this),
573 'is_pending' => true,
574 'can_view_info' => $space->privacy !== 'secret',
575 'can_view_documents' => $hasDocuments && in_array($documentAccess, [ 'everybody', 'logged_in' ]),
576 'can_view_media' => $hasMediaGallery && in_array($mediaAccess, [ 'everybody', 'logged_in' ]),
577 ];
578
579 if ($space->privacy === 'secret' || $space->privacy === 'private') {
580 $permissions['can_view_posts'] = false;
581 $permissions['can_view_members'] = false;
582 $permissions['can_view_documents'] = false;
583 $permissions['can_view_media'] = false;
584 }
585 } elseif ($role == 'member' || $role == 'student') {
586 $permissions = [
587 'can_create_post' => $isRestrictedPost ? false : true,
588 'registered' => true,
589 'can_view_posts' => true,
590 'can_view_members' => $space->canViewMembers($this),
591 'can_comment' => true,
592 'can_view_info' => true,
593 'can_view_documents' => $hasDocuments,
594 'can_upload_documents' => $hasDocuments && Arr::get($space->settings, 'document_upload') == 'members_only',
595 'can_view_media' => $hasMediaGallery,
596 ];
597 } else {
598 $isMod = in_array($role, [ 'admin', 'moderator' ]);
599 $isAdmin = $role === 'admin';
600 $permissions = [
601 'can_create_post' => $isRestrictedPost ? $isMod : true,
602 'can_view_posts' => true,
603 'can_view_members' => $isAdmin || $space->canViewMembers($this),
604 'registered' => true,
605 'community_admin' => $isAdmin,
606 'community_moderator' => $isMod,
607 'edit_any_feed' => $isMod,
608 'delete_any_feed' => $isMod,
609 'edit_any_comment' => $isMod,
610 'delete_any_comment' => $isMod,
611 'super_admin' => Helper::isSuperAdmin(),
612 'read' => true,
613 'can_remove_member' => $isAdmin,
614 'can_add_member' => $isAdmin,
615 'can_comment' => $isMod,
616 'can_view_info' => true,
617 'can_view_documents' => $hasDocuments,
618 'can_upload_documents' => $hasDocuments && $isMod,
619 'can_view_media' => $hasMediaGallery,
620 ];
621 }
622
623 $permissions['is_member'] = in_array($role, [ 'admin', 'moderator', 'member', 'student' ]);
624
625 return apply_filters('fluent_community/user/space/permissions', $permissions, $space, $role, $this);
626 }
627
628 public function hasCommunityPermission($permission)
629 {
630 $permissions = $this->getPermissions();
631
632 if (isset($permissions[$permission])) {
633 return $permissions[$permission];
634 }
635
636 return false;
637 }
638
639 public function hasSpacePermission($permission, $space)
640 {
641 $permissions = $this->getSpacePermissions($space);
642
643 if (isset($permissions[$permission])) {
644 return $permissions[$permission];
645 }
646
647 return false;
648 }
649
650 public function verifyCommunityPermission($permission)
651 {
652 if (!$this->hasCommunityPermission($permission)) {
653 throw new \Exception(esc_html__('You do not have permission to do this action', 'fluent-community'));
654 }
655
656 return true;
657 }
658
659 public function verifySpacePermission($permission, $space)
660 {
661 if (!$space || !$this->hasSpacePermission($permission, $space)) {
662 throw new \Exception(esc_html__('You do not have permission to do this action', 'fluent-community'));
663 }
664
665 return true;
666 }
667
668 public function canEditFeed($feed, $throwException = false)
669 {
670 $result = $feed->user_id == $this->ID || $this->hasCommunityPermission('edit_any_feed') || $this->hasSpacePermission('edit_any_feed', $feed->space);
671
672 if (!$result && $throwException) {
673 throw new \Exception(esc_html__('You do not have permission to do this action', 'fluent-community'));
674 }
675
676 return $result;
677 }
678
679 public function canDeleteFeed($feed, $throwException = false)
680 {
681 $result = $feed->user_id == $this->ID || $this->hasCommunityPermission('delete_any_feed') || $this->hasSpacePermission('delete_any_feed', $feed->space);
682
683 if (!$result && $throwException) {
684 throw new \Exception(esc_html__('You do not have permission to do this action', 'fluent-community'));
685 }
686 return $result;
687 }
688
689 public function can($permission, $space = null)
690 {
691 if ($space) {
692 return $this->hasSpacePermission($permission, $space);
693 }
694
695 return $this->hasCommunityPermission($permission);
696 }
697
698 public function hasPermissionOrInCurrentSpace($permission, $space = null)
699 {
700 if ($this->hasCommunityPermission($permission)) {
701 return true;
702 }
703
704 return $space && $this->hasSpacePermission($permission, $space);
705 }
706
707 public function getUnreadNotificationCount()
708 {
709 return NotificationSubscriber::where('user_id', $this->ID)
710 ->unread()
711 ->count();
712 }
713
714 public function getUnreadNotificationFeedIds()
715 {
716 $ids = Notification::whereHas('subscribers', function ($query) {
717 return $query->where('user_id', $this->ID)
718 ->unread();
719 })->pluck('feed_id')->toArray();
720
721 return array_values(array_unique($ids));
722 }
723
724 public function isVerified()
725 {
726 if ($this->xprofile) {
727 return (bool) $this->xprofile->is_verified;
728 }
729
730 return false;
731 }
732
733 public function syncXProfile($force = false, $useUserName = false)
734 {
735 $exist = XProfile::where('user_id', $this->ID)->first();
736
737 if (($exist && !$force) || ($exist && Utility::getPrivacySetting('enable_user_sync') === 'no')) {
738 return $exist;
739 }
740
741 $data = [
742 'user_id' => $this->ID,
743 'username' => ProfileHelper::generateUserName($this->ID, $useUserName),
744 'display_name' => $this->getDisplayName(),
745 'is_verified' => $this->isVerified() ? 1 : 0,
746 'short_description' => get_user_meta($this->ID, 'description', true),
747 'meta' => [
748 'website' => $this->user_url,
749 'cover_photo' => get_user_meta($this->ID, '_fluent_cover_photo', true),
750 'short_description_rendered' => wp_kses_post(FeedsHelper::mdToHtml(get_user_meta($this->ID, 'description', true))),
751 ],
752 ];
753
754 if ($exist) {
755 $data = array_diff_key($data, [ 'avatar' => true, 'username' => true ]);
756
757 if (apply_filters('fluent/community/user_wp_user_registered_date', true, $this)) {
758 $data['created_at'] = $this->user_registered;
759 }
760
761 $data['meta'] = wp_parse_args($exist->meta, $data['meta']);
762 $exist->fill($data);
763 $exist->save();
764 return $exist;
765 }
766
767 $counter = 1;
768 $initialUserName = $data['username'];
769 while (XProfile::where('username', $initialUserName)->first()) {
770 $initialUserName = $data['username'] . '_' . $counter;
771 ++$counter;
772 }
773
774 $data['username'] = $initialUserName;
775 $data['status'] = 'active';
776 if (apply_filters('fluent/community/user_wp_user_registered_date', true, $this)) {
777 $data['created_at'] = get_date_from_gmt($this->user_registered, 'Y-m-d H:i:s');
778 }
779
780 $xprofile = XProfile::create($data);
781 $this->load('xprofile');
782
783 return $xprofile;
784 }
785
786 public function getUserMeta($metaKey, $default = null)
787 {
788 return get_user_meta($this->ID, $metaKey, true) ?? $default;
789 }
790
791 public function getWpUser()
792 {
793 return get_user_by('ID', $this->ID);
794 }
795 }
796