Jump to main content Jump to doc navigation

modX::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

  • modmore
  • modmore
  • Jens Wittmann – Gestaltung & Entwicklung
  • Raffy
  • eydolan
  • Digital Penguin
  • Fabian Christen
  • Dannevang Digital
  • deJaya
  • Sepia River Studios
  • Following Sea
  • Anton Tarasov
  • Lefthandmedia
  • Nick Clark
  • Chris Fickling
  • Murray Wood
  • YJ
  • CrewMark
  • Richard

Budget

$305 per month—let's make that $500!

Learn more