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0-beta.1 3.2.2 6.3.0-rc.1 3.2.3 6.3.0-rc.2 3.2.4 6.3.1 3.2.5 6.3.2 3.2.6 6.4.0 3.3.0 6.4.0-beta.1 3.3.1 6.4.0-rc.1 3.3.2 6.4.1 3.3.2-rc.1 6.4.2 3.3.3 6.5.0 3.3.4 6.5.0-beta.1 3.3.5 6.5.0-rc.1 3.3.6 6.5.0-rc.2 3.4.0 6.5.1 3.4.0-beta.1 6.5.2 3.4.0-rc.2 6.6.0 3.4.1 6.6.0-beta.1 3.4.2 6.6.0-rc.1 3.4.3 6.6.0-rc.2 3.4.4 6.6.1 3.4.5 6.6.2 3.4.6 6.7.0 3.4.7 6.7.0-beta.1 3.4.8 6.7.0-beta.2 3.5.0 6.7.0-rc.1 3.5.0-beta.1 6.7.1 3.5.0-rc.1 6.8.0 3.5.0-rc.2 6.8.0-beta.1 3.5.1 6.8.0-beta.2 3.5.10 6.8.0-rc.1 3.5.2 6.8.1 3.5.3 6.8.2 3.5.4 6.8.3 3.5.5 6.9.0 3.5.6 6.9.0-beta.1 3.5.7 6.9.0-beta.2 3.5.8 6.9.0-rc.1 3.5.9 6.9.1 3.6.0 6.9.2 3.6.0-beta.1 6.9.3 3.6.0-rc.1 6.9.4 3.6.0-rc.2 6.9.5 3.6.0-rc.3 7.0.0 3.6.1 7.0.0-beta.1 3.6.2 7.0.0-beta.2 3.6.3 7.0.0-beta.3 3.6.4 7.0.0-rc.1 3.6.5 7.0.0-rc.2 3.6.6 7.0.1 3.6.7 7.0.2 3.7.0 7.1.0 3.7.0-beta.1 7.1.0-beta.1 3.7.0-rc.1 7.1.0-beta.2 3.7.0-rc.2 7.1.0-rc.1 3.7.1 7.1.0-rc.2 3.7.2 7.1.1
woocommerce / includes / class-wc-privacy-erasers.php
woocommerce / includes Last commit date
abstracts 4 weeks ago admin 1 week ago blocks 10 months ago cli 7 months ago customizer 3 months ago data-stores 3 weeks ago emails 1 week ago export 1 year ago gateways 2 months ago import 2 months ago integrations 4 weeks ago interfaces 3 months ago legacy 3 months ago libraries 1 year ago log-handlers 1 year ago payment-tokens 5 years ago product-usage 1 year ago queue 3 months ago react-admin 3 months ago rest-api 4 weeks ago shipping 2 months ago shortcodes 2 months ago theme-support 2 years ago tracks 3 months ago traits 5 years ago walkers 5 years ago wccom-site 4 weeks ago widgets 4 weeks ago class-wc-ajax.php 4 weeks ago class-wc-auth.php 1 year ago class-wc-autoloader.php 7 months ago class-wc-background-emailer.php 4 weeks ago class-wc-background-updater.php 5 years ago class-wc-brands-brand-settings-manager.php 1 year ago class-wc-brands-coupons.php 1 year ago class-wc-brands.php 4 months ago class-wc-breadcrumb.php 3 months ago class-wc-cache-helper.php 4 weeks ago class-wc-cart-fees.php 2 years ago class-wc-cart-session.php 2 months ago class-wc-cart-totals.php 10 months ago class-wc-cart.php 2 months ago class-wc-checkout.php 4 weeks ago class-wc-cli.php 9 months ago class-wc-comments.php 3 months ago class-wc-countries.php 4 weeks ago class-wc-coupon.php 4 weeks ago class-wc-customer-download-log.php 5 years ago class-wc-customer-download.php 1 year ago class-wc-customer.php 4 weeks ago class-wc-data-exception.php 8 years ago class-wc-data-store.php 3 years ago class-wc-datetime.php 4 years ago class-wc-deprecated-action-hooks.php 2 years ago class-wc-deprecated-filter-hooks.php 2 months ago class-wc-discounts.php 10 months ago class-wc-download-handler.php 1 year ago class-wc-emails.php 1 week ago class-wc-embed.php 1 year ago class-wc-form-handler.php 2 months ago class-wc-frontend-scripts.php 4 weeks ago class-wc-geo-ip.php 7 months ago class-wc-geolite-integration.php 6 years ago class-wc-geolocation.php 4 weeks ago class-wc-https.php 2 years ago class-wc-install.php 1 week ago class-wc-integrations.php 5 years ago class-wc-log-levels.php 2 years ago class-wc-logger.php 3 months ago class-wc-meta-data.php 4 years ago class-wc-order-factory.php 4 weeks ago class-wc-order-item-coupon.php 4 years ago class-wc-order-item-fee.php 4 months ago class-wc-order-item-meta.php 4 years ago class-wc-order-item-product.php 4 weeks ago class-wc-order-item-shipping.php 4 months ago class-wc-order-item-tax.php 4 years ago class-wc-order-item.php 4 months ago class-wc-order-query.php 3 months ago class-wc-order-refund.php 1 year ago class-wc-order.php 3 weeks ago class-wc-payment-gateways.php 4 weeks ago class-wc-payment-tokens.php 3 years ago class-wc-post-data.php 4 weeks ago class-wc-post-types.php 4 weeks ago class-wc-privacy-background-process.php 1 year ago class-wc-privacy-erasers.php 9 months ago class-wc-privacy-exporters.php 4 years ago class-wc-privacy.php 11 months ago class-wc-product-attribute.php 3 months ago class-wc-product-download.php 3 months ago class-wc-product-external.php 1 year ago class-wc-product-factory.php 2 months ago class-wc-product-grouped.php 2 months ago class-wc-product-query.php 3 months ago class-wc-product-simple.php 10 months ago class-wc-product-variable.php 2 months ago class-wc-product-variation.php 1 year ago class-wc-query.php 4 weeks ago class-wc-rate-limiter.php 4 years ago class-wc-regenerate-images-request.php 3 years ago class-wc-regenerate-images.php 1 year ago class-wc-register-wp-admin-settings.php 4 years ago class-wc-rest-authentication.php 1 year ago class-wc-rest-exception.php 5 years ago class-wc-session-handler.php 2 months ago class-wc-shipping-rate.php 11 months ago class-wc-shipping-zone.php 5 years ago class-wc-shipping-zones.php 6 months ago class-wc-shipping.php 4 weeks ago class-wc-shortcodes.php 1 year ago class-wc-structured-data.php 4 weeks ago class-wc-tax.php 4 weeks ago class-wc-template-loader.php 6 months ago class-wc-tracker.php 7 months ago class-wc-validation.php 2 years ago class-wc-webhook.php 4 weeks ago class-woocommerce.php 1 week ago wc-account-functions.php 6 months ago wc-attribute-functions.php 4 weeks ago wc-brands-functions.php 1 year ago wc-cart-functions.php 4 months ago wc-conditional-functions.php 10 months ago wc-core-functions.php 4 weeks ago wc-coupon-functions.php 4 months ago wc-deprecated-functions.php 3 months ago wc-formatting-functions.php 6 months ago wc-interactivity-api-functions.php 4 weeks ago wc-notice-functions.php 4 months ago wc-order-functions.php 3 weeks ago wc-order-item-functions.php 3 years ago wc-order-step-logger-functions.php 3 months ago wc-page-functions.php 3 weeks ago wc-product-functions.php 4 weeks ago wc-rest-functions.php 6 months ago wc-stock-functions.php 6 months ago wc-template-functions.php 4 weeks ago wc-template-hooks.php 9 months ago wc-term-functions.php 4 weeks ago wc-update-functions.php 1 week ago wc-user-functions.php 4 weeks ago wc-webhook-functions.php 4 weeks ago wc-widget-functions.php 5 years ago
class-wc-privacy-erasers.php
415 lines
1 <?php
2 /**
3 * Personal data erasers.
4 *
5 * @since 3.4.0
6 * @package WooCommerce\Classes
7 */
8
9 defined( 'ABSPATH' ) || exit;
10
11 /**
12 * WC_Privacy_Erasers Class.
13 */
14 class WC_Privacy_Erasers {
15 /**
16 * Finds and erases customer data by email address.
17 *
18 * @since 3.4.0
19 * @param string $email_address The user email address.
20 * @param int $page Page.
21 * @return array An array of personal data in name value pairs
22 */
23 public static function customer_data_eraser( $email_address, $page ) {
24 $response = array(
25 'items_removed' => false,
26 'items_retained' => false,
27 'messages' => array(),
28 'done' => true,
29 );
30
31 $user = get_user_by( 'email', $email_address ); // Check if user has an ID in the DB to load stored personal data.
32
33 if ( ! $user instanceof WP_User ) {
34 return $response;
35 }
36
37 $customer = new WC_Customer( $user->ID );
38
39 if ( ! $customer ) {
40 return $response;
41 }
42
43 $props_to_erase = apply_filters(
44 'woocommerce_privacy_erase_customer_personal_data_props',
45 array(
46 'billing_first_name' => __( 'Billing First Name', 'woocommerce' ),
47 'billing_last_name' => __( 'Billing Last Name', 'woocommerce' ),
48 'billing_company' => __( 'Billing Company', 'woocommerce' ),
49 'billing_address_1' => __( 'Billing Address 1', 'woocommerce' ),
50 'billing_address_2' => __( 'Billing Address 2', 'woocommerce' ),
51 'billing_city' => __( 'Billing City', 'woocommerce' ),
52 'billing_postcode' => __( 'Billing Postal/Zip Code', 'woocommerce' ),
53 'billing_state' => __( 'Billing State', 'woocommerce' ),
54 'billing_country' => __( 'Billing Country / Region', 'woocommerce' ),
55 'billing_phone' => __( 'Billing Phone Number', 'woocommerce' ),
56 'billing_email' => __( 'Email Address', 'woocommerce' ),
57 'shipping_first_name' => __( 'Shipping First Name', 'woocommerce' ),
58 'shipping_last_name' => __( 'Shipping Last Name', 'woocommerce' ),
59 'shipping_company' => __( 'Shipping Company', 'woocommerce' ),
60 'shipping_address_1' => __( 'Shipping Address 1', 'woocommerce' ),
61 'shipping_address_2' => __( 'Shipping Address 2', 'woocommerce' ),
62 'shipping_city' => __( 'Shipping City', 'woocommerce' ),
63 'shipping_postcode' => __( 'Shipping Postal/Zip Code', 'woocommerce' ),
64 'shipping_state' => __( 'Shipping State', 'woocommerce' ),
65 'shipping_country' => __( 'Shipping Country / Region', 'woocommerce' ),
66 'shipping_phone' => __( 'Shipping Phone Number', 'woocommerce' ),
67 ),
68 $customer
69 );
70
71 foreach ( $props_to_erase as $prop => $label ) {
72 $erased = false;
73
74 if ( is_callable( array( $customer, 'get_' . $prop ) ) && is_callable( array( $customer, 'set_' . $prop ) ) ) {
75 $value = $customer->{"get_$prop"}( 'edit' );
76
77 if ( $value ) {
78 $customer->{"set_$prop"}( '' );
79 $erased = true;
80 }
81 }
82
83 $erased = apply_filters( 'woocommerce_privacy_erase_customer_personal_data_prop', $erased, $prop, $customer );
84
85 if ( $erased ) {
86 /* Translators: %s Prop name. */
87 $response['messages'][] = sprintf( __( 'Removed customer "%s"', 'woocommerce' ), $label );
88 $response['items_removed'] = true;
89 }
90 }
91
92 $customer->save();
93
94 /**
95 * Allow extensions to remove data for this customer and adjust the response.
96 *
97 * @since 3.4.0
98 * @param array $response Array response data. Must include messages, num_items_removed, num_items_retained, done.
99 * @param WC_Customer $customer A customer object.
100 */
101 return apply_filters( 'woocommerce_privacy_erase_personal_data_customer', $response, $customer );
102 }
103
104 /**
105 * Finds and erases data which could be used to identify a person from WooCommerce data associated with an email address.
106 *
107 * Orders are erased in blocks of 10 to avoid timeouts.
108 *
109 * @since 3.4.0
110 * @param string $email_address The user email address.
111 * @param int $page Page.
112 * @return array An array of personal data in name value pairs
113 */
114 public static function order_data_eraser( $email_address, $page ) {
115 $page = (int) $page;
116 $user = get_user_by( 'email', $email_address ); // Check if user has an ID in the DB to load stored personal data.
117 $erasure_enabled = wc_string_to_bool( get_option( 'woocommerce_erasure_request_removes_order_data', 'no' ) );
118 $response = array(
119 'items_removed' => false,
120 'items_retained' => false,
121 'messages' => array(),
122 'done' => true,
123 );
124
125 $order_query = array(
126 'limit' => 10,
127 'page' => $page,
128 'customer' => array( $email_address ),
129 );
130
131 if ( $user instanceof WP_User ) {
132 $order_query['customer'][] = (int) $user->ID;
133 }
134
135 $orders = wc_get_orders( $order_query );
136
137 if ( 0 < count( $orders ) ) {
138 foreach ( $orders as $order ) {
139 if ( apply_filters( 'woocommerce_privacy_erase_order_personal_data', $erasure_enabled, $order ) ) {
140 self::remove_order_personal_data( $order );
141
142 /* Translators: %s Order number. */
143 $response['messages'][] = sprintf( __( 'Removed personal data from order %s.', 'woocommerce' ), $order->get_order_number() );
144 $response['items_removed'] = true;
145 } else {
146 /* Translators: %s Order number. */
147 $response['messages'][] = sprintf( __( 'Personal data within order %s has been retained.', 'woocommerce' ), $order->get_order_number() );
148 $response['items_retained'] = true;
149 }
150 }
151 $response['done'] = 10 > count( $orders );
152 } else {
153 $response['done'] = true;
154 }
155
156 return $response;
157 }
158
159 /**
160 * Finds and removes customer download logs by email address.
161 *
162 * @since 3.4.0
163 * @param string $email_address The user email address.
164 * @param int $page Page.
165 * @return array An array of personal data in name value pairs
166 */
167 public static function download_data_eraser( $email_address, $page ) {
168 $page = (int) $page;
169 $user = get_user_by( 'email', $email_address ); // Check if user has an ID in the DB to load stored personal data.
170 $erasure_enabled = wc_string_to_bool( get_option( 'woocommerce_erasure_request_removes_download_data', 'no' ) );
171 $response = array(
172 'items_removed' => false,
173 'items_retained' => false,
174 'messages' => array(),
175 'done' => true,
176 );
177
178 $downloads_query = array(
179 'limit' => -1,
180 'page' => $page,
181 'return' => 'ids',
182 );
183
184 if ( $user instanceof WP_User ) {
185 $downloads_query['user_id'] = (int) $user->ID;
186 } else {
187 $downloads_query['user_email'] = $email_address;
188 }
189
190 $customer_download_data_store = WC_Data_Store::load( 'customer-download' );
191
192 // Revoke download permissions.
193 if ( apply_filters( 'woocommerce_privacy_erase_download_personal_data', $erasure_enabled, $email_address ) ) {
194 if ( $user instanceof WP_User ) {
195 $result = $customer_download_data_store->delete_by_user_id( (int) $user->ID );
196 } else {
197 $result = $customer_download_data_store->delete_by_user_email( $email_address );
198 }
199 if ( $result ) {
200 $response['messages'][] = __( 'Removed access to downloadable files.', 'woocommerce' );
201 $response['items_removed'] = true;
202 }
203 } else {
204 $response['messages'][] = __( 'Customer download permissions have been retained.', 'woocommerce' );
205 $response['items_retained'] = true;
206 }
207
208 return $response;
209 }
210
211 /**
212 * Remove personal data specific to WooCommerce from an order object.
213 *
214 * Note; this will hinder order processing for obvious reasons!
215 *
216 * @param WC_Order $order Order object.
217 */
218 public static function remove_order_personal_data( $order ) {
219 $anonymized_data = array();
220
221 /**
222 * Allow extensions to remove their own personal data for this order first, so order data is still available.
223 *
224 * @since 3.4.0
225 * @param WC_Order $order A customer object.
226 */
227 do_action( 'woocommerce_privacy_before_remove_order_personal_data', $order );
228
229 /**
230 * Expose props and data types we'll be anonymizing.
231 *
232 * @since 3.4.0
233 * @param array $props Keys are the prop names, values are the data type we'll be passing to wp_privacy_anonymize_data().
234 * @param WC_Order $order A customer object.
235 */
236 $props_to_remove = apply_filters(
237 'woocommerce_privacy_remove_order_personal_data_props',
238 array(
239 'customer_ip_address' => 'ip',
240 'customer_user_agent' => 'text',
241 'billing_first_name' => 'text',
242 'billing_last_name' => 'text',
243 'billing_company' => 'text',
244 'billing_address_1' => 'text',
245 'billing_address_2' => 'text',
246 'billing_city' => 'text',
247 'billing_postcode' => 'text',
248 'billing_state' => 'address_state',
249 'billing_country' => 'address_country',
250 'billing_phone' => 'phone',
251 'billing_email' => 'email',
252 'shipping_first_name' => 'text',
253 'shipping_last_name' => 'text',
254 'shipping_company' => 'text',
255 'shipping_address_1' => 'text',
256 'shipping_address_2' => 'text',
257 'shipping_city' => 'text',
258 'shipping_postcode' => 'text',
259 'shipping_state' => 'address_state',
260 'shipping_country' => 'address_country',
261 'shipping_phone' => 'phone',
262 'customer_id' => 'numeric_id',
263 'transaction_id' => 'numeric_id',
264 ),
265 $order
266 );
267
268 if ( ! empty( $props_to_remove ) && is_array( $props_to_remove ) ) {
269 foreach ( $props_to_remove as $prop => $data_type ) {
270 // Get the current value in edit context.
271 $value = $order->{"get_$prop"}( 'edit' );
272
273 // If the value is empty, it does not need to be anonymized.
274 if ( empty( $value ) || empty( $data_type ) ) {
275 continue;
276 }
277
278 $anon_value = function_exists( 'wp_privacy_anonymize_data' ) ? wp_privacy_anonymize_data( $data_type, $value ) : '';
279
280 /**
281 * Expose a way to control the anonymized value of a prop via 3rd party code.
282 *
283 * @since 3.4.0
284 * @param string $anon_value Value of this prop after anonymization.
285 * @param string $prop Name of the prop being removed.
286 * @param string $value Current value of the data.
287 * @param string $data_type Type of data.
288 * @param WC_Order $order An order object.
289 */
290 $anonymized_data[ $prop ] = apply_filters( 'woocommerce_privacy_remove_order_personal_data_prop_value', $anon_value, $prop, $value, $data_type, $order );
291 }
292 }
293
294 // Set all new props and persist the new data to the database.
295 $order->set_props( $anonymized_data );
296
297 // Remove meta data.
298 $meta_to_remove = apply_filters(
299 'woocommerce_privacy_remove_order_personal_data_meta',
300 array(
301 'Payer first name' => 'text',
302 'Payer last name' => 'text',
303 'Payer PayPal address' => 'email',
304 'Transaction ID' => 'numeric_id',
305 )
306 );
307
308 if ( ! empty( $meta_to_remove ) && is_array( $meta_to_remove ) ) {
309 foreach ( $meta_to_remove as $meta_key => $data_type ) {
310 $value = $order->get_meta( $meta_key );
311
312 // If the value is empty, it does not need to be anonymized.
313 if ( empty( $value ) || empty( $data_type ) ) {
314 continue;
315 }
316
317 $anon_value = function_exists( 'wp_privacy_anonymize_data' ) ? wp_privacy_anonymize_data( $data_type, $value ) : '';
318
319 /**
320 * Expose a way to control the anonymized value of a value via 3rd party code.
321 *
322 * @since 3.4.0
323 * @param string $anon_value Value of this data after anonymization.
324 * @param string $prop meta_key key being removed.
325 * @param string $value Current value of the data.
326 * @param string $data_type Type of data.
327 * @param WC_Order $order An order object.
328 */
329 $anon_value = apply_filters( 'woocommerce_privacy_remove_order_personal_data_meta_value', $anon_value, $meta_key, $value, $data_type, $order );
330
331 if ( $anon_value ) {
332 $order->update_meta_data( $meta_key, $anon_value );
333 } else {
334 $order->delete_meta_data( $meta_key );
335 }
336 }
337 }
338
339 $order->update_meta_data( '_anonymized', 'yes' );
340 $order->save();
341
342 // Delete order notes which can contain PII.
343 $notes = wc_get_order_notes(
344 array(
345 'order_id' => $order->get_id(),
346 )
347 );
348
349 foreach ( $notes as $note ) {
350 wc_delete_order_note( $note->id );
351 }
352
353 // Add note that this event occurred.
354 $order->add_order_note( __( 'Personal data removed.', 'woocommerce' ) );
355
356 /**
357 * Allow extensions to remove their own personal data for this order.
358 *
359 * @since 3.4.0
360 * @param WC_Order $order Order instance.
361 */
362 do_action( 'woocommerce_privacy_remove_order_personal_data', $order );
363 }
364
365 /**
366 * Finds and erases customer tokens by email address.
367 *
368 * @since 3.4.0
369 * @param string $email_address The user email address.
370 * @param int $page Page.
371 * @return array An array of personal data in name value pairs
372 */
373 public static function customer_tokens_eraser( $email_address, $page ) {
374 $response = array(
375 'items_removed' => false,
376 'items_retained' => false,
377 'messages' => array(),
378 'done' => true,
379 );
380
381 $user = get_user_by( 'email', $email_address ); // Check if user has an ID in the DB to load stored personal data.
382
383 if ( ! $user instanceof WP_User ) {
384 return $response;
385 }
386
387 $tokens = WC_Payment_Tokens::get_tokens(
388 array(
389 'user_id' => $user->ID,
390 )
391 );
392
393 if ( empty( $tokens ) ) {
394 return $response;
395 }
396
397 foreach ( $tokens as $token ) {
398 WC_Payment_Tokens::delete( $token->get_id() );
399
400 /* Translators: %s Prop name. */
401 $response['messages'][] = sprintf( __( 'Removed payment token "%d"', 'woocommerce' ), $token->get_id() );
402 $response['items_removed'] = true;
403 }
404
405 /**
406 * Allow extensions to remove data for tokens and adjust the response.
407 *
408 * @since 3.4.0
409 * @param array $response Array response data. Must include messages, num_items_removed, num_items_retained, done.
410 * @param array $tokens Array of tokens.
411 */
412 return apply_filters( 'woocommerce_privacy_erase_personal_data_tokens', $response, $tokens );
413 }
414 }
415