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