bp_get_add_friend_button( int $potential_friend_id, bool $friend_status = false, array $button_args = array() )

Create the Connect button.

Description

Parameters

$potential_friend_id

(Required) ID of the user to whom the button applies. Default: value of bp_get_potential_friend_id().

$friend_status

(Optional) Not currently used.

Default value: false

$button_args

(Optional) See BP_Button class.

Default value: array()

Return

(false|string) HTML for the Connect button.

Source

File: bp-friends/bp-friends-template.php

374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
function bp_get_add_friend_button( $potential_friend_id = 0, $friend_status = false, $button_args = array() ) {
 
    if ( empty( $potential_friend_id ) )
        $potential_friend_id = bp_get_potential_friend_id( $potential_friend_id );
 
    $is_friend = bp_is_friend( $potential_friend_id );
 
    if ( empty( $is_friend ) )
        return false;
 
    $button_args = wp_parse_args( $button_args, get_class_vars( 'BP_Button' ) );
 
    switch ( $is_friend ) {
        case 'pending' :
            $button = wp_parse_args(
                array(
                    'id'                => 'pending',
                    'component'         => 'friends',
                    'must_be_logged_in' => true,
                    'block_self'        => true,
                    'wrapper_class'     => 'friendship-button pending_friend',
                    'wrapper_id'        => 'friendship-button-' . $potential_friend_id,
                    'link_href'         => wp_nonce_url( bp_loggedin_user_domain() . bp_get_friends_slug() . '/requests/cancel/' . $potential_friend_id . '/', 'friends_withdraw_friendship' ),
                    'link_text'         => __( 'Cancel connection request', 'buddyboss' ),
                    'link_id'           => 'friend-' . $potential_friend_id,
                    'link_rel'          => 'remove',
                    'link_class'        => 'friendship-button pending_friend requested'
                ), $button_args );
            break;
 
        case 'awaiting_response' :
            $button = wp_parse_args(
                array(
                    'id'                => 'awaiting_response',
                    'component'         => 'friends',
                    'must_be_logged_in' => true,
                    'block_self'        => true,
                    'wrapper_class'     => 'friendship-button awaiting_response_friend',
                    'wrapper_id'        => 'friendship-button-' . $potential_friend_id,
                    'link_href'         => bp_loggedin_user_domain() . bp_get_friends_slug() . '/requests/',
                    'link_text'         => __( 'Connect Requested', 'buddyboss' ),
                    'link_id'           => 'friend-' . $potential_friend_id,
                    'link_rel'          => 'remove',
                    'link_class'        => 'friendship-button awaiting_response_friend requested'
                ), $button_args );
            break;
 
        case 'is_friend' :
            $button = wp_parse_args(
                array(
                    'id'                => 'is_friend',
                    'component'         => 'friends',
                    'must_be_logged_in' => true,
                    'block_self'        => false,
                    'wrapper_class'     => 'friendship-button is_friend',
                    'wrapper_id'        => 'friendship-button-' . $potential_friend_id,
                    'link_href'         => wp_nonce_url( bp_loggedin_user_domain() . bp_get_friends_slug() . '/remove-friend/' . $potential_friend_id . '/', 'friends_remove_friend' ),
                    'link_text'         => __( 'Connected', 'buddyboss' ),
                    'link_id'           => 'friend-' . $potential_friend_id,
                    'link_rel'          => 'remove',
                    'link_class'        => 'friendship-button is_friend remove bp-toggle-action-button',
                    'button_attr'       => array(
                        'data-title'           => __( 'Remove Connection', 'buddyboss' ),
                        'data-title-displayed' => __( 'Connected', 'buddyboss' ),
                    )
                ), $button_args );
            break;
 
        default:
            $button = wp_parse_args(
                array(
                    'id'                => 'not_friends',
                    'component'         => 'friends',
                    'must_be_logged_in' => true,
                    'block_self'        => true,
                    'wrapper_class'     => 'friendship-button not_friends',
                    'wrapper_id'        => 'friendship-button-' . $potential_friend_id,
                    'link_href'         => wp_nonce_url( bp_loggedin_user_domain() . bp_get_friends_slug() . '/add-friend/' . $potential_friend_id . '/', 'friends_add_friend' ),
                    'link_text'         => __( 'Connect', 'buddyboss' ),
                    'link_id'           => 'friend-' . $potential_friend_id,
                    'link_rel'          => 'add',
                    'link_class'        => 'friendship-button not_friends add'
                ), $button_args );
            break;
    }
 
    /**
     * Filters the HTML for the add friend button.
     *
     * @since BuddyPress 1.1.0
     *
     * @param string $button HTML markup for add friend button.
     */
    return bp_get_button( apply_filters( 'bp_get_add_friend_button', $button ) );
}

Changelog

Changelog
Version Description
BuddyPress 1.1.0 Introduced.

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.