Completed
Push — master ( b4488c...e1d700 )
by Devin
55:57 queued 36:00
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/payments/functions.php 1 patch
Spacing   +380 added lines, -380 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
 
@@ -32,15 +32,15 @@  discard block
 block discarded – undo
32 32
  *
33 33
  * @return object $payments Payments retrieved from the database
34 34
  */
35
-function give_get_payments( $args = array() ) {
35
+function give_get_payments($args = array()) {
36 36
 
37 37
 	// Fallback to post objects to ensure backwards compatibility
38
-	if ( ! isset( $args['output'] ) ) {
38
+	if ( ! isset($args['output'])) {
39 39
 		$args['output'] = 'posts';
40 40
 	}
41 41
 
42
-	$args     = apply_filters( 'give_get_payments_args', $args );
43
-	$payments = new Give_Payments_Query( $args );
42
+	$args     = apply_filters('give_get_payments_args', $args);
43
+	$payments = new Give_Payments_Query($args);
44 44
 
45 45
 	return $payments->get_payments();
46 46
 }
@@ -55,48 +55,48 @@  discard block
 block discarded – undo
55 55
  *
56 56
  * @return      mixed
57 57
  */
58
-function give_get_payment_by( $field = '', $value = '' ) {
58
+function give_get_payment_by($field = '', $value = '') {
59 59
 
60
-	if ( empty( $field ) || empty( $value ) ) {
60
+	if (empty($field) || empty($value)) {
61 61
 		return false;
62 62
 	}
63 63
 
64
-	switch ( strtolower( $field ) ) {
64
+	switch (strtolower($field)) {
65 65
 
66 66
 		case 'id':
67
-			$payment = new Give_Payment( $value );
67
+			$payment = new Give_Payment($value);
68 68
 			$id      = $payment->ID;
69 69
 
70
-			if ( empty( $id ) ) {
70
+			if (empty($id)) {
71 71
 				return false;
72 72
 			}
73 73
 
74 74
 			break;
75 75
 
76 76
 		case 'key':
77
-			$payment = give_get_payments( array(
77
+			$payment = give_get_payments(array(
78 78
 				'meta_key'       => '_give_payment_purchase_key',
79 79
 				'meta_value'     => $value,
80 80
 				'posts_per_page' => 1,
81 81
 				'fields'         => 'ids',
82
-			) );
82
+			));
83 83
 
84
-			if ( $payment ) {
85
-				$payment = new Give_Payment( $payment[0] );
84
+			if ($payment) {
85
+				$payment = new Give_Payment($payment[0]);
86 86
 			}
87 87
 
88 88
 			break;
89 89
 
90 90
 		case 'payment_number':
91
-			$payment = give_get_payments( array(
91
+			$payment = give_get_payments(array(
92 92
 				'meta_key'       => '_give_payment_number',
93 93
 				'meta_value'     => $value,
94 94
 				'posts_per_page' => 1,
95 95
 				'fields'         => 'ids',
96
-			) );
96
+			));
97 97
 
98
-			if ( $payment ) {
99
-				$payment = new Give_Payment( $payment[0] );
98
+			if ($payment) {
99
+				$payment = new Give_Payment($payment[0]);
100 100
 			}
101 101
 
102 102
 			break;
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
 			return false;
106 106
 	}
107 107
 
108
-	if ( $payment ) {
108
+	if ($payment) {
109 109
 		return $payment;
110 110
 	}
111 111
 
@@ -121,23 +121,23 @@  discard block
 block discarded – undo
121 121
  *
122 122
  * @return int|bool Payment ID if payment is inserted, false otherwise
123 123
  */
124
-function give_insert_payment( $payment_data = array() ) {
124
+function give_insert_payment($payment_data = array()) {
125 125
 
126
-	if ( empty( $payment_data ) ) {
126
+	if (empty($payment_data)) {
127 127
 		return false;
128 128
 	}
129 129
 
130 130
 	$payment    = new Give_Payment();
131
-	$gateway    = ! empty( $payment_data['gateway'] ) ? $payment_data['gateway'] : '';
132
-	$gateway    = empty( $gateway ) && isset( $_POST['give-gateway'] ) ? $_POST['give-gateway'] : $gateway;
133
-	$form_id    = isset( $payment_data['give_form_id'] ) ? $payment_data['give_form_id'] : 0;
134
-	$price_id   = isset( $payment_data['give_price_id'] ) ? $payment_data['give_price_id'] : give_get_price_id( $payment_data['give_form_id'], $payment_data['price'] );
135
-	$form_title = isset( $payment_data['give_form_title'] ) ? $payment_data['give_form_title'] : get_the_title( $form_id );
131
+	$gateway    = ! empty($payment_data['gateway']) ? $payment_data['gateway'] : '';
132
+	$gateway    = empty($gateway) && isset($_POST['give-gateway']) ? $_POST['give-gateway'] : $gateway;
133
+	$form_id    = isset($payment_data['give_form_id']) ? $payment_data['give_form_id'] : 0;
134
+	$price_id   = isset($payment_data['give_price_id']) ? $payment_data['give_price_id'] : give_get_price_id($payment_data['give_form_id'], $payment_data['price']);
135
+	$form_title = isset($payment_data['give_form_title']) ? $payment_data['give_form_title'] : get_the_title($form_id);
136 136
 
137 137
 	//Set properties
138 138
 	$payment->total          = $payment_data['price'];
139
-	$payment->status         = ! empty( $payment_data['status'] ) ? $payment_data['status'] : 'pending';
140
-	$payment->currency       = ! empty( $payment_data['currency'] ) ? $payment_data['currency'] : give_get_currency();
139
+	$payment->status         = ! empty($payment_data['status']) ? $payment_data['status'] : 'pending';
140
+	$payment->currency       = ! empty($payment_data['currency']) ? $payment_data['currency'] : give_get_currency();
141 141
 	$payment->user_info      = $payment_data['user_info'];
142 142
 	$payment->gateway        = $gateway;
143 143
 	$payment->form_title     = $form_title;
@@ -151,40 +151,40 @@  discard block
 block discarded – undo
151 151
 	$payment->ip             = give_get_ip();
152 152
 	$payment->key            = $payment_data['purchase_key'];
153 153
 	$payment->mode           = give_is_test_mode() ? 'test' : 'live';
154
-	$payment->parent_payment = ! empty( $payment_data['parent'] ) ? absint( $payment_data['parent'] ) : '';
154
+	$payment->parent_payment = ! empty($payment_data['parent']) ? absint($payment_data['parent']) : '';
155 155
 
156 156
 	//Add the donation
157 157
 	$args = array(
158 158
 		'price'    => $payment->total,
159 159
 		'price_id' => $payment->price_id,
160
-		'fees'     => isset( $payment_data['fees'] ) ? $payment_data['fees'] : array()
160
+		'fees'     => isset($payment_data['fees']) ? $payment_data['fees'] : array()
161 161
 	);
162 162
 
163
-	$payment->add_donation( $payment->form_id, $args );
163
+	$payment->add_donation($payment->form_id, $args);
164 164
 
165 165
 	//Set date if present
166
-	if ( isset( $payment_data['post_date'] ) ) {
166
+	if (isset($payment_data['post_date'])) {
167 167
 		$payment->date = $payment_data['post_date'];
168 168
 	}
169 169
 
170 170
 	//Handle sequential payments
171
-	if ( give_get_option( 'enable_sequential' ) ) {
171
+	if (give_get_option('enable_sequential')) {
172 172
 		$number          = give_get_next_payment_number();
173
-		$payment->number = give_format_payment_number( $number );
174
-		update_option( 'give_last_payment_number', $number );
173
+		$payment->number = give_format_payment_number($number);
174
+		update_option('give_last_payment_number', $number);
175 175
 	}
176 176
 
177 177
 	// Clear the user's purchased cache
178
-	delete_transient( 'give_user_' . $payment_data['user_info']['id'] . '_purchases' );
178
+	delete_transient('give_user_'.$payment_data['user_info']['id'].'_purchases');
179 179
 
180 180
 	//Save payment
181 181
 	$payment->save();
182 182
 
183 183
 	//Hook it
184
-	do_action( 'give_insert_payment', $payment->ID, $payment_data );
184
+	do_action('give_insert_payment', $payment->ID, $payment_data);
185 185
 
186 186
 	//Return payment ID upon success
187
-	if ( ! empty( $payment->ID ) ) {
187
+	if ( ! empty($payment->ID)) {
188 188
 		return $payment->ID;
189 189
 	}
190 190
 
@@ -203,9 +203,9 @@  discard block
 block discarded – undo
203 203
  *
204 204
  * @return bool
205 205
  */
206
-function give_update_payment_status( $payment_id, $new_status = 'publish' ) {
206
+function give_update_payment_status($payment_id, $new_status = 'publish') {
207 207
 
208
-	$payment         = new Give_Payment( $payment_id );
208
+	$payment         = new Give_Payment($payment_id);
209 209
 	$payment->status = $new_status;
210 210
 	$updated         = $payment->save();
211 211
 
@@ -225,52 +225,52 @@  discard block
 block discarded – undo
225 225
  *
226 226
  * @return void
227 227
  */
228
-function give_delete_purchase( $payment_id = 0, $update_customer = true ) {
228
+function give_delete_purchase($payment_id = 0, $update_customer = true) {
229 229
 	global $give_logs;
230 230
 
231
-	$payment     = new Give_Payment( $payment_id );
232
-	$amount      = give_get_payment_amount( $payment_id );
231
+	$payment     = new Give_Payment($payment_id);
232
+	$amount      = give_get_payment_amount($payment_id);
233 233
 	$status      = $payment->post_status;
234
-	$customer_id = give_get_payment_customer_id( $payment_id );
235
-	$customer    = new Give_Customer( $customer_id );
234
+	$customer_id = give_get_payment_customer_id($payment_id);
235
+	$customer    = new Give_Customer($customer_id);
236 236
 
237 237
 	//Only undo purchases that aren't these statuses
238
-	$dont_undo_statuses = apply_filters( 'give_undo_purchase_statuses', array(
238
+	$dont_undo_statuses = apply_filters('give_undo_purchase_statuses', array(
239 239
 		'pending',
240 240
 		'cancelled'
241
-	) );
241
+	));
242 242
 
243
-	if ( ! in_array( $status, $dont_undo_statuses ) ) {
244
-		give_undo_purchase( false, $payment_id );
243
+	if ( ! in_array($status, $dont_undo_statuses)) {
244
+		give_undo_purchase(false, $payment_id);
245 245
 	}
246 246
 
247
-	if ( $status == 'publish' ) {
247
+	if ($status == 'publish') {
248 248
 
249 249
 		// Only decrease earnings if they haven't already been decreased (or were never increased for this payment)
250
-		give_decrease_total_earnings( $amount );
250
+		give_decrease_total_earnings($amount);
251 251
 		// Clear the This Month earnings (this_monththis_month is NOT a typo)
252
-		delete_transient( md5( 'give_earnings_this_monththis_month' ) );
252
+		delete_transient(md5('give_earnings_this_monththis_month'));
253 253
 
254
-		if ( $customer->id && $update_customer ) {
254
+		if ($customer->id && $update_customer) {
255 255
 
256 256
 			// Decrement the stats for the customer
257 257
 			$customer->decrease_purchase_count();
258
-			$customer->decrease_value( $amount );
258
+			$customer->decrease_value($amount);
259 259
 
260 260
 		}
261 261
 	}
262 262
 
263
-	do_action( 'give_payment_delete', $payment_id );
263
+	do_action('give_payment_delete', $payment_id);
264 264
 
265
-	if ( $customer->id && $update_customer ) {
265
+	if ($customer->id && $update_customer) {
266 266
 
267 267
 		// Remove the payment ID from the customer
268
-		$customer->remove_payment( $payment_id );
268
+		$customer->remove_payment($payment_id);
269 269
 
270 270
 	}
271 271
 
272 272
 	// Remove the payment
273
-	wp_delete_post( $payment_id, true );
273
+	wp_delete_post($payment_id, true);
274 274
 
275 275
 	// Remove related sale log entries
276 276
 	$give_logs->delete_logs(
@@ -284,7 +284,7 @@  discard block
 block discarded – undo
284 284
 		)
285 285
 	);
286 286
 
287
-	do_action( 'give_payment_deleted', $payment_id );
287
+	do_action('give_payment_deleted', $payment_id);
288 288
 }
289 289
 
290 290
 /**
@@ -297,25 +297,25 @@  discard block
 block discarded – undo
297 297
  *
298 298
  * @return void
299 299
  */
300
-function give_undo_purchase( $form_id = false, $payment_id ) {
300
+function give_undo_purchase($form_id = false, $payment_id) {
301 301
 
302
-	if ( ! empty( $form_id ) ) {
302
+	if ( ! empty($form_id)) {
303 303
 		$form_id = false;
304
-		_give_deprected_argument( 'form_id', 'give_undo_purchase', '1.5' );
304
+		_give_deprected_argument('form_id', 'give_undo_purchase', '1.5');
305 305
 	}
306 306
 
307
-	$payment = new Give_Payment( $payment_id );
307
+	$payment = new Give_Payment($payment_id);
308 308
 
309
-	$maybe_decrease_earnings = apply_filters( 'give_decrease_earnings_on_undo', true, $payment, $payment->form_id );
310
-	if ( true === $maybe_decrease_earnings ) {
309
+	$maybe_decrease_earnings = apply_filters('give_decrease_earnings_on_undo', true, $payment, $payment->form_id);
310
+	if (true === $maybe_decrease_earnings) {
311 311
 		// decrease earnings
312
-		give_decrease_earnings( $payment->form_id, $payment->total );
312
+		give_decrease_earnings($payment->form_id, $payment->total);
313 313
 	}
314 314
 
315
-	$maybe_decrease_sales = apply_filters( 'give_decrease_sales_on_undo', true, $payment, $payment->form_id );
316
-	if ( true === $maybe_decrease_sales ) {
315
+	$maybe_decrease_sales = apply_filters('give_decrease_sales_on_undo', true, $payment, $payment->form_id);
316
+	if (true === $maybe_decrease_sales) {
317 317
 		// decrease purchase count
318
-		give_decrease_purchase_count( $payment->form_id );
318
+		give_decrease_purchase_count($payment->form_id);
319 319
 	}
320 320
 
321 321
 }
@@ -332,7 +332,7 @@  discard block
 block discarded – undo
332 332
  *
333 333
  * @return array $count Number of payments sorted by payment status
334 334
  */
335
-function give_count_payments( $args = array() ) {
335
+function give_count_payments($args = array()) {
336 336
 
337 337
 	global $wpdb;
338 338
 
@@ -344,18 +344,18 @@  discard block
 block discarded – undo
344 344
 		'form_id'    => null,
345 345
 	);
346 346
 
347
-	$args = wp_parse_args( $args, $defaults );
347
+	$args = wp_parse_args($args, $defaults);
348 348
 
349 349
 	$select = "SELECT p.post_status,count( * ) AS num_posts";
350 350
 	$join   = '';
351 351
 	$where  = "WHERE p.post_type = 'give_payment'";
352 352
 
353 353
 	// Count payments for a specific user
354
-	if ( ! empty( $args['user'] ) ) {
354
+	if ( ! empty($args['user'])) {
355 355
 
356
-		if ( is_email( $args['user'] ) ) {
356
+		if (is_email($args['user'])) {
357 357
 			$field = 'email';
358
-		} elseif ( is_numeric( $args['user'] ) ) {
358
+		} elseif (is_numeric($args['user'])) {
359 359
 			$field = 'id';
360 360
 		} else {
361 361
 			$field = '';
@@ -363,108 +363,108 @@  discard block
 block discarded – undo
363 363
 
364 364
 		$join = "LEFT JOIN $wpdb->postmeta m ON (p.ID = m.post_id)";
365 365
 
366
-		if ( ! empty( $field ) ) {
366
+		if ( ! empty($field)) {
367 367
 			$where .= "
368 368
 				AND m.meta_key = '_give_payment_user_{$field}'
369 369
 				AND m.meta_value = '{$args['user']}'";
370 370
 		}
371 371
 
372 372
 		// Count payments for a search
373
-	} elseif ( ! empty( $args['s'] ) ) {
373
+	} elseif ( ! empty($args['s'])) {
374 374
 
375
-		if ( is_email( $args['s'] ) || strlen( $args['s'] ) == 32 ) {
375
+		if (is_email($args['s']) || strlen($args['s']) == 32) {
376 376
 
377
-			if ( is_email( $args['s'] ) ) {
377
+			if (is_email($args['s'])) {
378 378
 				$field = '_give_payment_user_email';
379 379
 			} else {
380 380
 				$field = '_give_payment_purchase_key';
381 381
 			}
382 382
 
383 383
 			$join = "LEFT JOIN $wpdb->postmeta m ON (p.ID = m.post_id)";
384
-			$where .= $wpdb->prepare( "
384
+			$where .= $wpdb->prepare("
385 385
 				AND m.meta_key = %s
386 386
 				AND m.meta_value = %s",
387 387
 				$field,
388 388
 				$args['s']
389 389
 			);
390 390
 
391
-		} elseif ( '#' == substr( $args['s'], 0, 1 ) ) {
391
+		} elseif ('#' == substr($args['s'], 0, 1)) {
392 392
 
393
-			$search = str_replace( '#:', '', $args['s'] );
394
-			$search = str_replace( '#', '', $search );
393
+			$search = str_replace('#:', '', $args['s']);
394
+			$search = str_replace('#', '', $search);
395 395
 
396 396
 			$select = "SELECT p2.post_status,count( * ) AS num_posts ";
397 397
 			$join   = "LEFT JOIN $wpdb->postmeta m ON m.meta_key = '_give_log_payment_id' AND m.post_id = p.ID ";
398 398
 			$join .= "INNER JOIN $wpdb->posts p2 ON m.meta_value = p2.ID ";
399 399
 			$where = "WHERE p.post_type = 'give_log' ";
400
-			$where .= $wpdb->prepare( "AND p.post_parent = %d} ", $search );
400
+			$where .= $wpdb->prepare("AND p.post_parent = %d} ", $search);
401 401
 
402
-		} elseif ( is_numeric( $args['s'] ) ) {
402
+		} elseif (is_numeric($args['s'])) {
403 403
 
404 404
 			$join = "LEFT JOIN $wpdb->postmeta m ON (p.ID = m.post_id)";
405
-			$where .= $wpdb->prepare( "
405
+			$where .= $wpdb->prepare("
406 406
 				AND m.meta_key = '_give_payment_user_id'
407 407
 				AND m.meta_value = %d",
408 408
 				$args['s']
409 409
 			);
410 410
 
411 411
 		} else {
412
-			$search = $wpdb->esc_like( $args['s'] );
413
-			$search = '%' . $search . '%';
412
+			$search = $wpdb->esc_like($args['s']);
413
+			$search = '%'.$search.'%';
414 414
 
415
-			$where .= $wpdb->prepare( "AND ((p.post_title LIKE %s) OR (p.post_content LIKE %s))", $search, $search );
415
+			$where .= $wpdb->prepare("AND ((p.post_title LIKE %s) OR (p.post_content LIKE %s))", $search, $search);
416 416
 		}
417 417
 
418 418
 	}
419 419
 
420
-	if ( ! empty( $args['form_id'] ) && is_numeric( $args['form_id'] ) ) {
420
+	if ( ! empty($args['form_id']) && is_numeric($args['form_id'])) {
421 421
 
422
-		$where .= $wpdb->prepare( " AND p.post_parent = %d", $args['form_id'] );
422
+		$where .= $wpdb->prepare(" AND p.post_parent = %d", $args['form_id']);
423 423
 
424 424
 	}
425 425
 	// Limit payments count by date
426
-	if ( ! empty( $args['start-date'] ) && false !== strpos( $args['start-date'], '/' ) ) {
426
+	if ( ! empty($args['start-date']) && false !== strpos($args['start-date'], '/')) {
427 427
 
428
-		$date_parts = explode( '/', $args['start-date'] );
429
-		$month      = ! empty( $date_parts[0] ) && is_numeric( $date_parts[0] ) ? $date_parts[0] : 0;
430
-		$day        = ! empty( $date_parts[1] ) && is_numeric( $date_parts[1] ) ? $date_parts[1] : 0;
431
-		$year       = ! empty( $date_parts[2] ) && is_numeric( $date_parts[2] ) ? $date_parts[2] : 0;
428
+		$date_parts = explode('/', $args['start-date']);
429
+		$month      = ! empty($date_parts[0]) && is_numeric($date_parts[0]) ? $date_parts[0] : 0;
430
+		$day        = ! empty($date_parts[1]) && is_numeric($date_parts[1]) ? $date_parts[1] : 0;
431
+		$year       = ! empty($date_parts[2]) && is_numeric($date_parts[2]) ? $date_parts[2] : 0;
432 432
 
433
-		$is_date = checkdate( $month, $day, $year );
434
-		if ( false !== $is_date ) {
433
+		$is_date = checkdate($month, $day, $year);
434
+		if (false !== $is_date) {
435 435
 
436
-			$date = new DateTime( $args['start-date'] );
437
-			$where .= $wpdb->prepare( " AND p.post_date >= '%s'", $date->format( 'Y-m-d' ) );
436
+			$date = new DateTime($args['start-date']);
437
+			$where .= $wpdb->prepare(" AND p.post_date >= '%s'", $date->format('Y-m-d'));
438 438
 
439 439
 		}
440 440
 
441 441
 		// Fixes an issue with the payments list table counts when no end date is specified (partiy with stats class)
442
-		if ( empty( $args['end-date'] ) ) {
442
+		if (empty($args['end-date'])) {
443 443
 			$args['end-date'] = $args['start-date'];
444 444
 		}
445 445
 
446 446
 	}
447 447
 
448
-	if ( ! empty ( $args['end-date'] ) && false !== strpos( $args['end-date'], '/' ) ) {
448
+	if ( ! empty ($args['end-date']) && false !== strpos($args['end-date'], '/')) {
449 449
 
450
-		$date_parts = explode( '/', $args['end-date'] );
450
+		$date_parts = explode('/', $args['end-date']);
451 451
 
452
-		$month = ! empty( $date_parts[0] ) ? $date_parts[0] : 0;
453
-		$day   = ! empty( $date_parts[1] ) ? $date_parts[1] : 0;
454
-		$year  = ! empty( $date_parts[2] ) ? $date_parts[2] : 0;
452
+		$month = ! empty($date_parts[0]) ? $date_parts[0] : 0;
453
+		$day   = ! empty($date_parts[1]) ? $date_parts[1] : 0;
454
+		$year  = ! empty($date_parts[2]) ? $date_parts[2] : 0;
455 455
 
456
-		$is_date = checkdate( $month, $day, $year );
457
-		if ( false !== $is_date ) {
456
+		$is_date = checkdate($month, $day, $year);
457
+		if (false !== $is_date) {
458 458
 
459
-			$date = new DateTime( $args['end-date'] );
460
-			$where .= $wpdb->prepare( " AND p.post_date <= '%s'", $date->format( 'Y-m-d' ) );
459
+			$date = new DateTime($args['end-date']);
460
+			$where .= $wpdb->prepare(" AND p.post_date <= '%s'", $date->format('Y-m-d'));
461 461
 
462 462
 		}
463 463
 
464 464
 	}
465 465
 
466
-	$where = apply_filters( 'give_count_payments_where', $where );
467
-	$join  = apply_filters( 'give_count_payments_join', $join );
466
+	$where = apply_filters('give_count_payments_where', $where);
467
+	$join  = apply_filters('give_count_payments_join', $join);
468 468
 
469 469
 	$query = "$select
470 470
 		FROM $wpdb->posts p
@@ -473,36 +473,36 @@  discard block
 block discarded – undo
473 473
 		GROUP BY p.post_status
474 474
 	";
475 475
 
476
-	$cache_key = md5( $query );
476
+	$cache_key = md5($query);
477 477
 
478
-	$count = wp_cache_get( $cache_key, 'counts' );
479
-	if ( false !== $count ) {
478
+	$count = wp_cache_get($cache_key, 'counts');
479
+	if (false !== $count) {
480 480
 		return $count;
481 481
 	}
482 482
 
483
-	$count = $wpdb->get_results( $query, ARRAY_A );
483
+	$count = $wpdb->get_results($query, ARRAY_A);
484 484
 
485 485
 	$stats    = array();
486 486
 	$statuses = get_post_stati();
487
-	if ( isset( $statuses['private'] ) && empty( $args['s'] ) ) {
488
-		unset( $statuses['private'] );
487
+	if (isset($statuses['private']) && empty($args['s'])) {
488
+		unset($statuses['private']);
489 489
 	}
490 490
 
491
-	foreach ( $statuses as $state ) {
492
-		$stats[ $state ] = 0;
491
+	foreach ($statuses as $state) {
492
+		$stats[$state] = 0;
493 493
 	}
494 494
 
495
-	foreach ( (array) $count as $row ) {
495
+	foreach ((array) $count as $row) {
496 496
 
497
-		if ( 'private' == $row['post_status'] && empty( $args['s'] ) ) {
497
+		if ('private' == $row['post_status'] && empty($args['s'])) {
498 498
 			continue;
499 499
 		}
500 500
 
501
-		$stats[ $row['post_status'] ] = $row['num_posts'];
501
+		$stats[$row['post_status']] = $row['num_posts'];
502 502
 	}
503 503
 
504 504
 	$stats = (object) $stats;
505
-	wp_cache_set( $cache_key, $stats, 'counts' );
505
+	wp_cache_set($cache_key, $stats, 'counts');
506 506
 
507 507
 	return $stats;
508 508
 }
@@ -517,12 +517,12 @@  discard block
 block discarded – undo
517 517
  *
518 518
  * @return bool true if payment exists, false otherwise
519 519
  */
520
-function give_check_for_existing_payment( $payment_id ) {
520
+function give_check_for_existing_payment($payment_id) {
521 521
 	$exists  = false;
522
-	$payment = new Give_Payment( $payment_id );
522
+	$payment = new Give_Payment($payment_id);
523 523
 
524 524
 
525
-	if ( $payment_id === $payment->ID && 'publish' === $payment->status ) {
525
+	if ($payment_id === $payment->ID && 'publish' === $payment->status) {
526 526
 		$exists = true;
527 527
 	}
528 528
 
@@ -539,29 +539,29 @@  discard block
 block discarded – undo
539 539
  *
540 540
  * @return bool|mixed if payment status exists, false otherwise
541 541
  */
542
-function give_get_payment_status( $payment, $return_label = false ) {
542
+function give_get_payment_status($payment, $return_label = false) {
543 543
 
544
-	if ( ! is_object( $payment ) || ! isset( $payment->post_status ) ) {
544
+	if ( ! is_object($payment) || ! isset($payment->post_status)) {
545 545
 		return false;
546 546
 	}
547 547
 
548 548
 	$statuses = give_get_payment_statuses();
549 549
 
550
-	if ( ! is_array( $statuses ) || empty( $statuses ) ) {
550
+	if ( ! is_array($statuses) || empty($statuses)) {
551 551
 		return false;
552 552
 	}
553 553
 
554
-	$payment = new Give_Payment( $payment->ID );
554
+	$payment = new Give_Payment($payment->ID);
555 555
 
556
-	if ( array_key_exists( $payment->status, $statuses ) ) {
557
-		if ( true === $return_label ) {
558
-			return $statuses[ $payment->status ];
556
+	if (array_key_exists($payment->status, $statuses)) {
557
+		if (true === $return_label) {
558
+			return $statuses[$payment->status];
559 559
 		} else {
560 560
 			// Account that our 'publish' status is labeled 'Complete'
561 561
 			$post_status = 'publish' == $payment->status ? 'Complete' : $payment->post_status;
562 562
 
563 563
 			// Make sure we're matching cases, since they matter
564
-			return array_search( strtolower( $post_status ), array_map( 'strtolower', $statuses ) );
564
+			return array_search(strtolower($post_status), array_map('strtolower', $statuses));
565 565
 		}
566 566
 	}
567 567
 
@@ -576,17 +576,17 @@  discard block
 block discarded – undo
576 576
  */
577 577
 function give_get_payment_statuses() {
578 578
 	$payment_statuses = array(
579
-		'pending'     => __( 'Pending', 'give' ),
580
-		'publish'     => __( 'Complete', 'give' ),
581
-		'refunded'    => __( 'Refunded', 'give' ),
582
-		'failed'      => __( 'Failed', 'give' ),
583
-		'cancelled'   => __( 'Cancelled', 'give' ),
584
-		'abandoned'   => __( 'Abandoned', 'give' ),
585
-		'preapproval' => __( 'Pre-Approved', 'give' ),
586
-		'revoked'     => __( 'Revoked', 'give' )
579
+		'pending'     => __('Pending', 'give'),
580
+		'publish'     => __('Complete', 'give'),
581
+		'refunded'    => __('Refunded', 'give'),
582
+		'failed'      => __('Failed', 'give'),
583
+		'cancelled'   => __('Cancelled', 'give'),
584
+		'abandoned'   => __('Abandoned', 'give'),
585
+		'preapproval' => __('Pre-Approved', 'give'),
586
+		'revoked'     => __('Revoked', 'give')
587 587
 	);
588 588
 
589
-	return apply_filters( 'give_payment_statuses', $payment_statuses );
589
+	return apply_filters('give_payment_statuses', $payment_statuses);
590 590
 }
591 591
 
592 592
 /**
@@ -598,10 +598,10 @@  discard block
 block discarded – undo
598 598
  * @return array $payment_status All the available payment statuses
599 599
  */
600 600
 function give_get_payment_status_keys() {
601
-	$statuses = array_keys( give_get_payment_statuses() );
602
-	asort( $statuses );
601
+	$statuses = array_keys(give_get_payment_statuses());
602
+	asort($statuses);
603 603
 
604
-	return array_values( $statuses );
604
+	return array_values($statuses);
605 605
 }
606 606
 
607 607
 /**
@@ -616,7 +616,7 @@  discard block
 block discarded – undo
616 616
  *
617 617
  * @return int $earnings Earnings
618 618
  */
619
-function give_get_earnings_by_date( $day = null, $month_num, $year = null, $hour = null ) {
619
+function give_get_earnings_by_date($day = null, $month_num, $year = null, $hour = null) {
620 620
 
621 621
 	// This is getting deprecated soon. Use Give_Payment_Stats with the get_earnings() method instead
622 622
 
@@ -627,41 +627,41 @@  discard block
 block discarded – undo
627 627
 		'nopaging'               => true,
628 628
 		'year'                   => $year,
629 629
 		'monthnum'               => $month_num,
630
-		'post_status'            => array( 'publish', 'revoked' ),
630
+		'post_status'            => array('publish', 'revoked'),
631 631
 		'fields'                 => 'ids',
632 632
 		'update_post_term_cache' => false
633 633
 	);
634
-	if ( ! empty( $day ) ) {
634
+	if ( ! empty($day)) {
635 635
 		$args['day'] = $day;
636 636
 	}
637 637
 
638
-	if ( ! empty( $hour ) ) {
638
+	if ( ! empty($hour)) {
639 639
 		$args['hour'] = $hour;
640 640
 	}
641 641
 
642
-	$args = apply_filters( 'give_get_earnings_by_date_args', $args );
643
-	$key  = 'give_stats_' . substr( md5( serialize( $args ) ), 0, 15 );
642
+	$args = apply_filters('give_get_earnings_by_date_args', $args);
643
+	$key  = 'give_stats_'.substr(md5(serialize($args)), 0, 15);
644 644
 
645
-	if ( ! empty( $_GET['_wpnonce'] ) && wp_verify_nonce( $_GET['_wpnonce'], 'give-refresh-reports' ) ) {
645
+	if ( ! empty($_GET['_wpnonce']) && wp_verify_nonce($_GET['_wpnonce'], 'give-refresh-reports')) {
646 646
 		$earnings = false;
647 647
 	} else {
648
-		$earnings = get_transient( $key );
648
+		$earnings = get_transient($key);
649 649
 	}
650 650
 
651
-	if ( false === $earnings ) {
652
-		$sales    = get_posts( $args );
651
+	if (false === $earnings) {
652
+		$sales    = get_posts($args);
653 653
 		$earnings = 0;
654
-		if ( $sales ) {
655
-			$sales = implode( ',', $sales );
654
+		if ($sales) {
655
+			$sales = implode(',', $sales);
656 656
 
657
-			$earnings = $wpdb->get_var( "SELECT SUM(meta_value) FROM $wpdb->postmeta WHERE meta_key = '_give_payment_total' AND post_id IN ({$sales})" );
657
+			$earnings = $wpdb->get_var("SELECT SUM(meta_value) FROM $wpdb->postmeta WHERE meta_key = '_give_payment_total' AND post_id IN ({$sales})");
658 658
 
659 659
 		}
660 660
 		// Cache the results for one hour
661
-		set_transient( $key, $earnings, HOUR_IN_SECONDS );
661
+		set_transient($key, $earnings, HOUR_IN_SECONDS);
662 662
 	}
663 663
 
664
-	return round( $earnings, 2 );
664
+	return round($earnings, 2);
665 665
 }
666 666
 
667 667
 /**
@@ -676,7 +676,7 @@  discard block
 block discarded – undo
676 676
  *
677 677
  * @return int $count Sales
678 678
  */
679
-function give_get_sales_by_date( $day = null, $month_num = null, $year = null, $hour = null ) {
679
+function give_get_sales_by_date($day = null, $month_num = null, $year = null, $hour = null) {
680 680
 
681 681
 	// This is getting deprecated soon. Use Give_Payment_Stats with the get_sales() method instead
682 682
 	$args = array(
@@ -684,14 +684,14 @@  discard block
 block discarded – undo
684 684
 		'nopaging'               => true,
685 685
 		'year'                   => $year,
686 686
 		'fields'                 => 'ids',
687
-		'post_status'            => array( 'publish', 'revoked' ),
687
+		'post_status'            => array('publish', 'revoked'),
688 688
 		'update_post_meta_cache' => false,
689 689
 		'update_post_term_cache' => false
690 690
 	);
691 691
 
692
-	$show_free = apply_filters( 'give_sales_by_date_show_free', true, $args );
692
+	$show_free = apply_filters('give_sales_by_date_show_free', true, $args);
693 693
 
694
-	if ( false === $show_free ) {
694
+	if (false === $show_free) {
695 695
 		$args['meta_query'] = array(
696 696
 			array(
697 697
 				'key'     => '_give_payment_total',
@@ -702,33 +702,33 @@  discard block
 block discarded – undo
702 702
 		);
703 703
 	}
704 704
 
705
-	if ( ! empty( $month_num ) ) {
705
+	if ( ! empty($month_num)) {
706 706
 		$args['monthnum'] = $month_num;
707 707
 	}
708 708
 
709
-	if ( ! empty( $day ) ) {
709
+	if ( ! empty($day)) {
710 710
 		$args['day'] = $day;
711 711
 	}
712 712
 
713
-	if ( ! empty( $hour ) ) {
713
+	if ( ! empty($hour)) {
714 714
 		$args['hour'] = $hour;
715 715
 	}
716 716
 
717
-	$args = apply_filters( 'give_get_sales_by_date_args', $args );
717
+	$args = apply_filters('give_get_sales_by_date_args', $args);
718 718
 
719
-	$key = 'give_stats_' . substr( md5( serialize( $args ) ), 0, 15 );
719
+	$key = 'give_stats_'.substr(md5(serialize($args)), 0, 15);
720 720
 
721
-	if ( ! empty( $_GET['_wpnonce'] ) && wp_verify_nonce( $_GET['_wpnonce'], 'give-refresh-reports' ) ) {
721
+	if ( ! empty($_GET['_wpnonce']) && wp_verify_nonce($_GET['_wpnonce'], 'give-refresh-reports')) {
722 722
 		$count = false;
723 723
 	} else {
724
-		$count = get_transient( $key );
724
+		$count = get_transient($key);
725 725
 	}
726 726
 
727
-	if ( false === $count ) {
728
-		$sales = new WP_Query( $args );
727
+	if (false === $count) {
728
+		$sales = new WP_Query($args);
729 729
 		$count = (int) $sales->post_count;
730 730
 		// Cache the results for one hour
731
-		set_transient( $key, $count, HOUR_IN_SECONDS );
731
+		set_transient($key, $count, HOUR_IN_SECONDS);
732 732
 	}
733 733
 
734 734
 	return $count;
@@ -743,20 +743,20 @@  discard block
 block discarded – undo
743 743
  *
744 744
  * @return bool true if complete, false otherwise
745 745
  */
746
-function give_is_payment_complete( $payment_id ) {
747
-	$payment = new Give_Payment( $payment_id );
746
+function give_is_payment_complete($payment_id) {
747
+	$payment = new Give_Payment($payment_id);
748 748
 
749 749
 	$ret = false;
750 750
 
751
-	if ( $payment->ID > 0 ) {
751
+	if ($payment->ID > 0) {
752 752
 
753
-		if ( (int) $payment_id === (int) $payment->ID && 'publish' == $payment->status ) {
753
+		if ((int) $payment_id === (int) $payment->ID && 'publish' == $payment->status) {
754 754
 			$ret = true;
755 755
 		}
756 756
 
757 757
 	}
758 758
 
759
-	return apply_filters( 'give_is_payment_complete', $ret, $payment_id, $payment->post_status );
759
+	return apply_filters('give_is_payment_complete', $ret, $payment_id, $payment->post_status);
760 760
 }
761 761
 
762 762
 /**
@@ -780,29 +780,29 @@  discard block
 block discarded – undo
780 780
  */
781 781
 function give_get_total_earnings() {
782 782
 
783
-	$total = get_option( 'give_earnings_total', false );
783
+	$total = get_option('give_earnings_total', false);
784 784
 
785 785
 	// If no total stored in DB, use old method of calculating total earnings
786
-	if ( false === $total ) {
786
+	if (false === $total) {
787 787
 
788 788
 		global $wpdb;
789 789
 
790
-		$total = get_transient( 'give_earnings_total' );
790
+		$total = get_transient('give_earnings_total');
791 791
 
792
-		if ( false === $total ) {
792
+		if (false === $total) {
793 793
 
794 794
 			$total = (float) 0;
795 795
 
796
-			$args = apply_filters( 'give_get_total_earnings_args', array(
796
+			$args = apply_filters('give_get_total_earnings_args', array(
797 797
 				'offset' => 0,
798
-				'number' => - 1,
799
-				'status' => array( 'publish', 'revoked' ),
798
+				'number' => -1,
799
+				'status' => array('publish', 'revoked'),
800 800
 				'fields' => 'ids'
801
-			) );
801
+			));
802 802
 
803 803
 
804
-			$payments = give_get_payments( $args );
805
-			if ( $payments ) {
804
+			$payments = give_get_payments($args);
805
+			if ($payments) {
806 806
 
807 807
 				/*
808 808
 				 * If performing a purchase, we need to skip the very last payment in the database, since it calls
@@ -810,30 +810,30 @@  discard block
 block discarded – undo
810 810
 				 * first purchase
811 811
 				 */
812 812
 
813
-				if ( did_action( 'give_update_payment_status' ) ) {
814
-					array_pop( $payments );
813
+				if (did_action('give_update_payment_status')) {
814
+					array_pop($payments);
815 815
 				}
816 816
 
817
-				if ( ! empty( $payments ) ) {
818
-					$payments = implode( ',', $payments );
819
-					$total += $wpdb->get_var( "SELECT SUM(meta_value) FROM $wpdb->postmeta WHERE meta_key = '_give_payment_total' AND post_id IN({$payments})" );
817
+				if ( ! empty($payments)) {
818
+					$payments = implode(',', $payments);
819
+					$total += $wpdb->get_var("SELECT SUM(meta_value) FROM $wpdb->postmeta WHERE meta_key = '_give_payment_total' AND post_id IN({$payments})");
820 820
 				}
821 821
 
822 822
 			}
823 823
 
824 824
 			// Cache results for 1 day. This cache is cleared automatically when a payment is made
825
-			set_transient( 'give_earnings_total', $total, 86400 );
825
+			set_transient('give_earnings_total', $total, 86400);
826 826
 
827 827
 			// Store the total for the first time
828
-			update_option( 'give_earnings_total', $total );
828
+			update_option('give_earnings_total', $total);
829 829
 		}
830 830
 	}
831 831
 
832
-	if ( $total < 0 ) {
832
+	if ($total < 0) {
833 833
 		$total = 0; // Don't ever show negative earnings
834 834
 	}
835 835
 
836
-	return apply_filters( 'give_total_earnings', round( $total, give_currency_decimal_filter() ) );
836
+	return apply_filters('give_total_earnings', round($total, give_currency_decimal_filter()));
837 837
 }
838 838
 
839 839
 /**
@@ -845,10 +845,10 @@  discard block
 block discarded – undo
845 845
  *
846 846
  * @return float $total Total earnings
847 847
  */
848
-function give_increase_total_earnings( $amount = 0 ) {
848
+function give_increase_total_earnings($amount = 0) {
849 849
 	$total = give_get_total_earnings();
850 850
 	$total += $amount;
851
-	update_option( 'give_earnings_total', $total );
851
+	update_option('give_earnings_total', $total);
852 852
 
853 853
 	return $total;
854 854
 }
@@ -862,13 +862,13 @@  discard block
 block discarded – undo
862 862
  *
863 863
  * @return float $total Total earnings
864 864
  */
865
-function give_decrease_total_earnings( $amount = 0 ) {
865
+function give_decrease_total_earnings($amount = 0) {
866 866
 	$total = give_get_total_earnings();
867 867
 	$total -= $amount;
868
-	if ( $total < 0 ) {
868
+	if ($total < 0) {
869 869
 		$total = 0;
870 870
 	}
871
-	update_option( 'give_earnings_total', $total );
871
+	update_option('give_earnings_total', $total);
872 872
 
873 873
 	return $total;
874 874
 }
@@ -884,10 +884,10 @@  discard block
 block discarded – undo
884 884
  *
885 885
  * @return mixed $meta Payment Meta
886 886
  */
887
-function give_get_payment_meta( $payment_id = 0, $meta_key = '_give_payment_meta', $single = true ) {
888
-	$payment = new Give_Payment( $payment_id );
887
+function give_get_payment_meta($payment_id = 0, $meta_key = '_give_payment_meta', $single = true) {
888
+	$payment = new Give_Payment($payment_id);
889 889
 
890
-	return $payment->get_meta( $meta_key, $single );
890
+	return $payment->get_meta($meta_key, $single);
891 891
 }
892 892
 
893 893
 /**
@@ -900,10 +900,10 @@  discard block
 block discarded – undo
900 900
  *
901 901
  * @return mixed               Meta ID if successful, false if unsuccessful
902 902
  */
903
-function give_update_payment_meta( $payment_id = 0, $meta_key = '', $meta_value = '', $prev_value = '' ) {
904
-	$payment = new Give_Payment( $payment_id );
903
+function give_update_payment_meta($payment_id = 0, $meta_key = '', $meta_value = '', $prev_value = '') {
904
+	$payment = new Give_Payment($payment_id);
905 905
 
906
-	return $payment->update_meta( $meta_key, $meta_value, $prev_value );
906
+	return $payment->update_meta($meta_key, $meta_value, $prev_value);
907 907
 }
908 908
 
909 909
 /**
@@ -915,8 +915,8 @@  discard block
 block discarded – undo
915 915
  *
916 916
  * @return array $user_info User Info Meta Values
917 917
  */
918
-function give_get_payment_meta_user_info( $payment_id ) {
919
-	$payment = new Give_Payment( $payment_id );
918
+function give_get_payment_meta_user_info($payment_id) {
919
+	$payment = new Give_Payment($payment_id);
920 920
 
921 921
 	return $payment->user_info;
922 922
 }
@@ -931,8 +931,8 @@  discard block
 block discarded – undo
931 931
  *
932 932
  * @return int $form_id
933 933
  */
934
-function give_get_payment_form_id( $payment_id ) {
935
-	$payment = new Give_Payment( $payment_id );
934
+function give_get_payment_form_id($payment_id) {
935
+	$payment = new Give_Payment($payment_id);
936 936
 
937 937
 	return $payment->form_id;
938 938
 }
@@ -946,8 +946,8 @@  discard block
 block discarded – undo
946 946
  *
947 947
  * @return string $email User Email
948 948
  */
949
-function give_get_payment_user_email( $payment_id ) {
950
-	$payment = new Give_Payment( $payment_id );
949
+function give_get_payment_user_email($payment_id) {
950
+	$payment = new Give_Payment($payment_id);
951 951
 
952 952
 	return $payment->email;
953 953
 }
@@ -961,11 +961,11 @@  discard block
 block discarded – undo
961 961
  *
962 962
  * @return bool            If the payment is associated with a user (false) or not (true)
963 963
  */
964
-function give_is_guest_payment( $payment_id ) {
965
-	$payment_user_id  = give_get_payment_user_id( $payment_id );
966
-	$is_guest_payment = ! empty( $payment_user_id ) && $payment_user_id > 0 ? false : true;
964
+function give_is_guest_payment($payment_id) {
965
+	$payment_user_id  = give_get_payment_user_id($payment_id);
966
+	$is_guest_payment = ! empty($payment_user_id) && $payment_user_id > 0 ? false : true;
967 967
 
968
-	return (bool) apply_filters( 'give_is_guest_payment', $is_guest_payment, $payment_id );
968
+	return (bool) apply_filters('give_is_guest_payment', $is_guest_payment, $payment_id);
969 969
 }
970 970
 
971 971
 /**
@@ -977,8 +977,8 @@  discard block
 block discarded – undo
977 977
  *
978 978
  * @return string $user_id User ID
979 979
  */
980
-function give_get_payment_user_id( $payment_id ) {
981
-	$payment = new Give_Payment( $payment_id );
980
+function give_get_payment_user_id($payment_id) {
981
+	$payment = new Give_Payment($payment_id);
982 982
 
983 983
 	return $payment->user_id;
984 984
 }
@@ -992,8 +992,8 @@  discard block
 block discarded – undo
992 992
  *
993 993
  * @return string $customer_id Customer ID
994 994
  */
995
-function give_get_payment_customer_id( $payment_id ) {
996
-	$payment = new Give_Payment( $payment_id );
995
+function give_get_payment_customer_id($payment_id) {
996
+	$payment = new Give_Payment($payment_id);
997 997
 
998 998
 	return $payment->customer_id;
999 999
 }
@@ -1007,8 +1007,8 @@  discard block
 block discarded – undo
1007 1007
  *
1008 1008
  * @return string $ip User IP
1009 1009
  */
1010
-function give_get_payment_user_ip( $payment_id ) {
1011
-	$payment = new Give_Payment( $payment_id );
1010
+function give_get_payment_user_ip($payment_id) {
1011
+	$payment = new Give_Payment($payment_id);
1012 1012
 
1013 1013
 	return $payment->ip;
1014 1014
 }
@@ -1022,8 +1022,8 @@  discard block
 block discarded – undo
1022 1022
  *
1023 1023
  * @return string $date The date the payment was completed
1024 1024
  */
1025
-function give_get_payment_completed_date( $payment_id = 0 ) {
1026
-	$payment = new Give_Payment( $payment_id );
1025
+function give_get_payment_completed_date($payment_id = 0) {
1026
+	$payment = new Give_Payment($payment_id);
1027 1027
 
1028 1028
 	return $payment->completed_date;
1029 1029
 }
@@ -1037,8 +1037,8 @@  discard block
 block discarded – undo
1037 1037
  *
1038 1038
  * @return string $gateway Gateway
1039 1039
  */
1040
-function give_get_payment_gateway( $payment_id ) {
1041
-	$payment = new Give_Payment( $payment_id );
1040
+function give_get_payment_gateway($payment_id) {
1041
+	$payment = new Give_Payment($payment_id);
1042 1042
 
1043 1043
 	return $payment->gateway;
1044 1044
 }
@@ -1052,8 +1052,8 @@  discard block
 block discarded – undo
1052 1052
  *
1053 1053
  * @return string $currency The currency code
1054 1054
  */
1055
-function give_get_payment_currency_code( $payment_id = 0 ) {
1056
-	$payment = new Give_Payment( $payment_id );
1055
+function give_get_payment_currency_code($payment_id = 0) {
1056
+	$payment = new Give_Payment($payment_id);
1057 1057
 
1058 1058
 	return $payment->currency;
1059 1059
 }
@@ -1067,10 +1067,10 @@  discard block
 block discarded – undo
1067 1067
  *
1068 1068
  * @return string $currency The currency name
1069 1069
  */
1070
-function give_get_payment_currency( $payment_id = 0 ) {
1071
-	$currency = give_get_payment_currency_code( $payment_id );
1070
+function give_get_payment_currency($payment_id = 0) {
1071
+	$currency = give_get_payment_currency_code($payment_id);
1072 1072
 
1073
-	return apply_filters( 'give_payment_currency', give_get_currency_name( $currency ), $payment_id );
1073
+	return apply_filters('give_payment_currency', give_get_currency_name($currency), $payment_id);
1074 1074
 }
1075 1075
 
1076 1076
 /**
@@ -1082,8 +1082,8 @@  discard block
 block discarded – undo
1082 1082
  *
1083 1083
  * @return string $key Purchase key
1084 1084
  */
1085
-function give_get_payment_key( $payment_id = 0 ) {
1086
-	$payment = new Give_Payment( $payment_id );
1085
+function give_get_payment_key($payment_id = 0) {
1086
+	$payment = new Give_Payment($payment_id);
1087 1087
 
1088 1088
 	return $payment->key;
1089 1089
 }
@@ -1099,8 +1099,8 @@  discard block
 block discarded – undo
1099 1099
  *
1100 1100
  * @return string $number Payment order number
1101 1101
  */
1102
-function give_get_payment_number( $payment_id = 0 ) {
1103
-	$payment = new Give_Payment( $payment_id );
1102
+function give_get_payment_number($payment_id = 0) {
1103
+	$payment = new Give_Payment($payment_id);
1104 1104
 
1105 1105
 	return $payment->number;
1106 1106
 }
@@ -1114,23 +1114,23 @@  discard block
 block discarded – undo
1114 1114
  *
1115 1115
  * @return string      The formatted payment number
1116 1116
  */
1117
-function give_format_payment_number( $number ) {
1117
+function give_format_payment_number($number) {
1118 1118
 
1119
-	if ( ! give_get_option( 'enable_sequential' ) ) {
1119
+	if ( ! give_get_option('enable_sequential')) {
1120 1120
 		return $number;
1121 1121
 	}
1122 1122
 
1123
-	if ( ! is_numeric( $number ) ) {
1123
+	if ( ! is_numeric($number)) {
1124 1124
 		return $number;
1125 1125
 	}
1126 1126
 
1127
-	$prefix  = give_get_option( 'sequential_prefix' );
1128
-	$number  = absint( $number );
1129
-	$postfix = give_get_option( 'sequential_postfix' );
1127
+	$prefix  = give_get_option('sequential_prefix');
1128
+	$number  = absint($number);
1129
+	$postfix = give_get_option('sequential_postfix');
1130 1130
 
1131
-	$formatted_number = $prefix . $number . $postfix;
1131
+	$formatted_number = $prefix.$number.$postfix;
1132 1132
 
1133
-	return apply_filters( 'give_format_payment_number', $formatted_number, $prefix, $number, $postfix );
1133
+	return apply_filters('give_format_payment_number', $formatted_number, $prefix, $number, $postfix);
1134 1134
 }
1135 1135
 
1136 1136
 /**
@@ -1143,17 +1143,17 @@  discard block
 block discarded – undo
1143 1143
  */
1144 1144
 function give_get_next_payment_number() {
1145 1145
 
1146
-	if ( ! give_get_option( 'enable_sequential' ) ) {
1146
+	if ( ! give_get_option('enable_sequential')) {
1147 1147
 		return false;
1148 1148
 	}
1149 1149
 
1150
-	$number           = get_option( 'give_last_payment_number' );
1151
-	$start            = give_get_option( 'sequential_start', 1 );
1150
+	$number           = get_option('give_last_payment_number');
1151
+	$start            = give_get_option('sequential_start', 1);
1152 1152
 	$increment_number = true;
1153 1153
 
1154
-	if ( false !== $number ) {
1154
+	if (false !== $number) {
1155 1155
 
1156
-		if ( empty( $number ) ) {
1156
+		if (empty($number)) {
1157 1157
 
1158 1158
 			$number           = $start;
1159 1159
 			$increment_number = false;
@@ -1163,24 +1163,24 @@  discard block
 block discarded – undo
1163 1163
 	} else {
1164 1164
 
1165 1165
 		// This case handles the first addition of the new option, as well as if it get's deleted for any reason
1166
-		$payments     = new Give_Payments_Query( array(
1166
+		$payments = new Give_Payments_Query(array(
1167 1167
 			'number'  => 1,
1168 1168
 			'order'   => 'DESC',
1169 1169
 			'orderby' => 'ID',
1170 1170
 			'output'  => 'posts',
1171 1171
 			'fields'  => 'ids'
1172
-		) );
1172
+		));
1173 1173
 		$last_payment = $payments->get_payments();
1174 1174
 
1175
-		if ( ! empty( $last_payment ) ) {
1175
+		if ( ! empty($last_payment)) {
1176 1176
 
1177
-			$number = give_get_payment_number( $last_payment[0] );
1177
+			$number = give_get_payment_number($last_payment[0]);
1178 1178
 
1179 1179
 		}
1180 1180
 
1181
-		if ( ! empty( $number ) && $number !== (int) $last_payment[0] ) {
1181
+		if ( ! empty($number) && $number !== (int) $last_payment[0]) {
1182 1182
 
1183
-			$number = give_remove_payment_prefix_postfix( $number );
1183
+			$number = give_remove_payment_prefix_postfix($number);
1184 1184
 
1185 1185
 		} else {
1186 1186
 
@@ -1190,13 +1190,13 @@  discard block
 block discarded – undo
1190 1190
 
1191 1191
 	}
1192 1192
 
1193
-	$increment_number = apply_filters( 'give_increment_payment_number', $increment_number, $number );
1193
+	$increment_number = apply_filters('give_increment_payment_number', $increment_number, $number);
1194 1194
 
1195
-	if ( $increment_number ) {
1196
-		$number ++;
1195
+	if ($increment_number) {
1196
+		$number++;
1197 1197
 	}
1198 1198
 
1199
-	return apply_filters( 'give_get_next_payment_number', $number );
1199
+	return apply_filters('give_get_next_payment_number', $number);
1200 1200
 }
1201 1201
 
1202 1202
 /**
@@ -1208,25 +1208,25 @@  discard block
 block discarded – undo
1208 1208
  *
1209 1209
  * @return string          The new Payment number without prefix and postfix
1210 1210
  */
1211
-function give_remove_payment_prefix_postfix( $number ) {
1211
+function give_remove_payment_prefix_postfix($number) {
1212 1212
 
1213
-	$prefix  = give_get_option( 'sequential_prefix' );
1214
-	$postfix = give_get_option( 'sequential_postfix' );
1213
+	$prefix  = give_get_option('sequential_prefix');
1214
+	$postfix = give_get_option('sequential_postfix');
1215 1215
 
1216 1216
 	// Remove prefix
1217
-	$number = preg_replace( '/' . $prefix . '/', '', $number, 1 );
1217
+	$number = preg_replace('/'.$prefix.'/', '', $number, 1);
1218 1218
 
1219 1219
 	// Remove the postfix
1220
-	$length      = strlen( $number );
1221
-	$postfix_pos = strrpos( $number, $postfix );
1222
-	if ( false !== $postfix_pos ) {
1223
-		$number = substr_replace( $number, '', $postfix_pos, $length );
1220
+	$length      = strlen($number);
1221
+	$postfix_pos = strrpos($number, $postfix);
1222
+	if (false !== $postfix_pos) {
1223
+		$number = substr_replace($number, '', $postfix_pos, $length);
1224 1224
 	}
1225 1225
 
1226 1226
 	// Ensure it's a whole number
1227
-	$number = intval( $number );
1227
+	$number = intval($number);
1228 1228
 
1229
-	return apply_filters( 'give_remove_payment_prefix_postfix', $number, $prefix, $postfix );
1229
+	return apply_filters('give_remove_payment_prefix_postfix', $number, $prefix, $postfix);
1230 1230
 
1231 1231
 }
1232 1232
 
@@ -1242,10 +1242,10 @@  discard block
 block discarded – undo
1242 1242
  *
1243 1243
  * @return string $amount Fully formatted payment amount
1244 1244
  */
1245
-function give_payment_amount( $payment_id = 0 ) {
1246
-	$amount = give_get_payment_amount( $payment_id );
1245
+function give_payment_amount($payment_id = 0) {
1246
+	$amount = give_get_payment_amount($payment_id);
1247 1247
 
1248
-	return give_currency_filter( give_format_amount( $amount ), give_get_payment_currency_code( $payment_id ) );
1248
+	return give_currency_filter(give_format_amount($amount), give_get_payment_currency_code($payment_id));
1249 1249
 }
1250 1250
 
1251 1251
 /**
@@ -1258,11 +1258,11 @@  discard block
 block discarded – undo
1258 1258
  *
1259 1259
  * @return mixed|void
1260 1260
  */
1261
-function give_get_payment_amount( $payment_id ) {
1261
+function give_get_payment_amount($payment_id) {
1262 1262
 
1263
-	$payment = new Give_Payment( $payment_id );
1263
+	$payment = new Give_Payment($payment_id);
1264 1264
 
1265
-	return apply_filters( 'give_payment_amount', floatval( $payment->total ), $payment_id );
1265
+	return apply_filters('give_payment_amount', floatval($payment->total), $payment_id);
1266 1266
 }
1267 1267
 
1268 1268
 /**
@@ -1278,10 +1278,10 @@  discard block
 block discarded – undo
1278 1278
  *
1279 1279
  * @return array Fully formatted payment subtotal
1280 1280
  */
1281
-function give_payment_subtotal( $payment_id = 0 ) {
1282
-	$subtotal = give_get_payment_subtotal( $payment_id );
1281
+function give_payment_subtotal($payment_id = 0) {
1282
+	$subtotal = give_get_payment_subtotal($payment_id);
1283 1283
 
1284
-	return give_currency_filter( give_format_amount( $subtotal ), give_get_payment_currency_code( $payment_id ) );
1284
+	return give_currency_filter(give_format_amount($subtotal), give_get_payment_currency_code($payment_id));
1285 1285
 }
1286 1286
 
1287 1287
 /**
@@ -1295,8 +1295,8 @@  discard block
 block discarded – undo
1295 1295
  *
1296 1296
  * @return float $subtotal Subtotal for payment (non formatted)
1297 1297
  */
1298
-function give_get_payment_subtotal( $payment_id = 0 ) {
1299
-	$payment = new G_Payment( $payment_id );
1298
+function give_get_payment_subtotal($payment_id = 0) {
1299
+	$payment = new G_Payment($payment_id);
1300 1300
 
1301 1301
 	return $payment->subtotal;
1302 1302
 }
@@ -1311,10 +1311,10 @@  discard block
 block discarded – undo
1311 1311
  *
1312 1312
  * @return mixed array if payment fees found, false otherwise
1313 1313
  */
1314
-function give_get_payment_fees( $payment_id = 0, $type = 'all' ) {
1315
-	$payment = new Give_Payment( $payment_id );
1314
+function give_get_payment_fees($payment_id = 0, $type = 'all') {
1315
+	$payment = new Give_Payment($payment_id);
1316 1316
 
1317
-	return $payment->get_fees( $type );
1317
+	return $payment->get_fees($type);
1318 1318
 }
1319 1319
 
1320 1320
 /**
@@ -1326,8 +1326,8 @@  discard block
 block discarded – undo
1326 1326
  *
1327 1327
  * @return string The Transaction ID
1328 1328
  */
1329
-function give_get_payment_transaction_id( $payment_id = 0 ) {
1330
-	$payment = new Give_Payment( $payment_id );
1329
+function give_get_payment_transaction_id($payment_id = 0) {
1330
+	$payment = new Give_Payment($payment_id);
1331 1331
 
1332 1332
 	return $payment->transaction_id;
1333 1333
 }
@@ -1342,15 +1342,15 @@  discard block
 block discarded – undo
1342 1342
  *
1343 1343
  * @return bool|mixed
1344 1344
  */
1345
-function give_set_payment_transaction_id( $payment_id = 0, $transaction_id = '' ) {
1345
+function give_set_payment_transaction_id($payment_id = 0, $transaction_id = '') {
1346 1346
 
1347
-	if ( empty( $payment_id ) || empty( $transaction_id ) ) {
1347
+	if (empty($payment_id) || empty($transaction_id)) {
1348 1348
 		return false;
1349 1349
 	}
1350 1350
 
1351
-	$transaction_id = apply_filters( 'give_set_payment_transaction_id', $transaction_id, $payment_id );
1351
+	$transaction_id = apply_filters('give_set_payment_transaction_id', $transaction_id, $payment_id);
1352 1352
 
1353
-	return give_update_payment_meta( $payment_id, '_give_payment_transaction_id', $transaction_id );
1353
+	return give_update_payment_meta($payment_id, '_give_payment_transaction_id', $transaction_id);
1354 1354
 }
1355 1355
 
1356 1356
 /**
@@ -1364,12 +1364,12 @@  discard block
 block discarded – undo
1364 1364
  *
1365 1365
  * @return int $purchase Purchase ID
1366 1366
  */
1367
-function give_get_purchase_id_by_key( $key ) {
1367
+function give_get_purchase_id_by_key($key) {
1368 1368
 	global $wpdb;
1369 1369
 
1370
-	$purchase = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_give_payment_purchase_key' AND meta_value = %s LIMIT 1", $key ) );
1370
+	$purchase = $wpdb->get_var($wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_give_payment_purchase_key' AND meta_value = %s LIMIT 1", $key));
1371 1371
 
1372
-	if ( $purchase != null ) {
1372
+	if ($purchase != null) {
1373 1373
 		return $purchase;
1374 1374
 	}
1375 1375
 
@@ -1388,12 +1388,12 @@  discard block
 block discarded – undo
1388 1388
  *
1389 1389
  * @return int $purchase Purchase ID
1390 1390
  */
1391
-function give_get_purchase_id_by_transaction_id( $key ) {
1391
+function give_get_purchase_id_by_transaction_id($key) {
1392 1392
 	global $wpdb;
1393 1393
 
1394
-	$purchase = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_give_payment_transaction_id' AND meta_value = %s LIMIT 1", $key ) );
1394
+	$purchase = $wpdb->get_var($wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_give_payment_transaction_id' AND meta_value = %s LIMIT 1", $key));
1395 1395
 
1396
-	if ( $purchase != null ) {
1396
+	if ($purchase != null) {
1397 1397
 		return $purchase;
1398 1398
 	}
1399 1399
 
@@ -1410,19 +1410,19 @@  discard block
 block discarded – undo
1410 1410
  *
1411 1411
  * @return array $notes Payment Notes
1412 1412
  */
1413
-function give_get_payment_notes( $payment_id = 0, $search = '' ) {
1413
+function give_get_payment_notes($payment_id = 0, $search = '') {
1414 1414
 
1415
-	if ( empty( $payment_id ) && empty( $search ) ) {
1415
+	if (empty($payment_id) && empty($search)) {
1416 1416
 		return false;
1417 1417
 	}
1418 1418
 
1419
-	remove_action( 'pre_get_comments', 'give_hide_payment_notes', 10 );
1420
-	remove_filter( 'comments_clauses', 'give_hide_payment_notes_pre_41', 10, 2 );
1419
+	remove_action('pre_get_comments', 'give_hide_payment_notes', 10);
1420
+	remove_filter('comments_clauses', 'give_hide_payment_notes_pre_41', 10, 2);
1421 1421
 
1422
-	$notes = get_comments( array( 'post_id' => $payment_id, 'order' => 'ASC', 'search' => $search ) );
1422
+	$notes = get_comments(array('post_id' => $payment_id, 'order' => 'ASC', 'search' => $search));
1423 1423
 
1424
-	add_action( 'pre_get_comments', 'give_hide_payment_notes', 10 );
1425
-	add_filter( 'comments_clauses', 'give_hide_payment_notes_pre_41', 10, 2 );
1424
+	add_action('pre_get_comments', 'give_hide_payment_notes', 10);
1425
+	add_filter('comments_clauses', 'give_hide_payment_notes_pre_41', 10, 2);
1426 1426
 
1427 1427
 	return $notes;
1428 1428
 }
@@ -1438,19 +1438,19 @@  discard block
 block discarded – undo
1438 1438
  *
1439 1439
  * @return int The new note ID
1440 1440
  */
1441
-function give_insert_payment_note( $payment_id = 0, $note = '' ) {
1442
-	if ( empty( $payment_id ) ) {
1441
+function give_insert_payment_note($payment_id = 0, $note = '') {
1442
+	if (empty($payment_id)) {
1443 1443
 		return false;
1444 1444
 	}
1445 1445
 
1446
-	do_action( 'give_pre_insert_payment_note', $payment_id, $note );
1446
+	do_action('give_pre_insert_payment_note', $payment_id, $note);
1447 1447
 
1448
-	$note_id = wp_insert_comment( wp_filter_comment( array(
1448
+	$note_id = wp_insert_comment(wp_filter_comment(array(
1449 1449
 		'comment_post_ID'      => $payment_id,
1450 1450
 		'comment_content'      => $note,
1451 1451
 		'user_id'              => is_admin() ? get_current_user_id() : 0,
1452
-		'comment_date'         => current_time( 'mysql' ),
1453
-		'comment_date_gmt'     => current_time( 'mysql', 1 ),
1452
+		'comment_date'         => current_time('mysql'),
1453
+		'comment_date_gmt'     => current_time('mysql', 1),
1454 1454
 		'comment_approved'     => 1,
1455 1455
 		'comment_parent'       => 0,
1456 1456
 		'comment_author'       => '',
@@ -1459,9 +1459,9 @@  discard block
 block discarded – undo
1459 1459
 		'comment_author_email' => '',
1460 1460
 		'comment_type'         => 'give_payment_note'
1461 1461
 
1462
-	) ) );
1462
+	)));
1463 1463
 
1464
-	do_action( 'give_insert_payment_note', $note_id, $payment_id, $note );
1464
+	do_action('give_insert_payment_note', $note_id, $payment_id, $note);
1465 1465
 
1466 1466
 	return $note_id;
1467 1467
 }
@@ -1476,14 +1476,14 @@  discard block
 block discarded – undo
1476 1476
  *
1477 1477
  * @return bool True on success, false otherwise
1478 1478
  */
1479
-function give_delete_payment_note( $comment_id = 0, $payment_id = 0 ) {
1480
-	if ( empty( $comment_id ) ) {
1479
+function give_delete_payment_note($comment_id = 0, $payment_id = 0) {
1480
+	if (empty($comment_id)) {
1481 1481
 		return false;
1482 1482
 	}
1483 1483
 
1484
-	do_action( 'give_pre_delete_payment_note', $comment_id, $payment_id );
1485
-	$ret = wp_delete_comment( $comment_id, true );
1486
-	do_action( 'give_post_delete_payment_note', $comment_id, $payment_id );
1484
+	do_action('give_pre_delete_payment_note', $comment_id, $payment_id);
1485
+	$ret = wp_delete_comment($comment_id, true);
1486
+	do_action('give_post_delete_payment_note', $comment_id, $payment_id);
1487 1487
 
1488 1488
 	return $ret;
1489 1489
 }
@@ -1498,32 +1498,32 @@  discard block
 block discarded – undo
1498 1498
  *
1499 1499
  * @return string
1500 1500
  */
1501
-function give_get_payment_note_html( $note, $payment_id = 0 ) {
1501
+function give_get_payment_note_html($note, $payment_id = 0) {
1502 1502
 
1503
-	if ( is_numeric( $note ) ) {
1504
-		$note = get_comment( $note );
1503
+	if (is_numeric($note)) {
1504
+		$note = get_comment($note);
1505 1505
 	}
1506 1506
 
1507
-	if ( ! empty( $note->user_id ) ) {
1508
-		$user = get_userdata( $note->user_id );
1507
+	if ( ! empty($note->user_id)) {
1508
+		$user = get_userdata($note->user_id);
1509 1509
 		$user = $user->display_name;
1510 1510
 	} else {
1511
-		$user = __( 'System', 'give' );
1511
+		$user = __('System', 'give');
1512 1512
 	}
1513 1513
 
1514
-	$date_format = get_option( 'date_format' ) . ', ' . get_option( 'time_format' );
1514
+	$date_format = get_option('date_format').', '.get_option('time_format');
1515 1515
 
1516
-	$delete_note_url = wp_nonce_url( add_query_arg( array(
1516
+	$delete_note_url = wp_nonce_url(add_query_arg(array(
1517 1517
 		'give-action' => 'delete_payment_note',
1518 1518
 		'note_id'     => $note->comment_ID,
1519 1519
 		'payment_id'  => $payment_id
1520
-	) ), 'give_delete_payment_note_' . $note->comment_ID );
1520
+	)), 'give_delete_payment_note_'.$note->comment_ID);
1521 1521
 
1522
-	$note_html = '<div class="give-payment-note" id="give-payment-note-' . $note->comment_ID . '">';
1522
+	$note_html = '<div class="give-payment-note" id="give-payment-note-'.$note->comment_ID.'">';
1523 1523
 	$note_html .= '<p>';
1524
-	$note_html .= '<strong>' . $user . '</strong>&nbsp;&ndash;&nbsp;<span style="color:#aaa;font-style:italic;">' . date_i18n( $date_format, strtotime( $note->comment_date ) ) . '</span><br/>';
1524
+	$note_html .= '<strong>'.$user.'</strong>&nbsp;&ndash;&nbsp;<span style="color:#aaa;font-style:italic;">'.date_i18n($date_format, strtotime($note->comment_date)).'</span><br/>';
1525 1525
 	$note_html .= $note->comment_content;
1526
-	$note_html .= '&nbsp;&ndash;&nbsp;<a href="' . esc_url( $delete_note_url ) . '" class="give-delete-payment-note" data-note-id="' . absint( $note->comment_ID ) . '" data-payment-id="' . absint( $payment_id ) . '" title="' . __( 'Delete this payment note', 'give' ) . '">' . __( 'Delete', 'give' ) . '</a>';
1526
+	$note_html .= '&nbsp;&ndash;&nbsp;<a href="'.esc_url($delete_note_url).'" class="give-delete-payment-note" data-note-id="'.absint($note->comment_ID).'" data-payment-id="'.absint($payment_id).'" title="'.__('Delete this payment note', 'give').'">'.__('Delete', 'give').'</a>';
1527 1527
 	$note_html .= '</p>';
1528 1528
 	$note_html .= '</div>';
1529 1529
 
@@ -1541,20 +1541,20 @@  discard block
 block discarded – undo
1541 1541
  *
1542 1542
  * @return void
1543 1543
  */
1544
-function give_hide_payment_notes( $query ) {
1544
+function give_hide_payment_notes($query) {
1545 1545
 	global $wp_version;
1546 1546
 
1547
-	if ( version_compare( floatval( $wp_version ), '4.1', '>=' ) ) {
1548
-		$types = isset( $query->query_vars['type__not_in'] ) ? $query->query_vars['type__not_in'] : array();
1549
-		if ( ! is_array( $types ) ) {
1550
-			$types = array( $types );
1547
+	if (version_compare(floatval($wp_version), '4.1', '>=')) {
1548
+		$types = isset($query->query_vars['type__not_in']) ? $query->query_vars['type__not_in'] : array();
1549
+		if ( ! is_array($types)) {
1550
+			$types = array($types);
1551 1551
 		}
1552 1552
 		$types[]                           = 'give_payment_note';
1553 1553
 		$query->query_vars['type__not_in'] = $types;
1554 1554
 	}
1555 1555
 }
1556 1556
 
1557
-add_action( 'pre_get_comments', 'give_hide_payment_notes', 10 );
1557
+add_action('pre_get_comments', 'give_hide_payment_notes', 10);
1558 1558
 
1559 1559
 /**
1560 1560
  * Exclude notes (comments) on give_payment post type from showing in Recent Comments widgets
@@ -1566,17 +1566,17 @@  discard block
 block discarded – undo
1566 1566
  *
1567 1567
  * @return array $clauses Updated comment clauses
1568 1568
  */
1569
-function give_hide_payment_notes_pre_41( $clauses, $wp_comment_query ) {
1569
+function give_hide_payment_notes_pre_41($clauses, $wp_comment_query) {
1570 1570
 	global $wpdb, $wp_version;
1571 1571
 
1572
-	if ( version_compare( floatval( $wp_version ), '4.1', '<' ) ) {
1572
+	if (version_compare(floatval($wp_version), '4.1', '<')) {
1573 1573
 		$clauses['where'] .= ' AND comment_type != "give_payment_note"';
1574 1574
 	}
1575 1575
 
1576 1576
 	return $clauses;
1577 1577
 }
1578 1578
 
1579
-add_filter( 'comments_clauses', 'give_hide_payment_notes_pre_41', 10, 2 );
1579
+add_filter('comments_clauses', 'give_hide_payment_notes_pre_41', 10, 2);
1580 1580
 
1581 1581
 
1582 1582
 /**
@@ -1589,15 +1589,15 @@  discard block
 block discarded – undo
1589 1589
  *
1590 1590
  * @return array $where
1591 1591
  */
1592
-function give_hide_payment_notes_from_feeds( $where, $wp_comment_query ) {
1592
+function give_hide_payment_notes_from_feeds($where, $wp_comment_query) {
1593 1593
 	global $wpdb;
1594 1594
 
1595
-	$where .= $wpdb->prepare( " AND comment_type != %s", 'give_payment_note' );
1595
+	$where .= $wpdb->prepare(" AND comment_type != %s", 'give_payment_note');
1596 1596
 
1597 1597
 	return $where;
1598 1598
 }
1599 1599
 
1600
-add_filter( 'comment_feed_where', 'give_hide_payment_notes_from_feeds', 10, 2 );
1600
+add_filter('comment_feed_where', 'give_hide_payment_notes_from_feeds', 10, 2);
1601 1601
 
1602 1602
 
1603 1603
 /**
@@ -1611,32 +1611,32 @@  discard block
 block discarded – undo
1611 1611
  *
1612 1612
  * @return array Array of comment counts
1613 1613
  */
1614
-function give_remove_payment_notes_in_comment_counts( $stats, $post_id ) {
1614
+function give_remove_payment_notes_in_comment_counts($stats, $post_id) {
1615 1615
 	global $wpdb, $pagenow;
1616 1616
 
1617
-	if ( 'index.php' != $pagenow ) {
1617
+	if ('index.php' != $pagenow) {
1618 1618
 		return $stats;
1619 1619
 	}
1620 1620
 
1621 1621
 	$post_id = (int) $post_id;
1622 1622
 
1623
-	if ( apply_filters( 'give_count_payment_notes_in_comments', false ) ) {
1623
+	if (apply_filters('give_count_payment_notes_in_comments', false)) {
1624 1624
 		return $stats;
1625 1625
 	}
1626 1626
 
1627
-	$stats = wp_cache_get( "comments-{$post_id}", 'counts' );
1627
+	$stats = wp_cache_get("comments-{$post_id}", 'counts');
1628 1628
 
1629
-	if ( false !== $stats ) {
1629
+	if (false !== $stats) {
1630 1630
 		return $stats;
1631 1631
 	}
1632 1632
 
1633 1633
 	$where = 'WHERE comment_type != "give_payment_note"';
1634 1634
 
1635
-	if ( $post_id > 0 ) {
1636
-		$where .= $wpdb->prepare( " AND comment_post_ID = %d", $post_id );
1635
+	if ($post_id > 0) {
1636
+		$where .= $wpdb->prepare(" AND comment_post_ID = %d", $post_id);
1637 1637
 	}
1638 1638
 
1639
-	$count = $wpdb->get_results( "SELECT comment_approved, COUNT( * ) AS num_comments FROM {$wpdb->comments} {$where} GROUP BY comment_approved", ARRAY_A );
1639
+	$count = $wpdb->get_results("SELECT comment_approved, COUNT( * ) AS num_comments FROM {$wpdb->comments} {$where} GROUP BY comment_approved", ARRAY_A);
1640 1640
 
1641 1641
 	$total    = 0;
1642 1642
 	$approved = array(
@@ -1646,30 +1646,30 @@  discard block
 block discarded – undo
1646 1646
 		'trash'        => 'trash',
1647 1647
 		'post-trashed' => 'post-trashed'
1648 1648
 	);
1649
-	foreach ( (array) $count as $row ) {
1649
+	foreach ((array) $count as $row) {
1650 1650
 		// Don't count post-trashed toward totals
1651
-		if ( 'post-trashed' != $row['comment_approved'] && 'trash' != $row['comment_approved'] ) {
1651
+		if ('post-trashed' != $row['comment_approved'] && 'trash' != $row['comment_approved']) {
1652 1652
 			$total += $row['num_comments'];
1653 1653
 		}
1654
-		if ( isset( $approved[ $row['comment_approved'] ] ) ) {
1655
-			$stats[ $approved[ $row['comment_approved'] ] ] = $row['num_comments'];
1654
+		if (isset($approved[$row['comment_approved']])) {
1655
+			$stats[$approved[$row['comment_approved']]] = $row['num_comments'];
1656 1656
 		}
1657 1657
 	}
1658 1658
 
1659 1659
 	$stats['total_comments'] = $total;
1660
-	foreach ( $approved as $key ) {
1661
-		if ( empty( $stats[ $key ] ) ) {
1662
-			$stats[ $key ] = 0;
1660
+	foreach ($approved as $key) {
1661
+		if (empty($stats[$key])) {
1662
+			$stats[$key] = 0;
1663 1663
 		}
1664 1664
 	}
1665 1665
 
1666 1666
 	$stats = (object) $stats;
1667
-	wp_cache_set( "comments-{$post_id}", $stats, 'counts' );
1667
+	wp_cache_set("comments-{$post_id}", $stats, 'counts');
1668 1668
 
1669 1669
 	return $stats;
1670 1670
 }
1671 1671
 
1672
-add_filter( 'wp_count_comments', 'give_remove_payment_notes_in_comment_counts', 10, 2 );
1672
+add_filter('wp_count_comments', 'give_remove_payment_notes_in_comment_counts', 10, 2);
1673 1673
 
1674 1674
 
1675 1675
 /**
@@ -1682,9 +1682,9 @@  discard block
 block discarded – undo
1682 1682
  *
1683 1683
  * @return string $where Modified where clause
1684 1684
  */
1685
-function give_filter_where_older_than_week( $where = '' ) {
1685
+function give_filter_where_older_than_week($where = '') {
1686 1686
 	// Payments older than one week
1687
-	$start = date( 'Y-m-d', strtotime( '-7 days' ) );
1687
+	$start = date('Y-m-d', strtotime('-7 days'));
1688 1688
 	$where .= " AND post_date <= '{$start}'";
1689 1689
 
1690 1690
 	return $where;
@@ -1703,37 +1703,37 @@  discard block
 block discarded – undo
1703 1703
  *
1704 1704
  * @return string $form_title Returns the full title if $level_title false, otherwise returns the levels title
1705 1705
  */
1706
-function give_get_payment_form_title( $payment_meta, $level_title = false, $separator = '' ) {
1706
+function give_get_payment_form_title($payment_meta, $level_title = false, $separator = '') {
1707 1707
 
1708
-	$form_id    = isset( $payment_meta['form_id'] ) ? $payment_meta['form_id'] : 0;
1709
-	$form_title = isset( $payment_meta['form_title'] ) ? $payment_meta['form_title'] : '';
1710
-	$price_id   = isset( $payment_meta['price_id'] ) ? $payment_meta['price_id'] : null;
1708
+	$form_id    = isset($payment_meta['form_id']) ? $payment_meta['form_id'] : 0;
1709
+	$form_title = isset($payment_meta['form_title']) ? $payment_meta['form_title'] : '';
1710
+	$price_id   = isset($payment_meta['price_id']) ? $payment_meta['price_id'] : null;
1711 1711
 
1712
-	if ( $level_title == true ) {
1712
+	if ($level_title == true) {
1713 1713
 		$form_title = '';
1714 1714
 	}
1715 1715
 
1716
-	if ( give_has_variable_prices( $form_id ) ) {
1716
+	if (give_has_variable_prices($form_id)) {
1717 1717
 
1718
-		if ( ! empty( $separator ) ) {
1719
-			$form_title .= ' ' . $separator;
1718
+		if ( ! empty($separator)) {
1719
+			$form_title .= ' '.$separator;
1720 1720
 		}
1721 1721
 		$form_title .= ' <span class="donation-level-text-wrap">';
1722 1722
 
1723
-		if ( $price_id == 'custom' ) {
1723
+		if ($price_id == 'custom') {
1724 1724
 
1725
-			$custom_amount_text = get_post_meta( $form_id, '_give_custom_amount_text', true );
1726
-			$form_title .= ! empty( $custom_amount_text ) ? $custom_amount_text : __( 'Custom Amount', 'give' );
1725
+			$custom_amount_text = get_post_meta($form_id, '_give_custom_amount_text', true);
1726
+			$form_title .= ! empty($custom_amount_text) ? $custom_amount_text : __('Custom Amount', 'give');
1727 1727
 
1728 1728
 		} else {
1729
-			$form_title .= give_get_price_option_name( $form_id, $price_id );
1729
+			$form_title .= give_get_price_option_name($form_id, $price_id);
1730 1730
 		}
1731 1731
 
1732 1732
 		$form_title .= '</span>';
1733 1733
 
1734 1734
 	}
1735 1735
 
1736
-	return apply_filters( 'give_get_payment_form_title', $form_title, $payment_meta );
1736
+	return apply_filters('give_get_payment_form_title', $form_title, $payment_meta);
1737 1737
 
1738 1738
 }
1739 1739
 
@@ -1747,20 +1747,20 @@  discard block
 block discarded – undo
1747 1747
  *
1748 1748
  * @return string $price_id
1749 1749
  */
1750
-function give_get_price_id( $form_id, $price ) {
1750
+function give_get_price_id($form_id, $price) {
1751 1751
 
1752 1752
 	$price_id = 0;
1753 1753
 
1754
-	if ( give_has_variable_prices( $form_id ) ) {
1754
+	if (give_has_variable_prices($form_id)) {
1755 1755
 
1756
-		$levels = maybe_unserialize( get_post_meta( $form_id, '_give_donation_levels', true ) );
1756
+		$levels = maybe_unserialize(get_post_meta($form_id, '_give_donation_levels', true));
1757 1757
 
1758
-		foreach ( $levels as $level ) {
1758
+		foreach ($levels as $level) {
1759 1759
 
1760
-			$level_amount = (float) give_sanitize_amount( $level['_give_amount'] );
1760
+			$level_amount = (float) give_sanitize_amount($level['_give_amount']);
1761 1761
 
1762 1762
 			//check that this indeed the recurring price
1763
-			if ( $level_amount == $price ) {
1763
+			if ($level_amount == $price) {
1764 1764
 
1765 1765
 				$price_id = $level['_give_id']['level_id'];
1766 1766
 
Please login to merge, or discard this patch.