$user->hasPermission() method

Does the user have the given permission?

  • Optionally accepts a Page or Template context for the permission.
  • This method accounts for the user's permissions across all their roles.

Example

if($user->hasPermission('page-publish')) {
  // user has the page-publish permission in one of their roles
}
if($user->hasPermission('page-publish', $page)) {
  // user has page-publish permission for $page
}

Usage

// basic usage
$bool = $user->hasPermission($name);

// usage with all arguments
$bool = $user->hasPermission($name, $context = null);

Arguments

NameType(s)Description
namestring, Permission

Permission name, object or id.

context (optional)Page, Template, bool, string

Page or Template...

  • or specify boolean true to return if user has permission OR if it was added at any template
  • or specify string "templates" to return array of Template objects where user has permission

Return value

bool array


$user methods and properties

API reference based on ProcessWire core version 3.0.236

Latest news

  • ProcessWire Weekly #549
    In the 549th issue of ProcessWire Weekly we’re going to check out the latest core updates, highlight one older yet still very relevant third party module, and more. Read on!
    Weekly.pw / 17 November 2024
  • Custom Fields Module
    This week we look at a new ProFields module named Custom Fields. This module provides a way to rapidly build out ProcessWire fields that contain any number of subfields/properties within them.
    Blog / 30 August 2024
  • Subscribe to weekly ProcessWire news

“…building with ProcessWire was a breeze, I really love all the flexibility the system provides. I can’t imagine using any other CMS in the future.” —Thomas Aull