Adding "Add Friends Button" anywhere on buddypress site

I'm trying to place the Add Friend button outside the contributor page, inside the loop, so the button appears next to the avatar author in the post. I tried to add:

<?php if ( bp_is_active( 'friends' ) ) { ?>

                        <?php bp_add_friend_button( $user_ids['users'][$i]->id ) ?>

                    <?php } ?>

      

Inside the loop, but it didn't return any results. Then I put the following action hook in functions.php, it rendered the button inside the loop, but after that it clicked all the buttons in the message list.

 add_action( ‘the_content’, ‘bp_add_friend_button’, 5 );

      

So now I am stuck. I thought adding a template tag inside the template would work as it worked for the Send Message button.

+3


source to share


2 answers


try it



<?php if ( function_exists( 'bp_add_friend_button' ) ) : ?> <?php bp_add_friend_button() ?> <?php endif; ?>

+1


source


Here is an example that works for me, hope it helps.



$id_or_email = $result -> user_ID;
$avatar_default = get_avatar($id_or_email, $size, $default = '', $alt = '', $args = null);
$potential_friend_id = $id_or_email;
$friend_status = false;
$friend_button = bp_add_friend_button($potential_friend_id, $friend_status);
 echo '<li>'. $avatar_default. $user_info->user_nicename . $friend_button . '</li> ';

      

0


source







All Articles