简体   繁体   中英

Two login forms require seperate redirects

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM