Account/subscription specific login redirect

Is it possible to set a login redirect based on the user’s subscription or user’s account, rather than a catch-all?

  • Ash
    • WordPress Hacker

    Hello @mark Blevis

    Welcome to WPMU community!

    I hope you are well today and thanks for asking the question.

    This is not possible out of the box, but we can make using some custom code. Would you please let me know a list of membership and corresponding login redirect URL? I will try to write some code for you.

    Cheers

    Ash

  • Ash
    • WordPress Hacker

    Hello @mark Blevis

    Is there a fee for that custom code?

    No, there is not fees at all. We provide all the support and small custom code snippet. But when you will need any huge customization, that’s beyond our support. In that case, you need to hire someone outside of WPMU or post a job in our job board. But no WPMU staff is not available for hiring.

    About your case, please enable support access so that I can check the membership IDs. Or if you can provide the IDs would be great :slight_smile:

    https://premium.wpmudev.org/manuals/wpmu-dev-dashboard-enabling-staff-login/

    Cheers

    Ash

  • Mark Blevis
    • Site Builder, Child of Zeus

    That’s strange. I just tried logging in and it worked — I was not redirected. I’m not sure why you’d be bounced over like that. If it occurs, one option is to manually enter the testing site URL. Don’t click on the home button of the testing site as that will redirect you to the main site (hard-coded).

  • Ash
    • WordPress Hacker

    Hello @mark Blevis

    I hope you are well today.

    Let’s make it simple :slight_smile:

    Please send me your login details. To send me details, please use our contact form: https://premium.wpmudev.org/contact/

    Select: I have a different question

    Subject: Attn-Ash (this ensures that it will be assigned to me)

    Details:

    1. Send all requested details

    2. Send a link of this thread so that I can track

    3. Send any other relevant link

    I will be happy to take a look :slight_smile:

    Cheers

    Ash

  • Ash
    • WordPress Hacker

    Hi Mark

    Please try the following code:

    function mem_login_redirect( $redirect_to, $request, $user ) {
    global $user;

    $member = MS_Factory::load( 'MS_Model_Member', $user->ID );
    $subscriptions = $member->get_membership_ids();
    $memberships = array();
    foreach( $subscriptions as $subscription ){
    $post = get_post( $subscription );
    $memberships[] = $post->ID;
    }

    if( in_array( 11502, $memberships ) ){
    return 'http://cna-testing.bistromatics.com/communications-working-group/';
    }elseif( in_array( 11528, $memberships ) ){
    return 'http://cna-testing.bistromatics.com/political-action-working-group/';
    }

    return $redirect_to;
    }

    add_filter( 'login_redirect', 'mem_login_redirect', 10, 3 );

    You can add those codes in your functions.php in the theme, if you think your theme won’t be changed. Otherwise mu-plugins is the best solution. To use mu-plugins, go to /wp-content/ and find the folder with name ‘mu-plugins’. If there is no folder in that name, then create a folder, name it ‘mu-plugins’, create a file inside that, give any name you like and paste the code in there. You don’t need to activate that plugin. Mu-plugins means must use plugins, so it will be activated automatically always. If you use mu-plugins then add a php start tag at the beginning of the code.

    Hope it helps :slight_smile: Please feel free to ask more question if you have any.

    Cheers

    Ash

  • Ash
    • WordPress Hacker

    Hello @mark Blevis

    if( in_array( MMSHP, $memberships ) ){

    Instead of MMSHP it should be the membership ID of MMSHP. You may notice that, I have used 11502, 11528 etc and those were membership IDs in my setup.

    So, you need to replace with your membership IDs.

    If you go to Membership 2 > Membership > in right column you will see shortcode for each membership and there you will get the IDs of each membership.

    Hope it helps :slight_smile: Please feel free to ask more question if you have any.

    Cheers

    Ash

  • Mark Blevis
    • Site Builder, Child of Zeus

    Thanks.

    It would be good to have this feature built in to the M2P administration interface in a future release — that is, being able to set login and logout redirects based on membership. I assume that this means there would have to be a primary membership associated with each member in the event that the administrator has enabled the multiple membership option.

    Mark

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.