bp_notifications_personal_data_exporter( string $email_address, int $page )

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


Parameters Parameters

$email_address

(string) (Required) The users email address.

$page

(int) (Required) Batch number.


Top ↑

Return Return

(array) An array of personal data.


Source Source

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

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

	$notifications = BP_Notifications_Notification::get( array(
		'is_new'   => null,
		'per_page' => $number,
		'page'     => $page,
		'user_id'  => $user->ID,
		'order'    => 'DESC',
	) );

	$user_data_to_export = array();

	foreach ( $notifications as $notification ) {
		if ( 'xprofile' === $notification->component_name ) {
			$component_name = 'profile';
		} else {
			$component_name = $notification->component_name;
		}

		// Format notifications.
		if ( isset( buddypress()->{$component_name}->notification_callback ) && is_callable( buddypress()->{$component_name}->notification_callback ) ) {
			$content = call_user_func( buddypress()->{$component_name}->notification_callback, $notification->component_action, $notification->item_id, $notification->secondary_item_id, 1, 'string', $notification->id );
		} else {
			/*
			 * Compile an array of data to send to filter.
			 *
			 * Note that a null value is passed in the slot filled by `total_count` in
			 * other filter contexts. We don't have enough info here to pass a `total_count`.
			 */
			$ref_array = array(
				$notification->component_action,
				$notification->item_id,
				$notification->secondary_item_id,
				null,
				'string',
				$notification->component_action,
				$component_name,
				$notification->id,
			);

			/** This filter is documented in bp-notifications/bp-notifications-functions.php */
			$content = apply_filters_ref_array( 'bp_notifications_get_notifications_for_user', $ref_array );
		}

		$item_data = array(
			array(
				'name'  => __( 'Notification Content', 'buddypress' ),
				'value' => $content,
			),
			array(
				'name'  => __( 'Notification Date', 'buddypress' ),
				'value' => $notification->date_notified,
			),
			array(
				'name'  => __( 'Status', 'buddypress' ),
				'value' => $notification->is_new ? __( 'Unread', 'buddypress' ) : __( 'Read', 'buddypress' ),
			),
		);

		$data_to_export[] = array(
			'group_id'    => 'bp_notifications',
			'group_label' => __( 'Notifications', 'buddypress' ),
			'item_id'     => "bp-notifications-{$notification->id}",
			'data'        => $item_data,
		);
	}

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