Completed
Push — master ( 376dfe...538a27 )
by Roy
02:16
created
includes/admin/class-wc-stripe-privacy.php 1 patch
Spacing   +95 added lines, -95 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! class_exists( 'WC_Abstract_Privacy' ) ) {
2
+if ( ! class_exists('WC_Abstract_Privacy')) {
3 3
 	return;
4 4
 }
5 5
 
@@ -9,18 +9,18 @@  discard block
 block discarded – undo
9 9
 	 *
10 10
 	 */
11 11
 	public function __construct() {
12
-		parent::__construct( __( 'Stripe', 'woocommerce-gateway-stripe' ) );
12
+		parent::__construct(__('Stripe', 'woocommerce-gateway-stripe'));
13 13
 
14
-		$this->add_exporter( 'woocommerce-gateway-stripe-order-data', __( 'WooCommerce Stripe Order Data', 'woocommerce-gateway-stripe' ), array( $this, 'order_data_exporter' ) );
14
+		$this->add_exporter('woocommerce-gateway-stripe-order-data', __('WooCommerce Stripe Order Data', 'woocommerce-gateway-stripe'), array($this, 'order_data_exporter'));
15 15
 
16
-		if ( function_exists( 'wcs_get_subscriptions' ) ) {
17
-			$this->add_exporter( 'woocommerce-gateway-stripe-subscriptions-data', __( 'WooCommerce Stripe Subscriptions Data', 'woocommerce-gateway-stripe' ), array( $this, 'subscriptions_data_exporter' ) );
16
+		if (function_exists('wcs_get_subscriptions')) {
17
+			$this->add_exporter('woocommerce-gateway-stripe-subscriptions-data', __('WooCommerce Stripe Subscriptions Data', 'woocommerce-gateway-stripe'), array($this, 'subscriptions_data_exporter'));
18 18
 		}
19 19
 
20
-		$this->add_exporter( 'woocommerce-gateway-stripe-customer-data', __( 'WooCommerce Stripe Customer Data', 'woocommerce-gateway-stripe' ), array( $this, 'customer_data_exporter' ) );
20
+		$this->add_exporter('woocommerce-gateway-stripe-customer-data', __('WooCommerce Stripe Customer Data', 'woocommerce-gateway-stripe'), array($this, 'customer_data_exporter'));
21 21
 
22
-		$this->add_eraser( 'woocommerce-gateway-stripe-customer-data', __( 'WooCommerce Stripe Customer Data', 'woocommerce-gateway-stripe' ), array( $this, 'customer_data_eraser' ) );
23
-		$this->add_eraser( 'woocommerce-gateway-stripe-order-data', __( 'WooCommerce Stripe Data', 'woocommerce-gateway-stripe' ), array( $this, 'order_data_eraser' ) );
22
+		$this->add_eraser('woocommerce-gateway-stripe-customer-data', __('WooCommerce Stripe Customer Data', 'woocommerce-gateway-stripe'), array($this, 'customer_data_eraser'));
23
+		$this->add_eraser('woocommerce-gateway-stripe-order-data', __('WooCommerce Stripe Data', 'woocommerce-gateway-stripe'), array($this, 'order_data_eraser'));
24 24
 	}
25 25
 
26 26
 	/**
@@ -31,22 +31,22 @@  discard block
 block discarded – undo
31 31
 	 *
32 32
 	 * @return array WP_Post
33 33
 	 */
34
-	protected function get_stripe_orders( $email_address, $page ) {
35
-		$user = get_user_by( 'email', $email_address ); // Check if user has an ID in the DB to load stored personal data.
34
+	protected function get_stripe_orders($email_address, $page) {
35
+		$user = get_user_by('email', $email_address); // Check if user has an ID in the DB to load stored personal data.
36 36
 
37
-		$order_query    = array(
38
-			'payment_method' => array( 'stripe', 'stripe_alipay', 'stripe_bancontact', 'stripe_eps', 'stripe_giropay', 'stripe_ideal', 'stripe_multibanco', 'stripe_p24', 'stripe_sepa', 'stripe_sofort' ),
37
+		$order_query = array(
38
+			'payment_method' => array('stripe', 'stripe_alipay', 'stripe_bancontact', 'stripe_eps', 'stripe_giropay', 'stripe_ideal', 'stripe_multibanco', 'stripe_p24', 'stripe_sepa', 'stripe_sofort'),
39 39
 			'limit'          => 10,
40 40
 			'page'           => $page,
41 41
 		);
42 42
 
43
-		if ( $user instanceof WP_User ) {
43
+		if ($user instanceof WP_User) {
44 44
 			$order_query['customer_id'] = (int) $user->ID;
45 45
 		} else {
46 46
 			$order_query['billing_email'] = $email_address;
47 47
 		}
48 48
 
49
-		return wc_get_orders( $order_query );
49
+		return wc_get_orders($order_query);
50 50
 	}
51 51
 
52 52
 	/**
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
 	 *
55 55
 	 */
56 56
 	public function get_privacy_message() {
57
-		return wpautop( sprintf( __( 'By using this extension, you may be storing personal data or sharing data with an external service. <a href="%s" target="_blank">Learn more about how this works, including what you may want to include in your privacy policy.</a>', 'woocommerce-gateway-stripe' ), 'https://docs.woocommerce.com/document/privacy-payments/#woocommerce-gateway-stripe' ) );
57
+		return wpautop(sprintf(__('By using this extension, you may be storing personal data or sharing data with an external service. <a href="%s" target="_blank">Learn more about how this works, including what you may want to include in your privacy policy.</a>', 'woocommerce-gateway-stripe'), 'https://docs.woocommerce.com/document/privacy-payments/#woocommerce-gateway-stripe'));
58 58
 	}
59 59
 
60 60
 	/**
@@ -65,34 +65,34 @@  discard block
 block discarded – undo
65 65
 	 *
66 66
 	 * @return array
67 67
 	 */
68
-	public function order_data_exporter( $email_address, $page = 1 ) {
68
+	public function order_data_exporter($email_address, $page = 1) {
69 69
 		$done           = false;
70 70
 		$data_to_export = array();
71 71
 
72
-		$orders = $this->get_stripe_orders( $email_address, (int) $page );
72
+		$orders = $this->get_stripe_orders($email_address, (int) $page);
73 73
 
74 74
 		$done = true;
75 75
 
76
-		if ( 0 < count( $orders ) ) {
77
-			foreach ( $orders as $order ) {
76
+		if (0 < count($orders)) {
77
+			foreach ($orders as $order) {
78 78
 				$data_to_export[] = array(
79 79
 					'group_id'    => 'woocommerce_orders',
80
-					'group_label' => __( 'Orders', 'woocommerce-gateway-stripe' ),
80
+					'group_label' => __('Orders', 'woocommerce-gateway-stripe'),
81 81
 					'item_id'     => 'order-' . $order->get_id(),
82 82
 					'data'        => array(
83 83
 						array(
84
-							'name'  => __( 'Stripe payment id', 'woocommerce-gateway-stripe' ),
85
-							'value' => get_post_meta( $order->get_id(), '_stripe_source_id', true ),
84
+							'name'  => __('Stripe payment id', 'woocommerce-gateway-stripe'),
85
+							'value' => get_post_meta($order->get_id(), '_stripe_source_id', true),
86 86
 						),
87 87
 						array(
88
-							'name'  => __( 'Stripe customer id', 'woocommerce-gateway-stripe' ),
89
-							'value' => get_post_meta( $order->get_id(), '_stripe_customer_id', true ),
88
+							'name'  => __('Stripe customer id', 'woocommerce-gateway-stripe'),
89
+							'value' => get_post_meta($order->get_id(), '_stripe_customer_id', true),
90 90
 						),
91 91
 					),
92 92
 				);
93 93
 			}
94 94
 
95
-			$done = 10 > count( $orders );
95
+			$done = 10 > count($orders);
96 96
 		}
97 97
 
98 98
 		return array(
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
 	 *
110 110
 	 * @return array
111 111
 	 */
112
-	public function subscriptions_data_exporter( $email_address, $page = 1 ) {
112
+	public function subscriptions_data_exporter($email_address, $page = 1) {
113 113
 		$done           = false;
114 114
 		$page           = (int) $page;
115 115
 		$data_to_export = array();
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
 			'relation'    => 'AND',
119 119
 			array(
120 120
 				'key'     => '_payment_method',
121
-				'value'   => array( 'stripe', 'stripe_alipay', 'stripe_bancontact', 'stripe_eps', 'stripe_giropay', 'stripe_ideal', 'stripe_multibanco', 'stripe_p24', 'stripe_sepa', 'stripe_sofort' ),
121
+				'value'   => array('stripe', 'stripe_alipay', 'stripe_bancontact', 'stripe_eps', 'stripe_giropay', 'stripe_ideal', 'stripe_multibanco', 'stripe_p24', 'stripe_sepa', 'stripe_sofort'),
122 122
 				'compare' => 'IN',
123 123
 			),
124 124
 			array(
@@ -128,36 +128,36 @@  discard block
 block discarded – undo
128 128
 			),
129 129
 		);
130 130
 
131
-		$subscription_query    = array(
131
+		$subscription_query = array(
132 132
 			'posts_per_page'  => 10,
133 133
 			'page'            => $page,
134 134
 			'meta_query'      => $meta_query,
135 135
 		);
136 136
 
137
-		$subscriptions = wcs_get_subscriptions( $subscription_query );
137
+		$subscriptions = wcs_get_subscriptions($subscription_query);
138 138
 
139 139
 		$done = true;
140 140
 
141
-		if ( 0 < count( $subscriptions ) ) {
142
-			foreach ( $subscriptions as $subscription ) {
141
+		if (0 < count($subscriptions)) {
142
+			foreach ($subscriptions as $subscription) {
143 143
 				$data_to_export[] = array(
144 144
 					'group_id'    => 'woocommerce_subscriptions',
145
-					'group_label' => __( 'Subscriptions', 'woocommerce-gateway-stripe' ),
145
+					'group_label' => __('Subscriptions', 'woocommerce-gateway-stripe'),
146 146
 					'item_id'     => 'subscription-' . $subscription->get_id(),
147 147
 					'data'        => array(
148 148
 						array(
149
-							'name'  => __( 'Stripe payment id', 'woocommerce-gateway-stripe' ),
150
-							'value' => get_post_meta( $subscription->get_id(), '_stripe_source_id', true ),
149
+							'name'  => __('Stripe payment id', 'woocommerce-gateway-stripe'),
150
+							'value' => get_post_meta($subscription->get_id(), '_stripe_source_id', true),
151 151
 						),
152 152
 						array(
153
-							'name'  => __( 'Stripe customer id', 'woocommerce-gateway-stripe' ),
154
-							'value' => get_post_meta( $subscription->get_id(), '_stripe_customer_id', true ),
153
+							'name'  => __('Stripe customer id', 'woocommerce-gateway-stripe'),
154
+							'value' => get_post_meta($subscription->get_id(), '_stripe_customer_id', true),
155 155
 						),
156 156
 					),
157 157
 				);
158 158
 			}
159 159
 
160
-			$done = 10 > count( $subscriptions );
160
+			$done = 10 > count($subscriptions);
161 161
 		}
162 162
 
163 163
 		return array(
@@ -173,24 +173,24 @@  discard block
 block discarded – undo
173 173
 	 * @param int    $page  Page.
174 174
 	 * @return array An array of personal data in name value pairs
175 175
 	 */
176
-	public function customer_data_exporter( $email_address, $page ) {
177
-		$user           = get_user_by( 'email', $email_address ); // Check if user has an ID in the DB to load stored personal data.
176
+	public function customer_data_exporter($email_address, $page) {
177
+		$user           = get_user_by('email', $email_address); // Check if user has an ID in the DB to load stored personal data.
178 178
 		$data_to_export = array();
179 179
 
180
-		if ( $user instanceof WP_User ) {
181
-			$stripe_user = new WC_Stripe_Customer( $user->ID );
180
+		if ($user instanceof WP_User) {
181
+			$stripe_user = new WC_Stripe_Customer($user->ID);
182 182
 
183 183
 			$data_to_export[] = array(
184 184
 				'group_id'    => 'woocommerce_customer',
185
-				'group_label' => __( 'Customer Data', 'woocommerce-gateway-stripe' ),
185
+				'group_label' => __('Customer Data', 'woocommerce-gateway-stripe'),
186 186
 				'item_id'     => 'user',
187 187
 				'data'        => array(
188 188
 					array(
189
-						'name'  => __( 'Stripe payment id', 'woocommerce-gateway-stripe' ),
190
-						'value' => get_user_meta( $user->ID, '_stripe_source_id', true ),
189
+						'name'  => __('Stripe payment id', 'woocommerce-gateway-stripe'),
190
+						'value' => get_user_meta($user->ID, '_stripe_source_id', true),
191 191
 					),
192 192
 					array(
193
-						'name'  => __( 'Stripe customer id', 'woocommerce-gateway-stripe' ),
193
+						'name'  => __('Stripe customer id', 'woocommerce-gateway-stripe'),
194 194
 						'value' => $stripe_user->get_id(),
195 195
 					),
196 196
 				),
@@ -210,21 +210,21 @@  discard block
 block discarded – undo
210 210
 	 * @param int    $page  Page.
211 211
 	 * @return array An array of personal data in name value pairs
212 212
 	 */
213
-	public function customer_data_eraser( $email_address, $page ) {
213
+	public function customer_data_eraser($email_address, $page) {
214 214
 		$page = (int) $page;
215
-		$user = get_user_by( 'email', $email_address ); // Check if user has an ID in the DB to load stored personal data.
215
+		$user = get_user_by('email', $email_address); // Check if user has an ID in the DB to load stored personal data.
216 216
 
217
-		$stripe_customer_id = get_user_meta( $user->ID, '_stripe_customer_id', true );
218
-		$stripe_source_id   = get_user_meta( $user->ID, '_stripe_source_id', true );
217
+		$stripe_customer_id = get_user_meta($user->ID, '_stripe_customer_id', true);
218
+		$stripe_source_id   = get_user_meta($user->ID, '_stripe_source_id', true);
219 219
 
220 220
 		$items_removed  = false;
221 221
 		$messages       = array();
222 222
 
223
-		if ( ! empty( $stripe_customer_id ) || ! empty( $stripe_source_id ) ) {
223
+		if ( ! empty($stripe_customer_id) || ! empty($stripe_source_id)) {
224 224
 			$items_removed = true;
225
-			delete_user_meta( $user->ID, '_stripe_customer_id' );
226
-			delete_user_meta( $user->ID, '_stripe_source_id' );
227
-			$messages[] = __( 'Stripe User Data Erased.', 'woocommerce-gateway-stripe' );
225
+			delete_user_meta($user->ID, '_stripe_customer_id');
226
+			delete_user_meta($user->ID, '_stripe_source_id');
227
+			$messages[] = __('Stripe User Data Erased.', 'woocommerce-gateway-stripe');
228 228
 		}
229 229
 
230 230
 		return array(
@@ -242,29 +242,29 @@  discard block
 block discarded – undo
242 242
 	 * @param int    $page  Page.
243 243
 	 * @return array An array of personal data in name value pairs
244 244
 	 */
245
-	public function order_data_eraser( $email_address, $page ) {
246
-		$orders = $this->get_stripe_orders( $email_address, (int) $page );
245
+	public function order_data_eraser($email_address, $page) {
246
+		$orders = $this->get_stripe_orders($email_address, (int) $page);
247 247
 
248 248
 		$items_removed  = false;
249 249
 		$items_retained = false;
250 250
 		$messages       = array();
251 251
 
252
-		foreach ( (array) $orders as $order ) {
253
-			$order = wc_get_order( $order->get_id() );
252
+		foreach ((array) $orders as $order) {
253
+			$order = wc_get_order($order->get_id());
254 254
 
255
-			list( $removed, $retained, $msgs ) = $this->maybe_handle_order( $order );
255
+			list($removed, $retained, $msgs) = $this->maybe_handle_order($order);
256 256
 			$items_removed  |= $removed;
257 257
 			$items_retained |= $retained;
258
-			$messages        = array_merge( $messages, $msgs );
258
+			$messages        = array_merge($messages, $msgs);
259 259
 
260
-			list( $removed, $retained, $msgs ) = $this->maybe_handle_subscription( $order );
260
+			list($removed, $retained, $msgs) = $this->maybe_handle_subscription($order);
261 261
 			$items_removed  |= $removed;
262 262
 			$items_retained |= $retained;
263
-			$messages        = array_merge( $messages, $msgs );
263
+			$messages        = array_merge($messages, $msgs);
264 264
 		}
265 265
 
266 266
 		// Tell core if we have more orders to work on still
267
-		$done = count( $orders ) < 10;
267
+		$done = count($orders) < 10;
268 268
 
269 269
 		return array(
270 270
 			'items_removed'  => $items_removed,
@@ -280,49 +280,49 @@  discard block
 block discarded – undo
280 280
 	 * @param WC_Order $order
281 281
 	 * @return array
282 282
 	 */
283
-	protected function maybe_handle_subscription( $order ) {
284
-		if ( ! class_exists( 'WC_Subscriptions' ) ) {
285
-			return array( false, false, array() );
283
+	protected function maybe_handle_subscription($order) {
284
+		if ( ! class_exists('WC_Subscriptions')) {
285
+			return array(false, false, array());
286 286
 		}
287 287
 
288
-		if ( ! wcs_order_contains_subscription( $order ) ) {
289
-			return array( false, false, array() );
288
+		if ( ! wcs_order_contains_subscription($order)) {
289
+			return array(false, false, array());
290 290
 		}
291 291
 
292
-		$subscription    = current( wcs_get_subscriptions_for_order( $order->get_id() ) );
292
+		$subscription    = current(wcs_get_subscriptions_for_order($order->get_id()));
293 293
 		$subscription_id = $subscription->get_id();
294 294
 
295
-		$stripe_source_id = get_post_meta( $subscription_id, '_stripe_source_id', true );
295
+		$stripe_source_id = get_post_meta($subscription_id, '_stripe_source_id', true);
296 296
 
297
-		if ( empty( $stripe_source_id ) ) {
298
-			return array( false, false, array() );
297
+		if (empty($stripe_source_id)) {
298
+			return array(false, false, array());
299 299
 		}
300 300
 
301
-		$order_age = strtotime( 'now' ) - $order->get_date_created()->getTimestamp();
301
+		$order_age = strtotime('now') - $order->get_date_created()->getTimestamp();
302 302
 
303 303
 		// If order age is longer than specified days, don't do anything to it
304 304
 		// TODO: Figure out if 180 is the real number
305
-		if ( $order_age < DAY_IN_SECONDS * 180 ) {
306
-			return array( false, true, array( sprintf( __( 'Order ID %d is less than 180 days (Stripe)' ), $order->get_id() ) ) );
305
+		if ($order_age < DAY_IN_SECONDS * 180) {
306
+			return array(false, true, array(sprintf(__('Order ID %d is less than 180 days (Stripe)'), $order->get_id())));
307 307
 		}
308 308
 
309
-		if ( $subscription->has_status( apply_filters( 'wc_stripe_privacy_eraser_subs_statuses', array( 'on-hold', 'active' ) ) ) ) {
310
-			return array( false, true, array( sprintf( __( 'Order ID %d contains an active Subscription' ), $order->get_id() ) ) );
309
+		if ($subscription->has_status(apply_filters('wc_stripe_privacy_eraser_subs_statuses', array('on-hold', 'active')))) {
310
+			return array(false, true, array(sprintf(__('Order ID %d contains an active Subscription'), $order->get_id())));
311 311
 		}
312 312
 
313
-		$renewal_orders = WC_Subscriptions_Renewal_Order::get_renewal_orders( $order->get_id() );
313
+		$renewal_orders = WC_Subscriptions_Renewal_Order::get_renewal_orders($order->get_id());
314 314
 
315
-		foreach ( $renewal_orders as $renewal_order_id ) {
316
-			delete_post_meta( $renewal_order_id, '_stripe_source_id' );
317
-			delete_post_meta( $renewal_order_id, '_stripe_refund_id' );
318
-			delete_post_meta( $renewal_order_id, '_stripe_customer_id' );
315
+		foreach ($renewal_orders as $renewal_order_id) {
316
+			delete_post_meta($renewal_order_id, '_stripe_source_id');
317
+			delete_post_meta($renewal_order_id, '_stripe_refund_id');
318
+			delete_post_meta($renewal_order_id, '_stripe_customer_id');
319 319
 		}
320 320
 
321
-		delete_post_meta( $subscription_id, '_stripe_source_id' );
322
-		delete_post_meta( $subscription_id, '_stripe_refund_id' );
323
-		delete_post_meta( $subscription_id, '_stripe_customer_id' );
321
+		delete_post_meta($subscription_id, '_stripe_source_id');
322
+		delete_post_meta($subscription_id, '_stripe_refund_id');
323
+		delete_post_meta($subscription_id, '_stripe_customer_id');
324 324
 
325
-		return array( true, false, array( __( 'Stripe Subscription Data Erased.', 'woocommerce-gateway-stripe' ) ) );
325
+		return array(true, false, array(__('Stripe Subscription Data Erased.', 'woocommerce-gateway-stripe')));
326 326
 	}
327 327
 
328 328
 	/**
@@ -331,21 +331,21 @@  discard block
 block discarded – undo
331 331
 	 * @param WC_Order $order
332 332
 	 * @return array
333 333
 	 */
334
-	protected function maybe_handle_order( $order ) {
334
+	protected function maybe_handle_order($order) {
335 335
 		$order_id           = $order->get_id();
336
-		$stripe_source_id   = get_post_meta( $order_id, '_stripe_source_id', true );
337
-		$stripe_refund_id   = get_post_meta( $order_id, '_stripe_refund_id', true );
338
-		$stripe_customer_id = get_post_meta( $order_id, '_stripe_customer_id', true );
336
+		$stripe_source_id   = get_post_meta($order_id, '_stripe_source_id', true);
337
+		$stripe_refund_id   = get_post_meta($order_id, '_stripe_refund_id', true);
338
+		$stripe_customer_id = get_post_meta($order_id, '_stripe_customer_id', true);
339 339
 
340
-		if ( empty( $stripe_source_id ) && empty( $stripe_refund_id ) && empty( $stripe_customer_id ) ) {
341
-			return array( false, false, array() );
340
+		if (empty($stripe_source_id) && empty($stripe_refund_id) && empty($stripe_customer_id)) {
341
+			return array(false, false, array());
342 342
 		}
343 343
 
344
-		delete_post_meta( $order_id, '_stripe_source_id' );
345
-		delete_post_meta( $order_id, '_stripe_refund_id' );
346
-		delete_post_meta( $order_id, '_stripe_customer_id' );
344
+		delete_post_meta($order_id, '_stripe_source_id');
345
+		delete_post_meta($order_id, '_stripe_refund_id');
346
+		delete_post_meta($order_id, '_stripe_customer_id');
347 347
 
348
-		return array( true, false, array( __( 'Stripe personal data erased.', 'woocommerce-gateway-stripe' ) ) );
348
+		return array(true, false, array(__('Stripe personal data erased.', 'woocommerce-gateway-stripe')));
349 349
 	}
350 350
 }
351 351
 
Please login to merge, or discard this patch.