> $exporters Exporters. * @return array> */ public function exporters( array $exporters ): array { $exporters['schedulereed'] = array( 'exporter_friendly_name' => __( 'Bookings', 'schedulereed' ), 'callback' => array( $this, 'export' ), ); return $exporters; } /** * Register the eraser. * * @param array> $erasers Erasers. * @return array> */ public function erasers( array $erasers ): array { $erasers['schedulereed'] = array( 'eraser_friendly_name' => __( 'Bookings', 'schedulereed' ), 'callback' => array( $this, 'erase' ), ); return $erasers; } /** * A customer's details and bookings for the export file. * * @param string $email Address. * @param int $page Page. * @return array{data: array>, done: bool} */ public function export( string $email, int $page = 1 ): array { $customer = Services::customers()->find_by_email( $email ); if ( null === $customer ) { return array( 'data' => array(), 'done' => true, ); } $data = array(); if ( 1 === $page ) { $data[] = array( 'group_id' => 'schedulereed-customer', 'group_label' => __( 'Booking profile', 'schedulereed' ), 'item_id' => 'customer-' . $customer['id'], 'data' => array( array( 'name' => __( 'Name', 'schedulereed' ), 'value' => trim( $customer['first_name'] . ' ' . $customer['last_name'] ), ), array( 'name' => __( 'Email', 'schedulereed' ), 'value' => $customer['email'], ), array( 'name' => __( 'Phone', 'schedulereed' ), 'value' => $customer['phone'], ), array( 'name' => __( 'Consent', 'schedulereed' ), 'value' => wp_json_encode( $customer['consent'] ), ), ), ); } $result = Services::bookings()->search( array( 'customer_id' => $customer['id'], 'page' => $page, 'per_page' => 50, ) ); foreach ( $result['items'] as $booking ) { $details = Services::notifier()->details( $booking ); $fields = array( array( 'name' => __( 'Reference', 'schedulereed' ), 'value' => Format::reference( $booking ), ), array( 'name' => __( 'Service', 'schedulereed' ), 'value' => $details['service'], ), array( 'name' => __( 'When', 'schedulereed' ), 'value' => Format::when( $booking['start'] ), ), array( 'name' => __( 'Status', 'schedulereed' ), 'value' => $booking['status'], ), array( 'name' => __( 'Total', 'schedulereed' ), 'value' => Format::money( $booking['total'], $booking['currency'] ), ), array( 'name' => __( 'Notes', 'schedulereed' ), 'value' => $booking['notes'], ), ); foreach ( $booking['fields'] as $answer ) { if ( is_array( $answer ) && isset( $answer['label'], $answer['value'] ) ) { $fields[] = array( 'name' => (string) $answer['label'], 'value' => is_array( $answer['value'] ) ? implode( ', ', $answer['value'] ) : (string) $answer['value'], ); } } $data[] = array( 'group_id' => 'schedulereed-bookings', 'group_label' => __( 'Bookings', 'schedulereed' ), 'item_id' => 'booking-' . $booking['id'], 'data' => $fields, ); } return array( 'data' => $data, 'done' => $page * 50 >= $result['total'], ); } /** * Erase a customer's personal details. * * @param string $email Address. * @return array{items_removed: bool, items_retained: bool, messages: string[], done: bool} */ public function erase( string $email ): array { $customer = Services::customers()->find_by_email( $email ); if ( null === $customer ) { return array( 'items_removed' => false, 'items_retained' => false, 'messages' => array(), 'done' => true, ); } $this->anonymize( $customer['id'] ); return array( 'items_removed' => true, 'items_retained' => true, 'messages' => array( __( 'Booking dates, amounts and payments are kept for the business records, without personal details.', 'schedulereed' ) ), 'done' => true, ); } /** * Remove a customer's personal details from their profile and bookings. * * @param int $customer_id Customer. */ public function anonymize( int $customer_id ): void { $page = 1; do { $result = Services::bookings()->search( array( 'customer_id' => $customer_id, 'page' => $page, 'per_page' => 200, ) ); foreach ( $result['items'] as $booking ) { Services::bookings()->update( $booking['id'], array( 'notes' => '', 'fields' => array(), ) ); } ++$page; } while ( ( $page - 1 ) * 200 < $result['total'] ); Services::customers()->anonymize( $customer_id ); Services::activity()->record( $customer_id, 'anonymized', array(), 'customer' ); /** * Fires after a customer's personal details are erased. * * @param int $customer_id Customer. */ do_action( 'schedulereed_customer_anonymized', $customer_id ); } /** * Anonymise customers who have not booked for the retention period; runs daily. */ public function apply_retention(): int { $months = Settings::privacy()['retention_months']; if ( $months <= 0 ) { return 0; } $ids = Services::customers()->inactive_since( Clock::now() - $months * MONTH_IN_SECONDS ); foreach ( $ids as $id ) { $this->anonymize( $id ); } return count( $ids ); } /** * Suggested text for the site's privacy policy. */ public function policy_text(): void { if ( ! function_exists( 'wp_add_privacy_policy_content' ) ) { return; } wp_add_privacy_policy_content( \ScheduleReed\Brand::name(), wp_kses_post( '

' . __( 'When you book, we store your name, email address, phone number (if you give it), the booking details and any answers you give, so we can provide the service and contact you about it. Online payments are handled by our payment provider; we do not store card details.', 'schedulereed' ) . '

' . '

' . __( 'We send you emails about your booking: confirmations, changes and reminders. You can see, move or cancel your bookings from the link in those emails.', 'schedulereed' ) . '

' ) ); } }