How to add an `Add Friend` button in a custom templates? Copy the codes below.
<?php if( $bp->displayed_user->id != bp_get_member_user_id() ) : ?> <div class="add-friend-btn"><?php bp_add_friend_button( bp_get_member_user_id() ); ?></div> <?php endif; ?>
How to get the total friends count? Read more here https://buddypress.wp-a2z.org/oik_api/friends_get_total_friend_count/.
<?php global $bp; echo bp_get_user_meta( $bp->loggedin_user->id, 'total_friend_count', true ); ?>
How to get the total friend requests count? Read more articles below.
bp_friend_total_requests_count – https://buddypress.wp-a2z.org/oik_api/bp_friend_total_requests_count/
bp_friend_get_total_requests_count – https://buddypress.wp-a2z.org/oik_api/bp_friend_get_total_requests_count/
<?php global $bp; bp_friend_total_requests_count( $bp->loggedin_user->id ); echo bp_friend_get_total_requests_count( $bp->loggedin_user->id ); ?>
How to remove `Add Friend` button in Buddypress pages.
// Original codes function bp_member_add_friend_button() { bp_add_friend_button( bp_get_member_user_id() ); } add_action( 'bp_directory_members_actions', 'bp_member_add_friend_button' ); // Here's the code on how to remove the `Add Friend` button in Buddypress pages remove_action( 'bp_directory_members_actions', 'bp_member_add_friend_button' ); // Here's the code on how to remove the `Add Friend` button in subscriber user role add_filter( 'bp_get_add_friend_button', 'anton_bp_get_add_friend_button', 10, 1 ); function anton_bp_get_add_friend_button( $button ){ global $bp, $members_template; $you = get_userdata( $members_template->member->id ); $me = get_userdata( $bp->loggedin_user->id ); if( in_array( 'public_users', $you->roles ) && in_array( 'subscriber', $me->roles ) ){ return; } return $button; }
Active menu link
function anton_active_link( $current_component = '', $current_action = '', $echo = true ){ global $bp; if( $bp->current_component == $current_component && $bp->current_action == $current_action ){ if( $echo ){ echo 'color:#db51b1;'; }else{ return 'color:#db51b1;'; } } } // Usage <?php global $bp; ?> <a class="sub-menu" href="<?php echo $bp->loggedin_user->domain; ?>/friends/requests"> <span style=" <?php anton_active_link( 'friends', 'requests' ); ?> ">» Requests (<?php bp_friend_total_requests_count( $bp->loggedin_user->id ); ?>)</span> </a>
How to override `bp_member_permalink()`, `bp_get_member_permalink()`, `bp_member_link()`, and `bp_get_member_link()` to profile page? Please copy the codes below to your functions.php of your current theme.
add_filter( 'bp_get_member_permalink', 'bp_get_member_profile_permalink', 10, 3 ); function bp_get_member_profile_permalink( $link ) { global $members_template; return bp_core_get_user_domain( $members_template->member->id, $members_template->member->user_nicename, $members_template->member->user_login ) . '/profile'; }
Original codes of `bp_member_permalink()`, `bp_get_member_permalink()`, `bp_member_link()`, and `bp_get_member_link()`.
function bp_member_permalink() { echo esc_url( bp_get_member_permalink() ); } function bp_get_member_permalink() { global $members_template; return apply_filters( 'bp_get_member_permalink', bp_core_get_user_domain( $members_template->member->id, $members_template->member->user_nicename, $members_template->member->user_login ) ); } function bp_member_link() { echo esc_url( bp_get_member_permalink() ); } function bp_get_member_link() { return bp_get_member_permalink(); }
Leave a Reply