How to redirect specific members to their relevant dashboards

Hi,

I've created 5 membership plans and 5 seperate member dashboard pages which allow the user to link off to their accounts, rewards page and training, specific to their subscription. What I would like to know is how I can send each user to the relevant dashboard automatically after they sign up / login.

I've looked into the 'Redirect' addon but this seems to only allow for one redirect. I'm going to need to redirect all 5 of my plans.

I have already provided Support Access which ends on the 25th (see attached).

Thanks,

Ash

  • Vaughan
    • Support/SLS MockingJay

    Hi ash,

    Hope you're well?

    this would most likely require a mu-plugin with some custom code.

    First we would need to get the users subscription level, then we can change the login URL depending on their subscription level. However, i've been unable to figure out how to achieve this, so let me just ask one of our SLS guys for some assistance with this for you.

    Thanks

  • Hoang Ngo
    • Code Slayer

    Hi ash,

    I hope you are well today.

    Please add this code to your theme functions.php or use mu-plugins

    add_filter('login_redirect', 'dashboard_pc_redirect', 10, 3);
    function dashboard_pc_redirect($redirect_to, $request, $user)
    {
        //find subscriptions this user has
        $member = MS_Factory::load('MS_Model_Member', $user->ID);
        $membership_id = 0;
        foreach ($member->ms_relationships as $subscription) {
            $membership = $subscription->get_membership();
            $membership_id = $membership->id;
            break;
        }
        if ($membership_id == 0) {
            return $redirect_to;
        }
        //redirects
        $redirects = array(
            'membership_id_1' => 'url1',
            'membership_id_2' => 'url2'
        );
    
        if (isset($redirects[$membership_id])) {
            return $redirects[$membership_id];
        }
        return $redirect_to;
    }

    You will need to config the variable $redirects, example you have a membership id = 1, and the dashboard url is http://yourdomain.com/dashboard1, so you can do it like this

    $redirects = array(
            1 => 'http://yourdomain.com/dashboard1',
        );

    And so on for the others :slight_smile:

    If you have any issues please don't hesitate to let us know so we can assist

    Best regards,
    Hoang

  • ash
    • Site Builder, Child of Zeus

    I'm not follwoing this process I'm afraid. It's talking about a multisite installation which I do not have.

    Could you explain to me what I'm supposed to be doing a little better please? I'm a newb with all this.

    Thanks,

    Ash

  • Hoang Ngo
    • Code Slayer

    Hi Ash,

    Could you please follow this guide to enable the staff access (Or reset it, as I don't see any gates for now :slight_frown: ), so I can check and update the code for you :slight_smile:

    Also, I will need to know the urls for redirect after users login. Can you please send it to me too? :slight_smile:

    Thanks.

    Best regards,
    Hoang

  • ash
    • Site Builder, Child of Zeus

    Hi Hoang,

    Everyone has mentioned they can't see access but I'm not sure why. Would it be because I had to move the original install directory and you guys are looking somewhere else? Please see attached.

    The new directory resides at 'thesbcollective.com/experience'

    The following memberships should redirect to their relevant dashboards:

    Annual Member - ../dashboard0
    Season 1 Member - ../dashboard1
    Season 2 Member - ../dashboard2
    Season 3 Member - ../dashboard3
    Season 4 Member - ../dashboard4

    If you need anything more from me please let me know and I'll be happy to help.

    Thanks!

    Ash

    My

  • Hoang Ngo
    • Code Slayer

    Hi @Ash,

    Hmm, for now, can you please send in:

    - Mark to my attention - ATTN: Hoang Ngo
    - Link back to this thread
    - Include admin/network access
    - Include FTP
    - Include any relevant URLS for your site

    On the contact form, select "I have a different question", this ensures it comes through and gets assigned to me.

    Thanks!!.

    Best regards,
    Hoang

  • ash
    • Site Builder, Child of Zeus

    Just to reiterate, I have 5 individual dashboards specific to each membership level.

    I want each corresponding dashboard to load for that relevant login. Currently I am only able to apply one redirect as a global setting which doesn't really make any sense as there should ultinately be be as many possible configurations for all membership level we decide to have.

    Otherwise it seems we only really have full control over one membership level.

    If you need any more information from me I'll be happy to provide.

    Many thanks,

    Ash

  • Hoang Ngo
    • Code Slayer

    Hi @Ash,

    I've just updated the code, it's working for me now, can you please check?

    Here's the new code

    add_filter('login_redirect', 'dashboard_pc_redirect', 9999999, 3);
    function dashboard_pc_redirect($redirect_to, $request, $user)
    {
        $rels = MS_Model_Relationship::get_subscriptions(
            array( 'user_id' => $user->ID )
        );
    
        $membership_id = 0;
        //var_dump($member->ms_relationships);
        foreach ((array)$rels as $subscription) {
            $membership = $subscription->get_membership();
            $membership_id = $membership->id;
            break;
        }
        if ($membership_id == 0) {
            return $redirect_to;
        }
        //redirects
        $redirects = array(
            82 => 'dashboard0',
            59 => 'dashboard1',
            62 => 'dashboard2',
            78 => 'dashboard3',
            72 => 'dashboard4'
        );
    
        if (isset($redirects[$membership_id])) {
            return admin_url($redirects[$membership_id]);
        }
        return $redirect_to;
    }

    Best regards,
    Hoang

  • ash
    • Site Builder, Child of Zeus

    Hi Hoang,

    I see that you have created a redirect.php file in the '/wp-content/mu-plugin' folder. Do I need to do anything else as it isn't working for me unfortunately. I'm logging in using existing accounts. Will this only work on new accounts?

    Thanks,

    Ash

  • Hoang Ngo
    • Code Slayer

    Ash,

    Your main admin account doesn't has any memberships, so It will not work for that account.

    Are you logging in from the login '../experience/login' page or do you go through the registration form process to login? Not that it should make a difference, should it?

    I'm using the native wp-login.php. The /login will not work I think, it's print out an URL and using javascript for redirect. We can update the URL, but's the point is, that's is before user log in to your site, so we have no idea which membership that's visitor having.

    Can we use the /wp-login.php instead?

    It appears that when I log out of my admin user account in the frontend it breaks my WP backend. Are you aware of this?

    Does it fine for you now?

    Best regards,
    Hoang

  • ash
    • Site Builder, Child of Zeus

    Hi Hoang,

    Update

    I've checked with the lead Developer, he can release a version today which necessary filter, so I can update the URL and make it work with your /login page :slight_smile:

    Thanks for the update. That sounds better for me. I don't want users to see a wordpress login when they login to their dashboard. It needs to remain in the style of the website and where I can amend the style. Will this still acknowledge what membership a user has based on their login credentials? I don't want them having to go through a parent page in order to get to the login form just so the form knows where to direct them.

    I originally wanted to place the 'Login' link in the navigation menu and have it automatcally change to logout when a user is logged in but I couldn't see how to do that so I opted for this more primative way. Do you know if this will be possible to do one day as it seems quite an obvious feature?

    Your main admin account doesn't has any memberships, so It will not work for that account.

    I'm confused as if I do not have any memberships assigned to my admin account, do you know why my account page says the following:

    "You are an admin user and have access to all memberships"

    It appears that when I log out of my admin user account in the frontend it breaks my WP backend. Are you aware of this?
    ..........
    Does it fine for you now?

    I'm afraid when I try and login to my WP backend with my admin account I am directed to my frontend dashboard now. I need to then manually enter the URL for the backend page to access.

    I want to be able to login with my admin account into my WP admin via the WP URL but still be able to login to my frontend dashboard via my frontend URL.

    You say there will be an update but will this potentially wipe out any custom work I currently have in flux on other threads - namely the replacement menu bug from this thread - https://premium.wpmudev.org/forums/topic/i-had-my-replacement-menus-working-for-varied-member-levels#post-851419

    I hope that makes sense but if you have any questions, please let me know and I'll be happy to help.

    It's urgent that this is ready by tomorrow latest as this website launches on Friday and I'm going to be out of my office at the launch event.

    Thanks for your time and effort on this Hoang. I really do appreciate it.

    Regards,

    Ash

  • Hoang Ngo
    • Code Slayer

    Hi @ash,

    Does you already made any changes to the plugin's code? If not, so you are can upgrade without issues.

    Admin is a special account, so it can access to any memberships without assigned to them. Actually we will need the account assigned to a membership for the login code to work.

    Also, a new version has been released. Can you please backup the current work and upgrade?

    Best regards,
    Hoang

  • ash
    • Site Builder, Child of Zeus

    Hi Hoang,

    This message just came through as I upgraded. I didn;t back that up. I've not changed any core files, but I've been waiting for a fix for the following thread which may have meant support have tried changing files.

    https://premium.wpmudev.org/forums/topic/i-had-my-replacement-menus-working-for-varied-member-levels#post-851419

    What do I need to do in order to send users to the dashboard with the new update?

    Thanks

  • ash
    • Site Builder, Child of Zeus

    Admin is a special account, so it can access to any memberships without assigned to them. Actually we will need the account assigned to a membership for the login code to work.

    How do I assign the admin account to a membership plan? I've gone into 'members' tab but it won't let me apply a membership to that account.

  • ash
    • Site Builder, Child of Zeus

    Hi Hoang,

    What are your directions on this? I'm not sure how or where to apply the redirection to each membership login. The MU Plugin is still on my server with the php file. What do I need to do in the Plugin now to get this to work?

    Thanks,

    Ash

  • ash
    • Site Builder, Child of Zeus

    Hi Hoang,

    admin account can access to all memberships, so how we can determine which dashboard URL they redirect to?

    I see what you mean, I envisaged the admin account would just have access to the annual dashboard so they can view all training pages.

    The redirection works for the 'Season 1' login but I can't see if the Annual account works as I'm trying to go through the Annual signup process it is sending me around in loops.

    1. I register a new account.
    2. I'm directed to the stripe payment page where I enter a coupon which enables me to get 100% off (free).
    3. That then directs me to another /membership page which has all the plans available and asking if I want to confirm payment. I click on confirm payment and it sends me back to the Stripe payment page.

    Can you signup for an Annual member page using the code SBCXXX in order to redeem 100% off and see what is happening please?

    I don't need to hit another membership page when I click on the stripe payment button. I should go to the dashboard directly after that.

    Thanks for all your help so far. We are nearly there!

    3. I

  • Hoang Ngo
    • Code Slayer

    Hi @ash,

    Admin account now default go to Dashboard0

    I also found that there's a bug with MoJo MarketPlace, which prevent the redirection after login, has fixed that.

    About the loop, it's sound like a bug, I'm checking with the lead developer about it and we will fix it ASAP.

    Best regards,
    Hoang

  • ash
    • Site Builder, Child of Zeus

    Hi Hoang,

    Have you had any joy? I'm getting really worried that this isn;t going to be ready for tomorrows launch. Can you give me an eta on the bug fix please?

    FYI - I've disabled MoJo MarketPlace as I don't believe I need it for anything.

    Hopefully hear from you soon with a solution/fix.

    Thanks,

    Ash

  • Hoang Ngo
    • Code Slayer

    Hi @Ash,

    I hope you are well today.

    The newest version 1.1.1.3 has fixed the redirect loop when checkout by 100% coupon, can you please check?

    Also, I updated the code for by-pass the register complete page and direct user to their dashboard too :slight_smile:

    Best regards,
    Hoang

  • ash
    • Design Lord, Child of Thor

    Hi Hoang,

    I encountered some issues when directing users to custom dashboards so I need the following which I guess would be achieved by simply removing the code you added to mu-plugin, however I didn't want to just go in a remove it myself as there might be something still working in there:

    Users registering for the first time should be directed to 'Registration Complete' page.
    Users logging in should be directed to their 'Account' page.

    If you could ensure my original redirects are removed correctly and that any other code within my mu-plugin is left intact so that the above works fine then I'd be very grateful.

    Thanks,

    Ash

  • Hoang Ngo
    • Code Slayer

    Hi @ash,

    I hope you are well today.

    Just for confirm, so now we don't redirect user to their dashboard anymore?, and what we will do is like the default way

    Users registering for the first time should be directed to 'Registration Complete' page.
    Users logging in should be directed to their 'Account' page.

    Please advise,
    Thanks!!!

    Best regards,
    Hoang

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.