$user API variable / User class

The $user API variable is a type of page representing the current user, and the User class is Page type used for all users.

Click any linked item for full usage details and examples. Hookable methods are indicated with the icon. In addition to those shown below, the User class also inherits all the methods and properties of: Page, WireData and Wire.

Show $var?             Show args?        

Common

NameReturnSummary 
$user->addRole($role)
boolAdd Role to this user 
$user->changed(string $what)
(nothing)Hook called when field has changed
$user->email string Get or set email address for this user. 
$user->getPermissions()
PageArrayGet this user’s permissions, optionally within the context of a Page. 
$user->hasPermission($name)
bool arrayDoes the user have the given permission? 
$user->hasRole($role)
boolDoes this user have the given Role? 
$user->isGuest()
boolIs this the non-logged in guest user? 
$user->isLoggedin()
boolIs the current user logged in? 
$user->isSuperuser()
boolDoes this user have the superuser role? 
$user->language Language User language, applicable only if LanguageSupport installed. 
$user->pass string Password Set the user’s password.  
$user->removeRole($role)
boolRemove Role from this user 
$user->roles PageArray Get the roles this user has.  

For hooks

These methods are only useful for hooking and should not be called directly.

Additional methods and properties

In addition to the methods and properties above, User also inherits the methods and properties of these classes:

API reference based on ProcessWire core version 3.0.125

Twitter updates

  • New post: ProcessWire 3.0.125 has several useful new Sanitizer methods & options, plus new ways to access them directly from the Input API variable. This makes handling user input even easier than before. Plus updates to our i18n functions & API docs— More
    25 January 2019
  • New post: In this week’s post, we’ll take a look a look at the new website and focus on some parts of it and how they were built. Then we’ll dive into the latest version of ProcessWire on the dev branch, version 3.0.124— More
    11 January 2019
  • New ProcessWire main site rebuild ready for preview— More
    4 January 2019

Latest news

  • ProcessWire Weekly #248
    In the 248th issue of ProcessWire Weekly we'll introduce a third party module called SEO Maestro, feature a handy little recipe of the week, and showcase a brilliant new site of the week called Urban Alternatives. Read on!
    Weekly.pw / 9 February 2019
  • A closer look at ProcessWire ProMailer
    This week we take a closer look at the upcoming ProMailer module with a lot more details and screenshots. Plus an update on next steps with the new website and development schedule in the weeks ahead. 
    Blog / 1 February 2019
  • Subscribe to weekly ProcessWire news

“I am currently managing a ProcessWire site with 2 million+ pages. It’s admirably fast, and much, much faster than any other CMS we tested.” —Nickie, Web developer