Panel Staff and Privilege Hooks
The ten hooks over staff accounts, privilege groups, departments and panel settings.
Overview
Everything about who uses the panel lives here: staff accounts, privilege groups, support departments and an administrator’s own preferences.
These hooks share one pattern: what you receive is not the whole record but the fields that changed. When nothing changed the array is empty.
Reference
Following a staff record being updated
Runs after an administrator account is updated.
Hook::add('action:admin.staff_updated', 10, function ($id, $data, $info) {
// The arrays hold what CHANGED, not the whole record.
if (isset($data['privilege'])) Acme::auditPrivilegeChange($id, $data['privilege']);
});Following a staff member being removed
Runs after an administrator account is deleted.
Hook::add('action:admin.staff_deleted', 10, function ($id) {
// No record is passed: keep what you need beforehand.
Acme::revokeAllTokens($id);
});Following two-step verification being switched off
Runs after two-step verification is switched off for an administrator. It is a weakening of security and is usually done by somebody else.
Hook::add('action:admin.staff_authentication_disabled', 10, function ($id, $method) {
// Security just weakened: do not stay quiet.
Acme::alertSecurityTeam($id, $method);
});Following a privilege group being saved
Runs when a privilege group is created or edited.
add or edit.Hook::add('action:admin.privilege_saved', 10, function ($id, $type, $name, $perms) {
// Tell a new record from the operation TYPE, not the id.
if ($type === 'add') Acme::noteNewRole($name, explode(',', $perms));
});Following an administrator updating their own profile
Runs when an administrator updates their own profile.
Hook::add('action:admin.profile_updated', 10,
function ($admin_id, $data_updates, $info_updates) {
if (isset($data_updates['email'])) Acme::alertEmailChange($admin_id);
});Following panel preferences changing
Runs when an administrator changes how the panel looks for them.
Hook::add('action:admin.preferences_updated', 10,
function ($admin_id, $info_sets, $data_sets) {
if (isset($data_sets['lang'])) Acme::syncLocale($admin_id, $data_sets['lang']);
});Following a department being saved
Runs when a support department is created or edited.
add or edit.Hook::add('action:admin.department_saved', 10, function ($id, $type, $set_data) {
// Here the id is correct on the create path as well.
Acme::syncDepartment($id, $set_data);
});Following a department being deleted
Runs after a support department is deleted.
Hook::add('action:admin.department_deleted', 10, function ($id, $detail) {
Acme::dropDepartmentRoute($id);
});Following logs being cleared
Runs when an administrator clears a log type. What is deleted does not come back.
Hook::add('action:admin.logs_cleared', 10, function ($type, $date) {
// What is gone stays gone: note it in your own archive.
Acme::noteRetention($type, $date);
});Following notification settings being saved
Runs when the engine used for notification templates changes. That setting decides how every notification is produced.
Hook::add('action:admin.notification_settings_saved', 10, function ($engine, $admin_id) {
// Every notification is produced through this setting.
Acme::notifyOps('notification engine: ' . $engine);
});Pitfalls
On the create path the id in the privilege hook is not the id of the new record and may be zero. Tell a new record from the operation type. The department hook does not share this flaw; there the id is right on both paths.
The arrays in the staff, profile and preference hooks hold only the fields that changed. A field being absent does not mean "removed", it means "untouched". Read the record separately if you need its current state.
Related Articles
Vielen Dank für Ihre Rückmeldung!
Unser Support-Team ist rund um die Uhr für Sie da, wenn Sie oben nicht fündig werden.