bp_messages_personal_data_exporter( string $email_address, int $page )

Finds and exports personal data associated with an email address from the Messages tables.


Parameters Parameters

$email_address

(string) (Required) The user's email address.

$page

(int) (Required) Batch number.


Top ↑

Return Return

(array) An array of personal data.


Source Source

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

function bp_messages_personal_data_exporter( $email_address, $page ) {
	$number = 10;

	$email_address = trim( $email_address );

	$data_to_export = array();

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

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

	$user_data_to_export = array();

	$user_threads = BP_Messages_Thread::get_current_threads_for_user( array(
		'user_id' => $user->ID,
		'box'     => 'sentbox',
		'type'    => null,
		'limit'   => $number,
		'page'    => $page,
	) );

	if ( empty( $user_threads ) ) {
		return array(
			'data' => $data_to_export,
			'done' => true,
		);
	}

	foreach ( $user_threads['threads'] as $thread ) {
		$recipient_links = array();
		foreach ( $thread->recipients as $recipient ) {
			if ( $recipient->user_id === $user->ID ) {
				continue;
			}

			$recipient_links[] = bp_core_get_userlink( $recipient->user_id );
		}
		$recipients = implode( ', ', $recipient_links );

		$thread_link = bp_get_message_thread_view_link( $thread->thread_id, $user->ID );

		foreach ( $thread->messages as $message_index => $message ) {
			// Only include messages written by the user.
			if ( $user->ID !== $message->sender_id ) {
				continue;
			}

			$message_data = array(
				array(
					'name'  => __( 'Message Subject', 'buddypress' ),
					'value' => $message->subject,
				),
				array(
					'name'  => __( 'Message Content', 'buddypress' ),
					'value' => $message->message,
				),
				array(
					'name'  => __( 'Date Sent', 'buddypress' ),
					'value' => $message->date_sent,
				),
				array(
					'name' => __( 'Recipients', 'buddypress' ),
					'value' => $recipients,
				),
				array(
					'name'  => __( 'Thread URL', 'buddypress' ),
					'value' => $thread_link,
				),
			);

			$data_to_export[] = array(
				'group_id'    => 'bp_messages',
				'group_label' => __( 'Private Messages', 'buddypress' ),
				'item_id'     => "bp-messages-{$message->id}",
				'data'        => $message_data,
			);
		}
	}

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


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.