wp_list_filter( $data_store->get_registered_meta(), array( 'privacy_erasure' => null, ), 'NOT' ); // Loop subscriptions. foreach ( $subscriptions as $subscription ) { $subscription_id = $subscription->get_id(); if ( empty( $subscription_id ) ) { continue; } $subscription_meta = get_post_meta( $subscription_id ); $subscription_status = null; if ( isset( $subscription_meta[ $data_store->meta_key_prefix . 'status' ] ) ) { $subscription_status = $subscription_meta[ $data_store->meta_key_prefix . 'status' ]; } // Subscription note and erasure return message. $note = __( 'Subscription anonymized for personal data erasure request.', 'pronamic_ideal' ); /* translators: %s = subscription id */ $message = __( 'Subscription ID %s anonymized.', 'pronamic_ideal' ); // Anonymize completed and cancelled subscriptions. if ( isset( $subscription_status ) && in_array( $subscription_status, array( PaymentStatus::COMPLETED, PaymentStatus::CANCELLED ), true ) ) { // Erase subscription meta. foreach ( $meta_keys as $meta_key => $meta_options ) { $meta_key = $data_store->meta_key_prefix . $meta_key; if ( ! array_key_exists( $meta_key, $subscription_meta ) ) { continue; } $action = ( isset( $meta_options['privacy_erasure'] ) ? $meta_options['privacy_erasure'] : null ); $privacy_manager->erase_meta( $subscription_id, $meta_key, $action ); } $items_removed = true; } else { $note = __( 'Subscription not anonymized for personal data erasure request because of active status.', 'pronamic_ideal' ); /* translators: %s: Subscription ID */ $message = __( 'Subscription ID %s not anonymized because of active status.', 'pronamic_ideal' ); $items_retained = true; } // Add erasure return message. $messages[] = sprintf( $message, $subscription_id ); // Add subscription note. try { $subscription->add_note( $note ); } catch ( \Exception $e ) { continue; } } $done = true; // Return results. return array( 'items_removed' => $items_removed, 'items_retained' => $items_retained, 'messages' => $messages, 'done' => $done, ); } }