PagePermissions class

Adds convenience methods to all Page objects for checking permissions, i.e.

if($page->editable()) { do something } if(!$page->viewable()) { echo "sorry you can't view this"; } ...and so on...

Optional special permissions that are optional (by default, not installed):

  1. page-publish: when installed, editable() returns false, when it would otherwise return true, on published pages, if user doesn't have page-publish permission in their roles.

  2. page-edit-created: when installed, editable() returns false, when it would otherwise return true, if user's role has this permission and they are not the $page->createdUser. This is a permission that reduces access rather than increasing it. Note that page-edit-created does nothing if the user doesn't have page-edit permission.

  3. page-rename: when installed, user must have this permission in their role before they can change the name of a published page. They can still change the name of an unpublished page. When not installed, this permission falls back to page-edit.

  4. page-edit-lang-default: when installed on a multi-language site, user must have this permission in order edit multi-language fields in "default" language. This permission is also required to create or delete pages (if user already has other permissions that enable them to create or delete pages).

  5. page-edit-lang-[language_name]: when installed on a multi-language site, user must have this permission to edit multi-language fields in the [language_name] language.

  6. page-edit-lang-none: when installed on a multi-language site, user must have this permission to edit non-multi-language fields. They must also have it to create or delete pages (if user already has other permissions that enable that).

  7. user-admin-all: when installed, a user must have this permission in order to edit other users of all roles (except superuser of course). When installed, the regular user-admin permission only acts as a pre-requisite for editing users, and enables only listing users, and editing users that have only the 'guest' role. The user-admin-all essentially grants the same thing as user-admin permission does on a system that has no user-admin-all permission installed. That's what it does, but why is it here? The entire purpose is to support user-admin-[role] permissions, as described in the next item below:

  8. user-admin-[role_name]: when installed on a site that also has user-admin-all permission installed, a user must have this permission (along with user-admin permission) in order to edit users in role [role_name], or to grant that role to other guest users, or to revoke it from them. Think of this permission as granting a user administrative privileges to just a specific group of users. Note that there would be no reason to combine this permission with the user-admin-all permission, as user-admin-all permission grants admin privileges to all roles.


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

Show class?     Show args?       Only hookable?    

Common

NameReturnSummary 
PagePermissions::addable(HookEvent $event)
NoneCan the current user add child pages to this page? 
PagePermissions::cloneable(HookEvent $event)
NoneIs page cloneable by current user? 
PagePermissions::deleteable(HookEvent $event)
NoneIs the page deleteable by the current user? 
PagePermissions::editable(HookEvent $event)
NoneHook that adds a Page::editable([$field]) method to determine if $page is editable by current user 
PagePermissions::fieldEditable(Page $page, $name)
boolIs the given field name editable? 
PagePermissions::fieldViewable(Page $page, $name)
boolIs the given Field or field name viewable? 
PagePermissions::listable(HookEvent $event)
NoneIs the page listable by the current user? 
PagePermissions::moveable(HookEvent $event)
NoneIs the given page moveable (i.e. change parent)? 
PagePermissions::publishable(HookEvent $event)
NoneIs the page publishable by the current user? 
PagePermissions::restorable(HookEvent $event)
NoneIs page restorable from trash? 
PagePermissions::sortable(HookEvent $event)
NoneIs the given page sortable by the current user? 
PagePermissions::trashListable()
boolReturn whether or not given page in Trash is listable 
PagePermissions::trashable(HookEvent $event)
NoneIs the page trashable by the current user? 
PagePermissions::userCanAssignRole($role)
boolCan the current user add/remove the given role from other users? 
PagePermissions::userEditable(Page $page)
boolReturns whether the given page ($page) is editable by the current user 
PagePermissions::userFieldEditable($name)
boolIs the given field editable by the current user in their user profile? 
PagePermissions::userViewable(Page $page)
boolReturns whether the given page ($page) is viewable by the current user 
PagePermissions::viewable(HookEvent $event)
NoneHook for Page::viewable() or Page::viewable($user) method 

Additional methods and properties

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

API reference based on ProcessWire core version 3.0.251