Contensio logo

User & Auth lifecycle hooks

Action and filter hooks fired on account registration, login, logout, profile updates, and deletion.

Since 1.5.0

These hooks fire at key points in the user account lifecycle. They cover both the admin user manager (/account/users) and self-service profile pages (/account/profile), so every user-creation or user-deletion path fires the same hook regardless of origin.


contensio/user/registered

Type: Action
Since: 1.5.0
Source: RegisterController::register, UserController::store

Fired after a new user account has been created and any default role assigned. Fires regardless of whether the account was created by the user themselves (registration form) or by an administrator.

Arguments

# Name Type Description
1 $user User The newly created user model.

Example

use App\Models\User;

add_action('contensio/user/registered', function (User $user) {
    // Send a welcome email
    Mail::to($user->email)->send(new WelcomeMail($user));
});

Notes

  • For admin-created users the account is active immediately. For self-registered users, $user->is_active may be false if require_approval is enabled.
  • Fires after the DB write and role sync.

contensio/user/login

Type: Action
Since: 1.5.0
Source: LoginController::login

Fired after a successful password-based login and session regeneration. Does not fire for two-factor challenge completions (Fortify handles those).

Arguments

# Name Type Description
1 $user User The authenticated user.

Example

use App\Models\User;

add_action('contensio/user/login', function (User $user) {
    // Record last-seen IP for fraud detection
    $user->update(['last_login_ip' => request()->ip()]);
});

contensio/user/logout

Type: Action
Since: 1.5.0
Source: LoginController::logout

Fired before Auth::logout() is called, so the user model is still fully accessible. This is intentional — once the session is invalidated auth()->user() returns null.

Arguments

# Name Type Description
1 $user User The user who is logging out.

Example

use App\Models\User;

add_action('contensio/user/logout', function (User $user) {
    // Clean up a custom presence table
    DB::table('online_users')->where('user_id', $user->id)->delete();
});

Notes

  • Fires before session invalidation. Do not attempt to read or write session data inside this callback.

contensio/user/updated

Type: Action
Since: 1.5.0
Source: ProfileController::update, UserController::update

Fired after a user's profile has been saved. Covers both self-service edits (name, email, username, bio) and admin edits (name, email, password, roles).

Arguments

# Name Type Description
1 $user User The updated user model (fresh from the database).

Example

use App\Models\User;

add_action('contensio/user/updated', function (User $user) {
    // Sync display name to a connected CRM
    Crm::updateContact($user->email, ['name' => $user->name]);
});

contensio/user/deleted

Type: Action
Since: 1.5.0
Source: ProfileController::destroy, UserController::destroy

Fired after a user account is deleted. The user row no longer exists in the database when this hook fires, so only the ID is passed.

Arguments

# Name Type Description
1 $id int The ID of the deleted user.

Example

add_action('contensio/user/deleted', function (int $id) {
    // Remove related records from a custom plugin table
    DB::table('plugin_user_meta')->where('user_id', $id)->delete();
});

Notes

  • Administrator accounts cannot be self-deleted; this hook only fires for non-admin accounts when triggered from the profile, and for any non-last-admin when triggered from the user manager.
  • Content authored by the deleted user is not automatically removed — handle that here if needed.

contensio/user/register-data

Type: Filter
Since: 1.5.0
Source: RegisterController::register

Allows plugins to modify the data array passed to User::create() during self-service registration. Use this to inject additional columns, override defaults, or conditionally flag accounts.

Arguments

# Name Type Description
1 $data array The registration data array (see default shape below).

Default $data shape

[
    'name'              => string,
    'username'          => string,
    'email'             => string,
    'password'          => string,   // already hashed
    'code'              => string,   // random 16-char token
    'is_active'         => bool,
    'email_verified_at' => Carbon|null,
]

Example

add_filter('contensio/user/register-data', function (array $data) {
    // Set a default timezone from the user's locale
    $data['timezone'] = app()->getLocale() === 'en' ? 'UTC' : 'Europe/Bucharest';
    return $data;
});

Notes

  • You must return the $data array, even if you make no changes.
  • The password field is already hashed — do not hash it again.
  • This filter does not fire for admin-created users (UserController::store). Admin creation is intentionally direct.