bp_activity_personal_data_exporter( string $email_address, int $page )

Finds and exports personal data associated with an email address from the Activity 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-activity/bp-activity-functions.php

function bp_activity_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,
		);
	}

	$activities = bp_activity_get( array(
		'display_comments' => 'stream',
		'per_page'         => $number,
		'page'             => $page,
		'show_hidden'      => true,
		'filter'           => array(
			'user_id' => $user->ID,
		),
	) );

	$user_data_to_export = array();
	$activity_actions    = bp_activity_get_actions();

	foreach ( $activities['activities'] as $activity ) {
		if ( ! empty( $activity_actions->{$activity->component}->{$activity->type}['format_callback'] ) ) {
			$description = call_user_func( $activity_actions->{$activity->component}->{$activity->type}['format_callback'], '', $activity );
		} elseif ( ! empty( $activity->action ) ) {
			$description = $activity->action;
		} else {
			$description = $activity->type;
		}

		$item_data = array(
			array(
				'name'  => __( 'Activity Date', 'buddypress' ),
				'value' => $activity->date_recorded,
			),
			array(
				'name'  => __( 'Activity Description', 'buddypress' ),
				'value' => $description,
			),
			array(
				'name'  => __( 'Activity URL', 'buddypress' ),
				'value' => bp_activity_get_permalink( $activity->id, $activity ),
			),
		);

		if ( ! empty( $activity->content ) ) {
			$item_data[] = array(
				'name'  => __( 'Activity Content', 'buddypress' ),
				'value' => $activity->content,
			);
		}

		/**
		 * Filters the data associated with an activity item when assembled for a WP personal data export.
		 *
		 * Plugins that register activity types whose `action` string doesn't adequately
		 * describe the activity item for the purposes of data export may filter the activity
		 * item data here.
		 *
		 * @since 4.0.0
		 *
		 * @param array                $item_data Array of data describing the activity item.
		 * @param BP_Activity_Activity $activity  Activity item.
		 */
		$item_data = apply_filters( 'bp_activity_personal_data_export_item_data', $item_data, $activity );

		$data_to_export[] = array(
			'group_id'    => 'bp_activity',
			'group_label' => __( 'Activity', 'buddypress' ),
			'item_id'     => "bp-activity-{$activity->id}",
			'data'        => $item_data,
		);
	}

	// Tell core if we have more items to process.
	$done = count( $activities['activities'] ) < $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.