Help with BP multisite menu.

I have subsites in my multisite. I have BuddyPress network enabled. I want to have a link on the subsite menu that links back to the logged-in member’s BP menu (on the main site, FROM the sub-site) if the member is part of both sites. Please check and help with this.

  • Adam
    • Support Gorilla

    Hi Peter Fae

    I hope you’re well today!

    By ‘BuddyPress Network” you mean that there are separate BP instances “per site” if I remember correctly (I think we’ve worked on that together some time ago), right?

    If yes, then I’m afraid that would require some custom coding. The whole point of such setup is to keep BP instances separate. With a regular default BP, network activated, it would always link to profile on the main site – by default. But it would also be “one BP per entire network”.

    Such standard BP can also be set to “multisite” which doesn’t change much in how it works except all the BP pages are kind of “duplicated” on sub-sites. So, it’s still one single “network-wide” setup but with profile and members’ pages available directly on sub-sites.

    A “network” setup with separate BP instances makes it actually separate instances so you would need a custom code. If I’m not mistaken a “bp_core_get_userlink” filer could help.

    I think this “skeleton code” could be a good starting point:

    function bp_custom_author_link($url, $user_id){
    
        
    	$is_main_site_member = false; // assume not a member of main site
    	
    	// here come the code to check if member is a member of main site too
    	// based on #user_id
    	// and if so set
    	// $is_main_site_member = true;
    	
    	if ( is_main_site_member ) {
    		// build your URL to the main site here
    		$url = "url_to_return_here";
    	}
    	
    		
    	return $url  
    
    }
    add_filter( 'bp_core_get_userlink', 'bp_custom_author_link', 10, 2 );

    but it would have to be further expanded to do the job. I’m afraid that would require custom coding which goes a bit outside the scope of this forum.

    Kind regards,
    Adam

  • Peter Fae
    • Site Builder, Child of Zeus

    Hey Adam. maybe I’m not understanding what you’re saying or what I’m saying isn’t being understood.

    I’m okay with Buddypress being on the main site and links on sub-sites going back to the main site.

    What I want is to have a custom link in the menu that takes a user *from* the sub-site to whatever their profile is on the main buddypress site.

    Like, let’s say ‘User X’ is logged into ‘Site Y’. They click the ‘Profile’ link, which is in the menu, and are taken *from* Site Y to their profile (User X) on the main site. Simple.

    Is that code appropriate for that?

  • Adam
    • Support Gorilla

    Hi Peter Fae

    Thanks for response and I’m sorry for confusion.

    It seems that misunderstood the point here. I checked your site again and it seems you already have a standard BP installation there, network-enabled, and not a BuddyPress Multi Network as I initially assumed (not sure why, sorry about that).

    With such an install, the default behavior is like that:

    – BuddyPress is “network wide”
    – but it always operates on the main site
    – so all users of all the sites on network are “BuddyPress Members” out of the box
    – but all the BuddyPress pages, including members’ profiles, are within main site

    There are links to all BuddyPress pages already automatically included in the “profile links” in the admin toolbar (so when you hover over “Howdy, user” or your avatar on toolber, upper-right corner). The links point to main site already and they would be visible in back-end and, if toolbar is enabled that way, on front-end too. That might, however, be set that way (toolbar visibility) on some sites only and/or limited to specific user roles.

    I understand, though, that what you want to do is to be able to add specifically a profile link to any standard menu on any sub-site, right?

    On main site, there are already “BuddyPress” links available in “Appearance -> Menus” page so you can simply add them just like any other menus. But it’s not available on sub-sites, indeed, so we would need additional code. Would you try this?

    1. create an empty file with .php extension (e.g. “my-bp-profile-links.php”:wink:
    2. copy and paste this code into that file

    <?php 
    
    function wpmu_bp_user_links_multisite( $menu_items ) {
    
        $placeholders = array(
            '#bp_profile_link#' => array(
    		'content' => bp_loggedin_user_domain(),
            ),
        );
    
        foreach ( $menu_items as $menu_item ) {
    
            if ( isset( $placeholders[ $menu_item->url ] ) ) {
    
                $placeholder = $placeholders[ $menu_item->url ];
    
    			$menu_item->url = $placeholder['content'];
                
            }
        }
    
        return $menu_items;
    }
    add_filter( 'wp_nav_menu_objects', 'wpmu_bp_user_links_multisite' );

    3. upload the file to the “/wp-content/mu-plugins” folder of the site via FTP or cPanel File Manager; if there’s no “mu-plugins” directly in “wp-content”, create that folder first

    4. now on any sub-site where you want to add a link:

    – go to “Appearance -> menus”
    – add a new “Custom Link” to any menu you want it to appear
    – give it any label you want
    – and in an URL field put this placeholder:

    #bp_profile_link#

    Once you save menu, the link should appear in the menu on front-end of that (sub)site, leading to the BP member page of the currently logged in member.

    Would that work for you?

    Best regards,
    Adam