uo-login-action-response
Filters the response data after a user login action, allowing for modifications before it's returned.
add_filter( 'uo-login-action-response', $callback, 10, 1 );
Description
This filter hook allows developers to modify the response array after a user login action. Developers can alter the redirect URL, user ID, or any other response data before it's returned to the frontend. The hook fires after the core login redirect logic and before the JSON response is sent.
Usage
add_filter( 'uo-login-action-response', 'your_function_name', 10, 1 );
Parameters
-
$response(mixed) - This parameter holds an array containing the login action's response data, including the user ID and any redirection information.
Return Value
The filtered value.
Examples
<?php
/**
* Example of using the 'uo-login-action-response' filter to modify the login redirect URL.
*
* This example checks if the user is trying to redirect to a specific admin page
* after login and modifies the redirect URL accordingly.
*
* @param array $response The current response array, which may contain a 'redirectTo' key.
* @return array The modified response array.
*/
add_filter( 'uo-login-action-response', function( $response ) {
// Check if a redirect URL is set in the response and if it's a specific admin page.
if ( isset( $response['redirectTo'] ) && strpos( $response['redirectTo'], 'admin.php?page=my-custom-dashboard' ) !== false ) {
// Modify the redirect URL to a different page for this specific scenario.
// In a real-world scenario, you might dynamically determine this based on user roles or other factors.
$response['redirectTo'] = admin_url( 'admin.php?page=my-welcome-page' );
}
// You can also add or modify other parts of the response array here if needed.
// For instance, adding a custom message:
// $response['message'] = 'Welcome back! You have successfully logged in.';
return $response;
}, 10, 1 ); // Priority 10, accepts 1 argument.
?>
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:3412
} else {
$response['redirectTo'] = apply_filters( 'login_redirect', $redirect_to, $requested_redirect_to, $user );
}
$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'] );