bp_friends_personal_data_exporter( string $email_address, int $page )

Finds and exports friendship data associated with an email address.


Description Description


Parameters Parameters

$email_address

(Required) The user's email address.

$page

(Required) Batch number.


Top ↑

Return Return

(array) An array of personal data.


Top ↑

Source Source

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

function bp_friends_personal_data_exporter( $email_address, $page ) {
	$number = 50;

	$email_address = trim( $email_address );

	$data_to_export = array();

	$user = get_user_by( 'email', $email_address );

	if ( ! $user ) {
		return array(
			'data' => array(),
			'done' => true,
		);
	}

	$friendships = BP_Friends_Friendship::get_friendships( $user->ID, array(
		'is_confirmed' => true,
		'page'         => $page,
		'per_page'     => $number,
	) );

	$user_data_to_export = array();

	foreach ( $friendships as $friendship ) {
		if ( (int) $user->ID === (int) $friendship->initiator_user_id ) {
			$friend_id         = $friendship->friend_user_id;
			$user_is_initiator = true;
		} else {
			$friend_id         = $friendship->initiator_user_id;
			$user_is_initiator = false;
		}

		$item_data = array(
			array(
				'name'  => __( 'Friend', 'buddypress' ),
				'value' => bp_core_get_userlink( $friend_id ),
			),
			array(
				'name'  => __( 'Initiated By Me', 'buddypress' ),
				'value' => $user_is_initiator ? __( 'Yes', 'buddypress' ) : __( 'No', 'buddypress' ),
			),
			array(
				'name'  => __( 'Friendship Date', 'buddypress' ),
				'value' => $friendship->date_created,
			),
		);

		$data_to_export[] = array(
			'group_id'    => 'bp_friends',
			'group_label' => __( 'Friends', 'buddypress' ),
			'item_id'     => "bp-friends-{$friend_id}",
			'data'        => $item_data,
		);
	}

	// Tell core if we have more items to process.
	$done = count( $friendships ) < $number;

	return array(
		'data' => $data_to_export,
		'done' => $done,
	);
}

Top ↑

Changelog Changelog

Changelog
Version Description
4.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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