Redirect to the same page after signup and signing

There will be a number of pages with download links on them. Ideally I want someone to land on a page, sign in and be redirected to that same page.

Or register and be redirected to that same page. With both being registered as a member. I have tried the codes here https://premium.wpmudev.org/forums/topic/redirect-to-current-page-after-registration-using-this-short-code-ms-membership-register-user#post-1300964

But it does not add the user as a member after signup with the form generate by the Membership 2 registration form.

  • Panos

    Hi Lloyd !

    There was something missing from the original snippet shared in chat. It doesn't create a paid invoice so in the protection rules the subscription is not valid. Here is the snippet with the missing part:

    add_action( 'ms_controller_frontend_register_user_complete', function( $member, $request, $front_controller ){
    
    	if ( ! isset( $request['membership_id'] ) ) {
    		return;
    	}
    
    	$membership_id = (int) $request['membership_id'];
    	$membership = MS_Factory::load(
    		'MS_Model_Membership',
    		$membership_id
    	);
    
    	if ( ! $membership->is_free() ) {
    		return;
    	}
    
    	$subscription = $member->add_membership( $membership->id, '' );
    	$subscription->add_payment( 0, MS_Gateway_Free::ID, 'free' );
    
    	if ( $subscription instanceof MS_Model_Relationship ) {
    		wp_safe_redirect( get_permalink() );
    		exit;
    	}
    
    }, 99, 3 );

    You can use this one instead in your mu-plugin.

    Hope this helps!
    Kind regards!

  • Lloyd

    Hi Panos,

    This code works perfectly. But there seems to be a conflict with the Mailchimp Add-on.

    When a user signs up it doesn't automatically add them to Mailchimp.
    I checked the follow:
    1. Double opt in is turned off at Mailchimp
    2. GDPR fields turned off at Mailchimp
    3. Required fields are turned off at Mailchimp
    4. Auto add to Mailchimp toggle is switched at Membership 2 Pro settings
    5. The correct newsletter lists have been selected at Membership 2 Pro settings

    I've spoke to Luis via the support chat and he did some tests on his side. It was creating issues for him where it was signing his members up to the 'Registered Users' list and not the 'Members' list. We removed the custom function and all was resolved (but the redirects stopped working). Luis said it looks like the flow in the code is breaking the mailchimp sign up.

    Can you help.
    Thanks

  • Panos

    Hey Lloyd ,

    Apologies for delay! I missed that you had the Mailchimp add-on active. A small modification would work in my tests, here's the updated snippet which worked for me:

    add_action( 'ms_controller_frontend_register_user_complete', function( $member, $request, $front_controller ){
    
    	if ( ! isset( $request['membership_id'] ) ) {
    		return;
    	}
    
    	$membership_id = (int) $request['membership_id'];
    	$membership = MS_Factory::load(
    		'MS_Model_Membership',
    		$membership_id
    	);
    
    	if ( ! $membership->is_free() ) {
    		return;
    	}
    
    	$subscription = $member->add_membership( $membership->id, '' );
    	$subscription->add_payment( 0, MS_Gateway_Free::ID, 'free' );
    
    	if ( $subscription instanceof MS_Model_Relationship ) {
    		// Used by Mailchimp Add-on
    		MS_Model_Event::save_event( MS_Model_Event::TYPE_MS_REGISTERED, $member );
    		wp_safe_redirect( get_permalink() );
    		exit;
    	}
    
    }, 99, 3 );

    Give it a go and let us know how it works on your side!

    Kind regards!

  • Panos

    Hey Lloyd!

    There have been some changes in the beta version as there was an issue with this feature. I am attaching a file that fixed this in my test here, which you can download, unzip and upload to folder:
    membership-pro/app/model/
    You can rename the original file to something like class-ms-model-relationship.php.txt so you can keep it as a backup before uploading that file.

    Those changes should be included in next release so you won't have to repeat this then.

    Kind regards!

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.