Multisite global login that redirects to correct subsite

Hi everyone. I am about to create a new wordpress membership site with s2member and was hoping to receive some feedback on what my options are before setting it up.

My goal is to create several different courses under one domain/website and have the users automatically redirected to their respective course (subsite) once they login from the main site (homesite). The courses will vary a bit depending on the location of the user.

I was thinking of setting it up the courses under wordpress multisite subsites. So my big question is if there are is a way to have to have the users login through the main site and automatically get redirected to their course (subsite).

Any ideas or advice?

Cheers

After doing some additional research, I guess I would have to add some “Special Redirection URL — Dynamic Login Welcome Page”. So the questions becomes, is there a way to make make the url the welcome page of the subsite the user belongs to?

I am just wondering why you want to do this using multisite and not by using a regular WP setup.

Hi Tim.

The thinking is that it would be the easiest way to separate the different courses and make to sure that user is logged in to the correct course immediately. I am open to other suggestions!

Edit: The courses are actually the same course but translated in different languages.

If you hadn’t added the bit about being in different languages, I would have strongly recommended that you just use a regular WP setup. You probably wouldn’t even need a Special Redirection URL for the Login Welcome Page because the LWP automatically recognizes who each person is anyway.

I don’t know whether using different languages makes a multisite setup better because I just don’t know enough about how a multi-language site works.

Hi Tim, what did you mean by “the LWP automatically recognizes who each person is anyway”?

Is there a way to add custom"login welcome pages" (custom url) depending on a value I can set during the registration process? If that’s the case that would solve my problem!

Thanks,

Lily

Lily,

What I meant by “the LWP automatically recognizes who each person is anyway” is that, if you have content that you only want to show to one person or a specific group of people, you can do that on the LWP because it recognizes who the current user is.

So you could, for example, add some code to the page that lists all the courses to which the user is subscribed, and it will show the right courses to the right users. This is very useful because it avoids having to create a separate LWP for each user.

Yes. You could use membership roles, levels, or custom capabilities (ccaps) for that. Take a look at the Replacement Codes below the box in Login Welcome Page -> Or, a Special Redirection URL

Yep, I have checked out the replacement codes but I am a bit confused how I could use them to to redirect to a custom lwp.

For example, in the profile registration field, I could add the option country_code and use the [s2Get user_field=“country_code” /] code to get the field but how do I use that info to redirect the user to a custom lwp?

Unfortunately showing them a list of their subscribed courses, or their user account doesn’t work for me, they need to able to login immediately to their respective course.

Thanks for taking the time to give me your feedback!

You would need to create a page for each country so that the URL generated by the special redirection code took the user to the right page.

Alternatively, you could just use a regular WP redirection to get what you are looking for. You’d still create a custom page for each country, but then you’d add a function to either your (child) theme’s functions.php file or as an mu-plugin. I have done this on some sites where I autogenerate a page (of a particular custom post type) when a new member is created, so this code won’t work for you out of the box, but it might give you some ideas:

function redirect_to_custom_lwp() {
	if ( !is_page( S2MEMBER_LOGIN_WELCOME_PAGE_ID ) ) {
		return; // nothing to do if no initial attempt to go to Login Welcome Page
	}
	$current_user = wp_get_current_user();
	$username = $current_user->user_login;

	if ( current_user_is( 's2member_level2' ) ) {
		$page = get_page_by_path( $username, OBJECT, 'custom_post_type_2' );
		if ( isset( $page ) ) {
			$redirect = get_permalink( $page );
			wp_redirect( $redirect );
			exit;
		}
	}	
	if ( current_user_is( 's2member_level1' ) ) {
		$page = get_page_by_path( $username, OBJECT, 'custom_post_type_1' );
		if ( isset( $page ) ) {
			$redirect = get_permalink( $page );
			wp_redirect( $redirect );
			exit;
		}
	}
}
add_action( 'template_redirect', 'redirect_to_custom_lwp' );

I would only have four different languages so I assume that means 4 custom lwp and then English for the rest. This looks like a good solution for a single installation but the coding part might be a more than I can chew haha.

That’s why the multisite login to a subsite route might be the easier option.

Thanks for the code, I’ll play with it and see if I get anywhere!

Well, if it’s only 4 languages, I think I’d use s2Member’s Special Redirection URL. (My code is really intended for tens or hundreds of different LWPs.)

Then you’d need to decide whether to differentiate based on s2Member level or ccap. If you have Pro, I’d use levels. If you have free, you would have to use ccaps because you won’t have enough roles available.

Then you would create several pages with either the s2Member level or ccap as part of the URL so that it would work with a Special Redirection URL including code like %%current_user_level%% or %%current_user_ccaps%%

Take a look at this: https://s2member.com/kb-article/customizing-your-login-welcome-page/

Yep, I have pro. That looks like it could be a solution! I’ll try to implement that and see where it takes me.

Thank you again for your help!

Got it to work with the special redirection url, the only drawback is that I have to create four different signup buttons/forms for the different membership levels (which really are the same level but directing to different LWPs) or I am missing something?

It would be sweet if there was a way to change the LWP’s based on a custom registration field or a conditional tag.

Great!

If you go to Stripe (or PayPal) Pro Forms, you will see an option at the end of the list called Wrapping Multiple Shortcodes as Checkout Options

If you follow the example there, you will be able to wrap all your forms into one with a dropdown list of options.