Two login forms require seperate redirects

64 views Asked by At

I have two login forms for my Wordpress Multisite site, one for logging into the web version of the app and another for logging into the mobile version of the app. The problem is that I need to redirect the different forms, after user login, to different urls.

I currently have a plugin that contains the code below that effectively redirects users who are using the web based login form:

function web_login_redirect( $redirect_to, $request_redirect_to, $user ) 
{    
        if ($user->primary_blog) {
            $url = example.com/web_app;
            wp_redirect($url);
            die();
        }

        return $redirect_to;
}
add_filter('login_redirect','web_login_redirect', 100, 3);

I now need to redirect my app login to a different page, for example - example.com/app. What is the best process to do this, can this easily be built into the above function?

1

There are 1 answers

4
Purvik Dhorajiya On

You can use wp_is_mobile(); functions.

This Conditional Tag checks if the user is visiting using a mobile device. This is a boolean function, meaning it returns either TRUE or FALSE. Works through the detection of the browser user agent string ($_SERVER['HTTP_USER_AGENT'])

function web_login_redirect( $redirect_to, $request_redirect_to, $user ) 
{    
        if ($user->primary_blog) {
            if ( wp_is_mobile() ) {
                $url = example.com/web_app;
            }else{
                $url = example.com;
            }            
            wp_redirect($url);
            die();
        }

        return $redirect_to;
}
add_filter('login_redirect','web_login_redirect', 100, 3);

Would you please try above code? I think It's helpful for you.