Passed
Push — master ( 6e3436...9f811d )
by Brian
04:49
created
includes/admin/register-settings.php 2 patches
Indentation   +299 added lines, -299 removed lines patch added patch discarded remove patch
@@ -192,13 +192,13 @@  discard block
 block discarded – undo
192 192
     $name       = isset( $option['name'] ) ? $option['name'] : '';
193 193
     $cb         = "wpinv_{$option['type']}_callback";
194 194
     $section    = "wpinv_settings_{$tab}_$section";
195
-	$is_wizzard = is_admin() && isset( $_GET['page'] ) && 'gp-setup' == $_GET['page'];
195
+    $is_wizzard = is_admin() && isset( $_GET['page'] ) && 'gp-setup' == $_GET['page'];
196 196
 
197
-	if ( isset( $option['desc'] ) && ( ! $is_wizzard && ! empty( $option['help-tip'] ) ) ) {
198
-		$tip   = wpinv_clean( $option['desc'] );
199
-		$name .= "<span class='dashicons dashicons-editor-help wpi-help-tip' title='$tip'></span>";
200
-		unset( $option['desc'] );
201
-	}
197
+    if ( isset( $option['desc'] ) && ( ! $is_wizzard && ! empty( $option['help-tip'] ) ) ) {
198
+        $tip   = wpinv_clean( $option['desc'] );
199
+        $name .= "<span class='dashicons dashicons-editor-help wpi-help-tip' title='$tip'></span>";
200
+        unset( $option['desc'] );
201
+    }
202 202
 
203 203
     // Loop through all tabs.
204 204
     add_settings_field(
@@ -225,9 +225,9 @@  discard block
 block discarded – undo
225 225
             'faux'            => isset( $option['faux'] ) ? $option['faux'] : false,
226 226
             'onchange'        => isset( $option['onchange'] ) ? $option['onchange'] : '',
227 227
             'custom'          => isset( $option['custom'] ) ? $option['custom'] : '',
228
-			'default_content' => isset( $option['default_content'] ) ? $option['default_content'] : '',
229
-			'class'           => isset( $option['class'] ) ? $option['class'] : '',
230
-			'style'           => isset( $option['style'] ) ? $option['style'] : '',
228
+            'default_content' => isset( $option['default_content'] ) ? $option['default_content'] : '',
229
+            'class'           => isset( $option['class'] ) ? $option['class'] : '',
230
+            'style'           => isset( $option['style'] ) ? $option['style'] : '',
231 231
             'cols'            => isset( $option['cols'] ) && (int) $option['cols'] > 0 ? (int) $option['cols'] : 50,
232 232
             'rows'            => isset( $option['rows'] ) && (int) $option['rows'] > 0 ? (int) $option['rows'] : 5,
233 233
         )
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
  * @return array
242 242
  */
243 243
 function wpinv_get_registered_settings() {
244
-	return array_filter( apply_filters( 'wpinv_registered_settings', wpinv_get_data( 'admin-settings' ) ) );
244
+    return array_filter( apply_filters( 'wpinv_registered_settings', wpinv_get_data( 'admin-settings' ) ) );
245 245
 }
246 246
 
247 247
 /**
@@ -260,18 +260,18 @@  discard block
 block discarded – undo
260 260
  */
261 261
 function wpinv_settings_sanitize( $input = array() ) {
262 262
 
263
-	$wpinv_options = wpinv_get_options();
264
-	$raw_referrer  = wp_get_raw_referer();
263
+    $wpinv_options = wpinv_get_options();
264
+    $raw_referrer  = wp_get_raw_referer();
265 265
 
266 266
     if ( empty( $raw_referrer ) ) {
267
-		return array_merge( $wpinv_options, $input );
267
+        return array_merge( $wpinv_options, $input );
268 268
     }
269 269
 
270 270
     wp_parse_str( $raw_referrer, $referrer );
271 271
 
272
-	if ( in_array( 'gp-setup', $referrer ) ) {
273
-		return array_merge( $wpinv_options, $input );
274
-	}
272
+    if ( in_array( 'gp-setup', $referrer ) ) {
273
+        return array_merge( $wpinv_options, $input );
274
+    }
275 275
 
276 276
     $settings = wpinv_get_registered_settings();
277 277
     $tab      = isset( $referrer['tab'] ) ? $referrer['tab'] : 'general';
@@ -293,10 +293,10 @@  discard block
 block discarded – undo
293 293
         }
294 294
 
295 295
         // General filter
296
-		$input[ $key ] = apply_filters( 'wpinv_settings_sanitize', $input[ $key ], $key );
296
+        $input[ $key ] = apply_filters( 'wpinv_settings_sanitize', $input[ $key ], $key );
297 297
 
298
-		// Key specific filter.
299
-		$input[ $key ] = apply_filters( "wpinv_settings_sanitize_$key", $input[ $key ] );
298
+        // Key specific filter.
299
+        $input[ $key ] = apply_filters( "wpinv_settings_sanitize_$key", $input[ $key ] );
300 300
     }
301 301
 
302 302
     // Loop through the whitelist and unset any that are empty for the tab being saved
@@ -339,14 +339,14 @@  discard block
 block discarded – undo
339 339
 
340 340
     foreach ( $new_rates as $rate ) {
341 341
 
342
-		$rate['rate']    = wpinv_sanitize_amount( $rate['rate'] );
343
-		$rate['name']    = sanitize_text_field( $rate['name'] );
344
-		$rate['state']   = sanitize_text_field( $rate['state'] );
345
-		$rate['country'] = sanitize_text_field( $rate['country'] );
346
-		$rate['global']  = empty( $rate['state'] );
347
-		$tax_rates[]     = $rate;
342
+        $rate['rate']    = wpinv_sanitize_amount( $rate['rate'] );
343
+        $rate['name']    = sanitize_text_field( $rate['name'] );
344
+        $rate['state']   = sanitize_text_field( $rate['state'] );
345
+        $rate['country'] = sanitize_text_field( $rate['country'] );
346
+        $rate['global']  = empty( $rate['state'] );
347
+        $tax_rates[]     = $rate;
348 348
 
349
-	}
349
+    }
350 350
 
351 351
     update_option( 'wpinv_tax_rates', $tax_rates );
352 352
 
@@ -359,11 +359,11 @@  discard block
 block discarded – undo
359 359
     $tabs['general']  = __( 'General', 'invoicing' );
360 360
     $tabs['gateways'] = __( 'Payment Gateways', 'invoicing' );
361 361
     $tabs['taxes']    = __( 'Taxes', 'invoicing' );
362
-	$tabs['emails']   = __( 'Emails', 'invoicing' );
362
+    $tabs['emails']   = __( 'Emails', 'invoicing' );
363 363
 
364
-	if ( count( getpaid_get_integration_settings() ) > 0 ) {
365
-		$tabs['integrations'] = __( 'Integrations', 'invoicing' );
366
-	}
364
+    if ( count( getpaid_get_integration_settings() ) > 0 ) {
365
+        $tabs['integrations'] = __( 'Integrations', 'invoicing' );
366
+    }
367 367
 
368 368
     $tabs['privacy']  = __( 'Privacy', 'invoicing' );
369 369
     $tabs['misc']     = __( 'Misc', 'invoicing' );
@@ -394,52 +394,52 @@  discard block
 block discarded – undo
394 394
         'general'      => apply_filters(
395 395
             'wpinv_settings_sections_general',
396 396
             array(
397
-				'main'             => __( 'General Settings', 'invoicing' ),
398
-				'page_section'     => __( 'Page Settings', 'invoicing' ),
399
-				'currency_section' => __( 'Currency Settings', 'invoicing' ),
400
-				'labels'           => __( 'Label Texts', 'invoicing' ),
397
+                'main'             => __( 'General Settings', 'invoicing' ),
398
+                'page_section'     => __( 'Page Settings', 'invoicing' ),
399
+                'currency_section' => __( 'Currency Settings', 'invoicing' ),
400
+                'labels'           => __( 'Label Texts', 'invoicing' ),
401 401
             )
402 402
         ),
403 403
         'gateways'     => apply_filters(
404 404
             'wpinv_settings_sections_gateways',
405 405
             array(
406
-				'main' => __( 'Gateway Settings', 'invoicing' ),
406
+                'main' => __( 'Gateway Settings', 'invoicing' ),
407 407
             )
408 408
         ),
409 409
         'taxes'        => apply_filters(
410 410
             'wpinv_settings_sections_taxes',
411 411
             array(
412
-				'main'  => __( 'Tax Settings', 'invoicing' ),
413
-				'rates' => __( 'Tax Rates', 'invoicing' ),
414
-				'vat'   => __( 'EU VAT Settings', 'invoicing' ),
412
+                'main'  => __( 'Tax Settings', 'invoicing' ),
413
+                'rates' => __( 'Tax Rates', 'invoicing' ),
414
+                'vat'   => __( 'EU VAT Settings', 'invoicing' ),
415 415
             )
416 416
         ),
417 417
         'emails'       => apply_filters(
418 418
             'wpinv_settings_sections_emails',
419 419
             array(
420
-				'main' => __( 'Email Settings', 'invoicing' ),
420
+                'main' => __( 'Email Settings', 'invoicing' ),
421 421
             )
422 422
         ),
423 423
 
424
-		'integrations' => wp_list_pluck( getpaid_get_integration_settings(), 'label', 'id' ),
424
+        'integrations' => wp_list_pluck( getpaid_get_integration_settings(), 'label', 'id' ),
425 425
 
426 426
         'privacy'      => apply_filters(
427 427
             'wpinv_settings_sections_privacy',
428 428
             array(
429
-				'main' => __( 'Privacy policy', 'invoicing' ),
429
+                'main' => __( 'Privacy policy', 'invoicing' ),
430 430
             )
431 431
         ),
432 432
         'misc'         => apply_filters(
433 433
             'wpinv_settings_sections_misc',
434 434
             array(
435
-				'main'       => __( 'Miscellaneous', 'invoicing' ),
436
-				'custom-css' => __( 'Custom CSS', 'invoicing' ),
435
+                'main'       => __( 'Miscellaneous', 'invoicing' ),
436
+                'custom-css' => __( 'Custom CSS', 'invoicing' ),
437 437
             )
438 438
         ),
439 439
         'tools'        => apply_filters(
440 440
             'wpinv_settings_sections_tools',
441 441
             array(
442
-				'main' => __( 'Diagnostic Tools', 'invoicing' ),
442
+                'main' => __( 'Diagnostic Tools', 'invoicing' ),
443 443
             )
444 444
         ),
445 445
     );
@@ -450,46 +450,46 @@  discard block
 block discarded – undo
450 450
 }
451 451
 
452 452
 function wpinv_get_pages( $with_slug = false, $default_label = null ) {
453
-	$pages_options = array();
453
+    $pages_options = array();
454 454
 
455
-	if ( $default_label !== null && $default_label !== false ) {
456
-		$pages_options = array( '' => $default_label ); // Blank option
457
-	}
455
+    if ( $default_label !== null && $default_label !== false ) {
456
+        $pages_options = array( '' => $default_label ); // Blank option
457
+    }
458 458
 
459
-	$pages = get_pages();
460
-	if ( $pages ) {
461
-		foreach ( $pages as $page ) {
462
-			$title = $with_slug ? $page->post_title . ' (' . $page->post_name . ')' : $page->post_title;
459
+    $pages = get_pages();
460
+    if ( $pages ) {
461
+        foreach ( $pages as $page ) {
462
+            $title = $with_slug ? $page->post_title . ' (' . $page->post_name . ')' : $page->post_title;
463 463
             $pages_options[ $page->ID ] = $title;
464
-		}
465
-	}
464
+        }
465
+    }
466 466
 
467
-	return $pages_options;
467
+    return $pages_options;
468 468
 }
469 469
 
