Support » Networking WordPress » Adminbar needs to link to users primary blog

  • Hi!

    I have a multisite set up and when a user is logged in the adminbar is always visible on top.

    However I need it to always point to the users primary blog. If a user today clicks a link while visiting another site in the network they get the white screen that asks the user where it want’s to go, since it has no access to the current site’s adminpanel.

    Any ideas?

Viewing 6 replies - 1 through 6 (of 6 total)
  • Moderator Ipstenu (Mika Epstein)


    Lead Plugin Wrangler

    The toolbar should have a “My Sites” – doesn’t it? No matter what site a user visits, the link to their own blog(including primary) is there. I can’t see a link in the toolbar a user would click on to get them to the “are you lost” white page while visiting another’s blog. Are you using a plugin to add other links or customize the toolbar?

    Here is another tact. Let’s say you do not want to land on the access denied page at all and want WP to immediately redirect to the dashboard url.

    Something like this as an mu-plugin might work:

    function my_access_denied_splash() {
    			$user_id = get_current_user_id();
    			$redirect = get_dashboard_url( $user_id );
    			wp_redirect( $redirect );
    add_action( 'admin_page_access_denied', 'my_access_denied_splash', 99 );


    Thanks for the suggestions! Forgot to mention that the menu items have been customized heavily so that’s why there is no “My Sites”-menu.

    The last suggestion works pretty well, maybe as good as it gets right now?

    The only “problem” is that if I try to go to my profile or Create a new post, I always land on the dashboard. So is it possible to find out what url the user requested and use that in the code?

    You said “the menu items have been customized heavily”.

    Is that why …

    you said “if I try to go to my profile or Create a new post, I always land on the dashboard”?

    Where do you see a link to profile or create a new post that you would trigger the access denied message anyway? That needs the fix, not a work around.

    If you are adding customized links to your toolbar that go to the wrong blog, that needs the fix. Give us a taste of the code you are using to add these menu items and we can troubleshoot that so there are fewer access denied redirects needed.

    Here is a taste of my toolbar code I offer to you that gets me a link to my primary “New Post” and “Profile” no matter which blog I happen to be visiting.

    function my_primary($wp_toolbar){
    	if (is_multisite() && is_user_logged_in()) {
    		$user_id = get_current_user_id();
    		$primary_blog = get_active_blog_for_user( $user_id );
    			if($primary_blog) {
    				$primary_url = 'http://'.$primary_blog->domain . $primary_blog->path;
    				$admin_url = $primary_url.'wp-admin/';
    			} else {
    				$admin_url = get_dashboard_url( $user_id );
    				'id' 		=> 'primary',
    				'title'		=> $primary_blog->blogname,
    				'href' 		=> '',
    				'meta' 		=> '',
     			'id'		=> 'newpost',
     			'title' 	=> 'New Post',
     			'parent'	=> 'primary',
    			'href' 		=> $admin_url .'post-new.php',
     			'id'		=> 'pprofile',
     			'title' 	=> 'Profile',
     			'parent'	=> 'primary',
    			'href' 		=> $admin_url .'profile.php',
    add_action('admin_bar_menu', 'my_primary', 999);
Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Adminbar needs to link to users primary blog’ is closed to new replies.