Buddypress Follower Plugin – Add Follow Link in other locations of your site

So you are looking to add additional Follow [user_name] links to your site?

Here is the function to use

<?php bp_follow_add_follow_button(array('leader_id'=>$displayed_userID, 'follower_id'=>$current_userID)) ?>

Where:

<?php
array(
'leader_id'=>$displayed_userID, //this is the user id of current displayed user or current displayed users content, the followed
'follower_id'=>$current_userID  //this is the user id of the currently logged in user, the follower
)
?>

Here is how I added the follow link to the activity stream.

Add two lines of code to the following template files:
/your_theme_folder/activity/entry.php
/your_theme_folder/activity/comment.php
If either of these files is missing then just copy them over from the default theme within the buddypress plugin folder.

This is the first line of code needed in both files, place it towards the top of the file, this is to make the buddypress object available in the file which is used to get the currently logged in user id.

<?php global $bp ?>

This line of code is used in the entry.php file. It utilizes a function to get the current entries user id.

<?php bp_follow_add_follow_button( array('leader_id'=>bp_get_activity_user_id(),'follower_id'=>$bp->loggedin_user->id)) ?>

This line of code is used in the comment.php file. It utilizes a function to get the current commenters user id.

<?php bp_follow_add_follow_button( array('leader_id'=>bp_get_activity_comment_user_id(),'follower_id'=>$bp->loggedin_user->id)) ?>

Leave a Reply

Your email address will not be published. Required fields are marked *