bp_get_add_follow_button( int $leader_id = false, int $follower_id = false, array $button_args = array() )
Returns a follow / unfollow button for a given user depending on the follower status.
Description
Checks to see if the follower is already following the leader. If is following, returns "Stop following" button; if not following, returns "Follow" button.
Parameters
- $leader_id
-
(Optional) The user ID of the person we want to follow.
Default value: false
- $follower_id
-
(Optional) The user ID initiating the follow request.
Default value: false
- $button_args
-
(Optional) See BP_Button class for more information.
Default value: array()
Return
(mixed) String of the button on success. Boolean false on failure.
Source
File: bp-activity/bp-activity-template.php
function bp_get_add_follow_button( $leader_id = false, $follower_id = false, $button_args = array() ) { if ( ! $leader_id || ! $follower_id ) return false; $is_following = bp_is_following( array( 'leader_id' => $leader_id, 'follower_id' => $follower_id ) ); $button_args = wp_parse_args( $button_args, get_class_vars( 'BP_Button' ) ); if ( $is_following ) { $button = wp_parse_args( array( 'id' => 'member_follow', 'component' => 'members', 'must_be_logged_in' => true, 'block_self' => true, 'wrapper_class' => 'follow-button following', 'wrapper_id' => 'follow-button-' . $leader_id, 'link_href' => wp_nonce_url( bp_loggedin_user_domain() . bp_get_follow_slug() . '/stop-following/' . $leader_id . '/', 'follow_unfollow' ), 'link_text' => __( 'Following', 'buddyboss' ), 'link_id' => 'follow-' . $leader_id, 'link_rel' => 'stop', 'link_class' => 'follow-button following stop bp-toggle-action-button', 'button_attr' => array( 'data-title' => __( 'Unfollow', 'buddyboss' ), 'data-title-displayed' => __( 'Following', 'buddyboss' ), 'data-bp-nonce' => wp_nonce_url( bp_loggedin_user_domain() . bp_get_follow_slug() . '/stop-following/' . $leader_id . '/', 'follow_unfollow' ) ) ) , $button_args ); } else { $button = wp_parse_args( array( 'id' => 'member_follow', 'component' => 'members', 'must_be_logged_in' => true, 'block_self' => true, 'wrapper_class' => 'follow-button not_following', 'wrapper_id' => 'follow-button-' . $leader_id, 'link_href' => wp_nonce_url( bp_loggedin_user_domain() . bp_get_follow_slug() . '/start-following/' . $leader_id . '/', 'follow_follow' ), 'link_text' => __( 'Follow', 'buddyboss' ), 'link_id' => 'follow-' . $leader_id, 'link_rel' => 'start', 'link_class' => 'follow-button not_following start', 'button_attr' => array( 'data-bp-nonce' => wp_nonce_url( bp_loggedin_user_domain() . bp_get_follow_slug() . '/start-following/' . $leader_id . '/', 'follow_follow' ), ) ) , $button_args ); } /** * Filters the HTML for the follow button. * * @since BuddyBoss 1.0.0 * * @param string $button HTML markup for follow button. */ return bp_get_button( apply_filters( 'bp_get_add_follow_button', $button ) ); }
Changelog
Version | Description |
---|---|
BuddyBoss 1.0.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.