BP_Message_Export::process_erase( $user,  $page, bool $email_address )

Delete user messages and change ownership to anonymous.

Description

Parameters

$user

(Required)

$page

(Required)

$email_address

(bool) (Required)

Return

(array)

Source

File: bp-core/gdpr/class-bp-message-export.php

	function process_erase( $user, $page, $email_address ) {

		global $wpdb, $bp;

		if ( ! $user || is_wp_error( $user ) ) {
			return $this->response_erase( array(), true );
		}

		$table            = "{$bp->messages->global_tables["table_name_messages"]}";
		$table_recipients = "{$bp->messages->global_tables["table_name_recipients"]}";
		$page             = (int) $page;
		$items_removed    = false;
		$items_retained   = false;

		$get_data = $this->get_data( $user, $page );

		foreach ( $get_data["items"] as $item ) {

			$item->subject = wp_privacy_anonymize_data( 'text', $item->subject );
			$item->message = wp_privacy_anonymize_data( 'longtext', $item->subject );

			$wpdb->update( $table,
				array(
					"subject" => $item->subject,
					"message" => $item->message,
				),
				array( "id" => $item->id ),
				array( '%s', '%s', '%d' ),
				array( '%d' ) );

			/**
			 * @todo add title/description
			 *
			 * @since BuddyBoss 1.0.0
			 */
			do_action( 'buddyboss_bp_gdpr_message_after_data_erasers_item', $item, $get_data );

			$items_removed = true;

		}

		$done = $get_data["total"] < $get_data["offset"];

		if ( $done ) {
			// Anonymous user from all recipients
			$wpdb->update( $table_recipients,
				array( "user_id" => 0 ),
				array( "user_id" => $user->ID ),
				array( '%d' ),
				array( "%d" ) );

			// Anonymous Sender ID from all messages
			$wpdb->update( $table,
				array( "sender_id" => 0 ),
				array( "sender_id" => $user->ID ),
				array( '%d' ),
				array( "%d" ) );

		}

		return $this->response_erase( $items_removed, $done, array(), $items_retained );
	}

Changelog

Changelog
Version Description
BuddyBoss 1.0.0 Introduced.

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.