Passed
Push — master ( 361a24...0a8090 )
by Brian
05:41
created
templates/payment-forms/elements/date.php 1 patch
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -7,34 +7,34 @@  discard block
 block discarded – undo
7 7
  * @version 1.0.19
8 8
  */
9 9
 
10
-defined( 'ABSPATH' ) || exit;
10
+defined('ABSPATH') || exit;
11 11
 
12
-$label       = empty( $label ) ? '' : wp_kses_post( $label );
13
-$label_class = sanitize_key( preg_replace( '/[^A-Za-z0-9_-]/', '-', $label ) );
14
-if ( ! empty( $required ) ) {
12
+$label       = empty($label) ? '' : wp_kses_post($label);
13
+$label_class = sanitize_key(preg_replace('/[^A-Za-z0-9_-]/', '-', $label));
14
+if (!empty($required)) {
15 15
 	$label .= "<span class='text-danger'> *</span>";
16 16
 }
17 17
 
18 18
 $disable_dates = array();
19 19
 
20
-if ( ! empty( $disabled_dates ) ) {
21
-	$disabled_dates = preg_replace( '/\s+/', '', $disabled_dates );
22
-	$disabled_dates = str_ireplace( 'today', current_time( 'Y-m-d' ), $disabled_dates );
23
-	$disabled_dates = array_filter( explode( ',', $disabled_dates ) );
20
+if (!empty($disabled_dates)) {
21
+	$disabled_dates = preg_replace('/\s+/', '', $disabled_dates);
22
+	$disabled_dates = str_ireplace('today', current_time('Y-m-d'), $disabled_dates);
23
+	$disabled_dates = array_filter(explode(',', $disabled_dates));
24 24
 
25
-	foreach ( $disabled_dates as $disabled_date ) {
25
+	foreach ($disabled_dates as $disabled_date) {
26 26
 
27
-		$disabled_date = trim( $disabled_date );
27
+		$disabled_date = trim($disabled_date);
28 28
 
29
-		if ( false === strpos( $disabled_date, '|' ) ) {
29
+		if (false === strpos($disabled_date, '|')) {
30 30
 			$disable_dates[] = $disabled_date;
31 31
 			continue;
32 32
 		}
33 33
 
34
-		$disabled_date   = explode( '|', $disabled_date );
34
+		$disabled_date   = explode('|', $disabled_date);
35 35
 		$disable_dates[] = array(
36
-			'from' => trim( $disabled_date[0] ),
37
-			'to'   => trim( $disabled_date[1] ),
36
+			'from' => trim($disabled_date[0]),
37
+			'to'   => trim($disabled_date[1]),
38 38
 		);
39 39
 
40 40
 	}
@@ -42,28 +42,28 @@  discard block
 block discarded – undo
42 42
 }
43 43
 
44 44
 $options = array(
45
-	'data-default-date' => empty( 'default_date' ) ? false : $default_date,
46
-	'data-min-date'     => empty( 'min_date' ) ? false : $min_date,
47
-	'data-max-date'     => empty( 'max_date' ) ? false : $max_date,
48
-	'data-mode'         => empty( 'mode' ) ? 'single' : $mode,
49
-	'data-alt-format'   => get_option( 'date_format', 'F j, Y' ),
45
+	'data-default-date' => empty('default_date') ? false : $default_date,
46
+	'data-min-date'     => empty('min_date') ? false : $min_date,
47
+	'data-max-date'     => empty('max_date') ? false : $max_date,
48
+	'data-mode'         => empty('mode') ? 'single' : $mode,
49
+	'data-alt-format'   => get_option('date_format', 'F j, Y'),
50 50
 	'data-date-format'  => 'Y-m-d',
51 51
 	'data-alt-input'    => 'true',
52
-	'data-disable_alt'  => empty( $disabled_dates ) ? false : wp_json_encode( $disable_dates ),
53
-	'data-disable_days_alt'  => empty( $disable_days ) ? false : wp_json_encode( wp_parse_id_list( $disable_days ) ),
52
+	'data-disable_alt'  => empty($disabled_dates) ? false : wp_json_encode($disable_dates),
53
+	'data-disable_days_alt'  => empty($disable_days) ? false : wp_json_encode(wp_parse_id_list($disable_days)),
54 54
 );
55 55
 
56 56
 echo aui()->input(
57 57
 	array(
58
-		'name'             => esc_attr( $id ),
59
-		'id'               => esc_attr( $id ) . uniqid( '_' ),
60
-		'placeholder'      => empty( $placeholder ) ? '' : esc_attr( $placeholder ),
61
-		'required'         => ! empty( $required ),
58
+		'name'             => esc_attr($id),
59
+		'id'               => esc_attr($id) . uniqid('_'),
60
+		'placeholder'      => empty($placeholder) ? '' : esc_attr($placeholder),
61
+		'required'         => !empty($required),
62 62
 		'label'            => $label,
63 63
 		'label_type'       => 'vertical',
64
-		'help_text'        => empty( $description ) ? '' : wp_kses_post( $description ),
64
+		'help_text'        => empty($description) ? '' : wp_kses_post($description),
65 65
 		'type'             => 'datepicker',
66 66
 		'class'            => $label_class . ' getpaid-init-flatpickr flatpickr-input',
67
-		'extra_attributes' => array_filter( apply_filters( 'getpaid_date_field_attributes', $options ) ),
67
+		'extra_attributes' => array_filter(apply_filters('getpaid_date_field_attributes', $options)),
68 68
 	)
69 69
 );
Please login to merge, or discard this patch.
templates/payment-forms-admin/edit/date.php 1 patch
Spacing   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -7,104 +7,104 @@
 block discarded – undo
7 7
  * @version 1.0.19
8 8
  */
9 9
 
10
-defined( 'ABSPATH' ) || exit;
10
+defined('ABSPATH') || exit;
11 11
 
12 12
 ?>
13 13
 
14 14
 <div class='form-group'>
15 15
 	<label class="d-block">
16
-		<span><?php esc_html_e( 'Field Label', 'invoicing' ); ?></span>
16
+		<span><?php esc_html_e('Field Label', 'invoicing'); ?></span>
17 17
 		<input v-model='active_form_element.label' class='form-control' type="text"/>
18 18
 	</label>
19 19
 </div>
20 20
 
21 21
 <div class='form-group'>
22 22
 	<label class="d-block">
23
-		<span><?php esc_html_e( 'Default Date', 'invoicing' ); ?></span>
24
-		<?php echo wpi_help_tip( sprintf( __( 'You can enter the shortcut "today" or enter a date matching the format Y-m-d, e.g %s', 'invoicing' ), current_time( 'Y-m-d' ) ), false, true ); ?>
25
-		<input v-model='active_form_element.default_date' placeholder="<?php esc_attr_e( 'None', 'invoicing' ); ?>" class='form-control' type="text"/>
23
+		<span><?php esc_html_e('Default Date', 'invoicing'); ?></span>
24
+		<?php echo wpi_help_tip(sprintf(__('You can enter the shortcut "today" or enter a date matching the format Y-m-d, e.g %s', 'invoicing'), current_time('Y-m-d')), false, true); ?>
25
+		<input v-model='active_form_element.default_date' placeholder="<?php esc_attr_e('None', 'invoicing'); ?>" class='form-control' type="text"/>
26 26
 	</label>
27 27
 </div>
28 28
 
29 29
 <div class='form-group'>
30 30
 	<label class="d-block">
31
-		<span><?php esc_html_e( 'Minimum Date', 'invoicing' ); ?></span>
32
-		<?php echo wpi_help_tip( sprintf( __( 'You can enter the shortcut "today" or enter a date matching the format Y-m-d, e.g %s', 'invoicing' ), current_time( 'Y-m-d' ) ), false, true ); ?>
33
-		<input v-model='active_form_element.min_date' placeholder="<?php esc_attr_e( 'None', 'invoicing' ); ?>" class='form-control' type="text"/>
34
-		<small class="form-text text-muted"><?php _e( 'Specify the minimum/earliest date (inclusively) allowed for selection.', 'invoicing' ); ?></small>
31
+		<span><?php esc_html_e('Minimum Date', 'invoicing'); ?></span>
32
+		<?php echo wpi_help_tip(sprintf(__('You can enter the shortcut "today" or enter a date matching the format Y-m-d, e.g %s', 'invoicing'), current_time('Y-m-d')), false, true); ?>
33
+		<input v-model='active_form_element.min_date' placeholder="<?php esc_attr_e('None', 'invoicing'); ?>" class='form-control' type="text"/>
34
+		<small class="form-text text-muted"><?php _e('Specify the minimum/earliest date (inclusively) allowed for selection.', 'invoicing'); ?></small>
35 35
 	</label>
36 36
 </div>
37 37
 
38 38
 <div class='form-group'>
39 39
 	<label class="d-block">
40
-		<span><?php esc_html_e( 'Maximum Date', 'invoicing' ); ?></span>
41
-		<?php echo wpi_help_tip( sprintf( __( 'You can enter the shortcut "today" or enter a date matching the format Y-m-d, e.g %s', 'invoicing' ), current_time( 'Y-m-d' ) ), false, true ); ?>
42
-		<input v-model='active_form_element.max_date' placeholder="<?php esc_attr_e( 'None', 'invoicing' ); ?>" class='form-control' type="text"/>
43
-		<small class="form-text text-muted"><?php _e( 'Specify the maximum/latest date (inclusively) allowed for selection.', 'invoicing' ); ?></small>
40
+		<span><?php esc_html_e('Maximum Date', 'invoicing'); ?></span>
41
+		<?php echo wpi_help_tip(sprintf(__('You can enter the shortcut "today" or enter a date matching the format Y-m-d, e.g %s', 'invoicing'), current_time('Y-m-d')), false, true); ?>
42
+		<input v-model='active_form_element.max_date' placeholder="<?php esc_attr_e('None', 'invoicing'); ?>" class='form-control' type="text"/>
43
+		<small class="form-text text-muted"><?php _e('Specify the maximum/latest date (inclusively) allowed for selection.', 'invoicing'); ?></small>
44 44
 	</label>
45 45
 </div>
46 46
 
47 47
 <div class='form-group'>
48 48
 	<label class="d-block">
49
-		<span><?php esc_html_e( 'Disabled Dates', 'invoicing' ); ?></span>
50
-		<?php echo wpi_help_tip( sprintf( __( 'You can use the shortcut "today" or enter dates matching the format Y-m-d, e.g %s', 'invoicing' ), current_time( 'Y-m-d' ) ), false, true ); ?>
51
-		<input v-model='active_form_element.disabled_dates' placeholder="<?php echo esc_attr( sprintf( __( 'For example, %s', 'invoicing' ), 'today,2025-04-01|2025-05-01,2025-09-01|2025-12-01' ) ); ?>" class='form-control' type="text"/>
52
-		<small class="form-text text-muted"><?php _e( 'Specify the dates to ignore. Use commas to separate dates and "|" to separate date ranges.', 'invoicing' ); ?></small>
49
+		<span><?php esc_html_e('Disabled Dates', 'invoicing'); ?></span>
50
+		<?php echo wpi_help_tip(sprintf(__('You can use the shortcut "today" or enter dates matching the format Y-m-d, e.g %s', 'invoicing'), current_time('Y-m-d')), false, true); ?>
51
+		<input v-model='active_form_element.disabled_dates' placeholder="<?php echo esc_attr(sprintf(__('For example, %s', 'invoicing'), 'today,2025-04-01|2025-05-01,2025-09-01|2025-12-01')); ?>" class='form-control' type="text"/>
52
+		<small class="form-text text-muted"><?php _e('Specify the dates to ignore. Use commas to separate dates and "|" to separate date ranges.', 'invoicing'); ?></small>
53 53
 	</label>
54 54
 </div>
55 55
 
56 56
 <div class='form-group'>
57 57
 	<label class="d-block">
58
-		<span><?php esc_html_e( 'Disable Days', 'invoicing' ) ?></span>
58
+		<span><?php esc_html_e('Disable Days', 'invoicing') ?></span>
59 59
 		<gpselect2 class='form-control custom-select' v-model='active_form_element.disable_days' multiple>
60
-			<option value='0'><?php esc_html_e( 'Sundays', 'invoicing' ); ?></option>
61
-			<option value='1'><?php esc_html_e( 'Mondays', 'invoicing' ); ?></option>
62
-			<option value='2'><?php esc_html_e( 'Tuesdays', 'invoicing' ); ?></option>
63
-			<option value='3'><?php esc_html_e( 'Wednesdays', 'invoicing' ); ?></option>
64
-			<option value='4'><?php esc_html_e( 'Thursdays', 'invoicing' ); ?></option>
65
-			<option value='5'><?php esc_html_e( 'Fridays', 'invoicing' ); ?></option>
66
-			<option value='6'><?php esc_html_e( 'Saturdays', 'invoicing' ); ?></option>
60
+			<option value='0'><?php esc_html_e('Sundays', 'invoicing'); ?></option>
61
+			<option value='1'><?php esc_html_e('Mondays', 'invoicing'); ?></option>
62
+			<option value='2'><?php esc_html_e('Tuesdays', 'invoicing'); ?></option>
63
+			<option value='3'><?php esc_html_e('Wednesdays', 'invoicing'); ?></option>
64
+			<option value='4'><?php esc_html_e('Thursdays', 'invoicing'); ?></option>
65
+			<option value='5'><?php esc_html_e('Fridays', 'invoicing'); ?></option>
66
+			<option value='6'><?php esc_html_e('Saturdays', 'invoicing'); ?></option>
67 67
 		</gpselect2>
68
-		<small class="form-text text-muted"><?php _e( 'Optionally specify the days of the week to disable.', 'invoicing' ); ?></small>
68
+		<small class="form-text text-muted"><?php _e('Optionally specify the days of the week to disable.', 'invoicing'); ?></small>
69 69
 	</label>
70 70
 </div>
71 71
 
72 72
 <div class='form-group'>
73 73
 	<label class="d-block">
74
-		<span><?php esc_html_e( 'Mode', 'invoicing' ) ?></span>
74
+		<span><?php esc_html_e('Mode', 'invoicing') ?></span>
75 75
 		<select class='form-control custom-select' v-model='active_form_element.mode'>
76
-			<option value='single'><?php esc_html_e( 'Users can only select a single date', 'invoicing' ); ?></option>
77
-			<option value='range'><?php esc_html_e( 'Users can select a date range', 'invoicing' ); ?></option>
78
-			<option value='multiple'><?php esc_html_e( 'Users can select multiple dates', 'invoicing' ); ?></option>
76
+			<option value='single'><?php esc_html_e('Users can only select a single date', 'invoicing'); ?></option>
77
+			<option value='range'><?php esc_html_e('Users can select a date range', 'invoicing'); ?></option>
78
+			<option value='multiple'><?php esc_html_e('Users can select multiple dates', 'invoicing'); ?></option>
79 79
 		</select>
80 80
 	</label>
81 81
 </div>
82 82
 
83 83
 <div class='form-group'>
84 84
 	<label class="d-block">
85
-		<span><?php esc_html_e( 'Help Text', 'invoicing' ); ?></span>
86
-		<textarea placeholder='<?php esc_attr_e( 'Add some help text for this field', 'invoicing' ); ?>' v-model='active_form_element.description' class='form-control' rows='3'></textarea>
87
-		<small class="form-text text-muted"><?php _e( 'HTML is allowed', 'invoicing' ); ?></small>
85
+		<span><?php esc_html_e('Help Text', 'invoicing'); ?></span>
86
+		<textarea placeholder='<?php esc_attr_e('Add some help text for this field', 'invoicing'); ?>' v-model='active_form_element.description' class='form-control' rows='3'></textarea>
87
+		<small class="form-text text-muted"><?php _e('HTML is allowed', 'invoicing'); ?></small>
88 88
 	</label>
89 89
 </div>
90 90
 
91 91
 <div class='form-group form-check'>
92 92
 	<input :id="active_form_element.id + '_edit'" v-model='active_form_element.required' type='checkbox' class='form-check-input' />
93
-	<label class='form-check-label' :for="active_form_element.id + '_edit'"><?php esc_html_e( 'Is this field required?', 'invoicing' ); ?></label>
93
+	<label class='form-check-label' :for="active_form_element.id + '_edit'"><?php esc_html_e('Is this field required?', 'invoicing'); ?></label>
94 94
 </div>
95 95
 
96 96
 <div class='form-group form-check'>
97 97
 	<input :id="active_form_element.id + '_add_meta'" v-model='active_form_element.add_meta' type='checkbox' class='form-check-input' />
98
-	<label class='form-check-label' :for="active_form_element.id + '_add_meta'"><?php esc_html_e( 'Show this field in receipts and emails?', 'invoicing' ); ?></label>
98
+	<label class='form-check-label' :for="active_form_element.id + '_add_meta'"><?php esc_html_e('Show this field in receipts and emails?', 'invoicing'); ?></label>
99 99
 </div>
100 100
 
101 101
 <hr class='featurette-divider mt-4'>
102 102
 
103 103
 <div class='form-group'>
104 104
 	<label class="d-block">
105
-		<span><?php esc_html_e( 'Email Merge Tag', 'invoicing' ); ?></span>
105
+		<span><?php esc_html_e('Email Merge Tag', 'invoicing'); ?></span>
106 106
 		<input :value='active_form_element.label | formatMergeTag' class='form-control bg-white' type="text" readonly onclick="this.select()" />
107
-		<span class="form-text text-muted"><?php esc_html_e( 'You can use this merge tag in notification emails', 'invoicing' ); ?></span>
107
+		<span class="form-text text-muted"><?php esc_html_e('You can use this merge tag in notification emails', 'invoicing'); ?></span>
108 108
 	</label>
109 109
 </div>
110 110
 
Please login to merge, or discard this patch.
includes/admin/class-wpinv-admin-menus.php 1 patch
Spacing   +82 added lines, -82 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
  * Setup menus in WP admin.
4 4
  */
5 5
 
6
-defined( 'ABSPATH' ) || exit;
6
+defined('ABSPATH') || exit;
7 7
 
8 8
 /**
9 9
  * WC_Admin_Menus Class.
@@ -13,14 +13,14 @@  discard block
 block discarded – undo
13 13
      * Hook in tabs.
14 14
      */
15 15
     public function __construct() {
16
-        add_action( 'admin_head', array( $this, 'set_admin_menu_class' ) );
17
-        add_action( 'admin_menu', array( $this, 'admin_menu' ), 10 );
18
-        add_action( 'admin_menu', array( $this, 'add_customers_menu' ), 18 );
19
-        add_action( 'admin_menu', array( $this, 'add_subscriptions_menu' ), 40 );
20
-        add_action( 'admin_menu', array( $this, 'add_addons_menu' ), 100 );
21
-        add_action( 'admin_menu', array( $this, 'add_settings_menu' ), 60 );
22
-        add_action( 'admin_menu', array( $this, 'remove_admin_submenus' ), 10 );
23
-        add_action( 'admin_head-nav-menus.php', array( $this, 'add_nav_menu_meta_boxes' ) );
16
+        add_action('admin_head', array($this, 'set_admin_menu_class'));
17
+        add_action('admin_menu', array($this, 'admin_menu'), 10);
18
+        add_action('admin_menu', array($this, 'add_customers_menu'), 18);
19
+        add_action('admin_menu', array($this, 'add_subscriptions_menu'), 40);
20
+        add_action('admin_menu', array($this, 'add_addons_menu'), 100);
21
+        add_action('admin_menu', array($this, 'add_settings_menu'), 60);
22
+        add_action('admin_menu', array($this, 'remove_admin_submenus'), 10);
23
+        add_action('admin_head-nav-menus.php', array($this, 'add_nav_menu_meta_boxes'));
24 24
     }
25 25
 
26 26
     /**
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
 	public function set_admin_menu_class() {
30 30
 		global $current_screen, $parent_file, $submenu_file;
31 31
 
32
-        if ( ! empty( $current_screen->id ) && in_array( $current_screen->id , array( 'wpi_discount', 'wpi_payment_form', 'wpi_invoice' ) ) ) {
32
+        if (!empty($current_screen->id) && in_array($current_screen->id, array('wpi_discount', 'wpi_payment_form', 'wpi_invoice'))) {
33 33
 			$parent_file = 'wpinv';
34 34
 			$submenu_file = 'edit.php?post_type=' . $current_screen->id;
35 35
         }
@@ -38,14 +38,14 @@  discard block
 block discarded – undo
38 38
 
39 39
     public function admin_menu() {
40 40
 
41
-        $capability = apply_filters( 'invoicing_capability', wpinv_get_capability() );
41
+        $capability = apply_filters('invoicing_capability', wpinv_get_capability());
42 42
         add_menu_page(
43
-            __( 'GetPaid', 'invoicing' ),
44
-            __( 'GetPaid', 'invoicing' ),
43
+            __('GetPaid', 'invoicing'),
44
+            __('GetPaid', 'invoicing'),
45 45
             $capability,
46 46
             'wpinv',
47 47
             null,
48
-            'data:image/svg+xml;base64,' . base64_encode( file_get_contents( WPINV_PLUGIN_DIR . 'assets/images/GetPaid.svg' ) ),
48
+            'data:image/svg+xml;base64,' . base64_encode(file_get_contents(WPINV_PLUGIN_DIR . 'assets/images/GetPaid.svg')),
49 49
             '54.123460'
50 50
         );
51 51
 
@@ -57,11 +57,11 @@  discard block
 block discarded – undo
57 57
     public function add_customers_menu() {
58 58
         add_submenu_page(
59 59
             'wpinv',
60
-            __( 'Customers', 'invoicing' ),
61
-            __( 'Customers', 'invoicing' ),
60
+            __('Customers', 'invoicing'),
61
+            __('Customers', 'invoicing'),
62 62
             wpinv_get_capability(),
63 63
             'wpinv-customers',
64
-            array( $this, 'customers_page' )
64
+            array($this, 'customers_page')
65 65
         );
66 66
     }
67 67
 
@@ -71,8 +71,8 @@  discard block
 block discarded – undo
71 71
     public function add_subscriptions_menu() {
72 72
         add_submenu_page(
73 73
             'wpinv',
74
-            __( 'Subscriptions', 'invoicing' ),
75
-            __( 'Subscriptions', 'invoicing' ),
74
+            __('Subscriptions', 'invoicing'),
75
+            __('Subscriptions', 'invoicing'),
76 76
             wpinv_get_capability(),
77 77
             'wpinv-subscriptions',
78 78
             'wpinv_subscriptions_page'
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
      * Displays the customers page.
84 84
      */
85 85
     public function customers_page() {
86
-        require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-customers-table.php' );
86
+        require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-customers-table.php');
87 87
         ?>
88 88
         <div class="wrap wpi-customers-wrap">
89 89
             <style>
@@ -91,12 +91,12 @@  discard block
 block discarded – undo
91 91
                     width: 30%;
92 92
                 }
93 93
             </style>
94
-            <h1><?php echo esc_html( __( 'Customers', 'invoicing' ) ); ?>&nbsp;<a href="<?php echo wp_nonce_url( add_query_arg( 'getpaid-admin-action', 'download_customers' ), 'getpaid-nonce', 'getpaid-nonce' ); ?>" class="page-title-action"><?php _e( 'Export', 'invoicing' ); ?></a></h1>
94
+            <h1><?php echo esc_html(__('Customers', 'invoicing')); ?>&nbsp;<a href="<?php echo wp_nonce_url(add_query_arg('getpaid-admin-action', 'download_customers'), 'getpaid-nonce', 'getpaid-nonce'); ?>" class="page-title-action"><?php _e('Export', 'invoicing'); ?></a></h1>
95 95
             <form method="post">
96 96
             <?php
97 97
                 $table = new WPInv_Customers_Table();
98 98
                 $table->prepare_items();
99
-                $table->search_box( __( 'Search Customers', 'invoicing' ), 'search-customers' );
99
+                $table->search_box(__('Search Customers', 'invoicing'), 'search-customers');
100 100
                 $table->display();
101 101
             ?>
102 102
             </form>
@@ -110,16 +110,16 @@  discard block
 block discarded – undo
110 110
     public function add_settings_menu() {
111 111
         add_submenu_page(
112 112
             'wpinv',
113
-            __( 'Invoice Settings', 'invoicing' ),
114
-            __( 'Settings', 'invoicing' ),
115
-            apply_filters( 'invoicing_capability', wpinv_get_capability() ),
113
+            __('Invoice Settings', 'invoicing'),
114
+            __('Settings', 'invoicing'),
115
+            apply_filters('invoicing_capability', wpinv_get_capability()),
116 116
             'wpinv-settings',
117
-            array( $this, 'options_page' )
117
+            array($this, 'options_page')
118 118
         );
119 119
     }
120 120
 
121
-    public function add_addons_menu(){
122
-        if ( !apply_filters( 'wpi_show_addons_page', true ) ) {
121
+    public function add_addons_menu() {
122
+        if (!apply_filters('wpi_show_addons_page', true)) {
123 123
             return;
124 124
         }
125 125
 
@@ -129,78 +129,78 @@  discard block
 block discarded – undo
129 129
             __('Extensions', 'invoicing'),
130 130
             'manage_options',
131 131
             'wpi-addons',
132
-            array( $this, 'addons_page' )
132
+            array($this, 'addons_page')
133 133
         );
134 134
     }
135 135
 
136
-    public function addons_page(){
136
+    public function addons_page() {
137 137
         $addon_obj = new WPInv_Admin_Addons();
138 138
         $addon_obj->output();
139 139
     }
140 140
 
141 141
     function options_page() {
142 142
 
143
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
143
+        if (!wpinv_current_user_can_manage_invoicing()) {
144 144
             return;
145 145
         }
146 146
 
147 147
         $settings_tabs = wpinv_get_settings_tabs();
148 148
         $settings_tabs = empty($settings_tabs) ? array() : $settings_tabs;
149
-        $active_tab    = isset( $_GET['tab'] ) && array_key_exists( $_GET['tab'], $settings_tabs ) ? esc_html( $_GET['tab'] ) : 'general';
150
-        $sections      = wpinv_get_settings_tab_sections( $active_tab );
149
+        $active_tab    = isset($_GET['tab']) && array_key_exists($_GET['tab'], $settings_tabs) ? esc_html($_GET['tab']) : 'general';
150
+        $sections      = wpinv_get_settings_tab_sections($active_tab);
151 151
         $key           = 'main';
152 152
 
153
-        if ( is_array( $sections ) ) {
154
-            $key = key( $sections );
153
+        if (is_array($sections)) {
154
+            $key = key($sections);
155 155
         }
156 156
 
157 157
         add_thickbox();
158 158
 
159
-        $registered_sections = wpinv_get_settings_tab_sections( $active_tab );
160
-        $section             = isset( $_GET['section'] ) && ! empty( $registered_sections ) && array_key_exists( $_GET['section'], $registered_sections ) ? $_GET['section'] : $key;
159
+        $registered_sections = wpinv_get_settings_tab_sections($active_tab);
160
+        $section             = isset($_GET['section']) && !empty($registered_sections) && array_key_exists($_GET['section'], $registered_sections) ? $_GET['section'] : $key;
161 161
         ?>
162 162
         <div class="wrap">
163 163
             <h1 class="nav-tab-wrapper">
164 164
                 <?php
165
-                foreach( wpinv_get_settings_tabs() as $tab_id => $tab_name ) {
166
-                    $tab_url = add_query_arg( array(
165
+                foreach (wpinv_get_settings_tabs() as $tab_id => $tab_name) {
166
+                    $tab_url = add_query_arg(array(
167 167
                         'settings-updated' => false,
168 168
                         'tab' => $tab_id,
169
-                    ), 'admin.php?page=wpinv-settings' );
169
+                    ), 'admin.php?page=wpinv-settings');
170 170
 
171 171
                     // Remove the section from the tabs so we always end up at the main section
172
-                    $tab_url = remove_query_arg( 'section', $tab_url );
173
-                    $tab_url = remove_query_arg( 'wpi_sub', $tab_url );
172
+                    $tab_url = remove_query_arg('section', $tab_url);
173
+                    $tab_url = remove_query_arg('wpi_sub', $tab_url);
174 174
 
175 175
                     $active = $active_tab == $tab_id ? ' nav-tab-active' : '';
176 176
 
177
-                    echo '<a href="' . esc_url( $tab_url ) . '" title="' . esc_attr( $tab_name ) . '" class="nav-tab' . $active . '">';
178
-                    echo esc_html( $tab_name );
177
+                    echo '<a href="' . esc_url($tab_url) . '" title="' . esc_attr($tab_name) . '" class="nav-tab' . $active . '">';
178
+                    echo esc_html($tab_name);
179 179
                     echo '</a>';
180 180
                 }
181 181
                 ?>
182 182
             </h1>
183 183
             <?php
184
-            $number_of_sections = count( $sections );
184
+            $number_of_sections = count($sections);
185 185
             $number = 0;
186
-            if ( $number_of_sections > 1 ) {
186
+            if ($number_of_sections > 1) {
187 187
                 echo '<div><ul class="subsubsub">';
188
-                foreach( $sections as $section_id => $section_name ) {
188
+                foreach ($sections as $section_id => $section_name) {
189 189
                     echo '<li>';
190 190
                     $number++;
191
-                    $tab_url = add_query_arg( array(
191
+                    $tab_url = add_query_arg(array(
192 192
                         'settings-updated' => false,
193 193
                         'tab' => $active_tab,
194 194
                         'section' => $section_id
195
-                    ), admin_url( 'admin.php?page=wpinv-settings' ) );
196
-                    $tab_url = remove_query_arg( 'wpi_sub', $tab_url );
195
+                    ), admin_url('admin.php?page=wpinv-settings'));
196
+                    $tab_url = remove_query_arg('wpi_sub', $tab_url);
197 197
                     $class = '';
198
-                    if ( $section == $section_id ) {
198
+                    if ($section == $section_id) {
199 199
                         $class = 'current';
200 200
                     }
201
-                    echo '<a class="' . $class . '" href="' . esc_url( $tab_url ) . '">' . $section_name . '</a>';
201
+                    echo '<a class="' . $class . '" href="' . esc_url($tab_url) . '">' . $section_name . '</a>';
202 202
 
203
-                    if ( $number != $number_of_sections ) {
203
+                    if ($number != $number_of_sections) {
204 204
                         echo ' | ';
205 205
                     }
206 206
                     echo '</li>';
@@ -212,20 +212,20 @@  discard block
 block discarded – undo
212 212
                 <form method="post" action="options.php">
213 213
                     <table class="form-table">
214 214
                         <?php
215
-                        settings_fields( 'wpinv_settings' );
215
+                        settings_fields('wpinv_settings');
216 216
 
217
-                        if ( 'main' === $section ) {
218
-                            do_action( 'wpinv_settings_tab_top', $active_tab );
217
+                        if ('main' === $section) {
218
+                            do_action('wpinv_settings_tab_top', $active_tab);
219 219
                         }
220 220
 
221
-                        do_action( 'wpinv_settings_tab_top_' . $active_tab . '_' . $section, $active_tab, $section );
222
-                        do_settings_sections( 'wpinv_settings_' . $active_tab . '_' . $section, $active_tab, $section );
223
-                        do_action( 'wpinv_settings_tab_bottom_' . $active_tab . '_' . $section, $active_tab, $section );
224
-                        do_action( 'getpaid_settings_tab_bottom', $active_tab, $section );
221
+                        do_action('wpinv_settings_tab_top_' . $active_tab . '_' . $section, $active_tab, $section);
222
+                        do_settings_sections('wpinv_settings_' . $active_tab . '_' . $section, $active_tab, $section);
223
+                        do_action('wpinv_settings_tab_bottom_' . $active_tab . '_' . $section, $active_tab, $section);
224
+                        do_action('getpaid_settings_tab_bottom', $active_tab, $section);
225 225
 
226 226
                         // For backwards compatibility
227
-                        if ( 'main' === $section ) {
228
-                            do_action( 'wpinv_settings_tab_bottom', $active_tab );
227
+                        if ('main' === $section) {
228
+                            do_action('wpinv_settings_tab_bottom', $active_tab);
229 229
                         }
230 230
                         ?>
231 231
                     </table>
@@ -237,7 +237,7 @@  discard block
 block discarded – undo
237 237
     }
238 238
 
239 239
     public function remove_admin_submenus() {
240
-        remove_submenu_page( 'edit.php?post_type=wpi_invoice', 'post-new.php?post_type=wpi_invoice' );
240
+        remove_submenu_page('edit.php?post_type=wpi_invoice', 'post-new.php?post_type=wpi_invoice');
241 241
     }
242 242
 
243 243
     /**
@@ -247,8 +247,8 @@  discard block
 block discarded – undo
247 247
 
248 248
         add_meta_box(
249 249
             'wpinv_endpoints_nav_link',
250
-            __( 'GetPaid endpoints', 'invoicing' ),
251
-            array( $this, 'nav_menu_links' ),
250
+            __('GetPaid endpoints', 'invoicing'),
251
+            array($this, 'nav_menu_links'),
252 252
             'nav-menus',
253 253
             'side',
254 254
             'low'
@@ -263,12 +263,12 @@  discard block
 block discarded – undo
263 263
         $endpoints = $this->get_menu_items();
264 264
         ?>
265 265
         <div id="invoicing-endpoints" class="posttypediv">
266
-            <?php if ( ! empty( $endpoints['pages'] ) ) : ?>
266
+            <?php if (!empty($endpoints['pages'])) : ?>
267 267
                 <div id="tabs-panel-invoicing-endpoints" class="tabs-panel tabs-panel-active">
268 268
                     <ul id="invoicing-endpoints-checklist" class="categorychecklist form-no-clear">
269 269
                         <?php
270
-                            $walker = new Walker_Nav_Menu_Checklist( array() );
271
-                            echo walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', $endpoints['pages'] ), 0, (object) array( 'walker' => $walker ) );
270
+                            $walker = new Walker_Nav_Menu_Checklist(array());
271
+                            echo walk_nav_menu_tree(array_map('wp_setup_nav_menu_item', $endpoints['pages']), 0, (object) array('walker' => $walker));
272 272
                         ?>
273 273
                     </ul>
274 274
                 </div>
@@ -277,11 +277,11 @@  discard block
 block discarded – undo
277 277
             <p class="button-controls wp-clearfix" data-items-type="invoicing-endpoints">
278 278
                 <span class="list-controls hide-if-no-js">
279 279
                     <input type="checkbox" id="invoicing-endpoints-tab" class="select-all">
280
-                    <label for="invoicing-endpoints-tab"><?php _e( 'Select all', 'invoicing' ); ?></label>
280
+                    <label for="invoicing-endpoints-tab"><?php _e('Select all', 'invoicing'); ?></label>
281 281
                 </span>
282 282
 
283 283
                 <span class="add-to-menu">
284
-                    <input type="submit" class="button submit-add-to-menu right" value="<?php esc_attr_e( 'Add to menu', 'invoicing' ); ?>" name="add-invoicing-endpoints-item" id="submit-invoicing-endpoints">
284
+                    <input type="submit" class="button submit-add-to-menu right" value="<?php esc_attr_e('Add to menu', 'invoicing'); ?>" name="add-invoicing-endpoints-item" id="submit-invoicing-endpoints">
285 285
                     <span class="spinner"></span>
286 286
                 </span>
287 287
             </p>
@@ -294,35 +294,35 @@  discard block
 block discarded – undo
294 294
      *
295 295
      * @return array.
296 296
      */
297
-    public function get_menu_items(){
297
+    public function get_menu_items() {
298 298
         $items = array();
299 299
 
300 300
         $pages = array(
301 301
             array(
302
-                'id'    => wpinv_get_option( 'invoice_history_page' ),
303
-                'label' => __( 'My Invoices', 'invoicing' ),
302
+                'id'    => wpinv_get_option('invoice_history_page'),
303
+                'label' => __('My Invoices', 'invoicing'),
304 304
             ),
305 305
             array(
306
-                'id'    => wpinv_get_option( 'invoice_subscription_page' ),
307
-                'label' => __( 'My Subscriptions', 'invoicing' ),
306
+                'id'    => wpinv_get_option('invoice_subscription_page'),
307
+                'label' => __('My Subscriptions', 'invoicing'),
308 308
             )
309 309
         );
310 310
 
311
-        foreach ( apply_filters( 'getpaid_menu_pages', $pages ) as $page ) {
311
+        foreach (apply_filters('getpaid_menu_pages', $pages) as $page) {
312 312
 
313
-            if ( (int) $page['id'] > 0 ) {
313
+            if ((int) $page['id'] > 0) {
314 314
 
315 315
                 $item                   = new stdClass();
316 316
                 $item->object_id        = (int) $page['id'];
317 317
                 $item->db_id            = 0;
318
-                $item->object           =  'page';
318
+                $item->object           = 'page';
319 319
                 $item->menu_item_parent = 0;
320 320
                 $item->type             = 'post_type';
321
-                $item->title            = esc_html( $page['label'] );
322
-                $item->url              = get_permalink( (int) $page['id'] );
321
+                $item->title            = esc_html($page['label']);
322
+                $item->url              = get_permalink((int) $page['id']);
323 323
                 $item->target           = '';
324 324
                 $item->attr_title       = '';
325
-                $item->classes          = array( 'wpinv-menu-item' );
325
+                $item->classes          = array('wpinv-menu-item');
326 326
                 $item->xfn              = '';
327 327
 
328 328
                 $items['pages'][]       = $item;
@@ -331,7 +331,7 @@  discard block
 block discarded – undo
331 331
 
332 332
         }
333 333
 
334
-        return apply_filters( 'wpinv_menu_items', $items );
334
+        return apply_filters('wpinv_menu_items', $items);
335 335
     }
336 336
 
337 337
 }
Please login to merge, or discard this patch.
templates/invoice/line-totals.php 1 patch
Spacing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -9,26 +9,26 @@  discard block
 block discarded – undo
9 9
  * @var WPInv_Invoice $invoice
10 10
  */
11 11
 
12
-defined( 'ABSPATH' ) || exit;
12
+defined('ABSPATH') || exit;
13 13
 
14 14
 // Totals rows.
15
-$totals = getpaid_invoice_totals_rows( $invoice );
15
+$totals = getpaid_invoice_totals_rows($invoice);
16 16
 
17
-do_action( 'getpaid_before_invoice_line_totals', $invoice, $totals );
17
+do_action('getpaid_before_invoice_line_totals', $invoice, $totals);
18 18
 
19 19
 ?>
20 20
 <div class='getpaid-invoice-line-totals'>
21 21
     <div class="row">
22 22
         <div class="col-12 offset-sm-6 col-sm-6 border-sm-left pl-sm-0">
23 23
 
24
-            <?php foreach ( $totals as $key => $label ) : ?>
24
+            <?php foreach ($totals as $key => $label) : ?>
25 25
 
26
-                <div class="getpaid-invoice-line-totals-col <?php echo sanitize_html_class( $key ); ?>">
26
+                <div class="getpaid-invoice-line-totals-col <?php echo sanitize_html_class($key); ?>">
27 27
 
28 28
                     <div class="form-row">
29 29
 
30 30
                         <div class="col-8 getpaid-invoice-line-totals-label">
31
-                            <?php echo esc_html( $label ); ?>
31
+                            <?php echo esc_html($label); ?>
32 32
                         </div>
33 33
 
34 34
                         <div class="col-4 getpaid-invoice-line-totals-value pl-0">
@@ -36,15 +36,15 @@  discard block
 block discarded – undo
36 36
                             <?php
37 37
 
38 38
                                 // Total tax.
39
-                                if ( 'tax' == $key ) {
40
-                                    echo wpinv_price( $invoice->get_total_tax(), $invoice->get_currency() );
39
+                                if ('tax' == $key) {
40
+                                    echo wpinv_price($invoice->get_total_tax(), $invoice->get_currency());
41 41
 
42
-                                    if ( wpinv_use_taxes() && ! $invoice->get_disable_taxes() ) {
42
+                                    if (wpinv_use_taxes() && !$invoice->get_disable_taxes()) {
43 43
 
44 44
                                         $taxes = $invoice->get_total_tax();
45
-                                        if ( empty( $taxes ) && GetPaid_Payment_Form_Submission_Taxes::is_eu_transaction( $invoice->get_country() ) ) {
45
+                                        if (empty($taxes) && GetPaid_Payment_Form_Submission_Taxes::is_eu_transaction($invoice->get_country())) {
46 46
                                             echo ' <em class="text-muted small">';
47
-                                            _x( '(Reverse charged)','This is a legal term for reverse charging tax in the EU', 'invoicing' );
47
+                                            _x('(Reverse charged)', 'This is a legal term for reverse charging tax in the EU', 'invoicing');
48 48
                                             echo '</em>';
49 49
                                         }
50 50
 
@@ -53,32 +53,32 @@  discard block
 block discarded – undo
53 53
                                 }
54 54
 
55 55
                                 // Total Fee.
56
-                                if ( 'fee' == $key ) {
57
-                                    echo wpinv_price( $invoice->get_total_fees(), $invoice->get_currency() );
56
+                                if ('fee' == $key) {
57
+                                    echo wpinv_price($invoice->get_total_fees(), $invoice->get_currency());
58 58
                                 }
59 59
 
60 60
                                 // Total discount.
61
-                                if ( 'discount' == $key ) {
62
-                                    echo wpinv_price( $invoice->get_total_discount(), $invoice->get_currency() );
61
+                                if ('discount' == $key) {
62
+                                    echo wpinv_price($invoice->get_total_discount(), $invoice->get_currency());
63 63
                                 }
64 64
 
65 65
                                 // Shipping.
66
-                                if ( 'shipping' == $key ) {
67
-                                    echo wpinv_price( $invoice->get_shipping(), $invoice->get_currency() );
66
+                                if ('shipping' == $key) {
67
+                                    echo wpinv_price($invoice->get_shipping(), $invoice->get_currency());
68 68
                                 }
69 69
 
70 70
                                 // Sub total.
71
-                                if ( 'subtotal' == $key ) {
72
-                                    echo wpinv_price( $invoice->get_subtotal(), $invoice->get_currency() );
71
+                                if ('subtotal' == $key) {
72
+                                    echo wpinv_price($invoice->get_subtotal(), $invoice->get_currency());
73 73
                                 }
74 74
 
75 75
                                 // Total.
76
-                                if ( 'total' == $key ) {
77
-                                    echo wpinv_price( $invoice->get_total(), $invoice->get_currency() );
76
+                                if ('total' == $key) {
77
+                                    echo wpinv_price($invoice->get_total(), $invoice->get_currency());
78 78
                                 }
79 79
  
80 80
                                 // Fires when printing a cart total.
81
-                                do_action( "getpaid_invoice_cart_totals_$key", $invoice );
81
+                                do_action("getpaid_invoice_cart_totals_$key", $invoice);
82 82
 
83 83
                             ?>
84 84
 
@@ -92,4 +92,4 @@  discard block
 block discarded – undo
92 92
     </div>
93 93
 </div> <!-- end .getpaid-invoice-line-totals -->
94 94
 
95
-<?php do_action(  'getpaid_after_invoice_line_totals', $invoice, $totals ); ?>
95
+<?php do_action('getpaid_after_invoice_line_totals', $invoice, $totals); ?>
Please login to merge, or discard this patch.
includes/invoice-functions.php 1 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
  * @package Invoicing
7 7
  */
8 8
 
9
-defined( 'ABSPATH' ) || exit;
9
+defined('ABSPATH') || exit;
10 10
 
11 11
 /**
12 12
  * Retrieves the current invoice.
@@ -14,15 +14,15 @@  discard block
 block discarded – undo
14 14
 function getpaid_get_current_invoice_id() {
15 15
 
16 16
     // Ensure that we have an invoice key.
17
-    if ( empty( $_GET['invoice_key'] ) ) {
17
+    if (empty($_GET['invoice_key'])) {
18 18
         return 0;
19 19
     }
20 20
 
21 21
     // Retrieve an invoice using the key.
22
-    $invoice = new WPInv_Invoice( $_GET['invoice_key'] );
22
+    $invoice = new WPInv_Invoice($_GET['invoice_key']);
23 23
 
24 24
     // Compare the invoice key and the parsed key.
25
-    if ( $invoice->get_id() != 0 && $invoice->get_key() == $_GET['invoice_key'] ) {
25
+    if ($invoice->get_id() != 0 && $invoice->get_key() == $_GET['invoice_key']) {
26 26
         return $invoice->get_id();
27 27
     }
28 28
 
@@ -32,42 +32,42 @@  discard block
 block discarded – undo
32 32
 /**
33 33
  * Checks if the current user cna view an invoice.
34 34
  */
35
-function wpinv_user_can_view_invoice( $invoice ) {
36
-    $invoice = new WPInv_Invoice( $invoice );
35
+function wpinv_user_can_view_invoice($invoice) {
36
+    $invoice = new WPInv_Invoice($invoice);
37 37
 
38 38
     // Abort if the invoice does not exist.
39
-    if ( 0 == $invoice->get_id() ) {
39
+    if (0 == $invoice->get_id()) {
40 40
         return false;
41 41
     }
42 42
 
43 43
     // Don't allow trash, draft status
44
-    if ( $invoice->is_draft() ) {
44
+    if ($invoice->is_draft()) {
45 45
         return false;
46 46
     }
47 47
 
48 48
     // If users are not required to login to check out, compare the invoice keys.
49
-    if ( ! wpinv_require_login_to_checkout() && isset( $_GET['invoice_key'] ) && trim( $_GET['invoice_key'] ) == $invoice->get_key() ) {
49
+    if (!wpinv_require_login_to_checkout() && isset($_GET['invoice_key']) && trim($_GET['invoice_key']) == $invoice->get_key()) {
50 50
         return true;
51 51
     }
52 52
 
53 53
     // Always enable for admins..
54
-    if ( wpinv_current_user_can_manage_invoicing() || current_user_can( 'view_invoices', $invoice->get_id() ) ) { // Admin user
54
+    if (wpinv_current_user_can_manage_invoicing() || current_user_can('view_invoices', $invoice->get_id())) { // Admin user
55 55
         return true;
56 56
     }
57 57
 
58 58
     // Else, ensure that this is their invoice.
59
-    if ( is_user_logged_in() && $invoice->get_user_id() == get_current_user_id() ) {
59
+    if (is_user_logged_in() && $invoice->get_user_id() == get_current_user_id()) {
60 60
         return true;
61 61
     }
62 62
 
63
-    return apply_filters( 'wpinv_current_user_can_view_invoice', false, $invoice );
63
+    return apply_filters('wpinv_current_user_can_view_invoice', false, $invoice);
64 64
 }
65 65
 
66 66
 /**
67 67
  * Checks if the current user cna view an invoice receipt.
68 68
  */
69
-function wpinv_can_view_receipt( $invoice ) {
70
-	return (bool) apply_filters( 'wpinv_can_view_receipt', wpinv_user_can_view_invoice( $invoice ), $invoice );
69
+function wpinv_can_view_receipt($invoice) {
70
+	return (bool) apply_filters('wpinv_can_view_receipt', wpinv_user_can_view_invoice($invoice), $invoice);
71 71
 }
72 72
 
73 73
 /**
@@ -77,16 +77,16 @@  discard block
 block discarded – undo
77 77
  */
78 78
 function getpaid_get_invoice_post_types() {
79 79
     $post_types = array(
80
-        'wpi_quote'   => __( 'Quote', 'invoicing' ),
81
-        'wpi_invoice' => __( 'Invoice', 'invoicing' ),
80
+        'wpi_quote'   => __('Quote', 'invoicing'),
81
+        'wpi_invoice' => __('Invoice', 'invoicing'),
82 82
     );
83 83
 
84 84
     // Ensure the quotes addon is installed.
85
-    if ( ! defined( 'WPINV_QUOTES_VERSION' ) ) {
86
-        unset( $post_types['wpi_quote'] );
85
+    if (!defined('WPINV_QUOTES_VERSION')) {
86
+        unset($post_types['wpi_quote']);
87 87
     }
88 88
 
89
-    return apply_filters( 'getpaid_invoice_post_types', $post_types );
89
+    return apply_filters('getpaid_invoice_post_types', $post_types);
90 90
 }
91 91
 
92 92
 /**
@@ -95,8 +95,8 @@  discard block
 block discarded – undo
95 95
  *
96 96
  * @param string $post_type The post type to check for.
97 97
  */
98
-function getpaid_is_invoice_post_type( $post_type ) {
99
-    return is_scalar( $post_type ) && ! empty( $post_type ) && array_key_exists( $post_type, getpaid_get_invoice_post_types() );
98
+function getpaid_is_invoice_post_type($post_type) {
99
+    return is_scalar($post_type) && !empty($post_type) && array_key_exists($post_type, getpaid_get_invoice_post_types());
100 100
 }
101 101
 
102 102
 /**
@@ -106,9 +106,9 @@  discard block
 block discarded – undo
106 106
  * @param  bool  $wp_error       Whether to return false or WP_Error on failure.
107 107
  * @return int|WP_Error|WPInv_Invoice The value 0 or WP_Error on failure. The WPInv_Invoice object on success.
108 108
  */
109
-function wpinv_create_invoice( $data = array(), $deprecated = null, $wp_error = false ) {
110
-    $data[ 'invoice_id' ] = 0;
111
-    return wpinv_insert_invoice( $data, $wp_error );
109
+function wpinv_create_invoice($data = array(), $deprecated = null, $wp_error = false) {
110
+    $data['invoice_id'] = 0;
111
+    return wpinv_insert_invoice($data, $wp_error);
112 112
 }
113 113
 
114 114
 /**
@@ -118,36 +118,36 @@  discard block
 block discarded – undo
118 118
  * @param  bool  $wp_error       Whether to return false or WP_Error on failure.
119 119
  * @return int|WP_Error|WPInv_Invoice The value 0 or WP_Error on failure. The WPInv_Invoice object on success.
120 120
  */
121
-function wpinv_update_invoice( $data = array(), $wp_error = false ) {
121
+function wpinv_update_invoice($data = array(), $wp_error = false) {
122 122
 
123 123
     // Backwards compatibility.
124
-    if ( ! empty( $data['ID'] ) ) {
124
+    if (!empty($data['ID'])) {
125 125
         $data['invoice_id'] = $data['ID'];
126 126
     }
127 127
 
128 128
     // Do we have an invoice id?
129
-    if ( empty( $data['invoice_id'] ) ) {
130
-        return $wp_error ? new WP_Error( 'invalid_invoice_id', __( 'Invalid invoice ID.', 'invoicing' ) ) : 0;
129
+    if (empty($data['invoice_id'])) {
130
+        return $wp_error ? new WP_Error('invalid_invoice_id', __('Invalid invoice ID.', 'invoicing')) : 0;
131 131
     }
132 132
 
133 133
     // Retrieve the invoice.
134
-    $invoice = wpinv_get_invoice( $data['invoice_id'] );
134
+    $invoice = wpinv_get_invoice($data['invoice_id']);
135 135
 
136 136
     // And abort if it does not exist.
137
-    if ( empty( $invoice ) ) {
138
-        return $wp_error ? new WP_Error( 'missing_invoice', __( 'Invoice not found.', 'invoicing' ) ) : 0;
137
+    if (empty($invoice)) {
138
+        return $wp_error ? new WP_Error('missing_invoice', __('Invoice not found.', 'invoicing')) : 0;
139 139
     }
140 140
 
141 141
     // Do not update totals for paid / refunded invoices.
142
-    if ( $invoice->is_paid() || $invoice->is_refunded() ) {
142
+    if ($invoice->is_paid() || $invoice->is_refunded()) {
143 143
 
144
-        if ( ! empty( $data['items'] ) || ! empty( $data['cart_details'] ) ) {
145
-            return $wp_error ? new WP_Error( 'paid_invoice', __( 'You can not update cart items for invoices that have already been paid for.', 'invoicing' ) ) : 0;
144
+        if (!empty($data['items']) || !empty($data['cart_details'])) {
145
+            return $wp_error ? new WP_Error('paid_invoice', __('You can not update cart items for invoices that have already been paid for.', 'invoicing')) : 0;
146 146
         }
147 147
 
148 148
     }
149 149
 
150
-    return wpinv_insert_invoice( $data, $wp_error );
150
+    return wpinv_insert_invoice($data, $wp_error);
151 151
 
152 152
 }
153 153
 
@@ -158,34 +158,34 @@  discard block
 block discarded – undo
158 158
  * @param  bool  $wp_error       Whether to return false or WP_Error on failure.
159 159
  * @return int|WP_Error|WPInv_Invoice The value 0 or WP_Error on failure. The WPInv_Invoice object on success.
160 160
  */
161
-function wpinv_insert_invoice( $data = array(), $wp_error = false ) {
161
+function wpinv_insert_invoice($data = array(), $wp_error = false) {
162 162
 
163 163
     // Ensure that we have invoice data.
164
-    if ( empty( $data ) ) {
164
+    if (empty($data)) {
165 165
         return false;
166 166
     }
167 167
 
168 168
     // The invoice id will be provided when updating an invoice.
169
-    $data['invoice_id'] = ! empty( $data['invoice_id'] ) ? (int) $data['invoice_id'] : false;
169
+    $data['invoice_id'] = !empty($data['invoice_id']) ? (int) $data['invoice_id'] : false;
170 170
 
171 171
     // Retrieve the invoice.
172
-    $invoice = new WPInv_Invoice( $data['invoice_id'] );
172
+    $invoice = new WPInv_Invoice($data['invoice_id']);
173 173
 
174 174
     // Do we have an error?
175
-    if ( ! empty( $invoice->last_error ) ) {
176
-        return $wp_error ? new WP_Error( 'invalid_invoice_id', $invoice->last_error ) : 0;
175
+    if (!empty($invoice->last_error)) {
176
+        return $wp_error ? new WP_Error('invalid_invoice_id', $invoice->last_error) : 0;
177 177
     }
178 178
 
179 179
     // Backwards compatibility (billing address).
180
-    if ( ! empty( $data['user_info'] ) ) {
180
+    if (!empty($data['user_info'])) {
181 181
 
182
-        foreach ( $data['user_info'] as $key => $value ) {
182
+        foreach ($data['user_info'] as $key => $value) {
183 183
 
184
-            if ( $key == 'discounts' ) {
184
+            if ($key == 'discounts') {
185 185
                 $value = (array) $value;
186
-                $data[ 'discount_code' ] = empty( $value ) ? null : $value[0];
186
+                $data['discount_code'] = empty($value) ? null : $value[0];
187 187
             } else {
188
-                $data[ $key ] = $value;
188
+                $data[$key] = $value;
189 189
             }
190 190
 
191 191
         }
@@ -193,30 +193,30 @@  discard block
 block discarded – undo
193 193
     }
194 194
 
195 195
     // Backwards compatibility.
196
-    if ( ! empty( $data['payment_details'] ) ) {
196
+    if (!empty($data['payment_details'])) {
197 197
 
198
-        foreach ( $data['payment_details'] as $key => $value ) {
199
-            $data[ $key ] = $value;
198
+        foreach ($data['payment_details'] as $key => $value) {
199
+            $data[$key] = $value;
200 200
         }
201 201
 
202 202
     }
203 203
 
204 204
     // Set up the owner of the invoice.
205
-    $user_id = ! empty( $data['user_id'] ) ? wpinv_clean( $data['user_id'] ) : get_current_user_id();
205
+    $user_id = !empty($data['user_id']) ? wpinv_clean($data['user_id']) : get_current_user_id();
206 206
 
207 207
     // Make sure the user exists.
208
-    if ( ! get_userdata( $user_id ) ) {
209
-        return $wp_error ? new WP_Error( 'wpinv_invalid_user', __( 'There is no user with that ID.', 'invoicing' ) ) : 0;
208
+    if (!get_userdata($user_id)) {
209
+        return $wp_error ? new WP_Error('wpinv_invalid_user', __('There is no user with that ID.', 'invoicing')) : 0;
210 210
     }
211 211
 
212
-    $address = wpinv_get_user_address( $user_id );
212
+    $address = wpinv_get_user_address($user_id);
213 213
 
214
-    foreach ( $address as $key => $value ) {
214
+    foreach ($address as $key => $value) {
215 215
 
216
-        if ( $value == '' ) {
217
-            $address[ $key ] = null;
216
+        if ($value == '') {
217
+            $address[$key] = null;
218 218
         } else {
219
-            $address[ $key ] = wpinv_clean( $value );
219
+            $address[$key] = wpinv_clean($value);
220 220
         }
221 221
 
222 222
     }
@@ -227,103 +227,103 @@  discard block
 block discarded – undo
227 227
         array(
228 228
 
229 229
             // Basic info.
230
-            'template'             => isset( $data['template'] ) ? wpinv_clean( $data['template'] ) : null,
231
-            'email_cc'             => isset( $data['email_cc'] ) ? wpinv_clean( $data['email_cc'] ) : null,
232
-            'date_created'         => isset( $data['created_date'] ) ? wpinv_clean( $data['created_date'] ) : null,
233
-            'due_date'             => isset( $data['due_date'] ) ? wpinv_clean( $data['due_date'] ) : null,
234
-            'date_completed'       => isset( $data['date_completed'] ) ? wpinv_clean( $data['date_completed'] ) : null,
235
-            'number'               => isset( $data['number'] ) ? wpinv_clean( $data['number'] ) : null,
236
-            'key'                  => isset( $data['key'] ) ? wpinv_clean( $data['key'] ) : null,
237
-            'status'               => isset( $data['status'] ) ? wpinv_clean( $data['status'] ) : null,
238
-            'post_type'            => isset( $data['post_type'] ) ? wpinv_clean( $data['post_type'] ) : null,
239
-            'user_ip'              => isset( $data['ip'] ) ? wpinv_clean( $data['ip'] ) : wpinv_get_ip(),
240
-            'parent_id'            => isset( $data['parent'] ) ? intval( $data['parent'] ) : null,
241
-            'mode'                 => isset( $data['mode'] ) ? wpinv_clean( $data['mode'] ) : null,
242
-            'description'          => isset( $data['description'] ) ? wp_kses_post( $data['description'] ) : null,
230
+            'template'             => isset($data['template']) ? wpinv_clean($data['template']) : null,
231
+            'email_cc'             => isset($data['email_cc']) ? wpinv_clean($data['email_cc']) : null,
232
+            'date_created'         => isset($data['created_date']) ? wpinv_clean($data['created_date']) : null,
233
+            'due_date'             => isset($data['due_date']) ? wpinv_clean($data['due_date']) : null,
234
+            'date_completed'       => isset($data['date_completed']) ? wpinv_clean($data['date_completed']) : null,
235
+            'number'               => isset($data['number']) ? wpinv_clean($data['number']) : null,
236
+            'key'                  => isset($data['key']) ? wpinv_clean($data['key']) : null,
237
+            'status'               => isset($data['status']) ? wpinv_clean($data['status']) : null,
238
+            'post_type'            => isset($data['post_type']) ? wpinv_clean($data['post_type']) : null,
239
+            'user_ip'              => isset($data['ip']) ? wpinv_clean($data['ip']) : wpinv_get_ip(),
240
+            'parent_id'            => isset($data['parent']) ? intval($data['parent']) : null,
241
+            'mode'                 => isset($data['mode']) ? wpinv_clean($data['mode']) : null,
242
+            'description'          => isset($data['description']) ? wp_kses_post($data['description']) : null,
243 243
 
244 244
             // Payment info.
245
-            'disable_taxes'        => ! empty( $data['disable_taxes'] ),
246
-            'currency'             => isset( $data['currency'] ) ? wpinv_clean( $data['currency'] ) : wpinv_get_currency(),
247
-            'gateway'              => isset( $data['gateway'] ) ? wpinv_clean( $data['gateway'] ) : null,
248
-            'transaction_id'       => isset( $data['transaction_id'] ) ? wpinv_clean( $data['transaction_id'] ) : null,
249
-            'discount_code'        => isset( $data['discount_code'] ) ? wpinv_clean( $data['discount_code'] ) : null,
250
-            'payment_form'         => isset( $data['payment_form'] ) ? intval( $data['payment_form'] ) : null,
251
-            'submission_id'        => isset( $data['submission_id'] ) ? wpinv_clean( $data['submission_id'] ) : null,
252
-            'subscription_id'      => isset( $data['subscription_id'] ) ? wpinv_clean( $data['subscription_id'] ) : null,
253
-            'is_viewed'            => isset( $data['is_viewed'] ) ? wpinv_clean( $data['is_viewed'] ) : null,
254
-            'fees'                 => isset( $data['fees'] ) ? wpinv_clean( $data['fees'] ) : null,
255
-            'discounts'            => isset( $data['discounts'] ) ? wpinv_clean( $data['discounts'] ) : null,
256
-            'taxes'                => isset( $data['taxes'] ) ? wpinv_clean( $data['taxes'] ) : null,
245
+            'disable_taxes'        => !empty($data['disable_taxes']),
246
+            'currency'             => isset($data['currency']) ? wpinv_clean($data['currency']) : wpinv_get_currency(),
247
+            'gateway'              => isset($data['gateway']) ? wpinv_clean($data['gateway']) : null,
248
+            'transaction_id'       => isset($data['transaction_id']) ? wpinv_clean($data['transaction_id']) : null,
249
+            'discount_code'        => isset($data['discount_code']) ? wpinv_clean($data['discount_code']) : null,
250
+            'payment_form'         => isset($data['payment_form']) ? intval($data['payment_form']) : null,
251
+            'submission_id'        => isset($data['submission_id']) ? wpinv_clean($data['submission_id']) : null,
252
+            'subscription_id'      => isset($data['subscription_id']) ? wpinv_clean($data['subscription_id']) : null,
253
+            'is_viewed'            => isset($data['is_viewed']) ? wpinv_clean($data['is_viewed']) : null,
254
+            'fees'                 => isset($data['fees']) ? wpinv_clean($data['fees']) : null,
255
+            'discounts'            => isset($data['discounts']) ? wpinv_clean($data['discounts']) : null,
256
+            'taxes'                => isset($data['taxes']) ? wpinv_clean($data['taxes']) : null,
257 257
 
258 258
 
259 259
             // Billing details.
260 260
             'user_id'              => $data['user_id'],
261
-            'first_name'           => isset( $data['first_name'] ) ? wpinv_clean( $data['first_name'] ) : $address['first_name'],
262
-            'last_name'            => isset( $data['last_name'] ) ? wpinv_clean( $data['last_name'] ) : $address['last_name'],
263
-            'address'              => isset( $data['address'] ) ? wpinv_clean( $data['address'] ) : $address['address'] ,
264
-            'vat_number'           => isset( $data['vat_number'] ) ? wpinv_clean( $data['vat_number'] ) : $address['vat_number'],
265
-            'company'              => isset( $data['company'] ) ? wpinv_clean( $data['company'] ) : $address['company'],
266
-            'zip'                  => isset( $data['zip'] ) ? wpinv_clean( $data['zip'] ) : $address['zip'],
267
-            'state'                => isset( $data['state'] ) ? wpinv_clean( $data['state'] ) : $address['state'],
268
-            'city'                 => isset( $data['city'] ) ? wpinv_clean( $data['city'] ) : $address['city'],
269
-            'country'              => isset( $data['country'] ) ? wpinv_clean( $data['country'] ) : $address['country'],
270
-            'phone'                => isset( $data['phone'] ) ? wpinv_clean( $data['phone'] ) : $address['phone'],
271
-            'address_confirmed'    => ! empty( $data['address_confirmed'] ),
261
+            'first_name'           => isset($data['first_name']) ? wpinv_clean($data['first_name']) : $address['first_name'],
262
+            'last_name'            => isset($data['last_name']) ? wpinv_clean($data['last_name']) : $address['last_name'],
263
+            'address'              => isset($data['address']) ? wpinv_clean($data['address']) : $address['address'],
264
+            'vat_number'           => isset($data['vat_number']) ? wpinv_clean($data['vat_number']) : $address['vat_number'],
265
+            'company'              => isset($data['company']) ? wpinv_clean($data['company']) : $address['company'],
266
+            'zip'                  => isset($data['zip']) ? wpinv_clean($data['zip']) : $address['zip'],
267
+            'state'                => isset($data['state']) ? wpinv_clean($data['state']) : $address['state'],
268
+            'city'                 => isset($data['city']) ? wpinv_clean($data['city']) : $address['city'],
269
+            'country'              => isset($data['country']) ? wpinv_clean($data['country']) : $address['country'],
270
+            'phone'                => isset($data['phone']) ? wpinv_clean($data['phone']) : $address['phone'],
271
+            'address_confirmed'    => !empty($data['address_confirmed']),
272 272
 
273 273
         )
274 274
 
275 275
     );
276 276
 
277 277
     // Backwards compatibililty.
278
-    if ( ! empty( $data['cart_details'] ) && is_array( $data['cart_details'] ) ) {
278
+    if (!empty($data['cart_details']) && is_array($data['cart_details'])) {
279 279
         $data['items'] = array();
280 280
 
281
-        foreach( $data['cart_details'] as $_item ) {
281
+        foreach ($data['cart_details'] as $_item) {
282 282
 
283 283
             // Ensure that we have an item id.
284
-            if ( empty(  $_item['id']  ) ) {
284
+            if (empty($_item['id'])) {
285 285
                 continue;
286 286
             }
287 287
 
288 288
             // Retrieve the item.
289
-            $item = new GetPaid_Form_Item(  $_item['id']  );
289
+            $item = new GetPaid_Form_Item($_item['id']);
290 290
 
291 291
             // Ensure that it is purchasable.
292
-            if ( ! $item->can_purchase() ) {
292
+            if (!$item->can_purchase()) {
293 293
                 continue;
294 294
             }
295 295
 
296 296
             // Set quantity.
297
-            if ( ! empty( $_item['quantity'] ) && is_numeric( $_item['quantity'] ) ) {
298
-                $item->set_quantity( $_item['quantity'] );
297
+            if (!empty($_item['quantity']) && is_numeric($_item['quantity'])) {
298
+                $item->set_quantity($_item['quantity']);
299 299
             }
300 300
 
301 301
             // Set price.
302
-            if ( isset( $_item['item_price'] ) ) {
303
-                $item->set_price( $_item['item_price'] );
302
+            if (isset($_item['item_price'])) {
303
+                $item->set_price($_item['item_price']);
304 304
             }
305 305
 
306
-            if ( isset( $_item['custom_price'] ) ) {
307
-                $item->set_price( $_item['custom_price'] );
306
+            if (isset($_item['custom_price'])) {
307
+                $item->set_price($_item['custom_price']);
308 308
             }
309 309
 
310 310
             // Set name.
311
-            if ( ! empty( $_item['name'] ) ) {
312
-                $item->set_name( $_item['name'] );
311
+            if (!empty($_item['name'])) {
312
+                $item->set_name($_item['name']);
313 313
             }
314 314
 
315 315
             // Set description.
316
-            if ( isset( $_item['description'] ) ) {
317
-                $item->set_custom_description( $_item['description'] );
316
+            if (isset($_item['description'])) {
317
+                $item->set_custom_description($_item['description']);
318 318
             }
319 319
 
320 320
             // Set meta.
321
-            if ( isset( $_item['meta'] ) && is_array( $_item['meta'] ) ) {
321
+            if (isset($_item['meta']) && is_array($_item['meta'])) {
322 322
 
323
-                $item->set_item_meta( $_item['meta'] );
323
+                $item->set_item_meta($_item['meta']);
324 324
 
325
-                if ( isset( $_item['meta']['description'] ) ) {
326
-                    $item->set_custom_description( $_item['meta']['description'] );
325
+                if (isset($_item['meta']['description'])) {
326
+                    $item->set_custom_description($_item['meta']['description']);
327 327
                 }
328 328
 
329 329
             }
@@ -334,14 +334,14 @@  discard block
 block discarded – undo
334 334
     }
335 335
 
336 336
     // Add invoice items.
337
-    if ( ! empty( $data['items'] ) && is_array( $data['items'] ) ) {
337
+    if (!empty($data['items']) && is_array($data['items'])) {
338 338
 
339
-        $invoice->set_items( array() );
339
+        $invoice->set_items(array());
340 340
 
341
-        foreach ( $data['items'] as $item ) {
341
+        foreach ($data['items'] as $item) {
342 342
 
343
-            if ( is_object( $item ) && is_a( $item, 'GetPaid_Form_Item' ) && $item->can_purchase() ) {
344
-                $invoice->add_item( $item );
343
+            if (is_object($item) && is_a($item, 'GetPaid_Form_Item') && $item->can_purchase()) {
344
+                $invoice->add_item($item);
345 345
             }
346 346
 
347 347
         }
@@ -352,30 +352,30 @@  discard block
 block discarded – undo
352 352
     $invoice->recalculate_total();
353 353
     $invoice->save();
354 354
 
355
-    if ( ! $invoice->get_id() ) {
356
-        return $wp_error ? new WP_Error( 'wpinv_insert_invoice_error', __( 'An error occured when saving your invoice.', 'invoicing' ) ) : 0;
355
+    if (!$invoice->get_id()) {
356
+        return $wp_error ? new WP_Error('wpinv_insert_invoice_error', __('An error occured when saving your invoice.', 'invoicing')) : 0;
357 357
     }
358 358
 
359 359
     // Add private note.
360
-    if ( ! empty( $data['private_note'] ) ) {
361
-        $invoice->add_note( $data['private_note'] );
360
+    if (!empty($data['private_note'])) {
361
+        $invoice->add_note($data['private_note']);
362 362
     }
363 363
 
364 364
     // User notes.
365
-    if ( !empty( $data['user_note'] ) ) {
366
-        $invoice->add_note( $data['user_note'], true );
365
+    if (!empty($data['user_note'])) {
366
+        $invoice->add_note($data['user_note'], true);
367 367
     }
368 368
 
369 369
     // Created via.
370
-    if ( isset( $data['created_via'] ) ) {
371
-        update_post_meta( $invoice->get_id(), 'wpinv_created_via', $data['created_via'] );
370
+    if (isset($data['created_via'])) {
371
+        update_post_meta($invoice->get_id(), 'wpinv_created_via', $data['created_via']);
372 372
     }
373 373
 
374 374
     // Backwards compatiblity.
375
-    if ( $invoice->is_quote() ) {
375
+    if ($invoice->is_quote()) {
376 376
 
377
-        if ( isset( $data['valid_until'] ) ) {
378
-            update_post_meta( $invoice->get_id(), 'wpinv_quote_valid_until', $data['valid_until'] );
377
+        if (isset($data['valid_until'])) {
378
+            update_post_meta($invoice->get_id(), 'wpinv_quote_valid_until', $data['valid_until']);
379 379
         }
380 380
 
381 381
     }
@@ -390,20 +390,20 @@  discard block
 block discarded – undo
390 390
  * @param $bool $deprecated
391 391
  * @return WPInv_Invoice|null
392 392
  */
393
-function wpinv_get_invoice( $invoice = 0, $deprecated = false ) {
393
+function wpinv_get_invoice($invoice = 0, $deprecated = false) {
394 394
 
395 395
     // If we are retrieving the invoice from the cart...
396
-    if ( $deprecated && empty( $invoice ) ) {
396
+    if ($deprecated && empty($invoice)) {
397 397
         $invoice = (int) getpaid_get_current_invoice_id();
398 398
     }
399 399
 
400 400
     // Retrieve the invoice.
401
-    if ( ! is_a( $invoice, 'WPInv_Invoice' ) ) {
402
-        $invoice = new WPInv_Invoice( $invoice );
401
+    if (!is_a($invoice, 'WPInv_Invoice')) {
402
+        $invoice = new WPInv_Invoice($invoice);
403 403
     }
404 404
 
405 405
     // Check if it exists.
406
-    if ( $invoice->exists() ) {
406
+    if ($invoice->exists()) {
407 407
         return $invoice;
408 408
     }
409 409
 
@@ -416,15 +416,15 @@  discard block
 block discarded – undo
416 416
  * @param array $args Args to search for.
417 417
  * @return WPInv_Invoice[]|int[]|object
418 418
  */
419
-function wpinv_get_invoices( $args ) {
419
+function wpinv_get_invoices($args) {
420 420
 
421 421
     // Prepare args.
422 422
     $args = wp_parse_args(
423 423
         $args,
424 424
         array(
425
-            'status'   => array_keys( wpinv_get_invoice_statuses() ),
425
+            'status'   => array_keys(wpinv_get_invoice_statuses()),
426 426
             'type'     => 'wpi_invoice',
427
-            'limit'    => get_option( 'posts_per_page' ),
427
+            'limit'    => get_option('posts_per_page'),
428 428
             'return'   => 'objects',
429 429
         )
430 430
     );
@@ -442,24 +442,24 @@  discard block
 block discarded – undo
442 442
         'post__in'       => 'include',
443 443
     );
444 444
 
445
-    foreach ( $map_legacy as $to => $from ) {
446
-        if ( isset( $args[ $from ] ) ) {
447
-            $args[ $to ] = $args[ $from ];
448
-            unset( $args[ $from ] );
445
+    foreach ($map_legacy as $to => $from) {
446
+        if (isset($args[$from])) {
447
+            $args[$to] = $args[$from];
448
+            unset($args[$from]);
449 449
         }
450 450
     }
451 451
 
452 452
     // Backwards compatibility.
453
-    if ( ! empty( $args['email'] ) && empty( $args['user'] ) ) {
453
+    if (!empty($args['email']) && empty($args['user'])) {
454 454
         $args['user'] = $args['email'];
455
-        unset( $args['email'] );
455
+        unset($args['email']);
456 456
     }
457 457
 
458 458
     // Handle cases where the user is set as an email.
459
-    if ( ! empty( $args['author'] ) && is_email( $args['author'] ) ) {
460
-        $user = get_user_by( 'email', $args['user'] );
459
+    if (!empty($args['author']) && is_email($args['author'])) {
460
+        $user = get_user_by('email', $args['user']);
461 461
 
462
-        if ( $user ) {
462
+        if ($user) {
463 463
             $args['author'] = $user->user_email;
464 464
         }
465 465
 
@@ -470,31 +470,31 @@  discard block
 block discarded – undo
470 470
 
471 471
     // Show all posts.
472 472
     $paginate = true;
473
-    if ( isset( $args['paginate'] ) ) {
473
+    if (isset($args['paginate'])) {
474 474
 
475 475
         $paginate = $args['paginate'];
476
-        $args['no_found_rows'] = empty( $args['paginate'] );
477
-        unset( $args['paginate'] );
476
+        $args['no_found_rows'] = empty($args['paginate']);
477
+        unset($args['paginate']);
478 478
 
479 479
     }
480 480
 
481 481
     // Whether to return objects or fields.
482 482
     $return = $args['return'];
483
-    unset( $args['return'] );
483
+    unset($args['return']);
484 484
 
485 485
     // Get invoices.
486
-    $invoices = new WP_Query( apply_filters( 'wpinv_get_invoices_args', $args ) );
486
+    $invoices = new WP_Query(apply_filters('wpinv_get_invoices_args', $args));
487 487
 
488 488
     // Prepare the results.
489
-    if ( 'objects' === $return ) {
490
-        $results = array_map( 'wpinv_get_invoice', $invoices->posts );
491
-    } elseif ( 'self' === $return ) {
489
+    if ('objects' === $return) {
490
+        $results = array_map('wpinv_get_invoice', $invoices->posts);
491
+    } elseif ('self' === $return) {
492 492
         return $invoices;
493 493
     } else {
494 494
         $results = $invoices->posts;
495 495
     }
496 496
 
497
-    if ( $paginate ) {
497
+    if ($paginate) {
498 498
         return (object) array(
499 499
             'invoices'      => $results,
500 500
             'total'         => $invoices->found_posts,
@@ -512,8 +512,8 @@  discard block
 block discarded – undo
512 512
  * @param string $transaction_id The transaction id to check.
513 513
  * @return int Invoice id on success or 0 on failure
514 514
  */
515
-function wpinv_get_id_by_transaction_id( $transaction_id ) {
516
-    return WPInv_Invoice::get_invoice_id_by_field( $transaction_id, 'transaction_id' );
515
+function wpinv_get_id_by_transaction_id($transaction_id) {
516
+    return WPInv_Invoice::get_invoice_id_by_field($transaction_id, 'transaction_id');
517 517
 }
518 518
 
519 519
 /**
@@ -522,8 +522,8 @@  discard block
 block discarded – undo
522 522
  * @param string $invoice_number The invoice number to check.
523 523
  * @return int Invoice id on success or 0 on failure
524 524
  */
525
-function wpinv_get_id_by_invoice_number( $invoice_number ) {
526
-    return WPInv_Invoice::get_invoice_id_by_field( $invoice_number, 'number' );
525
+function wpinv_get_id_by_invoice_number($invoice_number) {
526
+    return WPInv_Invoice::get_invoice_id_by_field($invoice_number, 'number');
527 527
 }
528 528
 
529 529
 /**
@@ -532,8 +532,8 @@  discard block
 block discarded – undo
532 532
  * @param string $invoice_key The invoice key to check.
533 533
  * @return int Invoice id on success or 0 on failure
534 534
  */
535
-function wpinv_get_invoice_id_by_key( $invoice_key ) {
536
-    return WPInv_Invoice::get_invoice_id_by_field( $invoice_key, 'key' );
535
+function wpinv_get_invoice_id_by_key($invoice_key) {
536
+    return WPInv_Invoice::get_invoice_id_by_field($invoice_key, 'key');
537 537
 }
538 538
 
539 539
 /**
@@ -543,19 +543,19 @@  discard block
 block discarded – undo
543 543
  * @param string $type Optionally filter by type i.e customer|system
544 544
  * @return array|null
545 545
  */
546
-function wpinv_get_invoice_notes( $invoice = 0, $type = '' ) {
546
+function wpinv_get_invoice_notes($invoice = 0, $type = '') {
547 547
 
548 548
     // Prepare the invoice.
549
-    $invoice = wpinv_get_invoice( $invoice );
550
-    if ( empty( $invoice ) ) {
549
+    $invoice = wpinv_get_invoice($invoice);
550
+    if (empty($invoice)) {
551 551
         return NULL;
552 552
     }
553 553
 
554 554
     // Fetch notes.
555
-    $notes = getpaid_notes()->get_invoice_notes( $invoice->get_id(), $type );
555
+    $notes = getpaid_notes()->get_invoice_notes($invoice->get_id(), $type);
556 556
 
557 557
     // Filter the notes.
558
-    return apply_filters( 'wpinv_invoice_notes', $notes, $invoice->get_id(), $type );
558
+    return apply_filters('wpinv_invoice_notes', $notes, $invoice->get_id(), $type);
559 559
 }
560 560
 
561 561
 /**
@@ -563,10 +563,10 @@  discard block
 block discarded – undo
563 563
  *
564 564
  * @param string $post_type
565 565
  */
566
-function wpinv_get_user_invoices_columns( $post_type = 'wpi_invoice' ) {
566
+function wpinv_get_user_invoices_columns($post_type = 'wpi_invoice') {
567 567
 
568
-    $label   = getpaid_get_post_type_label( $post_type, false );
569
-    $label   = empty( $label ) ? __( 'Invoice', 'invoicing' ) : sanitize_text_field( $label );
568
+    $label   = getpaid_get_post_type_label($post_type, false);
569
+    $label   = empty($label) ? __('Invoice', 'invoicing') : sanitize_text_field($label);
570 570
     $columns = array(
571 571
 
572 572
             'invoice-number'  => array(
@@ -575,22 +575,22 @@  discard block
 block discarded – undo
575 575
             ),
576 576
 
577 577
             'created-date'    => array(
578
-                'title' => __( 'Created Date', 'invoicing' ),
578
+                'title' => __('Created Date', 'invoicing'),
579 579
                 'class' => 'text-left'
580 580
             ),
581 581
 
582 582
             'payment-date'    => array(
583
-                'title' => __( 'Payment Date', 'invoicing' ),
583
+                'title' => __('Payment Date', 'invoicing'),
584 584
                 'class' => 'text-left'
585 585
             ),
586 586
 
587 587
             'invoice-status'  => array(
588
-                'title' => __( 'Status', 'invoicing' ),
588
+                'title' => __('Status', 'invoicing'),
589 589
                 'class' => 'text-center'
590 590
             ),
591 591
 
592 592
             'invoice-total'   => array(
593
-                'title' => __( 'Total', 'invoicing' ),
593
+                'title' => __('Total', 'invoicing'),
594 594
                 'class' => 'text-right'
595 595
             ),
596 596
 
@@ -601,7 +601,7 @@  discard block
 block discarded – undo
601 601
 
602 602
         );
603 603
 
604
-    return apply_filters( 'wpinv_user_invoices_columns', $columns, $post_type );
604
+    return apply_filters('wpinv_user_invoices_columns', $columns, $post_type);
605 605
 }
606 606
 
607 607
 /**
@@ -611,59 +611,59 @@  discard block
 block discarded – undo
611 611
 
612 612
     // Find the invoice.
613 613
     $invoice_id = getpaid_get_current_invoice_id();
614
-    $invoice = new WPInv_Invoice( $invoice_id );
614
+    $invoice = new WPInv_Invoice($invoice_id);
615 615
 
616 616
     // Abort if non was found.
617
-    if ( empty( $invoice_id ) || $invoice->is_draft() ) {
617
+    if (empty($invoice_id) || $invoice->is_draft()) {
618 618
 
619 619
         return aui()->alert(
620 620
             array(
621 621
                 'type'    => 'warning',
622
-                'content' => __( 'We could not find your invoice', 'invoicing' ),
622
+                'content' => __('We could not find your invoice', 'invoicing'),
623 623
             )
624 624
         );
625 625
 
626 626
     }
627 627
 
628 628
     // Can the user view this invoice?
629
-    if ( ! wpinv_can_view_receipt( $invoice_id ) ) {
629
+    if (!wpinv_can_view_receipt($invoice_id)) {
630 630
 
631 631
         return aui()->alert(
632 632
             array(
633 633
                 'type'    => 'warning',
634
-                'content' => __( 'You are not allowed to view this receipt', 'invoicing' ),
634
+                'content' => __('You are not allowed to view this receipt', 'invoicing'),
635 635
             )
636 636
         );
637 637
 
638 638
     }
639 639
 
640 640
     // Load the template.
641
-    return wpinv_get_template_html( 'invoice-receipt.php', compact( 'invoice' ) );
641
+    return wpinv_get_template_html('invoice-receipt.php', compact('invoice'));
642 642
 
643 643
 }
644 644
 
645 645
 /**
646 646
  * Displays the invoice history.
647 647
  */
648
-function getpaid_invoice_history( $user_id = 0, $post_type = 'wpi_invoice' ) {
648
+function getpaid_invoice_history($user_id = 0, $post_type = 'wpi_invoice') {
649 649
 
650 650
     // Ensure that we have a user id.
651
-    if ( empty( $user_id ) || ! is_numeric( $user_id ) ) {
651
+    if (empty($user_id) || !is_numeric($user_id)) {
652 652
         $user_id = get_current_user_id();
653 653
     }
654 654
 
655
-    $label = getpaid_get_post_type_label( $post_type );
656
-    $label = empty( $label ) ? __( 'Invoices', 'invoicing' ) : sanitize_text_field( $label );
655
+    $label = getpaid_get_post_type_label($post_type);
656
+    $label = empty($label) ? __('Invoices', 'invoicing') : sanitize_text_field($label);
657 657
 
658 658
     // View user id.
659
-    if ( empty( $user_id ) ) {
659
+    if (empty($user_id)) {
660 660
 
661 661
         return aui()->alert(
662 662
             array(
663 663
                 'type'    => 'warning',
664 664
                 'content' => sprintf(
665
-                    __( 'You must be logged in to view your %s.', 'invoicing' ),
666
-                    strtolower( $label )
665
+                    __('You must be logged in to view your %s.', 'invoicing'),
666
+                    strtolower($label)
667 667
                 )
668 668
             )
669 669
         );
@@ -674,23 +674,23 @@  discard block
 block discarded – undo
674 674
     $invoices = wpinv_get_invoices(
675 675
 
676 676
         array(
677
-            'page'      => ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1,
677
+            'page'      => (get_query_var('paged')) ? absint(get_query_var('paged')) : 1,
678 678
             'user'      => $user_id,
679 679
             'paginate'  => true,
680 680
             'type'      => $post_type,
681
-            'status'    => array_keys( wpinv_get_invoice_statuses( false, false, $post_type ) ),
681
+            'status'    => array_keys(wpinv_get_invoice_statuses(false, false, $post_type)),
682 682
         )
683 683
 
684 684
     );
685 685
 
686
-    if ( empty( $invoices->total ) ) {
686
+    if (empty($invoices->total)) {
687 687
 
688 688
         return aui()->alert(
689 689
             array(
690 690
                 'type'    => 'info',
691 691
                 'content' => sprintf(
692
-                    __( 'No %s found.', 'invoicing' ),
693
-                    strtolower( $label )
692
+                    __('No %s found.', 'invoicing'),
693
+                    strtolower($label)
694 694
                 )
695 695
             )
696 696
         );
@@ -698,38 +698,38 @@  discard block
 block discarded – undo
698 698
     }
699 699
 
700 700
     // Load the template.
701
-    return wpinv_get_template_html( 'invoice-history.php', compact( 'invoices', 'post_type' ) );
701
+    return wpinv_get_template_html('invoice-history.php', compact('invoices', 'post_type'));
702 702
 
703 703
 }
704 704
 
705 705
 /**
706 706
  * Formats an invoice number given an invoice type.
707 707
  */
708
-function wpinv_format_invoice_number( $number, $type = '' ) {
708
+function wpinv_format_invoice_number($number, $type = '') {
709 709
 
710 710
     // Allow other plugins to overide this.
711
-    $check = apply_filters( 'wpinv_pre_format_invoice_number', null, $number, $type );
712
-    if ( null !== $check ) {
711
+    $check = apply_filters('wpinv_pre_format_invoice_number', null, $number, $type);
712
+    if (null !== $check) {
713 713
         return $check;
714 714
     }
715 715
 
716 716
     // Ensure that we have a numeric number.
717
-    if ( ! is_numeric( $number ) ) {
717
+    if (!is_numeric($number)) {
718 718
         return $number;
719 719
     }
720 720
 
721 721
     // Format the number.
722
-    $padd             = absint( (int) wpinv_get_option( 'invoice_number_padd', 5 ) );
723
-    $prefix           = sanitize_text_field( (string) wpinv_get_option( 'invoice_number_prefix', 'INV-' ) );
724
-    $prefix           = sanitize_text_field( apply_filters( 'getpaid_invoice_type_prefix', $prefix, $type ) );
725
-    $postfix          = sanitize_text_field( (string) wpinv_get_option( 'invoice_number_postfix' ) );
726
-    $postfix          = sanitize_text_field( apply_filters( 'getpaid_invoice_type_postfix', $postfix, $type ) );
727
-    $formatted_number = zeroise( absint( $number ), $padd );
722
+    $padd             = absint((int) wpinv_get_option('invoice_number_padd', 5));
723
+    $prefix           = sanitize_text_field((string) wpinv_get_option('invoice_number_prefix', 'INV-'));
724
+    $prefix           = sanitize_text_field(apply_filters('getpaid_invoice_type_prefix', $prefix, $type));
725
+    $postfix          = sanitize_text_field((string) wpinv_get_option('invoice_number_postfix'));
726
+    $postfix          = sanitize_text_field(apply_filters('getpaid_invoice_type_postfix', $postfix, $type));
727
+    $formatted_number = zeroise(absint($number), $padd);
728 728
 
729 729
     // Add the prefix and post fix.
730 730
     $formatted_number = $prefix . $formatted_number . $postfix;
731 731
 
732
-    return apply_filters( 'wpinv_format_invoice_number', $formatted_number, $number, $prefix, $postfix, $padd );
732
+    return apply_filters('wpinv_format_invoice_number', $formatted_number, $number, $prefix, $postfix, $padd);
733 733
 }
734 734
 
735 735
 /**
@@ -738,58 +738,58 @@  discard block
 block discarded – undo
738 738
  * @param string $type.
739 739
  * @return int|null|bool
740 740
  */
741
-function wpinv_get_next_invoice_number( $type = '' ) {
741
+function wpinv_get_next_invoice_number($type = '') {
742 742
 
743 743
     // Allow plugins to overide this.
744
-    $check = apply_filters( 'wpinv_get_pre_next_invoice_number', null, $type );
745
-    if ( null !== $check ) {
744
+    $check = apply_filters('wpinv_get_pre_next_invoice_number', null, $type);
745
+    if (null !== $check) {
746 746
         return $check;
747 747
     }
748 748
 
749 749
     // Ensure sequential invoice numbers is active.
750
-    if ( ! wpinv_sequential_number_active() ) {
750
+    if (!wpinv_sequential_number_active()) {
751 751
         return false;
752 752
     }
753 753
 
754 754
     // Retrieve the current number and the start number.
755
-    $number = (int) get_option( 'wpinv_last_invoice_number', 0 );
756
-    $start  = absint( (int) wpinv_get_option( 'invoice_sequence_start', 1 ) );
755
+    $number = (int) get_option('wpinv_last_invoice_number', 0);
756
+    $start  = absint((int) wpinv_get_option('invoice_sequence_start', 1));
757 757
 
758 758
     // Ensure that we are starting at a positive integer.
759
-    $start  = max( $start, 1 );
759
+    $start  = max($start, 1);
760 760
 
761 761
     // If this is the first invoice, use the start number.
762
-    $number = max( $start, $number );
762
+    $number = max($start, $number);
763 763
 
764 764
     // Format the invoice number.
765
-    $formatted_number = wpinv_format_invoice_number( $number, $type );
765
+    $formatted_number = wpinv_format_invoice_number($number, $type);
766 766
 
767 767
     // Ensure that this number is unique.
768
-    $invoice_id = WPInv_Invoice::get_invoice_id_by_field( $formatted_number, 'number' );
768
+    $invoice_id = WPInv_Invoice::get_invoice_id_by_field($formatted_number, 'number');
769 769
 
770 770
     // We found a match. Nice.
771
-    if ( empty( $invoice_id ) ) {
772
-        update_option( 'wpinv_last_invoice_number', $number );
773
-        return apply_filters( 'wpinv_get_next_invoice_number', $number );
771
+    if (empty($invoice_id)) {
772
+        update_option('wpinv_last_invoice_number', $number);
773
+        return apply_filters('wpinv_get_next_invoice_number', $number);
774 774
     }
775 775
 
776
-    update_option( 'wpinv_last_invoice_number', $number + 1 );
777
-    return wpinv_get_next_invoice_number( $type );
776
+    update_option('wpinv_last_invoice_number', $number + 1);
777
+    return wpinv_get_next_invoice_number($type);
778 778
 
779 779
 }
780 780
 
781 781
 /**
782 782
  * The prefix used for invoice paths.
783 783
  */
784
-function wpinv_post_name_prefix( $post_type = 'wpi_invoice' ) {
785
-    return apply_filters( 'wpinv_post_name_prefix', 'inv-', $post_type );
784
+function wpinv_post_name_prefix($post_type = 'wpi_invoice') {
785
+    return apply_filters('wpinv_post_name_prefix', 'inv-', $post_type);
786 786
 }
787 787
 
788
-function wpinv_generate_post_name( $post_ID ) {
789
-    $prefix = wpinv_post_name_prefix( get_post_type( $post_ID ) );
790
-    $post_name = sanitize_title( $prefix . $post_ID );
788
+function wpinv_generate_post_name($post_ID) {
789
+    $prefix = wpinv_post_name_prefix(get_post_type($post_ID));
790
+    $post_name = sanitize_title($prefix . $post_ID);
791 791
 
792
-    return apply_filters( 'wpinv_generate_post_name', $post_name, $post_ID, $prefix );
792
+    return apply_filters('wpinv_generate_post_name', $post_name, $post_ID, $prefix);
793 793
 }
794 794
 
795 795
 /**
@@ -797,8 +797,8 @@  discard block
 block discarded – undo
797 797
  *
798 798
  * @param int|string|object|WPInv_Invoice|WPInv_Legacy_Invoice|WP_Post $invoice Invoice id, key, transaction id, number or object.
799 799
  */
800
-function wpinv_is_invoice_viewed( $invoice ) {
801
-    $invoice = new WPInv_Invoice( $invoice );
800
+function wpinv_is_invoice_viewed($invoice) {
801
+    $invoice = new WPInv_Invoice($invoice);
802 802
     return (bool) $invoice->get_is_viewed();
803 803
 }
804 804
 
@@ -807,17 +807,17 @@  discard block
 block discarded – undo
807 807
  *
808 808
  * @param int|string|object|WPInv_Invoice|WPInv_Legacy_Invoice|WP_Post $invoice Invoice id, key, transaction id, number or object.
809 809
  */
810
-function getpaid_maybe_mark_invoice_as_viewed( $invoice ) {
811
-    $invoice = new WPInv_Invoice( $invoice );
810
+function getpaid_maybe_mark_invoice_as_viewed($invoice) {
811
+    $invoice = new WPInv_Invoice($invoice);
812 812
 
813
-    if ( get_current_user_id() == $invoice->get_user_id() && ! $invoice->get_is_viewed() ) {
814
-        $invoice->set_is_viewed( true );
813
+    if (get_current_user_id() == $invoice->get_user_id() && !$invoice->get_is_viewed()) {
814
+        $invoice->set_is_viewed(true);
815 815
         $invoice->save();
816 816
     }
817 817
 
818 818
 }
819
-add_action( 'wpinv_invoice_print_before_display', 'getpaid_maybe_mark_invoice_as_viewed' );
820
-add_action( 'wpinv_before_receipt', 'getpaid_maybe_mark_invoice_as_viewed' );
819
+add_action('wpinv_invoice_print_before_display', 'getpaid_maybe_mark_invoice_as_viewed');
820
+add_action('wpinv_before_receipt', 'getpaid_maybe_mark_invoice_as_viewed');
821 821
 
822 822
 /**
823 823
  * Processes an invoice refund.
@@ -826,27 +826,27 @@  discard block
 block discarded – undo
826 826
  * @param array $status_transition
827 827
  * @todo: descrease customer/store earnings
828 828
  */
829
-function getpaid_maybe_process_refund( $invoice, $status_transition ) {
829
+function getpaid_maybe_process_refund($invoice, $status_transition) {
830 830
 
831
-    if ( empty( $status_transition['from'] ) || ! in_array( $status_transition['from'], array( 'publish', 'wpi-processing', 'wpi-renewal' ) ) ) {
831
+    if (empty($status_transition['from']) || !in_array($status_transition['from'], array('publish', 'wpi-processing', 'wpi-renewal'))) {
832 832
         return;
833 833
     }
834 834
 
835 835
     $discount_code = $invoice->get_discount_code();
836
-    if ( ! empty( $discount_code ) ) {
837
-        $discount = wpinv_get_discount_obj( $discount_code );
836
+    if (!empty($discount_code)) {
837
+        $discount = wpinv_get_discount_obj($discount_code);
838 838
 
839
-        if ( $discount->exists() ) {
839
+        if ($discount->exists()) {
840 840
             $discount->increase_usage( -1 );
841 841
         }
842 842
 
843 843
     }
844 844
 
845
-    do_action( 'wpinv_pre_refund_invoice', $invoice, $invoice->get_id() );
846
-    do_action( 'wpinv_refund_invoice', $invoice, $invoice->get_id() );
847
-    do_action( 'wpinv_post_refund_invoice', $invoice, $invoice->get_id() );
845
+    do_action('wpinv_pre_refund_invoice', $invoice, $invoice->get_id());
846
+    do_action('wpinv_refund_invoice', $invoice, $invoice->get_id());
847
+    do_action('wpinv_post_refund_invoice', $invoice, $invoice->get_id());
848 848
 }
849
-add_action( 'getpaid_invoice_status_wpi-refunded', 'getpaid_maybe_process_refund', 10, 2 );
849
+add_action('getpaid_invoice_status_wpi-refunded', 'getpaid_maybe_process_refund', 10, 2);
850 850
 
851 851
 
852 852
 /**
@@ -854,49 +854,49 @@  discard block
 block discarded – undo
854 854
  *
855 855
  * @param int $invoice_id
856 856
  */
857
-function getpaid_process_invoice_payment( $invoice_id ) {
857
+function getpaid_process_invoice_payment($invoice_id) {
858 858
 
859 859
     // Fetch the invoice.
860
-    $invoice = new WPInv_Invoice( $invoice_id );
860
+    $invoice = new WPInv_Invoice($invoice_id);
861 861
 
862 862
     // We only want to do this once.
863
-    if ( 1 ==  get_post_meta( $invoice->get_id(), 'wpinv_processed_payment', true ) ) {
863
+    if (1 == get_post_meta($invoice->get_id(), 'wpinv_processed_payment', true)) {
864 864
         return;
865 865
     }
866 866
 
867
-    update_post_meta( $invoice->get_id(), 'wpinv_processed_payment', 1 );
867
+    update_post_meta($invoice->get_id(), 'wpinv_processed_payment', 1);
868 868
 
869 869
     // Fires when processing a payment.
870
-    do_action( 'getpaid_process_payment', $invoice );
870
+    do_action('getpaid_process_payment', $invoice);
871 871
 
872 872
     // Fire an action for each invoice item.
873
-    foreach( $invoice->get_items() as $item ) {
874
-        do_action( 'getpaid_process_item_payment', $item, $invoice );
873
+    foreach ($invoice->get_items() as $item) {
874
+        do_action('getpaid_process_item_payment', $item, $invoice);
875 875
     }
876 876
 
877 877
     // Increase discount usage.
878 878
     $discount_code = $invoice->get_discount_code();
879
-    if ( ! empty( $discount_code ) && ! $invoice->is_renewal() ) {
880
-        $discount = wpinv_get_discount_obj( $discount_code );
879
+    if (!empty($discount_code) && !$invoice->is_renewal()) {
880
+        $discount = wpinv_get_discount_obj($discount_code);
881 881
 
882
-        if ( $discount->exists() ) {
882
+        if ($discount->exists()) {
883 883
             $discount->increase_usage();
884 884
         }
885 885
 
886 886
     }
887 887
 
888 888
     // Record reverse vat.
889
-    if ( 'invoice' == $invoice->get_type() && wpinv_use_taxes() && ! $invoice->get_disable_taxes() ) {
889
+    if ('invoice' == $invoice->get_type() && wpinv_use_taxes() && !$invoice->get_disable_taxes()) {
890 890
 
891 891
         $taxes = $invoice->get_total_tax();
892
-        if ( empty( $taxes ) && GetPaid_Payment_Form_Submission_Taxes::is_eu_transaction( $invoice->get_country() ) ) {
893
-            $invoice->add_note( __( 'VAT was reverse charged', 'invoicing' ), false, false, true );
892
+        if (empty($taxes) && GetPaid_Payment_Form_Submission_Taxes::is_eu_transaction($invoice->get_country())) {
893
+            $invoice->add_note(__('VAT was reverse charged', 'invoicing'), false, false, true);
894 894
         }
895 895
 
896 896
     }
897 897
 
898 898
 }
899
-add_action( 'getpaid_invoice_payment_status_changed', 'getpaid_process_invoice_payment' );
899
+add_action('getpaid_invoice_payment_status_changed', 'getpaid_process_invoice_payment');
900 900
 
901 901
 /**
902 902
  * Returns an array of invoice item columns
@@ -904,13 +904,13 @@  discard block
 block discarded – undo
904 904
  * @param int|WPInv_Invoice $invoice
905 905
  * @return array
906 906
  */
907
-function getpaid_invoice_item_columns( $invoice ) {
907
+function getpaid_invoice_item_columns($invoice) {
908 908
 
909 909
     // Prepare the invoice.
910
-    $invoice = new WPInv_Invoice( $invoice );
910
+    $invoice = new WPInv_Invoice($invoice);
911 911
 
912 912
     // Abort if there is no invoice.
913
-    if ( 0 == $invoice->get_id() ) {
913
+    if (0 == $invoice->get_id()) {
914 914
         return array();
915 915
     }
916 916
 
@@ -918,57 +918,57 @@  discard block
 block discarded – undo
918 918
     $columns = apply_filters(
919 919
         'getpaid_invoice_item_columns',
920 920
         array(
921
-            'name'     => __( 'Item', 'invoicing' ),
922
-            'price'    => __( 'Price', 'invoicing' ),
923
-            'tax_rate' => __( 'Tax Rate', 'invoicing' ),
924
-            'quantity' => __( 'Quantity', 'invoicing' ),
925
-            'subtotal' => __( 'Item Subtotal', 'invoicing' ),
921
+            'name'     => __('Item', 'invoicing'),
922
+            'price'    => __('Price', 'invoicing'),
923
+            'tax_rate' => __('Tax Rate', 'invoicing'),
924
+            'quantity' => __('Quantity', 'invoicing'),
925
+            'subtotal' => __('Item Subtotal', 'invoicing'),
926 926
         ),
927 927
         $invoice
928 928
     );
929 929
 
930 930
     // Quantities.
931
-    if ( isset( $columns[ 'quantity' ] ) ) {
931
+    if (isset($columns['quantity'])) {
932 932
 
933
-        if ( 'hours' == $invoice->get_template() ) {
934
-            $columns[ 'quantity' ] = __( 'Hours', 'invoicing' );
933
+        if ('hours' == $invoice->get_template()) {
934
+            $columns['quantity'] = __('Hours', 'invoicing');
935 935
         }
936 936
 
937
-        if ( ! wpinv_item_quantities_enabled() || 'amount' == $invoice->get_template() ) {
938
-            unset( $columns[ 'quantity' ] );
937
+        if (!wpinv_item_quantities_enabled() || 'amount' == $invoice->get_template()) {
938
+            unset($columns['quantity']);
939 939
         }
940 940
 
941 941
     }
942 942
 
943 943
 
944 944
     // Price.
945
-    if ( isset( $columns[ 'price' ] ) ) {
945
+    if (isset($columns['price'])) {
946 946
 
947
-        if ( 'amount' == $invoice->get_template() ) {
948
-            $columns[ 'price' ] = __( 'Amount', 'invoicing' );
947
+        if ('amount' == $invoice->get_template()) {
948
+            $columns['price'] = __('Amount', 'invoicing');
949 949
         }
950 950
 
951
-        if ( 'hours' == $invoice->get_template() ) {
952
-            $columns[ 'price' ] = __( 'Rate', 'invoicing' );
951
+        if ('hours' == $invoice->get_template()) {
952
+            $columns['price'] = __('Rate', 'invoicing');
953 953
         }
954 954
 
955 955
     }
956 956
 
957 957
 
958 958
     // Sub total.
959
-    if ( isset( $columns[ 'subtotal' ] ) ) {
959
+    if (isset($columns['subtotal'])) {
960 960
 
961
-        if ( 'amount' == $invoice->get_template() ) {
962
-            unset( $columns[ 'subtotal' ] );
961
+        if ('amount' == $invoice->get_template()) {
962
+            unset($columns['subtotal']);
963 963
         }
964 964
 
965 965
     }
966 966
 
967 967
     // Tax rates.
968
-    if ( isset( $columns[ 'tax_rate' ] ) ) {
968
+    if (isset($columns['tax_rate'])) {
969 969
 
970
-        if ( 0 == $invoice->get_tax() ) {
971
-            unset( $columns[ 'tax_rate' ] );
970
+        if (0 == $invoice->get_tax()) {
971
+            unset($columns['tax_rate']);
972 972
         }
973 973
 
974 974
     }
@@ -982,43 +982,43 @@  discard block
 block discarded – undo
982 982
  * @param int|WPInv_Invoice $invoice
983 983
  * @return array
984 984
  */
985
-function getpaid_invoice_totals_rows( $invoice ) {
985
+function getpaid_invoice_totals_rows($invoice) {
986 986
 
987 987
     // Prepare the invoice.
988
-    $invoice = new WPInv_Invoice( $invoice );
988
+    $invoice = new WPInv_Invoice($invoice);
989 989
 
990 990
     // Abort if there is no invoice.
991
-    if ( 0 == $invoice->get_id() ) {
991
+    if (0 == $invoice->get_id()) {
992 992
         return array();
993 993
     }
994 994
 
995 995
     $totals = apply_filters(
996 996
         'getpaid_invoice_totals_rows',
997 997
         array(
998
-            'subtotal' => __( 'Subtotal', 'invoicing' ),
999
-            'shipping' => __( 'Shipping', 'invoicing' ),
1000
-            'tax'      => __( 'Tax', 'invoicing' ),
1001
-            'fee'      => __( 'Fee', 'invoicing' ),
1002
-            'discount' => __( 'Discount', 'invoicing' ),
1003
-            'total'    => __( 'Total', 'invoicing' ),
998
+            'subtotal' => __('Subtotal', 'invoicing'),
999
+            'shipping' => __('Shipping', 'invoicing'),
1000
+            'tax'      => __('Tax', 'invoicing'),
1001
+            'fee'      => __('Fee', 'invoicing'),
1002
+            'discount' => __('Discount', 'invoicing'),
1003
+            'total'    => __('Total', 'invoicing'),
1004 1004
         ),
1005 1005
         $invoice
1006 1006
     );
1007 1007
 
1008
-    if ( ! $invoice->has_shipping() ) {
1009
-        unset( $totals['shipping'] );
1008
+    if (!$invoice->has_shipping()) {
1009
+        unset($totals['shipping']);
1010 1010
     }
1011 1011
 
1012
-    if ( ( $invoice->get_disable_taxes() || ! wpinv_use_taxes() ) && isset( $totals['tax'] ) ) {
1013
-        unset( $totals['tax'] );
1012
+    if (($invoice->get_disable_taxes() || !wpinv_use_taxes()) && isset($totals['tax'])) {
1013
+        unset($totals['tax']);
1014 1014
     }
1015 1015
 
1016
-    if ( 0 == $invoice->get_total_fees() && isset( $totals['fee'] ) ) {
1017
-        unset( $totals['fee'] );
1016
+    if (0 == $invoice->get_total_fees() && isset($totals['fee'])) {
1017
+        unset($totals['fee']);
1018 1018
     }
1019 1019
 
1020
-    if ( 0 == $invoice->get_total_discount() && isset( $totals['discount'] ) ) {
1021
-        unset( $totals['discount'] );
1020
+    if (0 == $invoice->get_total_discount() && isset($totals['discount'])) {
1021
+        unset($totals['discount']);
1022 1022
     }
1023 1023
 
1024 1024
     return $totals;
@@ -1029,47 +1029,47 @@  discard block
 block discarded – undo
1029 1029
  *
1030 1030
  * @param WPInv_Invoice $invoice
1031 1031
  */
1032
-function getpaid_new_invoice( $invoice ) {
1032
+function getpaid_new_invoice($invoice) {
1033 1033
 
1034
-    if ( ! $invoice->get_status() ) {
1034
+    if (!$invoice->get_status()) {
1035 1035
         return;
1036 1036
     }
1037 1037
 
1038 1038
     // Add an invoice created note.
1039 1039
     $invoice->add_note(
1040 1040
         sprintf(
1041
-            __( '%s created with the status "%s".', 'invoicing' ),
1042
-            ucfirst( $invoice->get_invoice_quote_type() ),
1043
-            wpinv_status_nicename( $invoice->get_status(), $invoice  )
1041
+            __('%s created with the status "%s".', 'invoicing'),
1042
+            ucfirst($invoice->get_invoice_quote_type()),
1043
+            wpinv_status_nicename($invoice->get_status(), $invoice)
1044 1044
         )
1045 1045
     );
1046 1046
 
1047 1047
 }
1048
-add_action( 'getpaid_new_invoice', 'getpaid_new_invoice' );
1048
+add_action('getpaid_new_invoice', 'getpaid_new_invoice');
1049 1049
 
1050 1050
 /**
1051 1051
  * This function updates invoice caches.
1052 1052
  *
1053 1053
  * @param WPInv_Invoice $invoice
1054 1054
  */
1055
-function getpaid_update_invoice_caches( $invoice ) {
1055
+function getpaid_update_invoice_caches($invoice) {
1056 1056
 
1057 1057
     // Cache invoice number.
1058
-    wp_cache_set( $invoice->get_number(), $invoice->get_id(), "getpaid_invoice_numbers_to_invoice_ids" );
1058
+    wp_cache_set($invoice->get_number(), $invoice->get_id(), "getpaid_invoice_numbers_to_invoice_ids");
1059 1059
 
1060 1060
     // Cache invoice key.
1061
-    wp_cache_set( $invoice->get_key(), $invoice->get_id(), "getpaid_invoice_keys_to_invoice_ids" );
1061
+    wp_cache_set($invoice->get_key(), $invoice->get_id(), "getpaid_invoice_keys_to_invoice_ids");
1062 1062
 
1063 1063
     // (Maybe) cache transaction id.
1064 1064
     $transaction_id = $invoice->get_transaction_id();
1065 1065
 
1066
-    if ( ! empty( $transaction_id ) ) {
1067
-        wp_cache_set( $transaction_id, $invoice->get_id(), "getpaid_invoice_transaction_ids_to_invoice_ids" );
1066
+    if (!empty($transaction_id)) {
1067
+        wp_cache_set($transaction_id, $invoice->get_id(), "getpaid_invoice_transaction_ids_to_invoice_ids");
1068 1068
     }
1069 1069
 
1070 1070
 }
1071
-add_action( 'getpaid_new_invoice', 'getpaid_update_invoice_caches', 5 );
1072
-add_action( 'getpaid_update_invoice', 'getpaid_update_invoice_caches', 5 );
1071
+add_action('getpaid_new_invoice', 'getpaid_update_invoice_caches', 5);
1072
+add_action('getpaid_update_invoice', 'getpaid_update_invoice_caches', 5);
1073 1073
 
1074 1074
 /**
1075 1075
  * Duplicates an invoice.
@@ -1079,7 +1079,7 @@  discard block
 block discarded – undo
1079 1079
  * @param  WPInv_Invoice $old_invoice The invoice to duplicate
1080 1080
  * @return WPInv_Invoice The new invoice.
1081 1081
  */
1082
-function getpaid_duplicate_invoice( $old_invoice ) {
1082
+function getpaid_duplicate_invoice($old_invoice) {
1083 1083
 
1084 1084
     // Create the new invoice.
1085 1085
     $invoice = new WPInv_Invoice();
@@ -1140,133 +1140,133 @@  discard block
 block discarded – undo
1140 1140
  * @param WPInv_Invoice $invoice
1141 1141
  * @return array
1142 1142
  */
1143
-function getpaid_get_invoice_meta( $invoice ) {
1143
+function getpaid_get_invoice_meta($invoice) {
1144 1144
 
1145 1145
     // Load the invoice meta.
1146 1146
     $meta = array(
1147 1147
 
1148 1148
         'number' => array(
1149 1149
             'label' => sprintf(
1150
-                __( '%s Number', 'invoicing' ),
1151
-                ucfirst( $invoice->get_invoice_quote_type() )
1150
+                __('%s Number', 'invoicing'),
1151
+                ucfirst($invoice->get_invoice_quote_type())
1152 1152
             ),
1153
-            'value' => sanitize_text_field( $invoice->get_number() ),
1153
+            'value' => sanitize_text_field($invoice->get_number()),
1154 1154
         ),
1155 1155
 
1156 1156
         'status' => array(
1157 1157
             'label' => sprintf(
1158
-                __( '%s Status', 'invoicing' ),
1159
-                ucfirst( $invoice->get_invoice_quote_type() )
1158
+                __('%s Status', 'invoicing'),
1159
+                ucfirst($invoice->get_invoice_quote_type())
1160 1160
             ),
1161 1161
             'value' => $invoice->get_status_label_html(),
1162 1162
         ),
1163 1163
 
1164 1164
         'date' => array(
1165 1165
             'label' => sprintf(
1166
-                __( '%s Date', 'invoicing' ),
1167
-                ucfirst( $invoice->get_invoice_quote_type() )
1166
+                __('%s Date', 'invoicing'),
1167
+                ucfirst($invoice->get_invoice_quote_type())
1168 1168
             ),
1169
-            'value' => getpaid_format_date( $invoice->get_created_date() ),
1169
+            'value' => getpaid_format_date($invoice->get_created_date()),
1170 1170
         ),
1171 1171
 
1172 1172
         'date_paid' => array(
1173
-            'label' => __( 'Paid On', 'invoicing' ),
1174
-            'value' => getpaid_format_date( $invoice->get_completed_date() ),
1173
+            'label' => __('Paid On', 'invoicing'),
1174
+            'value' => getpaid_format_date($invoice->get_completed_date()),
1175 1175
         ),
1176 1176
 
1177 1177
         'gateway'   => array(
1178
-            'label' => __( 'Payment Method', 'invoicing' ),
1179
-            'value' => sanitize_text_field( $invoice->get_gateway_title() ),
1178
+            'label' => __('Payment Method', 'invoicing'),
1179
+            'value' => sanitize_text_field($invoice->get_gateway_title()),
1180 1180
         ),
1181 1181
 
1182 1182
         'transaction_id' => array(
1183
-            'label' => __( 'Transaction ID', 'invoicing' ),
1184
-            'value' => sanitize_text_field( $invoice->get_transaction_id() ),
1183
+            'label' => __('Transaction ID', 'invoicing'),
1184
+            'value' => sanitize_text_field($invoice->get_transaction_id()),
1185 1185
         ),
1186 1186
 
1187 1187
         'due_date'  => array(
1188
-            'label' => __( 'Due Date', 'invoicing' ),
1189
-            'value' => getpaid_format_date( $invoice->get_due_date() ),
1188
+            'label' => __('Due Date', 'invoicing'),
1189
+            'value' => getpaid_format_date($invoice->get_due_date()),
1190 1190
         ),
1191 1191
 
1192 1192
         'vat_number' => array(
1193
-            'label' => __( 'VAT Number', 'invoicing' ),
1194
-            'value' => sanitize_text_field( $invoice->get_vat_number() ),
1193
+            'label' => __('VAT Number', 'invoicing'),
1194
+            'value' => sanitize_text_field($invoice->get_vat_number()),
1195 1195
         ),
1196 1196
 
1197 1197
     );
1198 1198
 
1199
-    $additional_meta = get_post_meta( $invoice->get_id(), 'additional_meta_data', true );
1199
+    $additional_meta = get_post_meta($invoice->get_id(), 'additional_meta_data', true);
1200 1200
 
1201
-    if ( ! empty( $additional_meta ) ) {
1201
+    if (!empty($additional_meta)) {
1202 1202
 
1203
-        foreach ( $additional_meta as $label => $value ) {
1204
-            $meta[ sanitize_key( $label ) ] = array(
1205
-                'label' => esc_html( $label ),
1206
-                'value' => esc_html( $value ),
1203
+        foreach ($additional_meta as $label => $value) {
1204
+            $meta[sanitize_key($label)] = array(
1205
+                'label' => esc_html($label),
1206
+                'value' => esc_html($value),
1207 1207
             );
1208 1208
         }
1209 1209
 
1210 1210
     }
1211 1211
     // If it is not paid, remove the date of payment.
1212
-    if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) {
1213
-        unset( $meta[ 'date_paid' ] );
1214
-        unset( $meta[ 'transaction_id' ] );
1212
+    if (!$invoice->is_paid() && !$invoice->is_refunded()) {
1213
+        unset($meta['date_paid']);
1214
+        unset($meta['transaction_id']);
1215 1215
     }
1216 1216
 
1217
-    if ( ! $invoice->is_paid() || 'none' == $invoice->get_gateway() ) {
1218
-        unset( $meta[ 'gateway' ] );
1217
+    if (!$invoice->is_paid() || 'none' == $invoice->get_gateway()) {
1218
+        unset($meta['gateway']);
1219 1219
     }
1220 1220
 
1221 1221
     // Only display the due date if due dates are enabled.
1222
-    if ( ! $invoice->needs_payment() || ! wpinv_get_option( 'overdue_active' ) ) {
1223
-        unset( $meta[ 'due_date' ] );
1222
+    if (!$invoice->needs_payment() || !wpinv_get_option('overdue_active')) {
1223
+        unset($meta['due_date']);
1224 1224
     }
1225 1225
 
1226 1226
     // Only display the vat number if taxes are enabled.
1227
-    if ( ! wpinv_use_taxes() ) {
1228
-        unset( $meta[ 'vat_number' ] );
1227
+    if (!wpinv_use_taxes()) {
1228
+        unset($meta['vat_number']);
1229 1229
     }
1230 1230
 
1231 1231
     // Link to the parent invoice.
1232
-    if ( $invoice->get_parent_id() > 0 ) {
1232
+    if ($invoice->get_parent_id() > 0) {
1233 1233
 
1234
-        $meta[ 'parent' ] = array(
1234
+        $meta['parent'] = array(
1235 1235
 
1236 1236
             'label' => sprintf(
1237
-                __( 'Parent %s', 'invoicing' ),
1238
-                ucfirst( $invoice->get_invoice_quote_type() )
1237
+                __('Parent %s', 'invoicing'),
1238
+                ucfirst($invoice->get_invoice_quote_type())
1239 1239
             ),
1240 1240
 
1241
-            'value' => wpinv_invoice_link( $invoice->get_parent_id() ),
1241
+            'value' => wpinv_invoice_link($invoice->get_parent_id()),
1242 1242
 
1243 1243
         );
1244 1244
 
1245 1245
     }
1246 1246
 
1247 1247
     
1248
-    if ( $invoice->is_recurring() ) {
1248
+    if ($invoice->is_recurring()) {
1249 1249
 
1250
-        $subscription = getpaid_get_invoice_subscriptions( $invoice );
1251
-        if ( ! empty ( $subscription ) && ! is_array( $subscription ) && $subscription->exists() ) {
1250
+        $subscription = getpaid_get_invoice_subscriptions($invoice);
1251
+        if (!empty ($subscription) && !is_array($subscription) && $subscription->exists()) {
1252 1252
 
1253 1253
             // Display the renewal date.
1254
-            if ( $subscription->is_active() && 'cancelled' != $subscription->get_status() ) {
1254
+            if ($subscription->is_active() && 'cancelled' != $subscription->get_status()) {
1255 1255
 
1256
-                $meta[ 'renewal_date' ] = array(
1257
-                    'label' => __( 'Renews On', 'invoicing' ),
1258
-                    'value' => getpaid_format_date( $subscription->get_expiration() ),
1256
+                $meta['renewal_date'] = array(
1257
+                    'label' => __('Renews On', 'invoicing'),
1258
+                    'value' => getpaid_format_date($subscription->get_expiration()),
1259 1259
                 );
1260 1260
 
1261 1261
             }
1262 1262
 
1263
-            if ( $invoice->is_parent() ) {
1263
+            if ($invoice->is_parent()) {
1264 1264
 
1265 1265
                 // Display the recurring amount.
1266
-                $meta[ 'recurring_total' ] = array(
1266
+                $meta['recurring_total'] = array(
1267 1267
 
1268
-                    'label' => __( 'Recurring Amount', 'invoicing' ),
1269
-                    'value' => wpinv_price( $subscription->get_recurring_amount(), $invoice->get_currency() ),
1268
+                    'label' => __('Recurring Amount', 'invoicing'),
1269
+                    'value' => wpinv_price($subscription->get_recurring_amount(), $invoice->get_currency()),
1270 1270
 
1271 1271
                 );
1272 1272
 
@@ -1276,15 +1276,15 @@  discard block
 block discarded – undo
1276 1276
     }
1277 1277
 
1278 1278
     // Add the invoice total to the meta.
1279
-    $meta[ 'invoice_total' ] = array(
1279
+    $meta['invoice_total'] = array(
1280 1280
 
1281
-        'label' => __( 'Total Amount', 'invoicing' ),
1282
-        'value' => wpinv_price( $invoice->get_total(), $invoice->get_currency() ),
1281
+        'label' => __('Total Amount', 'invoicing'),
1282
+        'value' => wpinv_price($invoice->get_total(), $invoice->get_currency()),
1283 1283
 
1284 1284
     );
1285 1285
 
1286 1286
     // Provide a way for third party plugins to filter the meta.
1287
-    $meta = apply_filters( 'getpaid_invoice_meta_data', $meta, $invoice );
1287
+    $meta = apply_filters('getpaid_invoice_meta_data', $meta, $invoice);
1288 1288
 
1289 1289
     return $meta;
1290 1290
 
@@ -1323,12 +1323,12 @@  discard block
 block discarded – undo
1323 1323
  * @param GetPaid_Form_Item $item
1324 1324
  * @return float
1325 1325
  */
1326
-function getpaid_get_invoice_tax_rate( $invoice, $item ) {
1326
+function getpaid_get_invoice_tax_rate($invoice, $item) {
1327 1327
 
1328
-    $rates   = getpaid_get_item_tax_rates( $item, $invoice->get_country(), $invoice->get_state() );
1329
-	$rates   = getpaid_filter_item_tax_rates( $item, $rates );
1330
-    $rates   = wp_list_pluck( $rates, 'rate' );
1328
+    $rates   = getpaid_get_item_tax_rates($item, $invoice->get_country(), $invoice->get_state());
1329
+	$rates = getpaid_filter_item_tax_rates($item, $rates);
1330
+    $rates   = wp_list_pluck($rates, 'rate');
1331 1331
 
1332
-    return array_sum( $rates );
1332
+    return array_sum($rates);
1333 1333
 
1334 1334
 }
Please login to merge, or discard this patch.
includes/payments/class-getpaid-payment-form-submission.php 1 patch
Spacing   +130 added lines, -130 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if (!defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
@@ -146,8 +146,8 @@  discard block
 block discarded – undo
146 146
 		$this->state   = wpinv_get_default_state();
147 147
 
148 148
 		// Do we have an actual submission?
149
-		if ( isset( $_POST['getpaid_payment_form_submission'] ) ) {
150
-			$this->load_data( $_POST );
149
+		if (isset($_POST['getpaid_payment_form_submission'])) {
150
+			$this->load_data($_POST);
151 151
 		}
152 152
 
153 153
 	}
@@ -157,19 +157,19 @@  discard block
 block discarded – undo
157 157
 	 *
158 158
 	 * @param array $data
159 159
 	 */
160
-	public function load_data( $data ) {
160
+	public function load_data($data) {
161 161
 
162 162
 		// Remove slashes from the submitted data...
163
-		$data       = wp_kses_post_deep( wp_unslash( $data ) );
163
+		$data       = wp_kses_post_deep(wp_unslash($data));
164 164
 
165 165
 		// Allow plugins to filter the data.
166
-		$data       = apply_filters( 'getpaid_submission_data', $data, $this );
166
+		$data       = apply_filters('getpaid_submission_data', $data, $this);
167 167
 
168 168
 		// Cache it...
169 169
 		$this->data = $data;
170 170
 
171 171
 		// Then generate a unique id from the data.
172
-		$this->id   = md5( wp_json_encode( $data ) );
172
+		$this->id   = md5(wp_json_encode($data));
173 173
 
174 174
 		// Finally, process the submission.
175 175
 		try {
@@ -179,30 +179,30 @@  discard block
 block discarded – undo
179 179
 			$processors = apply_filters(
180 180
 				'getpaid_payment_form_submission_processors',
181 181
 				array(
182
-					array( $this, 'process_payment_form' ),
183
-					array( $this, 'process_invoice' ),
184
-					array( $this, 'process_fees' ),
185
-					array( $this, 'process_items' ),
186
-					array( $this, 'process_discount' ),
187
-					array( $this, 'process_taxes' ),
182
+					array($this, 'process_payment_form'),
183
+					array($this, 'process_invoice'),
184
+					array($this, 'process_fees'),
185
+					array($this, 'process_items'),
186
+					array($this, 'process_discount'),
187
+					array($this, 'process_taxes'),
188 188
 				),
189 189
 				$this		
190 190
 			);
191 191
 
192
-			foreach ( $processors as $processor ) {
193
-				call_user_func_array( $processor, array( &$this ) );
192
+			foreach ($processors as $processor) {
193
+				call_user_func_array($processor, array(&$this));
194 194
 			}
195 195
 
196
-		} catch( GetPaid_Payment_Exception $e ) {
196
+		} catch (GetPaid_Payment_Exception $e) {
197 197
 			$this->last_error      = $e->getMessage();
198 198
 			$this->last_error_code = $e->getErrorCode();
199
-		} catch ( Exception $e ) {
199
+		} catch (Exception $e) {
200 200
 			$this->last_error      = $e->getMessage();
201 201
 			$this->last_error_code = $e->getCode();
202 202
 		}
203 203
 
204 204
 		// Fired when we are done processing a submission.
205
-		do_action_ref_array( 'getpaid_process_submission', array( &$this ) );
205
+		do_action_ref_array('getpaid_process_submission', array(&$this));
206 206
 
207 207
 	}
208 208
 
@@ -223,18 +223,18 @@  discard block
 block discarded – undo
223 223
 	public function process_payment_form() {
224 224
 
225 225
 		// Every submission needs an active payment form.
226
-		if ( empty( $this->data['form_id'] ) ) {
227
-			throw new Exception( __( 'Missing payment form', 'invoicing' ) );
226
+		if (empty($this->data['form_id'])) {
227
+			throw new Exception(__('Missing payment form', 'invoicing'));
228 228
 		}
229 229
 
230 230
 		// Fetch the payment form.
231
-		$this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] );
231
+		$this->payment_form = new GetPaid_Payment_Form($this->data['form_id']);
232 232
 
233
-		if ( ! $this->payment_form->is_active() ) {
234
-			throw new Exception( __( 'Payment form not active', 'invoicing' ) );
233
+		if (!$this->payment_form->is_active()) {
234
+			throw new Exception(__('Payment form not active', 'invoicing'));
235 235
 		}
236 236
 
237
-		do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) );
237
+		do_action_ref_array('getpaid_submissions_process_payment_form', array(&$this));
238 238
 	}
239 239
 
240 240
     /**
@@ -264,53 +264,53 @@  discard block
 block discarded – undo
264 264
 	public function process_invoice() {
265 265
 
266 266
 		// Abort if there is no invoice.
267
-		if ( empty( $this->data['invoice_id'] ) ) {
267
+		if (empty($this->data['invoice_id'])) {
268 268
 			return;
269 269
 		}
270 270
 
271 271
 		// If the submission is for an existing invoice, ensure that it exists
272 272
 		// and that it is not paid for.
273
-		$invoice = wpinv_get_invoice( $this->data['invoice_id'] );
273
+		$invoice = wpinv_get_invoice($this->data['invoice_id']);
274 274
 
275
-        if ( empty( $invoice ) ) {
276
-			throw new Exception( __( 'Invalid invoice', 'invoicing' ) );
275
+        if (empty($invoice)) {
276
+			throw new Exception(__('Invalid invoice', 'invoicing'));
277 277
 		}
278 278
 
279
-		if ( $invoice->is_paid() ) {
280
-			throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) );
279
+		if ($invoice->is_paid()) {
280
+			throw new Exception(__('This invoice is already paid for.', 'invoicing'));
281 281
 		}
282 282
 
283 283
 		$this->payment_form->invoice = $invoice;
284
-		if ( ! $this->payment_form->is_default() ) {
284
+		if (!$this->payment_form->is_default()) {
285 285
 
286 286
 			$items    = array();
287 287
 			$item_ids = array();
288 288
 	
289
-			foreach ( $invoice->get_items() as $item ) {
290
-				if ( ! in_array( $item->get_id(), $item_ids ) ) {
289
+			foreach ($invoice->get_items() as $item) {
290
+				if (!in_array($item->get_id(), $item_ids)) {
291 291
 					$item_ids[] = $item->get_id();
292 292
 					$items[]    = $item;
293 293
 				}
294 294
 			}
295 295
 	
296
-			foreach ( $this->payment_form->get_items() as $item ) {
297
-				if ( ! in_array( $item->get_id(), $item_ids ) ) {
296
+			foreach ($this->payment_form->get_items() as $item) {
297
+				if (!in_array($item->get_id(), $item_ids)) {
298 298
 					$item_ids[] = $item->get_id();
299 299
 					$items[]    = $item;
300 300
 				}
301 301
 			}
302 302
 	
303
-			$this->payment_form->set_items( $items );
303
+			$this->payment_form->set_items($items);
304 304
 	
305 305
 		} else {
306
-			$this->payment_form->set_items( $invoice->get_items() );
306
+			$this->payment_form->set_items($invoice->get_items());
307 307
 		}
308 308
 
309 309
 		$this->country = $invoice->get_country();
310 310
 		$this->state   = $invoice->get_state();
311 311
 		$this->invoice = $invoice;
312 312
 
313
-		do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) );
313
+		do_action_ref_array('getpaid_submissions_process_invoice', array(&$this));
314 314
 	}
315 315
 
316 316
 	/**
@@ -330,7 +330,7 @@  discard block
 block discarded – undo
330 330
 	 * @return bool
331 331
 	 */
332 332
 	public function has_invoice() {
333
-		return ! empty( $this->invoice );
333
+		return !empty($this->invoice);
334 334
 	}
335 335
 
336 336
 	/*
@@ -349,13 +349,13 @@  discard block
 block discarded – undo
349 349
 	 */
350 350
 	public function process_items() {
351 351
 
352
-		$processor = new GetPaid_Payment_Form_Submission_Items( $this );
352
+		$processor = new GetPaid_Payment_Form_Submission_Items($this);
353 353
 
354
-		foreach ( $processor->items as $item ) {
355
-			$this->add_item( $item );
354
+		foreach ($processor->items as $item) {
355
+			$this->add_item($item);
356 356
 		}
357 357
 
358
-		do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) );
358
+		do_action_ref_array('getpaid_submissions_process_items', array(&$this));
359 359
 	}
360 360
 
361 361
 	/**
@@ -364,20 +364,20 @@  discard block
 block discarded – undo
364 364
 	 * @since 1.0.19
365 365
 	 * @param GetPaid_Form_Item $item
366 366
 	 */
367
-	public function add_item( $item ) {
367
+	public function add_item($item) {
368 368
 
369 369
 		// Make sure that it is available for purchase.
370
-		if ( ! $item->can_purchase() || isset( $this->items[ $item->get_id() ] ) ) {
370
+		if (!$item->can_purchase() || isset($this->items[$item->get_id()])) {
371 371
 			return;
372 372
 		}
373 373
 
374 374
 		// Each submission can only contain one recurring item.
375
-		if ( $item->is_recurring() ) {
375
+		if ($item->is_recurring()) {
376 376
 			$this->has_recurring = $item->get_id();
377 377
 		}
378 378
 
379 379
 		// Update the items and totals.
380
-		$this->items[ $item->get_id() ]         = $item;
380
+		$this->items[$item->get_id()]         = $item;
381 381
 		$this->totals['subtotal']['initial']   += $item->get_sub_total();
382 382
 		$this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total();
383 383
 
@@ -391,17 +391,17 @@  discard block
 block discarded – undo
391 391
 	 *
392 392
 	 * @since 1.0.19
393 393
 	 */
394
-	public function remove_item( $item_id ) {
394
+	public function remove_item($item_id) {
395 395
 
396
-		if ( isset( $this->items[ $item_id ] ) ) {
397
-			$this->totals['subtotal']['initial']   -= $this->items[ $item_id ]->get_sub_total();
398
-			$this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total();
396
+		if (isset($this->items[$item_id])) {
397
+			$this->totals['subtotal']['initial']   -= $this->items[$item_id]->get_sub_total();
398
+			$this->totals['subtotal']['recurring'] -= $this->items[$item_id]->get_recurring_sub_total();
399 399
 
400
-			if ( $this->items[ $item_id ]->is_recurring() ) {
400
+			if ($this->items[$item_id]->is_recurring()) {
401 401
 				$this->has_recurring = 0;
402 402
 			}
403 403
 
404
-			unset( $this->items[ $item_id ] );
404
+			unset($this->items[$item_id]);
405 405
 		}
406 406
 
407 407
 	}
@@ -413,7 +413,7 @@  discard block
 block discarded – undo
413 413
 	 */
414 414
 	public function get_subtotal() {
415 415
 
416
-		if ( wpinv_prices_include_tax() ) {
416
+		if (wpinv_prices_include_tax()) {
417 417
 			return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial'];
418 418
 		}
419 419
 
@@ -427,7 +427,7 @@  discard block
 block discarded – undo
427 427
 	 */
428 428
 	public function get_recurring_subtotal() {
429 429
 
430
-		if ( wpinv_prices_include_tax() ) {
430
+		if (wpinv_prices_include_tax()) {
431 431
 			return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring'];
432 432
 		}
433 433
 
@@ -451,7 +451,7 @@  discard block
 block discarded – undo
451 451
 	 * @return bool
452 452
 	 */
453 453
 	public function has_subscription_group() {
454
-		return $this->has_recurring && getpaid_should_group_subscriptions( $this ) && 1 == count( getpaid_get_subscription_groups( $this ) );
454
+		return $this->has_recurring && getpaid_should_group_subscriptions($this) && 1 == count(getpaid_get_subscription_groups($this));
455 455
 	}
456 456
 
457 457
 	/**
@@ -461,7 +461,7 @@  discard block
 block discarded – undo
461 461
 	 * @return bool
462 462
 	 */
463 463
 	public function has_multiple_subscription_groups() {
464
-		return $this->has_recurring && 1 < count( getpaid_get_subscription_groups( $this ) );
464
+		return $this->has_recurring && 1 < count(getpaid_get_subscription_groups($this));
465 465
 	}
466 466
 
467 467
 	/*
@@ -481,39 +481,39 @@  discard block
 block discarded – undo
481 481
 	public function process_taxes() {
482 482
 
483 483
 		// Abort if we're not using taxes.
484
-		if ( ! $this->use_taxes() ) {
484
+		if (!$this->use_taxes()) {
485 485
 			return;
486 486
 		}
487 487
 
488 488
 		// If a custom country && state has been passed in, use it to calculate taxes.
489
-		$country = $this->get_field( 'wpinv_country', 'billing' );
490
-		if ( ! empty( $country ) ) {
489
+		$country = $this->get_field('wpinv_country', 'billing');
490
+		if (!empty($country)) {
491 491
 			$this->country = $country;
492 492
 		}
493 493
 
494
-		$state = $this->get_field( 'wpinv_state', 'billing' );
495
-		if ( ! empty( $state ) ) {
494
+		$state = $this->get_field('wpinv_state', 'billing');
495
+		if (!empty($state)) {
496 496
 			$this->state = $state;
497 497
 		}
498 498
 
499 499
 		// Confirm if the provided country and the ip country are similar.
500
-		$address_confirmed = $this->get_field( 'confirm-address' );
501
-		if ( isset( $_POST['billing']['country'] ) && wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty( $address_confirmed ) ) {
502
-			throw new Exception( __( 'The country of your current location must be the same as the country of your billing location or you must confirm the billing address is your home country.', 'invoicing' ) );
500
+		$address_confirmed = $this->get_field('confirm-address');
501
+		if (isset($_POST['billing']['country']) && wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty($address_confirmed)) {
502
+			throw new Exception(__('The country of your current location must be the same as the country of your billing location or you must confirm the billing address is your home country.', 'invoicing'));
503 503
 		}
504 504
 
505 505
 		// Abort if the country is not taxable.
506
-		if ( ! wpinv_is_country_taxable( $this->country ) ) {
506
+		if (!wpinv_is_country_taxable($this->country)) {
507 507
 			return;
508 508
 		}
509 509
 
510
-		$processor = new GetPaid_Payment_Form_Submission_Taxes( $this );
510
+		$processor = new GetPaid_Payment_Form_Submission_Taxes($this);
511 511
 
512
-		foreach ( $processor->taxes as $tax ) {
513
-			$this->add_tax( $tax );
512
+		foreach ($processor->taxes as $tax) {
513
+			$this->add_tax($tax);
514 514
 		}
515 515
 
516
-		do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) );
516
+		do_action_ref_array('getpaid_submissions_process_taxes', array(&$this));
517 517
 	}
518 518
 
519 519
 	/**
@@ -522,16 +522,16 @@  discard block
 block discarded – undo
522 522
 	 * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required.
523 523
 	 * @since 1.0.19
524 524
 	 */
525
-	public function add_tax( $tax ) {
525
+	public function add_tax($tax) {
526 526
 
527
-		if ( wpinv_round_tax_per_tax_rate() ) {
528
-			$tax['initial_tax']   = wpinv_round_amount( $tax['initial_tax'] );
529
-			$tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] );
527
+		if (wpinv_round_tax_per_tax_rate()) {
528
+			$tax['initial_tax']   = wpinv_round_amount($tax['initial_tax']);
529
+			$tax['recurring_tax'] = wpinv_round_amount($tax['recurring_tax']);
530 530
 		}
531 531
 
532
-		$this->taxes[ $tax['name'] ]         = $tax;
533
-		$this->totals['taxes']['initial']   += wpinv_sanitize_amount( $tax['initial_tax'] );
534
-		$this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] );
532
+		$this->taxes[$tax['name']]         = $tax;
533
+		$this->totals['taxes']['initial']   += wpinv_sanitize_amount($tax['initial_tax']);
534
+		$this->totals['taxes']['recurring'] += wpinv_sanitize_amount($tax['recurring_tax']);
535 535
 
536 536
 	}
537 537
 
@@ -540,12 +540,12 @@  discard block
 block discarded – undo
540 540
 	 *
541 541
 	 * @since 1.0.19
542 542
 	 */
543
-	public function remove_tax( $tax_name ) {
543
+	public function remove_tax($tax_name) {
544 544
 
545
-		if ( isset( $this->taxes[ $tax_name ] ) ) {
546
-			$this->totals['taxes']['initial']   -= $this->taxes[ $tax_name ]['initial_tax'];
547
-			$this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax'];
548
-			unset( $this->taxes[ $tax_name ] );
545
+		if (isset($this->taxes[$tax_name])) {
546
+			$this->totals['taxes']['initial']   -= $this->taxes[$tax_name]['initial_tax'];
547
+			$this->totals['taxes']['recurring'] -= $this->taxes[$tax_name]['recurring_tax'];
548
+			unset($this->taxes[$tax_name]);
549 549
 		}
550 550
 
551 551
 	}
@@ -559,11 +559,11 @@  discard block
 block discarded – undo
559 559
 
560 560
 		$use_taxes = wpinv_use_taxes();
561 561
 
562
-		if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) {
562
+		if ($this->has_invoice() && !$this->invoice->is_taxable()) {
563 563
 			$use_taxes = false;
564 564
 		}
565 565
 
566
-		return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this );
566
+		return apply_filters('getpaid_submission_use_taxes', $use_taxes, $this);
567 567
 
568 568
 	}
569 569
 
@@ -612,13 +612,13 @@  discard block
 block discarded – undo
612 612
 
613 613
 		$initial_total    = $this->get_subtotal() + $this->get_fee() + $this->get_tax();
614 614
 		$recurring_total  = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax();
615
-		$processor        = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total );
615
+		$processor        = new GetPaid_Payment_Form_Submission_Discount($this, $initial_total, $recurring_total);
616 616
 
617
-		foreach ( $processor->discounts as $discount ) {
618
-			$this->add_discount( $discount );
617
+		foreach ($processor->discounts as $discount) {
618
+			$this->add_discount($discount);
619 619
 		}
620 620
 
621
-		do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) );
621
+		do_action_ref_array('getpaid_submissions_process_discounts', array(&$this));
622 622
 	}
623 623
 
624 624
 	/**
@@ -627,10 +627,10 @@  discard block
 block discarded – undo
627 627
 	 * @param array $discount An array of discount details. name, initial_discount, and recurring_discount are required. Include discount_code if the discount is from a discount code.
628 628
 	 * @since 1.0.19
629 629
 	 */
630
-	public function add_discount( $discount ) {
631
-		$this->discounts[ $discount['name'] ]   = $discount;
632
-		$this->totals['discount']['initial']   += wpinv_sanitize_amount( $discount['initial_discount'] );
633
-		$this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] );
630
+	public function add_discount($discount) {
631
+		$this->discounts[$discount['name']]   = $discount;
632
+		$this->totals['discount']['initial']   += wpinv_sanitize_amount($discount['initial_discount']);
633
+		$this->totals['discount']['recurring'] += wpinv_sanitize_amount($discount['recurring_discount']);
634 634
 	}
635 635
 
636 636
 	/**
@@ -638,12 +638,12 @@  discard block
 block discarded – undo
638 638
 	 *
639 639
 	 * @since 1.0.19
640 640
 	 */
641
-	public function remove_discount( $name ) {
641
+	public function remove_discount($name) {
642 642
 
643
-		if ( isset( $this->discounts[ $name ] ) ) {
644
-			$this->totals['discount']['initial']   -= $this->discounts[ $name ]['initial_discount'];
645
-			$this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount'];
646
-			unset( $this->discounts[ $name ] );
643
+		if (isset($this->discounts[$name])) {
644
+			$this->totals['discount']['initial']   -= $this->discounts[$name]['initial_discount'];
645
+			$this->totals['discount']['recurring'] -= $this->discounts[$name]['recurring_discount'];
646
+			unset($this->discounts[$name]);
647 647
 		}
648 648
 
649 649
 	}
@@ -655,7 +655,7 @@  discard block
 block discarded – undo
655 655
 	 * @return bool
656 656
 	 */
657 657
 	public function has_discount_code() {
658
-		return ! empty( $this->discounts['discount_code'] );
658
+		return !empty($this->discounts['discount_code']);
659 659
 	}
660 660
 
661 661
 	/**
@@ -712,13 +712,13 @@  discard block
 block discarded – undo
712 712
 	 */
713 713
 	public function process_fees() {
714 714
 
715
-		$fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this );
715
+		$fees_processor = new GetPaid_Payment_Form_Submission_Fees($this);
716 716
 
717
-		foreach ( $fees_processor->fees as $fee ) {
718
-			$this->add_fee( $fee );
717
+		foreach ($fees_processor->fees as $fee) {
718
+			$this->add_fee($fee);
719 719
 		}
720 720
 
721
-		do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) );
721
+		do_action_ref_array('getpaid_submissions_process_fees', array(&$this));
722 722
 	}
723 723
 
724 724
 	/**
@@ -727,17 +727,17 @@  discard block
 block discarded – undo
727 727
 	 * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required.
728 728
 	 * @since 1.0.19
729 729
 	 */
730
-	public function add_fee( $fee ) {
730
+	public function add_fee($fee) {
731 731
 
732
-		if ( $fee['name'] == 'shipping' ) {
733
-			$this->totals['shipping']['initial']   += wpinv_sanitize_amount( $fee['initial_fee'] );
734
-			$this->totals['shipping']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] );
732
+		if ($fee['name'] == 'shipping') {
733
+			$this->totals['shipping']['initial']   += wpinv_sanitize_amount($fee['initial_fee']);
734
+			$this->totals['shipping']['recurring'] += wpinv_sanitize_amount($fee['recurring_fee']);
735 735
 			return;
736 736
 		}
737 737
 
738
-		$this->fees[ $fee['name'] ]         = $fee;
739
-		$this->totals['fees']['initial']   += wpinv_sanitize_amount( $fee['initial_fee'] );
740
-		$this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] );
738
+		$this->fees[$fee['name']]         = $fee;
739
+		$this->totals['fees']['initial']   += wpinv_sanitize_amount($fee['initial_fee']);
740
+		$this->totals['fees']['recurring'] += wpinv_sanitize_amount($fee['recurring_fee']);
741 741
 
742 742
 	}
743 743
 
@@ -746,15 +746,15 @@  discard block
 block discarded – undo
746 746
 	 *
747 747
 	 * @since 1.0.19
748 748
 	 */
749
-	public function remove_fee( $name ) {
749
+	public function remove_fee($name) {
750 750
 
751
-		if ( isset( $this->fees[ $name ] ) ) {
752
-			$this->totals['fees']['initial']   -= $this->fees[ $name ]['initial_fee'];
753
-			$this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee'];
754
-			unset( $this->fees[ $name ] );
751
+		if (isset($this->fees[$name])) {
752
+			$this->totals['fees']['initial']   -= $this->fees[$name]['initial_fee'];
753
+			$this->totals['fees']['recurring'] -= $this->fees[$name]['recurring_fee'];
754
+			unset($this->fees[$name]);
755 755
 		}
756 756
 
757
-		if ( 'shipping' == $name ) {
757
+		if ('shipping' == $name) {
758 758
 			$this->totals['shipping']['initial']   = 0;
759 759
 			$this->totals['shipping']['recurring'] = 0;
760 760
 		}
@@ -795,7 +795,7 @@  discard block
 block discarded – undo
795 795
 	 * @since 1.0.19
796 796
 	 */
797 797
 	public function has_fees() {
798
-		return count( $this->fees ) !== 0;
798
+		return count($this->fees) !== 0;
799 799
 	}
800 800
 
801 801
 	/*
@@ -831,7 +831,7 @@  discard block
 block discarded – undo
831 831
 	 * @since 1.0.19
832 832
 	 */
833 833
 	public function has_shipping() {
834
-		return apply_filters( 'getpaid_payment_form_has_shipping', false, $this );
834
+		return apply_filters('getpaid_payment_form_has_shipping', false, $this);
835 835
 	}
836 836
 
837 837
 	/**
@@ -841,7 +841,7 @@  discard block
 block discarded – undo
841 841
 	 * @since 1.0.19
842 842
 	 */
843 843
 	public function is_initial_fetch() {
844
-		return empty( $this->data['initial_state'] );
844
+		return empty($this->data['initial_state']);
845 845
 	}
846 846
 
847 847
 	/**
@@ -851,7 +851,7 @@  discard block
 block discarded – undo
851 851
 	 */
852 852
 	public function get_total() {
853 853
 		$total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() + $this->get_shipping() - $this->get_discount();
854
-		return max( $total, 0 );
854
+		return max($total, 0);
855 855
 	}
856 856
 
857 857
 	/**
@@ -861,7 +861,7 @@  discard block
 block discarded – undo
861 861
 	 */
862 862
 	public function get_recurring_total() {
863 863
 		$total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() + $this->get_recurring_shipping() - $this->get_recurring_discount();
864
-		return max( $total, 0 );
864
+		return max($total, 0);
865 865
 	}
866 866
 
867 867
 	/**
@@ -873,12 +873,12 @@  discard block
 block discarded – undo
873 873
 		$initial   = $this->get_total();
874 874
 		$recurring = $this->get_recurring_total();
875 875
 
876
-		if ( $this->has_recurring == 0 ) {
876
+		if ($this->has_recurring == 0) {
877 877
 			$recurring = 0;
878 878
 		}
879 879
 
880 880
 		$collect = $initial > 0 || $recurring > 0;
881
-		return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this  );
881
+		return apply_filters('getpaid_submission_should_collect_payment_details', $collect, $this);
882 882
 	}
883 883
 
884 884
 	/**
@@ -887,7 +887,7 @@  discard block
 block discarded – undo
887 887
 	 * @since 1.0.19
888 888
 	 */
889 889
 	public function get_billing_email() {
890
-		return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this  );
890
+		return apply_filters('getpaid_get_submission_billing_email', $this->get_field('billing_email'), $this);
891 891
 	}
892 892
 
893 893
 	/**
@@ -897,7 +897,7 @@  discard block
 block discarded – undo
897 897
 	 */
898 898
 	public function has_billing_email() {
899 899
 		$billing_email = $this->get_billing_email();
900
-		return ! empty( $billing_email ) && is_email( $billing_email );
900
+		return !empty($billing_email) && is_email($billing_email);
901 901
 	}
902 902
 
903 903
 	/**
@@ -927,8 +927,8 @@  discard block
 block discarded – undo
927 927
 	 * @since 1.0.19
928 928
 	 * @return mixed|null
929 929
 	 */
930
-	public function get_field( $field, $sub_array_key = null ) {
931
-		return getpaid_get_array_field( $this->data, $field, $sub_array_key );
930
+	public function get_field($field, $sub_array_key = null) {
931
+		return getpaid_get_array_field($this->data, $field, $sub_array_key);
932 932
 	}
933 933
 
934 934
 	/**
@@ -936,8 +936,8 @@  discard block
 block discarded – undo
936 936
 	 *
937 937
 	 * @since 1.0.19
938 938
 	 */
939
-	public function is_required_field_set( $field ) {
940
-		return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] );
939
+	public function is_required_field_set($field) {
940
+		return empty($field['required']) || !empty($this->data[$field['id']]);
941 941
 	}
942 942
 
943 943
 	/**
@@ -945,8 +945,8 @@  discard block
 block discarded – undo
945 945
 	 *
946 946
 	 * @since 1.0.19
947 947
 	 */
948
-	public function format_amount( $amount ) {
949
-		return wpinv_price( $amount, $this->get_currency() );
948
+	public function format_amount($amount) {
949
+		return wpinv_price($amount, $this->get_currency());
950 950
 	}
951 951
 
952 952
 }
Please login to merge, or discard this patch.
admin/meta-boxes/class-getpaid-meta-box-invoice-shipping-address.php 1 patch
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
  *
7 7
  */
8 8
 
9
-if ( ! defined( 'ABSPATH' ) ) {
9
+if (!defined('ABSPATH')) {
10 10
 	exit; // Exit if accessed directly
11 11
 }
12 12
 
@@ -20,13 +20,13 @@  discard block
 block discarded – undo
20 20
 	 *
21 21
 	 * @param WP_Post $post
22 22
 	 */
23
-	public static function output( $post ) {
23
+	public static function output($post) {
24 24
 
25 25
 		// Retrieve shipping address.
26
-		$shipping_address = get_post_meta( $post->ID, 'shipping_address', true );
26
+		$shipping_address = get_post_meta($post->ID, 'shipping_address', true);
27 27
 
28 28
 		// Abort if it is invalid.
29
-		if ( ! is_array( $shipping_address ) ) {
29
+		if (!is_array($shipping_address)) {
30 30
 			return;
31 31
 		}
32 32
 
@@ -34,29 +34,29 @@  discard block
 block discarded – undo
34 34
 
35 35
 		<div class="bsui">
36 36
 
37
-			<?php if ( ! empty( $shipping_address['method'] ) ) : ?>
37
+			<?php if (!empty($shipping_address['method'])) : ?>
38 38
 
39 39
 				<div class="form-group form-row" style="color: green;">
40 40
 					<div class="col">
41
-						<span style="font-weight: 600"><?php esc_html_e( 'Shipping Method', 'invoicing' ); ?>:</span>
41
+						<span style="font-weight: 600"><?php esc_html_e('Shipping Method', 'invoicing'); ?>:</span>
42 42
 					</div>
43 43
 					<div class="col">
44
-						<?php echo wp_kses_post( $shipping_address['method'] ); ?>
44
+						<?php echo wp_kses_post($shipping_address['method']); ?>
45 45
 					</div>
46 46
 				</div>
47 47
 
48 48
 			<?php endif; ?>
49 49
 
50
-			<?php foreach ( getpaid_user_address_fields() as $key => $label ) : ?>
50
+			<?php foreach (getpaid_user_address_fields() as $key => $label) : ?>
51 51
 
52
-					<?php if ( ! empty( $shipping_address[ $key ] ) ) : ?>
52
+					<?php if (!empty($shipping_address[$key])) : ?>
53 53
 
54 54
 						<div class="form-group form-row">
55 55
 							<div class="col">
56
-								<span style="font-weight: 600"><?php echo esc_html( $label ); ?>:</span>
56
+								<span style="font-weight: 600"><?php echo esc_html($label); ?>:</span>
57 57
 							</div>
58 58
 							<div class="col">
59
-								<?php echo self::prepare_for_display( $shipping_address, $key ); ?>
59
+								<?php echo self::prepare_for_display($shipping_address, $key); ?>
60 60
 							</div>
61 61
 						</div>
62 62
 
@@ -77,21 +77,21 @@  discard block
 block discarded – undo
77 77
 	 * @param string $key
78 78
 	 * @return string
79 79
 	 */
80
-	public static function prepare_for_display( $address, $key ) {
80
+	public static function prepare_for_display($address, $key) {
81 81
 
82 82
 		// Prepare the value.
83
-		$value = $address[ $key ];
83
+		$value = $address[$key];
84 84
 
85
-		if ( $key == 'country' ) {
86
-			$value = wpinv_country_name( $value );
85
+		if ($key == 'country') {
86
+			$value = wpinv_country_name($value);
87 87
 		}
88 88
 
89
-		if ( $key == 'state' ) {
90
-			$country = isset( $address[ 'country' ] ) ? $address[ 'country' ] : wpinv_get_default_country();
91
-			$value = wpinv_state_name( $value, $country );
89
+		if ($key == 'state') {
90
+			$country = isset($address['country']) ? $address['country'] : wpinv_get_default_country();
91
+			$value = wpinv_state_name($value, $country);
92 92
 		}
93 93
 
94
-		return esc_html( $value );
94
+		return esc_html($value);
95 95
 
96 96
 	}
97 97
 
Please login to merge, or discard this patch.
includes/payments/class-getpaid-checkout.php 1 patch
Spacing   +134 added lines, -134 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
  * Main Checkout Class.
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
 	 * 
23 23
 	 * @param GetPaid_Payment_Form_Submission $submission
24 24
 	 */
25
-	public function __construct( $submission ) {
25
+	public function __construct($submission) {
26 26
 		$this->payment_form_submission = $submission;
27 27
 	}
28 28
 
@@ -38,22 +38,22 @@  discard block
 block discarded – undo
38 38
 		// Prepare the invoice.
39 39
 		$items      = $this->get_submission_items();
40 40
 		$invoice    = $this->get_submission_invoice();
41
-		$invoice    = $this->process_submission_invoice( $invoice, $items );
41
+		$invoice    = $this->process_submission_invoice($invoice, $items);
42 42
 		$prepared   = $this->prepare_submission_data_for_saving();
43 43
 
44
-		$this->prepare_billing_info( $invoice );
44
+		$this->prepare_billing_info($invoice);
45 45
 
46
-		$shipping   = $this->prepare_shipping_info( $invoice );
46
+		$shipping = $this->prepare_shipping_info($invoice);
47 47
 
48 48
 		// Save the invoice.
49
-		$invoice->set_is_viewed( true );
49
+		$invoice->set_is_viewed(true);
50 50
 		$invoice->recalculate_total();
51 51
         $invoice->save();
52 52
 
53
-		do_action( 'getpaid_checkout_invoice_updated', $invoice );
53
+		do_action('getpaid_checkout_invoice_updated', $invoice);
54 54
 
55 55
 		// Send to the gateway.
56
-		$this->post_process_submission( $invoice, $prepared, $shipping );
56
+		$this->post_process_submission($invoice, $prepared, $shipping);
57 57
 	}
58 58
 
59 59
 	/**
@@ -66,34 +66,34 @@  discard block
 block discarded – undo
66 66
 		$data       = $submission->get_data();
67 67
 
68 68
 		// Do we have an error?
69
-        if ( ! empty( $submission->last_error ) ) {
70
-			wp_send_json_error( $submission->last_error );
69
+        if (!empty($submission->last_error)) {
70
+			wp_send_json_error($submission->last_error);
71 71
         }
72 72
 
73 73
 		// We need a billing email.
74
-        if ( ! $submission->has_billing_email() ) {
75
-            wp_send_json_error( __( 'Provide a valid billing email.', 'invoicing' ) );
74
+        if (!$submission->has_billing_email()) {
75
+            wp_send_json_error(__('Provide a valid billing email.', 'invoicing'));
76 76
 		}
77 77
 
78 78
 		// Non-recurring gateways should not be allowed to process recurring invoices.
79
-		if ( $submission->should_collect_payment_details() && $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) {
80
-			wp_send_json_error( __( 'The selected payment gateway does not support subscription payments.', 'invoicing' ) );
79
+		if ($submission->should_collect_payment_details() && $submission->has_recurring && !wpinv_gateway_support_subscription($data['wpi-gateway'])) {
80
+			wp_send_json_error(__('The selected payment gateway does not support subscription payments.', 'invoicing'));
81 81
 		}
82 82
 
83 83
 		// Ensure the gateway is active.
84
-		if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) {
85
-			wp_send_json_error( __( 'The selected payment gateway is not active', 'invoicing' ) );
84
+		if ($submission->should_collect_payment_details() && !wpinv_is_gateway_active($data['wpi-gateway'])) {
85
+			wp_send_json_error(__('The selected payment gateway is not active', 'invoicing'));
86 86
 		}
87 87
 
88 88
 		// Clear any existing errors.
89 89
 		wpinv_clear_errors();
90 90
 
91 91
 		// Allow themes and plugins to hook to errors
92
-		do_action( 'getpaid_checkout_error_checks', $submission );
92
+		do_action('getpaid_checkout_error_checks', $submission);
93 93
 
94 94
 		// Do we have any errors?
95
-        if ( wpinv_get_errors() ) {
96
-            wp_send_json_error( getpaid_get_errors_html() );
95
+        if (wpinv_get_errors()) {
96
+            wp_send_json_error(getpaid_get_errors_html());
97 97
 		}
98 98
 
99 99
 	}
@@ -108,8 +108,8 @@  discard block
 block discarded – undo
108 108
 		$items = $this->payment_form_submission->get_items();
109 109
 
110 110
         // Ensure that we have items.
111
-        if ( empty( $items ) && ! $this->payment_form_submission->has_fees() ) {
112
-            wp_send_json_error( __( 'Please provide at least one item or amount.', 'invoicing' ) );
111
+        if (empty($items) && !$this->payment_form_submission->has_fees()) {
112
+            wp_send_json_error(__('Please provide at least one item or amount.', 'invoicing'));
113 113
 		}
114 114
 
115 115
 		return $items;
@@ -123,17 +123,17 @@  discard block
 block discarded – undo
123 123
 	protected function get_submission_invoice() {
124 124
 		$submission = $this->payment_form_submission;
125 125
 
126
-		if ( ! $submission->has_invoice() ) {
126
+		if (!$submission->has_invoice()) {
127 127
 			$invoice = new WPInv_Invoice();
128
-			$invoice->set_created_via( 'payment_form' );
128
+			$invoice->set_created_via('payment_form');
129 129
 			return $invoice;
130 130
         }
131 131
 
132 132
 		$invoice = $submission->get_invoice();
133 133
 
134 134
 		// Make sure that it is neither paid or refunded.
135
-		if ( $invoice->is_paid() || $invoice->is_refunded() ) {
136
-			wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) );
135
+		if ($invoice->is_paid() || $invoice->is_refunded()) {
136
+			wp_send_json_error(__('This invoice has already been paid for.', 'invoicing'));
137 137
 		}
138 138
 
139 139
 		return $invoice;
@@ -146,33 +146,33 @@  discard block
 block discarded – undo
146 146
 	 * @param GetPaid_Form_Item[] $items
147 147
 	 * @return WPInv_Invoice
148 148
 	 */
149
-	protected function process_submission_invoice( $invoice, $items ) {
149
+	protected function process_submission_invoice($invoice, $items) {
150 150
 
151 151
 		$submission = $this->payment_form_submission;
152 152
 
153 153
 		// Set-up the invoice details.
154
-		$invoice->set_email( sanitize_email( $submission->get_billing_email() ) );
155
-		$invoice->set_user_id( $this->get_submission_customer() );
156
-		$invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) );
157
-        $invoice->set_items( $items );
158
-        $invoice->set_fees( $submission->get_fees() );
159
-        $invoice->set_taxes( $submission->get_taxes() );
160
-		$invoice->set_discounts( $submission->get_discounts() );
161
-		$invoice->set_gateway( $submission->get_field( 'wpi-gateway' ) );
162
-		$invoice->set_currency( $submission->get_currency() );
163
-
164
-		if ( $submission->has_shipping() ) {
165
-			$invoice->set_shipping( $submission->get_shipping() );
154
+		$invoice->set_email(sanitize_email($submission->get_billing_email()));
155
+		$invoice->set_user_id($this->get_submission_customer());
156
+		$invoice->set_payment_form(absint($submission->get_payment_form()->get_id()));
157
+        $invoice->set_items($items);
158
+        $invoice->set_fees($submission->get_fees());
159
+        $invoice->set_taxes($submission->get_taxes());
160
+		$invoice->set_discounts($submission->get_discounts());
161
+		$invoice->set_gateway($submission->get_field('wpi-gateway'));
162
+		$invoice->set_currency($submission->get_currency());
163
+
164
+		if ($submission->has_shipping()) {
165
+			$invoice->set_shipping($submission->get_shipping());
166 166
 		}
167 167
 
168
-		$address_confirmed = $submission->get_field( 'confirm-address' );
169
-		$invoice->set_address_confirmed( ! empty( $address_confirmed ) );
168
+		$address_confirmed = $submission->get_field('confirm-address');
169
+		$invoice->set_address_confirmed(!empty($address_confirmed));
170 170
 
171
-		if ( $submission->has_discount_code() ) {
172
-            $invoice->set_discount_code( $submission->get_discount_code() );
171
+		if ($submission->has_discount_code()) {
172
+            $invoice->set_discount_code($submission->get_discount_code());
173 173
 		}
174 174
 
175
-		getpaid_maybe_add_default_address( $invoice );
175
+		getpaid_maybe_add_default_address($invoice);
176 176
 		return $invoice;
177 177
 	}
178 178
 
@@ -185,33 +185,33 @@  discard block
 block discarded – undo
185 185
 		$submission = $this->payment_form_submission;
186 186
 
187 187
 		// If this is an existing invoice...
188
-		if ( $submission->has_invoice() ) {
188
+		if ($submission->has_invoice()) {
189 189
 			return $submission->get_invoice()->get_user_id();
190 190
 		}
191 191
 
192 192
 		// (Maybe) create the user.
193 193
         $user = get_current_user_id();
194 194
 
195
-        if ( empty( $user ) ) {
196
-            $user = get_user_by( 'email', $submission->get_billing_email() );
195
+        if (empty($user)) {
196
+            $user = get_user_by('email', $submission->get_billing_email());
197 197
         }
198 198
 
199
-        if ( empty( $user ) ) {
200
-            $user = wpinv_create_user( $submission->get_billing_email() );
199
+        if (empty($user)) {
200
+            $user = wpinv_create_user($submission->get_billing_email());
201 201
 
202 202
 			// (Maybe) send new user notification.
203
-			$should_send_notification = wpinv_get_option( 'disable_new_user_emails' );
204
-			if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ), $user ) ) {
205
-				wp_send_new_user_notifications( $user, 'user' );
203
+			$should_send_notification = wpinv_get_option('disable_new_user_emails');
204
+			if (!empty($user) && is_numeric($user) && apply_filters('getpaid_send_new_user_notification', empty($should_send_notification), $user)) {
205
+				wp_send_new_user_notifications($user, 'user');
206 206
 			}
207 207
 
208 208
         }
209 209
 
210
-        if ( is_wp_error( $user ) ) {
211
-            wp_send_json_error( $user->get_error_message() );
210
+        if (is_wp_error($user)) {
211
+            wp_send_json_error($user->get_error_message());
212 212
         }
213 213
 
214
-        if ( is_numeric( $user ) ) {
214
+        if (is_numeric($user)) {
215 215
             return $user;
216 216
 		}
217 217
 
@@ -235,24 +235,24 @@  discard block
 block discarded – undo
235 235
 		);
236 236
 
237 237
         // Raw submission details.
238
-		$data     = $submission->get_data();
238
+		$data = $submission->get_data();
239 239
 
240 240
 		// Loop through the submitted details.
241
-        foreach ( $submission->get_payment_form()->get_elements() as $field ) {
241
+        foreach ($submission->get_payment_form()->get_elements() as $field) {
242 242
 
243 243
 			// Skip premade fields.
244
-            if ( ! empty( $field['premade'] ) ) {
244
+            if (!empty($field['premade'])) {
245 245
                 continue;
246 246
             }
247 247
 
248 248
 			// Ensure address is provided.
249
-			if ( $field['type'] == 'address' ) {
250
-                $address_type = isset( $field['address_type'] ) && 'shipping' === $field['address_type'] ? 'shipping' : 'billing';
249
+			if ($field['type'] == 'address') {
250
+                $address_type = isset($field['address_type']) && 'shipping' === $field['address_type'] ? 'shipping' : 'billing';
251 251
 
252
-				foreach ( $field['fields'] as $address_field ) {
252
+				foreach ($field['fields'] as $address_field) {
253 253
 
254
-					if ( ! empty( $address_field['visible'] ) && ! empty( $address_field['required'] ) && '' === trim( $_POST[ $address_type ][ $address_field['name'] ] ) ) {
255
-						wp_send_json_error( __( 'Please fill all required fields.', 'invoicing' ) );
254
+					if (!empty($address_field['visible']) && !empty($address_field['required']) && '' === trim($_POST[$address_type][$address_field['name']])) {
255
+						wp_send_json_error(__('Please fill all required fields.', 'invoicing'));
256 256
 					}
257 257
 
258 258
 				}
@@ -260,49 +260,49 @@  discard block
 block discarded – undo
260 260
             }
261 261
 
262 262
             // If it is required and not set, abort.
263
-            if ( ! $submission->is_required_field_set( $field ) ) {
264
-                wp_send_json_error( __( 'Please fill all required fields.', 'invoicing' ) );
263
+            if (!$submission->is_required_field_set($field)) {
264
+                wp_send_json_error(__('Please fill all required fields.', 'invoicing'));
265 265
             }
266 266
 
267 267
             // Handle misc fields.
268
-            if ( isset( $data[ $field['id'] ] ) ) {
268
+            if (isset($data[$field['id']])) {
269 269
 
270 270
 				// Uploads.
271
-				if ( $field['type'] == 'file_upload' ) {
272
-					$max_file_num = empty( $field['max_file_num'] ) ? 1 : absint( $field['max_file_num'] );
271
+				if ($field['type'] == 'file_upload') {
272
+					$max_file_num = empty($field['max_file_num']) ? 1 : absint($field['max_file_num']);
273 273
 
274
-					if ( count( $data[ $field['id'] ] ) > $max_file_num ) {
275
-						wp_send_json_error( __( 'Maximum number of allowed files exceeded.', 'invoicing' ) );
274
+					if (count($data[$field['id']]) > $max_file_num) {
275
+						wp_send_json_error(__('Maximum number of allowed files exceeded.', 'invoicing'));
276 276
 					}
277 277
 
278 278
 					$value = array();
279 279
 
280
-					foreach ( $data[ $field['id'] ] as $url => $name ) {
280
+					foreach ($data[$field['id']] as $url => $name) {
281 281
 						$value[] = sprintf(
282 282
 							'<a href="%s" target="_blank">%s</a>',
283
-							esc_url_raw( $url ),
284
-							esc_html( $name )
283
+							esc_url_raw($url),
284
+							esc_html($name)
285 285
 						);
286 286
 					}
287 287
 
288
-					$value = implode( ' | ', $value );
288
+					$value = implode(' | ', $value);
289 289
 
290
-				} else if ( $field['type'] == 'checkbox' ) {
291
-					$value = isset( $data[ $field['id'] ] ) ? __( 'Yes', 'invoicing' ) : __( 'No', 'invoicing' );
290
+				} else if ($field['type'] == 'checkbox') {
291
+					$value = isset($data[$field['id']]) ? __('Yes', 'invoicing') : __('No', 'invoicing');
292 292
 				} else {
293
-					$value = wp_kses_post( $data[ $field['id'] ] );
293
+					$value = wp_kses_post($data[$field['id']]);
294 294
 				}
295 295
 
296 296
                 $label = $field['id'];
297 297
 
298
-                if ( isset( $field['label'] ) ) {
298
+                if (isset($field['label'])) {
299 299
                     $label = $field['label'];
300 300
                 }
301 301
 
302
-				if ( ! empty( $field['add_meta'] ) ) {
303
-					$prepared['meta'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value );
302
+				if (!empty($field['add_meta'])) {
303
+					$prepared['meta'][wpinv_clean($label)] = wp_kses_post_deep($value);
304 304
 				}
305
-				$prepared['all'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value );
305
+				$prepared['all'][wpinv_clean($label)] = wp_kses_post_deep($value);
306 306
 
307 307
             }
308 308
 
@@ -319,30 +319,30 @@  discard block
 block discarded – undo
319 319
 	 * @param WPInv_Invoice $invoice
320 320
 	 * @param string $type
321 321
      */
322
-    public function prepare_address_details( $invoice, $type = 'billing' ) {
322
+    public function prepare_address_details($invoice, $type = 'billing') {
323 323
 
324 324
 		$data     = $this->payment_form_submission->get_data();
325
-		$type     = sanitize_key( $type );
325
+		$type     = sanitize_key($type);
326 326
 		$address  = array();
327 327
 		$prepared = array();
328 328
 
329
-		if ( ! empty( $data[ $type ] ) ) {
330
-			$address = $data[ $type ];
329
+		if (!empty($data[$type])) {
330
+			$address = $data[$type];
331 331
 		}
332 332
 
333 333
 		// Clean address details.
334
-		foreach ( $address as $key => $value ) {
335
-			$key             = sanitize_key( $key );
336
-			$key             = str_replace( 'wpinv_', '', $key );
337
-			$value           = wpinv_clean( $value );
338
-			$prepared[ $key] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice );
334
+		foreach ($address as $key => $value) {
335
+			$key             = sanitize_key($key);
336
+			$key             = str_replace('wpinv_', '', $key);
337
+			$value           = wpinv_clean($value);
338
+			$prepared[$key] = apply_filters("getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice);
339 339
 		}
340 340
 
341 341
 		// Filter address details.
342
-		$prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice );
342
+		$prepared = apply_filters("getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice);
343 343
 
344 344
 		// Remove non-whitelisted values.
345
-		return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY );
345
+		return array_filter($prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY);
346 346
 
347 347
 	}
348 348
 
@@ -352,12 +352,12 @@  discard block
 block discarded – undo
352 352
 	 * @return array
353 353
 	 * @param WPInv_Invoice $invoice
354 354
      */
355
-    protected function prepare_billing_info( &$invoice ) {
355
+    protected function prepare_billing_info(&$invoice) {
356 356
 
357
-		$billing_address = $this->prepare_address_details( $invoice, 'billing' );
357
+		$billing_address = $this->prepare_address_details($invoice, 'billing');
358 358
 
359 359
 		// Update the invoice with the billing details.
360
-		$invoice->set_props( $billing_address );
360
+		$invoice->set_props($billing_address);
361 361
 
362 362
 	}
363 363
 
@@ -367,15 +367,15 @@  discard block
 block discarded – undo
367 367
 	 * @return array
368 368
 	 * @param WPInv_Invoice $invoice
369 369
      */
370
-    protected function prepare_shipping_info( $invoice ) {
370
+    protected function prepare_shipping_info($invoice) {
371 371
 
372 372
 		$data = $this->payment_form_submission->get_data();
373 373
 
374
-		if ( empty( $data['same-shipping-address'] ) ) {
375
-			return $this->prepare_address_details( $invoice, 'shipping' );
374
+		if (empty($data['same-shipping-address'])) {
375
+			return $this->prepare_address_details($invoice, 'shipping');
376 376
 		}
377 377
 
378
-		return $this->prepare_address_details( $invoice, 'billing' );
378
+		return $this->prepare_address_details($invoice, 'billing');
379 379
 
380 380
 	}
381 381
 
@@ -386,42 +386,42 @@  discard block
 block discarded – undo
386 386
 	 * @param array $prepared_payment_form_data
387 387
 	 * @param array $shipping
388 388
 	 */
389
-	protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) {
389
+	protected function post_process_submission($invoice, $prepared_payment_form_data, $shipping) {
390 390
 
391 391
 		// Ensure the invoice exists.
392
-        if ( ! $invoice->exists() ) {
393
-            wp_send_json_error( __( 'An error occured while saving your invoice. Please try again.', 'invoicing' ) );
392
+        if (!$invoice->exists()) {
393
+            wp_send_json_error(__('An error occured while saving your invoice. Please try again.', 'invoicing'));
394 394
         }
395 395
 
396 396
 		// Save payment form data.
397
-		$prepared_payment_form_data = apply_filters( 'getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice );
398
-        delete_post_meta( $invoice->get_id(), 'payment_form_data' );
399
-		delete_post_meta( $invoice->get_id(), 'additional_meta_data' );
400
-		if ( ! empty( $prepared_payment_form_data ) ) {
397
+		$prepared_payment_form_data = apply_filters('getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice);
398
+        delete_post_meta($invoice->get_id(), 'payment_form_data');
399
+		delete_post_meta($invoice->get_id(), 'additional_meta_data');
400
+		if (!empty($prepared_payment_form_data)) {
401 401
 
402
-			if ( ! empty( $prepared_payment_form_data['all'] ) ) {
403
-				update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data['all'] );
402
+			if (!empty($prepared_payment_form_data['all'])) {
403
+				update_post_meta($invoice->get_id(), 'payment_form_data', $prepared_payment_form_data['all']);
404 404
 			}
405 405
 
406
-			if ( ! empty( $prepared_payment_form_data['meta'] ) ) {
407
-				update_post_meta( $invoice->get_id(), 'additional_meta_data', $prepared_payment_form_data['meta'] );
406
+			if (!empty($prepared_payment_form_data['meta'])) {
407
+				update_post_meta($invoice->get_id(), 'additional_meta_data', $prepared_payment_form_data['meta']);
408 408
 			}
409 409
 
410 410
 		}
411 411
 
412 412
 		// Save payment form data.
413
-		$shipping = apply_filters( 'getpaid_checkout_shipping_details', $shipping, $this->payment_form_submission );
414
-        if ( ! empty( $shipping ) ) {
415
-            update_post_meta( $invoice->get_id(), 'shipping_address', $shipping );
413
+		$shipping = apply_filters('getpaid_checkout_shipping_details', $shipping, $this->payment_form_submission);
414
+        if (!empty($shipping)) {
415
+            update_post_meta($invoice->get_id(), 'shipping_address', $shipping);
416 416
 		}
417 417
 
418 418
 		// Backwards compatibility.
419
-        add_filter( 'wp_redirect', array( $this, 'send_redirect_response' ) );
419
+        add_filter('wp_redirect', array($this, 'send_redirect_response'));
420 420
 
421
-		$this->process_payment( $invoice );
421
+		$this->process_payment($invoice);
422 422
 
423 423
         // If we are here, there was an error.
424
-		wpinv_send_back_to_checkout( $invoice );
424
+		wpinv_send_back_to_checkout($invoice);
425 425
 
426 426
 	}
427 427
 
@@ -430,41 +430,41 @@  discard block
 block discarded – undo
430 430
 	 *
431 431
 	 * @param WPInv_Invoice $invoice
432 432
 	 */
433
-	protected function process_payment( $invoice ) {
433
+	protected function process_payment($invoice) {
434 434
 
435 435
 		// Clear any checkout errors.
436 436
 		wpinv_clear_errors();
437 437
 
438 438
 		// No need to send free invoices to the gateway.
439
-		if ( $invoice->is_free() ) {
440
-			$this->process_free_payment( $invoice );
439
+		if ($invoice->is_free()) {
440
+			$this->process_free_payment($invoice);
441 441
 		}
442 442
 
443 443
 		$submission = $this->payment_form_submission;
444 444
 
445 445
 		// Fires before sending to the gateway.
446
-		do_action( 'getpaid_checkout_before_gateway', $invoice, $submission );
446
+		do_action('getpaid_checkout_before_gateway', $invoice, $submission);
447 447
 
448 448
 		// Allow the sumission data to be modified before it is sent to the gateway.
449 449
 		$submission_data    = $submission->get_data();
450
-		$submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice );
451
-		$submission_data    = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice );
450
+		$submission_gateway = apply_filters('getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice);
451
+		$submission_data    = apply_filters('getpaid_gateway_submission_data', $submission_data, $submission, $invoice);
452 452
 
453 453
 		// Validate the currency.
454
-		if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) {
455
-			wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support this currency', 'invoicing' ) );
454
+		if (!apply_filters("getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency())) {
455
+			wpinv_set_error('invalid_currency', __('The chosen payment gateway does not support this currency', 'invoicing'));
456 456
 		}
457 457
 
458 458
 		// Check to see if we have any errors.
459
-		if ( wpinv_get_errors() ) {
460
-			wpinv_send_back_to_checkout( $invoice );
459
+		if (wpinv_get_errors()) {
460
+			wpinv_send_back_to_checkout($invoice);
461 461
 		}
462 462
 
463 463
 		// Send info to the gateway for payment processing
464
-		do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission );
464
+		do_action("getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission);
465 465
 
466 466
 		// Backwards compatibility.
467
-		wpinv_send_to_gateway( $submission_gateway, $invoice );
467
+		wpinv_send_to_gateway($submission_gateway, $invoice);
468 468
 
469 469
 	}
470 470
 
@@ -473,12 +473,12 @@  discard block
 block discarded – undo
473 473
 	 *
474 474
 	 * @param WPInv_Invoice $invoice
475 475
 	 */
476
-	protected function process_free_payment( $invoice ) {
476
+	protected function process_free_payment($invoice) {
477 477
 
478
-		$invoice->set_gateway( 'none' );
479
-		$invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true );
478
+		$invoice->set_gateway('none');
479
+		$invoice->add_note(__("This is a free invoice and won't be sent to the payment gateway", 'invoicing'), false, false, true);
480 480
 		$invoice->mark_paid();
481
-		wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
481
+		wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key()));
482 482
 
483 483
 	}
484 484
 
@@ -486,9 +486,9 @@  discard block
 block discarded – undo
486 486
      * Sends a redrect response to payment details.
487 487
      *
488 488
      */
489
-    public function send_redirect_response( $url ) {
490
-        $url = urlencode( $url );
491
-        wp_send_json_success( $url );
489
+    public function send_redirect_response($url) {
490
+        $url = urlencode($url);
491
+        wp_send_json_success($url);
492 492
     }
493 493
 
494 494
 }
Please login to merge, or discard this patch.
includes/wpinv-address-functions.php 1 patch
Spacing   +145 added lines, -145 removed lines patch added patch discarded remove patch
@@ -7,15 +7,15 @@  discard block
 block discarded – undo
7 7
  */
8 8
  
9 9
 // MUST have WordPress.
10
-if ( !defined( 'WPINC' ) ) {
11
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
10
+if (!defined('WPINC')) {
11
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
12 12
 }
13 13
 
14 14
 
15 15
 function wpinv_get_default_country() {
16
-	$country = wpinv_get_option( 'default_country', 'UK' );
16
+	$country = wpinv_get_option('default_country', 'UK');
17 17
 
18
-	return apply_filters( 'wpinv_default_country', $country );
18
+	return apply_filters('wpinv_default_country', $country);
19 19
 }
20 20
 
21 21
 /**
@@ -23,8 +23,8 @@  discard block
 block discarded – undo
23 23
  *
24 24
  * @return string
25 25
  */
26
-function getpaid_get_ip_country( $ip_address = '' ) {
27
-    $country = GetPaid_Geolocation::geolocate_ip( $ip_address, true );
26
+function getpaid_get_ip_country($ip_address = '') {
27
+    $country = GetPaid_Geolocation::geolocate_ip($ip_address, true);
28 28
     return $country['country'];
29 29
 }
30 30
 
@@ -34,59 +34,59 @@  discard block
 block discarded – undo
34 34
  * @param string $country The country code to sanitize
35 35
  * @return array
36 36
  */
37
-function wpinv_sanitize_country( $country ) {
37
+function wpinv_sanitize_country($country) {
38 38
 
39 39
 	// Enure the country is specified
40
-    if ( empty( $country ) ) {
40
+    if (empty($country)) {
41 41
         $country = wpinv_get_default_country();
42 42
     }
43
-    return trim( wpinv_utf8_strtoupper( $country ) );
43
+    return trim(wpinv_utf8_strtoupper($country));
44 44
 
45 45
 }
46 46
 
47
-function wpinv_is_base_country( $country ) {
47
+function wpinv_is_base_country($country) {
48 48
     $base_country = wpinv_get_default_country();
49 49
     
50
-    if ( $base_country === 'UK' ) {
50
+    if ($base_country === 'UK') {
51 51
         $base_country = 'GB';
52 52
     }
53
-    if ( $country == 'UK' ) {
53
+    if ($country == 'UK') {
54 54
         $country = 'GB';
55 55
     }
56 56
 
57
-    return ( $country && $country === $base_country ) ? true : false;
57
+    return ($country && $country === $base_country) ? true : false;
58 58
 }
59 59
 
60
-function wpinv_country_name( $country_code = '' ) { 
60
+function wpinv_country_name($country_code = '') { 
61 61
     $countries = wpinv_get_country_list();
62 62
     $country_code = $country_code == 'UK' ? 'GB' : $country_code;
63
-    $country = isset( $countries[$country_code] ) ? $countries[$country_code] : $country_code;
63
+    $country = isset($countries[$country_code]) ? $countries[$country_code] : $country_code;
64 64
 
65
-    return apply_filters( 'wpinv_country_name', $country, $country_code );
65
+    return apply_filters('wpinv_country_name', $country, $country_code);
66 66
 }
67 67
 
68 68
 function wpinv_get_default_state() {
69
-	$state = wpinv_get_option( 'default_state', '' );
69
+	$state = wpinv_get_option('default_state', '');
70 70
 
71
-	return apply_filters( 'wpinv_default_state', $state );
71
+	return apply_filters('wpinv_default_state', $state);
72 72
 }
73 73
 
74
-function wpinv_state_name( $state_code = '', $country_code = '' ) {
74
+function wpinv_state_name($state_code = '', $country_code = '') {
75 75
     $state = $state_code;
76 76
     
77
-    if ( !empty( $country_code ) ) {
78
-        $states = wpinv_get_country_states( $country_code );
77
+    if (!empty($country_code)) {
78
+        $states = wpinv_get_country_states($country_code);
79 79
         
80
-        $state = !empty( $states ) && isset( $states[$state_code] ) ? $states[$state_code] : $state;
80
+        $state = !empty($states) && isset($states[$state_code]) ? $states[$state_code] : $state;
81 81
     }
82 82
 
83
-    return apply_filters( 'wpinv_state_name', $state, $state_code, $country_code );
83
+    return apply_filters('wpinv_state_name', $state, $state_code, $country_code);
84 84
 }
85 85
 
86 86
 function wpinv_store_address() {
87
-    $address = wpinv_get_option( 'store_address', '' );
87
+    $address = wpinv_get_option('store_address', '');
88 88
 
89
-    return apply_filters( 'wpinv_store_address', $address );
89
+    return apply_filters('wpinv_store_address', $address);
90 90
 }
91 91
 
92 92
 /**
@@ -94,24 +94,24 @@  discard block
 block discarded – undo
94 94
  *
95 95
  * @param WPInv_Invoice $invoice
96 96
  */
97
-function getpaid_maybe_add_default_address( &$invoice ) {
97
+function getpaid_maybe_add_default_address(&$invoice) {
98 98
 
99 99
     $user_id = $invoice->get_user_id();
100 100
 
101 101
     // Abort if the invoice belongs to no one.
102
-    if ( empty( $user_id ) ) {
102
+    if (empty($user_id)) {
103 103
         return;
104 104
     }
105 105
 
106 106
     // Fill in defaults whenever necessary.
107
-    foreach ( wpinv_get_user_address( $user_id ) as $key => $value ) {
107
+    foreach (wpinv_get_user_address($user_id) as $key => $value) {
108 108
 
109
-        if ( is_callable( $invoice, "get_$key" ) ) {
110
-            $current = call_user_func( array( $invoice, "get_$key" ) );
109
+        if (is_callable($invoice, "get_$key")) {
110
+            $current = call_user_func(array($invoice, "get_$key"));
111 111
 
112
-            if ( empty( $current ) ) {
112
+            if (empty($current)) {
113 113
                 $method = "set_$key";
114
-                $invoice->$method( $value );
114
+                $invoice->$method($value);
115 115
             }
116 116
 
117 117
         }
@@ -130,22 +130,22 @@  discard block
 block discarded – undo
130 130
     $address_fields = apply_filters(
131 131
         'getpaid_user_address_fields',
132 132
         array(
133
-            'first_name' => __( 'First Name', 'invoicing' ),
134
-            'last_name'  => __( 'Last Name', 'invoicing' ),
135
-            'address'    => __( 'Address', 'invoicing' ),
136
-            'city'       => __( 'City', 'invoicing' ),
137
-            'country'    => __( 'Country', 'invoicing' ),
138
-            'state'      => __( 'State', 'invoicing' ),
139
-            'zip'        => __( 'Zip/Postal Code', 'invoicing' ),
140
-            'phone'      => __( 'Phone Number', 'invoicing' ),
141
-            'company'    => __( 'Company', 'invoicing' ),
142
-            'company_id'    => __( 'Company ID', 'invoicing' ),
143
-            'vat_number' => __( 'VAT Number', 'invoicing' ),
133
+            'first_name' => __('First Name', 'invoicing'),
134
+            'last_name'  => __('Last Name', 'invoicing'),
135
+            'address'    => __('Address', 'invoicing'),
136
+            'city'       => __('City', 'invoicing'),
137
+            'country'    => __('Country', 'invoicing'),
138
+            'state'      => __('State', 'invoicing'),
139
+            'zip'        => __('Zip/Postal Code', 'invoicing'),
140
+            'phone'      => __('Phone Number', 'invoicing'),
141
+            'company'    => __('Company', 'invoicing'),
142
+            'company_id'    => __('Company ID', 'invoicing'),
143
+            'vat_number' => __('VAT Number', 'invoicing'),
144 144
         )
145 145
     );
146 146
 
147
-    if ( ! wpinv_use_taxes() && isset( $address_fields['vat_number'] ) ) {
148
-        unset( $address_fields['vat_number'] );
147
+    if (!wpinv_use_taxes() && isset($address_fields['vat_number'])) {
148
+        unset($address_fields['vat_number']);
149 149
     }
150 150
 
151 151
     return $address_fields;
@@ -156,8 +156,8 @@  discard block
 block discarded – undo
156 156
  * 
157 157
  * @return bool
158 158
  */
159
-function getpaid_is_address_field_whitelisted( $key ) {
160
-    return array_key_exists( $key, getpaid_user_address_fields() );
159
+function getpaid_is_address_field_whitelisted($key) {
160
+    return array_key_exists($key, getpaid_user_address_fields());
161 161
 }
162 162
 
163 163
 /**
@@ -167,24 +167,24 @@  discard block
 block discarded – undo
167 167
  *
168 168
  * @param WPInv_Invoice $invoice
169 169
  */
170
-function getpaid_save_invoice_user_address( $invoice ) {
170
+function getpaid_save_invoice_user_address($invoice) {
171 171
 
172 172
     // Retrieve the invoice.
173
-    $invoice = wpinv_get_invoice( $invoice );
173
+    $invoice = wpinv_get_invoice($invoice);
174 174
 
175 175
     // Abort if it does not exist.
176
-    if ( empty( $invoice ) || $invoice->is_renewal() ) {
176
+    if (empty($invoice) || $invoice->is_renewal()) {
177 177
         return;
178 178
     }
179 179
 
180
-    foreach ( array_keys( getpaid_user_address_fields() ) as $field ) {
180
+    foreach (array_keys(getpaid_user_address_fields()) as $field) {
181 181
 
182
-        if ( is_callable( array( $invoice, "get_$field" ) ) ) {
183
-            $value = call_user_func( array( $invoice, "get_$field" ) );
182
+        if (is_callable(array($invoice, "get_$field"))) {
183
+            $value = call_user_func(array($invoice, "get_$field"));
184 184
 
185 185
             // Only save if it is not empty.
186
-            if ( ! empty( $value ) ) {
187
-                update_user_meta( $invoice->get_user_id(), '_wpinv_' . $field, $value );
186
+            if (!empty($value)) {
187
+                update_user_meta($invoice->get_user_id(), '_wpinv_' . $field, $value);
188 188
             }
189 189
 
190 190
         }
@@ -192,7 +192,7 @@  discard block
 block discarded – undo
192 192
     }
193 193
 
194 194
 }
195
-add_action( 'getpaid_checkout_invoice_updated', 'getpaid_save_invoice_user_address' );
195
+add_action('getpaid_checkout_invoice_updated', 'getpaid_save_invoice_user_address');
196 196
 
197 197
 /**
198 198
  * Retrieves a saved user address.
@@ -201,14 +201,14 @@  discard block
 block discarded – undo
201 201
  * @param bool $with_default Whether or not we should use the default country and state.
202 202
  * @return array
203 203
  */
204
-function wpinv_get_user_address( $user_id = 0, $with_default = true ) {
204
+function wpinv_get_user_address($user_id = 0, $with_default = true) {
205 205
 
206 206
     // Prepare the user id.
207
-    $user_id   = empty( $user_id ) ? get_current_user_id() : $user_id;
208
-    $user_info = get_userdata( $user_id );
207
+    $user_id   = empty($user_id) ? get_current_user_id() : $user_id;
208
+    $user_info = get_userdata($user_id);
209 209
 
210 210
     // Abort if non exists.
211
-    if ( empty( $user_info ) ) {
211
+    if (empty($user_info)) {
212 212
         return array();
213 213
     }
214 214
 
@@ -218,13 +218,13 @@  discard block
 block discarded – undo
218 218
         'email'   => $user_info->user_email,
219 219
     );
220 220
 
221
-    foreach ( array_keys( getpaid_user_address_fields() ) as $field ) {
222
-        $address[$field] = getpaid_get_user_address_field( $user_id, $field );
221
+    foreach (array_keys(getpaid_user_address_fields()) as $field) {
222
+        $address[$field] = getpaid_get_user_address_field($user_id, $field);
223 223
     }
224 224
 
225
-    $address = array_filter( $address );
225
+    $address = array_filter($address);
226 226
 
227
-    if ( ! $with_default ) {
227
+    if (!$with_default) {
228 228
         return $address;
229 229
     }
230 230
 
@@ -235,7 +235,7 @@  discard block
 block discarded – undo
235 235
         'country'    => wpinv_get_default_country(),
236 236
     );
237 237
 
238
-    return getpaid_array_merge_if_empty( $address, $defaults );
238
+    return getpaid_array_merge_if_empty($address, $defaults);
239 239
 
240 240
 }
241 241
 
@@ -246,7 +246,7 @@  discard block
 block discarded – undo
246 246
  * @param string $field The field to use.
247 247
  * @return string|null
248 248
  */
249
-function getpaid_get_user_address_field( $user_id, $field ) {
249
+function getpaid_get_user_address_field($user_id, $field) {
250 250
 
251 251
     $prefixes = array(
252 252
         '_wpinv_',
@@ -254,15 +254,15 @@  discard block
 block discarded – undo
254 254
         ''
255 255
     );
256 256
 
257
-    foreach ( $prefixes as $prefix ) {
257
+    foreach ($prefixes as $prefix) {
258 258
 
259 259
         // Meta table.
260
-        $value = get_user_meta( $user_id, $prefix . $field, true );
260
+        $value = get_user_meta($user_id, $prefix . $field, true);
261 261
         
262 262
         // UWP table.
263
-        $value = ( empty( $value ) && function_exists( 'uwp_get_usermeta' ) ) ? uwp_get_usermeta( $user_id, $prefix . $field ) : $value;
263
+        $value = (empty($value) && function_exists('uwp_get_usermeta')) ? uwp_get_usermeta($user_id, $prefix . $field) : $value;
264 264
 
265
-        if ( ! empty( $value ) ) {
265
+        if (!empty($value)) {
266 266
             return $value;
267 267
         }
268 268
 
@@ -279,16 +279,16 @@  discard block
 block discarded – undo
279 279
  * @param string $return What to return.
280 280
  * @return array
281 281
  */
282
-function wpinv_get_continents( $return = 'all' ) {
282
+function wpinv_get_continents($return = 'all') {
283 283
 
284
-    $continents = wpinv_get_data( 'continents' );
284
+    $continents = wpinv_get_data('continents');
285 285
 
286
-    switch( $return ) {
286
+    switch ($return) {
287 287
         case 'name' :
288
-            return wp_list_pluck( $continents, 'name' );
288
+            return wp_list_pluck($continents, 'name');
289 289
             break;
290 290
         case 'countries' :
291
-            return wp_list_pluck( $continents, 'countries' );
291
+            return wp_list_pluck($continents, 'countries');
292 292
             break;
293 293
         default :
294 294
             return $continents;
@@ -304,12 +304,12 @@  discard block
 block discarded – undo
304 304
  * @param string $country Country code. If no code is specified, defaults to the default country.
305 305
  * @return string
306 306
  */
307
-function wpinv_get_continent_code_for_country( $country = false ) {
307
+function wpinv_get_continent_code_for_country($country = false) {
308 308
 
309
-    $country = wpinv_sanitize_country( $country );
309
+    $country = wpinv_sanitize_country($country);
310 310
     
311
-	foreach ( wpinv_get_continents( 'countries' ) as $continent_code => $countries ) {
312
-		if ( false !== array_search( $country, $countries, true ) ) {
311
+	foreach (wpinv_get_continents('countries') as $continent_code => $countries) {
312
+		if (false !== array_search($country, $countries, true)) {
313 313
 			return $continent_code;
314 314
 		}
315 315
 	}
@@ -325,13 +325,13 @@  discard block
 block discarded – undo
325 325
  * @param string $country Country code. If no code is specified, defaults to the default country.
326 326
  * @return array
327 327
  */
328
-function wpinv_get_country_calling_code( $country = null) {
328
+function wpinv_get_country_calling_code($country = null) {
329 329
 
330
-    $country = wpinv_sanitize_country( $country );
331
-    $codes   = wpinv_get_data( 'phone-codes' );
332
-    $code    = isset( $codes[ $country ] ) ? $codes[ $country ] : '';
330
+    $country = wpinv_sanitize_country($country);
331
+    $codes   = wpinv_get_data('phone-codes');
332
+    $code    = isset($codes[$country]) ? $codes[$country] : '';
333 333
 
334
-    if ( is_array( $code ) ) {
334
+    if (is_array($code)) {
335 335
         return $code[0];
336 336
     }
337 337
     return $code;
@@ -344,8 +344,8 @@  discard block
 block discarded – undo
344 344
  * @param bool $first_empty Whether or not the first item in the list should be empty
345 345
  * @return array
346 346
  */
347
-function wpinv_get_country_list( $first_empty = false ) {
348
-    return wpinv_maybe_add_empty_option( apply_filters( 'wpinv_countries', wpinv_get_data( 'countries' ) ), $first_empty );
347
+function wpinv_get_country_list($first_empty = false) {
348
+    return wpinv_maybe_add_empty_option(apply_filters('wpinv_countries', wpinv_get_data('countries')), $first_empty);
349 349
 }
350 350
 
351 351
 /**
@@ -355,22 +355,22 @@  discard block
 block discarded – undo
355 355
  * @param bool $first_empty Whether or not the first item in the list should be empty
356 356
  * @return array
357 357
  */
358
-function wpinv_get_country_states( $country = null, $first_empty = false ) {
358
+function wpinv_get_country_states($country = null, $first_empty = false) {
359 359
     
360 360
     // Prepare the country.
361
-    $country = wpinv_sanitize_country( $country );
361
+    $country = wpinv_sanitize_country($country);
362 362
 
363 363
     // Fetch all states.
364
-    $all_states = wpinv_get_data( 'states' );
364
+    $all_states = wpinv_get_data('states');
365 365
 
366 366
     // Fetch the specified country's states.
367
-    $states     = isset( $all_states[ $country ] ) ? $all_states[ $country ] : array() ;
368
-    $states     = apply_filters( "wpinv_{$country}_states", $states );
369
-    $states     = apply_filters( 'wpinv_country_states', $states, $country );
367
+    $states     = isset($all_states[$country]) ? $all_states[$country] : array();
368
+    $states     = apply_filters("wpinv_{$country}_states", $states);
369
+    $states     = apply_filters('wpinv_country_states', $states, $country);
370 370
 
371
-    asort( $states );
371
+    asort($states);
372 372
      
373
-    return wpinv_maybe_add_empty_option( $states, $first_empty );
373
+    return wpinv_maybe_add_empty_option($states, $first_empty);
374 374
 }
375 375
 
376 376
 /**
@@ -380,7 +380,7 @@  discard block
 block discarded – undo
380 380
  * @return array
381 381
  */
382 382
 function wpinv_get_us_states_list() {
383
-    return apply_filters( 'wpinv_usa_states', wpinv_get_country_states( 'US' ) );
383
+    return apply_filters('wpinv_usa_states', wpinv_get_country_states('US'));
384 384
 }
385 385
 
386 386
 /**
@@ -390,7 +390,7 @@  discard block
 block discarded – undo
390 390
  * @return array
391 391
  */
392 392
 function wpinv_get_canada_states_list() {
393
-    return apply_filters( 'wpinv_canada_provinces', wpinv_get_country_states( 'CA' ) );
393
+    return apply_filters('wpinv_canada_provinces', wpinv_get_country_states('CA'));
394 394
 }
395 395
 
396 396
 /**
@@ -400,7 +400,7 @@  discard block
 block discarded – undo
400 400
  * @return array
401 401
  */
402 402
 function wpinv_get_australia_states_list() {
403
-    return apply_filters( 'wpinv_australia_states', wpinv_get_country_states( 'AU' ) );
403
+    return apply_filters('wpinv_australia_states', wpinv_get_country_states('AU'));
404 404
 }
405 405
 
406 406
 /**
@@ -410,7 +410,7 @@  discard block
 block discarded – undo
410 410
  * @return array
411 411
  */
412 412
 function wpinv_get_bangladesh_states_list() {
413
-    return apply_filters( 'wpinv_bangladesh_states', wpinv_get_country_states( 'BD' ) );
413
+    return apply_filters('wpinv_bangladesh_states', wpinv_get_country_states('BD'));
414 414
 }
415 415
 
416 416
 /**
@@ -420,7 +420,7 @@  discard block
 block discarded – undo
420 420
  * @return array
421 421
  */
422 422
 function wpinv_get_brazil_states_list() {
423
-    return apply_filters( 'wpinv_brazil_states', wpinv_get_country_states( 'BR' ) );
423
+    return apply_filters('wpinv_brazil_states', wpinv_get_country_states('BR'));
424 424
 }
425 425
 
426 426
 /**
@@ -430,7 +430,7 @@  discard block
 block discarded – undo
430 430
  * @return array
431 431
  */
432 432
 function wpinv_get_bulgaria_states_list() {
433
-    return apply_filters( 'wpinv_bulgaria_states', wpinv_get_country_states( 'BG' ) );
433
+    return apply_filters('wpinv_bulgaria_states', wpinv_get_country_states('BG'));
434 434
 }
435 435
 
436 436
 /**
@@ -440,7 +440,7 @@  discard block
 block discarded – undo
440 440
  * @return array
441 441
  */
442 442
 function wpinv_get_hong_kong_states_list() {
443
-    return apply_filters( 'wpinv_hong_kong_states', wpinv_get_country_states( 'HK' ) );
443
+    return apply_filters('wpinv_hong_kong_states', wpinv_get_country_states('HK'));
444 444
 }
445 445
 
446 446
 /**
@@ -450,7 +450,7 @@  discard block
 block discarded – undo
450 450
  * @return array
451 451
  */
452 452
 function wpinv_get_hungary_states_list() {
453
-    return apply_filters( 'wpinv_hungary_states', wpinv_get_country_states( 'HU' ) );
453
+    return apply_filters('wpinv_hungary_states', wpinv_get_country_states('HU'));
454 454
 }
455 455
 
456 456
 /**
@@ -460,7 +460,7 @@  discard block
 block discarded – undo
460 460
  * @return array
461 461
  */
462 462
 function wpinv_get_japan_states_list() {
463
-    return apply_filters( 'wpinv_japan_states', wpinv_get_country_states( 'JP' ) );
463
+    return apply_filters('wpinv_japan_states', wpinv_get_country_states('JP'));
464 464
 }
465 465
 
466 466
 /**
@@ -470,7 +470,7 @@  discard block
 block discarded – undo
470 470
  * @return array
471 471
  */
472 472
 function wpinv_get_china_states_list() {
473
-    return apply_filters( 'wpinv_china_states', wpinv_get_country_states( 'CN' ) );
473
+    return apply_filters('wpinv_china_states', wpinv_get_country_states('CN'));
474 474
 }
475 475
 
476 476
 /**
@@ -480,7 +480,7 @@  discard block
 block discarded – undo
480 480
  * @return array
481 481
  */
482 482
 function wpinv_get_new_zealand_states_list() {
483
-    return apply_filters( 'wpinv_new_zealand_states', wpinv_get_country_states( 'NZ' ) );
483
+    return apply_filters('wpinv_new_zealand_states', wpinv_get_country_states('NZ'));
484 484
 }
485 485
 
486 486
 /**
@@ -490,7 +490,7 @@  discard block
 block discarded – undo
490 490
  * @return array
491 491
  */
492 492
 function wpinv_get_peru_states_list() {
493
-    return apply_filters( 'wpinv_peru_states', wpinv_get_country_states( 'PE' ) );
493
+    return apply_filters('wpinv_peru_states', wpinv_get_country_states('PE'));
494 494
 }
495 495
 
496 496
 /**
@@ -500,7 +500,7 @@  discard block
 block discarded – undo
500 500
  * @return array
501 501
  */
502 502
 function wpinv_get_indonesia_states_list() {
503
-    return apply_filters( 'wpinv_indonesia_states', wpinv_get_country_states( 'ID' ) );
503
+    return apply_filters('wpinv_indonesia_states', wpinv_get_country_states('ID'));
504 504
 }
505 505
 
506 506
 /**
@@ -510,7 +510,7 @@  discard block
 block discarded – undo
510 510
  * @return array
511 511
  */
512 512
 function wpinv_get_india_states_list() {
513
-    return apply_filters( 'wpinv_india_states', wpinv_get_country_states( 'IN' ) );
513
+    return apply_filters('wpinv_india_states', wpinv_get_country_states('IN'));
514 514
 }
515 515
 
516 516
 /**
@@ -520,7 +520,7 @@  discard block
 block discarded – undo
520 520
  * @return array
521 521
  */
522 522
 function wpinv_get_iran_states_list() {
523
-    return apply_filters( 'wpinv_iran_states', wpinv_get_country_states( 'IR' ) );
523
+    return apply_filters('wpinv_iran_states', wpinv_get_country_states('IR'));
524 524
 }
525 525
 
526 526
 /**
@@ -530,7 +530,7 @@  discard block
 block discarded – undo
530 530
  * @return array
531 531
  */
532 532
 function wpinv_get_italy_states_list() {
533
-    return apply_filters( 'wpinv_italy_states', wpinv_get_country_states( 'IT' ) );
533
+    return apply_filters('wpinv_italy_states', wpinv_get_country_states('IT'));
534 534
 }
535 535
 
536 536
 /**
@@ -540,7 +540,7 @@  discard block
 block discarded – undo
540 540
  * @return array
541 541
  */
542 542
 function wpinv_get_malaysia_states_list() {
543
-    return apply_filters( 'wpinv_malaysia_states', wpinv_get_country_states( 'MY' ) );
543
+    return apply_filters('wpinv_malaysia_states', wpinv_get_country_states('MY'));
544 544
 }
545 545
 
546 546
 /**
@@ -550,7 +550,7 @@  discard block
 block discarded – undo
550 550
  * @return array
551 551
  */
552 552
 function wpinv_get_mexico_states_list() {
553
-    return apply_filters( 'wpinv_mexico_states', wpinv_get_country_states( 'MX' ) );
553
+    return apply_filters('wpinv_mexico_states', wpinv_get_country_states('MX'));
554 554
 }
555 555
 
556 556
 /**
@@ -560,7 +560,7 @@  discard block
 block discarded – undo
560 560
  * @return array
561 561
  */
562 562
 function wpinv_get_nepal_states_list() {
563
-    return apply_filters( 'wpinv_nepal_states', wpinv_get_country_states( 'NP' ) );
563
+    return apply_filters('wpinv_nepal_states', wpinv_get_country_states('NP'));
564 564
 }
565 565
 
566 566
 /**
@@ -570,7 +570,7 @@  discard block
 block discarded – undo
570 570
  * @return array
571 571
  */
572 572
 function wpinv_get_south_africa_states_list() {
573
-    return apply_filters( 'wpinv_south_africa_states', wpinv_get_country_states( 'ZA' ) );
573
+    return apply_filters('wpinv_south_africa_states', wpinv_get_country_states('ZA'));
574 574
 }
575 575
 
576 576
 /**
@@ -580,7 +580,7 @@  discard block
 block discarded – undo
580 580
  * @return array
581 581
  */
582 582
 function wpinv_get_thailand_states_list() {
583
-    return apply_filters( 'wpinv_thailand_states', wpinv_get_country_states( 'TH' ) );
583
+    return apply_filters('wpinv_thailand_states', wpinv_get_country_states('TH'));
584 584
 }
585 585
 
586 586
 /**
@@ -590,7 +590,7 @@  discard block
 block discarded – undo
590 590
  * @return array
591 591
  */
592 592
 function wpinv_get_turkey_states_list() {
593
-    return apply_filters( 'wpinv_turkey_states', wpinv_get_country_states( 'TR' ) );
593
+    return apply_filters('wpinv_turkey_states', wpinv_get_country_states('TR'));
594 594
 }
595 595
 
596 596
 /**
@@ -600,31 +600,31 @@  discard block
 block discarded – undo
600 600
  * @return array
601 601
  */
602 602
 function wpinv_get_spain_states_list() {
603
-    return apply_filters( 'wpinv_spain_states', wpinv_get_country_states( 'ES' ) );
603
+    return apply_filters('wpinv_spain_states', wpinv_get_country_states('ES'));
604 604
 }
605 605
 
606 606
 function wpinv_get_states_field() {
607
-	if( empty( $_POST['country'] ) ) {
607
+	if (empty($_POST['country'])) {
608 608
 		$_POST['country'] = wpinv_get_default_country();
609 609
 	}
610
-	$states = wpinv_get_country_states( sanitize_text_field( $_POST['country'] ) );
610
+	$states = wpinv_get_country_states(sanitize_text_field($_POST['country']));
611 611
 
612
-	if( !empty( $states ) ) {
613
-		$sanitized_field_name = sanitize_text_field( $_POST['field_name'] );
612
+	if (!empty($states)) {
613
+		$sanitized_field_name = sanitize_text_field($_POST['field_name']);
614 614
 
615
-        $class  = isset( $_POST['class'] ) ? esc_attr( $_POST['class'] ) : '';
615
+        $class  = isset($_POST['class']) ? esc_attr($_POST['class']) : '';
616 616
         $class .= " $sanitized_field_name getpaid_js_field-state custom-select wpinv-select wpi_select2";
617 617
 
618
-        $args  = array(
618
+        $args = array(
619 619
 			'name'    => $sanitized_field_name,
620 620
 			'id'      => $sanitized_field_name,
621
-			'class'   => implode( ' ', array_unique( explode( ' ', $class ) ) ),
622
-			'options' => array_merge( array( '' => '' ), $states ),
621
+			'class'   => implode(' ', array_unique(explode(' ', $class))),
622
+			'options' => array_merge(array('' => ''), $states),
623 623
 			'show_option_all'  => false,
624 624
 			'show_option_none' => false
625 625
 		);
626 626
 
627
-		$response = wpinv_html_select( $args );
627
+		$response = wpinv_html_select($args);
628 628
 
629 629
 	} else {
630 630
 		$response = 'nostates';
@@ -633,10 +633,10 @@  discard block
 block discarded – undo
633 633
 	return $response;
634 634
 }
635 635
 
636
-function wpinv_default_billing_country( $country = '', $user_id = 0 ) {
637
-    $country = !empty( $country ) ? $country : wpinv_get_default_country();
636
+function wpinv_default_billing_country($country = '', $user_id = 0) {
637
+    $country = !empty($country) ? $country : wpinv_get_default_country();
638 638
     
639
-    return apply_filters( 'wpinv_default_billing_country', $country, $user_id );
639
+    return apply_filters('wpinv_default_billing_country', $country, $user_id);
640 640
 }
641 641
 
642 642
 /**
@@ -648,7 +648,7 @@  discard block
 block discarded – undo
648 648
  */
649 649
 function wpinv_get_address_formats() {
650 650
 
651
-		return apply_filters( 'wpinv_localisation_address_formats',
651
+		return apply_filters('wpinv_localisation_address_formats',
652 652
 			array(
653 653
 				'default' => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}}\n{{zip}}\n{{country}}",
654 654
 				'AU'      => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}} {{zip}}\n{{country}}",
@@ -697,9 +697,9 @@  discard block
 block discarded – undo
697 697
  * @see `wpinv_get_invoice_address_replacements`
698 698
  * @return string
699 699
  */
700
-function wpinv_get_full_address_format( $country = false) {
700
+function wpinv_get_full_address_format($country = false) {
701 701
 
702
-    if( empty( $country ) ) {
702
+    if (empty($country)) {
703 703
         $country = wpinv_get_default_country();
704 704
     }
705 705
 
@@ -707,7 +707,7 @@  discard block
 block discarded – undo
707 707
 	$formats = wpinv_get_address_formats();
708 708
 
709 709
 	// Get format for the specified country.
710
-	$format = ( $country && isset( $formats[ $country ] ) ) ? $formats[ $country ] : $formats['default'];
710
+	$format = ($country && isset($formats[$country])) ? $formats[$country] : $formats['default'];
711 711
     
712 712
     /**
713 713
 	 * Filters the address format to use on Invoices.
@@ -719,7 +719,7 @@  discard block
 block discarded – undo
719 719
 	 * @param string $format  The address format to use.
720 720
      * @param string $country The country who's address format is being retrieved.
721 721
 	 */
722
-    return apply_filters( 'wpinv_get_full_address_format', $format, $country );
722
+    return apply_filters('wpinv_get_full_address_format', $format, $country);
723 723
 }
724 724
 
725 725
 /**
@@ -730,7 +730,7 @@  discard block
 block discarded – undo
730 730
  * @param array $billing_details customer's billing details
731 731
  * @return array
732 732
  */
733
-function wpinv_get_invoice_address_replacements( $billing_details ) {
733
+function wpinv_get_invoice_address_replacements($billing_details) {
734 734
 
735 735
     $default_args = array(
736 736
         'address'           => '',
@@ -743,22 +743,22 @@  discard block
 block discarded – undo
743 743
 		'company'           => '',
744 744
     );
745 745
 
746
-    $args    = map_deep( wp_parse_args( $billing_details, $default_args ), 'trim' );
746
+    $args    = map_deep(wp_parse_args($billing_details, $default_args), 'trim');
747 747
     $state   = $args['state'];
748 748
     $country = $args['country'];
749 749
 
750 750
     // Handle full country name.
751
-    $full_country = empty( $country ) ? $country : wpinv_country_name( $country );
751
+    $full_country = empty($country) ? $country : wpinv_country_name($country);
752 752
 
753 753
     // Handle full state name.
754
-    $full_state   = ( $country && $state ) ?  wpinv_state_name( $state, $country ) : $state;
754
+    $full_state   = ($country && $state) ?  wpinv_state_name($state, $country) : $state;
755 755
 
756 756
     $args['postcode']    = $args['zip'];
757 757
     $args['name']        = $args['first_name'] . ' ' . $args['last_name'];
758 758
     $args['state']       = $full_state;
759 759
     $args['state_code']  = $state;
760 760
     $args['country']     = $full_country;
761
-    $args['country_code']= $country;
761
+    $args['country_code'] = $country;
762 762
 
763 763
     /**
764 764
 	 * Filters the address format replacements to use on Invoices.
@@ -769,14 +769,14 @@  discard block
 block discarded – undo
769 769
 	 * @param array $replacements  The address replacements to use.
770 770
      * @param array $billing_details  The billing details to use.
771 771
 	 */
772
-    $replacements = apply_filters( 'wpinv_get_invoice_address_replacements', $args, $billing_details );
772
+    $replacements = apply_filters('wpinv_get_invoice_address_replacements', $args, $billing_details);
773 773
 
774 774
     $return = array();
775 775
 
776
-    foreach( $replacements as $key => $value ) {
777
-        $value  = is_scalar( $value ) ? trim( sanitize_text_field( $value ) ) : '';
776
+    foreach ($replacements as $key => $value) {
777
+        $value = is_scalar($value) ? trim(sanitize_text_field($value)) : '';
778 778
         $return['{{' . $key . '}}'] = $value;
779
-        $return['{{' . $key . '_upper}}'] = wpinv_utf8_strtoupper( $value );
779
+        $return['{{' . $key . '_upper}}'] = wpinv_utf8_strtoupper($value);
780 780
     }
781 781
 
782 782
     return $return;
@@ -790,6 +790,6 @@  discard block
 block discarded – undo
790 790
  * @since 1.0.14
791 791
  * @return string
792 792
  */
793
-function wpinv_trim_formatted_address_line( $line ) {
794
-	return trim( $line, ', ' );
793
+function wpinv_trim_formatted_address_line($line) {
794
+	return trim($line, ', ');
795 795
 }
796 796
\ No newline at end of file
Please login to merge, or discard this patch.