Test Failed
Push — master ( 966cf3...fe1ced )
by Devin
13:57 queued 06:53
created
includes/admin/tools/data/class-give-tools-recount-all-stats.php 1 patch
Spacing   +95 added lines, -97 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@  discard block
 block discarded – undo
11 11
  */
12 12
 
13 13
 // Exit if accessed directly.
14
-if ( ! defined( 'ABSPATH' ) ) {
14
+if ( ! defined('ABSPATH')) {
15 15
 	exit;
16 16
 }
17 17
 
@@ -80,108 +80,106 @@  discard block
 block discarded – undo
80 80
 	 */
81 81
 	public function get_data() {
82 82
 
83
-		$totals             = $this->get_stored_data( 'give_temp_recount_all_stats' );
84
-		$payment_items      = $this->get_stored_data( 'give_temp_payment_items' );
85
-		$processed_payments = $this->get_stored_data( 'give_temp_processed_payments' );
86
-		$accepted_statuses  = apply_filters( 'give_recount_accepted_statuses', array( 'publish' ) );
83
+		$totals             = $this->get_stored_data('give_temp_recount_all_stats');
84
+		$payment_items      = $this->get_stored_data('give_temp_payment_items');
85
+		$processed_payments = $this->get_stored_data('give_temp_processed_payments');
86
+		$accepted_statuses  = apply_filters('give_recount_accepted_statuses', array('publish'));
87 87
 
88
-		if ( false === $totals ) {
88
+		if (false === $totals) {
89 89
 			$totals = array();
90 90
 		}
91 91
 
92
-		if ( false === $payment_items ) {
92
+		if (false === $payment_items) {
93 93
 			$payment_items = array();
94 94
 		}
95 95
 
96
-		if ( false === $processed_payments ) {
96
+		if (false === $processed_payments) {
97 97
 			$processed_payments = array();
98 98
 		}
99 99
 
100
-		$all_forms = $this->get_stored_data( 'give_temp_form_ids' );
100
+		$all_forms = $this->get_stored_data('give_temp_form_ids');
101 101
 
102
-		$payments = $this->get_stored_data( 'give_temp_all_payments_data' );
102
+		$payments = $this->get_stored_data('give_temp_all_payments_data');
103 103
 
104
-		if ( empty( $payments ) ) {
105
-			$args = apply_filters( 'give_recount_form_stats_args', array(
104
+		if (empty($payments)) {
105
+			$args = apply_filters('give_recount_form_stats_args', array(
106 106
 				'give_forms' => $all_forms,
107 107
 				'number'     => $this->per_step,
108 108
 				'status'     => $accepted_statuses,
109 109
 				'paged'      => $this->step,
110 110
 				'output'     => 'give_payments',
111
-			) );
111
+			));
112 112
 
113
-			$payments_query = new Give_Payments_Query( $args );
113
+			$payments_query = new Give_Payments_Query($args);
114 114
 			$payments       = $payments_query->get_payments();
115 115
 		}
116 116
 
117
-		if ( ! empty( $payments ) ) {
117
+		if ( ! empty($payments)) {
118 118
 
119 119
 			//Loop through payments
120
-			foreach ( $payments as $payment ) {
120
+			foreach ($payments as $payment) {
121 121
 
122
-				$payment_id = ( ! empty( $payment['ID'] ) ? absint( $payment['ID'] ) : ( ! empty( $payment->ID ) ? absint( $payment->ID ) : false ) );
123
-				$payment = new Give_Payment( $payment_id );
122
+				$payment_id = ( ! empty($payment['ID']) ? absint($payment['ID']) : ( ! empty($payment->ID) ? absint($payment->ID) : false));
123
+				$payment = new Give_Payment($payment_id);
124 124
 
125 125
 				// Prevent payments that have all ready been retrieved from a previous sales log from counting again.
126
-				if ( in_array( $payment->ID, $processed_payments ) ) {
126
+				if (in_array($payment->ID, $processed_payments)) {
127 127
 					continue;
128 128
 				}
129 129
 
130 130
 				// Verify accepted status.
131
-				if ( ! in_array( $payment->post_status, $accepted_statuses ) ) {
131
+				if ( ! in_array($payment->post_status, $accepted_statuses)) {
132 132
 					$processed_payments[] = $payment->ID;
133 133
 					continue;
134 134
 				}
135 135
 
136
-				$payment_item = $payment_items[ $payment->ID ];
136
+				$payment_item = $payment_items[$payment->ID];
137 137
 
138
-				$form_id = isset( $payment_item['id'] ) ? $payment_item['id'] : '';
138
+				$form_id = isset($payment_item['id']) ? $payment_item['id'] : '';
139 139
 
140 140
 				// Must have a form ID.
141
-				if ( empty( $form_id ) ) {
141
+				if (empty($form_id)) {
142 142
 					continue;
143 143
 				}
144 144
 
145 145
 				// Form ID must be within $all_forms array to be validated.
146
-				if ( ! in_array( $form_id, $all_forms ) ) {
146
+				if ( ! in_array($form_id, $all_forms)) {
147 147
 					continue;
148 148
 				}
149 149
 
150 150
 				// Set Sales count
151
-				$totals[ $form_id ]['sales'] = isset( $totals[ $form_id ]['sales'] ) ?
152
-					++ $totals[ $form_id ]['sales'] :
153
-					1;
151
+				$totals[$form_id]['sales'] = isset($totals[$form_id]['sales']) ?
152
+					++$totals[$form_id]['sales'] : 1;
154 153
 
155 154
 				// Set Total Earnings
156
-				$totals[ $form_id ]['earnings'] = isset( $totals[ $form_id ]['earnings'] ) ?
157
-					( $totals[ $form_id ]['earnings'] + $payment_item['price'] ) :
158
-					$payment_item['price'];
155
+				$totals[$form_id]['earnings'] = isset($totals[$form_id]['earnings']) ?
156
+					($totals[$form_id]['earnings'] + $payment_item['price']) : $payment_item['price'];
159 157
 
160 158
 				$processed_payments[] = $payment->ID;
161 159
 			}
162 160
 
163 161
 			// Get the list of form ids which does not contain any payment record.
164
-			$remaining_form_ids = array_diff( $all_forms, array_keys( $totals ) );
165
-			foreach ( $remaining_form_ids as $form_id ) {
162
+			$remaining_form_ids = array_diff($all_forms, array_keys($totals));
163
+			foreach ($remaining_form_ids as $form_id) {
166 164
 				//If array key doesn't exist, create it
167
-				if ( ! array_key_exists( $form_id, $totals ) ) {
168
-					$totals[ $form_id ] = array(
165
+				if ( ! array_key_exists($form_id, $totals)) {
166
+					$totals[$form_id] = array(
169 167
 						'sales'    => (int) 0,
170 168
 						'earnings' => (float) 0,
171 169
 					);
172 170
 				}
173 171
 			}
174 172
 
175
-			$this->store_data( 'give_temp_processed_payments', $processed_payments );
176
-			$this->store_data( 'give_temp_recount_all_stats', $totals );
173
+			$this->store_data('give_temp_processed_payments', $processed_payments);
174
+			$this->store_data('give_temp_recount_all_stats', $totals);
177 175
 
178 176
 			return true;
179 177
 		}
180 178
 
181 179
 
182
-		foreach ( $totals as $key => $stats ) {
183
-			give_update_meta( $key, '_give_form_sales', $stats['sales'] );
184
-			give_update_meta( $key, '_give_form_earnings', give_sanitize_amount_for_db( $stats['earnings'] ) );
180
+		foreach ($totals as $key => $stats) {
181
+			give_update_meta($key, '_give_form_sales', $stats['sales']);
182
+			give_update_meta($key, '_give_form_earnings', give_sanitize_amount_for_db($stats['earnings']));
185 183
 		}
186 184
 
187 185
 		return false;
@@ -196,20 +194,20 @@  discard block
 block discarded – undo
196 194
 	 */
197 195
 	public function get_percentage_complete() {
198 196
 
199
-		$total = $this->get_stored_data( 'give_recount_all_total' );
197
+		$total = $this->get_stored_data('give_recount_all_total');
200 198
 
201
-		if ( false === $total ) {
199
+		if (false === $total) {
202 200
 			$this->pre_fetch();
203
-			$total = $this->get_stored_data( 'give_recount_all_total' );
201
+			$total = $this->get_stored_data('give_recount_all_total');
204 202
 		}
205 203
 
206 204
 		$percentage = 100;
207 205
 
208
-		if ( $total > 0 ) {
209
-			$percentage = ( ( $this->per_step * $this->step ) / $total ) * 100;
206
+		if ($total > 0) {
207
+			$percentage = (($this->per_step * $this->step) / $total) * 100;
210 208
 		}
211 209
 
212
-		if ( $percentage > 100 ) {
210
+		if ($percentage > 100) {
213 211
 			$percentage = 100;
214 212
 		}
215 213
 
@@ -223,8 +221,8 @@  discard block
 block discarded – undo
223 221
 	 *
224 222
 	 * @param array $request The Form Data passed into the batch processing
225 223
 	 */
226
-	public function set_properties( $request ) {
227
-		$this->form_id = isset( $request['form_id'] ) ? sanitize_text_field( $request['form_id'] ) : false;
224
+	public function set_properties($request) {
225
+		$this->form_id = isset($request['form_id']) ? sanitize_text_field($request['form_id']) : false;
228 226
 	}
229 227
 
230 228
 	/**
@@ -235,25 +233,25 @@  discard block
 block discarded – undo
235 233
 	 */
236 234
 	public function process_step() {
237 235
 
238
-		if ( ! $this->can_export() ) {
239
-			wp_die( esc_html__( 'You do not have permission to recount stats.', 'give' ), esc_html__( 'Error', 'give' ), array( 'response' => 403 ) );
236
+		if ( ! $this->can_export()) {
237
+			wp_die(esc_html__('You do not have permission to recount stats.', 'give'), esc_html__('Error', 'give'), array('response' => 403));
240 238
 		}
241 239
 
242 240
 		$had_data = $this->get_data();
243 241
 
244
-		if ( $had_data ) {
242
+		if ($had_data) {
245 243
 			$this->done = false;
246 244
 
247 245
 			return true;
248 246
 		} else {
249
-			$this->delete_data( 'give_recount_total_' . $this->form_id );
250
-			$this->delete_data( 'give_recount_all_total' );
251
-			$this->delete_data( 'give_temp_recount_all_stats' );
252
-			$this->delete_data( 'give_temp_payment_items' );
253
-			$this->delete_data( 'give_temp_form_ids' );
254
-			$this->delete_data( 'give_temp_processed_payments' );
247
+			$this->delete_data('give_recount_total_'.$this->form_id);
248
+			$this->delete_data('give_recount_all_total');
249
+			$this->delete_data('give_temp_recount_all_stats');
250
+			$this->delete_data('give_temp_payment_items');
251
+			$this->delete_data('give_temp_form_ids');
252
+			$this->delete_data('give_temp_processed_payments');
255 253
 			$this->done    = true;
256
-			$this->message = esc_html__( 'Donation form income amounts and donation counts stats successfully recounted.', 'give' );
254
+			$this->message = esc_html__('Donation form income amounts and donation counts stats successfully recounted.', 'give');
257 255
 
258 256
 			return false;
259 257
 		}
@@ -289,70 +287,70 @@  discard block
 block discarded – undo
289 287
 	 */
290 288
 	public function pre_fetch() {
291 289
 
292
-		if ( 1 == $this->step ) {
293
-			$this->delete_data( 'give_temp_recount_all_total' );
294
-			$this->delete_data( 'give_temp_recount_all_stats' );
295
-			$this->delete_data( 'give_temp_payment_items' );
296
-			$this->delete_data( 'give_temp_processed_payments' );
297
-			$this->delete_data( 'give_temp_all_payments_data' );
290
+		if (1 == $this->step) {
291
+			$this->delete_data('give_temp_recount_all_total');
292
+			$this->delete_data('give_temp_recount_all_stats');
293
+			$this->delete_data('give_temp_payment_items');
294
+			$this->delete_data('give_temp_processed_payments');
295
+			$this->delete_data('give_temp_all_payments_data');
298 296
 		}
299 297
 
300
-		$accepted_statuses = apply_filters( 'give_recount_accepted_statuses', array( 'publish' ) );
301
-		$total             = $this->get_stored_data( 'give_temp_recount_all_total' );
298
+		$accepted_statuses = apply_filters('give_recount_accepted_statuses', array('publish'));
299
+		$total             = $this->get_stored_data('give_temp_recount_all_total');
302 300
 
303
-		if ( false === $total ) {
301
+		if (false === $total) {
304 302
 
305
-			$payment_items = $this->get_stored_data( 'give_temp_payment_items' );
303
+			$payment_items = $this->get_stored_data('give_temp_payment_items');
306 304
 
307
-			if ( false === $payment_items ) {
305
+			if (false === $payment_items) {
308 306
 				$payment_items = array();
309
-				$this->store_data( 'give_temp_payment_items', $payment_items );
307
+				$this->store_data('give_temp_payment_items', $payment_items);
310 308
 			}
311 309
 
312 310
 			$args = array(
313 311
 				'post_status'    => 'publish',
314 312
 				'post_type'      => 'give_forms',
315
-				'posts_per_page' => - 1,
313
+				'posts_per_page' => -1,
316 314
 				'fields'         => 'ids',
317 315
 			);
318 316
 
319
-			$all_forms = get_posts( $args );
317
+			$all_forms = get_posts($args);
320 318
 
321
-			$this->store_data( 'give_temp_form_ids', $all_forms );
319
+			$this->store_data('give_temp_form_ids', $all_forms);
322 320
 
323
-			$args = apply_filters( 'give_recount_form_stats_total_args', array(
321
+			$args = apply_filters('give_recount_form_stats_total_args', array(
324 322
 				'give_forms' => $all_forms,
325 323
 				'number'     => $this->per_step,
326 324
 				'status'     => $accepted_statuses,
327 325
 				'page'       => $this->step,
328 326
 				'output'     => 'payments',
329
-			) );
327
+			));
330 328
 
331
-			$payments_query = new Give_Payments_Query( $args );
329
+			$payments_query = new Give_Payments_Query($args);
332 330
 			$payments       = $payments_query->get_payments();
333 331
 
334
-			$total = wp_count_posts( 'give_payment' )->publish;
332
+			$total = wp_count_posts('give_payment')->publish;
335 333
 
336
-			$this->store_data( 'give_temp_all_payments_data', $payments );
334
+			$this->store_data('give_temp_all_payments_data', $payments);
337 335
 
338
-			if ( $payments ) {
336
+			if ($payments) {
339 337
 
340
-				foreach ( $payments as $payment ) {
338
+				foreach ($payments as $payment) {
341 339
 
342 340
 					$form_id = $payment->form_id;
343 341
 
344 342
 					//If for some reason somehow the form_ID isn't set check payment meta
345
-					if ( empty( $payment->form_id ) ) {
343
+					if (empty($payment->form_id)) {
346 344
 						$payment_meta = $payment->get_meta();
347
-						$form_id      = isset( $payment_meta['form_id'] ) ? $payment_meta['form_id'] : 0;
345
+						$form_id      = isset($payment_meta['form_id']) ? $payment_meta['form_id'] : 0;
348 346
 					}
349 347
 
350
-					if ( ! in_array( $payment->post_status, $accepted_statuses ) ) {
348
+					if ( ! in_array($payment->post_status, $accepted_statuses)) {
351 349
 						continue;
352 350
 					}
353 351
 
354
-					if ( ! array_key_exists( $payment->ID, $payment_items ) ) {
355
-						$payment_items[ $payment->ID ] = array(
352
+					if ( ! array_key_exists($payment->ID, $payment_items)) {
353
+						$payment_items[$payment->ID] = array(
356 354
 							'id'         => $form_id,
357 355
 							'payment_id' => $payment->ID,
358 356
 							'price'      => $payment->total,
@@ -360,8 +358,8 @@  discard block
 block discarded – undo
360 358
 					}
361 359
 				}
362 360
 			}
363
-			$this->store_data( 'give_temp_payment_items', $payment_items );
364
-			$this->store_data( 'give_recount_all_total', $total );
361
+			$this->store_data('give_temp_payment_items', $payment_items);
362
+			$this->store_data('give_recount_all_total', $total);
365 363
 		}
366 364
 
367 365
 	}
@@ -375,17 +373,17 @@  discard block
 block discarded – undo
375 373
 	 *
376 374
 	 * @return mixed       Returns the data from the database
377 375
 	 */
378
-	private function get_stored_data( $key ) {
376
+	private function get_stored_data($key) {
379 377
 		global $wpdb;
380
-		$value = $wpdb->get_var( $wpdb->prepare( "SELECT option_value FROM $wpdb->options WHERE option_name = '%s'", $key ) );
381
-		if ( empty( $value ) ) {
378
+		$value = $wpdb->get_var($wpdb->prepare("SELECT option_value FROM $wpdb->options WHERE option_name = '%s'", $key));
379
+		if (empty($value)) {
382 380
 			return false;
383 381
 		}
384 382
 
385
-		$maybe_json = json_decode( $value );
383
+		$maybe_json = json_decode($value);
386 384
 
387
-		if ( ! is_null( $maybe_json ) ) {
388
-			$value = json_decode( $value, true );
385
+		if ( ! is_null($maybe_json)) {
386
+			$value = json_decode($value, true);
389 387
 		}
390 388
 
391 389
 		return $value;
@@ -401,10 +399,10 @@  discard block
 block discarded – undo
401 399
 	 *
402 400
 	 * @return void
403 401
 	 */
404
-	private function store_data( $key, $value ) {
402
+	private function store_data($key, $value) {
405 403
 		global $wpdb;
406 404
 
407
-		$value = is_array( $value ) ? wp_json_encode( $value ) : esc_attr( $value );
405
+		$value = is_array($value) ? wp_json_encode($value) : esc_attr($value);
408 406
 
409 407
 		$data = array(
410 408
 			'option_name'  => $key,
@@ -418,7 +416,7 @@  discard block
 block discarded – undo
418 416
 			'%s',
419 417
 		);
420 418
 
421
-		$wpdb->replace( $wpdb->options, $data, $formats );
419
+		$wpdb->replace($wpdb->options, $data, $formats);
422 420
 	}
423 421
 
424 422
 	/**
@@ -430,9 +428,9 @@  discard block
 block discarded – undo
430 428
 	 *
431 429
 	 * @return void
432 430
 	 */
433
-	private function delete_data( $key ) {
431
+	private function delete_data($key) {
434 432
 		global $wpdb;
435
-		$wpdb->delete( $wpdb->options, array( 'option_name' => $key ) );
433
+		$wpdb->delete($wpdb->options, array('option_name' => $key));
436 434
 	}
437 435
 
438 436
 }
Please login to merge, or discard this patch.
includes/admin/tools/data/class-give-tools-recount-single-donor-stats.php 1 patch
Spacing   +71 added lines, -71 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@  discard block
 block discarded – undo
11 11
  */
12 12
 
13 13
 // Exit if accessed directly.
14
-if ( ! defined( 'ABSPATH' ) ) {
14
+if ( ! defined('ABSPATH')) {
15 15
 	exit;
16 16
 }
17 17
 
@@ -53,40 +53,40 @@  discard block
 block discarded – undo
53 53
 	 */
54 54
 	public function get_data() {
55 55
 
56
-		$donor    = new Give_Donor( $this->customer_id );
57
-		$payments = $this->get_stored_data( 'give_recount_donor_payments_' . $donor->id );
56
+		$donor    = new Give_Donor($this->customer_id);
57
+		$payments = $this->get_stored_data('give_recount_donor_payments_'.$donor->id);
58 58
 
59
-		$offset     = ( $this->step - 1 ) * $this->per_step;
60
-		$step_items = array_slice( $payments, $offset, $this->per_step );
59
+		$offset     = ($this->step - 1) * $this->per_step;
60
+		$step_items = array_slice($payments, $offset, $this->per_step);
61 61
 
62
-		if ( count( $step_items ) > 0 ) {
63
-			$pending_total = (float) $this->get_stored_data( 'give_stats_donor_pending_total' . $donor->id );
62
+		if (count($step_items) > 0) {
63
+			$pending_total = (float) $this->get_stored_data('give_stats_donor_pending_total'.$donor->id);
64 64
 			$step_total    = 0;
65 65
 
66
-			$found_payment_ids = $this->get_stored_data( 'give_stats_found_payments_' . $donor->id );
66
+			$found_payment_ids = $this->get_stored_data('give_stats_found_payments_'.$donor->id);
67 67
 
68
-			foreach ( $step_items as $payment ) {
69
-				$payment = get_post( $payment->ID );
68
+			foreach ($step_items as $payment) {
69
+				$payment = get_post($payment->ID);
70 70
 
71
-				if ( is_null( $payment ) || is_wp_error( $payment ) || 'give_payment' !== $payment->post_type ) {
71
+				if (is_null($payment) || is_wp_error($payment) || 'give_payment' !== $payment->post_type) {
72 72
 
73
-					$missing_payments   = $this->get_stored_data( 'give_stats_missing_payments' . $donor->id );
73
+					$missing_payments   = $this->get_stored_data('give_stats_missing_payments'.$donor->id);
74 74
 					$missing_payments[] = $payment->ID;
75
-					$this->store_data( 'give_stats_missing_payments' . $donor->id, $missing_payments );
75
+					$this->store_data('give_stats_missing_payments'.$donor->id, $missing_payments);
76 76
 
77 77
 					continue;
78 78
 				}
79 79
 
80 80
 				$should_process_payment = 'publish' == $payment->post_status ? true : false;
81
-				$should_process_payment = apply_filters( 'give_donor_recount_should_process_donation', $should_process_payment, $payment );
81
+				$should_process_payment = apply_filters('give_donor_recount_should_process_donation', $should_process_payment, $payment);
82 82
 
83
-				if ( true === $should_process_payment ) {
83
+				if (true === $should_process_payment) {
84 84
 
85 85
 					$found_payment_ids[] = $payment->ID;
86 86
 
87
-					if ( apply_filters( 'give_donor_recount_should_increase_value', true, $payment ) ) {
88
-						$payment_amount = (float) give_donation_amount( $payment->ID, array( 'type' => 'stats' ) );
89
-						$step_total     += $payment_amount;
87
+					if (apply_filters('give_donor_recount_should_increase_value', true, $payment)) {
88
+						$payment_amount = (float) give_donation_amount($payment->ID, array('type' => 'stats'));
89
+						$step_total += $payment_amount;
90 90
 					}
91 91
 
92 92
 				}
@@ -94,8 +94,8 @@  discard block
 block discarded – undo
94 94
 			}
95 95
 
96 96
 			$updated_total = $pending_total + $step_total;
97
-			$this->store_data( 'give_stats_donor_pending_total' . $donor->id, $updated_total );
98
-			$this->store_data( 'give_stats_found_payments_' . $donor->id, $found_payment_ids );
97
+			$this->store_data('give_stats_donor_pending_total'.$donor->id, $updated_total);
98
+			$this->store_data('give_stats_found_payments_'.$donor->id, $found_payment_ids);
99 99
 
100 100
 			return true;
101 101
 		}
@@ -112,16 +112,16 @@  discard block
 block discarded – undo
112 112
 	 */
113 113
 	public function get_percentage_complete() {
114 114
 
115
-		$payments = $this->get_stored_data( 'give_recount_donor_payments_' . $this->customer_id );
116
-		$total    = count( $payments );
115
+		$payments = $this->get_stored_data('give_recount_donor_payments_'.$this->customer_id);
116
+		$total    = count($payments);
117 117
 
118 118
 		$percentage = 100;
119 119
 
120
-		if ( $total > 0 ) {
121
-			$percentage = ( ( $this->per_step * $this->step ) / $total ) * 100;
120
+		if ($total > 0) {
121
+			$percentage = (($this->per_step * $this->step) / $total) * 100;
122 122
 		}
123 123
 
124
-		if ( $percentage > 100 ) {
124
+		if ($percentage > 100) {
125 125
 			$percentage = 100;
126 126
 		}
127 127
 
@@ -135,8 +135,8 @@  discard block
 block discarded – undo
135 135
 	 *
136 136
 	 * @param array $request The Form Data passed into the batch processing
137 137
 	 */
138
-	public function set_properties( $request ) {
139
-		$this->customer_id = isset( $request['customer_id'] ) ? sanitize_text_field( $request['customer_id'] ) : false;
138
+	public function set_properties($request) {
139
+		$this->customer_id = isset($request['customer_id']) ? sanitize_text_field($request['customer_id']) : false;
140 140
 	}
141 141
 
142 142
 	/**
@@ -147,53 +147,53 @@  discard block
 block discarded – undo
147 147
 	 */
148 148
 	public function process_step() {
149 149
 
150
-		if ( ! $this->can_export() ) {
151
-			wp_die( esc_html__( 'You do not have permission to recount stats.', 'give' ), esc_html__( 'Error', 'give' ), array( 'response' => 403 ) );
150
+		if ( ! $this->can_export()) {
151
+			wp_die(esc_html__('You do not have permission to recount stats.', 'give'), esc_html__('Error', 'give'), array('response' => 403));
152 152
 		}
153 153
 
154 154
 		$had_data = $this->get_data();
155 155
 
156
-		if ( $had_data ) {
156
+		if ($had_data) {
157 157
 			$this->done = false;
158 158
 
159 159
 			return true;
160 160
 		} else {
161
-			$donor       = new Give_Donor( $this->customer_id );
162
-			$payment_ids = get_option( 'give_stats_found_payments_' . $donor->id, array() );
163
-			$this->delete_data( 'give_stats_found_payments_' . $donor->id );
161
+			$donor       = new Give_Donor($this->customer_id);
162
+			$payment_ids = get_option('give_stats_found_payments_'.$donor->id, array());
163
+			$this->delete_data('give_stats_found_payments_'.$donor->id);
164 164
 
165
-			$removed_payments = array_unique( get_option( 'give_stats_missing_payments' . $donor->id, array() ) );
165
+			$removed_payments = array_unique(get_option('give_stats_missing_payments'.$donor->id, array()));
166 166
 
167 167
 			// Find non-existing payments (deleted) and total up the donation count
168 168
 			$purchase_count = 0;
169
-			foreach ( $payment_ids as $key => $payment_id ) {
170
-				if ( in_array( $payment_id, $removed_payments ) ) {
171
-					unset( $payment_ids[ $key ] );
169
+			foreach ($payment_ids as $key => $payment_id) {
170
+				if (in_array($payment_id, $removed_payments)) {
171
+					unset($payment_ids[$key]);
172 172
 					continue;
173 173
 				}
174 174
 
175
-				$payment = get_post( $payment_id );
176
-				if ( apply_filters( 'give_donor_recount_should_increase_count', true, $payment ) ) {
177
-					$purchase_count ++;
175
+				$payment = get_post($payment_id);
176
+				if (apply_filters('give_donor_recount_should_increase_count', true, $payment)) {
177
+					$purchase_count++;
178 178
 				}
179 179
 			}
180 180
 
181
-			$this->delete_data( 'give_stats_missing_payments' . $donor->id );
181
+			$this->delete_data('give_stats_missing_payments'.$donor->id);
182 182
 
183
-			$pending_total = $this->get_stored_data( 'give_stats_donor_pending_total' . $donor->id );
184
-			$this->delete_data( 'give_stats_donor_pending_total' . $donor->id );
185
-			$this->delete_data( 'give_recount_donor_stats_' . $donor->id );
186
-			$this->delete_data( 'give_recount_donor_payments_' . $this->customer_id );
183
+			$pending_total = $this->get_stored_data('give_stats_donor_pending_total'.$donor->id);
184
+			$this->delete_data('give_stats_donor_pending_total'.$donor->id);
185
+			$this->delete_data('give_recount_donor_stats_'.$donor->id);
186
+			$this->delete_data('give_recount_donor_payments_'.$this->customer_id);
187 187
 
188
-			$payment_ids = implode( ',', $payment_ids );
189
-			$donor->update( array(
188
+			$payment_ids = implode(',', $payment_ids);
189
+			$donor->update(array(
190 190
 				'payment_ids'    => $payment_ids,
191 191
 				'purchase_count' => $purchase_count,
192 192
 				'purchase_value' => $pending_total,
193
-			) );
193
+			));
194 194
 
195 195
 			$this->done    = true;
196
-			$this->message = esc_html__( 'Donor stats have been successfully recounted.', 'give' );
196
+			$this->message = esc_html__('Donor stats have been successfully recounted.', 'give');
197 197
 
198 198
 			return false;
199 199
 		}
@@ -226,26 +226,26 @@  discard block
 block discarded – undo
226 226
 	 * @return void
227 227
 	 */
228 228
 	public function pre_fetch() {
229
-		if ( $this->step === 1 ) {
230
-			$allowed_payment_status = apply_filters( 'give_recount_donors_donation_statuses', give_get_payment_status_keys() );
229
+		if ($this->step === 1) {
230
+			$allowed_payment_status = apply_filters('give_recount_donors_donation_statuses', give_get_payment_status_keys());
231 231
 
232 232
 			// Before we start, let's zero out the customer's data
233
-			$donor = new Give_Donor( $this->customer_id );
234
-			$donor->update( array( 'purchase_value' => give_format_amount( 0, array( 'sanitize' => false ) ), 'purchase_count' => 0 ) );
233
+			$donor = new Give_Donor($this->customer_id);
234
+			$donor->update(array('purchase_value' => give_format_amount(0, array('sanitize' => false)), 'purchase_count' => 0));
235 235
 
236
-			$attached_payment_ids = explode( ',', $donor->payment_ids );
236
+			$attached_payment_ids = explode(',', $donor->payment_ids);
237 237
 
238 238
 			$attached_args = array(
239 239
 				'post__in' => $attached_payment_ids,
240
-				'number'   => - 1,
240
+				'number'   => -1,
241 241
 				'status'   => $allowed_payment_status,
242 242
 			);
243 243
 
244
-			$attached_payments = give_get_payments( $attached_args );
244
+			$attached_payments = give_get_payments($attached_args);
245 245
 
246 246
 			$unattached_args = array(
247 247
 				'post__not_in' => $attached_payment_ids,
248
-				'number'       => - 1,
248
+				'number'       => -1,
249 249
 				'status'       => $allowed_payment_status,
250 250
 				'meta_query'   => array(
251 251
 					array(
@@ -255,11 +255,11 @@  discard block
 block discarded – undo
255 255
 				),
256 256
 			);
257 257
 
258
-			$unattached_payments = give_get_payments( $unattached_args );
258
+			$unattached_payments = give_get_payments($unattached_args);
259 259
 
260
-			$payments = array_merge( $attached_payments, $unattached_payments );
260
+			$payments = array_merge($attached_payments, $unattached_payments);
261 261
 
262
-			$this->store_data( 'give_recount_donor_payments_' . $donor->id, $payments );
262
+			$this->store_data('give_recount_donor_payments_'.$donor->id, $payments);
263 263
 		}
264 264
 	}
265 265
 
@@ -272,17 +272,17 @@  discard block
 block discarded – undo
272 272
 	 *
273 273
 	 * @return mixed       Returns the data from the database
274 274
 	 */
275
-	private function get_stored_data( $key ) {
275
+	private function get_stored_data($key) {
276 276
 		global $wpdb;
277
-		$value = $wpdb->get_var( $wpdb->prepare( "SELECT option_value FROM $wpdb->options WHERE option_name = '%s'", $key ) );
277
+		$value = $wpdb->get_var($wpdb->prepare("SELECT option_value FROM $wpdb->options WHERE option_name = '%s'", $key));
278 278
 
279
-		if ( empty( $value ) ) {
279
+		if (empty($value)) {
280 280
 			return false;
281 281
 		}
282 282
 
283
-		$maybe_json = json_decode( $value );
284
-		if ( ! is_null( $maybe_json ) ) {
285
-			$value = json_decode( $value, true );
283
+		$maybe_json = json_decode($value);
284
+		if ( ! is_null($maybe_json)) {
285
+			$value = json_decode($value, true);
286 286
 		}
287 287
 
288 288
 		return $value;
@@ -298,10 +298,10 @@  discard block
 block discarded – undo
298 298
 	 *
299 299
 	 * @return void
300 300
 	 */
301
-	private function store_data( $key, $value ) {
301
+	private function store_data($key, $value) {
302 302
 		global $wpdb;
303 303
 
304
-		$value = is_array( $value ) ? wp_json_encode( $value ) : esc_attr( $value );
304
+		$value = is_array($value) ? wp_json_encode($value) : esc_attr($value);
305 305
 
306 306
 		$data = array(
307 307
 			'option_name'  => $key,
@@ -315,7 +315,7 @@  discard block
 block discarded – undo
315 315
 			'%s',
316 316
 		);
317 317
 
318
-		$wpdb->replace( $wpdb->options, $data, $formats );
318
+		$wpdb->replace($wpdb->options, $data, $formats);
319 319
 	}
320 320
 
321 321
 	/**
@@ -327,9 +327,9 @@  discard block
 block discarded – undo
327 327
 	 *
328 328
 	 * @return void
329 329
 	 */
330
-	private function delete_data( $key ) {
330
+	private function delete_data($key) {
331 331
 		global $wpdb;
332
-		$wpdb->delete( $wpdb->options, array( 'option_name' => $key ) );
332
+		$wpdb->delete($wpdb->options, array('option_name' => $key));
333 333
 	}
334 334
 
335 335
 }
Please login to merge, or discard this patch.
includes/admin/tools/data/class-give-tools-recount-income.php 1 patch
Spacing   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@  discard block
 block discarded – undo
11 11
  */
12 12
 
13 13
 // Exit if accessed directly.
14
-if ( ! defined( 'ABSPATH' ) ) {
14
+if ( ! defined('ABSPATH')) {
15 15
 	exit;
16 16
 }
17 17
 
@@ -53,49 +53,49 @@  discard block
 block discarded – undo
53 53
 	 */
54 54
 	public function get_data() {
55 55
 
56
-		if ( $this->step == 1 ) {
57
-			$this->delete_data( 'give_temp_recount_earnings' );
56
+		if ($this->step == 1) {
57
+			$this->delete_data('give_temp_recount_earnings');
58 58
 		}
59 59
 
60
-		$total = get_option( 'give_temp_recount_earnings', false );
60
+		$total = get_option('give_temp_recount_earnings', false);
61 61
 
62
-		if ( false === $total ) {
62
+		if (false === $total) {
63 63
 			$total = (float) 0;
64
-			$this->store_data( 'give_temp_recount_earnings', $total );
64
+			$this->store_data('give_temp_recount_earnings', $total);
65 65
 		}
66 66
 
67
-		$accepted_statuses = apply_filters( 'give_recount_accepted_statuses', array( 'publish' ) );
67
+		$accepted_statuses = apply_filters('give_recount_accepted_statuses', array('publish'));
68 68
 
69
-		$args = apply_filters( 'give_recount_earnings_args', array(
69
+		$args = apply_filters('give_recount_earnings_args', array(
70 70
 			'number' => $this->per_step,
71 71
 			'page'   => $this->step,
72 72
 			'status' => $accepted_statuses,
73 73
 			'fields' => 'ids'
74
-		) );
74
+		));
75 75
 
76
-		$payments = give_get_payments( $args );
76
+		$payments = give_get_payments($args);
77 77
 
78
-		if ( ! empty( $payments ) ) {
78
+		if ( ! empty($payments)) {
79 79
 
80
-			foreach ( $payments as $payment ) {
80
+			foreach ($payments as $payment) {
81 81
 
82
-				$total += (float) give_donation_amount( $payment, array( 'type' => 'stats' ) );
82
+				$total += (float) give_donation_amount($payment, array('type' => 'stats'));
83 83
 
84 84
 			}
85 85
 
86
-			if ( $total < 0 ) {
86
+			if ($total < 0) {
87 87
 				$totals = 0;
88 88
 			}
89 89
 
90
-			$total = round( $total, give_get_price_decimals() );
90
+			$total = round($total, give_get_price_decimals());
91 91
 
92
-			$this->store_data( 'give_temp_recount_earnings', $total );
92
+			$this->store_data('give_temp_recount_earnings', $total);
93 93
 
94 94
 			return true;
95 95
 
96 96
 		}
97 97
 
98
-		update_option( 'give_earnings_total', $total );
98
+		update_option('give_earnings_total', $total);
99 99
 
100 100
 		return false;
101 101
 
@@ -109,25 +109,25 @@  discard block
 block discarded – undo
109 109
 	 */
110 110
 	public function get_percentage_complete() {
111 111
 
112
-		$total = $this->get_stored_data( 'give_recount_earnings_total' );
112
+		$total = $this->get_stored_data('give_recount_earnings_total');
113 113
 
114
-		if ( false === $total ) {
115
-			$args = apply_filters( 'give_recount_earnings_total_args', array() );
114
+		if (false === $total) {
115
+			$args = apply_filters('give_recount_earnings_total_args', array());
116 116
 
117
-			$counts = give_count_payments( $args );
118
-			$total  = absint( $counts->publish );
119
-			$total  = apply_filters( 'give_recount_store_earnings_total', $total );
117
+			$counts = give_count_payments($args);
118
+			$total  = absint($counts->publish);
119
+			$total  = apply_filters('give_recount_store_earnings_total', $total);
120 120
 
121
-			$this->store_data( 'give_recount_earnings_total', $total );
121
+			$this->store_data('give_recount_earnings_total', $total);
122 122
 		}
123 123
 
124 124
 		$percentage = 100;
125 125
 
126
-		if ( $total > 0 ) {
127
-			$percentage = ( ( $this->per_step * $this->step ) / $total ) * 100;
126
+		if ($total > 0) {
127
+			$percentage = (($this->per_step * $this->step) / $total) * 100;
128 128
 		}
129 129
 
130
-		if ( $percentage > 100 ) {
130
+		if ($percentage > 100) {
131 131
 			$percentage = 100;
132 132
 		}
133 133
 
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
 	 *
142 142
 	 * @param array $request The Form Data passed into the batch processing
143 143
 	 */
144
-	public function set_properties( $request ) {
144
+	public function set_properties($request) {
145 145
 	}
146 146
 
147 147
 	/**
@@ -152,21 +152,21 @@  discard block
 block discarded – undo
152 152
 	 */
153 153
 	public function process_step() {
154 154
 
155
-		if ( ! $this->can_export() ) {
156
-			wp_die( esc_html__( 'You do not have permission to recount stats.', 'give' ), esc_html__( 'Error', 'give' ), array( 'response' => 403 ) );
155
+		if ( ! $this->can_export()) {
156
+			wp_die(esc_html__('You do not have permission to recount stats.', 'give'), esc_html__('Error', 'give'), array('response' => 403));
157 157
 		}
158 158
 
159 159
 		$had_data = $this->get_data();
160 160
 
161
-		if ( $had_data ) {
161
+		if ($had_data) {
162 162
 			$this->done = false;
163 163
 
164 164
 			return true;
165 165
 		} else {
166
-			$this->delete_data( 'give_recount_earnings_total' );
167
-			$this->delete_data( 'give_temp_recount_earnings' );
166
+			$this->delete_data('give_recount_earnings_total');
167
+			$this->delete_data('give_temp_recount_earnings');
168 168
 			$this->done    = true;
169
-			$this->message = esc_html__( 'Income stats have been successfully recounted.', 'give' );
169
+			$this->message = esc_html__('Income stats have been successfully recounted.', 'give');
170 170
 
171 171
 			return false;
172 172
 		}
@@ -203,17 +203,17 @@  discard block
 block discarded – undo
203 203
 	 *
204 204
 	 * @return mixed       Returns the data from the database
205 205
 	 */
206
-	private function get_stored_data( $key ) {
206
+	private function get_stored_data($key) {
207 207
 		global $wpdb;
208
-		$value = $wpdb->get_var( $wpdb->prepare( "SELECT option_value FROM $wpdb->options WHERE option_name = '%s'", $key ) );
208
+		$value = $wpdb->get_var($wpdb->prepare("SELECT option_value FROM $wpdb->options WHERE option_name = '%s'", $key));
209 209
 
210
-		if ( empty( $value ) ) {
210
+		if (empty($value)) {
211 211
 			return false;
212 212
 		}
213 213
 
214
-		$maybe_json = json_decode( $value );
215
-		if ( ! is_null( $maybe_json ) ) {
216
-			$value = json_decode( $value, true );
214
+		$maybe_json = json_decode($value);
215
+		if ( ! is_null($maybe_json)) {
216
+			$value = json_decode($value, true);
217 217
 		}
218 218
 
219 219
 		return $value;
@@ -229,10 +229,10 @@  discard block
 block discarded – undo
229 229
 	 *
230 230
 	 * @return void
231 231
 	 */
232
-	private function store_data( $key, $value ) {
232
+	private function store_data($key, $value) {
233 233
 		global $wpdb;
234 234
 
235
-		$value = is_array( $value ) ? wp_json_encode( $value ) : esc_attr( $value );
235
+		$value = is_array($value) ? wp_json_encode($value) : esc_attr($value);
236 236
 
237 237
 		$data = array(
238 238
 			'option_name'  => $key,
@@ -246,7 +246,7 @@  discard block
 block discarded – undo
246 246
 			'%s',
247 247
 		);
248 248
 
249
-		$wpdb->replace( $wpdb->options, $data, $formats );
249
+		$wpdb->replace($wpdb->options, $data, $formats);
250 250
 	}
251 251
 
252 252
 	/**
@@ -258,9 +258,9 @@  discard block
 block discarded – undo
258 258
 	 *
259 259
 	 * @return void
260 260
 	 */
261
-	private function delete_data( $key ) {
261
+	private function delete_data($key) {
262 262
 		global $wpdb;
263
-		$wpdb->delete( $wpdb->options, array( 'option_name' => $key ) );
263
+		$wpdb->delete($wpdb->options, array('option_name' => $key));
264 264
 	}
265 265
 
266 266
 }
Please login to merge, or discard this patch.
includes/admin/tools/data/class-give-tools-recount-donor-stats.php 1 patch
Spacing   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@  discard block
 block discarded – undo
10 10
  */
11 11
 
12 12
 // Exit if accessed directly.
13
-if ( ! defined( 'ABSPATH' ) ) {
13
+if ( ! defined('ABSPATH')) {
14 14
 	exit;
15 15
 }
16 16
 
@@ -57,32 +57,32 @@  discard block
 block discarded – undo
57 57
 
58 58
 		$args = array(
59 59
 			'number'  => $this->per_step,
60
-			'offset'  => $this->per_step * ( $this->step - 1 ),
60
+			'offset'  => $this->per_step * ($this->step - 1),
61 61
 			'orderby' => 'id',
62 62
 			'order'   => 'DESC',
63 63
 		);
64 64
 
65
-		$donors = Give()->donors->get_donors( $args );
65
+		$donors = Give()->donors->get_donors($args);
66 66
 
67
-		if ( $donors ) {
67
+		if ($donors) {
68 68
 
69
-			$allowed_payment_status = apply_filters( 'give_recount_donors_donation_statuses', give_get_payment_status_keys() );
69
+			$allowed_payment_status = apply_filters('give_recount_donors_donation_statuses', give_get_payment_status_keys());
70 70
 
71
-			foreach ( $donors as $donor ) {
71
+			foreach ($donors as $donor) {
72 72
 
73
-				$attached_payment_ids = explode( ',', $donor->payment_ids );
73
+				$attached_payment_ids = explode(',', $donor->payment_ids);
74 74
 
75 75
 				$attached_args = array(
76 76
 					'post__in' => $attached_payment_ids,
77
-					'number'   => - 1,
77
+					'number'   => -1,
78 78
 					'status'   => $allowed_payment_status,
79 79
 				);
80 80
 
81
-				$attached_payments = (array) give_get_payments( $attached_args );
81
+				$attached_payments = (array) give_get_payments($attached_args);
82 82
 
83 83
 				$unattached_args = array(
84 84
 					'post__not_in' => $attached_payment_ids,
85
-					'number'       => - 1,
85
+					'number'       => -1,
86 86
 					'status'       => $allowed_payment_status,
87 87
 					'meta_query'   => array(
88 88
 						array(
@@ -93,29 +93,29 @@  discard block
 block discarded – undo
93 93
 					),
94 94
 				);
95 95
 
96
-				$unattached_payments = give_get_payments( $unattached_args );
96
+				$unattached_payments = give_get_payments($unattached_args);
97 97
 
98
-				$payments = array_merge( $attached_payments, $unattached_payments );
98
+				$payments = array_merge($attached_payments, $unattached_payments);
99 99
 
100 100
 				$purchase_value = 0.00;
101 101
 				$purchase_count = 0;
102 102
 				$payment_ids    = array();
103 103
 
104
-				if ( $payments ) {
104
+				if ($payments) {
105 105
 
106
-					foreach ( $payments as $payment ) {
106
+					foreach ($payments as $payment) {
107 107
 
108 108
 						$should_process_payment = 'publish' == $payment->post_status ? true : false;
109
-						$should_process_payment = apply_filters( 'give_donor_recount_should_process_donation', $should_process_payment, $payment );
109
+						$should_process_payment = apply_filters('give_donor_recount_should_process_donation', $should_process_payment, $payment);
110 110
 
111
-						if ( true === $should_process_payment ) {
111
+						if (true === $should_process_payment) {
112 112
 
113
-							if ( apply_filters( 'give_donor_recount_should_increase_value', true, $payment ) ) {
114
-								$purchase_value += (float) give_donation_amount( $payment->ID, array( 'type' => 'stats' ) );
113
+							if (apply_filters('give_donor_recount_should_increase_value', true, $payment)) {
114
+								$purchase_value += (float) give_donation_amount($payment->ID, array('type' => 'stats'));
115 115
 							}
116 116
 
117
-							if ( apply_filters( 'give_donor_recount_should_increase_count', true, $payment ) ) {
118
-								$purchase_count ++;
117
+							if (apply_filters('give_donor_recount_should_increase_count', true, $payment)) {
118
+								$purchase_count++;
119 119
 							}
120 120
 						}
121 121
 
@@ -123,7 +123,7 @@  discard block
 block discarded – undo
123 123
 					}
124 124
 				}
125 125
 
126
-				$payment_ids = implode( ',', $payment_ids );
126
+				$payment_ids = implode(',', $payment_ids);
127 127
 
128 128
 				$donor_update_data = array(
129 129
 					'purchase_count' => $purchase_count,
@@ -131,8 +131,8 @@  discard block
 block discarded – undo
131 131
 					'payment_ids'    => $payment_ids,
132 132
 				);
133 133
 
134
-				$donor_instance = new Give_Donor( $donor->id );
135
-				$donor_instance->update( $donor_update_data );
134
+				$donor_instance = new Give_Donor($donor->id);
135
+				$donor_instance->update($donor_update_data);
136 136
 
137 137
 			}// End foreach().
138 138
 
@@ -152,21 +152,21 @@  discard block
 block discarded – undo
152 152
 	public function get_percentage_complete() {
153 153
 
154 154
 		$args = array(
155
-			'number'  => - 1,
155
+			'number'  => -1,
156 156
 			'orderby' => 'id',
157 157
 			'order'   => 'DESC',
158 158
 		);
159 159
 
160
-		$donors = Give()->donors->get_donors( $args );
161
-		$total     = count( $donors );
160
+		$donors = Give()->donors->get_donors($args);
161
+		$total = count($donors);
162 162
 
163 163
 		$percentage = 100;
164 164
 
165
-		if ( $total > 0 ) {
166
-			$percentage = ( ( $this->per_step * $this->step ) / $total ) * 100;
165
+		if ($total > 0) {
166
+			$percentage = (($this->per_step * $this->step) / $total) * 100;
167 167
 		}
168 168
 
169
-		if ( $percentage > 100 ) {
169
+		if ($percentage > 100) {
170 170
 			$percentage = 100;
171 171
 		}
172 172
 
@@ -180,7 +180,7 @@  discard block
 block discarded – undo
180 180
 	 *
181 181
 	 * @param array $request The Form Data passed into the batch processing
182 182
 	 */
183
-	public function set_properties( $request ) {
183
+	public function set_properties($request) {
184 184
 	}
185 185
 
186 186
 	/**
@@ -191,21 +191,21 @@  discard block
 block discarded – undo
191 191
 	 */
192 192
 	public function process_step() {
193 193
 
194
-		if ( ! $this->can_export() ) {
195
-			wp_die( esc_html__( 'You do not have permission to recount stats.', 'give' ), esc_html__( 'Error', 'give' ), array(
194
+		if ( ! $this->can_export()) {
195
+			wp_die(esc_html__('You do not have permission to recount stats.', 'give'), esc_html__('Error', 'give'), array(
196 196
 				'response' => 403,
197
-			) );
197
+			));
198 198
 		}
199 199
 
200 200
 		$had_data = $this->get_data();
201 201
 
202
-		if ( $had_data ) {
202
+		if ($had_data) {
203 203
 			$this->done = false;
204 204
 
205 205
 			return true;
206 206
 		} else {
207 207
 			$this->done    = true;
208
-			$this->message = esc_html__( 'Donor stats have been successfully recounted.', 'give' );
208
+			$this->message = esc_html__('Donor stats have been successfully recounted.', 'give');
209 209
 
210 210
 			return false;
211 211
 		}
Please login to merge, or discard this patch.
includes/admin/tools/data/class-give-tools-recount-form-stats.php 1 patch
Spacing   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@  discard block
 block discarded – undo
11 11
  */
12 12
 
13 13
 // Exit if accessed directly.
14
-if ( ! defined( 'ABSPATH' ) ) {
14
+if ( ! defined('ABSPATH')) {
15 15
 	exit;
16 16
 }
17 17
 
@@ -60,59 +60,59 @@  discard block
 block discarded – undo
60 60
 	 */
61 61
 	public function get_data() {
62 62
 
63
-		$accepted_statuses = apply_filters( 'give_recount_accepted_statuses', array( 'publish' ) );
63
+		$accepted_statuses = apply_filters('give_recount_accepted_statuses', array('publish'));
64 64
 
65
-		if ( $this->step == 1 ) {
66
-			$this->delete_data( 'give_temp_recount_form_stats' );
65
+		if ($this->step == 1) {
66
+			$this->delete_data('give_temp_recount_form_stats');
67 67
 		}
68 68
 
69
-		$totals = $this->get_stored_data( 'give_temp_recount_form_stats' );
69
+		$totals = $this->get_stored_data('give_temp_recount_form_stats');
70 70
 
71
-		if ( false === $totals ) {
71
+		if (false === $totals) {
72 72
 			$totals = array(
73 73
 				'earnings' => (float) 0,
74 74
 				'sales'    => 0,
75 75
 			);
76
-			$this->store_data( 'give_temp_recount_form_stats', $totals );
76
+			$this->store_data('give_temp_recount_form_stats', $totals);
77 77
 		}
78 78
 
79
-		$args = apply_filters( 'give_recount_form_stats_args', array(
79
+		$args = apply_filters('give_recount_form_stats_args', array(
80 80
 			'give_forms' => $this->form_id,
81 81
 			'number'     => $this->per_step,
82 82
 			'status'     => $accepted_statuses,
83 83
 			'paged'      => $this->step,
84 84
 			'fields'     => 'ids',
85
-		) );
85
+		));
86 86
 
87
-		$payments = new Give_Payments_Query( $args );
87
+		$payments = new Give_Payments_Query($args);
88 88
 		$payments = $payments->get_payments();
89 89
 
90
-		if ( $payments ) {
91
-			foreach ( $payments as $payment ) {
90
+		if ($payments) {
91
+			foreach ($payments as $payment) {
92 92
 
93 93
 				// Ensure acceptable status only.
94
-				if ( ! in_array( $payment->post_status, $accepted_statuses ) ) {
94
+				if ( ! in_array($payment->post_status, $accepted_statuses)) {
95 95
 					continue;
96 96
 				}
97 97
 
98 98
 				// Ensure only payments for this form are counted.
99
-				if ( $payment->form_id != $this->form_id ) {
99
+				if ($payment->form_id != $this->form_id) {
100 100
 					continue;
101 101
 				}
102 102
 
103
-				$totals['sales'] ++;
103
+				$totals['sales']++;
104 104
 				$totals['earnings'] += $payment->total;
105 105
 
106 106
 			}
107 107
 
108
-			$this->store_data( 'give_temp_recount_form_stats', $totals );
108
+			$this->store_data('give_temp_recount_form_stats', $totals);
109 109
 
110 110
 			return true;
111 111
 		}
112 112
 
113 113
 
114
-		give_update_meta( $this->form_id, '_give_form_sales', $totals['sales'] );
115
-		give_update_meta( $this->form_id, '_give_form_earnings', give_sanitize_amount_for_db( $totals['earnings'] ) );
114
+		give_update_meta($this->form_id, '_give_form_sales', $totals['sales']);
115
+		give_update_meta($this->form_id, '_give_form_earnings', give_sanitize_amount_for_db($totals['earnings']));
116 116
 
117 117
 		return false;
118 118
 	}
@@ -124,35 +124,35 @@  discard block
 block discarded – undo
124 124
 	 * @return int
125 125
 	 */
126 126
 	public function get_percentage_complete() {
127
-		if ( $this->step == 1 ) {
128
-			$this->delete_data( 'give_recount_total_' . $this->form_id );
127
+		if ($this->step == 1) {
128
+			$this->delete_data('give_recount_total_'.$this->form_id);
129 129
 		}
130 130
 
131
-		$accepted_statuses = apply_filters( 'give_recount_accepted_statuses', array( 'publish' ) );
132
-		$total             = $this->get_stored_data( 'give_recount_total_' . $this->form_id );
131
+		$accepted_statuses = apply_filters('give_recount_accepted_statuses', array('publish'));
132
+		$total             = $this->get_stored_data('give_recount_total_'.$this->form_id);
133 133
 
134
-		if ( false === $total ) {
134
+		if (false === $total) {
135 135
 			$total = 0;
136
-			$args  = apply_filters( 'give_recount_form_stats_total_args', array(
136
+			$args  = apply_filters('give_recount_form_stats_total_args', array(
137 137
 				'give_forms' => $this->form_id,
138
-				'number'     => - 1,
138
+				'number'     => -1,
139 139
 				'status'     => $accepted_statuses,
140 140
 				'fields'     => 'ids',
141
-			) );
141
+			));
142 142
 
143
-			$payments = new Give_Payments_Query( $args );
144
-			$total    = count( $payments->get_payments() );
145
-			$this->store_data( 'give_recount_total_' . $this->form_id, $total );
143
+			$payments = new Give_Payments_Query($args);
144
+			$total    = count($payments->get_payments());
145
+			$this->store_data('give_recount_total_'.$this->form_id, $total);
146 146
 
147 147
 		}
148 148
 
149 149
 		$percentage = 100;
150 150
 
151
-		if ( $total > 0 ) {
152
-			$percentage = ( ( $this->per_step * $this->step ) / $total ) * 100;
151
+		if ($total > 0) {
152
+			$percentage = (($this->per_step * $this->step) / $total) * 100;
153 153
 		}
154 154
 
155
-		if ( $percentage > 100 ) {
155
+		if ($percentage > 100) {
156 156
 			$percentage = 100;
157 157
 		}
158 158
 
@@ -166,8 +166,8 @@  discard block
 block discarded – undo
166 166
 	 *
167 167
 	 * @param array $request The Form Data passed into the batch processing
168 168
 	 */
169
-	public function set_properties( $request ) {
170
-		$this->form_id = isset( $request['form_id'] ) ? sanitize_text_field( $request['form_id'] ) : false;
169
+	public function set_properties($request) {
170
+		$this->form_id = isset($request['form_id']) ? sanitize_text_field($request['form_id']) : false;
171 171
 	}
172 172
 
173 173
 	/**
@@ -178,21 +178,21 @@  discard block
 block discarded – undo
178 178
 	 */
179 179
 	public function process_step() {
180 180
 
181
-		if ( ! $this->can_export() ) {
182
-			wp_die( esc_html__( 'You do not have permission to recount stats.', 'give' ), esc_html__( 'Error', 'give' ), array( 'response' => 403 ) );
181
+		if ( ! $this->can_export()) {
182
+			wp_die(esc_html__('You do not have permission to recount stats.', 'give'), esc_html__('Error', 'give'), array('response' => 403));
183 183
 		}
184 184
 
185 185
 		$had_data = $this->get_data();
186 186
 
187
-		if ( $had_data ) {
187
+		if ($had_data) {
188 188
 			$this->done = false;
189 189
 
190 190
 			return true;
191 191
 		} else {
192
-			$this->delete_data( 'give_recount_total_' . $this->form_id );
193
-			$this->delete_data( 'give_temp_recount_form_stats' );
192
+			$this->delete_data('give_recount_total_'.$this->form_id);
193
+			$this->delete_data('give_temp_recount_form_stats');
194 194
 			$this->done    = true;
195
-			$this->message = sprintf( esc_html__( 'Donation counts and income amount statistics successfully recounted for "%s".', 'give' ), get_the_title( $this->form_id ) );
195
+			$this->message = sprintf(esc_html__('Donation counts and income amount statistics successfully recounted for "%s".', 'give'), get_the_title($this->form_id));
196 196
 
197 197
 			return false;
198 198
 		}
@@ -226,17 +226,17 @@  discard block
 block discarded – undo
226 226
 	 *
227 227
 	 * @return mixed       Returns the data from the database
228 228
 	 */
229
-	private function get_stored_data( $key ) {
229
+	private function get_stored_data($key) {
230 230
 		global $wpdb;
231
-		$value = $wpdb->get_var( $wpdb->prepare( "SELECT option_value FROM $wpdb->options WHERE option_name = '%s'", $key ) );
231
+		$value = $wpdb->get_var($wpdb->prepare("SELECT option_value FROM $wpdb->options WHERE option_name = '%s'", $key));
232 232
 
233
-		if ( empty( $value ) ) {
233
+		if (empty($value)) {
234 234
 			return false;
235 235
 		}
236 236
 
237
-		$maybe_json = json_decode( $value );
238
-		if ( ! is_null( $maybe_json ) ) {
239
-			$value = json_decode( $value, true );
237
+		$maybe_json = json_decode($value);
238
+		if ( ! is_null($maybe_json)) {
239
+			$value = json_decode($value, true);
240 240
 		}
241 241
 
242 242
 		return $value;
@@ -252,10 +252,10 @@  discard block
 block discarded – undo
252 252
 	 *
253 253
 	 * @return void
254 254
 	 */
255
-	private function store_data( $key, $value ) {
255
+	private function store_data($key, $value) {
256 256
 		global $wpdb;
257 257
 
258
-		$value = is_array( $value ) ? wp_json_encode( $value ) : esc_attr( $value );
258
+		$value = is_array($value) ? wp_json_encode($value) : esc_attr($value);
259 259
 
260 260
 		$data = array(
261 261
 			'option_name'  => $key,
@@ -269,7 +269,7 @@  discard block
 block discarded – undo
269 269
 			'%s',
270 270
 		);
271 271
 
272
-		$wpdb->replace( $wpdb->options, $data, $formats );
272
+		$wpdb->replace($wpdb->options, $data, $formats);
273 273
 	}
274 274
 
275 275
 	/**
@@ -281,9 +281,9 @@  discard block
 block discarded – undo
281 281
 	 *
282 282
 	 * @return void
283 283
 	 */
284
-	private function delete_data( $key ) {
284
+	private function delete_data($key) {
285 285
 		global $wpdb;
286
-		$wpdb->delete( $wpdb->options, array( 'option_name' => $key ) );
286
+		$wpdb->delete($wpdb->options, array('option_name' => $key));
287 287
 	}
288 288
 
289 289
 }
290 290
\ No newline at end of file
Please login to merge, or discard this patch.
includes/admin/tools/export/class-batch-export-payments.php 1 patch
Spacing   +71 added lines, -71 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
  */
13 13
 
14 14
 // Exit if accessed directly.
15
-if ( ! defined( 'ABSPATH' ) ) {
15
+if ( ! defined('ABSPATH')) {
16 16
 	exit;
17 17
 }
18 18
 
@@ -39,30 +39,30 @@  discard block
 block discarded – undo
39 39
 	 */
40 40
 	public function csv_cols() {
41 41
 		$cols = array(
42
-			'id'        => __( 'ID', 'give' ), // unaltered payment ID (use for querying).
43
-			'seq_id'    => __( 'Payment Number', 'give' ), // sequential payment ID.
44
-			'email'     => __( 'Email', 'give' ),
45
-			'first'     => __( 'First Name', 'give' ),
46
-			'last'      => __( 'Last Name', 'give' ),
47
-			'address1'  => __( 'Address 1', 'give' ),
48
-			'address2'  => __( 'Address 2', 'give' ),
49
-			'city'      => __( 'City', 'give' ),
50
-			'state'     => __( 'State', 'give' ),
51
-			'country'   => __( 'Country', 'give' ),
52
-			'zip'       => __( 'Zip / Postal Code', 'give' ),
53
-			'form_id'   => __( 'Form ID', 'give' ),
54
-			'form_name' => __( 'Form Name', 'give' ),
55
-			'amount'    => __( 'Amount', 'give' ) . ' (' . give_currency_symbol( '', true ) . ')',
56
-			'gateway'   => __( 'Payment Method', 'give' ),
57
-			'trans_id'  => __( 'Transaction ID', 'give' ),
58
-			'key'       => __( 'Key', 'give' ),
59
-			'date'      => __( 'Date', 'give' ),
60
-			'user'      => __( 'User', 'give' ),
61
-			'status'    => __( 'Status', 'give' )
42
+			'id'        => __('ID', 'give'), // unaltered payment ID (use for querying).
43
+			'seq_id'    => __('Payment Number', 'give'), // sequential payment ID.
44
+			'email'     => __('Email', 'give'),
45
+			'first'     => __('First Name', 'give'),
46
+			'last'      => __('Last Name', 'give'),
47
+			'address1'  => __('Address 1', 'give'),
48
+			'address2'  => __('Address 2', 'give'),
49
+			'city'      => __('City', 'give'),
50
+			'state'     => __('State', 'give'),
51
+			'country'   => __('Country', 'give'),
52
+			'zip'       => __('Zip / Postal Code', 'give'),
53
+			'form_id'   => __('Form ID', 'give'),
54
+			'form_name' => __('Form Name', 'give'),
55
+			'amount'    => __('Amount', 'give').' ('.give_currency_symbol('', true).')',
56
+			'gateway'   => __('Payment Method', 'give'),
57
+			'trans_id'  => __('Transaction ID', 'give'),
58
+			'key'       => __('Key', 'give'),
59
+			'date'      => __('Date', 'give'),
60
+			'user'      => __('User', 'give'),
61
+			'status'    => __('Status', 'give')
62 62
 		);
63 63
 
64
-		if ( ! give_get_option( 'enable_sequential' ) ) {
65
-			unset( $cols['seq_id'] );
64
+		if ( ! give_get_option('enable_sequential')) {
65
+			unset($cols['seq_id']);
66 66
 		}
67 67
 
68 68
 		return $cols;
@@ -86,12 +86,12 @@  discard block
 block discarded – undo
86 86
 			'status' => $this->status
87 87
 		);
88 88
 
89
-		if ( ! empty( $this->start ) || ! empty( $this->end ) ) {
89
+		if ( ! empty($this->start) || ! empty($this->end)) {
90 90
 
91 91
 			$args['date_query'] = array(
92 92
 				array(
93
-					'after'     => date( 'Y-n-d 00:00:00', strtotime( $this->start ) ),
94
-					'before'    => date( 'Y-n-d 23:59:59', strtotime( $this->end ) ),
93
+					'after'     => date('Y-n-d 00:00:00', strtotime($this->start)),
94
+					'before'    => date('Y-n-d 23:59:59', strtotime($this->end)),
95 95
 					'inclusive' => true
96 96
 				)
97 97
 			);
@@ -99,11 +99,11 @@  discard block
 block discarded – undo
99 99
 		}
100 100
 
101 101
 		// Add category or tag to payment query if any.
102
-		if ( ! empty( $this->categories ) || ! empty( $this->tags ) ) {
102
+		if ( ! empty($this->categories) || ! empty($this->tags)) {
103 103
 			$form_args = array(
104 104
 				'post_type'      => 'give_forms',
105 105
 				'post_status'    => 'publish',
106
-				'posts_per_page' => - 1,
106
+				'posts_per_page' => -1,
107 107
 				'fields'         => 'ids',
108 108
 				'tax_query'      => array(
109 109
 					'relation' => 'AND',
@@ -111,72 +111,72 @@  discard block
 block discarded – undo
111 111
 			);
112 112
 
113 113
 
114
-			if ( ! empty( $this->categories ) ) {
114
+			if ( ! empty($this->categories)) {
115 115
 				$form_args['tax_query'][] = array(
116 116
 					'taxonomy' => 'give_forms_category',
117 117
 					'terms'    => $this->categories,
118 118
 				);
119 119
 			}
120 120
 
121
-			if ( ! empty( $this->tags ) ) {
121
+			if ( ! empty($this->tags)) {
122 122
 				$form_args['tax_query'][] = array(
123 123
 					'taxonomy' => 'give_forms_tag',
124 124
 					'terms'    => $this->tags,
125 125
 				);
126 126
 			}
127 127
 
128
-			$forms = new WP_Query( $form_args );
128
+			$forms = new WP_Query($form_args);
129 129
 
130
-			if ( empty( $forms->posts ) ) {
130
+			if (empty($forms->posts)) {
131 131
 				return array();
132 132
 			}
133 133
 
134 134
 			$args['give_forms'] = $forms->posts;
135 135
 		}
136 136
 
137
-		$payments = give_get_payments( $args );
137
+		$payments = give_get_payments($args);
138 138
 
139
-		if ( $payments ) {
139
+		if ($payments) {
140 140
 
141
-			foreach ( $payments as $payment ) {
142
-				$payment_meta = give_get_payment_meta( $payment->ID );
143
-				$user_info    = give_get_payment_meta_user_info( $payment->ID );
144
-				$total        = give_donation_amount( $payment->ID, array( 'type' => 'stats' ) );
145
-				$user_id      = isset( $user_info['id'] ) && $user_info['id'] != - 1 ? $user_info['id'] : $user_info['email'];
141
+			foreach ($payments as $payment) {
142
+				$payment_meta = give_get_payment_meta($payment->ID);
143
+				$user_info    = give_get_payment_meta_user_info($payment->ID);
144
+				$total        = give_donation_amount($payment->ID, array('type' => 'stats'));
145
+				$user_id      = isset($user_info['id']) && $user_info['id'] != - 1 ? $user_info['id'] : $user_info['email'];
146 146
 
147
-				if ( is_numeric( $user_id ) ) {
148
-					$user = get_userdata( $user_id );
147
+				if (is_numeric($user_id)) {
148
+					$user = get_userdata($user_id);
149 149
 				} else {
150 150
 					$user = false;
151 151
 				}
152 152
 
153 153
 				$data[] = array(
154 154
 					'id'        => $payment->ID,
155
-					'seq_id'    => give_get_payment_number( $payment->ID ),
155
+					'seq_id'    => give_get_payment_number($payment->ID),
156 156
 					'email'     => $payment_meta['email'],
157 157
 					'first'     => $user_info['first_name'],
158 158
 					'last'      => $user_info['last_name'],
159
-					'address1'  => isset( $user_info['address']['line1'] ) ? $user_info['address']['line1'] : '',
160
-					'address2'  => isset( $user_info['address']['line2'] ) ? $user_info['address']['line2'] : '',
161
-					'city'      => isset( $user_info['address']['city'] ) ? $user_info['address']['city'] : '',
162
-					'state'     => isset( $user_info['address']['state'] ) ? $user_info['address']['state'] : '',
163
-					'country'   => isset( $user_info['address']['country'] ) ? $user_info['address']['country'] : '',
164
-					'zip'       => isset( $user_info['address']['zip'] ) ? $user_info['address']['zip'] : '',
165
-					'form_id'   => isset( $payment_meta['form_id'] ) ? $payment_meta['form_id'] : '',
166
-					'form_name' => isset( $payment_meta['form_title'] ) ? $payment_meta['form_title'] : '',
167
-					'amount'    => html_entity_decode( give_format_amount( $total, array( 'sanitize' => false ) ) ),
168
-					'gateway'   => give_get_gateway_admin_label( give_get_meta( $payment->ID, '_give_payment_gateway', true ) ),
169
-					'trans_id'  => give_get_payment_transaction_id( $payment->ID ),
159
+					'address1'  => isset($user_info['address']['line1']) ? $user_info['address']['line1'] : '',
160
+					'address2'  => isset($user_info['address']['line2']) ? $user_info['address']['line2'] : '',
161
+					'city'      => isset($user_info['address']['city']) ? $user_info['address']['city'] : '',
162
+					'state'     => isset($user_info['address']['state']) ? $user_info['address']['state'] : '',
163
+					'country'   => isset($user_info['address']['country']) ? $user_info['address']['country'] : '',
164
+					'zip'       => isset($user_info['address']['zip']) ? $user_info['address']['zip'] : '',
165
+					'form_id'   => isset($payment_meta['form_id']) ? $payment_meta['form_id'] : '',
166
+					'form_name' => isset($payment_meta['form_title']) ? $payment_meta['form_title'] : '',
167
+					'amount'    => html_entity_decode(give_format_amount($total, array('sanitize' => false))),
168
+					'gateway'   => give_get_gateway_admin_label(give_get_meta($payment->ID, '_give_payment_gateway', true)),
169
+					'trans_id'  => give_get_payment_transaction_id($payment->ID),
170 170
 					'key'       => $payment_meta['key'],
171 171
 					'date'      => $payment->post_date,
172
-					'user'      => $user ? $user->display_name : __( 'guest', 'give' ),
173
-					'status'    => give_get_payment_status( $payment, true )
172
+					'user'      => $user ? $user->display_name : __('guest', 'give'),
173
+					'status'    => give_get_payment_status($payment, true)
174 174
 				);
175 175
 
176 176
 			}
177 177
 
178
-			$data = apply_filters( 'give_export_get_data', $data );
179
-			$data = apply_filters( "give_export_get_data_{$this->export_type}", $data );
178
+			$data = apply_filters('give_export_get_data', $data);
179
+			$data = apply_filters("give_export_get_data_{$this->export_type}", $data);
180 180
 
181 181
 			return $data;
182 182
 
@@ -196,27 +196,27 @@  discard block
 block discarded – undo
196 196
 
197 197
 		$status = $this->status;
198 198
 		$args   = array(
199
-			'start-date' => date( 'n/d/Y', strtotime( $this->start ) ),
200
-			'end-date'   => date( 'n/d/Y', strtotime( $this->end ) ),
199
+			'start-date' => date('n/d/Y', strtotime($this->start)),
200
+			'end-date'   => date('n/d/Y', strtotime($this->end)),
201 201
 		);
202 202
 
203
-		if ( 'any' == $status ) {
203
+		if ('any' == $status) {
204 204
 
205
-			$total = array_sum( (array) give_count_payments( $args ) );
205
+			$total = array_sum((array) give_count_payments($args));
206 206
 
207 207
 		} else {
208 208
 
209
-			$total = give_count_payments( $args )->$status;
209
+			$total = give_count_payments($args)->$status;
210 210
 
211 211
 		}
212 212
 
213 213
 		$percentage = 100;
214 214
 
215
-		if ( $total > 0 ) {
216
-			$percentage = ( ( 30 * $this->step ) / $total ) * 100;
215
+		if ($total > 0) {
216
+			$percentage = ((30 * $this->step) / $total) * 100;
217 217
 		}
218 218
 
219
-		if ( $percentage > 100 ) {
219
+		if ($percentage > 100) {
220 220
 			$percentage = 100;
221 221
 		}
222 222
 
@@ -230,11 +230,11 @@  discard block
 block discarded – undo
230 230
 	 *
231 231
 	 * @param array $request The Form Data passed into the batch processing.
232 232
 	 */
233
-	public function set_properties( $request ) {
234
-		$this->start      = isset( $request['start'] ) ? sanitize_text_field( $request['start'] ) : '';
235
-		$this->end        = isset( $request['end'] ) ? sanitize_text_field( $request['end'] ) : '';
236
-		$this->status     = isset( $request['status'] ) ? sanitize_text_field( $request['status'] ) : 'complete';
237
-		$this->categories = isset( $request['give_forms_categories'] ) ? give_clean( $request['give_forms_categories'] ) : array();
238
-		$this->tags       = isset( $request['give_forms_tags'] ) ? give_clean( $request['give_forms_tags'] ) : array();
233
+	public function set_properties($request) {
234
+		$this->start      = isset($request['start']) ? sanitize_text_field($request['start']) : '';
235
+		$this->end        = isset($request['end']) ? sanitize_text_field($request['end']) : '';
236
+		$this->status     = isset($request['status']) ? sanitize_text_field($request['status']) : 'complete';
237
+		$this->categories = isset($request['give_forms_categories']) ? give_clean($request['give_forms_categories']) : array();
238
+		$this->tags       = isset($request['give_forms_tags']) ? give_clean($request['give_forms_tags']) : array();
239 239
 	}
240 240
 }
Please login to merge, or discard this patch.
includes/admin/tools/export/class-core-settings-export.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
  */
13 13
 
14 14
 // Exit if accessed directly.
15
-if ( ! defined( 'ABSPATH' ) ) {
15
+if ( ! defined('ABSPATH')) {
16 16
 	exit;
17 17
 }
18 18
 
@@ -42,9 +42,9 @@  discard block
 block discarded – undo
42 42
 		give_ignore_user_abort();
43 43
 
44 44
 		nocache_headers();
45
-		header( 'Content-Type: application/json; charset=utf-8' );
46
-		header( 'Content-Disposition: attachment; filename=' . apply_filters( 'give_core_settings_export_filename', 'give-export-' . $this->export_type . '-' . date( 'n' ) . '-' . date( 'Y' ) ) . '.json' );
47
-		header( 'Expires: 0' );
45
+		header('Content-Type: application/json; charset=utf-8');
46
+		header('Content-Disposition: attachment; filename='.apply_filters('give_core_settings_export_filename', 'give-export-'.$this->export_type.'-'.date('n').'-'.date('Y')).'.json');
47
+		header('Expires: 0');
48 48
 	}
49 49
 
50 50
 	/**
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
 	 * @since 1.8.17
55 55
 	 */
56 56
 	public function json_core_settings_export() {
57
-		echo wp_json_encode( get_option( 'give_settings' ) );
57
+		echo wp_json_encode(get_option('give_settings'));
58 58
 	}
59 59
 
60 60
 	/**
@@ -64,8 +64,8 @@  discard block
 block discarded – undo
64 64
 	 * @since  1.8.17
65 65
 	 */
66 66
 	public function export() {
67
-		if ( ! $this->can_export() ) {
68
-			wp_die( __( 'You do not have permission to export data.', 'give' ), __( 'Error', 'give' ), array( 'response' => 403 ) );
67
+		if ( ! $this->can_export()) {
68
+			wp_die(__('You do not have permission to export data.', 'give'), __('Error', 'give'), array('response' => 403));
69 69
 		}
70 70
 
71 71
 		// Set headers.
Please login to merge, or discard this patch.
includes/admin/tools/export/class-export.php 1 patch
Spacing   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
  */
13 13
 
14 14
 // Exit if accessed directly.
15
-if ( ! defined( 'ABSPATH' ) ) {
15
+if ( ! defined('ABSPATH')) {
16 16
 	exit;
17 17
 }
18 18
 
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
 	 * @return bool Whether we can export or not
38 38
 	 */
39 39
 	public function can_export() {
40
-		return (bool) apply_filters( 'give_export_capability', current_user_can( 'export_give_reports' ) );
40
+		return (bool) apply_filters('give_export_capability', current_user_can('export_give_reports'));
41 41
 	}
42 42
 
43 43
 	/**
@@ -51,9 +51,9 @@  discard block
 block discarded – undo
51 51
 		give_ignore_user_abort();
52 52
 
53 53
 		nocache_headers();
54
-		header( 'Content-Type: text/csv; charset=utf-8' );
55
-		header( 'Content-Disposition: attachment; filename=give-export-' . $this->export_type . '-' . date( 'm-d-Y' ) . '.csv' );
56
-		header( "Expires: 0" );
54
+		header('Content-Type: text/csv; charset=utf-8');
55
+		header('Content-Disposition: attachment; filename=give-export-'.$this->export_type.'-'.date('m-d-Y').'.csv');
56
+		header("Expires: 0");
57 57
 	}
58 58
 
59 59
 	/**
@@ -65,8 +65,8 @@  discard block
 block discarded – undo
65 65
 	 */
66 66
 	public function csv_cols() {
67 67
 		$cols = array(
68
-			'id'   => __( 'ID', 'give' ),
69
-			'date' => __( 'Date', 'give' )
68
+			'id'   => __('ID', 'give'),
69
+			'date' => __('Date', 'give')
70 70
 		);
71 71
 
72 72
 		return $cols;
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
 	public function get_csv_cols() {
83 83
 		$cols = $this->csv_cols();
84 84
 
85
-		return apply_filters( "give_export_csv_cols_{$this->export_type}", $cols );
85
+		return apply_filters("give_export_csv_cols_{$this->export_type}", $cols);
86 86
 	}
87 87
 
88 88
 	/**
@@ -96,10 +96,10 @@  discard block
 block discarded – undo
96 96
 	public function csv_cols_out() {
97 97
 		$cols = $this->get_csv_cols();
98 98
 		$i    = 1;
99
-		foreach ( $cols as $col_id => $column ) {
100
-			echo '"' . addslashes( $column ) . '"';
101
-			echo $i == count( $cols ) ? '' : ',';
102
-			$i ++;
99
+		foreach ($cols as $col_id => $column) {
100
+			echo '"'.addslashes($column).'"';
101
+			echo $i == count($cols) ? '' : ',';
102
+			$i++;
103 103
 		}
104 104
 		echo "\r\n";
105 105
 	}
@@ -116,16 +116,16 @@  discard block
 block discarded – undo
116 116
 		$data = array(
117 117
 			0 => array(
118 118
 				'id'   => '',
119
-				'data' => date( 'F j, Y' )
119
+				'data' => date('F j, Y')
120 120
 			),
121 121
 			1 => array(
122 122
 				'id'   => '',
123
-				'data' => date( 'F j, Y' )
123
+				'data' => date('F j, Y')
124 124
 			)
125 125
 		);
126 126
 
127
-		$data = apply_filters( 'give_export_get_data', $data );
128
-		$data = apply_filters( "give_export_get_data_{$this->export_type}", $data );
127
+		$data = apply_filters('give_export_get_data', $data);
128
+		$data = apply_filters("give_export_get_data_{$this->export_type}", $data);
129 129
 
130 130
 		return $data;
131 131
 	}
@@ -143,14 +143,14 @@  discard block
 block discarded – undo
143 143
 		$cols = $this->get_csv_cols();
144 144
 
145 145
 		// Output each row
146
-		foreach ( $data as $row ) {
146
+		foreach ($data as $row) {
147 147
 			$i = 1;
148
-			foreach ( $row as $col_id => $column ) {
148
+			foreach ($row as $col_id => $column) {
149 149
 				// Make sure the column is valid
150
-				if ( array_key_exists( $col_id, $cols ) ) {
151
-					echo '"' . addslashes( $column ) . '"';
152
-					echo $i == count( $cols ) ? '' : ',';
153
-					$i ++;
150
+				if (array_key_exists($col_id, $cols)) {
151
+					echo '"'.addslashes($column).'"';
152
+					echo $i == count($cols) ? '' : ',';
153
+					$i++;
154 154
 				}
155 155
 			}
156 156
 			echo "\r\n";
@@ -169,8 +169,8 @@  discard block
 block discarded – undo
169 169
 	 * @return void
170 170
 	 */
171 171
 	public function export() {
172
-		if ( ! $this->can_export() ) {
173
-			wp_die( __( 'You do not have permission to export data.', 'give' ), __( 'Error', 'give' ), array( 'response' => 403 ) );
172
+		if ( ! $this->can_export()) {
173
+			wp_die(__('You do not have permission to export data.', 'give'), __('Error', 'give'), array('response' => 403));
174 174
 		}
175 175
 
176 176
 		// Set headers
Please login to merge, or discard this patch.
includes/admin/tools/export/class-export-earnings.php 1 patch
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
  */
13 13
 
14 14
 // Exit if accessed directly.
15
-if ( ! defined( 'ABSPATH' ) ) {
15
+if ( ! defined('ABSPATH')) {
16 16
 	exit;
17 17
 }
18 18
 
@@ -41,9 +41,9 @@  discard block
 block discarded – undo
41 41
 		give_ignore_user_abort();
42 42
 
43 43
 		nocache_headers();
44
-		header( 'Content-Type: text/csv; charset=utf-8' );
45
-		header( 'Content-Disposition: attachment; filename=' . apply_filters( 'give_earnings_export_filename', 'give-export-' . $this->export_type . '-' . date( 'n' ) . '-' . date( 'Y' ) ) . '.csv' );
46
-		header( "Expires: 0" );
44
+		header('Content-Type: text/csv; charset=utf-8');
45
+		header('Content-Disposition: attachment; filename='.apply_filters('give_earnings_export_filename', 'give-export-'.$this->export_type.'-'.date('n').'-'.date('Y')).'.csv');
46
+		header("Expires: 0");
47 47
 
48 48
 	}
49 49
 
@@ -57,10 +57,10 @@  discard block
 block discarded – undo
57 57
 	public function csv_cols() {
58 58
 
59 59
 		$cols = array(
60
-			'date'      => __( 'Date', 'give' ),
61
-			'donations' => __( 'Donations', 'give' ),
60
+			'date'      => __('Date', 'give'),
61
+			'donations' => __('Donations', 'give'),
62 62
 			/* translators: %s: currency */
63
-			'earnings'  => sprintf( __( 'Income (%s)', 'give' ), give_currency_symbol('', true) )
63
+			'earnings'  => sprintf(__('Income (%s)', 'give'), give_currency_symbol('', true))
64 64
 		);
65 65
 
66 66
 		return $cols;
@@ -75,28 +75,28 @@  discard block
 block discarded – undo
75 75
 	 */
76 76
 	public function get_data() {
77 77
 
78
-		$start_year  = isset( $_POST['start_year'] ) ? absint( $_POST['start_year'] ) : date( 'Y' );
79
-		$end_year    = isset( $_POST['end_year'] ) ? absint( $_POST['end_year'] ) : date( 'Y' );
80
-		$start_month = isset( $_POST['start_month'] ) ? absint( $_POST['start_month'] ) : date( 'n' );
81
-		$end_month   = isset( $_POST['end_month'] ) ? absint( $_POST['end_month'] ) : date( 'n' );
78
+		$start_year  = isset($_POST['start_year']) ? absint($_POST['start_year']) : date('Y');
79
+		$end_year    = isset($_POST['end_year']) ? absint($_POST['end_year']) : date('Y');
80
+		$start_month = isset($_POST['start_month']) ? absint($_POST['start_month']) : date('n');
81
+		$end_month   = isset($_POST['end_month']) ? absint($_POST['end_month']) : date('n');
82 82
 
83 83
 		$data  = array();
84 84
 		$year  = $start_year;
85 85
 		$stats = new Give_Payment_Stats;
86 86
 
87
-		while ( $year <= $end_year ) {
87
+		while ($year <= $end_year) {
88 88
 
89
-			if ( $year == $start_year && $year == $end_year ) {
89
+			if ($year == $start_year && $year == $end_year) {
90 90
 
91 91
 				$m1 = $start_month;
92 92
 				$m2 = $end_month;
93 93
 
94
-			} elseif ( $year == $start_year ) {
94
+			} elseif ($year == $start_year) {
95 95
 
96 96
 				$m1 = $start_month;
97 97
 				$m2 = 12;
98 98
 
99
-			} elseif ( $year == $end_year ) {
99
+			} elseif ($year == $end_year) {
100 100
 
101 101
 				$m1 = 1;
102 102
 				$m2 = $end_month;
@@ -108,28 +108,28 @@  discard block
 block discarded – undo
108 108
 
109 109
 			}
110 110
 
111
-			while ( $m1 <= $m2 ) {
111
+			while ($m1 <= $m2) {
112 112
 
113
-				$date1 = mktime( 0, 0, 0, $m1, 1, $year );
114
-				$date2 = mktime( 0, 0, 0, $m1, cal_days_in_month( CAL_GREGORIAN, $m1, $year ), $year );
113
+				$date1 = mktime(0, 0, 0, $m1, 1, $year);
114
+				$date2 = mktime(0, 0, 0, $m1, cal_days_in_month(CAL_GREGORIAN, $m1, $year), $year);
115 115
 
116 116
 				$data[] = array(
117
-					'date'      => date_i18n( 'F Y', $date1 ),
118
-					'donations' => $stats->get_sales( 0, $date1, $date2 ),
119
-					'earnings'  => give_format_amount( $stats->get_earnings( 0, $date1, $date2 ), array( 'sanitize' => false ) ),
117
+					'date'      => date_i18n('F Y', $date1),
118
+					'donations' => $stats->get_sales(0, $date1, $date2),
119
+					'earnings'  => give_format_amount($stats->get_earnings(0, $date1, $date2), array('sanitize' => false)),
120 120
 				);
121 121
 
122
-				$m1 ++;
122
+				$m1++;
123 123
 
124 124
 			}
125 125
 
126 126
 
127
-			$year ++;
127
+			$year++;
128 128
 
129 129
 		}
130 130
 
131
-		$data = apply_filters( 'give_export_get_data', $data );
132
-		$data = apply_filters( "give_export_get_data_{$this->export_type}", $data );
131
+		$data = apply_filters('give_export_get_data', $data);
132
+		$data = apply_filters("give_export_get_data_{$this->export_type}", $data);
133 133
 
134 134
 		return $data;
135 135
 	}
Please login to merge, or discard this patch.