Redirect members to specific pages based on membership levels after login

For Memberships pro, is there a way to redirect a membership level to a specific page on login? We have tried some custom codes with the chat representative which didn't work. Looking for some more insights regarding this.

  • Paul Kevin
    • Neo

    Hello SEO Admin,

    Hope you are well today. Could you please try the following code :

    function my_custom_ms_redirect( $current_url, $user_id ) {
    $member = MS_Model_Member::get_current_member();
    if ( $member->has_membership( 44 ) ) {
    return 'https://www.google.com';
    }
    return $current_url;
    }
    add_filter('ms-ajax-login-redirect', 'my_custom_ms_redirect');

    function ms_set_redirect_url( $url, $enforce ) {
    $member = MS_Model_Member::get_current_member();
    if ( $member->has_membership( 44 ) ) {
    return 'https://www.google.com';
    }
    return $url;
    }
    add_filter( 'ms_url_after_login', 'ms_set_redirect_url');

    Another option could be also to include this code

    add_filter( 'ms_shortcode_ajax_login', '__return_false' );

    in your themes functions.php file to make membership login use the default WordPress login method, then use the WordPress filter login_redirect to redirect to the custom url.
    Hope this helps

    Warm Regards
    Paul Kevin

  • Paul Kevin
    • Neo

    Hey there SEO Admin ,

    Sorry for the late response on this. Kindly set 44 to a membership id of your choice and try again. I had set 44 as a test value in this case.
    You could also add this add_filter( 'ms_shortcode_ajax_login', '__return_false' ); in your themes functions.php file and the following function

    add_filter( 'login_redirect', function( $url, $query, $user ) {
    	$member = MS_Model_Member::get_current_member();
    	//44 is just a test membershi id
    	if ( $member->has_membership( 44 ) ) {
    		return 'https://www.google.com';
    	}
    		return $url;
    	}
    }, 10, 3 );

    Which will tell Membership to use the default WordPress login action to handle the login.

    Warm Regards
    Paul Kevin

    • Paul Kevin
      • Neo

      Sorry about that, it should be this :

      add_filter( 'login_redirect', function( $url, $query, $user ) {
      	$member = MS_Model_Member::get_current_member();
      	//44 is just a test membershi id
      	if ( $member->has_membership( 44 ) ) {
      		return 'https://www.google.com';
      	} else {
      		return $url;
      	}
      }, 10, 3 );
    • Paul Kevin
      • Neo

      For multiple memberships with the same url you could do something like this :

      add_filter( 'login_redirect', function( $url, $query, $user ) {
      	$member = MS_Model_Member::get_current_member();
      	//44 is just a test membershi id
      	if ( $member->has_membership( 44 ) || $member->has_membership( 45 ) || $member->has_membership( 46 ) || $member->has_membership( 47 ) ) {
      		return 'https://www.google.com';
      	} else {
      		return $url;
      	}
      }, 10, 3 );

      This will send them all to the same url. Or you could do this

      add_filter( 'login_redirect', function( $url, $query, $user ) {
      	$member = MS_Model_Member::get_current_member();
      	//44 is just a test membershi id
      	if ( $member->has_membership( 44 ) ) {
      		return 'https://www.google.com';
      	} else if ( $member->has_membership( 45 ) ) {
      		return 'https://www.facebook.com';
      	} else if ( $member->has_membership( 46 ) ) {
      		return 'https://www.mysite.com';
      	}else {
      		return $url;
      	}
      }, 10, 3 );

      To send them to different URLS. I will look at adding this into a future release to allow custom url redirection setting on the membership setting and maybe a custom one for each member.

      Warm Regards
      Paul Kevin

  • SEO Admin
    • WPMU DEV Initiate

    Hey Paul, that did not see to work.

    here is what I added to my functions.php

    add_filter( 'ms_shortcode_ajax_login', '__return_false' );
    add_filter( 'login_redirect', function( $url, $query, $user ) {
    	$member = MS_Model_Member::get_current_member();
    	if ( $member->has_membership( 2217 ) ) {
    		return 'http://67.227.213.206/~promohitachi/coop/';
        } else if ( $member->has_membership( 2228 ) ) {
    		return 'http://67.227.213.206/~promohitachi/sales/';
    	} else {
    		return $url;
    	}
    }, 10, 3 );
    ?>
    • Paul Kevin
      • Neo

      Hey there SEO Admin ,

      Hope you are well today. Could you please try the 2 separate scripts each separately. The first one:

      add_filter( 'ms_shortcode_ajax_login', '__return_false' );
      add_filter( 'login_redirect', function( $url, $query, $user ) {
      	$member = MS_Model_Member::get_current_member();
      	if ( $member->has_membership( 2217 ) ) {
      		return 'http://67.227.213.206/~promohitachi/coop/';
          } else {
      		return $url;
      	}
      }, 10, 3 );

      For membership 2217 and

      add_filter( 'ms_shortcode_ajax_login', '__return_false' );
      add_filter( 'login_redirect', function( $url, $query, $user ) {
      	$member = MS_Model_Member::get_current_member();
      	if ( $member->has_membership( 2228 ) ) {
      		return 'http://67.227.213.206/~promohitachi/sales/';
      	} else {
      		return $url;
      	}
      }, 10, 3 );

      for membership 2228. Im trying to see if the user has that membership active as the code should work if the member has an active membership matching that id.

      Warm Regards
      Paul Kevin

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.