Skip to main content
Version: 4.x

WordPress JWT Hooks and Filters

Simple JWT Login exposes 39 WordPress action and filter hooks that let you extend or customize the plugin's behavior without modifying its source code. Use them to enrich JWT payloads, send notifications, apply business logic, gate requests, or build fully custom flows on top of the plugin.

The hooks come in two groups, and each group is switched on in a different place:

  • 19 general hooks (the Quick Reference table) - enable each one in Settings → Simple JWT Login → Hooks.
  • 20 audit hooks (see Audit Hooks) - they fire when audit logging is enabled and the matching event is selected.
Enable hooks first

All hooks are disabled by default. A hook that isn't enabled never fires, even if your code calls add_action() or add_filter() for it.

Quick Reference​

HookTypeTriggered
simple_jwt_login_before_endpointactionBefore any endpoint is processed
simple_jwt_login_login_hookactionAfter a user logs in
simple_jwt_login_redirect_hookactionBefore the post-login redirect
simple_jwt_login_register_hookactionAfter a new user is created
simple_jwt_login_delete_user_hookactionAfter a user is deleted
simple_jwt_login_jwt_payload_authfilterBefore the JWT is signed on /auth
simple_jwt_login_no_redirect_messagefilterBefore the no-redirect response on /autologin
simple_jwt_login_reset_password_custom_email_templatefilterBefore the reset-password email is sent
simple_jwt_login_response_auth_userfilterBefore the /auth response is returned
simple_jwt_login_response_register_userfilterBefore the register response is returned
simple_jwt_login_response_delete_userfilterBefore the delete-user response is returned
simple_jwt_login_response_refresh_tokenfilterBefore the refresh-token response is returned
simple_jwt_login_response_send_reset_passwordfilterBefore the send-reset-password response is returned
simple_jwt_login_response_change_user_passwordfilterBefore the change-password response is returned
simple_jwt_login_response_revoke_tokenfilterBefore the revoke-token response is returned
simple_jwt_login_response_validate_tokenfilterBefore the validate-token response is returned
simple_jwt_login_generate_payloadfilterBefore a JWT payload is generated (any endpoint)
simple_jwt_login_response_2fa_challengefilterBefore the 2FA challenge response is returned
simple_jwt_login_response_2fa_verifyfilterBefore the 2FA verify response is returned

Action Hooks​

Action hooks let you run side-effect code at a specific point in the request lifecycle. They do not return a value.

simple_jwt_login_before_endpoint​

Fires before a Simple JWT Login REST route is processed. Use it to validate requests, block specific callers, enforce policies (for example, minimum password length), or log activity - for any endpoint.

ParameterTypeDescription
$methodstringHTTP method (GET, POST, …)
$endpointstringEndpoint name (auth, users, …)
$requestarrayFull request parameters

Throw an Exception to abort the request with an error response.


simple_jwt_login_login_hook​

Fires after a user has been successfully authenticated and logged in.

ParameterTypeDescription
$userWP_UserThe authenticated user

simple_jwt_login_redirect_hook​

Fires before the user is redirected to the URL configured in the Login settings. Use it to implement dynamic redirect logic based on request parameters.

ParameterTypeDescription
$urlstringThe configured redirect URL
$requestarrayFull request parameters
tip

Enable "Include request parameters in the redirect URL" in Login settings to forward custom query parameters (for example, &page=dashboard) that your hook can read.


simple_jwt_login_register_hook​

Fires after a new user has been created via the register endpoint.

ParameterTypeDescription
$userWP_UserThe newly created user
$plain_text_passwordstringThe user's plain-text password (available only at creation time)

simple_jwt_login_delete_user_hook​

Fires immediately after a user has been deleted.

ParameterTypeDescription
$userWP_UserThe deleted user

Filter Hooks​

Filter hooks let you inspect and modify data before it is used or returned. Always return the (modified) value.

simple_jwt_login_jwt_payload_auth​

Fires on the /auth endpoint before the JWT is signed. Use it to add custom claims to the token.

ParameterTypeDescription
$payloadarrayThe JWT payload (modify and return)
$requestarrayFull request parameters

Returns: array - the modified payload.


simple_jwt_login_no_redirect_message​

Fires on the /autologin endpoint when No Redirect is selected. Use it to customize the JSON response returned to the client.

ParameterTypeDescription
$payloadarrayThe response payload (modify and return)
$requestarrayFull request parameters

Returns: array - the modified response payload.


simple_jwt_login_reset_password_custom_email_template​

Fires when POST /user/reset_password is called. Use it to replace the default email template set in Reset Password settings with a fully custom HTML email.

ParameterTypeDescription
$templatestringThe current email template
$requestarrayFull request parameters

