In my plugin I try to login a user and redirect them to a specific page, but when I redirect the user, they are not logged in :-/
I have tried multiple variations of code that looks like this:
$wp_user = get_user_by( 'email', '[email protected]');
wp_clear_auth_cookie();
do_action('wp_login', $wp_user->user_login, $wp_user);
wp_set_current_user($wp_user->ID);
wp_set_auth_cookie($wp_user->ID, true);
$redirect_to = '/' . $redirectUrl;
if ( wp_safe_redirect($redirect_to ) ) {
exit;
}
How can I programmatically login the user and redirect them to a specific page?