Redirect to External URL
-
Hi. I’m trying to write a simple plugin to redirect a user to their home site on a multisite if they log in on a multisite. So basically if they go to mymultisite.com and login, I want them to be redirected to the multisite they registered to (their source domain) so like mysite.mymultisite.com.
This is what I have:
<?php add_filter( 'login_redirect', 'send_subscribers_home', 10, 3 ); function send_subscribers_home( $location, $request, $user ) { global $user; if ( isset( $user->roles ) && is_array( $user->roles ) ) { if ( in_array( 'customer', $user->roles ) ) { $user_ID = get_current_user_id(); $homeRedirect = get_user_meta($user_ID, 'source_domain'); $homeRedirectFinal = json_encode($homeRedirect); return $homeRedirectFinal; } else { return $redirect_to; } } return; } ?>
So basically I’m intercepting the login_redirect filter, checking if the user is in a certain group, and if so, grabbing the website they originally registered to (in this case it will be a subdomain) and redirecting that.
I’ve never written a WordPress plugin before. Anyways the problem is that this returns “www.mymultisite.com/www.mysite.mymultisite.com” as a web page, and obviously throws a 404. Does anyone know if I can change how WordPress parses this address (so it’s not as a page of the main site, but rather just an external URL) without modifying wp-login.php ?
Thanks.
- The topic ‘Redirect to External URL’ is closed to new replies.