user2011524
user2011524

Reputation: 11

Check if user are friend to display data in members-loop buddyprress

Can someone please help me out, I have a profile field named BB Pin and i use

BB Pin:<?php bp_member_profile_data('field=BB Pin');?>

to show the data in members-loop.php and it work fine but i want to do it so that if you are not friend the field value is *****.

Something like

if is friend{

BB Pin:<?php bp_member_profile_data('field=BB Pin');?>

} else{ ****.

Thanks for you help.

Regards

Update:

I have just tried the below code in the members-loop.php but did not work.

<?php global $bp; $friend = BP_Friends_Friendship::check_is_friend( $bp->loggedin_user->id, $bp->displayed_user->id ); if ( $bp->loggedin_user->id || $friend == 'is_friend') : ?> echo <?php bp_member_profile_data('field=BB Pin');?> <?php else : ?> echo *************** <?php endif; ?>

Upvotes: 0

Views: 1221

Answers (2)

$is_friend = friends_check_friendship( bp_loggedin_user_id(), bp_displayed_user_id() );

if($is_friend) {
  BB Pin:<?php bp_member_profile_data('field=BB Pin');?>
} else{
BB Pin: ***;

This one should work in the loop! You can´t use the global Variable $bp in the loop, but there are other variables for that particular task. In this case I just changed

$bp->loggedin_user->id, $bp->displayed_user->id

to the ones in my code example!

Upvotes: 0

Chirag Patel
Chirag Patel

Reputation: 506

Check if logged in user is friend or not please use below code:

global $bp;
$is_friend = friends_check_friendship( $bp->loggedin_user->id, $bp->displayed_user->id );

if($is_friend) {
   BB Pin:<?php bp_member_profile_data('field=BB Pin');?>
} else{
   BB Pin: ***;
}

Upvotes: 0

Related Questions