Skip to the content
Documentation
Help Start
Reading in:
  • German: 9,059 of 9,059 pages
About the help in other languages
All help pages

eZUser and access checks

The current user and access checks from PHP and templates - eZUser::currentUser(), isAnonymous(), isLoggedIn(), hasAccessTo() and its accessWord yes, no or limited, object-level checks, and the user fetch functions.

Download as PDF

Address: https://doc.exponential.earth/exphelp/viewer/help/extension-development/part-8-reference/ezuser-and-access.md

On this page

eZUser and access checks

Part 8, reference 9. eZUser (kernel/classes/datatypes/ezuser/ezuser.php) is a user account. Every request has a current user; on a public page that is usually the anonymous user. Access is granted through roles and their policies (Sections, roles and access for builders), and an extension declares its own policy functions (Policy functions and access).

The current user

Method (static)Returns
eZUser::currentUser()the user of this request
eZUser::currentUserID()the ID
eZUser::fetch( $id, $asObject = true ), fetchByName( $login, ... ), fetchByEmail( $email, ... )other users
MethodReturns
isAnonymous()true for the anonymous user
isLoggedIn()true when signed in
contentObject()the user's content object (name, photo ...)
groups( $asObject = false )the user's groups
roles()the user's roles

hasAccessTo()

function hasAccessTo( $module, $function = false )

returns an array whose accessWord is one of:

accessWordMeaning
yesfull access
nono access
limitedaccess with limitations (sections, classes, subtrees ...), listed in policies
<?php
$user = eZUser::currentUser();
$access = $user->hasAccessTo( 'myext', 'manage' );
if ( $access['accessWord'] === 'no' )
{
    return $Module->handleError( eZError::KERNEL_ACCESS_DENIED, 'kernel' );
}

Run in a command line script as the anonymous user, hasAccessTo( 'content', 'read' ) returned limited and hasAccessTo( 'setup', 'setup' ) returned no.

For a policy function without limitations (most extension functions), treat anything but yes as no access unless your function declares limitations and you evaluate them.

Access to content

For content, use the object's and node's own checks, which evaluate all limitations:

MethodOn
canRead(), canEdit( ... ), checkAccess( $functionName, ... )eZContentObject
canRead(), canEdit(), canCreate(), canRemove()eZContentObjectTreeNode

subTreeByNodeID() and the content fetch functions apply read access themselves.

In templates

{if fetch( 'user', 'has_access_to', hash( 'module', 'myext', 'function', 'manage' ) )}
    <a href={'/myext/manage'|ezurl}>{'Manage'|i18n( 'extension/myext' )}</a>
{/if}

fetch( 'user', 'current_user' ) gives the current user. In admin menus, menu.ini [MenuAccessSettings] hides links a user cannot open (Context menus and admin integration).

Rules

  • Check access in the view, even if the link to it is hidden: anyone can type a URL.
  • Never compare user IDs or group names in code to grant access; grant it through a policy function, so administrators can assign it.
  • Signing a user in from code (eZUser::loginUser()) is for login handlers; an ordinary extension never does it.

Demo mode. eZUser::store() keeps the stored password of an administrator while EXP_DEMO_MODE=1; ask expDemoMode::protectsPassword( $user ) before changing a password so the user gets the reason. Demo mode for developers.

Become an Exponential Partner

Partners share their information, provide funding, contribute back and develop the products with us, and that is how Exponential grows. A partner website and dashboard are planned for mid-2027: please become a partner today to speed up our growth rate and land new features faster.

Something wrong on this page? Report an error

Documentation license

This documentation is free documentation, licensed under the GNU Free Documentation License 1.3 or later.

Exponential Copyright © 1998-2026 Exponential Foundation and 7x