Returns: string - the custom email template.


Response Filters​

The following 8 filters fire immediately before their respective endpoint returns a JSON response. Use them to add, remove, or transform fields in the API response.

simple_jwt_login_response_auth_user​

Fires before the POST /auth response is returned.

ParameterTypeDescription
$responsearrayThe response data (modify and return)
$userWP_UserThe user associated with the request

Returns: array - the modified response.


simple_jwt_login_response_register_user​

Fires before the POST /users (register) response is returned.

ParameterTypeDescription
$responsearrayThe response data (modify and return)
$userWP_UserThe user associated with the request

Returns: array - the modified response.


simple_jwt_login_response_delete_user​

Fires before the DELETE /users response is returned.

ParameterTypeDescription
$responsearrayThe response data (modify and return)
$userWP_UserThe user associated with the request

Returns: array - the modified response.


simple_jwt_login_response_refresh_token​

Fires before the POST /auth/refresh response is returned.

ParameterTypeDescription
$responsearrayThe response data (modify and return)
$userWP_UserThe user associated with the request

Returns: array - the modified response.


simple_jwt_login_response_send_reset_password​

Fires before the POST /user/reset_password response is returned.

caution

Since version 4.2.0, this filter runs only for emails that belong to a user. If it changes the response or adds a delay, callers can tell which emails have an account.

ParameterTypeDescription
$responsearrayThe response data (modify and return)
$userWP_UserThe user associated with the request

Returns: array - the modified response.


simple_jwt_login_response_change_user_password​

Fires before the PUT /user/reset_password response is returned.

ParameterTypeDescription
$responsearrayThe response data (modify and return)
$userWP_UserThe user associated with the request

Returns: array - the modified response.


simple_jwt_login_response_revoke_token​

Fires before the DELETE /auth response is returned.

ParameterTypeDescription
$responsearrayThe response data (modify and return)
$userWP_UserThe user associated with the request

Returns: array - the modified response.


simple_jwt_login_response_validate_token​

Fires before the GET /auth/validate response is returned.

ParameterTypeDescription
$responsearrayThe response data (modify and return)
$userWP_UserThe user associated with the request

Returns: array - the modified response.


simple_jwt_login_generate_payload​

Fires before the JWT payload is generated on any endpoint (not just /auth). Use it to append extra claims to every JWT issued by the plugin, regardless of which endpoint generates the token.

ParameterTypeDescription
$payloadarrayThe JWT payload (modify and return)
$userWP_UserThe user for whom the token is being generated

Returns: array - the modified payload.


2FA Hooks​

These filters work with the Two-Factor Authentication integration. Enable Two-Factor in Settings → Integrations → Third Party → Two-Factor, then enable each filter in Settings → Simple JWT Login → Hooks.

simple_jwt_login_response_2fa_challenge​

Fires before POST /auth returns the interim 2FA token (instead of a JWT) for a user who has two-factor authentication set up. Use it to add extra fields or transform the response.

ParameterTypeDescription
$responsearrayThe response data (modify and return)
$userWP_UserThe user associated with the request

Returns: array - the modified response.


simple_jwt_login_response_2fa_verify​

Fires before the POST /auth/2fa response is returned.

ParameterTypeDescription
$responsearrayThe response data (modify and return)
$userWP_UserThe user associated with the request

Returns: array - the modified response.


Audit Hooks​

Audit hooks are actions that fire for each audit log event. They are not listed in the Hooks settings. Instead, a hook fires only when Enable Audit Logging is on and its event is selected under Settings → Simple JWT Login → Audit Logs → Config. Use them to send authentication events to your own monitoring or alerting system.

All audit hooks receive the same arguments:

