Jump to main content Jump to doc navigation


Get the current authenticated User and assigns it to the modX instance.


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


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.


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


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

Learn more