[Membership 2 Pro] Membership 2 redirect to member page depending on membership type

Hi, I'm looking to redirect users to different pages after login depending on their membership type. I found the code on the link below, but it doesn't work for me, I get the white screen of death. So I'm wondering if the code is ok.

https://premium.wpmudev.org/forums/topic/membership-2-redirect-after-login-based-on-membership

  • Patrick Freitas
    • Staff

    Hi James

    Hope you are doing well.

    Wouldn't you mind, please, try this mu-plugin?

    1] Navigate to your /wp-content/ directory and create a new one named mu-plugins if it doesn't exist.
    2] Inside the mu-plugins folder create a file named m2p-login-redirect.php
    3] Edit the file and copy / paste this code snippet inside.

    <?php
    
    add_filter(
    	'wp_login',
    	function( $user_login, $user ) {
    		$member = MS_Factory::load( 'MS_Model_Member', $user->ID );
    
    		if ( $member->has_membership( 11 ) ) {
    			$url = 'https://url.one/';
    
    			wp_redirect( $url );
    			exit;
    		} elseif ( $member->has_membership( 12 ) ) {
    			$url = 'https://url.two/';
    
    			wp_redirect( $url );
    			exit;
    		} elseif ( $member->has_membership( 13 ) ) {
    			$url = 'https://url.three/';
    
    			wp_redirect( $url );
    			exit;
    		}
    
    	},
    	15,
    	2
    );

    4] Save and close the file.
    5] The final path should look like /wp-content/mu-plugins/m2p-login-redirect.php

    You just need to update the membership ID to match your memberships.

    References on
    https://codex.wordpress.org/Must_Use_Plugins
    https://premium.wpmudev.org/forums/topic/membership-redirect-help-needed

    Let us know if you need any further help on this.
    Best Regards,
    Patrick Freitas

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.