uo-login-action-before-json-response
Fires before the JSON login response is sent, allowing modification of data or execution of custom actions with the user object.
add_action( 'uo-login-action-before-json-response', $callback, 10, 1 );
Description
Fires just before the JSON login response is sent to the client. Developers can use this hook to perform actions after user data is prepared but before the response is finalized and sent. The `$user` object is available for inspection. This hook is called before redirect URLs are sanitized.
Usage
add_action( 'uo-login-action-before-json-response', 'your_function_name', 10, 1 );
Parameters
-
$user(mixed) - This parameter contains the user object that was just logged in or whose login attempt just concluded.
Examples
<?php
/**
* Example of how to hook into 'uo-login-action-before-json-response'.
* This example logs the user ID before the JSON response is sent.
*
* @param WP_User|null $user The user object if logged in, null otherwise.
*/
add_action(
'uo-login-action-before-json-response',
function ( $user ) {
// Only proceed if a user object is available.
if ( $user instanceof WP_User ) {
// Log the user ID to the WordPress debug log.
// In a real-world scenario, you might send this information to an analytics service
// or perform other actions based on the logged-in user.
error_log( 'User logged in with ID: ' . $user->ID );
}
},
10, // Priority: 10 is the default
1 // Accepted args: The callback function accepts 1 argument ($user)
);
Placement
This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.
Source Code
src/classes/frontend-login-plus.php:3415
$response['user_id'] = $user->ID ?? null;
// Allow modifications.
$response = apply_filters( 'uo-login-action-response', $response );
// Allow actions to be perform.
do_action( 'uo-login-action-before-json-response', $user );
// Disable external websites redirect.
$response['redirectTo'] = self::sanitize_redirect_url( $response['redirectTo'] );
self::wp_send_json( $response, $response_code );
}