MU: how to restrict user access to main site dash but not their site dash

So currently users sign up and are able to create their own sub-site. I use sub-directories
For this example I will use as the main site where users create sub-sites, which will be

Currently when they login they go straight to the admin panel. This is because they are using as the log in.

Here they are able to view their profile and make changes.

From there they can go to the My Sites link in the admin bar and go their site admin panel. This is where they have access to all their stuff that I have permitted using Pro Sites.

How can I stop them from ever going to and ever being able to access the admin panel? Though they can't do anything there other than change profile settings, it is confusing to people and isn't user friendly.

Also, I still want them to have access to their profile settings because this is where they update their settings.

  • Jack Kitterhing
    • Code Norris

    Hi there @josh

    Hope your well today and thanks for your question.

    Where would you like them to go? See we could do a redirect to their admin dashboard, but this would do that everytime and stop them accessing the main site dashboard completely, is that what you wanted?

    Thank you!

    Kind Regards

  • josh
    • Site Builder, Child of Zeus

    I am doing well, hope you are too @Jack Kitterhing

    Well I have a vision I want, but not sure how to get this. I have been trying to find a modal login plugin that I can put in a menu. I know there are plugins that put the login in the sidebar as a widget, but I like the look when it is in the menu and a modal screen pops up. I have found one "BAW login logout menu" but it just redirects to the default wordpress login not a modal pop up screen, like I want.

    So basically what I want is a log in button in the menu that has a pop up modal window when it is clicked. Or it can just drop down and have the login fields.

    I don't want users to deal with a separate page to log in. Once they login, they can either be redirected to THEIR admin panel or the main site home page. I think I like the home page over the admin panel.

    I am using the admin bar so once they login that will pop up and they can click on my custom logo on the left side and they would be redirected to their admin panel.
    Also if there is a way that I can add a link in the admin panel to go to their profile settings that would be awesome!
    I still need them to be able to access their profile settings. I already have a plugin for inserting custom items and menus in the admin bar, I just don't know how to set up a link that goes to the profile setting.

  • Jack Kitterhing
    • Code Norris

    Hi there Josh,

    I'm great thanks :slight_smile:

    Interesting, first for the redirect try out our login redirect plugin here that should work :slight_smile:

    For your modal login, I believe that this should work

    So then we have a workflow of, modal login > redirect to homepage, sidebar link for the admin or something else? :slight_smile:


    Kind Regards

  • josh
    • Site Builder, Child of Zeus

    Hi there @Jack Kitterhing

    Thanks for the suggestions.

    I will use the redirect plugin

    As for wp modal login, I can't find a way to put it in the nav menu.
    I found this

    But it doesn't work. In fact it makes my admin panel completely white.
    Any suggestions?

    I have the BAW login logout menu plugin which I am fine with (not modal but I don't mind a drop down box)

    I can use this BAW plugin but how can I totally disable the login page? I don't want a separate login page at all. Just login through my menu. I don't want user to be able to access the page even through the url. Hopefully that's possible

    Thanks Jack

  • josh
    • Site Builder, Child of Zeus

    Hi @Jack Kitterhing

    Thanks for all the help and sorry for the delay

    I was able to get the modal login working in the nav menu.
    I just followed the same directions and it worked. Weird.

    So I have almost everything working just how I want. Few things left though.

    I have a custom logo in the admin bar and I want that to link to the users admin panel. So not

    I also want them to be able to edit their profile page that is located in the main site's admin area. I can create a link in the admin bar that takes them to this page but it will still confuse my users because the sidebar totally gives away that they are in another admin panel. Ideally I would like to have the profile button moved to their admin panel and they wouldn't have to ever leave it, but I don't think this is possible.

    I did have another idea. I tried this plugin: to make the profile page front end and I created a link in the admin bar to take them to that page, but the plugin creates a custom profile page, it doesn't just pull all the info from the normal profile page in the admin panel . I need the normal profile info because I have a custom field that the users have to be able to edit.

    The Questions:
    1. How to link username and site name during registration? So if a user picks "User1" as their username the site name field would auto fill and be un-editable,

    2. How to get custom admin bar logo to link to their admin page? Is there a variable syntax that would do this? Ex.
    But this reference to the username would mean the issue in question 1 would have to be resolved.

    3. Any ideas on how to enable the users to be able to edit their profile in a user friendly way? Ideally I could somehow put the profile option in their admin panel so they would never have to venture away from their admin panel.


  • josh
    • Site Builder, Child of Zeus


    I used this code in my theme's function.php file

    add_action( 'init', 'blockusers_init' );
    function blockusers_init() {
        if ( is_admin() && ! current_user_can( 'administrator' ) &&
           ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
            wp_redirect( home_url() );

    This blocked off access to the main site's admin area. I also used this plugin: and created a page with the shortcode that created a front end page for editing profiles.

    This answers my question #3 from the previous post. But if there is a way to make it better or move it to the back end but in the users admin area instead that would be great!

    I'm still trying to find a way to link the username to the site name and how to have a variable link for my custom logo i the admin bar so that it takes the user to their admin area.


  • josh
    • Site Builder, Child of Zeus

    Thanks @Jack Kitterhing

    Sorry I'm a newbie and don't really understand what to do with the get_admin_url() and get_bloginfo() stuff you posted above.

    What exactly do I write and where do I enter it. I used the "Ultimate Rebranding" plugin and in the admin bar setting it allows me to edit where the link leads to.

    I'm assuming I have to click on the option that says "This URL" and enter in the custom URL with the codex stuff you gave me???

    But the link that you supplied leads me to believe that it has to do with coding in a specific file not creating a variable link/URL

    Can you clarify how I can do this, please?

    And also, when users sign up they can pick a username then on the next page they can pick a site name independently of their username. It autofills with their username which is great, but I don't want the users to be able to change it. I want their username to be used as the site name. Any way I can do this?

  • Jack Kitterhing
    • Code Norris

    Hi there @josh,

    Hope you're well today :slight_smile:

    Ah, yes this would be a issue, as we need to change the link where the logo is correct? As that admin url?

    On the field not being editable, I'm not aware of a way to do that within the signup form, But I'll check with my colleague @Alexander Rohmann to see if he has any ideas on that, thanks for your patience :slight_smile:


    Kind Regards

  • josh
    • Site Builder, Child of Zeus

    Thanks @Jack Kitterhing. Hope you had a good holiday

    I've actually somewhat changed my mind. I'll still prefer the username being used as the site name, but.... I don't mind if they are independent (how it currently is).

    As long as I can create that variable link that pulls the site name based on the user/username.

    An Idea for a Possible Workaround
    In the default admin bar their is a link to "my sites". Currently in my case it is a drop down menu and the options are My Main Site and Their Site. This is because they are a subscriber to my site and an admin in their site. When a user hover over their site they have a flyout menu with a few options, but the most important is that they have a link to their dashboard.
    I don't want to leave this my sites menu, because it isn't as user friendly as I would like. I would rather have a custom entry that isn't a menu that leads to THEIR dash.

    So my idea...
    Is there a way to look up how Wordpress is generating that link to their site? Specifically the link associated with "dashboard" under their site.
    Here is the path in the admin bar: My Sites --> User's Site Name --> Dashboard

    If we can look it up, maybe we can just copy it and change a few things (the title, the location in regards to hierarchy)

    Thanks a million!

  • Alexander
    • DEV MAN’s Mascot

    Hey @josh,

    That's possible, but modifying the toolbar takes a good bit of custom code. You can checkout the class reference here:

    To get started, I'd recommend just dumping the admin bar so you can get familiar with the data structure. Then you will know which nodes you want to add/remove.

    Use this code to get started:

    add_action( 'admin_bar_menu', 'custom_toolbar_modifications', 999 );
    function custom_toolbar_modifications( $wp_admin_bar ) {
    	echo '<pre>';
    	echo '</pre>';

    That will dump the menu for you so you can see the elements. It will also go ahead and remove anything that would be under "my sites"

    Best regards,

  • josh
    • Site Builder, Child of Zeus

    Hi @Alexander Rohmann

    Thanks for your help!

    Unfortunately I don't quite follow. What is "dumping"?

    I somewhat know how to add menu items and remove them with custom code (due to tutorials on the web and also plugins that do the work for me). I think that is what you were trying to help me do?? :slight_smile:

    Is there a way that I can code in a dynamic link?
    This is what I have so far:

    add_action( 'admin_bar_menu', 'toolbar_link_to_mypage', 999 );
    function toolbar_link_to_mypage( $wp_admin_bar ) {
    	//custom variable
    	$usersite = XXXXXXXX;
    	$args = array(
    		'id'    => 'my_store',
    		'title' => 'My Store',
    		'href'  => '$usersite/wp-admin/',
    		'meta'  => array( 'class' => 'my-toolbar-page' )
    	$wp_admin_bar->add_node( $args );

    But I am not sure how to code in the dynamic part written as XXXXXXXX above.
    This is where the shop/blog name has to get pulled. I'm assuming it has to do with what Jack was originally saying in the following:

    For question 1 and 2, so you want them to be redirect to their wp-admin dashboard correct? If that's the case, you can use the get_admin_url() along with the get_bloginfo(), codex here

    And also, I know I didn't include the variable ($usersite) in the href correctly. I'm not exactly sure how to include that.
    My guess: 'href' => ''. $usersite . '/wp-admin/',
    I really have no clue though :slight_frown:

    Thanks you guys and sorry if this is what you were originally trying to tell me.

  • Alexander
    • DEV MAN’s Mascot

    Hey @josh,

    Dumping is just outputting the contents of a variable so you can see what's inside. The var_dump function does this. (see above code)

    And yes, you're free to code that link dynamically. In fact, this is how most of them are added anyways.

    Now, to get that URL, you'll want to use this function:

    So something like this perhaps:

    'href' => get_active_blog_for_user(get_current_user_id())->siteurl . '/wp-admin/'

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.