WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Automatic redirection to child site from main (20 posts)

  1. valuser
    Member
    Posted 3 years ago #

    Absolute newbie.

    Is there a way , "a best way" to AUTOMATE the following process in this set-up - Network Options - Both sites and user accounts can be registered.

    Q.1
    When a sub-site owner logs in on the MAIN Site that they are redirected to their own site.
    or
    Q.2
    Alternatively-is there a way to automatically add a new child site owner as a subscriber to main site .

    (then Peter's login redirect seems to do the job- but that seems to be only when child site owner is MANUALLY added as subscriber to main site)

  2. When a sub-site owner logs in on the MAIN Site that they are redirected to their own site.

    When logging in a site owner should be redirected to their primary site automatically.

    Alternatively-is there a way to automatically add a new child site owner as a subscriber to main site .

    Is it because you need them to be added to some integrated software like a forum? Because users are pseudo-subscribers on every site across the whole network.

  3. valuser
    Member
    Posted 3 years ago #

    Many thanks.

    "When logging in a site owner should be redirected to their primary site automatically."

    Obviously I have misconfigured something as this only happens (for me) immediately after registration. Thereafter when a sub-site owner logs in on the MAIN Site they stay there, on the MAIN Site, but logged in.

    "Is it because you need them to be added to some integrated software like a forum?"

    No. (just experimenting-to learn). I just found that if they were manually added as subscribers to the MAIN site then when they logged in to the MAIN site they could be redirected to their own site via Peter's login re-direct. Hence the query could I get them to be automatically added as subscribers to the MAIN Site when they registered their own site (as opposed to subsequent manual addition).

    Am a complete novice.

    Just would like when anyone logs in on the Main Site they are redirected to their own site - but apparently this is what should happen. I have misconfigured something. I should begin again and forget about the redirect plugin ?

  4. David Sader
    Member
    Posted 3 years ago #

    When logging in a site owner should be redirected to their primary site automatically.

    Only with a plugin, AFAIK. Whatever blog you log in from is the dashboard/profile you'll get by default.

    See
    http://wordpress.org/support/topic/link-to-primary-site?replies=7

  5. valuser
    Member
    Posted 3 years ago #

    Please bear with my ignorance!

    From the correspondence at
    http://wordpress.org/support/topic/link-to-primary-site?replies=7

    am i to infer

    1) save your code (code 1 or code 2 ?) as a .php file

    2) put this file (in a folder ??) into "mu-plugins" directory

    3) network activate as a plugin ?

    and your correspondent states

    "If this is hooked to login_redirect, it will send them to their primary site backend on login"

    Presumably if login_redirect is configured to send them to their front-end it will ??

    There is then no need to manually add sub-site owners as subscribers to the main site ??

  6. There is then no need to manually add sub-site owners as subscribers to the main site ??

    no, there is not, unless you're integrating with something else. If you're looking for them to have to rights to "must be logged in to comment" then they already have that.

    Only with a plugin, AFAIK. Whatever blog you log in from is the dashboard/profile you'll get by default.

    Really? I have a site where a secondary site is listed as my primary site, and every single time I login to the main blog, I get sent to the other site. :-/

  7. David Sader
    Member
    Posted 3 years ago #

    Sorry Andrea_r for "rocking the boat" on this one. I do have all my users as subscribers on the main.

    With no plugins active, when user "jdsalinger" logs into the main site he goes to his profile at the main site. He then must go to Dashboard->My Sites to select the dashboard for his "jdsalinger" site. There is no automagic redirection to his primary site. WP 3.0.3.

    I have to use a plugin to get the redirection to the primary you describe.( or remove him from the list of users on the main).

  8. David Sader
    Member
    Posted 3 years ago #

    valuser,

    I have this in my "mu-plugins", in its own "my_login_redirect.php" file:

    <?php
    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);
    ?>

    There is no other activation necessary as any code in the "mu-plugins" is always on.

    The effect is that no matter what blog a user logs in at, member or not, s/he redirects to their primary.

  9. valuser
    Member
    Posted 3 years ago #

    First, thank you both for replying.

    I never even knew about an mu-plugins folder!

    Anyway

    1) installed an mu-plugins folder in the wp-content folder

    2) did as David suggested .php file etc.

    3) Logged on Main Site as a sub-site user and Yes I was redirected to the sub-site users back-end. (that user not being a subscriber etc of main site).

    Now how to alter that to the users front end ????

    delete . 'wp-admin/ ???

  10. valuser
    Member
    Posted 3 years ago #

    yes!
    retired farmer very pleased

    Thanks again

  11. Sorry Andrea_r for "rocking the boat" on this one.

    Rock away! Could be something unique to plugin or becasue yours is an upgraded mu install. I've seen stuff like that happen. Odd.

    You got this guy sorted out tho, so all's good. :)

  12. Just for my own sanity, I wanted to recheck this behavior.

    IF a user is registered and has their own site, and only has a role on that site (not the main) they *should* get redirected to their site if they login anywhere else.

    IF they have a role on the site they are logging in to (like subscriber on the main site) they will *not* get redirected.

    If it's different, then a plugin messed it up. Also, this behavior may change in 3.1.

  13. valuser
    Member
    Posted 3 years ago #

    So far, David's solution appears to function as he intended in WP 3.02, 3.03, and 3.1 Beta 2. Here's hoping it stays that way.

  14. valuser
    Member
    Posted 3 years ago #

    Andrea said

    "Also, this behavior may change in 3.1."

    Perhaps it has? In recent install of 3.1 RC2 i think the previous solution has ceased to work. (for me anyway)

  15. valuser
    Member
    Posted 3 years ago #

    Please disregard the previous post. function ds_login_redirect still works as intended in WP 3.1 RC2.

  16. jschinker
    Member
    Posted 2 years ago #

    Note that the default behavior does change in 3.2.1.

    When a user logs in to the main site, they now get this message:
    http://www.flickr.com/photos/63873121@N00/5997264349/in/photostream

    The code that David posted above does work to redirect them to their dashboards, though. I just put it in a file in the mu-plugins folder and everything seems to be working like it used to now.

    Thanks, everyone, for documenting this and making it so easy to fix.

  17. Tomas
    Member
    Posted 2 years ago #

    Thanks David, your mu-plugin fixed our issues after upgrading to 3.2.1

  18. bwinn
    Member
    Posted 2 years ago #

    I upgraded to 3.2.1, copy & pasted David's exact code, placed it in my MU Plugins folder and I am still getting the same error that jschinker is showing above...

    http://www.flickr.com/photos/63873121@N00/5997264349/in/photostream

    Any idea, why this is still not working for me? My users are growing tired of this.

  19. @bwinn - do not bump posts. The mods are volunteers here and sometimes we do things like sleep. ;) We get to it when we get to it.

    If David has subscribed to this thread, he will get notified.

  20. Tomas
    Member
    Posted 2 years ago #

    bwinn, you sure there's no extra chars or spaces in your paste?
    As stated before, this worked out of the box for us.

Topic Closed

This topic has been closed to new replies.

About this Topic