Filter uncanny-automator-pro

uap_auto_login_link_success_redirect

Filters the redirect URL after a successful auto-login attempt by a user.

add_filter( 'uap_auto_login_link_success_redirect', $callback, 10, 2 );

Description

Filters the redirect URL after a successful auto-login link is generated by Uncanny Automator Pro. Developers can modify the destination URL by hooking into this filter, allowing custom redirects after the user is automatically logged in. The original redirect URL and the user object are passed for conditional logic.


Usage

add_filter( 'uap_auto_login_link_success_redirect', 'your_function_name', 10, 2 );

Parameters

$url (mixed)
This parameter contains the URL that the user will be redirected to after a successful auto-login.
$user (mixed)
This parameter is the URL where the user will be redirected after a successful auto-login.

Return Value

The filtered value.


Examples

<?php

/**
 * Modify the redirect URL after a successful auto-login.
 *
 * This example appends a UTM parameter to the redirect URL if the user
 * is a subscriber.
 *
 * @param string $url  The current redirect URL.
 * @param WP_User $user The WP_User object of the logged-in user.
 * @return string The modified redirect URL.
 */
add_filter( 'uap_auto_login_link_success_redirect', function( $url, $user ) {

	// Check if the user has the 'subscriber' role.
	if ( in_array( 'subscriber', $user->roles ) ) {

		// Append a UTM parameter to the URL.
		$url = add_query_arg( 'utm_source', 'autologin_success', $url );

	}

	return $url;

}, 10, 2 );

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

uncanny-automator-pro/src/integrations/advanced/tokens/autologin-link-token.php:194

private function log_in_and_redirect( $user ) {

		wp_clear_auth_cookie();
		wp_set_current_user( $user->ID );
		wp_set_auth_cookie( $user->ID );

		do_action( 'uap_auto_login_link_success' );

		$url = admin_url( 'profile.php' );

		if ( automator_filter_has_var( 'redirect_to' ) ) {
			$url = automator_filter_input( 'redirect_to' );
		} 

		wp_safe_redirect( apply_filters( 'uap_auto_login_link_success_redirect', $url, $user ) );
		
		exit();
	}


Scroll to Top