helpers.php
Authentication helper functions.
Provides convenient access to authentication functionality.
Table of Contents
Functions
- auth() : User|null
- Get the authenticated user
- user() : User|null
- Alias for auth()
- user_id() : int|null
- Get the authenticated user's ID
- is_logged_in() : bool
- Check if user is authenticated
- is_guest() : bool
- Check if user is a guest (not authenticated)
- is_admin() : bool
- Check if user is an admin
- is_editor() : bool
- Check if user is an editor
- is_author() : bool
- Check if user is an author
- has_role() : bool
- Check if user has a specific role
- csrf_token() : string
- Get the current CSRF token
- csrf_field() : string
- Generate a CSRF token hidden input field
- current_user_identifier() : string
- Get current user identifier for audit purposes
Functions
auth()
Get the authenticated user
auth() : User|null
Return values
User|nulluser()
Alias for auth()
user() : User|null
Return values
User|nulluser_id()
Get the authenticated user's ID
user_id() : int|null
Return values
int|nullis_logged_in()
Check if user is authenticated
is_logged_in() : bool
Return values
boolis_guest()
Check if user is a guest (not authenticated)
is_guest() : bool
Return values
boolis_admin()
Check if user is an admin
is_admin() : bool
Return values
boolis_editor()
Check if user is an editor
is_editor() : bool
Return values
boolis_author()
Check if user is an author
is_author() : bool
Return values
boolhas_role()
Check if user has a specific role
has_role(string $role) : bool
Parameters
- $role : string
Return values
boolcsrf_token()
Get the current CSRF token
csrf_token() : string
Return values
stringcsrf_field()
Generate a CSRF token hidden input field
csrf_field() : string
Return values
stringcurrent_user_identifier()
Get current user identifier for audit purposes
current_user_identifier() : string
Returns the authenticated CMS user's username if available (web context), otherwise returns the OS user running the process (CLI context).
Return values
string —User identifier (e.g., "admin" or "www-data" or "system")