Skip to:
Content
Pages
Categories
Search
Top
Bottom

How to make a custom add friend link in buddypress


  • jaybee08
    Participant

    @jaybee08

    Hi buddypress users,

    I would like ask if someone had done this before where a custom link created for adding a friend.

    I had installed this plugin “BuddyPress Extended Friendship Request” and need to make a custom link somewhere on the members header template.

    What I would like to achieve is to have an “add a friend” link using an icon.

    I have tried this code below:

    <?php $btn?>" rel="add" title="buddy request" href="<?php global $bp; echo wp_nonce_url( bp_loggedin_user_domain() . bp_get_friends_slug() .'/add-friend/' . $_POST['fid'], 'friends_add_friend' ) ?>"

    but it didn’t work out.

    When i hover the add friend icon I got this link http://mysite.com/all-members/janitor/friends/add-friend/?_wpnonce=c4231b4ca5, but when you click it is redirect me to a blank white page where it should supposed to be a pop-up frame just like on the members directory add a friend button.

    Any help would be greatly appreciated. Thanks a lot

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

  • Henry Wright
    Moderator

    @henrywright

    Hi @jaybee08

    Building the link isn’t straightforward because there are a number of cases to consider. To take all of the conditions into account it is necessary to use a switch statement like this:

    $is_friend = bp_is_friend( $potential_friend_id );
    
    if ( empty( $is_friend ) )
        return false;
    
    switch ( $is_friend ) {
        case 'pending' :
            $link = wp_nonce_url( bp_loggedin_user_domain() . bp_get_friends_slug() . '/requests/cancel/' . $potential_friend_id . '/', 'friends_withdraw_friendship' );
        break;
    
        case 'awaiting_response' :
            $link = bp_loggedin_user_domain() . bp_get_friends_slug() . '/requests/';
        break;
    
        case 'is_friend' :
            $link = wp_nonce_url( bp_loggedin_user_domain() . bp_get_friends_slug() . '/remove-friend/' . $potential_friend_id . '/', 'friends_remove_friend' );
        break;
    
        default:
            $link = wp_nonce_url( bp_loggedin_user_domain() . bp_get_friends_slug() . '/add-friend/' . $potential_friend_id . '/', 'friends_add_friend' );
        break;
    }
    
    echo $link;

    Note: You will need to provide the value of $potential_friend_id yourself. For example, if you know the ID of the potential friend is 8 then do this at the very top of that code:

    $potential_friend_id = 8;

    Alternatively, bp_displayed_user_id() will get the ID of the currently displayed member.


    jaybee08
    Participant

    @jaybee08

    Hi @henrywright, i think you are right, I tried your code and it seems working. But do you know how to make it the same way like when I click on the Buddy request/add friend icon will have a pop-up text area and write message/request to the user. Just like what the plugin does.

    I really appreciate your help. Your awesome.


    jaybee08
    Participant

    @jaybee08

    I mean for the popover friend request message, not sure how to load that when I click the add a friend icon

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to make a custom add friend link in buddypress’ is closed to new replies.
Skip to toolbar