WordPress.org

Ready to get started?Download WordPress

Forums

Adminbar needs to link to users primary blog (7 posts)

  1. osby
    Member
    Posted 1 year ago #

    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?

  2. David Sader
    Member
    Posted 1 year ago #

    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?

  3. David Sader
    Member
    Posted 1 year ago #

    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 );
    			exit;
    }
    add_action( 'admin_page_access_denied', 'my_access_denied_splash', 99 );
  4. osby
    Member
    Posted 1 year ago #

    Hi!

    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?

  5. David Sader
    Member
    Posted 1 year ago #

    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.

  6. David Sader
    Member
    Posted 1 year ago #

    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 );
    			}
    
    	$wp_toolbar->add_node(array(
    				'id' 		=> 'primary',
    				'title'		=> $primary_blog->blogname,
    				'href' 		=> '',
    				'meta' 		=> '',
    			));
    	$wp_toolbar->add_node(array(
     			'id'		=> 'newpost',
     			'title' 	=> 'New Post',
     			'parent'	=> 'primary',
    			'href' 		=> $admin_url .'post-new.php',
    			));
    	$wp_toolbar->add_node(array(
     			'id'		=> 'pprofile',
     			'title' 	=> 'Profile',
     			'parent'	=> 'primary',
    			'href' 		=> $admin_url .'profile.php',
    			));
    	}
    }
    add_action('admin_bar_menu', 'my_primary', 999);

Topic Closed

This topic has been closed to new replies.

About this Topic