modX.getUser
Last updated Apr 15th, 2021 | Page history | Improve this page | Report an issue
Support the team building MODX with a monthly donation.
The budget raised through OpenCollective is transparent, including payouts, and any contributor can apply to be paid for their work on MODX.
Backers
Budget
$306 per month—let's make that $500!
Learn moremodX::getUser¶
Get the current authenticated User and assigns it to the modX instance.
Syntax¶
API Doc: modX::getUser()
modUser getUser ([string $contextKey = ''], [bool $forceLoadSettings = false])
-
$contextKey
(string) Indicates the context to initialize, an optional context to get the user from. -
$forceLoadSettings
(bool) If set to true, will load settings regardless of whether the user has an authenticated context or not
Example¶
Get the current auth'ed user and print out its username.
$user = $modx->getUser();
echo $user->get('username');
Get the user's email address (stored in their profile) from 'web' context:
$user = $modx->getUser('web', true);
if (!$user) return '';
$profile = $user->getOne('Profile');
if (!$profile) return '';
print $profile->get('email');
Get an extended field from the user.
$user = $modx->getUser();
if (!$user) return '';
$profile = $user->getOne('Profile');
if (!$profile) return '';
$extended = $profile->get('extended');
print (isset($extended['custom_user_field'])) ? $extended['custom_user_field'] : '';
See Also¶
Support the team building MODX with a monthly donation.
The budget raised through OpenCollective is transparent, including payouts, and any contributor can apply to be paid for their work on MODX.
Backers
Budget
$306 per month—let's make that $500!
Learn more