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
4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 | 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.