Completed
Pull Request — master (#740)
by
unknown
04:10
created
includes/class-give-customer.php 1 patch
Spacing   +128 added lines, -128 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
 
@@ -97,29 +97,29 @@  discard block
 block discarded – undo
97 97
 	 * @param bool $_id_or_email
98 98
 	 * @param bool $by_user_id
99 99
 	 */
100
-	public function __construct( $_id_or_email = false, $by_user_id = false ) {
100
+	public function __construct($_id_or_email = false, $by_user_id = false) {
101 101
 
102 102
 		$this->db = new Give_DB_Customers;
103 103
 
104
-		if ( false === $_id_or_email || ( is_numeric( $_id_or_email ) && (int) $_id_or_email !== absint( $_id_or_email ) ) ) {
104
+		if (false === $_id_or_email || (is_numeric($_id_or_email) && (int) $_id_or_email !== absint($_id_or_email))) {
105 105
 			return false;
106 106
 		}
107 107
 
108
-		$by_user_id = is_bool( $by_user_id ) ? $by_user_id : false;
108
+		$by_user_id = is_bool($by_user_id) ? $by_user_id : false;
109 109
 
110
-		if ( is_numeric( $_id_or_email ) ) {
110
+		if (is_numeric($_id_or_email)) {
111 111
 			$field = $by_user_id ? 'user_id' : 'id';
112 112
 		} else {
113 113
 			$field = 'email';
114 114
 		}
115 115
 
116
-		$customer = $this->db->get_customer_by( $field, $_id_or_email );
116
+		$customer = $this->db->get_customer_by($field, $_id_or_email);
117 117
 
118
-		if ( empty( $customer ) || ! is_object( $customer ) ) {
118
+		if (empty($customer) || ! is_object($customer)) {
119 119
 			return false;
120 120
 		}
121 121
 
122
-		$this->setup_customer( $customer );
122
+		$this->setup_customer($customer);
123 123
 
124 124
 	}
125 125
 
@@ -132,15 +132,15 @@  discard block
 block discarded – undo
132 132
 	 *
133 133
 	 * @return bool             If the setup was successful or not
134 134
 	 */
135
-	private function setup_customer( $customer ) {
135
+	private function setup_customer($customer) {
136 136
 
137
-		if ( ! is_object( $customer ) ) {
137
+		if ( ! is_object($customer)) {
138 138
 			return false;
139 139
 		}
140 140
 
141
-		foreach ( $customer as $key => $value ) {
141
+		foreach ($customer as $key => $value) {
142 142
 
143
-			switch ( $key ) {
143
+			switch ($key) {
144 144
 
145 145
 				case 'notes':
146 146
 					$this->$key = $this->get_notes();
@@ -155,7 +155,7 @@  discard block
 block discarded – undo
155 155
 		}
156 156
 
157 157
 		// Customer ID and email are the only things that are necessary, make sure they exist
158
-		if ( ! empty( $this->id ) && ! empty( $this->email ) ) {
158
+		if ( ! empty($this->id) && ! empty($this->email)) {
159 159
 			return true;
160 160
 		}
161 161
 
@@ -168,15 +168,15 @@  discard block
 block discarded – undo
168 168
 	 *
169 169
 	 * @since 1.0
170 170
 	 */
171
-	public function __get( $key ) {
171
+	public function __get($key) {
172 172
 
173
-		if ( method_exists( $this, 'get_' . $key ) ) {
173
+		if (method_exists($this, 'get_'.$key)) {
174 174
 
175
-			return call_user_func( array( $this, 'get_' . $key ) );
175
+			return call_user_func(array($this, 'get_'.$key));
176 176
 
177 177
 		} else {
178 178
 
179
-			return new WP_Error( 'give-customer-invalid-property', sprintf( __( 'Can\'t get property %s.', 'give' ), $key ) );
179
+			return new WP_Error('give-customer-invalid-property', sprintf(__('Can\'t get property %s.', 'give'), $key));
180 180
 
181 181
 		}
182 182
 
@@ -191,9 +191,9 @@  discard block
 block discarded – undo
191 191
 	 *
192 192
 	 * @return mixed        False if not a valid creation, Customer ID if user is found or valid creation
193 193
 	 */
194
-	public function create( $data = array() ) {
194
+	public function create($data = array()) {
195 195
 
196
-		if ( $this->id != 0 || empty( $data ) ) {
196
+		if ($this->id != 0 || empty($data)) {
197 197
 			return false;
198 198
 		}
199 199
 
@@ -201,34 +201,34 @@  discard block
 block discarded – undo
201 201
 			'payment_ids' => ''
202 202
 		);
203 203
 
204
-		$args = wp_parse_args( $data, $defaults );
205
-		$args = $this->sanitize_columns( $args );
204
+		$args = wp_parse_args($data, $defaults);
205
+		$args = $this->sanitize_columns($args);
206 206
 
207
-		if ( empty( $args['email'] ) || ! is_email( $args['email'] ) ) {
207
+		if (empty($args['email']) || ! is_email($args['email'])) {
208 208
 			return false;
209 209
 		}
210 210
 
211
-		if ( ! empty( $args['payment_ids'] ) && is_array( $args['payment_ids'] ) ) {
212
-			$args['payment_ids'] = implode( ',', array_unique( array_values( $args['payment_ids'] ) ) );
211
+		if ( ! empty($args['payment_ids']) && is_array($args['payment_ids'])) {
212
+			$args['payment_ids'] = implode(',', array_unique(array_values($args['payment_ids'])));
213 213
 		}
214 214
 
215
-		do_action( 'give_customer_pre_create', $args );
215
+		do_action('give_customer_pre_create', $args);
216 216
 
217 217
 		$created = false;
218 218
 
219 219
 		// The DB class 'add' implies an update if the customer being asked to be created already exists
220
-		if ( $this->db->add( $data ) ) {
220
+		if ($this->db->add($data)) {
221 221
 
222 222
 			// We've successfully added/updated the customer, reset the class vars with the new data
223
-			$customer = $this->db->get_customer_by( 'email', $args['email'] );
223
+			$customer = $this->db->get_customer_by('email', $args['email']);
224 224
 
225 225
 			// Setup the customer data with the values from DB
226
-			$this->setup_customer( $customer );
226
+			$this->setup_customer($customer);
227 227
 
228 228
 			$created = $this->id;
229 229
 		}
230 230
 
231
-		do_action( 'give_customer_post_create', $created, $args );
231
+		do_action('give_customer_post_create', $created, $args);
232 232
 
233 233
 		return $created;
234 234
 
@@ -243,27 +243,27 @@  discard block
 block discarded – undo
243 243
 	 *
244 244
 	 * @return bool         If the update was successful or not
245 245
 	 */
246
-	public function update( $data = array() ) {
246
+	public function update($data = array()) {
247 247
 
248
-		if ( empty( $data ) ) {
248
+		if (empty($data)) {
249 249
 			return false;
250 250
 		}
251 251
 
252
-		$data = $this->sanitize_columns( $data );
252
+		$data = $this->sanitize_columns($data);
253 253
 
254
-		do_action( 'give_customer_pre_update', $this->id, $data );
254
+		do_action('give_customer_pre_update', $this->id, $data);
255 255
 
256 256
 		$updated = false;
257 257
 
258
-		if ( $this->db->update( $this->id, $data ) ) {
258
+		if ($this->db->update($this->id, $data)) {
259 259
 
260
-			$customer = $this->db->get_customer_by( 'id', $this->id );
261
-			$this->setup_customer( $customer );
260
+			$customer = $this->db->get_customer_by('id', $this->id);
261
+			$this->setup_customer($customer);
262 262
 
263 263
 			$updated = true;
264 264
 		}
265 265
 
266
-		do_action( 'give_customer_post_update', $updated, $this->id, $data );
266
+		do_action('give_customer_post_update', $updated, $this->id, $data);
267 267
 
268 268
 		return $updated;
269 269
 	}
@@ -279,44 +279,44 @@  discard block
 block discarded – undo
279 279
 	 *
280 280
 	 * @return bool            If the attachment was successfuly
281 281
 	 */
282
-	public function attach_payment( $payment_id = 0, $update_stats = true ) {
282
+	public function attach_payment($payment_id = 0, $update_stats = true) {
283 283
 
284
-		if ( empty( $payment_id ) ) {
284
+		if (empty($payment_id)) {
285 285
 			return false;
286 286
 		}
287 287
 
288
-		if ( empty( $this->payment_ids ) ) {
288
+		if (empty($this->payment_ids)) {
289 289
 
290 290
 			$new_payment_ids = $payment_id;
291 291
 
292 292
 		} else {
293 293
 
294
-			$payment_ids = array_map( 'absint', explode( ',', $this->payment_ids ) );
294
+			$payment_ids = array_map('absint', explode(',', $this->payment_ids));
295 295
 
296
-			if ( in_array( $payment_id, $payment_ids ) ) {
296
+			if (in_array($payment_id, $payment_ids)) {
297 297
 				$update_stats = false;
298 298
 			}
299 299
 
300 300
 			$payment_ids[] = $payment_id;
301 301
 
302
-			$new_payment_ids = implode( ',', array_unique( array_values( $payment_ids ) ) );
302
+			$new_payment_ids = implode(',', array_unique(array_values($payment_ids)));
303 303
 
304 304
 		}
305 305
 
306
-		do_action( 'give_customer_pre_attach_payment', $payment_id, $this->id );
306
+		do_action('give_customer_pre_attach_payment', $payment_id, $this->id);
307 307
 
308
-		$payment_added = $this->update( array( 'payment_ids' => $new_payment_ids ) );
308
+		$payment_added = $this->update(array('payment_ids' => $new_payment_ids));
309 309
 
310
-		if ( $payment_added ) {
310
+		if ($payment_added) {
311 311
 
312 312
 			$this->payment_ids = $new_payment_ids;
313 313
 
314 314
 			// We added this payment successfully, increment the stats
315
-			if ( $update_stats ) {
316
-				$payment_amount = give_get_payment_amount( $payment_id );
315
+			if ($update_stats) {
316
+				$payment_amount = give_get_payment_amount($payment_id);
317 317
 
318
-				if ( ! empty( $payment_amount ) ) {
319
-					$this->increase_value( $payment_amount );
318
+				if ( ! empty($payment_amount)) {
319
+					$this->increase_value($payment_amount);
320 320
 				}
321 321
 
322 322
 				$this->increase_purchase_count();
@@ -324,7 +324,7 @@  discard block
 block discarded – undo
324 324
 
325 325
 		}
326 326
 
327
-		do_action( 'give_customer_post_attach_payment', $payment_added, $payment_id, $this->id );
327
+		do_action('give_customer_post_attach_payment', $payment_added, $payment_id, $this->id);
328 328
 
329 329
 		return $payment_added;
330 330
 	}
@@ -340,50 +340,50 @@  discard block
 block discarded – undo
340 340
 	 *
341 341
 	 * @return boolean             If the removal was successful
342 342
 	 */
343
-	public function remove_payment( $payment_id = 0, $update_stats = true ) {
343
+	public function remove_payment($payment_id = 0, $update_stats = true) {
344 344
 
345
-		if ( empty( $payment_id ) ) {
345
+		if (empty($payment_id)) {
346 346
 			return false;
347 347
 		}
348 348
 
349
-		$payment = new Give_Payment( $payment_id );
349
+		$payment = new Give_Payment($payment_id);
350 350
 
351
-		if ( 'publish' !== $payment->status && 'revoked' !== $payment->status ) {
351
+		if ('publish' !== $payment->status && 'revoked' !== $payment->status) {
352 352
 			$update_stats = false;
353 353
 		}
354 354
 
355 355
 		$new_payment_ids = '';
356 356
 
357
-		if ( ! empty( $this->payment_ids ) ) {
357
+		if ( ! empty($this->payment_ids)) {
358 358
 
359
-			$payment_ids = array_map( 'absint', explode( ',', $this->payment_ids ) );
359
+			$payment_ids = array_map('absint', explode(',', $this->payment_ids));
360 360
 
361
-			$pos = array_search( $payment_id, $payment_ids );
362
-			if ( false === $pos ) {
361
+			$pos = array_search($payment_id, $payment_ids);
362
+			if (false === $pos) {
363 363
 				return false;
364 364
 			}
365 365
 
366
-			unset( $payment_ids[ $pos ] );
367
-			$payment_ids = array_filter( $payment_ids );
366
+			unset($payment_ids[$pos]);
367
+			$payment_ids = array_filter($payment_ids);
368 368
 
369
-			$new_payment_ids = implode( ',', array_unique( array_values( $payment_ids ) ) );
369
+			$new_payment_ids = implode(',', array_unique(array_values($payment_ids)));
370 370
 
371 371
 		}
372 372
 
373
-		do_action( 'give_customer_pre_remove_payment', $payment_id, $this->id );
373
+		do_action('give_customer_pre_remove_payment', $payment_id, $this->id);
374 374
 
375
-		$payment_removed = $this->update( array( 'payment_ids' => $new_payment_ids ) );
375
+		$payment_removed = $this->update(array('payment_ids' => $new_payment_ids));
376 376
 
377
-		if ( $payment_removed ) {
377
+		if ($payment_removed) {
378 378
 
379 379
 			$this->payment_ids = $new_payment_ids;
380 380
 
381
-			if ( $update_stats ) {
381
+			if ($update_stats) {
382 382
 				// We removed this payment successfully, decrement the stats
383
-				$payment_amount = give_get_payment_amount( $payment_id );
383
+				$payment_amount = give_get_payment_amount($payment_id);
384 384
 
385
-				if ( ! empty( $payment_amount ) ) {
386
-					$this->decrease_value( $payment_amount );
385
+				if ( ! empty($payment_amount)) {
386
+					$this->decrease_value($payment_amount);
387 387
 				}
388 388
 
389 389
 				$this->decrease_purchase_count();
@@ -391,7 +391,7 @@  discard block
 block discarded – undo
391 391
 
392 392
 		}
393 393
 
394
-		do_action( 'give_customer_post_remove_payment', $payment_removed, $payment_id, $this->id );
394
+		do_action('give_customer_post_remove_payment', $payment_removed, $payment_id, $this->id);
395 395
 
396 396
 		return $payment_removed;
397 397
 
@@ -406,22 +406,22 @@  discard block
 block discarded – undo
406 406
 	 *
407 407
 	 * @return int            The purchase count
408 408
 	 */
409
-	public function increase_purchase_count( $count = 1 ) {
409
+	public function increase_purchase_count($count = 1) {
410 410
 
411 411
 		// Make sure it's numeric and not negative
412
-		if ( ! is_numeric( $count ) || $count != absint( $count ) ) {
412
+		if ( ! is_numeric($count) || $count != absint($count)) {
413 413
 			return false;
414 414
 		}
415 415
 
416 416
 		$new_total = (int) $this->purchase_count + (int) $count;
417 417
 
418
-		do_action( 'give_customer_pre_increase_purchase_count', $count, $this->id );
418
+		do_action('give_customer_pre_increase_purchase_count', $count, $this->id);
419 419
 
420
-		if ( $this->update( array( 'purchase_count' => $new_total ) ) ) {
420
+		if ($this->update(array('purchase_count' => $new_total))) {
421 421
 			$this->purchase_count = $new_total;
422 422
 		}
423 423
 
424
-		do_action( 'give_customer_post_increase_purchase_count', $this->purchase_count, $count, $this->id );
424
+		do_action('give_customer_post_increase_purchase_count', $this->purchase_count, $count, $this->id);
425 425
 
426 426
 		return $this->purchase_count;
427 427
 	}
@@ -435,26 +435,26 @@  discard block
 block discarded – undo
435 435
 	 *
436 436
 	 * @return mixed          If successful, the new count, otherwise false
437 437
 	 */
438
-	public function decrease_purchase_count( $count = 1 ) {
438
+	public function decrease_purchase_count($count = 1) {
439 439
 
440 440
 		// Make sure it's numeric and not negative
441
-		if ( ! is_numeric( $count ) || $count != absint( $count ) ) {
441
+		if ( ! is_numeric($count) || $count != absint($count)) {
442 442
 			return false;
443 443
 		}
444 444
 
445 445
 		$new_total = (int) $this->purchase_count - (int) $count;
446 446
 
447
-		if ( $new_total < 0 ) {
447
+		if ($new_total < 0) {
448 448
 			$new_total = 0;
449 449
 		}
450 450
 
451
-		do_action( 'give_customer_pre_decrease_purchase_count', $count, $this->id );
451
+		do_action('give_customer_pre_decrease_purchase_count', $count, $this->id);
452 452
 
453
-		if ( $this->update( array( 'purchase_count' => $new_total ) ) ) {
453
+		if ($this->update(array('purchase_count' => $new_total))) {
454 454
 			$this->purchase_count = $new_total;
455 455
 		}
456 456
 
457
-		do_action( 'give_customer_post_decrease_purchase_count', $this->purchase_count, $count, $this->id );
457
+		do_action('give_customer_post_decrease_purchase_count', $this->purchase_count, $count, $this->id);
458 458
 
459 459
 		return $this->purchase_count;
460 460
 	}
@@ -468,17 +468,17 @@  discard block
 block discarded – undo
468 468
 	 *
469 469
 	 * @return mixed         If successful, the new value, otherwise false
470 470
 	 */
471
-	public function increase_value( $value = 0.00 ) {
471
+	public function increase_value($value = 0.00) {
472 472
 
473
-		$new_value = floatval( $this->purchase_value ) + $value;
473
+		$new_value = floatval($this->purchase_value) + $value;
474 474
 
475
-		do_action( 'give_customer_pre_increase_value', $value, $this->id );
475
+		do_action('give_customer_pre_increase_value', $value, $this->id);
476 476
 
477
-		if ( $this->update( array( 'purchase_value' => $new_value ) ) ) {
477
+		if ($this->update(array('purchase_value' => $new_value))) {
478 478
 			$this->purchase_value = $new_value;
479 479
 		}
480 480
 
481
-		do_action( 'give_customer_post_increase_value', $this->purchase_value, $value, $this->id );
481
+		do_action('give_customer_post_increase_value', $this->purchase_value, $value, $this->id);
482 482
 
483 483
 		return $this->purchase_value;
484 484
 	}
@@ -492,21 +492,21 @@  discard block
 block discarded – undo
492 492
 	 *
493 493
 	 * @return mixed         If successful, the new value, otherwise false
494 494
 	 */
495
-	public function decrease_value( $value = 0.00 ) {
495
+	public function decrease_value($value = 0.00) {
496 496
 
497
-		$new_value = floatval( $this->purchase_value ) - $value;
497
+		$new_value = floatval($this->purchase_value) - $value;
498 498
 
499
-		if ( $new_value < 0 ) {
499
+		if ($new_value < 0) {
500 500
 			$new_value = 0.00;
501 501
 		}
502 502
 
503
-		do_action( 'give_customer_pre_decrease_value', $value, $this->id );
503
+		do_action('give_customer_pre_decrease_value', $value, $this->id);
504 504
 
505
-		if ( $this->update( array( 'purchase_value' => $new_value ) ) ) {
505
+		if ($this->update(array('purchase_value' => $new_value))) {
506 506
 			$this->purchase_value = $new_value;
507 507
 		}
508 508
 
509
-		do_action( 'give_customer_post_decrease_value', $this->purchase_value, $value, $this->id );
509
+		do_action('give_customer_post_decrease_value', $this->purchase_value, $value, $this->id);
510 510
 
511 511
 		return $this->purchase_value;
512 512
 	}
@@ -521,15 +521,15 @@  discard block
 block discarded – undo
521 521
 	 *
522 522
 	 * @return array           The notes requsted
523 523
 	 */
524
-	public function get_notes( $length = 20, $paged = 1 ) {
524
+	public function get_notes($length = 20, $paged = 1) {
525 525
 
526
-		$length = is_numeric( $length ) ? $length : 20;
527
-		$offset = is_numeric( $paged ) && $paged != 1 ? ( ( absint( $paged ) - 1 ) * $length ) : 0;
526
+		$length = is_numeric($length) ? $length : 20;
527
+		$offset = is_numeric($paged) && $paged != 1 ? ((absint($paged) - 1) * $length) : 0;
528 528
 
529 529
 		$all_notes   = $this->get_raw_notes();
530
-		$notes_array = array_reverse( array_filter( explode( "\n\n", $all_notes ) ) );
530
+		$notes_array = array_reverse(array_filter(explode("\n\n", $all_notes)));
531 531
 
532
-		$desired_notes = array_slice( $notes_array, $offset, $length );
532
+		$desired_notes = array_slice($notes_array, $offset, $length);
533 533
 
534 534
 		return $desired_notes;
535 535
 
@@ -544,9 +544,9 @@  discard block
 block discarded – undo
544 544
 	public function get_notes_count() {
545 545
 
546 546
 		$all_notes   = $this->get_raw_notes();
547
-		$notes_array = array_reverse( array_filter( explode( "\n\n", $all_notes ) ) );
547
+		$notes_array = array_reverse(array_filter(explode("\n\n", $all_notes)));
548 548
 
549
-		return count( $notes_array );
549
+		return count($notes_array);
550 550
 
551 551
 	}
552 552
 
@@ -559,32 +559,32 @@  discard block
 block discarded – undo
559 559
 	 *
560 560
 	 * @return string|boolean The new note if added succesfully, false otherwise
561 561
 	 */
562
-	public function add_note( $note = '' ) {
562
+	public function add_note($note = '') {
563 563
 
564
-		$note = trim( $note );
565
-		if ( empty( $note ) ) {
564
+		$note = trim($note);
565
+		if (empty($note)) {
566 566
 			return false;
567 567
 		}
568 568
 
569 569
 		$notes = $this->get_raw_notes();
570 570
 
571
-		if ( empty( $notes ) ) {
571
+		if (empty($notes)) {
572 572
 			$notes = '';
573 573
 		}
574 574
 
575
-		$note_string = date_i18n( 'F j, Y H:i:s', current_time( 'timestamp' ) ) . ' - ' . $note;
576
-		$new_note    = apply_filters( 'give_customer_add_note_string', $note_string );
577
-		$notes .= "\n\n" . $new_note;
575
+		$note_string = date_i18n('F j, Y H:i:s', current_time('timestamp')).' - '.$note;
576
+		$new_note    = apply_filters('give_customer_add_note_string', $note_string);
577
+		$notes .= "\n\n".$new_note;
578 578
 
579
-		do_action( 'give_customer_pre_add_note', $new_note, $this->id );
579
+		do_action('give_customer_pre_add_note', $new_note, $this->id);
580 580
 
581
-		$updated = $this->update( array( 'notes' => $notes ) );
581
+		$updated = $this->update(array('notes' => $notes));
582 582
 
583
-		if ( $updated ) {
583
+		if ($updated) {
584 584
 			$this->notes = $this->get_notes();
585 585
 		}
586 586
 
587
-		do_action( 'give_customer_post_add_note', $this->notes, $new_note, $this->id );
587
+		do_action('give_customer_post_add_note', $this->notes, $new_note, $this->id);
588 588
 
589 589
 		// Return the formatted note, so we can test, as well as update any displays
590 590
 		return $new_note;
@@ -599,7 +599,7 @@  discard block
 block discarded – undo
599 599
 	 */
600 600
 	private function get_raw_notes() {
601 601
 
602
-		$all_notes = $this->db->get_column( 'notes', $this->id );
602
+		$all_notes = $this->db->get_column('notes', $this->id);
603 603
 
604 604
 		return $all_notes;
605 605
 
@@ -614,51 +614,51 @@  discard block
 block discarded – undo
614 614
 	 *
615 615
 	 * @return array       The sanitized data, based off column defaults
616 616
 	 */
617
-	private function sanitize_columns( $data ) {
617
+	private function sanitize_columns($data) {
618 618
 
619 619
 		$columns        = $this->db->get_columns();
620 620
 		$default_values = $this->db->get_column_defaults();
621 621
 
622
-		foreach ( $columns as $key => $type ) {
622
+		foreach ($columns as $key => $type) {
623 623
 
624 624
 			// Only sanitize data that we were provided
625
-			if ( ! array_key_exists( $key, $data ) ) {
625
+			if ( ! array_key_exists($key, $data)) {
626 626
 				continue;
627 627
 			}
628 628
 
629
-			switch ( $type ) {
629
+			switch ($type) {
630 630
 
631 631
 				case '%s':
632
-					if ( 'email' == $key ) {
633
-						$data[ $key ] = sanitize_email( $data[ $key ] );
634
-					} elseif ( 'notes' == $key ) {
635
-						$data[ $key ] = strip_tags( $data[ $key ] );
632
+					if ('email' == $key) {
633
+						$data[$key] = sanitize_email($data[$key]);
634
+					} elseif ('notes' == $key) {
635
+						$data[$key] = strip_tags($data[$key]);
636 636
 					} else {
637
-						$data[ $key ] = sanitize_text_field( $data[ $key ] );
637
+						$data[$key] = sanitize_text_field($data[$key]);
638 638
 					}
639 639
 					break;
640 640
 
641 641
 				case '%d':
642
-					if ( ! is_numeric( $data[ $key ] ) || (int) $data[ $key ] !== absint( $data[ $key ] ) ) {
643
-						$data[ $key ] = $default_values[ $key ];
642
+					if ( ! is_numeric($data[$key]) || (int) $data[$key] !== absint($data[$key])) {
643
+						$data[$key] = $default_values[$key];
644 644
 					} else {
645
-						$data[ $key ] = absint( $data[ $key ] );
645
+						$data[$key] = absint($data[$key]);
646 646
 					}
647 647
 					break;
648 648
 
649 649
 				case '%f':
650 650
 					// Convert what was given to a float
651
-					$value = floatval( $data[ $key ] );
651
+					$value = floatval($data[$key]);
652 652
 
653
-					if ( ! is_float( $value ) ) {
654
-						$data[ $key ] = $default_values[ $key ];
653
+					if ( ! is_float($value)) {
654
+						$data[$key] = $default_values[$key];
655 655
 					} else {
656
-						$data[ $key ] = $value;
656
+						$data[$key] = $value;
657 657
 					}
658 658
 					break;
659 659
 
660 660
 				default:
661
-					$data[ $key ] = sanitize_text_field( $data[ $key ] );
661
+					$data[$key] = sanitize_text_field($data[$key]);
662 662
 					break;
663 663
 
664 664
 			}
Please login to merge, or discard this patch.
includes/class-give-donate-form.php 1 patch
Spacing   +97 added lines, -97 removed lines patch added patch discarded remove patch
@@ -100,12 +100,12 @@  discard block
 block discarded – undo
100 100
 	 * @param bool $_id
101 101
 	 * @param array $_args
102 102
 	 */
103
-	public function __construct( $_id = false, $_args = array() ) {
103
+	public function __construct($_id = false, $_args = array()) {
104 104
 
105 105
 
106
-		$donation_form = WP_Post::get_instance( $_id );
106
+		$donation_form = WP_Post::get_instance($_id);
107 107
 
108
-		return $this->setup_donation_form( $donation_form );
108
+		return $this->setup_donation_form($donation_form);
109 109
 	}
110 110
 
111 111
 	/**
@@ -117,23 +117,23 @@  discard block
 block discarded – undo
117 117
 	 *
118 118
 	 * @return bool             If the setup was successful or not
119 119
 	 */
120
-	private function setup_donation_form( $donation_form ) {
120
+	private function setup_donation_form($donation_form) {
121 121
 
122
-		if ( ! is_object( $donation_form ) ) {
122
+		if ( ! is_object($donation_form)) {
123 123
 			return false;
124 124
 		}
125 125
 
126
-		if ( ! is_a( $donation_form, 'WP_Post' ) ) {
126
+		if ( ! is_a($donation_form, 'WP_Post')) {
127 127
 			return false;
128 128
 		}
129 129
 
130
-		if ( 'give_forms' !== $donation_form->post_type ) {
130
+		if ('give_forms' !== $donation_form->post_type) {
131 131
 			return false;
132 132
 		}
133 133
 
134
-		foreach ( $donation_form as $key => $value ) {
134
+		foreach ($donation_form as $key => $value) {
135 135
 
136
-			switch ( $key ) {
136
+			switch ($key) {
137 137
 
138 138
 				default:
139 139
 					$this->$key = $value;
@@ -157,15 +157,15 @@  discard block
 block discarded – undo
157 157
 	 * @return mixed
158 158
 	 * @throws Exception
159 159
 	 */
160
-	public function __get( $key ) {
160
+	public function __get($key) {
161 161
 
162
-		if ( method_exists( $this, 'get_' . $key ) ) {
162
+		if (method_exists($this, 'get_'.$key)) {
163 163
 
164
-			return call_user_func( array( $this, 'get_' . $key ) );
164
+			return call_user_func(array($this, 'get_'.$key));
165 165
 
166 166
 		} else {
167 167
 
168
-			return new WP_Error( 'give-form-invalid-property', sprintf( __( 'Can\'t get property %s.', 'give' ), $key ) );
168
+			return new WP_Error('give-form-invalid-property', sprintf(__('Can\'t get property %s.', 'give'), $key));
169 169
 
170 170
 		}
171 171
 
@@ -181,30 +181,30 @@  discard block
 block discarded – undo
181 181
 	 *
182 182
 	 * @return mixed  false if data isn't passed and class not instantiated for creation, or New Form ID
183 183
 	 */
184
-	public function create( $data = array() ) {
184
+	public function create($data = array()) {
185 185
 
186
-		if ( $this->id != 0 ) {
186
+		if ($this->id != 0) {
187 187
 			return false;
188 188
 		}
189 189
 
190 190
 		$defaults = array(
191 191
 			'post_type'   => 'give_forms',
192 192
 			'post_status' => 'draft',
193
-			'post_title'  => __( 'New Donation Form', 'give' )
193
+			'post_title'  => __('New Donation Form', 'give')
194 194
 		);
195 195
 
196
-		$args = wp_parse_args( $data, $defaults );
196
+		$args = wp_parse_args($data, $defaults);
197 197
 
198 198
 		/**
199 199
 		 * Fired before a donation form is created
200 200
 		 *
201 201
 		 * @param array $args The post object arguments used for creation.
202 202
 		 */
203
-		do_action( 'give_form_pre_create', $args );
203
+		do_action('give_form_pre_create', $args);
204 204
 
205
-		$id = wp_insert_post( $args, true );
205
+		$id = wp_insert_post($args, true);
206 206
 
207
-		$donation_form = WP_Post::get_instance( $id );
207
+		$donation_form = WP_Post::get_instance($id);
208 208
 
209 209
 		/**
210 210
 		 * Fired after a donation form is created
@@ -212,9 +212,9 @@  discard block
 block discarded – undo
212 212
 		 * @param int $id The post ID of the created item.
213 213
 		 * @param array $args The post object arguments used for creation.
214 214
 		 */
215
-		do_action( 'give_form_post_create', $id, $args );
215
+		do_action('give_form_post_create', $id, $args);
216 216
 
217
-		return $this->setup_donation_form( $donation_form );
217
+		return $this->setup_donation_form($donation_form);
218 218
 
219 219
 	}
220 220
 
@@ -237,7 +237,7 @@  discard block
 block discarded – undo
237 237
 	 * @return string Name of the donation form
238 238
 	 */
239 239
 	public function get_name() {
240
-		return get_the_title( $this->ID );
240
+		return get_the_title($this->ID);
241 241
 	}
242 242
 
243 243
 	/**
@@ -248,13 +248,13 @@  discard block
 block discarded – undo
248 248
 	 */
249 249
 	public function get_price() {
250 250
 
251
-		if ( ! isset( $this->price ) ) {
251
+		if ( ! isset($this->price)) {
252 252
 
253
-			$this->price = get_post_meta( $this->ID, '_give_set_price', true );
253
+			$this->price = get_post_meta($this->ID, '_give_set_price', true);
254 254
 
255
-			if ( $this->price ) {
255
+			if ($this->price) {
256 256
 
257
-				$this->price = give_sanitize_amount( $this->price );
257
+				$this->price = give_sanitize_amount($this->price);
258 258
 
259 259
 			} else {
260 260
 
@@ -272,7 +272,7 @@  discard block
 block discarded – undo
272 272
 		 * @param string $price The donation form price.
273 273
 		 * @param string|int $id The form ID.
274 274
 		 */
275
-		return apply_filters( 'give_get_set_price', $this->price, $this->ID );
275
+		return apply_filters('give_get_set_price', $this->price, $this->ID);
276 276
 	}
277 277
 
278 278
 	/**
@@ -283,14 +283,14 @@  discard block
 block discarded – undo
283 283
 	 */
284 284
 	public function get_minimum_price() {
285 285
 
286
-		if ( ! isset( $this->minimum_price ) ) {
286
+		if ( ! isset($this->minimum_price)) {
287 287
 
288
-			$allow_custom_amount = get_post_meta( $this->ID, '_give_custom_amount', true );
289
-			$this->minimum_price = get_post_meta( $this->ID, '_give_custom_amount_minimum', true );
288
+			$allow_custom_amount = get_post_meta($this->ID, '_give_custom_amount', true);
289
+			$this->minimum_price = get_post_meta($this->ID, '_give_custom_amount_minimum', true);
290 290
 
291
-			if ( $allow_custom_amount != 'no' && $this->minimum_price ) {
291
+			if ($allow_custom_amount != 'no' && $this->minimum_price) {
292 292
 
293
-				$this->minimum_price = give_sanitize_amount( $this->minimum_price );
293
+				$this->minimum_price = give_sanitize_amount($this->minimum_price);
294 294
 
295 295
 			} else {
296 296
 
@@ -300,7 +300,7 @@  discard block
 block discarded – undo
300 300
 
301 301
 		}
302 302
 
303
-		return apply_filters( 'give_get_set_minimum_price', $this->minimum_price, $this->ID );
303
+		return apply_filters('give_get_set_minimum_price', $this->minimum_price, $this->ID);
304 304
 	}
305 305
 
306 306
 	/**
@@ -311,9 +311,9 @@  discard block
 block discarded – undo
311 311
 	 */
312 312
 	public function get_prices() {
313 313
 
314
-		if ( ! isset( $this->prices ) ) {
314
+		if ( ! isset($this->prices)) {
315 315
 
316
-			$this->prices = get_post_meta( $this->ID, '_give_donation_levels', true );
316
+			$this->prices = get_post_meta($this->ID, '_give_donation_levels', true);
317 317
 
318 318
 		}
319 319
 
@@ -325,7 +325,7 @@  discard block
 block discarded – undo
325 325
 		 * @param array $prices The array of mulit-level prices.
326 326
 		 * @param int|string The ID of the form.
327 327
 		 */
328
-		return apply_filters( 'give_get_donation_levels', $this->prices, $this->ID );
328
+		return apply_filters('give_get_donation_levels', $this->prices, $this->ID);
329 329
 
330 330
 	}
331 331
 
@@ -337,13 +337,13 @@  discard block
 block discarded – undo
337 337
 	 */
338 338
 	public function get_goal() {
339 339
 
340
-		if ( ! isset( $this->goal ) ) {
340
+		if ( ! isset($this->goal)) {
341 341
 
342
-			$this->goal = get_post_meta( $this->ID, '_give_set_goal', true );
342
+			$this->goal = get_post_meta($this->ID, '_give_set_goal', true);
343 343
 
344
-			if ( $this->goal ) {
344
+			if ($this->goal) {
345 345
 
346
-				$this->goal = give_sanitize_amount( $this->goal );
346
+				$this->goal = give_sanitize_amount($this->goal);
347 347
 
348 348
 			} else {
349 349
 
@@ -353,7 +353,7 @@  discard block
 block discarded – undo
353 353
 
354 354
 		}
355 355
 
356
-		return apply_filters( 'give_get_set_goal', $this->goal, $this->ID );
356
+		return apply_filters('give_get_set_goal', $this->goal, $this->ID);
357 357
 
358 358
 	}
359 359
 
@@ -365,10 +365,10 @@  discard block
 block discarded – undo
365 365
 	 */
366 366
 	public function is_single_price_mode() {
367 367
 
368
-		$option = get_post_meta( $this->ID, '_give_price_options_mode', true );
368
+		$option = get_post_meta($this->ID, '_give_price_options_mode', true);
369 369
 		$ret    = 0;
370 370
 
371
-		if ( empty( $option ) || $option === 'set' ) {
371
+		if (empty($option) || $option === 'set') {
372 372
 			$ret = 1;
373 373
 		}
374 374
 		
@@ -380,7 +380,7 @@  discard block
 block discarded – undo
380 380
 		 * @param bool $ret Is donation form in single price mode?
381 381
 		 * @param int|string The ID of the donation form.
382 382
 		 */
383
-		return (bool) apply_filters( 'give_single_price_option_mode', $ret, $this->ID );
383
+		return (bool) apply_filters('give_single_price_option_mode', $ret, $this->ID);
384 384
 
385 385
 	}
386 386
 
@@ -394,10 +394,10 @@  discard block
 block discarded – undo
394 394
 	 */
395 395
 	public function has_variable_prices() {
396 396
 
397
-		$option = get_post_meta( $this->ID, '_give_price_option', true );
397
+		$option = get_post_meta($this->ID, '_give_price_option', true);
398 398
 		$ret    = 0;
399 399
 
400
-		if ( $option === 'multi' ) {
400
+		if ($option === 'multi') {
401 401
 			$ret = 1;
402 402
 		}
403 403
 
@@ -407,7 +407,7 @@  discard block
 block discarded – undo
407 407
 		 * @param bool $ret Does donation form have variable prices?
408 408
 		 * @param int|string The ID of the donation form.
409 409
 		 */
410
-		return (bool) apply_filters( 'give_has_variable_prices', $ret, $this->ID );
410
+		return (bool) apply_filters('give_has_variable_prices', $ret, $this->ID);
411 411
 
412 412
 	}
413 413
 
@@ -419,17 +419,17 @@  discard block
 block discarded – undo
419 419
 	 */
420 420
 	public function get_type() {
421 421
 
422
-		if ( ! isset( $this->type ) ) {
422
+		if ( ! isset($this->type)) {
423 423
 
424
-			$this->type = get_post_meta( $this->ID, '_give_price_option', true );
424
+			$this->type = get_post_meta($this->ID, '_give_price_option', true);
425 425
 
426
-			if ( empty( $this->type ) ) {
426
+			if (empty($this->type)) {
427 427
 				$this->type = 'set';
428 428
 			}
429 429
 
430 430
 		}
431 431
 
432
-		return apply_filters( 'give_get_form_type', $this->type, $this->ID );
432
+		return apply_filters('give_get_form_type', $this->type, $this->ID);
433 433
 
434 434
 	}
435 435
 
@@ -441,15 +441,15 @@  discard block
 block discarded – undo
441 441
 	 */
442 442
 	public function get_sales() {
443 443
 
444
-		if ( ! isset( $this->sales ) ) {
444
+		if ( ! isset($this->sales)) {
445 445
 
446
-			if ( '' == get_post_meta( $this->ID, '_give_form_sales', true ) ) {
447
-				add_post_meta( $this->ID, '_give_form_sales', 0 );
446
+			if ('' == get_post_meta($this->ID, '_give_form_sales', true)) {
447
+				add_post_meta($this->ID, '_give_form_sales', 0);
448 448
 			} // End if
449 449
 
450
-			$this->sales = get_post_meta( $this->ID, '_give_form_sales', true );
450
+			$this->sales = get_post_meta($this->ID, '_give_form_sales', true);
451 451
 
452
-			if ( $this->sales < 0 ) {
452
+			if ($this->sales < 0) {
453 453
 				// Never let sales be less than zero
454 454
 				$this->sales = 0;
455 455
 			}
@@ -469,13 +469,13 @@  discard block
 block discarded – undo
469 469
 	 *
470 470
 	 * @return int|false  New number of total sales
471 471
 	 */
472
-	public function increase_sales( $quantity = 1 ) {
472
+	public function increase_sales($quantity = 1) {
473 473
 
474
-		$sales       = give_get_form_sales_stats( $this->ID );
475
-		$quantity    = absint( $quantity );
474
+		$sales       = give_get_form_sales_stats($this->ID);
475
+		$quantity    = absint($quantity);
476 476
 		$total_sales = $sales + $quantity;
477 477
 
478
-		if ( $this->update_meta( '_give_form_sales', $total_sales ) ) {
478
+		if ($this->update_meta('_give_form_sales', $total_sales)) {
479 479
 
480 480
 			$this->sales = $total_sales;
481 481
 
@@ -495,17 +495,17 @@  discard block
 block discarded – undo
495 495
 	 *
496 496
 	 * @return int|false  New number of total sales
497 497
 	 */
498
-	public function decrease_sales( $quantity = 1 ) {
498
+	public function decrease_sales($quantity = 1) {
499 499
 
500
-		$sales = give_get_form_sales_stats( $this->ID );
500
+		$sales = give_get_form_sales_stats($this->ID);
501 501
 
502 502
 		// Only decrease if not already zero
503
-		if ( $sales > 0 ) {
503
+		if ($sales > 0) {
504 504
 
505
-			$quantity    = absint( $quantity );
505
+			$quantity    = absint($quantity);
506 506
 			$total_sales = $sales - $quantity;
507 507
 
508
-			if ( $this->update_meta( '_give_form_sales', $total_sales ) ) {
508
+			if ($this->update_meta('_give_form_sales', $total_sales)) {
509 509
 
510 510
 				$this->sales = $sales;
511 511
 
@@ -527,15 +527,15 @@  discard block
 block discarded – undo
527 527
 	 */
528 528
 	public function get_earnings() {
529 529
 
530
-		if ( ! isset( $this->earnings ) ) {
530
+		if ( ! isset($this->earnings)) {
531 531
 
532
-			if ( '' == get_post_meta( $this->ID, '_give_form_earnings', true ) ) {
533
-				add_post_meta( $this->ID, '_give_form_earnings', 0 );
532
+			if ('' == get_post_meta($this->ID, '_give_form_earnings', true)) {
533
+				add_post_meta($this->ID, '_give_form_earnings', 0);
534 534
 			}
535 535
 
536
-			$this->earnings = get_post_meta( $this->ID, '_give_form_earnings', true );
536
+			$this->earnings = get_post_meta($this->ID, '_give_form_earnings', true);
537 537
 
538
-			if ( $this->earnings < 0 ) {
538
+			if ($this->earnings < 0) {
539 539
 				// Never let earnings be less than zero
540 540
 				$this->earnings = 0;
541 541
 			}
@@ -552,12 +552,12 @@  discard block
 block discarded – undo
552 552
 	 * @since 1.0
553 553
 	 * @return float|false
554 554
 	 */
555
-	public function increase_earnings( $amount = 0 ) {
555
+	public function increase_earnings($amount = 0) {
556 556
 
557
-		$earnings   = give_get_form_earnings_stats( $this->ID );
557
+		$earnings   = give_get_form_earnings_stats($this->ID);
558 558
 		$new_amount = $earnings + (float) $amount;
559 559
 
560
-		if ( $this->update_meta( '_give_form_earnings', $new_amount ) ) {
560
+		if ($this->update_meta('_give_form_earnings', $new_amount)) {
561 561
 
562 562
 			$this->earnings = $new_amount;
563 563
 
@@ -575,16 +575,16 @@  discard block
 block discarded – undo
575 575
 	 * @since 1.0
576 576
 	 * @return float|false
577 577
 	 */
578
-	public function decrease_earnings( $amount ) {
578
+	public function decrease_earnings($amount) {
579 579
 
580
-		$earnings = give_get_form_earnings_stats( $this->ID );
580
+		$earnings = give_get_form_earnings_stats($this->ID);
581 581
 
582
-		if ( $earnings > 0 ) {
582
+		if ($earnings > 0) {
583 583
 			// Only decrease if greater than zero
584 584
 			$new_amount = $earnings - (float) $amount;
585 585
 
586 586
 
587
-			if ( $this->update_meta( '_give_form_earnings', $new_amount ) ) {
587
+			if ($this->update_meta('_give_form_earnings', $new_amount)) {
588 588
 
589 589
 				$this->earnings = $new_amount;
590 590
 
@@ -604,22 +604,22 @@  discard block
 block discarded – undo
604 604
 	 * @since 1.0
605 605
 	 * @return bool
606 606
 	 */
607
-	public function is_free( $price_id = false ) {
607
+	public function is_free($price_id = false) {
608 608
 
609 609
 		$is_free          = false;
610
-		$variable_pricing = give_has_variable_prices( $this->ID );
610
+		$variable_pricing = give_has_variable_prices($this->ID);
611 611
 
612
-		if ( $variable_pricing && ! is_null( $price_id ) && $price_id !== false ) {
613
-			$price = give_get_price_option_amount( $this->ID, $price_id );
614
-		} elseif ( ! $variable_pricing ) {
615
-			$price = get_post_meta( $this->ID, '_give_set_price', true );
612
+		if ($variable_pricing && ! is_null($price_id) && $price_id !== false) {
613
+			$price = give_get_price_option_amount($this->ID, $price_id);
614
+		} elseif ( ! $variable_pricing) {
615
+			$price = get_post_meta($this->ID, '_give_set_price', true);
616 616
 		}
617 617
 
618
-		if ( isset( $price ) && (float) $price == 0 ) {
618
+		if (isset($price) && (float) $price == 0) {
619 619
 			$is_free = true;
620 620
 		}
621 621
 
622
-		return (bool) apply_filters( 'give_is_free_donation', $is_free, $this->ID, $price_id );
622
+		return (bool) apply_filters('give_is_free_donation', $is_free, $this->ID, $price_id);
623 623
 
624 624
 	}
625 625
 
@@ -636,9 +636,9 @@  discard block
 block discarded – undo
636 636
 	 */
637 637
 	public function is_close_donation_form() {
638 638
 		return (
639
-				'yes' === get_post_meta( $this->ID, '_give_goal_option', true ) )
640
-				&& ( 'yes' === get_post_meta( $this->ID, '_give_close_form_when_goal_achieved', true ) )
641
-				&& ( $this->get_goal() <= $this->get_earnings()
639
+				'yes' === get_post_meta($this->ID, '_give_goal_option', true) )
640
+				&& ('yes' === get_post_meta($this->ID, '_give_close_form_when_goal_achieved', true))
641
+				&& ($this->get_goal() <= $this->get_earnings()
642 642
 		);
643 643
 	}
644 644
 
@@ -654,28 +654,28 @@  discard block
 block discarded – undo
654 654
 	 *
655 655
 	 * @return bool             The result of the update query
656 656
 	 */
657
-	private function update_meta( $meta_key = '', $meta_value = '' ) {
657
+	private function update_meta($meta_key = '', $meta_value = '') {
658 658
 
659 659
 		global $wpdb;
660 660
 
661
-		if ( empty( $meta_key ) || empty( $meta_value ) ) {
661
+		if (empty($meta_key) || empty($meta_value)) {
662 662
 			return false;
663 663
 		}
664 664
 
665 665
 		// Make sure if it needs to be serialized, we do
666
-		$meta_value = maybe_serialize( $meta_value );
666
+		$meta_value = maybe_serialize($meta_value);
667 667
 
668
-		if ( is_numeric( $meta_value ) ) {
669
-			$value_type = is_float( $meta_value ) ? '%f' : '%d';
668
+		if (is_numeric($meta_value)) {
669
+			$value_type = is_float($meta_value) ? '%f' : '%d';
670 670
 		} else {
671 671
 			$value_type = "'%s'";
672 672
 		}
673 673
 
674
-		$sql = $wpdb->prepare( "UPDATE $wpdb->postmeta SET meta_value = $value_type WHERE post_id = $this->ID AND meta_key = '%s'", $meta_value, $meta_key );
674
+		$sql = $wpdb->prepare("UPDATE $wpdb->postmeta SET meta_value = $value_type WHERE post_id = $this->ID AND meta_key = '%s'", $meta_value, $meta_key);
675 675
 
676
-		if ( $wpdb->query( $sql ) ) {
676
+		if ($wpdb->query($sql)) {
677 677
 
678
-			clean_post_cache( $this->ID );
678
+			clean_post_cache($this->ID);
679 679
 
680 680
 			return true;
681 681
 
Please login to merge, or discard this patch.
includes/process-purchase.php 1 patch
Spacing   +235 added lines, -235 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,27 +25,27 @@  discard block
 block discarded – undo
25 25
  */
26 26
 function give_process_purchase_form() {
27 27
 
28
-	do_action( 'give_pre_process_purchase' );
28
+	do_action('give_pre_process_purchase');
29 29
 
30 30
 	// Validate the form $_POST data
31 31
 	$valid_data = give_purchase_form_validate_fields();
32 32
 
33 33
 	// Allow themes and plugins to hook to errors
34
-	do_action( 'give_checkout_error_checks', $valid_data, $_POST );
34
+	do_action('give_checkout_error_checks', $valid_data, $_POST);
35 35
 
36
-	$is_ajax = isset( $_POST['give_ajax'] );
36
+	$is_ajax = isset($_POST['give_ajax']);
37 37
 
38 38
 	// Process the login form
39
-	if ( isset( $_POST['give_login_submit'] ) ) {
39
+	if (isset($_POST['give_login_submit'])) {
40 40
 		give_process_form_login();
41 41
 	}
42 42
 
43 43
 	// Validate the user
44
-	$user = give_get_purchase_form_user( $valid_data );
44
+	$user = give_get_purchase_form_user($valid_data);
45 45
 
46
-	if ( false === $valid_data || give_get_errors() || ! $user ) {
47
-		if ( $is_ajax ) {
48
-			do_action( 'give_ajax_checkout_errors' );
46
+	if (false === $valid_data || give_get_errors() || ! $user) {
47
+		if ($is_ajax) {
48
+			do_action('give_ajax_checkout_errors');
49 49
 			give_die();
50 50
 		} else {
51 51
 			return false;
@@ -53,17 +53,17 @@  discard block
 block discarded – undo
53 53
 	}
54 54
 
55 55
 	//If AJAX send back success to proceed with form submission
56
-	if ( $is_ajax ) {
56
+	if ($is_ajax) {
57 57
 		echo 'success';
58 58
 		give_die();
59 59
 	}
60 60
 
61 61
 	//After AJAX: Setup session if not using php_sessions
62
-	if ( ! Give()->session->use_php_sessions() ) {
62
+	if ( ! Give()->session->use_php_sessions()) {
63 63
 		//Double-check that set_cookie is publicly accessible;
64 64
 		// we're using a slightly modified class-wp-sessions.php
65
-		$session_reflection = new ReflectionMethod( 'WP_Session', 'set_cookie' );
66
-		if ( $session_reflection->isPublic() ) {
65
+		$session_reflection = new ReflectionMethod('WP_Session', 'set_cookie');
66
+		if ($session_reflection->isPublic()) {
67 67
 			// Manually set the cookie.
68 68
 			Give()->session->init()->set_cookie();
69 69
 		}
@@ -78,18 +78,18 @@  discard block
 block discarded – undo
78 78
 		'address'    => $user['address']
79 79
 	);
80 80
 
81
-	$auth_key = defined( 'AUTH_KEY' ) ? AUTH_KEY : '';
81
+	$auth_key = defined('AUTH_KEY') ? AUTH_KEY : '';
82 82
 
83
-	$price        = isset( $_POST['give-amount'] ) ? (float) apply_filters( 'give_donation_total', give_sanitize_amount( give_format_amount( $_POST['give-amount'] ) ) ) : '0.00';
84
-	$purchase_key = strtolower( md5( $user['user_email'] . date( 'Y-m-d H:i:s' ) . $auth_key . uniqid( 'give', true ) ) );
83
+	$price        = isset($_POST['give-amount']) ? (float) apply_filters('give_donation_total', give_sanitize_amount(give_format_amount($_POST['give-amount']))) : '0.00';
84
+	$purchase_key = strtolower(md5($user['user_email'].date('Y-m-d H:i:s').$auth_key.uniqid('give', true)));
85 85
 
86 86
 	// Setup purchase information
87 87
 	$purchase_data = array(
88 88
 		'price'        => $price,
89 89
 		'purchase_key' => $purchase_key,
90 90
 		'user_email'   => $user['user_email'],
91
-		'date'         => date( 'Y-m-d H:i:s', current_time( 'timestamp' ) ),
92
-		'user_info'    => stripslashes_deep( $user_info ),
91
+		'date'         => date('Y-m-d H:i:s', current_time('timestamp')),
92
+		'user_info'    => stripslashes_deep($user_info),
93 93
 		'post_data'    => $_POST,
94 94
 		'gateway'      => $valid_data['gateway'],
95 95
 		'card_info'    => $valid_data['cc_info']
@@ -99,37 +99,37 @@  discard block
 block discarded – undo
99 99
 	$valid_data['user'] = $user;
100 100
 
101 101
 	// Allow themes and plugins to hook before the gateway
102
-	do_action( 'give_checkout_before_gateway', $_POST, $user_info, $valid_data );
102
+	do_action('give_checkout_before_gateway', $_POST, $user_info, $valid_data);
103 103
 
104 104
 	//Sanity check for price
105
-	if ( ! $purchase_data['price'] ) {
105
+	if ( ! $purchase_data['price']) {
106 106
 		// Revert to manual
107 107
 		$purchase_data['gateway'] = 'manual';
108 108
 		$_POST['give-gateway']    = 'manual';
109 109
 	}
110 110
 
111 111
 	// Allow the purchase data to be modified before it is sent to the gateway
112
-	$purchase_data = apply_filters( 'give_purchase_data_before_gateway', $purchase_data, $valid_data );
112
+	$purchase_data = apply_filters('give_purchase_data_before_gateway', $purchase_data, $valid_data);
113 113
 
114 114
 	// Setup the data we're storing in the purchase session
115 115
 	$session_data = $purchase_data;
116 116
 
117 117
 	// Make sure credit card numbers are never stored in sessions
118
-	unset( $session_data['card_info']['card_number'] );
119
-	unset( $session_data['post_data']['card_number'] );
118
+	unset($session_data['card_info']['card_number']);
119
+	unset($session_data['post_data']['card_number']);
120 120
 
121 121
 	// Used for showing data to non logged-in users after purchase, and for other plugins needing purchase data.
122
-	give_set_purchase_session( $session_data );
122
+	give_set_purchase_session($session_data);
123 123
 
124 124
 	// Send info to the gateway for payment processing
125
-	give_send_to_gateway( $purchase_data['gateway'], $purchase_data );
125
+	give_send_to_gateway($purchase_data['gateway'], $purchase_data);
126 126
 	give_die();
127 127
 
128 128
 }
129 129
 
130
-add_action( 'give_purchase', 'give_process_purchase_form' );
131
-add_action( 'wp_ajax_give_process_checkout', 'give_process_purchase_form' );
132
-add_action( 'wp_ajax_nopriv_give_process_checkout', 'give_process_purchase_form' );
130
+add_action('give_purchase', 'give_process_purchase_form');
131
+add_action('wp_ajax_give_process_checkout', 'give_process_purchase_form');
132
+add_action('wp_ajax_nopriv_give_process_checkout', 'give_process_purchase_form');
133 133
 
134 134
 /**
135 135
  * Process the checkout login form
@@ -140,32 +140,32 @@  discard block
 block discarded – undo
140 140
  */
141 141
 function give_process_form_login() {
142 142
 
143
-	$is_ajax = isset( $_POST['give_ajax'] );
143
+	$is_ajax = isset($_POST['give_ajax']);
144 144
 
145 145
 	$user_data = give_purchase_form_validate_user_login();
146 146
 
147
-	if ( give_get_errors() || $user_data['user_id'] < 1 ) {
148
-		if ( $is_ajax ) {
149
-			do_action( 'give_ajax_checkout_errors' );
147
+	if (give_get_errors() || $user_data['user_id'] < 1) {
148
+		if ($is_ajax) {
149
+			do_action('give_ajax_checkout_errors');
150 150
 			give_die();
151 151
 		} else {
152
-			wp_redirect( $_SERVER['HTTP_REFERER'] );
152
+			wp_redirect($_SERVER['HTTP_REFERER']);
153 153
 			exit;
154 154
 		}
155 155
 	}
156 156
 
157
-	give_log_user_in( $user_data['user_id'], $user_data['user_login'], $user_data['user_pass'] );
157
+	give_log_user_in($user_data['user_id'], $user_data['user_login'], $user_data['user_pass']);
158 158
 
159
-	if ( $is_ajax ) {
159
+	if ($is_ajax) {
160 160
 		echo 'success';
161 161
 		give_die();
162 162
 	} else {
163
-		wp_redirect( $_SERVER['HTTP_REFERER'] );
163
+		wp_redirect($_SERVER['HTTP_REFERER']);
164 164
 	}
165 165
 }
166 166
 
167
-add_action( 'wp_ajax_give_process_checkout_login', 'give_process_form_login' );
168
-add_action( 'wp_ajax_nopriv_give_process_checkout_login', 'give_process_form_login' );
167
+add_action('wp_ajax_give_process_checkout_login', 'give_process_form_login');
168
+add_action('wp_ajax_nopriv_give_process_checkout_login', 'give_process_form_login');
169 169
 
170 170
 /**
171 171
  * Purchase Form Validate Fields
@@ -177,45 +177,45 @@  discard block
 block discarded – undo
177 177
 function give_purchase_form_validate_fields() {
178 178
 
179 179
 	// Check if there is $_POST
180
-	if ( empty( $_POST ) ) {
180
+	if (empty($_POST)) {
181 181
 		return false;
182 182
 	}
183 183
 
184
-	$form_id = isset( $_POST['give-form-id'] ) ? $_POST['give-form-id'] : '';
184
+	$form_id = isset($_POST['give-form-id']) ? $_POST['give-form-id'] : '';
185 185
 
186 186
 	// Start an array to collect valid data
187 187
 	$valid_data = array(
188 188
 		'gateway'          => give_purchase_form_validate_gateway(), // Gateway fallback (amount is validated here)
189
-		'need_new_user'    => false,     // New user flag
190
-		'need_user_login'  => false,     // Login user flag
191
-		'logged_user_data' => array(),   // Logged user collected data
192
-		'new_user_data'    => array(),   // New user collected data
193
-		'login_user_data'  => array(),   // Login user collected data
194
-		'guest_user_data'  => array(),   // Guest user collected data
189
+		'need_new_user'    => false, // New user flag
190
+		'need_user_login'  => false, // Login user flag
191
+		'logged_user_data' => array(), // Logged user collected data
192
+		'new_user_data'    => array(), // New user collected data
193
+		'login_user_data'  => array(), // Login user collected data
194
+		'guest_user_data'  => array(), // Guest user collected data
195 195
 		'cc_info'          => give_purchase_form_validate_cc()    // Credit card info
196 196
 	);
197 197
 
198 198
 	//Validate Honeypot First
199
-	if ( ! empty( $_POST['give-honeypot'] ) ) {
200
-		give_set_error( 'invalid_honeypot', __( 'Honeypot field detected. Go away bad bot!', 'give' ) );
199
+	if ( ! empty($_POST['give-honeypot'])) {
200
+		give_set_error('invalid_honeypot', __('Honeypot field detected. Go away bad bot!', 'give'));
201 201
 	}
202 202
 
203 203
 	// Validate agree to terms
204
-	$terms_option = get_post_meta( $form_id, '_give_terms_option', true );
205
-	if ( isset( $terms_option ) && $terms_option === 'yes' ) {
204
+	$terms_option = get_post_meta($form_id, '_give_terms_option', true);
205
+	if (isset($terms_option) && $terms_option === 'yes') {
206 206
 		give_purchase_form_validate_agree_to_terms();
207 207
 	}
208 208
 
209
-	if ( is_user_logged_in() ) {
209
+	if (is_user_logged_in()) {
210 210
 		// Collect logged in user data
211 211
 		$valid_data['logged_in_user'] = give_purchase_form_validate_logged_in_user();
212
-	} else if ( isset( $_POST['give-purchase-var'] ) && $_POST['give-purchase-var'] == 'needs-to-register' ) {
212
+	} else if (isset($_POST['give-purchase-var']) && $_POST['give-purchase-var'] == 'needs-to-register') {
213 213
 		// Set new user registration as required
214 214
 		$valid_data['need_new_user'] = true;
215 215
 		// Validate new user data
216 216
 		$valid_data['new_user_data'] = give_purchase_form_validate_new_user();
217 217
 		// Check if login validation is needed
218
-	} else if ( isset( $_POST['give-purchase-var'] ) && $_POST['give-purchase-var'] == 'needs-to-login' ) {
218
+	} else if (isset($_POST['give-purchase-var']) && $_POST['give-purchase-var'] == 'needs-to-login') {
219 219
 		// Set user login as required
220 220
 		$valid_data['need_user_login'] = true;
221 221
 		// Validate users login info
@@ -240,37 +240,37 @@  discard block
 block discarded – undo
240 240
  */
241 241
 function give_purchase_form_validate_gateway() {
242 242
 
243
-	$form_id = isset( $_REQUEST['give-form-id'] ) ? $_REQUEST['give-form-id'] : 0;
244
-	$amount  = isset( $_REQUEST['give-amount'] ) ? give_sanitize_amount( $_REQUEST['give-amount'] ) : 0;
245
-	$gateway = give_get_default_gateway( $form_id );
243
+	$form_id = isset($_REQUEST['give-form-id']) ? $_REQUEST['give-form-id'] : 0;
244
+	$amount  = isset($_REQUEST['give-amount']) ? give_sanitize_amount($_REQUEST['give-amount']) : 0;
245
+	$gateway = give_get_default_gateway($form_id);
246 246
 
247 247
 	// Check if a gateway value is present
248
-	if ( ! empty( $_REQUEST['give-gateway'] ) ) {
248
+	if ( ! empty($_REQUEST['give-gateway'])) {
249 249
 
250
-		$gateway = sanitize_text_field( $_REQUEST['give-gateway'] );
250
+		$gateway = sanitize_text_field($_REQUEST['give-gateway']);
251 251
 
252 252
 		//Is amount being donated in LIVE mode 0.00? If so, error:
253
-		if ( $amount == 0 && ! give_is_test_mode() ) {
253
+		if ($amount == 0 && ! give_is_test_mode()) {
254 254
 
255
-			give_set_error( 'invalid_donation_amount', __( 'Please insert a valid donation amount.', 'give' ) );
255
+			give_set_error('invalid_donation_amount', __('Please insert a valid donation amount.', 'give'));
256 256
 
257 257
 		} //Check for a minimum custom amount
258
-		elseif ( ! give_verify_minimum_price() ) {
258
+		elseif ( ! give_verify_minimum_price()) {
259 259
 
260
-			$minimum       = give_currency_filter( give_format_amount( give_get_form_minimum_price( $form_id ) ) );
261
-			$error_message = __( 'This form has a minimum donation amount of %s.', 'give' );
260
+			$minimum       = give_currency_filter(give_format_amount(give_get_form_minimum_price($form_id)));
261
+			$error_message = __('This form has a minimum donation amount of %s.', 'give');
262 262
 
263
-			give_set_error( 'invalid_donation_minimum', sprintf( $error_message, $minimum ) );
263
+			give_set_error('invalid_donation_minimum', sprintf($error_message, $minimum));
264 264
 
265 265
 		} //Is this test mode zero donation? Let it through but set to manual gateway
266
-		elseif ( $amount == 0 && give_is_test_mode() ) {
266
+		elseif ($amount == 0 && give_is_test_mode()) {
267 267
 
268 268
 			$gateway = 'manual';
269 269
 
270 270
 		} //Check if this gateway is active
271
-		elseif ( ! give_is_gateway_active( $gateway ) ) {
271
+		elseif ( ! give_is_gateway_active($gateway)) {
272 272
 
273
-			give_set_error( 'invalid_gateway', __( 'The selected payment gateway is not enabled.', 'give' ) );
273
+			give_set_error('invalid_gateway', __('The selected payment gateway is not enabled.', 'give'));
274 274
 
275 275
 		}
276 276
 
@@ -289,23 +289,23 @@  discard block
 block discarded – undo
289 289
  */
290 290
 function give_verify_minimum_price() {
291 291
 
292
-	$amount          = give_sanitize_amount( $_REQUEST['give-amount'] );
293
-	$form_id         = isset( $_REQUEST['give-form-id'] ) ? $_REQUEST['give-form-id'] : 0;
294
-	$price_id        = isset( $_REQUEST['give-price-id'] ) ? $_REQUEST['give-price-id'] : 0;
295
-	$variable_prices = give_has_variable_prices( $form_id );
292
+	$amount          = give_sanitize_amount($_REQUEST['give-amount']);
293
+	$form_id         = isset($_REQUEST['give-form-id']) ? $_REQUEST['give-form-id'] : 0;
294
+	$price_id        = isset($_REQUEST['give-price-id']) ? $_REQUEST['give-price-id'] : 0;
295
+	$variable_prices = give_has_variable_prices($form_id);
296 296
 
297
-	if ( $variable_prices && ! empty( $price_id ) ) {
297
+	if ($variable_prices && ! empty($price_id)) {
298 298
 
299
-		$price_level_amount = give_get_price_option_amount( $form_id, $price_id );
299
+		$price_level_amount = give_get_price_option_amount($form_id, $price_id);
300 300
 
301
-		if ( $price_level_amount == $amount ) {
301
+		if ($price_level_amount == $amount) {
302 302
 			return true;
303 303
 		}
304 304
 	}
305 305
 
306
-	$minimum = give_get_form_minimum_price( $form_id );
306
+	$minimum = give_get_form_minimum_price($form_id);
307 307
 
308
-	if ( $minimum > $amount ) {
308
+	if ($minimum > $amount) {
309 309
 		return false;
310 310
 	}
311 311
 
@@ -321,9 +321,9 @@  discard block
 block discarded – undo
321 321
  */
322 322
 function give_purchase_form_validate_agree_to_terms() {
323 323
 	// Validate agree to terms
324
-	if ( ! isset( $_POST['give_agree_to_terms'] ) || $_POST['give_agree_to_terms'] != 1 ) {
324
+	if ( ! isset($_POST['give_agree_to_terms']) || $_POST['give_agree_to_terms'] != 1) {
325 325
 		// User did not agree
326
-		give_set_error( 'agree_to_terms', apply_filters( 'give_agree_to_terms_text', __( 'You must agree to the terms of use.', 'give' ) ) );
326
+		give_set_error('agree_to_terms', apply_filters('give_agree_to_terms_text', __('You must agree to the terms of use.', 'give')));
327 327
 	}
328 328
 }
329 329
 
@@ -337,47 +337,47 @@  discard block
 block discarded – undo
337 337
  *
338 338
  * @return      array
339 339
  */
340
-function give_purchase_form_required_fields( $form_id ) {
340
+function give_purchase_form_required_fields($form_id) {
341 341
 
342
-	$payment_mode = give_get_chosen_gateway( $form_id );
342
+	$payment_mode = give_get_chosen_gateway($form_id);
343 343
 
344 344
 	$required_fields = array(
345 345
 		'give_email' => array(
346 346
 			'error_id'      => 'invalid_email',
347
-			'error_message' => __( 'Please enter a valid email address.', 'give' )
347
+			'error_message' => __('Please enter a valid email address.', 'give')
348 348
 		),
349 349
 		'give_first' => array(
350 350
 			'error_id'      => 'invalid_first_name',
351
-			'error_message' => __( 'Please enter your first name.', 'give' )
351
+			'error_message' => __('Please enter your first name.', 'give')
352 352
 		)
353 353
 	);
354 354
 
355
-	$require_address = give_require_billing_address( $payment_mode );
355
+	$require_address = give_require_billing_address($payment_mode);
356 356
 
357
-	if ( $require_address ) {
358
-		$required_fields['card_address']    = array(
357
+	if ($require_address) {
358
+		$required_fields['card_address'] = array(
359 359
 			'error_id'      => 'invalid_card_address',
360
-			'error_message' => __( 'Please enter your primary billing address.', 'give' )
360
+			'error_message' => __('Please enter your primary billing address.', 'give')
361 361
 		);
362
-		$required_fields['card_zip']        = array(
362
+		$required_fields['card_zip'] = array(
363 363
 			'error_id'      => 'invalid_zip_code',
364
-			'error_message' => __( 'Please enter your zip / postal code.', 'give' )
364
+			'error_message' => __('Please enter your zip / postal code.', 'give')
365 365
 		);
366
-		$required_fields['card_city']       = array(
366
+		$required_fields['card_city'] = array(
367 367
 			'error_id'      => 'invalid_city',
368
-			'error_message' => __( 'Please enter your billing city.', 'give' )
368
+			'error_message' => __('Please enter your billing city.', 'give')
369 369
 		);
370 370
 		$required_fields['billing_country'] = array(
371 371
 			'error_id'      => 'invalid_country',
372
-			'error_message' => __( 'Please select your billing country.', 'give' )
372
+			'error_message' => __('Please select your billing country.', 'give')
373 373
 		);
374
-		$required_fields['card_state']      = array(
374
+		$required_fields['card_state'] = array(
375 375
 			'error_id'      => 'invalid_state',
376
-			'error_message' => __( 'Please enter billing state / province.', 'give' )
376
+			'error_message' => __('Please enter billing state / province.', 'give')
377 377
 		);
378 378
 	}
379 379
 
380
-	return apply_filters( 'give_purchase_form_required_fields', $required_fields, $form_id );
380
+	return apply_filters('give_purchase_form_required_fields', $required_fields, $form_id);
381 381
 
382 382
 }
383 383
 
@@ -390,16 +390,16 @@  discard block
 block discarded – undo
390 390
  *
391 391
  * @return mixed|void
392 392
  */
393
-function give_require_billing_address( $payment_mode ) {
393
+function give_require_billing_address($payment_mode) {
394 394
 
395 395
 	$return = false;
396 396
 
397
-	if ( isset( $_POST['billing_country'] ) || did_action( "give_{$payment_mode}_cc_form" ) || did_action( 'give_cc_form' ) ) {
397
+	if (isset($_POST['billing_country']) || did_action("give_{$payment_mode}_cc_form") || did_action('give_cc_form')) {
398 398
 		$return = true;
399 399
 	}
400 400
 
401 401
 	// Let payment gateways and other extensions determine if address fields should be required
402
-	return apply_filters( 'give_require_billing_address', $return );
402
+	return apply_filters('give_require_billing_address', $return);
403 403
 
404 404
 }
405 405
 
@@ -413,43 +413,43 @@  discard block
 block discarded – undo
413 413
 function give_purchase_form_validate_logged_in_user() {
414 414
 	global $user_ID;
415 415
 
416
-	$form_id = isset( $_POST['give-form-id'] ) ? $_POST['give-form-id'] : '';
416
+	$form_id = isset($_POST['give-form-id']) ? $_POST['give-form-id'] : '';
417 417
 
418 418
 	// Start empty array to collect valid user data
419 419
 	$valid_user_data = array(
420 420
 		// Assume there will be errors
421
-		'user_id' => - 1
421
+		'user_id' => -1
422 422
 	);
423 423
 
424 424
 	// Verify there is a user_ID
425
-	if ( $user_ID > 0 ) {
425
+	if ($user_ID > 0) {
426 426
 		// Get the logged in user data
427
-		$user_data = get_userdata( $user_ID );
427
+		$user_data = get_userdata($user_ID);
428 428
 
429 429
 		// Loop through required fields and show error messages
430
-		foreach ( give_purchase_form_required_fields( $form_id ) as $field_name => $value ) {
431
-			if ( in_array( $value, give_purchase_form_required_fields( $form_id ) ) && empty( $_POST[ $field_name ] ) ) {
432
-				give_set_error( $value['error_id'], $value['error_message'] );
430
+		foreach (give_purchase_form_required_fields($form_id) as $field_name => $value) {
431
+			if (in_array($value, give_purchase_form_required_fields($form_id)) && empty($_POST[$field_name])) {
432
+				give_set_error($value['error_id'], $value['error_message']);
433 433
 			}
434 434
 		}
435 435
 
436 436
 		// Verify data
437
-		if ( $user_data ) {
437
+		if ($user_data) {
438 438
 			// Collected logged in user data
439 439
 			$valid_user_data = array(
440 440
 				'user_id'    => $user_ID,
441
-				'user_email' => isset( $_POST['give_email'] ) ? sanitize_email( $_POST['give_email'] ) : $user_data->user_email,
442
-				'user_first' => isset( $_POST['give_first'] ) && ! empty( $_POST['give_first'] ) ? sanitize_text_field( $_POST['give_first'] ) : $user_data->first_name,
443
-				'user_last'  => isset( $_POST['give_last'] ) && ! empty( $_POST['give_last'] ) ? sanitize_text_field( $_POST['give_last'] ) : $user_data->last_name,
441
+				'user_email' => isset($_POST['give_email']) ? sanitize_email($_POST['give_email']) : $user_data->user_email,
442
+				'user_first' => isset($_POST['give_first']) && ! empty($_POST['give_first']) ? sanitize_text_field($_POST['give_first']) : $user_data->first_name,
443
+				'user_last'  => isset($_POST['give_last']) && ! empty($_POST['give_last']) ? sanitize_text_field($_POST['give_last']) : $user_data->last_name,
444 444
 			);
445 445
 
446
-			if ( ! is_email( $valid_user_data['user_email'] ) ) {
447
-				give_set_error( 'email_invalid', __( 'Invalid email', 'give' ) );
446
+			if ( ! is_email($valid_user_data['user_email'])) {
447
+				give_set_error('email_invalid', __('Invalid email', 'give'));
448 448
 			}
449 449
 
450 450
 		} else {
451 451
 			// Set invalid user error
452
-			give_set_error( 'invalid_user', __( 'The user information is invalid.', 'give' ) );
452
+			give_set_error('invalid_user', __('The user information is invalid.', 'give'));
453 453
 		}
454 454
 	}
455 455
 
@@ -467,90 +467,90 @@  discard block
 block discarded – undo
467 467
 function give_purchase_form_validate_new_user() {
468 468
 
469 469
 	$registering_new_user = false;
470
-	$form_id              = isset( $_POST['give-form-id'] ) ? $_POST['give-form-id'] : '';
470
+	$form_id              = isset($_POST['give-form-id']) ? $_POST['give-form-id'] : '';
471 471
 
472 472
 	// Start an empty array to collect valid user data
473 473
 	$valid_user_data = array(
474 474
 		// Assume there will be errors
475
-		'user_id'    => - 1,
475
+		'user_id'    => -1,
476 476
 		// Get first name
477
-		'user_first' => isset( $_POST['give_first'] ) ? sanitize_text_field( $_POST['give_first'] ) : '',
477
+		'user_first' => isset($_POST['give_first']) ? sanitize_text_field($_POST['give_first']) : '',
478 478
 		// Get last name
479
-		'user_last'  => isset( $_POST['give_last'] ) ? sanitize_text_field( $_POST['give_last'] ) : '',
479
+		'user_last'  => isset($_POST['give_last']) ? sanitize_text_field($_POST['give_last']) : '',
480 480
 	);
481 481
 
482 482
 	// Check the new user's credentials against existing ones
483
-	$user_login   = isset( $_POST['give_user_login'] ) ? trim( $_POST['give_user_login'] ) : false;
484
-	$user_email   = isset( $_POST['give_email'] ) ? trim( $_POST['give_email'] ) : false;
485
-	$user_pass    = isset( $_POST['give_user_pass'] ) ? trim( $_POST['give_user_pass'] ) : false;
486
-	$pass_confirm = isset( $_POST['give_user_pass_confirm'] ) ? trim( $_POST['give_user_pass_confirm'] ) : false;
483
+	$user_login   = isset($_POST['give_user_login']) ? trim($_POST['give_user_login']) : false;
484
+	$user_email   = isset($_POST['give_email']) ? trim($_POST['give_email']) : false;
485
+	$user_pass    = isset($_POST['give_user_pass']) ? trim($_POST['give_user_pass']) : false;
486
+	$pass_confirm = isset($_POST['give_user_pass_confirm']) ? trim($_POST['give_user_pass_confirm']) : false;
487 487
 
488 488
 	// Loop through required fields and show error messages
489
-	foreach ( give_purchase_form_required_fields( $form_id ) as $field_name => $value ) {
490
-		if ( in_array( $value, give_purchase_form_required_fields( $form_id ) ) && empty( $_POST[ $field_name ] ) ) {
491
-			give_set_error( $value['error_id'], $value['error_message'] );
489
+	foreach (give_purchase_form_required_fields($form_id) as $field_name => $value) {
490
+		if (in_array($value, give_purchase_form_required_fields($form_id)) && empty($_POST[$field_name])) {
491
+			give_set_error($value['error_id'], $value['error_message']);
492 492
 		}
493 493
 	}
494 494
 
495 495
 	// Check if we have an username to register
496
-	if ( $user_login && strlen( $user_login ) > 0 ) {
496
+	if ($user_login && strlen($user_login) > 0) {
497 497
 		$registering_new_user = true;
498 498
 
499 499
 		// We have an user name, check if it already exists
500
-		if ( username_exists( $user_login ) ) {
500
+		if (username_exists($user_login)) {
501 501
 			// Username already registered
502
-			give_set_error( 'username_unavailable', __( 'Username already taken.', 'give' ) );
502
+			give_set_error('username_unavailable', __('Username already taken.', 'give'));
503 503
 			// Check if it's valid
504
-		} else if ( ! give_validate_username( $user_login ) ) {
504
+		} else if ( ! give_validate_username($user_login)) {
505 505
 			// Invalid username
506
-			if ( is_multisite() ) {
507
-				give_set_error( 'username_invalid', __( 'Invalid username. Only lowercase letters (a-z) and numbers are allowed.', 'give' ) );
506
+			if (is_multisite()) {
507
+				give_set_error('username_invalid', __('Invalid username. Only lowercase letters (a-z) and numbers are allowed.', 'give'));
508 508
 			} else {
509
-				give_set_error( 'username_invalid', __( 'Invalid username.', 'give' ) );
509
+				give_set_error('username_invalid', __('Invalid username.', 'give'));
510 510
 			}
511 511
 		} else {
512 512
 			// All the checks have run and it's good to go
513 513
 			$valid_user_data['user_login'] = $user_login;
514 514
 		}
515
-	} elseif ( give_logged_in_only( $form_id ) ) {
516
-		give_set_error( 'registration_required', esc_html__( 'You must register or login to complete your donation.', 'give' ) );
515
+	} elseif (give_logged_in_only($form_id)) {
516
+		give_set_error('registration_required', esc_html__('You must register or login to complete your donation.', 'give'));
517 517
 	}
518 518
 
519 519
 	// Check if we have an email to verify
520
-	if ( $user_email && strlen( $user_email ) > 0 ) {
520
+	if ($user_email && strlen($user_email) > 0) {
521 521
 		// Validate email
522
-		if ( ! is_email( $user_email ) ) {
523
-			give_set_error( 'email_invalid', __( 'Sorry, that email is invalid.', 'give' ) );
522
+		if ( ! is_email($user_email)) {
523
+			give_set_error('email_invalid', __('Sorry, that email is invalid.', 'give'));
524 524
 			// Check if email exists
525
-		} else if ( email_exists( $user_email ) && $registering_new_user ) {
526
-			give_set_error( 'email_used', __( 'Sorry, that email already active for another user.', 'give' ) );
525
+		} else if (email_exists($user_email) && $registering_new_user) {
526
+			give_set_error('email_used', __('Sorry, that email already active for another user.', 'give'));
527 527
 		} else {
528 528
 			// All the checks have run and it's good to go
529 529
 			$valid_user_data['user_email'] = $user_email;
530 530
 		}
531 531
 	} else {
532 532
 		// No email
533
-		give_set_error( 'email_empty', __( 'Enter an email.', 'give' ) );
533
+		give_set_error('email_empty', __('Enter an email.', 'give'));
534 534
 	}
535 535
 
536 536
 	// Check password
537
-	if ( $user_pass && $pass_confirm ) {
537
+	if ($user_pass && $pass_confirm) {
538 538
 		// Verify confirmation matches
539
-		if ( $user_pass != $pass_confirm ) {
539
+		if ($user_pass != $pass_confirm) {
540 540
 			// Passwords do not match
541
-			give_set_error( 'password_mismatch', __( 'Passwords don\'t match.', 'give' ) );
541
+			give_set_error('password_mismatch', __('Passwords don\'t match.', 'give'));
542 542
 		} else {
543 543
 			// All is good to go
544 544
 			$valid_user_data['user_pass'] = $user_pass;
545 545
 		}
546 546
 	} else {
547 547
 		// Password or confirmation missing
548
-		if ( ! $user_pass && $registering_new_user ) {
548
+		if ( ! $user_pass && $registering_new_user) {
549 549
 			// The password is invalid
550
-			give_set_error( 'password_empty', __( 'Enter a password.', 'give' ) );
551
-		} else if ( ! $pass_confirm && $registering_new_user ) {
550
+			give_set_error('password_empty', __('Enter a password.', 'give'));
551
+		} else if ( ! $pass_confirm && $registering_new_user) {
552 552
 			// Confirmation password is invalid
553
-			give_set_error( 'confirmation_empty', __( 'Enter the password confirmation.', 'give' ) );
553
+			give_set_error('confirmation_empty', __('Enter the password confirmation.', 'give'));
554 554
 		}
555 555
 	}
556 556
 
@@ -569,36 +569,36 @@  discard block
 block discarded – undo
569 569
 	// Start an array to collect valid user data
570 570
 	$valid_user_data = array(
571 571
 		// Assume there will be errors
572
-		'user_id' => - 1
572
+		'user_id' => -1
573 573
 	);
574 574
 
575 575
 	// Username
576
-	if ( ! isset( $_POST['give_user_login'] ) || $_POST['give_user_login'] == '' ) {
577
-		give_set_error( 'must_log_in', __( 'You must login or register to complete your donation.', 'give' ) );
576
+	if ( ! isset($_POST['give_user_login']) || $_POST['give_user_login'] == '') {
577
+		give_set_error('must_log_in', __('You must login or register to complete your donation.', 'give'));
578 578
 
579 579
 		return $valid_user_data;
580 580
 	}
581 581
 
582 582
 	// Get the user by login
583
-	$user_data = get_user_by( 'login', strip_tags( $_POST['give_user_login'] ) );
583
+	$user_data = get_user_by('login', strip_tags($_POST['give_user_login']));
584 584
 
585 585
 	// Check if user exists
586
-	if ( $user_data ) {
586
+	if ($user_data) {
587 587
 		// Get password
588
-		$user_pass = isset( $_POST['give_user_pass'] ) ? $_POST['give_user_pass'] : false;
588
+		$user_pass = isset($_POST['give_user_pass']) ? $_POST['give_user_pass'] : false;
589 589
 
590 590
 		// Check user_pass
591
-		if ( $user_pass ) {
591
+		if ($user_pass) {
592 592
 			// Check if password is valid
593
-			if ( ! wp_check_password( $user_pass, $user_data->user_pass, $user_data->ID ) ) {
593
+			if ( ! wp_check_password($user_pass, $user_data->user_pass, $user_data->ID)) {
594 594
 				// Incorrect password
595 595
 				give_set_error(
596 596
 					'password_incorrect',
597 597
 					sprintf(
598 598
 						'%1$s <a href="%2$s">%3$s</a>',
599
-						__( 'The password you entered is incorrect.', 'give' ),
600
-						wp_lostpassword_url( "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]" ),
601
-						__( 'Reset Password', 'give' )
599
+						__('The password you entered is incorrect.', 'give'),
600
+						wp_lostpassword_url("http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"),
601
+						__('Reset Password', 'give')
602 602
 					)
603 603
 				);
604 604
 				// All is correct
@@ -615,11 +615,11 @@  discard block
 block discarded – undo
615 615
 			}
616 616
 		} else {
617 617
 			// Empty password
618
-			give_set_error( 'password_empty', __( 'Enter a password.', 'give' ) );
618
+			give_set_error('password_empty', __('Enter a password.', 'give'));
619 619
 		}
620 620
 	} else {
621 621
 		// no username
622
-		give_set_error( 'username_incorrect', __( 'The username you entered does not exist.', 'give' ) );
622
+		give_set_error('username_incorrect', __('The username you entered does not exist.', 'give'));
623 623
 	}
624 624
 
625 625
 	return $valid_user_data;
@@ -634,7 +634,7 @@  discard block
 block discarded – undo
634 634
  */
635 635
 function give_purchase_form_validate_guest_user() {
636 636
 
637
-	$form_id = isset( $_POST['give-form-id'] ) ? $_POST['give-form-id'] : '';
637
+	$form_id = isset($_POST['give-form-id']) ? $_POST['give-form-id'] : '';
638 638
 
639 639
 	// Start an array to collect valid user data
640 640
 	$valid_user_data = array(
@@ -643,32 +643,32 @@  discard block
 block discarded – undo
643 643
 	);
644 644
 
645 645
 	// Show error message if user must be logged in
646
-	if ( give_logged_in_only( $form_id ) ) {
647
-		give_set_error( 'logged_in_only', __( 'You must be logged into to donate.', 'give' ) );
646
+	if (give_logged_in_only($form_id)) {
647
+		give_set_error('logged_in_only', __('You must be logged into to donate.', 'give'));
648 648
 	}
649 649
 
650 650
 	// Get the guest email
651
-	$guest_email = isset( $_POST['give_email'] ) ? $_POST['give_email'] : false;
651
+	$guest_email = isset($_POST['give_email']) ? $_POST['give_email'] : false;
652 652
 
653 653
 	// Check email
654
-	if ( $guest_email && strlen( $guest_email ) > 0 ) {
654
+	if ($guest_email && strlen($guest_email) > 0) {
655 655
 		// Validate email
656
-		if ( ! is_email( $guest_email ) ) {
656
+		if ( ! is_email($guest_email)) {
657 657
 			// Invalid email
658
-			give_set_error( 'email_invalid', __( 'Invalid email.', 'give' ) );
658
+			give_set_error('email_invalid', __('Invalid email.', 'give'));
659 659
 		} else {
660 660
 			// All is good to go
661 661
 			$valid_user_data['user_email'] = $guest_email;
662 662
 		}
663 663
 	} else {
664 664
 		// No email
665
-		give_set_error( 'email_empty', __( 'Enter an email.', 'give' ) );
665
+		give_set_error('email_empty', __('Enter an email.', 'give'));
666 666
 	}
667 667
 
668 668
 	// Loop through required fields and show error messages
669
-	foreach ( give_purchase_form_required_fields( $form_id ) as $field_name => $value ) {
670
-		if ( in_array( $value, give_purchase_form_required_fields( $form_id ) ) && empty( $_POST[ $field_name ] ) ) {
671
-			give_set_error( $value['error_id'], $value['error_message'] );
669
+	foreach (give_purchase_form_required_fields($form_id) as $field_name => $value) {
670
+		if (in_array($value, give_purchase_form_required_fields($form_id)) && empty($_POST[$field_name])) {
671
+			give_set_error($value['error_id'], $value['error_message']);
672 672
 		}
673 673
 	}
674 674
 
@@ -684,42 +684,42 @@  discard block
 block discarded – undo
684 684
  * @since   1.0
685 685
  * @return  integer
686 686
  */
687
-function give_register_and_login_new_user( $user_data = array() ) {
687
+function give_register_and_login_new_user($user_data = array()) {
688 688
 	// Verify the array
689
-	if ( empty( $user_data ) ) {
690
-		return - 1;
689
+	if (empty($user_data)) {
690
+		return -1;
691 691
 	}
692 692
 
693
-	if ( give_get_errors() ) {
694
-		return - 1;
693
+	if (give_get_errors()) {
694
+		return -1;
695 695
 	}
696 696
 
697
-	$user_args = apply_filters( 'give_insert_user_args', array(
698
-		'user_login'      => isset( $user_data['user_login'] ) ? $user_data['user_login'] : '',
699
-		'user_pass'       => isset( $user_data['user_pass'] ) ? $user_data['user_pass'] : '',
700
-		'user_email'      => isset( $user_data['user_email'] ) ? $user_data['user_email'] : '',
701
-		'first_name'      => isset( $user_data['user_first'] ) ? $user_data['user_first'] : '',
702
-		'last_name'       => isset( $user_data['user_last'] ) ? $user_data['user_last'] : '',
703
-		'user_registered' => date( 'Y-m-d H:i:s' ),
704
-		'role'            => get_option( 'default_role' )
705
-	), $user_data );
697
+	$user_args = apply_filters('give_insert_user_args', array(
698
+		'user_login'      => isset($user_data['user_login']) ? $user_data['user_login'] : '',
699
+		'user_pass'       => isset($user_data['user_pass']) ? $user_data['user_pass'] : '',
700
+		'user_email'      => isset($user_data['user_email']) ? $user_data['user_email'] : '',
701
+		'first_name'      => isset($user_data['user_first']) ? $user_data['user_first'] : '',
702
+		'last_name'       => isset($user_data['user_last']) ? $user_data['user_last'] : '',
703
+		'user_registered' => date('Y-m-d H:i:s'),
704
+		'role'            => get_option('default_role')
705
+	), $user_data);
706 706
 
707 707
 	// Insert new user
708
-	$user_id = wp_insert_user( $user_args );
708
+	$user_id = wp_insert_user($user_args);
709 709
 
710 710
 	// Validate inserted user
711
-	if ( is_wp_error( $user_id ) ) {
712
-		return - 1;
711
+	if (is_wp_error($user_id)) {
712
+		return -1;
713 713
 	}
714 714
 
715 715
 	// Allow themes and plugins to filter the user data
716
-	$user_data = apply_filters( 'give_insert_user_data', $user_data, $user_args );
716
+	$user_data = apply_filters('give_insert_user_data', $user_data, $user_args);
717 717
 
718 718
 	// Allow themes and plugins to hook
719
-	do_action( 'give_insert_user', $user_id, $user_data );
719
+	do_action('give_insert_user', $user_id, $user_data);
720 720
 
721 721
 	// Login new user
722
-	give_log_user_in( $user_id, $user_data['user_login'], $user_data['user_pass'] );
722
+	give_log_user_in($user_id, $user_data['user_login'], $user_data['user_pass']);
723 723
 
724 724
 	// Return user id
725 725
 	return $user_id;
@@ -734,27 +734,27 @@  discard block
 block discarded – undo
734 734
  * @since   1.0
735 735
  * @return  array
736 736
  */
737
-function give_get_purchase_form_user( $valid_data = array() ) {
737
+function give_get_purchase_form_user($valid_data = array()) {
738 738
 
739 739
 	// Initialize user
740 740
 	$user    = false;
741
-	$is_ajax = defined( 'DOING_AJAX' ) && DOING_AJAX;
741
+	$is_ajax = defined('DOING_AJAX') && DOING_AJAX;
742 742
 
743
-	if ( $is_ajax ) {
743
+	if ($is_ajax) {
744 744
 		// Do not create or login the user during the ajax submission (check for errors only)
745 745
 		return true;
746
-	} else if ( is_user_logged_in() ) {
746
+	} else if (is_user_logged_in()) {
747 747
 		// Set the valid user as the logged in collected data
748 748
 		$user = $valid_data['logged_in_user'];
749
-	} else if ( $valid_data['need_new_user'] === true || $valid_data['need_user_login'] === true ) {
749
+	} else if ($valid_data['need_new_user'] === true || $valid_data['need_user_login'] === true) {
750 750
 		// New user registration
751
-		if ( $valid_data['need_new_user'] === true ) {
751
+		if ($valid_data['need_new_user'] === true) {
752 752
 			// Set user
753 753
 			$user = $valid_data['new_user_data'];
754 754
 			// Register and login new user
755
-			$user['user_id'] = give_register_and_login_new_user( $user );
755
+			$user['user_id'] = give_register_and_login_new_user($user);
756 756
 			// User login
757
-		} else if ( $valid_data['need_user_login'] === true && ! $is_ajax ) {
757
+		} else if ($valid_data['need_user_login'] === true && ! $is_ajax) {
758 758
 
759 759
 			/*
760 760
 			 * The login form is now processed in the give_process_purchase_login() function.
@@ -769,48 +769,48 @@  discard block
 block discarded – undo
769 769
 			// Set user
770 770
 			$user = $valid_data['login_user_data'];
771 771
 			// Login user
772
-			give_log_user_in( $user['user_id'], $user['user_login'], $user['user_pass'] );
772
+			give_log_user_in($user['user_id'], $user['user_login'], $user['user_pass']);
773 773
 		}
774 774
 	}
775 775
 
776 776
 	// Check guest checkout
777
-	if ( false === $user && false === give_logged_in_only( $_POST['give-form-id'] ) ) {
777
+	if (false === $user && false === give_logged_in_only($_POST['give-form-id'])) {
778 778
 		// Set user
779 779
 		$user = $valid_data['guest_user_data'];
780 780
 	}
781 781
 
782 782
 	// Verify we have an user
783
-	if ( false === $user || empty( $user ) ) {
783
+	if (false === $user || empty($user)) {
784 784
 		// Return false
785 785
 		return false;
786 786
 	}
787 787
 
788 788
 	// Get user first name
789
-	if ( ! isset( $user['user_first'] ) || strlen( trim( $user['user_first'] ) ) < 1 ) {
790
-		$user['user_first'] = isset( $_POST['give_first'] ) ? strip_tags( trim( $_POST['give_first'] ) ) : '';
789
+	if ( ! isset($user['user_first']) || strlen(trim($user['user_first'])) < 1) {
790
+		$user['user_first'] = isset($_POST['give_first']) ? strip_tags(trim($_POST['give_first'])) : '';
791 791
 	}
792 792
 
793 793
 	// Get user last name
794
-	if ( ! isset( $user['user_last'] ) || strlen( trim( $user['user_last'] ) ) < 1 ) {
795
-		$user['user_last'] = isset( $_POST['give_last'] ) ? strip_tags( trim( $_POST['give_last'] ) ) : '';
794
+	if ( ! isset($user['user_last']) || strlen(trim($user['user_last'])) < 1) {
795
+		$user['user_last'] = isset($_POST['give_last']) ? strip_tags(trim($_POST['give_last'])) : '';
796 796
 	}
797 797
 
798 798
 	// Get the user's billing address details
799 799
 	$user['address']            = array();
800
-	$user['address']['line1']   = ! empty( $_POST['card_address'] ) ? sanitize_text_field( $_POST['card_address'] ) : false;
801
-	$user['address']['line2']   = ! empty( $_POST['card_address_2'] ) ? sanitize_text_field( $_POST['card_address_2'] ) : false;
802
-	$user['address']['city']    = ! empty( $_POST['card_city'] ) ? sanitize_text_field( $_POST['card_city'] ) : false;
803
-	$user['address']['state']   = ! empty( $_POST['card_state'] ) ? sanitize_text_field( $_POST['card_state'] ) : false;
804
-	$user['address']['country'] = ! empty( $_POST['billing_country'] ) ? sanitize_text_field( $_POST['billing_country'] ) : false;
805
-	$user['address']['zip']     = ! empty( $_POST['card_zip'] ) ? sanitize_text_field( $_POST['card_zip'] ) : false;
806
-
807
-	if ( empty( $user['address']['country'] ) ) {
800
+	$user['address']['line1']   = ! empty($_POST['card_address']) ? sanitize_text_field($_POST['card_address']) : false;
801
+	$user['address']['line2']   = ! empty($_POST['card_address_2']) ? sanitize_text_field($_POST['card_address_2']) : false;
802
+	$user['address']['city']    = ! empty($_POST['card_city']) ? sanitize_text_field($_POST['card_city']) : false;
803
+	$user['address']['state']   = ! empty($_POST['card_state']) ? sanitize_text_field($_POST['card_state']) : false;
804
+	$user['address']['country'] = ! empty($_POST['billing_country']) ? sanitize_text_field($_POST['billing_country']) : false;
805
+	$user['address']['zip']     = ! empty($_POST['card_zip']) ? sanitize_text_field($_POST['card_zip']) : false;
806
+
807
+	if (empty($user['address']['country'])) {
808 808
 		$user['address'] = false;
809 809
 	} // Country will always be set if address fields are present
810 810
 
811
-	if ( ! empty( $user['user_id'] ) && $user['user_id'] > 0 && ! empty( $user['address'] ) ) {
811
+	if ( ! empty($user['user_id']) && $user['user_id'] > 0 && ! empty($user['address'])) {
812 812
 		// Store the address in the user's meta so the donation form can be pre-populated with it on return purchases
813
-		update_user_meta( $user['user_id'], '_give_user_address', $user['address'] );
813
+		update_user_meta($user['user_id'], '_give_user_address', $user['address']);
814 814
 	}
815 815
 
816 816
 	// Return valid user
@@ -829,16 +829,16 @@  discard block
 block discarded – undo
829 829
 	$card_data = give_get_purchase_cc_info();
830 830
 
831 831
 	// Validate the card zip
832
-	if ( ! empty( $card_data['card_zip'] ) ) {
833
-		if ( ! give_purchase_form_validate_cc_zip( $card_data['card_zip'], $card_data['card_country'] ) ) {
834
-			give_set_error( 'invalid_cc_zip', __( 'The zip / postal code you entered for your billing address is invalid.', 'give' ) );
832
+	if ( ! empty($card_data['card_zip'])) {
833
+		if ( ! give_purchase_form_validate_cc_zip($card_data['card_zip'], $card_data['card_country'])) {
834
+			give_set_error('invalid_cc_zip', __('The zip / postal code you entered for your billing address is invalid.', 'give'));
835 835
 		}
836 836
 	}
837 837
 
838 838
 	//Ensure no spaces
839
-	if ( ! empty( $card_data['card_number'] ) ) {
840
-		$card_data['card_number'] = str_replace( '+', '', $card_data['card_number'] ); //no "+" signs
841
-		$card_data['card_number'] = str_replace( ' ', '', $card_data['card_number'] ); // No spaces
839
+	if ( ! empty($card_data['card_number'])) {
840
+		$card_data['card_number'] = str_replace('+', '', $card_data['card_number']); //no "+" signs
841
+		$card_data['card_number'] = str_replace(' ', '', $card_data['card_number']); // No spaces
842 842
 	}
843 843
 
844 844
 	// This should validate card numbers at some point too
@@ -854,17 +854,17 @@  discard block
 block discarded – undo
854 854
  */
855 855
 function give_get_purchase_cc_info() {
856 856
 	$cc_info                   = array();
857
-	$cc_info['card_name']      = isset( $_POST['card_name'] ) ? sanitize_text_field( $_POST['card_name'] ) : '';
858
-	$cc_info['card_number']    = isset( $_POST['card_number'] ) ? sanitize_text_field( $_POST['card_number'] ) : '';
859
-	$cc_info['card_cvc']       = isset( $_POST['card_cvc'] ) ? sanitize_text_field( $_POST['card_cvc'] ) : '';
860
-	$cc_info['card_exp_month'] = isset( $_POST['card_exp_month'] ) ? sanitize_text_field( $_POST['card_exp_month'] ) : '';
861
-	$cc_info['card_exp_year']  = isset( $_POST['card_exp_year'] ) ? sanitize_text_field( $_POST['card_exp_year'] ) : '';
862
-	$cc_info['card_address']   = isset( $_POST['card_address'] ) ? sanitize_text_field( $_POST['card_address'] ) : '';
863
-	$cc_info['card_address_2'] = isset( $_POST['card_address_2'] ) ? sanitize_text_field( $_POST['card_address_2'] ) : '';
864
-	$cc_info['card_city']      = isset( $_POST['card_city'] ) ? sanitize_text_field( $_POST['card_city'] ) : '';
865
-	$cc_info['card_state']     = isset( $_POST['card_state'] ) ? sanitize_text_field( $_POST['card_state'] ) : '';
866
-	$cc_info['card_country']   = isset( $_POST['billing_country'] ) ? sanitize_text_field( $_POST['billing_country'] ) : '';
867
-	$cc_info['card_zip']       = isset( $_POST['card_zip'] ) ? sanitize_text_field( $_POST['card_zip'] ) : '';
857
+	$cc_info['card_name']      = isset($_POST['card_name']) ? sanitize_text_field($_POST['card_name']) : '';
858
+	$cc_info['card_number']    = isset($_POST['card_number']) ? sanitize_text_field($_POST['card_number']) : '';
859
+	$cc_info['card_cvc']       = isset($_POST['card_cvc']) ? sanitize_text_field($_POST['card_cvc']) : '';
860
+	$cc_info['card_exp_month'] = isset($_POST['card_exp_month']) ? sanitize_text_field($_POST['card_exp_month']) : '';
861
+	$cc_info['card_exp_year']  = isset($_POST['card_exp_year']) ? sanitize_text_field($_POST['card_exp_year']) : '';
862
+	$cc_info['card_address']   = isset($_POST['card_address']) ? sanitize_text_field($_POST['card_address']) : '';
863
+	$cc_info['card_address_2'] = isset($_POST['card_address_2']) ? sanitize_text_field($_POST['card_address_2']) : '';
864
+	$cc_info['card_city']      = isset($_POST['card_city']) ? sanitize_text_field($_POST['card_city']) : '';
865
+	$cc_info['card_state']     = isset($_POST['card_state']) ? sanitize_text_field($_POST['card_state']) : '';
866
+	$cc_info['card_country']   = isset($_POST['billing_country']) ? sanitize_text_field($_POST['billing_country']) : '';
867
+	$cc_info['card_zip']       = isset($_POST['card_zip']) ? sanitize_text_field($_POST['card_zip']) : '';
868 868
 
869 869
 	// Return cc info
870 870
 	return $cc_info;
@@ -880,14 +880,14 @@  discard block
 block discarded – undo
880 880
  *
881 881
  * @return bool|mixed|void
882 882
  */
883
-function give_purchase_form_validate_cc_zip( $zip = 0, $country_code = '' ) {
883
+function give_purchase_form_validate_cc_zip($zip = 0, $country_code = '') {
884 884
 	$ret = false;
885 885
 
886
-	if ( empty( $zip ) || empty( $country_code ) ) {
886
+	if (empty($zip) || empty($country_code)) {
887 887
 		return $ret;
888 888
 	}
889 889
 
890
-	$country_code = strtoupper( $country_code );
890
+	$country_code = strtoupper($country_code);
891 891
 
892 892
 	$zip_regex = array(
893 893
 		"AD" => "AD\d{3}",
@@ -1047,9 +1047,9 @@  discard block
 block discarded – undo
1047 1047
 		"ZM" => "\d{5}"
1048 1048
 	);
1049 1049
 
1050
-	if ( ! isset ( $zip_regex[ $country_code ] ) || preg_match( "/" . $zip_regex[ $country_code ] . "/i", $zip ) ) {
1050
+	if ( ! isset ($zip_regex[$country_code]) || preg_match("/".$zip_regex[$country_code]."/i", $zip)) {
1051 1051
 		$ret = true;
1052 1052
 	}
1053 1053
 
1054
-	return apply_filters( 'give_is_zip_valid', $ret, $zip, $country_code );
1054
+	return apply_filters('give_is_zip_valid', $ret, $zip, $country_code);
1055 1055
 }
1056 1056
\ No newline at end of file
Please login to merge, or discard this patch.
includes/payments/actions.php 1 patch
Spacing   +53 added lines, -53 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
 
@@ -28,21 +28,21 @@  discard block
 block discarded – undo
28 28
  *
29 29
  * @return void
30 30
  */
31
-function give_complete_purchase( $payment_id, $new_status, $old_status ) {
31
+function give_complete_purchase($payment_id, $new_status, $old_status) {
32 32
 
33 33
 	// Make sure that payments are only completed once
34
-	if ( $old_status == 'publish' || $old_status == 'complete' ) {
34
+	if ($old_status == 'publish' || $old_status == 'complete') {
35 35
 		return;
36 36
 	}
37 37
 
38 38
 	// Make sure the payment completion is only processed when new status is complete
39
-	if ( $new_status != 'publish' && $new_status != 'complete' ) {
39
+	if ($new_status != 'publish' && $new_status != 'complete') {
40 40
 		return;
41 41
 	}
42 42
 	
43
-	$payment = new Give_Payment( $payment_id );
43
+	$payment = new Give_Payment($payment_id);
44 44
 
45
-	$creation_date  = get_post_field( 'post_date', $payment_id, 'raw' );
45
+	$creation_date  = get_post_field('post_date', $payment_id, 'raw');
46 46
 	$payment_meta   = $payment->payment_meta;
47 47
 	$completed_date = $payment->completed_date;
48 48
 	$user_info      = $payment->user_info;
@@ -51,45 +51,45 @@  discard block
 block discarded – undo
51 51
 	$price_id       = $payment->price_id;
52 52
 	$form_id        = $payment->form_id;
53 53
 
54
-	do_action( 'give_pre_complete_purchase', $payment_id );
54
+	do_action('give_pre_complete_purchase', $payment_id);
55 55
 
56 56
 	// Ensure these actions only run once, ever
57
-	if ( empty( $completed_date ) ) {
57
+	if (empty($completed_date)) {
58 58
 
59
-		give_record_sale_in_log( $form_id, $payment_id, $price_id, $creation_date );
60
-		do_action( 'give_complete_form_donation', $form_id, $payment_id, $payment_meta );
59
+		give_record_sale_in_log($form_id, $payment_id, $price_id, $creation_date);
60
+		do_action('give_complete_form_donation', $form_id, $payment_id, $payment_meta);
61 61
 
62 62
 	}
63 63
 
64 64
 	// Increase the earnings for this form ID
65
-	give_increase_earnings( $form_id, $amount );
66
-	give_increase_purchase_count( $form_id );
65
+	give_increase_earnings($form_id, $amount);
66
+	give_increase_purchase_count($form_id);
67 67
 
68 68
 	// Clear the total earnings cache
69
-	delete_transient( 'give_earnings_total' );
69
+	delete_transient('give_earnings_total');
70 70
 	// Clear the This Month earnings (this_monththis_month is NOT a typo)
71
-	delete_transient( md5( 'give_earnings_this_monththis_month' ) );
72
-	delete_transient( md5( 'give_earnings_todaytoday' ) );
71
+	delete_transient(md5('give_earnings_this_monththis_month'));
72
+	delete_transient(md5('give_earnings_todaytoday'));
73 73
 	
74 74
 	// Increase the donor's purchase stats
75
-	$customer = new Give_Customer( $customer_id );
75
+	$customer = new Give_Customer($customer_id);
76 76
 	$customer->increase_purchase_count();
77
-	$customer->increase_value( $amount );
77
+	$customer->increase_value($amount);
78 78
 
79
-	give_increase_total_earnings( $amount );
79
+	give_increase_total_earnings($amount);
80 80
 
81 81
 	// Ensure this action only runs once ever
82
-	if ( empty( $completed_date ) ) {
82
+	if (empty($completed_date)) {
83 83
 
84 84
 		// Save the completed date
85
-		$payment->completed_date = current_time( 'mysql' );
85
+		$payment->completed_date = current_time('mysql');
86 86
 		$payment->save();
87
-		do_action( 'give_complete_purchase', $payment_id );
87
+		do_action('give_complete_purchase', $payment_id);
88 88
 	}
89 89
 
90 90
 }
91 91
 
92
-add_action( 'give_update_payment_status', 'give_complete_purchase', 100, 3 );
92
+add_action('give_update_payment_status', 'give_complete_purchase', 100, 3);
93 93
 
94 94
 
95 95
 /**
@@ -103,19 +103,19 @@  discard block
 block discarded – undo
103 103
  *
104 104
  * @return void
105 105
  */
106
-function give_record_status_change( $payment_id, $new_status, $old_status ) {
106
+function give_record_status_change($payment_id, $new_status, $old_status) {
107 107
 
108 108
 	// Get the list of statuses so that status in the payment note can be translated
109 109
 	$stati      = give_get_payment_statuses();
110
-	$old_status = isset( $stati[ $old_status ] ) ? $stati[ $old_status ] : $old_status;
111
-	$new_status = isset( $stati[ $new_status ] ) ? $stati[ $new_status ] : $new_status;
110
+	$old_status = isset($stati[$old_status]) ? $stati[$old_status] : $old_status;
111
+	$new_status = isset($stati[$new_status]) ? $stati[$new_status] : $new_status;
112 112
 
113
-	$status_change = sprintf( __( 'Status changed from %s to %s'., 'give' ), $old_status, $new_status );
113
+	$status_change = sprintf(__('Status changed from %s to %s'., 'give'), $old_status, $new_status);
114 114
 
115
-	give_insert_payment_note( $payment_id, $status_change );
115
+	give_insert_payment_note($payment_id, $status_change);
116 116
 }
117 117
 
118
-add_action( 'give_update_payment_status', 'give_record_status_change', 100, 3 );
118
+add_action('give_update_payment_status', 'give_record_status_change', 100, 3);
119 119
 
120 120
 
121 121
 /**
@@ -128,17 +128,17 @@  discard block
 block discarded – undo
128 128
  * @param $new_status the status of the payment, probably "publish"
129 129
  * @param $old_status the status of the payment prior to being marked as "complete", probably "pending"
130 130
  */
131
-function give_clear_user_history_cache( $payment_id, $new_status, $old_status ) {
131
+function give_clear_user_history_cache($payment_id, $new_status, $old_status) {
132 132
 
133
-	$payment = new Give_Payment( $payment_id );
133
+	$payment = new Give_Payment($payment_id);
134 134
 
135
-	if ( ! empty( $payment->user_id ) ) {
136
-		delete_transient( 'give_user_' . $payment->user_id . '_purchases' );
135
+	if ( ! empty($payment->user_id)) {
136
+		delete_transient('give_user_'.$payment->user_id.'_purchases');
137 137
 	}
138 138
 
139 139
 }
140 140
 
141
-add_action( 'give_update_payment_status', 'give_clear_user_history_cache', 10, 3 );
141
+add_action('give_update_payment_status', 'give_clear_user_history_cache', 10, 3);
142 142
 
143 143
 /**
144 144
  * Updates all old payments, prior to 1.2, with new
@@ -152,25 +152,25 @@  discard block
 block discarded – undo
152 152
  *
153 153
  * @return void
154 154
  */
155
-function give_update_old_payments_with_totals( $data ) {
156
-	if ( ! wp_verify_nonce( $data['_wpnonce'], 'give_upgrade_payments_nonce' ) ) {
155
+function give_update_old_payments_with_totals($data) {
156
+	if ( ! wp_verify_nonce($data['_wpnonce'], 'give_upgrade_payments_nonce')) {
157 157
 		return;
158 158
 	}
159 159
 
160
-	if ( get_option( 'give_payment_totals_upgraded' ) ) {
160
+	if (get_option('give_payment_totals_upgraded')) {
161 161
 		return;
162 162
 	}
163 163
 
164
-	$payments = give_get_payments( array(
164
+	$payments = give_get_payments(array(
165 165
 		'offset' => 0,
166
-		'number' => - 1,
166
+		'number' => -1,
167 167
 		'mode'   => 'all'
168
-	) );
168
+	));
169 169
 
170
-	if ( $payments ) {
171
-		foreach ( $payments as $payment ) {
170
+	if ($payments) {
171
+		foreach ($payments as $payment) {
172 172
 
173
-			$payment = new Give_Payment( $payment->ID );
173
+			$payment = new Give_Payment($payment->ID);
174 174
 			$meta    = $payment->get_meta();
175 175
 
176 176
 			$payment->total = $meta['amount'];
@@ -179,10 +179,10 @@  discard block
 block discarded – undo
179 179
 		}
180 180
 	}
181 181
 
182
-	add_option( 'give_payment_totals_upgraded', 1 );
182
+	add_option('give_payment_totals_upgraded', 1);
183 183
 }
184 184
 
185
-add_action( 'give_upgrade_payments', 'give_update_old_payments_with_totals' );
185
+add_action('give_upgrade_payments', 'give_update_old_payments_with_totals');
186 186
 
187 187
 /**
188 188
  * Updates week-old+ 'pending' orders to 'abandoned'
@@ -193,21 +193,21 @@  discard block
 block discarded – undo
193 193
 function give_mark_abandoned_donations() {
194 194
 	$args = array(
195 195
 		'status' => 'pending',
196
-		'number' => - 1,
196
+		'number' => -1,
197 197
 		'output' => 'give_payments',
198 198
 	);
199 199
 
200
-	add_filter( 'posts_where', 'give_filter_where_older_than_week' );
200
+	add_filter('posts_where', 'give_filter_where_older_than_week');
201 201
 
202
-	$payments = give_get_payments( $args );
202
+	$payments = give_get_payments($args);
203 203
 
204
-	remove_filter( 'posts_where', 'give_filter_where_older_than_week' );
204
+	remove_filter('posts_where', 'give_filter_where_older_than_week');
205 205
 
206
-	if ( $payments ) {
207
-		foreach ( $payments as $payment ) {
208
-			$gateway = give_get_payment_gateway( $payment );
206
+	if ($payments) {
207
+		foreach ($payments as $payment) {
208
+			$gateway = give_get_payment_gateway($payment);
209 209
 			//Skip offline gateway payments
210
-			if ( $gateway == 'offline' ) {
210
+			if ($gateway == 'offline') {
211 211
 				continue;
212 212
 			}
213 213
 			$payment->status = 'abandoned';
@@ -216,4 +216,4 @@  discard block
 block discarded – undo
216 216
 	}
217 217
 }
218 218
 
219
-add_action( 'give_weekly_scheduled_events', 'give_mark_abandoned_donations' );
220 219
\ No newline at end of file
220
+add_action('give_weekly_scheduled_events', 'give_mark_abandoned_donations');
221 221
\ No newline at end of file
Please login to merge, or discard this patch.
includes/scripts.php 1 patch
Spacing   +138 added lines, -138 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
 
@@ -28,94 +28,94 @@  discard block
 block discarded – undo
28 28
 
29 29
 	global $give_options;
30 30
 
31
-	$js_dir         = GIVE_PLUGIN_URL . 'assets/js/frontend/';
32
-	$js_plugins     = GIVE_PLUGIN_URL . 'assets/js/plugins/';
33
-	$scripts_footer = ( give_get_option( 'scripts_footer' ) == 'on' ) ? true : false;
31
+	$js_dir         = GIVE_PLUGIN_URL.'assets/js/frontend/';
32
+	$js_plugins     = GIVE_PLUGIN_URL.'assets/js/plugins/';
33
+	$scripts_footer = (give_get_option('scripts_footer') == 'on') ? true : false;
34 34
 
35 35
 	// Use minified libraries if SCRIPT_DEBUG is turned off
36
-	$suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
36
+	$suffix = (defined('SCRIPT_DEBUG') && SCRIPT_DEBUG) ? '' : '.min';
37 37
 
38 38
 	//Localize / PHP to AJAX vars
39
-	$localize_give_checkout = apply_filters( 'give_global_script_vars', array(
39
+	$localize_give_checkout = apply_filters('give_global_script_vars', array(
40 40
 		'ajaxurl'             => give_get_ajax_url(),
41
-		'checkout_nonce'      => wp_create_nonce( 'give_checkout_nonce' ),
42
-		'currency_sign'       => give_currency_filter( '' ),
41
+		'checkout_nonce'      => wp_create_nonce('give_checkout_nonce'),
42
+		'currency_sign'       => give_currency_filter(''),
43 43
 		'currency_pos'        => give_get_currency_position(),
44
-		'thousands_separator' => isset( $give_options['thousands_separator'] ) ? $give_options['thousands_separator'] : ',',
45
-		'decimal_separator'   => isset( $give_options['decimal_separator'] ) ? $give_options['decimal_separator'] : '.',
46
-		'no_gateway'          => __( 'Please select a payment method.', 'give' ),
47
-		'bad_minimum'         => __( 'The minimum donation amount for this form is', 'give' ),
48
-		'general_loading'     => __( 'Loading...', 'give' ),
49
-		'purchase_loading'    => __( 'Please Wait...', 'give' ),
50
-		'number_decimals'  => apply_filters( 'give_format_amount_decimals', 2 ),
44
+		'thousands_separator' => isset($give_options['thousands_separator']) ? $give_options['thousands_separator'] : ',',
45
+		'decimal_separator'   => isset($give_options['decimal_separator']) ? $give_options['decimal_separator'] : '.',
46
+		'no_gateway'          => __('Please select a payment method.', 'give'),
47
+		'bad_minimum'         => __('The minimum donation amount for this form is', 'give'),
48
+		'general_loading'     => __('Loading...', 'give'),
49
+		'purchase_loading'    => __('Please Wait...', 'give'),
50
+		'number_decimals'  => apply_filters('give_format_amount_decimals', 2),
51 51
 		'give_version'        => GIVE_VERSION
52
-	) );
53
-	$localize_give_ajax     = apply_filters( 'give_global_ajax_vars', array(
52
+	));
53
+	$localize_give_ajax = apply_filters('give_global_ajax_vars', array(
54 54
 		'ajaxurl'          => give_get_ajax_url(),
55
-		'loading'          => __( 'Loading', 'give' ),
55
+		'loading'          => __('Loading', 'give'),
56 56
 		// General loading message
57
-		'select_option'    => __( 'Please select an option', 'give' ),
57
+		'select_option'    => __('Please select an option', 'give'),
58 58
 		// Variable pricing error with multi-purchase option enabled
59
-		'default_gateway'  => give_get_default_gateway( null ),
60
-		'permalinks'       => get_option( 'permalink_structure' ) ? '1' : '0',
61
-		'number_decimals'  => apply_filters( 'give_format_amount_decimals', 2 )
62
-	) );
59
+		'default_gateway'  => give_get_default_gateway(null),
60
+		'permalinks'       => get_option('permalink_structure') ? '1' : '0',
61
+		'number_decimals'  => apply_filters('give_format_amount_decimals', 2)
62
+	));
63 63
 
64 64
 	//DEBUG is On
65
-	if ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) {
65
+	if (defined('SCRIPT_DEBUG') && SCRIPT_DEBUG) {
66 66
 
67
-		if ( give_is_cc_verify_enabled() ) {
68
-			wp_register_script( 'give-cc-validator', $js_plugins . 'jquery.payment' . $suffix . '.js', array( 'jquery' ), GIVE_VERSION, $scripts_footer );
69
-			wp_enqueue_script( 'give-cc-validator' );
67
+		if (give_is_cc_verify_enabled()) {
68
+			wp_register_script('give-cc-validator', $js_plugins.'jquery.payment'.$suffix.'.js', array('jquery'), GIVE_VERSION, $scripts_footer);
69
+			wp_enqueue_script('give-cc-validator');
70 70
 		}
71 71
 
72
-		wp_register_script( 'give-float-labels', $js_plugins . 'float-labels' . $suffix . '.js', array( 'jquery' ), GIVE_VERSION, $scripts_footer );
73
-		wp_enqueue_script( 'give-float-labels' );
72
+		wp_register_script('give-float-labels', $js_plugins.'float-labels'.$suffix.'.js', array('jquery'), GIVE_VERSION, $scripts_footer);
73
+		wp_enqueue_script('give-float-labels');
74 74
 
75
-		wp_register_script( 'give-blockui', $js_plugins . 'jquery.blockUI' . $suffix . '.js', array( 'jquery' ), GIVE_VERSION, $scripts_footer );
76
-		wp_enqueue_script( 'give-blockui' );
75
+		wp_register_script('give-blockui', $js_plugins.'jquery.blockUI'.$suffix.'.js', array('jquery'), GIVE_VERSION, $scripts_footer);
76
+		wp_enqueue_script('give-blockui');
77 77
 
78
-		wp_register_script( 'give-qtip', $js_plugins . 'jquery.qtip' . $suffix . '.js', array( 'jquery' ), GIVE_VERSION, $scripts_footer );
79
-		wp_enqueue_script( 'give-qtip' );
78
+		wp_register_script('give-qtip', $js_plugins.'jquery.qtip'.$suffix.'.js', array('jquery'), GIVE_VERSION, $scripts_footer);
79
+		wp_enqueue_script('give-qtip');
80 80
 
81
-		wp_register_script( 'give-accounting', $js_plugins . 'accounting' . $suffix . '.js', array( 'jquery' ), GIVE_VERSION, $scripts_footer );
82
-		wp_enqueue_script( 'give-accounting' );
81
+		wp_register_script('give-accounting', $js_plugins.'accounting'.$suffix.'.js', array('jquery'), GIVE_VERSION, $scripts_footer);
82
+		wp_enqueue_script('give-accounting');
83 83
 
84
-		wp_register_script( 'give-magnific', $js_plugins . 'jquery.magnific-popup' . $suffix . '.js', array( 'jquery' ), GIVE_VERSION, $scripts_footer );
85
-		wp_enqueue_script( 'give-magnific' );
84
+		wp_register_script('give-magnific', $js_plugins.'jquery.magnific-popup'.$suffix.'.js', array('jquery'), GIVE_VERSION, $scripts_footer);
85
+		wp_enqueue_script('give-magnific');
86 86
 
87
-		wp_register_script( 'give-checkout-global', $js_dir . 'give-checkout-global' . $suffix . '.js', array( 'jquery' ), GIVE_VERSION, $scripts_footer );
88
-		wp_enqueue_script( 'give-checkout-global' );
87
+		wp_register_script('give-checkout-global', $js_dir.'give-checkout-global'.$suffix.'.js', array('jquery'), GIVE_VERSION, $scripts_footer);
88
+		wp_enqueue_script('give-checkout-global');
89 89
 
90 90
 		//General scripts
91
-		wp_register_script( 'give-scripts', $js_dir . 'give' . $suffix . '.js', array( 'jquery' ), GIVE_VERSION, $scripts_footer );
92
-		wp_enqueue_script( 'give-scripts' );
91
+		wp_register_script('give-scripts', $js_dir.'give'.$suffix.'.js', array('jquery'), GIVE_VERSION, $scripts_footer);
92
+		wp_enqueue_script('give-scripts');
93 93
 
94 94
 		// Load AJAX scripts, if enabled
95
-		wp_register_script( 'give-ajax', $js_dir . 'give-ajax' . $suffix . '.js', array( 'jquery' ), GIVE_VERSION, $scripts_footer );
96
-		wp_enqueue_script( 'give-ajax' );
95
+		wp_register_script('give-ajax', $js_dir.'give-ajax'.$suffix.'.js', array('jquery'), GIVE_VERSION, $scripts_footer);
96
+		wp_enqueue_script('give-ajax');
97 97
 
98 98
 		//Localize / Pass AJAX vars from PHP
99
-		wp_localize_script( 'give-checkout-global', 'give_global_vars', $localize_give_checkout );
100
-		wp_localize_script( 'give-ajax', 'give_scripts', $localize_give_ajax );
99
+		wp_localize_script('give-checkout-global', 'give_global_vars', $localize_give_checkout);
100
+		wp_localize_script('give-ajax', 'give_scripts', $localize_give_ajax);
101 101
 
102 102
 
103 103
 	} else {
104 104
 
105 105
 		//DEBUG is OFF (one JS file to rule them all!)
106
-		wp_register_script( 'give', $js_dir . 'give.all.min.js', array( 'jquery' ), GIVE_VERSION, $scripts_footer );
107
-		wp_enqueue_script( 'give' );
106
+		wp_register_script('give', $js_dir.'give.all.min.js', array('jquery'), GIVE_VERSION, $scripts_footer);
107
+		wp_enqueue_script('give');
108 108
 
109 109
 		//Localize / Pass AJAX vars from PHP
110
-		wp_localize_script( 'give', 'give_global_vars', $localize_give_checkout );
111
-		wp_localize_script( 'give', 'give_scripts', $localize_give_ajax );
110
+		wp_localize_script('give', 'give_global_vars', $localize_give_checkout);
111
+		wp_localize_script('give', 'give_scripts', $localize_give_ajax);
112 112
 
113 113
 	}
114 114
 
115 115
 
116 116
 }
117 117
 
118
-add_action( 'wp_enqueue_scripts', 'give_load_scripts' );
118
+add_action('wp_enqueue_scripts', 'give_load_scripts');
119 119
 
120 120
 /**
121 121
  * Register Styles
@@ -127,47 +127,47 @@  discard block
 block discarded – undo
127 127
  */
128 128
 function give_register_styles() {
129 129
 
130
-	if ( give_get_option( 'disable_css', false ) ) {
130
+	if (give_get_option('disable_css', false)) {
131 131
 		return;
132 132
 	}
133 133
 
134 134
 	// Use minified libraries if SCRIPT_DEBUG is turned off
135
-	$suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
135
+	$suffix = (defined('SCRIPT_DEBUG') && SCRIPT_DEBUG) ? '' : '.min';
136 136
 
137
-	$file          = 'give' . $suffix . '.css';
137
+	$file          = 'give'.$suffix.'.css';
138 138
 	$templates_dir = give_get_theme_template_dir_name();
139 139
 
140
-	$child_theme_style_sheet    = trailingslashit( get_stylesheet_directory() ) . $templates_dir . $file;
141
-	$child_theme_style_sheet_2  = trailingslashit( get_stylesheet_directory() ) . $templates_dir . 'give.css';
142
-	$parent_theme_style_sheet   = trailingslashit( get_template_directory() ) . $templates_dir . $file;
143
-	$parent_theme_style_sheet_2 = trailingslashit( get_template_directory() ) . $templates_dir . 'give.css';
144
-	$give_plugin_style_sheet    = trailingslashit( give_get_templates_dir() ) . $file;
140
+	$child_theme_style_sheet    = trailingslashit(get_stylesheet_directory()).$templates_dir.$file;
141
+	$child_theme_style_sheet_2  = trailingslashit(get_stylesheet_directory()).$templates_dir.'give.css';
142
+	$parent_theme_style_sheet   = trailingslashit(get_template_directory()).$templates_dir.$file;
143
+	$parent_theme_style_sheet_2 = trailingslashit(get_template_directory()).$templates_dir.'give.css';
144
+	$give_plugin_style_sheet    = trailingslashit(give_get_templates_dir()).$file;
145 145
 
146 146
 	// Look in the child theme directory first, followed by the parent theme, followed by the Give core templates directory
147 147
 	// Also look for the min version first, followed by non minified version, even if SCRIPT_DEBUG is not enabled.
148 148
 	// This allows users to copy just give.css to their theme
149
-	if ( file_exists( $child_theme_style_sheet ) || ( ! empty( $suffix ) && ( $nonmin = file_exists( $child_theme_style_sheet_2 ) ) ) ) {
150
-		if ( ! empty( $nonmin ) ) {
151
-			$url = trailingslashit( get_stylesheet_directory_uri() ) . $templates_dir . 'give.css';
149
+	if (file_exists($child_theme_style_sheet) || ( ! empty($suffix) && ($nonmin = file_exists($child_theme_style_sheet_2)))) {
150
+		if ( ! empty($nonmin)) {
151
+			$url = trailingslashit(get_stylesheet_directory_uri()).$templates_dir.'give.css';
152 152
 		} else {
153
-			$url = trailingslashit( get_stylesheet_directory_uri() ) . $templates_dir . $file;
153
+			$url = trailingslashit(get_stylesheet_directory_uri()).$templates_dir.$file;
154 154
 		}
155
-	} elseif ( file_exists( $parent_theme_style_sheet ) || ( ! empty( $suffix ) && ( $nonmin = file_exists( $parent_theme_style_sheet_2 ) ) ) ) {
156
-		if ( ! empty( $nonmin ) ) {
157
-			$url = trailingslashit( get_template_directory_uri() ) . $templates_dir . 'give.css';
155
+	} elseif (file_exists($parent_theme_style_sheet) || ( ! empty($suffix) && ($nonmin = file_exists($parent_theme_style_sheet_2)))) {
156
+		if ( ! empty($nonmin)) {
157
+			$url = trailingslashit(get_template_directory_uri()).$templates_dir.'give.css';
158 158
 		} else {
159
-			$url = trailingslashit( get_template_directory_uri() ) . $templates_dir . $file;
159
+			$url = trailingslashit(get_template_directory_uri()).$templates_dir.$file;
160 160
 		}
161
-	} elseif ( file_exists( $give_plugin_style_sheet ) || file_exists( $give_plugin_style_sheet ) ) {
162
-		$url = trailingslashit( give_get_templates_url() ) . $file;
161
+	} elseif (file_exists($give_plugin_style_sheet) || file_exists($give_plugin_style_sheet)) {
162
+		$url = trailingslashit(give_get_templates_url()).$file;
163 163
 	}
164 164
 
165
-	wp_register_style( 'give-styles', $url, array(), GIVE_VERSION, 'all' );
166
-	wp_enqueue_style( 'give-styles' );
165
+	wp_register_style('give-styles', $url, array(), GIVE_VERSION, 'all');
166
+	wp_enqueue_style('give-styles');
167 167
 
168 168
 }
169 169
 
170
-add_action( 'wp_enqueue_scripts', 'give_register_styles' );
170
+add_action('wp_enqueue_scripts', 'give_register_styles');
171 171
 
172 172
 /**
173 173
  * Load Admin Scripts
@@ -181,103 +181,103 @@  discard block
 block discarded – undo
181 181
  *
182 182
  * @return void
183 183
  */
184
-function give_load_admin_scripts( $hook ) {
184
+function give_load_admin_scripts($hook) {
185 185
 
186 186
 	global $wp_version, $post, $post_type;
187 187
 
188 188
 	//Directories of assets
189
-	$js_dir     = GIVE_PLUGIN_URL . 'assets/js/admin/';
190
-	$js_plugins = GIVE_PLUGIN_URL . 'assets/js/plugins/';
191
-	$css_dir    = GIVE_PLUGIN_URL . 'assets/css/';
189
+	$js_dir     = GIVE_PLUGIN_URL.'assets/js/admin/';
190
+	$js_plugins = GIVE_PLUGIN_URL.'assets/js/plugins/';
191
+	$css_dir    = GIVE_PLUGIN_URL.'assets/css/';
192 192
 
193 193
 	// Use minified libraries if SCRIPT_DEBUG is turned off
194
-	$suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
194
+	$suffix = (defined('SCRIPT_DEBUG') && SCRIPT_DEBUG) ? '' : '.min';
195 195
 
196 196
 	//Global Admin:
197
-	wp_register_style( 'give-admin-bar-notification', $css_dir . 'adminbar-style.css' );
198
-	wp_enqueue_style( 'give-admin-bar-notification' );
197
+	wp_register_style('give-admin-bar-notification', $css_dir.'adminbar-style.css');
198
+	wp_enqueue_style('give-admin-bar-notification');
199 199
 
200 200
 	//Give Admin Only:
201
-	if ( ! apply_filters( 'give_load_admin_scripts', give_is_admin_page(), $hook ) ) {
201
+	if ( ! apply_filters('give_load_admin_scripts', give_is_admin_page(), $hook)) {
202 202
 		return;
203 203
 	}
204 204
 
205 205
 	//CSS
206
-	wp_register_style( 'jquery-ui-css', $css_dir . 'jquery-ui-fresh' . $suffix . '.css' );
207
-	wp_enqueue_style( 'jquery-ui-css' );
208
-	wp_register_style( 'give-admin', $css_dir . 'give-admin' . $suffix . '.css', GIVE_VERSION );
209
-	wp_enqueue_style( 'give-admin' );
210
-	wp_register_style( 'jquery-chosen', $css_dir . 'chosen' . $suffix . '.css', array(), GIVE_VERSION );
211
-	wp_enqueue_style( 'jquery-chosen' );
212
-	wp_enqueue_style( 'thickbox' );
206
+	wp_register_style('jquery-ui-css', $css_dir.'jquery-ui-fresh'.$suffix.'.css');
207
+	wp_enqueue_style('jquery-ui-css');
208
+	wp_register_style('give-admin', $css_dir.'give-admin'.$suffix.'.css', GIVE_VERSION);
209
+	wp_enqueue_style('give-admin');
210
+	wp_register_style('jquery-chosen', $css_dir.'chosen'.$suffix.'.css', array(), GIVE_VERSION);
211
+	wp_enqueue_style('jquery-chosen');
212
+	wp_enqueue_style('thickbox');
213 213
 
214 214
 	//JS
215
-	wp_register_script( 'jquery-chosen', $js_plugins . 'chosen.jquery' . $suffix . '.js', array( 'jquery' ), GIVE_VERSION );
216
-	wp_enqueue_script( 'jquery-chosen' );
215
+	wp_register_script('jquery-chosen', $js_plugins.'chosen.jquery'.$suffix.'.js', array('jquery'), GIVE_VERSION);
216
+	wp_enqueue_script('jquery-chosen');
217 217
 
218
-	wp_register_script( 'give-admin-scripts', $js_dir . 'admin-scripts' . $suffix . '.js', array( 'jquery' ), GIVE_VERSION, false );
219
-	wp_enqueue_script( 'give-admin-scripts' );
218
+	wp_register_script('give-admin-scripts', $js_dir.'admin-scripts'.$suffix.'.js', array('jquery'), GIVE_VERSION, false);
219
+	wp_enqueue_script('give-admin-scripts');
220 220
 
221
-	wp_register_script( 'jquery-flot', $js_plugins . 'jquery.flot' . $suffix . '.js' );
222
-	wp_enqueue_script( 'jquery-flot' );
221
+	wp_register_script('jquery-flot', $js_plugins.'jquery.flot'.$suffix.'.js');
222
+	wp_enqueue_script('jquery-flot');
223 223
 
224
-	wp_register_script( 'give-qtip', $js_plugins . 'jquery.qtip' . $suffix . '.js', array( 'jquery' ), GIVE_VERSION, false );
225
-	wp_enqueue_script( 'give-qtip' );
224
+	wp_register_script('give-qtip', $js_plugins.'jquery.qtip'.$suffix.'.js', array('jquery'), GIVE_VERSION, false);
225
+	wp_enqueue_script('give-qtip');
226 226
 
227
-	wp_enqueue_script( 'jquery-ui-datepicker' );
228
-	wp_enqueue_script( 'thickbox' );
227
+	wp_enqueue_script('jquery-ui-datepicker');
228
+	wp_enqueue_script('thickbox');
229 229
 
230 230
 	//Forms CPT Script
231
-	if ( $post_type === 'give_forms' ) {
232
-		wp_register_script( 'give-admin-forms-scripts', $js_dir . 'admin-forms' . $suffix . '.js', array( 'jquery' ), GIVE_VERSION, false );
233
-		wp_enqueue_script( 'give-admin-forms-scripts' );
231
+	if ($post_type === 'give_forms') {
232
+		wp_register_script('give-admin-forms-scripts', $js_dir.'admin-forms'.$suffix.'.js', array('jquery'), GIVE_VERSION, false);
233
+		wp_enqueue_script('give-admin-forms-scripts');
234 234
 	}
235 235
 
236 236
 	//Settings Scripts
237
-	if (isset($_GET['page']) && $_GET['page'] == 'give-settings'  ) {
237
+	if (isset($_GET['page']) && $_GET['page'] == 'give-settings') {
238 238
 		wp_enqueue_script('jquery-ui-sortable');
239
-		wp_register_script( 'give-admin-settings-scripts', $js_dir . 'admin-settings' . $suffix . '.js', array( 'jquery' ), GIVE_VERSION, false );
240
-		wp_enqueue_script( 'give-admin-settings-scripts' );
239
+		wp_register_script('give-admin-settings-scripts', $js_dir.'admin-settings'.$suffix.'.js', array('jquery'), GIVE_VERSION, false);
240
+		wp_enqueue_script('give-admin-settings-scripts');
241 241
 	}
242 242
 
243 243
 	//Localize strings & variables for JS
244
-	wp_localize_script( 'give-admin-scripts', 'give_vars', array(
245
-		'post_id'                 => isset( $post->ID ) ? $post->ID : null,
244
+	wp_localize_script('give-admin-scripts', 'give_vars', array(
245
+		'post_id'                 => isset($post->ID) ? $post->ID : null,
246 246
 		'give_version'            => GIVE_VERSION,
247
-		'quick_edit_warning'      => __( 'Sorry, not available for variable priced forms.', 'give' ),
248
-		'delete_payment'          => __( 'Are you sure you wish to delete this payment?', 'give' ),
249
-		'delete_payment_note'     => __( 'Are you sure you wish to delete this note?', 'give' ),
250
-		'revoke_api_key'          => __( 'Are you sure you wish to revoke this API key?', 'give' ),
251
-		'regenerate_api_key'      => __( 'Are you sure you wish to regenerate this API key?', 'give' ),
252
-		'resend_receipt'          => __( 'Are you sure you wish to resend the donation receipt?', 'give' ),
253
-		'copy_download_link_text' => __( 'Copy these links to your clipboard and give them to your donor.', 'give' ),
254
-		'delete_payment_download' => sprintf( __( 'Are you sure you wish to delete this %s?', 'give' ), give_get_forms_label_singular() ),
255
-		'one_price_min'           => __( 'You must have at least one price.', 'give' ),
256
-		'one_file_min'            => __( 'You must have at least one file.', 'give' ),
257
-		'one_field_min'           => __( 'You must have at least one field.', 'give' ),
258
-		'one_option'              => sprintf( __( 'Choose a %s', 'give' ), give_get_forms_label_singular() ),
259
-		'one_or_more_option'      => sprintf( __( 'Choose one or more %s', 'give' ), give_get_forms_label_plural() ),
260
-		'numeric_item_price'      => __( 'Item price must be numeric.', 'give' ),
261
-		'numeric_quantity'        => __( 'Quantity must be numeric.', 'give' ),
262
-		'currency_sign'           => give_currency_filter( '' ),
263
-		'currency_pos'            => isset( $give_options['currency_position'] ) ? $give_options['currency_position'] : 'before',
247
+		'quick_edit_warning'      => __('Sorry, not available for variable priced forms.', 'give'),
248
+		'delete_payment'          => __('Are you sure you wish to delete this payment?', 'give'),
249
+		'delete_payment_note'     => __('Are you sure you wish to delete this note?', 'give'),
250
+		'revoke_api_key'          => __('Are you sure you wish to revoke this API key?', 'give'),
251
+		'regenerate_api_key'      => __('Are you sure you wish to regenerate this API key?', 'give'),
252
+		'resend_receipt'          => __('Are you sure you wish to resend the donation receipt?', 'give'),
253
+		'copy_download_link_text' => __('Copy these links to your clipboard and give them to your donor.', 'give'),
254
+		'delete_payment_download' => sprintf(__('Are you sure you wish to delete this %s?', 'give'), give_get_forms_label_singular()),
255
+		'one_price_min'           => __('You must have at least one price.', 'give'),
256
+		'one_file_min'            => __('You must have at least one file.', 'give'),
257
+		'one_field_min'           => __('You must have at least one field.', 'give'),
258
+		'one_option'              => sprintf(__('Choose a %s', 'give'), give_get_forms_label_singular()),
259
+		'one_or_more_option'      => sprintf(__('Choose one or more %s', 'give'), give_get_forms_label_plural()),
260
+		'numeric_item_price'      => __('Item price must be numeric.', 'give'),
261
+		'numeric_quantity'        => __('Quantity must be numeric.', 'give'),
262
+		'currency_sign'           => give_currency_filter(''),
263
+		'currency_pos'            => isset($give_options['currency_position']) ? $give_options['currency_position'] : 'before',
264 264
 		'currency_decimals'       => give_currency_decimal_filter(),
265
-		'new_media_ui'            => apply_filters( 'give_use_35_media_ui', 1 ),
266
-		'remove_text'             => __( 'Remove', 'give' ),
267
-		'type_to_search'          => sprintf( __( 'Type to search %s', 'give' ), give_get_forms_label_plural() ),
268
-		'batch_export_no_class'   => __( 'You must choose a method.', 'give' ),
269
-		'batch_export_no_reqs'    => __( 'Required fields not completed.', 'give' ),
270
-		'reset_stats_warn'        => __( 'Are you sure you want to reset Give? This process is <strong><em>not reversible</em></strong> and will delete all data regardless of test or live mode. Please be sure you have a recent backup before proceeding.', 'give' ),
271
-	) );
272
-
273
-	if ( function_exists( 'wp_enqueue_media' ) && version_compare( $wp_version, '3.5', '>=' ) ) {
265
+		'new_media_ui'            => apply_filters('give_use_35_media_ui', 1),
266
+		'remove_text'             => __('Remove', 'give'),
267
+		'type_to_search'          => sprintf(__('Type to search %s', 'give'), give_get_forms_label_plural()),
268
+		'batch_export_no_class'   => __('You must choose a method.', 'give'),
269
+		'batch_export_no_reqs'    => __('Required fields not completed.', 'give'),
270
+		'reset_stats_warn'        => __('Are you sure you want to reset Give? This process is <strong><em>not reversible</em></strong> and will delete all data regardless of test or live mode. Please be sure you have a recent backup before proceeding.', 'give'),
271
+	));
272
+
273
+	if (function_exists('wp_enqueue_media') && version_compare($wp_version, '3.5', '>=')) {
274 274
 		//call for new media manager
275 275
 		wp_enqueue_media();
276 276
 	}
277 277
 
278 278
 }
279 279
 
280
-add_action( 'admin_enqueue_scripts', 'give_load_admin_scripts', 100 );
280
+add_action('admin_enqueue_scripts', 'give_load_admin_scripts', 100);
281 281
 
282 282
 /**
283 283
  * Admin Give Icon
@@ -294,14 +294,14 @@  discard block
 block discarded – undo
294 294
 	?>
295 295
 	<style type="text/css" media="screen">
296 296
 
297
-		<?php if( version_compare( $wp_version, '3.8-RC', '>=' ) || version_compare( $wp_version, '3.8', '>=' ) ) { ?>
297
+		<?php if (version_compare($wp_version, '3.8-RC', '>=') || version_compare($wp_version, '3.8', '>=')) { ?>
298 298
 		@font-face {
299 299
 			font-family: 'give-icomoon';
300
-			src: url('<?php echo GIVE_PLUGIN_URL . '/assets/fonts/icomoon.eot?-ngjl88'; ?>');
301
-			src: url('<?php echo GIVE_PLUGIN_URL . '/assets/fonts/icomoon.eot?#iefix-ngjl88'?>') format('embedded-opentype'),
302
-			url('<?php echo GIVE_PLUGIN_URL . '/assets/fonts/icomoon.woff?-ngjl88'; ?>') format('woff'),
303
-			url('<?php echo GIVE_PLUGIN_URL . '/assets/fonts/icomoon.ttf?-ngjl88'; ?>') format('truetype'),
304
-			url('<?php echo GIVE_PLUGIN_URL . '/assets/fonts/icomoon.svg?-ngjl88#icomoon'; ?>') format('svg');
300
+			src: url('<?php echo GIVE_PLUGIN_URL.'/assets/fonts/icomoon.eot?-ngjl88'; ?>');
301
+			src: url('<?php echo GIVE_PLUGIN_URL.'/assets/fonts/icomoon.eot?#iefix-ngjl88'?>') format('embedded-opentype'),
302
+			url('<?php echo GIVE_PLUGIN_URL.'/assets/fonts/icomoon.woff?-ngjl88'; ?>') format('woff'),
303
+			url('<?php echo GIVE_PLUGIN_URL.'/assets/fonts/icomoon.ttf?-ngjl88'; ?>') format('truetype'),
304
+			url('<?php echo GIVE_PLUGIN_URL.'/assets/fonts/icomoon.svg?-ngjl88#icomoon'; ?>') format('svg');
305 305
 			font-weight: normal;
306 306
 			font-style: normal;
307 307
 		}
@@ -320,4 +320,4 @@  discard block
 block discarded – undo
320 320
 	<?php
321 321
 }
322 322
 
323
-add_action( 'admin_head', 'give_admin_icon' );
323
+add_action('admin_head', 'give_admin_icon');
Please login to merge, or discard this patch.
includes/gateways/paypal-standard.php 1 patch
Spacing   +163 added lines, -163 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
  * @since       1.0
10 10
  */
11 11
 
12
-if ( ! defined( 'ABSPATH' ) ) {
12
+if ( ! defined('ABSPATH')) {
13 13
 	exit;
14 14
 }
15 15
 
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
21 21
  * @access private
22 22
  * @since  1.0
23 23
  */
24
-add_action( 'give_paypal_cc_form', '__return_false' );
24
+add_action('give_paypal_cc_form', '__return_false');
25 25
 
26 26
 /**
27 27
  * Process PayPal Purchase
@@ -32,13 +32,13 @@  discard block
 block discarded – undo
32 32
  *
33 33
  * @return void
34 34
  */
35
-function give_process_paypal_purchase( $purchase_data ) {
35
+function give_process_paypal_purchase($purchase_data) {
36 36
 
37
-	if ( ! wp_verify_nonce( $purchase_data['gateway_nonce'], 'give-gateway' ) ) {
38
-		wp_die( __( 'Nonce verification has failed.', 'give' ), __( 'Error', 'give' ), array( 'response' => 403 ) );
37
+	if ( ! wp_verify_nonce($purchase_data['gateway_nonce'], 'give-gateway')) {
38
+		wp_die(__('Nonce verification has failed.', 'give'), __('Error', 'give'), array('response' => 403));
39 39
 	}
40 40
 
41
-	$form_id = intval( $purchase_data['post_data']['give-form-id'] );
41
+	$form_id = intval($purchase_data['post_data']['give-form-id']);
42 42
 	$price_id = isset($purchase_data['post_data']['give-price-id']) ? $purchase_data['post_data']['give-price-id'] : '';
43 43
 	
44 44
 	// Collect payment data
@@ -57,59 +57,59 @@  discard block
 block discarded – undo
57 57
 	);
58 58
 
59 59
 	// Record the pending payment
60
-	$payment = give_insert_payment( $payment_data );
60
+	$payment = give_insert_payment($payment_data);
61 61
 
62 62
 	// Check payment
63
-	if ( ! $payment ) {
63
+	if ( ! $payment) {
64 64
 		// Record the error
65
-		give_record_gateway_error( __( 'Payment Error', 'give' ), sprintf( __( 'Payment creation failed before sending buyer to PayPal. Payment data: %s', 'give' ), json_encode( $payment_data ) ), $payment );
65
+		give_record_gateway_error(__('Payment Error', 'give'), sprintf(__('Payment creation failed before sending buyer to PayPal. Payment data: %s', 'give'), json_encode($payment_data)), $payment);
66 66
 		// Problems? send back
67
-		give_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['give-gateway'] );
67
+		give_send_back_to_checkout('?payment-mode='.$purchase_data['post_data']['give-gateway']);
68 68
 	} else {
69 69
 		// Only send to PayPal if the pending payment is created successfully
70
-		$listener_url = add_query_arg( 'give-listener', 'IPN', home_url( 'index.php' ) );
70
+		$listener_url = add_query_arg('give-listener', 'IPN', home_url('index.php'));
71 71
 
72 72
 		// Get the success url
73
-		$return_url = add_query_arg( array(
73
+		$return_url = add_query_arg(array(
74 74
 			'payment-confirmation' => 'paypal',
75 75
 			'payment-id'           => $payment
76 76
 
77
-		), get_permalink( give_get_option( 'success_page' ) ) );
77
+		), get_permalink(give_get_option('success_page')));
78 78
 
79 79
 		// Get the PayPal redirect uri
80
-		$paypal_redirect = trailingslashit( give_get_paypal_redirect() ) . '?';
80
+		$paypal_redirect = trailingslashit(give_get_paypal_redirect()).'?';
81 81
 
82 82
 		//Item name - pass level name if variable priced
83 83
 		$item_name = $purchase_data['post_data']['give-form-title'];
84 84
 
85 85
 		//Verify has variable prices
86
-		if ( give_has_variable_prices( $form_id ) && isset( $purchase_data['post_data']['give-price-id'] ) ) {
86
+		if (give_has_variable_prices($form_id) && isset($purchase_data['post_data']['give-price-id'])) {
87 87
 
88
-			$item_price_level_text = give_get_price_option_name( $form_id, $purchase_data['post_data']['give-price-id'] );
88
+			$item_price_level_text = give_get_price_option_name($form_id, $purchase_data['post_data']['give-price-id']);
89 89
 
90
-			$price_level_amount = give_get_price_option_amount( $form_id, $purchase_data['post_data']['give-price-id'] );
90
+			$price_level_amount = give_get_price_option_amount($form_id, $purchase_data['post_data']['give-price-id']);
91 91
 
92 92
 			//Donation given doesn't match selected level (must be a custom amount)
93
-			if ( $price_level_amount != give_sanitize_amount( $purchase_data['price'] ) ) {
94
-				$custom_amount_text = get_post_meta( $form_id, '_give_custom_amount_text', true );
93
+			if ($price_level_amount != give_sanitize_amount($purchase_data['price'])) {
94
+				$custom_amount_text = get_post_meta($form_id, '_give_custom_amount_text', true);
95 95
 				//user custom amount text if any, fallback to default if not
96
-				$item_name .= ' - ' . ( ! empty( $custom_amount_text ) ? $custom_amount_text : __( 'Custom Amount', 'give' ) );
96
+				$item_name .= ' - '.( ! empty($custom_amount_text) ? $custom_amount_text : __('Custom Amount', 'give'));
97 97
 
98 98
 			} //Is there any donation level text?
99
-			elseif ( ! empty( $item_price_level_text ) ) {
100
-				$item_name .= ' - ' . $item_price_level_text;
99
+			elseif ( ! empty($item_price_level_text)) {
100
+				$item_name .= ' - '.$item_price_level_text;
101 101
 			}
102 102
 
103 103
 		} //Single donation: Custom Amount
104
-		elseif ( give_get_form_price( $form_id ) !== give_sanitize_amount( $purchase_data['price'] ) ) {
105
-			$custom_amount_text = get_post_meta( $form_id, '_give_custom_amount_text', true );
104
+		elseif (give_get_form_price($form_id) !== give_sanitize_amount($purchase_data['price'])) {
105
+			$custom_amount_text = get_post_meta($form_id, '_give_custom_amount_text', true);
106 106
 			//user custom amount text if any, fallback to default if not
107
-			$item_name .= ' - ' . ( ! empty( $custom_amount_text ) ? $custom_amount_text : __( 'Custom Amount', 'give' ) );
107
+			$item_name .= ' - '.( ! empty($custom_amount_text) ? $custom_amount_text : __('Custom Amount', 'give'));
108 108
 		}
109 109
 
110 110
 		// Setup PayPal arguments
111 111
 		$paypal_args = array(
112
-			'business'      => give_get_option( 'paypal_email', false ),
112
+			'business'      => give_get_option('paypal_email', false),
113 113
 			'email'         => $purchase_data['user_email'],
114 114
 			'invoice'       => $purchase_data['purchase_key'],
115 115
 			'amount'        => $purchase_data['price'],
@@ -120,25 +120,25 @@  discard block
 block discarded – undo
120 120
 			'shipping'      => '0',
121 121
 			'no_note'       => '1',
122 122
 			'currency_code' => give_get_currency(),
123
-			'charset'       => get_bloginfo( 'charset' ),
123
+			'charset'       => get_bloginfo('charset'),
124 124
 			'custom'        => $payment,
125 125
 			'rm'            => '2',
126 126
 			'return'        => $return_url,
127
-			'cancel_return' => give_get_failed_transaction_uri( '?payment-id=' . $payment ),
127
+			'cancel_return' => give_get_failed_transaction_uri('?payment-id='.$payment),
128 128
 			'notify_url'    => $listener_url,
129 129
 			'page_style'    => give_get_paypal_page_style(),
130
-			'cbt'           => get_bloginfo( 'name' ),
130
+			'cbt'           => get_bloginfo('name'),
131 131
 			'bn'            => 'givewp_SP'
132 132
 		);
133 133
 
134
-		if ( ! empty( $purchase_data['user_info']['address'] ) ) {
134
+		if ( ! empty($purchase_data['user_info']['address'])) {
135 135
 			$paypal_args['address1'] = $purchase_data['user_info']['address']['line1'];
136 136
 			$paypal_args['address2'] = $purchase_data['user_info']['address']['line2'];
137 137
 			$paypal_args['city']     = $purchase_data['user_info']['address']['city'];
138 138
 			$paypal_args['country']  = $purchase_data['user_info']['address']['country'];
139 139
 		}
140 140
 
141
-		if ( give_get_option( 'paypal_button_type' ) === 'standard' ) {
141
+		if (give_get_option('paypal_button_type') === 'standard') {
142 142
 			$paypal_extra_args = array(
143 143
 				'cmd' => '_xclick',
144 144
 			);
@@ -148,23 +148,23 @@  discard block
 block discarded – undo
148 148
 			);
149 149
 		}
150 150
 
151
-		$paypal_args = array_merge( $paypal_extra_args, $paypal_args );
152
-		$paypal_args = apply_filters( 'give_paypal_redirect_args', $paypal_args, $purchase_data );
151
+		$paypal_args = array_merge($paypal_extra_args, $paypal_args);
152
+		$paypal_args = apply_filters('give_paypal_redirect_args', $paypal_args, $purchase_data);
153 153
 
154 154
 		// Build query
155
-		$paypal_redirect .= http_build_query( $paypal_args );
155
+		$paypal_redirect .= http_build_query($paypal_args);
156 156
 
157 157
 		// Fix for some sites that encode the entities
158
-		$paypal_redirect = str_replace( '&amp;', '&', $paypal_redirect );
158
+		$paypal_redirect = str_replace('&amp;', '&', $paypal_redirect);
159 159
 
160 160
 		// Redirect to PayPal
161
-		wp_redirect( $paypal_redirect );
161
+		wp_redirect($paypal_redirect);
162 162
 		exit;
163 163
 	}
164 164
 
165 165
 }
166 166
 
167
-add_action( 'give_gateway_paypal', 'give_process_paypal_purchase' );
167
+add_action('give_gateway_paypal', 'give_process_paypal_purchase');
168 168
 
169 169
 /**
170 170
  * Listens for a PayPal IPN requests and then sends to the processing function
@@ -174,12 +174,12 @@  discard block
 block discarded – undo
174 174
  */
175 175
 function give_listen_for_paypal_ipn() {
176 176
 	// Regular PayPal IPN
177
-	if ( isset( $_GET['give-listener'] ) && $_GET['give-listener'] == 'IPN' ) {
178
-		do_action( 'give_verify_paypal_ipn' );
177
+	if (isset($_GET['give-listener']) && $_GET['give-listener'] == 'IPN') {
178
+		do_action('give_verify_paypal_ipn');
179 179
 	}
180 180
 }
181 181
 
182
-add_action( 'init', 'give_listen_for_paypal_ipn' );
182
+add_action('init', 'give_listen_for_paypal_ipn');
183 183
 
184 184
 /**
185 185
  * Process PayPal IPN
@@ -190,7 +190,7 @@  discard block
 block discarded – undo
190 190
 function give_process_paypal_ipn() {
191 191
 
192 192
 	// Check the request method is POST
193
-	if ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] != 'POST' ) {
193
+	if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] != 'POST') {
194 194
 		return;
195 195
 	}
196 196
 
@@ -198,11 +198,11 @@  discard block
 block discarded – undo
198 198
 	$post_data = '';
199 199
 
200 200
 	// Fallback just in case post_max_size is lower than needed
201
-	if ( ini_get( 'allow_url_fopen' ) ) {
202
-		$post_data = file_get_contents( 'php://input' );
201
+	if (ini_get('allow_url_fopen')) {
202
+		$post_data = file_get_contents('php://input');
203 203
 	} else {
204 204
 		// If allow_url_fopen is not enabled, then make sure that post_max_size is large enough
205
-		ini_set( 'post_max_size', '12M' );
205
+		ini_set('post_max_size', '12M');
206 206
 	}
207 207
 	// Start the encoded data collection with notification command
208 208
 	$encoded_data = 'cmd=_notify-validate';
@@ -211,40 +211,40 @@  discard block
 block discarded – undo
211 211
 	$arg_separator = give_get_php_arg_separator_output();
212 212
 
213 213
 	// Verify there is a post_data
214
-	if ( $post_data || strlen( $post_data ) > 0 ) {
214
+	if ($post_data || strlen($post_data) > 0) {
215 215
 		// Append the data
216
-		$encoded_data .= $arg_separator . $post_data;
216
+		$encoded_data .= $arg_separator.$post_data;
217 217
 	} else {
218 218
 		// Check if POST is empty
219
-		if ( empty( $_POST ) ) {
219
+		if (empty($_POST)) {
220 220
 			// Nothing to do
221 221
 			return;
222 222
 		} else {
223 223
 			// Loop through each POST
224
-			foreach ( $_POST as $key => $value ) {
224
+			foreach ($_POST as $key => $value) {
225 225
 				// Encode the value and append the data
226
-				$encoded_data .= $arg_separator . "$key=" . urlencode( $value );
226
+				$encoded_data .= $arg_separator."$key=".urlencode($value);
227 227
 			}
228 228
 		}
229 229
 	}
230 230
 
231 231
 	// Convert collected post data to an array
232
-	parse_str( $encoded_data, $encoded_data_array );
232
+	parse_str($encoded_data, $encoded_data_array);
233 233
 
234
-	foreach ( $encoded_data_array as $key => $value ) {
234
+	foreach ($encoded_data_array as $key => $value) {
235 235
 
236
-		if ( false !== strpos( $key, 'amp;' ) ) {
237
-			$new_key = str_replace( '&amp;', '&', $key );
238
-			$new_key = str_replace( 'amp;', '&' , $new_key );
236
+		if (false !== strpos($key, 'amp;')) {
237
+			$new_key = str_replace('&amp;', '&', $key);
238
+			$new_key = str_replace('amp;', '&', $new_key);
239 239
 
240
-			unset( $encoded_data_array[ $key ] );
241
-			$encoded_data_array[ $new_key ] = $value;
240
+			unset($encoded_data_array[$key]);
241
+			$encoded_data_array[$new_key] = $value;
242 242
 		}
243 243
 
244 244
 	}
245 245
 	
246 246
 	//Validate IPN request w/ PayPal if user hasn't disabled this security measure
247
-	if ( ! give_get_option( 'disable_paypal_verification' ) ) {
247
+	if ( ! give_get_option('disable_paypal_verification')) {
248 248
 
249 249
 		$remote_post_vars = array(
250 250
 			'method'      => 'POST',
@@ -264,22 +264,22 @@  discard block
 block discarded – undo
264 264
 		);
265 265
 
266 266
 		// Validate the IPN
267
-		$api_response = wp_remote_post( give_get_paypal_redirect(), $remote_post_vars );
267
+		$api_response = wp_remote_post(give_get_paypal_redirect(), $remote_post_vars);
268 268
 
269
-		if ( is_wp_error( $api_response ) ) {
270
-			give_record_gateway_error( __( 'IPN Error', 'give' ), sprintf( __( 'Invalid IPN verification response. IPN data: %s', 'give' ), json_encode( $api_response ) ) );
269
+		if (is_wp_error($api_response)) {
270
+			give_record_gateway_error(__('IPN Error', 'give'), sprintf(__('Invalid IPN verification response. IPN data: %s', 'give'), json_encode($api_response)));
271 271
 			return; // Something went wrong
272 272
 		}
273 273
 
274
-		if ( $api_response['body'] !== 'VERIFIED' && give_get_option( 'disable_paypal_verification', false ) ) {
275
-			give_record_gateway_error( __( 'IPN Error', 'give' ), sprintf( __( 'Invalid IPN verification response. IPN data: %s', 'give' ), json_encode( $api_response ) ) );
274
+		if ($api_response['body'] !== 'VERIFIED' && give_get_option('disable_paypal_verification', false)) {
275
+			give_record_gateway_error(__('IPN Error', 'give'), sprintf(__('Invalid IPN verification response. IPN data: %s', 'give'), json_encode($api_response)));
276 276
 			return; // Response not okay
277 277
 		}
278 278
 
279 279
 	}
280 280
 
281 281
 	// Check if $post_data_array has been populated
282
-	if ( ! is_array( $encoded_data_array ) && ! empty( $encoded_data_array ) ) {
282
+	if ( ! is_array($encoded_data_array) && ! empty($encoded_data_array)) {
283 283
 		return;
284 284
 	}
285 285
 
@@ -288,21 +288,21 @@  discard block
 block discarded – undo
288 288
 		'payment_status' => ''
289 289
 	);
290 290
 
291
-	$encoded_data_array = wp_parse_args( $encoded_data_array, $defaults );
291
+	$encoded_data_array = wp_parse_args($encoded_data_array, $defaults);
292 292
 
293
-	$payment_id = isset( $encoded_data_array['custom'] ) ? absint( $encoded_data_array['custom'] ) : 0;
293
+	$payment_id = isset($encoded_data_array['custom']) ? absint($encoded_data_array['custom']) : 0;
294 294
 
295
-	if ( has_action( 'give_paypal_' . $encoded_data_array['txn_type'] ) ) {
295
+	if (has_action('give_paypal_'.$encoded_data_array['txn_type'])) {
296 296
 		// Allow PayPal IPN types to be processed separately
297
-		do_action( 'give_paypal_' . $encoded_data_array['txn_type'], $encoded_data_array, $payment_id );
297
+		do_action('give_paypal_'.$encoded_data_array['txn_type'], $encoded_data_array, $payment_id);
298 298
 	} else {
299 299
 		// Fallback to web accept just in case the txn_type isn't present
300
-		do_action( 'give_paypal_web_accept', $encoded_data_array, $payment_id );
300
+		do_action('give_paypal_web_accept', $encoded_data_array, $payment_id);
301 301
 	}
302 302
 	exit;
303 303
 }
304 304
 
305
-add_action( 'give_verify_paypal_ipn', 'give_process_paypal_ipn' );
305
+add_action('give_verify_paypal_ipn', 'give_process_paypal_ipn');
306 306
 
307 307
 /**
308 308
  * Process web accept (one time) payment IPNs
@@ -313,185 +313,185 @@  discard block
 block discarded – undo
313 313
  *
314 314
  * @return void
315 315
  */
316
-function give_process_paypal_web_accept_and_cart( $data, $payment_id ) {
316
+function give_process_paypal_web_accept_and_cart($data, $payment_id) {
317 317
 
318
-	if ( $data['txn_type'] != 'web_accept' && $data['txn_type'] != 'cart' && $data['payment_status'] != 'Refunded' ) {
318
+	if ($data['txn_type'] != 'web_accept' && $data['txn_type'] != 'cart' && $data['payment_status'] != 'Refunded') {
319 319
 		return;
320 320
 	}
321 321
 
322
-	if ( empty( $payment_id ) ) {
322
+	if (empty($payment_id)) {
323 323
 		return;
324 324
 	}
325 325
 
326 326
 	// Collect payment details
327
-	$purchase_key   = isset( $data['invoice'] ) ? $data['invoice'] : $data['item_number'];
327
+	$purchase_key   = isset($data['invoice']) ? $data['invoice'] : $data['item_number'];
328 328
 	$paypal_amount  = $data['mc_gross'];
329
-	$payment_status = strtolower( $data['payment_status'] );
330
-	$currency_code  = strtolower( $data['mc_currency'] );
331
-	$business_email = isset( $data['business'] ) && is_email( $data['business'] ) ? trim( $data['business'] ) : trim( $data['receiver_email'] );
332
-	$payment_meta   = give_get_payment_meta( $payment_id );
329
+	$payment_status = strtolower($data['payment_status']);
330
+	$currency_code  = strtolower($data['mc_currency']);
331
+	$business_email = isset($data['business']) && is_email($data['business']) ? trim($data['business']) : trim($data['receiver_email']);
332
+	$payment_meta   = give_get_payment_meta($payment_id);
333 333
 
334 334
 
335
-	if ( give_get_payment_gateway( $payment_id ) != 'paypal' ) {
335
+	if (give_get_payment_gateway($payment_id) != 'paypal') {
336 336
 		return; // this isn't a PayPal standard IPN
337 337
 	}
338 338
 
339 339
 	// Verify payment recipient
340
-	if ( strcasecmp( $business_email, trim( give_get_option( 'paypal_email' ) ) ) != 0 ) {
340
+	if (strcasecmp($business_email, trim(give_get_option('paypal_email'))) != 0) {
341 341
 
342
-		give_record_gateway_error( __( 'IPN Error', 'give' ), sprintf( __( 'Invalid business email in IPN response. IPN data: %s', 'give' ), json_encode( $data ) ), $payment_id );
343
-		give_update_payment_status( $payment_id, 'failed' );
344
-		give_insert_payment_note( $payment_id, __( 'Payment failed due to invalid PayPal business email.', 'give' ) );
342
+		give_record_gateway_error(__('IPN Error', 'give'), sprintf(__('Invalid business email in IPN response. IPN data: %s', 'give'), json_encode($data)), $payment_id);
343
+		give_update_payment_status($payment_id, 'failed');
344
+		give_insert_payment_note($payment_id, __('Payment failed due to invalid PayPal business email.', 'give'));
345 345
 
346 346
 		return;
347 347
 	}
348 348
 
349 349
 	// Verify payment currency
350
-	if ( $currency_code != strtolower( $payment_meta['currency'] ) ) {
350
+	if ($currency_code != strtolower($payment_meta['currency'])) {
351 351
 
352
-		give_record_gateway_error( __( 'IPN Error', 'give' ), sprintf( __( 'Invalid currency in IPN response. IPN data: %s', 'give' ), json_encode( $data ) ), $payment_id );
353
-		give_update_payment_status( $payment_id, 'failed' );
354
-		give_insert_payment_note( $payment_id, __( 'Payment failed due to invalid currency in PayPal IPN.', 'give' ) );
352
+		give_record_gateway_error(__('IPN Error', 'give'), sprintf(__('Invalid currency in IPN response. IPN data: %s', 'give'), json_encode($data)), $payment_id);
353
+		give_update_payment_status($payment_id, 'failed');
354
+		give_insert_payment_note($payment_id, __('Payment failed due to invalid currency in PayPal IPN.', 'give'));
355 355
 
356 356
 		return;
357 357
 	}
358 358
 
359
-	if ( ! give_get_payment_user_email( $payment_id ) ) {
359
+	if ( ! give_get_payment_user_email($payment_id)) {
360 360
 
361 361
 		// No email associated with purchase, so store from PayPal
362
-		give_update_payment_meta( $payment_id, '_give_payment_user_email', $data['payer_email'] );
362
+		give_update_payment_meta($payment_id, '_give_payment_user_email', $data['payer_email']);
363 363
 
364 364
 		// Setup and store the donors's details
365 365
 		$address            = array();
366
-		$address['line1']   = ! empty( $data['address_street'] ) ? sanitize_text_field( $data['address_street'] ) : false;
367
-		$address['city']    = ! empty( $data['address_city'] ) ? sanitize_text_field( $data['address_city'] ) : false;
368
-		$address['state']   = ! empty( $data['address_state'] ) ? sanitize_text_field( $data['address_state'] ) : false;
369
-		$address['country'] = ! empty( $data['address_country_code'] ) ? sanitize_text_field( $data['address_country_code'] ) : false;
370
-		$address['zip']     = ! empty( $data['address_zip'] ) ? sanitize_text_field( $data['address_zip'] ) : false;
366
+		$address['line1']   = ! empty($data['address_street']) ? sanitize_text_field($data['address_street']) : false;
367
+		$address['city']    = ! empty($data['address_city']) ? sanitize_text_field($data['address_city']) : false;
368
+		$address['state']   = ! empty($data['address_state']) ? sanitize_text_field($data['address_state']) : false;
369
+		$address['country'] = ! empty($data['address_country_code']) ? sanitize_text_field($data['address_country_code']) : false;
370
+		$address['zip']     = ! empty($data['address_zip']) ? sanitize_text_field($data['address_zip']) : false;
371 371
 
372 372
 		$user_info = array(
373 373
 			'id'         => '-1',
374
-			'email'      => sanitize_text_field( $data['payer_email'] ),
375
-			'first_name' => sanitize_text_field( $data['first_name'] ),
376
-			'last_name'  => sanitize_text_field( $data['last_name'] ),
374
+			'email'      => sanitize_text_field($data['payer_email']),
375
+			'first_name' => sanitize_text_field($data['first_name']),
376
+			'last_name'  => sanitize_text_field($data['last_name']),
377 377
 			'discount'   => '',
378 378
 			'address'    => $address
379 379
 		);
380 380
 
381 381
 		$payment_meta['user_info'] = $user_info;
382
-		give_update_payment_meta( $payment_id, '_give_payment_meta', $payment_meta );
382
+		give_update_payment_meta($payment_id, '_give_payment_meta', $payment_meta);
383 383
 	}
384 384
 
385
-	if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) {
385
+	if ($payment_status == 'refunded' || $payment_status == 'reversed') {
386 386
 
387 387
 		// Process a refund
388
-		give_process_paypal_refund( $data, $payment_id );
388
+		give_process_paypal_refund($data, $payment_id);
389 389
 
390 390
 	} else {
391 391
 
392
-		if ( get_post_status( $payment_id ) == 'publish' ) {
392
+		if (get_post_status($payment_id) == 'publish') {
393 393
 			return; // Only complete payments once
394 394
 		}
395 395
 
396 396
 		// Retrieve the total purchase amount (before PayPal)
397
-		$payment_amount = give_get_payment_amount( $payment_id );
397
+		$payment_amount = give_get_payment_amount($payment_id);
398 398
 
399
-		if ( number_format( (float) $paypal_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) {
399
+		if (number_format((float) $paypal_amount, 2) < number_format((float) $payment_amount, 2)) {
400 400
 			// The prices don't match
401
-			give_record_gateway_error( __( 'IPN Error', 'give' ), sprintf( __( 'Invalid payment amount in IPN response. IPN data: %s', 'give' ), json_encode( $data ) ), $payment_id );
402
-			give_update_payment_status( $payment_id, 'failed' );
403
-			give_insert_payment_note( $payment_id, __( 'Payment failed due to invalid amount in PayPal IPN.', 'give' ) );
401
+			give_record_gateway_error(__('IPN Error', 'give'), sprintf(__('Invalid payment amount in IPN response. IPN data: %s', 'give'), json_encode($data)), $payment_id);
402
+			give_update_payment_status($payment_id, 'failed');
403
+			give_insert_payment_note($payment_id, __('Payment failed due to invalid amount in PayPal IPN.', 'give'));
404 404
 
405 405
 			return;
406 406
 		}
407
-		if ( $purchase_key != give_get_payment_key( $payment_id ) ) {
407
+		if ($purchase_key != give_get_payment_key($payment_id)) {
408 408
 			// Purchase keys don't match
409
-			give_record_gateway_error( __( 'IPN Error', 'give' ), sprintf( __( 'Invalid purchase key in IPN response. IPN data: %s', 'give' ), json_encode( $data ) ), $payment_id );
410
-			give_update_payment_status( $payment_id, 'failed' );
411
-			give_insert_payment_note( $payment_id, __( 'Payment failed due to invalid purchase key in PayPal IPN.', 'give' ) );
409
+			give_record_gateway_error(__('IPN Error', 'give'), sprintf(__('Invalid purchase key in IPN response. IPN data: %s', 'give'), json_encode($data)), $payment_id);
410
+			give_update_payment_status($payment_id, 'failed');
411
+			give_insert_payment_note($payment_id, __('Payment failed due to invalid purchase key in PayPal IPN.', 'give'));
412 412
 
413 413
 			return;
414 414
 		}
415 415
 
416
-		if ( $payment_status == 'completed' || give_is_test_mode() ) {
417
-			give_insert_payment_note( $payment_id, sprintf( __( 'PayPal Transaction ID: %s', 'give' ), $data['txn_id'] ) );
418
-			give_set_payment_transaction_id( $payment_id, $data['txn_id'] );
419
-			give_update_payment_status( $payment_id, 'publish' );
420
-		} else if ( 'pending' == $payment_status && isset( $data['pending_reason'] ) ) {
416
+		if ($payment_status == 'completed' || give_is_test_mode()) {
417
+			give_insert_payment_note($payment_id, sprintf(__('PayPal Transaction ID: %s', 'give'), $data['txn_id']));
418
+			give_set_payment_transaction_id($payment_id, $data['txn_id']);
419
+			give_update_payment_status($payment_id, 'publish');
420
+		} else if ('pending' == $payment_status && isset($data['pending_reason'])) {
421 421
 
422 422
 			// Look for possible pending reasons, such as an echeck
423 423
 
424 424
 			$note = '';
425 425
 
426
-			switch ( strtolower( $data['pending_reason'] ) ) {
426
+			switch (strtolower($data['pending_reason'])) {
427 427
 
428 428
 				case 'echeck' :
429 429
 
430
-					$note = __( 'Payment made via eCheck and will clear automatically in 5-8 days.', 'give' );
430
+					$note = __('Payment made via eCheck and will clear automatically in 5-8 days.', 'give');
431 431
 
432 432
 					break;
433 433
 
434 434
 				case 'address' :
435 435
 
436
-					$note = __( 'Payment requires a confirmed donor address and must be accepted manually through PayPal.', 'give' );
436
+					$note = __('Payment requires a confirmed donor address and must be accepted manually through PayPal.', 'give');
437 437
 
438 438
 					break;
439 439
 
440 440
 				case 'intl' :
441 441
 
442
-					$note = __( 'Payment must be accepted manually through PayPal due to international account regulations.', 'give' );
442
+					$note = __('Payment must be accepted manually through PayPal due to international account regulations.', 'give');
443 443
 
444 444
 					break;
445 445
 
446 446
 				case 'multi-currency' :
447 447
 
448
-					$note = __( 'Payment received in non-shop currency and must be accepted manually through PayPal.', 'give' );
448
+					$note = __('Payment received in non-shop currency and must be accepted manually through PayPal.', 'give');
449 449
 
450 450
 					break;
451 451
 
452 452
 				case 'paymentreview' :
453 453
 				case 'regulatory_review' :
454 454
 
455
-					$note = __( 'Payment is being reviewed by PayPal staff as high-risk or in possible violation of government regulations.', 'give' );
455
+					$note = __('Payment is being reviewed by PayPal staff as high-risk or in possible violation of government regulations.', 'give');
456 456
 
457 457
 					break;
458 458
 
459 459
 				case 'unilateral' :
460 460
 
461
-					$note = __( 'Payment was sent to non-confirmed or non-registered email address.', 'give' );
461
+					$note = __('Payment was sent to non-confirmed or non-registered email address.', 'give');
462 462
 
463 463
 					break;
464 464
 
465 465
 				case 'upgrade' :
466 466
 
467
-					$note = __( 'PayPal account must be upgraded before this payment can be accepted.', 'give' );
467
+					$note = __('PayPal account must be upgraded before this payment can be accepted.', 'give');
468 468
 
469 469
 					break;
470 470
 
471 471
 				case 'verify' :
472 472
 
473
-					$note = __( 'PayPal account is not verified. Verify account in order to accept this payment.', 'give' );
473
+					$note = __('PayPal account is not verified. Verify account in order to accept this payment.', 'give');
474 474
 
475 475
 					break;
476 476
 
477 477
 				case 'other' :
478 478
 
479
-					$note = __( 'Payment is pending for unknown reasons. Contact PayPal support for assistance.', 'give' );
479
+					$note = __('Payment is pending for unknown reasons. Contact PayPal support for assistance.', 'give');
480 480
 
481 481
 					break;
482 482
 
483 483
 			}
484 484
 
485
-			if ( ! empty( $note ) ) {
485
+			if ( ! empty($note)) {
486 486
 
487
-				give_insert_payment_note( $payment_id, $note );
487
+				give_insert_payment_note($payment_id, $note);
488 488
 
489 489
 			}
490 490
 		}
491 491
 	}
492 492
 }
493 493
 
494
-add_action( 'give_paypal_web_accept', 'give_process_paypal_web_accept_and_cart', 10, 2 );
494
+add_action('give_paypal_web_accept', 'give_process_paypal_web_accept_and_cart', 10, 2);
495 495
 
496 496
 /**
497 497
  * Process PayPal IPN Refunds
@@ -502,32 +502,32 @@  discard block
 block discarded – undo
502 502
  *
503 503
  * @return void
504 504
  */
505
-function give_process_paypal_refund( $data, $payment_id = 0 ) {
505
+function give_process_paypal_refund($data, $payment_id = 0) {
506 506
 
507 507
 	// Collect payment details
508 508
 
509
-	if ( empty( $payment_id ) ) {
509
+	if (empty($payment_id)) {
510 510
 		return;
511 511
 	}
512 512
 
513
-	if ( get_post_status( $payment_id ) == 'refunded' ) {
513
+	if (get_post_status($payment_id) == 'refunded') {
514 514
 		return; // Only refund payments once
515 515
 	}
516 516
 
517
-	$payment_amount = give_get_payment_amount( $payment_id );
517
+	$payment_amount = give_get_payment_amount($payment_id);
518 518
 	$refund_amount  = $data['payment_gross'] * - 1;
519 519
 
520
-	if ( number_format( (float) $refund_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) {
520
+	if (number_format((float) $refund_amount, 2) < number_format((float) $payment_amount, 2)) {
521 521
 
522
-		give_insert_payment_note( $payment_id, sprintf( __( 'Partial PayPal refund processed: %s', 'give' ), $data['parent_txn_id'] ) );
522
+		give_insert_payment_note($payment_id, sprintf(__('Partial PayPal refund processed: %s', 'give'), $data['parent_txn_id']));
523 523
 
524 524
 		return; // This is a partial refund
525 525
 
526 526
 	}
527 527
 
528
-	give_insert_payment_note( $payment_id, sprintf( __( 'PayPal Payment #%s Refunded for reason: %s', 'give' ), $data['parent_txn_id'], $data['reason_code'] ) );
529
-	give_insert_payment_note( $payment_id, sprintf( __( 'PayPal Refund Transaction ID: %s', 'give' ), $data['txn_id'] ) );
530
-	give_update_payment_status( $payment_id, 'refunded' );
528
+	give_insert_payment_note($payment_id, sprintf(__('PayPal Payment #%s Refunded for reason: %s', 'give'), $data['parent_txn_id'], $data['reason_code']));
529
+	give_insert_payment_note($payment_id, sprintf(__('PayPal Refund Transaction ID: %s', 'give'), $data['txn_id']));
530
+	give_update_payment_status($payment_id, 'refunded');
531 531
 }
532 532
 
533 533
 /**
@@ -539,24 +539,24 @@  discard block
 block discarded – undo
539 539
  *
540 540
  * @return string
541 541
  */
542
-function give_get_paypal_redirect( $ssl_check = false ) {
542
+function give_get_paypal_redirect($ssl_check = false) {
543 543
 
544
-	if ( is_ssl() || ! $ssl_check ) {
544
+	if (is_ssl() || ! $ssl_check) {
545 545
 		$protocal = 'https://';
546 546
 	} else {
547 547
 		$protocal = 'http://';
548 548
 	}
549 549
 
550 550
 	// Check the current payment mode
551
-	if ( give_is_test_mode() ) {
551
+	if (give_is_test_mode()) {
552 552
 		// Test mode
553
-		$paypal_uri = $protocal . 'www.sandbox.paypal.com/cgi-bin/webscr';
553
+		$paypal_uri = $protocal.'www.sandbox.paypal.com/cgi-bin/webscr';
554 554
 	} else {
555 555
 		// Live mode
556
-		$paypal_uri = $protocal . 'www.paypal.com/cgi-bin/webscr';
556
+		$paypal_uri = $protocal.'www.paypal.com/cgi-bin/webscr';
557 557
 	}
558 558
 
559
-	return apply_filters( 'give_paypal_uri', $paypal_uri );
559
+	return apply_filters('give_paypal_uri', $paypal_uri);
560 560
 }
561 561
 
562 562
 /**
@@ -566,8 +566,8 @@  discard block
 block discarded – undo
566 566
  * @return string
567 567
  */
568 568
 function give_get_paypal_page_style() {
569
-	$page_style = trim( give_get_option( 'paypal_page_style', 'PayPal' ) );
570
-	return apply_filters( 'give_paypal_page_style', $page_style );
569
+	$page_style = trim(give_get_option('paypal_page_style', 'PayPal'));
570
+	return apply_filters('give_paypal_page_style', $page_style);
571 571
 }
572 572
 
573 573
 /**
@@ -582,27 +582,27 @@  discard block
 block discarded – undo
582 582
  * @return string
583 583
  *
584 584
  */
585
-function give_paypal_success_page_content( $content ) {
585
+function give_paypal_success_page_content($content) {
586 586
 
587
-	if ( ! isset( $_GET['payment-id'] ) && ! give_get_purchase_session() ) {
587
+	if ( ! isset($_GET['payment-id']) && ! give_get_purchase_session()) {
588 588
 		return $content;
589 589
 	}
590 590
 
591
-	$payment_id = isset( $_GET['payment-id'] ) ? absint( $_GET['payment-id'] ) : false;
591
+	$payment_id = isset($_GET['payment-id']) ? absint($_GET['payment-id']) : false;
592 592
 
593
-	if ( ! $payment_id ) {
593
+	if ( ! $payment_id) {
594 594
 		$session    = give_get_purchase_session();
595
-		$payment_id = give_get_purchase_id_by_key( $session['purchase_key'] );
595
+		$payment_id = give_get_purchase_id_by_key($session['purchase_key']);
596 596
 	}
597 597
 
598
-	$payment = get_post( $payment_id );
598
+	$payment = get_post($payment_id);
599 599
 
600
-	if ( $payment && 'pending' == $payment->post_status ) {
600
+	if ($payment && 'pending' == $payment->post_status) {
601 601
 
602 602
 		// Payment is still pending so show processing indicator to fix the Race Condition
603 603
 		ob_start();
604 604
 
605
-		give_get_template_part( 'payment', 'processing' );
605
+		give_get_template_part('payment', 'processing');
606 606
 
607 607
 		$content = ob_get_clean();
608 608
 
@@ -612,7 +612,7 @@  discard block
 block discarded – undo
612 612
 
613 613
 }
614 614
 
615
-add_filter( 'give_payment_confirm_paypal', 'give_paypal_success_page_content' );
615
+add_filter('give_payment_confirm_paypal', 'give_paypal_success_page_content');
616 616
 
617 617
 /**
618 618
  * Given a Payment ID, extract the transaction ID
@@ -623,22 +623,22 @@  discard block
 block discarded – undo
623 623
  *
624 624
  * @return string                   Transaction ID
625 625
  */
626
-function give_paypal_get_payment_transaction_id( $payment_id ) {
626
+function give_paypal_get_payment_transaction_id($payment_id) {
627 627
 
628 628
 	$transaction_id = '';
629
-	$notes          = give_get_payment_notes( $payment_id );
629
+	$notes          = give_get_payment_notes($payment_id);
630 630
 
631
-	foreach ( $notes as $note ) {
632
-		if ( preg_match( '/^PayPal Transaction ID: ([^\s]+)/', $note->comment_content, $match ) ) {
631
+	foreach ($notes as $note) {
632
+		if (preg_match('/^PayPal Transaction ID: ([^\s]+)/', $note->comment_content, $match)) {
633 633
 			$transaction_id = $match[1];
634 634
 			continue;
635 635
 		}
636 636
 	}
637 637
 
638
-	return apply_filters( 'give_paypal_set_payment_transaction_id', $transaction_id, $payment_id );
638
+	return apply_filters('give_paypal_set_payment_transaction_id', $transaction_id, $payment_id);
639 639
 }
640 640
 
641
-add_filter( 'give_get_payment_transaction_id-paypal', 'give_paypal_get_payment_transaction_id', 10, 1 );
641
+add_filter('give_get_payment_transaction_id-paypal', 'give_paypal_get_payment_transaction_id', 10, 1);
642 642
 
643 643
 /**
644 644
  * Given a transaction ID, generate a link to the PayPal transaction ID details
@@ -650,13 +650,13 @@  discard block
 block discarded – undo
650 650
  *
651 651
  * @return string                 A link to the PayPal transaction details
652 652
  */
653
-function give_paypal_link_transaction_id( $transaction_id, $payment_id ) {
653
+function give_paypal_link_transaction_id($transaction_id, $payment_id) {
654 654
 
655 655
 	$paypal_base_url = 'https://history.paypal.com/cgi-bin/webscr?cmd=_history-details-from-hub&id=';
656
-	$transaction_url = '<a href="' . esc_url( $paypal_base_url . $transaction_id ) . '" target="_blank">' . $transaction_id . '</a>';
656
+	$transaction_url = '<a href="'.esc_url($paypal_base_url.$transaction_id).'" target="_blank">'.$transaction_id.'</a>';
657 657
 
658
-	return apply_filters( 'give_paypal_link_payment_details_transaction_id', $transaction_url );
658
+	return apply_filters('give_paypal_link_payment_details_transaction_id', $transaction_url);
659 659
 
660 660
 }
661 661
 
662
-add_filter( 'give_payment_details_transaction_id-paypal', 'give_paypal_link_transaction_id', 10, 2 );
662
+add_filter('give_payment_details_transaction_id-paypal', 'give_paypal_link_transaction_id', 10, 2);
Please login to merge, or discard this patch.
includes/gateways/actions.php 1 patch
Spacing   +13 added lines, -13 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
 
@@ -21,14 +21,14 @@  discard block
 block discarded – undo
21 21
  *
22 22
  * @param $data
23 23
  */
24
-function give_process_gateway_select( $data ) {
25
-	if ( isset( $_POST['gateway_submit'] ) ) {
26
-		wp_redirect( esc_url( add_query_arg( 'payment-mode', $_POST['payment-mode'] ) ) );
24
+function give_process_gateway_select($data) {
25
+	if (isset($_POST['gateway_submit'])) {
26
+		wp_redirect(esc_url(add_query_arg('payment-mode', $_POST['payment-mode'])));
27 27
 		exit;
28 28
 	}
29 29
 }
30 30
 
31
-add_action( 'give_gateway_select', 'give_process_gateway_select' );
31
+add_action('give_gateway_select', 'give_process_gateway_select');
32 32
 
33 33
 /**
34 34
  * Loads a payment gateway via AJAX
@@ -37,14 +37,14 @@  discard block
 block discarded – undo
37 37
  * @return void
38 38
  */
39 39
 function give_load_ajax_gateway() {
40
-	if ( isset( $_POST['give_payment_mode'] ) ) {
41
-		do_action( 'give_purchase_form', $_POST['give_form_id'] );
40
+	if (isset($_POST['give_payment_mode'])) {
41
+		do_action('give_purchase_form', $_POST['give_form_id']);
42 42
 		exit();
43 43
 	}
44 44
 }
45 45
 
46
-add_action( 'wp_ajax_give_load_gateway', 'give_load_ajax_gateway' );
47
-add_action( 'wp_ajax_nopriv_give_load_gateway', 'give_load_ajax_gateway' );
46
+add_action('wp_ajax_give_load_gateway', 'give_load_ajax_gateway');
47
+add_action('wp_ajax_nopriv_give_load_gateway', 'give_load_ajax_gateway');
48 48
 
49 49
 /**
50 50
  * Sets an error on checkout if no gateways are enabled
@@ -55,11 +55,11 @@  discard block
 block discarded – undo
55 55
 function give_no_gateway_error() {
56 56
 	$gateways = give_get_enabled_payment_gateways();
57 57
 
58
-	if ( empty( $gateways ) ) {
59
-		give_set_error( 'no_gateways', __( 'You must enable a payment gateway to use Give.', 'give' ) );
58
+	if (empty($gateways)) {
59
+		give_set_error('no_gateways', __('You must enable a payment gateway to use Give.', 'give'));
60 60
 	} else {
61
-		give_unset_error( 'no_gateways' );
61
+		give_unset_error('no_gateways');
62 62
 	}
63 63
 }
64 64
 
65
-add_action( 'init', 'give_no_gateway_error' );
66 65
\ No newline at end of file
66
+add_action('init', 'give_no_gateway_error');
67 67
\ No newline at end of file
Please login to merge, or discard this patch.
includes/class-give-license-handler.php 1 patch
Spacing   +62 added lines, -62 removed lines patch added patch discarded remove patch
@@ -8,11 +8,11 @@  discard block
 block discarded – undo
8 8
  */
9 9
 
10 10
 // Exit if accessed directly
11
-if ( ! defined( 'ABSPATH' ) ) {
11
+if ( ! defined('ABSPATH')) {
12 12
 	exit;
13 13
 }
14 14
 
15
-if ( ! class_exists( 'Give_License' ) ) :
15
+if ( ! class_exists('Give_License')) :
16 16
 
17 17
 	/**
18 18
 	 * Give_License Class
@@ -38,16 +38,16 @@  discard block
 block discarded – undo
38 38
 		 * @param string  $_optname
39 39
 		 * @param string  $_api_url
40 40
 		 */
41
-		public function __construct( $_file, $_item_name, $_version, $_author, $_optname = null, $_api_url = null ) {
41
+		public function __construct($_file, $_item_name, $_version, $_author, $_optname = null, $_api_url = null) {
42 42
 			global $give_options;
43 43
 
44 44
 			$this->file           = $_file;
45 45
 			$this->item_name      = $_item_name;
46
-			$this->item_shortname = 'give_' . preg_replace( '/[^a-zA-Z0-9_\s]/', '', str_replace( ' ', '_', strtolower( $this->item_name ) ) );
46
+			$this->item_shortname = 'give_'.preg_replace('/[^a-zA-Z0-9_\s]/', '', str_replace(' ', '_', strtolower($this->item_name)));
47 47
 			$this->version        = $_version;
48
-			$this->license        = isset( $give_options[ $this->item_shortname . '_license_key' ] ) ? trim( $give_options[ $this->item_shortname . '_license_key' ] ) : '';
48
+			$this->license        = isset($give_options[$this->item_shortname.'_license_key']) ? trim($give_options[$this->item_shortname.'_license_key']) : '';
49 49
 			$this->author         = $_author;
50
-			$this->api_url        = is_null( $_api_url ) ? $this->api_url : $_api_url;
50
+			$this->api_url        = is_null($_api_url) ? $this->api_url : $_api_url;
51 51
 
52 52
 
53 53
 			// Setup hooks
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
 		 * @return  void
64 64
 		 */
65 65
 		private function includes() {
66
-			if ( ! class_exists( 'EDD_SL_Plugin_Updater' ) ) {
66
+			if ( ! class_exists('EDD_SL_Plugin_Updater')) {
67 67
 				require_once 'admin/EDD_SL_Plugin_Updater.php';
68 68
 			}
69 69
 		}
@@ -77,18 +77,18 @@  discard block
 block discarded – undo
77 77
 		private function hooks() {
78 78
 
79 79
 			// Register settings
80
-			add_filter( 'give_settings_licenses', array( $this, 'settings' ), 1 );
80
+			add_filter('give_settings_licenses', array($this, 'settings'), 1);
81 81
 
82 82
 			// Activate license key on settings save
83
-			add_action( 'admin_init', array( $this, 'activate_license' ) );
83
+			add_action('admin_init', array($this, 'activate_license'));
84 84
 
85 85
 			// Deactivate license key
86
-			add_action( 'admin_init', array( $this, 'deactivate_license' ) );
86
+			add_action('admin_init', array($this, 'deactivate_license'));
87 87
 
88 88
 			// Updater
89
-			add_action( 'admin_init', array( $this, 'auto_updater' ), 0 );
89
+			add_action('admin_init', array($this, 'auto_updater'), 0);
90 90
 
91
-			add_action( 'admin_notices', array( $this, 'notices' ) );
91
+			add_action('admin_notices', array($this, 'notices'));
92 92
 		}
93 93
 
94 94
 		/**
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
 		 */
101 101
 		public function auto_updater() {
102 102
 
103
-			if ( 'valid' !== get_option( $this->item_shortname . '_license_active' ) ) {
103
+			if ('valid' !== get_option($this->item_shortname.'_license_active')) {
104 104
 				return;
105 105
 			}
106 106
 
@@ -127,20 +127,20 @@  discard block
 block discarded – undo
127 127
 		 *
128 128
 		 * @return  array
129 129
 		 */
130
-		public function settings( $settings ) {
130
+		public function settings($settings) {
131 131
 
132 132
 			$give_license_settings = array(
133 133
 				array(
134 134
 					'name'    => $this->item_name,
135
-					'id'      => $this->item_shortname . '_license_key',
135
+					'id'      => $this->item_shortname.'_license_key',
136 136
 					'desc'    => '',
137 137
 					'type'    => 'license_key',
138
-					'options' => array( 'is_valid_license_option' => $this->item_shortname . '_license_active' ),
138
+					'options' => array('is_valid_license_option' => $this->item_shortname.'_license_active'),
139 139
 					'size'    => 'regular'
140 140
 				)
141 141
 			);
142 142
 
143
-			return array_merge( $settings, $give_license_settings );
143
+			return array_merge($settings, $give_license_settings);
144 144
 		}
145 145
 
146 146
 		/**
@@ -152,18 +152,18 @@  discard block
 block discarded – undo
152 152
 		 *
153 153
 		 * @return  array
154 154
 		 */
155
-		public function license_settings_content( $settings ) {
155
+		public function license_settings_content($settings) {
156 156
 
157 157
 			$give_license_settings = array(
158 158
 				array(
159
-					'name' => __( 'Add-on Licenses', 'give' ),
159
+					'name' => __('Add-on Licenses', 'give'),
160 160
 					'desc' => '<hr>',
161 161
 					'type' => 'give_title',
162 162
 					'id'   => 'give_title'
163 163
 				),
164 164
 			);
165 165
 
166
-			return array_merge( $settings, $give_license_settings );
166
+			return array_merge($settings, $give_license_settings);
167 167
 		}
168 168
 
169 169
 
@@ -175,34 +175,34 @@  discard block
 block discarded – undo
175 175
 		 */
176 176
 		public function activate_license() {
177 177
 
178
-			if ( ! isset( $_POST[ $this->item_shortname . '_license_key' ] ) ) {
178
+			if ( ! isset($_POST[$this->item_shortname.'_license_key'])) {
179 179
 				return;
180 180
 			}
181 181
 
182
-			foreach ( $_POST as $key => $value ) {
183
-				if ( false !== strpos( $key, 'license_key_deactivate' ) ) {
182
+			foreach ($_POST as $key => $value) {
183
+				if (false !== strpos($key, 'license_key_deactivate')) {
184 184
 					// Don't activate a key when deactivating a different key
185 185
 					return;
186 186
 				}
187 187
 			}
188 188
 
189
-			if ( ! wp_verify_nonce( $_REQUEST[ $this->item_shortname . '_license_key-nonce' ], $this->item_shortname . '_license_key-nonce' ) ) {
189
+			if ( ! wp_verify_nonce($_REQUEST[$this->item_shortname.'_license_key-nonce'], $this->item_shortname.'_license_key-nonce')) {
190 190
 
191
-				wp_die( __( 'Nonce verification failed.', 'give' ), __( 'Error', 'give' ), array( 'response' => 403 ) );
191
+				wp_die(__('Nonce verification failed.', 'give'), __('Error', 'give'), array('response' => 403));
192 192
 
193 193
 			}
194 194
 
195
-			if ( ! current_user_can( 'manage_give_settings' ) ) {
195
+			if ( ! current_user_can('manage_give_settings')) {
196 196
 				return;
197 197
 			}
198 198
 
199
-			if ( 'valid' === get_option( $this->item_shortname . '_license_active' ) ) {
199
+			if ('valid' === get_option($this->item_shortname.'_license_active')) {
200 200
 				return;
201 201
 			}
202 202
 
203
-			$license = sanitize_text_field( $_POST[ $this->item_shortname . '_license_key' ] );
203
+			$license = sanitize_text_field($_POST[$this->item_shortname.'_license_key']);
204 204
 
205
-			if ( empty( $license ) ) {
205
+			if (empty($license)) {
206 206
 				return;
207 207
 			}
208 208
 
@@ -210,7 +210,7 @@  discard block
 block discarded – undo
210 210
 			$api_params = array(
211 211
 				'edd_action' => 'activate_license', //never change from "edd_" to "give_"!
212 212
 				'license'    => $license,
213
-				'item_name'  => urlencode( $this->item_name ),
213
+				'item_name'  => urlencode($this->item_name),
214 214
 				'url'        => home_url()
215 215
 			);
216 216
 
@@ -225,22 +225,22 @@  discard block
 block discarded – undo
225 225
 			);
226 226
 
227 227
 			// Make sure there are no errors
228
-			if ( is_wp_error( $response ) ) {
228
+			if (is_wp_error($response)) {
229 229
 				return;
230 230
 			}
231 231
 
232 232
 			// Tell WordPress to look for updates
233
-			set_site_transient( 'update_plugins', null );
233
+			set_site_transient('update_plugins', null);
234 234
 
235 235
 			// Decode license data
236
-			$license_data = json_decode( wp_remote_retrieve_body( $response ) );
236
+			$license_data = json_decode(wp_remote_retrieve_body($response));
237 237
 
238
-			update_option( $this->item_shortname . '_license_active', $license_data->license );
238
+			update_option($this->item_shortname.'_license_active', $license_data->license);
239 239
 
240
-			if ( ! (bool) $license_data->success ) {
241
-				set_transient( 'give_license_error', $license_data, 1000 );
240
+			if ( ! (bool) $license_data->success) {
241
+				set_transient('give_license_error', $license_data, 1000);
242 242
 			} else {
243
-				delete_transient( 'give_license_error' );
243
+				delete_transient('give_license_error');
244 244
 			}
245 245
 		}
246 246
 
@@ -253,28 +253,28 @@  discard block
 block discarded – undo
253 253
 		 */
254 254
 		public function deactivate_license() {
255 255
 
256
-			if ( ! isset( $_POST[ $this->item_shortname . '_license_key' ] ) ) {
256
+			if ( ! isset($_POST[$this->item_shortname.'_license_key'])) {
257 257
 				return;
258 258
 			}
259 259
 
260
-			if ( ! wp_verify_nonce( $_REQUEST[ $this->item_shortname . '_license_key-nonce' ], $this->item_shortname . '_license_key-nonce' ) ) {
260
+			if ( ! wp_verify_nonce($_REQUEST[$this->item_shortname.'_license_key-nonce'], $this->item_shortname.'_license_key-nonce')) {
261 261
 
262
-				wp_die( __( 'Nonce verification failed.', 'give' ), __( 'Error', 'give' ), array( 'response' => 403 ) );
262
+				wp_die(__('Nonce verification failed.', 'give'), __('Error', 'give'), array('response' => 403));
263 263
 
264 264
 			}
265 265
 
266
-			if ( ! current_user_can( 'manage_give_settings' ) ) {
266
+			if ( ! current_user_can('manage_give_settings')) {
267 267
 				return;
268 268
 			}
269 269
 
270 270
 			// Run on deactivate button press
271
-			if ( isset( $_POST[ $this->item_shortname . '_license_key_deactivate' ] ) ) {
271
+			if (isset($_POST[$this->item_shortname.'_license_key_deactivate'])) {
272 272
 
273 273
 				// Data to send to the API
274 274
 				$api_params = array(
275 275
 					'edd_action' => 'deactivate_license', //never change from "edd_" to "give_"!
276 276
 					'license'    => $this->license,
277
-					'item_name'  => urlencode( $this->item_name ),
277
+					'item_name'  => urlencode($this->item_name),
278 278
 					'url'        => home_url()
279 279
 				);
280 280
 
@@ -290,19 +290,19 @@  discard block
 block discarded – undo
290 290
 
291 291
 
292 292
 				// Make sure there are no errors
293
-				if ( is_wp_error( $response ) ) {
293
+				if (is_wp_error($response)) {
294 294
 					return;
295 295
 				}
296 296
 
297 297
 				// Decode the license data
298
-				$license_data = json_decode( wp_remote_retrieve_body( $response ) );
298
+				$license_data = json_decode(wp_remote_retrieve_body($response));
299 299
 
300
-				delete_option( $this->item_shortname . '_license_active' );
300
+				delete_option($this->item_shortname.'_license_active');
301 301
 
302
-				if ( ! (bool) $license_data->success ) {
303
-					set_transient( 'give_license_error', $license_data, 1000 );
302
+				if ( ! (bool) $license_data->success) {
303
+					set_transient('give_license_error', $license_data, 1000);
304 304
 				} else {
305
-					delete_transient( 'give_license_error' );
305
+					delete_transient('give_license_error');
306 306
 				}
307 307
 			}
308 308
 		}
@@ -316,57 +316,57 @@  discard block
 block discarded – undo
316 316
 		 */
317 317
 		public function notices() {
318 318
 
319
-			if ( ! isset( $_GET['page'] ) || 'give-settings' !== $_GET['page'] ) {
319
+			if ( ! isset($_GET['page']) || 'give-settings' !== $_GET['page']) {
320 320
 				return;
321 321
 			}
322 322
 
323
-			if ( ! isset( $_GET['tab'] ) || 'licenses' !== $_GET['tab'] ) {
323
+			if ( ! isset($_GET['tab']) || 'licenses' !== $_GET['tab']) {
324 324
 				return;
325 325
 			}
326 326
 
327
-			$license_error = get_transient( 'give_license_error' );
327
+			$license_error = get_transient('give_license_error');
328 328
 
329
-			if ( false === $license_error ) {
329
+			if (false === $license_error) {
330 330
 				return;
331 331
 			}
332 332
 
333
-			if ( ! empty( $license_error->error ) ) {
333
+			if ( ! empty($license_error->error)) {
334 334
 
335
-				switch ( $license_error->error ) {
335
+				switch ($license_error->error) {
336 336
 
337 337
 					case 'item_name_mismatch' :
338 338
 
339
-						$message = __( 'This license does not belong to the product you have entered it for.', 'give' );
339
+						$message = __('This license does not belong to the product you have entered it for.', 'give');
340 340
 						break;
341 341
 
342 342
 					case 'no_activations_left' :
343 343
 
344
-						$message = __( 'This license does not have any activations left.', 'give' );
344
+						$message = __('This license does not have any activations left.', 'give');
345 345
 						break;
346 346
 
347 347
 					case 'expired' :
348 348
 
349
-						$message = __( 'This license key is expired. Please renew it.', 'give' );
349
+						$message = __('This license key is expired. Please renew it.', 'give');
350 350
 						break;
351 351
 
352 352
 					default :
353 353
 
354
-						$message = sprintf( __( 'There was a problem activating your license key, please try again or contact support. Error code: %s', 'give' ), $license_error->error );
354
+						$message = sprintf(__('There was a problem activating your license key, please try again or contact support. Error code: %s', 'give'), $license_error->error);
355 355
 						break;
356 356
 
357 357
 				}
358 358
 
359 359
 			}
360 360
 
361
-			if ( ! empty( $message ) ) {
361
+			if ( ! empty($message)) {
362 362
 
363 363
 				echo '<div class="error">';
364
-				echo '<p>' . $message . '</p>';
364
+				echo '<p>'.$message.'</p>';
365 365
 				echo '</div>';
366 366
 
367 367
 			}
368 368
 
369
-			delete_transient( 'give_license_error' );
369
+			delete_transient('give_license_error');
370 370
 
371 371
 		}
372 372
 	}
Please login to merge, or discard this patch.
includes/login-register.php 1 patch
Spacing   +59 added lines, -59 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,10 +25,10 @@  discard block
 block discarded – undo
25 25
  *
26 26
  * @return string Login form
27 27
  */
28
-function give_login_form( $redirect = '' ) {
28
+function give_login_form($redirect = '') {
29 29
 	global $give_login_redirect;
30 30
 
31
-	if ( empty( $redirect ) ) {
31
+	if (empty($redirect)) {
32 32
 		$redirect = add_query_arg('give-login-success', 'true', give_get_current_page_url());
33 33
 	}
34 34
 
@@ -36,9 +36,9 @@  discard block
 block discarded – undo
36 36
 
37 37
 	ob_start();
38 38
 
39
-	give_get_template_part( 'shortcode', 'login' );
39
+	give_get_template_part('shortcode', 'login');
40 40
 
41
-	return apply_filters( 'give_login_form', ob_get_clean() );
41
+	return apply_filters('give_login_form', ob_get_clean());
42 42
 }
43 43
 
44 44
 /**
@@ -52,10 +52,10 @@  discard block
 block discarded – undo
52 52
  *
53 53
  * @return string Register form
54 54
  */
55
-function give_register_form( $redirect = '' ) {
55
+function give_register_form($redirect = '') {
56 56
 	global $give_options, $give_register_redirect;
57 57
 
58
-	if ( empty( $redirect ) ) {
58
+	if (empty($redirect)) {
59 59
 		$redirect = give_get_current_page_url();
60 60
 	}
61 61
 
@@ -63,11 +63,11 @@  discard block
 block discarded – undo
63 63
 
64 64
 	ob_start();
65 65
 
66
-	if ( ! is_user_logged_in() ) {
67
-		give_get_template_part( 'shortcode', 'register' );
66
+	if ( ! is_user_logged_in()) {
67
+		give_get_template_part('shortcode', 'register');
68 68
 	}
69 69
 
70
-	return apply_filters( 'give_register_form', ob_get_clean() );
70
+	return apply_filters('give_register_form', ob_get_clean());
71 71
 }
72 72
 
73 73
 /**
@@ -79,34 +79,34 @@  discard block
 block discarded – undo
79 79
  *
80 80
  * @return void
81 81
  */
82
-function give_process_login_form( $data ) {
83
-	if ( wp_verify_nonce( $data['give_login_nonce'], 'give-login-nonce' ) ) {
84
-		$user_data = get_user_by( 'login', $data['give_user_login'] );
85
-		if ( ! $user_data ) {
86
-			$user_data = get_user_by( 'email', $data['give_user_login'] );
82
+function give_process_login_form($data) {
83
+	if (wp_verify_nonce($data['give_login_nonce'], 'give-login-nonce')) {
84
+		$user_data = get_user_by('login', $data['give_user_login']);
85
+		if ( ! $user_data) {
86
+			$user_data = get_user_by('email', $data['give_user_login']);
87 87
 		}
88
-		if ( $user_data ) {
88
+		if ($user_data) {
89 89
 			$user_ID    = $user_data->ID;
90 90
 			$user_email = $user_data->user_email;
91
-			if ( wp_check_password( $data['give_user_pass'], $user_data->user_pass, $user_data->ID ) ) {
92
-				give_log_user_in( $user_data->ID, $data['give_user_login'], $data['give_user_pass'] );
91
+			if (wp_check_password($data['give_user_pass'], $user_data->user_pass, $user_data->ID)) {
92
+				give_log_user_in($user_data->ID, $data['give_user_login'], $data['give_user_pass']);
93 93
 			} else {
94
-				give_set_error( 'password_incorrect', __( 'The password you entered is incorrect.', 'give' ) );
94
+				give_set_error('password_incorrect', __('The password you entered is incorrect.', 'give'));
95 95
 			}
96 96
 		} else {
97
-			give_set_error( 'username_incorrect', __( 'The username you entered does not exist.', 'give' ) );
97
+			give_set_error('username_incorrect', __('The username you entered does not exist.', 'give'));
98 98
 		}
99 99
 		// Check for errors and redirect if none present
100 100
 		$errors = give_get_errors();
101
-		if ( ! $errors ) {
102
-			$redirect = apply_filters( 'give_login_redirect', $data['give_redirect'], $user_ID );
103
-			wp_redirect( $redirect );
101
+		if ( ! $errors) {
102
+			$redirect = apply_filters('give_login_redirect', $data['give_redirect'], $user_ID);
103
+			wp_redirect($redirect);
104 104
 			give_die();
105 105
 		}
106 106
 	}
107 107
 }
108 108
 
109
-add_action( 'give_user_login', 'give_process_login_form' );
109
+add_action('give_user_login', 'give_process_login_form');
110 110
 
111 111
 /**
112 112
  * Log User In
@@ -119,15 +119,15 @@  discard block
 block discarded – undo
119 119
  *
120 120
  * @return void
121 121
  */
122
-function give_log_user_in( $user_id, $user_login, $user_pass ) {
123
-	if ( $user_id < 1 ) {
122
+function give_log_user_in($user_id, $user_login, $user_pass) {
123
+	if ($user_id < 1) {
124 124
 		return;
125 125
 	}
126 126
 
127
-	wp_set_auth_cookie( $user_id );
128
-	wp_set_current_user( $user_id, $user_login );
129
-	do_action( 'wp_login', $user_login, get_userdata( $user_id ) );
130
-	do_action( 'give_log_user_in', $user_id, $user_login, $user_pass );
127
+	wp_set_auth_cookie($user_id);
128
+	wp_set_current_user($user_id, $user_login);
129
+	do_action('wp_login', $user_login, get_userdata($user_id));
130
+	do_action('give_log_user_in', $user_id, $user_login, $user_pass);
131 131
 }
132 132
 
133 133
 
@@ -140,70 +140,70 @@  discard block
 block discarded – undo
140 140
  *
141 141
  * @return void
142 142
  */
143
-function give_process_register_form( $data ) {
143
+function give_process_register_form($data) {
144 144
 
145
-	if ( is_user_logged_in() ) {
145
+	if (is_user_logged_in()) {
146 146
 		return;
147 147
 	}
148 148
 
149
-	if ( empty( $_POST['give_register_submit'] ) ) {
149
+	if (empty($_POST['give_register_submit'])) {
150 150
 		return;
151 151
 	}
152 152
 
153
-	do_action( 'give_pre_process_register_form' );
153
+	do_action('give_pre_process_register_form');
154 154
 
155
-	if ( empty( $data['give_user_login'] ) ) {
156
-		give_set_error( 'empty_username', __( 'Invalid username.', 'give' ) );
155
+	if (empty($data['give_user_login'])) {
156
+		give_set_error('empty_username', __('Invalid username.', 'give'));
157 157
 	}
158 158
 
159
-	if ( username_exists( $data['give_user_login'] ) ) {
160
-		give_set_error( 'username_unavailable', __( 'Username already taken.', 'give' ) );
159
+	if (username_exists($data['give_user_login'])) {
160
+		give_set_error('username_unavailable', __('Username already taken.', 'give'));
161 161
 	}
162 162
 
163
-	if ( ! validate_username( $data['give_user_login'] ) ) {
164
-		give_set_error( 'username_invalid', __( 'Invalid username.', 'give' ) );
163
+	if ( ! validate_username($data['give_user_login'])) {
164
+		give_set_error('username_invalid', __('Invalid username.', 'give'));
165 165
 	}
166 166
 
167
-	if ( email_exists( $data['give_user_email'] ) ) {
168
-		give_set_error( 'email_unavailable', __( 'Email address already taken.', 'give' ) );
167
+	if (email_exists($data['give_user_email'])) {
168
+		give_set_error('email_unavailable', __('Email address already taken.', 'give'));
169 169
 	}
170 170
 
171
-	if ( empty( $data['give_user_email'] ) || ! is_email( $data['give_user_email'] ) ) {
172
-		give_set_error( 'email_invalid', __( 'Invalid email.', 'give' ) );
171
+	if (empty($data['give_user_email']) || ! is_email($data['give_user_email'])) {
172
+		give_set_error('email_invalid', __('Invalid email.', 'give'));
173 173
 	}
174 174
 
175
-	if ( ! empty( $data['give_payment_email'] ) && $data['give_payment_email'] != $data['give_user_email'] && ! is_email( $data['give_payment_email'] ) ) {
176
-		give_set_error( 'payment_email_invalid', __( 'Invalid payment email.', 'give' ) );
175
+	if ( ! empty($data['give_payment_email']) && $data['give_payment_email'] != $data['give_user_email'] && ! is_email($data['give_payment_email'])) {
176
+		give_set_error('payment_email_invalid', __('Invalid payment email.', 'give'));
177 177
 	}
178 178
 
179
-	if ( empty( $_POST['give_user_pass'] ) ) {
180
-		give_set_error( 'empty_password', __( 'Please enter a password.', 'give' ) );
179
+	if (empty($_POST['give_user_pass'])) {
180
+		give_set_error('empty_password', __('Please enter a password.', 'give'));
181 181
 	}
182 182
 
183
-	if ( ( ! empty( $_POST['give_user_pass'] ) && empty( $_POST['give_user_pass2'] ) ) || ( $_POST['give_user_pass'] !== $_POST['give_user_pass2'] ) ) {
184
-		give_set_error( 'password_mismatch', __( 'Passwords don\'t match.', 'give' ) );
183
+	if (( ! empty($_POST['give_user_pass']) && empty($_POST['give_user_pass2'])) || ($_POST['give_user_pass'] !== $_POST['give_user_pass2'])) {
184
+		give_set_error('password_mismatch', __('Passwords don\'t match.', 'give'));
185 185
 	}
186 186
 
187
-	do_action( 'give_process_register_form' );
187
+	do_action('give_process_register_form');
188 188
 
189 189
 	// Check for errors and redirect if none present
190 190
 	$errors = give_get_errors();
191 191
 
192
-	if ( empty( $errors ) ) {
192
+	if (empty($errors)) {
193 193
 
194
-		$redirect = apply_filters( 'give_register_redirect', $data['give_redirect'] );
194
+		$redirect = apply_filters('give_register_redirect', $data['give_redirect']);
195 195
 
196
-		give_register_and_login_new_user( array(
196
+		give_register_and_login_new_user(array(
197 197
 			'user_login'      => $data['give_user_login'],
198 198
 			'user_pass'       => $data['give_user_pass'],
199 199
 			'user_email'      => $data['give_user_email'],
200
-			'user_registered' => date( 'Y-m-d H:i:s' ),
201
-			'role'            => get_option( 'default_role' )
202
-		) );
200
+			'user_registered' => date('Y-m-d H:i:s'),
201
+			'role'            => get_option('default_role')
202
+		));
203 203
 
204
-		wp_redirect( $redirect );
204
+		wp_redirect($redirect);
205 205
 		give_die();
206 206
 	}
207 207
 }
208 208
 
209
-add_action( 'give_user_register', 'give_process_register_form' );
210 209
\ No newline at end of file
210
+add_action('give_user_register', 'give_process_register_form');
211 211
\ No newline at end of file
Please login to merge, or discard this patch.