• Resolved chrisfried

    (@chrisfried)


    I have a multisite set up with subdomains. What I’d like to happen is, whether a user goes to “site.example.com/wp-admin” or “example.com/wp-admin”, they end up at the admin panel for “site.example.com”. One solution I ran across is to simply remove them as a user from the main site, however I need them to be users of main site in order to give them access to member only content on the main site.

    Might anyone be able to offer an alternative solution?

    I was originally looking for a way to link to the admin panel of a user’s Primary site, which would also be an acceptable resolution. The issue is that I’d like to include the link on a bbpress forum as well. That seems like it would likely require a deep integration, which I’d prefer to avoid that if I can.

Viewing 6 replies - 1 through 6 (of 6 total)
  • I have this in my “mu-plugins” dir:

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

    Thread Starter chrisfried

    (@chrisfried)

    If this is hooked to login_redirect, it will send them to their primary site backend on login, but what if they’re already logged in and click a link sending them to example.com/wp-admin?

    click a link

    How about this?

    <?php
    function ds_redirect_admin() {
    	global $current_user, $blog_id;
    
    //	if ($blog_id !='1') return;
    
    		$primary_url = get_blogaddress_by_id($current_user->primary_blog) . 'wp-admin/';
    
    	if( strpos($_SERVER['REQUEST_URI'], 'wp-admin' ) && ( $blog_id != $current_user->primary_blog) ) {
    		wp_redirect($primary_url);
    	}
    }
    
    add_action('_admin_menu', 'ds_redirect_admin');
    ?>
    Thread Starter chrisfried

    (@chrisfried)

    For a moment, I thought my problem was solved. Then it occurred to me: What if a user ends up as admin of more than one site?

    Thread Starter chrisfried

    (@chrisfried)

    Oh, right, that’s where the commented out bit would come in. Gotcha’.

    Thread Starter chrisfried

    (@chrisfried)

    Thanks!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Link to Primary Site’ is closed to new replies.