Skip to:
Content
Pages
Categories
Search
Top
Bottom

[Resolved] Changing from a slug to a dynamic url


  • wolfpup64
    Participant

    @wolfpup64

    Hey Buddies, first off the obligatory I’m totally new to this stuff, php makes sense but I haven’t the faintest grasp of the language or the logic. I got asked to build a community page for a smallish company and I’ll hopefully get a position more fitting my background if I do a decent job.

    Running:
    Current version of WordPress/BuddyPress
    The BuddyBoss Boss. Theme
    gVectors wpForo

    Basically what I’m trying to do is create a link in the BuddyPress Profile page tabs that directs to the wpForo forum profile, to better integrate the 2 profiles. I managed to create the tab by bogarting some code from some other support page, however the link is dictated by a slug and if I remove the slug the whole tab disappears. The code is located in a mu-plugin and this is what it looks like:

    function add_communityprofile_tab() {
    	global $bp;
    	
    	bp_core_new_nav_item( array(
    		'name'                  => 'Community',
    		'slug'                  => 'communityprofile',
    		'parent_url'            => $bp->displayed_user->domain,
    		'parent_slug'           => $bp->profile->slug,
    		'screen_function'       => 'communityprofile_screen',			
    		'position'              => 200,
    		'default_subnav_slug'   => 'communityprofile'
    	) );
    
    }
    add_action( 'bp_setup_nav', 'add_communityprofile_tab', 100 );

    The url of the profile pages is

    http://localhost/wordpress/users/*username*/profile/

    The tab naturally links to

    http://localhost/wordpress/users/admin/communityprofile/

    what I am trying to link to is

    http://localhost/wordpress/community/profile/<displayed_user>/

    at least I’m pretty sure displayed_user would get the job done.

    I looked into exploding and parsing the URL but that seemed more trouble than it was worth. I’ve spent quite a bit of time stubbornly trying to figure this out hahaha. But I think this is something that anyone with a decent knowledge of what they are doing could solve quickly, I’d really appreciate it if someone could give me a hand.

Viewing 11 replies - 1 through 11 (of 11 total)

  • shanebp
    Moderator

    @shanebp

    Try:

    function communityprofile_screen() {
       bp_core_redirect( site_url( '/community/profile/' . bp_displayed_user_username() ) );
    }

    wolfpup64
    Participant

    @wolfpup64

    Thanks for getting back to me shane, unfortunately that redirects to the wpForo page:

    http://localhost/wordpress/community/


    wolfpup64
    Participant

    @wolfpup64

    bump for some love?


    danbp
    Participant

    @danbp

    Hi,
    Shane’s answer is related to the BP way to get a user name inside a redirection. wpF use probably a similar method, but certainly also his own function(s) for that. You have to find out how it does. Unfortunately, this plugin doesn’t provide documentation at the moment.

    Accordingly to wpForum support, there is still a button to wpforum on each profile. If you have difficulties to tweak the default behave, you have to ask for on their support.

    https://wordpress.org/support/topic/buddypress-compatibility-plans/


    wolfpup64
    Participant

    @wolfpup64

    Theres a button to the site profile from the wpforo profile, but not vice versa.

    Thanks for the help though, I’ll check in with wpForo support and see if they can’t help me out.


    danbp
    Participant

    @danbp

    Perhaps this one may work: <a href="'. bp_get_loggedin_user_link() .'">View my profile</a>

    Reference


    wolfpup64
    Participant

    @wolfpup64

    That seems to work for pulling the appropriate user, I input it into the line shane provided

    function communityprofile_screen() {
       bp_core_redirect( site_url( '/community/profile/'.bp_get_loggedin_user_link()() ) );
    }

    but it looks like it gets overwritten by the slug in the aforementioned code that makes the tab appear and leads me to the url:

    http://localhost/wordpress/users/*username*/communityprofile/

    once again, if I try to remove the slug from the line the tab itself disappears. oh man this has been frustrating.


    wolfpup64
    Participant

    @wolfpup64

    oh wait no, thats what it was giving me in the first place…

    arrhhggh. I’ve got it down like this.

    function add_communityprofile_tab() {
    	global $bp;
    	
    	bp_core_new_nav_item( array(
    		'name'                  => 'Community',
    		'slug'                  => 'communityprofile',
    		'parent_url'            => $bp->displayed_user->domain,
    		'parent_slug'           => $bp->profile->slug,
    		'screen_function'       => 'communityprofile_screen',			
    		'position'              => 200,
    		'default_subnav_slug'   => 'communityprofile'
    	) );
    }
    function communityprofile_tab() {
       bp_core_redirect( site_url( '/community/profile/'.bp_get_loggedin_user_link()() ) );
    }
    add_action( 'bp_setup_nav', 'add_communityprofile_tab', 100 );

    danbp
    Participant

    @danbp

    Ok, i misunderstood the whole… The initial question was:
    what I am trying to link to is
    http://localhost/wordpress/community/profile/<displayed_user>/

    Try this:

    function tab_custom_link_to_page() {
    
    	if ( bp_is_activity_component() || bp_is_page( BP_MEMBERS_SLUG ) ) {
    
    		// link to what you want		
    		$link = bp_get_root_domain() . '/community/profile/'. bp_get_displayed_user_username();
    		echo '<li><a href="'. $link .'">Community</a></li>'; 
    	}  
    }
    add_action( 'bp_member_options_nav', 'tab_custom_link_to_page' );

    wolfpup64
    Participant

    @wolfpup64

    yo my god my dude, you are the best. merci! I certainly owe you beers.


    danbp
    Participant

    @danbp

    Don’t tell me that: i’m a beer fan ! You’re welcome 😉

Viewing 11 replies - 1 through 11 (of 11 total)
  • You must be logged in to reply to this topic.
Skip to toolbar