Skip to main content

Hooks

This plugin allows advanced users to link some hooks with the plugin and perform some custom scripts.

You are able to enable/disable any of these hooks.

note

By default, no hooks are enabled. You need to check the one that you want to use.

List Of Hooks

1. simple_jwt_login_login_hook

  • type: action
  • parameters: Wp_User $user
  • description: This hook it is called after the user has been logged in.

2. simple_jwt_login_redirect_hook

  • type: action
  • parameters: string $url, array $request
  • description: This hook it is called before the user it will be redirected to the page he specified in the login section.

3. simple_jwt_login_register_hook

  • type: action
  • parameters: Wp_User $user, string $plain_text_password
  • description: This hook it is called after a new user has been created.

4. simple_jwt_login_delete_user_hook

  • type: action
  • parameters: Wp_User $user
  • description: This hook it is called right after the user has been deleted.

5. simple_jwt_login_jwt_payload_auth

  • type: filter
  • parameters: array $payload, array $request
  • return: array $payload
  • description: This hook is called on /auth endpoint. Here you can modify payload parameters.

6. simple_jwt_login_no_redirect_message

  • type: filter
  • parameters: array $payload, array $request
  • return: array $payload
  • description: This hook is called on /autologin endpoint when the option No Redirect is selected. You can customize the message and add parameters.

7. simple_jwt_login_reset_password_custom_email_template

  • type: filter
  • parameters: string $template, array $request
  • return: string $template
  • description: This is executed when POST /user/reset_password is called. It will replace the email template that has been added in Reset Password settings.

8. simple_jwt_login_response_auth_user

  • type: filter
  • parameters: array $response, WP_User $user
  • return: array $response
  • description: This is executed before displaying the response of auth endpoint.

9. simple_jwt_login_response_delete_user

  • type: filter
  • parameters: array $response, WP_User $user
  • return: array $response
  • description: This is executed before displaying the response of delete user endpoint.

10. simple_jwt_login_response_refresh_token

  • type: filter
  • parameters: array $response, WP_User $user
  • return: array $response
  • description: This is executed before displaying the response of refresh token endpoint.

11. simple_jwt_login_response_register_user

  • type: filter
  • parameters: array $response, WP_User $user
  • return: array $response
  • description: This is executed before displaying the response of register user endpoint.

12. simple_jwt_login_response_send_reset_password

  • type: filter
  • parameters: array $response, WP_User $user
  • return: array $response
  • description: This is executed before displaying the response of send reset password endpoint.

13. simple_jwt_login_response_change_user_password

  • type: filter
  • parameters: array $response, WP_User $user
  • return: array $response
  • description: This is executed before displaying the response of change user password endpoint.

13. simple_jwt_login_response_revoke_token

  • type: filter
  • parameters: array $response, WP_User $user
  • return: array $response
  • description: This is executed before displaying the response of revoke token endpoint.

14. simple_jwt_login_response_validate_token

  • type: filter
  • parameters: array $response, WP_User $user
  • return: array $response
  • description: This is executed before displaying the response of validate token endpoint.

Screenshot

Code Examples

Send an email after a new user has been created.

add_action( 'simple_jwt_login_register_hook', function($user, $password){
$to = $user->user_email;
$subject = 'Welcome';
$message = '
Welcome to My Site. Your new user credentials are:
email: ' . $to .'
password: '. $password;
wp_mail($to, $subject, $message);
}, 10, 2);

Add some custom data in the JWT payload on the /auth endpoint

add_filter('simple_jwt_login_no_redirect_message',function($payload, $request){
$payload['myvalue'] = 'somevalue';

return $payload;
},10, 2);

Dynamic Redirection URLs After Login

In order to achieve this, you need to check the option Include request parameters used for login link in the REDIRECT URL from the Login section. After that, in your login URL, add one new parameter &page=your_page

add_action('simple_jwt_login_redirect_hook', function($url, $request){
$page = isset($_REQUEST['page'])
? $_REQUEST['page']
: null;
if($page === null){
wp_redirect($url);
return;
}
switch($page){
case "page1":
wp_redirect('https://site1.com');
break;
case "page2":
wp_redirect('https://site2.com');
break;
}
},10,2);