ElggUser::removeFriend PHP Method

removeFriend() public method

Removes a user as a friend
public removeFriend ( integer $friend_guid ) : boolean
$friend_guid integer The GUID of the user to remove
return boolean
    public function removeFriend($friend_guid)
    {
        if (!get_user($friend_guid)) {
            return false;
        }
        // @todo this should be done with a plugin hook handler on the delete relationship
        // perform cleanup for access lists.
        $collections = get_user_access_collections($this->guid);
        if ($collections) {
            foreach ($collections as $collection) {
                remove_user_from_access_collection($friend_guid, $collection->id);
            }
        }
        return remove_entity_relationship($this->guid, "friend", $friend_guid);
    }

Usage Example

 public function testFriendSubscriptionRemovedWhenFriendRelationshipDeleted()
 {
     $this->user1->addFriend($this->user2->guid);
     $this->assertTrue($this->user1->isFriendsWith($this->user2->guid));
     elgg_add_subscription($this->user1->guid, 'test', $this->user2->guid);
     $this->assertIsA(check_entity_relationship($this->user1->guid, 'notifytest', $this->user2->guid), ElggRelationship::class);
     $this->user1->removeFriend($this->user2->guid);
     $this->assertFalse($this->user1->isFriendsWith($this->user2->guid));
     $this->assertFalse(check_entity_relationship($this->user1->guid, 'notifytest', $this->user2->guid));
 }