What is the correct link structure from the front end to a registered users blog dashboard?

Hi, thanks for taking a sec.
What is the correct link structure from the front end of a site to a registered users blog dashboard?
I've tried:
http://chelseanyc.com/BLOG_PATH/wp-admin/index.php
But this is not working...
Any help or insight would be greatly appreciated.
Kind regards,
Yohan

  • Ash
    • WordPress Hacker

    Hello @yohanaton

    Welcome to WPMU community!

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

    Where do you want to use that link? If in code, you can use like this:
    echo site_url().'/wp-admin';

    And if in content from dashboard, just link to SUBSITE_URL/wp-admin/index.php

    Please let me know.

    Cheers
    Ash

  • yohanaton
    • New Recruit

    Hi Ashok,
    My first choice would be to add it to "appearance/menus/custom links" and add a custom link.
    If this is not possible, then I'll likely add a div tag to the header and link to the backend dash. (I've added "wp admin bar removal" to clean up the site, but now I need a way for registered blog users/owners to easily get to their back end dashboard.)
    I'm open to other suggestions if you have any.
    Kind regards,
    Yohan

  • Ash
    • WordPress Hacker

    Well, try using the following file as mu-plugins, then you should not need to add menu items manually.

    function add_login_logout_link($items, $args)
    {
    
        $items . = '<li><a title="Admin" href="'. site_url().'/wp-admin' .'">Admin</a></li>';
        return $items;
    }
    add_filter('wp_nav_menu_items', 'add_login_logout_link', 10, 2);

    Please check if it works for you.

    Cheers
    Ash

  • Ash
    • WordPress Hacker

    FYI, 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 their. You don't need to activate that plugin. Mu-plugins means must use plugins, so it will be activated automatically always.

  • yohanaton
    • New Recruit

    Hi Ashok,
    Thanks so much for your help thus far.
    I really would just like to know how to create a link that would direct each user to various areas of their unique backend dashboard.
    As I've tried several variations, I think I'm missing something...
    Is this what your suggesting above?
    General Settings

    Should it be echo user site? or something along those lines? Or am I formatting it incorrectly?

    Thanks so much for your help & patience. Greatly appreciated,
    Yohan

  • Ash
    • WordPress Hacker

    When you see the white screen, then would you please enable debug mode?

    To enable debug mode please edit a line in your wp-config.php:
    Change

    define('WP_DEBUG', false);

    to

    define('WP_DEBUG', true);

    Then there should print an error instead of white screen.

    Please let me know.

    Cheers
    Ash

  • yohanaton
    • New Recruit

    Hi Ashok,
    The white screen was with the php file added.
    I'd really just like to be able to create the proper link structure as I want to add links to the back end dash in various places on the site.
    I just realized the last link I posted for you as a reference, turned into a live link and is not showing up... (general)
    It was
    a href=mydomain.com/echo site_url.'/wp-admin/options-general.php
    Am I writing this incorrectly or can you recommend another suggestion?
    Thanks so much,
    Yohan

  • yohanaton
    • New Recruit

    Hi Ashok,
    Thanks so much.
    This is what shows up in the header after changing debug and add the mu plugin back:
    function add_login_logout_link($items, $args) { $items . = '
    Admin
    '; return $items; } add_filter('wp_nav_menu_items', 'add_login_logout_link', 10, 2);
    Deprecated: Assigning the return value of new by reference is deprecated in /var/home/chelseanyc/chelseanyc.com/www/wp-content/plugins/login-redirect/login-redirect.php on line 146

    Deprecated: Assigning the return value of new by reference is deprecated in /var/home/chelseanyc/chelseanyc.com/www/wp-content/plugins/logout-redirect/logout-redirect.php on line 203

  • yohanaton
    • New Recruit

    Hi Ashok,
    Sorry, here's the correct output returned:
    Parse error: syntax error, unexpected '=' in /var/home/chelseanyc/chelseanyc.com/www/wp-content/mu-plugins/todash.php on line 5

    This is the code in the file:

    <?php
    function add_login_logout_link($items, $args)
    {

    $items . = '

  • Admin
  • ';
    return $items;
    }
    add_filter('wp_nav_menu_items', 'add_login_logout_link', 10, 2);

  • Ash
    • WordPress Hacker

    Cool try this please:

    function add_login_logout_link($items, $args)
    {
    
        $items .= '<li><a title=&quot;Admin&quot; href=&quot;'. site_url().'/wp-admin' .'&quot;>Admin</a></li>';
        return $items;
    }
    add_filter('wp_nav_menu_items', 'add_login_logout_link', 10, 2);

    Also when you write code in the forum, please make sure you wrap the code within the code tag.

    Cheers
    Ash

  • yohanaton
    • New Recruit

    Hi Ash,
    Thanks so much.
    I've created a new file (dotphp) with the code above and added it to the mu folder.
    What should be the link structure to link from the front end of my site to the logged in individual users dashboard?
    Thanks so much,
    Yohan

  • yohanaton
    • New Recruit

    Hi Ashok,
    Yes, "admin" has been added to all of my custom menu's.
    It does not link to the registered users back end dashboard.
    I'm super grateful that your helping me, but I the solution your providing does not fulfill my goal.
    I simply want to be able to create a link that I can place on my site, where I choose, that will link to the logged in, registered users dashboard.
    Is there a way to achieve this that you can recommend?
    Gratefully,
    Yohan

  • Ash
    • WordPress Hacker

    Hi @yohanaton

    To be more sure I have just tested in one of my test account. I am repeating the process again.

    function add_login_logout_link($items, $args)
    {
    
        $items .= '<li><a title="Admin" href="'. site_url().'/wp-admin' .'">Admin</a></li>';
        return $items;
    }
    add_filter('wp_nav_menu_items', 'add_login_logout_link', 10, 2);

    Add the above code in mu-plugins. I know you did already, just make sure the code matches.

    Then you will see a menu 'admin' in those subsites which are registering a nav from Appearance > Menus.

    Screenshot attached.

    You will see the url in bottom left corner.

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

    Cheers
    Ash

  • DavidM
    • DEV MAN’s Mascot

    Hi @yohanaton,

    Hope you don't mind my jumping in here, but from what I understand you're just trying to get the link you'd need for users to easily get to their respective dashboard on your network, is that correct?

    If so, you're basically correct in your original post, just without the index.php, as follows:
    yoursite.com/BLOG_PATH/wp-admin

    However, even with the index.php, it would still work.

    The issue though, is that the "BLOG_PATH" is dynamic. You would need a dynamic solution to be able to provide a link that takes into account the logged in user.

    That's what the code that Ash provided does, it's a dynamic solution that will take into account the logged in user and provide a link to their dashboard. It adds a link to your menu for that.

    Not sure if that was unclear, but using the code he provided should automatically add a menu item for that link.

    Does that help? If we've misunderstood you at all please feel free to let us know and we'll gladly see how we can clarify. :slight_smile:

    Cheers,
    David

  • yohanaton
    • New Recruit

    Hi Guys,
    Thanks so much for your help & patience.
    I can imagine this must be frustrating.
    I'll try to a little better to explain whats going on.
    1. When I add this to my MU folder, it creates an admin tab on all of my custom menu's
    --- I currently have 4 custom menu's, I would only want this "admin" link on the top menu.
    2. When I add this code to a php file and place it in my Mu folder the admin link goes to "http://mydomain.com/wp-admin" and the page is completely white.
    The goal should be to get to "http://mydomain.com/username/wp-admin" as when I enter this in the browser it goes to the right destination.
    3. I need to be able to create html links in the registered blog users dashboard to take them to various pages of theirs.
    4. If we can come up with a solution that has nothing to do with the menu's, I can create a div on the front of the site with a link that would go to the said users dashboard.
    5. I found this post here on wporg that seems to be relevant but I'm not sure how to implement it. http://wordpress.org/support/topic/multi-site-how-can-i-create-a-link-to-the-wordpress-users-admin-dashboard

    Thanks again for your help & patience,
    Yohan

  • DavidM
    • DEV MAN’s Mascot

    Hi @yohanaton,

    Thanks for your reply. Without having tested, I believe the following adaptation of Ash's snippet would work:

    function add_login_logout_link($items, $args)
    {
        global $current_user;
        get_currentuserinfo();
        $items .= '<li><a title="Admin" href="' . site_url() . '/' . $current_user->user_login . '/wp-admin' .'">Admin</a></li>';
        return $items;
    }
    add_filter('wp_nav_menu_items', 'add_login_logout_link', 10, 2);

    Before proceeding, would that sort of link work for ya?

    EDIT: Code fixed per bug report below. :wink:

    Thanks,
    David

  • DavidM
    • DEV MAN’s Mascot

    Hiya @yohanaton,

    Sorry for that! I should've been clearer. Could you simply replace the earlier code snippet with the above one and let us know how the link it provides works for you?

    We can then see about the other items you mentioned.

    Thanks,
    David

  • Ash
    • WordPress Hacker

    Good solution @David though it produces a 404 page in my test site.

    @yohanaton: If the above code works for you, you can modify the code with this:

    function add_login_logout_link($items, $args)
    {
        global $current_user;
        get_currentuserinfo();
        if($args->theme_location == 'LOCATION')
            $items .= '<li><a title="Admin" href="' . site_url() . '/' . $current_user->user_login . '/wp-admin/' .'">Admin</a></li>';
        return $items;
    }
    add_filter('wp_nav_menu_items', 'add_login_logout_link', 10, 2);

    Here LOCATION needs to be replaced with your desired custom menu location.

    For example, if you use in your theme:

    register_nav_menus( array(
    		'primary' => 'Primary Menu',
    		'secondary' => 'Secondayr Menu'
    	) );

    For creating menu, then primary or secondary is the menu location that is used in the theme.

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

    Cheers
    Ash

  • yohanaton
    • New Recruit

    Awesome!
    Ok, so now we've got the link to the dash to the logged in user in only the menu of choice. This is great!

    Now, what would be the correct html link structure so I can place links in the users dashboard that would go to their specific settings? (Various tabs are being covered by easy blogging.)
    Thanks so much for your help & patience,
    Yohan

  • DavidM
    • DEV MAN’s Mascot

    Hi @yohanaton,

    Glad Ash's snippet fixed that first issue for ya. Could you let us know where it is that you want those links to be?

    Also, could you let us know more precisely what the links are? Would they be links to specific dashboard urls? Maybe front-end urls?

    Thanks,
    David

  • yohanaton
    • New Recruit

    Hi David,
    I've got admin message installed, so theres a box available for text & html. That's where I would like to add multiple links.

    For example, I have "fundraising" installed. The tabs are all blocked by "easy blogging"

    The links I would like to access in fundraising are:
    http://mydomain.com/username/wp-admin/edit.php?post_type=funder
    http://mydomain.com/username/wp-admin/edit.php?post_type=donation
    http://mydomain.com/username/wp-admin/edit.php?post_type=funder&page=wdf_settings

    Same goes for several other plugins I have installed where the tab is being covered by easy blogging.

    You guys rock! Thank you so much,
    Yohan

  • be
    • WP Core Meltdown

    hey @yohanaton

    I wonder if you are referring here simply to easy blogging.

    If so you simply :slight_smile: need to go to..
    Easy blogging
    Menu items
    Scroll to add your new items and the
    URL PATH ( I think you may be seeking )
    The part after wp-admin... so would be
    edit.php?post_type=funder
    edit.php?post_type=donation

    etc

    In easy blogging its a few steps and you only get one go - ie there is no edit ...
    So if something is wrong you need to delete and make a new one..
    if you forgot an icon or a help message..or to assign it to a role..
    2 MORE steps..
    Then you need to save...
    Then you need to go back and check that item so its visible to whatever permission you set in their backend dashboard..

    If however you are not referring to "EASY BLOGGING" menu forget what I just said... :slight_smile:

  • yohanaton
    • New Recruit

    Hi be,
    Thanks for your reply.
    Yes, it is easy blogging.
    I've tried this and for some reason the new "menu" items that I add, do not get added.
    I've been thinking this is an issue with easy blogging or a conflict with something else on my site.
    This is actually where I originally got the idea to add "BLOG_PATH" to my urls.
    The link structure that works is
    http://mydomain.com/username/wp-admin/edit.php?post_type=donation

    The missing piece, seems to be "username", that would be the global substitute for which ever user is logged in.

  • be
    • WP Core Meltdown

    just checking are the items checked - ie the new item you added..
    And does it have a user role assigned..
    And are you checking with that user role or above
    ie subscriber and above... etc

    for some reason the forum is stripping out headers and sometimes link to plugin so folks don't know it relates to a specific plugin..

    If you are adding the entire path it will take everyone back there..
    If you want the global for subsites, it should just be the last part of the path..

    In some instances it is user specific then -
    users.php?

    See here its the path that is after and depends on
    So go to the page you want and take the last part..
    Make sure it is checked in the list which you can only do after you save it..

  • yohanaton
    • New Recruit

    Hi be,
    Thanks for all your help.
    When I:
    Add a title
    Add a url
    Add help
    Choose administrator & above,
    Add new item,
    The page will act as if its adding the item to the list above, however, nothing gets added to the list, hence the opportunity to add a check box next to it, to show is not an option.
    The "add menu items" just returns empty as if I hadn't just added a new menu item.

  • yohanaton
    • New Recruit

    Another way to go would be to remove tabs from the side bar.
    (deleting easy blogging)
    Found this script, ...

    function remove_admin_menu_items() {
            $remove_menu_items = array(__('Links'));
            global $menu;
            end ($menu);
            while (prev($menu)){
                $item = explode(' ',$menu[key($menu)][0]);
                if(in_array($item[0] != NULL?$item[0]:"" , $remove_menu_items)){
                unset($menu[key($menu)]);}
            }
        }
    
        add_action('admin_menu', 'remove_admin_menu_items');
  • yohanaton
    • New Recruit

    Hey David,
    Thanks so much!
    Picked up the pro version and I think this will do the trick.
    Gotta do some more testing tonight, but it's looking like the angels are singing!
    I'll shoot out a heads up to confirm in a little bit.
    Many thanks,
    Yohan

  • be
    • WP Core Meltdown

    Thankyou @DavidM

    @yohanaton

    Not sure here but it sounds like you may have a number of things altering the same menu area and that may be an issue.

    If "easy blogging" is not adding to the menu when you choose that tab then something is wrong..
    (theoretically - this can do what you are asking managed by a super admin dashboard) You cannot strip out parts of sections in some cases if they are a block layout eg: Top right hand admin Help and Screen options are a "set" so its both or none without a hack..)

    Or is the path you are trying to add one that you have hidden or disabled with either "easy blogging" or "Ultimate branding"?

    Easy blogging - easy blogging..

    Could you advise what you are trying to add that wont save -

  • yohanaton
    • New Recruit

    Hi David,
    I'm looking at "Ultimate Branding" and that may be the conflict with regard to "Easy Blogging". Not sure at this point, but regardless, "Admin Menu Editor Pro" is awesome! Wish I found it sooner, as this would have been an option as opposed to the "
    Mu-Admin" tab.
    Regardless, all seems to be good now.
    Thanks so much & Super Grateful,
    Yohan

  • DavidM
    • DEV MAN’s Mascot

    Excellent! Glad that's sorted. The thread was getting a bit tough to following being a bit lengthy. A new discussion usually helps with that but I'm glad everything's working to your satisfaction now @yohanaton.

    Thanks for letting us know.

    Cheers,
    David

  • be
    • WP Core Meltdown

    @yohanaton
    Thankyou for your kindness..
    I would note here.. it is important to know what you have changed where and by what means as down the track it can get mightily confusing when updates occur..

    So if you have used plugins (you know about conflicts etc and you can usually get support)
    If you have used code hacks you need to ensure you have them where you can get them later so you can update fields etc when/if things change ie wordpress codex or other hooks ...

    I'm looking at "Ultimate Branding" and that may be the conflict with regard to "Easy Blogging".

    They both can work side by side but depending on timing - some things can get unchecked or whatever..
    and if you add code hacks in the mix.. then sometimes things break or are doing the job differently and conflict with other things.
    Anyways onward and upward as they say.. :slight_smile:

  • yohanaton
    • New Recruit

    Hey folks,
    Sorry to beat a dead horse, but it seems there's an error with the "admin" mu plugin we created.
    When logged out state.
    I click "Admin" (The link we added to the top menu)
    This takes us to the standard wp login page. (back door)
    When entering u & p, I'm taken to the url,
    "mydomain.com//wp-admin"
    I realize I added the ' / ' to the mu plugin which takes us to the right place when clicking
    "admin" if were already loggged in.
    Could we either fix this so the back end login goes to the dash w/o "//", or simply make the "Admin" link invisible if the visitor is not logged in?
    Many thanks,
    Yohan

  • DavidM
    • DEV MAN’s Mascot

    Hi @yohanaton,

    Hehe, in programming I think the horse is never dead. It's beaten perpetually till infinity! :wink:

    How would this work?

    function add_login_logout_link($items, $args)
    {
    	if is_user_logged_in(){
    		global $current_user;
    		get_currentuserinfo();
    		if($args->theme_location == 'LOCATION')
    			$items .= '<li><a title="Admin" href="' . site_url() . '/' . $current_user->user_login . '/wp-admin/' .'">Admin</a></li>';
    		return $items;
    	}
    	return;
    }
    add_filter('wp_nav_menu_items', 'add_login_logout_link', 10, 2);

    It just adds a check to see if the user is logged in. Otherwise it does nothing.

    Cheers,
    David

  • yohanaton
    • New Recruit

    Sucks to be a code horse...
    Thanks so much for your reply.
    I've swapped out the previous for your new, changed 'location' to primary and all is going white... Guessing something simple is a miss...
    Here's the code that worked previously:

    <?php
    function add_login_logout_link($items, $args)
    {
        global $current_user;
        get_currentuserinfo();
        if($args->theme_location == 'primary')
            $items .= '<li><a title="Admin" href="' . site_url() . '/' . $current_user->user_login . '/wp-admin/' .'">My Site</a></li>';
        return $items;
    }
    add_filter('wp_nav_menu_items', 'add_login_logout_link', 10, 2);

    Any other ideas would be greatly appreciated.
    Thanks & best,
    Yohan

  • yohanaton
    • New Recruit

    Hi Ashok,
    Here is what I replaced the other one with that went "white"

    <?php
    function add_login_logout_link($items, $args)
    {
    	if is_user_logged_in(){
    		global $current_user;
    		get_currentuserinfo();
    		if($args->theme_location == 'primary')
    			$items .= '<li><a title="Admin" href="' . site_url() . '/' . $current_user->user_login . '/wp-admin/' .'">My Site</a></li>';
    		return $items;
    	}
    	return;
    }
    add_filter('wp_nav_menu_items', 'add_login_logout_link', 10, 2);

    Thanks so much,
    Yohan

  • DavidM
    • DEV MAN’s Mascot

    Hi @yohanaton,

    Sorry for the mess up there. I also didn't return the correct $items.

    The following should fix that for you.

    <?php
    function add_login_logout_link($items, $args)
    {
    	if (is_user_logged_in()){
    		global $current_user;
    		get_currentuserinfo();
    		if($args->theme_location == 'primary')
    			$items .= '<li><a title="Admin" href="' . site_url() . '/' . $current_user->user_login . '/wp-admin/' .'">My Site</a></li>';
    		return $items;
    	}
    	return $items;
    }
    add_filter('wp_nav_menu_items', 'add_login_logout_link', 10, 2);

    Thanks Ash, for catching those missing parens. :slight_smile:

  • yohanaton
    • New Recruit

    Hi David, Hi Ash,
    Sorry to return to this pain in the butt thread, seems I didn't catch an error that was happening. You were correct about the horse...

    When I upgrade a user from subscriber to vendor on mydomain.com, (woocommerce)
    The link we created no longer takes them to their site, it directs them instead as follows:
    "mydomain.com/user/wp-admin/" redirects to "http://mydomain.com/wp-admin/admin.php?page=woocommerce_reports"
    Here's the original mu plugin you guys got working for this link in the top nav bar.
    Any help or insight as to how to fix this would be greatly appreciated.
    Many thanks,
    Yohan

    <?php
    function add_login_logout_link($items, $args)
    {
    	if (is_user_logged_in()){
    		global $current_user;
    		get_currentuserinfo();
    		if($args->theme_location == 'primary')
    			$items .= '<li><a title="Admin" href="' . site_url() . '/' . $current_user->user_login . '/wp-admin/' .'">My Site</a></li>';
    		return $items;
    	}
    	return $items;
    }
    add_filter('wp_nav_menu_items', 'add_login_logout_link', 10, 2);
  • DavidM
    • DEV MAN’s Mascot

    Hi @yohanaton,

    Hmm, how might this work instead?

    <?php
    function add_login_logout_link($items, $args)
    {
    	if (is_user_logged_in()){
    		global $current_user;
    		get_currentuserinfo();
    		$blog = get_active_blog_for_user( $current_user->ID );
    		if($args->theme_location == 'primary')
    			$items .= '<li><a title="Admin" href="' . $blog->siteurl;
    			$items .= '/wp-admin/' .'">My Site</a></li>';
    		return $items;
    	}
    	return $items;
    }
    add_filter('wp_nav_menu_items', 'add_login_logout_link', 10, 2);
    ?>
  • DavidM
    • DEV MAN’s Mascot

    Hi @yohanaton,

    Thanks and Happy New Year as well! Hope this one's going great for you so far, let's see about making it even better by sorting this one out! :slight_smile:

    As the thread's gotten a bit lengthy, I'd like to be sure I understand fully what we've got now. Could I ask, in that menu, does the url at least display the respective user's primary blog and the /wp-admin/ link?

    Also, to be sure this isn't actually a redirect issue, can users access their blog dashboard at all?

    Could I ask what the general structure of the url is for those dashboards?
    ex: yoursite.com/blogname/wp-admin/

    Would that be roughly correct?

    Thanks,
    David

  • yohanaton
    • New Recruit

    Hi Guys, First off, thanks so much for jumping back in on this. I'm super grateful for your help:slight_smile:

    I just tried it again, and unfortunately, it's still redirecting in the same manner.

    David, forgive my if I'm not following correctly, but when hovering/mouse over the "My Site" link, the visual display in firefox/bottom left shows "mydomain.com/wp-admin" - As well, when the mouse is hovering over the text "My Site", the word "Admin" shows up as if it's alt text on an image.

    When I click it, "mydomain.com/wp-admin/" shows up first in the browser, it tries to load, and then seems to redirect to "mydomain.com/wp-admin/admin.php?page=woocommerce_reports"

    Again, I can't thank you guys enough for all your help.

  • DavidM
    • DEV MAN’s Mascot

    Hi @yohanaton,

    Hmm, I think I may be misunderstanding something here.

    Could you possibly grant me access to the site to see how that works and how exactly it needs to work?

    That way I could get it sorted really quickly for you.

    If so, you can simply go in your Dashboard to WPMU DEV > Support > Support Access and press the Grant Access button.

    Thanks,
    David

  • DavidM
    • DEV MAN’s Mascot

    Hi @yohanaton,

    Thanks for sending that through. Could you please double check to ensure you've actually updated the code snippet I last posted, again here:

    <?php
    function add_login_logout_link($items, $args)
    {
    	if (is_user_logged_in()){
    		global $current_user;
    		get_currentuserinfo();
    		$blog = get_active_blog_for_user( $current_user->ID );
    		if($args->theme_location == 'primary')
    			$items .= '<li><a title="Admin Dashboard" href="' . $blog->siteurl;
    			$items .= '/wp-admin/' .'">My Site</a></li>';
    		return $items;
    	}
    	return $items;
    }
    add_filter('wp_nav_menu_items', 'add_login_logout_link', 10, 2);
    ?>

    The link is currently going to the following:
    username/wp-admin/

    But with that snippet, it should be going here
    blog-name/wp-admin/

    Which seems to indicate that you're still using that previous snippet.

    Could you let us know?

    Thanks,
    David

  • yohanaton
    • New Recruit

    Hi David,
    Sorry for the confusion. I put the snippet back to where it was last week to start from a bench mark...
    I did test the revision out several times though and it didn't act as desired.
    I'll put back in the latest snippet for you to look at though.
    Would it be helpful for you to have ftp info?
    Many thanks,
    Yohan

  • yohanaton
    • New Recruit

    Hi David,
    Thanks for your reply
    I've put your latest snippet in and have left it in place for you.
    unfortunately it's still not behaving as desired.
    I was referring to the count and placement of the two versions of quotes...
    ' "
    Clearly, I'm no expert...
    Thanks so much for all your help,
    Yohan

  • DavidM
    • DEV MAN’s Mascot

    Hi @yohanaton,

    Thanks for replacing that code, seems to have worked perfectly!

    The issue though, was that your user account 'al43s' didn't have a primary site setup.

    In Multisite, the first site a user creates will be designated as their 'primary' site. That user account didn't have a primary site specified, not sure why.

    To fix that, I used that account to login and to go to Dashboard > My Sites and select the 'al43s2' as that user's primary site.

    The snippet then works to link to that user's primary site,

    I hope you won't mind, but I changed the user's password, so the account is now as follows:

    user: al43s
    pass: al43s

    Could I ask that you change that now, back to whatever you may have had that as before?

    And I believe that should sort this. Users who create new sites should automatically be linked to their primary site. :slight_smile:

    Just let us know if you have questions or concerns about this.

    Thanks,
    David

  • yohanaton
    • New Recruit

    Hi David,
    Thanks again for all your help. I'm super grateful.
    It seems there's still a challenge though.
    As I anticipate some users will not have sites - most will just be registered users on the main site.
    So when I delete the site allocated for user al43s
    And then click mysites on the top of the home page. The user al43s is taken to
    http://mydomain.com/wp-admin/admin.php?page=woocommerce_reports
    These should be off limits to all but super admin
    So if the user doesn't have a site, the link should probably not appear in the menu or I should link it to a page where people can request a site.
    Is there a way to remove the mysite link for users that don't have a site?

  • DavidM
    • DEV MAN’s Mascot

    Hi @yohanaton,

    This should sort it:

    <?php
    function add_login_logout_link($items, $args)
    {
    	if (is_user_logged_in()){
    		global $current_user;
    		get_currentuserinfo();
    		$blog = get_active_blog_for_user( $current_user->ID );
    		if($blog->siteurl == network_site_url()) {
    			if($args->theme_location == 'primary')
    				$items .= '<li><a title="Admin" href="' . $blog->siteurl . '/wp-admin/' .'">My Site</a></li>';
    		}
    		return $items;
    	}
    	return $items;
    }
    add_filter('wp_nav_menu_items', 'add_login_logout_link', 10, 2);
    ?>

    It shouldn't display anything if the user has no primary site.

    Let us know how that works for ya! :slight_smile:

    -David

  • yohanaton
    • New Recruit

    Hi David,
    Thanks so much.
    Seems the "my sites" link is totally gone now... (For admin, as well as when I create users & sites)
    As well,
    If admin creates a user
    Then admin creates a site for the user.
    How / where do I go as admin to assign the new site as their primary site?
    Does the new user have to login from the auto email they get and goto:dashboard/mysites/ => choose primary site?
    Thanks so much for your help & patience,
    Yohan

  • yohanaton
    • New Recruit

    Hi David, Hi Ash,
    Just wanted to reach out. I began playing around and digging deeper in wp toolbar editor and menu editor and have come up with a solution that seems to work at the moment. It means I will have to keep the toolbar menu showing, and while not my first choice, I'll take it.
    I'm super appreciative of all your help on this thread and hopefully... this will be the end.
    Gratefully,
    Yohan

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.