Disable redirect to membership sign-up

Hi there, thanks in advance to anyone who can help out with this little quirk.

I’m using s2Member in conjunction with EventEspresso for a booking system where the events need to be hidden behind the s2Member wall.

I set my events to require Level#1 Access and so that works just fine.

The only thing is that on going to that page while not logged in, it redirects to the membership sign-up page which we don’t want to happen.

The membership sign-up page link we send out to potential members (it’s a University Club) so they can sign-up but we don’t want the automatic redirect for a protected page landed on by a non-logged in person to be the sign-up page - if anything, it could be better if it could redirect to the LOGIN page.

Saw one email that dealt with a similar issue and their answer was that they protected the Login Page at level 0.

I’m pretty sure I didn’t do this myself so wouldn’t know where to look for that.

Thanks for any pointers!

Michael

To redirect to the login page and then send the member to the post/page s/he was seeking upon logging in, put this code in a plain text file and upload it to your mu-plugins folder:

<?php
/* AUTO-REDIRECT TO BYPASS MOP */
add_action( 'template_redirect', function () {
	if ( !is_page( S2MEMBER_MEMBERSHIP_OPTIONS_PAGE_ID ) ) {
		return; // nothing to do if no initial redirection to MOP
	}
	else if ( !empty( $_REQUEST["_s2member_vars"] ) ) {
		@list ( $restriction_type, $requirement_type, $requirement_type_value, $seeking_type, $seeking_type_value, $seeking_uri ) = explode ( "..", stripslashes( ( string )$_REQUEST["_s2member_vars"] ) );
	}
	if ( !empty( $seeking_uri ) ) {
		$URI = base64_decode( $seeking_uri );
	}
	if ( !is_user_logged_in() && !empty( $URI ) ) {
		$redirect = home_url( '/wp-login.php' ); // login page: change as required
		$redirect = add_query_arg( 'redirect_to', urlencode( $URI ), $redirect );
		wp_redirect( $redirect ); // perform the redirection
		exit;
	}
});

function s2_redirect( $redirect, $vars = array() ) {
	if ( ( isset( $_GET['action'] ) && $_GET['action'] != 'logout' ) || ( isset( $_POST['login_location'] ) && !empty( $_POST['login_location'] ) ) ) {
		$redirect = $_SERVER['HTTP_REFERER'];
		return $redirect;
	}
}
add_filter( 'ws_plugin__s2member_login_redirect', 's2_redirect', 10, 2 );

Hey Tim,

Many thanks for the incredibly speedy reply! I’ll give that a go.

Thank you!

Michael :slight_smile:

Fantastic, that worked perfectly!!

Thank you Tim,

Michael

Great! Thanks for letting me know!