__( 'Action Receipts', 'action-receipts' ), 'callback' => array( $this, 'export' ), ); return $exporters; } public function register_eraser( $erasers ) { $erasers['action-receipts'] = array( 'eraser_friendly_name' => __( 'Action Receipts', 'action-receipts' ), 'callback' => array( $this, 'erase' ), ); return $erasers; } public function export( $email, $page = 1 ): array { $page = max( 1, (int) $page ); $receipts = ReceiptRepository::find_by_email( (string) $email, self::PAGE_SIZE, ( $page - 1 ) * self::PAGE_SIZE ); $items = array(); foreach ( $receipts as $receipt ) { $data = array( array( 'name' => __( 'Reference', 'action-receipts' ), 'value' => $receipt['reference'], ), array( 'name' => __( 'Form', 'action-receipts' ), 'value' => $receipt['form_title'], ), array( 'name' => __( 'Status', 'action-receipts' ), 'value' => StatusPipeline::get( $receipt['status_key'] )['label'], ), array( 'name' => __( 'Submitted (UTC)', 'action-receipts' ), 'value' => $receipt['created_at'], ), ); foreach ( SnapshotService::decode( $receipt ) as $field ) { $data[] = array( 'name' => (string) ( $field['label'] ?? '' ), 'value' => (string) ( $field['value'] ?? '' ), ); } $items[] = array( 'group_id' => 'action-receipts', 'group_label' => __( 'Submission receipts', 'action-receipts' ), 'item_id' => 'receipt-' . $receipt['id'], 'data' => $data, ); } return array( 'data' => $items, 'done' => count( $receipts ) < self::PAGE_SIZE, ); } public function erase( $email, $page = 1 ): array { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed -- WordPress passes the page; we always read the first one. // Always read the first page: erased rows disappear from the result. $receipts = ReceiptRepository::find_by_email( (string) $email, self::PAGE_SIZE, 0 ); foreach ( $receipts as $receipt ) { ReceiptRepository::delete( (int) $receipt['id'] ); } return array( 'items_removed' => count( $receipts ) > 0, 'items_retained' => false, 'messages' => array(), 'done' => count( $receipts ) < self::PAGE_SIZE, ); } public function policy_text(): void { if ( ! function_exists( 'wp_add_privacy_policy_content' ) ) { return; } $text = '

' . __( 'When you submit a form on this site, we store a receipt of your submission: a reference number, the date, the fields you filled in that are needed to process your request, your email address and the status of your request. We use this to let you check the status of your submission and to send you updates by email.', 'action-receipts' ) . '

' . '

' . __( 'You can view your submission through a private link we send you, or by entering your reference number and email address on our tracking page. You can ask us to export or delete this data.', 'action-receipts' ) . '

'; wp_add_privacy_policy_content( __( 'Action Receipts', 'action-receipts' ), wp_kses_post( $text ) ); } public function purge_expired(): void { foreach ( ReceiptRepository::expired_ids() as $id ) { ReceiptRepository::delete( $id ); } } }