$kirby->impersonate()
Become any existing user or disable the current user
Parameters
Name | Type | Default | Description |
---|---|---|---|
$who | string |null |
null |
User ID or email address,null to use the actual user again,'kirby' for a virtual admin user or'nobody' to disable the actual user |
$callback | Closure |null |
null |
Optional action function that will be run with the permissions of the impersonated user; the impersonation will be reset afterwards |
Return type
mixed
Exceptions
Type | Description |
---|---|
Throwable |
Parent class
$who
There are four options for the $who
parameter:
- a username (impersonates the specific user with their permissions)
'kirby'
(impersonates the allmighty user with full permissions)'nobody'
(disables the currently logged in user, added in Kirby 3.5.0)null
(resets the impersonation)
Example
The impersonation will be active for all code that runs in the current request after the call to $kirby->impersonate()
. If you want to limit the impact to a single operation, call the method with a callback (see below).
With callback
If you only want a single operation to run with different privileges, use a callback:
The impersonation automatically gets reset to the previous value after the callback returns.