friends_update_friend_totals( int $initiator_user_id, int $friend_user_id, string $status = 'add' )

Update user friend counts.


Description Description

Friend counts are cached in usermeta for performance reasons. After a friendship event (acceptance, deletion), call this function to regenerate the cached values.


Parameters Parameters

$initiator_user_id

(Required) ID of the first user.

$friend_user_id

(Required) ID of the second user.

$status

(Optional) The friendship event that's been triggered. 'add' will ++ each user's friend counts, while any other string will --.

Default value: 'add'


Top ↑

Source Source

File: bp-friends/bp-friends-functions.php

function friends_update_friend_totals( $initiator_user_id, $friend_user_id, $status = 'add' ) {

	if ( 'add' == $status ) {
		bp_update_user_meta( $initiator_user_id, 'total_friend_count', (int)bp_get_user_meta( $initiator_user_id, 'total_friend_count', true ) + 1 );
		bp_update_user_meta( $friend_user_id, 'total_friend_count', (int)bp_get_user_meta( $friend_user_id, 'total_friend_count', true ) + 1 );
	} else {
		bp_update_user_meta( $initiator_user_id, 'total_friend_count', (int)bp_get_user_meta( $initiator_user_id, 'total_friend_count', true ) - 1 );
		bp_update_user_meta( $friend_user_id, 'total_friend_count', (int)bp_get_user_meta( $friend_user_id, 'total_friend_count', true ) - 1 );
	}
}

Top ↑

Changelog Changelog

Changelog
Version Description
1.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.