uo_frontend_login_modal_ignore_redirect
Filters whether the frontend login modal should ignore redirects after a successful login.
add_filter( 'uo_frontend_login_modal_ignore_redirect', $callback, 10, 4 );
Description
This filter allows developers to programmatically control whether the frontend login modal ignores the `redirect_to` parameter. Modify the `$redirect_ignored` boolean to override the default setting and force or prevent redirects after a successful login. This is applied just before the login response is determined.
Usage
add_filter( 'uo_frontend_login_modal_ignore_redirect', 'your_function_name', 10, 4 );
Parameters
-
$redirect_ignored(mixed) - This parameter indicates whether the redirect functionality should be ignored when the login modal is used.
-
$redirect_to(mixed) - This parameter indicates whether the redirect should be ignored, typically controlled by a plugin setting.
-
$requested_redirect_to(mixed) - This parameter specifies the intended redirect URL after a successful login.
-
$user(mixed) - This parameter holds the value of the 'redirect_to' parameter from the request, which specifies where the user should be redirected after login.
Return Value
The filtered value.
Examples
<?php
/**
* Prevent redirect when logging in via a modal if the user is already logged in.
*
* @param mixed $redirect_ignored Whether the redirect should be ignored.
* @param mixed $redirect_to The intended redirect URL.
* @param mixed $requested_redirect_to The redirect URL requested by the user.
* @param WP_User|null $user The current WP_User object, or null if not logged in.
* @return mixed The modified $redirect_ignored value.
*/
add_filter( 'uo_frontend_login_modal_ignore_redirect', function( $redirect_ignored, $redirect_to, $requested_redirect_to, $user ) {
// If the user is already logged in and attempting to log in via a modal,
// ignore any redirect to prevent them from being taken away from the current page.
if ( is_user_logged_in() && isset( $_REQUEST['uo_is_login_modal'] ) && 1 === (int) $_REQUEST['uo_is_login_modal'] ) {
return 'on'; // Force ignore redirect
}
// Otherwise, respect the existing setting or default behavior.
return $redirect_ignored;
}, 10, 4 );
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:3396
$response['success'] = true;
$requested_redirect_to = isset( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : '';
// Decide if there will be a redirect
$redirect_ignored = Config::get_settings_value( 'uo_frontend_login_modal_ignore_redirect', 'FrontendLoginPlus', false );
$redirect_ignored = apply_filters( 'uo_frontend_login_modal_ignore_redirect', $redirect_ignored, $redirect_to, $requested_redirect_to, $user );
$uo_login_modal = false;
if ( isset( $_REQUEST['uo_is_login_modal'] ) && 1 === (int) $_REQUEST['uo_is_login_modal'] ) {
$uo_login_modal = true;
}
if ( 'on' === $redirect_ignored && true === $uo_login_modal ) {
$response['ignoredRedirectTo'] = true;