$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->admin_theme string Admin theme class name 
$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.137

Twitter updates

  • ProcessWire 3.0.142 has a lot of updates but the biggest is the addition of custom fields support for file and image fields. In this post, we take a closer look at that, and also outline all of the new features in the just-released FormBuilder v40— More
    11 October 2019
  • This week’s dev branch version brings you improvements to ProcessWire’s input->cookie API variable, plus it adds the ability to modify system URLs and paths at runtime. This post also includes some examples to demonstrate just how useful this can be— More
    20 September 2019
  • New post: This week we’ll take a look at a new version of FormBuilder that's on the way (with a screencast), as well as the latest version of the core: ProcessWire 3.0.140— More
    6 September 2019

Latest news

  • ProcessWire Weekly #283
    The 283rd issue of ProcessWire Weekly introduces ProcessWire 3.0.142 and FormBuilder v40, highlights some conference content, and features a new weekly poll continuing with the #processwireworks theme. Read on!
    Weekly.pw / 12 October 2019
  • ProcessWire 3.0.142 core updates
    This latest version of the core on the dev branch has a lot of updates, bnd the biggest is the addition of custom fields support for file and image fields. In this post, we take a closer look and also outline all of the new features in the just-released FormBuilder v40.
    Blog / 11 October 2019
  • Subscribe to weekly ProcessWire news

I just love the easy and intuitive ProcessWire API. ProcessWire rocks!” —Jens Martsch, Web developer