After login redirect user to their own dashboard

Hey there,

I have read through every post referring to this issue and it seems no one is able to provide an answer that works like most of us need it to.

Let's say our imaginary friend Sally creates a website on my multi-site network: sally.getbranded.me.

I place a "member login" button on the hompage of getbranded.me and Sally goes to login.

Once she logs in she is taken back to getbranded.me, but she needs to be taken to sally.getbranded.me/wp-admin.

So how can this be accomplished? Thanks!

  • Ash
    • WordPress Hacker

    Hello @magicdood

    Welcome to WPMU community!

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

    I understand the issue. But what if the user has more than one sites? Like:
    sally1.getbranded.me
    sally2.getbranded.me
    sally3.getbranded.me

    Where do you want him to send?

    Please let me know.

    Cheers
    Ash

  • magicdood
    • WPMU DEV Initiate

    Thanks for the quick reply. I had not thought of that. Perhaps then the question should be:

    How can I redirect the user to a page that list all of their sites and provides links to their individual site dashboards?

    Thanks,
    Magicdood

  • webmaharaj
    • Design Lord, Child of Thor

    If the user has only one site, he should be redirected to that site admin and if he has more than one site, he should be redirected all sites dashboard page or the first site admin he has created and showing all other sites in admin gar will be fine.

    Thanks

  • Ash
    • WordPress Hacker

    Please use the attached zip file. Extract the zip, put it in /wp-content/mu-plugins/ folder. If there is no folder named "mu-plugins", just create one.

    Then check and let me know the result.

    Please let me know if you find this is helpful, or if you have any further questions.

    Cheers
    Ash

  • magicdood
    • WPMU DEV Initiate

    Hey there,

    Sorry for my absenteeism. I guess I should rephrase the question.

    I am wanting a user to be able to go to my main network site (getbranded.me) click login, be taken to getbranded.me/wp-login, then once logged in be taken to their respective dashboard (example.getbranded.me/wp-admin) instead of being redirected to my homepage.

    Thanks

  • Ash
    • WordPress Hacker

    Try the following in mu-plugins folder please:

    function ds_login_redirect( $redirect_to, $request_redirect_to, $user )
    {
        if ($user->ID != 0) {
            $user_info = get_userdata($user->ID);
            if ($user_info->primary_blog) {
                $primary_url = get_blogaddress_by_id($user_info->primary_blog) . 'wp-admin/';
                if ($primary_url) {
                    wp_redirect($primary_url);
                    die();
                }
            }
        }
        return $redirect_to;
    }
    add_filter('login_redirect','ds_login_redirect', 100, 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.

    Let me know if it works.

    Please let me know if you find this is helpful, or if you have any further questions.

    Cheers
    Ash

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.