BuddyDev

Search

Issue with provided code (profile tab depending to member type)

  • Participant
    Level: Enlightened
    Posts: 38
    Beuza on #12247
    This reply has been marked as private.
  • Keymaster
    (BuddyDev Team)
    Posts: 24583
    Brajesh Singh on #12249
    This reply has been marked as private.
  • Keymaster
    (BuddyDev Team)
    Posts: 24583
    Brajesh Singh on #12258

    Please use the following code instead.

    
    
    /**
     * Remove groups from user profile based on member type.
     */
    function buddydev_remove_group_based_on_member_types() {
    	if ( ! bp_is_user() ) {
    		return;
    	}
    
    	$user_id = bp_displayed_user_id();
    
    	if ( ! bp_has_member_type( $user_id, 'agent' ) ) {
    		bp_core_remove_nav_item( 'groups' );
    
    		$access = bp_core_can_edit_settings();
    		$friends_link = bp_displayed_user_domain()? bp_displayed_user_domain() : bp_loggedin_user_domain();
    		$friends_link = trailingslashit( $friends_link . bp_get_friends_slug() );
    		bp_core_new_subnav_item(array(
    			'name'            => __( 'Invitations', 'buddypress' ),
    			'slug'            => 'invites',
    			'parent_url'      => $friends_link,
    			'parent_slug'     => bp_get_friends_slug(),
    			'screen_function' => 'buddydev_groups_screen_group_invites',
    			'user_has_access' => $access,
    			'position'        => 30
    		));
    		// move the invitations to the friends screen.
    	}
    }
    
    add_action( 'bp_setup_nav', 'buddydev_remove_group_based_on_member_types', 1001 );
    
    /**
     * Helps us detect screen.
     */
    function buddydev_groups_screen_group_invites() {
        add_action( 'groups_screen_group_invites', 'buddydev_load_invite_template' );
    	groups_screen_group_invites();
    }
    
    /**
     * Load our template.
     */
    function buddydev_load_invite_template() {
        add_action( 'bp_template_content', function () {
            bp_get_template_part('members/single/groups/invites');
        });
    
    	bp_core_load_template('members/single/plugins' );
    }
    
    /**
     * Change the invite link url for the non 'agent' users.
     *
     * @param string $link original link.
     *
     * @return string
     */
    function buddydev_update_group_invite_link( $link ) {
        // for agent, do not break it.
        if ( bp_has_member_type( bp_loggedin_user_id(), 'agent' ) ) {
           return $link;
        }
    
    	global $groups_template;
    
    	if ( empty( $group ) ) {
    		$group =& $groups_template->group;
    	}
    
    	$friends_url = bp_loggedin_user_domain() . bp_get_friends_slug() .'/invites/';
    	$url         = trailingslashit( $friends_url . 'accept/' . $group->id );
    	$url         = add_query_arg( array( 'redirect_to' => $friends_url  ), $url );
    
    	//
    	return wp_nonce_url( $url, 'groups_accept_invite' );
    }
    
    add_filter( 'bp_get_group_accept_invite_link', 'buddydev_update_group_invite_link' );
    
    /**
     * Change the reject link url for the non 'agent' users.
     *
     * @param string $link original link.
     *
     * @return string
     */
    function buddydev_update_group_reject_link( $link ) {
        // for agent, do not break it.
        if ( bp_has_member_type( bp_loggedin_user_id(), 'agent' ) ) {
           return $link;
        }
    
    	global $groups_template;
    
    	if ( empty( $group ) ) {
    		$group =& $groups_template->group;
    	}
    
    	$friends_url = bp_loggedin_user_domain() . bp_get_friends_slug() .'/invites/';
    	$url         = trailingslashit( $friends_url . 'reject/' . $group->id );
    	$url         = add_query_arg( array( 'redirect_to' => $friends_url ), $url );
    
    	return wp_nonce_url( $url, 'groups_reject_invite' ) ;
    }
    
    add_filter( 'bp_get_group_reject_invite_link', 'buddydev_update_group_reject_link' );
    
    /**
     * Remove groups from adminbar based on member type.
     *
     * @param array $nav nav items.
     *
     * @return array
     */
    function buddydev_filter_show_hide_groups_in_adminbar( $nav ) {
    	if ( ! is_user_logged_in() ) {
    		return $nav;
    	}
    
    	if ( ! bp_has_member_type( bp_loggedin_user_id(), 'agent' ) ) {
    		$nav = array();
    	}
    
    	return $nav;
    }
    
    add_filter( 'bp_groups_admin_nav', 'buddydev_filter_show_hide_groups_in_adminbar' );
    
    

    It will work if you try to accept from the Friends->Invites screen.

    Problem:-
    – I don’t see a way for filtering the link in the email notification.
    – You also need code for filtering the link in the local notification(atleast 2 more filters).

    Regards
    Brajesh

  • Participant
    Level: Enlightened
    Posts: 38
    Beuza on #12261

    First view it works in Friends-> Invites screen!
    Thank you so much Brajesh! You have already done a lot!

    Beuza

  • Keymaster
    (BuddyDev Team)
    Posts: 24583
    Brajesh Singh on #12274

    No problem. I am glad It finally worked. I wish there was a way to filter email notification link.

  • Participant
    Level: Initiated
    Posts: 1
    Zigomar on #40092

    HI,
    I doesn’t work with your snippet below. I tried to remove it for one of my two member types. Still showing.
    I just want the “Add Create Group sub nav to User Profile->Groups screen” for one member type only.

    Thanks

    /**
    * Add Create Group sub nav to User Profile->Groups screen
    */
    function buddydev_custom_add_create_group_tab_to_profile_nav() {

    if ( ! bp_is_my_profile() ) {
    return;
    }
    $slug = bp_get_groups_slug();
    $access = bp_core_can_edit_settings() && bp_user_can_create_groups();
    $groups_link = trailingslashit( bp_core_get_user_domain() . $slug );

    bp_core_new_subnav_item(
    array(
    ‘name’ => __( ‘Create’ ),
    ‘slug’ => ‘create-group’,
    ‘parent_slug’ => $slug,
    ‘parent_url’ => $groups_link,
    ‘position’ => 1010,
    ‘user_has_access’ => $access,
    ‘screen_function’ => function () {
    },
    ‘show_in_admin_bar’ => false,
    ‘link’ => trailingslashit( bp_get_groups_directory_permalink() . ‘create’ ),
    )
    );
    }

    add_action( ‘bp_groups_setup_nav’, ‘buddydev_custom_add_create_group_tab_to_profile_nav’, 100 );

  • Keymaster
    (BuddyDev Team)
    Posts: 24583
    Brajesh Singh on #40094

    Hi Zigomar ,
    Welcome to BuddyDev.

    Please open a new topic and reference to this one. It has been resolved for a long time and creating a new topic will help us assit you better.

    Also, Please use backticks(`) to enclose the code.

    Regards
    Brajesh

You must be logged in to reply to this topic.

This topic is: not resolved