ParameterTypeDescription
$userIdint or nullWordPress user ID, or null when the user is unknown
$userEmailstring or nullUser's email address (on failures, the email that was attempted), or null when unknown
$messagestringFailure reason. Passed to *_failed hooks only
HookAudit eventFires when
simple_jwt_login_audit_auth_login_successauth.login.success/auth issues a JWT
simple_jwt_login_audit_auth_login_failedauth.login.failed/auth rejects the credentials
simple_jwt_login_audit_auth_logout_successauth.logout.success/auth/revoke revokes a JWT
simple_jwt_login_audit_auth_logout_failedauth.logout.failed/auth/revoke fails
simple_jwt_login_audit_auth_register_successauth.register.success/users creates a user
simple_jwt_login_audit_auth_register_failedauth.register.failed/users fails to create a user
simple_jwt_login_audit_password_reset_requestauth.password_reset.requestA password reset code is requested
simple_jwt_login_audit_password_reset_successauth.password_reset.successA password is changed
simple_jwt_login_audit_password_reset_failedauth.password_reset.failedA password reset or change fails
simple_jwt_login_audit_delete_user_successauth.delete_user.successDELETE /users deletes a user
simple_jwt_login_audit_delete_user_failedauth.delete_user.failedDELETE /users fails
simple_jwt_login_audit_login_session_successauth.login_session.success/autologin logs a user in
simple_jwt_login_audit_login_session_failedauth.login_session.failed/autologin fails
simple_jwt_login_audit_refresh_token_successauth.refresh_token.success/auth/refresh issues a new JWT
simple_jwt_login_audit_refresh_token_failedauth.refresh_token.failed/auth/refresh fails
simple_jwt_login_audit_oauth_successauth.oauth.successAn OAuth login succeeds
simple_jwt_login_audit_oauth_failedauth.oauth.failedAn OAuth login fails
simple_jwt_login_audit_2fa_challenge_issuedauth.2fa.challenge_issuedA 2FA challenge is issued
simple_jwt_login_audit_2fa_verify_successauth.2fa.verify_successA 2FA code is verified
simple_jwt_login_audit_2fa_verify_failedauth.2fa.verify_failedA 2FA verification fails
add_action('simple_jwt_login_audit_auth_login_failed', function ($userId, $userEmail, $message) {
error_log(sprintf('JWT login failed for %s: %s', $userEmail ?? 'unknown', $message));
}, 10, 3);

simple_jwt_login_audit_2fa_challenge_issued​

Fires when a two-factor authentication challenge has been issued (that is, after the user submits valid credentials and an interim JWT is returned, triggering a 2FA code delivery).

ParameterTypeDescription
$userIdintWordPress user ID
$userEmailstringUser's email address

simple_jwt_login_audit_2fa_verify_success​

Fires after a successful two-factor authentication verification.

ParameterTypeDescription
$userIdintWordPress user ID
$userEmailstringUser's email address

simple_jwt_login_audit_2fa_verify_failed​

Fires when a two-factor authentication verification attempt fails.

ParameterTypeDescription
$userIdintWordPress user ID
$userEmailstringUser's email address
$messagestringHuman-readable failure reason

Settings Screenshot​

Hooks settings panel


Code Examples​

Add custom claims to the JWT payload​

Enrich the token with user metadata (roles, plan, tenant ID) so downstream services don't need a separate lookup.

add_filter('simple_jwt_login_jwt_payload_auth', function (array $payload, array $request): array {
$user = get_user_by('email', $request['email'] ?? '');
if ($user) {
$payload['roles'] = $user->roles;
$payload['display_name'] = $user->display_name;
}
return $payload;
}, 10, 2);

Send a welcome email after registration​

add_action('simple_jwt_login_register_hook', function (WP_User $user, string $password): void {
wp_mail(
$user->user_email,
'Welcome to My Site',
sprintf(
"Hi %s,\n\nYour account is ready.\n\nEmail: %s\nPassword: %s",
$user->display_name,
$user->user_email,
$password
)
);
}, 10, 2);

Dynamic redirect URLs after login​

Enable "Include request parameters in the redirect URL" in Login settings, then add &page=dashboard (or any value) to the login URL. The hook reads it and redirects accordingly.

add_action('simple_jwt_login_redirect_hook', function (string $url, array $request): void {
$page = $request['page'] ?? null;

$destinations = [
'dashboard' => 'https://mysite.com/dashboard',
'profile' => 'https://mysite.com/profile',
];

wp_redirect($destinations[$page] ?? $url);
}, 10, 2);

Block a specific email address on /auth​

add_action('simple_jwt_login_before_endpoint', function (string $method, string $endpoint, array $request): void {
if ($method !== 'POST' || $endpoint !== 'auth') {
return;
}

$blocked = ['[email protected]'];

if (in_array($request['email'] ?? '', $blocked, true)) {
throw new Exception('This account has been suspended.');
}
}, 10, 3);

Enforce a minimum password length on registration​

add_action('simple_jwt_login_before_endpoint', function (string $method, string $endpoint, array $request): void {
if ($method !== 'POST' || $endpoint !== 'users') {
return;
}

$minLength = 8;
$password = $request['password'] ?? '';

if (strlen($password) < $minLength) {
throw new Exception("Password must be at least {$minLength} characters.");
}
}, 10, 3);

Add extra fields to the auth response​

add_filter('simple_jwt_login_response_auth_user', function (array $response, WP_User $user): array {
$response['user_id'] = $user->ID;
$response['display_name'] = $user->display_name;
$response['avatar_url'] = get_avatar_url($user->ID);
return $response;
}, 10, 2);

Next steps​