Test Failed
Push — master ( 7fe983...516c23 )
by Devin
08:07 queued 03:09
created
includes/class-give-cli-commands.php 1 patch
Spacing   +196 added lines, -196 removed lines patch added patch discarded remove patch
@@ -7,12 +7,12 @@  discard block
 block discarded – undo
7 7
  */
8 8
 
9 9
 // Exit if accessed directly.
10
-if ( ! defined( 'ABSPATH' ) ) {
10
+if ( ! defined('ABSPATH')) {
11 11
 	exit;
12 12
 }
13 13
 
14 14
 // Add give command.
15
-WP_CLI::add_command( 'give', 'GIVE_CLI_COMMAND' );
15
+WP_CLI::add_command('give', 'GIVE_CLI_COMMAND');
16 16
 
17 17
 
18 18
 /**
@@ -68,8 +68,8 @@  discard block
 block discarded – undo
68 68
 	 *
69 69
 	 * @subcommand    logo
70 70
 	 */
71
-	public function ascii( $args, $assoc_args ) {
72
-		WP_CLI::log( file_get_contents( GIVE_PLUGIN_DIR . 'assets/images/give-ascii-logo.txt' ) );
71
+	public function ascii($args, $assoc_args) {
72
+		WP_CLI::log(file_get_contents(GIVE_PLUGIN_DIR.'assets/images/give-ascii-logo.txt'));
73 73
 	}
74 74
 
75 75
 
@@ -94,54 +94,54 @@  discard block
 block discarded – undo
94 94
 	 *
95 95
 	 * @subcommand    details
96 96
 	 */
97
-	public function details( $args, $assoc_args ) {
97
+	public function details($args, $assoc_args) {
98 98
 
99 99
 		/**
100 100
 		 * Plugin Information
101 101
 		 */
102
-		WP_CLI::log( $this->color_message( __( 'Give Version: ', 'give' ) ) . GIVE_VERSION );
102
+		WP_CLI::log($this->color_message(__('Give Version: ', 'give')).GIVE_VERSION);
103 103
 
104 104
 		/**
105 105
 		 * General Information.
106 106
 		 */
107
-		WP_CLI::log( "\n####   " . $this->color_message( __( 'General information', 'give' ) ) . '   ####' );
107
+		WP_CLI::log("\n####   ".$this->color_message(__('General information', 'give')).'   ####');
108 108
 
109
-		$success_page = give_get_option( 'success_page' );
110
-		$failure_page = give_get_option( 'failure_page' );
111
-		$history_page = give_get_option( 'history_page' );
109
+		$success_page = give_get_option('success_page');
110
+		$failure_page = give_get_option('failure_page');
111
+		$history_page = give_get_option('history_page');
112 112
 
113
-		WP_CLI::log( $this->color_message( sprintf( __( 'Success Page: ', 'give' ) ) ) . ( $success_page ? "[{$success_page}] " . get_permalink( $success_page ) : __( 'Not Set', 'give' ) ) );
114
-		WP_CLI::log( $this->color_message( __( 'Failed Donation Page: ', 'give' ) ) . ( $failure_page ? "[{$failure_page}] " . get_permalink( $failure_page ) : __( 'Not Set', 'give' ) ) );
115
-		WP_CLI::log( $this->color_message( __( 'Donation History Page: ', 'give' ) ) . ( $history_page ? "[{$history_page}] " . get_permalink( $history_page ) : __( 'Not Set', 'give' ) ) );
116
-		WP_CLI::log( $this->color_message( __( 'Country: ', 'give' ) ) . give_get_country() );
113
+		WP_CLI::log($this->color_message(sprintf(__('Success Page: ', 'give'))).($success_page ? "[{$success_page}] ".get_permalink($success_page) : __('Not Set', 'give')));
114
+		WP_CLI::log($this->color_message(__('Failed Donation Page: ', 'give')).($failure_page ? "[{$failure_page}] ".get_permalink($failure_page) : __('Not Set', 'give')));
115
+		WP_CLI::log($this->color_message(__('Donation History Page: ', 'give')).($history_page ? "[{$history_page}] ".get_permalink($history_page) : __('Not Set', 'give')));
116
+		WP_CLI::log($this->color_message(__('Country: ', 'give')).give_get_country());
117 117
 
118 118
 		/**
119 119
 		 * Currency Information.
120 120
 		 */
121
-		$default_gateway = give_get_option( 'default_gateway' );
121
+		$default_gateway = give_get_option('default_gateway');
122 122
 
123
-		WP_CLI::log( "\n####   " . $this->color_message( __( 'Currency Information', 'give' ) ) . '   ####' );
123
+		WP_CLI::log("\n####   ".$this->color_message(__('Currency Information', 'give')).'   ####');
124 124
 
125
-		WP_CLI::log( $this->color_message( __( 'Currency: ', 'give' ), give_get_currency() ) );
126
-		WP_CLI::log( $this->color_message( __( 'Currency Position: ', 'give' ), give_get_currency_position() ) );
127
-		WP_CLI::log( $this->color_message( __( 'Thousand Separator: ', 'give' ), give_get_price_thousand_separator() ) );
128
-		WP_CLI::log( $this->color_message( __( 'Decimal Separator: ', 'give' ), give_get_price_decimal_separator() ) );
129
-		WP_CLI::log( $this->color_message( __( 'Number of Decimals: ', 'give' ), give_get_price_decimals() ) );
130
-		WP_CLI::log( $this->color_message( __( 'Test Mode: ', 'give' ), ( give_get_option( 'test_mode' ) ? __( 'Yes', 'give' ) : __( 'No', 'give' ) ) ) );
131
-		WP_CLI::log( $this->color_message( __( 'Default Gateway: ', 'give' ), ( $default_gateway ? $default_gateway : __( 'Not Set', 'give' ) ) ) );
125
+		WP_CLI::log($this->color_message(__('Currency: ', 'give'), give_get_currency()));
126
+		WP_CLI::log($this->color_message(__('Currency Position: ', 'give'), give_get_currency_position()));
127
+		WP_CLI::log($this->color_message(__('Thousand Separator: ', 'give'), give_get_price_thousand_separator()));
128
+		WP_CLI::log($this->color_message(__('Decimal Separator: ', 'give'), give_get_price_decimal_separator()));
129
+		WP_CLI::log($this->color_message(__('Number of Decimals: ', 'give'), give_get_price_decimals()));
130
+		WP_CLI::log($this->color_message(__('Test Mode: ', 'give'), (give_get_option('test_mode') ? __('Yes', 'give') : __('No', 'give'))));
131
+		WP_CLI::log($this->color_message(__('Default Gateway: ', 'give'), ($default_gateway ? $default_gateway : __('Not Set', 'give'))));
132 132
 
133 133
 		// Payment gateways Information.
134
-		$gateways = give_get_ordered_payment_gateways( give_get_payment_gateways() );
135
-		WP_CLI::log( $this->color_message( __( 'Enabled Gateways: ', 'give' ) ) );
134
+		$gateways = give_get_ordered_payment_gateways(give_get_payment_gateways());
135
+		WP_CLI::log($this->color_message(__('Enabled Gateways: ', 'give')));
136 136
 
137
-		if ( ! empty( $gateways ) ) {
137
+		if ( ! empty($gateways)) {
138 138
 			self::$counter = 1;
139
-			foreach ( $gateways as $gateway ) {
140
-				WP_CLI::log( '  ' . $this->color_message( self::$counter, $gateway['admin_label'] ) );
141
-				self::$counter ++;
139
+			foreach ($gateways as $gateway) {
140
+				WP_CLI::log('  '.$this->color_message(self::$counter, $gateway['admin_label']));
141
+				self::$counter++;
142 142
 			}
143 143
 		} else {
144
-			WP_CLI::log( __( 'Not any payment gateways found', 'give' ) );
144
+			WP_CLI::log(__('Not any payment gateways found', 'give'));
145 145
 		}
146 146
 	}
147 147
 
@@ -173,15 +173,15 @@  discard block
 block discarded – undo
173 173
 	 *
174 174
 	 * @subcommand    forms
175 175
 	 */
176
-	public function forms( $args, $assoc_args ) {
176
+	public function forms($args, $assoc_args) {
177 177
 		global $wp_query;
178
-		$form_id = isset( $assoc_args ) && array_key_exists( 'id', $assoc_args ) ? absint( $assoc_args['id'] ) : false;
179
-		$number  = isset( $assoc_args ) && array_key_exists( 'number', $assoc_args ) ? absint( $assoc_args['number'] ) : 10;
178
+		$form_id = isset($assoc_args) && array_key_exists('id', $assoc_args) ? absint($assoc_args['id']) : false;
179
+		$number  = isset($assoc_args) && array_key_exists('number', $assoc_args) ? absint($assoc_args['number']) : 10;
180 180
 		$start   = time();
181 181
 
182 182
 		// Cache previous number query var.
183 183
 		$is_set_number = $cache_per_page = false;
184
-		if ( isset( $wp_query->query_vars['number'] ) ) {
184
+		if (isset($wp_query->query_vars['number'])) {
185 185
 			$cache_per_page = $wp_query->query_vars['number'];
186 186
 			$is_set_number  = true;
187 187
 		}
@@ -190,22 +190,22 @@  discard block
 block discarded – undo
190 190
 		$wp_query->query_vars['number'] = $number;
191 191
 
192 192
 		// Get forms.
193
-		$forms = $form_id ? $this->api->get_forms( $form_id ) : $this->api->get_forms();
193
+		$forms = $form_id ? $this->api->get_forms($form_id) : $this->api->get_forms();
194 194
 
195 195
 		// Reset number query var.
196
-		if ( $is_set_number ) {
196
+		if ($is_set_number) {
197 197
 			$wp_query->query_vars['number'] = $cache_per_page;
198 198
 		}
199 199
 
200 200
 		// Bailout.
201
-		if ( array_key_exists( 'error', $forms ) ) {
201
+		if (array_key_exists('error', $forms)) {
202 202
 
203
-			WP_CLI::warning( $forms['error'] );
203
+			WP_CLI::warning($forms['error']);
204 204
 
205 205
 			return;
206
-		} elseif ( empty( $forms['forms'] ) ) {
206
+		} elseif (empty($forms['forms'])) {
207 207
 
208
-			WP_CLI::error( __( 'No forms found.', 'give' ) );
208
+			WP_CLI::error(__('No forms found.', 'give'));
209 209
 
210 210
 			return;
211 211
 		}
@@ -213,25 +213,25 @@  discard block
 block discarded – undo
213 213
 		// Param to check if form typeis already showed or not.
214 214
 		$is_show_form_type = false;
215 215
 
216
-		if ( 1 === count( $forms ) && $form_id ) {
216
+		if (1 === count($forms) && $form_id) {
217 217
 			// Show single form.
218
-			foreach ( $forms['forms'][0] as $key => $info ) {
219
-				switch ( $key ) {
218
+			foreach ($forms['forms'][0] as $key => $info) {
219
+				switch ($key) {
220 220
 					case 'stats':
221
-						$this->color_main_heading( ucfirst( $key ) );
221
+						$this->color_main_heading(ucfirst($key));
222 222
 
223
-						foreach ( $info as $heading => $data ) {
224
-							$this->color_sub_heading( ucfirst( $heading ) );
225
-							switch ( $heading ) {
223
+						foreach ($info as $heading => $data) {
224
+							$this->color_sub_heading(ucfirst($heading));
225
+							switch ($heading) {
226 226
 								default:
227
-									foreach ( $data as $subheading => $subdata ) {
227
+									foreach ($data as $subheading => $subdata) {
228 228
 
229
-										switch ( $subheading ) {
229
+										switch ($subheading) {
230 230
 											case 'earnings':
231
-												WP_CLI::log( $this->color_message( $subheading . ': ', give_currency_filter( $subdata ) ) );
231
+												WP_CLI::log($this->color_message($subheading.': ', give_currency_filter($subdata)));
232 232
 												break;
233 233
 											default:
234
-												WP_CLI::log( $this->color_message( $subheading . ': ', $subdata ) );
234
+												WP_CLI::log($this->color_message($subheading.': ', $subdata));
235 235
 										}
236 236
 									}
237 237
 							}
@@ -241,26 +241,26 @@  discard block
 block discarded – undo
241 241
 					case 'pricing':
242 242
 					case 'info':
243 243
 					default:
244
-						$this->color_main_heading( ucfirst( $key ) );
244
+						$this->color_main_heading(ucfirst($key));
245 245
 
246 246
 						// Show form type.
247
-						if ( ! $is_show_form_type ) {
248
-							$form              = new Give_Donate_Form( $form_id );
247
+						if ( ! $is_show_form_type) {
248
+							$form              = new Give_Donate_Form($form_id);
249 249
 							$is_show_form_type = true;
250 250
 
251
-							WP_CLI::log( $this->color_message( __( 'form type', 'give' ), $form->get_type() ) );
251
+							WP_CLI::log($this->color_message(__('form type', 'give'), $form->get_type()));
252 252
 						}
253 253
 
254
-						foreach ( $info as $heading => $data ) {
254
+						foreach ($info as $heading => $data) {
255 255
 
256
-							switch ( $heading ) {
256
+							switch ($heading) {
257 257
 								case 'id':
258
-									WP_CLI::log( $this->color_message( $heading, $data ) );
258
+									WP_CLI::log($this->color_message($heading, $data));
259 259
 									break;
260 260
 
261 261
 								default:
262
-									$data = empty( $data ) ? __( 'Not set', 'give' ) : $data;
263
-									WP_CLI::log( $this->color_message( $heading, $data ) );
262
+									$data = empty($data) ? __('Not set', 'give') : $data;
263
+									WP_CLI::log($this->color_message($heading, $data));
264 264
 							}
265 265
 						}
266 266
 				}// End switch().
@@ -271,37 +271,37 @@  discard block
 block discarded – undo
271 271
 			$is_table_first_row_set = false;
272 272
 			$table_column_count     = 0;
273 273
 
274
-			WP_CLI::line( $this->color_message( sprintf( __( '%d donation forms found', 'give' ), count( $forms['forms'] ) ), '', false ) );
274
+			WP_CLI::line($this->color_message(sprintf(__('%d donation forms found', 'give'), count($forms['forms'])), '', false));
275 275
 
276
-			foreach ( $forms['forms'] as $index => $form_data ) {
276
+			foreach ($forms['forms'] as $index => $form_data) {
277 277
 
278 278
 				// Default table data.
279 279
 				$table_first_row = array();
280 280
 				$table_row       = array();
281 281
 
282
-				foreach ( $form_data['info'] as $key => $form ) {
282
+				foreach ($form_data['info'] as $key => $form) {
283 283
 
284 284
 					// Do not show thumbnail, content and link in table.
285
-					if ( in_array( $key, array( 'content', 'thumbnail', 'link' ), true ) ) {
285
+					if (in_array($key, array('content', 'thumbnail', 'link'), true)) {
286 286
 						continue;
287 287
 					}
288 288
 
289
-					if ( ! $is_table_first_row_set ) {
289
+					if ( ! $is_table_first_row_set) {
290 290
 						$table_first_row[] = $key;
291 291
 					}
292 292
 
293 293
 					$table_row[] = $form;
294 294
 
295
-					if ( 'status' === $key ) {
295
+					if ('status' === $key) {
296 296
 						// First array item will be an form id in our case.
297
-						$form = new Give_Donate_Form( absint( $table_row[0] ) );
297
+						$form = new Give_Donate_Form(absint($table_row[0]));
298 298
 
299 299
 						$table_row[] = $form->get_type();
300 300
 					}
301 301
 				}
302 302
 
303 303
 				// Set table first row.
304
-				if ( ! $is_table_first_row_set ) {
304
+				if ( ! $is_table_first_row_set) {
305 305
 
306 306
 					// Add extra column to table.
307 307
 					$table_first_row[] = 'type';
@@ -314,7 +314,7 @@  discard block
 block discarded – undo
314 314
 				$table_data[] = $table_row;
315 315
 			}// End foreach().
316 316
 
317
-			$this->display_table( $table_data );
317
+			$this->display_table($table_data);
318 318
 		}// End if().
319 319
 	}
320 320
 
@@ -367,37 +367,37 @@  discard block
 block discarded – undo
367 367
 	 *
368 368
 	 * @subcommand    donors
369 369
 	 */
370
-	public function donors( $args, $assoc_args ) {
370
+	public function donors($args, $assoc_args) {
371 371
 		global $wp_query;
372
-		$donor_id = isset( $assoc_args ) && array_key_exists( 'id', $assoc_args ) ? absint( $assoc_args['id'] ) : false;
373
-		$email    = isset( $assoc_args ) && array_key_exists( 'email', $assoc_args ) ? $assoc_args['email'] : false;
374
-		$name     = isset( $assoc_args ) && array_key_exists( 'name', $assoc_args ) ? $assoc_args['name'] : '';
375
-		$create   = isset( $assoc_args ) && array_key_exists( 'create', $assoc_args ) ? $assoc_args['create'] : false;
376
-		$number   = isset( $assoc_args ) && array_key_exists( 'number', $assoc_args ) ? $assoc_args['number'] : 10;
377
-		$form_id  = isset( $assoc_args ) && array_key_exists( 'form-id', $assoc_args ) ? $assoc_args['form-id'] : 0;
378
-		$format   = isset( $assoc_args ) && array_key_exists( 'format', $assoc_args ) ? $assoc_args['format'] : 'table';
372
+		$donor_id = isset($assoc_args) && array_key_exists('id', $assoc_args) ? absint($assoc_args['id']) : false;
373
+		$email    = isset($assoc_args) && array_key_exists('email', $assoc_args) ? $assoc_args['email'] : false;
374
+		$name     = isset($assoc_args) && array_key_exists('name', $assoc_args) ? $assoc_args['name'] : '';
375
+		$create   = isset($assoc_args) && array_key_exists('create', $assoc_args) ? $assoc_args['create'] : false;
376
+		$number   = isset($assoc_args) && array_key_exists('number', $assoc_args) ? $assoc_args['number'] : 10;
377
+		$form_id  = isset($assoc_args) && array_key_exists('form-id', $assoc_args) ? $assoc_args['form-id'] : 0;
378
+		$format   = isset($assoc_args) && array_key_exists('format', $assoc_args) ? $assoc_args['format'] : 'table';
379 379
 		$start    = time();
380 380
 
381
-		if ( $create ) {
381
+		if ($create) {
382 382
 			$number = 1;
383 383
 
384
-			if ( isset( $assoc_args['email'] ) && ! is_email( $email ) ) {
385
-				WP_CLI::warning( 'Wrong email address provided.', 'give' );
384
+			if (isset($assoc_args['email']) && ! is_email($email)) {
385
+				WP_CLI::warning('Wrong email address provided.', 'give');
386 386
 
387 387
 				return;
388 388
 			}
389 389
 
390 390
 			// Create one or more donors.
391
-			if ( ! $email ) {
391
+			if ( ! $email) {
392 392
 				// If no email is specified, look to see if we are generating arbitrary donor accounts.
393
-				$number = is_numeric( $create ) ? absint( $create ) : 1;
393
+				$number = is_numeric($create) ? absint($create) : 1;
394 394
 			}
395 395
 
396
-			for ( $i = 0; $i < $number; $i ++ ) {
397
-				if ( ! $email ) {
396
+			for ($i = 0; $i < $number; $i++) {
397
+				if ( ! $email) {
398 398
 
399 399
 					// Generate fake email.
400
-					$email = 'customer-' . uniqid() . '@test.com';
400
+					$email = 'customer-'.uniqid().'@test.com';
401 401
 				}
402 402
 
403 403
 				$args = array(
@@ -405,19 +405,19 @@  discard block
 block discarded – undo
405 405
 					'name'  => $name,
406 406
 				);
407 407
 
408
-				$donor_id = Give()->donors->add( $args );
408
+				$donor_id = Give()->donors->add($args);
409 409
 
410
-				if ( $donor_id ) {
411
-					WP_CLI::line( $this->color_message( sprintf( __( 'Donor #%d created successfully', 'give' ), $donor_id ) ) );
410
+				if ($donor_id) {
411
+					WP_CLI::line($this->color_message(sprintf(__('Donor #%d created successfully', 'give'), $donor_id)));
412 412
 				} else {
413
-					WP_CLI::error( __( 'Failed to create donor', 'give' ) );
413
+					WP_CLI::error(__('Failed to create donor', 'give'));
414 414
 				}
415 415
 
416 416
 				// Reset email to false so it is generated on the next loop (if creating donors).
417 417
 				$email = false;
418 418
 			}
419 419
 
420
-			WP_CLI::line( $this->color_message( sprintf( __( '%1$d donors created in %2$d seconds', 'give' ), $number, time() - $start ) ) );
420
+			WP_CLI::line($this->color_message(sprintf(__('%1$d donors created in %2$d seconds', 'give'), $number, time() - $start)));
421 421
 
422 422
 		} else {
423 423
 			// Counter.
@@ -431,7 +431,7 @@  discard block
 block discarded – undo
431 431
 			 */
432 432
 			// Cache previous number query var.
433 433
 			$is_set_number = $cache_per_page = false;
434
-			if ( isset( $wp_query->query_vars['number'] ) ) {
434
+			if (isset($wp_query->query_vars['number'])) {
435 435
 				$cache_per_page = $wp_query->query_vars['number'];
436 436
 				$is_set_number  = true;
437 437
 			}
@@ -440,24 +440,24 @@  discard block
 block discarded – undo
440 440
 			$wp_query->query_vars['number'] = $number;
441 441
 
442 442
 			// Get donors.
443
-			if ( $form_id ) {
443
+			if ($form_id) {
444 444
 				// @TODO: Allow user to get a list of donors by donation status.
445
-				$donors = $this->get_donors_by_form_id( $form_id );
445
+				$donors = $this->get_donors_by_form_id($form_id);
446 446
 			} else {
447
-				$donors = $this->api->get_donors( $search );
447
+				$donors = $this->api->get_donors($search);
448 448
 			}
449 449
 
450 450
 			// Reset number query var.
451
-			if ( $is_set_number ) {
451
+			if ($is_set_number) {
452 452
 				$wp_query->query_vars['number'] = $cache_per_page;
453 453
 			}
454 454
 
455
-			if ( isset( $donors['error'] ) ) {
456
-				WP_CLI::error( $donors['error'] );
455
+			if (isset($donors['error'])) {
456
+				WP_CLI::error($donors['error']);
457 457
 			}
458 458
 
459
-			if ( empty( $donors ) ) {
460
-				WP_CLI::error( __( 'No donors found.', 'give' ) );
459
+			if (empty($donors)) {
460
+				WP_CLI::error(__('No donors found.', 'give'));
461 461
 
462 462
 				return;
463 463
 			}
@@ -465,24 +465,24 @@  discard block
 block discarded – undo
465 465
 			$table_data             = array();
466 466
 			$is_table_first_row_set = false;
467 467
 
468
-			foreach ( $donors['donors'] as $donor_data ) {
468
+			foreach ($donors['donors'] as $donor_data) {
469 469
 				// Set default table row data.
470
-				$table_first_row = array( __( 's_no', 'give' ) );
471
-				$table_row       = array( self::$counter );
470
+				$table_first_row = array(__('s_no', 'give'));
471
+				$table_row       = array(self::$counter);
472 472
 
473
-				foreach ( $donor_data as $key => $donor ) {
474
-					switch ( $key ) {
473
+				foreach ($donor_data as $key => $donor) {
474
+					switch ($key) {
475 475
 						case 'stats':
476
-							foreach ( $donor as $heading => $data ) {
476
+							foreach ($donor as $heading => $data) {
477 477
 
478 478
 								// Get first row.
479
-								if ( ! $is_table_first_row_set ) {
479
+								if ( ! $is_table_first_row_set) {
480 480
 									$table_first_row[] = $heading;
481 481
 								}
482 482
 
483
-								switch ( $heading ) {
483
+								switch ($heading) {
484 484
 									case 'total_spent':
485
-										$table_row[] = give_currency_filter( $data );
485
+										$table_row[] = give_currency_filter($data);
486 486
 										break;
487 487
 
488 488
 									default:
@@ -493,10 +493,10 @@  discard block
 block discarded – undo
493 493
 
494 494
 						case 'info':
495 495
 						default:
496
-							foreach ( $donor as $heading => $data ) {
496
+							foreach ($donor as $heading => $data) {
497 497
 
498 498
 								// Get first row.
499
-								if ( ! $is_table_first_row_set ) {
499
+								if ( ! $is_table_first_row_set) {
500 500
 									$table_first_row[] = $heading;
501 501
 								}
502 502
 
@@ -506,7 +506,7 @@  discard block
 block discarded – undo
506 506
 				}
507 507
 
508 508
 				// Add first row data to table data.
509
-				if ( ! $is_table_first_row_set ) {
509
+				if ( ! $is_table_first_row_set) {
510 510
 					$table_data[]           = $table_first_row;
511 511
 					$is_table_first_row_set = true;
512 512
 				}
@@ -515,44 +515,44 @@  discard block
 block discarded – undo
515 515
 				$table_data[] = $table_row;
516 516
 
517 517
 				// Increase counter.
518
-				self::$counter ++;
518
+				self::$counter++;
519 519
 			}// End foreach().
520 520
 
521
-			switch ( $format ) {
521
+			switch ($format) {
522 522
 				case 'json':
523 523
 					$table_column_name = $table_data[0];
524
-					unset( $table_data[0] );
524
+					unset($table_data[0]);
525 525
 
526 526
 					$new_table_data = array();
527
-					foreach ( $table_data as $index => $data ) {
528
-						foreach ( $data as $key => $value ) {
529
-							$new_table_data[ $index ][ $table_column_name[ $key ] ] = $value;
527
+					foreach ($table_data as $index => $data) {
528
+						foreach ($data as $key => $value) {
529
+							$new_table_data[$index][$table_column_name[$key]] = $value;
530 530
 						}
531 531
 					}
532 532
 
533
-					WP_CLI::log( json_encode( $new_table_data ) );
533
+					WP_CLI::log(json_encode($new_table_data));
534 534
 					break;
535 535
 
536 536
 				case 'csv':
537
-					$file_path = trailingslashit( WP_CONTENT_DIR ) . 'uploads/give_donors_' . date( 'Y_m_d_s', current_time( 'timestamp' ) ) . '.csv';
538
-					$fp        = fopen( $file_path, 'w' );
537
+					$file_path = trailingslashit(WP_CONTENT_DIR).'uploads/give_donors_'.date('Y_m_d_s', current_time('timestamp')).'.csv';
538
+					$fp        = fopen($file_path, 'w');
539 539
 
540
-					if ( is_writable( $file_path ) ) {
541
-						foreach ( $table_data as $fields ) {
542
-							fputcsv( $fp, $fields );
540
+					if (is_writable($file_path)) {
541
+						foreach ($table_data as $fields) {
542
+							fputcsv($fp, $fields);
543 543
 						}
544 544
 
545
-						fclose( $fp );
545
+						fclose($fp);
546 546
 
547
-						WP_CLI::success( "Donors list csv created successfully: {$file_path}" );
547
+						WP_CLI::success("Donors list csv created successfully: {$file_path}");
548 548
 					} else {
549
-						WP_CLI::warning( "Unable to create donors list csv file: {$file_path} (May folder do not have write permission)" );
549
+						WP_CLI::warning("Unable to create donors list csv file: {$file_path} (May folder do not have write permission)");
550 550
 					}
551 551
 
552 552
 					break;
553 553
 
554 554
 				default:
555
-					$this->display_table( $table_data );
555
+					$this->display_table($table_data);
556 556
 			}// End switch().
557 557
 		}// End if().
558 558
 	}
@@ -582,13 +582,13 @@  discard block
 block discarded – undo
582 582
 	 *
583 583
 	 * @subcommand    donations
584 584
 	 */
585
-	public function donations( $args, $assoc_args ) {
585
+	public function donations($args, $assoc_args) {
586 586
 		global $wp_query;
587
-		$number = isset( $assoc_args ) && array_key_exists( 'number', $assoc_args ) ? $assoc_args['number'] : 10;
587
+		$number = isset($assoc_args) && array_key_exists('number', $assoc_args) ? $assoc_args['number'] : 10;
588 588
 
589 589
 		// Cache previous number query var.
590 590
 		$is_set_number = $cache_per_page = false;
591
-		if ( isset( $wp_query->query_vars['number'] ) ) {
591
+		if (isset($wp_query->query_vars['number'])) {
592 592
 			$cache_per_page = $wp_query->query_vars['number'];
593 593
 			$is_set_number  = true;
594 594
 		}
@@ -600,46 +600,46 @@  discard block
 block discarded – undo
600 600
 		$donations = $this->api->get_recent_donations();
601 601
 
602 602
 		// Reset number query var.
603
-		if ( $is_set_number ) {
603
+		if ($is_set_number) {
604 604
 			$wp_query->query_vars['number'] = $cache_per_page;
605 605
 		}
606 606
 
607
-		if ( empty( $donations ) ) {
608
-			WP_CLI::error( __( 'No donations found.', 'give' ) );
607
+		if (empty($donations)) {
608
+			WP_CLI::error(__('No donations found.', 'give'));
609 609
 
610 610
 			return;
611 611
 		}
612 612
 
613 613
 		self::$counter = 1;
614 614
 
615
-		foreach ( $donations['donations'] as $key => $donation ) {
616
-			$this->color_main_heading( sprintf( __( '%1$s. Donation #%2$s', 'give' ), self::$counter, $donation['ID'] ), 'Y' );
617
-			self::$counter ++;
615
+		foreach ($donations['donations'] as $key => $donation) {
616
+			$this->color_main_heading(sprintf(__('%1$s. Donation #%2$s', 'give'), self::$counter, $donation['ID']), 'Y');
617
+			self::$counter++;
618 618
 
619
-			foreach ( $donation as $column => $data ) {
619
+			foreach ($donation as $column => $data) {
620 620
 
621
-				if ( is_array( $data ) ) {
622
-					$this->color_sub_heading( $column );
623
-					foreach ( $data as $subcolumn => $subdata ) {
621
+				if (is_array($data)) {
622
+					$this->color_sub_heading($column);
623
+					foreach ($data as $subcolumn => $subdata) {
624 624
 
625 625
 						// Decode html codes.
626
-						switch ( $subcolumn ) {
626
+						switch ($subcolumn) {
627 627
 							case 'name':
628
-								$subdata = html_entity_decode( $subdata );
628
+								$subdata = html_entity_decode($subdata);
629 629
 								break;
630 630
 						}
631 631
 
632 632
 						// @TODO Check if multi dimension array information is importent to show or not. For example inside donation array we have array for fees data inside payment meta.
633
-						if ( is_array( $subdata ) ) {
633
+						if (is_array($subdata)) {
634 634
 							continue;
635 635
 						}
636 636
 
637
-						WP_CLI::log( $this->color_message( $subcolumn, $subdata ) );
637
+						WP_CLI::log($this->color_message($subcolumn, $subdata));
638 638
 					}
639 639
 					continue;
640 640
 				}
641 641
 
642
-				WP_CLI::log( $this->color_message( $column, $data ) );
642
+				WP_CLI::log($this->color_message($column, $data));
643 643
 			}
644 644
 		}
645 645
 	}
@@ -679,27 +679,27 @@  discard block
 block discarded – undo
679 679
 	 *
680 680
 	 * @return        void
681 681
 	 */
682
-	public function report( $args, $assoc_args ) {
682
+	public function report($args, $assoc_args) {
683 683
 		$stats      = new Give_Payment_Stats();
684
-		$date       = isset( $assoc_args ) && array_key_exists( 'date', $assoc_args ) ? $assoc_args['date'] : false;
685
-		$start_date = isset( $assoc_args ) && array_key_exists( 'start-date', $assoc_args ) ? $assoc_args['start-date'] : false;
686
-		$end_date   = isset( $assoc_args ) && array_key_exists( 'end-date', $assoc_args ) ? $assoc_args['end-date'] : false;
687
-		$form_id    = isset( $assoc_args ) && array_key_exists( 'id', $assoc_args ) ? $assoc_args['id'] : 0;
684
+		$date       = isset($assoc_args) && array_key_exists('date', $assoc_args) ? $assoc_args['date'] : false;
685
+		$start_date = isset($assoc_args) && array_key_exists('start-date', $assoc_args) ? $assoc_args['start-date'] : false;
686
+		$end_date   = isset($assoc_args) && array_key_exists('end-date', $assoc_args) ? $assoc_args['end-date'] : false;
687
+		$form_id    = isset($assoc_args) && array_key_exists('id', $assoc_args) ? $assoc_args['id'] : 0;
688 688
 
689
-		if ( ! empty( $date ) ) {
689
+		if ( ! empty($date)) {
690 690
 			$start_date = $date;
691 691
 			$end_date   = false;
692
-		} elseif ( empty( $date ) && empty( $start_date ) ) {
692
+		} elseif (empty($date) && empty($start_date)) {
693 693
 			$start_date = 'this_month';
694 694
 			$end_date   = false;
695 695
 		}
696 696
 
697 697
 		// Get stats.
698
-		$earnings = $stats->get_earnings( $form_id, $start_date, $end_date );
699
-		$sales    = $stats->get_sales( $form_id, $start_date, $end_date );
698
+		$earnings = $stats->get_earnings($form_id, $start_date, $end_date);
699
+		$sales    = $stats->get_sales($form_id, $start_date, $end_date);
700 700
 
701
-		WP_CLI::line( $this->color_message( __( 'Earnings', 'give' ), give_currency_filter( $earnings ) ) );
702
-		WP_CLI::line( $this->color_message( __( 'Sales', 'give' ), $sales ) );
701
+		WP_CLI::line($this->color_message(__('Earnings', 'give'), give_currency_filter($earnings)));
702
+		WP_CLI::line($this->color_message(__('Sales', 'give'), $sales));
703 703
 	}
704 704
 
705 705
 
@@ -726,27 +726,27 @@  discard block
 block discarded – undo
726 726
 	 *
727 727
 	 * @subcommand    cache
728 728
 	 */
729
-	public function cache( $args, $assoc_args ) {
730
-		$action = isset( $assoc_args ) && array_key_exists( 'action', $assoc_args ) ? $assoc_args['action'] : false;
729
+	public function cache($args, $assoc_args) {
730
+		$action = isset($assoc_args) && array_key_exists('action', $assoc_args) ? $assoc_args['action'] : false;
731 731
 
732 732
 		// Bailout.
733
-		if ( ! $action || ! in_array( $action, array( 'delete' ), true ) ) {
734
-			WP_CLI::warning( __( 'Type wp give cache --action=delete to delete all stat transients', 'give' ) );
733
+		if ( ! $action || ! in_array($action, array('delete'), true)) {
734
+			WP_CLI::warning(__('Type wp give cache --action=delete to delete all stat transients', 'give'));
735 735
 
736 736
 			return;
737 737
 		}
738 738
 
739
-		switch ( $action ) {
739
+		switch ($action) {
740 740
 			case 'delete' :
741 741
 				// Reset counter.
742 742
 				self::$counter = 1;
743 743
 
744
-				if ( $this->delete_stats_transients() ) {
744
+				if ($this->delete_stats_transients()) {
745 745
 					// Report .eading.
746
-					WP_CLI::success( 'Give cache deleted.' );
746
+					WP_CLI::success('Give cache deleted.');
747 747
 				} else {
748 748
 					// Report .eading.
749
-					WP_CLI::warning( 'We did not find any Give plugin cache to delete :)' );
749
+					WP_CLI::warning('We did not find any Give plugin cache to delete :)');
750 750
 				}
751 751
 				break;
752 752
 		}
@@ -775,27 +775,27 @@  discard block
 block discarded – undo
775 775
 			ARRAY_A
776 776
 		);
777 777
 
778
-		if ( ! empty( $stat_option_names ) ) {
778
+		if ( ! empty($stat_option_names)) {
779 779
 
780
-			foreach ( $stat_option_names as $option_name ) {
780
+			foreach ($stat_option_names as $option_name) {
781 781
 				$error       = false;
782 782
 				$option_name = $option_name['option_name'];
783 783
 
784
-				switch ( true ) {
785
-					case ( false !== strpos( $option_name, 'transient' ) ):
786
-						$option_name = str_replace( '_transient_', '', $option_name );
787
-						$error       = delete_transient( $option_name );
784
+				switch (true) {
785
+					case (false !== strpos($option_name, 'transient')):
786
+						$option_name = str_replace('_transient_', '', $option_name);
787
+						$error       = delete_transient($option_name);
788 788
 						break;
789 789
 
790 790
 					default:
791
-						$error = delete_option( $option_name );
791
+						$error = delete_option($option_name);
792 792
 				}
793 793
 
794
-				if ( $error ) {
795
-					WP_CLI::log( $this->color_message( self::$counter, $option_name ) );
796
-					self::$counter ++;
794
+				if ($error) {
795
+					WP_CLI::log($this->color_message(self::$counter, $option_name));
796
+					self::$counter++;
797 797
 				} else {
798
-					WP_CLI::log( $this->color_message( __( 'Error while deleting this transient', 'give' ), $option_name ) );
798
+					WP_CLI::log($this->color_message(__('Error while deleting this transient', 'give'), $option_name));
799 799
 				}
800 800
 			}
801 801
 
@@ -816,13 +816,13 @@  discard block
 block discarded – undo
816 816
 	 *
817 817
 	 * @return   string
818 818
 	 */
819
-	private function color_message( $heading, $message = '', $colon = true, $color = 'g' ) {
819
+	private function color_message($heading, $message = '', $colon = true, $color = 'g') {
820 820
 		// Add colon.
821
-		if ( $colon ) {
822
-			$heading = $heading . ': ';
821
+		if ($colon) {
822
+			$heading = $heading.': ';
823 823
 		}
824 824
 
825
-		return WP_CLI::colorize( "%{$color}" . $heading . '%n' ) . $message;
825
+		return WP_CLI::colorize("%{$color}".$heading.'%n').$message;
826 826
 	}
827 827
 
828 828
 
@@ -837,8 +837,8 @@  discard block
 block discarded – undo
837 837
 	 *
838 838
 	 * @return    void
839 839
 	 */
840
-	private function color_main_heading( $heading, $color = 'g' ) {
841
-		WP_CLI::log( "\n######   " . $this->color_message( $heading, '', false, $color ) . '   ######' );
840
+	private function color_main_heading($heading, $color = 'g') {
841
+		WP_CLI::log("\n######   ".$this->color_message($heading, '', false, $color).'   ######');
842 842
 	}
843 843
 
844 844
 	/**
@@ -851,8 +851,8 @@  discard block
 block discarded – undo
851 851
 	 *
852 852
 	 * @return    void
853 853
 	 */
854
-	private function color_sub_heading( $subheading ) {
855
-		WP_CLI::log( "\n--->" . $subheading . '', '', false );
854
+	private function color_sub_heading($subheading) {
855
+		WP_CLI::log("\n--->".$subheading.'', '', false);
856 856
 	}
857 857
 
858 858
 
@@ -866,17 +866,17 @@  discard block
 block discarded – undo
866 866
 	 *
867 867
 	 * @return    void
868 868
 	 */
869
-	private function display_table( $data ) {
869
+	private function display_table($data) {
870 870
 		$table = new \cli\Table();
871 871
 
872 872
 		// Set table header.
873
-		$table->setHeaders( $data[0] );
873
+		$table->setHeaders($data[0]);
874 874
 
875 875
 		// Remove table header.
876
-		unset( $data[0] );
876
+		unset($data[0]);
877 877
 
878 878
 		// Set table data.
879
-		$table->setRows( $data );
879
+		$table->setRows($data);
880 880
 
881 881
 		// Display table.
882 882
 		$table->display();
@@ -893,14 +893,14 @@  discard block
 block discarded – undo
893 893
 	 * @return array
894 894
 	 */
895 895
 
896
-	private function get_donors_by_form_id( $form_id ) {
896
+	private function get_donors_by_form_id($form_id) {
897 897
 		$donors = array();
898 898
 
899 899
 		$donations = new Give_Payments_Query(
900 900
 			array(
901
-				'give_forms' => array( $form_id ),
902
-				'number'     => - 1,
903
-				'status'     => array( 'publish' ),
901
+				'give_forms' => array($form_id),
902
+				'number'     => -1,
903
+				'status'     => array('publish'),
904 904
 			)
905 905
 		);
906 906
 
@@ -908,16 +908,16 @@  discard block
 block discarded – undo
908 908
 		$skip_donors = array();
909 909
 
910 910
 		/* @var Give_Payment|object $donation Payment object. */
911
-		foreach ( $donations as $donation ) {
911
+		foreach ($donations as $donation) {
912 912
 
913
-			if ( in_array( $donation->customer_id, $skip_donors ,true ) ) {
913
+			if (in_array($donation->customer_id, $skip_donors, true)) {
914 914
 				continue;
915 915
 			}
916 916
 
917
-			if ( ! empty( $donors ) ) {
918
-				$donors['donors'][] = current( current( $this->api->get_donors( (int) $donation->customer_id ) ) );
917
+			if ( ! empty($donors)) {
918
+				$donors['donors'][] = current(current($this->api->get_donors((int) $donation->customer_id)));
919 919
 			} else {
920
-				$donors = array_merge( $donors, $this->api->get_donors( (int) $donation->customer_id ) );
920
+				$donors = array_merge($donors, $this->api->get_donors((int) $donation->customer_id));
921 921
 			}
922 922
 
923 923
 			$skip_donors[] = $donation->customer_id;
Please login to merge, or discard this patch.
includes/admin/tools/class-settings-import.php 2 patches
Doc Comments   +6 added lines patch added patch discarded remove patch
@@ -388,6 +388,9 @@  discard block
 block discarded – undo
388 388
 			}
389 389
 		}
390 390
 
391
+		/**
392
+		 * @param boolean $value
393
+		 */
391 394
 		static function selected( $option_value, $value ) {
392 395
 			$selected = '';
393 396
 			if ( stristr( $value, $option_value ) ) {
@@ -456,6 +459,9 @@  discard block
 block discarded – undo
456 459
 			<?php
457 460
 		}
458 461
 
462
+		/**
463
+		 * @param integer $file_id
464
+		 */
459 465
 		static function get_csv_total( $file_id ) {
460 466
 			$total = false;
461 467
 			if ( $file_id ) {
Please login to merge, or discard this patch.
Spacing   +159 added lines, -159 removed lines patch added patch discarded remove patch
@@ -9,11 +9,11 @@  discard block
 block discarded – undo
9 9
  * @since       1.8
10 10
  */
11 11
 
12
-if ( ! defined( 'ABSPATH' ) ) {
12
+if ( ! defined('ABSPATH')) {
13 13
 	exit; // Exit if accessed directly
14 14
 }
15 15
 
16
-if ( ! class_exists( 'Give_Settings_Import' ) ) {
16
+if ( ! class_exists('Give_Settings_Import')) {
17 17
 
18 18
 	/**
19 19
 	 * Give_Settings_Import.
@@ -56,37 +56,37 @@  discard block
 block discarded – undo
56 56
 		 */
57 57
 		public function __construct() {
58 58
 			$this->id    = 'import';
59
-			$this->label = __( 'Import Donations', 'give' );
59
+			$this->label = __('Import Donations', 'give');
60 60
 
61 61
 			// Add Import tab in submenu.
62
-			add_filter( 'give-tools_tabs_array', array( $this, 'add_settings_page' ), 20 );
62
+			add_filter('give-tools_tabs_array', array($this, 'add_settings_page'), 20);
63 63
 			// Will display html of the import donation.
64
-			add_action( 'give_admin_field_tools_import', array( $this, 'render_import_field' ), 10, 2 );
64
+			add_action('give_admin_field_tools_import', array($this, 'render_import_field'), 10, 2);
65 65
 			// Will call the function that genetrated the hook called 'give_admin_field_tools_import'.
66
-			add_action( "give-tools_settings_{$this->id}_page", array( $this, 'output' ) );
66
+			add_action("give-tools_settings_{$this->id}_page", array($this, 'output'));
67 67
 			// Do not use main form for this tab.
68
-			if ( give_get_current_setting_tab() === $this->id ) {
69
-				add_action( "give-tools_open_form", '__return_empty_string' );
70
-				add_action( "give-tools_close_form", '__return_empty_string' );
68
+			if (give_get_current_setting_tab() === $this->id) {
69
+				add_action("give-tools_open_form", '__return_empty_string');
70
+				add_action("give-tools_close_form", '__return_empty_string');
71 71
 			}
72 72
 			// Run when form submit.
73
-			add_action( 'give-tools_save_import', array( $this, 'save' ) );
74
-			add_action( 'give-tools_update_notices', array( $this, 'update_notices' ), 11, 1 );
73
+			add_action('give-tools_save_import', array($this, 'save'));
74
+			add_action('give-tools_update_notices', array($this, 'update_notices'), 11, 1);
75 75
 
76 76
 
77 77
 			// Will add the progress of the import
78
-			add_action( 'give_tools_import_form_before_start', array( 'Give_Settings_Import', 'progress' ), 10 );
78
+			add_action('give_tools_import_form_before_start', array('Give_Settings_Import', 'progress'), 10);
79 79
 			// Print the HTML.
80
-			add_action( 'give_tools_import_form_start', array( 'Give_Settings_Import', 'html' ), 10 );
80
+			add_action('give_tools_import_form_start', array('Give_Settings_Import', 'html'), 10);
81 81
 			// Used to add submit button.
82
-			add_action( 'give_tools_import_form_end', array( 'Give_Settings_Import', 'submit' ), 10 );
82
+			add_action('give_tools_import_form_end', array('Give_Settings_Import', 'submit'), 10);
83 83
 			// Print the html for CSV file upload.
84
-			add_action( 'give_admin_field_media_csv', array( $this, 'render_media_csv' ), 10, 2 );
84
+			add_action('give_admin_field_media_csv', array($this, 'render_media_csv'), 10, 2);
85 85
 		}
86 86
 
87
-		static function update_notices( $messages ) {
88
-			if ( ! empty( $_GET['tab'] ) && 'import' === give_clean( $_GET['tab'] ) ) {
89
-				unset( $messages['give-setting-updated'] );
87
+		static function update_notices($messages) {
88
+			if ( ! empty($_GET['tab']) && 'import' === give_clean($_GET['tab'])) {
89
+				unset($messages['give-setting-updated']);
90 90
 			}
91 91
 
92 92
 			return $messages;
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
 		 * @since 1.8.13
99 99
 		 */
100 100
 		static function submit() {
101
-			wp_nonce_field( 'give-save-settings', '_give-save-settings' );
101
+			wp_nonce_field('give-save-settings', '_give-save-settings');
102 102
 			?>
103 103
 			<input type="hidden" class="import-step" id="import-step" name="step"
104 104
 			       value="<?php echo Give_Settings_Import::get_step(); ?>"/>
@@ -114,33 +114,33 @@  discard block
 block discarded – undo
114 114
 			$step = Give_Settings_Import::get_step();
115 115
 			?>
116 116
 			<section>
117
-				<table class="widefat export-options-table give-table <?php echo 'step-' . $step; ?>"
118
-				       id="<?php echo 'step-' . $step; ?>">
117
+				<table class="widefat export-options-table give-table <?php echo 'step-'.$step; ?>"
118
+				       id="<?php echo 'step-'.$step; ?>">
119 119
 					<tbody>
120 120
 					<?php
121
-					if ( 1 === $step ) {
121
+					if (1 === $step) {
122 122
 						// Get the html of CSV file upload.
123 123
 						Give_Settings_Import::render_media_csv();
124
-					} elseif ( 2 === $step ) {
124
+					} elseif (2 === $step) {
125 125
 						Give_Settings_Import::render_dropdown();
126
-					} elseif ( 3 === $step ) {
126
+					} elseif (3 === $step) {
127 127
 						// Drop down for importer files.
128 128
 						Give_Settings_Import::start_import();
129
-					} elseif ( 4 === $step ) {
129
+					} elseif (4 === $step) {
130 130
 						// Successful or fail message.
131 131
 						Give_Settings_Import::import_success();
132 132
 					}
133 133
 
134
-					if ( self::check_for_dropdown_or_import() == false ) {
134
+					if (self::check_for_dropdown_or_import() == false) {
135 135
 						$step = Give_Settings_Import::get_step();
136 136
 						?>
137 137
 						<tr valign="top">
138 138
 							<th></th>
139 139
 							<th>
140 140
 								<input type="submit"
141
-								       class="button button-primary button-large button-secondary <?php echo 'step-' . $step; ?>"
141
+								       class="button button-primary button-large button-secondary <?php echo 'step-'.$step; ?>"
142 142
 								       id="recount-stats-submit"
143
-								       value="<?php esc_attr_e( 'Submit', 'give' ); ?>"/>
143
+								       value="<?php esc_attr_e('Submit', 'give'); ?>"/>
144 144
 							</th>
145 145
 						</tr>
146 146
 						<?php
@@ -154,38 +154,38 @@  discard block
 block discarded – undo
154 154
 
155 155
 		static function import_success() {
156 156
 
157
-			$delete_csv = ( ! empty( $_GET['delete_csv'] ) ? absint( $_GET['delete_csv'] ) : false );
158
-			$csv        = ( ! empty( $_GET['csv'] ) ? absint( $_GET['csv'] ) : false );
159
-			if ( ! empty( $delete_csv ) && ! empty( $csv ) ) {
160
-				wp_delete_attachment( $csv, true );
157
+			$delete_csv = ( ! empty($_GET['delete_csv']) ? absint($_GET['delete_csv']) : false);
158
+			$csv        = ( ! empty($_GET['csv']) ? absint($_GET['csv']) : false);
159
+			if ( ! empty($delete_csv) && ! empty($csv)) {
160
+				wp_delete_attachment($csv, true);
161 161
 			}
162 162
 
163 163
 			$report      = give_import_donation_report();
164 164
 			$report_html = array(
165 165
 				'duplicate_donor'    => array(
166
-					__( '%s duplicate %s detected', 'give' ),
167
-					__( 'donor', 'give' ),
168
-					__( 'donors', 'give' ),
166
+					__('%s duplicate %s detected', 'give'),
167
+					__('donor', 'give'),
168
+					__('donors', 'give'),
169 169
 				),
170 170
 				'create_donor'       => array(
171
-					__( '%s %s created', 'give' ),
172
-					__( 'donor', 'give' ),
173
-					__( 'donors', 'give' ),
171
+					__('%s %s created', 'give'),
172
+					__('donor', 'give'),
173
+					__('donors', 'give'),
174 174
 				),
175 175
 				'create_form'        => array(
176
-					__( '%s donation %s created', 'give' ),
177
-					__( 'form', 'give' ),
178
-					__( 'forms', 'give' ),
176
+					__('%s donation %s created', 'give'),
177
+					__('form', 'give'),
178
+					__('forms', 'give'),
179 179
 				),
180 180
 				'duplicate_donation' => array(
181
-					__( '%s duplicate %s detected', 'give' ),
182
-					__( 'donation', 'give' ),
183
-					__( 'donations', 'give' ),
181
+					__('%s duplicate %s detected', 'give'),
182
+					__('donation', 'give'),
183
+					__('donations', 'give'),
184 184
 				),
185 185
 				'create_donation'    => array(
186
-					__( '%s %s imported', 'give' ),
187
-					__( 'donation', 'give' ),
188
-					__( 'donations', 'give' ),
186
+					__('%s %s imported', 'give'),
187
+					__('donation', 'give'),
188
+					__('donations', 'give'),
189 189
 				),
190 190
 			);
191 191
 			$total       = (int) $_GET['total'];
@@ -196,34 +196,34 @@  discard block
 block discarded – undo
196 196
 				<th colspan="2">
197 197
 					<h2>
198 198
 						<?php
199
-						if ( $success ) {
200
-							echo sprintf( __( 'Import complete! %s donations processed', 'give' ), "<strong>{$total}</strong>" );
199
+						if ($success) {
200
+							echo sprintf(__('Import complete! %s donations processed', 'give'), "<strong>{$total}</strong>");
201 201
 						} else {
202
-							echo sprintf( __( 'Failed to import %s donations', 'give' ), "<strong>{$total}</strong>" );
202
+							echo sprintf(__('Failed to import %s donations', 'give'), "<strong>{$total}</strong>");
203 203
 						}
204 204
 						?>
205 205
 					</h2>
206 206
 
207 207
 					<?php
208
-					$text      = __( 'Import Donation', 'give' );
208
+					$text      = __('Import Donation', 'give');
209 209
 					$query_arg = array(
210 210
 						'post_type' => 'give_forms',
211 211
 						'page'      => 'give-tools',
212 212
 						'tab'       => 'import',
213 213
 					);
214
-					if ( $success ) {
214
+					if ($success) {
215 215
 						$query_arg = array(
216 216
 							'post_type' => 'give_forms',
217 217
 							'page'      => 'give-payment-history',
218 218
 						);
219
-						$text      = __( 'View Donations', 'give' );
219
+						$text = __('View Donations', 'give');
220 220
 					}
221 221
 
222
-					foreach ( $report as $key => $value ) {
223
-						if ( array_key_exists( $key, $report_html ) && ! empty( $value ) ) {
222
+					foreach ($report as $key => $value) {
223
+						if (array_key_exists($key, $report_html) && ! empty($value)) {
224 224
 							?>
225 225
 							<p>
226
-								<?php echo esc_html( wp_sprintf( $report_html[ $key ][0], $value, _n( $report_html[ $key ][1], $report_html[ $key ][2], $value, 'give' ) ) ); ?>
226
+								<?php echo esc_html(wp_sprintf($report_html[$key][0], $value, _n($report_html[$key][1], $report_html[$key][2], $value, 'give'))); ?>
227 227
 							</p>
228 228
 							<?php
229 229
 						}
@@ -231,7 +231,7 @@  discard block
 block discarded – undo
231 231
 					?>
232 232
 
233 233
 					<p>
234
-						<a class="button button-large button-secondary" href="<?php echo add_query_arg( $query_arg, admin_url( 'edit.php' ) ); ?>"><?php echo $text; ?></a>
234
+						<a class="button button-large button-secondary" href="<?php echo add_query_arg($query_arg, admin_url('edit.php')); ?>"><?php echo $text; ?></a>
235 235
 					</p>
236 236
 				</th>
237 237
 			</tr>
@@ -249,22 +249,22 @@  discard block
 block discarded – undo
249 249
 			$index_start = 1;
250 250
 			$index_end   = 1;
251 251
 			$next        = true;
252
-			$total       = self::get_csv_total( $csv );
253
-			if ( self::$per_page < $total ) {
254
-				$total_ajax = ceil( $total / self::$per_page );
252
+			$total       = self::get_csv_total($csv);
253
+			if (self::$per_page < $total) {
254
+				$total_ajax = ceil($total / self::$per_page);
255 255
 				$index_end  = self::$per_page;
256 256
 			} else {
257 257
 				$total_ajax = 1;
258 258
 				$index_end  = $total;
259 259
 				$next       = false;
260 260
 			}
261
-			$current_percentage = 100 / ( $total_ajax + 1 );
261
+			$current_percentage = 100 / ($total_ajax + 1);
262 262
 
263 263
 			?>
264 264
 			<tr valign="top" class="give-import-dropdown">
265 265
 				<th colspan="2">
266
-					<h2 id="give-import-title"><?php esc_html_e( 'Importing', 'give' ) ?></h2>
267
-					<p class="give-field-description"><?php esc_html_e( 'Your donations are now being imported...', 'give' ) ?></p>
266
+					<h2 id="give-import-title"><?php esc_html_e('Importing', 'give') ?></h2>
267
+					<p class="give-field-description"><?php esc_html_e('Your donations are now being imported...', 'give') ?></p>
268 268
 				</th>
269 269
 			</tr>
270 270
 
@@ -283,7 +283,7 @@  discard block
 block discarded – undo
283 283
 						<div style="width: <?php echo $current_percentage; ?>%"></div>
284 284
 					</div>
285 285
 					<input type="hidden" value="3" name="step">
286
-					<input type="hidden" value='<?php echo maybe_serialize( $_REQUEST['mapto'] ); ?>' name="mapto"
286
+					<input type="hidden" value='<?php echo maybe_serialize($_REQUEST['mapto']); ?>' name="mapto"
287 287
 					       class="mapto">
288 288
 					<input type="hidden" value="<?php echo $_REQUEST['csv']; ?>" name="csv" class="csv">
289 289
 					<input type="hidden" value="<?php echo $_REQUEST['mode']; ?>" name="mode" class="mode">
@@ -292,7 +292,7 @@  discard block
 block discarded – undo
292 292
 					<input type="hidden" value="<?php echo $_REQUEST['delete_csv']; ?>" name="delete_csv"
293 293
 					       class="delete_csv">
294 294
 					<input type="hidden" value="<?php echo $_REQUEST['delimiter']; ?>" name="delimiter">
295
-					<input type="hidden" value='<?php echo maybe_serialize( self::get_importer( $csv ) ); ?>'
295
+					<input type="hidden" value='<?php echo maybe_serialize(self::get_importer($csv)); ?>'
296 296
 					       name="main_key"
297 297
 					       class="main_key">
298 298
 				</th>
@@ -313,20 +313,20 @@  discard block
 block discarded – undo
313 313
 		 */
314 314
 		static function check_for_dropdown_or_import() {
315 315
 			$return = true;
316
-			if ( isset( $_REQUEST['mapto'] ) ) {
316
+			if (isset($_REQUEST['mapto'])) {
317 317
 				$mapto = (array) $_REQUEST['mapto'];
318
-				if ( false === in_array( 'form_title', $mapto ) && false === in_array( 'form_id', $mapto ) ) {
319
-					Give_Admin_Settings::add_error( 'give-import-csv-form', __( 'Please select Form ID or Form Name options from the dropdown.', 'give' ) );
318
+				if (false === in_array('form_title', $mapto) && false === in_array('form_id', $mapto)) {
319
+					Give_Admin_Settings::add_error('give-import-csv-form', __('Please select Form ID or Form Name options from the dropdown.', 'give'));
320 320
 					$return = false;
321 321
 				}
322 322
 
323
-				if ( false === in_array( 'amount', $mapto ) ) {
324
-					Give_Admin_Settings::add_error( 'give-import-csv-amount', __( 'Please select Amount option from the dropdown.', 'give' ) );
323
+				if (false === in_array('amount', $mapto)) {
324
+					Give_Admin_Settings::add_error('give-import-csv-amount', __('Please select Amount option from the dropdown.', 'give'));
325 325
 					$return = false;
326 326
 				}
327 327
 
328
-				if ( false === in_array( 'email', $mapto ) && false === in_array( 'donor_id', $mapto ) ) {
329
-					Give_Admin_Settings::add_error( 'give-import-csv-donor', __( 'Please select Email id or Customer ID options from the dropdown.', 'give' ) );
328
+				if (false === in_array('email', $mapto) && false === in_array('donor_id', $mapto)) {
329
+					Give_Admin_Settings::add_error('give-import-csv-donor', __('Please select Email id or Customer ID options from the dropdown.', 'give'));
330 330
 					$return = false;
331 331
 				}
332 332
 			} else {
@@ -345,8 +345,8 @@  discard block
 block discarded – undo
345 345
 			$csv = (int) $_GET['csv'];
346 346
 
347 347
 			// TO check if the CSV files that is being add is valid or not if not then redirect to first step again
348
-			$has_error = self::csv_check( $csv );
349
-			if ( $has_error ) {
348
+			$has_error = self::csv_check($csv);
349
+			if ($has_error) {
350 350
 				$url = give_import_page_url();
351 351
 				?>
352 352
 				<script type="text/javascript">
@@ -357,29 +357,29 @@  discard block
 block discarded – undo
357 357
 				?>
358 358
 				<tr valign="top" class="give-import-dropdown">
359 359
 					<th colspan="2">
360
-						<h2 id="give-import-title"><?php esc_html_e( 'Map CSV fields to donations', 'give' ) ?></h2>
361
-						<p class="give-field-description"><?php esc_html_e( 'Select fields from your CSV file to map against donations fields or to ignore during import.', 'give' ) ?></p>
360
+						<h2 id="give-import-title"><?php esc_html_e('Map CSV fields to donations', 'give') ?></h2>
361
+						<p class="give-field-description"><?php esc_html_e('Select fields from your CSV file to map against donations fields or to ignore during import.', 'give') ?></p>
362 362
 					</th>
363 363
 				</tr>
364 364
 
365 365
 				<tr valign="top" class="give-import-dropdown">
366
-					<th><b><?php esc_html_e( 'Column name', 'give' ); ?></b></th>
367
-					<th><b><?php esc_html_e( 'Map to field', 'give' ); ?></b></th>
366
+					<th><b><?php esc_html_e('Column name', 'give'); ?></b></th>
367
+					<th><b><?php esc_html_e('Map to field', 'give'); ?></b></th>
368 368
 				</tr>
369 369
 
370 370
 				<?php
371
-				$raw_key   = self::get_importer( $csv );
371
+				$raw_key   = self::get_importer($csv);
372 372
 				$donations = give_import_donations_options();
373 373
 				$donors    = give_import_donor_options();
374 374
 				$forms     = give_import_donation_form_options();
375 375
 
376
-				foreach ( $raw_key as $index => $value ) {
376
+				foreach ($raw_key as $index => $value) {
377 377
 					?>
378 378
 					<tr valign="top" class="give-import-option">
379 379
 						<th><?php echo $value; ?></th>
380 380
 						<th>
381 381
 							<?php
382
-							self::get_columns( $index, $donations, $donors, $forms, $value );
382
+							self::get_columns($index, $donations, $donors, $forms, $value);
383 383
 							?>
384 384
 						</th>
385 385
 					</tr>
@@ -388,11 +388,11 @@  discard block
 block discarded – undo
388 388
 			}
389 389
 		}
390 390
 
391
-		static function selected( $option_value, $value ) {
391
+		static function selected($option_value, $value) {
392 392
 			$selected = '';
393
-			if ( stristr( $value, $option_value ) ) {
393
+			if (stristr($value, $option_value)) {
394 394
 				$selected = 'selected';
395
-			} elseif ( strrpos( $value, '_' ) && stristr( $option_value, 'Import as Meta' ) ) {
395
+			} elseif (strrpos($value, '_') && stristr($option_value, 'Import as Meta')) {
396 396
 				$selected = 'selected';
397 397
 			}
398 398
 
@@ -404,13 +404,13 @@  discard block
 block discarded – undo
404 404
 		 *
405 405
 		 * @since 1.8.13
406 406
 		 */
407
-		static function get_columns( $index, $donations, $donors, $forms, $value = false ) {
407
+		static function get_columns($index, $donations, $donors, $forms, $value = false) {
408 408
 			$default = give_import_default_options();
409 409
 			?>
410 410
 			<select name="mapto[<?php echo $index; ?>]">
411 411
 				<?php
412
-				foreach ( $default as $option => $option_value ) {
413
-					$checked = self::selected( $option_value, $value );
412
+				foreach ($default as $option => $option_value) {
413
+					$checked = self::selected($option_value, $value);
414 414
 					?>
415 415
 					<option value="<?php echo $option; ?>" <?php echo $checked; ?> ><?php echo $option_value; ?></option>
416 416
 					<?php
@@ -418,8 +418,8 @@  discard block
 block discarded – undo
418 418
 				?>
419 419
 				<optgroup label="Donations">
420 420
 					<?php
421
-					foreach ( $donations as $option => $option_value ) {
422
-						$checked = self::selected( $option_value, $value );
421
+					foreach ($donations as $option => $option_value) {
422
+						$checked = self::selected($option_value, $value);
423 423
 						?>
424 424
 						<option value="<?php echo $option; ?>" <?php echo $checked; ?> ><?php echo $option_value; ?></option>
425 425
 						<?php
@@ -429,8 +429,8 @@  discard block
 block discarded – undo
429 429
 
430 430
 				<optgroup label="Donors">
431 431
 					<?php
432
-					foreach ( $donors as $option => $option_value ) {
433
-						$checked = self::selected( $option_value, $value );
432
+					foreach ($donors as $option => $option_value) {
433
+						$checked = self::selected($option_value, $value);
434 434
 						?>
435 435
 						<option value="<?php echo $option; ?>" <?php echo $checked; ?> ><?php echo $option_value; ?></option>
436 436
 						<?php
@@ -440,8 +440,8 @@  discard block
 block discarded – undo
440 440
 
441 441
 				<optgroup label="Forms">
442 442
 					<?php
443
-					foreach ( $forms as $option => $option_value ) {
444
-						$checked = self::selected( $option_value, $value );
443
+					foreach ($forms as $option => $option_value) {
444
+						$checked = self::selected($option_value, $value);
445 445
 						?>
446 446
 						<option value="<?php echo $option; ?>" <?php echo $checked; ?> ><?php echo $option_value; ?></option>
447 447
 						<?php
@@ -450,19 +450,19 @@  discard block
 block discarded – undo
450 450
 				</optgroup>
451 451
 
452 452
 				<?php
453
-				do_action( 'give_import_dropdown_option', $index, $donations, $donors, $forms, $value );
453
+				do_action('give_import_dropdown_option', $index, $donations, $donors, $forms, $value);
454 454
 				?>
455 455
 			</select>
456 456
 			<?php
457 457
 		}
458 458
 
459
-		static function get_csv_total( $file_id ) {
459
+		static function get_csv_total($file_id) {
460 460
 			$total = false;
461
-			if ( $file_id ) {
462
-				$file_dir = get_attached_file( $file_id );
463
-				if ( $file_dir ) {
464
-					$file = new SplFileObject( $file_dir, 'r' );
465
-					$file->seek( PHP_INT_MAX );
461
+			if ($file_id) {
462
+				$file_dir = get_attached_file($file_id);
463
+				if ($file_dir) {
464
+					$file = new SplFileObject($file_dir, 'r');
465
+					$file->seek(PHP_INT_MAX);
466 466
 					$total = $file->key() + 1;
467 467
 				}
468 468
 			}
@@ -481,15 +481,15 @@  discard block
 block discarded – undo
481 481
 		 *
482 482
 		 * @return array|bool $raw_data title of the CSV file fields
483 483
 		 */
484
-		static function get_importer( $file_id, $index = 0, $delimiter = ',' ) {
484
+		static function get_importer($file_id, $index = 0, $delimiter = ',') {
485 485
 			$raw_data = false;
486
-			$file_dir = get_attached_file( $file_id );
487
-			if ( $file_dir ) {
488
-				if ( false !== ( $handle = fopen( $file_dir, 'r' ) ) ) {
489
-					$raw_data = fgetcsv( $handle, $index, $delimiter );
486
+			$file_dir = get_attached_file($file_id);
487
+			if ($file_dir) {
488
+				if (false !== ($handle = fopen($file_dir, 'r'))) {
489
+					$raw_data = fgetcsv($handle, $index, $delimiter);
490 490
 					// Remove BOM signature from the first item.
491
-					if ( isset( $raw_data[0] ) ) {
492
-						$raw_data[0] = self::remove_utf8_bom( $raw_data[0] );
491
+					if (isset($raw_data[0])) {
492
+						$raw_data[0] = self::remove_utf8_bom($raw_data[0]);
493 493
 					}
494 494
 				}
495 495
 			}
@@ -506,9 +506,9 @@  discard block
 block discarded – undo
506 506
 		 *
507 507
 		 * @return string
508 508
 		 */
509
-		static function remove_utf8_bom( $string ) {
510
-			if ( 'efbbbf' === substr( bin2hex( $string ), 0, 6 ) ) {
511
-				$string = substr( $string, 3 );
509
+		static function remove_utf8_bom($string) {
510
+			if ('efbbbf' === substr(bin2hex($string), 0, 6)) {
511
+				$string = substr($string, 3);
512 512
 			}
513 513
 
514 514
 			return $string;
@@ -524,10 +524,10 @@  discard block
 block discarded – undo
524 524
 			$step = Give_Settings_Import::get_step();
525 525
 			?>
526 526
 			<ol class="give-progress-steps">
527
-				<li class="<?php echo( 1 === $step ? 'active' : '' ); ?>"><?php esc_html_e( 'Upload CSV file', 'give' ); ?></li>
528
-				<li class="<?php echo( 2 === $step ? 'active' : '' ); ?>"><?php esc_html_e( 'Column mapping', 'give' ); ?></li>
529
-				<li class="<?php echo( 3 === $step ? 'active' : '' ); ?>"><?php esc_html_e( 'Import', 'give' ); ?></li>
530
-				<li class="<?php echo( 4 === $step ? 'active' : '' ); ?>"><?php esc_html_e( 'Done!', 'give' ); ?></li>
527
+				<li class="<?php echo(1 === $step ? 'active' : ''); ?>"><?php esc_html_e('Upload CSV file', 'give'); ?></li>
528
+				<li class="<?php echo(2 === $step ? 'active' : ''); ?>"><?php esc_html_e('Column mapping', 'give'); ?></li>
529
+				<li class="<?php echo(3 === $step ? 'active' : ''); ?>"><?php esc_html_e('Import', 'give'); ?></li>
530
+				<li class="<?php echo(4 === $step ? 'active' : ''); ?>"><?php esc_html_e('Done!', 'give'); ?></li>
531 531
 			</ol>
532 532
 			<?php
533 533
 		}
@@ -540,15 +540,15 @@  discard block
 block discarded – undo
540 540
 		 * @return int $step on which step doest the import is on.
541 541
 		 */
542 542
 		static function get_step() {
543
-			$step    = (int) ( isset( $_REQUEST['step'] ) ? give_clean( $_REQUEST['step'] ) : 0 );
543
+			$step    = (int) (isset($_REQUEST['step']) ? give_clean($_REQUEST['step']) : 0);
544 544
 			$on_step = 1;
545
-			if ( empty( $step ) || 1 === $step ) {
545
+			if (empty($step) || 1 === $step) {
546 546
 				$on_step = 1;
547
-			} elseif ( self::check_for_dropdown_or_import() ) {
547
+			} elseif (self::check_for_dropdown_or_import()) {
548 548
 				$on_step = 3;
549
-			} elseif ( 2 === $step ) {
549
+			} elseif (2 === $step) {
550 550
 				$on_step = 2;
551
-			} elseif ( 4 === $step ) {
551
+			} elseif (4 === $step) {
552 552
 				$on_step = 4;
553 553
 			}
554 554
 
@@ -566,56 +566,56 @@  discard block
 block discarded – undo
566 566
 			?>
567 567
 			<tr valign="top">
568 568
 				<th colspan="2">
569
-					<h2 id="give-import-title"><?php esc_html_e( 'Import donations from a CSV file', 'give' ) ?></h2>
570
-					<p class="give-field-description"><?php esc_html_e( 'This tool allows you to import (or merge) donation data to give from a CSV file.', 'give' ) ?></p>
569
+					<h2 id="give-import-title"><?php esc_html_e('Import donations from a CSV file', 'give') ?></h2>
570
+					<p class="give-field-description"><?php esc_html_e('This tool allows you to import (or merge) donation data to give from a CSV file.', 'give') ?></p>
571 571
 				</th>
572 572
 			</tr>
573 573
 			<?php
574
-			$csv         = ( isset( $_REQUEST['csv'] ) ? give_clean( $_POST['csv'] ) : '' );
575
-			$delimiter   = ( isset( $_REQUEST['delimiter'] ) ? give_clean( $_POST['delimiter'] ) : ',' );
576
-			$mode        = ( ! empty( $_REQUEST['mode'] ) ? 'on' : '' );
577
-			$create_user = ( isset( $_REQUEST['create_user'] ) && isset( $_REQUEST['csv'] ) && 1 == absint( $_REQUEST['create_user'] ) ? 'on' : ( isset( $_REQUEST['csv'] ) ? '' : 'on' ) );
578
-			$delete_csv = ( isset( $_REQUEST['delete_csv'] ) && isset( $_REQUEST['csv'] ) && 1 == absint( $_REQUEST['delete_csv'] ) ? 'on' : ( isset( $_REQUEST['csv'] ) ? '' : 'on' ) );
574
+			$csv         = (isset($_REQUEST['csv']) ? give_clean($_POST['csv']) : '');
575
+			$delimiter   = (isset($_REQUEST['delimiter']) ? give_clean($_POST['delimiter']) : ',');
576
+			$mode        = ( ! empty($_REQUEST['mode']) ? 'on' : '');
577
+			$create_user = (isset($_REQUEST['create_user']) && isset($_REQUEST['csv']) && 1 == absint($_REQUEST['create_user']) ? 'on' : (isset($_REQUEST['csv']) ? '' : 'on'));
578
+			$delete_csv = (isset($_REQUEST['delete_csv']) && isset($_REQUEST['csv']) && 1 == absint($_REQUEST['delete_csv']) ? 'on' : (isset($_REQUEST['csv']) ? '' : 'on'));
579 579
 
580 580
 			$settings = array(
581 581
 				array(
582 582
 					'id'         => 'csv',
583
-					'name'       => __( 'Choose a CSV file:', 'give' ),
583
+					'name'       => __('Choose a CSV file:', 'give'),
584 584
 					'type'       => 'file',
585
-					'attributes' => array( 'editing' => 'false', 'library' => 'text' ),
585
+					'attributes' => array('editing' => 'false', 'library' => 'text'),
586 586
 					'fvalue'     => 'id',
587 587
 					'default'    => $csv,
588 588
 				),
589 589
 				array(
590 590
 					'id'         => 'delimiter',
591
-					'name'       => __( 'CSV Delimiter:', 'give' ),
591
+					'name'       => __('CSV Delimiter:', 'give'),
592 592
 					'type'       => 'text',
593
-					'attributes' => array( 'placeholder' => ',', 'size' => '2' ),
593
+					'attributes' => array('placeholder' => ',', 'size' => '2'),
594 594
 					'default'    => $delimiter,
595 595
 				),
596 596
 				array(
597 597
 					'id'      => 'mode',
598
-					'name'    => __( 'Test Mode:', 'give' ),
598
+					'name'    => __('Test Mode:', 'give'),
599 599
 					'type'    => 'checkbox',
600 600
 					'default' => $mode,
601 601
 				),
602 602
 				array(
603 603
 					'id'      => 'create_user',
604
-					'name'    => __( 'Create WP users for new donors?:', 'give' ),
604
+					'name'    => __('Create WP users for new donors?:', 'give'),
605 605
 					'type'    => 'checkbox',
606 606
 					'default' => $create_user,
607 607
 				),
608 608
 				array(
609 609
 					'id'      => 'delete_csv',
610
-					'name'    => __( 'Delete CSV after import:', 'give' ),
610
+					'name'    => __('Delete CSV after import:', 'give'),
611 611
 					'type'    => 'checkbox',
612 612
 					'default' => $delete_csv,
613 613
 				),
614 614
 			);
615 615
 
616
-			$settings = apply_filters( 'give_import_file_upload_html', $settings );
616
+			$settings = apply_filters('give_import_file_upload_html', $settings);
617 617
 
618
-			Give_Admin_Settings::output_fields( $settings, 'give_settings' );
618
+			Give_Admin_Settings::output_fields($settings, 'give_settings');
619 619
 		}
620 620
 
621 621
 		/**
@@ -628,21 +628,21 @@  discard block
 block discarded – undo
628 628
 			$step = Give_Settings_Import::get_step();
629 629
 
630 630
 			// Validation for first step.
631
-			if ( 1 === $step ) {
632
-				$csv = absint( $_POST['csv'] );
631
+			if (1 === $step) {
632
+				$csv = absint($_POST['csv']);
633 633
 
634
-				$has_error = self::csv_check( $csv );
634
+				$has_error = self::csv_check($csv);
635 635
 
636
-				if ( false == $has_error ) {
636
+				if (false == $has_error) {
637 637
 
638
-					$url = give_import_page_url( (array) apply_filters( 'give_import_step_two_url', array(
638
+					$url = give_import_page_url((array) apply_filters('give_import_step_two_url', array(
639 639
 						'step'        => '2',
640 640
 						'csv'         => $csv,
641
-						'delimiter'   => ( isset( $_REQUEST['delimiter'] ) ) ? give_clean( $_REQUEST['delimiter'] ) : ',',
642
-						'mode'        => ( isset( $_REQUEST['mode'] ) ) ? give_clean( $_REQUEST['mode'] ) : '0',
643
-						'create_user' => ( isset( $_REQUEST['create_user'] ) ) ? give_clean( $_REQUEST['create_user'] ) : '0',
644
-						'delete_csv'  => ( isset( $_REQUEST['delete_csv'] ) ) ? give_clean( $_REQUEST['delete_csv'] ) : '0',
645
-					) ) );
641
+						'delimiter'   => (isset($_REQUEST['delimiter'])) ? give_clean($_REQUEST['delimiter']) : ',',
642
+						'mode'        => (isset($_REQUEST['mode'])) ? give_clean($_REQUEST['mode']) : '0',
643
+						'create_user' => (isset($_REQUEST['create_user'])) ? give_clean($_REQUEST['create_user']) : '0',
644
+						'delete_csv'  => (isset($_REQUEST['delete_csv'])) ? give_clean($_REQUEST['delete_csv']) : '0',
645
+					)));
646 646
 					?>
647 647
 					<script type="text/javascript">
648 648
 						window.location = "<?php echo $url; ?>"
@@ -661,19 +661,19 @@  discard block
 block discarded – undo
661 661
 		 *
662 662
 		 * return bool $has_error CSV is valid or not.
663 663
 		 */
664
-		static function csv_check( $csv = false ) {
664
+		static function csv_check($csv = false) {
665 665
 			$has_error = false;
666
-			if ( $csv ) {
667
-				if ( ! wp_get_attachment_url( $csv ) ) {
666
+			if ($csv) {
667
+				if ( ! wp_get_attachment_url($csv)) {
668 668
 					$has_error = true;
669
-					Give_Admin_Settings::add_error( 'give-import-csv', __( 'Please upload or provide the ID to a valid CSV file.', 'give' ) );
670
-				} elseif ( ( $mime_type = get_post_mime_type( $csv ) ) && ! strpos( $mime_type, 'csv' ) ) {
669
+					Give_Admin_Settings::add_error('give-import-csv', __('Please upload or provide the ID to a valid CSV file.', 'give'));
670
+				} elseif (($mime_type = get_post_mime_type($csv)) && ! strpos($mime_type, 'csv')) {
671 671
 					$has_error = true;
672
-					Give_Admin_Settings::add_error( 'give-import-csv', __( 'Please upload or provide the ID to a valid CSV file.', 'give' ) );
672
+					Give_Admin_Settings::add_error('give-import-csv', __('Please upload or provide the ID to a valid CSV file.', 'give'));
673 673
 				}
674 674
 			} else {
675 675
 				$has_error = true;
676
-				Give_Admin_Settings::add_error( 'give-import-csv', __( 'Please upload or provide the ID to a valid CSV file.', 'give' ) );
676
+				Give_Admin_Settings::add_error('give-import-csv', __('Please upload or provide the ID to a valid CSV file.', 'give'));
677 677
 			}
678 678
 
679 679
 			return $has_error;
@@ -688,8 +688,8 @@  discard block
 block discarded – undo
688 688
 		 *
689 689
 		 * @return array
690 690
 		 */
691
-		public function add_settings_page( $pages ) {
692
-			$pages[ $this->id ] = $this->label;
691
+		public function add_settings_page($pages) {
692
+			$pages[$this->id] = $this->label;
693 693
 
694 694
 			return $pages;
695 695
 		}
@@ -712,11 +712,11 @@  discard block
 block discarded – undo
712 712
 			 * @param  array $settings
713 713
 			 */
714 714
 			$settings = apply_filters(
715
-				'give_get_settings_' . $this->id,
715
+				'give_get_settings_'.$this->id,
716 716
 				array(
717 717
 					array(
718 718
 						'id'   => 'import',
719
-						'name' => __( 'Import Donations', 'give' ),
719
+						'name' => __('Import Donations', 'give'),
720 720
 						'type' => 'tools_import',
721 721
 					),
722 722
 				)
@@ -734,7 +734,7 @@  discard block
 block discarded – undo
734 734
 		 */
735 735
 		public function output() {
736 736
 			$settings = $this->get_settings();
737
-			Give_Admin_Settings::output_fields( $settings, 'give_settings' );
737
+			Give_Admin_Settings::output_fields($settings, 'give_settings');
738 738
 		}
739 739
 
740 740
 		/**
@@ -746,8 +746,8 @@  discard block
 block discarded – undo
746 746
 		 * @param $field
747 747
 		 * @param $option_value
748 748
 		 */
749
-		public function render_import_field( $field, $option_value ) {
750
-			include_once( 'views/html-admin-page-imports.php' );
749
+		public function render_import_field($field, $option_value) {
750
+			include_once('views/html-admin-page-imports.php');
751 751
 		}
752 752
 	}
753 753
 }
Please login to merge, or discard this patch.
includes/admin/tools/data/class-give-tools-delete-import-donors.php 2 patches
Doc Comments   +4 added lines, -1 removed lines patch added patch discarded remove patch
@@ -216,7 +216,7 @@  discard block
 block discarded – undo
216 216
 	 * Return the calculated completion percentage.
217 217
 	 *
218 218
 	 * @since 1.8.12
219
-	 * @return int
219
+	 * @return double
220 220
 	 */
221 221
 	public function get_percentage_complete() {
222 222
 		return ceil( ( 100 * $this->step_completed ) / $this->total_step );
@@ -353,6 +353,9 @@  discard block
 block discarded – undo
353 353
 		return true;
354 354
 	}
355 355
 
356
+	/**
357
+	 * @param integer $page
358
+	 */
356 359
 	public function get_delete_ids( $donation_ids, $page ) {
357 360
 		$index            = $page --;
358 361
 		$count            = count( $donation_ids );
Please login to merge, or discard this patch.
Spacing   +111 added lines, -111 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
 
@@ -116,34 +116,34 @@  discard block
 block discarded – undo
116 116
 		$donor_ids    = array();
117 117
 
118 118
 		// Check if the ajax request if running for the first time.
119
-		if ( 1 === (int) $this->step ) {
119
+		if (1 === (int) $this->step) {
120 120
 			// Delete all the form ids.
121
-			$this->delete_option( $this->form_key );
121
+			$this->delete_option($this->form_key);
122 122
 			// Delete all the donation ids.
123
-			$this->delete_option( $this->donation_key );
123
+			$this->delete_option($this->donation_key);
124 124
 			// Delete all the donor ids.
125
-			$this->delete_option( $this->donor_key );
125
+			$this->delete_option($this->donor_key);
126 126
 
127 127
 			// Delete all the step and set to 'count' which if the first step in the process of deleting the donors.
128
-			$this->update_option( $this->step_key, 'count' );
128
+			$this->update_option($this->step_key, 'count');
129 129
 
130 130
 			// Delete tha page count of the step.
131
-			$this->update_option( $this->step_on_key, '0' );
131
+			$this->update_option($this->step_on_key, '0');
132 132
 		} else {
133 133
 			// Get the old donors list.
134
-			$donor_ids = $this->get_option( $this->donor_key );
134
+			$donor_ids = $this->get_option($this->donor_key);
135 135
 
136 136
 			// Get the old donation list.
137
-			$donation_ids = $this->get_option( $this->donation_key );
137
+			$donation_ids = $this->get_option($this->donation_key);
138 138
 		}
139 139
 
140 140
 		// Get the step and check for it if it's on the first step( 'count' ) or not.
141 141
 		$step = (int) $this->get_step();
142
-		if ( 1 === $step ) {
142
+		if (1 === $step) {
143 143
 			/**
144 144
 			 * Will add or update the donation and donor data by running wp query.
145 145
 			 */
146
-			$this->count( $step, $donation_ids, $donor_ids );
146
+			$this->count($step, $donation_ids, $donor_ids);
147 147
 		}
148 148
 	}
149 149
 
@@ -154,17 +154,17 @@  discard block
 block discarded – undo
154 154
 	 * @param array $donation_ids Contain the list of all the donation id's that has being add before this
155 155
 	 * @param array $donor_ids Contain the list of all the donors id's that has being add before this
156 156
 	 */
157
-	private function count( $step, $donation_ids = array(), $donor_ids = array() ) {
157
+	private function count($step, $donation_ids = array(), $donor_ids = array()) {
158 158
 
159 159
 		// Get the Page count by default it's zero.
160 160
 		$paged = (int) $this->get_step_page();
161 161
 		// Incresed the page count by one.
162
-		++ $paged;
162
+		++$paged;
163 163
 
164 164
 		/**
165 165
 		 * Filter add to alter the argument before the wp quest run
166 166
 		 */
167
-		$args = apply_filters( 'give_tools_reset_stats_total_args', array(
167
+		$args = apply_filters('give_tools_reset_stats_total_args', array(
168 168
 			'post_type'      => 'give_payment',
169 169
 			'post_status'    => 'any',
170 170
 			'posts_per_page' => $this->per_step,
@@ -172,40 +172,40 @@  discard block
 block discarded – undo
172 172
 			'meta_key'       => '_give_payment_import',
173 173
 			'meta_value_num' => 1,
174 174
 			'meta_compare'   => '=',
175
-		) );
175
+		));
176 176
 
177 177
 		// Reset the post data.
178 178
 		wp_reset_postdata();
179 179
 		// Getting the new donation.
180
-		$donation_posts = new WP_Query( $args );
180
+		$donation_posts = new WP_Query($args);
181 181
 
182 182
 		// The Loop.
183
-		if ( $donation_posts->have_posts() ) {
184
-			while ( $donation_posts->have_posts() ) {
183
+		if ($donation_posts->have_posts()) {
184
+			while ($donation_posts->have_posts()) {
185 185
 				$add_author = true;
186 186
 				$donation_posts->the_post();
187 187
 				global $post;
188 188
 				// Add the donation id in side the array.
189 189
 				$donation_ids[] = $post->ID;
190 190
 
191
-				$donor_id = (int) get_post_meta( $post->ID, '_give_payment_customer_id', true );
192
-				if ( ! empty( $donor_id ) ) {
193
-					$donor = new Give_Donor( $donor_id );
194
-					if ( ! empty( $donor->id ) ) {
195
-						if ( empty( $donor->user_id ) && ! empty( $donor->payment_ids ) ) {
191
+				$donor_id = (int) get_post_meta($post->ID, '_give_payment_customer_id', true);
192
+				if ( ! empty($donor_id)) {
193
+					$donor = new Give_Donor($donor_id);
194
+					if ( ! empty($donor->id)) {
195
+						if (empty($donor->user_id) && ! empty($donor->payment_ids)) {
196 196
 							$add_author = false;
197
-							$count      = (int) count( $donor->payment_ids );
198
-							if ( 1 === $count ) {
199
-								Give()->donors->delete( $donor->id );
197
+							$count      = (int) count($donor->payment_ids);
198
+							if (1 === $count) {
199
+								Give()->donors->delete($donor->id);
200 200
 							} else {
201
-								$donor->remove_payment( $post->ID );
201
+								$donor->remove_payment($post->ID);
202 202
 								$donor->decrease_donation_count();
203 203
 							}
204 204
 						}
205 205
 					}
206 206
 				}
207 207
 
208
-				if ( ! empty( $add_author ) ) {
208
+				if ( ! empty($add_author)) {
209 209
 					// Add the donor id in side the array.
210 210
 					$donor_ids[] = (int) $post->post_author;
211 211
 				}
@@ -220,23 +220,23 @@  discard block
 block discarded – undo
220 220
 		$max_num_pages = (int) $donation_posts->max_num_pages;
221 221
 
222 222
 		// Check current page is less then max number of page or not
223
-		if ( $paged < $max_num_pages ) {
223
+		if ($paged < $max_num_pages) {
224 224
 			// Update the curretn page virable for the next step
225
-			$this->update_option( $this->step_on_key, $paged );
225
+			$this->update_option($this->step_on_key, $paged);
226 226
 
227 227
 			// Calculating percentage.
228 228
 			$page_remain          = $max_num_pages - $paged;
229
-			$this->total_step     = (int) $max_num_pages + ( $total_donation / $this->per_step ) + ( ( $page_remain * 2 ) * count( $donor_ids ) );
229
+			$this->total_step     = (int) $max_num_pages + ($total_donation / $this->per_step) + (($page_remain * 2) * count($donor_ids));
230 230
 			$this->step_completed = $paged;
231 231
 		} else {
232
-			$donation_ids_count = count( $donor_ids );
233
-			$this->update_option( $this->step_key, 'donation' );
234
-			$this->update_option( $this->step_on_key, '0' );
232
+			$donation_ids_count = count($donor_ids);
233
+			$this->update_option($this->step_key, 'donation');
234
+			$this->update_option($this->step_on_key, '0');
235 235
 		}
236 236
 
237
-		$donor_ids = array_unique( $donor_ids );
238
-		$this->update_option( $this->donor_key, $donor_ids );
239
-		$this->update_option( $this->donation_key, $donation_ids );
237
+		$donor_ids = array_unique($donor_ids);
238
+		$this->update_option($this->donor_key, $donor_ids);
239
+		$this->update_option($this->donation_key, $donation_ids);
240 240
 
241 241
 		wp_reset_postdata();
242 242
 	}
@@ -248,34 +248,34 @@  discard block
 block discarded – undo
248 248
 	 * @return int
249 249
 	 */
250 250
 	public function get_percentage_complete() {
251
-		return ceil( ( 100 * $this->step_completed ) / $this->total_step );
251
+		return ceil((100 * $this->step_completed) / $this->total_step);
252 252
 	}
253 253
 
254 254
 	public function process_step() {
255 255
 
256
-		if ( ! $this->can_export() ) {
257
-			wp_die( __( 'You do not have permission to delete Import transactions.', 'give' ), __( 'Error', 'give' ), array( 'response' => 403 ) );
256
+		if ( ! $this->can_export()) {
257
+			wp_die(__('You do not have permission to delete Import transactions.', 'give'), __('Error', 'give'), array('response' => 403));
258 258
 		}
259 259
 
260 260
 		$had_data = $this->get_data();
261 261
 
262
-		if ( $had_data ) {
262
+		if ($had_data) {
263 263
 			$this->done = false;
264 264
 
265 265
 			return true;
266 266
 		} else {
267
-			update_option( 'give_earnings_total', give_get_total_earnings( true ) );
268
-			Give_Cache::delete( Give_Cache::get_key( 'give_estimated_monthly_stats' ) );
267
+			update_option('give_earnings_total', give_get_total_earnings(true));
268
+			Give_Cache::delete(Give_Cache::get_key('give_estimated_monthly_stats'));
269 269
 
270
-			$this->delete_option( $this->donation_key );
270
+			$this->delete_option($this->donation_key);
271 271
 
272 272
 			// Reset the sequential order numbers
273
-			if ( give_get_option( 'enable_sequential' ) ) {
274
-				delete_option( 'give_last_payment_number' );
273
+			if (give_get_option('enable_sequential')) {
274
+				delete_option('give_last_payment_number');
275 275
 			}
276 276
 
277 277
 			$this->done    = true;
278
-			$this->message = __( 'Imported donor and transactions successfully deleted.', 'give' );
278
+			$this->message = __('Imported donor and transactions successfully deleted.', 'give');
279 279
 
280 280
 			return false;
281 281
 		}
@@ -293,12 +293,12 @@  discard block
 block discarded – undo
293 293
 	public function get_data() {
294 294
 
295 295
 		// Get the donation id's.
296
-		$donation_ids = $this->get_option( $this->donation_key );
296
+		$donation_ids = $this->get_option($this->donation_key);
297 297
 
298 298
 		/**
299 299
 		 * Return false id not Import donation is found.
300 300
 		 */
301
-		if ( empty( $donation_ids ) ) {
301
+		if (empty($donation_ids)) {
302 302
 			$this->is_empty   = true;
303 303
 			$this->total_step = 1;
304 304
 
@@ -309,97 +309,97 @@  discard block
 block discarded – undo
309 309
 		$step = (int) $this->get_step();
310 310
 
311 311
 		// get teh donor ids.
312
-		$donor_ids = $this->get_option( $this->donor_key );
312
+		$donor_ids = $this->get_option($this->donor_key);
313 313
 
314 314
 		// In step to we delete all the donation in loop.
315
-		if ( 2 === $step ) {
315
+		if (2 === $step) {
316 316
 			$pass_to_donor = false;
317 317
 			$page          = (int) $this->get_step_page();
318
-			$page ++;
319
-			$count = count( $donation_ids );
318
+			$page++;
319
+			$count = count($donation_ids);
320 320
 
321
-			$this->total_step     = ( ( count( $donation_ids ) / $this->per_step ) * 2 ) + count( $donor_ids );
321
+			$this->total_step     = ((count($donation_ids) / $this->per_step) * 2) + count($donor_ids);
322 322
 			$this->step_completed = $page;
323 323
 
324 324
 
325
-			if ( $count > $this->per_step ) {
325
+			if ($count > $this->per_step) {
326 326
 
327
-				$this->update_option( $this->step_on_key, $page );
328
-				$donation_ids = $this->get_delete_ids( $donation_ids, $page );
329
-				$current_page = (int) ceil( $count / $this->per_step );
327
+				$this->update_option($this->step_on_key, $page);
328
+				$donation_ids = $this->get_delete_ids($donation_ids, $page);
329
+				$current_page = (int) ceil($count / $this->per_step);
330 330
 
331
-				if ( $page === $current_page ) {
331
+				if ($page === $current_page) {
332 332
 					$pass_to_donor = true;
333 333
 				}
334 334
 			} else {
335 335
 				$pass_to_donor = true;
336 336
 			}
337 337
 
338
-			if ( true === $pass_to_donor ) {
339
-				$this->update_option( $this->step_key, 'donor' );
340
-				$this->update_option( $this->step_on_key, '0' );
338
+			if (true === $pass_to_donor) {
339
+				$this->update_option($this->step_key, 'donor');
340
+				$this->update_option($this->step_on_key, '0');
341 341
 			}
342 342
 
343 343
 			// Get the old form list.
344
-			$form_ids = (array) $this->get_option( $this->form_key );
344
+			$form_ids = (array) $this->get_option($this->form_key);
345 345
 
346
-			foreach ( $donation_ids as $item ) {
347
-				$form_ids[] = get_post_meta( $item, '_give_payment_form_id', true );
348
-				wp_delete_post( $item, true );
346
+			foreach ($donation_ids as $item) {
347
+				$form_ids[] = get_post_meta($item, '_give_payment_form_id', true);
348
+				wp_delete_post($item, true);
349 349
 			}
350 350
 
351 351
 			// update the new form list.
352
-			$this->update_option( $this->form_key, $form_ids );
352
+			$this->update_option($this->form_key, $form_ids);
353 353
 		}
354 354
 
355 355
 
356 356
 		// Here we delete all the donor
357
-		if ( 3 === $step ) {
357
+		if (3 === $step) {
358 358
 
359 359
 			// Get the old form list.
360
-			$form_ids = (array) $this->get_option( $this->form_key );
361
-			if ( ! empty( $form_ids ) ) {
362
-				$form_ids = array_unique( $form_ids );
363
-				foreach ( $form_ids as $form_id ) {
364
-					give_recount_form_income_donation( (int) $form_id );
360
+			$form_ids = (array) $this->get_option($this->form_key);
361
+			if ( ! empty($form_ids)) {
362
+				$form_ids = array_unique($form_ids);
363
+				foreach ($form_ids as $form_id) {
364
+					give_recount_form_income_donation((int) $form_id);
365 365
 				}
366 366
 			}
367 367
 			// update the new form list.
368
-			$this->update_option( $this->form_key, array() );
368
+			$this->update_option($this->form_key, array());
369 369
 
370 370
 			$page  = (int) $this->get_step_page();
371
-			$count = count( $donor_ids );
371
+			$count = count($donor_ids);
372 372
 
373
-			$this->total_step     = ( ( count( $donation_ids ) / $this->per_step ) * 2 ) + count( $donor_ids );
374
-			$this->step_completed = $page + ( count( $donation_ids ) / $this->per_step );
373
+			$this->total_step     = ((count($donation_ids) / $this->per_step) * 2) + count($donor_ids);
374
+			$this->step_completed = $page + (count($donation_ids) / $this->per_step);
375 375
 
376
-			$args = apply_filters( 'give_tools_reset_stats_total_args', array(
376
+			$args = apply_filters('give_tools_reset_stats_total_args', array(
377 377
 				'post_status'    => 'any',
378 378
 				'posts_per_page' => 1,
379
-				'author'         => $donor_ids[ $page ]
380
-			) );
379
+				'author'         => $donor_ids[$page]
380
+			));
381 381
 
382 382
 			$donations = array();
383
-			$payments = new Give_Payments_Query( $args );
383
+			$payments = new Give_Payments_Query($args);
384 384
 			$payments = $payments->get_payments();
385
-			if ( empty( $payments ) ) {
386
-				Give()->donors->delete_by_user_id( $donor_ids[ $page ] );
385
+			if (empty($payments)) {
386
+				Give()->donors->delete_by_user_id($donor_ids[$page]);
387 387
 			} else {
388
-				foreach ( $payments as $payment ) {
388
+				foreach ($payments as $payment) {
389 389
 					$donations[] = $payment->ID;
390 390
 				}
391 391
 
392
-				$donor          = new Give_Donor( $donor_ids[ $page ], true );
392
+				$donor          = new Give_Donor($donor_ids[$page], true);
393 393
 				$data_to_update = array(
394
-					'purchase_count' => count( $donations ),
395
-					'payment_ids'    => implode( ',', $donations ),
394
+					'purchase_count' => count($donations),
395
+					'payment_ids'    => implode(',', $donations),
396 396
 				);
397
-				$donor->update( $data_to_update );
397
+				$donor->update($data_to_update);
398 398
 			}
399 399
 
400
-			$page ++;
401
-			$this->update_option( $this->step_on_key, $page );
402
-			if ( $count === $page ) {
400
+			$page++;
401
+			$this->update_option($this->step_on_key, $page);
402
+			if ($count === $page) {
403 403
 				$this->is_empty = false;
404 404
 
405 405
 				return false;
@@ -411,24 +411,24 @@  discard block
 block discarded – undo
411 411
 		return true;
412 412
 	}
413 413
 
414
-	public function get_delete_ids( $donation_ids, $page ) {
415
-		$index            = $page --;
416
-		$count            = count( $donation_ids );
414
+	public function get_delete_ids($donation_ids, $page) {
415
+		$index            = $page--;
416
+		$count            = count($donation_ids);
417 417
 		$temp             = 0;
418 418
 		$current_page     = 0;
419 419
 		$post_delete      = $this->per_step;
420 420
 		$page_donation_id = array();
421 421
 
422
-		foreach ( $donation_ids as $item ) {
423
-			$temp ++;
424
-			$page_donation_id[ $current_page ][] = $item;
425
-			if ( $temp === $post_delete ) {
426
-				$current_page ++;
422
+		foreach ($donation_ids as $item) {
423
+			$temp++;
424
+			$page_donation_id[$current_page][] = $item;
425
+			if ($temp === $post_delete) {
426
+				$current_page++;
427 427
 				$temp = 0;
428 428
 			}
429 429
 		}
430 430
 
431
-		return $page_donation_id[ $page ];
431
+		return $page_donation_id[$page];
432 432
 	}
433 433
 
434 434
 	/**
@@ -440,8 +440,8 @@  discard block
 block discarded – undo
440 440
 	 *
441 441
 	 * @return mixed       Returns the data from the database
442 442
 	 */
443
-	public function get_option( $key, $defalut_value = false ) {
444
-		return get_option( $key, $defalut_value );
443
+	public function get_option($key, $defalut_value = false) {
444
+		return get_option($key, $defalut_value);
445 445
 	}
446 446
 
447 447
 	/**
@@ -454,8 +454,8 @@  discard block
 block discarded – undo
454 454
 	 *
455 455
 	 * @return void
456 456
 	 */
457
-	public function update_option( $key, $value ) {
458
-		update_option( $key, $value, false );
457
+	public function update_option($key, $value) {
458
+		update_option($key, $value, false);
459 459
 	}
460 460
 
461 461
 	/**
@@ -467,8 +467,8 @@  discard block
 block discarded – undo
467 467
 	 *
468 468
 	 * @return void
469 469
 	 */
470
-	public function delete_option( $key ) {
471
-		delete_option( $key );
470
+	public function delete_option($key) {
471
+		delete_option($key);
472 472
 	}
473 473
 
474 474
 	/**
@@ -479,12 +479,12 @@  discard block
 block discarded – undo
479 479
 	 * @return int|string
480 480
 	 */
481 481
 	private function get_step() {
482
-		$step_key = (string) $this->get_option( $this->step_key, false );
483
-		if ( 'count' === $step_key ) {
482
+		$step_key = (string) $this->get_option($this->step_key, false);
483
+		if ('count' === $step_key) {
484 484
 			return 1;
485
-		} elseif ( 'donation' === $step_key ) {
485
+		} elseif ('donation' === $step_key) {
486 486
 			return 2;
487
-		} elseif ( 'donor' === $step_key ) {
487
+		} elseif ('donor' === $step_key) {
488 488
 			return 3;
489 489
 		} else {
490 490
 			return $step_key;
@@ -495,6 +495,6 @@  discard block
 block discarded – undo
495 495
 	 * Get the current $page value in the ajax.
496 496
 	 */
497 497
 	private function get_step_page() {
498
-		return $this->get_option( $this->step_on_key, false );
498
+		return $this->get_option($this->step_on_key, false);
499 499
 	}
500 500
 }
Please login to merge, or discard this patch.
includes/class-give-db-donors.php 2 patches
Doc Comments   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -164,7 +164,7 @@  discard block
 block discarded – undo
164 164
 	 * @since  1.0
165 165
 	 * @access public
166 166
 	 *
167
-	 * @param  bool|string|int $_id_or_email
167
+	 * @param  integer $_id_or_email
168 168
 	 *
169 169
 	 * @return bool|int
170 170
 	 */
@@ -359,7 +359,7 @@  discard block
 block discarded – undo
359 359
 	 * @param  int $user_id User ID.
360 360
 	 * @param  WP_User|bool $old_user_data User data.
361 361
 	 *
362
-	 * @return bool
362
+	 * @return false|null
363 363
 	 */
364 364
 	public function update_donor_email_on_user_update( $user_id = 0, $old_user_data = false ) {
365 365
 
@@ -416,7 +416,7 @@  discard block
 block discarded – undo
416 416
 	 * @access public
417 417
 	 *
418 418
 	 * @param  string $field ID or email. Default is 'id'.
419
-	 * @param  mixed $value The Customer ID or email to search. Default is 0.
419
+	 * @param  integer $value The Customer ID or email to search. Default is 0.
420 420
 	 *
421 421
 	 * @return mixed         Upon success, an object of the donor. Upon failure, NULL
422 422
 	 */
Please login to merge, or discard this patch.
Spacing   +141 added lines, -141 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
 
@@ -34,14 +34,14 @@  discard block
 block discarded – undo
34 34
 		/* @var WPDB $wpdb */
35 35
 		global $wpdb;
36 36
 
37
-		$this->table_name  = $wpdb->prefix . 'give_customers';
37
+		$this->table_name  = $wpdb->prefix.'give_customers';
38 38
 		$this->primary_key = 'id';
39 39
 		$this->version     = '1.0';
40 40
 
41 41
 		// Set hooks and register table only if instance loading first time.
42
-		if ( ! ( Give()->donors instanceof Give_DB_Donors ) ) {
42
+		if ( ! (Give()->donors instanceof Give_DB_Donors)) {
43 43
 			// Setup hook.
44
-			add_action( 'profile_update', array( $this, 'update_donor_email_on_user_update' ), 10, 2 );
44
+			add_action('profile_update', array($this, 'update_donor_email_on_user_update'), 10, 2);
45 45
 
46 46
 			// Install table.
47 47
 			$this->register_table();
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
 			'purchase_value' => 0.00,
89 89
 			'purchase_count' => 0,
90 90
 			'notes'          => '',
91
-			'date_created'   => date( 'Y-m-d H:i:s' ),
91
+			'date_created'   => date('Y-m-d H:i:s'),
92 92
 		);
93 93
 	}
94 94
 
@@ -102,40 +102,40 @@  discard block
 block discarded – undo
102 102
 	 *
103 103
 	 * @return int|bool
104 104
 	 */
105
-	public function add( $data = array() ) {
105
+	public function add($data = array()) {
106 106
 
107 107
 		$defaults = array(
108 108
 			'payment_ids' => ''
109 109
 		);
110 110
 
111
-		$args = wp_parse_args( $data, $defaults );
111
+		$args = wp_parse_args($data, $defaults);
112 112
 
113
-		if ( empty( $args['email'] ) ) {
113
+		if (empty($args['email'])) {
114 114
 			return false;
115 115
 		}
116 116
 
117
-		if ( ! empty( $args['payment_ids'] ) && is_array( $args['payment_ids'] ) ) {
118
-			$args['payment_ids'] = implode( ',', array_unique( array_values( $args['payment_ids'] ) ) );
117
+		if ( ! empty($args['payment_ids']) && is_array($args['payment_ids'])) {
118
+			$args['payment_ids'] = implode(',', array_unique(array_values($args['payment_ids'])));
119 119
 		}
120 120
 
121
-		$donor = $this->get_donor_by( 'email', $args['email'] );
121
+		$donor = $this->get_donor_by('email', $args['email']);
122 122
 
123 123
 		// update an existing donor.
124
-		if ( $donor ) {
124
+		if ($donor) {
125 125
 
126 126
 			// Update the payment IDs attached to the donor
127
-			if ( ! empty( $args['payment_ids'] ) ) {
127
+			if ( ! empty($args['payment_ids'])) {
128 128
 
129
-				if ( empty( $donor->payment_ids ) ) {
129
+				if (empty($donor->payment_ids)) {
130 130
 
131 131
 					$donor->payment_ids = $args['payment_ids'];
132 132
 
133 133
 				} else {
134 134
 
135
-					$existing_ids       = array_map( 'absint', explode( ',', $donor->payment_ids ) );
136
-					$payment_ids        = array_map( 'absint', explode( ',', $args['payment_ids'] ) );
137
-					$payment_ids        = array_merge( $payment_ids, $existing_ids );
138
-					$donor->payment_ids = implode( ',', array_unique( array_values( $payment_ids ) ) );
135
+					$existing_ids       = array_map('absint', explode(',', $donor->payment_ids));
136
+					$payment_ids        = array_map('absint', explode(',', $args['payment_ids']));
137
+					$payment_ids        = array_merge($payment_ids, $existing_ids);
138
+					$donor->payment_ids = implode(',', array_unique(array_values($payment_ids)));
139 139
 
140 140
 				}
141 141
 
@@ -143,13 +143,13 @@  discard block
 block discarded – undo
143 143
 
144 144
 			}
145 145
 
146
-			$this->update( $donor->id, $args );
146
+			$this->update($donor->id, $args);
147 147
 
148 148
 			return $donor->id;
149 149
 
150 150
 		} else {
151 151
 
152
-			return $this->insert( $args, 'donor' );
152
+			return $this->insert($args, 'donor');
153 153
 
154 154
 		}
155 155
 
@@ -168,16 +168,16 @@  discard block
 block discarded – undo
168 168
 	 *
169 169
 	 * @return bool|int
170 170
 	 */
171
-	public function delete( $_id_or_email = false ) {
171
+	public function delete($_id_or_email = false) {
172 172
 
173
-		if ( empty( $_id_or_email ) ) {
173
+		if (empty($_id_or_email)) {
174 174
 			return false;
175 175
 		}
176 176
 
177
-		$column = is_email( $_id_or_email ) ? 'email' : 'id';
178
-		$donor  = $this->get_donor_by( $column, $_id_or_email );
177
+		$column = is_email($_id_or_email) ? 'email' : 'id';
178
+		$donor  = $this->get_donor_by($column, $_id_or_email);
179 179
 
180
-		if ( $donor->id > 0 ) {
180
+		if ($donor->id > 0) {
181 181
 
182 182
 			global $wpdb;
183 183
 
@@ -186,9 +186,9 @@  discard block
 block discarded – undo
186 186
 			 *
187 187
 			 * @since 1.8.14
188 188
 			 */
189
-			Give()->donor_meta->delete_all_meta( $donor->id );
189
+			Give()->donor_meta->delete_all_meta($donor->id);
190 190
 
191
-			return $wpdb->delete( $this->table_name, array( 'id' => $donor->id ), array( '%d' ) );
191
+			return $wpdb->delete($this->table_name, array('id' => $donor->id), array('%d'));
192 192
 
193 193
 		} else {
194 194
 			return false;
@@ -209,9 +209,9 @@  discard block
 block discarded – undo
209 209
 	 *
210 210
 	 * @return bool|int
211 211
 	 */
212
-	public function delete_by_user_id( $user_id = false ) {
212
+	public function delete_by_user_id($user_id = false) {
213 213
 
214
-		if ( empty( $user_id ) ) {
214
+		if (empty($user_id)) {
215 215
 			return false;
216 216
 		}
217 217
 
@@ -220,13 +220,13 @@  discard block
 block discarded – undo
220 220
 		 *
221 221
 		 * @since 1.8.14
222 222
 		 */
223
-		$donor = new Give_Donor( $user_id, true );
224
-		if( ! empty( $donor->id ) ) {
225
-			Give()->donor_meta->delete_all_meta( $donor->id );
223
+		$donor = new Give_Donor($user_id, true);
224
+		if ( ! empty($donor->id)) {
225
+			Give()->donor_meta->delete_all_meta($donor->id);
226 226
 		}
227 227
 
228 228
 		global $wpdb;
229
-		return $wpdb->delete( $this->table_name, array( 'user_id' => $user_id ), array( '%d' ) );
229
+		return $wpdb->delete($this->table_name, array('user_id' => $user_id), array('%d'));
230 230
 	}
231 231
 
232 232
 	/**
@@ -240,14 +240,14 @@  discard block
 block discarded – undo
240 240
 	 *
241 241
 	 * @return bool          True is exists, false otherwise.
242 242
 	 */
243
-	public function exists( $value = '', $field = 'email' ) {
243
+	public function exists($value = '', $field = 'email') {
244 244
 
245 245
 		$columns = $this->get_columns();
246
-		if ( ! array_key_exists( $field, $columns ) ) {
246
+		if ( ! array_key_exists($field, $columns)) {
247 247
 			return false;
248 248
 		}
249 249
 
250
-		return (bool) $this->get_column_by( 'id', $field, $value );
250
+		return (bool) $this->get_column_by('id', $field, $value);
251 251
 
252 252
 	}
253 253
 
@@ -262,16 +262,16 @@  discard block
 block discarded – undo
262 262
 	 *
263 263
 	 * @return bool
264 264
 	 */
265
-	public function attach_payment( $donor_id = 0, $payment_id = 0 ) {
265
+	public function attach_payment($donor_id = 0, $payment_id = 0) {
266 266
 
267
-		$donor = new Give_Donor( $donor_id );
267
+		$donor = new Give_Donor($donor_id);
268 268
 
269
-		if ( empty( $donor->id ) ) {
269
+		if (empty($donor->id)) {
270 270
 			return false;
271 271
 		}
272 272
 
273 273
 		// Attach the payment, but don't increment stats, as this function previously did not
274
-		return $donor->attach_payment( $payment_id, false );
274
+		return $donor->attach_payment($payment_id, false);
275 275
 
276 276
 	}
277 277
 
@@ -286,16 +286,16 @@  discard block
 block discarded – undo
286 286
 	 *
287 287
 	 * @return bool
288 288
 	 */
289
-	public function remove_payment( $donor_id = 0, $payment_id = 0 ) {
289
+	public function remove_payment($donor_id = 0, $payment_id = 0) {
290 290
 
291
-		$donor = new Give_Donor( $donor_id );
291
+		$donor = new Give_Donor($donor_id);
292 292
 
293
-		if ( ! $donor ) {
293
+		if ( ! $donor) {
294 294
 			return false;
295 295
 		}
296 296
 
297 297
 		// Remove the payment, but don't decrease stats, as this function previously did not
298
-		return $donor->remove_payment( $payment_id, false );
298
+		return $donor->remove_payment($payment_id, false);
299 299
 
300 300
 	}
301 301
 
@@ -309,18 +309,18 @@  discard block
 block discarded – undo
309 309
 	 *
310 310
 	 * @return bool
311 311
 	 */
312
-	public function increment_stats( $donor_id = 0, $amount = 0.00 ) {
312
+	public function increment_stats($donor_id = 0, $amount = 0.00) {
313 313
 
314
-		$donor = new Give_Donor( $donor_id );
314
+		$donor = new Give_Donor($donor_id);
315 315
 
316
-		if ( empty( $donor->id ) ) {
316
+		if (empty($donor->id)) {
317 317
 			return false;
318 318
 		}
319 319
 
320 320
 		$increased_count = $donor->increase_purchase_count();
321
-		$increased_value = $donor->increase_value( $amount );
321
+		$increased_value = $donor->increase_value($amount);
322 322
 
323
-		return ( $increased_count && $increased_value ) ? true : false;
323
+		return ($increased_count && $increased_value) ? true : false;
324 324
 
325 325
 	}
326 326
 
@@ -335,18 +335,18 @@  discard block
 block discarded – undo
335 335
 	 *
336 336
 	 * @return bool
337 337
 	 */
338
-	public function decrement_stats( $donor_id = 0, $amount = 0.00 ) {
338
+	public function decrement_stats($donor_id = 0, $amount = 0.00) {
339 339
 
340
-		$donor = new Give_Donor( $donor_id );
340
+		$donor = new Give_Donor($donor_id);
341 341
 
342
-		if ( ! $donor ) {
342
+		if ( ! $donor) {
343 343
 			return false;
344 344
 		}
345 345
 
346 346
 		$decreased_count = $donor->decrease_donation_count();
347
-		$decreased_value = $donor->decrease_value( $amount );
347
+		$decreased_value = $donor->decrease_value($amount);
348 348
 
349
-		return ( $decreased_count && $decreased_value ) ? true : false;
349
+		return ($decreased_count && $decreased_value) ? true : false;
350 350
 
351 351
 	}
352 352
 
@@ -361,31 +361,31 @@  discard block
 block discarded – undo
361 361
 	 *
362 362
 	 * @return bool
363 363
 	 */
364
-	public function update_donor_email_on_user_update( $user_id = 0, $old_user_data = false ) {
364
+	public function update_donor_email_on_user_update($user_id = 0, $old_user_data = false) {
365 365
 
366
-		$donor = new Give_Donor( $user_id, true );
366
+		$donor = new Give_Donor($user_id, true);
367 367
 
368
-		if ( ! $donor ) {
368
+		if ( ! $donor) {
369 369
 			return false;
370 370
 		}
371 371
 
372
-		$user = get_userdata( $user_id );
372
+		$user = get_userdata($user_id);
373 373
 
374
-		if ( ! empty( $user ) && $user->user_email !== $donor->email ) {
374
+		if ( ! empty($user) && $user->user_email !== $donor->email) {
375 375
 
376
-			if ( ! $this->get_donor_by( 'email', $user->user_email ) ) {
376
+			if ( ! $this->get_donor_by('email', $user->user_email)) {
377 377
 
378
-				$success = $this->update( $donor->id, array( 'email' => $user->user_email ) );
378
+				$success = $this->update($donor->id, array('email' => $user->user_email));
379 379
 
380
-				if ( $success ) {
380
+				if ($success) {
381 381
 					// Update some payment meta if we need to
382
-					$payments_array = explode( ',', $donor->payment_ids );
382
+					$payments_array = explode(',', $donor->payment_ids);
383 383
 
384
-					if ( ! empty( $payments_array ) ) {
384
+					if ( ! empty($payments_array)) {
385 385
 
386
-						foreach ( $payments_array as $payment_id ) {
386
+						foreach ($payments_array as $payment_id) {
387 387
 
388
-							give_update_payment_meta( $payment_id, 'email', $user->user_email );
388
+							give_update_payment_meta($payment_id, 'email', $user->user_email);
389 389
 
390 390
 						}
391 391
 
@@ -399,7 +399,7 @@  discard block
 block discarded – undo
399 399
 					 * @param  WP_User $user WordPress User object.
400 400
 					 * @param  Give_Donor $donor Give donor object.
401 401
 					 */
402
-					do_action( 'give_update_donor_email_on_user_update', $user, $donor );
402
+					do_action('give_update_donor_email_on_user_update', $user, $donor);
403 403
 
404 404
 				}
405 405
 
@@ -420,46 +420,46 @@  discard block
 block discarded – undo
420 420
 	 *
421 421
 	 * @return mixed         Upon success, an object of the donor. Upon failure, NULL
422 422
 	 */
423
-	public function get_donor_by( $field = 'id', $value = 0 ) {
423
+	public function get_donor_by($field = 'id', $value = 0) {
424 424
 		/* @var WPDB $wpdb */
425 425
 		global $wpdb;
426 426
 
427
-		if ( empty( $field ) || empty( $value ) ) {
427
+		if (empty($field) || empty($value)) {
428 428
 			return null;
429 429
 		}
430 430
 
431
-		if ( 'id' == $field || 'user_id' == $field ) {
431
+		if ('id' == $field || 'user_id' == $field) {
432 432
 			// Make sure the value is numeric to avoid casting objects, for example,
433 433
 			// to int 1.
434
-			if ( ! is_numeric( $value ) ) {
434
+			if ( ! is_numeric($value)) {
435 435
 				return false;
436 436
 			}
437 437
 
438
-			$value = intval( $value );
438
+			$value = intval($value);
439 439
 
440
-			if ( $value < 1 ) {
440
+			if ($value < 1) {
441 441
 				return false;
442 442
 			}
443 443
 
444
-		} elseif ( 'email' === $field ) {
444
+		} elseif ('email' === $field) {
445 445
 
446
-			if ( ! is_email( $value ) ) {
446
+			if ( ! is_email($value)) {
447 447
 				return false;
448 448
 			}
449 449
 
450
-			$value = trim( $value );
450
+			$value = trim($value);
451 451
 		}
452 452
 
453
-		if ( ! $value ) {
453
+		if ( ! $value) {
454 454
 			return false;
455 455
 		}
456 456
 
457
-		switch ( $field ) {
457
+		switch ($field) {
458 458
 			case 'id':
459 459
 				$db_field = 'id';
460 460
 				break;
461 461
 			case 'email':
462
-				$value    = sanitize_text_field( $value );
462
+				$value    = sanitize_text_field($value);
463 463
 				$db_field = 'email';
464 464
 				break;
465 465
 			case 'user_id':
@@ -469,15 +469,15 @@  discard block
 block discarded – undo
469 469
 				return false;
470 470
 		}
471 471
 
472
-		if ( ! $donor = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $this->table_name WHERE $db_field = %s LIMIT 1", $value ) ) ) {
472
+		if ( ! $donor = $wpdb->get_row($wpdb->prepare("SELECT * FROM $this->table_name WHERE $db_field = %s LIMIT 1", $value))) {
473 473
 
474 474
 			// Look for donor from an additional email.
475
-			if ( 'email' === $field ) {
475
+			if ('email' === $field) {
476 476
 				$meta_table = Give()->donor_meta->table_name;
477
-				$donor_id   = $wpdb->get_var( $wpdb->prepare( "SELECT customer_id FROM {$meta_table} WHERE meta_key = 'additional_email' AND meta_value = %s LIMIT 1", $value ) );
477
+				$donor_id   = $wpdb->get_var($wpdb->prepare("SELECT customer_id FROM {$meta_table} WHERE meta_key = 'additional_email' AND meta_value = %s LIMIT 1", $value));
478 478
 
479
-				if ( ! empty( $donor_id ) ) {
480
-					return $this->get( $donor_id );
479
+				if ( ! empty($donor_id)) {
480
+					return $this->get($donor_id);
481 481
 				}
482 482
 			}
483 483
 
@@ -497,7 +497,7 @@  discard block
 block discarded – undo
497 497
 	 *
498 498
 	 * @return array|object|null Customers array or object. Null if not found.
499 499
 	 */
500
-	public function get_donors( $args = array() ) {
500
+	public function get_donors($args = array()) {
501 501
 		/* @var WPDB $wpdb */
502 502
 		global $wpdb;
503 503
 
@@ -509,21 +509,21 @@  discard block
 block discarded – undo
509 509
 			'order'   => 'DESC'
510 510
 		);
511 511
 
512
-		$args = wp_parse_args( $args, $defaults );
512
+		$args = wp_parse_args($args, $defaults);
513 513
 
514
-		if ( $args['number'] < 1 ) {
514
+		if ($args['number'] < 1) {
515 515
 			$args['number'] = 999999999999;
516 516
 		}
517 517
 
518 518
 		$where = ' WHERE 1=1 ';
519 519
 
520 520
 		// specific donors.
521
-		if ( ! empty( $args['id'] ) ) {
521
+		if ( ! empty($args['id'])) {
522 522
 
523
-			if ( is_array( $args['id'] ) ) {
524
-				$ids = implode( ',', array_map( 'intval', $args['id'] ) );
523
+			if (is_array($args['id'])) {
524
+				$ids = implode(',', array_map('intval', $args['id']));
525 525
 			} else {
526
-				$ids = intval( $args['id'] );
526
+				$ids = intval($args['id']);
527 527
 			}
528 528
 
529 529
 			$where .= " AND `id` IN( {$ids} ) ";
@@ -531,12 +531,12 @@  discard block
 block discarded – undo
531 531
 		}
532 532
 
533 533
 		// donors for specific user accounts
534
-		if ( ! empty( $args['user_id'] ) ) {
534
+		if ( ! empty($args['user_id'])) {
535 535
 
536
-			if ( is_array( $args['user_id'] ) ) {
537
-				$user_ids = implode( ',', array_map( 'intval', $args['user_id'] ) );
536
+			if (is_array($args['user_id'])) {
537
+				$user_ids = implode(',', array_map('intval', $args['user_id']));
538 538
 			} else {
539
-				$user_ids = intval( $args['user_id'] );
539
+				$user_ids = intval($args['user_id']);
540 540
 			}
541 541
 
542 542
 			$where .= " AND `user_id` IN( {$user_ids} ) ";
@@ -544,41 +544,41 @@  discard block
 block discarded – undo
544 544
 		}
545 545
 
546 546
 		//specific donors by email
547
-		if ( ! empty( $args['email'] ) ) {
547
+		if ( ! empty($args['email'])) {
548 548
 
549
-			if ( is_array( $args['email'] ) ) {
549
+			if (is_array($args['email'])) {
550 550
 
551
-				$emails_count       = count( $args['email'] );
552
-				$emails_placeholder = array_fill( 0, $emails_count, '%s' );
553
-				$emails             = implode( ', ', $emails_placeholder );
551
+				$emails_count       = count($args['email']);
552
+				$emails_placeholder = array_fill(0, $emails_count, '%s');
553
+				$emails             = implode(', ', $emails_placeholder);
554 554
 
555
-				$where .= $wpdb->prepare( " AND `email` IN( $emails ) ", $args['email'] );
555
+				$where .= $wpdb->prepare(" AND `email` IN( $emails ) ", $args['email']);
556 556
 			} else {
557
-				$where .= $wpdb->prepare( " AND `email` = %s ", $args['email'] );
557
+				$where .= $wpdb->prepare(" AND `email` = %s ", $args['email']);
558 558
 			}
559 559
 		}
560 560
 
561 561
 		// specific donors by name
562
-		if ( ! empty( $args['name'] ) ) {
563
-			$where .= $wpdb->prepare( " AND `name` LIKE '%%%%" . '%s' . "%%%%' ", $args['name'] );
562
+		if ( ! empty($args['name'])) {
563
+			$where .= $wpdb->prepare(" AND `name` LIKE '%%%%".'%s'."%%%%' ", $args['name']);
564 564
 		}
565 565
 
566 566
 		// Donors created for a specific date or in a date range
567
-		if ( ! empty( $args['date'] ) ) {
567
+		if ( ! empty($args['date'])) {
568 568
 
569
-			if ( is_array( $args['date'] ) ) {
569
+			if (is_array($args['date'])) {
570 570
 
571
-				if ( ! empty( $args['date']['start'] ) ) {
571
+				if ( ! empty($args['date']['start'])) {
572 572
 
573
-					$start = date( 'Y-m-d H:i:s', strtotime( $args['date']['start'] ) );
573
+					$start = date('Y-m-d H:i:s', strtotime($args['date']['start']));
574 574
 
575 575
 					$where .= " AND `date_created` >= '{$start}'";
576 576
 
577 577
 				}
578 578
 
579
-				if ( ! empty( $args['date']['end'] ) ) {
579
+				if ( ! empty($args['date']['end'])) {
580 580
 
581
-					$end = date( 'Y-m-d H:i:s', strtotime( $args['date']['end'] ) );
581
+					$end = date('Y-m-d H:i:s', strtotime($args['date']['end']));
582 582
 
583 583
 					$where .= " AND `date_created` <= '{$end}'";
584 584
 
@@ -586,31 +586,31 @@  discard block
 block discarded – undo
586 586
 
587 587
 			} else {
588 588
 
589
-				$year  = date( 'Y', strtotime( $args['date'] ) );
590
-				$month = date( 'm', strtotime( $args['date'] ) );
591
-				$day   = date( 'd', strtotime( $args['date'] ) );
589
+				$year  = date('Y', strtotime($args['date']));
590
+				$month = date('m', strtotime($args['date']));
591
+				$day   = date('d', strtotime($args['date']));
592 592
 
593 593
 				$where .= " AND $year = YEAR ( date_created ) AND $month = MONTH ( date_created ) AND $day = DAY ( date_created )";
594 594
 			}
595 595
 
596 596
 		}
597 597
 
598
-		$args['orderby'] = ! array_key_exists( $args['orderby'], $this->get_columns() ) ? 'id' : $args['orderby'];
598
+		$args['orderby'] = ! array_key_exists($args['orderby'], $this->get_columns()) ? 'id' : $args['orderby'];
599 599
 
600
-		if ( 'purchase_value' == $args['orderby'] ) {
600
+		if ('purchase_value' == $args['orderby']) {
601 601
 			$args['orderby'] = 'purchase_value+0';
602 602
 		}
603 603
 
604
-		$cache_key = md5( 'give_donors_' . serialize( $args ) );
604
+		$cache_key = md5('give_donors_'.serialize($args));
605 605
 
606
-		$donors = wp_cache_get( $cache_key, 'donors' );
606
+		$donors = wp_cache_get($cache_key, 'donors');
607 607
 
608
-		$args['orderby'] = esc_sql( $args['orderby'] );
609
-		$args['order']   = esc_sql( $args['order'] );
608
+		$args['orderby'] = esc_sql($args['orderby']);
609
+		$args['order']   = esc_sql($args['order']);
610 610
 
611
-		if ( $donors === false ) {
612
-			$donors = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM  $this->table_name $where ORDER BY {$args['orderby']} {$args['order']} LIMIT %d,%d;", absint( $args['offset'] ), absint( $args['number'] ) ) );
613
-			wp_cache_set( $cache_key, $donors, 'donors', 3600 );
611
+		if ($donors === false) {
612
+			$donors = $wpdb->get_results($wpdb->prepare("SELECT * FROM  $this->table_name $where ORDER BY {$args['orderby']} {$args['order']} LIMIT %d,%d;", absint($args['offset']), absint($args['number'])));
613
+			wp_cache_set($cache_key, $donors, 'donors', 3600);
614 614
 		}
615 615
 
616 616
 		return $donors;
@@ -628,26 +628,26 @@  discard block
 block discarded – undo
628 628
 	 *
629 629
 	 * @return int         Total number of donors.
630 630
 	 */
631
-	public function count( $args = array() ) {
631
+	public function count($args = array()) {
632 632
 		/* @var WPDB $wpdb */
633 633
 		global $wpdb;
634 634
 
635 635
 		$where = ' WHERE 1=1 ';
636 636
 
637
-		if ( ! empty( $args['date'] ) ) {
637
+		if ( ! empty($args['date'])) {
638 638
 
639
-			if ( is_array( $args['date'] ) ) {
639
+			if (is_array($args['date'])) {
640 640
 
641
-				$start = date( 'Y-m-d H:i:s', strtotime( $args['date']['start'] ) );
642
-				$end   = date( 'Y-m-d H:i:s', strtotime( $args['date']['end'] ) );
641
+				$start = date('Y-m-d H:i:s', strtotime($args['date']['start']));
642
+				$end   = date('Y-m-d H:i:s', strtotime($args['date']['end']));
643 643
 
644 644
 				$where .= " AND `date_created` >= '{$start}' AND `date_created` <= '{$end}'";
645 645
 
646 646
 			} else {
647 647
 
648
-				$year  = date( 'Y', strtotime( $args['date'] ) );
649
-				$month = date( 'm', strtotime( $args['date'] ) );
650
-				$day   = date( 'd', strtotime( $args['date'] ) );
648
+				$year  = date('Y', strtotime($args['date']));
649
+				$month = date('m', strtotime($args['date']));
650
+				$day   = date('d', strtotime($args['date']));
651 651
 
652 652
 				$where .= " AND $year = YEAR ( date_created ) AND $month = MONTH ( date_created ) AND $day = DAY ( date_created )";
653 653
 			}
@@ -655,16 +655,16 @@  discard block
 block discarded – undo
655 655
 		}
656 656
 
657 657
 
658
-		$cache_key = md5( 'give_donors_count' . serialize( $args ) );
658
+		$cache_key = md5('give_donors_count'.serialize($args));
659 659
 
660
-		$count = wp_cache_get( $cache_key, 'donors' );
660
+		$count = wp_cache_get($cache_key, 'donors');
661 661
 
662
-		if ( $count === false ) {
663
-			$count = $wpdb->get_var( "SELECT COUNT($this->primary_key) FROM " . $this->table_name . "{$where};" );
664
-			wp_cache_set( $cache_key, $count, 'donors', 3600 );
662
+		if ($count === false) {
663
+			$count = $wpdb->get_var("SELECT COUNT($this->primary_key) FROM ".$this->table_name."{$where};");
664
+			wp_cache_set($cache_key, $count, 'donors', 3600);
665 665
 		}
666 666
 
667
-		return absint( $count );
667
+		return absint($count);
668 668
 
669 669
 	}
670 670
 
@@ -678,9 +678,9 @@  discard block
 block discarded – undo
678 678
 	 */
679 679
 	public function create_table() {
680 680
 
681
-		require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
681
+		require_once(ABSPATH.'wp-admin/includes/upgrade.php');
682 682
 
683
-		$sql = "CREATE TABLE " . $this->table_name . " (
683
+		$sql = "CREATE TABLE ".$this->table_name." (
684 684
 		id bigint(20) NOT NULL AUTO_INCREMENT,
685 685
 		user_id bigint(20) NOT NULL,
686 686
 		email varchar(50) NOT NULL,
@@ -695,9 +695,9 @@  discard block
 block discarded – undo
695 695
 		KEY user (user_id)
696 696
 		) CHARACTER SET utf8 COLLATE utf8_general_ci;";
697 697
 
698
-		dbDelta( $sql );
698
+		dbDelta($sql);
699 699
 
700
-		update_option( $this->table_name . '_db_version', $this->version );
700
+		update_option($this->table_name.'_db_version', $this->version);
701 701
 	}
702 702
 
703 703
 	/**
@@ -709,7 +709,7 @@  discard block
 block discarded – undo
709 709
 	 * @return bool Returns if the donors table was installed and upgrade routine run.
710 710
 	 */
711 711
 	public function installed() {
712
-		return $this->table_exists( $this->table_name );
712
+		return $this->table_exists($this->table_name);
713 713
 	}
714 714
 
715 715
 }
Please login to merge, or discard this patch.
includes/class-give-donor.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -918,7 +918,7 @@
 block discarded – undo
918 918
 	 * @access public
919 919
 	 *
920 920
 	 * @param  string $meta_key Metadata name. Default is empty.
921
-	 * @param  mixed $meta_value Optional. Metadata value. Default is empty.
921
+	 * @param  string $meta_value Optional. Metadata value. Default is empty.
922 922
 	 *
923 923
 	 * @return bool               False for failure. True for success.
924 924
 	 */
Please login to merge, or discard this patch.
Spacing   +170 added lines, -170 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
 
@@ -139,32 +139,32 @@  discard block
 block discarded – undo
139 139
 	 * @param bool $_id_or_email
140 140
 	 * @param bool $by_user_id
141 141
 	 */
142
-	public function __construct( $_id_or_email = false, $by_user_id = false ) {
142
+	public function __construct($_id_or_email = false, $by_user_id = false) {
143 143
 
144 144
 		$this->db = Give()->donors;
145 145
 
146 146
 		if (
147 147
 			false === $_id_or_email
148
-			|| ( is_numeric( $_id_or_email ) && (int) $_id_or_email !== absint( $_id_or_email ) )
148
+			|| (is_numeric($_id_or_email) && (int) $_id_or_email !== absint($_id_or_email))
149 149
 		) {
150 150
 			return false;
151 151
 		}
152 152
 
153
-		$by_user_id = is_bool( $by_user_id ) ? $by_user_id : false;
153
+		$by_user_id = is_bool($by_user_id) ? $by_user_id : false;
154 154
 
155
-		if ( is_numeric( $_id_or_email ) ) {
155
+		if (is_numeric($_id_or_email)) {
156 156
 			$field = $by_user_id ? 'user_id' : 'id';
157 157
 		} else {
158 158
 			$field = 'email';
159 159
 		}
160 160
 
161
-		$donor = $this->db->get_donor_by( $field, $_id_or_email );
161
+		$donor = $this->db->get_donor_by($field, $_id_or_email);
162 162
 
163
-		if ( empty( $donor ) || ! is_object( $donor ) ) {
163
+		if (empty($donor) || ! is_object($donor)) {
164 164
 			return false;
165 165
 		}
166 166
 
167
-		$this->setup_donor( $donor );
167
+		$this->setup_donor($donor);
168 168
 
169 169
 	}
170 170
 
@@ -180,15 +180,15 @@  discard block
 block discarded – undo
180 180
 	 *
181 181
 	 * @return bool             If the setup was successful or not.
182 182
 	 */
183
-	private function setup_donor( $donor ) {
183
+	private function setup_donor($donor) {
184 184
 
185
-		if ( ! is_object( $donor ) ) {
185
+		if ( ! is_object($donor)) {
186 186
 			return false;
187 187
 		}
188 188
 
189
-		foreach ( $donor as $key => $value ) {
189
+		foreach ($donor as $key => $value) {
190 190
 
191
-			switch ( $key ) {
191
+			switch ($key) {
192 192
 
193 193
 				case 'notes':
194 194
 					$this->$key = $this->get_notes();
@@ -202,11 +202,11 @@  discard block
 block discarded – undo
202 202
 		}
203 203
 
204 204
 		// Get donor's all email including primary email.
205
-		$this->emails = (array) $this->get_meta( 'additional_email', false );
206
-		$this->emails = array( 'primary' => $this->email ) + $this->emails;
205
+		$this->emails = (array) $this->get_meta('additional_email', false);
206
+		$this->emails = array('primary' => $this->email) + $this->emails;
207 207
 
208 208
 		// Donor ID and email are the only things that are necessary, make sure they exist.
209
-		if ( ! empty( $this->id ) && ! empty( $this->email ) ) {
209
+		if ( ! empty($this->id) && ! empty($this->email)) {
210 210
 			return true;
211 211
 		}
212 212
 
@@ -223,16 +223,16 @@  discard block
 block discarded – undo
223 223
 	 *
224 224
 	 * @return mixed|\WP_Error
225 225
 	 */
226
-	public function __get( $key ) {
226
+	public function __get($key) {
227 227
 
228
-		if ( method_exists( $this, 'get_' . $key ) ) {
228
+		if (method_exists($this, 'get_'.$key)) {
229 229
 
230
-			return call_user_func( array( $this, 'get_' . $key ) );
230
+			return call_user_func(array($this, 'get_'.$key));
231 231
 
232 232
 		} else {
233 233
 
234 234
 			/* translators: %s: property key */
235
-			return new WP_Error( 'give-donor-invalid-property', sprintf( esc_html__( 'Can\'t get property %s.', 'give' ), $key ) );
235
+			return new WP_Error('give-donor-invalid-property', sprintf(esc_html__('Can\'t get property %s.', 'give'), $key));
236 236
 
237 237
 		}
238 238
 
@@ -248,9 +248,9 @@  discard block
 block discarded – undo
248 248
 	 *
249 249
 	 * @return bool|int    False if not a valid creation, donor ID if user is found or valid creation.
250 250
 	 */
251
-	public function create( $data = array() ) {
251
+	public function create($data = array()) {
252 252
 
253
-		if ( $this->id != 0 || empty( $data ) ) {
253
+		if ($this->id != 0 || empty($data)) {
254 254
 			return false;
255 255
 		}
256 256
 
@@ -258,15 +258,15 @@  discard block
 block discarded – undo
258 258
 			'payment_ids' => '',
259 259
 		);
260 260
 
261
-		$args = wp_parse_args( $data, $defaults );
262
-		$args = $this->sanitize_columns( $args );
261
+		$args = wp_parse_args($data, $defaults);
262
+		$args = $this->sanitize_columns($args);
263 263
 
264
-		if ( empty( $args['email'] ) || ! is_email( $args['email'] ) ) {
264
+		if (empty($args['email']) || ! is_email($args['email'])) {
265 265
 			return false;
266 266
 		}
267 267
 
268
-		if ( ! empty( $args['payment_ids'] ) && is_array( $args['payment_ids'] ) ) {
269
-			$args['payment_ids'] = implode( ',', array_unique( array_values( $args['payment_ids'] ) ) );
268
+		if ( ! empty($args['payment_ids']) && is_array($args['payment_ids'])) {
269
+			$args['payment_ids'] = implode(',', array_unique(array_values($args['payment_ids'])));
270 270
 		}
271 271
 
272 272
 		/**
@@ -276,18 +276,18 @@  discard block
 block discarded – undo
276 276
 		 *
277 277
 		 * @param array $args Donor attributes.
278 278
 		 */
279
-		do_action( 'give_donor_pre_create', $args );
279
+		do_action('give_donor_pre_create', $args);
280 280
 
281 281
 		$created = false;
282 282
 
283 283
 		// The DB class 'add' implies an update if the donor being asked to be created already exists
284
-		if ( $this->db->add( $data ) ) {
284
+		if ($this->db->add($data)) {
285 285
 
286 286
 			// We've successfully added/updated the donor, reset the class vars with the new data
287
-			$donor = $this->db->get_donor_by( 'email', $args['email'] );
287
+			$donor = $this->db->get_donor_by('email', $args['email']);
288 288
 
289 289
 			// Setup the donor data with the values from DB
290
-			$this->setup_donor( $donor );
290
+			$this->setup_donor($donor);
291 291
 
292 292
 			$created = $this->id;
293 293
 		}
@@ -300,7 +300,7 @@  discard block
 block discarded – undo
300 300
 		 * @param bool|int $created False if not a valid creation, donor ID if user is found or valid creation.
301 301
 		 * @param array $args Customer attributes.
302 302
 		 */
303
-		do_action( 'give_donor_post_create', $created, $args );
303
+		do_action('give_donor_post_create', $created, $args);
304 304
 
305 305
 		return $created;
306 306
 
@@ -316,13 +316,13 @@  discard block
 block discarded – undo
316 316
 	 *
317 317
 	 * @return bool        If the update was successful or not.
318 318
 	 */
319
-	public function update( $data = array() ) {
319
+	public function update($data = array()) {
320 320
 
321
-		if ( empty( $data ) ) {
321
+		if (empty($data)) {
322 322
 			return false;
323 323
 		}
324 324
 
325
-		$data = $this->sanitize_columns( $data );
325
+		$data = $this->sanitize_columns($data);
326 326
 
327 327
 		/**
328 328
 		 * Fires before updating donors.
@@ -332,14 +332,14 @@  discard block
 block discarded – undo
332 332
 		 * @param int $donor_id Donor id.
333 333
 		 * @param array $data Donor attributes.
334 334
 		 */
335
-		do_action( 'give_donor_pre_update', $this->id, $data );
335
+		do_action('give_donor_pre_update', $this->id, $data);
336 336
 
337 337
 		$updated = false;
338 338
 
339
-		if ( $this->db->update( $this->id, $data ) ) {
339
+		if ($this->db->update($this->id, $data)) {
340 340
 
341
-			$donor = $this->db->get_donor_by( 'id', $this->id );
342
-			$this->setup_donor( $donor );
341
+			$donor = $this->db->get_donor_by('id', $this->id);
342
+			$this->setup_donor($donor);
343 343
 
344 344
 			$updated = true;
345 345
 		}
@@ -353,7 +353,7 @@  discard block
 block discarded – undo
353 353
 		 * @param int $donor_id Donor id.
354 354
 		 * @param array $data Donor attributes.
355 355
 		 */
356
-		do_action( 'give_donor_post_update', $updated, $this->id, $data );
356
+		do_action('give_donor_post_update', $updated, $this->id, $data);
357 357
 
358 358
 		return $updated;
359 359
 	}
@@ -371,27 +371,27 @@  discard block
 block discarded – undo
371 371
 	 *
372 372
 	 * @return bool            If the attachment was successfully.
373 373
 	 */
374
-	public function attach_payment( $payment_id = 0, $update_stats = true ) {
374
+	public function attach_payment($payment_id = 0, $update_stats = true) {
375 375
 
376
-		if ( empty( $payment_id ) ) {
376
+		if (empty($payment_id)) {
377 377
 			return false;
378 378
 		}
379 379
 
380
-		if ( empty( $this->payment_ids ) ) {
380
+		if (empty($this->payment_ids)) {
381 381
 
382 382
 			$new_payment_ids = $payment_id;
383 383
 
384 384
 		} else {
385 385
 
386
-			$payment_ids = array_map( 'absint', explode( ',', $this->payment_ids ) );
386
+			$payment_ids = array_map('absint', explode(',', $this->payment_ids));
387 387
 
388
-			if ( in_array( $payment_id, $payment_ids ) ) {
388
+			if (in_array($payment_id, $payment_ids)) {
389 389
 				$update_stats = false;
390 390
 			}
391 391
 
392 392
 			$payment_ids[] = $payment_id;
393 393
 
394
-			$new_payment_ids = implode( ',', array_unique( array_values( $payment_ids ) ) );
394
+			$new_payment_ids = implode(',', array_unique(array_values($payment_ids)));
395 395
 
396 396
 		}
397 397
 
@@ -403,20 +403,20 @@  discard block
 block discarded – undo
403 403
 		 * @param int $payment_id Payment id.
404 404
 		 * @param int $donor_id Customer id.
405 405
 		 */
406
-		do_action( 'give_donor_pre_attach_payment', $payment_id, $this->id );
406
+		do_action('give_donor_pre_attach_payment', $payment_id, $this->id);
407 407
 
408
-		$payment_added = $this->update( array( 'payment_ids' => $new_payment_ids ) );
408
+		$payment_added = $this->update(array('payment_ids' => $new_payment_ids));
409 409
 
410
-		if ( $payment_added ) {
410
+		if ($payment_added) {
411 411
 
412 412
 			$this->payment_ids = $new_payment_ids;
413 413
 
414 414
 			// We added this payment successfully, increment the stats
415
-			if ( $update_stats ) {
416
-				$payment_amount = give_get_payment_amount( $payment_id );
415
+			if ($update_stats) {
416
+				$payment_amount = give_get_payment_amount($payment_id);
417 417
 
418
-				if ( ! empty( $payment_amount ) ) {
419
-					$this->increase_value( $payment_amount );
418
+				if ( ! empty($payment_amount)) {
419
+					$this->increase_value($payment_amount);
420 420
 				}
421 421
 
422 422
 				$this->increase_purchase_count();
@@ -432,7 +432,7 @@  discard block
 block discarded – undo
432 432
 		 * @param int $payment_id Payment id.
433 433
 		 * @param int $donor_id Donor id.
434 434
 		 */
435
-		do_action( 'give_donor_post_attach_payment', $payment_added, $payment_id, $this->id );
435
+		do_action('give_donor_post_attach_payment', $payment_added, $payment_id, $this->id);
436 436
 
437 437
 		return $payment_added;
438 438
 	}
@@ -450,33 +450,33 @@  discard block
 block discarded – undo
450 450
 	 *
451 451
 	 * @return boolean               If the removal was successful.
452 452
 	 */
453
-	public function remove_payment( $payment_id = 0, $update_stats = true ) {
453
+	public function remove_payment($payment_id = 0, $update_stats = true) {
454 454
 
455
-		if ( empty( $payment_id ) ) {
455
+		if (empty($payment_id)) {
456 456
 			return false;
457 457
 		}
458 458
 
459
-		$payment = new Give_Payment( $payment_id );
459
+		$payment = new Give_Payment($payment_id);
460 460
 
461
-		if ( 'publish' !== $payment->status && 'revoked' !== $payment->status ) {
461
+		if ('publish' !== $payment->status && 'revoked' !== $payment->status) {
462 462
 			$update_stats = false;
463 463
 		}
464 464
 
465 465
 		$new_payment_ids = '';
466 466
 
467
-		if ( ! empty( $this->payment_ids ) ) {
467
+		if ( ! empty($this->payment_ids)) {
468 468
 
469
-			$payment_ids = array_map( 'absint', explode( ',', $this->payment_ids ) );
469
+			$payment_ids = array_map('absint', explode(',', $this->payment_ids));
470 470
 
471
-			$pos = array_search( $payment_id, $payment_ids );
472
-			if ( false === $pos ) {
471
+			$pos = array_search($payment_id, $payment_ids);
472
+			if (false === $pos) {
473 473
 				return false;
474 474
 			}
475 475
 
476
-			unset( $payment_ids[ $pos ] );
477
-			$payment_ids = array_filter( $payment_ids );
476
+			unset($payment_ids[$pos]);
477
+			$payment_ids = array_filter($payment_ids);
478 478
 
479
-			$new_payment_ids = implode( ',', array_unique( array_values( $payment_ids ) ) );
479
+			$new_payment_ids = implode(',', array_unique(array_values($payment_ids)));
480 480
 
481 481
 		}
482 482
 
@@ -488,20 +488,20 @@  discard block
 block discarded – undo
488 488
 		 * @param int $payment_id Payment id.
489 489
 		 * @param int $donor_id Customer id.
490 490
 		 */
491
-		do_action( 'give_donor_pre_remove_payment', $payment_id, $this->id );
491
+		do_action('give_donor_pre_remove_payment', $payment_id, $this->id);
492 492
 
493
-		$payment_removed = $this->update( array( 'payment_ids' => $new_payment_ids ) );
493
+		$payment_removed = $this->update(array('payment_ids' => $new_payment_ids));
494 494
 
495
-		if ( $payment_removed ) {
495
+		if ($payment_removed) {
496 496
 
497 497
 			$this->payment_ids = $new_payment_ids;
498 498
 
499
-			if ( $update_stats ) {
499
+			if ($update_stats) {
500 500
 				// We removed this payment successfully, decrement the stats
501
-				$payment_amount = give_get_payment_amount( $payment_id );
501
+				$payment_amount = give_get_payment_amount($payment_id);
502 502
 
503
-				if ( ! empty( $payment_amount ) ) {
504
-					$this->decrease_value( $payment_amount );
503
+				if ( ! empty($payment_amount)) {
504
+					$this->decrease_value($payment_amount);
505 505
 				}
506 506
 
507 507
 				$this->decrease_donation_count();
@@ -517,7 +517,7 @@  discard block
 block discarded – undo
517 517
 		 * @param int $payment_id Payment id.
518 518
 		 * @param int $donor_id Donor id.
519 519
 		 */
520
-		do_action( 'give_donor_post_remove_payment', $payment_removed, $payment_id, $this->id );
520
+		do_action('give_donor_post_remove_payment', $payment_removed, $payment_id, $this->id);
521 521
 
522 522
 		return $payment_removed;
523 523
 
@@ -533,10 +533,10 @@  discard block
 block discarded – undo
533 533
 	 *
534 534
 	 * @return int        The donation count.
535 535
 	 */
536
-	public function increase_purchase_count( $count = 1 ) {
536
+	public function increase_purchase_count($count = 1) {
537 537
 
538 538
 		// Make sure it's numeric and not negative.
539
-		if ( ! is_numeric( $count ) || $count != absint( $count ) ) {
539
+		if ( ! is_numeric($count) || $count != absint($count)) {
540 540
 			return false;
541 541
 		}
542 542
 
@@ -550,9 +550,9 @@  discard block
 block discarded – undo
550 550
 		 * @param int $count The number to increase by.
551 551
 		 * @param int $donor_id Donor id.
552 552
 		 */
553
-		do_action( 'give_donor_pre_increase_donation_count', $count, $this->id );
553
+		do_action('give_donor_pre_increase_donation_count', $count, $this->id);
554 554
 
555
-		if ( $this->update( array( 'purchase_count' => $new_total ) ) ) {
555
+		if ($this->update(array('purchase_count' => $new_total))) {
556 556
 			$this->purchase_count = $new_total;
557 557
 		}
558 558
 
@@ -565,7 +565,7 @@  discard block
 block discarded – undo
565 565
 		 * @param int $count The number increased by.
566 566
 		 * @param int $donor_id Donor id.
567 567
 		 */
568
-		do_action( 'give_donor_post_increase_donation_count', $this->purchase_count, $count, $this->id );
568
+		do_action('give_donor_post_increase_donation_count', $this->purchase_count, $count, $this->id);
569 569
 
570 570
 		return $this->purchase_count;
571 571
 	}
@@ -580,16 +580,16 @@  discard block
 block discarded – undo
580 580
 	 *
581 581
 	 * @return mixed      If successful, the new count, otherwise false.
582 582
 	 */
583
-	public function decrease_donation_count( $count = 1 ) {
583
+	public function decrease_donation_count($count = 1) {
584 584
 
585 585
 		// Make sure it's numeric and not negative
586
-		if ( ! is_numeric( $count ) || $count != absint( $count ) ) {
586
+		if ( ! is_numeric($count) || $count != absint($count)) {
587 587
 			return false;
588 588
 		}
589 589
 
590 590
 		$new_total = (int) $this->purchase_count - (int) $count;
591 591
 
592
-		if ( $new_total < 0 ) {
592
+		if ($new_total < 0) {
593 593
 			$new_total = 0;
594 594
 		}
595 595
 
@@ -601,9 +601,9 @@  discard block
 block discarded – undo
601 601
 		 * @param int $count The number to decrease by.
602 602
 		 * @param int $donor_id Customer id.
603 603
 		 */
604
-		do_action( 'give_donor_pre_decrease_donation_count', $count, $this->id );
604
+		do_action('give_donor_pre_decrease_donation_count', $count, $this->id);
605 605
 
606
-		if ( $this->update( array( 'purchase_count' => $new_total ) ) ) {
606
+		if ($this->update(array('purchase_count' => $new_total))) {
607 607
 			$this->purchase_count = $new_total;
608 608
 		}
609 609
 
@@ -616,7 +616,7 @@  discard block
 block discarded – undo
616 616
 		 * @param int $count The number decreased by.
617 617
 		 * @param int $donor_id Donor id.
618 618
 		 */
619
-		do_action( 'give_donor_post_decrease_donation_count', $this->purchase_count, $count, $this->id );
619
+		do_action('give_donor_post_decrease_donation_count', $this->purchase_count, $count, $this->id);
620 620
 
621 621
 		return $this->purchase_count;
622 622
 	}
@@ -631,9 +631,9 @@  discard block
 block discarded – undo
631 631
 	 *
632 632
 	 * @return mixed        If successful, the new value, otherwise false.
633 633
 	 */
634
-	public function increase_value( $value = 0.00 ) {
634
+	public function increase_value($value = 0.00) {
635 635
 
636
-		$new_value = floatval( $this->purchase_value ) + $value;
636
+		$new_value = floatval($this->purchase_value) + $value;
637 637
 
638 638
 		/**
639 639
 		 * Fires before increasing donor lifetime value.
@@ -643,9 +643,9 @@  discard block
 block discarded – undo
643 643
 		 * @param float $value The value to increase by.
644 644
 		 * @param int $donor_id Customer id.
645 645
 		 */
646
-		do_action( 'give_donor_pre_increase_value', $value, $this->id );
646
+		do_action('give_donor_pre_increase_value', $value, $this->id);
647 647
 
648
-		if ( $this->update( array( 'purchase_value' => $new_value ) ) ) {
648
+		if ($this->update(array('purchase_value' => $new_value))) {
649 649
 			$this->purchase_value = $new_value;
650 650
 		}
651 651
 
@@ -658,7 +658,7 @@  discard block
 block discarded – undo
658 658
 		 * @param float $value The value increased by.
659 659
 		 * @param int $donor_id Donor id.
660 660
 		 */
661
-		do_action( 'give_donor_post_increase_value', $this->purchase_value, $value, $this->id );
661
+		do_action('give_donor_post_increase_value', $this->purchase_value, $value, $this->id);
662 662
 
663 663
 		return $this->purchase_value;
664 664
 	}
@@ -673,11 +673,11 @@  discard block
 block discarded – undo
673 673
 	 *
674 674
 	 * @return mixed        If successful, the new value, otherwise false.
675 675
 	 */
676
-	public function decrease_value( $value = 0.00 ) {
676
+	public function decrease_value($value = 0.00) {
677 677
 
678
-		$new_value = floatval( $this->purchase_value ) - $value;
678
+		$new_value = floatval($this->purchase_value) - $value;
679 679
 
680
-		if ( $new_value < 0 ) {
680
+		if ($new_value < 0) {
681 681
 			$new_value = 0.00;
682 682
 		}
683 683
 
@@ -689,9 +689,9 @@  discard block
 block discarded – undo
689 689
 		 * @param float $value The value to decrease by.
690 690
 		 * @param int $donor_id Donor id.
691 691
 		 */
692
-		do_action( 'give_donor_pre_decrease_value', $value, $this->id );
692
+		do_action('give_donor_pre_decrease_value', $value, $this->id);
693 693
 
694
-		if ( $this->update( array( 'purchase_value' => $new_value ) ) ) {
694
+		if ($this->update(array('purchase_value' => $new_value))) {
695 695
 			$this->purchase_value = $new_value;
696 696
 		}
697 697
 
@@ -704,7 +704,7 @@  discard block
 block discarded – undo
704 704
 		 * @param float $value The value decreased by.
705 705
 		 * @param int $donor_id Donor id.
706 706
 		 */
707
-		do_action( 'give_donor_post_decrease_value', $this->purchase_value, $value, $this->id );
707
+		do_action('give_donor_post_decrease_value', $this->purchase_value, $value, $this->id);
708 708
 
709 709
 		return $this->purchase_value;
710 710
 	}
@@ -723,7 +723,7 @@  discard block
 block discarded – undo
723 723
 	 *
724 724
 	 * @return mixed              If successful, the new donation stat value, otherwise false.
725 725
 	 */
726
-	public function update_donation_value( $curr_amount, $new_amount ) {
726
+	public function update_donation_value($curr_amount, $new_amount) {
727 727
 		/**
728 728
 		 * Payment total difference value can be:
729 729
 		 *  zero   (in case amount not change)
@@ -733,15 +733,15 @@  discard block
 block discarded – undo
733 733
 		$payment_total_diff = $new_amount - $curr_amount;
734 734
 
735 735
 		// We do not need to update donation stat if donation did not change.
736
-		if ( ! $payment_total_diff ) {
736
+		if ( ! $payment_total_diff) {
737 737
 			return false;
738 738
 		}
739 739
 
740
-		if ( $payment_total_diff > 0 ) {
741
-			$this->increase_value( $payment_total_diff );
740
+		if ($payment_total_diff > 0) {
741
+			$this->increase_value($payment_total_diff);
742 742
 		} else {
743 743
 			// Pass payment total difference as +ve value to decrease amount from user lifetime stat.
744
-			$this->decrease_value( - $payment_total_diff );
744
+			$this->decrease_value( -$payment_total_diff );
745 745
 		}
746 746
 
747 747
 		return $this->purchase_value;
@@ -758,15 +758,15 @@  discard block
 block discarded – undo
758 758
 	 *
759 759
 	 * @return array       The notes requested.
760 760
 	 */
761
-	public function get_notes( $length = 20, $paged = 1 ) {
761
+	public function get_notes($length = 20, $paged = 1) {
762 762
 
763
-		$length = is_numeric( $length ) ? $length : 20;
764
-		$offset = is_numeric( $paged ) && $paged != 1 ? ( ( absint( $paged ) - 1 ) * $length ) : 0;
763
+		$length = is_numeric($length) ? $length : 20;
764
+		$offset = is_numeric($paged) && $paged != 1 ? ((absint($paged) - 1) * $length) : 0;
765 765
 
766 766
 		$all_notes   = $this->get_raw_notes();
767
-		$notes_array = array_reverse( array_filter( explode( "\n\n", $all_notes ) ) );
767
+		$notes_array = array_reverse(array_filter(explode("\n\n", $all_notes)));
768 768
 
769
-		$desired_notes = array_slice( $notes_array, $offset, $length );
769
+		$desired_notes = array_slice($notes_array, $offset, $length);
770 770
 
771 771
 		return $desired_notes;
772 772
 
@@ -783,9 +783,9 @@  discard block
 block discarded – undo
783 783
 	public function get_notes_count() {
784 784
 
785 785
 		$all_notes   = $this->get_raw_notes();
786
-		$notes_array = array_reverse( array_filter( explode( "\n\n", $all_notes ) ) );
786
+		$notes_array = array_reverse(array_filter(explode("\n\n", $all_notes)));
787 787
 
788
-		return count( $notes_array );
788
+		return count($notes_array);
789 789
 
790 790
 	}
791 791
 
@@ -799,22 +799,22 @@  discard block
 block discarded – undo
799 799
 	 *
800 800
 	 * @return string|boolean The new note if added successfully, false otherwise.
801 801
 	 */
802
-	public function add_note( $note = '' ) {
802
+	public function add_note($note = '') {
803 803
 
804
-		$note = trim( $note );
805
-		if ( empty( $note ) ) {
804
+		$note = trim($note);
805
+		if (empty($note)) {
806 806
 			return false;
807 807
 		}
808 808
 
809 809
 		$notes = $this->get_raw_notes();
810 810
 
811
-		if ( empty( $notes ) ) {
811
+		if (empty($notes)) {
812 812
 			$notes = '';
813 813
 		}
814 814
 
815
-		$note_string = date_i18n( 'F j, Y H:i:s', current_time( 'timestamp' ) ) . ' - ' . $note;
816
-		$new_note    = apply_filters( 'give_customer_add_note_string', $note_string );
817
-		$notes       .= "\n\n" . $new_note;
815
+		$note_string = date_i18n('F j, Y H:i:s', current_time('timestamp')).' - '.$note;
816
+		$new_note    = apply_filters('give_customer_add_note_string', $note_string);
817
+		$notes .= "\n\n".$new_note;
818 818
 
819 819
 		/**
820 820
 		 * Fires before donor note is added.
@@ -824,11 +824,11 @@  discard block
 block discarded – undo
824 824
 		 * @param string $new_note New note to add.
825 825
 		 * @param int $donor_id Donor id.
826 826
 		 */
827
-		do_action( 'give_donor_pre_add_note', $new_note, $this->id );
827
+		do_action('give_donor_pre_add_note', $new_note, $this->id);
828 828
 
829
-		$updated = $this->update( array( 'notes' => $notes ) );
829
+		$updated = $this->update(array('notes' => $notes));
830 830
 
831
-		if ( $updated ) {
831
+		if ($updated) {
832 832
 			$this->notes = $this->get_notes();
833 833
 		}
834 834
 
@@ -841,7 +841,7 @@  discard block
 block discarded – undo
841 841
 		 * @param string $new_note New note added.
842 842
 		 * @param int $donor_id Donor id.
843 843
 		 */
844
-		do_action( 'give_donor_post_add_note', $this->notes, $new_note, $this->id );
844
+		do_action('give_donor_post_add_note', $this->notes, $new_note, $this->id);
845 845
 
846 846
 		// Return the formatted note, so we can test, as well as update any displays
847 847
 		return $new_note;
@@ -858,7 +858,7 @@  discard block
 block discarded – undo
858 858
 	 */
859 859
 	private function get_raw_notes() {
860 860
 
861
-		$all_notes = $this->db->get_column( 'notes', $this->id );
861
+		$all_notes = $this->db->get_column('notes', $this->id);
862 862
 
863 863
 		return $all_notes;
864 864
 
@@ -875,8 +875,8 @@  discard block
 block discarded – undo
875 875
 	 *
876 876
 	 * @return mixed            Will be an array if $single is false. Will be value of meta data field if $single is true.
877 877
 	 */
878
-	public function get_meta( $meta_key = '', $single = true ) {
879
-		return Give()->donor_meta->get_meta( $this->id, $meta_key, $single );
878
+	public function get_meta($meta_key = '', $single = true) {
879
+		return Give()->donor_meta->get_meta($this->id, $meta_key, $single);
880 880
 	}
881 881
 
882 882
 	/**
@@ -891,8 +891,8 @@  discard block
 block discarded – undo
891 891
 	 *
892 892
 	 * @return bool               False for failure. True for success.
893 893
 	 */
894
-	public function add_meta( $meta_key = '', $meta_value, $unique = false ) {
895
-		return Give()->donor_meta->add_meta( $this->id, $meta_key, $meta_value, $unique );
894
+	public function add_meta($meta_key = '', $meta_value, $unique = false) {
895
+		return Give()->donor_meta->add_meta($this->id, $meta_key, $meta_value, $unique);
896 896
 	}
897 897
 
898 898
 	/**
@@ -907,8 +907,8 @@  discard block
 block discarded – undo
907 907
 	 *
908 908
 	 * @return bool               False on failure, true if success.
909 909
 	 */
910
-	public function update_meta( $meta_key = '', $meta_value, $prev_value = '' ) {
911
-		return Give()->donor_meta->update_meta( $this->id, $meta_key, $meta_value, $prev_value );
910
+	public function update_meta($meta_key = '', $meta_value, $prev_value = '') {
911
+		return Give()->donor_meta->update_meta($this->id, $meta_key, $meta_value, $prev_value);
912 912
 	}
913 913
 
914 914
 	/**
@@ -922,8 +922,8 @@  discard block
 block discarded – undo
922 922
 	 *
923 923
 	 * @return bool               False for failure. True for success.
924 924
 	 */
925
-	public function delete_meta( $meta_key = '', $meta_value = '' ) {
926
-		return Give()->donor_meta->delete_meta( $this->id, $meta_key, $meta_value );
925
+	public function delete_meta($meta_key = '', $meta_value = '') {
926
+		return Give()->donor_meta->delete_meta($this->id, $meta_key, $meta_value);
927 927
 	}
928 928
 
929 929
 	/**
@@ -936,51 +936,51 @@  discard block
 block discarded – undo
936 936
 	 *
937 937
 	 * @return array       The sanitized data, based off column defaults.
938 938
 	 */
939
-	private function sanitize_columns( $data ) {
939
+	private function sanitize_columns($data) {
940 940
 
941 941
 		$columns        = $this->db->get_columns();
942 942
 		$default_values = $this->db->get_column_defaults();
943 943
 
944
-		foreach ( $columns as $key => $type ) {
944
+		foreach ($columns as $key => $type) {
945 945
 
946 946
 			// Only sanitize data that we were provided
947
-			if ( ! array_key_exists( $key, $data ) ) {
947
+			if ( ! array_key_exists($key, $data)) {
948 948
 				continue;
949 949
 			}
950 950
 
951
-			switch ( $type ) {
951
+			switch ($type) {
952 952
 
953 953
 				case '%s':
954
-					if ( 'email' == $key ) {
955
-						$data[ $key ] = sanitize_email( $data[ $key ] );
956
-					} elseif ( 'notes' == $key ) {
957
-						$data[ $key ] = strip_tags( $data[ $key ] );
954
+					if ('email' == $key) {
955
+						$data[$key] = sanitize_email($data[$key]);
956
+					} elseif ('notes' == $key) {
957
+						$data[$key] = strip_tags($data[$key]);
958 958
 					} else {
959
-						$data[ $key ] = sanitize_text_field( $data[ $key ] );
959
+						$data[$key] = sanitize_text_field($data[$key]);
960 960
 					}
961 961
 					break;
962 962
 
963 963
 				case '%d':
964
-					if ( ! is_numeric( $data[ $key ] ) || (int) $data[ $key ] !== absint( $data[ $key ] ) ) {
965
-						$data[ $key ] = $default_values[ $key ];
964
+					if ( ! is_numeric($data[$key]) || (int) $data[$key] !== absint($data[$key])) {
965
+						$data[$key] = $default_values[$key];
966 966
 					} else {
967
-						$data[ $key ] = absint( $data[ $key ] );
967
+						$data[$key] = absint($data[$key]);
968 968
 					}
969 969
 					break;
970 970
 
971 971
 				case '%f':
972 972
 					// Convert what was given to a float
973
-					$value = floatval( $data[ $key ] );
973
+					$value = floatval($data[$key]);
974 974
 
975
-					if ( ! is_float( $value ) ) {
976
-						$data[ $key ] = $default_values[ $key ];
975
+					if ( ! is_float($value)) {
976
+						$data[$key] = $default_values[$key];
977 977
 					} else {
978
-						$data[ $key ] = $value;
978
+						$data[$key] = $value;
979 979
 					}
980 980
 					break;
981 981
 
982 982
 				default:
983
-					$data[ $key ] = sanitize_text_field( $data[ $key ] );
983
+					$data[$key] = sanitize_text_field($data[$key]);
984 984
 					break;
985 985
 
986 986
 			}
@@ -1000,33 +1000,33 @@  discard block
 block discarded – undo
1000 1000
 	 *
1001 1001
 	 * @return bool            If the email was added successfully
1002 1002
 	 */
1003
-	public function add_email( $email = '', $primary = false ) {
1004
-		if ( ! is_email( $email ) ) {
1003
+	public function add_email($email = '', $primary = false) {
1004
+		if ( ! is_email($email)) {
1005 1005
 			return false;
1006 1006
 		}
1007
-		$existing = new Give_Donor( $email );
1007
+		$existing = new Give_Donor($email);
1008 1008
 
1009
-		if ( $existing->id > 0 ) {
1009
+		if ($existing->id > 0) {
1010 1010
 			// Email address already belongs to another donor
1011 1011
 			return false;
1012 1012
 		}
1013 1013
 
1014
-		if ( email_exists( $email ) ) {
1015
-			$user = get_user_by( 'email', $email );
1016
-			if ( $user->ID != $this->user_id ) {
1014
+		if (email_exists($email)) {
1015
+			$user = get_user_by('email', $email);
1016
+			if ($user->ID != $this->user_id) {
1017 1017
 				return false;
1018 1018
 			}
1019 1019
 		}
1020 1020
 
1021
-		do_action( 'give_donor_pre_add_email', $email, $this->id, $this );
1021
+		do_action('give_donor_pre_add_email', $email, $this->id, $this);
1022 1022
 
1023 1023
 		// Add is used to ensure duplicate emails are not added
1024
-		$ret = (bool) $this->add_meta( 'additional_email', $email );
1024
+		$ret = (bool) $this->add_meta('additional_email', $email);
1025 1025
 
1026
-		do_action( 'give_donor_post_add_email', $email, $this->id, $this );
1026
+		do_action('give_donor_post_add_email', $email, $this->id, $this);
1027 1027
 
1028
-		if ( $ret && true === $primary ) {
1029
-			$this->set_primary_email( $email );
1028
+		if ($ret && true === $primary) {
1029
+			$this->set_primary_email($email);
1030 1030
 		}
1031 1031
 
1032 1032
 		return $ret;
@@ -1042,16 +1042,16 @@  discard block
 block discarded – undo
1042 1042
 	 *
1043 1043
 	 * @return bool          If the email was removed successfully.
1044 1044
 	 */
1045
-	public function remove_email( $email = '' ) {
1046
-		if ( ! is_email( $email ) ) {
1045
+	public function remove_email($email = '') {
1046
+		if ( ! is_email($email)) {
1047 1047
 			return false;
1048 1048
 		}
1049 1049
 
1050
-		do_action( 'give_donor_pre_remove_email', $email, $this->id, $this );
1050
+		do_action('give_donor_pre_remove_email', $email, $this->id, $this);
1051 1051
 
1052
-		$ret = (bool) $this->delete_meta( 'additional_email', $email );
1052
+		$ret = (bool) $this->delete_meta('additional_email', $email);
1053 1053
 
1054
-		do_action( 'give_donor_post_remove_email', $email, $this->id, $this );
1054
+		do_action('give_donor_post_remove_email', $email, $this->id, $this);
1055 1055
 
1056 1056
 		return $ret;
1057 1057
 	}
@@ -1068,16 +1068,16 @@  discard block
 block discarded – undo
1068 1068
 	 *
1069 1069
 	 * @return bool                      If the email was set as primary successfully.
1070 1070
 	 */
1071
-	public function set_primary_email( $new_primary_email = '' ) {
1072
-		if ( ! is_email( $new_primary_email ) ) {
1071
+	public function set_primary_email($new_primary_email = '') {
1072
+		if ( ! is_email($new_primary_email)) {
1073 1073
 			return false;
1074 1074
 		}
1075 1075
 
1076
-		do_action( 'give_donor_pre_set_primary_email', $new_primary_email, $this->id, $this );
1076
+		do_action('give_donor_pre_set_primary_email', $new_primary_email, $this->id, $this);
1077 1077
 
1078
-		$existing = new Give_Donor( $new_primary_email );
1078
+		$existing = new Give_Donor($new_primary_email);
1079 1079
 
1080
-		if ( $existing->id > 0 && (int) $existing->id !== (int) $this->id ) {
1080
+		if ($existing->id > 0 && (int) $existing->id !== (int) $this->id) {
1081 1081
 			// This email belongs to another donor.
1082 1082
 			return false;
1083 1083
 		}
@@ -1085,21 +1085,21 @@  discard block
 block discarded – undo
1085 1085
 		$old_email = $this->email;
1086 1086
 
1087 1087
 		// Update donor record with new email.
1088
-		$update = $this->update( array( 'email' => $new_primary_email ) );
1088
+		$update = $this->update(array('email' => $new_primary_email));
1089 1089
 
1090 1090
 		// Remove new primary from list of additional emails.
1091
-		$remove = $this->remove_email( $new_primary_email );
1091
+		$remove = $this->remove_email($new_primary_email);
1092 1092
 
1093 1093
 		// Add old email to additional emails list.
1094
-		$add = $this->add_email( $old_email );
1094
+		$add = $this->add_email($old_email);
1095 1095
 
1096 1096
 		$ret = $update && $remove && $add;
1097 1097
 
1098
-		if ( $ret ) {
1098
+		if ($ret) {
1099 1099
 			$this->email = $new_primary_email;
1100 1100
 		}
1101 1101
 
1102
-		do_action( 'give_donor_post_set_primary_email', $new_primary_email, $this->id, $this );
1102
+		do_action('give_donor_post_set_primary_email', $new_primary_email, $this->id, $this);
1103 1103
 
1104 1104
 		return $ret;
1105 1105
 	}
Please login to merge, or discard this patch.
includes/payments/functions.php 2 patches
Doc Comments   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -697,7 +697,7 @@  discard block
 block discarded – undo
697 697
  * @param  int $year Year number. Default is null.
698 698
  * @param  int $hour Hour number. Default is null.
699 699
  *
700
- * @return int $earnings  Earnings
700
+ * @return double $earnings  Earnings
701 701
  */
702 702
 function give_get_earnings_by_date( $day = null, $month_num, $year = null, $hour = null ) {
703 703
 
@@ -986,7 +986,7 @@  discard block
 block discarded – undo
986 986
  *
987 987
  * @param int $payment_id Payment ID.
988 988
  *
989
- * @return array $user_info User Info Meta Values.
989
+ * @return string $user_info User Info Meta Values.
990 990
  */
991 991
 function give_get_payment_meta_user_info( $payment_id ) {
992 992
 	$payment = new Give_Payment( $payment_id );
@@ -1003,7 +1003,7 @@  discard block
 block discarded – undo
1003 1003
  *
1004 1004
  * @param int $payment_id Payment ID.
1005 1005
  *
1006
- * @return int $form_id Form ID.
1006
+ * @return string $form_id Form ID.
1007 1007
  */
1008 1008
 function give_get_payment_form_id( $payment_id ) {
1009 1009
 	$payment = new Give_Payment( $payment_id );
Please login to merge, or discard this patch.
Spacing   +416 added lines, -416 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
 
@@ -43,15 +43,15 @@  discard block
 block discarded – undo
43 43
  *
44 44
  * @return array $payments Payments retrieved from the database
45 45
  */
46
-function give_get_payments( $args = array() ) {
46
+function give_get_payments($args = array()) {
47 47
 
48 48
 	// Fallback to post objects to ensure backwards compatibility.
49
-	if ( ! isset( $args['output'] ) ) {
49
+	if ( ! isset($args['output'])) {
50 50
 		$args['output'] = 'posts';
51 51
 	}
52 52
 
53
-	$args     = apply_filters( 'give_get_payments_args', $args );
54
-	$payments = new Give_Payments_Query( $args );
53
+	$args     = apply_filters('give_get_payments_args', $args);
54
+	$payments = new Give_Payments_Query($args);
55 55
 
56 56
 	return $payments->get_payments();
57 57
 }
@@ -66,48 +66,48 @@  discard block
 block discarded – undo
66 66
  *
67 67
  * @return mixed
68 68
  */
69
-function give_get_payment_by( $field = '', $value = '' ) {
69
+function give_get_payment_by($field = '', $value = '') {
70 70
 
71
-	if ( empty( $field ) || empty( $value ) ) {
71
+	if (empty($field) || empty($value)) {
72 72
 		return false;
73 73
 	}
74 74
 
75
-	switch ( strtolower( $field ) ) {
75
+	switch (strtolower($field)) {
76 76
 
77 77
 		case 'id':
78
-			$payment = new Give_Payment( $value );
78
+			$payment = new Give_Payment($value);
79 79
 			$id      = $payment->ID;
80 80
 
81
-			if ( empty( $id ) ) {
81
+			if (empty($id)) {
82 82
 				return false;
83 83
 			}
84 84
 
85 85
 			break;
86 86
 
87 87
 		case 'key':
88
-			$payment = give_get_payments( array(
88
+			$payment = give_get_payments(array(
89 89
 				'meta_key'       => '_give_payment_purchase_key',
90 90
 				'meta_value'     => $value,
91 91
 				'posts_per_page' => 1,
92 92
 				'fields'         => 'ids',
93
-			) );
93
+			));
94 94
 
95
-			if ( $payment ) {
96
-				$payment = new Give_Payment( $payment[0] );
95
+			if ($payment) {
96
+				$payment = new Give_Payment($payment[0]);
97 97
 			}
98 98
 
99 99
 			break;
100 100
 
101 101
 		case 'payment_number':
102
-			$payment = give_get_payments( array(
102
+			$payment = give_get_payments(array(
103 103
 				'meta_key'       => '_give_payment_number',
104 104
 				'meta_value'     => $value,
105 105
 				'posts_per_page' => 1,
106 106
 				'fields'         => 'ids',
107
-			) );
107
+			));
108 108
 
109
-			if ( $payment ) {
110
-				$payment = new Give_Payment( $payment[0] );
109
+			if ($payment) {
110
+				$payment = new Give_Payment($payment[0]);
111 111
 			}
112 112
 
113 113
 			break;
@@ -116,7 +116,7 @@  discard block
 block discarded – undo
116 116
 			return false;
117 117
 	}// End switch().
118 118
 
119
-	if ( $payment ) {
119
+	if ($payment) {
120 120
 		return $payment;
121 121
 	}
122 122
 
@@ -132,29 +132,29 @@  discard block
 block discarded – undo
132 132
  *
133 133
  * @return int|bool Payment ID if payment is inserted, false otherwise.
134 134
  */
135
-function give_insert_payment( $payment_data = array() ) {
135
+function give_insert_payment($payment_data = array()) {
136 136
 
137
-	if ( empty( $payment_data ) ) {
137
+	if (empty($payment_data)) {
138 138
 		return false;
139 139
 	}
140 140
 
141 141
 	$payment    = new Give_Payment();
142
-	$gateway    = ! empty( $payment_data['gateway'] ) ? $payment_data['gateway'] : '';
143
-	$gateway    = empty( $gateway ) && isset( $_POST['give-gateway'] ) ? $_POST['give-gateway'] : $gateway;
144
-	$form_id    = isset( $payment_data['give_form_id'] ) ? $payment_data['give_form_id'] : 0;
145
-	$price_id   = give_get_payment_meta_price_id( $payment_data );
146
-	$form_title = isset( $payment_data['give_form_title'] ) ? $payment_data['give_form_title'] : get_the_title( $form_id );
142
+	$gateway    = ! empty($payment_data['gateway']) ? $payment_data['gateway'] : '';
143
+	$gateway    = empty($gateway) && isset($_POST['give-gateway']) ? $_POST['give-gateway'] : $gateway;
144
+	$form_id    = isset($payment_data['give_form_id']) ? $payment_data['give_form_id'] : 0;
145
+	$price_id   = give_get_payment_meta_price_id($payment_data);
146
+	$form_title = isset($payment_data['give_form_title']) ? $payment_data['give_form_title'] : get_the_title($form_id);
147 147
 
148 148
 	// Set properties.
149 149
 	$payment->total          = $payment_data['price'];
150
-	$payment->status         = ! empty( $payment_data['status'] ) ? $payment_data['status'] : 'pending';
151
-	$payment->currency       = ! empty( $payment_data['currency'] ) ? $payment_data['currency'] : give_get_currency();
150
+	$payment->status         = ! empty($payment_data['status']) ? $payment_data['status'] : 'pending';
151
+	$payment->currency       = ! empty($payment_data['currency']) ? $payment_data['currency'] : give_get_currency();
152 152
 	$payment->user_info      = $payment_data['user_info'];
153 153
 	$payment->gateway        = $gateway;
154 154
 	$payment->form_title     = $form_title;
155 155
 	$payment->form_id        = $form_id;
156 156
 	$payment->price_id       = $price_id;
157
-	$payment->donor_id       = ( ! empty( $payment_data['donor_id'] ) ? $payment_data['donor_id'] : '' );
157
+	$payment->donor_id       = ( ! empty($payment_data['donor_id']) ? $payment_data['donor_id'] : '');
158 158
 	$payment->user_id        = $payment_data['user_info']['id'];
159 159
 	$payment->email          = $payment_data['user_email'];
160 160
 	$payment->first_name     = $payment_data['user_info']['first_name'];
@@ -162,8 +162,8 @@  discard block
 block discarded – undo
162 162
 	$payment->email          = $payment_data['user_info']['email'];
163 163
 	$payment->ip             = give_get_ip();
164 164
 	$payment->key            = $payment_data['purchase_key'];
165
-	$payment->mode           = ( ! empty( $payment_data['mode'] ) ? (string) $payment_data['mode'] : ( give_is_test_mode() ? 'test' : 'live' ) );
166
-	$payment->parent_payment = ! empty( $payment_data['parent'] ) ? absint( $payment_data['parent'] ) : '';
165
+	$payment->mode           = ( ! empty($payment_data['mode']) ? (string) $payment_data['mode'] : (give_is_test_mode() ? 'test' : 'live'));
166
+	$payment->parent_payment = ! empty($payment_data['parent']) ? absint($payment_data['parent']) : '';
167 167
 
168 168
 	// Add the donation.
169 169
 	$args = array(
@@ -171,19 +171,19 @@  discard block
 block discarded – undo
171 171
 		'price_id' => $payment->price_id,
172 172
 	);
173 173
 
174
-	$payment->add_donation( $payment->form_id, $args );
174
+	$payment->add_donation($payment->form_id, $args);
175 175
 
176 176
 
177 177
 	// Set date if present.
178
-	if ( isset( $payment_data['post_date'] ) ) {
178
+	if (isset($payment_data['post_date'])) {
179 179
 		$payment->date = $payment_data['post_date'];
180 180
 	}
181 181
 
182 182
 	// Handle sequential payments.
183
-	if ( give_get_option( 'enable_sequential' ) ) {
183
+	if (give_get_option('enable_sequential')) {
184 184
 		$number          = give_get_next_payment_number();
185
-		$payment->number = give_format_payment_number( $number );
186
-		update_option( 'give_last_payment_number', $number );
185
+		$payment->number = give_format_payment_number($number);
186
+		update_option('give_last_payment_number', $number);
187 187
 	}
188 188
 
189 189
 	// Save payment.
@@ -197,10 +197,10 @@  discard block
 block discarded – undo
197 197
 	 * @param int $payment_id The payment ID.
198 198
 	 * @param array $payment_data Arguments passed.
199 199
 	 */
200
-	do_action( 'give_insert_payment', $payment->ID, $payment_data );
200
+	do_action('give_insert_payment', $payment->ID, $payment_data);
201 201
 
202 202
 	// Return payment ID upon success.
203
-	if ( ! empty( $payment->ID ) ) {
203
+	if ( ! empty($payment->ID)) {
204 204
 		return $payment->ID;
205 205
 	}
206 206
 
@@ -216,10 +216,10 @@  discard block
 block discarded – undo
216 216
  *
217 217
  * @return bool|int
218 218
  */
219
-function give_create_payment( $payment_data ) {
219
+function give_create_payment($payment_data) {
220 220
 
221
-	$form_id  = intval( $payment_data['post_data']['give-form-id'] );
222
-	$price_id = isset( $payment_data['post_data']['give-price-id'] ) ? $payment_data['post_data']['give-price-id'] : '';
221
+	$form_id  = intval($payment_data['post_data']['give-form-id']);
222
+	$price_id = isset($payment_data['post_data']['give-price-id']) ? $payment_data['post_data']['give-price-id'] : '';
223 223
 
224 224
 	// Collect payment data.
225 225
 	$insert_payment_data = array(
@@ -243,10 +243,10 @@  discard block
 block discarded – undo
243 243
 	 *
244 244
 	 * @param array $insert_payment_data
245 245
 	 */
246
-	$insert_payment_data = apply_filters( 'give_create_payment', $insert_payment_data );
246
+	$insert_payment_data = apply_filters('give_create_payment', $insert_payment_data);
247 247
 
248 248
 	// Record the pending payment.
249
-	return give_insert_payment( $insert_payment_data );
249
+	return give_insert_payment($insert_payment_data);
250 250
 }
251 251
 
252 252
 /**
@@ -259,12 +259,12 @@  discard block
 block discarded – undo
259 259
  *
260 260
  * @return bool
261 261
  */
262
-function give_update_payment_status( $payment_id, $new_status = 'publish' ) {
262
+function give_update_payment_status($payment_id, $new_status = 'publish') {
263 263
 
264 264
 	$updated = false;
265
-	$payment = new Give_Payment( $payment_id );
265
+	$payment = new Give_Payment($payment_id);
266 266
 
267
-	if ( $payment && $payment->ID > 0 ) {
267
+	if ($payment && $payment->ID > 0) {
268 268
 
269 269
 		$payment->status = $new_status;
270 270
 		$updated         = $payment->save();
@@ -286,38 +286,38 @@  discard block
 block discarded – undo
286 286
  *
287 287
  * @return void
288 288
  */
289
-function give_delete_donation( $payment_id = 0, $update_donor = true ) {
289
+function give_delete_donation($payment_id = 0, $update_donor = true) {
290 290
 	global $give_logs;
291 291
 
292
-	$payment  = new Give_Payment( $payment_id );
293
-	$amount   = give_get_payment_amount( $payment_id );
292
+	$payment  = new Give_Payment($payment_id);
293
+	$amount   = give_get_payment_amount($payment_id);
294 294
 	$status   = $payment->post_status;
295
-	$donor_id = give_get_payment_donor_id( $payment_id );
296
-	$donor    = new Give_Donor( $donor_id );
295
+	$donor_id = give_get_payment_donor_id($payment_id);
296
+	$donor    = new Give_Donor($donor_id);
297 297
 
298 298
 	// Only undo donations that aren't these statuses.
299
-	$dont_undo_statuses = apply_filters( 'give_undo_donation_statuses', array(
299
+	$dont_undo_statuses = apply_filters('give_undo_donation_statuses', array(
300 300
 		'pending',
301 301
 		'cancelled',
302
-	) );
302
+	));
303 303
 
304
-	if ( ! in_array( $status, $dont_undo_statuses ) ) {
305
-		give_undo_donation( $payment_id );
304
+	if ( ! in_array($status, $dont_undo_statuses)) {
305
+		give_undo_donation($payment_id);
306 306
 	}
307 307
 
308
-	if ( $status == 'publish' ) {
308
+	if ($status == 'publish') {
309 309
 
310 310
 		// Only decrease earnings if they haven't already been decreased (or were never increased for this payment).
311
-		give_decrease_total_earnings( $amount );
311
+		give_decrease_total_earnings($amount);
312 312
 
313 313
 		// @todo: Refresh only range related stat cache
314 314
 		give_delete_donation_stats();
315 315
 
316
-		if ( $donor->id && $update_donor ) {
316
+		if ($donor->id && $update_donor) {
317 317
 
318 318
 			// Decrement the stats for the donor.
319 319
 			$donor->decrease_donation_count();
320
-			$donor->decrease_value( $amount );
320
+			$donor->decrease_value($amount);
321 321
 
322 322
 		}
323 323
 	}
@@ -329,25 +329,25 @@  discard block
 block discarded – undo
329 329
 	 *
330 330
 	 * @param int $payment_id Payment ID.
331 331
 	 */
332
-	do_action( 'give_payment_delete', $payment_id );
332
+	do_action('give_payment_delete', $payment_id);
333 333
 
334
-	if ( $donor->id && $update_donor ) {
334
+	if ($donor->id && $update_donor) {
335 335
 
336 336
 		// Remove the payment ID from the donor.
337
-		$donor->remove_payment( $payment_id );
337
+		$donor->remove_payment($payment_id);
338 338
 
339 339
 	}
340 340
 
341 341
 	// Remove the payment.
342
-	wp_delete_post( $payment_id, true );
342
+	wp_delete_post($payment_id, true);
343 343
 
344 344
 	// Remove related sale log entries.
345
-	$give_logs->delete_logs( null, 'sale', array(
345
+	$give_logs->delete_logs(null, 'sale', array(
346 346
 		array(
347 347
 			'key'   => '_give_log_payment_id',
348 348
 			'value' => $payment_id,
349 349
 		),
350
-	) );
350
+	));
351 351
 
352 352
 	/**
353 353
 	 * Fires after payment deleted.
@@ -356,7 +356,7 @@  discard block
 block discarded – undo
356 356
 	 *
357 357
 	 * @param int $payment_id Payment ID.
358 358
 	 */
359
-	do_action( 'give_payment_deleted', $payment_id );
359
+	do_action('give_payment_deleted', $payment_id);
360 360
 }
361 361
 
362 362
 /**
@@ -371,20 +371,20 @@  discard block
 block discarded – undo
371 371
  *
372 372
  * @return void
373 373
  */
374
-function give_undo_donation( $payment_id ) {
374
+function give_undo_donation($payment_id) {
375 375
 
376
-	$payment = new Give_Payment( $payment_id );
376
+	$payment = new Give_Payment($payment_id);
377 377
 
378
-	$maybe_decrease_earnings = apply_filters( 'give_decrease_earnings_on_undo', true, $payment, $payment->form_id );
379
-	if ( true === $maybe_decrease_earnings ) {
378
+	$maybe_decrease_earnings = apply_filters('give_decrease_earnings_on_undo', true, $payment, $payment->form_id);
379
+	if (true === $maybe_decrease_earnings) {
380 380
 		// Decrease earnings.
381
-		give_decrease_earnings( $payment->form_id, $payment->total );
381
+		give_decrease_earnings($payment->form_id, $payment->total);
382 382
 	}
383 383
 
384
-	$maybe_decrease_donations = apply_filters( 'give_decrease_donations_on_undo', true, $payment, $payment->form_id );
385
-	if ( true === $maybe_decrease_donations ) {
384
+	$maybe_decrease_donations = apply_filters('give_decrease_donations_on_undo', true, $payment, $payment->form_id);
385
+	if (true === $maybe_decrease_donations) {
386 386
 		// Decrease donation count.
387
-		give_decrease_donation_count( $payment->form_id );
387
+		give_decrease_donation_count($payment->form_id);
388 388
 	}
389 389
 
390 390
 }
@@ -401,7 +401,7 @@  discard block
 block discarded – undo
401 401
  *
402 402
  * @return object $stats Contains the number of payments per payment status.
403 403
  */
404
-function give_count_payments( $args = array() ) {
404
+function give_count_payments($args = array()) {
405 405
 
406 406
 	global $wpdb;
407 407
 
@@ -413,18 +413,18 @@  discard block
 block discarded – undo
413 413
 		'form_id'    => null,
414 414
 	);
415 415
 
416
-	$args = wp_parse_args( $args, $defaults );
416
+	$args = wp_parse_args($args, $defaults);
417 417
 
418 418
 	$select = 'SELECT p.post_status,count( * ) AS num_posts';
419 419
 	$join   = '';
420
-	$where  = "WHERE p.post_type = 'give_payment' AND p.post_status IN ('" . implode( "','", give_get_payment_status_keys() ) . "')";
420
+	$where  = "WHERE p.post_type = 'give_payment' AND p.post_status IN ('".implode("','", give_get_payment_status_keys())."')";
421 421
 
422 422
 	// Count payments for a specific user.
423
-	if ( ! empty( $args['user'] ) ) {
423
+	if ( ! empty($args['user'])) {
424 424
 
425
-		if ( is_email( $args['user'] ) ) {
425
+		if (is_email($args['user'])) {
426 426
 			$field = 'email';
427
-		} elseif ( is_numeric( $args['user'] ) ) {
427
+		} elseif (is_numeric($args['user'])) {
428 428
 			$field = 'id';
429 429
 		} else {
430 430
 			$field = '';
@@ -432,107 +432,107 @@  discard block
 block discarded – undo
432 432
 
433 433
 		$join = "LEFT JOIN $wpdb->postmeta m ON (p.ID = m.post_id)";
434 434
 
435
-		if ( ! empty( $field ) ) {
435
+		if ( ! empty($field)) {
436 436
 			$where .= "
437 437
 				AND m.meta_key = '_give_payment_user_{$field}'
438 438
 				AND m.meta_value = '{$args['user']}'";
439 439
 		}
440
-	} elseif ( ! empty( $args['donor'] ) ) {
440
+	} elseif ( ! empty($args['donor'])) {
441 441
 
442
-		$join  = "LEFT JOIN $wpdb->postmeta m ON (p.ID = m.post_id)";
442
+		$join = "LEFT JOIN $wpdb->postmeta m ON (p.ID = m.post_id)";
443 443
 		$where .= "
444 444
 			AND m.meta_key = '_give_payment_customer_id'
445 445
 			AND m.meta_value = '{$args['donor']}'";
446 446
 
447 447
 		// Count payments for a search.
448
-	} elseif ( ! empty( $args['s'] ) ) {
448
+	} elseif ( ! empty($args['s'])) {
449 449
 
450
-		if ( is_email( $args['s'] ) || strlen( $args['s'] ) == 32 ) {
450
+		if (is_email($args['s']) || strlen($args['s']) == 32) {
451 451
 
452
-			if ( is_email( $args['s'] ) ) {
452
+			if (is_email($args['s'])) {
453 453
 				$field = '_give_payment_user_email';
454 454
 			} else {
455 455
 				$field = '_give_payment_purchase_key';
456 456
 			}
457 457
 
458
-			$join  = "LEFT JOIN $wpdb->postmeta m ON (p.ID = m.post_id)";
459
-			$where .= $wpdb->prepare( '
458
+			$join = "LEFT JOIN $wpdb->postmeta m ON (p.ID = m.post_id)";
459
+			$where .= $wpdb->prepare('
460 460
                 AND m.meta_key = %s
461
-                AND m.meta_value = %s', $field, $args['s'] );
461
+                AND m.meta_value = %s', $field, $args['s']);
462 462
 
463
-		} elseif ( '#' == substr( $args['s'], 0, 1 ) ) {
463
+		} elseif ('#' == substr($args['s'], 0, 1)) {
464 464
 
465
-			$search = str_replace( '#:', '', $args['s'] );
466
-			$search = str_replace( '#', '', $search );
465
+			$search = str_replace('#:', '', $args['s']);
466
+			$search = str_replace('#', '', $search);
467 467
 
468 468
 			$select = 'SELECT p.post_status,count( * ) AS num_posts ';
469 469
 			$join   = '';
470
-			$where  = $wpdb->prepare( 'WHERE p.post_type=%s  AND p.ID = %d ', 'give_payment', $search );
470
+			$where  = $wpdb->prepare('WHERE p.post_type=%s  AND p.ID = %d ', 'give_payment', $search);
471 471
 
472
-		} elseif ( is_numeric( $args['s'] ) ) {
472
+		} elseif (is_numeric($args['s'])) {
473 473
 
474
-			$join  = "LEFT JOIN $wpdb->postmeta m ON (p.ID = m.post_id)";
475
-			$where .= $wpdb->prepare( "
474
+			$join = "LEFT JOIN $wpdb->postmeta m ON (p.ID = m.post_id)";
475
+			$where .= $wpdb->prepare("
476 476
 				AND m.meta_key = '_give_payment_user_id'
477
-				AND m.meta_value = %d", $args['s'] );
477
+				AND m.meta_value = %d", $args['s']);
478 478
 
479 479
 		} else {
480
-			$search = $wpdb->esc_like( $args['s'] );
481
-			$search = '%' . $search . '%';
480
+			$search = $wpdb->esc_like($args['s']);
481
+			$search = '%'.$search.'%';
482 482
 
483
-			$where .= $wpdb->prepare( 'AND ((p.post_title LIKE %s) OR (p.post_content LIKE %s))', $search, $search );
483
+			$where .= $wpdb->prepare('AND ((p.post_title LIKE %s) OR (p.post_content LIKE %s))', $search, $search);
484 484
 		}// End if().
485 485
 	}// End if().
486 486
 
487
-	if ( ! empty( $args['form_id'] ) && is_numeric( $args['form_id'] ) ) {
487
+	if ( ! empty($args['form_id']) && is_numeric($args['form_id'])) {
488 488
 
489
-		$join  = "LEFT JOIN $wpdb->postmeta m ON (p.ID = m.post_id)";
490
-		$where .= $wpdb->prepare( '
489
+		$join = "LEFT JOIN $wpdb->postmeta m ON (p.ID = m.post_id)";
490
+		$where .= $wpdb->prepare('
491 491
                 AND m.meta_key = %s
492
-                AND m.meta_value = %s', '_give_payment_form_id', $args['form_id'] );
492
+                AND m.meta_value = %s', '_give_payment_form_id', $args['form_id']);
493 493
 	}
494 494
 
495 495
 	// Limit payments count by date.
496
-	if ( ! empty( $args['start-date'] ) && false !== strpos( $args['start-date'], '/' ) ) {
496
+	if ( ! empty($args['start-date']) && false !== strpos($args['start-date'], '/')) {
497 497
 
498
-		$date_parts = explode( '/', $args['start-date'] );
499
-		$month      = ! empty( $date_parts[0] ) && is_numeric( $date_parts[0] ) ? $date_parts[0] : 0;
500
-		$day        = ! empty( $date_parts[1] ) && is_numeric( $date_parts[1] ) ? $date_parts[1] : 0;
501
-		$year       = ! empty( $date_parts[2] ) && is_numeric( $date_parts[2] ) ? $date_parts[2] : 0;
498
+		$date_parts = explode('/', $args['start-date']);
499
+		$month      = ! empty($date_parts[0]) && is_numeric($date_parts[0]) ? $date_parts[0] : 0;
500
+		$day        = ! empty($date_parts[1]) && is_numeric($date_parts[1]) ? $date_parts[1] : 0;
501
+		$year       = ! empty($date_parts[2]) && is_numeric($date_parts[2]) ? $date_parts[2] : 0;
502 502
 
503
-		$is_date = checkdate( $month, $day, $year );
504
-		if ( false !== $is_date ) {
503
+		$is_date = checkdate($month, $day, $year);
504
+		if (false !== $is_date) {
505 505
 
506
-			$date  = new DateTime( $args['start-date'] );
507
-			$where .= $wpdb->prepare( " AND p.post_date >= '%s'", $date->format( 'Y-m-d' ) );
506
+			$date = new DateTime($args['start-date']);
507
+			$where .= $wpdb->prepare(" AND p.post_date >= '%s'", $date->format('Y-m-d'));
508 508
 
509 509
 		}
510 510
 
511 511
 		// Fixes an issue with the payments list table counts when no end date is specified (with stats class).
512
-		if ( empty( $args['end-date'] ) ) {
512
+		if (empty($args['end-date'])) {
513 513
 			$args['end-date'] = $args['start-date'];
514 514
 		}
515 515
 	}
516 516
 
517
-	if ( ! empty( $args['end-date'] ) && false !== strpos( $args['end-date'], '/' ) ) {
517
+	if ( ! empty($args['end-date']) && false !== strpos($args['end-date'], '/')) {
518 518
 
519
-		$date_parts = explode( '/', $args['end-date'] );
519
+		$date_parts = explode('/', $args['end-date']);
520 520
 
521
-		$month = ! empty( $date_parts[0] ) ? $date_parts[0] : 0;
522
-		$day   = ! empty( $date_parts[1] ) ? $date_parts[1] : 0;
523
-		$year  = ! empty( $date_parts[2] ) ? $date_parts[2] : 0;
521
+		$month = ! empty($date_parts[0]) ? $date_parts[0] : 0;
522
+		$day   = ! empty($date_parts[1]) ? $date_parts[1] : 0;
523
+		$year  = ! empty($date_parts[2]) ? $date_parts[2] : 0;
524 524
 
525
-		$is_date = checkdate( $month, $day, $year );
526
-		if ( false !== $is_date ) {
525
+		$is_date = checkdate($month, $day, $year);
526
+		if (false !== $is_date) {
527 527
 
528
-			$date  = new DateTime( $args['end-date'] );
529
-			$where .= $wpdb->prepare( " AND p.post_date <= '%s'", $date->format( 'Y-m-d' ) );
528
+			$date = new DateTime($args['end-date']);
529
+			$where .= $wpdb->prepare(" AND p.post_date <= '%s'", $date->format('Y-m-d'));
530 530
 
531 531
 		}
532 532
 	}
533 533
 
534
-	$where = apply_filters( 'give_count_payments_where', $where );
535
-	$join  = apply_filters( 'give_count_payments_join', $join );
534
+	$where = apply_filters('give_count_payments_where', $where);
535
+	$join  = apply_filters('give_count_payments_join', $join);
536 536
 
537 537
 	$query = "$select
538 538
 		FROM $wpdb->posts p
@@ -541,36 +541,36 @@  discard block
 block discarded – undo
541 541
 		GROUP BY p.post_status
542 542
 	";
543 543
 
544
-	$cache_key = md5( $query );
544
+	$cache_key = md5($query);
545 545
 
546
-	$count = wp_cache_get( $cache_key, 'counts' );
547
-	if ( false !== $count ) {
546
+	$count = wp_cache_get($cache_key, 'counts');
547
+	if (false !== $count) {
548 548
 		return $count;
549 549
 	}
550 550
 
551
-	$count = $wpdb->get_results( $query, ARRAY_A );
551
+	$count = $wpdb->get_results($query, ARRAY_A);
552 552
 
553 553
 	$stats    = array();
554 554
 	$statuses = get_post_stati();
555
-	if ( isset( $statuses['private'] ) && empty( $args['s'] ) ) {
556
-		unset( $statuses['private'] );
555
+	if (isset($statuses['private']) && empty($args['s'])) {
556
+		unset($statuses['private']);
557 557
 	}
558 558
 
559
-	foreach ( $statuses as $state ) {
560
-		$stats[ $state ] = 0;
559
+	foreach ($statuses as $state) {
560
+		$stats[$state] = 0;
561 561
 	}
562 562
 
563
-	foreach ( (array) $count as $row ) {
563
+	foreach ((array) $count as $row) {
564 564
 
565
-		if ( 'private' == $row['post_status'] && empty( $args['s'] ) ) {
565
+		if ('private' == $row['post_status'] && empty($args['s'])) {
566 566
 			continue;
567 567
 		}
568 568
 
569
-		$stats[ $row['post_status'] ] = $row['num_posts'];
569
+		$stats[$row['post_status']] = $row['num_posts'];
570 570
 	}
571 571
 
572 572
 	$stats = (object) $stats;
573
-	wp_cache_set( $cache_key, $stats, 'counts' );
573
+	wp_cache_set($cache_key, $stats, 'counts');
574 574
 
575 575
 	return $stats;
576 576
 }
@@ -585,11 +585,11 @@  discard block
 block discarded – undo
585 585
  *
586 586
  * @return bool $exists True if payment exists, false otherwise.
587 587
  */
588
-function give_check_for_existing_payment( $payment_id ) {
588
+function give_check_for_existing_payment($payment_id) {
589 589
 	$exists  = false;
590
-	$payment = new Give_Payment( $payment_id );
590
+	$payment = new Give_Payment($payment_id);
591 591
 
592
-	if ( $payment_id === $payment->ID && 'publish' === $payment->status ) {
592
+	if ($payment_id === $payment->ID && 'publish' === $payment->status) {
593 593
 		$exists = true;
594 594
 	}
595 595
 
@@ -607,41 +607,41 @@  discard block
 block discarded – undo
607 607
  *
608 608
  * @return bool|mixed True if payment status exists, false otherwise.
609 609
  */
610
-function give_get_payment_status( $payment, $return_label = false ) {
610
+function give_get_payment_status($payment, $return_label = false) {
611 611
 
612
-	if ( is_numeric( $payment ) ) {
612
+	if (is_numeric($payment)) {
613 613
 
614
-		$payment = new Give_Payment( $payment );
614
+		$payment = new Give_Payment($payment);
615 615
 
616
-		if ( ! $payment->ID > 0 ) {
616
+		if ( ! $payment->ID > 0) {
617 617
 			return false;
618 618
 		}
619 619
 
620 620
 	}
621 621
 
622
-	if ( ! is_object( $payment ) || ! isset( $payment->post_status ) ) {
622
+	if ( ! is_object($payment) || ! isset($payment->post_status)) {
623 623
 		return false;
624 624
 	}
625 625
 
626 626
 	$statuses = give_get_payment_statuses();
627 627
 
628
-	if ( ! is_array( $statuses ) || empty( $statuses ) ) {
628
+	if ( ! is_array($statuses) || empty($statuses)) {
629 629
 		return false;
630 630
 	}
631 631
 
632 632
 	// Get payment object if not already given.
633
-	$payment = $payment instanceof Give_Payment ? $payment : new Give_Payment( $payment->ID );
633
+	$payment = $payment instanceof Give_Payment ? $payment : new Give_Payment($payment->ID);
634 634
 
635
-	if ( array_key_exists( $payment->status, $statuses ) ) {
636
-		if ( true === $return_label ) {
635
+	if (array_key_exists($payment->status, $statuses)) {
636
+		if (true === $return_label) {
637 637
 			// Return translated status label.
638
-			return $statuses[ $payment->status ];
638
+			return $statuses[$payment->status];
639 639
 		} else {
640 640
 			// Account that our 'publish' status is labeled 'Complete'
641 641
 			$post_status = 'publish' == $payment->status ? 'Complete' : $payment->post_status;
642 642
 
643 643
 			// Make sure we're matching cases, since they matter
644
-			return array_search( strtolower( $post_status ), array_map( 'strtolower', $statuses ) );
644
+			return array_search(strtolower($post_status), array_map('strtolower', $statuses));
645 645
 		}
646 646
 	}
647 647
 
@@ -657,18 +657,18 @@  discard block
 block discarded – undo
657 657
  */
658 658
 function give_get_payment_statuses() {
659 659
 	$payment_statuses = array(
660
-		'pending'     => __( 'Pending', 'give' ),
661
-		'publish'     => __( 'Complete', 'give' ),
662
-		'refunded'    => __( 'Refunded', 'give' ),
663
-		'failed'      => __( 'Failed', 'give' ),
664
-		'cancelled'   => __( 'Cancelled', 'give' ),
665
-		'abandoned'   => __( 'Abandoned', 'give' ),
666
-		'preapproval' => __( 'Pre-Approved', 'give' ),
667
-		'processing'  => __( 'Processing', 'give' ),
668
-		'revoked'     => __( 'Revoked', 'give' ),
660
+		'pending'     => __('Pending', 'give'),
661
+		'publish'     => __('Complete', 'give'),
662
+		'refunded'    => __('Refunded', 'give'),
663
+		'failed'      => __('Failed', 'give'),
664
+		'cancelled'   => __('Cancelled', 'give'),
665
+		'abandoned'   => __('Abandoned', 'give'),
666
+		'preapproval' => __('Pre-Approved', 'give'),
667
+		'processing'  => __('Processing', 'give'),
668
+		'revoked'     => __('Revoked', 'give'),
669 669
 	);
670 670
 
671
-	return apply_filters( 'give_payment_statuses', $payment_statuses );
671
+	return apply_filters('give_payment_statuses', $payment_statuses);
672 672
 }
673 673
 
674 674
 /**
@@ -681,10 +681,10 @@  discard block
 block discarded – undo
681 681
  * @return array $payment_status All the available payment statuses.
682 682
  */
683 683
 function give_get_payment_status_keys() {
684
-	$statuses = array_keys( give_get_payment_statuses() );
685
-	asort( $statuses );
684
+	$statuses = array_keys(give_get_payment_statuses());
685
+	asort($statuses);
686 686
 
687
-	return array_values( $statuses );
687
+	return array_values($statuses);
688 688
 }
689 689
 
690 690
 /**
@@ -699,7 +699,7 @@  discard block
 block discarded – undo
699 699
  *
700 700
  * @return int $earnings  Earnings
701 701
  */
702
-function give_get_earnings_by_date( $day = null, $month_num, $year = null, $hour = null ) {
702
+function give_get_earnings_by_date($day = null, $month_num, $year = null, $hour = null) {
703 703
 
704 704
 	// This is getting deprecated soon. Use Give_Payment_Stats with the get_earnings() method instead.
705 705
 	global $wpdb;
@@ -709,41 +709,41 @@  discard block
 block discarded – undo
709 709
 		'nopaging'               => true,
710 710
 		'year'                   => $year,
711 711
 		'monthnum'               => $month_num,
712
-		'post_status'            => array( 'publish' ),
712
+		'post_status'            => array('publish'),
713 713
 		'fields'                 => 'ids',
714 714
 		'update_post_term_cache' => false,
715 715
 	);
716
-	if ( ! empty( $day ) ) {
716
+	if ( ! empty($day)) {
717 717
 		$args['day'] = $day;
718 718
 	}
719 719
 
720
-	if ( ! empty( $hour ) ) {
720
+	if ( ! empty($hour)) {
721 721
 		$args['hour'] = $hour;
722 722
 	}
723 723
 
724
-	$args = apply_filters( 'give_get_earnings_by_date_args', $args );
725
-	$key  = Give_Cache::get_key( 'give_stats', $args );
724
+	$args = apply_filters('give_get_earnings_by_date_args', $args);
725
+	$key  = Give_Cache::get_key('give_stats', $args);
726 726
 
727
-	if ( ! empty( $_GET['_wpnonce'] ) && wp_verify_nonce( $_GET['_wpnonce'], 'give-refresh-reports' ) ) {
727
+	if ( ! empty($_GET['_wpnonce']) && wp_verify_nonce($_GET['_wpnonce'], 'give-refresh-reports')) {
728 728
 		$earnings = false;
729 729
 	} else {
730
-		$earnings = Give_Cache::get( $key );
730
+		$earnings = Give_Cache::get($key);
731 731
 	}
732 732
 
733
-	if ( false === $earnings ) {
734
-		$donations = get_posts( $args );
733
+	if (false === $earnings) {
734
+		$donations = get_posts($args);
735 735
 		$earnings  = 0;
736
-		if ( $donations ) {
737
-			$donations = implode( ',', $donations );
736
+		if ($donations) {
737
+			$donations = implode(',', $donations);
738 738
 
739
-			$earnings = $wpdb->get_var( "SELECT SUM(meta_value) FROM $wpdb->postmeta WHERE meta_key = '_give_payment_total' AND post_id IN ({$donations})" );
739
+			$earnings = $wpdb->get_var("SELECT SUM(meta_value) FROM $wpdb->postmeta WHERE meta_key = '_give_payment_total' AND post_id IN ({$donations})");
740 740
 
741 741
 		}
742 742
 		// Cache the results for one hour.
743
-		Give_Cache::set( $key, $earnings, HOUR_IN_SECONDS );
743
+		Give_Cache::set($key, $earnings, HOUR_IN_SECONDS);
744 744
 	}
745 745
 
746
-	return round( $earnings, 2 );
746
+	return round($earnings, 2);
747 747
 }
748 748
 
749 749
 /**
@@ -758,7 +758,7 @@  discard block
 block discarded – undo
758 758
  *
759 759
  * @return int $count     Sales
760 760
  */
761
-function give_get_sales_by_date( $day = null, $month_num = null, $year = null, $hour = null ) {
761
+function give_get_sales_by_date($day = null, $month_num = null, $year = null, $hour = null) {
762 762
 
763 763
 	// This is getting deprecated soon. Use Give_Payment_Stats with the get_sales() method instead.
764 764
 	$args = array(
@@ -766,14 +766,14 @@  discard block
 block discarded – undo
766 766
 		'nopaging'               => true,
767 767
 		'year'                   => $year,
768 768
 		'fields'                 => 'ids',
769
-		'post_status'            => array( 'publish' ),
769
+		'post_status'            => array('publish'),
770 770
 		'update_post_meta_cache' => false,
771 771
 		'update_post_term_cache' => false,
772 772
 	);
773 773
 
774
-	$show_free = apply_filters( 'give_sales_by_date_show_free', true, $args );
774
+	$show_free = apply_filters('give_sales_by_date_show_free', true, $args);
775 775
 
776
-	if ( false === $show_free ) {
776
+	if (false === $show_free) {
777 777
 		$args['meta_query'] = array(
778 778
 			array(
779 779
 				'key'     => '_give_payment_total',
@@ -784,33 +784,33 @@  discard block
 block discarded – undo
784 784
 		);
785 785
 	}
786 786
 
787
-	if ( ! empty( $month_num ) ) {
787
+	if ( ! empty($month_num)) {
788 788
 		$args['monthnum'] = $month_num;
789 789
 	}
790 790
 
791
-	if ( ! empty( $day ) ) {
791
+	if ( ! empty($day)) {
792 792
 		$args['day'] = $day;
793 793
 	}
794 794
 
795
-	if ( ! empty( $hour ) ) {
795
+	if ( ! empty($hour)) {
796 796
 		$args['hour'] = $hour;
797 797
 	}
798 798
 
799
-	$args = apply_filters( 'give_get_sales_by_date_args', $args );
799
+	$args = apply_filters('give_get_sales_by_date_args', $args);
800 800
 
801
-	$key = Give_Cache::get_key( 'give_stats', $args );
801
+	$key = Give_Cache::get_key('give_stats', $args);
802 802
 
803
-	if ( ! empty( $_GET['_wpnonce'] ) && wp_verify_nonce( $_GET['_wpnonce'], 'give-refresh-reports' ) ) {
803
+	if ( ! empty($_GET['_wpnonce']) && wp_verify_nonce($_GET['_wpnonce'], 'give-refresh-reports')) {
804 804
 		$count = false;
805 805
 	} else {
806
-		$count = Give_Cache::get( $key );
806
+		$count = Give_Cache::get($key);
807 807
 	}
808 808
 
809
-	if ( false === $count ) {
810
-		$donations = new WP_Query( $args );
809
+	if (false === $count) {
810
+		$donations = new WP_Query($args);
811 811
 		$count     = (int) $donations->post_count;
812 812
 		// Cache the results for one hour.
813
-		Give_Cache::set( $key, $count, HOUR_IN_SECONDS );
813
+		Give_Cache::set($key, $count, HOUR_IN_SECONDS);
814 814
 	}
815 815
 
816 816
 	return $count;
@@ -825,19 +825,19 @@  discard block
 block discarded – undo
825 825
  *
826 826
  * @return bool $ret True if complete, false otherwise.
827 827
  */
828
-function give_is_payment_complete( $payment_id ) {
829
-	$payment = new Give_Payment( $payment_id );
828
+function give_is_payment_complete($payment_id) {
829
+	$payment = new Give_Payment($payment_id);
830 830
 
831 831
 	$ret = false;
832 832
 
833
-	if ( $payment->ID > 0 ) {
833
+	if ($payment->ID > 0) {
834 834
 
835
-		if ( (int) $payment_id === (int) $payment->ID && 'publish' == $payment->status ) {
835
+		if ((int) $payment_id === (int) $payment->ID && 'publish' == $payment->status) {
836 836
 			$ret = true;
837 837
 		}
838 838
 	}
839 839
 
840
-	return apply_filters( 'give_is_payment_complete', $ret, $payment_id, $payment->post_status );
840
+	return apply_filters('give_is_payment_complete', $ret, $payment_id, $payment->post_status);
841 841
 }
842 842
 
843 843
 /**
@@ -863,49 +863,49 @@  discard block
 block discarded – undo
863 863
  *
864 864
  * @return float $total Total earnings.
865 865
  */
866
-function give_get_total_earnings( $recalculate = false ) {
866
+function give_get_total_earnings($recalculate = false) {
867 867
 
868
-	$total = get_option( 'give_earnings_total', 0 );
868
+	$total = get_option('give_earnings_total', 0);
869 869
 
870 870
 	// Calculate total earnings.
871
-	if ( ! $total || $recalculate ) {
871
+	if ( ! $total || $recalculate) {
872 872
 		global $wpdb;
873 873
 
874 874
 		$total = (float) 0;
875 875
 
876
-		$args = apply_filters( 'give_get_total_earnings_args', array(
876
+		$args = apply_filters('give_get_total_earnings_args', array(
877 877
 			'offset' => 0,
878
-			'number' => - 1,
879
-			'status' => array( 'publish' ),
878
+			'number' => -1,
879
+			'status' => array('publish'),
880 880
 			'fields' => 'ids',
881
-		) );
881
+		));
882 882
 
883
-		$payments = give_get_payments( $args );
884
-		if ( $payments ) {
883
+		$payments = give_get_payments($args);
884
+		if ($payments) {
885 885
 
886 886
 			/**
887 887
 			 * If performing a donation, we need to skip the very last payment in the database,
888 888
 			 * since it calls give_increase_total_earnings() on completion,
889 889
 			 * which results in duplicated earnings for the very first donation.
890 890
 			 */
891
-			if ( did_action( 'give_update_payment_status' ) ) {
892
-				array_pop( $payments );
891
+			if (did_action('give_update_payment_status')) {
892
+				array_pop($payments);
893 893
 			}
894 894
 
895
-			if ( ! empty( $payments ) ) {
896
-				$payments = implode( ',', $payments );
897
-				$total    += $wpdb->get_var( "SELECT SUM(meta_value) FROM $wpdb->postmeta WHERE meta_key = '_give_payment_total' AND post_id IN({$payments})" );
895
+			if ( ! empty($payments)) {
896
+				$payments = implode(',', $payments);
897
+				$total += $wpdb->get_var("SELECT SUM(meta_value) FROM $wpdb->postmeta WHERE meta_key = '_give_payment_total' AND post_id IN({$payments})");
898 898
 			}
899 899
 		}
900 900
 
901
-		update_option( 'give_earnings_total', $total, 'no' );
901
+		update_option('give_earnings_total', $total, 'no');
902 902
 	}
903 903
 
904
-	if ( $total < 0 ) {
904
+	if ($total < 0) {
905 905
 		$total = 0; // Don't ever show negative earnings.
906 906
 	}
907 907
 
908
-	return apply_filters( 'give_total_earnings', round( $total, give_currency_decimal_filter() ) );
908
+	return apply_filters('give_total_earnings', round($total, give_currency_decimal_filter()));
909 909
 }
910 910
 
911 911
 /**
@@ -918,10 +918,10 @@  discard block
 block discarded – undo
918 918
  *
919 919
  * @return float $total  Total earnings.
920 920
  */
921
-function give_increase_total_earnings( $amount = 0 ) {
921
+function give_increase_total_earnings($amount = 0) {
922 922
 	$total = give_get_total_earnings();
923 923
 	$total += $amount;
924
-	update_option( 'give_earnings_total', $total );
924
+	update_option('give_earnings_total', $total);
925 925
 
926 926
 	return $total;
927 927
 }
@@ -935,13 +935,13 @@  discard block
 block discarded – undo
935 935
  *
936 936
  * @return float $total Total earnings.
937 937
  */
938
-function give_decrease_total_earnings( $amount = 0 ) {
938
+function give_decrease_total_earnings($amount = 0) {
939 939
 	$total = give_get_total_earnings();
940 940
 	$total -= $amount;
941
-	if ( $total < 0 ) {
941
+	if ($total < 0) {
942 942
 		$total = 0;
943 943
 	}
944
-	update_option( 'give_earnings_total', $total );
944
+	update_option('give_earnings_total', $total);
945 945
 
946 946
 	return $total;
947 947
 }
@@ -957,10 +957,10 @@  discard block
 block discarded – undo
957 957
  *
958 958
  * @return mixed $meta Payment Meta.
959 959
  */
960
-function give_get_payment_meta( $payment_id = 0, $meta_key = '_give_payment_meta', $single = true ) {
961
-	$payment = new Give_Payment( $payment_id );
960
+function give_get_payment_meta($payment_id = 0, $meta_key = '_give_payment_meta', $single = true) {
961
+	$payment = new Give_Payment($payment_id);
962 962
 
963
-	return $payment->get_meta( $meta_key, $single );
963
+	return $payment->get_meta($meta_key, $single);
964 964
 }
965 965
 
966 966
 /**
@@ -973,10 +973,10 @@  discard block
 block discarded – undo
973 973
  *
974 974
  * @return mixed Meta ID if successful, false if unsuccessful.
975 975
  */
976
-function give_update_payment_meta( $payment_id = 0, $meta_key = '', $meta_value = '', $prev_value = '' ) {
977
-	$payment = new Give_Payment( $payment_id );
976
+function give_update_payment_meta($payment_id = 0, $meta_key = '', $meta_value = '', $prev_value = '') {
977
+	$payment = new Give_Payment($payment_id);
978 978
 
979
-	return $payment->update_meta( $meta_key, $meta_value, $prev_value );
979
+	return $payment->update_meta($meta_key, $meta_value, $prev_value);
980 980
 }
981 981
 
982 982
 /**
@@ -988,8 +988,8 @@  discard block
 block discarded – undo
988 988
  *
989 989
  * @return array $user_info User Info Meta Values.
990 990
  */
991
-function give_get_payment_meta_user_info( $payment_id ) {
992
-	$payment = new Give_Payment( $payment_id );
991
+function give_get_payment_meta_user_info($payment_id) {
992
+	$payment = new Give_Payment($payment_id);
993 993
 
994 994
 	return $payment->user_info;
995 995
 }
@@ -1005,8 +1005,8 @@  discard block
 block discarded – undo
1005 1005
  *
1006 1006
  * @return int $form_id Form ID.
1007 1007
  */
1008
-function give_get_payment_form_id( $payment_id ) {
1009
-	$payment = new Give_Payment( $payment_id );
1008
+function give_get_payment_form_id($payment_id) {
1009
+	$payment = new Give_Payment($payment_id);
1010 1010
 
1011 1011
 	return $payment->form_id;
1012 1012
 }
@@ -1020,8 +1020,8 @@  discard block
 block discarded – undo
1020 1020
  *
1021 1021
  * @return string $email User email.
1022 1022
  */
1023
-function give_get_payment_user_email( $payment_id ) {
1024
-	$payment = new Give_Payment( $payment_id );
1023
+function give_get_payment_user_email($payment_id) {
1024
+	$payment = new Give_Payment($payment_id);
1025 1025
 
1026 1026
 	return $payment->email;
1027 1027
 }
@@ -1035,11 +1035,11 @@  discard block
 block discarded – undo
1035 1035
  *
1036 1036
  * @return bool $is_guest_payment If the payment is associated with a user (false) or not (true)
1037 1037
  */
1038
-function give_is_guest_payment( $payment_id ) {
1039
-	$payment_user_id  = give_get_payment_user_id( $payment_id );
1040
-	$is_guest_payment = ! empty( $payment_user_id ) && $payment_user_id > 0 ? false : true;
1038
+function give_is_guest_payment($payment_id) {
1039
+	$payment_user_id  = give_get_payment_user_id($payment_id);
1040
+	$is_guest_payment = ! empty($payment_user_id) && $payment_user_id > 0 ? false : true;
1041 1041
 
1042
-	return (bool) apply_filters( 'give_is_guest_payment', $is_guest_payment, $payment_id );
1042
+	return (bool) apply_filters('give_is_guest_payment', $is_guest_payment, $payment_id);
1043 1043
 }
1044 1044
 
1045 1045
 /**
@@ -1051,8 +1051,8 @@  discard block
 block discarded – undo
1051 1051
  *
1052 1052
  * @return int $user_id User ID.
1053 1053
  */
1054
-function give_get_payment_user_id( $payment_id ) {
1055
-	$payment = new Give_Payment( $payment_id );
1054
+function give_get_payment_user_id($payment_id) {
1055
+	$payment = new Give_Payment($payment_id);
1056 1056
 
1057 1057
 	return $payment->user_id;
1058 1058
 }
@@ -1066,8 +1066,8 @@  discard block
 block discarded – undo
1066 1066
  *
1067 1067
  * @return int $payment->customer_id Donor ID.
1068 1068
  */
1069
-function give_get_payment_donor_id( $payment_id ) {
1070
-	$payment = new Give_Payment( $payment_id );
1069
+function give_get_payment_donor_id($payment_id) {
1070
+	$payment = new Give_Payment($payment_id);
1071 1071
 
1072 1072
 	return $payment->customer_id;
1073 1073
 }
@@ -1081,8 +1081,8 @@  discard block
 block discarded – undo
1081 1081
  *
1082 1082
  * @return string $ip User IP.
1083 1083
  */
1084
-function give_get_payment_user_ip( $payment_id ) {
1085
-	$payment = new Give_Payment( $payment_id );
1084
+function give_get_payment_user_ip($payment_id) {
1085
+	$payment = new Give_Payment($payment_id);
1086 1086
 
1087 1087
 	return $payment->ip;
1088 1088
 }
@@ -1096,8 +1096,8 @@  discard block
 block discarded – undo
1096 1096
  *
1097 1097
  * @return string $date The date the payment was completed.
1098 1098
  */
1099
-function give_get_payment_completed_date( $payment_id = 0 ) {
1100
-	$payment = new Give_Payment( $payment_id );
1099
+function give_get_payment_completed_date($payment_id = 0) {
1100
+	$payment = new Give_Payment($payment_id);
1101 1101
 
1102 1102
 	return $payment->completed_date;
1103 1103
 }
@@ -1111,8 +1111,8 @@  discard block
 block discarded – undo
1111 1111
  *
1112 1112
  * @return string $gateway Gateway.
1113 1113
  */
1114
-function give_get_payment_gateway( $payment_id ) {
1115
-	$payment = new Give_Payment( $payment_id );
1114
+function give_get_payment_gateway($payment_id) {
1115
+	$payment = new Give_Payment($payment_id);
1116 1116
 
1117 1117
 	return $payment->gateway;
1118 1118
 }
@@ -1126,8 +1126,8 @@  discard block
 block discarded – undo
1126 1126
  *
1127 1127
  * @return string $currency The currency code.
1128 1128
  */
1129
-function give_get_payment_currency_code( $payment_id = 0 ) {
1130
-	$payment = new Give_Payment( $payment_id );
1129
+function give_get_payment_currency_code($payment_id = 0) {
1130
+	$payment = new Give_Payment($payment_id);
1131 1131
 
1132 1132
 	return $payment->currency;
1133 1133
 }
@@ -1141,10 +1141,10 @@  discard block
 block discarded – undo
1141 1141
  *
1142 1142
  * @return string $currency The currency name.
1143 1143
  */
1144
-function give_get_payment_currency( $payment_id = 0 ) {
1145
-	$currency = give_get_payment_currency_code( $payment_id );
1144
+function give_get_payment_currency($payment_id = 0) {
1145
+	$currency = give_get_payment_currency_code($payment_id);
1146 1146
 
1147
-	return apply_filters( 'give_payment_currency', give_get_currency_name( $currency ), $payment_id );
1147
+	return apply_filters('give_payment_currency', give_get_currency_name($currency), $payment_id);
1148 1148
 }
1149 1149
 
1150 1150
 /**
@@ -1156,8 +1156,8 @@  discard block
 block discarded – undo
1156 1156
  *
1157 1157
  * @return string $key Donation key.
1158 1158
  */
1159
-function give_get_payment_key( $payment_id = 0 ) {
1160
-	$payment = new Give_Payment( $payment_id );
1159
+function give_get_payment_key($payment_id = 0) {
1160
+	$payment = new Give_Payment($payment_id);
1161 1161
 
1162 1162
 	return $payment->key;
1163 1163
 }
@@ -1173,8 +1173,8 @@  discard block
 block discarded – undo
1173 1173
  *
1174 1174
  * @return string $number Payment order number.
1175 1175
  */
1176
-function give_get_payment_number( $payment_id = 0 ) {
1177
-	$payment = new Give_Payment( $payment_id );
1176
+function give_get_payment_number($payment_id = 0) {
1177
+	$payment = new Give_Payment($payment_id);
1178 1178
 
1179 1179
 	return $payment->number;
1180 1180
 }
@@ -1188,23 +1188,23 @@  discard block
 block discarded – undo
1188 1188
  *
1189 1189
  * @return string      The formatted payment number.
1190 1190
  */
1191
-function give_format_payment_number( $number ) {
1191
+function give_format_payment_number($number) {
1192 1192
 
1193
-	if ( ! give_get_option( 'enable_sequential' ) ) {
1193
+	if ( ! give_get_option('enable_sequential')) {
1194 1194
 		return $number;
1195 1195
 	}
1196 1196
 
1197
-	if ( ! is_numeric( $number ) ) {
1197
+	if ( ! is_numeric($number)) {
1198 1198
 		return $number;
1199 1199
 	}
1200 1200
 
1201
-	$prefix  = give_get_option( 'sequential_prefix' );
1202
-	$number  = absint( $number );
1203
-	$postfix = give_get_option( 'sequential_postfix' );
1201
+	$prefix  = give_get_option('sequential_prefix');
1202
+	$number  = absint($number);
1203
+	$postfix = give_get_option('sequential_postfix');
1204 1204
 
1205
-	$formatted_number = $prefix . $number . $postfix;
1205
+	$formatted_number = $prefix.$number.$postfix;
1206 1206
 
1207
-	return apply_filters( 'give_format_payment_number', $formatted_number, $prefix, $number, $postfix );
1207
+	return apply_filters('give_format_payment_number', $formatted_number, $prefix, $number, $postfix);
1208 1208
 }
1209 1209
 
1210 1210
 /**
@@ -1217,17 +1217,17 @@  discard block
 block discarded – undo
1217 1217
  */
1218 1218
 function give_get_next_payment_number() {
1219 1219
 
1220
-	if ( ! give_get_option( 'enable_sequential' ) ) {
1220
+	if ( ! give_get_option('enable_sequential')) {
1221 1221
 		return false;
1222 1222
 	}
1223 1223
 
1224
-	$number           = get_option( 'give_last_payment_number' );
1225
-	$start            = give_get_option( 'sequential_start', 1 );
1224
+	$number           = get_option('give_last_payment_number');
1225
+	$start            = give_get_option('sequential_start', 1);
1226 1226
 	$increment_number = true;
1227 1227
 
1228
-	if ( false !== $number ) {
1228
+	if (false !== $number) {
1229 1229
 
1230
-		if ( empty( $number ) ) {
1230
+		if (empty($number)) {
1231 1231
 
1232 1232
 			$number           = $start;
1233 1233
 			$increment_number = false;
@@ -1236,24 +1236,24 @@  discard block
 block discarded – undo
1236 1236
 	} else {
1237 1237
 
1238 1238
 		// This case handles the first addition of the new option, as well as if it get's deleted for any reason.
1239
-		$payments     = new Give_Payments_Query( array(
1239
+		$payments = new Give_Payments_Query(array(
1240 1240
 			'number'  => 1,
1241 1241
 			'order'   => 'DESC',
1242 1242
 			'orderby' => 'ID',
1243 1243
 			'output'  => 'posts',
1244 1244
 			'fields'  => 'ids',
1245
-		) );
1245
+		));
1246 1246
 		$last_payment = $payments->get_payments();
1247 1247
 
1248
-		if ( ! empty( $last_payment ) ) {
1248
+		if ( ! empty($last_payment)) {
1249 1249
 
1250
-			$number = give_get_payment_number( $last_payment[0] );
1250
+			$number = give_get_payment_number($last_payment[0]);
1251 1251
 
1252 1252
 		}
1253 1253
 
1254
-		if ( ! empty( $number ) && $number !== (int) $last_payment[0] ) {
1254
+		if ( ! empty($number) && $number !== (int) $last_payment[0]) {
1255 1255
 
1256
-			$number = give_remove_payment_prefix_postfix( $number );
1256
+			$number = give_remove_payment_prefix_postfix($number);
1257 1257
 
1258 1258
 		} else {
1259 1259
 
@@ -1262,13 +1262,13 @@  discard block
 block discarded – undo
1262 1262
 		}
1263 1263
 	}// End if().
1264 1264
 
1265
-	$increment_number = apply_filters( 'give_increment_payment_number', $increment_number, $number );
1265
+	$increment_number = apply_filters('give_increment_payment_number', $increment_number, $number);
1266 1266
 
1267
-	if ( $increment_number ) {
1268
-		$number ++;
1267
+	if ($increment_number) {
1268
+		$number++;
1269 1269
 	}
1270 1270
 
1271
-	return apply_filters( 'give_get_next_payment_number', $number );
1271
+	return apply_filters('give_get_next_payment_number', $number);
1272 1272
 }
1273 1273
 
1274 1274
 /**
@@ -1280,25 +1280,25 @@  discard block
 block discarded – undo
1280 1280
  *
1281 1281
  * @return string The new Payment number without prefix and postfix.
1282 1282
  */
1283
-function give_remove_payment_prefix_postfix( $number ) {
1283
+function give_remove_payment_prefix_postfix($number) {
1284 1284
 
1285
-	$prefix  = give_get_option( 'sequential_prefix' );
1286
-	$postfix = give_get_option( 'sequential_postfix' );
1285
+	$prefix  = give_get_option('sequential_prefix');
1286
+	$postfix = give_get_option('sequential_postfix');
1287 1287
 
1288 1288
 	// Remove prefix.
1289
-	$number = preg_replace( '/' . $prefix . '/', '', $number, 1 );
1289
+	$number = preg_replace('/'.$prefix.'/', '', $number, 1);
1290 1290
 
1291 1291
 	// Remove the postfix.
1292
-	$length      = strlen( $number );
1293
-	$postfix_pos = strrpos( $number, $postfix );
1294
-	if ( false !== $postfix_pos ) {
1295
-		$number = substr_replace( $number, '', $postfix_pos, $length );
1292
+	$length      = strlen($number);
1293
+	$postfix_pos = strrpos($number, $postfix);
1294
+	if (false !== $postfix_pos) {
1295
+		$number = substr_replace($number, '', $postfix_pos, $length);
1296 1296
 	}
1297 1297
 
1298 1298
 	// Ensure it's a whole number.
1299
-	$number = intval( $number );
1299
+	$number = intval($number);
1300 1300
 
1301
-	return apply_filters( 'give_remove_payment_prefix_postfix', $number, $prefix, $postfix );
1301
+	return apply_filters('give_remove_payment_prefix_postfix', $number, $prefix, $postfix);
1302 1302
 
1303 1303
 }
1304 1304
 
@@ -1315,10 +1315,10 @@  discard block
 block discarded – undo
1315 1315
  *
1316 1316
  * @return string $amount Fully formatted payment amount.
1317 1317
  */
1318
-function give_payment_amount( $payment_id = 0 ) {
1319
-	$amount = give_get_payment_amount( $payment_id );
1318
+function give_payment_amount($payment_id = 0) {
1319
+	$amount = give_get_payment_amount($payment_id);
1320 1320
 
1321
-	return give_currency_filter( give_format_amount( $amount, array( 'sanitize' => false ) ), give_get_payment_currency_code( $payment_id ) );
1321
+	return give_currency_filter(give_format_amount($amount, array('sanitize' => false)), give_get_payment_currency_code($payment_id));
1322 1322
 }
1323 1323
 
1324 1324
 /**
@@ -1331,11 +1331,11 @@  discard block
 block discarded – undo
1331 1331
  *
1332 1332
  * @return mixed
1333 1333
  */
1334
-function give_get_payment_amount( $payment_id ) {
1334
+function give_get_payment_amount($payment_id) {
1335 1335
 
1336
-	$payment = new Give_Payment( $payment_id );
1336
+	$payment = new Give_Payment($payment_id);
1337 1337
 
1338
-	return apply_filters( 'give_payment_amount', floatval( $payment->total ), $payment_id );
1338
+	return apply_filters('give_payment_amount', floatval($payment->total), $payment_id);
1339 1339
 }
1340 1340
 
1341 1341
 /**
@@ -1352,10 +1352,10 @@  discard block
 block discarded – undo
1352 1352
  *
1353 1353
  * @return array Fully formatted payment subtotal.
1354 1354
  */
1355
-function give_payment_subtotal( $payment_id = 0 ) {
1356
-	$subtotal = give_get_payment_subtotal( $payment_id );
1355
+function give_payment_subtotal($payment_id = 0) {
1356
+	$subtotal = give_get_payment_subtotal($payment_id);
1357 1357
 
1358
-	return give_currency_filter( give_format_amount( $subtotal, array( 'sanitize' => false ) ), give_get_payment_currency_code( $payment_id ) );
1358
+	return give_currency_filter(give_format_amount($subtotal, array('sanitize' => false)), give_get_payment_currency_code($payment_id));
1359 1359
 }
1360 1360
 
1361 1361
 /**
@@ -1369,8 +1369,8 @@  discard block
 block discarded – undo
1369 1369
  *
1370 1370
  * @return float $subtotal Subtotal for payment (non formatted).
1371 1371
  */
1372
-function give_get_payment_subtotal( $payment_id = 0 ) {
1373
-	$payment = new Give_Payment( $payment_id );
1372
+function give_get_payment_subtotal($payment_id = 0) {
1373
+	$payment = new Give_Payment($payment_id);
1374 1374
 
1375 1375
 	return $payment->subtotal;
1376 1376
 }
@@ -1384,8 +1384,8 @@  discard block
 block discarded – undo
1384 1384
  *
1385 1385
  * @return string The donation ID.
1386 1386
  */
1387
-function give_get_payment_transaction_id( $payment_id = 0 ) {
1388
-	$payment = new Give_Payment( $payment_id );
1387
+function give_get_payment_transaction_id($payment_id = 0) {
1388
+	$payment = new Give_Payment($payment_id);
1389 1389
 
1390 1390
 	return $payment->transaction_id;
1391 1391
 }
@@ -1400,15 +1400,15 @@  discard block
 block discarded – undo
1400 1400
  *
1401 1401
  * @return bool|mixed
1402 1402
  */
1403
-function give_set_payment_transaction_id( $payment_id = 0, $transaction_id = '' ) {
1403
+function give_set_payment_transaction_id($payment_id = 0, $transaction_id = '') {
1404 1404
 
1405
-	if ( empty( $payment_id ) || empty( $transaction_id ) ) {
1405
+	if (empty($payment_id) || empty($transaction_id)) {
1406 1406
 		return false;
1407 1407
 	}
1408 1408
 
1409
-	$transaction_id = apply_filters( 'give_set_payment_transaction_id', $transaction_id, $payment_id );
1409
+	$transaction_id = apply_filters('give_set_payment_transaction_id', $transaction_id, $payment_id);
1410 1410
 
1411
-	return give_update_payment_meta( $payment_id, '_give_payment_transaction_id', $transaction_id );
1411
+	return give_update_payment_meta($payment_id, '_give_payment_transaction_id', $transaction_id);
1412 1412
 }
1413 1413
 
1414 1414
 /**
@@ -1421,12 +1421,12 @@  discard block
 block discarded – undo
1421 1421
  *
1422 1422
  * @return int $purchase Donation ID.
1423 1423
  */
1424
-function give_get_purchase_id_by_key( $key ) {
1424
+function give_get_purchase_id_by_key($key) {
1425 1425
 	global $wpdb;
1426 1426
 
1427
-	$purchase = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_give_payment_purchase_key' AND meta_value = %s LIMIT 1", $key ) );
1427
+	$purchase = $wpdb->get_var($wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_give_payment_purchase_key' AND meta_value = %s LIMIT 1", $key));
1428 1428
 
1429
-	if ( $purchase != null ) {
1429
+	if ($purchase != null) {
1430 1430
 		return $purchase;
1431 1431
 	}
1432 1432
 
@@ -1444,12 +1444,12 @@  discard block
 block discarded – undo
1444 1444
  *
1445 1445
  * @return int $purchase Donation ID.
1446 1446
  */
1447
-function give_get_purchase_id_by_transaction_id( $key ) {
1447
+function give_get_purchase_id_by_transaction_id($key) {
1448 1448
 	global $wpdb;
1449 1449
 
1450
-	$purchase = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_give_payment_transaction_id' AND meta_value = %s LIMIT 1", $key ) );
1450
+	$purchase = $wpdb->get_var($wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_give_payment_transaction_id' AND meta_value = %s LIMIT 1", $key));
1451 1451
 
1452
-	if ( $purchase != null ) {
1452
+	if ($purchase != null) {
1453 1453
 		return $purchase;
1454 1454
 	}
1455 1455
 
@@ -1466,23 +1466,23 @@  discard block
 block discarded – undo
1466 1466
  *
1467 1467
  * @return array $notes Donation Notes
1468 1468
  */
1469
-function give_get_payment_notes( $payment_id = 0, $search = '' ) {
1469
+function give_get_payment_notes($payment_id = 0, $search = '') {
1470 1470
 
1471
-	if ( empty( $payment_id ) && empty( $search ) ) {
1471
+	if (empty($payment_id) && empty($search)) {
1472 1472
 		return false;
1473 1473
 	}
1474 1474
 
1475
-	remove_action( 'pre_get_comments', 'give_hide_payment_notes', 10 );
1476
-	remove_filter( 'comments_clauses', 'give_hide_payment_notes_pre_41', 10 );
1475
+	remove_action('pre_get_comments', 'give_hide_payment_notes', 10);
1476
+	remove_filter('comments_clauses', 'give_hide_payment_notes_pre_41', 10);
1477 1477
 
1478
-	$notes = get_comments( array(
1478
+	$notes = get_comments(array(
1479 1479
 		'post_id' => $payment_id,
1480 1480
 		'order'   => 'ASC',
1481 1481
 		'search'  => $search,
1482
-	) );
1482
+	));
1483 1483
 
1484
-	add_action( 'pre_get_comments', 'give_hide_payment_notes', 10 );
1485
-	add_filter( 'comments_clauses', 'give_hide_payment_notes_pre_41', 10, 2 );
1484
+	add_action('pre_get_comments', 'give_hide_payment_notes', 10);
1485
+	add_filter('comments_clauses', 'give_hide_payment_notes_pre_41', 10, 2);
1486 1486
 
1487 1487
 	return $notes;
1488 1488
 }
@@ -1498,8 +1498,8 @@  discard block
 block discarded – undo
1498 1498
  *
1499 1499
  * @return int The new note ID
1500 1500
  */
1501
-function give_insert_payment_note( $payment_id = 0, $note = '' ) {
1502
-	if ( empty( $payment_id ) ) {
1501
+function give_insert_payment_note($payment_id = 0, $note = '') {
1502
+	if (empty($payment_id)) {
1503 1503
 		return false;
1504 1504
 	}
1505 1505
 
@@ -1511,14 +1511,14 @@  discard block
 block discarded – undo
1511 1511
 	 * @param int $payment_id Payment ID.
1512 1512
 	 * @param string $note The note.
1513 1513
 	 */
1514
-	do_action( 'give_pre_insert_payment_note', $payment_id, $note );
1514
+	do_action('give_pre_insert_payment_note', $payment_id, $note);
1515 1515
 
1516
-	$note_id = wp_insert_comment( wp_filter_comment( array(
1516
+	$note_id = wp_insert_comment(wp_filter_comment(array(
1517 1517
 		'comment_post_ID'      => $payment_id,
1518 1518
 		'comment_content'      => $note,
1519 1519
 		'user_id'              => is_admin() ? get_current_user_id() : 0,
1520
-		'comment_date'         => current_time( 'mysql' ),
1521
-		'comment_date_gmt'     => current_time( 'mysql', 1 ),
1520
+		'comment_date'         => current_time('mysql'),
1521
+		'comment_date_gmt'     => current_time('mysql', 1),
1522 1522
 		'comment_approved'     => 1,
1523 1523
 		'comment_parent'       => 0,
1524 1524
 		'comment_author'       => '',
@@ -1527,7 +1527,7 @@  discard block
 block discarded – undo
1527 1527
 		'comment_author_email' => '',
1528 1528
 		'comment_type'         => 'give_payment_note',
1529 1529
 
1530
-	) ) );
1530
+	)));
1531 1531
 
1532 1532
 	/**
1533 1533
 	 * Fires after payment note inserted.
@@ -1538,7 +1538,7 @@  discard block
 block discarded – undo
1538 1538
 	 * @param int $payment_id Payment ID.
1539 1539
 	 * @param string $note The note.
1540 1540
 	 */
1541
-	do_action( 'give_insert_payment_note', $note_id, $payment_id, $note );
1541
+	do_action('give_insert_payment_note', $note_id, $payment_id, $note);
1542 1542
 
1543 1543
 	return $note_id;
1544 1544
 }
@@ -1553,8 +1553,8 @@  discard block
 block discarded – undo
1553 1553
  *
1554 1554
  * @return bool True on success, false otherwise.
1555 1555
  */
1556
-function give_delete_payment_note( $comment_id = 0, $payment_id = 0 ) {
1557
-	if ( empty( $comment_id ) ) {
1556
+function give_delete_payment_note($comment_id = 0, $payment_id = 0) {
1557
+	if (empty($comment_id)) {
1558 1558
 		return false;
1559 1559
 	}
1560 1560
 
@@ -1566,9 +1566,9 @@  discard block
 block discarded – undo
1566 1566
 	 * @param int $comment_id Note ID.
1567 1567
 	 * @param int $payment_id Payment ID.
1568 1568
 	 */
1569
-	do_action( 'give_pre_delete_payment_note', $comment_id, $payment_id );
1569
+	do_action('give_pre_delete_payment_note', $comment_id, $payment_id);
1570 1570
 
1571
-	$ret = wp_delete_comment( $comment_id, true );
1571
+	$ret = wp_delete_comment($comment_id, true);
1572 1572
 
1573 1573
 	/**
1574 1574
 	 * Fires after donation note deleted.
@@ -1578,7 +1578,7 @@  discard block
 block discarded – undo
1578 1578
 	 * @param int $comment_id Note ID.
1579 1579
 	 * @param int $payment_id Payment ID.
1580 1580
 	 */
1581
-	do_action( 'give_post_delete_payment_note', $comment_id, $payment_id );
1581
+	do_action('give_post_delete_payment_note', $comment_id, $payment_id);
1582 1582
 
1583 1583
 	return $ret;
1584 1584
 }
@@ -1593,32 +1593,32 @@  discard block
 block discarded – undo
1593 1593
  *
1594 1594
  * @return string
1595 1595
  */
1596
-function give_get_payment_note_html( $note, $payment_id = 0 ) {
1596
+function give_get_payment_note_html($note, $payment_id = 0) {
1597 1597
 
1598
-	if ( is_numeric( $note ) ) {
1599
-		$note = get_comment( $note );
1598
+	if (is_numeric($note)) {
1599
+		$note = get_comment($note);
1600 1600
 	}
1601 1601
 
1602
-	if ( ! empty( $note->user_id ) ) {
1603
-		$user = get_userdata( $note->user_id );
1602
+	if ( ! empty($note->user_id)) {
1603
+		$user = get_userdata($note->user_id);
1604 1604
 		$user = $user->display_name;
1605 1605
 	} else {
1606
-		$user = esc_html__( 'System', 'give' );
1606
+		$user = esc_html__('System', 'give');
1607 1607
 	}
1608 1608
 
1609
-	$date_format = give_date_format() . ', ' . get_option( 'time_format' );
1609
+	$date_format = give_date_format().', '.get_option('time_format');
1610 1610
 
1611
-	$delete_note_url = wp_nonce_url( add_query_arg( array(
1611
+	$delete_note_url = wp_nonce_url(add_query_arg(array(
1612 1612
 		'give-action' => 'delete_payment_note',
1613 1613
 		'note_id'     => $note->comment_ID,
1614 1614
 		'payment_id'  => $payment_id,
1615
-	) ), 'give_delete_payment_note_' . $note->comment_ID );
1615
+	)), 'give_delete_payment_note_'.$note->comment_ID);
1616 1616
 
1617
-	$note_html = '<div class="give-payment-note" id="give-payment-note-' . $note->comment_ID . '">';
1617
+	$note_html = '<div class="give-payment-note" id="give-payment-note-'.$note->comment_ID.'">';
1618 1618
 	$note_html .= '<p>';
1619
-	$note_html .= '<strong>' . $user . '</strong>&nbsp;&ndash;&nbsp;<span style="color:#aaa;font-style:italic;">' . date_i18n( $date_format, strtotime( $note->comment_date ) ) . '</span><br/>';
1619
+	$note_html .= '<strong>'.$user.'</strong>&nbsp;&ndash;&nbsp;<span style="color:#aaa;font-style:italic;">'.date_i18n($date_format, strtotime($note->comment_date)).'</span><br/>';
1620 1620
 	$note_html .= $note->comment_content;
1621
-	$note_html .= '&nbsp;&ndash;&nbsp;<a href="' . esc_url( $delete_note_url ) . '" class="give-delete-payment-note" data-note-id="' . absint( $note->comment_ID ) . '" data-payment-id="' . absint( $payment_id ) . '" aria-label="' . esc_attr__( 'Delete this donation note.', 'give' ) . '">' . esc_html__( 'Delete', 'give' ) . '</a>';
1621
+	$note_html .= '&nbsp;&ndash;&nbsp;<a href="'.esc_url($delete_note_url).'" class="give-delete-payment-note" data-note-id="'.absint($note->comment_ID).'" data-payment-id="'.absint($payment_id).'" aria-label="'.esc_attr__('Delete this donation note.', 'give').'">'.esc_html__('Delete', 'give').'</a>';
1622 1622
 	$note_html .= '</p>';
1623 1623
 	$note_html .= '</div>';
1624 1624
 
@@ -1636,18 +1636,18 @@  discard block
 block discarded – undo
1636 1636
  *
1637 1637
  * @return void
1638 1638
  */
1639
-function give_hide_payment_notes( $query ) {
1640
-	if ( version_compare( floatval( get_bloginfo( 'version' ) ), '4.1', '>=' ) ) {
1641
-		$types = isset( $query->query_vars['type__not_in'] ) ? $query->query_vars['type__not_in'] : array();
1642
-		if ( ! is_array( $types ) ) {
1643
-			$types = array( $types );
1639
+function give_hide_payment_notes($query) {
1640
+	if (version_compare(floatval(get_bloginfo('version')), '4.1', '>=')) {
1641
+		$types = isset($query->query_vars['type__not_in']) ? $query->query_vars['type__not_in'] : array();
1642
+		if ( ! is_array($types)) {
1643
+			$types = array($types);
1644 1644
 		}
1645 1645
 		$types[]                           = 'give_payment_note';
1646 1646
 		$query->query_vars['type__not_in'] = $types;
1647 1647
 	}
1648 1648
 }
1649 1649
 
1650
-add_action( 'pre_get_comments', 'give_hide_payment_notes', 10 );
1650
+add_action('pre_get_comments', 'give_hide_payment_notes', 10);
1651 1651
 
1652 1652
 /**
1653 1653
  * Exclude notes (comments) on give_payment post type from showing in Recent Comments widgets
@@ -1659,15 +1659,15 @@  discard block
 block discarded – undo
1659 1659
  *
1660 1660
  * @return array $clauses Updated comment clauses.
1661 1661
  */
1662
-function give_hide_payment_notes_pre_41( $clauses, $wp_comment_query ) {
1663
-	if ( version_compare( floatval( get_bloginfo( 'version' ) ), '4.1', '<' ) ) {
1662
+function give_hide_payment_notes_pre_41($clauses, $wp_comment_query) {
1663
+	if (version_compare(floatval(get_bloginfo('version')), '4.1', '<')) {
1664 1664
 		$clauses['where'] .= ' AND comment_type != "give_payment_note"';
1665 1665
 	}
1666 1666
 
1667 1667
 	return $clauses;
1668 1668
 }
1669 1669
 
1670
-add_filter( 'comments_clauses', 'give_hide_payment_notes_pre_41', 10, 2 );
1670
+add_filter('comments_clauses', 'give_hide_payment_notes_pre_41', 10, 2);
1671 1671
 
1672 1672
 
1673 1673
 /**
@@ -1680,15 +1680,15 @@  discard block
 block discarded – undo
1680 1680
  *
1681 1681
  * @return string $where
1682 1682
  */
1683
-function give_hide_payment_notes_from_feeds( $where, $wp_comment_query ) {
1683
+function give_hide_payment_notes_from_feeds($where, $wp_comment_query) {
1684 1684
 	global $wpdb;
1685 1685
 
1686
-	$where .= $wpdb->prepare( ' AND comment_type != %s', 'give_payment_note' );
1686
+	$where .= $wpdb->prepare(' AND comment_type != %s', 'give_payment_note');
1687 1687
 
1688 1688
 	return $where;
1689 1689
 }
1690 1690
 
1691
-add_filter( 'comment_feed_where', 'give_hide_payment_notes_from_feeds', 10, 2 );
1691
+add_filter('comment_feed_where', 'give_hide_payment_notes_from_feeds', 10, 2);
1692 1692
 
1693 1693
 
1694 1694
 /**
@@ -1702,32 +1702,32 @@  discard block
 block discarded – undo
1702 1702
  *
1703 1703
  * @return array Array of comment counts.
1704 1704
  */
1705
-function give_remove_payment_notes_in_comment_counts( $stats, $post_id ) {
1705
+function give_remove_payment_notes_in_comment_counts($stats, $post_id) {
1706 1706
 	global $wpdb, $pagenow;
1707 1707
 
1708
-	if ( 'index.php' != $pagenow ) {
1708
+	if ('index.php' != $pagenow) {
1709 1709
 		return $stats;
1710 1710
 	}
1711 1711
 
1712 1712
 	$post_id = (int) $post_id;
1713 1713
 
1714
-	if ( apply_filters( 'give_count_payment_notes_in_comments', false ) ) {
1714
+	if (apply_filters('give_count_payment_notes_in_comments', false)) {
1715 1715
 		return $stats;
1716 1716
 	}
1717 1717
 
1718
-	$stats = wp_cache_get( "comments-{$post_id}", 'counts' );
1718
+	$stats = wp_cache_get("comments-{$post_id}", 'counts');
1719 1719
 
1720
-	if ( false !== $stats ) {
1720
+	if (false !== $stats) {
1721 1721
 		return $stats;
1722 1722
 	}
1723 1723
 
1724 1724
 	$where = 'WHERE comment_type != "give_payment_note"';
1725 1725
 
1726
-	if ( $post_id > 0 ) {
1727
-		$where .= $wpdb->prepare( ' AND comment_post_ID = %d', $post_id );
1726
+	if ($post_id > 0) {
1727
+		$where .= $wpdb->prepare(' AND comment_post_ID = %d', $post_id);
1728 1728
 	}
1729 1729
 
1730
-	$count = $wpdb->get_results( "SELECT comment_approved, COUNT( * ) AS num_comments FROM {$wpdb->comments} {$where} GROUP BY comment_approved", ARRAY_A );
1730
+	$count = $wpdb->get_results("SELECT comment_approved, COUNT( * ) AS num_comments FROM {$wpdb->comments} {$where} GROUP BY comment_approved", ARRAY_A);
1731 1731
 
1732 1732
 	$total    = 0;
1733 1733
 	$approved = array(
@@ -1737,30 +1737,30 @@  discard block
 block discarded – undo
1737 1737
 		'trash'        => 'trash',
1738 1738
 		'post-trashed' => 'post-trashed',
1739 1739
 	);
1740
-	foreach ( (array) $count as $row ) {
1740
+	foreach ((array) $count as $row) {
1741 1741
 		// Don't count post-trashed toward totals.
1742
-		if ( 'post-trashed' != $row['comment_approved'] && 'trash' != $row['comment_approved'] ) {
1742
+		if ('post-trashed' != $row['comment_approved'] && 'trash' != $row['comment_approved']) {
1743 1743
 			$total += $row['num_comments'];
1744 1744
 		}
1745
-		if ( isset( $approved[ $row['comment_approved'] ] ) ) {
1746
-			$stats[ $approved[ $row['comment_approved'] ] ] = $row['num_comments'];
1745
+		if (isset($approved[$row['comment_approved']])) {
1746
+			$stats[$approved[$row['comment_approved']]] = $row['num_comments'];
1747 1747
 		}
1748 1748
 	}
1749 1749
 
1750 1750
 	$stats['total_comments'] = $total;
1751
-	foreach ( $approved as $key ) {
1752
-		if ( empty( $stats[ $key ] ) ) {
1753
-			$stats[ $key ] = 0;
1751
+	foreach ($approved as $key) {
1752
+		if (empty($stats[$key])) {
1753
+			$stats[$key] = 0;
1754 1754
 		}
1755 1755
 	}
1756 1756
 
1757 1757
 	$stats = (object) $stats;
1758
-	wp_cache_set( "comments-{$post_id}", $stats, 'counts' );
1758
+	wp_cache_set("comments-{$post_id}", $stats, 'counts');
1759 1759
 
1760 1760
 	return $stats;
1761 1761
 }
1762 1762
 
1763
-add_filter( 'wp_count_comments', 'give_remove_payment_notes_in_comment_counts', 10, 2 );
1763
+add_filter('wp_count_comments', 'give_remove_payment_notes_in_comment_counts', 10, 2);
1764 1764
 
1765 1765
 
1766 1766
 /**
@@ -1773,9 +1773,9 @@  discard block
 block discarded – undo
1773 1773
  *
1774 1774
  * @return string $where Modified where clause.
1775 1775
  */
1776
-function give_filter_where_older_than_week( $where = '' ) {
1776
+function give_filter_where_older_than_week($where = '') {
1777 1777
 	// Payments older than one week.
1778
-	$start = date( 'Y-m-d', strtotime( '-7 days' ) );
1778
+	$start = date('Y-m-d', strtotime('-7 days'));
1779 1779
 	$where .= " AND post_date <= '{$start}'";
1780 1780
 
1781 1781
 	return $where;
@@ -1795,38 +1795,38 @@  discard block
 block discarded – undo
1795 1795
  *
1796 1796
  * @return string $form_title Returns the full title if $only_level is false, otherwise returns the levels title.
1797 1797
  */
1798
-function give_get_payment_form_title( $payment_meta, $only_level = false, $separator = '' ) {
1798
+function give_get_payment_form_title($payment_meta, $only_level = false, $separator = '') {
1799 1799
 
1800
-	$form_id    = isset( $payment_meta['form_id'] ) ? $payment_meta['form_id'] : 0;
1801
-	$price_id   = isset( $payment_meta['price_id'] ) ? $payment_meta['price_id'] : null;
1802
-	$form_title = isset( $payment_meta['form_title'] ) ? $payment_meta['form_title'] : '';
1800
+	$form_id    = isset($payment_meta['form_id']) ? $payment_meta['form_id'] : 0;
1801
+	$price_id   = isset($payment_meta['price_id']) ? $payment_meta['price_id'] : null;
1802
+	$form_title = isset($payment_meta['form_title']) ? $payment_meta['form_title'] : '';
1803 1803
 
1804
-	if ( $only_level == true ) {
1804
+	if ($only_level == true) {
1805 1805
 		$form_title = '';
1806 1806
 	}
1807 1807
 
1808 1808
 	// If multi-level, append to the form title.
1809
-	if ( give_has_variable_prices( $form_id ) ) {
1809
+	if (give_has_variable_prices($form_id)) {
1810 1810
 
1811 1811
 		// Only add separator if there is a form title.
1812
-		if ( ! empty( $form_title ) ) {
1813
-			$form_title .= ' ' . $separator . ' ';
1812
+		if ( ! empty($form_title)) {
1813
+			$form_title .= ' '.$separator.' ';
1814 1814
 		}
1815 1815
 
1816 1816
 		$form_title .= '<span class="donation-level-text-wrap">';
1817 1817
 
1818
-		if ( $price_id == 'custom' ) {
1819
-			$custom_amount_text = give_get_meta( $form_id, '_give_custom_amount_text', true );
1820
-			$form_title         .= ! empty( $custom_amount_text ) ? $custom_amount_text : __( 'Custom Amount', 'give' );
1818
+		if ($price_id == 'custom') {
1819
+			$custom_amount_text = give_get_meta($form_id, '_give_custom_amount_text', true);
1820
+			$form_title .= ! empty($custom_amount_text) ? $custom_amount_text : __('Custom Amount', 'give');
1821 1821
 		} else {
1822
-			$form_title .= give_get_price_option_name( $form_id, $price_id );
1822
+			$form_title .= give_get_price_option_name($form_id, $price_id);
1823 1823
 		}
1824 1824
 
1825 1825
 		$form_title .= '</span>';
1826 1826
 
1827 1827
 	}
1828 1828
 
1829
-	return apply_filters( 'give_get_payment_form_title', $form_title, $payment_meta );
1829
+	return apply_filters('give_get_payment_form_title', $form_title, $payment_meta);
1830 1830
 
1831 1831
 }
1832 1832
 
@@ -1840,19 +1840,19 @@  discard block
 block discarded – undo
1840 1840
  *
1841 1841
  * @return string $price_id
1842 1842
  */
1843
-function give_get_price_id( $form_id, $price ) {
1843
+function give_get_price_id($form_id, $price) {
1844 1844
 	$price_id = null;
1845 1845
 
1846
-	if ( give_has_variable_prices( $form_id ) ) {
1846
+	if (give_has_variable_prices($form_id)) {
1847 1847
 
1848
-		$levels = give_get_meta( $form_id, '_give_donation_levels', true );
1848
+		$levels = give_get_meta($form_id, '_give_donation_levels', true);
1849 1849
 
1850
-		foreach ( $levels as $level ) {
1850
+		foreach ($levels as $level) {
1851 1851
 
1852
-			$level_amount = give_maybe_sanitize_amount( $level['_give_amount'] );
1852
+			$level_amount = give_maybe_sanitize_amount($level['_give_amount']);
1853 1853
 
1854 1854
 			// Check that this indeed the recurring price.
1855
-			if ( $level_amount == $price ) {
1855
+			if ($level_amount == $price) {
1856 1856
 
1857 1857
 				$price_id = $level['_give_id']['level_id'];
1858 1858
 				break;
@@ -1860,13 +1860,13 @@  discard block
 block discarded – undo
1860 1860
 			}
1861 1861
 		}
1862 1862
 
1863
-		if( is_null( $price_id ) && give_is_custom_price_mode( $form_id ) ) {
1863
+		if (is_null($price_id) && give_is_custom_price_mode($form_id)) {
1864 1864
 			$price_id = 'custom';
1865 1865
 		}
1866 1866
 	}
1867 1867
 
1868 1868
 	// Price ID must be numeric or string.
1869
-	$price_id = ! is_numeric( $price_id ) && ! is_string( $price_id ) ? 0 : $price_id;
1869
+	$price_id = ! is_numeric($price_id) && ! is_string($price_id) ? 0 : $price_id;
1870 1870
 
1871 1871
 	return $price_id;
1872 1872
 }
@@ -1884,10 +1884,10 @@  discard block
 block discarded – undo
1884 1884
  *
1885 1885
  * @return string
1886 1886
  */
1887
-function give_get_form_dropdown( $args = array(), $echo = false ) {
1888
-	$form_dropdown_html = Give()->html->forms_dropdown( $args );
1887
+function give_get_form_dropdown($args = array(), $echo = false) {
1888
+	$form_dropdown_html = Give()->html->forms_dropdown($args);
1889 1889
 
1890
-	if ( ! $echo ) {
1890
+	if ( ! $echo) {
1891 1891
 		return $form_dropdown_html;
1892 1892
 	}
1893 1893
 
@@ -1904,17 +1904,17 @@  discard block
 block discarded – undo
1904 1904
  *
1905 1905
  * @return string|bool
1906 1906
  */
1907
-function give_get_form_variable_price_dropdown( $args = array(), $echo = false ) {
1907
+function give_get_form_variable_price_dropdown($args = array(), $echo = false) {
1908 1908
 
1909 1909
 	// Check for give form id.
1910
-	if ( empty( $args['id'] ) ) {
1910
+	if (empty($args['id'])) {
1911 1911
 		return false;
1912 1912
 	}
1913 1913
 
1914
-	$form = new Give_Donate_Form( $args['id'] );
1914
+	$form = new Give_Donate_Form($args['id']);
1915 1915
 
1916 1916
 	// Check if form has variable prices or not.
1917
-	if ( ! $form->ID || ! $form->has_variable_prices() ) {
1917
+	if ( ! $form->ID || ! $form->has_variable_prices()) {
1918 1918
 		return false;
1919 1919
 	}
1920 1920
 
@@ -1922,24 +1922,24 @@  discard block
 block discarded – undo
1922 1922
 	$variable_price_options = array();
1923 1923
 
1924 1924
 	// Check if multi donation form support custom donation or not.
1925
-	if ( $form->is_custom_price_mode() ) {
1926
-		$variable_price_options['custom'] = _x( 'Custom', 'custom donation dropdown item', 'give' );
1925
+	if ($form->is_custom_price_mode()) {
1926
+		$variable_price_options['custom'] = _x('Custom', 'custom donation dropdown item', 'give');
1927 1927
 	}
1928 1928
 
1929 1929
 	// Get variable price and ID from variable price array.
1930
-	foreach ( $variable_prices as $variable_price ) {
1931
-		$variable_price_options[ $variable_price['_give_id']['level_id'] ] = ! empty( $variable_price['_give_text'] ) ? $variable_price['_give_text'] : give_currency_filter( give_format_amount( $variable_price['_give_amount'], array( 'sanitize' => false ) ) );
1930
+	foreach ($variable_prices as $variable_price) {
1931
+		$variable_price_options[$variable_price['_give_id']['level_id']] = ! empty($variable_price['_give_text']) ? $variable_price['_give_text'] : give_currency_filter(give_format_amount($variable_price['_give_amount'], array('sanitize' => false)));
1932 1932
 	}
1933 1933
 
1934 1934
 	// Update options.
1935
-	$args = array_merge( $args, array(
1935
+	$args = array_merge($args, array(
1936 1936
 		'options' => $variable_price_options,
1937
-	) );
1937
+	));
1938 1938
 
1939 1939
 	// Generate select html.
1940
-	$form_dropdown_html = Give()->html->select( $args );
1940
+	$form_dropdown_html = Give()->html->select($args);
1941 1941
 
1942
-	if ( ! $echo ) {
1942
+	if ( ! $echo) {
1943 1943
 		return $form_dropdown_html;
1944 1944
 	}
1945 1945
 
@@ -1958,16 +1958,16 @@  discard block
 block discarded – undo
1958 1958
  *
1959 1959
  * @return string
1960 1960
  */
1961
-function give_get_payment_meta_price_id( $payment_meta ) {
1961
+function give_get_payment_meta_price_id($payment_meta) {
1962 1962
 
1963
-	if ( isset( $payment_meta['give_price_id'] ) ) {
1963
+	if (isset($payment_meta['give_price_id'])) {
1964 1964
 		$price_id = $payment_meta['give_price_id'];
1965
-	} elseif ( isset( $payment_meta['price_id'] ) ) {
1965
+	} elseif (isset($payment_meta['price_id'])) {
1966 1966
 		$price_id = $payment_meta['price_id'];
1967 1967
 	} else {
1968
-		$price_id = give_get_price_id( $payment_meta['give_form_id'], $payment_meta['price'] );
1968
+		$price_id = give_get_price_id($payment_meta['give_form_id'], $payment_meta['price']);
1969 1969
 	}
1970 1970
 
1971
-	return apply_filters( 'give_get_payment_meta_price_id', $price_id );
1971
+	return apply_filters('give_get_payment_meta_price_id', $price_id);
1972 1972
 
1973 1973
 }
Please login to merge, or discard this patch.
includes/user-functions.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -671,7 +671,7 @@
 block discarded – undo
671 671
 /**
672 672
  * This function will check whether the donor email is primary or additional.
673 673
  *
674
- * @param $email Donor Email.
674
+ * @param string $email Donor Email.
675 675
  *
676 676
  * @since 1.8.13
677 677
  *
Please login to merge, or discard this patch.
Spacing   +144 added lines, -144 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
 
@@ -30,54 +30,54 @@  discard block
 block discarded – undo
30 30
  *
31 31
  * @return bool|array List of all user donations.
32 32
  */
33
-function give_get_users_donations( $user = 0, $number = 20, $pagination = false, $status = 'complete' ) {
33
+function give_get_users_donations($user = 0, $number = 20, $pagination = false, $status = 'complete') {
34 34
 
35
-	if ( empty( $user ) ) {
35
+	if (empty($user)) {
36 36
 		$user = get_current_user_id();
37 37
 	}
38 38
 
39
-	if ( 0 === $user && ! Give()->email_access->token_exists ) {
39
+	if (0 === $user && ! Give()->email_access->token_exists) {
40 40
 		return false;
41 41
 	}
42 42
 
43 43
 	$status = $status === 'complete' ? 'publish' : $status;
44 44
 	$paged = 1;
45 45
 
46
-	if ( $pagination ) {
47
-		if ( get_query_var( 'paged' ) ) {
48
-			$paged = get_query_var( 'paged' );
49
-		} elseif ( get_query_var( 'page' ) ) {
50
-			$paged = get_query_var( 'page' );
46
+	if ($pagination) {
47
+		if (get_query_var('paged')) {
48
+			$paged = get_query_var('paged');
49
+		} elseif (get_query_var('page')) {
50
+			$paged = get_query_var('page');
51 51
 		}
52 52
 	}
53 53
 
54
-	$args = apply_filters( 'give_get_users_donations_args', array(
54
+	$args = apply_filters('give_get_users_donations_args', array(
55 55
 		'user'    => $user,
56 56
 		'number'  => $number,
57 57
 		'status'  => $status,
58 58
 		'orderby' => 'date',
59
-	) );
59
+	));
60 60
 
61
-	if ( $pagination ) {
61
+	if ($pagination) {
62 62
 		$args['page'] = $paged;
63 63
 	} else {
64 64
 		$args['nopaging'] = true;
65 65
 	}
66 66
 
67
-	$by_user_id = is_numeric( $user ) ? true : false;
68
-	$donor   = new Give_Donor( $user, $by_user_id );
67
+	$by_user_id = is_numeric($user) ? true : false;
68
+	$donor = new Give_Donor($user, $by_user_id);
69 69
 
70
-	if ( ! empty( $donor->payment_ids ) ) {
70
+	if ( ! empty($donor->payment_ids)) {
71 71
 
72
-		unset( $args['user'] );
73
-		$args['post__in'] = array_map( 'absint', explode( ',', $donor->payment_ids ) );
72
+		unset($args['user']);
73
+		$args['post__in'] = array_map('absint', explode(',', $donor->payment_ids));
74 74
 
75 75
 	}
76 76
 
77
-	$donations = give_get_payments( apply_filters( 'give_get_users_donations_args', $args ) );
77
+	$donations = give_get_payments(apply_filters('give_get_users_donations_args', $args));
78 78
 
79 79
 	// No donations
80
-	if ( ! $donations ) {
80
+	if ( ! $donations) {
81 81
 		return false;
82 82
 	}
83 83
 
@@ -96,65 +96,65 @@  discard block
 block discarded – undo
96 96
  *
97 97
  * @return bool|object List of unique forms donated by user
98 98
  */
99
-function give_get_users_completed_donations( $user = 0, $status = 'complete' ) {
100
-	if ( empty( $user ) ) {
99
+function give_get_users_completed_donations($user = 0, $status = 'complete') {
100
+	if (empty($user)) {
101 101
 		$user = get_current_user_id();
102 102
 	}
103 103
 
104
-	if ( empty( $user ) ) {
104
+	if (empty($user)) {
105 105
 		return false;
106 106
 	}
107 107
 
108
-	$by_user_id = is_numeric( $user ) ? true : false;
108
+	$by_user_id = is_numeric($user) ? true : false;
109 109
 
110
-	$donor = new Give_Donor( $user, $by_user_id );
110
+	$donor = new Give_Donor($user, $by_user_id);
111 111
 
112
-	if ( empty( $donor->payment_ids ) ) {
112
+	if (empty($donor->payment_ids)) {
113 113
 		return false;
114 114
 	}
115 115
 
116 116
 	// Get all the items donated.
117
-	$payment_ids    = array_reverse( explode( ',', $donor->payment_ids ) );
118
-	$limit_payments = apply_filters( 'give_users_completed_donations_payments', 50 );
119
-	if ( ! empty( $limit_payments ) ) {
120
-		$payment_ids = array_slice( $payment_ids, 0, $limit_payments );
117
+	$payment_ids    = array_reverse(explode(',', $donor->payment_ids));
118
+	$limit_payments = apply_filters('give_users_completed_donations_payments', 50);
119
+	if ( ! empty($limit_payments)) {
120
+		$payment_ids = array_slice($payment_ids, 0, $limit_payments);
121 121
 	}
122 122
 	$donation_data = array();
123
-	foreach ( $payment_ids as $payment_id ) {
124
-		$donation_data[] = give_get_payment_meta( $payment_id );
123
+	foreach ($payment_ids as $payment_id) {
124
+		$donation_data[] = give_get_payment_meta($payment_id);
125 125
 	}
126 126
 
127
-	if ( empty( $donation_data ) ) {
127
+	if (empty($donation_data)) {
128 128
 		return false;
129 129
 	}
130 130
 
131 131
 	// Grab only the post ids "form_id" of the forms donated on this order
132 132
 	$completed_donations_ids = array();
133
-	foreach ( $donation_data as $donation_meta ) {
134
-		$completed_donations_ids[] = isset( $donation_meta['form_id'] ) ? $donation_meta['form_id'] : '';
133
+	foreach ($donation_data as $donation_meta) {
134
+		$completed_donations_ids[] = isset($donation_meta['form_id']) ? $donation_meta['form_id'] : '';
135 135
 	}
136 136
 
137
-	if ( empty( $completed_donations_ids ) ) {
137
+	if (empty($completed_donations_ids)) {
138 138
 		return false;
139 139
 	}
140 140
 
141 141
 	// Only include each donation once
142
-	$form_ids = array_unique( $completed_donations_ids );
142
+	$form_ids = array_unique($completed_donations_ids);
143 143
 
144 144
 	// Make sure we still have some products and a first item
145
-	if ( empty( $form_ids ) || ! isset( $form_ids[0] ) ) {
145
+	if (empty($form_ids) || ! isset($form_ids[0])) {
146 146
 		return false;
147 147
 	}
148 148
 
149
-	$post_type = get_post_type( $form_ids[0] );
149
+	$post_type = get_post_type($form_ids[0]);
150 150
 
151
-	$args = apply_filters( 'give_get_users_completed_donations_args', array(
151
+	$args = apply_filters('give_get_users_completed_donations_args', array(
152 152
 		'include'        => $form_ids,
153 153
 		'post_type'      => $post_type,
154
-		'posts_per_page' => - 1,
155
-	) );
154
+		'posts_per_page' => -1,
155
+	));
156 156
 
157
-	return apply_filters( 'give_users_completed_donations_list', get_posts( $args ) );
157
+	return apply_filters('give_users_completed_donations_list', get_posts($args));
158 158
 }
159 159
 
160 160
 
@@ -170,12 +170,12 @@  discard block
 block discarded – undo
170 170
  *
171 171
  * @return      bool True if has donated, false other wise.
172 172
  */
173
-function give_has_donations( $user_id = null ) {
174
-	if ( empty( $user_id ) ) {
173
+function give_has_donations($user_id = null) {
174
+	if (empty($user_id)) {
175 175
 		$user_id = get_current_user_id();
176 176
 	}
177 177
 
178
-	if ( give_get_users_donations( $user_id, 1 ) ) {
178
+	if (give_get_users_donations($user_id, 1)) {
179 179
 		return true; // User has at least one donation.
180 180
 	}
181 181
 
@@ -196,23 +196,23 @@  discard block
 block discarded – undo
196 196
  *
197 197
  * @return      array
198 198
  */
199
-function give_get_donation_stats_by_user( $user = '' ) {
199
+function give_get_donation_stats_by_user($user = '') {
200 200
 
201 201
 	$field = '';
202 202
 
203
-	if ( is_email( $user ) ) {
203
+	if (is_email($user)) {
204 204
 		$field = 'email';
205
-	} elseif ( is_numeric( $user ) ) {
205
+	} elseif (is_numeric($user)) {
206 206
 		$field = 'user_id';
207 207
 	}
208 208
 
209
-	$stats    = array();
210
-	$donor = Give()->donors->get_donor_by( $field, $user );
209
+	$stats = array();
210
+	$donor = Give()->donors->get_donor_by($field, $user);
211 211
 
212
-	if ( $donor ) {
213
-		$donor = new Give_Donor( $donor->id );
214
-		$stats['purchases']   = absint( $donor->purchase_count );
215
-		$stats['total_spent'] = give_maybe_sanitize_amount( $donor->purchase_value );
212
+	if ($donor) {
213
+		$donor = new Give_Donor($donor->id);
214
+		$stats['purchases']   = absint($donor->purchase_count);
215
+		$stats['total_spent'] = give_maybe_sanitize_amount($donor->purchase_value);
216 216
 	}
217 217
 
218 218
 	/**
@@ -220,7 +220,7 @@  discard block
 block discarded – undo
220 220
 	 *
221 221
 	 * @since 1.7
222 222
 	 */
223
-	$stats = (array) apply_filters( 'give_donation_stats_by_user', $stats, $user );
223
+	$stats = (array) apply_filters('give_donation_stats_by_user', $stats, $user);
224 224
 
225 225
 	return $stats;
226 226
 }
@@ -238,21 +238,21 @@  discard block
 block discarded – undo
238 238
  *
239 239
  * @return      int The total number of donations.
240 240
  */
241
-function give_count_donations_of_donor( $user = null ) {
241
+function give_count_donations_of_donor($user = null) {
242 242
 
243 243
 	// Logged in?
244
-	if ( empty( $user ) ) {
244
+	if (empty($user)) {
245 245
 		$user = get_current_user_id();
246 246
 	}
247 247
 
248 248
 	// Email access?
249
-	if ( empty( $user ) && Give()->email_access->token_email ) {
249
+	if (empty($user) && Give()->email_access->token_email) {
250 250
 		$user = Give()->email_access->token_email;
251 251
 	}
252 252
 
253
-	$stats = ! empty( $user ) ? give_get_donation_stats_by_user( $user ) : false;
253
+	$stats = ! empty($user) ? give_get_donation_stats_by_user($user) : false;
254 254
 
255
-	return isset( $stats['purchases'] ) ? $stats['purchases'] : 0;
255
+	return isset($stats['purchases']) ? $stats['purchases'] : 0;
256 256
 }
257 257
 
258 258
 /**
@@ -265,9 +265,9 @@  discard block
 block discarded – undo
265 265
  *
266 266
  * @return      float The total amount the user has spent
267 267
  */
268
-function give_donation_total_of_user( $user = null ) {
268
+function give_donation_total_of_user($user = null) {
269 269
 
270
-	$stats = give_get_donation_stats_by_user( $user );
270
+	$stats = give_get_donation_stats_by_user($user);
271 271
 
272 272
 	return $stats['total_spent'];
273 273
 }
@@ -283,40 +283,40 @@  discard block
 block discarded – undo
283 283
  *
284 284
  * @return bool
285 285
  */
286
-function give_validate_username( $username, $form_id = 0 ) {
286
+function give_validate_username($username, $form_id = 0) {
287 287
 	$valid = true;
288 288
 
289 289
 	// Validate username.
290
-	if ( ! empty( $username ) ) {
290
+	if ( ! empty($username)) {
291 291
 
292 292
 		// Sanitize username.
293
-		$sanitized_user_name = sanitize_user( $username, false );
293
+		$sanitized_user_name = sanitize_user($username, false);
294 294
 
295 295
 		// We have an user name, check if it already exists.
296
-		if ( username_exists( $username ) ) {
296
+		if (username_exists($username)) {
297 297
 			// Username already registered.
298
-			give_set_error( 'username_unavailable', __( 'Username already taken.', 'give' ) );
298
+			give_set_error('username_unavailable', __('Username already taken.', 'give'));
299 299
 			$valid = false;
300 300
 
301 301
 			// Check if it's valid.
302
-		} elseif ( $sanitized_user_name !== $username ) {
302
+		} elseif ($sanitized_user_name !== $username) {
303 303
 			// Invalid username.
304
-			if ( is_multisite() ) {
305
-				give_set_error( 'username_invalid', __( 'Invalid username. Only lowercase letters (a-z) and numbers are allowed.', 'give' ) );
304
+			if (is_multisite()) {
305
+				give_set_error('username_invalid', __('Invalid username. Only lowercase letters (a-z) and numbers are allowed.', 'give'));
306 306
 				$valid = false;
307 307
 			} else {
308
-				give_set_error( 'username_invalid', __( 'Invalid username.', 'give' ) );
308
+				give_set_error('username_invalid', __('Invalid username.', 'give'));
309 309
 				$valid = false;
310 310
 			}
311 311
 		}
312 312
 	} else {
313 313
 		// Username is empty.
314
-		give_set_error( 'username_empty', __( 'Enter a username.', 'give' ) );
314
+		give_set_error('username_empty', __('Enter a username.', 'give'));
315 315
 		$valid = false;
316 316
 
317 317
 		// Check if guest checkout is disable for form.
318
-		if ( $form_id && give_logged_in_only( $form_id ) ) {
319
-			give_set_error( 'registration_required', __( 'You must register or login to complete your donation.', 'give' ) );
318
+		if ($form_id && give_logged_in_only($form_id)) {
319
+			give_set_error('registration_required', __('You must register or login to complete your donation.', 'give'));
320 320
 			$valid = false;
321 321
 		}
322 322
 	}
@@ -330,7 +330,7 @@  discard block
 block discarded – undo
330 330
 	 * @param string $username
331 331
 	 * @param bool   $form_id
332 332
 	 */
333
-	$valid = (bool) apply_filters( 'give_validate_username', $valid, $username, $form_id );
333
+	$valid = (bool) apply_filters('give_validate_username', $valid, $username, $form_id);
334 334
 
335 335
 	return $valid;
336 336
 }
@@ -346,25 +346,25 @@  discard block
 block discarded – undo
346 346
  *
347 347
  * @return bool
348 348
  */
349
-function give_validate_user_email( $email, $registering_new_user = false ) {
349
+function give_validate_user_email($email, $registering_new_user = false) {
350 350
 	$valid = true;
351 351
 
352
-	if ( empty( $email ) ) {
352
+	if (empty($email)) {
353 353
 		// No email.
354
-		give_set_error( 'email_empty', __( 'Enter an email.', 'give' ) );
354
+		give_set_error('email_empty', __('Enter an email.', 'give'));
355 355
 		$valid = false;
356 356
 
357
-	} elseif ( ! is_email( $email ) ) {
357
+	} elseif ( ! is_email($email)) {
358 358
 		// Validate email.
359
-		give_set_error( 'email_invalid', __( 'Invalid email.', 'give' ) );
359
+		give_set_error('email_invalid', __('Invalid email.', 'give'));
360 360
 		$valid = false;
361 361
 
362
-	} elseif ( $registering_new_user ) {
362
+	} elseif ($registering_new_user) {
363 363
 
364 364
 		// If donor email is not primary
365
-		if ( ! email_exists( $email ) && give_donor_email_exists( $email ) && give_is_additional_email( $email ) ) {
365
+		if ( ! email_exists($email) && give_donor_email_exists($email) && give_is_additional_email($email)) {
366 366
 			// Check if email exists.
367
-			give_set_error( 'email_used', __( 'The email address provided is already active for another user.', 'give' ) );
367
+			give_set_error('email_used', __('The email address provided is already active for another user.', 'give'));
368 368
 			$valid = false;
369 369
 		}
370 370
 	}
@@ -378,7 +378,7 @@  discard block
 block discarded – undo
378 378
 	 * @param string $email
379 379
 	 * @param bool   $registering_new_user
380 380
 	 */
381
-	$valid = (bool) apply_filters( 'give_validate_user_email', $valid, $email, $registering_new_user );
381
+	$valid = (bool) apply_filters('give_validate_user_email', $valid, $email, $registering_new_user);
382 382
 
383 383
 	return $valid;
384 384
 }
@@ -394,34 +394,34 @@  discard block
 block discarded – undo
394 394
  *
395 395
  * @return bool
396 396
  */
397
-function give_validate_user_password( $password = '', $confirm_password = '', $registering_new_user = false ) {
397
+function give_validate_user_password($password = '', $confirm_password = '', $registering_new_user = false) {
398 398
 	$valid = true;
399 399
 
400 400
 	// Passwords Validation For New Donors Only
401
-	if ( $registering_new_user ) {
401
+	if ($registering_new_user) {
402 402
 		// Password or confirmation missing.
403
-		if ( ! $password ) {
403
+		if ( ! $password) {
404 404
 			// The password is invalid.
405
-			give_set_error( 'password_empty', __( 'Enter a password.', 'give' ) );
405
+			give_set_error('password_empty', __('Enter a password.', 'give'));
406 406
 			$valid = false;
407
-		} elseif ( ! $confirm_password ) {
407
+		} elseif ( ! $confirm_password) {
408 408
 			// Confirmation password is invalid.
409
-			give_set_error( 'confirmation_empty', __( 'Enter the password confirmation.', 'give' ) );
409
+			give_set_error('confirmation_empty', __('Enter the password confirmation.', 'give'));
410 410
 			$valid = false;
411 411
 		}
412 412
 	}
413 413
 	// Passwords Validation For New Donors as well as Existing Donors
414
-	if ( $password || $confirm_password ) {
415
-		if ( strlen( $password ) < 6 || strlen( $confirm_password ) < 6 ) {
414
+	if ($password || $confirm_password) {
415
+		if (strlen($password) < 6 || strlen($confirm_password) < 6) {
416 416
 			// Seems Weak Password
417
-			give_set_error( 'password_weak', __( 'Passwords should have at least 6 characters.', 'give' ) );
417
+			give_set_error('password_weak', __('Passwords should have at least 6 characters.', 'give'));
418 418
 			$valid = false;
419 419
 		}
420
-		if ( $password && $confirm_password ) {
420
+		if ($password && $confirm_password) {
421 421
 			// Verify confirmation matches.
422
-			if ( $password != $confirm_password ) {
422
+			if ($password != $confirm_password) {
423 423
 				// Passwords do not match
424
-				give_set_error( 'password_mismatch', __( 'Passwords you entered do not match. Please try again.', 'give' ) );
424
+				give_set_error('password_mismatch', __('Passwords you entered do not match. Please try again.', 'give'));
425 425
 				$valid = false;
426 426
 			}
427 427
 		}
@@ -437,7 +437,7 @@  discard block
 block discarded – undo
437 437
 	 * @param string $confirm_password
438 438
 	 * @param bool   $registering_new_user
439 439
 	 */
440
-	$valid = (bool) apply_filters( 'give_validate_user_email', $valid, $password, $confirm_password, $registering_new_user );
440
+	$valid = (bool) apply_filters('give_validate_user_email', $valid, $password, $confirm_password, $registering_new_user);
441 441
 
442 442
 	return $valid;
443 443
 }
@@ -455,19 +455,19 @@  discard block
 block discarded – undo
455 455
  *
456 456
  * @return      void
457 457
  */
458
-function give_add_past_donations_to_new_user( $user_id ) {
458
+function give_add_past_donations_to_new_user($user_id) {
459 459
 
460
-	$email = get_the_author_meta( 'user_email', $user_id );
460
+	$email = get_the_author_meta('user_email', $user_id);
461 461
 
462
-	$payments = give_get_payments( array(
462
+	$payments = give_get_payments(array(
463 463
 		's' => $email,
464
-	) );
464
+	));
465 465
 
466
-	if ( $payments ) {
467
-		foreach ( $payments as $payment ) {
466
+	if ($payments) {
467
+		foreach ($payments as $payment) {
468 468
 			/* @var $payment \Give_Payment */
469 469
 
470
-			if ( intval( give_get_payment_user_id( $payment->ID ) ) > 0 ) {
470
+			if (intval(give_get_payment_user_id($payment->ID)) > 0) {
471 471
 				continue;
472 472
 			}
473 473
 
@@ -479,7 +479,7 @@  discard block
 block discarded – undo
479 479
 
480 480
 }
481 481
 
482
-add_action( 'user_register', 'give_add_past_donations_to_new_user' );
482
+add_action('user_register', 'give_add_past_donations_to_new_user');
483 483
 
484 484
 
485 485
 /**
@@ -505,34 +505,34 @@  discard block
 block discarded – undo
505 505
  *
506 506
  * @return        array The donor's address, if any
507 507
  */
508
-function give_get_donor_address( $user_id = 0 ) {
509
-	if ( empty( $user_id ) ) {
508
+function give_get_donor_address($user_id = 0) {
509
+	if (empty($user_id)) {
510 510
 		$user_id = get_current_user_id();
511 511
 	}
512 512
 
513
-	$address = get_user_meta( $user_id, '_give_user_address', true );
513
+	$address = get_user_meta($user_id, '_give_user_address', true);
514 514
 
515
-	if ( ! isset( $address['line1'] ) ) {
515
+	if ( ! isset($address['line1'])) {
516 516
 		$address['line1'] = '';
517 517
 	}
518 518
 
519
-	if ( ! isset( $address['line2'] ) ) {
519
+	if ( ! isset($address['line2'])) {
520 520
 		$address['line2'] = '';
521 521
 	}
522 522
 
523
-	if ( ! isset( $address['city'] ) ) {
523
+	if ( ! isset($address['city'])) {
524 524
 		$address['city'] = '';
525 525
 	}
526 526
 
527
-	if ( ! isset( $address['zip'] ) ) {
527
+	if ( ! isset($address['zip'])) {
528 528
 		$address['zip'] = '';
529 529
 	}
530 530
 
531
-	if ( ! isset( $address['country'] ) ) {
531
+	if ( ! isset($address['country'])) {
532 532
 		$address['country'] = '';
533 533
 	}
534 534
 
535
-	if ( ! isset( $address['state'] ) ) {
535
+	if ( ! isset($address['state'])) {
536 536
 		$address['state'] = '';
537 537
 	}
538 538
 
@@ -552,53 +552,53 @@  discard block
 block discarded – undo
552 552
  *
553 553
  * @return        void
554 554
  */
555
-function give_new_user_notification( $user_id = 0, $user_data = array() ) {
555
+function give_new_user_notification($user_id = 0, $user_data = array()) {
556 556
 
557
-	if ( empty( $user_id ) || empty( $user_data ) ) {
557
+	if (empty($user_id) || empty($user_data)) {
558 558
 		return;
559 559
 	}
560
-	$blogname = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
560
+	$blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
561 561
 
562 562
 	// New User Registration: Email sends to the site admin.
563 563
 	$emails = Give()->emails;
564
-	$emails->__set( 'heading', esc_html__( 'New User Registration', 'give' ) );
564
+	$emails->__set('heading', esc_html__('New User Registration', 'give'));
565 565
 
566 566
 	/* translators: %s: site name */
567
-	$message = sprintf( esc_attr__( 'A new user has registered on %s:', 'give' ), $blogname ) . "\r\n\r\n";
567
+	$message = sprintf(esc_attr__('A new user has registered on %s:', 'give'), $blogname)."\r\n\r\n";
568 568
 	/* translators: %s: user login */
569
-	$message .= '<strong>' . esc_attr__( 'Username:', 'give' ) . '</strong> ' . $user_data['user_login'] . "\r\n";
569
+	$message .= '<strong>'.esc_attr__('Username:', 'give').'</strong> '.$user_data['user_login']."\r\n";
570 570
 	/* translators: %s: user email */
571
-	$message .= '<strong>' . esc_attr__( 'E-mail:', 'give' ) . '</strong> ' . $user_data['user_email'] . "\r\n\r\n";
571
+	$message .= '<strong>'.esc_attr__('E-mail:', 'give').'</strong> '.$user_data['user_email']."\r\n\r\n";
572 572
 
573
-	$message .= '<a href="' . admin_url( 'user-edit.php?user_id=' . $user_id ) . '" target="_blank"> ' . esc_attr__( 'Click here to view &raquo;', 'give' ) . '</a>' . "\r\n";
573
+	$message .= '<a href="'.admin_url('user-edit.php?user_id='.$user_id).'" target="_blank"> '.esc_attr__('Click here to view &raquo;', 'give').'</a>'."\r\n";
574 574
 
575 575
 	$emails->send(
576
-		get_option( 'admin_email' ),
576
+		get_option('admin_email'),
577 577
 		sprintf(
578 578
 			/* translators: %s: site name */
579
-			esc_attr__( '[%s] New User Registration', 'give' ),
579
+			esc_attr__('[%s] New User Registration', 'give'),
580 580
 			$blogname
581 581
 		),
582 582
 		$message
583 583
 	);
584 584
 
585 585
 	// Account Information: Email sends to donor who registered.
586
-	$emails->__set( 'heading', esc_html__( 'Account Information', 'give' ) );
586
+	$emails->__set('heading', esc_html__('Account Information', 'give'));
587 587
 
588
-	$message = sprintf( esc_attr__( 'The following email contains your account information for %s:', 'give' ), $blogname ) . "\r\n\r\n";
588
+	$message = sprintf(esc_attr__('The following email contains your account information for %s:', 'give'), $blogname)."\r\n\r\n";
589 589
 
590 590
 	/* translators: %s: user login */
591
-	$message .= '<strong>' . esc_attr__( 'Username:', 'give' ) . '</strong> ' . $user_data['user_login'] . "\r\n";
591
+	$message .= '<strong>'.esc_attr__('Username:', 'give').'</strong> '.$user_data['user_login']."\r\n";
592 592
 	/* translators: %s: password */
593
-	$message .= '<strong>' . esc_attr__( 'Password:', 'give' ) . '</strong> ' . esc_attr__( '[Password entered during donation]', 'give' ) . "\r\n\r\n";
593
+	$message .= '<strong>'.esc_attr__('Password:', 'give').'</strong> '.esc_attr__('[Password entered during donation]', 'give')."\r\n\r\n";
594 594
 
595
-	$message .= '<a href="' . wp_login_url() . '" target="_blank"> ' . esc_attr__( 'Click here to login &raquo;', 'give' ) . '</a>' . "\r\n";
595
+	$message .= '<a href="'.wp_login_url().'" target="_blank"> '.esc_attr__('Click here to login &raquo;', 'give').'</a>'."\r\n";
596 596
 
597 597
 	$emails->send(
598 598
 		$user_data['user_email'],
599 599
 		sprintf(
600 600
 			/* translators: %s: site name */
601
-			esc_attr__( '[%s] Your username and password', 'give' ),
601
+			esc_attr__('[%s] Your username and password', 'give'),
602 602
 			$blogname
603 603
 		),
604 604
 		$message
@@ -606,7 +606,7 @@  discard block
 block discarded – undo
606 606
 
607 607
 }
608 608
 
609
-add_action( 'give_insert_user', 'give_new_user_notification', 10, 2 );
609
+add_action('give_insert_user', 'give_new_user_notification', 10, 2);
610 610
 
611 611
 
612 612
 /**
@@ -622,34 +622,34 @@  discard block
 block discarded – undo
622 622
  *
623 623
  * @return      string
624 624
  */
625
-function give_get_donor_name_by( $id = 0, $from = 'donation' ) {
625
+function give_get_donor_name_by($id = 0, $from = 'donation') {
626 626
 
627 627
 	// ID shouldn't be empty
628
-	if ( empty( $id ) ) {
628
+	if (empty($id)) {
629 629
 		return;
630 630
 	}
631 631
 
632 632
 	$name = '';
633 633
 
634
-	switch ( $from ) {
634
+	switch ($from) {
635 635
 
636 636
 		case 'donation':
637 637
 
638
-			$user_info = give_get_payment_meta_user_info( $id );
639
-			$name = $user_info['first_name'] . ' ' . $user_info['last_name'];
638
+			$user_info = give_get_payment_meta_user_info($id);
639
+			$name = $user_info['first_name'].' '.$user_info['last_name'];
640 640
 
641 641
 		break;
642 642
 
643 643
 		case 'donor':
644 644
 
645
-			$donor = new Give_Donor( $id );
645
+			$donor = new Give_Donor($id);
646 646
 			$name = $donor->name;
647 647
 
648 648
 		break;
649 649
 
650 650
 	}
651 651
 
652
-	return trim( $name );
652
+	return trim($name);
653 653
 
654 654
 }
655 655
 
@@ -661,8 +661,8 @@  discard block
 block discarded – undo
661 661
  * @param  string $email Donor Email.
662 662
  * @return boolean  The user's ID on success, and false on failure.
663 663
  */
664
-function give_donor_email_exists( $email ) {
665
-	if ( Give()->donors->get_donor_by( 'email', $email ) ) {
664
+function give_donor_email_exists($email) {
665
+	if (Give()->donors->get_donor_by('email', $email)) {
666 666
 		return true;
667 667
 	}
668 668
 	return false;
@@ -677,12 +677,12 @@  discard block
 block discarded – undo
677 677
  *
678 678
  * @return bool
679 679
  */
680
-function give_is_additional_email( $email ) {
680
+function give_is_additional_email($email) {
681 681
 	global $wpdb;
682
-	$meta_table  = Give()->donor_meta->table_name;
683
-	$donor_id = $wpdb->get_var( $wpdb->prepare( "SELECT customer_id FROM {$meta_table} WHERE meta_key = 'additional_email' AND meta_value = %s LIMIT 1", $email ) );
682
+	$meta_table = Give()->donor_meta->table_name;
683
+	$donor_id = $wpdb->get_var($wpdb->prepare("SELECT customer_id FROM {$meta_table} WHERE meta_key = 'additional_email' AND meta_value = %s LIMIT 1", $email));
684 684
 
685
-	if ( empty( $donor_id ) ) {
685
+	if (empty($donor_id)) {
686 686
 		return false;
687 687
 	}
688 688
 	return true;
Please login to merge, or discard this patch.
includes/process-donation.php 1 patch
Spacing   +247 added lines, -248 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
 
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
 	 *
31 31
 	 * @since 1.0
32 32
 	 */
33
-	do_action( 'give_pre_process_donation' );
33
+	do_action('give_pre_process_donation');
34 34
 
35 35
 	// Validate the form $_POST data
36 36
 	$valid_data = give_donation_form_validate_fields();
@@ -45,26 +45,26 @@  discard block
 block discarded – undo
45 45
 	 * @param bool|array $valid_data Validate fields.
46 46
 	 * @param array $_POST Array of variables passed via the HTTP POST.
47 47
 	 */
48
-	do_action( 'give_checkout_error_checks', $valid_data, $_POST );
48
+	do_action('give_checkout_error_checks', $valid_data, $_POST);
49 49
 
50
-	$is_ajax = isset( $_POST['give_ajax'] );
50
+	$is_ajax = isset($_POST['give_ajax']);
51 51
 
52 52
 	// Process the login form
53
-	if ( isset( $_POST['give_login_submit'] ) ) {
53
+	if (isset($_POST['give_login_submit'])) {
54 54
 		give_process_form_login();
55 55
 	}
56 56
 
57 57
 	// Validate the user
58
-	$user = give_get_donation_form_user( $valid_data );
58
+	$user = give_get_donation_form_user($valid_data);
59 59
 
60
-	if ( false === $valid_data || give_get_errors() || ! $user ) {
61
-		if ( $is_ajax ) {
60
+	if (false === $valid_data || give_get_errors() || ! $user) {
61
+		if ($is_ajax) {
62 62
 			/**
63 63
 			 * Fires when AJAX sends back errors from the donation form.
64 64
 			 *
65 65
 			 * @since 1.0
66 66
 			 */
67
-			do_action( 'give_ajax_donation_errors' );
67
+			do_action('give_ajax_donation_errors');
68 68
 			give_die();
69 69
 		} else {
70 70
 			return false;
@@ -72,17 +72,17 @@  discard block
 block discarded – undo
72 72
 	}
73 73
 
74 74
 	// If AJAX send back success to proceed with form submission
75
-	if ( $is_ajax ) {
75
+	if ($is_ajax) {
76 76
 		echo 'success';
77 77
 		give_die();
78 78
 	}
79 79
 
80 80
 	// After AJAX: Setup session if not using php_sessions
81
-	if ( ! Give()->session->use_php_sessions() ) {
81
+	if ( ! Give()->session->use_php_sessions()) {
82 82
 		// Double-check that set_cookie is publicly accessible;
83 83
 		// we're using a slightly modified class-wp-sessions.php
84
-		$session_reflection = new ReflectionMethod( 'WP_Session', 'set_cookie' );
85
-		if ( $session_reflection->isPublic() ) {
84
+		$session_reflection = new ReflectionMethod('WP_Session', 'set_cookie');
85
+		if ($session_reflection->isPublic()) {
86 86
 			// Manually set the cookie.
87 87
 			Give()->session->init()->set_cookie();
88 88
 		}
@@ -97,20 +97,19 @@  discard block
 block discarded – undo
97 97
 		'address'    => $user['address'],
98 98
 	);
99 99
 
100
-	$auth_key = defined( 'AUTH_KEY' ) ? AUTH_KEY : '';
100
+	$auth_key = defined('AUTH_KEY') ? AUTH_KEY : '';
101 101
 
102
-	$price        = isset( $_POST['give-amount'] ) ?
103
-		(float) apply_filters( 'give_donation_total', give_maybe_sanitize_amount( $_POST['give-amount'] ) ) :
104
-		'0.00';
105
-	$purchase_key = strtolower( md5( $user['user_email'] . date( 'Y-m-d H:i:s' ) . $auth_key . uniqid( 'give', true ) ) );
102
+	$price        = isset($_POST['give-amount']) ?
103
+		(float) apply_filters('give_donation_total', give_maybe_sanitize_amount($_POST['give-amount'])) : '0.00';
104
+	$purchase_key = strtolower(md5($user['user_email'].date('Y-m-d H:i:s').$auth_key.uniqid('give', true)));
106 105
 
107 106
 	// Setup donation information
108 107
 	$donation_data = array(
109 108
 		'price'        => $price,
110 109
 		'purchase_key' => $purchase_key,
111 110
 		'user_email'   => $user['user_email'],
112
-		'date'         => date( 'Y-m-d H:i:s', current_time( 'timestamp' ) ),
113
-		'user_info'    => stripslashes_deep( $user_info ),
111
+		'date'         => date('Y-m-d H:i:s', current_time('timestamp')),
112
+		'user_info'    => stripslashes_deep($user_info),
114 113
 		'post_data'    => $_POST,
115 114
 		'gateway'      => $valid_data['gateway'],
116 115
 		'card_info'    => $valid_data['cc_info'],
@@ -130,10 +129,10 @@  discard block
 block discarded – undo
130 129
 	 * @param array $user_info Array containing basic user information.
131 130
 	 * @param bool|array $valid_data Validate fields.
132 131
 	 */
133
-	do_action( 'give_checkout_before_gateway', $_POST, $user_info, $valid_data );
132
+	do_action('give_checkout_before_gateway', $_POST, $user_info, $valid_data);
134 133
 
135 134
 	// Sanity check for price
136
-	if ( ! $donation_data['price'] ) {
135
+	if ( ! $donation_data['price']) {
137 136
 		// Revert to manual
138 137
 		$donation_data['gateway'] = 'manual';
139 138
 		$_POST['give-gateway']    = 'manual';
@@ -144,27 +143,27 @@  discard block
 block discarded – undo
144 143
 	 *
145 144
 	 * @since 1.7
146 145
 	 */
147
-	$donation_data = apply_filters( 'give_donation_data_before_gateway', $donation_data, $valid_data );
146
+	$donation_data = apply_filters('give_donation_data_before_gateway', $donation_data, $valid_data);
148 147
 
149 148
 	// Setup the data we're storing in the donation session
150 149
 	$session_data = $donation_data;
151 150
 
152 151
 	// Make sure credit card numbers are never stored in sessions
153
-	unset( $session_data['card_info']['card_number'] );
154
-	unset( $session_data['post_data']['card_number'] );
152
+	unset($session_data['card_info']['card_number']);
153
+	unset($session_data['post_data']['card_number']);
155 154
 
156 155
 	// Used for showing data to non logged-in users after donation, and for other plugins needing donation data.
157
-	give_set_purchase_session( $session_data );
156
+	give_set_purchase_session($session_data);
158 157
 
159 158
 	// Send info to the gateway for payment processing
160
-	give_send_to_gateway( $donation_data['gateway'], $donation_data );
159
+	give_send_to_gateway($donation_data['gateway'], $donation_data);
161 160
 	give_die();
162 161
 
163 162
 }
164 163
 
165
-add_action( 'give_purchase', 'give_process_donation_form' );
166
-add_action( 'wp_ajax_give_process_donation', 'give_process_donation_form' );
167
-add_action( 'wp_ajax_nopriv_give_process_donation', 'give_process_donation_form' );
164
+add_action('give_purchase', 'give_process_donation_form');
165
+add_action('wp_ajax_give_process_donation', 'give_process_donation_form');
166
+add_action('wp_ajax_nopriv_give_process_donation', 'give_process_donation_form');
168 167
 
169 168
 
170 169
 /**
@@ -177,29 +176,29 @@  discard block
 block discarded – undo
177 176
  *
178 177
  * @return void
179 178
  */
180
-function give_check_logged_in_user_for_existing_email( $valid_data, $post ) {
179
+function give_check_logged_in_user_for_existing_email($valid_data, $post) {
181 180
 
182 181
 	// Verify that the email address belongs to this customer.
183
-	if ( is_user_logged_in() ) {
182
+	if (is_user_logged_in()) {
184 183
 
185 184
 		$submitted_email = $valid_data['logged_in_user']['user_email'];
186
-		$donor           = new Give_Donor( get_current_user_id(), true );
185
+		$donor           = new Give_Donor(get_current_user_id(), true);
187 186
 
188 187
 		// If this email address is not registered with this customer, see if it belongs to any other customer
189 188
 		if (
190 189
 			$submitted_email !== $donor->email
191
-			&& ( is_array( $donor->emails ) && ! in_array( $submitted_email, $donor->emails ) )
190
+			&& (is_array($donor->emails) && ! in_array($submitted_email, $donor->emails))
192 191
 		) {
193
-			$found_donor = new Give_Donor( $submitted_email );
192
+			$found_donor = new Give_Donor($submitted_email);
194 193
 
195
-			if ( $found_donor->id > 0 ) {
196
-				give_set_error( 'give-customer-email-exists', sprintf( __( 'You are logged in as %1$s, and are submitting a donation as %2$s, which is an existing donor. To ensure that the email address is tied to the correct donor, please submit this donation from a logged-out browser, or choose another email address.', 'give' ), $donor->email, $submitted_email ) );
194
+			if ($found_donor->id > 0) {
195
+				give_set_error('give-customer-email-exists', sprintf(__('You are logged in as %1$s, and are submitting a donation as %2$s, which is an existing donor. To ensure that the email address is tied to the correct donor, please submit this donation from a logged-out browser, or choose another email address.', 'give'), $donor->email, $submitted_email));
197 196
 			}
198 197
 		}
199 198
 	}
200 199
 }
201 200
 
202
-add_action( 'give_checkout_error_checks', 'give_check_logged_in_user_for_existing_email', 10, 2 );
201
+add_action('give_checkout_error_checks', 'give_check_logged_in_user_for_existing_email', 10, 2);
203 202
 
204 203
 /**
205 204
  * Process the checkout login form
@@ -209,49 +208,49 @@  discard block
 block discarded – undo
209 208
  * @return      void
210 209
  */
211 210
 function give_process_form_login() {
212
-	$is_ajax = isset( $_POST['give_ajax'] );
211
+	$is_ajax = isset($_POST['give_ajax']);
213 212
 
214 213
 	$user_data = give_donation_form_validate_user_login();
215 214
 
216
-	if ( give_get_errors() || $user_data['user_id'] < 1 ) {
217
-		if ( $is_ajax ) {
215
+	if (give_get_errors() || $user_data['user_id'] < 1) {
216
+		if ($is_ajax) {
218 217
 			/**
219 218
 			 * Fires when AJAX sends back errors from the donation form.
220 219
 			 *
221 220
 			 * @since 1.0
222 221
 			 */
223 222
 			ob_start();
224
-			do_action( 'give_ajax_donation_errors' );
223
+			do_action('give_ajax_donation_errors');
225 224
 			$message = ob_get_contents();
226 225
 			ob_end_clean();
227
-			wp_send_json_error( $message );
226
+			wp_send_json_error($message);
228 227
 		} else {
229
-			wp_redirect( $_SERVER['HTTP_REFERER'] );
228
+			wp_redirect($_SERVER['HTTP_REFERER']);
230 229
 			exit;
231 230
 		}
232 231
 	}
233 232
 
234
-	give_log_user_in( $user_data['user_id'], $user_data['user_login'], $user_data['user_pass'] );
233
+	give_log_user_in($user_data['user_id'], $user_data['user_login'], $user_data['user_pass']);
235 234
 
236
-	if ( $is_ajax ) {
235
+	if ($is_ajax) {
237 236
 		$message = Give()->notices->print_frontend_notice(
238 237
 			sprintf(
239 238
 			/* translators: %s: user first name */
240
-				esc_html__( 'Welcome %s! You have successfully logged into your account.', 'give' ),
241
-				( ! empty( $user_data['user_first'] ) ) ? $user_data['user_first'] : $user_data['user_login']
239
+				esc_html__('Welcome %s! You have successfully logged into your account.', 'give'),
240
+				( ! empty($user_data['user_first'])) ? $user_data['user_first'] : $user_data['user_login']
242 241
 			),
243 242
 			false,
244 243
 			'success'
245 244
 		);
246 245
 
247
-		wp_send_json_success( $message );
246
+		wp_send_json_success($message);
248 247
 	} else {
249
-		wp_redirect( $_SERVER['HTTP_REFERER'] );
248
+		wp_redirect($_SERVER['HTTP_REFERER']);
250 249
 	}
251 250
 }
252 251
 
253
-add_action( 'wp_ajax_give_process_donation_login', 'give_process_form_login' );
254
-add_action( 'wp_ajax_nopriv_give_process_donation_login', 'give_process_form_login' );
252
+add_action('wp_ajax_give_process_donation_login', 'give_process_form_login');
253
+add_action('wp_ajax_nopriv_give_process_donation_login', 'give_process_form_login');
255 254
 
256 255
 /**
257 256
  * Donation Form Validate Fields.
@@ -263,55 +262,55 @@  discard block
 block discarded – undo
263 262
 function give_donation_form_validate_fields() {
264 263
 
265 264
 	// Check if there is $_POST
266
-	if ( empty( $_POST ) ) {
265
+	if (empty($_POST)) {
267 266
 		return false;
268 267
 	}
269 268
 
270
-	$form_id = isset( $_POST['give-form-id'] ) ? $_POST['give-form-id'] : '';
269
+	$form_id = isset($_POST['give-form-id']) ? $_POST['give-form-id'] : '';
271 270
 
272 271
 	// Start an array to collect valid data
273 272
 	$valid_data = array(
274 273
 		'gateway'          => give_donation_form_validate_gateway(), // Gateway fallback (amount is validated here)
275
-		'need_new_user'    => false,     // New user flag
276
-		'need_user_login'  => false,     // Login user flag
277
-		'logged_user_data' => array(),   // Logged user collected data
278
-		'new_user_data'    => array(),   // New user collected data
279
-		'login_user_data'  => array(),   // Login user collected data
280
-		'guest_user_data'  => array(),   // Guest user collected data
281
-		'cc_info'          => give_donation_form_validate_cc(),// Credit card info
274
+		'need_new_user'    => false, // New user flag
275
+		'need_user_login'  => false, // Login user flag
276
+		'logged_user_data' => array(), // Logged user collected data
277
+		'new_user_data'    => array(), // New user collected data
278
+		'login_user_data'  => array(), // Login user collected data
279
+		'guest_user_data'  => array(), // Guest user collected data
280
+		'cc_info'          => give_donation_form_validate_cc(), // Credit card info
282 281
 	);
283 282
 
284 283
 	// Validate Honeypot First
285
-	if ( ! empty( $_POST['give-honeypot'] ) ) {
286
-		give_set_error( 'invalid_honeypot', esc_html__( 'Honeypot field detected. Go away bad bot!', 'give' ) );
284
+	if ( ! empty($_POST['give-honeypot'])) {
285
+		give_set_error('invalid_honeypot', esc_html__('Honeypot field detected. Go away bad bot!', 'give'));
287 286
 	}
288 287
 
289 288
 	// Validate agree to terms
290
-	if ( give_is_terms_enabled( $form_id ) ) {
289
+	if (give_is_terms_enabled($form_id)) {
291 290
 		give_donation_form_validate_agree_to_terms();
292 291
 	}
293 292
 
294 293
 	// Stop processing donor registration, if donor registration is optional and donor can do guest checkout.
295 294
 	// If registration form username field is empty that means donor do not want to registration instead want guest checkout.
296 295
 	if (
297
-		! give_logged_in_only( $form_id )
298
-		&& isset( $_POST['give-purchase-var'] )
296
+		! give_logged_in_only($form_id)
297
+		&& isset($_POST['give-purchase-var'])
299 298
 		&& $_POST['give-purchase-var'] == 'needs-to-register'
300
-		&& empty( $_POST['give_user_login'] )
299
+		&& empty($_POST['give_user_login'])
301 300
 	) {
302
-		unset( $_POST['give-purchase-var'] );
301
+		unset($_POST['give-purchase-var']);
303 302
 	}
304 303
 
305
-	if ( is_user_logged_in() ) {
304
+	if (is_user_logged_in()) {
306 305
 		// Collect logged in user data.
307 306
 		$valid_data['logged_in_user'] = give_donation_form_validate_logged_in_user();
308
-	} elseif ( isset( $_POST['give-purchase-var'] ) && $_POST['give-purchase-var'] == 'needs-to-register' ) {
307
+	} elseif (isset($_POST['give-purchase-var']) && $_POST['give-purchase-var'] == 'needs-to-register') {
309 308
 		// Set new user registration as required.
310 309
 		$valid_data['need_new_user'] = true;
311 310
 		// Validate new user data.
312 311
 		$valid_data['new_user_data'] = give_donation_form_validate_new_user();
313 312
 		// Check if login validation is needed.
314
-	} elseif ( isset( $_POST['give-purchase-var'] ) && $_POST['give-purchase-var'] == 'needs-to-login' ) {
313
+	} elseif (isset($_POST['give-purchase-var']) && $_POST['give-purchase-var'] == 'needs-to-login') {
315 314
 		// Set user login as required.
316 315
 		$valid_data['need_user_login'] = true;
317 316
 		// Validate users login info.
@@ -336,41 +335,41 @@  discard block
 block discarded – undo
336 335
  */
337 336
 function give_donation_form_validate_gateway() {
338 337
 
339
-	$form_id = isset( $_REQUEST['give-form-id'] ) ? $_REQUEST['give-form-id'] : 0;
340
-	$amount  = isset( $_REQUEST['give-amount'] ) ? give_maybe_sanitize_amount( $_REQUEST['give-amount'] ) : 0;
341
-	$gateway = give_get_default_gateway( $form_id );
338
+	$form_id = isset($_REQUEST['give-form-id']) ? $_REQUEST['give-form-id'] : 0;
339
+	$amount  = isset($_REQUEST['give-amount']) ? give_maybe_sanitize_amount($_REQUEST['give-amount']) : 0;
340
+	$gateway = give_get_default_gateway($form_id);
342 341
 
343 342
 	// Check if a gateway value is present.
344
-	if ( ! empty( $_REQUEST['give-gateway'] ) ) {
343
+	if ( ! empty($_REQUEST['give-gateway'])) {
345 344
 
346
-		$gateway = sanitize_text_field( $_REQUEST['give-gateway'] );
345
+		$gateway = sanitize_text_field($_REQUEST['give-gateway']);
347 346
 
348 347
 		// Is amount being donated in LIVE mode 0.00? If so, error:
349
-		if ( $amount == 0 && ! give_is_test_mode() ) {
348
+		if ($amount == 0 && ! give_is_test_mode()) {
350 349
 
351
-			give_set_error( 'invalid_donation_amount', __( 'Please insert a valid donation amount.', 'give' ) );
350
+			give_set_error('invalid_donation_amount', __('Please insert a valid donation amount.', 'give'));
352 351
 
353 352
 		} // End if().
354
-		elseif ( ! give_verify_minimum_price() ) {
353
+		elseif ( ! give_verify_minimum_price()) {
355 354
 			// translators: %s: minimum donation amount.
356 355
 			give_set_error(
357 356
 				'invalid_donation_minimum',
358 357
 				sprintf(
359 358
 				/* translators: %s: minimum donation amount */
360
-					__( 'This form has a minimum donation amount of %s.', 'give' ),
361
-					give_currency_filter( give_format_amount( give_get_form_minimum_price( $form_id ), array( 'sanitize' => false ) ) )
359
+					__('This form has a minimum donation amount of %s.', 'give'),
360
+					give_currency_filter(give_format_amount(give_get_form_minimum_price($form_id), array('sanitize' => false)))
362 361
 				)
363 362
 			);
364 363
 
365 364
 		} //Is this test mode zero donation? Let it through but set to manual gateway.
366
-		elseif ( $amount == 0 && give_is_test_mode() ) {
365
+		elseif ($amount == 0 && give_is_test_mode()) {
367 366
 
368 367
 			$gateway = 'manual';
369 368
 
370 369
 		} //Check if this gateway is active.
371
-		elseif ( ! give_is_gateway_active( $gateway ) ) {
370
+		elseif ( ! give_is_gateway_active($gateway)) {
372 371
 
373
-			give_set_error( 'invalid_gateway', __( 'The selected payment gateway is not enabled.', 'give' ) );
372
+			give_set_error('invalid_gateway', __('The selected payment gateway is not enabled.', 'give'));
374 373
 
375 374
 		}
376 375
 	}
@@ -388,21 +387,21 @@  discard block
 block discarded – undo
388 387
  */
389 388
 function give_verify_minimum_price() {
390 389
 
391
-	$amount          = give_maybe_sanitize_amount( $_REQUEST['give-amount'] );
392
-	$form_id         = isset( $_REQUEST['give-form-id'] ) ? $_REQUEST['give-form-id'] : 0;
393
-	$price_id        = isset( $_REQUEST['give-price-id'] ) ? $_REQUEST['give-price-id'] : null;
394
-	$variable_prices = give_has_variable_prices( $form_id );
390
+	$amount          = give_maybe_sanitize_amount($_REQUEST['give-amount']);
391
+	$form_id         = isset($_REQUEST['give-form-id']) ? $_REQUEST['give-form-id'] : 0;
392
+	$price_id        = isset($_REQUEST['give-price-id']) ? $_REQUEST['give-price-id'] : null;
393
+	$variable_prices = give_has_variable_prices($form_id);
395 394
 
396
-	if ( $variable_prices && in_array( $price_id, give_get_variable_price_ids( $form_id ) ) ) {
395
+	if ($variable_prices && in_array($price_id, give_get_variable_price_ids($form_id))) {
397 396
 
398
-		$price_level_amount = give_get_price_option_amount( $form_id, $price_id );
397
+		$price_level_amount = give_get_price_option_amount($form_id, $price_id);
399 398
 
400
-		if ( $price_level_amount == $amount ) {
399
+		if ($price_level_amount == $amount) {
401 400
 			return true;
402 401
 		}
403 402
 	}
404 403
 
405
-	if ( give_get_form_minimum_price( $form_id ) > $amount ) {
404
+	if (give_get_form_minimum_price($form_id) > $amount) {
406 405
 		return false;
407 406
 	}
408 407
 
@@ -418,9 +417,9 @@  discard block
 block discarded – undo
418 417
  */
419 418
 function give_donation_form_validate_agree_to_terms() {
420 419
 	// Validate agree to terms.
421
-	if ( ! isset( $_POST['give_agree_to_terms'] ) || $_POST['give_agree_to_terms'] != 1 ) {
420
+	if ( ! isset($_POST['give_agree_to_terms']) || $_POST['give_agree_to_terms'] != 1) {
422 421
 		// User did not agree.
423
-		give_set_error( 'agree_to_terms', apply_filters( 'give_agree_to_terms_text', __( 'You must agree to the terms and conditions.', 'give' ) ) );
422
+		give_set_error('agree_to_terms', apply_filters('give_agree_to_terms_text', __('You must agree to the terms and conditions.', 'give')));
424 423
 	}
425 424
 }
426 425
 
@@ -434,59 +433,59 @@  discard block
 block discarded – undo
434 433
  *
435 434
  * @return      array
436 435
  */
437
-function give_get_required_fields( $form_id ) {
436
+function give_get_required_fields($form_id) {
438 437
 
439
-	$payment_mode = give_get_chosen_gateway( $form_id );
438
+	$payment_mode = give_get_chosen_gateway($form_id);
440 439
 
441 440
 	$required_fields = array(
442 441
 		'give_email' => array(
443 442
 			'error_id'      => 'invalid_email',
444
-			'error_message' => __( 'Please enter a valid email address.', 'give' ),
443
+			'error_message' => __('Please enter a valid email address.', 'give'),
445 444
 		),
446 445
 		'give_first' => array(
447 446
 			'error_id'      => 'invalid_first_name',
448
-			'error_message' => __( 'Please enter your first name.', 'give' ),
447
+			'error_message' => __('Please enter your first name.', 'give'),
449 448
 		),
450 449
 	);
451 450
 
452
-	$require_address = give_require_billing_address( $payment_mode );
451
+	$require_address = give_require_billing_address($payment_mode);
453 452
 
454
-	if ( $require_address ) {
455
-		$required_fields['card_address']    = array(
453
+	if ($require_address) {
454
+		$required_fields['card_address'] = array(
456 455
 			'error_id'      => 'invalid_card_address',
457
-			'error_message' => __( 'Please enter your primary billing address.', 'give' ),
456
+			'error_message' => __('Please enter your primary billing address.', 'give'),
458 457
 		);
459
-		$required_fields['card_zip']        = array(
458
+		$required_fields['card_zip'] = array(
460 459
 			'error_id'      => 'invalid_zip_code',
461
-			'error_message' => __( 'Please enter your zip / postal code.', 'give' ),
460
+			'error_message' => __('Please enter your zip / postal code.', 'give'),
462 461
 		);
463
-		$required_fields['card_city']       = array(
462
+		$required_fields['card_city'] = array(
464 463
 			'error_id'      => 'invalid_city',
465
-			'error_message' => __( 'Please enter your billing city.', 'give' ),
464
+			'error_message' => __('Please enter your billing city.', 'give'),
466 465
 		);
467 466
 		$required_fields['billing_country'] = array(
468 467
 			'error_id'      => 'invalid_country',
469
-			'error_message' => __( 'Please select your billing country.', 'give' ),
468
+			'error_message' => __('Please select your billing country.', 'give'),
470 469
 		);
471 470
 
472 471
 
473 472
 		$required_fields['card_state'] = array(
474 473
 			'error_id'      => 'invalid_state',
475
-			'error_message' => __( 'Please enter billing state / province / County.', 'give' ),
474
+			'error_message' => __('Please enter billing state / province / County.', 'give'),
476 475
 		);
477 476
 
478 477
 		// Check if billing country alredy exists.
479
-		if ( ! empty( $_POST['billing_country'] ) ) {
478
+		if ( ! empty($_POST['billing_country'])) {
480 479
 			// Get the value from $_POST.
481
-			$country = sanitize_text_field( $_POST['billing_country'] );
480
+			$country = sanitize_text_field($_POST['billing_country']);
482 481
 
483 482
 			// Get the country list that does not required any states init.
484 483
 			$states_country = give_states_not_required_country_list();
485 484
 
486 485
 			// Check if states is empty or not.
487
-			if ( array_key_exists( $country, $states_country ) ) {
486
+			if (array_key_exists($country, $states_country)) {
488 487
 				// If states is empty remove the required feilds of state in billing cart.
489
-				unset( $required_fields['card_state'] );
488
+				unset($required_fields['card_state']);
490 489
 			}
491 490
 		}
492 491
 	}
@@ -496,7 +495,7 @@  discard block
 block discarded – undo
496 495
 	 *
497 496
 	 * @since 1.7
498 497
 	 */
499
-	$required_fields = apply_filters( 'give_donation_form_required_fields', $required_fields, $form_id );
498
+	$required_fields = apply_filters('give_donation_form_required_fields', $required_fields, $form_id);
500 499
 
501 500
 	return $required_fields;
502 501
 
@@ -511,16 +510,16 @@  discard block
 block discarded – undo
511 510
  *
512 511
  * @return bool
513 512
  */
514
-function give_require_billing_address( $payment_mode ) {
513
+function give_require_billing_address($payment_mode) {
515 514
 
516 515
 	$return = false;
517 516
 
518
-	if ( isset( $_POST['billing_country'] ) || did_action( "give_{$payment_mode}_cc_form" ) || did_action( 'give_cc_form' ) ) {
517
+	if (isset($_POST['billing_country']) || did_action("give_{$payment_mode}_cc_form") || did_action('give_cc_form')) {
519 518
 		$return = true;
520 519
 	}
521 520
 
522 521
 	// Let payment gateways and other extensions determine if address fields should be required.
523
-	return apply_filters( 'give_require_billing_address', $return );
522
+	return apply_filters('give_require_billing_address', $return);
524 523
 
525 524
 }
526 525
 
@@ -534,42 +533,42 @@  discard block
 block discarded – undo
534 533
 function give_donation_form_validate_logged_in_user() {
535 534
 	global $user_ID;
536 535
 
537
-	$form_id = isset( $_POST['give-form-id'] ) ? $_POST['give-form-id'] : '';
536
+	$form_id = isset($_POST['give-form-id']) ? $_POST['give-form-id'] : '';
538 537
 
539 538
 	// Start empty array to collect valid user data.
540 539
 	$valid_user_data = array(
541 540
 		// Assume there will be errors.
542
-		'user_id' => - 1,
541
+		'user_id' => -1,
543 542
 	);
544 543
 
545 544
 	// Verify there is a user_ID.
546
-	if ( $user_ID > 0 ) {
545
+	if ($user_ID > 0) {
547 546
 		// Get the logged in user data.
548
-		$user_data = get_userdata( $user_ID );
547
+		$user_data = get_userdata($user_ID);
549 548
 
550 549
 		// Loop through required fields and show error messages.
551
-		foreach ( give_get_required_fields( $form_id ) as $field_name => $value ) {
552
-			if ( in_array( $value, give_get_required_fields( $form_id ) ) && empty( $_POST[ $field_name ] ) ) {
553
-				give_set_error( $value['error_id'], $value['error_message'] );
550
+		foreach (give_get_required_fields($form_id) as $field_name => $value) {
551
+			if (in_array($value, give_get_required_fields($form_id)) && empty($_POST[$field_name])) {
552
+				give_set_error($value['error_id'], $value['error_message']);
554 553
 			}
555 554
 		}
556 555
 
557 556
 		// Verify data.
558
-		if ( $user_data ) {
557
+		if ($user_data) {
559 558
 			// Collected logged in user data.
560 559
 			$valid_user_data = array(
561 560
 				'user_id'    => $user_ID,
562
-				'user_email' => isset( $_POST['give_email'] ) ? sanitize_email( $_POST['give_email'] ) : $user_data->user_email,
563
-				'user_first' => isset( $_POST['give_first'] ) && ! empty( $_POST['give_first'] ) ? sanitize_text_field( $_POST['give_first'] ) : $user_data->first_name,
564
-				'user_last'  => isset( $_POST['give_last'] ) && ! empty( $_POST['give_last'] ) ? sanitize_text_field( $_POST['give_last'] ) : $user_data->last_name,
561
+				'user_email' => isset($_POST['give_email']) ? sanitize_email($_POST['give_email']) : $user_data->user_email,
562
+				'user_first' => isset($_POST['give_first']) && ! empty($_POST['give_first']) ? sanitize_text_field($_POST['give_first']) : $user_data->first_name,
563
+				'user_last'  => isset($_POST['give_last']) && ! empty($_POST['give_last']) ? sanitize_text_field($_POST['give_last']) : $user_data->last_name,
565 564
 			);
566 565
 
567
-			if ( ! is_email( $valid_user_data['user_email'] ) ) {
568
-				give_set_error( 'email_invalid', esc_html__( 'Invalid email.', 'give' ) );
566
+			if ( ! is_email($valid_user_data['user_email'])) {
567
+				give_set_error('email_invalid', esc_html__('Invalid email.', 'give'));
569 568
 			}
570 569
 		} else {
571 570
 			// Set invalid user error.
572
-			give_set_error( 'invalid_user', esc_html__( 'The user information is invalid.', 'give' ) );
571
+			give_set_error('invalid_user', esc_html__('The user information is invalid.', 'give'));
573 572
 		}
574 573
 	}
575 574
 
@@ -588,7 +587,7 @@  discard block
 block discarded – undo
588 587
 	// Default user data.
589 588
 	$default_user_data = array(
590 589
 		'give-form-id'           => '',
591
-		'user_id'                => - 1, // Assume there will be errors.
590
+		'user_id'                => -1, // Assume there will be errors.
592 591
 		'user_first'             => '',
593 592
 		'user_last'              => '',
594 593
 		'give_user_login'        => false,
@@ -598,14 +597,14 @@  discard block
 block discarded – undo
598 597
 	);
599 598
 
600 599
 	// Get user data.
601
-	$user_data            = wp_parse_args( array_map( 'trim', give_clean( $_POST ) ), $default_user_data );
600
+	$user_data            = wp_parse_args(array_map('trim', give_clean($_POST)), $default_user_data);
602 601
 	$registering_new_user = false;
603
-	$form_id              = absint( $user_data['give-form-id'] );
602
+	$form_id              = absint($user_data['give-form-id']);
604 603
 
605 604
 	// Start an empty array to collect valid user data.
606 605
 	$valid_user_data = array(
607 606
 		// Assume there will be errors.
608
-		'user_id'    => - 1,
607
+		'user_id'    => -1,
609 608
 
610 609
 		// Get first name.
611 610
 		'user_first' => $user_data['give_first'],
@@ -615,25 +614,25 @@  discard block
 block discarded – undo
615 614
 	);
616 615
 
617 616
 	// Loop through required fields and show error messages.
618
-	foreach ( give_get_required_fields( $form_id ) as $field_name => $value ) {
619
-		if ( in_array( $value, give_get_required_fields( $form_id ) ) && empty( $_POST[ $field_name ] ) ) {
620
-			give_set_error( $value['error_id'], $value['error_message'] );
617
+	foreach (give_get_required_fields($form_id) as $field_name => $value) {
618
+		if (in_array($value, give_get_required_fields($form_id)) && empty($_POST[$field_name])) {
619
+			give_set_error($value['error_id'], $value['error_message']);
621 620
 		}
622 621
 	}
623 622
 
624 623
 	// Check if we have an username to register.
625
-	if ( give_validate_username( $user_data['give_user_login'] ) ) {
624
+	if (give_validate_username($user_data['give_user_login'])) {
626 625
 		$registering_new_user          = true;
627 626
 		$valid_user_data['user_login'] = $user_data['give_user_login'];
628 627
 	}
629 628
 
630 629
 	// Check if we have an email to verify.
631
-	if ( give_validate_user_email( $user_data['give_email'], $registering_new_user ) ) {
630
+	if (give_validate_user_email($user_data['give_email'], $registering_new_user)) {
632 631
 		$valid_user_data['user_email'] = $user_data['give_email'];
633 632
 	}
634 633
 
635 634
 	// Check password.
636
-	if ( give_validate_user_password( $user_data['give_user_pass'], $user_data['give_user_pass_confirm'], $registering_new_user ) ) {
635
+	if (give_validate_user_password($user_data['give_user_pass'], $user_data['give_user_pass_confirm'], $registering_new_user)) {
637 636
 		// All is good to go.
638 637
 		$valid_user_data['user_pass'] = $user_data['give_user_pass'];
639 638
 	}
@@ -653,36 +652,36 @@  discard block
 block discarded – undo
653 652
 	// Start an array to collect valid user data.
654 653
 	$valid_user_data = array(
655 654
 		// Assume there will be errors.
656
-		'user_id' => - 1,
655
+		'user_id' => -1,
657 656
 	);
658 657
 
659 658
 	// Username.
660
-	if ( ! isset( $_POST['give_user_login'] ) || $_POST['give_user_login'] == '' ) {
661
-		give_set_error( 'must_log_in', __( 'You must register or login to complete your donation.', 'give' ) );
659
+	if ( ! isset($_POST['give_user_login']) || $_POST['give_user_login'] == '') {
660
+		give_set_error('must_log_in', __('You must register or login to complete your donation.', 'give'));
662 661
 
663 662
 		return $valid_user_data;
664 663
 	}
665 664
 
666 665
 	// Get the user by login.
667
-	$user_data = get_user_by( 'login', strip_tags( $_POST['give_user_login'] ) );
666
+	$user_data = get_user_by('login', strip_tags($_POST['give_user_login']));
668 667
 
669 668
 	// Check if user exists.
670
-	if ( $user_data ) {
669
+	if ($user_data) {
671 670
 		// Get password.
672
-		$user_pass = isset( $_POST['give_user_pass'] ) ? $_POST['give_user_pass'] : false;
671
+		$user_pass = isset($_POST['give_user_pass']) ? $_POST['give_user_pass'] : false;
673 672
 
674 673
 		// Check user_pass.
675
-		if ( $user_pass ) {
674
+		if ($user_pass) {
676 675
 			// Check if password is valid.
677
-			if ( ! wp_check_password( $user_pass, $user_data->user_pass, $user_data->ID ) ) {
676
+			if ( ! wp_check_password($user_pass, $user_data->user_pass, $user_data->ID)) {
678 677
 				// Incorrect password.
679 678
 				give_set_error(
680 679
 					'password_incorrect',
681 680
 					sprintf(
682 681
 						'%1$s <a href="%2$s">%3$s</a>',
683
-						__( 'The password you entered is incorrect.', 'give' ),
684
-						wp_lostpassword_url( "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]" ),
685
-						__( 'Reset Password', 'give' )
682
+						__('The password you entered is incorrect.', 'give'),
683
+						wp_lostpassword_url("http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"),
684
+						__('Reset Password', 'give')
686 685
 					)
687 686
 				);
688 687
 				// All is correct.
@@ -699,11 +698,11 @@  discard block
 block discarded – undo
699 698
 			}
700 699
 		} else {
701 700
 			// Empty password.
702
-			give_set_error( 'password_empty', __( 'Enter a password.', 'give' ) );
701
+			give_set_error('password_empty', __('Enter a password.', 'give'));
703 702
 		}
704 703
 	} else {
705 704
 		// No username.
706
-		give_set_error( 'username_incorrect', __( 'The username you entered does not exist.', 'give' ) );
705
+		give_set_error('username_incorrect', __('The username you entered does not exist.', 'give'));
707 706
 	}// End if().
708 707
 
709 708
 	return $valid_user_data;
@@ -718,7 +717,7 @@  discard block
 block discarded – undo
718 717
  */
719 718
 function give_donation_form_validate_guest_user() {
720 719
 
721
-	$form_id = isset( $_POST['give-form-id'] ) ? $_POST['give-form-id'] : '';
720
+	$form_id = isset($_POST['give-form-id']) ? $_POST['give-form-id'] : '';
722 721
 
723 722
 	// Start an array to collect valid user data.
724 723
 	$valid_user_data = array(
@@ -727,38 +726,38 @@  discard block
 block discarded – undo
727 726
 	);
728 727
 
729 728
 	// Show error message if user must be logged in.
730
-	if ( give_logged_in_only( $form_id ) ) {
731
-		give_set_error( 'logged_in_only', __( 'You must be logged in to donate.', 'give' ) );
729
+	if (give_logged_in_only($form_id)) {
730
+		give_set_error('logged_in_only', __('You must be logged in to donate.', 'give'));
732 731
 	}
733 732
 
734 733
 	// Get the guest email.
735
-	$guest_email = isset( $_POST['give_email'] ) ? $_POST['give_email'] : false;
734
+	$guest_email = isset($_POST['give_email']) ? $_POST['give_email'] : false;
736 735
 
737 736
 	// Check email.
738
-	if ( $guest_email && strlen( $guest_email ) > 0 ) {
737
+	if ($guest_email && strlen($guest_email) > 0) {
739 738
 		// Validate email.
740
-		if ( ! is_email( $guest_email ) ) {
739
+		if ( ! is_email($guest_email)) {
741 740
 			// Invalid email.
742
-			give_set_error( 'email_invalid', __( 'Invalid email.', 'give' ) );
741
+			give_set_error('email_invalid', __('Invalid email.', 'give'));
743 742
 		} else {
744 743
 			// All is good to go.
745 744
 			$valid_user_data['user_email'] = $guest_email;
746 745
 
747 746
 			// Get user_id from donor if exist.
748
-			$donor = new Give_Donor( $guest_email );
749
-			if ( $donor->id && $donor->user_id ) {
747
+			$donor = new Give_Donor($guest_email);
748
+			if ($donor->id && $donor->user_id) {
750 749
 				$valid_user_data['user_id'] = $donor->user_id;
751 750
 			}
752 751
 		}
753 752
 	} else {
754 753
 		// No email.
755
-		give_set_error( 'email_empty', __( 'Enter an email.', 'give' ) );
754
+		give_set_error('email_empty', __('Enter an email.', 'give'));
756 755
 	}
757 756
 
758 757
 	// Loop through required fields and show error messages.
759
-	foreach ( give_get_required_fields( $form_id ) as $field_name => $value ) {
760
-		if ( in_array( $value, give_get_required_fields( $form_id ) ) && empty( $_POST[ $field_name ] ) ) {
761
-			give_set_error( $value['error_id'], $value['error_message'] );
758
+	foreach (give_get_required_fields($form_id) as $field_name => $value) {
759
+		if (in_array($value, give_get_required_fields($form_id)) && empty($_POST[$field_name])) {
760
+			give_set_error($value['error_id'], $value['error_message']);
762 761
 		}
763 762
 	}
764 763
 
@@ -774,36 +773,36 @@  discard block
 block discarded – undo
774 773
  * @since   1.0
775 774
  * @return  integer
776 775
  */
777
-function give_register_and_login_new_user( $user_data = array() ) {
776
+function give_register_and_login_new_user($user_data = array()) {
778 777
 	// Verify the array.
779
-	if ( empty( $user_data ) ) {
780
-		return - 1;
778
+	if (empty($user_data)) {
779
+		return -1;
781 780
 	}
782 781
 
783
-	if ( give_get_errors() ) {
784
-		return - 1;
782
+	if (give_get_errors()) {
783
+		return -1;
785 784
 	}
786 785
 
787
-	$user_args = apply_filters( 'give_insert_user_args', array(
788
-		'user_login'      => isset( $user_data['user_login'] ) ? $user_data['user_login'] : '',
789
-		'user_pass'       => isset( $user_data['user_pass'] ) ? $user_data['user_pass'] : '',
790
-		'user_email'      => isset( $user_data['user_email'] ) ? $user_data['user_email'] : '',
791
-		'first_name'      => isset( $user_data['user_first'] ) ? $user_data['user_first'] : '',
792
-		'last_name'       => isset( $user_data['user_last'] ) ? $user_data['user_last'] : '',
793
-		'user_registered' => date( 'Y-m-d H:i:s' ),
794
-		'role'            => give_get_option( 'donor_default_user_role', 'give_donor' ),
795
-	), $user_data );
786
+	$user_args = apply_filters('give_insert_user_args', array(
787
+		'user_login'      => isset($user_data['user_login']) ? $user_data['user_login'] : '',
788
+		'user_pass'       => isset($user_data['user_pass']) ? $user_data['user_pass'] : '',
789
+		'user_email'      => isset($user_data['user_email']) ? $user_data['user_email'] : '',
790
+		'first_name'      => isset($user_data['user_first']) ? $user_data['user_first'] : '',
791
+		'last_name'       => isset($user_data['user_last']) ? $user_data['user_last'] : '',
792
+		'user_registered' => date('Y-m-d H:i:s'),
793
+		'role'            => give_get_option('donor_default_user_role', 'give_donor'),
794
+	), $user_data);
796 795
 
797 796
 	// Insert new user.
798
-	$user_id = wp_insert_user( $user_args );
797
+	$user_id = wp_insert_user($user_args);
799 798
 
800 799
 	// Validate inserted user.
801
-	if ( is_wp_error( $user_id ) ) {
802
-		return - 1;
800
+	if (is_wp_error($user_id)) {
801
+		return -1;
803 802
 	}
804 803
 
805 804
 	// Allow themes and plugins to filter the user data.
806
-	$user_data = apply_filters( 'give_insert_user_data', $user_data, $user_args );
805
+	$user_data = apply_filters('give_insert_user_data', $user_data, $user_args);
807 806
 
808 807
 	/**
809 808
 	 * Fires after inserting user.
@@ -813,7 +812,7 @@  discard block
 block discarded – undo
813 812
 	 * @param int $user_id User id.
814 813
 	 * @param array $user_data Array containing user data.
815 814
 	 */
816
-	do_action( 'give_insert_user', $user_id, $user_data );
815
+	do_action('give_insert_user', $user_id, $user_data);
817 816
 
818 817
 	/**
819 818
 	 * Filter allow user to alter if user when to login or not when user is register for the first time.
@@ -822,9 +821,9 @@  discard block
 block discarded – undo
822 821
 	 *
823 822
 	 * return bool True if login with registration and False if only want to register.
824 823
 	 */
825
-	if ( true === (bool) apply_filters( 'give_log_user_in_on_register', true ) ) {
824
+	if (true === (bool) apply_filters('give_log_user_in_on_register', true)) {
826 825
 		// Login new user.
827
-		give_log_user_in( $user_id, $user_data['user_login'], $user_data['user_pass'] );
826
+		give_log_user_in($user_id, $user_data['user_login'], $user_data['user_pass']);
828 827
 	}
829 828
 
830 829
 	// Return user id.
@@ -840,27 +839,27 @@  discard block
 block discarded – undo
840 839
  * @since   1.0
841 840
  * @return  array|bool
842 841
  */
843
-function give_get_donation_form_user( $valid_data = array() ) {
842
+function give_get_donation_form_user($valid_data = array()) {
844 843
 
845 844
 	// Initialize user.
846 845
 	$user    = false;
847
-	$is_ajax = defined( 'DOING_AJAX' ) && DOING_AJAX;
846
+	$is_ajax = defined('DOING_AJAX') && DOING_AJAX;
848 847
 
849
-	if ( $is_ajax ) {
848
+	if ($is_ajax) {
850 849
 		// Do not create or login the user during the ajax submission (check for errors only).
851 850
 		return true;
852
-	} elseif ( is_user_logged_in() ) {
851
+	} elseif (is_user_logged_in()) {
853 852
 		// Set the valid user as the logged in collected data.
854 853
 		$user = $valid_data['logged_in_user'];
855
-	} elseif ( $valid_data['need_new_user'] === true || $valid_data['need_user_login'] === true ) {
854
+	} elseif ($valid_data['need_new_user'] === true || $valid_data['need_user_login'] === true) {
856 855
 		// New user registration.
857
-		if ( $valid_data['need_new_user'] === true ) {
856
+		if ($valid_data['need_new_user'] === true) {
858 857
 			// Set user.
859 858
 			$user = $valid_data['new_user_data'];
860 859
 			// Register and login new user.
861
-			$user['user_id'] = give_register_and_login_new_user( $user );
860
+			$user['user_id'] = give_register_and_login_new_user($user);
862 861
 			// User login
863
-		} elseif ( $valid_data['need_user_login'] === true && ! $is_ajax ) {
862
+		} elseif ($valid_data['need_user_login'] === true && ! $is_ajax) {
864 863
 
865 864
 			/**
866 865
 			 * The login form is now processed in the give_process_donation_login() function.
@@ -872,48 +871,48 @@  discard block
 block discarded – undo
872 871
 			// Set user.
873 872
 			$user = $valid_data['login_user_data'];
874 873
 			// Login user.
875
-			give_log_user_in( $user['user_id'], $user['user_login'], $user['user_pass'] );
874
+			give_log_user_in($user['user_id'], $user['user_login'], $user['user_pass']);
876 875
 		}
877 876
 	}
878 877
 
879 878
 	// Check guest checkout.
880
-	if ( false === $user && false === give_logged_in_only( $_POST['give-form-id'] ) ) {
879
+	if (false === $user && false === give_logged_in_only($_POST['give-form-id'])) {
881 880
 		// Set user
882 881
 		$user = $valid_data['guest_user_data'];
883 882
 	}
884 883
 
885 884
 	// Verify we have an user.
886
-	if ( false === $user || empty( $user ) ) {
885
+	if (false === $user || empty($user)) {
887 886
 		// Return false.
888 887
 		return false;
889 888
 	}
890 889
 
891 890
 	// Get user first name.
892
-	if ( ! isset( $user['user_first'] ) || strlen( trim( $user['user_first'] ) ) < 1 ) {
893
-		$user['user_first'] = isset( $_POST['give_first'] ) ? strip_tags( trim( $_POST['give_first'] ) ) : '';
891
+	if ( ! isset($user['user_first']) || strlen(trim($user['user_first'])) < 1) {
892
+		$user['user_first'] = isset($_POST['give_first']) ? strip_tags(trim($_POST['give_first'])) : '';
894 893
 	}
895 894
 
896 895
 	// Get user last name.
897
-	if ( ! isset( $user['user_last'] ) || strlen( trim( $user['user_last'] ) ) < 1 ) {
898
-		$user['user_last'] = isset( $_POST['give_last'] ) ? strip_tags( trim( $_POST['give_last'] ) ) : '';
896
+	if ( ! isset($user['user_last']) || strlen(trim($user['user_last'])) < 1) {
897
+		$user['user_last'] = isset($_POST['give_last']) ? strip_tags(trim($_POST['give_last'])) : '';
899 898
 	}
900 899
 
901 900
 	// Get the user's billing address details.
902 901
 	$user['address']            = array();
903
-	$user['address']['line1']   = ! empty( $_POST['card_address'] ) ? give_clean( $_POST['card_address'] ) : false;
904
-	$user['address']['line2']   = ! empty( $_POST['card_address_2'] ) ? give_clean( $_POST['card_address_2'] ) : false;
905
-	$user['address']['city']    = ! empty( $_POST['card_city'] ) ? give_clean( $_POST['card_city'] ) : false;
906
-	$user['address']['state']   = ! empty( $_POST['card_state'] ) ? give_clean( $_POST['card_state'] ) : false;
907
-	$user['address']['zip']     = ! empty( $_POST['card_zip'] ) ? give_clean( $_POST['card_zip'] ) : false;
908
-	$user['address']['country'] = ! empty( $_POST['billing_country'] ) ? give_clean( $_POST['billing_country'] ) : false;
909
-
910
-	if ( empty( $user['address']['country'] ) ) {
902
+	$user['address']['line1']   = ! empty($_POST['card_address']) ? give_clean($_POST['card_address']) : false;
903
+	$user['address']['line2']   = ! empty($_POST['card_address_2']) ? give_clean($_POST['card_address_2']) : false;
904
+	$user['address']['city']    = ! empty($_POST['card_city']) ? give_clean($_POST['card_city']) : false;
905
+	$user['address']['state']   = ! empty($_POST['card_state']) ? give_clean($_POST['card_state']) : false;
906
+	$user['address']['zip']     = ! empty($_POST['card_zip']) ? give_clean($_POST['card_zip']) : false;
907
+	$user['address']['country'] = ! empty($_POST['billing_country']) ? give_clean($_POST['billing_country']) : false;
908
+
909
+	if (empty($user['address']['country'])) {
911 910
 		$user['address'] = false;
912 911
 	} // End if().
913 912
 
914
-	if ( ! empty( $user['user_id'] ) && $user['user_id'] > 0 && ! empty( $user['address'] ) ) {
913
+	if ( ! empty($user['user_id']) && $user['user_id'] > 0 && ! empty($user['address'])) {
915 914
 		// Store the address in the user's meta so the donation form can be pre-populated with it on return donation.
916
-		update_user_meta( $user['user_id'], '_give_user_address', $user['address'] );
915
+		update_user_meta($user['user_id'], '_give_user_address', $user['address']);
917 916
 	}
918 917
 
919 918
 	// Return valid user.
@@ -932,16 +931,16 @@  discard block
 block discarded – undo
932 931
 	$card_data = give_get_donation_cc_info();
933 932
 
934 933
 	// Validate the card zip.
935
-	if ( ! empty( $card_data['card_zip'] ) ) {
936
-		if ( ! give_donation_form_validate_cc_zip( $card_data['card_zip'], $card_data['card_country'] ) ) {
937
-			give_set_error( 'invalid_cc_zip', __( 'The zip / postal code you entered for your billing address is invalid.', 'give' ) );
934
+	if ( ! empty($card_data['card_zip'])) {
935
+		if ( ! give_donation_form_validate_cc_zip($card_data['card_zip'], $card_data['card_country'])) {
936
+			give_set_error('invalid_cc_zip', __('The zip / postal code you entered for your billing address is invalid.', 'give'));
938 937
 		}
939 938
 	}
940 939
 
941 940
 	// Ensure no spaces.
942
-	if ( ! empty( $card_data['card_number'] ) ) {
943
-		$card_data['card_number'] = str_replace( '+', '', $card_data['card_number'] ); // no "+" signs
944
-		$card_data['card_number'] = str_replace( ' ', '', $card_data['card_number'] ); // No spaces
941
+	if ( ! empty($card_data['card_number'])) {
942
+		$card_data['card_number'] = str_replace('+', '', $card_data['card_number']); // no "+" signs
943
+		$card_data['card_number'] = str_replace(' ', '', $card_data['card_number']); // No spaces
945 944
 	}
946 945
 
947 946
 	// This should validate card numbers at some point too.
@@ -958,17 +957,17 @@  discard block
 block discarded – undo
958 957
 function give_get_donation_cc_info() {
959 958
 
960 959
 	$cc_info                   = array();
961
-	$cc_info['card_name']      = isset( $_POST['card_name'] ) ? sanitize_text_field( $_POST['card_name'] ) : '';
962
-	$cc_info['card_number']    = isset( $_POST['card_number'] ) ? sanitize_text_field( $_POST['card_number'] ) : '';
963
-	$cc_info['card_cvc']       = isset( $_POST['card_cvc'] ) ? sanitize_text_field( $_POST['card_cvc'] ) : '';
964
-	$cc_info['card_exp_month'] = isset( $_POST['card_exp_month'] ) ? sanitize_text_field( $_POST['card_exp_month'] ) : '';
965
-	$cc_info['card_exp_year']  = isset( $_POST['card_exp_year'] ) ? sanitize_text_field( $_POST['card_exp_year'] ) : '';
966
-	$cc_info['card_address']   = isset( $_POST['card_address'] ) ? sanitize_text_field( $_POST['card_address'] ) : '';
967
-	$cc_info['card_address_2'] = isset( $_POST['card_address_2'] ) ? sanitize_text_field( $_POST['card_address_2'] ) : '';
968
-	$cc_info['card_city']      = isset( $_POST['card_city'] ) ? sanitize_text_field( $_POST['card_city'] ) : '';
969
-	$cc_info['card_state']     = isset( $_POST['card_state'] ) ? sanitize_text_field( $_POST['card_state'] ) : '';
970
-	$cc_info['card_country']   = isset( $_POST['billing_country'] ) ? sanitize_text_field( $_POST['billing_country'] ) : '';
971
-	$cc_info['card_zip']       = isset( $_POST['card_zip'] ) ? sanitize_text_field( $_POST['card_zip'] ) : '';
960
+	$cc_info['card_name']      = isset($_POST['card_name']) ? sanitize_text_field($_POST['card_name']) : '';
961
+	$cc_info['card_number']    = isset($_POST['card_number']) ? sanitize_text_field($_POST['card_number']) : '';
962
+	$cc_info['card_cvc']       = isset($_POST['card_cvc']) ? sanitize_text_field($_POST['card_cvc']) : '';
963
+	$cc_info['card_exp_month'] = isset($_POST['card_exp_month']) ? sanitize_text_field($_POST['card_exp_month']) : '';
964
+	$cc_info['card_exp_year']  = isset($_POST['card_exp_year']) ? sanitize_text_field($_POST['card_exp_year']) : '';
965
+	$cc_info['card_address']   = isset($_POST['card_address']) ? sanitize_text_field($_POST['card_address']) : '';
966
+	$cc_info['card_address_2'] = isset($_POST['card_address_2']) ? sanitize_text_field($_POST['card_address_2']) : '';
967
+	$cc_info['card_city']      = isset($_POST['card_city']) ? sanitize_text_field($_POST['card_city']) : '';
968
+	$cc_info['card_state']     = isset($_POST['card_state']) ? sanitize_text_field($_POST['card_state']) : '';
969
+	$cc_info['card_country']   = isset($_POST['billing_country']) ? sanitize_text_field($_POST['billing_country']) : '';
970
+	$cc_info['card_zip']       = isset($_POST['card_zip']) ? sanitize_text_field($_POST['card_zip']) : '';
972 971
 
973 972
 	// Return cc info.
974 973
 	return $cc_info;
@@ -984,14 +983,14 @@  discard block
 block discarded – undo
984 983
  *
985 984
  * @return bool|mixed
986 985
  */
987
-function give_donation_form_validate_cc_zip( $zip = 0, $country_code = '' ) {
986
+function give_donation_form_validate_cc_zip($zip = 0, $country_code = '') {
988 987
 	$ret = false;
989 988
 
990
-	if ( empty( $zip ) || empty( $country_code ) ) {
989
+	if (empty($zip) || empty($country_code)) {
991 990
 		return $ret;
992 991
 	}
993 992
 
994
-	$country_code = strtoupper( $country_code );
993
+	$country_code = strtoupper($country_code);
995 994
 
996 995
 	$zip_regex = array(
997 996
 		'AD' => 'AD\d{3}',
@@ -1151,11 +1150,11 @@  discard block
 block discarded – undo
1151 1150
 		'ZM' => '\d{5}',
1152 1151
 	);
1153 1152
 
1154
-	if ( ! isset( $zip_regex[ $country_code ] ) || preg_match( '/' . $zip_regex[ $country_code ] . '/i', $zip ) ) {
1153
+	if ( ! isset($zip_regex[$country_code]) || preg_match('/'.$zip_regex[$country_code].'/i', $zip)) {
1155 1154
 		$ret = true;
1156 1155
 	}
1157 1156
 
1158
-	return apply_filters( 'give_is_zip_valid', $ret, $zip, $country_code );
1157
+	return apply_filters('give_is_zip_valid', $ret, $zip, $country_code);
1159 1158
 }
1160 1159
 
1161 1160
 
@@ -1169,33 +1168,33 @@  discard block
 block discarded – undo
1169 1168
  *
1170 1169
  * @return bool
1171 1170
  */
1172
-function give_validate_multi_donation_form_level( $valid_data, $data ) {
1171
+function give_validate_multi_donation_form_level($valid_data, $data) {
1173 1172
 	/* @var Give_Donate_Form $form */
1174
-	$form = new Give_Donate_Form( $data['give-form-id'] );
1173
+	$form = new Give_Donate_Form($data['give-form-id']);
1175 1174
 
1176 1175
 	$donation_level_matched = false;
1177 1176
 
1178
-	if ( $form->is_multi_type_donation_form() ) {
1177
+	if ($form->is_multi_type_donation_form()) {
1179 1178
 
1180 1179
 		// Bailout.
1181
-		if ( ! ( $variable_prices = $form->get_prices() ) ) {
1180
+		if ( ! ($variable_prices = $form->get_prices())) {
1182 1181
 			return false;
1183 1182
 		}
1184 1183
 
1185 1184
 		// Sanitize donation amount.
1186
-		$data['give-amount'] = give_maybe_sanitize_amount( $data['give-amount'] );
1185
+		$data['give-amount'] = give_maybe_sanitize_amount($data['give-amount']);
1187 1186
 
1188
-		if ( $data['give-amount'] === give_maybe_sanitize_amount( give_get_price_option_amount( $data['give-form-id'], $data['give-price-id'] ) ) ) {
1187
+		if ($data['give-amount'] === give_maybe_sanitize_amount(give_get_price_option_amount($data['give-form-id'], $data['give-price-id']))) {
1189 1188
 			return true;
1190 1189
 		}
1191 1190
 
1192 1191
 		// Find correct donation level from all donation levels.
1193
-		foreach ( $variable_prices as $variable_price ) {
1192
+		foreach ($variable_prices as $variable_price) {
1194 1193
 			// Sanitize level amount.
1195
-			$variable_price['_give_amount'] = give_maybe_sanitize_amount( $variable_price['_give_amount'] );
1194
+			$variable_price['_give_amount'] = give_maybe_sanitize_amount($variable_price['_give_amount']);
1196 1195
 
1197 1196
 			// Set first match donation level ID.
1198
-			if ( $data['give-amount'] === $variable_price['_give_amount'] ) {
1197
+			if ($data['give-amount'] === $variable_price['_give_amount']) {
1199 1198
 				$_POST['give-price-id'] = $variable_price['_give_id']['level_id'];
1200 1199
 				$donation_level_matched = true;
1201 1200
 				break;
@@ -1206,19 +1205,19 @@  discard block
 block discarded – undo
1206 1205
 		// If yes then set price id to custom if amount is greater then custom minimum amount (if any).
1207 1206
 		if (
1208 1207
 			! $donation_level_matched
1209
-			&& ( give_is_setting_enabled( give_get_meta( $data['give-form-id'], '_give_custom_amount', true ) ) )
1208
+			&& (give_is_setting_enabled(give_get_meta($data['give-form-id'], '_give_custom_amount', true)))
1210 1209
 		) {
1211 1210
 			// Sanitize custom minimum amount.
1212
-			$custom_minimum_amount = give_maybe_sanitize_amount( give_get_meta( $data['give-form-id'], '_give_custom_amount_minimum', true ) );
1211
+			$custom_minimum_amount = give_maybe_sanitize_amount(give_get_meta($data['give-form-id'], '_give_custom_amount_minimum', true));
1213 1212
 
1214
-			if ( $data['give-amount'] >= $custom_minimum_amount ) {
1213
+			if ($data['give-amount'] >= $custom_minimum_amount) {
1215 1214
 				$_POST['give-price-id'] = 'custom';
1216 1215
 				$donation_level_matched = true;
1217 1216
 			}
1218 1217
 		}
1219 1218
 	}// End if().
1220 1219
 
1221
-	return ( $donation_level_matched ? true : false );
1220
+	return ($donation_level_matched ? true : false);
1222 1221
 }
1223 1222
 
1224
-add_action( 'give_checkout_error_checks', 'give_validate_multi_donation_form_level', 10, 2 );
1223
+add_action('give_checkout_error_checks', 'give_validate_multi_donation_form_level', 10, 2);
Please login to merge, or discard this patch.
includes/error-tracking.php 1 patch
Spacing   +19 added lines, -19 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
 
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
  * @return mixed array if errors are present, false if none found
26 26
  */
27 27
 function give_get_errors() {
28
-	return Give()->session->get( 'give_errors' );
28
+	return Give()->session->get('give_errors');
29 29
 }
30 30
 
31 31
 /**
@@ -42,23 +42,23 @@  discard block
 block discarded – undo
42 42
  *
43 43
  * @return void
44 44
  */
45
-function give_set_error( $error_id, $error_message, $notice_args = array() ) {
45
+function give_set_error($error_id, $error_message, $notice_args = array()) {
46 46
 	$errors = give_get_errors();
47
-	if ( ! $errors ) {
47
+	if ( ! $errors) {
48 48
 		$errors = array();
49 49
 	}
50 50
 
51
-	if( is_array( $notice_args ) && ! empty( $notice_args ) ) {
52
-		$errors[ $error_id ] = array(
51
+	if (is_array($notice_args) && ! empty($notice_args)) {
52
+		$errors[$error_id] = array(
53 53
 			'message'     => $error_message,
54 54
 			'notice_args' => $notice_args,
55 55
 		);
56 56
 	} else {
57 57
 		// Backward compatibility v<1.8.11.
58
-		$errors[ $error_id ] = $error_message;
58
+		$errors[$error_id] = $error_message;
59 59
 	}
60 60
 
61
-	Give()->session->set( 'give_errors', $errors );
61
+	Give()->session->set('give_errors', $errors);
62 62
 }
63 63
 
64 64
 /**
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
  * @return void
70 70
  */
71 71
 function give_clear_errors() {
72
-	Give()->session->set( 'give_errors', null );
72
+	Give()->session->set('give_errors', null);
73 73
 }
74 74
 
75 75
 /**
@@ -82,19 +82,19 @@  discard block
 block discarded – undo
82 82
  *
83 83
  * @return void
84 84
  */
85
-function give_unset_error( $error_id ) {
85
+function give_unset_error($error_id) {
86 86
 	$errors = give_get_errors();
87
-	if ( $errors ) {
87
+	if ($errors) {
88 88
 		/**
89 89
 		 * Check If $error_id exists in the array.
90 90
 		 * If exists then unset it.
91 91
 		 *
92 92
 		 * @since 1.8.13
93 93
 		 */
94
-		if ( isset( $errors[ $error_id ] ) ) {
95
-			unset( $errors[ $error_id ] );
94
+		if (isset($errors[$error_id])) {
95
+			unset($errors[$error_id]);
96 96
 		}
97
-		Give()->session->set( 'give_errors', $errors );
97
+		Give()->session->set('give_errors', $errors);
98 98
 	}
99 99
 }
100 100
 
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
  * @return string
106 106
  */
107 107
 function _give_die_handler() {
108
-	if ( defined( 'GIVE_UNIT_TESTS' ) ) {
108
+	if (defined('GIVE_UNIT_TESTS')) {
109 109
 		return '_give_die_handler';
110 110
 	} else {
111 111
 		die();
@@ -125,8 +125,8 @@  discard block
 block discarded – undo
125 125
  *
126 126
  * @return void
127 127
  */
128
-function give_die( $message = '', $title = '', $status = 400 ) {
129
-	add_filter( 'wp_die_ajax_handler', '_give_die_handler', 10, 3 );
130
-	add_filter( 'wp_die_handler', '_give_die_handler', 10, 3 );
131
-	wp_die( $message, $title, array( 'response' => $status ) );
128
+function give_die($message = '', $title = '', $status = 400) {
129
+	add_filter('wp_die_ajax_handler', '_give_die_handler', 10, 3);
130
+	add_filter('wp_die_handler', '_give_die_handler', 10, 3);
131
+	wp_die($message, $title, array('response' => $status));
132 132
 }
Please login to merge, or discard this patch.