470 470
 function wpinv_header_callback( $args ) {
471
-	if ( ! empty( $args['desc'] ) ) {
471
+    if ( ! empty( $args['desc'] ) ) {
472 472
         echo wp_kses_post( $args['desc'] );
473 473
     }
474 474
 }
475 475
 
476 476
 function wpinv_hidden_callback( $args ) {
477 477
 
478
-	$std     = isset( $args['std'] ) ? $args['std'] : '';
479
-	$value   = wpinv_get_option( $args['id'], $std );
478
+    $std     = isset( $args['std'] ) ? $args['std'] : '';
479
+    $value   = wpinv_get_option( $args['id'], $std );
480 480
 
481
-	if ( isset( $args['set_value'] ) ) {
482
-		$value = $args['set_value'];
483
-	}
481
+    if ( isset( $args['set_value'] ) ) {
482
+        $value = $args['set_value'];
483
+    }
484 484
 
485
-	if ( isset( $args['faux'] ) && true === $args['faux'] ) {
486
-		$args['readonly'] = true;
487
-		$name  = '';
488
-	} else {
489
-		$name = 'wpinv_settings[' . esc_attr( $args['id'] ) . ']';
490
-	}
485
+    if ( isset( $args['faux'] ) && true === $args['faux'] ) {
486
+        $args['readonly'] = true;
487
+        $name  = '';
488
+    } else {
489
+        $name = 'wpinv_settings[' . esc_attr( $args['id'] ) . ']';
490
+    }
491 491
 
492
-	echo '<input type="hidden" id="wpinv_settings[' . esc_attr( $args['id'] ) . ']" name="' . esc_attr( $name ) . '" value="' . esc_attr( stripslashes( $value ) ) . '" />';
492
+    echo '<input type="hidden" id="wpinv_settings[' . esc_attr( $args['id'] ) . ']" name="' . esc_attr( $name ) . '" value="' . esc_attr( stripslashes( $value ) ) . '" />';
493 493
 
494 494
 }
495 495
 
@@ -498,12 +498,12 @@  discard block
 block discarded – undo
498 498
  */
499 499
 function wpinv_checkbox_callback( $args ) {
500 500
 
501
-	$std = isset( $args['std'] ) ? $args['std'] : '';
502
-	$std = wpinv_get_option( $args['id'], $std );
503
-	$id  = esc_attr( $args['id'] );
501
+    $std = isset( $args['std'] ) ? $args['std'] : '';
502
+    $std = wpinv_get_option( $args['id'], $std );
503
+    $id  = esc_attr( $args['id'] );
504 504
 
505
-	getpaid_hidden_field( "wpinv_settings[$id]", '0' );
506
-	?>
505
+    getpaid_hidden_field( "wpinv_settings[$id]", '0' );
506
+    ?>
507 507
 		<fieldset>
508 508
 			<label>
509 509
 				<input id="wpinv-settings-<?php echo esc_attr( $id ); ?>" name="wpinv_settings[<?php echo esc_attr( $id ); ?>]" <?php checked( empty( $std ), false ); ?> value="1" type="checkbox">
@@ -515,75 +515,75 @@  discard block
 block discarded – undo
515 515
 
516 516
 function wpinv_multicheck_callback( $args ) {
517 517
 
518
-	$sanitize_id = wpinv_sanitize_key( $args['id'] );
519
-	$class = ! empty( $args['class'] ) ? ' ' . esc_attr( $args['class'] ) : '';
518
+    $sanitize_id = wpinv_sanitize_key( $args['id'] );
519
+    $class = ! empty( $args['class'] ) ? ' ' . esc_attr( $args['class'] ) : '';
520 520
 
521
-	if ( ! empty( $args['options'] ) ) {
521
+    if ( ! empty( $args['options'] ) ) {
522 522
 
523
-		$std     = isset( $args['std'] ) ? $args['std'] : array();
524
-		$value   = wpinv_get_option( $args['id'], $std );
523
+        $std     = isset( $args['std'] ) ? $args['std'] : array();
524
+        $value   = wpinv_get_option( $args['id'], $std );
525 525
 
526
-		echo '<div class="wpi-mcheck-rows wpi-mcheck-' . esc_attr( $sanitize_id . $class ) . '">';
526
+        echo '<div class="wpi-mcheck-rows wpi-mcheck-' . esc_attr( $sanitize_id . $class ) . '">';
527 527
         foreach ( $args['options'] as $key => $option ) :
528
-			$sanitize_key = esc_attr( wpinv_sanitize_key( $key ) );
529
-			if ( in_array( $sanitize_key, $value ) ) {
530
-				$enabled = $sanitize_key;
531
-			} else {
532
-				$enabled = null;
533
-			}
534
-			echo '<div class="wpi-mcheck-row"><input name="wpinv_settings[' . esc_attr( $sanitize_id ) . '][' . esc_attr( $sanitize_key ) . ']" id="wpinv_settings[' . esc_attr( $sanitize_id ) . '][' . esc_attr( $sanitize_key ) . ']" type="checkbox" value="' . esc_attr( $sanitize_key ) . '" ' . checked( $sanitize_key, $enabled, false ) . '/>&nbsp;';
535
-			echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . '][' . esc_attr( $sanitize_key ) . ']">' . wp_kses_post( $option ) . '</label></div>';
536
-		endforeach;
537
-		echo '</div>';
538
-		echo '<p class="description">' . wp_kses_post( $args['desc'] ) . '</p>';
539
-	}
528
+            $sanitize_key = esc_attr( wpinv_sanitize_key( $key ) );
529
+            if ( in_array( $sanitize_key, $value ) ) {
530
+                $enabled = $sanitize_key;
531
+            } else {
532
+                $enabled = null;
533
+            }
534
+            echo '<div class="wpi-mcheck-row"><input name="wpinv_settings[' . esc_attr( $sanitize_id ) . '][' . esc_attr( $sanitize_key ) . ']" id="wpinv_settings[' . esc_attr( $sanitize_id ) . '][' . esc_attr( $sanitize_key ) . ']" type="checkbox" value="' . esc_attr( $sanitize_key ) . '" ' . checked( $sanitize_key, $enabled, false ) . '/>&nbsp;';
535
+            echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . '][' . esc_attr( $sanitize_key ) . ']">' . wp_kses_post( $option ) . '</label></div>';
536
+        endforeach;
537
+        echo '</div>';
538
+        echo '<p class="description">' . wp_kses_post( $args['desc'] ) . '</p>';
539
+    }
540 540
 }
541 541
 
542 542
 function wpinv_payment_icons_callback( $args ) {
543 543
 
544 544
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
545
-	$value   = wpinv_get_option( $args['id'], false );
545
+    $value   = wpinv_get_option( $args['id'], false );
546 546
 
547
-	if ( ! empty( $args['options'] ) ) {
548
-		foreach ( $args['options'] as $key => $option ) {
547
+    if ( ! empty( $args['options'] ) ) {
548
+        foreach ( $args['options'] as $key => $option ) {
549 549
             $sanitize_key = wpinv_sanitize_key( $key );
550 550
 
551
-			if ( empty( $value ) ) {
552
-				$enabled = $option;
553
-			} else {
554
-				$enabled = null;
555
-			}
556
-
557
-			echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . '][' . esc_attr( $sanitize_key ) . ']" style="margin-right:10px;line-height:16px;height:16px;display:inline-block;">';
558
-
559
-				echo '<input name="wpinv_settings[' . esc_attr( $sanitize_id ) . '][' . esc_attr( $sanitize_key ) . ']" id="wpinv_settings[' . esc_attr( $sanitize_id ) . '][' . esc_attr( $sanitize_key ) . ']" type="checkbox" value="' . esc_attr( $option ) . '" ' . checked( $option, $enabled, false ) . '/>&nbsp;';
560
-
561
-				if ( wpinv_string_is_image_url( $key ) ) {
562
-				echo '<img class="payment-icon" src="' . esc_url( $key ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>';
563
-				} else {
564
-				$card = strtolower( str_replace( ' ', '', $option ) );
565
-
566
-				if ( has_filter( 'wpinv_accepted_payment_' . $card . '_image' ) ) {
567
-					$image = apply_filters( 'wpinv_accepted_payment_' . $card . '_image', '' );
568
-					} else {
569
-					$image       = wpinv_locate_template( 'images' . DIRECTORY_SEPARATOR . 'icons' . DIRECTORY_SEPARATOR . $card . '.gif', false );
570
-					$content_dir = WP_CONTENT_DIR;
571
-
572
-					if ( function_exists( 'wp_normalize_path' ) ) {
573
-						// Replaces backslashes with forward slashes for Windows systems
574
-						$image = wp_normalize_path( $image );
575
-						$content_dir = wp_normalize_path( $content_dir );
576
-						}
577
-
578
-					$image = str_replace( $content_dir, content_url(), $image );
579
-					}
580
-
581
-				echo '<img class="payment-icon" src="' . esc_url( $image ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>';
582
-				}
583
-			echo wp_kses_post( $option ) . '</label>';
584
-		}
585
-		echo '<p class="description" style="margin-top:16px;">' . wp_kses_post( $args['desc'] ) . '</p>';
586
-	}
551
+            if ( empty( $value ) ) {
552
+                $enabled = $option;
553
+            } else {
554
+                $enabled = null;
555
+            }
556
+
557
+            echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . '][' . esc_attr( $sanitize_key ) . ']" style="margin-right:10px;line-height:16px;height:16px;display:inline-block;">';
558
+
559
+                echo '<input name="wpinv_settings[' . esc_attr( $sanitize_id ) . '][' . esc_attr( $sanitize_key ) . ']" id="wpinv_settings[' . esc_attr( $sanitize_id ) . '][' . esc_attr( $sanitize_key ) . ']" type="checkbox" value="' . esc_attr( $option ) . '" ' . checked( $option, $enabled, false ) . '/>&nbsp;';
560
+
561
+                if ( wpinv_string_is_image_url( $key ) ) {
562
+                echo '<img class="payment-icon" src="' . esc_url( $key ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>';
563
+                } else {
564
+                $card = strtolower( str_replace( ' ', '', $option ) );
565
+
566
+                if ( has_filter( 'wpinv_accepted_payment_' . $card . '_image' ) ) {
567
+                    $image = apply_filters( 'wpinv_accepted_payment_' . $card . '_image', '' );
568
+                    } else {
569
+                    $image       = wpinv_locate_template( 'images' . DIRECTORY_SEPARATOR . 'icons' . DIRECTORY_SEPARATOR . $card . '.gif', false );
570
+                    $content_dir = WP_CONTENT_DIR;
571
+
572
+                    if ( function_exists( 'wp_normalize_path' ) ) {
573
+                        // Replaces backslashes with forward slashes for Windows systems
574
+                        $image = wp_normalize_path( $image );
575
+                        $content_dir = wp_normalize_path( $content_dir );
576
+                        }
577
+
578
+                    $image = str_replace( $content_dir, content_url(), $image );
579
+                    }
580
+
581
+                echo '<img class="payment-icon" src="' . esc_url( $image ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>';
582
+                }
583
+            echo wp_kses_post( $option ) . '</label>';
584
+        }
585
+        echo '<p class="description" style="margin-top:16px;">' . wp_kses_post( $args['desc'] ) . '</p>';
586
+    }
587 587
 }
588 588
 
589 589
 /**
@@ -591,9 +591,9 @@  discard block
 block discarded – undo
591 591
  */
592 592
 function wpinv_radio_callback( $args ) {
593 593
 
594
-	$std = isset( $args['std'] ) ? $args['std'] : '';
595
-	$std = wpinv_get_option( $args['id'], $std );
596
-	?>
594
+    $std = isset( $args['std'] ) ? $args['std'] : '';
595
+    $std = wpinv_get_option( $args['id'], $std );
596
+    ?>
597 597
 		<fieldset>
598 598
 			<ul id="wpinv-settings-<?php echo esc_attr( $args['id'] ); ?>" style="margin-top: 0;">
599 599
 				<?php foreach ( $args['options'] as $key => $option ) : ?>
@@ -607,7 +607,7 @@  discard block
 block discarded – undo
607 607
 			</ul>
608 608
 		</fieldset>
609 609
 	<?php
610
-	getpaid_settings_description_callback( $args );
610
+    getpaid_settings_description_callback( $args );
611 611
 }
612 612
 
613 613
 /**
@@ -615,10 +615,10 @@  discard block
 block discarded – undo
615 615
  */
616 616
 function getpaid_settings_description_callback( $args ) {
617 617
 
618
-	if ( ! empty( $args['desc'] ) ) {
619
-		$description = $args['desc'];
620
-		echo wp_kses_post( "<p class='description'>$description</p>" );
621
-	}
618
+    if ( ! empty( $args['desc'] ) ) {
619
+        $description = $args['desc'];
620
+        echo wp_kses_post( "<p class='description'>$description</p>" );
621
+    }
622 622
 
623 623
 }
624 624
 
@@ -627,7 +627,7 @@  discard block
 block discarded – undo
627 627
  */
628 628
 function wpinv_gateways_callback() {
629 629
 
630
-	?>
630
+    ?>
631 631
 		</td>
632 632
 	</tr>
633 633
 	<tr class="bsui">
@@ -641,26 +641,26 @@  discard block
 block discarded – undo
641 641
 
642 642
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
643 643
     $class = ! empty( $args['class'] ) ? ' ' . esc_attr( $args['class'] ) : '';
644
-	$std     = isset( $args['std'] ) ? $args['std'] : '';
645
-	$value   = wpinv_get_option( $args['id'], $std );
644
+    $std     = isset( $args['std'] ) ? $args['std'] : '';
645
+    $value   = wpinv_get_option( $args['id'], $std );
646 646
 
647
-	echo '<select name="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"" id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" class="' . esc_attr( $class ) . '" >';
647
+    echo '<select name="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"" id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" class="' . esc_attr( $class ) . '" >';
648 648
 
649
-	foreach ( $args['options'] as $key => $option ) :
649
+    foreach ( $args['options'] as $key => $option ) :
650 650
 
651
-		echo '<option value="' . esc_attr( $key ) . '" ';
651
+        echo '<option value="' . esc_attr( $key ) . '" ';
652 652
 
653
-		if ( isset( $args['selected'] ) && $args['selected'] !== null && $args['selected'] !== false ) {
653
+        if ( isset( $args['selected'] ) && $args['selected'] !== null && $args['selected'] !== false ) {
654 654
             selected( $key, $args['selected'] );
655 655
         } else {
656 656
             selected( $key, $value );
657 657
         }
658 658
 
659
-		echo '>' . esc_html( $option['admin_label'] ) . '</option>';
660
-	endforeach;
659
+        echo '>' . esc_html( $option['admin_label'] ) . '</option>';
660
+    endforeach;
661 661
 
662
-	echo '</select>';
663
-	echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
662
+    echo '</select>';
663
+    echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
664 664
 }
665 665
 
666 666
 /**
@@ -671,38 +671,38 @@  discard block
 block discarded – undo
671 671
  */
672 672
 function wpinv_settings_attrs_helper( $args ) {
673 673
 
674
-	$value = isset( $args['std'] ) ? $args['std'] : '';
675
-	$id    = esc_attr( $args['id'] );
676
-	$value = is_scalar( $value ) ? $value : '';
677
-
678
-	$attrs = array(
679
-		'name'     => ! empty( $args['faux'] ) ? false : "wpinv_settings[$id]",
680
-		'readonly' => ! empty( $args['faux'] ),
681
-		'value'    => ! empty( $args['faux'] ) ? $value : wpinv_get_option( $args['id'], $value ),
682
-		'id'       => 'wpinv-settings-' . $args['id'],
683
-		'style'    => $args['style'],
684
-		'class'    => $args['class'],
685
-		'placeholder' => $args['placeholder'],
686
-		'data-placeholder' => $args['placeholder'],
687
-	);
674
+    $value = isset( $args['std'] ) ? $args['std'] : '';
675
+    $id    = esc_attr( $args['id'] );
676
+    $value = is_scalar( $value ) ? $value : '';
677
+
678
+    $attrs = array(
679
+        'name'     => ! empty( $args['faux'] ) ? false : "wpinv_settings[$id]",
680
+        'readonly' => ! empty( $args['faux'] ),
681
+        'value'    => ! empty( $args['faux'] ) ? $value : wpinv_get_option( $args['id'], $value ),
682
+        'id'       => 'wpinv-settings-' . $args['id'],
683
+        'style'    => $args['style'],
684
+        'class'    => $args['class'],
685
+        'placeholder' => $args['placeholder'],
686
+        'data-placeholder' => $args['placeholder'],
687
+    );
688 688
 
689
-	if ( ! empty( $args['onchange'] ) ) {
690
-		$attrs['onchange'] = $args['onchange'];
691
-	}
689
+    if ( ! empty( $args['onchange'] ) ) {
690
+        $attrs['onchange'] = $args['onchange'];
691
+    }
692 692
 
693
-	foreach ( $attrs as $key => $value ) {
693
+    foreach ( $attrs as $key => $value ) {
694 694
 
695
-		if ( false === $value ) {
696
-			continue;
697
-		}
695
+        if ( false === $value ) {
696
+            continue;
697
+        }
698 698
 
699
-		if ( true === $value ) {
700
-			echo ' ' . esc_attr( $key );
701
-		} else {
702
-			echo ' ' . esc_attr( $key ) . '="' . esc_attr( $value ) . '"';
703
-		}
699
+        if ( true === $value ) {
700
+            echo ' ' . esc_attr( $key );
701
+        } else {
702
+            echo ' ' . esc_attr( $key ) . '="' . esc_attr( $value ) . '"';
703
+        }
704 704
 
705
-	}
705
+    }
706 706
 
707 707
 }
708 708
 
@@ -711,9 +711,9 @@  discard block
 block discarded – undo
711 711
  */
712 712
 function wpinv_text_callback( $args ) {
713 713
 
714
-	$desc = empty( $desc ) ? '' : "<p class='description'>$desc</p>";
714
+    $desc = empty( $desc ) ? '' : "<p class='description'>$desc</p>";
715 715
 
716
-	?>
716
+    ?>
717 717
 		<label style="width: 100%;">
718 718
 			<input type="text" <?php wpinv_settings_attrs_helper( $args ); ?>>
719 719
 			<?php echo wp_kses_post( $desc ); ?>
@@ -727,9 +727,9 @@  discard block
 block discarded – undo
727 727
  */
728 728
 function wpinv_number_callback( $args ) {
729 729
 
730
-	$desc = empty( $desc ) ? '' : "<p class='description'>$desc</p>";
730
+    $desc = empty( $desc ) ? '' : "<p class='description'>$desc</p>";
731 731
 
732
-	?>
732
+    ?>
733 733
 		<label style="width: 100%;">
734 734
 			<input type="number" step="<?php echo floatval( $args['step'] ); ?>" max="<?php echo intval( $args['max'] ); ?>" min="<?php echo intval( $args['min'] ); ?>" <?php wpinv_settings_attrs_helper( $args ); ?>>
735 735
 			<?php echo wp_kses_post( $desc ); ?>
@@ -741,34 +741,34 @@  discard block
 block discarded – undo
741 741
 function wpinv_textarea_callback( $args ) {
742 742
 
743 743
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
744
-	$std     = isset( $args['std'] ) ? $args['std'] : '';
745
-	$value   = wpinv_get_option( $args['id'], $std );
744
+    $std     = isset( $args['std'] ) ? $args['std'] : '';
745
+    $value   = wpinv_get_option( $args['id'], $std );
746 746
 
747 747
     $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
748 748
     $class = ( isset( $args['class'] ) && ! is_null( $args['class'] ) ) ? $args['class'] : 'large-text';
749 749
 
750
-	echo '<textarea class="' . esc_attr( $class ) . ' txtarea-' . esc_attr( $size ) . ' wpi-' . esc_attr( sanitize_html_class( $sanitize_id ) ) . ' " cols="' . esc_attr( $args['cols'] ) . '" rows="' . esc_attr( $args['rows'] ) . '" id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']">' . esc_textarea( stripslashes( $value ) ) . '</textarea>';
751
-	echo '<br /><label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
750
+    echo '<textarea class="' . esc_attr( $class ) . ' txtarea-' . esc_attr( $size ) . ' wpi-' . esc_attr( sanitize_html_class( $sanitize_id ) ) . ' " cols="' . esc_attr( $args['cols'] ) . '" rows="' . esc_attr( $args['rows'] ) . '" id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']">' . esc_textarea( stripslashes( $value ) ) . '</textarea>';
751
+    echo '<br /><label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
752 752
 
753 753
 }
754 754
 
755 755
 function wpinv_password_callback( $args ) {
756 756
 
757 757
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
758
-	$std     = isset( $args['std'] ) ? $args['std'] : '';
759
-	$value   = wpinv_get_option( $args['id'], $std );
758
+    $std     = isset( $args['std'] ) ? $args['std'] : '';
759
+    $value   = wpinv_get_option( $args['id'], $std );
760 760
 
761
-	$size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
762
-	echo '<input type="password" class="' . esc_attr( $size ) . '-text" id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '"/>';
763
-	echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
761
+    $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
762
+    echo '<input type="password" class="' . esc_attr( $size ) . '-text" id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '"/>';
763
+    echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
764 764
 
765 765
 }
766 766
 
767 767
 function wpinv_missing_callback( $args ) {
768
-	printf(
769
-		esc_html__( 'The callback function used for the %s setting is missing.', 'invoicing' ),
770
-		'<strong>' . esc_html( $args['id'] ) . '</strong>'
771
-	);
768
+    printf(
769
+        esc_html__( 'The callback function used for the %s setting is missing.', 'invoicing' ),
770
+        '<strong>' . esc_html( $args['id'] ) . '</strong>'
771
+    );
772 772
 }
773 773
 
774 774
 /**
@@ -776,13 +776,13 @@  discard block
 block discarded – undo
776 776
  */
777 777
 function wpinv_select_callback( $args ) {
778 778
 
779
-	$desc   = wp_kses_post( $args['desc'] );
780
-	$desc   = empty( $desc ) ? '' : "<p class='description'>$desc</p>";
781
-	$value  = isset( $args['std'] ) ? $args['std'] : '';
782
-	$value  = wpinv_get_option( $args['id'], $value );
783
-	$rand   = uniqid( 'random_id' );
779
+    $desc   = wp_kses_post( $args['desc'] );
780
+    $desc   = empty( $desc ) ? '' : "<p class='description'>$desc</p>";
781
+    $value  = isset( $args['std'] ) ? $args['std'] : '';
782
+    $value  = wpinv_get_option( $args['id'], $value );
783
+    $rand   = uniqid( 'random_id' );
784 784
 
785
-	?>
785
+    ?>
786 786
 		<label style="width: 100%;">
787 787
 			<select <?php wpinv_settings_attrs_helper( $args ); ?> data-allow-clear="true">
788 788
 				<?php foreach ( $args['options'] as $option => $name ) : ?>
@@ -815,50 +815,50 @@  discard block
 block discarded – undo
815 815
 function wpinv_color_select_callback( $args ) {
816 816
 
817 817
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
818
-	$std     = isset( $args['std'] ) ? $args['std'] : '';
819
-	$value   = wpinv_get_option( $args['id'], $std );
818
+    $std     = isset( $args['std'] ) ? $args['std'] : '';
819
+    $value   = wpinv_get_option( $args['id'], $std );
820 820
 
821
-	echo '<select id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"/>';
821
+    echo '<select id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"/>';
822 822
 
823
-	foreach ( $args['options'] as $option => $color ) {
824
-		echo '<option value="' . esc_attr( $option ) . '" ' . selected( $option, $value ) . '>' . esc_html( $color['label'] ) . '</option>';
825
-	}
823
+    foreach ( $args['options'] as $option => $color ) {
824
+        echo '<option value="' . esc_attr( $option ) . '" ' . selected( $option, $value ) . '>' . esc_html( $color['label'] ) . '</option>';
825
+    }
826 826
 
827
-	echo '</select>';
828
-	echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
827
+    echo '</select>';
828
+    echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
829 829
 
830 830
 }
831 831
 
832 832
 function wpinv_rich_editor_callback( $args ) {
833
-	global $wp_version;
833
+    global $wp_version;
834 834
 
835 835
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
836 836
 
837
-	$std     = isset( $args['std'] ) ? $args['std'] : '';
838
-	$value   = wpinv_get_option( $args['id'], $std );
837
+    $std     = isset( $args['std'] ) ? $args['std'] : '';
838
+    $value   = wpinv_get_option( $args['id'], $std );
839 839
 
840
-	if ( ! empty( $args['allow_blank'] ) && empty( $value ) ) {
841
-		$value = $std;
842
-	}
840
+    if ( ! empty( $args['allow_blank'] ) && empty( $value ) ) {
841
+        $value = $std;
842
+    }
843 843
 
844
-	$rows = isset( $args['size'] ) ? $args['size'] : 20;
844
+    $rows = isset( $args['size'] ) ? $args['size'] : 20;
845 845
 
846
-	echo '<div class="getpaid-settings-editor-input">';
847
-	if ( $wp_version >= 3.3 && function_exists( 'wp_editor' ) ) {
848
-		wp_editor(
846
+    echo '<div class="getpaid-settings-editor-input">';
847
+    if ( $wp_version >= 3.3 && function_exists( 'wp_editor' ) ) {
848
+        wp_editor(
849 849
             stripslashes( $value ),
850 850
             'wpinv_settings_' . esc_attr( $args['id'] ),
851 851
             array(
852
-				'textarea_name' => 'wpinv_settings[' . esc_attr( $args['id'] ) . ']',
853
-				'textarea_rows' => absint( $rows ),
854
-				'media_buttons' => false,
852
+                'textarea_name' => 'wpinv_settings[' . esc_attr( $args['id'] ) . ']',
853
+                'textarea_rows' => absint( $rows ),
854
+                'media_buttons' => false,
855 855
             )
856 856
         );
857
-	} else {
858
-		echo '<textarea class="large-text" rows="10" id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" class="wpi-' . esc_attr( sanitize_html_class( $args['id'] ) ) . '">' . esc_textarea( stripslashes( $value ) ) . '</textarea>';
859
-	}
857
+    } else {
858
+        echo '<textarea class="large-text" rows="10" id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" class="wpi-' . esc_attr( sanitize_html_class( $args['id'] ) ) . '">' . esc_textarea( stripslashes( $value ) ) . '</textarea>';
859
+    }
860 860
 
861
-	echo '</div><br/><label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
861
+    echo '</div><br/><label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
862 862
 
863 863
 }
864 864
 
@@ -866,51 +866,51 @@  discard block
 block discarded – undo
866 866
 
867 867
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
868 868
 
869
-	$std     = isset( $args['std'] ) ? $args['std'] : '';
870
-	$value   = wpinv_get_option( $args['id'], $std );
869
+    $std     = isset( $args['std'] ) ? $args['std'] : '';
870
+    $value   = wpinv_get_option( $args['id'], $std );
871 871
 
872
-	$size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
873
-	echo '<input type="text" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( stripslashes( $value ) ) . '"/>';
874
-	echo '<span>&nbsp;<input type="button" class="wpinv_settings_upload_button button-secondary" value="' . esc_attr__( 'Upload File', 'invoicing' ) . '"/></span>';
875
-	echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
872
+    $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
873
+    echo '<input type="text" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( stripslashes( $value ) ) . '"/>';
874
+    echo '<span>&nbsp;<input type="button" class="wpinv_settings_upload_button button-secondary" value="' . esc_attr__( 'Upload File', 'invoicing' ) . '"/></span>';
875
+    echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
876 876
 
877 877
 }
878 878
 
879 879
 function wpinv_color_callback( $args ) {
880 880
 
881
-	$std         = isset( $args['std'] ) ? $args['std'] : '';
882
-	$value       = wpinv_get_option( $args['id'], $std );
881
+    $std         = isset( $args['std'] ) ? $args['std'] : '';
882
+    $value       = wpinv_get_option( $args['id'], $std );
883 883
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
884 884
 
885
-	echo '<input type="text" class="wpinv-color-picker" id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '" data-default-color="' . esc_attr( $std ) . '" />';
886
-	echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
885
+    echo '<input type="text" class="wpinv-color-picker" id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '" data-default-color="' . esc_attr( $std ) . '" />';
886
+    echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
887 887
 
888 888
 }
889 889
 
890 890
 function wpinv_country_states_callback( $args ) {
891 891
 
892
-	$std     = isset( $args['std'] ) ? $args['std'] : '';
893
-	$value   = wpinv_get_option( $args['id'], $std );
892
+    $std     = isset( $args['std'] ) ? $args['std'] : '';
893
+    $value   = wpinv_get_option( $args['id'], $std );
894 894
 
895 895
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
896 896
 
897
-	if ( isset( $args['placeholder'] ) ) {
898
-		$placeholder = $args['placeholder'];
899
-	} else {
900
-		$placeholder = '';
901
-	}
897
+    if ( isset( $args['placeholder'] ) ) {
898
+        $placeholder = $args['placeholder'];
899
+    } else {
900
+        $placeholder = '';
901
+    }
902 902
 
903
-	$states = wpinv_get_country_states();
903
+    $states = wpinv_get_country_states();
904 904
 
905
-	$class = empty( $states ) ? 'wpinv-no-states' : 'wpi_select2';
906
-	echo '<select id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" class="' . esc_attr( $class ) . '" data-placeholder="' . esc_html( $placeholder ) . '"/>';
905
+    $class = empty( $states ) ? 'wpinv-no-states' : 'wpi_select2';
906
+    echo '<select id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" class="' . esc_attr( $class ) . '" data-placeholder="' . esc_html( $placeholder ) . '"/>';
907 907
 
908
-	foreach ( $states as $option => $name ) {
909
-		echo '<option value="' . esc_attr( $option ) . '" ' . selected( $option, $value ) . '>' . esc_html( $name ) . '</option>';
910
-	}
908
+    foreach ( $states as $option => $name ) {
909
+        echo '<option value="' . esc_attr( $option ) . '" ' . selected( $option, $value ) . '>' . esc_html( $name ) . '</option>';
910
+    }
911 911
 
912
-	echo '</select>';
913
-	echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
912
+    echo '</select>';
913
+    echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
914 914
 
915 915
 }
916 916
 
@@ -919,7 +919,7 @@  discard block
 block discarded – undo
919 919
  */
920 920
 function wpinv_tax_rates_callback() {
921 921
 
922
-	?>
922
+    ?>
923 923
 		</td>
924 924
 	</tr>
925 925
 	<tr class="bsui">
@@ -935,9 +935,9 @@  discard block
 block discarded – undo
935 935
  */
936 936
 function wpinv_tax_rate_callback( $tax_rate, $key ) {
937 937
 
938
-	$key                      = sanitize_key( $key );
939
-	$tax_rate['reduced_rate'] = empty( $tax_rate['reduced_rate'] ) ? 0 : $tax_rate['reduced_rate'];
940
-	include plugin_dir_path( __FILE__ ) . 'views/html-tax-rate-edit.php';
938
+    $key                      = sanitize_key( $key );
939
+    $tax_rate['reduced_rate'] = empty( $tax_rate['reduced_rate'] ) ? 0 : $tax_rate['reduced_rate'];
940
+    include plugin_dir_path( __FILE__ ) . 'views/html-tax-rate-edit.php';
941 941
 
942 942
 }
943 943
 
@@ -969,14 +969,14 @@  discard block
 block discarded – undo
969 969
                 <td>
970 970
 					<a href="
971 971
                     <?php
972
-						echo esc_url(
973
-							wp_nonce_url(
974
-								add_query_arg( 'getpaid-admin-action', 'create_missing_pages' ),
975
-								'getpaid-nonce',
976
-								'getpaid-nonce'
977
-							)
978
-						);
979
-					?>
972
+                        echo esc_url(
973
+                            wp_nonce_url(
974
+                                add_query_arg( 'getpaid-admin-action', 'create_missing_pages' ),
975
+                                'getpaid-nonce',
976
+                                'getpaid-nonce'
977
+                            )
978
+                        );
979
+                    ?>
980 980
                     " class="button button-primary"><?php esc_html_e( 'Run', 'invoicing' ); ?></a>
981 981
                 </td>
982 982
             </tr>
@@ -988,14 +988,14 @@  discard block
 block discarded – undo
988 988
                 <td>
989 989
 					<a href="
990 990
                     <?php
991
-						echo esc_url(
992
-							wp_nonce_url(
993
-								add_query_arg( 'getpaid-admin-action', 'create_missing_tables' ),
994
-								'getpaid-nonce',
995
-								'getpaid-nonce'
996
-							)
997
-						);
998
-					?>
991
+                        echo esc_url(
992
+                            wp_nonce_url(
993
+                                add_query_arg( 'getpaid-admin-action', 'create_missing_tables' ),
994
+                                'getpaid-nonce',
995
+                                'getpaid-nonce'
996
+                            )
997
+                        );
998
+                    ?>
999 999
                     " class="button button-primary"><?php esc_html_e( 'Run', 'invoicing' ); ?></a>
1000 1000
                 </td>
1001 1001
             </tr>
@@ -1007,14 +1007,14 @@  discard block
 block discarded – undo
1007 1007
                 <td>
1008 1008
 					<a href="
1009 1009
                     <?php
1010
-						echo esc_url(
1011
-							wp_nonce_url(
1012
-								add_query_arg( 'getpaid-admin-action', 'migrate_old_invoices' ),
1013
-								'getpaid-nonce',
1014
-								'getpaid-nonce'
1015
-							)
1016
-						);
1017
-					?>
1010
+                        echo esc_url(
1011
+                            wp_nonce_url(
1012
+                                add_query_arg( 'getpaid-admin-action', 'migrate_old_invoices' ),
1013
+                                'getpaid-nonce',
1014
+                                'getpaid-nonce'
1015
+                            )
1016
+                        );
1017
+                    ?>
1018 1018
                     " class="button button-primary"><?php esc_html_e( 'Run', 'invoicing' ); ?></a>
1019 1019
                 </td>
1020 1020
             </tr>
@@ -1027,14 +1027,14 @@  discard block
 block discarded – undo
1027 1027
                 <td>
1028 1028
 					<a href="
1029 1029
                     <?php
1030
-						echo esc_url(
1031
-							wp_nonce_url(
1032
-								add_query_arg( 'getpaid-admin-action', 'recalculate_discounts' ),
1033
-								'getpaid-nonce',
1034
-								'getpaid-nonce'
1035
-							)
1036
-						);
1037
-					?>
1030
+                        echo esc_url(
1031
+                            wp_nonce_url(
1032
+                                add_query_arg( 'getpaid-admin-action', 'recalculate_discounts' ),
1033
+                                'getpaid-nonce',
1034
+                                'getpaid-nonce'
1035
+                            )
1036
+                        );
1037
+                    ?>
1038 1038
                     " class="button button-primary"><?php esc_html_e( 'Run', 'invoicing' ); ?></a>
1039 1039
                 </td>
1040 1040
             </tr>
@@ -1047,8 +1047,8 @@  discard block
 block discarded – undo
1047 1047
                 <td>
1048 1048
 					<a href="
1049 1049
                     <?php
1050
-						echo esc_url( admin_url( 'index.php?page=gp-setup' ) );
1051
-					?>
1050
+                        echo esc_url( admin_url( 'index.php?page=gp-setup' ) );
1051
+                    ?>
1052 1052
                     " class="button button-primary"><?php esc_html_e( 'Launch', 'invoicing' ); ?></a>
1053 1053
                 </td>
1054 1054
             </tr>
@@ -1062,19 +1062,19 @@  discard block
 block discarded – undo
1062 1062
 
1063 1063
 
1064 1064
 function wpinv_descriptive_text_callback( $args ) {
1065
-	echo wp_kses_post( $args['desc'] );
1065
+    echo wp_kses_post( $args['desc'] );
1066 1066
 }
1067 1067
 
1068 1068
 function wpinv_raw_html_callback( $args ) {
1069
-	echo wp_kses( $args['desc'], getpaid_allowed_html() );
1069
+    echo wp_kses( $args['desc'], getpaid_allowed_html() );
1070 1070
 }
1071 1071
 
1072 1072
 function wpinv_hook_callback( $args ) {
1073
-	do_action( 'wpinv_' . $args['id'], $args );
1073
+    do_action( 'wpinv_' . $args['id'], $args );
1074 1074
 }
1075 1075
 
1076 1076
 function wpinv_set_settings_cap() {
1077
-	return wpinv_get_capability();
1077
+    return wpinv_get_capability();
1078 1078
 }
1079 1079
 add_filter( 'option_page_capability_wpinv_settings', 'wpinv_set_settings_cap' );
1080 1080
 
@@ -1098,15 +1098,15 @@  discard block
 block discarded – undo
1098 1098
  */
1099 1099
 function wpinv_get_merge_tags_help_text( $subscription = false ) {
1100 1100
 
1101
-	$url  = $subscription ? 'https://gist.github.com/picocodes/3d213982d57c34edf7a46fd3f0e8583e' : 'https://gist.github.com/picocodes/43bdc4d4bbba844534b2722e2af0b58f';
1102
-	$link = sprintf(
1103
-		'<strong><a href="%s" target="_blank">%s</a></strong>',
1104
-		$url,
1105
-		esc_html__( 'View available merge tags.', 'wpinv-quotes' )
1106
-	);
1101
+    $url  = $subscription ? 'https://gist.github.com/picocodes/3d213982d57c34edf7a46fd3f0e8583e' : 'https://gist.github.com/picocodes/43bdc4d4bbba844534b2722e2af0b58f';
1102
+    $link = sprintf(
1103
+        '<strong><a href="%s" target="_blank">%s</a></strong>',
1104
+        $url,
1105
+        esc_html__( 'View available merge tags.', 'wpinv-quotes' )
1106
+    );
1107 1107
 
1108
-	$description = esc_html__( 'The content of the email (Merge Tags and HTML are allowed).', 'invoicing' );
1108
+    $description = esc_html__( 'The content of the email (Merge Tags and HTML are allowed).', 'invoicing' );
1109 1109
 
1110
-	return "$description $link";
1110
+    return "$description $link";
1111 1111
 
1112 1112
 }
Please login to merge, or discard this patch.
Spacing   +369 added lines, -369 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
  * @since   1.0.0
7 7
  */
8 8
 
9
-defined( 'ABSPATH' ) || exit;
9
+defined('ABSPATH') || exit;
10 10
 
11 11
 /**
12 12
  * Retrieves all default settings.
@@ -16,13 +16,13 @@  discard block
 block discarded – undo
16 16
 function wpinv_get_settings() {
17 17
     $defaults = array();
18 18
 
19
-    foreach ( array_values( wpinv_get_registered_settings() ) as $tab_settings ) {
19
+    foreach (array_values(wpinv_get_registered_settings()) as $tab_settings) {
20 20
 
21
-        foreach ( array_values( $tab_settings ) as $section_settings ) {
21
+        foreach (array_values($tab_settings) as $section_settings) {
22 22
 
23
-            foreach ( $section_settings as $key => $setting ) {
24
-                if ( isset( $setting['std'] ) ) {
25
-                    $defaults[ $key ] = $setting['std'];
23
+            foreach ($section_settings as $key => $setting) {
24
+                if (isset($setting['std'])) {
25
+                    $defaults[$key] = $setting['std'];
26 26
                 }
27 27
             }
28 28
 }
@@ -41,12 +41,12 @@  discard block
 block discarded – undo
41 41
     global $wpinv_options;
42 42
 
43 43
     // Try fetching the saved options.
44
-    if ( empty( $wpinv_options ) ) {
45
-        $wpinv_options = get_option( 'wpinv_settings' );
44
+    if (empty($wpinv_options)) {
45
+        $wpinv_options = get_option('wpinv_settings');
46 46
     }
47 47
 
48 48
     // If that fails, don't fetch the default settings to prevent a loop.
49
-    if ( ! is_array( $wpinv_options ) ) {
49
+    if (!is_array($wpinv_options)) {
50 50
         $wpinv_options = array();
51 51
     }
52 52
 
@@ -60,13 +60,13 @@  discard block
 block discarded – undo
60 60
  * @param mixed $default The default value to use if the setting has not been set.
61 61
  * @return mixed
62 62
  */
63
-function wpinv_get_option( $key = '', $default = false ) {
63
+function wpinv_get_option($key = '', $default = false) {
64 64
 
65 65
     $options = wpinv_get_options();
66
-    $value   = isset( $options[ $key ] ) ? $options[ $key ] : $default;
67
-    $value   = apply_filters( 'wpinv_get_option', $value, $key, $default );
66
+    $value   = isset($options[$key]) ? $options[$key] : $default;
67
+    $value   = apply_filters('wpinv_get_option', $value, $key, $default);
68 68
 
69
-    return apply_filters( 'wpinv_get_option_' . $key, $value, $key, $default );
69
+    return apply_filters('wpinv_get_option_' . $key, $value, $key, $default);
70 70
 }
71 71
 
72 72
 /**
@@ -75,11 +75,11 @@  discard block
 block discarded – undo
75 75
  * @param array $options the new options.
76 76
  * @return bool
77 77
  */
78
-function wpinv_update_options( $options ) {
78
+function wpinv_update_options($options) {
79 79
     global $wpinv_options;
80 80
 
81 81
     // update the option.
82
-    if ( is_array( $options ) && update_option( 'wpinv_settings', $options ) ) {
82
+    if (is_array($options) && update_option('wpinv_settings', $options)) {
83 83
         $wpinv_options = $options;
84 84
         return true;
85 85
     }
@@ -94,24 +94,24 @@  discard block
 block discarded – undo
94 94
  * @param mixed $value The setting value.
95 95
  * @return bool
96 96
  */
97
-function wpinv_update_option( $key = '', $value = false ) {
97
+function wpinv_update_option($key = '', $value = false) {
98 98
 
99 99
     // If no key, exit.
100
-    if ( empty( $key ) ) {
100
+    if (empty($key)) {
101 101
         return false;
102 102
     }
103 103
 
104 104
     // Maybe delete the option instead.
105
-    if ( is_null( $value ) ) {
106
-        return wpinv_delete_option( $key );
105
+    if (is_null($value)) {
106
+        return wpinv_delete_option($key);
107 107
     }
108 108
 
109 109
     // Prepare the new options.
110 110
     $options         = wpinv_get_options();
111
-    $options[ $key ] = apply_filters( 'wpinv_update_option', $value, $key );
111
+    $options[$key] = apply_filters('wpinv_update_option', $value, $key);
112 112
 
113 113
     // Save the new options.
114
-    return wpinv_update_options( $options );
114
+    return wpinv_update_options($options);
115 115
 
116 116
 }
117 117
 
@@ -121,18 +121,18 @@  discard block
 block discarded – undo
121 121
  * @param string $key the setting key.
122 122
  * @return bool
123 123
  */
124
-function wpinv_delete_option( $key = '' ) {
124
+function wpinv_delete_option($key = '') {
125 125
 
126 126
     // If no key, exit
127
-    if ( empty( $key ) ) {
127
+    if (empty($key)) {
128 128
         return false;
129 129
     }
130 130
 
131 131
     $options = wpinv_get_options();
132 132
 
133
-    if ( isset( $options[ $key ] ) ) {
134
-        unset( $options[ $key ] );
135
-        return wpinv_update_options( $options );
133
+    if (isset($options[$key])) {
134
+        unset($options[$key]);
135
+        return wpinv_update_options($options);
136 136
     }
137 137
 
138 138
     return true;
@@ -146,14 +146,14 @@  discard block
 block discarded – undo
146 146
 function wpinv_register_settings() {
147 147
 
148 148
     // Loop through all tabs.
149
-    foreach ( wpinv_get_registered_settings() as $tab => $sections ) {
149
+    foreach (wpinv_get_registered_settings() as $tab => $sections) {
150 150
 
151 151
         // In each tab, loop through sections.
152
-        foreach ( $sections as $section => $settings ) {
152
+        foreach ($sections as $section => $settings) {
153 153
 
154 154
             // Check for backwards compatibility
155
-            $section_tabs = wpinv_get_settings_tab_sections( $tab );
156
-            if ( ! is_array( $section_tabs ) || ! array_key_exists( $section, $section_tabs ) ) {
155
+            $section_tabs = wpinv_get_settings_tab_sections($tab);
156
+            if (!is_array($section_tabs) || !array_key_exists($section, $section_tabs)) {
157 157
                 $section = 'main';
158 158
                 $settings = $sections;
159 159
             }
@@ -166,18 +166,18 @@  discard block
 block discarded – undo
166 166
                 'wpinv_settings_' . $tab . '_' . $section
167 167
             );
168 168
 
169
-            foreach ( $settings as $option ) {
170
-                if ( ! empty( $option['id'] ) ) {
171
-                    wpinv_register_settings_option( $tab, $section, $option );
169
+            foreach ($settings as $option) {
170
+                if (!empty($option['id'])) {
171
+                    wpinv_register_settings_option($tab, $section, $option);
172 172
                 }
173 173
             }
174 174
 }
175 175
     }
176 176
 
177 177
     // Creates our settings in the options table.
178
-    register_setting( 'wpinv_settings', 'wpinv_settings', 'wpinv_settings_sanitize' );
178
+    register_setting('wpinv_settings', 'wpinv_settings', 'wpinv_settings_sanitize');
179 179
 }
180
-add_action( 'admin_init', 'wpinv_register_settings' );
180
+add_action('admin_init', 'wpinv_register_settings');
181 181
 
182 182
 /**
183 183
  * Register a single settings option.
@@ -187,49 +187,49 @@  discard block
 block discarded – undo
187 187
  * @param string $option
188 188
  *
189 189
  */
190
-function wpinv_register_settings_option( $tab, $section, $option ) {
190
+function wpinv_register_settings_option($tab, $section, $option) {
191 191
 
192
-    $name       = isset( $option['name'] ) ? $option['name'] : '';
192
+    $name       = isset($option['name']) ? $option['name'] : '';
193 193
     $cb         = "wpinv_{$option['type']}_callback";
194 194
     $section    = "wpinv_settings_{$tab}_$section";
195
-	$is_wizzard = is_admin() && isset( $_GET['page'] ) && 'gp-setup' == $_GET['page'];
195
+	$is_wizzard = is_admin() && isset($_GET['page']) && 'gp-setup' == $_GET['page'];
196 196
 
197
-	if ( isset( $option['desc'] ) && ( ! $is_wizzard && ! empty( $option['help-tip'] ) ) ) {
198
-		$tip   = wpinv_clean( $option['desc'] );
197
+	if (isset($option['desc']) && (!$is_wizzard && !empty($option['help-tip']))) {
198
+		$tip   = wpinv_clean($option['desc']);
199 199
 		$name .= "<span class='dashicons dashicons-editor-help wpi-help-tip' title='$tip'></span>";
200
-		unset( $option['desc'] );
200
+		unset($option['desc']);
201 201
 	}
202 202
 
203 203
     // Loop through all tabs.
204 204
     add_settings_field(
205 205
         'wpinv_settings[' . $option['id'] . ']',
206 206
         $name,
207
-        function_exists( $cb ) ? $cb : 'wpinv_missing_callback',
207
+        function_exists($cb) ? $cb : 'wpinv_missing_callback',
208 208
         $section,
209 209
         $section,
210 210
         array(
211 211
             'section'         => $section,
212
-            'id'              => isset( $option['id'] ) ? $option['id'] : uniqid( 'wpinv-' ),
213
-            'desc'            => isset( $option['desc'] ) ? $option['desc'] : '',
212
+            'id'              => isset($option['id']) ? $option['id'] : uniqid('wpinv-'),
213
+            'desc'            => isset($option['desc']) ? $option['desc'] : '',
214 214
             'name'            => $name,
215
-            'size'            => isset( $option['size'] ) ? $option['size'] : null,
216
-            'options'         => isset( $option['options'] ) ? $option['options'] : '',
217
-            'selected'        => isset( $option['selected'] ) ? $option['selected'] : null,
218
-            'std'             => isset( $option['std'] ) ? $option['std'] : '',
219
-            'min'             => isset( $option['min'] ) ? $option['min'] : 0,
220
-            'max'             => isset( $option['max'] ) ? $option['max'] : 999999,
221
-            'step'            => isset( $option['step'] ) ? $option['step'] : 1,
222
-            'placeholder'     => isset( $option['placeholder'] ) ? $option['placeholder'] : null,
223
-            'allow_blank'     => isset( $option['allow_blank'] ) ? $option['allow_blank'] : true,
224
-            'readonly'        => isset( $option['readonly'] ) ? $option['readonly'] : false,
225
-            'faux'            => isset( $option['faux'] ) ? $option['faux'] : false,
226
-            'onchange'        => isset( $option['onchange'] ) ? $option['onchange'] : '',
227
-            'custom'          => isset( $option['custom'] ) ? $option['custom'] : '',
228
-			'default_content' => isset( $option['default_content'] ) ? $option['default_content'] : '',
229
-			'class'           => isset( $option['class'] ) ? $option['class'] : '',
230
-			'style'           => isset( $option['style'] ) ? $option['style'] : '',
231
-            'cols'            => isset( $option['cols'] ) && (int) $option['cols'] > 0 ? (int) $option['cols'] : 50,
232
-            'rows'            => isset( $option['rows'] ) && (int) $option['rows'] > 0 ? (int) $option['rows'] : 5,
215
+            'size'            => isset($option['size']) ? $option['size'] : null,
216
+            'options'         => isset($option['options']) ? $option['options'] : '',
217
+            'selected'        => isset($option['selected']) ? $option['selected'] : null,
218
+            'std'             => isset($option['std']) ? $option['std'] : '',
219
+            'min'             => isset($option['min']) ? $option['min'] : 0,
220
+            'max'             => isset($option['max']) ? $option['max'] : 999999,
221
+            'step'            => isset($option['step']) ? $option['step'] : 1,
222
+            'placeholder'     => isset($option['placeholder']) ? $option['placeholder'] : null,
223
+            'allow_blank'     => isset($option['allow_blank']) ? $option['allow_blank'] : true,
224
+            'readonly'        => isset($option['readonly']) ? $option['readonly'] : false,
225
+            'faux'            => isset($option['faux']) ? $option['faux'] : false,
226
+            'onchange'        => isset($option['onchange']) ? $option['onchange'] : '',
227
+            'custom'          => isset($option['custom']) ? $option['custom'] : '',
228
+			'default_content' => isset($option['default_content']) ? $option['default_content'] : '',
229
+			'class'           => isset($option['class']) ? $option['class'] : '',
230
+			'style'           => isset($option['style']) ? $option['style'] : '',
231
+            'cols'            => isset($option['cols']) && (int) $option['cols'] > 0 ? (int) $option['cols'] : 50,
232
+            'rows'            => isset($option['rows']) && (int) $option['rows'] > 0 ? (int) $option['rows'] : 5,
233 233
         )
234 234
     );
235 235
 
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
  * @return array
242 242
  */
243 243
 function wpinv_get_registered_settings() {
244
-	return array_filter( apply_filters( 'wpinv_registered_settings', wpinv_get_data( 'admin-settings' ) ) );
244
+	return array_filter(apply_filters('wpinv_registered_settings', wpinv_get_data('admin-settings')));
245 245
 }
246 246
 
247 247
 /**
@@ -250,7 +250,7 @@  discard block
 block discarded – undo
250 250
  * @return array
251 251
  */
252 252
 function getpaid_get_integration_settings() {
253
-    return apply_filters( 'getpaid_integration_settings', array() );
253
+    return apply_filters('getpaid_integration_settings', array());
254 254
 }
255 255
 
256 256
 /**
@@ -258,126 +258,126 @@  discard block
 block discarded – undo
258 258
  *
259 259
  * @return array
260 260
  */
261
-function wpinv_settings_sanitize( $input = array() ) {
261
+function wpinv_settings_sanitize($input = array()) {
262 262
 
263 263
 	$wpinv_options = wpinv_get_options();
264 264
 	$raw_referrer  = wp_get_raw_referer();
265 265
 
266
-    if ( empty( $raw_referrer ) ) {
267
-		return array_merge( $wpinv_options, $input );
266
+    if (empty($raw_referrer)) {
267
+		return array_merge($wpinv_options, $input);
268 268
     }
269 269
 
270
-    wp_parse_str( $raw_referrer, $referrer );
270
+    wp_parse_str($raw_referrer, $referrer);
271 271
 
272
-	if ( in_array( 'gp-setup', $referrer ) ) {
273
-		return array_merge( $wpinv_options, $input );
272
+	if (in_array('gp-setup', $referrer)) {
273
+		return array_merge($wpinv_options, $input);
274 274
 	}
275 275
 
276 276
     $settings = wpinv_get_registered_settings();
277
-    $tab      = isset( $referrer['tab'] ) ? $referrer['tab'] : 'general';
278
-    $section  = isset( $referrer['section'] ) ? $referrer['section'] : 'main';
277
+    $tab      = isset($referrer['tab']) ? $referrer['tab'] : 'general';
278
+    $section  = isset($referrer['section']) ? $referrer['section'] : 'main';
279 279
 
280 280
     $input = $input ? $input : array();
281
-    $input = apply_filters( 'wpinv_settings_tab_' . $tab . '_sanitize', $input );
282
-    $input = apply_filters( 'wpinv_settings_' . $tab . '-' . $section . '_sanitize', $input );
281
+    $input = apply_filters('wpinv_settings_tab_' . $tab . '_sanitize', $input);
282
+    $input = apply_filters('wpinv_settings_' . $tab . '-' . $section . '_sanitize', $input);
283 283
 
284 284
     // Loop through each setting being saved and pass it through a sanitization filter
285
-    foreach ( $input as $key => $value ) {
285
+    foreach ($input as $key => $value) {
286 286
 
287 287
         // Get the setting type (checkbox, select, etc)
288
-        $type = isset( $settings[ $tab ][ $section ][ $key ]['type'] ) ? $settings[ $tab ][ $section ][ $key ]['type'] : false;
288
+        $type = isset($settings[$tab][$section][$key]['type']) ? $settings[$tab][$section][$key]['type'] : false;
289 289
 
290
-        if ( $type ) {
290
+        if ($type) {
291 291
             // Field type specific filter
292
-            $input[ $key ] = apply_filters( "wpinv_settings_sanitize_$type", $value, $key );
292
+            $input[$key] = apply_filters("wpinv_settings_sanitize_$type", $value, $key);
293 293
         }
294 294
 
295 295
         // General filter
296
-		$input[ $key ] = apply_filters( 'wpinv_settings_sanitize', $input[ $key ], $key );
296
+		$input[$key] = apply_filters('wpinv_settings_sanitize', $input[$key], $key);
297 297
 
298 298
 		// Key specific filter.
299
-		$input[ $key ] = apply_filters( "wpinv_settings_sanitize_$key", $input[ $key ] );
299
+		$input[$key] = apply_filters("wpinv_settings_sanitize_$key", $input[$key]);
300 300
     }
301 301
 
302 302
     // Loop through the whitelist and unset any that are empty for the tab being saved
303
-    $main_settings    = isset( $settings[ $tab ] ) ? $settings[ $tab ] : array(); // Check for extensions that aren't using new sections
304
-    $section_settings = ! empty( $settings[ $tab ][ $section ] ) ? $settings[ $tab ][ $section ] : array();
303
+    $main_settings    = isset($settings[$tab]) ? $settings[$tab] : array(); // Check for extensions that aren't using new sections
304
+    $section_settings = !empty($settings[$tab][$section]) ? $settings[$tab][$section] : array();
305 305
 
306
-    $found_settings   = array_merge( $main_settings, $section_settings );
306
+    $found_settings   = array_merge($main_settings, $section_settings);
307 307
 
308
-    if ( ! empty( $found_settings ) ) {
309
-        foreach ( $found_settings as $key => $value ) {
308
+    if (!empty($found_settings)) {
309
+        foreach ($found_settings as $key => $value) {
310 310
 
311 311
             // settings used to have numeric keys, now they have keys that match the option ID. This ensures both methods work
312
-            if ( is_numeric( $key ) ) {
312
+            if (is_numeric($key)) {
313 313
                 $key = $value['id'];
314 314
             }
315 315
 
316
-            if ( ! isset( $input[ $key ] ) && isset( $wpinv_options[ $key ] ) ) {
317
-                unset( $wpinv_options[ $key ] );
316
+            if (!isset($input[$key]) && isset($wpinv_options[$key])) {
317
+                unset($wpinv_options[$key]);
318 318
             }
319 319
         }
320 320
     }
321 321
 
322 322
     // Merge our new settings with the existing
323
-    $output = array_merge( $wpinv_options, $input );
323
+    $output = array_merge($wpinv_options, $input);
324 324
 
325
-    add_settings_error( 'wpinv-notices', '', __( 'Settings updated.', 'invoicing' ), 'updated' );
325
+    add_settings_error('wpinv-notices', '', __('Settings updated.', 'invoicing'), 'updated');
326 326
 
327 327
     return $output;
328 328
 }
329
-add_filter( 'wpinv_settings_sanitize_text', 'trim', 10, 1 );
330
-add_filter( 'wpinv_settings_sanitize_tax_rate', 'wpinv_sanitize_amount' );
329
+add_filter('wpinv_settings_sanitize_text', 'trim', 10, 1);
330
+add_filter('wpinv_settings_sanitize_tax_rate', 'wpinv_sanitize_amount');
331 331
 
332
-function wpinv_settings_sanitize_tax_rates( $input ) {
333
-    if ( ! wpinv_current_user_can_manage_invoicing() ) {
332
+function wpinv_settings_sanitize_tax_rates($input) {
333
+    if (!wpinv_current_user_can_manage_invoicing()) {
334 334
         return $input;
335 335
     }
336 336
 
337
-    $new_rates = ! empty( $_POST['tax_rates'] ) ? wp_kses_post_deep( array_values( $_POST['tax_rates'] ) ) : array();
337
+    $new_rates = !empty($_POST['tax_rates']) ? wp_kses_post_deep(array_values($_POST['tax_rates'])) : array();
338 338
     $tax_rates = array();
339 339
 
340
-    foreach ( $new_rates as $rate ) {
340
+    foreach ($new_rates as $rate) {
341 341
 
342
-		$rate['rate']    = wpinv_sanitize_amount( $rate['rate'] );
343
-		$rate['name']    = sanitize_text_field( $rate['name'] );
344
-		$rate['state']   = sanitize_text_field( $rate['state'] );
345
-		$rate['country'] = sanitize_text_field( $rate['country'] );
346
-		$rate['global']  = empty( $rate['state'] );
342
+		$rate['rate']    = wpinv_sanitize_amount($rate['rate']);
343
+		$rate['name']    = sanitize_text_field($rate['name']);
344
+		$rate['state']   = sanitize_text_field($rate['state']);
345
+		$rate['country'] = sanitize_text_field($rate['country']);
346
+		$rate['global']  = empty($rate['state']);
347 347
 		$tax_rates[]     = $rate;
348 348
 
349 349
 	}
350 350
 
351
-    update_option( 'wpinv_tax_rates', $tax_rates );
351
+    update_option('wpinv_tax_rates', $tax_rates);
352 352
 
353 353
     return $input;
354 354
 }
355
-add_filter( 'wpinv_settings_taxes-rates_sanitize', 'wpinv_settings_sanitize_tax_rates' );
355
+add_filter('wpinv_settings_taxes-rates_sanitize', 'wpinv_settings_sanitize_tax_rates');
356 356
 
357 357
 function wpinv_get_settings_tabs() {
358 358
     $tabs             = array();
359
-    $tabs['general']  = __( 'General', 'invoicing' );
360
-    $tabs['gateways'] = __( 'Payment Gateways', 'invoicing' );
361
-    $tabs['taxes']    = __( 'Taxes', 'invoicing' );
362
-	$tabs['emails']   = __( 'Emails', 'invoicing' );
359
+    $tabs['general']  = __('General', 'invoicing');
360
+    $tabs['gateways'] = __('Payment Gateways', 'invoicing');
361
+    $tabs['taxes']    = __('Taxes', 'invoicing');
362
+	$tabs['emails'] = __('Emails', 'invoicing');
363 363
 
364
-	if ( count( getpaid_get_integration_settings() ) > 0 ) {
365
-		$tabs['integrations'] = __( 'Integrations', 'invoicing' );
364
+	if (count(getpaid_get_integration_settings()) > 0) {
365
+		$tabs['integrations'] = __('Integrations', 'invoicing');
366 366
 	}
367 367
 
368
-    $tabs['privacy']  = __( 'Privacy', 'invoicing' );
369
-    $tabs['misc']     = __( 'Misc', 'invoicing' );
370
-    $tabs['tools']    = __( 'Tools', 'invoicing' );
368
+    $tabs['privacy']  = __('Privacy', 'invoicing');
369
+    $tabs['misc']     = __('Misc', 'invoicing');
370
+    $tabs['tools']    = __('Tools', 'invoicing');
371 371
 
372
-    return apply_filters( 'wpinv_settings_tabs', $tabs );
372
+    return apply_filters('wpinv_settings_tabs', $tabs);
373 373
 }
374 374
 
375
-function wpinv_get_settings_tab_sections( $tab = false ) {
375
+function wpinv_get_settings_tab_sections($tab = false) {
376 376
     $tabs     = false;
377 377
     $sections = wpinv_get_registered_settings_sections();
378 378
 
379
-    if ( $tab && ! empty( $sections[ $tab ] ) ) {
380
-        $tabs = $sections[ $tab ];
379
+    if ($tab && !empty($sections[$tab])) {
380
+        $tabs = $sections[$tab];
381 381
     }
382 382
 
383 383
     return $tabs;
@@ -386,7 +386,7 @@  discard block
 block discarded – undo
386 386
 function wpinv_get_registered_settings_sections() {
387 387
     static $sections = false;
388 388
 
389
-    if ( false !== $sections ) {
389
+    if (false !== $sections) {
390 390
         return $sections;
391 391
     }
392 392
 
@@ -394,230 +394,230 @@  discard block
 block discarded – undo
394 394
         'general'      => apply_filters(
395 395
             'wpinv_settings_sections_general',
396 396
             array(
397
-				'main'             => __( 'General Settings', 'invoicing' ),
398
-				'page_section'     => __( 'Page Settings', 'invoicing' ),
399
-				'currency_section' => __( 'Currency Settings', 'invoicing' ),
400
-				'labels'           => __( 'Label Texts', 'invoicing' ),
397
+				'main'             => __('General Settings', 'invoicing'),
398
+				'page_section'     => __('Page Settings', 'invoicing'),
399
+				'currency_section' => __('Currency Settings', 'invoicing'),
400
+				'labels'           => __('Label Texts', 'invoicing'),
401 401
             )
402 402
         ),
403 403
         'gateways'     => apply_filters(
404 404
             'wpinv_settings_sections_gateways',
405 405
             array(
406
-				'main' => __( 'Gateway Settings', 'invoicing' ),
406
+				'main' => __('Gateway Settings', 'invoicing'),
407 407
             )
408 408
         ),
409 409
         'taxes'        => apply_filters(
410 410
             'wpinv_settings_sections_taxes',
411 411
             array(
412
-				'main'  => __( 'Tax Settings', 'invoicing' ),
413
-				'rates' => __( 'Tax Rates', 'invoicing' ),
414
-				'vat'   => __( 'EU VAT Settings', 'invoicing' ),
412
+				'main'  => __('Tax Settings', 'invoicing'),
413
+				'rates' => __('Tax Rates', 'invoicing'),
414
+				'vat'   => __('EU VAT Settings', 'invoicing'),
415 415
             )
416 416
         ),
417 417
         'emails'       => apply_filters(
418 418
             'wpinv_settings_sections_emails',
419 419
             array(
420
-				'main' => __( 'Email Settings', 'invoicing' ),
420
+				'main' => __('Email Settings', 'invoicing'),
421 421
             )
422 422
         ),
423 423
 
424
-		'integrations' => wp_list_pluck( getpaid_get_integration_settings(), 'label', 'id' ),
424
+		'integrations' => wp_list_pluck(getpaid_get_integration_settings(), 'label', 'id'),
425 425
 
426 426
         'privacy'      => apply_filters(
427 427
             'wpinv_settings_sections_privacy',
428 428
             array(
429
-				'main' => __( 'Privacy policy', 'invoicing' ),
429
+				'main' => __('Privacy policy', 'invoicing'),
430 430
             )
431 431
         ),
432 432
         'misc'         => apply_filters(
433 433
             'wpinv_settings_sections_misc',
434 434
             array(
435
-				'main'       => __( 'Miscellaneous', 'invoicing' ),
436
-				'custom-css' => __( 'Custom CSS', 'invoicing' ),
435
+				'main'       => __('Miscellaneous', 'invoicing'),
436
+				'custom-css' => __('Custom CSS', 'invoicing'),
437 437
             )
438 438
         ),
439 439
         'tools'        => apply_filters(
440 440
             'wpinv_settings_sections_tools',
441 441
             array(
442
-				'main' => __( 'Diagnostic Tools', 'invoicing' ),
442
+				'main' => __('Diagnostic Tools', 'invoicing'),
443 443
             )
444 444
         ),
445 445
     );
446 446
 
447
-    $sections = apply_filters( 'wpinv_settings_sections', $sections );
447
+    $sections = apply_filters('wpinv_settings_sections', $sections);
448 448
 
449 449
     return $sections;
450 450
 }
451 451
 
452
-function wpinv_get_pages( $with_slug = false, $default_label = null ) {
452
+function wpinv_get_pages($with_slug = false, $default_label = null) {
453 453
 	$pages_options = array();
454 454
 
455
-	if ( $default_label !== null && $default_label !== false ) {
456
-		$pages_options = array( '' => $default_label ); // Blank option
455
+	if ($default_label !== null && $default_label !== false) {
456
+		$pages_options = array('' => $default_label); // Blank option
457 457
 	}
458 458
 
459 459
 	$pages = get_pages();
460
-	if ( $pages ) {
461
-		foreach ( $pages as $page ) {
460
+	if ($pages) {
461
+		foreach ($pages as $page) {
462 462
 			$title = $with_slug ? $page->post_title . ' (' . $page->post_name . ')' : $page->post_title;
463
-            $pages_options[ $page->ID ] = $title;
463
+            $pages_options[$page->ID] = $title;
464 464
 		}
465 465
 	}
466 466
 
467 467
 	return $pages_options;
468 468
 }
469 469
 
470
-function wpinv_header_callback( $args ) {
471
-	if ( ! empty( $args['desc'] ) ) {
472
-        echo wp_kses_post( $args['desc'] );
470
+function wpinv_header_callback($args) {
471
+	if (!empty($args['desc'])) {
472
+        echo wp_kses_post($args['desc']);
473 473
     }
474 474
 }
475 475
 
476
-function wpinv_hidden_callback( $args ) {
476
+function wpinv_hidden_callback($args) {
477 477
 
478
-	$std     = isset( $args['std'] ) ? $args['std'] : '';
479
-	$value   = wpinv_get_option( $args['id'], $std );
478
+	$std     = isset($args['std']) ? $args['std'] : '';
479
+	$value   = wpinv_get_option($args['id'], $std);
480 480
 
481
-	if ( isset( $args['set_value'] ) ) {
481
+	if (isset($args['set_value'])) {
482 482
 		$value = $args['set_value'];
483 483
 	}
484 484
 
485
-	if ( isset( $args['faux'] ) && true === $args['faux'] ) {
485
+	if (isset($args['faux']) && true === $args['faux']) {
486 486
 		$args['readonly'] = true;
487
-		$name  = '';
487
+		$name = '';
488 488
 	} else {
489
-		$name = 'wpinv_settings[' . esc_attr( $args['id'] ) . ']';
489
+		$name = 'wpinv_settings[' . esc_attr($args['id']) . ']';
490 490
 	}
491 491
 
492
-	echo '<input type="hidden" id="wpinv_settings[' . esc_attr( $args['id'] ) . ']" name="' . esc_attr( $name ) . '" value="' . esc_attr( stripslashes( $value ) ) . '" />';
492
+	echo '<input type="hidden" id="wpinv_settings[' . esc_attr($args['id']) . ']" name="' . esc_attr($name) . '" value="' . esc_attr(stripslashes($value)) . '" />';
493 493
 
494 494
 }
495 495
 
496 496
 /**
497 497
  * Displays a checkbox settings callback.
498 498
  */
499
-function wpinv_checkbox_callback( $args ) {
499
+function wpinv_checkbox_callback($args) {
500 500
 
501
-	$std = isset( $args['std'] ) ? $args['std'] : '';
502
-	$std = wpinv_get_option( $args['id'], $std );
503
-	$id  = esc_attr( $args['id'] );
501
+	$std = isset($args['std']) ? $args['std'] : '';
502
+	$std = wpinv_get_option($args['id'], $std);
503
+	$id  = esc_attr($args['id']);
504 504
 
505
-	getpaid_hidden_field( "wpinv_settings[$id]", '0' );
505
+	getpaid_hidden_field("wpinv_settings[$id]", '0');
506 506
 	?>
507 507
 		<fieldset>
508 508
 			<label>
509
-				<input id="wpinv-settings-<?php echo esc_attr( $id ); ?>" name="wpinv_settings[<?php echo esc_attr( $id ); ?>]" <?php checked( empty( $std ), false ); ?> value="1" type="checkbox">
510
-				<?php echo wp_kses_post( $args['desc'] ); ?>
509
+				<input id="wpinv-settings-<?php echo esc_attr($id); ?>" name="wpinv_settings[<?php echo esc_attr($id); ?>]" <?php checked(empty($std), false); ?> value="1" type="checkbox">
510
+				<?php echo wp_kses_post($args['desc']); ?>
511 511
 			</label>
512 512
 		</fieldset>
513 513
 	<?php
514 514
 }
515 515
 
516
-function wpinv_multicheck_callback( $args ) {
516
+function wpinv_multicheck_callback($args) {
517 517
 
518
-	$sanitize_id = wpinv_sanitize_key( $args['id'] );
519
-	$class = ! empty( $args['class'] ) ? ' ' . esc_attr( $args['class'] ) : '';
518
+	$sanitize_id = wpinv_sanitize_key($args['id']);
519
+	$class = !empty($args['class']) ? ' ' . esc_attr($args['class']) : '';
520 520
 
521
-	if ( ! empty( $args['options'] ) ) {
521
+	if (!empty($args['options'])) {
522 522
 
523
-		$std     = isset( $args['std'] ) ? $args['std'] : array();
524
-		$value   = wpinv_get_option( $args['id'], $std );
523
+		$std     = isset($args['std']) ? $args['std'] : array();
524
+		$value   = wpinv_get_option($args['id'], $std);
525 525
 
526
-		echo '<div class="wpi-mcheck-rows wpi-mcheck-' . esc_attr( $sanitize_id . $class ) . '">';
527
-        foreach ( $args['options'] as $key => $option ) :
528
-			$sanitize_key = esc_attr( wpinv_sanitize_key( $key ) );
529
-			if ( in_array( $sanitize_key, $value ) ) {
526
+		echo '<div class="wpi-mcheck-rows wpi-mcheck-' . esc_attr($sanitize_id . $class) . '">';
527
+        foreach ($args['options'] as $key => $option) :
528
+			$sanitize_key = esc_attr(wpinv_sanitize_key($key));
529
+			if (in_array($sanitize_key, $value)) {
530 530
 				$enabled = $sanitize_key;
531 531
 			} else {
532 532
 				$enabled = null;
533 533
 			}
534
-			echo '<div class="wpi-mcheck-row"><input name="wpinv_settings[' . esc_attr( $sanitize_id ) . '][' . esc_attr( $sanitize_key ) . ']" id="wpinv_settings[' . esc_attr( $sanitize_id ) . '][' . esc_attr( $sanitize_key ) . ']" type="checkbox" value="' . esc_attr( $sanitize_key ) . '" ' . checked( $sanitize_key, $enabled, false ) . '/>&nbsp;';
535
-			echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . '][' . esc_attr( $sanitize_key ) . ']">' . wp_kses_post( $option ) . '</label></div>';
534
+			echo '<div class="wpi-mcheck-row"><input name="wpinv_settings[' . esc_attr($sanitize_id) . '][' . esc_attr($sanitize_key) . ']" id="wpinv_settings[' . esc_attr($sanitize_id) . '][' . esc_attr($sanitize_key) . ']" type="checkbox" value="' . esc_attr($sanitize_key) . '" ' . checked($sanitize_key, $enabled, false) . '/>&nbsp;';
535
+			echo '<label for="wpinv_settings[' . esc_attr($sanitize_id) . '][' . esc_attr($sanitize_key) . ']">' . wp_kses_post($option) . '</label></div>';
536 536
 		endforeach;
537 537
 		echo '</div>';
538
-		echo '<p class="description">' . wp_kses_post( $args['desc'] ) . '</p>';
538
+		echo '<p class="description">' . wp_kses_post($args['desc']) . '</p>';
539 539
 	}
540 540
 }
541 541
 
542
-function wpinv_payment_icons_callback( $args ) {
542
+function wpinv_payment_icons_callback($args) {
543 543
 
544
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
545
-	$value   = wpinv_get_option( $args['id'], false );
544
+    $sanitize_id = wpinv_sanitize_key($args['id']);
545
+	$value = wpinv_get_option($args['id'], false);
546 546
 
547
-	if ( ! empty( $args['options'] ) ) {
548
-		foreach ( $args['options'] as $key => $option ) {
549
-            $sanitize_key = wpinv_sanitize_key( $key );
547
+	if (!empty($args['options'])) {
548
+		foreach ($args['options'] as $key => $option) {
549
+            $sanitize_key = wpinv_sanitize_key($key);
550 550
 
551
-			if ( empty( $value ) ) {
551
+			if (empty($value)) {
552 552
 				$enabled = $option;
553 553
 			} else {
554 554
 				$enabled = null;
555 555
 			}
556 556
 
557
-			echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . '][' . esc_attr( $sanitize_key ) . ']" style="margin-right:10px;line-height:16px;height:16px;display:inline-block;">';
557
+			echo '<label for="wpinv_settings[' . esc_attr($sanitize_id) . '][' . esc_attr($sanitize_key) . ']" style="margin-right:10px;line-height:16px;height:16px;display:inline-block;">';
558 558
 
559
-				echo '<input name="wpinv_settings[' . esc_attr( $sanitize_id ) . '][' . esc_attr( $sanitize_key ) . ']" id="wpinv_settings[' . esc_attr( $sanitize_id ) . '][' . esc_attr( $sanitize_key ) . ']" type="checkbox" value="' . esc_attr( $option ) . '" ' . checked( $option, $enabled, false ) . '/>&nbsp;';
559
+				echo '<input name="wpinv_settings[' . esc_attr($sanitize_id) . '][' . esc_attr($sanitize_key) . ']" id="wpinv_settings[' . esc_attr($sanitize_id) . '][' . esc_attr($sanitize_key) . ']" type="checkbox" value="' . esc_attr($option) . '" ' . checked($option, $enabled, false) . '/>&nbsp;';
560 560
 
561
-				if ( wpinv_string_is_image_url( $key ) ) {
562
-				echo '<img class="payment-icon" src="' . esc_url( $key ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>';
561
+				if (wpinv_string_is_image_url($key)) {
562
+				echo '<img class="payment-icon" src="' . esc_url($key) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>';
563 563
 				} else {
564
-				$card = strtolower( str_replace( ' ', '', $option ) );
564
+				$card = strtolower(str_replace(' ', '', $option));
565 565
 
566
-				if ( has_filter( 'wpinv_accepted_payment_' . $card . '_image' ) ) {
567
-					$image = apply_filters( 'wpinv_accepted_payment_' . $card . '_image', '' );
566
+				if (has_filter('wpinv_accepted_payment_' . $card . '_image')) {
567
+					$image = apply_filters('wpinv_accepted_payment_' . $card . '_image', '');
568 568
 					} else {
569
-					$image       = wpinv_locate_template( 'images' . DIRECTORY_SEPARATOR . 'icons' . DIRECTORY_SEPARATOR . $card . '.gif', false );
569
+					$image       = wpinv_locate_template('images' . DIRECTORY_SEPARATOR . 'icons' . DIRECTORY_SEPARATOR . $card . '.gif', false);
570 570
 					$content_dir = WP_CONTENT_DIR;
571 571
 
572
-					if ( function_exists( 'wp_normalize_path' ) ) {
572
+					if (function_exists('wp_normalize_path')) {
573 573
 						// Replaces backslashes with forward slashes for Windows systems
574
-						$image = wp_normalize_path( $image );
575
-						$content_dir = wp_normalize_path( $content_dir );
574
+						$image = wp_normalize_path($image);
575
+						$content_dir = wp_normalize_path($content_dir);
576 576
 						}
577 577
 
578
-					$image = str_replace( $content_dir, content_url(), $image );
578
+					$image = str_replace($content_dir, content_url(), $image);
579 579
 					}
580 580
 
581
-				echo '<img class="payment-icon" src="' . esc_url( $image ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>';
581
+				echo '<img class="payment-icon" src="' . esc_url($image) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>';
582 582
 				}
583
-			echo wp_kses_post( $option ) . '</label>';
583
+			echo wp_kses_post($option) . '</label>';
584 584
 		}
585
-		echo '<p class="description" style="margin-top:16px;">' . wp_kses_post( $args['desc'] ) . '</p>';
585
+		echo '<p class="description" style="margin-top:16px;">' . wp_kses_post($args['desc']) . '</p>';
586 586
 	}
587 587
 }
588 588
 
589 589
 /**
590 590
  * Displays a radio settings field.
591 591
  */
592
-function wpinv_radio_callback( $args ) {
592
+function wpinv_radio_callback($args) {
593 593
 
594
-	$std = isset( $args['std'] ) ? $args['std'] : '';
595
-	$std = wpinv_get_option( $args['id'], $std );
594
+	$std = isset($args['std']) ? $args['std'] : '';
595
+	$std = wpinv_get_option($args['id'], $std);
596 596
 	?>
597 597
 		<fieldset>
598
-			<ul id="wpinv-settings-<?php echo esc_attr( $args['id'] ); ?>" style="margin-top: 0;">
599
-				<?php foreach ( $args['options'] as $key => $option ) : ?>
598
+			<ul id="wpinv-settings-<?php echo esc_attr($args['id']); ?>" style="margin-top: 0;">
599
+				<?php foreach ($args['options'] as $key => $option) : ?>
600 600
 					<li>
601 601
 						<label>
602
-							<input name="wpinv_settings[<?php echo esc_attr( $args['id'] ); ?>]" <?php checked( $std, $key ); ?> value="<?php echo esc_attr( $key ); ?>" type="radio">
603
-							<?php echo wp_kses_post( $option ); ?>
602
+							<input name="wpinv_settings[<?php echo esc_attr($args['id']); ?>]" <?php checked($std, $key); ?> value="<?php echo esc_attr($key); ?>" type="radio">
603
+							<?php echo wp_kses_post($option); ?>
604 604
 						</label>
605 605
 					</li>
606 606
 				<?php endforeach; ?>
607 607
 			</ul>
608 608
 		</fieldset>
609 609
 	<?php
610
-	getpaid_settings_description_callback( $args );
610
+	getpaid_settings_description_callback($args);
611 611
 }
612 612
 
613 613
 /**
614 614
  * Displays a description if available.
615 615
  */
616
-function getpaid_settings_description_callback( $args ) {
616
+function getpaid_settings_description_callback($args) {
617 617
 
618
-	if ( ! empty( $args['desc'] ) ) {
618
+	if (!empty($args['desc'])) {
619 619
 		$description = $args['desc'];
620
-		echo wp_kses_post( "<p class='description'>$description</p>" );
620
+		echo wp_kses_post("<p class='description'>$description</p>");
621 621
 	}
622 622
 
623 623
 }
@@ -632,35 +632,35 @@  discard block
 block discarded – undo
632 632
 	</tr>
633 633
 	<tr class="bsui">
634 634
     	<td colspan="2" class="p-0">
635
-			<?php include plugin_dir_path( __FILE__ ) . 'views/html-gateways-edit.php'; ?>
635
+			<?php include plugin_dir_path(__FILE__) . 'views/html-gateways-edit.php'; ?>
636 636
 
637 637
 	<?php
638 638
 }
639 639
 
640
-function wpinv_gateway_select_callback( $args ) {
640
+function wpinv_gateway_select_callback($args) {
641 641
 
642
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
643
-    $class = ! empty( $args['class'] ) ? ' ' . esc_attr( $args['class'] ) : '';
644
-	$std     = isset( $args['std'] ) ? $args['std'] : '';
645
-	$value   = wpinv_get_option( $args['id'], $std );
642
+    $sanitize_id = wpinv_sanitize_key($args['id']);
643
+    $class = !empty($args['class']) ? ' ' . esc_attr($args['class']) : '';
644
+	$std     = isset($args['std']) ? $args['std'] : '';
645
+	$value   = wpinv_get_option($args['id'], $std);
646 646
 
647
-	echo '<select name="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"" id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" class="' . esc_attr( $class ) . '" >';
647
+	echo '<select name="wpinv_settings[' . esc_attr($sanitize_id) . ']"" id="wpinv_settings[' . esc_attr($sanitize_id) . ']" class="' . esc_attr($class) . '" >';
648 648
 
649
-	foreach ( $args['options'] as $key => $option ) :
649
+	foreach ($args['options'] as $key => $option) :
650 650
 
651
-		echo '<option value="' . esc_attr( $key ) . '" ';
651
+		echo '<option value="' . esc_attr($key) . '" ';
652 652
 
653
-		if ( isset( $args['selected'] ) && $args['selected'] !== null && $args['selected'] !== false ) {
654
-            selected( $key, $args['selected'] );
653
+		if (isset($args['selected']) && $args['selected'] !== null && $args['selected'] !== false) {
654
+            selected($key, $args['selected']);
655 655
         } else {
656
-            selected( $key, $value );
656
+            selected($key, $value);
657 657
         }
658 658
 
659
-		echo '>' . esc_html( $option['admin_label'] ) . '</option>';
659
+		echo '>' . esc_html($option['admin_label']) . '</option>';
660 660
 	endforeach;
661 661
 
662 662
 	echo '</select>';
663
-	echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
663
+	echo '<label for="wpinv_settings[' . esc_attr($sanitize_id) . ']"> ' . wp_kses_post($args['desc']) . '</label>';
664 664
 }
665 665
 
666 666
 /**
@@ -669,16 +669,16 @@  discard block
 block discarded – undo
669 669
  * @param array $args
670 670
  * @return string
671 671
  */
672
-function wpinv_settings_attrs_helper( $args ) {
672
+function wpinv_settings_attrs_helper($args) {
673 673
 
674
-	$value = isset( $args['std'] ) ? $args['std'] : '';
675
-	$id    = esc_attr( $args['id'] );
676
-	$value = is_scalar( $value ) ? $value : '';
674
+	$value = isset($args['std']) ? $args['std'] : '';
675
+	$id    = esc_attr($args['id']);
676
+	$value = is_scalar($value) ? $value : '';
677 677
 
678 678
 	$attrs = array(
679
-		'name'     => ! empty( $args['faux'] ) ? false : "wpinv_settings[$id]",
680
-		'readonly' => ! empty( $args['faux'] ),
681
-		'value'    => ! empty( $args['faux'] ) ? $value : wpinv_get_option( $args['id'], $value ),
679
+		'name'     => !empty($args['faux']) ? false : "wpinv_settings[$id]",
680
+		'readonly' => !empty($args['faux']),
681
+		'value'    => !empty($args['faux']) ? $value : wpinv_get_option($args['id'], $value),
682 682
 		'id'       => 'wpinv-settings-' . $args['id'],
683 683
 		'style'    => $args['style'],
684 684
 		'class'    => $args['class'],
@@ -686,20 +686,20 @@  discard block
 block discarded – undo
686 686
 		'data-placeholder' => $args['placeholder'],
687 687
 	);
688 688
 
689
-	if ( ! empty( $args['onchange'] ) ) {
689
+	if (!empty($args['onchange'])) {
690 690
 		$attrs['onchange'] = $args['onchange'];
691 691
 	}
692 692
 
693
-	foreach ( $attrs as $key => $value ) {
693
+	foreach ($attrs as $key => $value) {
694 694
 
695
-		if ( false === $value ) {
695
+		if (false === $value) {
696 696
 			continue;
697 697
 		}
698 698
 
699
-		if ( true === $value ) {
700
-			echo ' ' . esc_attr( $key );
699
+		if (true === $value) {
700
+			echo ' ' . esc_attr($key);
701 701
 		} else {
702
-			echo ' ' . esc_attr( $key ) . '="' . esc_attr( $value ) . '"';
702
+			echo ' ' . esc_attr($key) . '="' . esc_attr($value) . '"';
703 703
 		}
704 704
 
705 705
 	}
@@ -709,14 +709,14 @@  discard block
 block discarded – undo
709 709
 /**
710 710
  * Displays a text input settings callback.
711 711
  */
712
-function wpinv_text_callback( $args ) {
712
+function wpinv_text_callback($args) {
713 713
 
714
-	$desc = empty( $desc ) ? '' : "<p class='description'>$desc</p>";
714
+	$desc = empty($desc) ? '' : "<p class='description'>$desc</p>";
715 715
 
716 716
 	?>
717 717
 		<label style="width: 100%;">
718
-			<input type="text" <?php wpinv_settings_attrs_helper( $args ); ?>>
719
-			<?php echo wp_kses_post( $desc ); ?>
718
+			<input type="text" <?php wpinv_settings_attrs_helper($args); ?>>
719
+			<?php echo wp_kses_post($desc); ?>
720 720
 		</label>
721 721
 	<?php
722 722
 
@@ -725,176 +725,176 @@  discard block
 block discarded – undo
725 725
 /**
726 726
  * Displays a number input settings callback.
727 727
  */
728
-function wpinv_number_callback( $args ) {
728
+function wpinv_number_callback($args) {
729 729
 
730
-	$desc = empty( $desc ) ? '' : "<p class='description'>$desc</p>";
730
+	$desc = empty($desc) ? '' : "<p class='description'>$desc</p>";
731 731
 
732 732
 	?>
733 733
 		<label style="width: 100%;">
734
-			<input type="number" step="<?php echo floatval( $args['step'] ); ?>" max="<?php echo intval( $args['max'] ); ?>" min="<?php echo intval( $args['min'] ); ?>" <?php wpinv_settings_attrs_helper( $args ); ?>>
735
-			<?php echo wp_kses_post( $desc ); ?>
734
+			<input type="number" step="<?php echo floatval($args['step']); ?>" max="<?php echo intval($args['max']); ?>" min="<?php echo intval($args['min']); ?>" <?php wpinv_settings_attrs_helper($args); ?>>
735
+			<?php echo wp_kses_post($desc); ?>
736 736
 		</label>
737 737
 	<?php
738 738
 
739 739
 }
740 740
 
741
-function wpinv_textarea_callback( $args ) {
741
+function wpinv_textarea_callback($args) {
742 742
 
743
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
744
-	$std     = isset( $args['std'] ) ? $args['std'] : '';
745
-	$value   = wpinv_get_option( $args['id'], $std );
743
+    $sanitize_id = wpinv_sanitize_key($args['id']);
744
+	$std     = isset($args['std']) ? $args['std'] : '';
745
+	$value   = wpinv_get_option($args['id'], $std);
746 746
 
747
-    $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
748
-    $class = ( isset( $args['class'] ) && ! is_null( $args['class'] ) ) ? $args['class'] : 'large-text';
747
+    $size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular';
748
+    $class = (isset($args['class']) && !is_null($args['class'])) ? $args['class'] : 'large-text';
749 749
 
750
-	echo '<textarea class="' . esc_attr( $class ) . ' txtarea-' . esc_attr( $size ) . ' wpi-' . esc_attr( sanitize_html_class( $sanitize_id ) ) . ' " cols="' . esc_attr( $args['cols'] ) . '" rows="' . esc_attr( $args['rows'] ) . '" id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']">' . esc_textarea( stripslashes( $value ) ) . '</textarea>';
751
-	echo '<br /><label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
750
+	echo '<textarea class="' . esc_attr($class) . ' txtarea-' . esc_attr($size) . ' wpi-' . esc_attr(sanitize_html_class($sanitize_id)) . ' " cols="' . esc_attr($args['cols']) . '" rows="' . esc_attr($args['rows']) . '" id="wpinv_settings[' . esc_attr($sanitize_id) . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']">' . esc_textarea(stripslashes($value)) . '</textarea>';
751
+	echo '<br /><label for="wpinv_settings[' . esc_attr($sanitize_id) . ']"> ' . wp_kses_post($args['desc']) . '</label>';
752 752
 
753 753
 }
754 754
 
755
-function wpinv_password_callback( $args ) {
755
+function wpinv_password_callback($args) {
756 756
 
757
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
758
-	$std     = isset( $args['std'] ) ? $args['std'] : '';
759
-	$value   = wpinv_get_option( $args['id'], $std );
757
+    $sanitize_id = wpinv_sanitize_key($args['id']);
758
+	$std     = isset($args['std']) ? $args['std'] : '';
759
+	$value   = wpinv_get_option($args['id'], $std);
760 760
 
761
-	$size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
762
-	echo '<input type="password" class="' . esc_attr( $size ) . '-text" id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '"/>';
763
-	echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
761
+	$size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular';
762
+	echo '<input type="password" class="' . esc_attr($size) . '-text" id="wpinv_settings[' . esc_attr($sanitize_id) . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']" value="' . esc_attr($value) . '"/>';
763
+	echo '<label for="wpinv_settings[' . esc_attr($sanitize_id) . ']"> ' . wp_kses_post($args['desc']) . '</label>';
764 764
 
765 765
 }
766 766
 
767
-function wpinv_missing_callback( $args ) {
767
+function wpinv_missing_callback($args) {
768 768
 	printf(
769
-		esc_html__( 'The callback function used for the %s setting is missing.', 'invoicing' ),
770
-		'<strong>' . esc_html( $args['id'] ) . '</strong>'
769
+		esc_html__('The callback function used for the %s setting is missing.', 'invoicing'),
770
+		'<strong>' . esc_html($args['id']) . '</strong>'
771 771
 	);
772 772
 }
773 773
 
774 774
 /**
775 775
  * Displays a number input settings callback.
776 776
  */
777
-function wpinv_select_callback( $args ) {
777
+function wpinv_select_callback($args) {
778 778
 
779
-	$desc   = wp_kses_post( $args['desc'] );
780
-	$desc   = empty( $desc ) ? '' : "<p class='description'>$desc</p>";
781
-	$value  = isset( $args['std'] ) ? $args['std'] : '';
782
-	$value  = wpinv_get_option( $args['id'], $value );
783
-	$rand   = uniqid( 'random_id' );
779
+	$desc   = wp_kses_post($args['desc']);
780
+	$desc   = empty($desc) ? '' : "<p class='description'>$desc</p>";
781
+	$value  = isset($args['std']) ? $args['std'] : '';
782
+	$value  = wpinv_get_option($args['id'], $value);
783
+	$rand   = uniqid('random_id');
784 784
 
785 785
 	?>
786 786
 		<label style="width: 100%;">
787
-			<select <?php wpinv_settings_attrs_helper( $args ); ?> data-allow-clear="true">
788
-				<?php foreach ( $args['options'] as $option => $name ) : ?>
789
-					<option value="<?php echo esc_attr( $option ); ?>" <?php echo selected( $option, $value ); ?>><?php echo esc_html( $name ); ?></option>
787
+			<select <?php wpinv_settings_attrs_helper($args); ?> data-allow-clear="true">
788
+				<?php foreach ($args['options'] as $option => $name) : ?>
789
+					<option value="<?php echo esc_attr($option); ?>" <?php echo selected($option, $value); ?>><?php echo esc_html($name); ?></option>
790 790
 				<?php endforeach; ?>
791 791
 			</select>
792 792
 
793
-			<?php if ( substr( $args['id'], -5 ) === '_page' && is_numeric( $value ) ) : ?>
794
-				<a href="<?php echo esc_url( get_edit_post_link( $value ) ); ?>" target="_blank" class="button getpaid-page-setting-edit"><?php esc_html_e( 'Edit Page', 'invoicing' ); ?></a>
793
+			<?php if (substr($args['id'], -5) === '_page' && is_numeric($value)) : ?>
794
+				<a href="<?php echo esc_url(get_edit_post_link($value)); ?>" target="_blank" class="button getpaid-page-setting-edit"><?php esc_html_e('Edit Page', 'invoicing'); ?></a>
795 795
 			<?php endif; ?>
796 796
 
797
-			<?php if ( substr( $args['id'], -5 ) === '_page' && ! empty( $args['default_content'] ) ) : ?>
798
-				&nbsp;<a href="#TB_inline?&width=400&height=550&inlineId=<?php echo esc_attr( $rand ); ?>" class="button thickbox getpaid-page-setting-view-default"><?php esc_html_e( 'View Default Content', 'invoicing' ); ?></a>
799
-				<div id='<?php echo esc_attr( $rand ); ?>' style='display:none;'>
797
+			<?php if (substr($args['id'], -5) === '_page' && !empty($args['default_content'])) : ?>
798
+				&nbsp;<a href="#TB_inline?&width=400&height=550&inlineId=<?php echo esc_attr($rand); ?>" class="button thickbox getpaid-page-setting-view-default"><?php esc_html_e('View Default Content', 'invoicing'); ?></a>
799
+				<div id='<?php echo esc_attr($rand); ?>' style='display:none;'>
800 800
 					<div>
801
-						<h3><?php esc_html_e( 'Original Content', 'invoicing' ); ?></h3>
802
-						<textarea readonly onclick="this.select()" rows="8" style="width: 100%;"><?php echo wp_kses_post( gepaid_trim_lines( $args['default_content'] ) ); ?></textarea>
803
-						<h3><?php esc_html_e( 'Current Content', 'invoicing' ); ?></h3>
804
-						<textarea readonly onclick="this.select()" rows="8" style="width: 100%;"><?php $_post = get_post( $value ); echo empty( $_post ) ? '' : wp_kses_post( gepaid_trim_lines( $_post->post_content ) ); ?></textarea>
801
+						<h3><?php esc_html_e('Original Content', 'invoicing'); ?></h3>
802
+						<textarea readonly onclick="this.select()" rows="8" style="width: 100%;"><?php echo wp_kses_post(gepaid_trim_lines($args['default_content'])); ?></textarea>
803
+						<h3><?php esc_html_e('Current Content', 'invoicing'); ?></h3>
804
+						<textarea readonly onclick="this.select()" rows="8" style="width: 100%;"><?php $_post = get_post($value); echo empty($_post) ? '' : wp_kses_post(gepaid_trim_lines($_post->post_content)); ?></textarea>
805 805
 					</div>
806 806
 				</div>
807 807
 			<?php endif; ?>
808 808
 
809
-			<?php echo wp_kses_post( $desc ); ?>
809
+			<?php echo wp_kses_post($desc); ?>
810 810
 		</label>
811 811
 	<?php
812 812
 
813 813
 }
814 814
 
815
-function wpinv_color_select_callback( $args ) {
815
+function wpinv_color_select_callback($args) {
816 816
 
817
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
818
-	$std     = isset( $args['std'] ) ? $args['std'] : '';
819
-	$value   = wpinv_get_option( $args['id'], $std );
817
+    $sanitize_id = wpinv_sanitize_key($args['id']);
818
+	$std     = isset($args['std']) ? $args['std'] : '';
819
+	$value   = wpinv_get_option($args['id'], $std);
820 820
 
821
-	echo '<select id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"/>';
821
+	echo '<select id="wpinv_settings[' . esc_attr($sanitize_id) . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']"/>';
822 822
 
823
-	foreach ( $args['options'] as $option => $color ) {
824
-		echo '<option value="' . esc_attr( $option ) . '" ' . selected( $option, $value ) . '>' . esc_html( $color['label'] ) . '</option>';
823
+	foreach ($args['options'] as $option => $color) {
824
+		echo '<option value="' . esc_attr($option) . '" ' . selected($option, $value) . '>' . esc_html($color['label']) . '</option>';
825 825
 	}
826 826
 
827 827
 	echo '</select>';
828
-	echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
828
+	echo '<label for="wpinv_settings[' . esc_attr($sanitize_id) . ']"> ' . wp_kses_post($args['desc']) . '</label>';
829 829
 
830 830
 }
831 831
 
832
-function wpinv_rich_editor_callback( $args ) {
832
+function wpinv_rich_editor_callback($args) {
833 833
 	global $wp_version;
834 834
 
835
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
835
+    $sanitize_id = wpinv_sanitize_key($args['id']);
836 836
 
837
-	$std     = isset( $args['std'] ) ? $args['std'] : '';
838
-	$value   = wpinv_get_option( $args['id'], $std );
837
+	$std     = isset($args['std']) ? $args['std'] : '';
838
+	$value   = wpinv_get_option($args['id'], $std);
839 839
 
840
-	if ( ! empty( $args['allow_blank'] ) && empty( $value ) ) {
840
+	if (!empty($args['allow_blank']) && empty($value)) {
841 841
 		$value = $std;
842 842
 	}
843 843
 
844
-	$rows = isset( $args['size'] ) ? $args['size'] : 20;
844
+	$rows = isset($args['size']) ? $args['size'] : 20;
845 845
 
846 846
 	echo '<div class="getpaid-settings-editor-input">';
847
-	if ( $wp_version >= 3.3 && function_exists( 'wp_editor' ) ) {
847
+	if ($wp_version >= 3.3 && function_exists('wp_editor')) {
848 848
 		wp_editor(
849
-            stripslashes( $value ),
850
-            'wpinv_settings_' . esc_attr( $args['id'] ),
849
+            stripslashes($value),
850
+            'wpinv_settings_' . esc_attr($args['id']),
851 851
             array(
852
-				'textarea_name' => 'wpinv_settings[' . esc_attr( $args['id'] ) . ']',
853
-				'textarea_rows' => absint( $rows ),
852
+				'textarea_name' => 'wpinv_settings[' . esc_attr($args['id']) . ']',
853
+				'textarea_rows' => absint($rows),
854 854
 				'media_buttons' => false,
855 855
             )
856 856
         );
857 857
 	} else {
858
-		echo '<textarea class="large-text" rows="10" id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" class="wpi-' . esc_attr( sanitize_html_class( $args['id'] ) ) . '">' . esc_textarea( stripslashes( $value ) ) . '</textarea>';
858
+		echo '<textarea class="large-text" rows="10" id="wpinv_settings[' . esc_attr($sanitize_id) . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']" class="wpi-' . esc_attr(sanitize_html_class($args['id'])) . '">' . esc_textarea(stripslashes($value)) . '</textarea>';
859 859
 	}
860 860
 
861
-	echo '</div><br/><label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
861
+	echo '</div><br/><label for="wpinv_settings[' . esc_attr($sanitize_id) . ']"> ' . wp_kses_post($args['desc']) . '</label>';
862 862
 
863 863
 }
864 864
 
865
-function wpinv_upload_callback( $args ) {
865
+function wpinv_upload_callback($args) {
866 866
 
867
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
867
+    $sanitize_id = wpinv_sanitize_key($args['id']);
868 868
 
869
-	$std     = isset( $args['std'] ) ? $args['std'] : '';
870
-	$value   = wpinv_get_option( $args['id'], $std );
869
+	$std     = isset($args['std']) ? $args['std'] : '';
870
+	$value   = wpinv_get_option($args['id'], $std);
871 871
 
872
-	$size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
873
-	echo '<input type="text" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( stripslashes( $value ) ) . '"/>';
874
-	echo '<span>&nbsp;<input type="button" class="wpinv_settings_upload_button button-secondary" value="' . esc_attr__( 'Upload File', 'invoicing' ) . '"/></span>';
875
-	echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
872
+	$size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular';
873
+	echo '<input type="text" class="' . sanitize_html_class($size) . '-text" id="wpinv_settings[' . esc_attr($sanitize_id) . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']" value="' . esc_attr(stripslashes($value)) . '"/>';
874
+	echo '<span>&nbsp;<input type="button" class="wpinv_settings_upload_button button-secondary" value="' . esc_attr__('Upload File', 'invoicing') . '"/></span>';
875
+	echo '<label for="wpinv_settings[' . esc_attr($sanitize_id) . ']"> ' . wp_kses_post($args['desc']) . '</label>';
876 876
 
877 877
 }
878 878
 
879
-function wpinv_color_callback( $args ) {
879
+function wpinv_color_callback($args) {
880 880
 
881
-	$std         = isset( $args['std'] ) ? $args['std'] : '';
882
-	$value       = wpinv_get_option( $args['id'], $std );
883
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
881
+	$std         = isset($args['std']) ? $args['std'] : '';
882
+	$value       = wpinv_get_option($args['id'], $std);
883
+    $sanitize_id = wpinv_sanitize_key($args['id']);
884 884
 
885
-	echo '<input type="text" class="wpinv-color-picker" id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '" data-default-color="' . esc_attr( $std ) . '" />';
886
-	echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
885
+	echo '<input type="text" class="wpinv-color-picker" id="wpinv_settings[' . esc_attr($sanitize_id) . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']" value="' . esc_attr($value) . '" data-default-color="' . esc_attr($std) . '" />';
886
+	echo '<label for="wpinv_settings[' . esc_attr($sanitize_id) . ']"> ' . wp_kses_post($args['desc']) . '</label>';
887 887
 
888 888
 }
889 889
 
890
-function wpinv_country_states_callback( $args ) {
890
+function wpinv_country_states_callback($args) {
891 891
 
892
-	$std     = isset( $args['std'] ) ? $args['std'] : '';
893
-	$value   = wpinv_get_option( $args['id'], $std );
892
+	$std     = isset($args['std']) ? $args['std'] : '';
893
+	$value   = wpinv_get_option($args['id'], $std);
894 894
 
895
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
895
+    $sanitize_id = wpinv_sanitize_key($args['id']);
896 896
 
897
-	if ( isset( $args['placeholder'] ) ) {
897
+	if (isset($args['placeholder'])) {
898 898
 		$placeholder = $args['placeholder'];
899 899
 	} else {
900 900
 		$placeholder = '';
@@ -902,15 +902,15 @@  discard block
 block discarded – undo
902 902
 
903 903
 	$states = wpinv_get_country_states();
904 904
 
905
-	$class = empty( $states ) ? 'wpinv-no-states' : 'wpi_select2';
906
-	echo '<select id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" class="' . esc_attr( $class ) . '" data-placeholder="' . esc_html( $placeholder ) . '"/>';
905
+	$class = empty($states) ? 'wpinv-no-states' : 'wpi_select2';
906
+	echo '<select id="wpinv_settings[' . esc_attr($sanitize_id) . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']" class="' . esc_attr($class) . '" data-placeholder="' . esc_html($placeholder) . '"/>';
907 907
 
908
-	foreach ( $states as $option => $name ) {
909
-		echo '<option value="' . esc_attr( $option ) . '" ' . selected( $option, $value ) . '>' . esc_html( $name ) . '</option>';
908
+	foreach ($states as $option => $name) {
909
+		echo '<option value="' . esc_attr($option) . '" ' . selected($option, $value) . '>' . esc_html($name) . '</option>';
910 910
 	}
911 911
 
912 912
 	echo '</select>';
913
-	echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
913
+	echo '<label for="wpinv_settings[' . esc_attr($sanitize_id) . ']"> ' . wp_kses_post($args['desc']) . '</label>';
914 914
 
915 915
 }
916 916
 
@@ -924,7 +924,7 @@  discard block
 block discarded – undo
924 924
 	</tr>
925 925
 	<tr class="bsui">
926 926
     	<td colspan="2" class="p-0">
927
-			<?php include plugin_dir_path( __FILE__ ) . 'views/html-tax-rates-edit.php'; ?>
927
+			<?php include plugin_dir_path(__FILE__) . 'views/html-tax-rates-edit.php'; ?>
928 928
 
929 929
 	<?php
930 930
 
@@ -933,161 +933,161 @@  discard block
 block discarded – undo
933 933
 /**
934 934
  * Displays a tax rate' edit row.
935 935
  */
936
-function wpinv_tax_rate_callback( $tax_rate, $key ) {
936
+function wpinv_tax_rate_callback($tax_rate, $key) {
937 937
 
938
-	$key                      = sanitize_key( $key );
939
-	$tax_rate['reduced_rate'] = empty( $tax_rate['reduced_rate'] ) ? 0 : $tax_rate['reduced_rate'];
940
-	include plugin_dir_path( __FILE__ ) . 'views/html-tax-rate-edit.php';
938
+	$key                      = sanitize_key($key);
939
+	$tax_rate['reduced_rate'] = empty($tax_rate['reduced_rate']) ? 0 : $tax_rate['reduced_rate'];
940
+	include plugin_dir_path(__FILE__) . 'views/html-tax-rate-edit.php';
941 941
 
942 942
 }
943 943
 
944 944
 
945
-function wpinv_tools_callback( $args ) {
945
+function wpinv_tools_callback($args) {
946 946
     ?>
947 947
     </td><tr>
948 948
     <td colspan="2" class="wpinv_tools_tdbox">
949 949
     <?php
950
-    if ( $args['desc'] ) {
950
+    if ($args['desc']) {
951 951
 ?>
952
-<p><?php echo wp_kses_post( $args['desc'] ); ?></p><?php } ?>
953
-    <?php do_action( 'wpinv_tools_before' ); ?>
952
+<p><?php echo wp_kses_post($args['desc']); ?></p><?php } ?>
953
+    <?php do_action('wpinv_tools_before'); ?>
954 954
     <table id="wpinv_tools_table" class="wp-list-table widefat fixed posts">
955 955
         <thead>
956 956
             <tr>
957
-                <th scope="col" class="wpinv-th-tool"><?php esc_html_e( 'Tool', 'invoicing' ); ?></th>
958
-                <th scope="col" class="wpinv-th-desc"><?php esc_html_e( 'Description', 'invoicing' ); ?></th>
959
-                <th scope="col" class="wpinv-th-action"><?php esc_html_e( 'Action', 'invoicing' ); ?></th>
957
+                <th scope="col" class="wpinv-th-tool"><?php esc_html_e('Tool', 'invoicing'); ?></th>
958
+                <th scope="col" class="wpinv-th-desc"><?php esc_html_e('Description', 'invoicing'); ?></th>
959
+                <th scope="col" class="wpinv-th-action"><?php esc_html_e('Action', 'invoicing'); ?></th>
960 960
             </tr>
961 961
         </thead>
962 962
 
963 963
         <tbody>
964 964
 			<tr>
965
-                <td><?php esc_html_e( 'Check Pages', 'invoicing' ); ?></td>
965
+                <td><?php esc_html_e('Check Pages', 'invoicing'); ?></td>
966 966
                 <td>
967
-                    <small><?php esc_html_e( 'Creates any missing GetPaid pages.', 'invoicing' ); ?></small>
967
+                    <small><?php esc_html_e('Creates any missing GetPaid pages.', 'invoicing'); ?></small>
968 968
                 </td>
969 969
                 <td>
970 970
 					<a href="
971 971
                     <?php
972 972
 						echo esc_url(
973 973
 							wp_nonce_url(
974
-								add_query_arg( 'getpaid-admin-action', 'create_missing_pages' ),
974
+								add_query_arg('getpaid-admin-action', 'create_missing_pages'),
975 975
 								'getpaid-nonce',
976 976
 								'getpaid-nonce'
977 977
 							)
978 978
 						);
979 979
 					?>
980
-                    " class="button button-primary"><?php esc_html_e( 'Run', 'invoicing' ); ?></a>
980
+                    " class="button button-primary"><?php esc_html_e('Run', 'invoicing'); ?></a>
981 981
                 </td>
982 982
             </tr>
983 983
 			<tr>
984
-                <td><?php esc_html_e( 'Create Database Tables', 'invoicing' ); ?></td>
984
+                <td><?php esc_html_e('Create Database Tables', 'invoicing'); ?></td>
985 985
                 <td>
986
-                    <small><?php esc_html_e( 'Run this tool to create any missing database tables.', 'invoicing' ); ?></small>
986
+                    <small><?php esc_html_e('Run this tool to create any missing database tables.', 'invoicing'); ?></small>
987 987
                 </td>
988 988
                 <td>
989 989
 					<a href="
990 990
                     <?php
991 991
 						echo esc_url(
992 992
 							wp_nonce_url(
993
-								add_query_arg( 'getpaid-admin-action', 'create_missing_tables' ),
993
+								add_query_arg('getpaid-admin-action', 'create_missing_tables'),
994 994
 								'getpaid-nonce',
995 995
 								'getpaid-nonce'
996 996
 							)
997 997
 						);
998 998
 					?>
999
-                    " class="button button-primary"><?php esc_html_e( 'Run', 'invoicing' ); ?></a>
999
+                    " class="button button-primary"><?php esc_html_e('Run', 'invoicing'); ?></a>
1000 1000
                 </td>
1001 1001
             </tr>
1002 1002
 			<tr>
1003
-                <td><?php esc_html_e( 'Migrate old invoices', 'invoicing' ); ?></td>
1003
+                <td><?php esc_html_e('Migrate old invoices', 'invoicing'); ?></td>
1004 1004
                 <td>
1005
-                    <small><?php esc_html_e( 'If your old invoices were not migrated after updating from Invoicing to GetPaid, you can use this tool to migrate them.', 'invoicing' ); ?></small>
1005
+                    <small><?php esc_html_e('If your old invoices were not migrated after updating from Invoicing to GetPaid, you can use this tool to migrate them.', 'invoicing'); ?></small>
1006 1006
                 </td>
1007 1007
                 <td>
1008 1008
 					<a href="
1009 1009
                     <?php
1010 1010
 						echo esc_url(
1011 1011
 							wp_nonce_url(
1012
-								add_query_arg( 'getpaid-admin-action', 'migrate_old_invoices' ),
1012
+								add_query_arg('getpaid-admin-action', 'migrate_old_invoices'),
1013 1013
 								'getpaid-nonce',
1014 1014
 								'getpaid-nonce'
1015 1015
 							)
1016 1016
 						);
1017 1017
 					?>
1018
-                    " class="button button-primary"><?php esc_html_e( 'Run', 'invoicing' ); ?></a>
1018
+                    " class="button button-primary"><?php esc_html_e('Run', 'invoicing'); ?></a>
1019 1019
                 </td>
1020 1020
             </tr>
1021 1021
 
1022 1022
 			<tr>
1023
-                <td><?php esc_html_e( 'Recalculate Discounts', 'invoicing' ); ?></td>
1023
+                <td><?php esc_html_e('Recalculate Discounts', 'invoicing'); ?></td>
1024 1024
                 <td>
1025
-                    <small><?php esc_html_e( 'Recalculate discounts for existing invoices that have discount codes but are not discounted.', 'invoicing' ); ?></small>
1025
+                    <small><?php esc_html_e('Recalculate discounts for existing invoices that have discount codes but are not discounted.', 'invoicing'); ?></small>
1026 1026
                 </td>
1027 1027
                 <td>
1028 1028
 					<a href="
1029 1029
                     <?php
1030 1030
 						echo esc_url(
1031 1031
 							wp_nonce_url(
1032
-								add_query_arg( 'getpaid-admin-action', 'recalculate_discounts' ),
1032
+								add_query_arg('getpaid-admin-action', 'recalculate_discounts'),
1033 1033
 								'getpaid-nonce',
1034 1034
 								'getpaid-nonce'
1035 1035
 							)
1036 1036
 						);
1037 1037
 					?>
1038
-                    " class="button button-primary"><?php esc_html_e( 'Run', 'invoicing' ); ?></a>
1038
+                    " class="button button-primary"><?php esc_html_e('Run', 'invoicing'); ?></a>
1039 1039
                 </td>
1040 1040
             </tr>
1041 1041
 
1042 1042
 			<tr>
1043
-                <td><?php esc_html_e( 'Set-up Wizard', 'invoicing' ); ?></td>
1043
+                <td><?php esc_html_e('Set-up Wizard', 'invoicing'); ?></td>
1044 1044
                 <td>
1045
-                    <small><?php esc_html_e( 'Launch the quick set-up wizard.', 'invoicing' ); ?></small>
1045
+                    <small><?php esc_html_e('Launch the quick set-up wizard.', 'invoicing'); ?></small>
1046 1046
                 </td>
1047 1047
                 <td>
1048 1048
 					<a href="
1049 1049
                     <?php
1050
-						echo esc_url( admin_url( 'index.php?page=gp-setup' ) );
1050
+						echo esc_url(admin_url('index.php?page=gp-setup'));
1051 1051
 					?>
1052
-                    " class="button button-primary"><?php esc_html_e( 'Launch', 'invoicing' ); ?></a>
1052
+                    " class="button button-primary"><?php esc_html_e('Launch', 'invoicing'); ?></a>
1053 1053
                 </td>
1054 1054
             </tr>
1055 1055
 
1056
-			<?php do_action( 'wpinv_tools_row' ); ?>
1056
+			<?php do_action('wpinv_tools_row'); ?>
1057 1057
         </tbody>
1058 1058
     </table>
1059
-    <?php do_action( 'wpinv_tools_after' ); ?>
1059
+    <?php do_action('wpinv_tools_after'); ?>
1060 1060
     <?php
1061 1061
 }
1062 1062
 
1063 1063
 
1064
-function wpinv_descriptive_text_callback( $args ) {
1065
-	echo wp_kses_post( $args['desc'] );
1064
+function wpinv_descriptive_text_callback($args) {
1065
+	echo wp_kses_post($args['desc']);
1066 1066
 }
1067 1067
 
1068
-function wpinv_raw_html_callback( $args ) {
1069
-	echo wp_kses( $args['desc'], getpaid_allowed_html() );
1068
+function wpinv_raw_html_callback($args) {
1069
+	echo wp_kses($args['desc'], getpaid_allowed_html());
1070 1070
 }
1071 1071
 
1072
-function wpinv_hook_callback( $args ) {
1073
-	do_action( 'wpinv_' . $args['id'], $args );
1072
+function wpinv_hook_callback($args) {
1073
+	do_action('wpinv_' . $args['id'], $args);
1074 1074
 }
1075 1075
 
1076 1076
 function wpinv_set_settings_cap() {
1077 1077
 	return wpinv_get_capability();
1078 1078
 }
1079
-add_filter( 'option_page_capability_wpinv_settings', 'wpinv_set_settings_cap' );
1079
+add_filter('option_page_capability_wpinv_settings', 'wpinv_set_settings_cap');
1080 1080
 
1081 1081
 
1082
-function wpinv_on_update_settings( $old_value, $value, $option ) {
1083
-    $old = ! empty( $old_value['remove_data_on_unistall'] ) ? 1 : '';
1084
-    $new = ! empty( $value['remove_data_on_unistall'] ) ? 1 : '';
1082
+function wpinv_on_update_settings($old_value, $value, $option) {
1083
+    $old = !empty($old_value['remove_data_on_unistall']) ? 1 : '';
1084
+    $new = !empty($value['remove_data_on_unistall']) ? 1 : '';
1085 1085
 
1086
-    if ( $old != $new ) {
1087
-        update_option( 'wpinv_remove_data_on_invoice_unistall', $new );
1086
+    if ($old != $new) {
1087
+        update_option('wpinv_remove_data_on_invoice_unistall', $new);
1088 1088
     }
1089 1089
 }
1090
-add_action( 'update_option_wpinv_settings', 'wpinv_on_update_settings', 10, 3 );
1090
+add_action('update_option_wpinv_settings', 'wpinv_on_update_settings', 10, 3);
1091 1091
 
1092 1092
 /**
1093 1093
  * Returns the merge tags help text.
@@ -1096,16 +1096,16 @@  discard block
 block discarded – undo
1096 1096
  *
1097 1097
  * @return string
1098 1098
  */
1099
-function wpinv_get_merge_tags_help_text( $subscription = false ) {
1099
+function wpinv_get_merge_tags_help_text($subscription = false) {
1100 1100
 
1101 1101
 	$url  = $subscription ? 'https://gist.github.com/picocodes/3d213982d57c34edf7a46fd3f0e8583e' : 'https://gist.github.com/picocodes/43bdc4d4bbba844534b2722e2af0b58f';
1102 1102
 	$link = sprintf(
1103 1103
 		'<strong><a href="%s" target="_blank">%s</a></strong>',
1104 1104
 		$url,
1105
-		esc_html__( 'View available merge tags.', 'wpinv-quotes' )
1105
+		esc_html__('View available merge tags.', 'wpinv-quotes')
1106 1106
 	);
1107 1107
 
1108
-	$description = esc_html__( 'The content of the email (Merge Tags and HTML are allowed).', 'invoicing' );
1108
+	$description = esc_html__('The content of the email (Merge Tags and HTML are allowed).', 'invoicing');
1109 1109
 
1110 1110
 	return "$description $link";
1111 1111
 
Please login to merge, or discard this patch.
includes/gateways/class-getpaid-paypal-gateway.php 2 patches
Indentation   +336 added lines, -336 removed lines patch added patch discarded remove patch
@@ -13,96 +13,96 @@  discard block
 block discarded – undo
13 13
 class GetPaid_Paypal_Gateway extends GetPaid_Payment_Gateway {
14 14
 
15 15
     /**
16
-	 * Payment method id.
17
-	 *
18
-	 * @var string
19
-	 */
16
+     * Payment method id.
17
+     *
18
+     * @var string
19
+     */
20 20
     public $id = 'paypal';
21 21
 
22 22
     /**
23
-	 * An array of features that this gateway supports.
24
-	 *
25
-	 * @var array
26
-	 */
23
+     * An array of features that this gateway supports.
24
+     *
25
+     * @var array
26
+     */
27 27
     protected $supports = array( 'subscription', 'sandbox', 'single_subscription_group' );
28 28
 
29 29
     /**
30
-	 * Payment method order.
31
-	 *
32
-	 * @var int
33
-	 */
30
+     * Payment method order.
31
+     *
32
+     * @var int
33
+     */
34 34
     public $order = 1;
35 35
 
36 36
     /**
37
-	 * Stores line items to send to PayPal.
38
-	 *
39
-	 * @var array
40
-	 */
37
+     * Stores line items to send to PayPal.
38
+     *
39
+     * @var array
40
+     */
41 41
     protected $line_items = array();
42 42
 
43 43
     /**
44
-	 * Endpoint for requests from PayPal.
45
-	 *
46
-	 * @var string
47
-	 */
48
-	protected $notify_url;
49
-
50
-	/**
51
-	 * Endpoint for requests to PayPal.
52
-	 *
53
-	 * @var string
54
-	 */
44
+     * Endpoint for requests from PayPal.
45
+     *
46
+     * @var string
47
+     */
48
+    protected $notify_url;
49
+
50
+    /**
51
+     * Endpoint for requests to PayPal.
52
+     *
53
+     * @var string
54
+     */
55 55
     protected $endpoint;
56 56
 
57 57
     /**
58
-	 * Currencies this gateway is allowed for.
59
-	 *
60
-	 * @var array
61
-	 */
62
-	public $currencies = array( 'AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR' );
58
+     * Currencies this gateway is allowed for.
59
+     *
60
+     * @var array
61
+     */
62
+    public $currencies = array( 'AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR' );
63 63
 
64 64
     /**
65
-	 * URL to view a transaction.
66
-	 *
67
-	 * @var string
68
-	 */
65
+     * URL to view a transaction.
66
+     *
67
+     * @var string
68
+     */
69 69
     public $view_transaction_url = 'https://www.{sandbox}paypal.com/activity/payment/%s';
70 70
 
71 71
     /**
72
-	 * URL to view a subscription.
73
-	 *
74
-	 * @var string
75
-	 */
76
-	public $view_subscription_url = 'https://www.{sandbox}paypal.com/cgi-bin/webscr?cmd=_profile-recurring-payments&encrypted_profile_id=%s';
72
+     * URL to view a subscription.
73
+     *
74
+     * @var string
75
+     */
76
+    public $view_subscription_url = 'https://www.{sandbox}paypal.com/cgi-bin/webscr?cmd=_profile-recurring-payments&encrypted_profile_id=%s';
77 77
 
78 78
     /**
79
-	 * Class constructor.
80
-	 */
81
-	public function __construct() {
79
+     * Class constructor.
80
+     */
81
+    public function __construct() {
82 82
 
83 83
         $this->title                = __( 'PayPal Standard', 'invoicing' );
84 84
         $this->method_title         = __( 'PayPal Standard', 'invoicing' );
85 85
         $this->checkout_button_text = __( 'Proceed to PayPal', 'invoicing' );
86 86
         $this->notify_url           = wpinv_get_ipn_url( $this->id );
87 87
 
88
-		add_filter( 'getpaid_paypal_args', array( $this, 'process_subscription' ), 10, 2 );
88
+        add_filter( 'getpaid_paypal_args', array( $this, 'process_subscription' ), 10, 2 );
89 89
         add_filter( 'getpaid_paypal_sandbox_notice', array( $this, 'sandbox_notice' ) );
90
-		add_filter( 'getpaid_get_paypal_connect_url', array( $this, 'maybe_get_connect_url' ), 10, 2 );
91
-		add_action( 'getpaid_authenticated_admin_action_connect_paypal', array( $this, 'connect_paypal' ) );
92
-		add_action( 'wpinv_paypal_connect', array( $this, 'display_connect_buttons' ) );
93
-		parent::__construct();
90
+        add_filter( 'getpaid_get_paypal_connect_url', array( $this, 'maybe_get_connect_url' ), 10, 2 );
91
+        add_action( 'getpaid_authenticated_admin_action_connect_paypal', array( $this, 'connect_paypal' ) );
92
+        add_action( 'wpinv_paypal_connect', array( $this, 'display_connect_buttons' ) );
93
+        parent::__construct();
94 94
     }
95 95
 
96 96
     /**
97
-	 * Process Payment.
98
-	 *
99
-	 *
100
-	 * @param WPInv_Invoice $invoice Invoice.
101
-	 * @param array $submission_data Posted checkout fields.
102
-	 * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
103
-	 * @return array
104
-	 */
105
-	public function process_payment( $invoice, $submission_data, $submission ) {
97
+     * Process Payment.
98
+     *
99
+     *
100
+     * @param WPInv_Invoice $invoice Invoice.
101
+     * @param array $submission_data Posted checkout fields.
102
+     * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
103
+     * @return array
104
+     */
105
+    public function process_payment( $invoice, $submission_data, $submission ) {
106 106
 
107 107
         // Get redirect url.
108 108
         $paypal_redirect = $this->get_request_url( $invoice );
@@ -125,15 +125,15 @@  discard block
 block discarded – undo
125 125
     }
126 126
 
127 127
     /**
128
-	 * Get the PayPal request URL for an invoice.
129
-	 *
130
-	 * @param  WPInv_Invoice $invoice Invoice object.
131
-	 * @return string
132
-	 */
133
-	public function get_request_url( $invoice ) {
128
+     * Get the PayPal request URL for an invoice.
129
+     *
130
+     * @param  WPInv_Invoice $invoice Invoice object.
131
+     * @return string
132
+     */
133
+    public function get_request_url( $invoice ) {
134 134
 
135 135
         // Endpoint for this request
136
-		$this->endpoint    = $this->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?';
136
+        $this->endpoint    = $this->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?';
137 137
 
138 138
         // Retrieve paypal args.
139 139
         $paypal_args       = map_deep( $this->get_paypal_args( $invoice ), 'urlencode' );
@@ -146,45 +146,45 @@  discard block
 block discarded – undo
146 146
 
147 147
         return add_query_arg( $paypal_args, $this->endpoint );
148 148
 
149
-	}
149
+    }
150 150
 
151 151
     /**
152
-	 * Get PayPal Args for passing to PP.
153
-	 *
154
-	 * @param  WPInv_Invoice $invoice Invoice object.
155
-	 * @return array
156
-	 */
157
-	protected function get_paypal_args( $invoice ) {
152
+     * Get PayPal Args for passing to PP.
153
+     *
154
+     * @param  WPInv_Invoice $invoice Invoice object.
155
+     * @return array
156
+     */
157
+    protected function get_paypal_args( $invoice ) {
158 158
 
159 159
         // Whether or not to send the line items as one item.
160
-		$force_one_line_item = apply_filters( 'getpaid_paypal_force_one_line_item', true, $invoice );
161
-
162
-		if ( $invoice->is_recurring() || ( wpinv_use_taxes() && wpinv_prices_include_tax() ) ) {
163
-			$force_one_line_item = true;
164
-		}
165
-
166
-		$paypal_args = apply_filters(
167
-			'getpaid_paypal_args',
168
-			array_merge(
169
-				$this->get_transaction_args( $invoice ),
170
-				$this->get_line_item_args( $invoice, $force_one_line_item )
171
-			),
172
-			$invoice
173
-		);
174
-
175
-		return $this->fix_request_length( $invoice, $paypal_args );
160
+        $force_one_line_item = apply_filters( 'getpaid_paypal_force_one_line_item', true, $invoice );
161
+
162
+        if ( $invoice->is_recurring() || ( wpinv_use_taxes() && wpinv_prices_include_tax() ) ) {
163
+            $force_one_line_item = true;
164
+        }
165
+
166
+        $paypal_args = apply_filters(
167
+            'getpaid_paypal_args',
168
+            array_merge(
169
+                $this->get_transaction_args( $invoice ),
170
+                $this->get_line_item_args( $invoice, $force_one_line_item )
171
+            ),
172
+            $invoice
173
+        );
174
+
175
+        return $this->fix_request_length( $invoice, $paypal_args );
176 176
     }
177 177
 
178 178
     /**
179
-	 * Get transaction args for paypal request.
180
-	 *
181
-	 * @param WPInv_Invoice $invoice Invoice object.
182
-	 * @return array
183
-	 */
184
-	protected function get_transaction_args( $invoice ) {
185
-
186
-		$email = $this->is_sandbox( $invoice ) ? wpinv_get_option( 'paypal_sandbox_email', wpinv_get_option( 'paypal_email', '' ) ) : wpinv_get_option( 'paypal_email', '' );
187
-		return array(
179
+     * Get transaction args for paypal request.
180
+     *
181
+     * @param WPInv_Invoice $invoice Invoice object.
182
+     * @return array
183
+     */
184
+    protected function get_transaction_args( $invoice ) {
185
+
186
+        $email = $this->is_sandbox( $invoice ) ? wpinv_get_option( 'paypal_sandbox_email', wpinv_get_option( 'paypal_email', '' ) ) : wpinv_get_option( 'paypal_email', '' );
187
+        return array(
188 188
             'cmd'           => '_cart',
189 189
             'business'      => $email,
190 190
             'no_shipping'   => '1',
@@ -209,16 +209,16 @@  discard block
 block discarded – undo
209 209
     }
210 210
 
211 211
     /**
212
-	 * Get line item args for paypal request.
213
-	 *
214
-	 * @param  WPInv_Invoice $invoice Invoice object.
215
-	 * @param  bool     $force_one_line_item Create only one item for this invoice.
216
-	 * @return array
217
-	 */
218
-	protected function get_line_item_args( $invoice, $force_one_line_item = false ) {
212
+     * Get line item args for paypal request.
213
+     *
214
+     * @param  WPInv_Invoice $invoice Invoice object.
215
+     * @param  bool     $force_one_line_item Create only one item for this invoice.
216
+     * @return array
217
+     */
218
+    protected function get_line_item_args( $invoice, $force_one_line_item = false ) {
219 219
 
220 220
         // Maybe send invoice as a single item.
221
-		if ( $force_one_line_item ) {
221
+        if ( $force_one_line_item ) {
222 222
             return $this->get_line_item_args_single_item( $invoice );
223 223
         }
224 224
 
@@ -238,129 +238,129 @@  discard block
 block discarded – undo
238 238
             $line_item_args['discount_amount_cart'] = wpinv_sanitize_amount( (float) $invoice->get_total_discount(), 2 );
239 239
         }
240 240
 
241
-		return array_merge( $line_item_args, $this->get_line_items() );
241
+        return array_merge( $line_item_args, $this->get_line_items() );
242 242
 
243 243
     }
244 244
 
245 245
     /**
246
-	 * Get line item args for paypal request as a single line item.
247
-	 *
248
-	 * @param  WPInv_Invoice $invoice Invoice object.
249
-	 * @return array
250
-	 */
251
-	protected function get_line_item_args_single_item( $invoice ) {
252
-		$this->delete_line_items();
246
+     * Get line item args for paypal request as a single line item.
247
+     *
248
+     * @param  WPInv_Invoice $invoice Invoice object.
249
+     * @return array
250
+     */
251
+    protected function get_line_item_args_single_item( $invoice ) {
252
+        $this->delete_line_items();
253 253
 
254 254
         $item_name = sprintf( __( 'Invoice #%s', 'invoicing' ), $invoice->get_number() );
255
-		$this->add_line_item( $item_name, 1, wpinv_round_amount( (float) $invoice->get_total(), 2, true ), $invoice->get_id() );
255
+        $this->add_line_item( $item_name, 1, wpinv_round_amount( (float) $invoice->get_total(), 2, true ), $invoice->get_id() );
256 256
 
257
-		return $this->get_line_items();
257
+        return $this->get_line_items();
258 258
     }
259 259
 
260 260
     /**
261
-	 * Return all line items.
262
-	 */
263
-	protected function get_line_items() {
264
-		return $this->line_items;
265
-	}
261
+     * Return all line items.
262
+     */
263
+    protected function get_line_items() {
264
+        return $this->line_items;
265
+    }
266 266
 
267 267
     /**
268
-	 * Remove all line items.
269
-	 */
270
-	protected function delete_line_items() {
271
-		$this->line_items = array();
268
+     * Remove all line items.
269
+     */
270
+    protected function delete_line_items() {
271
+        $this->line_items = array();
272 272
     }
273 273
 
274 274
     /**
275
-	 * Prepare line items to send to paypal.
276
-	 *
277
-	 * @param  WPInv_Invoice $invoice Invoice object.
278
-	 */
279
-	protected function prepare_line_items( $invoice ) {
280
-		$this->delete_line_items();
281
-
282
-		// Items.
283
-		foreach ( $invoice->get_items() as $item ) {
284
-			$amount   = $item->get_price();
285
-			$quantity = $invoice->get_template() == 'amount' ? 1 : $item->get_quantity();
286
-			$this->add_line_item( $item->get_raw_name(), $quantity, $amount, $item->get_id() );
275
+     * Prepare line items to send to paypal.
276
+     *
277
+     * @param  WPInv_Invoice $invoice Invoice object.
278
+     */
279
+    protected function prepare_line_items( $invoice ) {
280
+        $this->delete_line_items();
281
+
282
+        // Items.
283
+        foreach ( $invoice->get_items() as $item ) {
284
+            $amount   = $item->get_price();
285
+            $quantity = $invoice->get_template() == 'amount' ? 1 : $item->get_quantity();
286
+            $this->add_line_item( $item->get_raw_name(), $quantity, $amount, $item->get_id() );
287 287
         }
288 288
 
289 289
         // Fees.
290
-		foreach ( $invoice->get_fees() as $fee => $data ) {
290
+        foreach ( $invoice->get_fees() as $fee => $data ) {
291 291
             $this->add_line_item( $fee, 1, wpinv_sanitize_amount( $data['initial_fee'] ) );
292 292
         }
293 293
 
294 294
     }
295 295
 
296 296
     /**
297
-	 * Add PayPal Line Item.
298
-	 *
299
-	 * @param  string $item_name Item name.
300
-	 * @param  float    $quantity Item quantity.
301
-	 * @param  float  $amount Amount.
302
-	 * @param  string $item_number Item number.
303
-	 */
304
-	protected function add_line_item( $item_name, $quantity = 1, $amount = 0.0, $item_number = '' ) {
305
-		$index = ( count( $this->line_items ) / 4 ) + 1;
306
-
307
-		$item = apply_filters(
308
-			'getpaid_paypal_line_item',
309
-			array(
310
-				'item_name'   => html_entity_decode( getpaid_limit_length( $item_name ? wp_strip_all_tags( $item_name ) : __( 'Item', 'invoicing' ), 127 ), ENT_NOQUOTES, 'UTF-8' ),
311
-				'quantity'    => (float) $quantity,
312
-				'amount'      => wpinv_sanitize_amount( (float) $amount, 2 ),
313
-				'item_number' => $item_number,
314
-			),
315
-			$item_name,
316
-			$quantity,
317
-			$amount,
318
-			$item_number
319
-		);
320
-
321
-		$this->line_items[ 'item_name_' . $index ]   = getpaid_limit_length( $item['item_name'], 127 );
297
+     * Add PayPal Line Item.
298
+     *
299
+     * @param  string $item_name Item name.
300
+     * @param  float    $quantity Item quantity.
301
+     * @param  float  $amount Amount.
302
+     * @param  string $item_number Item number.
303
+     */
304
+    protected function add_line_item( $item_name, $quantity = 1, $amount = 0.0, $item_number = '' ) {
305
+        $index = ( count( $this->line_items ) / 4 ) + 1;
306
+
307
+        $item = apply_filters(
308
+            'getpaid_paypal_line_item',
309
+            array(
310
+                'item_name'   => html_entity_decode( getpaid_limit_length( $item_name ? wp_strip_all_tags( $item_name ) : __( 'Item', 'invoicing' ), 127 ), ENT_NOQUOTES, 'UTF-8' ),
311
+                'quantity'    => (float) $quantity,
312
+                'amount'      => wpinv_sanitize_amount( (float) $amount, 2 ),
313
+                'item_number' => $item_number,
314
+            ),
315
+            $item_name,
316
+            $quantity,
317
+            $amount,
318
+            $item_number
319
+        );
320
+
321
+        $this->line_items[ 'item_name_' . $index ]   = getpaid_limit_length( $item['item_name'], 127 );
322 322
         $this->line_items[ 'quantity_' . $index ]    = $item['quantity'];
323 323
 
324 324
         // The price or amount of the product, service, or contribution, not including shipping, handling, or tax.
325
-		$this->line_items[ 'amount_' . $index ]      = $item['amount'] * $item['quantity'];
326
-		$this->line_items[ 'item_number_' . $index ] = getpaid_limit_length( $item['item_number'], 127 );
325
+        $this->line_items[ 'amount_' . $index ]      = $item['amount'] * $item['quantity'];
326
+        $this->line_items[ 'item_number_' . $index ] = getpaid_limit_length( $item['item_number'], 127 );
327 327
     }
328 328
 
329 329
     /**
330
-	 * If the default request with line items is too long, generate a new one with only one line item.
331
-	 *
332
-	 * https://support.microsoft.com/en-us/help/208427/maximum-url-length-is-2-083-characters-in-internet-explorer.
333
-	 *
334
-	 * @param WPInv_Invoice $invoice Invoice to be sent to Paypal.
335
-	 * @param array    $paypal_args Arguments sent to Paypal in the request.
336
-	 * @return array
337
-	 */
338
-	protected function fix_request_length( $invoice, $paypal_args ) {
339
-		$max_paypal_length = 2083;
340
-		$query_candidate   = http_build_query( $paypal_args, '', '&' );
341
-
342
-		if ( strlen( $this->endpoint . $query_candidate ) <= $max_paypal_length ) {
343
-			return $paypal_args;
344
-		}
345
-
346
-		return apply_filters(
347
-			'getpaid_paypal_args',
348
-			array_merge(
349
-				$this->get_transaction_args( $invoice ),
350
-				$this->get_line_item_args( $invoice, true )
351
-			),
352
-			$invoice
353
-		);
330
+     * If the default request with line items is too long, generate a new one with only one line item.
331
+     *
332
+     * https://support.microsoft.com/en-us/help/208427/maximum-url-length-is-2-083-characters-in-internet-explorer.
333
+     *
334
+     * @param WPInv_Invoice $invoice Invoice to be sent to Paypal.
335
+     * @param array    $paypal_args Arguments sent to Paypal in the request.
336
+     * @return array
337
+     */
338
+    protected function fix_request_length( $invoice, $paypal_args ) {
339
+        $max_paypal_length = 2083;
340
+        $query_candidate   = http_build_query( $paypal_args, '', '&' );
341
+
342
+        if ( strlen( $this->endpoint . $query_candidate ) <= $max_paypal_length ) {
343
+            return $paypal_args;
344
+        }
345
+
346
+        return apply_filters(
347
+            'getpaid_paypal_args',
348
+            array_merge(
349
+                $this->get_transaction_args( $invoice ),
350
+                $this->get_line_item_args( $invoice, true )
351
+            ),
352
+            $invoice
353
+        );
354 354
 
355 355
     }
356 356
 
357 357
     /**
358
-	 * Processes recurring invoices.
359
-	 *
360
-	 * @param  array $paypal_args PayPal args.
361
-	 * @param  WPInv_Invoice    $invoice Invoice object.
362
-	 */
363
-	public function process_subscription( $paypal_args, $invoice ) {
358
+     * Processes recurring invoices.
359
+     *
360
+     * @param  array $paypal_args PayPal args.
361
+     * @param  WPInv_Invoice    $invoice Invoice object.
362
+     */
363
+    public function process_subscription( $paypal_args, $invoice ) {
364 364
 
365 365
         // Make sure this is a subscription.
366 366
         if ( ! $invoice->is_recurring() || ! $subscription = getpaid_get_invoice_subscription( $invoice ) ) {
@@ -381,21 +381,21 @@  discard block
 block discarded – undo
381 381
         $recurring_amount       = (float) wpinv_sanitize_amount( $invoice->get_recurring_total(), 2 );
382 382
         $subscription_item      = $invoice->get_recurring( true );
383 383
 
384
-		// Convert 365 days to 1 year.
385
-		if ( 'D' == $period && 365 == $interval ) {
386
-			$period = 'Y';
387
-			$interval = 1;
388
-		}
384
+        // Convert 365 days to 1 year.
385
+        if ( 'D' == $period && 365 == $interval ) {
386
+            $period = 'Y';
387
+            $interval = 1;
388
+        }
389 389
 
390 390
         if ( $subscription_item->has_free_trial() ) {
391 391
 
392 392
             $paypal_args['a1'] = 0 == $initial_amount ? 0 : $initial_amount;
393 393
 
394
-			// Trial period length.
395
-			$paypal_args['p1'] = $subscription_item->get_trial_interval();
394
+            // Trial period length.
395
+            $paypal_args['p1'] = $subscription_item->get_trial_interval();
396 396
 
397
-			// Trial period.
398
-			$paypal_args['t1'] = $subscription_item->get_trial_period();
397
+            // Trial period.
398
+            $paypal_args['t1'] = $subscription_item->get_trial_period();
399 399
 
400 400
         } elseif ( $initial_amount != $recurring_amount ) {
401 401
 
@@ -418,40 +418,40 @@  discard block
 block discarded – undo
418 418
         }
419 419
 
420 420
         // We have a recurring payment
421
-		if ( ! isset( $param_number ) || 1 == $param_number ) {
421
+        if ( ! isset( $param_number ) || 1 == $param_number ) {
422 422
 
423
-			// Subscription price
424
-			$paypal_args['a3'] = $recurring_amount;
423
+            // Subscription price
424
+            $paypal_args['a3'] = $recurring_amount;
425 425
 
426
-			// Subscription duration
427
-			$paypal_args['p3'] = $interval;
426
+            // Subscription duration
427
+            $paypal_args['p3'] = $interval;
428 428
 
429
-			// Subscription period
430
-			$paypal_args['t3'] = $period;
429
+            // Subscription period
430
+            $paypal_args['t3'] = $period;
431 431
 
432 432
         }
433 433
 
434 434
         // Recurring payments
435
-		if ( 1 == $bill_times || ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() && 2 == $bill_times ) ) {
435
+        if ( 1 == $bill_times || ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() && 2 == $bill_times ) ) {
436 436
 
437
-			// Non-recurring payments
438
-			$paypal_args['src'] = 0;
437
+            // Non-recurring payments
438
+            $paypal_args['src'] = 0;
439 439
 
440
-		} else {
440
+        } else {
441 441
 
442
-			$paypal_args['src'] = 1;
442
+            $paypal_args['src'] = 1;
443 443
 
444
-			if ( $bill_times > 0 ) {
444
+            if ( $bill_times > 0 ) {
445 445
 
446
-				// An initial period is being used to charge a sign-up fee
447
-				if ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() ) {
448
-					$bill_times--;
449
-				}
446
+                // An initial period is being used to charge a sign-up fee
447
+                if ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() ) {
448
+                    $bill_times--;
449
+                }
450 450
 
451 451
                 // Make sure it's not over the max of 52
452 452
                 $paypal_args['srt'] = ( $bill_times <= 52 ? absint( $bill_times ) : 52 );
453 453
 
454
-			}
454
+            }
455 455
         }
456 456
 
457 457
         // Force return URL so that order description & instructions display
@@ -466,19 +466,19 @@  discard block
 block discarded – undo
466 466
 }
467 467
 
468 468
         return apply_filters(
469
-			'getpaid_paypal_subscription_args',
470
-			$paypal_args,
471
-			$invoice
469
+            'getpaid_paypal_subscription_args',
470
+            $paypal_args,
471
+            $invoice
472 472
         );
473 473
 
474 474
     }
475 475
 
476 476
     /**
477
-	 * Processes ipns and marks payments as complete.
478
-	 *
479
-	 * @return void
480
-	 */
481
-	public function verify_ipn() {
477
+     * Processes ipns and marks payments as complete.
478
+     *
479
+     * @return void
480
+     */
481
+    public function verify_ipn() {
482 482
         new GetPaid_Paypal_Gateway_IPN_Handler( $this );
483 483
     }
484 484
 
@@ -488,19 +488,19 @@  discard block
 block discarded – undo
488 488
     public function sandbox_notice() {
489 489
 
490 490
         return sprintf(
491
-			__( 'SANDBOX ENABLED. You can use sandbox testing accounts only. See the %1$sPayPal Sandbox Testing Guide%2$s for more details.', 'invoicing' ),
492
-			'<a href="https://developer.paypal.com/docs/classic/lifecycle/ug_sandbox/">',
493
-			'</a>'
494
-		);
491
+            __( 'SANDBOX ENABLED. You can use sandbox testing accounts only. See the %1$sPayPal Sandbox Testing Guide%2$s for more details.', 'invoicing' ),
492
+            '<a href="https://developer.paypal.com/docs/classic/lifecycle/ug_sandbox/">',
493
+            '</a>'
494
+        );
495 495
 
496 496
     }
497 497
 
498
-	/**
499
-	 * Filters the gateway settings.
500
-	 *
501
-	 * @param array $admin_settings
502
-	 */
503
-	public function admin_settings( $admin_settings ) {
498
+    /**
499
+     * Filters the gateway settings.
500
+     *
501
+     * @param array $admin_settings
502
+     */
503
+    public function admin_settings( $admin_settings ) {
504 504
 
505 505
         $currencies = sprintf(
506 506
             __( 'Supported Currencies: %s', 'invoicing' ),
@@ -510,31 +510,31 @@  discard block
 block discarded – undo
510 510
         $admin_settings['paypal_active']['desc'] .= " ($currencies)";
511 511
         $admin_settings['paypal_desc']['std']     = __( 'Pay via PayPal: you can pay with your credit card if you don\'t have a PayPal account.', 'invoicing' );
512 512
 
513
-		// Access tokens.
514
-		$live_email      = wpinv_get_option( 'paypal_email' );
515
-		$sandbox_email   = wpinv_get_option( 'paypal_sandbox_email' );
513
+        // Access tokens.
514
+        $live_email      = wpinv_get_option( 'paypal_email' );
515
+        $sandbox_email   = wpinv_get_option( 'paypal_sandbox_email' );
516 516
 
517
-		$admin_settings['paypal_connect'] = array(
518
-			'type' => 'hook',
519
-			'id'   => 'paypal_connect',
520
-			'name' => __( 'Connect to PayPal', 'invoicing' ),
521
-		);
517
+        $admin_settings['paypal_connect'] = array(
518
+            'type' => 'hook',
519
+            'id'   => 'paypal_connect',
520
+            'name' => __( 'Connect to PayPal', 'invoicing' ),
521
+        );
522 522
 
523 523
         $admin_settings['paypal_email'] = array(
524 524
             'type'  => 'text',
525
-			'class' => 'live-auth-data',
525
+            'class' => 'live-auth-data',
526 526
             'id'    => 'paypal_email',
527 527
             'name'  => __( 'Live Email Address', 'invoicing' ),
528 528
             'desc'  => __( 'The email address of your PayPal account.', 'invoicing' ),
529 529
         );
530 530
 
531
-		$admin_settings['paypal_sandbox_email'] = array(
531
+        $admin_settings['paypal_sandbox_email'] = array(
532 532
             'type'  => 'text',
533
-			'class' => 'sandbox-auth-data',
533
+            'class' => 'sandbox-auth-data',
534 534
             'id'    => 'paypal_sandbox_email',
535 535
             'name'  => __( 'Sandbox Email Address', 'invoicing' ),
536 536
             'desc'  => __( 'The email address of your sandbox PayPal account.', 'invoicing' ),
537
-			'std'   => wpinv_get_option( 'paypal_email', '' ),
537
+            'std'   => wpinv_get_option( 'paypal_email', '' ),
538 538
         );
539 539
 
540 540
         $admin_settings['paypal_ipn_url'] = array(
@@ -546,29 +546,29 @@  discard block
 block discarded – undo
546 546
             'readonly' => true,
547 547
         );
548 548
 
549
-		return $admin_settings;
550
-	}
549
+        return $admin_settings;
550
+    }
551 551
 
552
-	/**
553
-	 * Retrieves the PayPal connect URL when using the setup wizzard.
554
-	 *
555
-	 *
552
+    /**
553
+     * Retrieves the PayPal connect URL when using the setup wizzard.
554
+     *
555
+     *
556 556
      * @param array $data
557 557
      * @return string
558
-	 */
559
-	public static function maybe_get_connect_url( $url = '', $data = array() ) {
560
-		return self::get_connect_url( false, urldecode( $data['redirect'] ) );
561
-	}
562
-
563
-	/**
564
-	 * Retrieves the PayPal connect URL.
565
-	 *
566
-	 *
558
+     */
559
+    public static function maybe_get_connect_url( $url = '', $data = array() ) {
560
+        return self::get_connect_url( false, urldecode( $data['redirect'] ) );
561
+    }
562
+
563
+    /**
564
+     * Retrieves the PayPal connect URL.
565
+     *
566
+     *
567 567
      * @param bool $is_sandbox
568
-	 * @param string $redirect
568
+     * @param string $redirect
569 569
      * @return string
570
-	 */
571
-	public static function get_connect_url( $is_sandbox, $redirect = '' ) {
570
+     */
571
+    public static function get_connect_url( $is_sandbox, $redirect = '' ) {
572 572
 
573 573
         $redirect_url = add_query_arg(
574 574
             array(
@@ -578,7 +578,7 @@  discard block
 block discarded – undo
578 578
                 'tab'                  => 'gateways',
579 579
                 'section'              => 'paypal',
580 580
                 'getpaid-nonce'        => wp_create_nonce( 'getpaid-nonce' ),
581
-				'redirect'             => urlencode( $redirect ),
581
+                'redirect'             => urlencode( $redirect ),
582 582
             ),
583 583
             admin_url( 'admin.php' )
584 584
         );
@@ -593,12 +593,12 @@  discard block
 block discarded – undo
593 593
 
594 594
     }
595 595
 
596
-	/**
597
-	 * Generates settings page js.
598
-	 *
596
+    /**
597
+     * Generates settings page js.
598
+     *
599 599
      * @return void
600
-	 */
601
-	public static function display_connect_buttons() {
600
+     */
601
+    public static function display_connect_buttons() {
602 602
 
603 603
         ?>
604 604
 			<div class="wpinv-paypal-connect-live">
@@ -640,70 +640,70 @@  discard block
 block discarded – undo
640 640
         <?php
641 641
     }
642 642
 
643
-	/**
644
-	 * Connects to PayPal.
645
-	 *
646
-	 * @param array $data Connection data.
647
-	 * @return void
648
-	 */
649
-	public function connect_paypal( $data ) {
650
-
651
-		$sandbox      = $this->is_sandbox();
652
-		$data         = wp_unslash( $data );
653
-		$access_token = empty( $data['access_token'] ) ? '' : sanitize_text_field( $data['access_token'] );
654
-
655
-		if ( isset( $data['live_mode'] ) ) {
656
-			$sandbox = empty( $data['live_mode'] );
657
-		}
658
-
659
-		wpinv_update_option( 'paypal_sandbox', (int) $sandbox );
660
-		wpinv_update_option( 'paypal_active', 1 );
661
-
662
-		if ( ! empty( $data['error_description'] ) ) {
663
-			getpaid_admin()->show_error( wp_kses_post( urldecode( $data['error_description'] ) ) );
664
-		} else {
665
-
666
-			// Retrieve the user info.
667
-			$user_info = wp_remote_get(
668
-				! $sandbox ? 'https://api-m.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1' : 'https://api-m.sandbox.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1',
669
-				array(
670
-
671
-					'headers' => array(
672
-						'Authorization' => 'Bearer ' . $access_token,
673
-						'Content-type'  => 'application/json',
674
-					),
675
-
676
-				)
677
-			);
678
-
679
-			if ( is_wp_error( $user_info ) ) {
680
-				getpaid_admin()->show_error( wp_kses_post( $user_info->get_error_message() ) );
681
-			} else {
682
-
683
-				// Create application.
684
-				$user_info = json_decode( wp_remote_retrieve_body( $user_info ) );
685
-
686
-				if ( $sandbox ) {
687
-					wpinv_update_option( 'paypal_sandbox_email', sanitize_email( $user_info->emails[0]->value ) );
688
-					wpinv_update_option( 'paypal_sandbox_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) );
689
-					set_transient( 'getpaid_paypal_sandbox_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] );
690
-					getpaid_admin()->show_success( __( 'Successfully connected your PayPal sandbox account', 'invoicing' ) );
691
-				} else {
692
-					wpinv_update_option( 'paypal_email', sanitize_email( $user_info->emails[0]->value ) );
693
-					wpinv_update_option( 'paypal_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) );
694
-					set_transient( 'getpaid_paypal_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] );
695
-					getpaid_admin()->show_success( __( 'Successfully connected your PayPal account', 'invoicing' ) );
696
-				}
643
+    /**
644
+     * Connects to PayPal.
645
+     *
646
+     * @param array $data Connection data.
647
+     * @return void
648
+     */
649
+    public function connect_paypal( $data ) {
650
+
651
+        $sandbox      = $this->is_sandbox();
652
+        $data         = wp_unslash( $data );
653
+        $access_token = empty( $data['access_token'] ) ? '' : sanitize_text_field( $data['access_token'] );
654
+
655
+        if ( isset( $data['live_mode'] ) ) {
656
+            $sandbox = empty( $data['live_mode'] );
657
+        }
658
+
659
+        wpinv_update_option( 'paypal_sandbox', (int) $sandbox );
660
+        wpinv_update_option( 'paypal_active', 1 );
661
+
662
+        if ( ! empty( $data['error_description'] ) ) {
663
+            getpaid_admin()->show_error( wp_kses_post( urldecode( $data['error_description'] ) ) );
664
+        } else {
665
+
666
+            // Retrieve the user info.
667
+            $user_info = wp_remote_get(
668
+                ! $sandbox ? 'https://api-m.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1' : 'https://api-m.sandbox.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1',
669
+                array(
670
+
671
+                    'headers' => array(
672
+                        'Authorization' => 'Bearer ' . $access_token,
673
+                        'Content-type'  => 'application/json',
674
+                    ),
675
+
676
+                )
677
+            );
678
+
679
+            if ( is_wp_error( $user_info ) ) {
680
+                getpaid_admin()->show_error( wp_kses_post( $user_info->get_error_message() ) );
681
+            } else {
682
+
683
+                // Create application.
684
+                $user_info = json_decode( wp_remote_retrieve_body( $user_info ) );
685
+
686
+                if ( $sandbox ) {
687
+                    wpinv_update_option( 'paypal_sandbox_email', sanitize_email( $user_info->emails[0]->value ) );
688
+                    wpinv_update_option( 'paypal_sandbox_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) );
689
+                    set_transient( 'getpaid_paypal_sandbox_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] );
690
+                    getpaid_admin()->show_success( __( 'Successfully connected your PayPal sandbox account', 'invoicing' ) );
691
+                } else {
692
+                    wpinv_update_option( 'paypal_email', sanitize_email( $user_info->emails[0]->value ) );
693
+                    wpinv_update_option( 'paypal_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) );
694
+                    set_transient( 'getpaid_paypal_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] );
695
+                    getpaid_admin()->show_success( __( 'Successfully connected your PayPal account', 'invoicing' ) );
696
+                }
697 697
 }
698 698
 }
699 699
 
700
-		$redirect = empty( $data['redirect'] ) ? admin_url( 'admin.php?page=wpinv-settings&tab=gateways&section=paypal' ) : urldecode( $data['redirect'] );
700
+        $redirect = empty( $data['redirect'] ) ? admin_url( 'admin.php?page=wpinv-settings&tab=gateways&section=paypal' ) : urldecode( $data['redirect'] );
701 701
 
702
-		if ( isset( $data['step'] ) ) {
703
-			$redirect = add_query_arg( 'step', $data['step'], $redirect );
704
-		}
705
-		wp_redirect( $redirect );
706
-		exit;
707
-	}
702
+        if ( isset( $data['step'] ) ) {
703
+            $redirect = add_query_arg( 'step', $data['step'], $redirect );
704
+        }
705
+        wp_redirect( $redirect );
706
+        exit;
707
+    }
708 708
 
709 709
 }
Please login to merge, or discard this patch.
Spacing   +144 added lines, -144 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  *
5 5
  */
6 6
 
7
-defined( 'ABSPATH' ) || exit;
7
+defined('ABSPATH') || exit;
8 8
 
9 9
 /**
10 10
  * Paypal Payment Gateway class.
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
 	 *
25 25
 	 * @var array
26 26
 	 */
27
-    protected $supports = array( 'subscription', 'sandbox', 'single_subscription_group' );
27
+    protected $supports = array('subscription', 'sandbox', 'single_subscription_group');
28 28
 
29 29
     /**
30 30
 	 * Payment method order.
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
 	 *
60 60
 	 * @var array
61 61
 	 */
62
-	public $currencies = array( 'AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR' );
62
+	public $currencies = array('AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR');
63 63
 
64 64
     /**
65 65
 	 * URL to view a transaction.
@@ -80,16 +80,16 @@  discard block
 block discarded – undo
80 80
 	 */
81 81
 	public function __construct() {
82 82
 
83
-        $this->title                = __( 'PayPal Standard', 'invoicing' );
84
-        $this->method_title         = __( 'PayPal Standard', 'invoicing' );
85
-        $this->checkout_button_text = __( 'Proceed to PayPal', 'invoicing' );
86
-        $this->notify_url           = wpinv_get_ipn_url( $this->id );
83
+        $this->title                = __('PayPal Standard', 'invoicing');
84
+        $this->method_title         = __('PayPal Standard', 'invoicing');
85
+        $this->checkout_button_text = __('Proceed to PayPal', 'invoicing');
86
+        $this->notify_url           = wpinv_get_ipn_url($this->id);
87 87
 
88
-		add_filter( 'getpaid_paypal_args', array( $this, 'process_subscription' ), 10, 2 );
89
-        add_filter( 'getpaid_paypal_sandbox_notice', array( $this, 'sandbox_notice' ) );
90
-		add_filter( 'getpaid_get_paypal_connect_url', array( $this, 'maybe_get_connect_url' ), 10, 2 );
91
-		add_action( 'getpaid_authenticated_admin_action_connect_paypal', array( $this, 'connect_paypal' ) );
92
-		add_action( 'wpinv_paypal_connect', array( $this, 'display_connect_buttons' ) );
88
+		add_filter('getpaid_paypal_args', array($this, 'process_subscription'), 10, 2);
89
+        add_filter('getpaid_paypal_sandbox_notice', array($this, 'sandbox_notice'));
90
+		add_filter('getpaid_get_paypal_connect_url', array($this, 'maybe_get_connect_url'), 10, 2);
91
+		add_action('getpaid_authenticated_admin_action_connect_paypal', array($this, 'connect_paypal'));
92
+		add_action('wpinv_paypal_connect', array($this, 'display_connect_buttons'));
93 93
 		parent::__construct();
94 94
     }
95 95
 
@@ -102,16 +102,16 @@  discard block
 block discarded – undo
102 102
 	 * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
103 103
 	 * @return array
104 104
 	 */
105
-	public function process_payment( $invoice, $submission_data, $submission ) {
105
+	public function process_payment($invoice, $submission_data, $submission) {
106 106
 
107 107
         // Get redirect url.
108
-        $paypal_redirect = $this->get_request_url( $invoice );
108
+        $paypal_redirect = $this->get_request_url($invoice);
109 109
 
110 110
         // Add a note about the request url.
111 111
         $invoice->add_note(
112 112
             sprintf(
113
-                __( 'Redirecting to PayPal: %s', 'invoicing' ),
114
-                esc_url( $paypal_redirect )
113
+                __('Redirecting to PayPal: %s', 'invoicing'),
114
+                esc_url($paypal_redirect)
115 115
             ),
116 116
             false,
117 117
             false,
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
         );
120 120
 
121 121
         // Redirect to PayPal
122
-        wp_redirect( $paypal_redirect );
122
+        wp_redirect($paypal_redirect);
123 123
         exit;
124 124
 
125 125
     }
@@ -130,21 +130,21 @@  discard block
 block discarded – undo
130 130
 	 * @param  WPInv_Invoice $invoice Invoice object.
131 131
 	 * @return string
132 132
 	 */
133
-	public function get_request_url( $invoice ) {
133
+	public function get_request_url($invoice) {
134 134
 
135 135
         // Endpoint for this request
136
-		$this->endpoint    = $this->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?';
136
+		$this->endpoint = $this->is_sandbox($invoice) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?';
137 137
 
138 138
         // Retrieve paypal args.
139
-        $paypal_args       = map_deep( $this->get_paypal_args( $invoice ), 'urlencode' );
139
+        $paypal_args = map_deep($this->get_paypal_args($invoice), 'urlencode');
140 140
 
141
-        if ( $invoice->is_recurring() ) {
141
+        if ($invoice->is_recurring()) {
142 142
             $paypal_args['bn'] = 'GetPaid_Subscribe_WPS_US';
143 143
         } else {
144 144
             $paypal_args['bn'] = 'GetPaid_ShoppingCart_WPS_US';
145 145
         }
146 146
 
147
-        return add_query_arg( $paypal_args, $this->endpoint );
147
+        return add_query_arg($paypal_args, $this->endpoint);
148 148
 
149 149
 	}
150 150
 
@@ -154,25 +154,25 @@  discard block
 block discarded – undo
154 154
 	 * @param  WPInv_Invoice $invoice Invoice object.
155 155
 	 * @return array
156 156
 	 */
157
-	protected function get_paypal_args( $invoice ) {
157
+	protected function get_paypal_args($invoice) {
158 158
 
159 159
         // Whether or not to send the line items as one item.
160
-		$force_one_line_item = apply_filters( 'getpaid_paypal_force_one_line_item', true, $invoice );
160
+		$force_one_line_item = apply_filters('getpaid_paypal_force_one_line_item', true, $invoice);
161 161
 
162
-		if ( $invoice->is_recurring() || ( wpinv_use_taxes() && wpinv_prices_include_tax() ) ) {
162
+		if ($invoice->is_recurring() || (wpinv_use_taxes() && wpinv_prices_include_tax())) {
163 163
 			$force_one_line_item = true;
164 164
 		}
165 165
 
166 166
 		$paypal_args = apply_filters(
167 167
 			'getpaid_paypal_args',
168 168
 			array_merge(
169
-				$this->get_transaction_args( $invoice ),
170
-				$this->get_line_item_args( $invoice, $force_one_line_item )
169
+				$this->get_transaction_args($invoice),
170
+				$this->get_line_item_args($invoice, $force_one_line_item)
171 171
 			),
172 172
 			$invoice
173 173
 		);
174 174
 
175
-		return $this->fix_request_length( $invoice, $paypal_args );
175
+		return $this->fix_request_length($invoice, $paypal_args);
176 176
     }
177 177
 
178 178
     /**
@@ -181,9 +181,9 @@  discard block
 block discarded – undo
181 181
 	 * @param WPInv_Invoice $invoice Invoice object.
182 182
 	 * @return array
183 183
 	 */
184
-	protected function get_transaction_args( $invoice ) {
184
+	protected function get_transaction_args($invoice) {
185 185
 
186
-		$email = $this->is_sandbox( $invoice ) ? wpinv_get_option( 'paypal_sandbox_email', wpinv_get_option( 'paypal_email', '' ) ) : wpinv_get_option( 'paypal_email', '' );
186
+		$email = $this->is_sandbox($invoice) ? wpinv_get_option('paypal_sandbox_email', wpinv_get_option('paypal_email', '')) : wpinv_get_option('paypal_email', '');
187 187
 		return array(
188 188
             'cmd'           => '_cart',
189 189
             'business'      => $email,
@@ -194,16 +194,16 @@  discard block
 block discarded – undo
194 194
             'rm'            => is_ssl() ? 2 : 1,
195 195
             'upload'        => 1,
196 196
             'currency_code' => $invoice->get_currency(), // https://developer.paypal.com/docs/nvp-soap-api/currency-codes/#paypal
197
-            'return'        => esc_url_raw( $this->get_return_url( $invoice ) ),
198
-            'cancel_return' => esc_url_raw( $invoice->get_checkout_payment_url() ),
199
-            'notify_url'    => getpaid_limit_length( $this->notify_url, 255 ),
200
-            'invoice'       => getpaid_limit_length( $invoice->get_number(), 127 ),
197
+            'return'        => esc_url_raw($this->get_return_url($invoice)),
198
+            'cancel_return' => esc_url_raw($invoice->get_checkout_payment_url()),
199
+            'notify_url'    => getpaid_limit_length($this->notify_url, 255),
200
+            'invoice'       => getpaid_limit_length($invoice->get_number(), 127),
201 201
             'custom'        => $invoice->get_id(),
202
-            'first_name'    => getpaid_limit_length( $invoice->get_first_name(), 32 ),
203
-            'last_name'     => getpaid_limit_length( $invoice->get_last_name(), 64 ),
204
-            'country'       => getpaid_limit_length( $invoice->get_country(), 2 ),
205
-            'email'         => getpaid_limit_length( $invoice->get_email(), 127 ),
206
-            'cbt'           => get_bloginfo( 'name' ),
202
+            'first_name'    => getpaid_limit_length($invoice->get_first_name(), 32),
203
+            'last_name'     => getpaid_limit_length($invoice->get_last_name(), 64),
204
+            'country'       => getpaid_limit_length($invoice->get_country(), 2),
205
+            'email'         => getpaid_limit_length($invoice->get_email(), 127),
206
+            'cbt'           => get_bloginfo('name'),
207 207
         );
208 208
 
209 209
     }
@@ -215,30 +215,30 @@  discard block
 block discarded – undo
215 215
 	 * @param  bool     $force_one_line_item Create only one item for this invoice.
216 216
 	 * @return array
217 217
 	 */
218
-	protected function get_line_item_args( $invoice, $force_one_line_item = false ) {
218
+	protected function get_line_item_args($invoice, $force_one_line_item = false) {
219 219
 
220 220
         // Maybe send invoice as a single item.
221
-		if ( $force_one_line_item ) {
222
-            return $this->get_line_item_args_single_item( $invoice );
221
+		if ($force_one_line_item) {
222
+            return $this->get_line_item_args_single_item($invoice);
223 223
         }
224 224
 
225 225
         // Send each line item individually.
226 226
         $line_item_args = array();
227 227
 
228 228
         // Prepare line items.
229
-        $this->prepare_line_items( $invoice );
229
+        $this->prepare_line_items($invoice);
230 230
 
231 231
         // Add taxes to the cart
232
-        if ( wpinv_use_taxes() && $invoice->is_taxable() ) {
233
-            $line_item_args['tax_cart'] = wpinv_sanitize_amount( (float) $invoice->get_total_tax(), 2 );
232
+        if (wpinv_use_taxes() && $invoice->is_taxable()) {
233
+            $line_item_args['tax_cart'] = wpinv_sanitize_amount((float) $invoice->get_total_tax(), 2);
234 234
         }
235 235
 
236 236
         // Add discount.
237
-        if ( $invoice->get_total_discount() > 0 ) {
238
-            $line_item_args['discount_amount_cart'] = wpinv_sanitize_amount( (float) $invoice->get_total_discount(), 2 );
237
+        if ($invoice->get_total_discount() > 0) {
238
+            $line_item_args['discount_amount_cart'] = wpinv_sanitize_amount((float) $invoice->get_total_discount(), 2);
239 239
         }
240 240
 
241
-		return array_merge( $line_item_args, $this->get_line_items() );
241
+		return array_merge($line_item_args, $this->get_line_items());
242 242
 
243 243
     }
244 244
 
@@ -248,11 +248,11 @@  discard block
 block discarded – undo
248 248
 	 * @param  WPInv_Invoice $invoice Invoice object.
249 249
 	 * @return array
250 250
 	 */
251
-	protected function get_line_item_args_single_item( $invoice ) {
251
+	protected function get_line_item_args_single_item($invoice) {
252 252
 		$this->delete_line_items();
253 253
 
254
-        $item_name = sprintf( __( 'Invoice #%s', 'invoicing' ), $invoice->get_number() );
255
-		$this->add_line_item( $item_name, 1, wpinv_round_amount( (float) $invoice->get_total(), 2, true ), $invoice->get_id() );
254
+        $item_name = sprintf(__('Invoice #%s', 'invoicing'), $invoice->get_number());
255
+		$this->add_line_item($item_name, 1, wpinv_round_amount((float) $invoice->get_total(), 2, true), $invoice->get_id());
256 256
 
257 257
 		return $this->get_line_items();
258 258
     }
@@ -276,19 +276,19 @@  discard block
 block discarded – undo
276 276
 	 *
277 277
 	 * @param  WPInv_Invoice $invoice Invoice object.
278 278
 	 */
279
-	protected function prepare_line_items( $invoice ) {
279
+	protected function prepare_line_items($invoice) {
280 280
 		$this->delete_line_items();
281 281
 
282 282
 		// Items.
283
-		foreach ( $invoice->get_items() as $item ) {
283
+		foreach ($invoice->get_items() as $item) {
284 284
 			$amount   = $item->get_price();
285 285
 			$quantity = $invoice->get_template() == 'amount' ? 1 : $item->get_quantity();
286
-			$this->add_line_item( $item->get_raw_name(), $quantity, $amount, $item->get_id() );
286
+			$this->add_line_item($item->get_raw_name(), $quantity, $amount, $item->get_id());
287 287
         }
288 288
 
289 289
         // Fees.
290
-		foreach ( $invoice->get_fees() as $fee => $data ) {
291
-            $this->add_line_item( $fee, 1, wpinv_sanitize_amount( $data['initial_fee'] ) );
290
+		foreach ($invoice->get_fees() as $fee => $data) {
291
+            $this->add_line_item($fee, 1, wpinv_sanitize_amount($data['initial_fee']));
292 292
         }
293 293
 
294 294
     }
@@ -301,15 +301,15 @@  discard block
 block discarded – undo
301 301
 	 * @param  float  $amount Amount.
302 302
 	 * @param  string $item_number Item number.
303 303
 	 */
304
-	protected function add_line_item( $item_name, $quantity = 1, $amount = 0.0, $item_number = '' ) {
305
-		$index = ( count( $this->line_items ) / 4 ) + 1;
304
+	protected function add_line_item($item_name, $quantity = 1, $amount = 0.0, $item_number = '') {
305
+		$index = (count($this->line_items) / 4) + 1;
306 306
 
307 307
 		$item = apply_filters(
308 308
 			'getpaid_paypal_line_item',
309 309
 			array(
310
-				'item_name'   => html_entity_decode( getpaid_limit_length( $item_name ? wp_strip_all_tags( $item_name ) : __( 'Item', 'invoicing' ), 127 ), ENT_NOQUOTES, 'UTF-8' ),
310
+				'item_name'   => html_entity_decode(getpaid_limit_length($item_name ? wp_strip_all_tags($item_name) : __('Item', 'invoicing'), 127), ENT_NOQUOTES, 'UTF-8'),
311 311
 				'quantity'    => (float) $quantity,
312
-				'amount'      => wpinv_sanitize_amount( (float) $amount, 2 ),
312
+				'amount'      => wpinv_sanitize_amount((float) $amount, 2),
313 313
 				'item_number' => $item_number,
314 314
 			),
315 315
 			$item_name,
@@ -318,12 +318,12 @@  discard block
 block discarded – undo
318 318
 			$item_number
319 319
 		);
320 320
 
321
-		$this->line_items[ 'item_name_' . $index ]   = getpaid_limit_length( $item['item_name'], 127 );
322
-        $this->line_items[ 'quantity_' . $index ]    = $item['quantity'];
321
+		$this->line_items['item_name_' . $index] = getpaid_limit_length($item['item_name'], 127);
322
+        $this->line_items['quantity_' . $index] = $item['quantity'];
323 323
 
324 324
         // The price or amount of the product, service, or contribution, not including shipping, handling, or tax.
325
-		$this->line_items[ 'amount_' . $index ]      = $item['amount'] * $item['quantity'];
326
-		$this->line_items[ 'item_number_' . $index ] = getpaid_limit_length( $item['item_number'], 127 );
325
+		$this->line_items['amount_' . $index]      = $item['amount'] * $item['quantity'];
326
+		$this->line_items['item_number_' . $index] = getpaid_limit_length($item['item_number'], 127);
327 327
     }
328 328
 
329 329
     /**
@@ -335,19 +335,19 @@  discard block
 block discarded – undo
335 335
 	 * @param array    $paypal_args Arguments sent to Paypal in the request.
336 336
 	 * @return array
337 337
 	 */
338
-	protected function fix_request_length( $invoice, $paypal_args ) {
338
+	protected function fix_request_length($invoice, $paypal_args) {
339 339
 		$max_paypal_length = 2083;
340
-		$query_candidate   = http_build_query( $paypal_args, '', '&' );
340
+		$query_candidate   = http_build_query($paypal_args, '', '&');
341 341
 
342
-		if ( strlen( $this->endpoint . $query_candidate ) <= $max_paypal_length ) {
342
+		if (strlen($this->endpoint . $query_candidate) <= $max_paypal_length) {
343 343
 			return $paypal_args;
344 344
 		}
345 345
 
346 346
 		return apply_filters(
347 347
 			'getpaid_paypal_args',
348 348
 			array_merge(
349
-				$this->get_transaction_args( $invoice ),
350
-				$this->get_line_item_args( $invoice, true )
349
+				$this->get_transaction_args($invoice),
350
+				$this->get_line_item_args($invoice, true)
351 351
 			),
352 352
 			$invoice
353 353
 		);
@@ -360,10 +360,10 @@  discard block
 block discarded – undo
360 360
 	 * @param  array $paypal_args PayPal args.
361 361
 	 * @param  WPInv_Invoice    $invoice Invoice object.
362 362
 	 */
363
-	public function process_subscription( $paypal_args, $invoice ) {
363
+	public function process_subscription($paypal_args, $invoice) {
364 364
 
365 365
         // Make sure this is a subscription.
366
-        if ( ! $invoice->is_recurring() || ! $subscription = getpaid_get_invoice_subscription( $invoice ) ) {
366
+        if (!$invoice->is_recurring() || !$subscription = getpaid_get_invoice_subscription($invoice)) {
367 367
             return $paypal_args;
368 368
         }
369 369
 
@@ -371,23 +371,23 @@  discard block
 block discarded – undo
371 371
         $paypal_args['cmd'] = '_xclick-subscriptions';
372 372
 
373 373
         // Subscription name.
374
-        $paypal_args['item_name'] = sprintf( __( 'Invoice #%s', 'invoicing' ), $invoice->get_number() );
374
+        $paypal_args['item_name'] = sprintf(__('Invoice #%s', 'invoicing'), $invoice->get_number());
375 375
 
376 376
         // Get subscription args.
377
-        $period                 = strtoupper( substr( $subscription->get_period(), 0, 1 ) );
377
+        $period                 = strtoupper(substr($subscription->get_period(), 0, 1));
378 378
         $interval               = (int) $subscription->get_frequency();
379 379
         $bill_times             = (int) $subscription->get_bill_times();
380
-        $initial_amount         = (float) wpinv_sanitize_amount( $invoice->get_initial_total(), 2 );
381
-        $recurring_amount       = (float) wpinv_sanitize_amount( $invoice->get_recurring_total(), 2 );
382
-        $subscription_item      = $invoice->get_recurring( true );
380
+        $initial_amount         = (float) wpinv_sanitize_amount($invoice->get_initial_total(), 2);
381
+        $recurring_amount       = (float) wpinv_sanitize_amount($invoice->get_recurring_total(), 2);
382
+        $subscription_item      = $invoice->get_recurring(true);
383 383
 
384 384
 		// Convert 365 days to 1 year.
385
-		if ( 'D' == $period && 365 == $interval ) {
385
+		if ('D' == $period && 365 == $interval) {
386 386
 			$period = 'Y';
387 387
 			$interval = 1;
388 388
 		}
389 389
 
390
-        if ( $subscription_item->has_free_trial() ) {
390
+        if ($subscription_item->has_free_trial()) {
391 391
 
392 392
             $paypal_args['a1'] = 0 == $initial_amount ? 0 : $initial_amount;
393 393
 
@@ -397,28 +397,28 @@  discard block
 block discarded – undo
397 397
 			// Trial period.
398 398
 			$paypal_args['t1'] = $subscription_item->get_trial_period();
399 399
 
400
-        } elseif ( $initial_amount != $recurring_amount ) {
400
+        } elseif ($initial_amount != $recurring_amount) {
401 401
 
402 402
             // No trial period, but initial amount includes a sign-up fee and/or other items, so charge it as a separate period.
403 403
 
404
-            if ( 1 == $bill_times ) {
404
+            if (1 == $bill_times) {
405 405
                 $param_number = 3;
406 406
             } else {
407 407
                 $param_number = 1;
408 408
             }
409 409
 
410
-            $paypal_args[ 'a' . $param_number ] = $initial_amount ? $initial_amount : 0;
410
+            $paypal_args['a' . $param_number] = $initial_amount ? $initial_amount : 0;
411 411
 
412 412
             // Sign Up interval
413
-            $paypal_args[ 'p' . $param_number ] = $interval;
413
+            $paypal_args['p' . $param_number] = $interval;
414 414
 
415 415
             // Sign Up unit of duration
416
-            $paypal_args[ 't' . $param_number ] = $period;
416
+            $paypal_args['t' . $param_number] = $period;
417 417
 
418 418
         }
419 419
 
420 420
         // We have a recurring payment
421
-		if ( ! isset( $param_number ) || 1 == $param_number ) {
421
+		if (!isset($param_number) || 1 == $param_number) {
422 422
 
423 423
 			// Subscription price
424 424
 			$paypal_args['a3'] = $recurring_amount;
@@ -432,7 +432,7 @@  discard block
 block discarded – undo
432 432
         }
433 433
 
434 434
         // Recurring payments
435
-		if ( 1 == $bill_times || ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() && 2 == $bill_times ) ) {
435
+		if (1 == $bill_times || ($initial_amount != $recurring_amount && !$subscription_item->has_free_trial() && 2 == $bill_times)) {
436 436
 
437 437
 			// Non-recurring payments
438 438
 			$paypal_args['src'] = 0;
@@ -441,15 +441,15 @@  discard block
 block discarded – undo
441 441
 
442 442
 			$paypal_args['src'] = 1;
443 443
 
444
-			if ( $bill_times > 0 ) {
444
+			if ($bill_times > 0) {
445 445
 
446 446
 				// An initial period is being used to charge a sign-up fee
447
-				if ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() ) {
447
+				if ($initial_amount != $recurring_amount && !$subscription_item->has_free_trial()) {
448 448
 					$bill_times--;
449 449
 				}
450 450
 
451 451
                 // Make sure it's not over the max of 52
452
-                $paypal_args['srt'] = ( $bill_times <= 52 ? absint( $bill_times ) : 52 );
452
+                $paypal_args['srt'] = ($bill_times <= 52 ? absint($bill_times) : 52);
453 453
 
454 454
 			}
455 455
         }
@@ -458,10 +458,10 @@  discard block
 block discarded – undo
458 458
         $paypal_args['rm'] = 2;
459 459
 
460 460
         // Get rid of redudant items.
461
-        foreach ( array( 'item_name_1', 'quantity_1', 'amount_1', 'item_number_1' ) as $arg ) {
461
+        foreach (array('item_name_1', 'quantity_1', 'amount_1', 'item_number_1') as $arg) {
462 462
 
463
-            if ( isset( $paypal_args[ $arg ] ) ) {
464
-                unset( $paypal_args[ $arg ] );
463
+            if (isset($paypal_args[$arg])) {
464
+                unset($paypal_args[$arg]);
465 465
             }
466 466
 }
467 467
 
@@ -479,7 +479,7 @@  discard block
 block discarded – undo
479 479
 	 * @return void
480 480
 	 */
481 481
 	public function verify_ipn() {
482
-        new GetPaid_Paypal_Gateway_IPN_Handler( $this );
482
+        new GetPaid_Paypal_Gateway_IPN_Handler($this);
483 483
     }
484 484
 
485 485
     /**
@@ -488,7 +488,7 @@  discard block
 block discarded – undo
488 488
     public function sandbox_notice() {
489 489
 
490 490
         return sprintf(
491
-			__( 'SANDBOX ENABLED. You can use sandbox testing accounts only. See the %1$sPayPal Sandbox Testing Guide%2$s for more details.', 'invoicing' ),
491
+			__('SANDBOX ENABLED. You can use sandbox testing accounts only. See the %1$sPayPal Sandbox Testing Guide%2$s for more details.', 'invoicing'),
492 492
 			'<a href="https://developer.paypal.com/docs/classic/lifecycle/ug_sandbox/">',
493 493
 			'</a>'
494 494
 		);
@@ -500,49 +500,49 @@  discard block
 block discarded – undo
500 500
 	 *
501 501
 	 * @param array $admin_settings
502 502
 	 */
503
-	public function admin_settings( $admin_settings ) {
503
+	public function admin_settings($admin_settings) {
504 504
 
505 505
         $currencies = sprintf(
506
-            __( 'Supported Currencies: %s', 'invoicing' ),
507
-            implode( ', ', $this->currencies )
506
+            __('Supported Currencies: %s', 'invoicing'),
507
+            implode(', ', $this->currencies)
508 508
         );
509 509
 
510 510
         $admin_settings['paypal_active']['desc'] .= " ($currencies)";
511
-        $admin_settings['paypal_desc']['std']     = __( 'Pay via PayPal: you can pay with your credit card if you don\'t have a PayPal account.', 'invoicing' );
511
+        $admin_settings['paypal_desc']['std']     = __('Pay via PayPal: you can pay with your credit card if you don\'t have a PayPal account.', 'invoicing');
512 512
 
513 513
 		// Access tokens.
514
-		$live_email      = wpinv_get_option( 'paypal_email' );
515
-		$sandbox_email   = wpinv_get_option( 'paypal_sandbox_email' );
514
+		$live_email      = wpinv_get_option('paypal_email');
515
+		$sandbox_email   = wpinv_get_option('paypal_sandbox_email');
516 516
 
517 517
 		$admin_settings['paypal_connect'] = array(
518 518
 			'type' => 'hook',
519 519
 			'id'   => 'paypal_connect',
520
-			'name' => __( 'Connect to PayPal', 'invoicing' ),
520
+			'name' => __('Connect to PayPal', 'invoicing'),
521 521
 		);
522 522
 
523 523
         $admin_settings['paypal_email'] = array(
524 524
             'type'  => 'text',
525 525
 			'class' => 'live-auth-data',
526 526
             'id'    => 'paypal_email',
527
-            'name'  => __( 'Live Email Address', 'invoicing' ),
528
-            'desc'  => __( 'The email address of your PayPal account.', 'invoicing' ),
527
+            'name'  => __('Live Email Address', 'invoicing'),
528
+            'desc'  => __('The email address of your PayPal account.', 'invoicing'),
529 529
         );
530 530
 
531 531
 		$admin_settings['paypal_sandbox_email'] = array(
532 532
             'type'  => 'text',
533 533
 			'class' => 'sandbox-auth-data',
534 534
             'id'    => 'paypal_sandbox_email',
535
-            'name'  => __( 'Sandbox Email Address', 'invoicing' ),
536
-            'desc'  => __( 'The email address of your sandbox PayPal account.', 'invoicing' ),
537
-			'std'   => wpinv_get_option( 'paypal_email', '' ),
535
+            'name'  => __('Sandbox Email Address', 'invoicing'),
536
+            'desc'  => __('The email address of your sandbox PayPal account.', 'invoicing'),
537
+			'std'   => wpinv_get_option('paypal_email', ''),
538 538
         );
539 539
 
540 540
         $admin_settings['paypal_ipn_url'] = array(
541 541
             'type'     => 'ipn_url',
542 542
             'id'       => 'paypal_ipn_url',
543
-            'name'     => __( 'IPN Url', 'invoicing' ),
543
+            'name'     => __('IPN Url', 'invoicing'),
544 544
             'std'      => $this->notify_url,
545
-            'desc'     => __( "If you've not enabled IPNs in your paypal account, use the above URL to enable them.", 'invoicing' ) . ' <a href="https://developer.paypal.com/docs/api-basics/notifications/ipn/"><em>' . __( 'Learn more.', 'invoicing' ) . '</em></a>',
545
+            'desc'     => __("If you've not enabled IPNs in your paypal account, use the above URL to enable them.", 'invoicing') . ' <a href="https://developer.paypal.com/docs/api-basics/notifications/ipn/"><em>' . __('Learn more.', 'invoicing') . '</em></a>',
546 546
             'readonly' => true,
547 547
         );
548 548
 
@@ -556,8 +556,8 @@  discard block
 block discarded – undo
556 556
      * @param array $data
557 557
      * @return string
558 558
 	 */
559
-	public static function maybe_get_connect_url( $url = '', $data = array() ) {
560
-		return self::get_connect_url( false, urldecode( $data['redirect'] ) );
559
+	public static function maybe_get_connect_url($url = '', $data = array()) {
560
+		return self::get_connect_url(false, urldecode($data['redirect']));
561 561
 	}
562 562
 
563 563
 	/**
@@ -568,25 +568,25 @@  discard block
 block discarded – undo
568 568
 	 * @param string $redirect
569 569
      * @return string
570 570
 	 */
571
-	public static function get_connect_url( $is_sandbox, $redirect = '' ) {
571
+	public static function get_connect_url($is_sandbox, $redirect = '') {
572 572
 
573 573
         $redirect_url = add_query_arg(
574 574
             array(
575 575
                 'getpaid-admin-action' => 'connect_paypal',
576 576
                 'page'                 => 'wpinv-settings',
577
-                'live_mode'            => (int) empty( $is_sandbox ),
577
+                'live_mode'            => (int) empty($is_sandbox),
578 578
                 'tab'                  => 'gateways',
579 579
                 'section'              => 'paypal',
580
-                'getpaid-nonce'        => wp_create_nonce( 'getpaid-nonce' ),
581
-				'redirect'             => urlencode( $redirect ),
580
+                'getpaid-nonce'        => wp_create_nonce('getpaid-nonce'),
581
+				'redirect'             => urlencode($redirect),
582 582
             ),
583
-            admin_url( 'admin.php' )
583
+            admin_url('admin.php')
584 584
         );
585 585
 
586 586
         return add_query_arg(
587 587
             array(
588
-                'live_mode'    => (int) empty( $is_sandbox ),
589
-                'redirect_url' => urlencode( str_replace( '&amp;', '&', $redirect_url ) ),
588
+                'live_mode'    => (int) empty($is_sandbox),
589
+                'redirect_url' => urlencode(str_replace('&amp;', '&', $redirect_url)),
590 590
             ),
591 591
             'https://ayecode.io/oauth/paypal'
592 592
         );
@@ -602,10 +602,10 @@  discard block
 block discarded – undo
602 602
 
603 603
         ?>
604 604
 			<div class="wpinv-paypal-connect-live">
605
-				<a class="button button-primary" href="<?php echo esc_url( self::get_connect_url( false ) ); ?>"><?php esc_html_e( 'Connect to PayPal', 'invoicing' ); ?></a>
605
+				<a class="button button-primary" href="<?php echo esc_url(self::get_connect_url(false)); ?>"><?php esc_html_e('Connect to PayPal', 'invoicing'); ?></a>
606 606
 			</div>
607 607
 			<div class="wpinv-paypal-connect-sandbox">
608
-				<a class="button button-primary" href="<?php echo esc_url( self::get_connect_url( true ) ); ?>"><?php esc_html_e( 'Connect to PayPal Sandbox', 'invoicing' ); ?></a>
608
+				<a class="button button-primary" href="<?php echo esc_url(self::get_connect_url(true)); ?>"><?php esc_html_e('Connect to PayPal Sandbox', 'invoicing'); ?></a>
609 609
 			</div>
610 610
 
611 611
             <script>
@@ -646,26 +646,26 @@  discard block
 block discarded – undo
646 646
 	 * @param array $data Connection data.
647 647
 	 * @return void
648 648
 	 */
649
-	public function connect_paypal( $data ) {
649
+	public function connect_paypal($data) {
650 650
 
651 651
 		$sandbox      = $this->is_sandbox();
652
-		$data         = wp_unslash( $data );
653
-		$access_token = empty( $data['access_token'] ) ? '' : sanitize_text_field( $data['access_token'] );
652
+		$data         = wp_unslash($data);
653
+		$access_token = empty($data['access_token']) ? '' : sanitize_text_field($data['access_token']);
654 654
 
655
-		if ( isset( $data['live_mode'] ) ) {
656
-			$sandbox = empty( $data['live_mode'] );
655
+		if (isset($data['live_mode'])) {
656
+			$sandbox = empty($data['live_mode']);
657 657
 		}
658 658
 
659
-		wpinv_update_option( 'paypal_sandbox', (int) $sandbox );
660
-		wpinv_update_option( 'paypal_active', 1 );
659
+		wpinv_update_option('paypal_sandbox', (int) $sandbox);
660
+		wpinv_update_option('paypal_active', 1);
661 661
 
662
-		if ( ! empty( $data['error_description'] ) ) {
663
-			getpaid_admin()->show_error( wp_kses_post( urldecode( $data['error_description'] ) ) );
662
+		if (!empty($data['error_description'])) {
663
+			getpaid_admin()->show_error(wp_kses_post(urldecode($data['error_description'])));
664 664
 		} else {
665 665
 
666 666
 			// Retrieve the user info.
667 667
 			$user_info = wp_remote_get(
668
-				! $sandbox ? 'https://api-m.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1' : 'https://api-m.sandbox.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1',
668
+				!$sandbox ? 'https://api-m.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1' : 'https://api-m.sandbox.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1',
669 669
 				array(
670 670
 
671 671
 					'headers' => array(
@@ -676,33 +676,33 @@  discard block
 block discarded – undo
676 676
 				)
677 677
 			);
678 678
 
679
-			if ( is_wp_error( $user_info ) ) {
680
-				getpaid_admin()->show_error( wp_kses_post( $user_info->get_error_message() ) );
679
+			if (is_wp_error($user_info)) {
680
+				getpaid_admin()->show_error(wp_kses_post($user_info->get_error_message()));
681 681
 			} else {
682 682
 
683 683
 				// Create application.
684
-				$user_info = json_decode( wp_remote_retrieve_body( $user_info ) );
684
+				$user_info = json_decode(wp_remote_retrieve_body($user_info));
685 685
 
686
-				if ( $sandbox ) {
687
-					wpinv_update_option( 'paypal_sandbox_email', sanitize_email( $user_info->emails[0]->value ) );
688
-					wpinv_update_option( 'paypal_sandbox_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) );
689
-					set_transient( 'getpaid_paypal_sandbox_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] );
690
-					getpaid_admin()->show_success( __( 'Successfully connected your PayPal sandbox account', 'invoicing' ) );
686
+				if ($sandbox) {
687
+					wpinv_update_option('paypal_sandbox_email', sanitize_email($user_info->emails[0]->value));
688
+					wpinv_update_option('paypal_sandbox_refresh_token', sanitize_text_field(urldecode($data['refresh_token'])));
689
+					set_transient('getpaid_paypal_sandbox_access_token', sanitize_text_field(urldecode($data['access_token'])), (int) $data['expires_in']);
690
+					getpaid_admin()->show_success(__('Successfully connected your PayPal sandbox account', 'invoicing'));
691 691
 				} else {
692
-					wpinv_update_option( 'paypal_email', sanitize_email( $user_info->emails[0]->value ) );
693
-					wpinv_update_option( 'paypal_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) );
694
-					set_transient( 'getpaid_paypal_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] );
695
-					getpaid_admin()->show_success( __( 'Successfully connected your PayPal account', 'invoicing' ) );
692
+					wpinv_update_option('paypal_email', sanitize_email($user_info->emails[0]->value));
693
+					wpinv_update_option('paypal_refresh_token', sanitize_text_field(urldecode($data['refresh_token'])));
694
+					set_transient('getpaid_paypal_access_token', sanitize_text_field(urldecode($data['access_token'])), (int) $data['expires_in']);
695
+					getpaid_admin()->show_success(__('Successfully connected your PayPal account', 'invoicing'));
696 696
 				}
697 697
 }
698 698
 }
699 699
 
700
-		$redirect = empty( $data['redirect'] ) ? admin_url( 'admin.php?page=wpinv-settings&tab=gateways&section=paypal' ) : urldecode( $data['redirect'] );
700
+		$redirect = empty($data['redirect']) ? admin_url('admin.php?page=wpinv-settings&tab=gateways&section=paypal') : urldecode($data['redirect']);
701 701
 
702
-		if ( isset( $data['step'] ) ) {
703
-			$redirect = add_query_arg( 'step', $data['step'], $redirect );
702
+		if (isset($data['step'])) {
703
+			$redirect = add_query_arg('step', $data['step'], $redirect);
704 704
 		}
705
-		wp_redirect( $redirect );
705
+		wp_redirect($redirect);
706 706
 		exit;
707 707
 	}
708 708
 
Please login to merge, or discard this patch.