BuddyDev

Search

[Resolved] Default Tab for Connected Members

Tagged: 

  • Participant
    Level: Initiated
    Posts: 13
    Matthew Ling on #35222

    Hi, Is there a way to make a tab the default tab for members that are connected? In other words, if I’m not connected with someone the tab I see would be their profile, but once I’m connected with them the default tab I land on when visiting their page is a different tab that is not visible to uncommected members? Is this possible?

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2935
    Ravi on #35229

    Hello Matthew,

    Thank you for posting. Please try the following code and modify as per your requirement.

    
    
    /**
     * Modify default tab.
     */
    function buddydev_modify_default_tab() {
    
    	if ( ! is_user_logged_in() || bp_is_my_profile() || ! bp_is_active( 'friends' ) ) {
    		return;
    	}
    
            // If both are friends set default tab to profile otherwise activity.
    	if ( friends_check_friendship( bp_loggedin_user_id(), bp_displayed_user_id() ) ) {
    		define( 'BP_DEFAULT_COMPONENT', 'profile' );
    	} else {
    		define( 'BP_DEFAULT_COMPONENT', 'activity' );
    	}
    }
    
    add_action( 'bp_setup_globals', 'buddydev_modify_default_tab', 15 );
    
    

    Please let me know if it works or not.

    Regards
    Ravi

  • Participant
    Level: Initiated
    Posts: 13
    Matthew Ling on #35231

    Ok, thanks so much. Just to be sure, what php file should this be added to?

  • Keymaster
    (BuddyDev Team)
    Posts: 24212
    Brajesh Singh on #35235

    Hi Matthew,
    Please put it in the bp-custom.php
    https://buddydev.com/docs/buddypress-guides/what-is-bp-custom-php/

    Regards
    Brajesh

  • Participant
    Level: Initiated
    Posts: 13
    Matthew Ling on #35251

    Hi, unfortunately I haven’t been able to get this to work. Here are the contents of my bp-custom file.

    <?php

    add_filter( ‘bp_auto_friendship_pro_enable_on_user_register’, ‘__return_true’ );

    /**
    * Modify default tab.
    */
    function buddydev_modify_default_tab() {

    if ( ! is_user_logged_in() || bp_is_my_profile() || ! bp_is_active( ‘friends’ ) ) {
    return;
    }

    // If both are friends set default tab to profile otherwise activity.
    if ( friends_check_friendship( bp_loggedin_user_id(), bp_displayed_user_id() ) ) {
    define( ‘BP_DEFAULT_COMPONENT’, ‘my-survey’ );
    } else {
    define( ‘BP_DEFAULT_COMPONENT’, ‘profile’ );
    }
    }

    add_action( ‘bp_setup_globals’, ‘buddydev_modify_default_tab’, 15 );

    FYI – the auto connect users is working correctly. it is the default tab to display if two people are connecting that I can’t figure out.

    Any help is greatly appreciated. Thanks, Matt

  • Participant
    Level: Initiated
    Posts: 13
    Matthew Ling on #35252

    Hi, unfortunately I haven’t been able to get this to work. Here are the contents of my bp-custom file.
    Sorry if this is a duplicate, not sure if the code would have been received because I didnt use the `.

    <?php
    
    add_filter( 'bp_auto_friendship_pro_enable_on_user_register', '__return_true' );
    
    /**
     * Modify default tab.
     */
    function buddydev_modify_default_tab() {
    
    	if ( ! is_user_logged_in() || bp_is_my_profile() || ! bp_is_active( 'friends' ) ) {
    		return;
    	}
    
            // If both are friends set default tab to profile otherwise activity.
    	if ( friends_check_friendship( bp_loggedin_user_id(), bp_displayed_user_id() ) ) {
    		define( 'BP_DEFAULT_COMPONENT', 'connections' );
    	} else {
    		define( 'BP_DEFAULT_COMPONENT', 'profile' );
    	}
    }
    
    add_action( 'bp_setup_globals', 'buddydev_modify_default_tab', 15 );

    FYI – the auto connect users is working correctly. it is the default tab to display if two people are connected that I can’t figure out.

    Any help is greatly appreciated. Thanks, Matt

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2935
    Ravi on #35253

    Hello Mathew,

    It seems you are using BuddyBoss. What they are doing is overriding default component with nouveau option. Try the following code it will override default tab in nouveau settings.

    
    
    /**
     * Modify default tab.
     */
    function buddydev_modify_default_tab( $tab ) {
    
    	if ( ! is_user_logged_in() || bp_is_my_profile() || ! bp_is_active( 'friends' ) ) {
    		return $tab;
    	}
    
    	// If both are friends set default tab to profile otherwise activity.
    	if ( friends_check_friendship( bp_loggedin_user_id(), bp_displayed_user_id() ) ) {
    		return 'friends';
    	}
    
    	return 'profile';
    }
    
    add_filter( 'bp_member_default_component', 'buddydev_modify_default_tab' );
    
    

    Regards
    Ravi

  • Participant
    Level: Initiated
    Posts: 13
    Matthew Ling on #35254

    Ok, so should this replace the previous code or be in addition to the previous code?

  • Participant
    Level: Initiated
    Posts: 13
    Matthew Ling on #35255

    Actually that code gave me the following error. Parse error: syntax error, unexpected ‘ ‘ (T_STRING) in /home/customer/www/youryous.com/public_html/wp-content/plugins/bp-custom.php on line 10

  • Participant
    Level: Initiated
    Posts: 13
    Matthew Ling on #35256

    Disregard the msg about the error. Still working on the issue.

You must be logged in to reply to this topic.

This topic is: resolved