__( 'Loyalty rewards', 'loyaltyspin' ), 'callback' => array( __CLASS__, 'export' ), ); return $exporters; } /** * Register eraser. * * @param array $erasers Erasers. * @return array */ public static function register_eraser( $erasers ) { $erasers['loyaltypress'] = array( 'eraser_friendly_name' => __( 'Loyalty rewards', 'loyaltyspin' ), 'callback' => array( __CLASS__, 'erase' ), ); return $erasers; } /** * Export ledger, spins and draw wins. * * @param string $email Email. * @param int $page Page. * @return array */ public static function export( $email, $page = 1 ) { $user = get_user_by( 'email', $email ); if ( ! $user ) { return array( 'data' => array(), 'done' => true, ); } $per = 200; $rows = Coins\Ledger::history( $user->ID, $per, ( $page - 1 ) * $per ); $items = array(); foreach ( $rows as $r ) { $items[] = array( 'group_id' => 'loyaltypress-ledger', 'group_label' => __( 'Loyalty coin history', 'loyaltyspin' ), 'item_id' => 'lp-ledger-' . $r->id, 'data' => array( array( 'name' => __( 'Date', 'loyaltyspin' ), 'value' => $r->created_at, ), array( 'name' => __( 'Type', 'loyaltyspin' ), 'value' => $r->type, ), array( 'name' => __( 'Amount', 'loyaltyspin' ), 'value' => $r->amount, ), array( 'name' => __( 'Reason', 'loyaltyspin' ), 'value' => $r->reason, ), ), ); } if ( 1 === (int) $page ) { $bday = get_user_meta( $user->ID, 'loyaltypress_birthday', true ); if ( $bday ) { $items[] = array( 'group_id' => 'loyaltypress-profile', 'group_label' => __( 'Loyalty profile', 'loyaltyspin' ), 'item_id' => 'lp-profile', 'data' => array( array( 'name' => __( 'Birthday (MM-DD)', 'loyaltyspin' ), 'value' => $bday, ), ), ); } } return array( 'data' => $items, 'done' => count( $rows ) < $per, ); } /** * Erase: delete coin/spin data, anonymise draw entries (kept for draw integrity). * * @param string $email Email. * @return array */ public static function erase( $email ) { global $wpdb; $user = get_user_by( 'email', $email ); if ( ! $user ) { return array( 'items_removed' => false, 'items_retained' => false, 'messages' => array(), 'done' => true, ); } $p = $wpdb->prefix . 'loyaltypress_'; // phpcs:disable WordPress.DB.DirectDatabaseQuery $removed = (int) $wpdb->delete( $p . 'coin_ledger', array( 'user_id' => $user->ID ) ); $removed += (int) $wpdb->delete( $p . 'spin_tokens', array( 'user_id' => $user->ID ) ); $removed += (int) $wpdb->delete( $p . 'spin_results', array( 'user_id' => $user->ID ) ); $anon = (int) $wpdb->update( $p . 'draw_entries', array( 'user_id' => 0, 'customer_key' => md5( 'erased' . $user->ID ), ), array( 'user_id' => $user->ID ) ); $wpdb->update( $p . 'draw_winners', array( 'user_id' => 0 ), array( 'user_id' => $user->ID ) ); // phpcs:enable delete_user_meta( $user->ID, 'loyaltypress_birthday' ); delete_user_meta( $user->ID, '_loyaltypress_spin_progress' ); return array( 'items_removed' => $removed > 0, 'items_retained' => $anon > 0, 'messages' => $anon ? array( __( 'Lucky Draw entries were anonymised but kept so past draw results stay verifiable.', 'loyaltyspin' ) ) : array(), 'done' => true, ); } /** * Suggested privacy policy text. */ public static function policy_text() { if ( ! function_exists( 'wp_add_privacy_policy_content' ) ) { return; } wp_add_privacy_policy_content( 'LoyaltySpin', '

' . esc_html__( 'When you place an order or take part in our rewards program we record your reward coin history, spin results, lucky draw entries and wins, and optionally your birthday (day and month). This is used only to run the rewards program. You can request an export or deletion of this data at any time.', 'loyaltyspin' ) . '

' ); } }