' . esc_html__( 'Artwork proofs and approval records', 'proofkit' ) . ''; $html .= '
' . esc_html__( 'This shop uses ProofKit to collect artwork for orders and to record proof approvals. This notice explains what is stored, where it is kept and why.', 'proofkit' ) . '
'; $html .= '' . esc_html__( 'Files are kept in a private folder inside this site’s uploads directory. They do not have public URLs and are only served by the plugin after an access check. The information stays on this website: ProofKit does not send artwork, order data or usage data to any other service.', 'proofkit' ) . '
'; $html .= '' . esc_html__( 'To fulfil your order and to keep a record of which file version was approved, by whom and when. That record helps the shop answer questions about a print job.', 'proofkit' ) . '
'; $html .= '' . esc_html__( 'Shop staff who have the manage_woocommerce permission can see proofs and order records. Customers reach a proof through a private link that expires and, for an approval, can be used once.', 'proofkit' ) . '
'; $html .= '' . esc_html( $retention ) . '
'; $html .= '' . esc_html__( 'You can ask the shop for a copy of the information held about you, or ask for it to be erased. Shop staff can use Tools → Export Personal Data and Tools → Erase Personal Data in WordPress, or you can contact the shop directly.', 'proofkit' ) . '
'; $html .= '' . esc_html__( 'Approval records may be kept for the shop’s legitimate record-keeping after an erasure request, where the shop needs evidence of what was approved and when. The shop will keep only what it needs and will follow its own legal and accounting obligations.', 'proofkit' ) . '
'; return $html; } /** * Registers the personal data exporter. * * @param array $exporters Existing exporters. * @return array */ public static function exporters( array $exporters ): array { $exporters[ self::GROUP ] = array( 'exporter_friendly_name' => self::group_label(), 'callback' => array( self::class, 'export_order_data' ), 'priority' => 15, ); return $exporters; } /** * Registers the personal data eraser. * * @param array $erasers Existing erasers. * @return array */ public static function erasers( array $erasers ): array { $erasers[ self::GROUP ] = array( 'eraser_friendly_name' => self::group_label(), 'callback' => array( self::class, 'erase_order_data' ), 'priority' => 15, ); return $erasers; } /** * Exports proof metadata for every order billed to an email address. * * One item is returned per proof. File contents and download URLs are * never included. * * @param string $email Email address being exported. * @param int $page 1-based page of orders. * @return array{data: array, done: bool} */ public static function export_order_data( string $email, int $page = 1 ): array { $page = max( 1, $page ); $order_ids = self::orders_for_email( $email, $page, self::PER_PAGE ); $items = array(); foreach ( $order_ids as $order_id ) { if ( ! function_exists( 'wc_get_order' ) ) { break; } $order = wc_get_order( $order_id ); if ( ! $order instanceof \WC_Order ) { continue; } $proofs = Proof::get_for_order( $order_id ); if ( array() === $proofs ) { continue; } $order_number = (string) $order->get_order_number(); $created = $order->get_date_created(); $order_date = $created instanceof \WC_DateTime ? Util::format_datetime( gmdate( 'Y-m-d H:i:s', $created->getTimestamp() ) ) : ''; foreach ( $proofs as $proof ) { $items[] = array( 'group_id' => self::GROUP, 'group_label' => self::group_label(), 'item_id' => 'proof-' . (int) $proof->id, 'data' => array( array( 'name' => __( 'Order number', 'proofkit' ), 'value' => $order_number, ), array( 'name' => __( 'Order date', 'proofkit' ), 'value' => $order_date, ), array( 'name' => __( 'Item name', 'proofkit' ), 'value' => self::item_name( $order, (int) $proof->order_item_id ), ), array( 'name' => __( 'Proof version', 'proofkit' ), 'value' => (string) (int) $proof->version, ), array( 'name' => __( 'Status', 'proofkit' ), 'value' => Proof::status_label( (string) $proof->status ), ), array( 'name' => __( 'Original file name', 'proofkit' ), 'value' => (string) $proof->file_name, ), array( 'name' => __( 'File size', 'proofkit' ), 'value' => Util::human_size( (int) $proof->size_bytes ), ), array( 'name' => __( 'SHA-256', 'proofkit' ), 'value' => (string) $proof->sha256, ), array( 'name' => __( 'Uploaded by', 'proofkit' ), 'value' => (int) $proof->created_by > 0 ? __( 'Shop staff', 'proofkit' ) : __( 'Customer', 'proofkit' ), ), array( 'name' => __( 'Created date', 'proofkit' ), 'value' => Util::format_datetime( (string) $proof->created_at ), ), array( 'name' => __( 'Last approval or change-request note', 'proofkit' ), 'value' => self::last_note( (int) $proof->id ), ), ), ); } } $done = count( $order_ids ) < self::PER_PAGE; // Only on the last page, so a long export does not repeat the note. if ( $done ) { $items[] = self::retention_item(); } return array( 'data' => $items, 'done' => $done, ); } /** * Handles an erasure request. * * Proofs are retained by default because they are the shop's record of * what the customer approved. Returning true from the * `proofkit_privacy_erase_proof` filter opts a site in to deleting the * files and rows for the order currently being processed. * * @param string $email Email address being erased. * @param int $page 1-based page of orders. * @return array{items_removed: bool, items_retained: bool, messages: string[], done: bool} */ public static function erase_order_data( string $email, int $page = 1 ): array { $page = max( 1, $page ); $order_ids = self::orders_for_email( $email, $page, self::PER_PAGE ); $done = count( $order_ids ) < self::PER_PAGE; $removed = 0; $retained = 0; $cleaned = 0; foreach ( $order_ids as $order_id ) { $proofs = Proof::get_for_order( $order_id ); /** * Filters whether ProofKit should delete artwork and approval * records while WordPress processes an erasure request. * * Default false: the records are kept as the shop's audit trail. * Return true to delete the proof files, rows, events, tokens and * stored order/item artwork metadata for $order_id. * * @param bool $erase Whether to erase. Default false. * @param int $order_id Order being processed. */ $erase = (bool) apply_filters( 'proofkit_privacy_erase_proof', false, $order_id ); if ( $erase ) { Proof::delete_for_order( $order_id ); if ( self::erase_order_meta( $order_id ) ) { $cleaned++; } $removed += is_array( $proofs ) ? count( $proofs ) : 0; continue; } if ( ! is_array( $proofs ) || array() === $proofs ) { continue; } $retained += count( $proofs ); } $messages = array(); if ( $removed > 0 ) { $messages[] = sprintf( /* translators: %d: number of proofs deleted. */ _n( 'ProofKit deleted %d artwork proof and its approval records for this email address.', 'ProofKit deleted %d artwork proofs and their approval records for this email address.', $removed, 'proofkit' ), $removed ); } elseif ( $cleaned > 0 ) { $messages[] = __( 'ProofKit deleted the stored artwork references for this email address.', 'proofkit' ); } if ( $retained > 0 ) { $messages[] = __( 'ProofKit keeps artwork and approval records for the shop’s order and audit history. An administrator can delete them from the order screen or by filtering proofkit_privacy_erase_proof.', 'proofkit' ); } if ( array() === $messages ) { $messages[] = __( 'No ProofKit artwork or approval records were found for this email address.', 'proofkit' ); } return array( 'items_removed' => $removed > 0 || $cleaned > 0, 'items_retained' => $retained > 0, 'messages' => $messages, 'done' => $done, ); } /** * Deletes stored artwork descriptors and proof metadata from an order. * * Uses the WooCommerce data objects so the same code works for legacy * post storage and HPOS. It runs even when the order has no proof rows. * * @param int $order_id Order id. * @return bool Whether any metadata was removed. */ private static function erase_order_meta( int $order_id ): bool { if ( ! function_exists( 'wc_get_order' ) ) { return false; } $order = wc_get_order( $order_id ); if ( ! $order instanceof \WC_Order ) { return false; } $changed = false; foreach ( $order->get_items() as $item ) { if ( $item->meta_exists( '_proofkit_artwork' ) ) { $item->delete_meta_data( '_proofkit_artwork' ); $item->save(); $changed = true; } } foreach ( array( '_proofkit_proof_ids', '_proofkit_last_proof_status' ) as $meta_key ) { if ( $order->meta_exists( $meta_key ) ) { $order->delete_meta_data( $meta_key ); $changed = true; } } if ( $changed ) { $order->save(); } return $changed; } /** * Human-readable statuses whose orders are eligible for retention. * * @return string Comma-separated list. */ private static function retention_status_list(): string { $labels = array(); foreach ( Install::PURGEABLE_STATUSES as $status ) { $key = str_starts_with( $status, 'wc-' ) ? $status : 'wc-' . $status; $label = function_exists( 'wc_get_order_status_name' ) ? (string) wc_get_order_status_name( $key ) : ''; $fallback = str_starts_with( $status, 'wc-' ) ? substr( $status, 3 ) : $status; $labels[] = '' !== $label ? $label : ucfirst( str_replace( '-', ' ', $fallback ) ); } return implode( ', ', array_values( array_unique( $labels ) ) ); } /** * Finds order ids billed to an email address. * * WooCommerce's own WC_Order_Query default is * `array_keys( wc_get_order_statuses() )`, so that list is passed * explicitly rather than the legacy `'any'` shorthand. This keeps every * registered status (including custom and HPOS statuses) in scope. * * @param string $email Email address. * @param int $page 1-based page. * @param int $per_page Orders per page. * @return int[] */ private static function orders_for_email( string $email, int $page, int $per_page = 50 ): array { if ( ! function_exists( 'wc_get_orders' ) || ! function_exists( 'wc_get_order_statuses' ) ) { return array(); } $email = sanitize_email( $email ); if ( '' === $email ) { return array(); } $page = max( 1, $page ); $per_page = max( 1, min( 200, $per_page ) ); $orders = wc_get_orders( array( 'billing_email' => $email, 'limit' => $per_page, 'page' => $page, 'orderby' => 'date', 'order' => 'DESC', 'return' => 'ids', 'status' => array_keys( wc_get_order_statuses() ), ) ); if ( ! is_array( $orders ) ) { return array(); } return array_values( array_filter( array_map( 'absint', $orders ) ) ); } /** * Translated group label shared by the exporter and eraser. * * @return string */ private static function group_label(): string { return __( 'ProofKit artwork proofs', 'proofkit' ); } /** * Resolves the order line item name for a proof. * * @param \WC_Order $order Order. * @param int $order_item_id Order item id. * @return string Empty string when the item is gone. */ private static function item_name( \WC_Order $order, int $order_item_id ): string { if ( $order_item_id <= 0 ) { return ''; } $item = $order->get_item( $order_item_id ); if ( ! $item instanceof \WC_Order_Item_Product ) { return ''; } return (string) $item->get_name(); } /** * Returns the most recent approval or change-request note as plain text. * * @param int $proof_id Proof id. * @return string */ private static function last_note( int $proof_id ): string { $note = ''; foreach ( Proof::events( $proof_id ) as $event ) { $event_name = isset( $event->event ) ? (string) $event->event : ''; if ( 'approved' !== $event_name && 'changes_requested' !== $event_name ) { continue; } $meta = isset( $event->meta ) ? json_decode( (string) $event->meta, true ) : null; if ( is_array( $meta ) && isset( $meta['note'] ) && is_string( $meta['note'] ) ) { $note = $meta['note']; } } $note = trim( $note ); if ( '' === $note ) { return ''; } $note = trim( wp_strip_all_tags( wp_kses_post( $note ) ) ); if ( function_exists( 'mb_substr' ) && mb_strlen( $note, 'UTF-8' ) > 2000 ) { $note = mb_substr( $note, 0, 2000, 'UTF-8' ); } return $note; } /** * Builds the closing item that explains the retention period. * * @return array */ private static function retention_item(): array { $months = max( 1, (int) Settings::get( 'retention_months', 12 ) ); $statuses = self::retention_status_list(); $value = sprintf( /* translators: 1: number of months, 2: comma-separated order statuses. */ _n( 'ProofKit keeps proof artwork and approval records for %1$d month for orders in these statuses: %2$s. The period starts on the order’s creation date. Processing orders are never purged. After that they are removed by the shop’s scheduled cleanup. Approval records may be kept longer where the shop needs them for its own legal or accounting obligations.', 'ProofKit keeps proof artwork and approval records for %1$d months for orders in these statuses: %2$s. The period starts on the order’s creation date. Processing orders are never purged. After that they are removed by the shop’s scheduled cleanup. Approval records may be kept longer where the shop needs them for its own legal or accounting obligations.', $months, 'proofkit' ), $months, $statuses ); return array( 'group_id' => self::GROUP, 'group_label' => self::group_label(), 'item_id' => 'proofkit-retention', 'data' => array( array( 'name' => __( 'Retention period', 'proofkit' ), 'value' => $value, ), array( 'name' => __( 'Data location', 'proofkit' ), 'value' => __( 'This website’s database and private uploads directory. No data is sent to an external service.', 'proofkit' ), ), ), ); } }