Passed
Pull Request — master (#377)
by Brian
06:57
created
includes/wpinv-helper-functions.php 2 patches
Indentation   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -96,13 +96,13 @@  discard block
 block discarded – undo
96 96
  * @return array
97 97
  */
98 98
 function wpinv_get_invoice_statuses( $draft = false, $trashed = false, $invoice = false ) {
99
-	$invoice_statuses = array(
100
-		'wpi-pending'    => _x( 'Pending payment', 'Invoice status', 'invoicing' ),
99
+    $invoice_statuses = array(
100
+        'wpi-pending'    => _x( 'Pending payment', 'Invoice status', 'invoicing' ),
101 101
         'publish'        => _x( 'Paid', 'Invoice status', 'invoicing' ),
102 102
         'wpi-processing' => _x( 'Processing', 'Invoice status', 'invoicing' ),
103
-		'wpi-onhold'     => _x( 'On hold', 'Invoice status', 'invoicing' ),
104
-		'wpi-cancelled'  => _x( 'Cancelled', 'Invoice status', 'invoicing' ),
105
-		'wpi-refunded'   => _x( 'Refunded', 'Invoice status', 'invoicing' ),
103
+        'wpi-onhold'     => _x( 'On hold', 'Invoice status', 'invoicing' ),
104
+        'wpi-cancelled'  => _x( 'Cancelled', 'Invoice status', 'invoicing' ),
105
+        'wpi-refunded'   => _x( 'Refunded', 'Invoice status', 'invoicing' ),
106 106
         'wpi-failed'     => _x( 'Failed', 'Invoice status', 'invoicing' ),
107 107
         'wpi-renewal'    => _x( 'Renewal Payment', 'Invoice status', 'invoicing' ),
108 108
     );
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
         $invoice_statuses['trash'] = __( 'Trash', 'invoicing' );
116 116
     }
117 117
 
118
-	return apply_filters( 'wpinv_statuses', $invoice_statuses, $invoice );
118
+    return apply_filters( 'wpinv_statuses', $invoice_statuses, $invoice );
119 119
 }
120 120
 
121 121
 function wpinv_status_nicename( $status ) {
@@ -712,13 +712,13 @@  discard block
 block discarded – undo
712 712
  * @param mixed  $value Value.
713 713
  */
714 714
 function getpaid_maybe_define_constant( $name, $value ) {
715
-	if ( ! defined( $name ) ) {
716
-		define( $name, $value );
717
-	}
715
+    if ( ! defined( $name ) ) {
716
+        define( $name, $value );
717
+    }
718 718
 }
719 719
 
720 720
 function wpinv_get_php_arg_separator_output() {
721
-	return ini_get( 'arg_separator.output' );
721
+    return ini_get( 'arg_separator.output' );
722 722
 }
723 723
 
724 724
 function wpinv_rgb_from_hex( $color ) {
@@ -1067,11 +1067,11 @@  discard block
 block discarded – undo
1067 1067
         $list = array();
1068 1068
     }
1069 1069
 
1070
-	if ( ! is_array( $list ) ) {
1071
-		return preg_split( '/[\s,]+/', $list, -1, PREG_SPLIT_NO_EMPTY );
1072
-	}
1070
+    if ( ! is_array( $list ) ) {
1071
+        return preg_split( '/[\s,]+/', $list, -1, PREG_SPLIT_NO_EMPTY );
1072
+    }
1073 1073
 
1074
-	return $list;
1074
+    return $list;
1075 1075
 }
1076 1076
 
1077 1077
 /**
@@ -1091,9 +1091,9 @@  discard block
 block discarded – undo
1091 1091
     }
1092 1092
 
1093 1093
     $data = apply_filters( "wpinv_get_$key", include WPINV_PLUGIN_DIR . "includes/data/$key.php" );
1094
-	wp_cache_set( "wpinv-$key", $data, 'wpinv' );
1094
+    wp_cache_set( "wpinv-$key", $data, 'wpinv' );
1095 1095
 
1096
-	return $data;
1096
+    return $data;
1097 1097
 }
1098 1098
 
1099 1099
 /**
@@ -1122,17 +1122,17 @@  discard block
 block discarded – undo
1122 1122
  */
1123 1123
 function wpinv_clean( $var ) {
1124 1124
 
1125
-	if ( is_array( $var ) ) {
1126
-		return array_map( 'wpinv_clean', $var );
1125
+    if ( is_array( $var ) ) {
1126
+        return array_map( 'wpinv_clean', $var );
1127 1127
     }
1128 1128
 
1129 1129
     if ( is_object( $var ) ) {
1130
-		$object_vars = get_object_vars( $var );
1131
-		foreach ( $object_vars as $property_name => $property_value ) {
1132
-			$var->$property_name = wpinv_clean( $property_value );
1130
+        $object_vars = get_object_vars( $var );
1131
+        foreach ( $object_vars as $property_name => $property_value ) {
1132
+            $var->$property_name = wpinv_clean( $property_value );
1133 1133
         }
1134 1134
         return $var;
1135
-	}
1135
+    }
1136 1136
     
1137 1137
     return is_string( $var ) ? sanitize_text_field( $var ) : $var;
1138 1138
 }
@@ -1145,7 +1145,7 @@  discard block
 block discarded – undo
1145 1145
  */
1146 1146
 function getpaid_convert_price_string_to_options( $str ) {
1147 1147
 
1148
-	$raw_options = array_map( 'trim', explode( ',', $str ) );
1148
+    $raw_options = array_map( 'trim', explode( ',', $str ) );
1149 1149
     $options     = array();
1150 1150
 
1151 1151
     foreach ( $raw_options as $option ) {
Please login to merge, or discard this patch.
Spacing   +431 added lines, -431 removed lines patch added patch discarded remove patch
@@ -7,86 +7,86 @@  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
 function wpinv_item_quantities_enabled() {
15
-    $ret = wpinv_get_option( 'item_quantities', true );
15
+    $ret = wpinv_get_option('item_quantities', true);
16 16
 
17
-    return (bool) apply_filters( 'wpinv_item_quantities_enabled', $ret );
17
+    return (bool) apply_filters('wpinv_item_quantities_enabled', $ret);
18 18
 }
19 19
 
20 20
 function wpinv_get_ip() {
21 21
     $ip = '127.0.0.1';
22 22
 
23
-    if ( !empty( $_SERVER['HTTP_CLIENT_IP'] ) ) {
24
-        $ip = sanitize_text_field( $_SERVER['HTTP_CLIENT_IP'] );
25
-    } elseif ( !empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
26
-        $ip = sanitize_text_field( $_SERVER['HTTP_X_FORWARDED_FOR'] );
27
-    } elseif( !empty( $_SERVER['REMOTE_ADDR'] ) ) {
28
-        $ip = sanitize_text_field( $_SERVER['REMOTE_ADDR'] );
23
+    if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
24
+        $ip = sanitize_text_field($_SERVER['HTTP_CLIENT_IP']);
25
+    } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
26
+        $ip = sanitize_text_field($_SERVER['HTTP_X_FORWARDED_FOR']);
27
+    } elseif (!empty($_SERVER['REMOTE_ADDR'])) {
28
+        $ip = sanitize_text_field($_SERVER['REMOTE_ADDR']);
29 29
     }
30 30
 
31
-    return apply_filters( 'wpinv_get_ip', $ip );
31
+    return apply_filters('wpinv_get_ip', $ip);
32 32
 }
33 33
 
34 34
 function wpinv_get_user_agent() {
35
-    if ( ! empty( $_SERVER['HTTP_USER_AGENT'] ) ) {
36
-        $user_agent = sanitize_text_field( $_SERVER['HTTP_USER_AGENT'] );
35
+    if (!empty($_SERVER['HTTP_USER_AGENT'])) {
36
+        $user_agent = sanitize_text_field($_SERVER['HTTP_USER_AGENT']);
37 37
     } else {
38 38
         $user_agent = '';
39 39
     }
40 40
 
41
-    return apply_filters( 'wpinv_get_user_agent', $user_agent );
41
+    return apply_filters('wpinv_get_user_agent', $user_agent);
42 42
 }
43 43
 
44
-function wpinv_sanitize_amount( $amount, $decimals = NULL ) {
44
+function wpinv_sanitize_amount($amount, $decimals = NULL) {
45 45
     $is_negative   = false;
46 46
     $thousands_sep = wpinv_thousands_separator();
47 47
     $decimal_sep   = wpinv_decimal_separator();
48
-    if ( $decimals === NULL ) {
48
+    if ($decimals === NULL) {
49 49
         $decimals = wpinv_decimals();
50 50
     }
51 51
 
52 52
     // Sanitize the amount
53
-    if ( $decimal_sep == ',' && false !== ( $found = strpos( $amount, $decimal_sep ) ) ) {
54
-        if ( ( $thousands_sep == '.' || $thousands_sep == ' ' ) && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) {
55
-            $amount = str_replace( $thousands_sep, '', $amount );
56
-        } elseif( empty( $thousands_sep ) && false !== ( $found = strpos( $amount, '.' ) ) ) {
57
-            $amount = str_replace( '.', '', $amount );
53
+    if ($decimal_sep == ',' && false !== ($found = strpos($amount, $decimal_sep))) {
54
+        if (($thousands_sep == '.' || $thousands_sep == ' ') && false !== ($found = strpos($amount, $thousands_sep))) {
55
+            $amount = str_replace($thousands_sep, '', $amount);
56
+        } elseif (empty($thousands_sep) && false !== ($found = strpos($amount, '.'))) {
57
+            $amount = str_replace('.', '', $amount);
58 58
         }
59 59
 
60
-        $amount = str_replace( $decimal_sep, '.', $amount );
61
-    } elseif( $thousands_sep == ',' && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) {
62
-        $amount = str_replace( $thousands_sep, '', $amount );
60
+        $amount = str_replace($decimal_sep, '.', $amount);
61
+    } elseif ($thousands_sep == ',' && false !== ($found = strpos($amount, $thousands_sep))) {
62
+        $amount = str_replace($thousands_sep, '', $amount);
63 63
     }
64 64
 
65
-    if( $amount < 0 ) {
65
+    if ($amount < 0) {
66 66
         $is_negative = true;
67 67
     }
68 68
 
69
-    $amount   = preg_replace( '/[^0-9\.]/', '', $amount );
69
+    $amount   = preg_replace('/[^0-9\.]/', '', $amount);
70 70
 
71
-    $decimals = apply_filters( 'wpinv_sanitize_amount_decimals', absint( $decimals ), $amount );
72
-    $amount   = number_format( (double) $amount, absint( $decimals ), '.', '' );
71
+    $decimals = apply_filters('wpinv_sanitize_amount_decimals', absint($decimals), $amount);
72
+    $amount   = number_format((double) $amount, absint($decimals), '.', '');
73 73
 
74
-    if( $is_negative ) {
74
+    if ($is_negative) {
75 75
         $amount *= -1;
76 76
     }
77 77
 
78
-    return apply_filters( 'wpinv_sanitize_amount', $amount, $decimals );
78
+    return apply_filters('wpinv_sanitize_amount', $amount, $decimals);
79 79
 }
80
-add_filter( 'wpinv_sanitize_amount_decimals', 'wpinv_currency_decimal_filter', 10, 1 );
80
+add_filter('wpinv_sanitize_amount_decimals', 'wpinv_currency_decimal_filter', 10, 1);
81 81
 
82
-function wpinv_round_amount( $amount, $decimals = NULL ) {
83
-    if ( $decimals === NULL ) {
82
+function wpinv_round_amount($amount, $decimals = NULL) {
83
+    if ($decimals === NULL) {
84 84
         $decimals = wpinv_decimals();
85 85
     }
86 86
     
87
-    $amount = round( (double)$amount, wpinv_currency_decimal_filter( absint( $decimals ) ) );
87
+    $amount = round((double) $amount, wpinv_currency_decimal_filter(absint($decimals)));
88 88
 
89
-    return apply_filters( 'wpinv_round_amount', $amount, $decimals );
89
+    return apply_filters('wpinv_round_amount', $amount, $decimals);
90 90
 }
91 91
 
92 92
 /**
@@ -95,48 +95,48 @@  discard block
 block discarded – undo
95 95
  * @since 1.0.19
96 96
  * @return array
97 97
  */
98
-function wpinv_get_invoice_statuses( $draft = false, $trashed = false, $invoice = false ) {
98
+function wpinv_get_invoice_statuses($draft = false, $trashed = false, $invoice = false) {
99 99
 	$invoice_statuses = array(
100
-		'wpi-pending'    => _x( 'Pending payment', 'Invoice status', 'invoicing' ),
101
-        'publish'        => _x( 'Paid', 'Invoice status', 'invoicing' ),
102
-        'wpi-processing' => _x( 'Processing', 'Invoice status', 'invoicing' ),
103
-		'wpi-onhold'     => _x( 'On hold', 'Invoice status', 'invoicing' ),
104
-		'wpi-cancelled'  => _x( 'Cancelled', 'Invoice status', 'invoicing' ),
105
-		'wpi-refunded'   => _x( 'Refunded', 'Invoice status', 'invoicing' ),
106
-        'wpi-failed'     => _x( 'Failed', 'Invoice status', 'invoicing' ),
107
-        'wpi-renewal'    => _x( 'Renewal Payment', 'Invoice status', 'invoicing' ),
100
+		'wpi-pending'    => _x('Pending payment', 'Invoice status', 'invoicing'),
101
+        'publish'        => _x('Paid', 'Invoice status', 'invoicing'),
102
+        'wpi-processing' => _x('Processing', 'Invoice status', 'invoicing'),
103
+		'wpi-onhold'     => _x('On hold', 'Invoice status', 'invoicing'),
104
+		'wpi-cancelled'  => _x('Cancelled', 'Invoice status', 'invoicing'),
105
+		'wpi-refunded'   => _x('Refunded', 'Invoice status', 'invoicing'),
106
+        'wpi-failed'     => _x('Failed', 'Invoice status', 'invoicing'),
107
+        'wpi-renewal'    => _x('Renewal Payment', 'Invoice status', 'invoicing'),
108 108
     );
109 109
 
110
-    if ( $draft ) {
111
-        $invoice_statuses['draft'] = __( 'Draft', 'invoicing' );
110
+    if ($draft) {
111
+        $invoice_statuses['draft'] = __('Draft', 'invoicing');
112 112
     }
113 113
 
114
-    if ( $trashed ) {
115
-        $invoice_statuses['trash'] = __( 'Trash', 'invoicing' );
114
+    if ($trashed) {
115
+        $invoice_statuses['trash'] = __('Trash', 'invoicing');
116 116
     }
117 117
 
118
-	return apply_filters( 'wpinv_statuses', $invoice_statuses, $invoice );
118
+	return apply_filters('wpinv_statuses', $invoice_statuses, $invoice);
119 119
 }
120 120
 
121
-function wpinv_status_nicename( $status ) {
122
-    $statuses = wpinv_get_invoice_statuses( true, true );
123
-    $status   = isset( $statuses[$status] ) ? $statuses[$status] : __( $status, 'invoicing' );
121
+function wpinv_status_nicename($status) {
122
+    $statuses = wpinv_get_invoice_statuses(true, true);
123
+    $status   = isset($statuses[$status]) ? $statuses[$status] : __($status, 'invoicing');
124 124
 
125 125
     return $status;
126 126
 }
127 127
 
128 128
 function wpinv_get_currency() {
129
-    $currency = wpinv_get_option( 'currency', 'USD' );
129
+    $currency = wpinv_get_option('currency', 'USD');
130 130
     
131
-    return apply_filters( 'wpinv_currency', $currency );
131
+    return apply_filters('wpinv_currency', $currency);
132 132
 }
133 133
 
134
-function wpinv_currency_symbol( $currency = '' ) {
135
-    if ( empty( $currency ) ) {
134
+function wpinv_currency_symbol($currency = '') {
135
+    if (empty($currency)) {
136 136
         $currency = wpinv_get_currency();
137 137
     }
138 138
     
139
-    $symbols = apply_filters( 'wpinv_currency_symbols', array(
139
+    $symbols = apply_filters('wpinv_currency_symbols', array(
140 140
         'AED' => '&#x62f;.&#x625;',
141 141
         'AFN' => '&#x60b;',
142 142
         'ALL' => 'L',
@@ -299,209 +299,209 @@  discard block
 block discarded – undo
299 299
         'YER' => '&#xfdfc;',
300 300
         'ZAR' => '&#82;',
301 301
         'ZMW' => 'ZK',
302
-    ) );
302
+    ));
303 303
 
304
-    $currency_symbol = isset( $symbols[$currency] ) ? $symbols[$currency] : $currency;
304
+    $currency_symbol = isset($symbols[$currency]) ? $symbols[$currency] : $currency;
305 305
 
306
-    return apply_filters( 'wpinv_currency_symbol', $currency_symbol, $currency );
306
+    return apply_filters('wpinv_currency_symbol', $currency_symbol, $currency);
307 307
 }
308 308
 
309 309
 function wpinv_currency_position() {
310
-    $position = wpinv_get_option( 'currency_position', 'left' );
310
+    $position = wpinv_get_option('currency_position', 'left');
311 311
     
312
-    return apply_filters( 'wpinv_currency_position', $position );
312
+    return apply_filters('wpinv_currency_position', $position);
313 313
 }
314 314
 
315 315
 function wpinv_thousands_separator() {
316
-    $thousand_sep = wpinv_get_option( 'thousands_separator', ',' );
316
+    $thousand_sep = wpinv_get_option('thousands_separator', ',');
317 317
     
318
-    return apply_filters( 'wpinv_thousands_separator', $thousand_sep );
318
+    return apply_filters('wpinv_thousands_separator', $thousand_sep);
319 319
 }
320 320
 
321 321
 function wpinv_decimal_separator() {
322
-    $decimal_sep = wpinv_get_option( 'decimal_separator', '.' );
322
+    $decimal_sep = wpinv_get_option('decimal_separator', '.');
323 323
     
324
-    return apply_filters( 'wpinv_decimal_separator', $decimal_sep );
324
+    return apply_filters('wpinv_decimal_separator', $decimal_sep);
325 325
 }
326 326
 
327 327
 function wpinv_decimals() {
328
-    $decimals = apply_filters( 'wpinv_decimals', wpinv_get_option( 'decimals', 2 ) );
328
+    $decimals = apply_filters('wpinv_decimals', wpinv_get_option('decimals', 2));
329 329
     
330
-    return absint( $decimals );
330
+    return absint($decimals);
331 331
 }
332 332
 
333 333
 function wpinv_get_currencies() {
334 334
     $currencies = array(
335
-        'USD' => __( 'US Dollar', 'invoicing' ),
336
-        'EUR' => __( 'Euro', 'invoicing' ),
337
-        'GBP' => __( 'Pound Sterling', 'invoicing' ),
338
-        'AED' => __( 'United Arab Emirates', 'invoicing' ),
339
-        'AFN' => __( 'Afghan Afghani', 'invoicing' ),
340
-        'ALL' => __( 'Albanian Lek', 'invoicing' ),
341
-        'AMD' => __( 'Armenian Dram', 'invoicing' ),
342
-        'ANG' => __( 'Netherlands Antillean Guilder', 'invoicing' ),
343
-        'AOA' => __( 'Angolan Kwanza', 'invoicing' ),
344
-        'ARS' => __( 'Argentine Peso', 'invoicing' ),
345
-        'AUD' => __( 'Australian Dollar', 'invoicing' ),
346
-        'AWG' => __( 'Aruban Florin', 'invoicing' ),
347
-        'AZN' => __( 'Azerbaijani Manat', 'invoicing' ),
348
-        'BAM' => __( 'Bosnia and Herzegovina Convertible Marka', 'invoicing' ),
349
-        'BBD' => __( 'Barbadian Dollar', 'invoicing' ),
350
-        'BDT' => __( 'Bangladeshi Taka', 'invoicing' ),
351
-        'BGN' => __( 'Bulgarian Lev', 'invoicing' ),
352
-        'BHD' => __( 'Bahraini Dinar', 'invoicing' ),
353
-        'BIF' => __( 'Burundian Franc', 'invoicing' ),
354
-        'BMD' => __( 'Bermudian Dollar', 'invoicing' ),
355
-        'BND' => __( 'Brunei Dollar', 'invoicing' ),
356
-        'BOB' => __( 'Bolivian Boliviano', 'invoicing' ),
357
-        'BRL' => __( 'Brazilian Real', 'invoicing' ),
358
-        'BSD' => __( 'Bahamian Dollar', 'invoicing' ),
359
-        'BTC' => __( 'Bitcoin', 'invoicing' ),
360
-        'BTN' => __( 'Bhutanese Ngultrum', 'invoicing' ),
361
-        'BWP' => __( 'Botswana Pula', 'invoicing' ),
362
-        'BYN' => __( 'Belarusian Ruble', 'invoicing' ),
363
-        'BZD' => __( 'Belize Dollar', 'invoicing' ),
364
-        'CAD' => __( 'Canadian Dollar', 'invoicing' ),
365
-        'CDF' => __( 'Congolese Franc', 'invoicing' ),
366
-        'CHF' => __( 'Swiss Franc', 'invoicing' ),
367
-        'CLP' => __( 'Chilean Peso', 'invoicing' ),
368
-        'CNY' => __( 'Chinese Yuan', 'invoicing' ),
369
-        'COP' => __( 'Colombian Peso', 'invoicing' ),
370
-        'CRC' => __( 'Costa Rican Colon', 'invoicing' ),
371
-        'CUC' => __( 'Cuban Convertible Peso', 'invoicing' ),
372
-        'CUP' => __( 'Cuban Peso', 'invoicing' ),
373
-        'CVE' => __( 'Cape Verdean escudo', 'invoicing' ),
374
-        'CZK' => __( 'Czech Koruna', 'invoicing' ),
375
-        'DJF' => __( 'Djiboutian Franc', 'invoicing' ),
376
-        'DKK' => __( 'Danish Krone', 'invoicing' ),
377
-        'DOP' => __( 'Dominican Peso', 'invoicing' ),
378
-        'DZD' => __( 'Algerian Dinar', 'invoicing' ),
379
-        'EGP' => __( 'Egyptian Pound', 'invoicing' ),
380
-        'ERN' => __( 'Eritrean Nakfa', 'invoicing' ),
381
-        'ETB' => __( 'Ethiopian Irr', 'invoicing' ),
382
-        'FJD' => __( 'Fijian Dollar', 'invoicing' ),
383
-        'FKP' => __( 'Falkland Islands Pound', 'invoicing' ),
384
-        'GEL' => __( 'Georgian Lari', 'invoicing' ),
385
-        'GGP' => __( 'Guernsey Pound', 'invoicing' ),
386
-        'GHS' => __( 'Ghana Cedi', 'invoicing' ),
387
-        'GIP' => __( 'Gibraltar Pound', 'invoicing' ),
388
-        'GMD' => __( 'Gambian Dalasi', 'invoicing' ),
389
-        'GNF' => __( 'Guinean Franc', 'invoicing' ),
390
-        'GTQ' => __( 'Guatemalan Quetzal', 'invoicing' ),
391
-        'GYD' => __( 'Guyanese Dollar', 'invoicing' ),
392
-        'HKD' => __( 'Hong Kong Dollar', 'invoicing' ),
393
-        'HNL' => __( 'Honduran Lempira', 'invoicing' ),
394
-        'HRK' => __( 'Croatian Kuna', 'invoicing' ),
395
-        'HTG' => __( 'Haitian Gourde', 'invoicing' ),
396
-        'HUF' => __( 'Hungarian Forint', 'invoicing' ),
397
-        'IDR' => __( 'Indonesian Rupiah', 'invoicing' ),
398
-        'ILS' => __( 'Israeli New Shekel', 'invoicing' ),
399
-        'IMP' => __( 'Manx Pound', 'invoicing' ),
400
-        'INR' => __( 'Indian Rupee', 'invoicing' ),
401
-        'IQD' => __( 'Iraqi Dinar', 'invoicing' ),
402
-        'IRR' => __( 'Iranian Rial', 'invoicing' ),
403
-        'IRT' => __( 'Iranian Toman', 'invoicing' ),
404
-        'ISK' => __( 'Icelandic Krona', 'invoicing' ),
405
-        'JEP' => __( 'Jersey Pound', 'invoicing' ),
406
-        'JMD' => __( 'Jamaican Dollar', 'invoicing' ),
407
-        'JOD' => __( 'Jordanian Dinar', 'invoicing' ),
408
-        'JPY' => __( 'Japanese Yen', 'invoicing' ),
409
-        'KES' => __( 'Kenyan Shilling', 'invoicing' ),
410
-        'KGS' => __( 'Kyrgyzstani Som', 'invoicing' ),
411
-        'KHR' => __( 'Cambodian Riel', 'invoicing' ),
412
-        'KMF' => __( 'Comorian Franc', 'invoicing' ),
413
-        'KPW' => __( 'North Korean Won', 'invoicing' ),
414
-        'KRW' => __( 'South Korean Won', 'invoicing' ),
415
-        'KWD' => __( 'Kuwaiti Dinar', 'invoicing' ),
416
-        'KYD' => __( 'Cayman Islands Dollar', 'invoicing' ),
417
-        'KZT' => __( 'Kazakhstani Tenge', 'invoicing' ),
418
-        'LAK' => __( 'Lao Kip', 'invoicing' ),
419
-        'LBP' => __( 'Lebanese Pound', 'invoicing' ),
420
-        'LKR' => __( 'Sri Lankan Rupee', 'invoicing' ),
421
-        'LRD' => __( 'Liberian Dollar', 'invoicing' ),
422
-        'LSL' => __( 'Lesotho Loti', 'invoicing' ),
423
-        'LYD' => __( 'Libyan Dinar', 'invoicing' ),
424
-        'MAD' => __( 'Moroccan Dirham', 'invoicing' ),
425
-        'MDL' => __( 'Moldovan Leu', 'invoicing' ),
426
-        'MGA' => __( 'Malagasy Ariary', 'invoicing' ),
427
-        'MKD' => __( 'Macedonian Denar', 'invoicing' ),
428
-        'MMK' => __( 'Burmese Kyat', 'invoicing' ),
429
-        'MNT' => __( 'Mongolian Tughrik', 'invoicing' ),
430
-        'MOP' => __( 'Macanese Pataca', 'invoicing' ),
431
-        'MRO' => __( 'Mauritanian Ouguiya', 'invoicing' ),
432
-        'MUR' => __( 'Mauritian Rupee', 'invoicing' ),
433
-        'MVR' => __( 'Maldivian Rufiyaa', 'invoicing' ),
434
-        'MWK' => __( 'Malawian Kwacha', 'invoicing' ),
435
-        'MXN' => __( 'Mexican Peso', 'invoicing' ),
436
-        'MYR' => __( 'Malaysian Ringgit', 'invoicing' ),
437
-        'MZN' => __( 'Mozambican Metical', 'invoicing' ),
438
-        'NAD' => __( 'Namibian Dollar', 'invoicing' ),
439
-        'NGN' => __( 'Nigerian Naira', 'invoicing' ),
440
-        'NIO' => __( 'Nicaraguan Cordoba', 'invoicing' ),
441
-        'NOK' => __( 'Norwegian Krone', 'invoicing' ),
442
-        'NPR' => __( 'Nepalese Rupee', 'invoicing' ),
443
-        'NZD' => __( 'New Zealand Dollar', 'invoicing' ),
444
-        'OMR' => __( 'Omani Rial', 'invoicing' ),
445
-        'PAB' => __( 'Panamanian Balboa', 'invoicing' ),
446
-        'PEN' => __( 'Peruvian Nuevo Sol', 'invoicing' ),
447
-        'PGK' => __( 'Papua New Guinean Kina', 'invoicing' ),
448
-        'PHP' => __( 'Philippine Peso', 'invoicing' ),
449
-        'PKR' => __( 'Pakistani Rupee', 'invoicing' ),
450
-        'PLN' => __( 'Polish Zloty', 'invoicing' ),
451
-        'PRB' => __( 'Transnistrian Ruble', 'invoicing' ),
452
-        'PYG' => __( 'Paraguayan Guarani', 'invoicing' ),
453
-        'QAR' => __( 'Qatari Riyal', 'invoicing' ),
454
-        'RON' => __( 'Romanian Leu', 'invoicing' ),
455
-        'RSD' => __( 'Serbian Dinar', 'invoicing' ),
456
-        'RUB' => __( 'Russian Ruble', 'invoicing' ),
457
-        'RWF' => __( 'Rwandan Franc', 'invoicing' ),
458
-        'SAR' => __( 'Saudi Riyal', 'invoicing' ),
459
-        'SBD' => __( 'Solomon Islands Dollar', 'invoicing' ),
460
-        'SCR' => __( 'Seychellois Rupee', 'invoicing' ),
461
-        'SDG' => __( 'Sudanese Pound', 'invoicing' ),
462
-        'SEK' => __( 'Swedish Krona', 'invoicing' ),
463
-        'SGD' => __( 'Singapore Dollar', 'invoicing' ),
464
-        'SHP' => __( 'Saint Helena Pound', 'invoicing' ),
465
-        'SLL' => __( 'Sierra Leonean Leone', 'invoicing' ),
466
-        'SOS' => __( 'Somali Shilling', 'invoicing' ),
467
-        'SRD' => __( 'Surinamese Dollar', 'invoicing' ),
468
-        'SSP' => __( 'South Sudanese Pound', 'invoicing' ),
469
-        'STD' => __( 'Sao Tomean Dobra', 'invoicing' ),
470
-        'SYP' => __( 'Syrian Pound', 'invoicing' ),
471
-        'SZL' => __( 'Swazi Lilangeni', 'invoicing' ),
472
-        'THB' => __( 'Thai Baht', 'invoicing' ),
473
-        'TJS' => __( 'Tajikistani Somoni', 'invoicing' ),
474
-        'TMT' => __( 'Turkmenistan Manat', 'invoicing' ),
475
-        'TND' => __( 'Tunisian Dinar', 'invoicing' ),
476
-        'TOP' => __( 'Tongan Pa&#x2bb;anga', 'invoicing' ),
477
-        'TRY' => __( 'Turkish Lira', 'invoicing' ),
478
-        'TTD' => __( 'Trinidad and Tobago Dollar', 'invoicing' ),
479
-        'TWD' => __( 'New Taiwan Dollar', 'invoicing' ),
480
-        'TZS' => __( 'Tanzanian Shilling', 'invoicing' ),
481
-        'UAH' => __( 'Ukrainian Hryvnia', 'invoicing' ),
482
-        'UGX' => __( 'Ugandan Shilling', 'invoicing' ),
483
-        'UYU' => __( 'Uruguayan Peso', 'invoicing' ),
484
-        'UZS' => __( 'Uzbekistani Som', 'invoicing' ),
485
-        'VEF' => __( 'Venezuelan Bol&iacute;var', 'invoicing' ),
486
-        'VND' => __( 'Vietnamese Dong', 'invoicing' ),
487
-        'VUV' => __( 'Vanuatu Vatu', 'invoicing' ),
488
-        'WST' => __( 'Samoan Tala', 'invoicing' ),
489
-        'XAF' => __( 'Central African CFA Franc', 'invoicing' ),
490
-        'XCD' => __( 'East Caribbean Dollar', 'invoicing' ),
491
-        'XOF' => __( 'West African CFA Franc', 'invoicing' ),
492
-        'XPF' => __( 'CFP Franc', 'invoicing' ),
493
-        'YER' => __( 'Yemeni Rial', 'invoicing' ),
494
-        'ZAR' => __( 'South African Rand', 'invoicing' ),
495
-        'ZMW' => __( 'Zambian Kwacha', 'invoicing' ),
335
+        'USD' => __('US Dollar', 'invoicing'),
336
+        'EUR' => __('Euro', 'invoicing'),
337
+        'GBP' => __('Pound Sterling', 'invoicing'),
338
+        'AED' => __('United Arab Emirates', 'invoicing'),
339
+        'AFN' => __('Afghan Afghani', 'invoicing'),
340
+        'ALL' => __('Albanian Lek', 'invoicing'),
341
+        'AMD' => __('Armenian Dram', 'invoicing'),
342
+        'ANG' => __('Netherlands Antillean Guilder', 'invoicing'),
343
+        'AOA' => __('Angolan Kwanza', 'invoicing'),
344
+        'ARS' => __('Argentine Peso', 'invoicing'),
345
+        'AUD' => __('Australian Dollar', 'invoicing'),
346
+        'AWG' => __('Aruban Florin', 'invoicing'),
347
+        'AZN' => __('Azerbaijani Manat', 'invoicing'),
348
+        'BAM' => __('Bosnia and Herzegovina Convertible Marka', 'invoicing'),
349
+        'BBD' => __('Barbadian Dollar', 'invoicing'),
350
+        'BDT' => __('Bangladeshi Taka', 'invoicing'),
351
+        'BGN' => __('Bulgarian Lev', 'invoicing'),
352
+        'BHD' => __('Bahraini Dinar', 'invoicing'),
353
+        'BIF' => __('Burundian Franc', 'invoicing'),
354
+        'BMD' => __('Bermudian Dollar', 'invoicing'),
355
+        'BND' => __('Brunei Dollar', 'invoicing'),
356
+        'BOB' => __('Bolivian Boliviano', 'invoicing'),
357
+        'BRL' => __('Brazilian Real', 'invoicing'),
358
+        'BSD' => __('Bahamian Dollar', 'invoicing'),
359
+        'BTC' => __('Bitcoin', 'invoicing'),
360
+        'BTN' => __('Bhutanese Ngultrum', 'invoicing'),
361
+        'BWP' => __('Botswana Pula', 'invoicing'),
362
+        'BYN' => __('Belarusian Ruble', 'invoicing'),
363
+        'BZD' => __('Belize Dollar', 'invoicing'),
364
+        'CAD' => __('Canadian Dollar', 'invoicing'),
365
+        'CDF' => __('Congolese Franc', 'invoicing'),
366
+        'CHF' => __('Swiss Franc', 'invoicing'),
367
+        'CLP' => __('Chilean Peso', 'invoicing'),
368
+        'CNY' => __('Chinese Yuan', 'invoicing'),
369
+        'COP' => __('Colombian Peso', 'invoicing'),
370
+        'CRC' => __('Costa Rican Colon', 'invoicing'),
371
+        'CUC' => __('Cuban Convertible Peso', 'invoicing'),
372
+        'CUP' => __('Cuban Peso', 'invoicing'),
373
+        'CVE' => __('Cape Verdean escudo', 'invoicing'),
374
+        'CZK' => __('Czech Koruna', 'invoicing'),
375
+        'DJF' => __('Djiboutian Franc', 'invoicing'),
376
+        'DKK' => __('Danish Krone', 'invoicing'),
377
+        'DOP' => __('Dominican Peso', 'invoicing'),
378
+        'DZD' => __('Algerian Dinar', 'invoicing'),
379
+        'EGP' => __('Egyptian Pound', 'invoicing'),
380
+        'ERN' => __('Eritrean Nakfa', 'invoicing'),
381
+        'ETB' => __('Ethiopian Irr', 'invoicing'),
382
+        'FJD' => __('Fijian Dollar', 'invoicing'),
383
+        'FKP' => __('Falkland Islands Pound', 'invoicing'),
384
+        'GEL' => __('Georgian Lari', 'invoicing'),
385
+        'GGP' => __('Guernsey Pound', 'invoicing'),
386
+        'GHS' => __('Ghana Cedi', 'invoicing'),
387
+        'GIP' => __('Gibraltar Pound', 'invoicing'),
388
+        'GMD' => __('Gambian Dalasi', 'invoicing'),
389
+        'GNF' => __('Guinean Franc', 'invoicing'),
390
+        'GTQ' => __('Guatemalan Quetzal', 'invoicing'),
391
+        'GYD' => __('Guyanese Dollar', 'invoicing'),
392
+        'HKD' => __('Hong Kong Dollar', 'invoicing'),
393
+        'HNL' => __('Honduran Lempira', 'invoicing'),
394
+        'HRK' => __('Croatian Kuna', 'invoicing'),
395
+        'HTG' => __('Haitian Gourde', 'invoicing'),
396
+        'HUF' => __('Hungarian Forint', 'invoicing'),
397
+        'IDR' => __('Indonesian Rupiah', 'invoicing'),
398
+        'ILS' => __('Israeli New Shekel', 'invoicing'),
399
+        'IMP' => __('Manx Pound', 'invoicing'),
400
+        'INR' => __('Indian Rupee', 'invoicing'),
401
+        'IQD' => __('Iraqi Dinar', 'invoicing'),
402
+        'IRR' => __('Iranian Rial', 'invoicing'),
403
+        'IRT' => __('Iranian Toman', 'invoicing'),
404
+        'ISK' => __('Icelandic Krona', 'invoicing'),
405
+        'JEP' => __('Jersey Pound', 'invoicing'),
406
+        'JMD' => __('Jamaican Dollar', 'invoicing'),
407
+        'JOD' => __('Jordanian Dinar', 'invoicing'),
408
+        'JPY' => __('Japanese Yen', 'invoicing'),
409
+        'KES' => __('Kenyan Shilling', 'invoicing'),
410
+        'KGS' => __('Kyrgyzstani Som', 'invoicing'),
411
+        'KHR' => __('Cambodian Riel', 'invoicing'),
412
+        'KMF' => __('Comorian Franc', 'invoicing'),
413
+        'KPW' => __('North Korean Won', 'invoicing'),
414
+        'KRW' => __('South Korean Won', 'invoicing'),
415
+        'KWD' => __('Kuwaiti Dinar', 'invoicing'),
416
+        'KYD' => __('Cayman Islands Dollar', 'invoicing'),
417
+        'KZT' => __('Kazakhstani Tenge', 'invoicing'),
418
+        'LAK' => __('Lao Kip', 'invoicing'),
419
+        'LBP' => __('Lebanese Pound', 'invoicing'),
420
+        'LKR' => __('Sri Lankan Rupee', 'invoicing'),
421
+        'LRD' => __('Liberian Dollar', 'invoicing'),
422
+        'LSL' => __('Lesotho Loti', 'invoicing'),
423
+        'LYD' => __('Libyan Dinar', 'invoicing'),
424
+        'MAD' => __('Moroccan Dirham', 'invoicing'),
425
+        'MDL' => __('Moldovan Leu', 'invoicing'),
426
+        'MGA' => __('Malagasy Ariary', 'invoicing'),
427
+        'MKD' => __('Macedonian Denar', 'invoicing'),
428
+        'MMK' => __('Burmese Kyat', 'invoicing'),
429
+        'MNT' => __('Mongolian Tughrik', 'invoicing'),
430
+        'MOP' => __('Macanese Pataca', 'invoicing'),
431
+        'MRO' => __('Mauritanian Ouguiya', 'invoicing'),
432
+        'MUR' => __('Mauritian Rupee', 'invoicing'),
433
+        'MVR' => __('Maldivian Rufiyaa', 'invoicing'),
434
+        'MWK' => __('Malawian Kwacha', 'invoicing'),
435
+        'MXN' => __('Mexican Peso', 'invoicing'),
436
+        'MYR' => __('Malaysian Ringgit', 'invoicing'),
437
+        'MZN' => __('Mozambican Metical', 'invoicing'),
438
+        'NAD' => __('Namibian Dollar', 'invoicing'),
439
+        'NGN' => __('Nigerian Naira', 'invoicing'),
440
+        'NIO' => __('Nicaraguan Cordoba', 'invoicing'),
441
+        'NOK' => __('Norwegian Krone', 'invoicing'),
442
+        'NPR' => __('Nepalese Rupee', 'invoicing'),
443
+        'NZD' => __('New Zealand Dollar', 'invoicing'),
444
+        'OMR' => __('Omani Rial', 'invoicing'),
445
+        'PAB' => __('Panamanian Balboa', 'invoicing'),
446
+        'PEN' => __('Peruvian Nuevo Sol', 'invoicing'),
447
+        'PGK' => __('Papua New Guinean Kina', 'invoicing'),
448
+        'PHP' => __('Philippine Peso', 'invoicing'),
449
+        'PKR' => __('Pakistani Rupee', 'invoicing'),
450
+        'PLN' => __('Polish Zloty', 'invoicing'),
451
+        'PRB' => __('Transnistrian Ruble', 'invoicing'),
452
+        'PYG' => __('Paraguayan Guarani', 'invoicing'),
453
+        'QAR' => __('Qatari Riyal', 'invoicing'),
454
+        'RON' => __('Romanian Leu', 'invoicing'),
455
+        'RSD' => __('Serbian Dinar', 'invoicing'),
456
+        'RUB' => __('Russian Ruble', 'invoicing'),
457
+        'RWF' => __('Rwandan Franc', 'invoicing'),
458
+        'SAR' => __('Saudi Riyal', 'invoicing'),
459
+        'SBD' => __('Solomon Islands Dollar', 'invoicing'),
460
+        'SCR' => __('Seychellois Rupee', 'invoicing'),
461
+        'SDG' => __('Sudanese Pound', 'invoicing'),
462
+        'SEK' => __('Swedish Krona', 'invoicing'),
463
+        'SGD' => __('Singapore Dollar', 'invoicing'),
464
+        'SHP' => __('Saint Helena Pound', 'invoicing'),
465
+        'SLL' => __('Sierra Leonean Leone', 'invoicing'),
466
+        'SOS' => __('Somali Shilling', 'invoicing'),
467
+        'SRD' => __('Surinamese Dollar', 'invoicing'),
468
+        'SSP' => __('South Sudanese Pound', 'invoicing'),
469
+        'STD' => __('Sao Tomean Dobra', 'invoicing'),
470
+        'SYP' => __('Syrian Pound', 'invoicing'),
471
+        'SZL' => __('Swazi Lilangeni', 'invoicing'),
472
+        'THB' => __('Thai Baht', 'invoicing'),
473
+        'TJS' => __('Tajikistani Somoni', 'invoicing'),
474
+        'TMT' => __('Turkmenistan Manat', 'invoicing'),
475
+        'TND' => __('Tunisian Dinar', 'invoicing'),
476
+        'TOP' => __('Tongan Pa&#x2bb;anga', 'invoicing'),
477
+        'TRY' => __('Turkish Lira', 'invoicing'),
478
+        'TTD' => __('Trinidad and Tobago Dollar', 'invoicing'),
479
+        'TWD' => __('New Taiwan Dollar', 'invoicing'),
480
+        'TZS' => __('Tanzanian Shilling', 'invoicing'),
481
+        'UAH' => __('Ukrainian Hryvnia', 'invoicing'),
482
+        'UGX' => __('Ugandan Shilling', 'invoicing'),
483
+        'UYU' => __('Uruguayan Peso', 'invoicing'),
484
+        'UZS' => __('Uzbekistani Som', 'invoicing'),
485
+        'VEF' => __('Venezuelan Bol&iacute;var', 'invoicing'),
486
+        'VND' => __('Vietnamese Dong', 'invoicing'),
487
+        'VUV' => __('Vanuatu Vatu', 'invoicing'),
488
+        'WST' => __('Samoan Tala', 'invoicing'),
489
+        'XAF' => __('Central African CFA Franc', 'invoicing'),
490
+        'XCD' => __('East Caribbean Dollar', 'invoicing'),
491
+        'XOF' => __('West African CFA Franc', 'invoicing'),
492
+        'XPF' => __('CFP Franc', 'invoicing'),
493
+        'YER' => __('Yemeni Rial', 'invoicing'),
494
+        'ZAR' => __('South African Rand', 'invoicing'),
495
+        'ZMW' => __('Zambian Kwacha', 'invoicing'),
496 496
     );
497 497
     
498 498
     //asort( $currencies ); // this
499 499
 
500
-    return apply_filters( 'wpinv_currencies', $currencies );
500
+    return apply_filters('wpinv_currencies', $currencies);
501 501
 }
502 502
 
503
-function wpinv_price( $amount = '', $currency = '' ) {
504
-    if( empty( $currency ) ) {
503
+function wpinv_price($amount = '', $currency = '') {
504
+    if (empty($currency)) {
505 505
         $currency = wpinv_get_currency();
506 506
     }
507 507
 
@@ -509,14 +509,14 @@  discard block
 block discarded – undo
509 509
 
510 510
     $negative = $amount < 0;
511 511
 
512
-    if ( $negative ) {
513
-        $amount = substr( $amount, 1 );
512
+    if ($negative) {
513
+        $amount = substr($amount, 1);
514 514
     }
515 515
 
516
-    $symbol = wpinv_currency_symbol( $currency );
516
+    $symbol = wpinv_currency_symbol($currency);
517 517
 
518
-    if ( $position == 'left' || $position == 'left_space' ) {
519
-        switch ( $currency ) {
518
+    if ($position == 'left' || $position == 'left_space') {
519
+        switch ($currency) {
520 520
             case "GBP" :
521 521
             case "BRL" :
522 522
             case "EUR" :
@@ -528,15 +528,15 @@  discard block
 block discarded – undo
528 528
             case "NZD" :
529 529
             case "SGD" :
530 530
             case "JPY" :
531
-                $price = $position == 'left_space' ? $symbol . ' ' .  $amount : $symbol . $amount;
531
+                $price = $position == 'left_space' ? $symbol . ' ' . $amount : $symbol . $amount;
532 532
                 break;
533 533
             default :
534 534
                 //$price = $currency . ' ' . $amount;
535
-                $price = $position == 'left_space' ? $symbol . ' ' .  $amount : $symbol . $amount;
535
+                $price = $position == 'left_space' ? $symbol . ' ' . $amount : $symbol . $amount;
536 536
                 break;
537 537
         }
538 538
     } else {
539
-        switch ( $currency ) {
539
+        switch ($currency) {
540 540
             case "GBP" :
541 541
             case "BRL" :
542 542
             case "EUR" :
@@ -547,83 +547,83 @@  discard block
 block discarded – undo
547 547
             case "MXN" :
548 548
             case "SGD" :
549 549
             case "JPY" :
550
-                $price = $position == 'right_space' ? $amount . ' ' .  $symbol : $amount . $symbol;
550
+                $price = $position == 'right_space' ? $amount . ' ' . $symbol : $amount . $symbol;
551 551
                 break;
552 552
             default :
553 553
                 //$price = $amount . ' ' . $currency;
554
-                $price = $position == 'right_space' ? $amount . ' ' .  $symbol : $amount . $symbol;
554
+                $price = $position == 'right_space' ? $amount . ' ' . $symbol : $amount . $symbol;
555 555
                 break;
556 556
         }
557 557
     }
558 558
     
559
-    if ( $negative ) {
559
+    if ($negative) {
560 560
         $price = '-' . $price;
561 561
     }
562 562
     
563
-    $price = apply_filters( 'wpinv_' . strtolower( $currency ) . '_currency_filter_' . $position, $price, $currency, $amount );
563
+    $price = apply_filters('wpinv_' . strtolower($currency) . '_currency_filter_' . $position, $price, $currency, $amount);
564 564
 
565 565
     return $price;
566 566
 }
567 567
 
568
-function wpinv_format_amount( $amount, $decimals = NULL, $calculate = false ) {
568
+function wpinv_format_amount($amount, $decimals = NULL, $calculate = false) {
569 569
     $thousands_sep = wpinv_thousands_separator();
570 570
     $decimal_sep   = wpinv_decimal_separator();
571 571
 
572
-    if ( $decimals === NULL ) {
572
+    if ($decimals === NULL) {
573 573
         $decimals = wpinv_decimals();
574 574
     }
575 575
 
576
-    if ( $decimal_sep == ',' && false !== ( $sep_found = strpos( $amount, $decimal_sep ) ) ) {
577
-        $whole = substr( $amount, 0, $sep_found );
578
-        $part = substr( $amount, $sep_found + 1, ( strlen( $amount ) - 1 ) );
576
+    if ($decimal_sep == ',' && false !== ($sep_found = strpos($amount, $decimal_sep))) {
577
+        $whole = substr($amount, 0, $sep_found);
578
+        $part = substr($amount, $sep_found + 1, (strlen($amount) - 1));
579 579
         $amount = $whole . '.' . $part;
580 580
     }
581 581
 
582
-    if ( $thousands_sep == ',' && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) {
583
-        $amount = str_replace( ',', '', $amount );
582
+    if ($thousands_sep == ',' && false !== ($found = strpos($amount, $thousands_sep))) {
583
+        $amount = str_replace(',', '', $amount);
584 584
     }
585 585
 
586
-    if ( $thousands_sep == ' ' && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) {
587
-        $amount = str_replace( ' ', '', $amount );
586
+    if ($thousands_sep == ' ' && false !== ($found = strpos($amount, $thousands_sep))) {
587
+        $amount = str_replace(' ', '', $amount);
588 588
     }
589 589
 
590
-    if ( empty( $amount ) ) {
590
+    if (empty($amount)) {
591 591
         $amount = 0;
592 592
     }
593 593
     
594
-    $decimals  = apply_filters( 'wpinv_amount_format_decimals', $decimals ? $decimals : 0, $amount, $calculate );
595
-    $formatted = number_format( (float)$amount, $decimals, $decimal_sep, $thousands_sep );
594
+    $decimals  = apply_filters('wpinv_amount_format_decimals', $decimals ? $decimals : 0, $amount, $calculate);
595
+    $formatted = number_format((float) $amount, $decimals, $decimal_sep, $thousands_sep);
596 596
     
597
-    if ( $calculate ) {
598
-        if ( $thousands_sep === "," ) {
599
-            $formatted = str_replace( ",", "", $formatted );
597
+    if ($calculate) {
598
+        if ($thousands_sep === ",") {
599
+            $formatted = str_replace(",", "", $formatted);
600 600
         }
601 601
         
602
-        if ( $decimal_sep === "," ) {
603
-            $formatted = str_replace( ",", ".", $formatted );
602
+        if ($decimal_sep === ",") {
603
+            $formatted = str_replace(",", ".", $formatted);
604 604
         }
605 605
     }
606 606
 
607
-    return apply_filters( 'wpinv_amount_format', $formatted, $amount, $decimals, $decimal_sep, $thousands_sep, $calculate );
607
+    return apply_filters('wpinv_amount_format', $formatted, $amount, $decimals, $decimal_sep, $thousands_sep, $calculate);
608 608
 }
609
-add_filter( 'wpinv_amount_format_decimals', 'wpinv_currency_decimal_filter', 10, 1 );
609
+add_filter('wpinv_amount_format_decimals', 'wpinv_currency_decimal_filter', 10, 1);
610 610
 
611
-function wpinv_sanitize_key( $key ) {
611
+function wpinv_sanitize_key($key) {
612 612
     $raw_key = $key;
613
-    $key = preg_replace( '/[^a-zA-Z0-9_\-\.\:\/]/', '', $key );
613
+    $key = preg_replace('/[^a-zA-Z0-9_\-\.\:\/]/', '', $key);
614 614
 
615
-    return apply_filters( 'wpinv_sanitize_key', $key, $raw_key );
615
+    return apply_filters('wpinv_sanitize_key', $key, $raw_key);
616 616
 }
617 617
 
618
-function wpinv_get_file_extension( $str ) {
619
-    $parts = explode( '.', $str );
620
-    return end( $parts );
618
+function wpinv_get_file_extension($str) {
619
+    $parts = explode('.', $str);
620
+    return end($parts);
621 621
 }
622 622
 
623
-function wpinv_string_is_image_url( $str ) {
624
-    $ext = wpinv_get_file_extension( $str );
623
+function wpinv_string_is_image_url($str) {
624
+    $ext = wpinv_get_file_extension($str);
625 625
 
626
-    switch ( strtolower( $ext ) ) {
626
+    switch (strtolower($ext)) {
627 627
         case 'jpeg';
628 628
         case 'jpg';
629 629
             $return = true;
@@ -639,33 +639,33 @@  discard block
 block discarded – undo
639 639
             break;
640 640
     }
641 641
 
642
-    return (bool)apply_filters( 'wpinv_string_is_image', $return, $str );
642
+    return (bool) apply_filters('wpinv_string_is_image', $return, $str);
643 643
 }
644 644
 
645
-function wpinv_error_log( $log, $title = '', $file = '', $line = '', $exit = false ) {
646
-    $should_log = apply_filters( 'wpinv_log_errors', WP_DEBUG );
645
+function wpinv_error_log($log, $title = '', $file = '', $line = '', $exit = false) {
646
+    $should_log = apply_filters('wpinv_log_errors', WP_DEBUG);
647 647
     
648
-    if ( true === $should_log ) {
648
+    if (true === $should_log) {
649 649
         $label = '';
650
-        if ( $file && $file !== '' ) {
651
-            $label .= basename( $file ) . ( $line ? '(' . $line . ')' : '' );
650
+        if ($file && $file !== '') {
651
+            $label .= basename($file) . ($line ? '(' . $line . ')' : '');
652 652
         }
653 653
         
654
-        if ( $title && $title !== '' ) {
654
+        if ($title && $title !== '') {
655 655
             $label = $label !== '' ? $label . ' ' : '';
656 656
             $label .= $title . ' ';
657 657
         }
658 658
         
659
-        $label = $label !== '' ? trim( $label ) . ' : ' : '';
659
+        $label = $label !== '' ? trim($label) . ' : ' : '';
660 660
         
661
-        if ( is_array( $log ) || is_object( $log ) ) {
662
-            error_log( $label . print_r( $log, true ) );
661
+        if (is_array($log) || is_object($log)) {
662
+            error_log($label . print_r($log, true));
663 663
         } else {
664
-            error_log( $label . $log );
664
+            error_log($label . $log);
665 665
         }
666 666
 
667
-        error_log( wp_debug_backtrace_summary() );
668
-        if ( $exit ) {
667
+        error_log(wp_debug_backtrace_summary());
668
+        if ($exit) {
669 669
             exit;
670 670
         }
671 671
     }
@@ -673,32 +673,32 @@  discard block
 block discarded – undo
673 673
 
674 674
 function wpinv_is_ajax_disabled() {
675 675
     $retval = false;
676
-    return apply_filters( 'wpinv_is_ajax_disabled', $retval );
676
+    return apply_filters('wpinv_is_ajax_disabled', $retval);
677 677
 }
678 678
 
679
-function wpinv_get_current_page_url( $nocache = false ) {
679
+function wpinv_get_current_page_url($nocache = false) {
680 680
     global $wp;
681 681
 
682
-    if ( get_option( 'permalink_structure' ) ) {
683
-        $base = trailingslashit( home_url( $wp->request ) );
682
+    if (get_option('permalink_structure')) {
683
+        $base = trailingslashit(home_url($wp->request));
684 684
     } else {
685
-        $base = add_query_arg( $wp->query_string, '', trailingslashit( home_url( $wp->request ) ) );
686
-        $base = remove_query_arg( array( 'post_type', 'name' ), $base );
685
+        $base = add_query_arg($wp->query_string, '', trailingslashit(home_url($wp->request)));
686
+        $base = remove_query_arg(array('post_type', 'name'), $base);
687 687
     }
688 688
 
689 689
     $scheme = is_ssl() ? 'https' : 'http';
690
-    $uri    = set_url_scheme( $base, $scheme );
690
+    $uri    = set_url_scheme($base, $scheme);
691 691
 
692
-    if ( is_front_page() ) {
693
-        $uri = home_url( '/' );
694
-    } elseif ( wpinv_is_checkout( array(), false ) ) {
692
+    if (is_front_page()) {
693
+        $uri = home_url('/');
694
+    } elseif (wpinv_is_checkout(array(), false)) {
695 695
         $uri = wpinv_get_checkout_uri();
696 696
     }
697 697
 
698
-    $uri = apply_filters( 'wpinv_get_current_page_url', $uri );
698
+    $uri = apply_filters('wpinv_get_current_page_url', $uri);
699 699
 
700
-    if ( $nocache ) {
701
-        $uri = wpinv_add_cache_busting( $uri );
700
+    if ($nocache) {
701
+        $uri = wpinv_add_cache_busting($uri);
702 702
     }
703 703
 
704 704
     return $uri;
@@ -711,46 +711,46 @@  discard block
 block discarded – undo
711 711
  * @param string $name  Constant name.
712 712
  * @param mixed  $value Value.
713 713
  */
714
-function getpaid_maybe_define_constant( $name, $value ) {
715
-	if ( ! defined( $name ) ) {
716
-		define( $name, $value );
714
+function getpaid_maybe_define_constant($name, $value) {
715
+	if (!defined($name)) {
716
+		define($name, $value);
717 717
 	}
718 718
 }
719 719
 
720 720
 function wpinv_get_php_arg_separator_output() {
721
-	return ini_get( 'arg_separator.output' );
721
+	return ini_get('arg_separator.output');
722 722
 }
723 723
 
724
-function wpinv_rgb_from_hex( $color ) {
725
-    $color = str_replace( '#', '', $color );
724
+function wpinv_rgb_from_hex($color) {
725
+    $color = str_replace('#', '', $color);
726 726
 
727 727
     // Convert shorthand colors to full format, e.g. "FFF" -> "FFFFFF"
728
-    $color = preg_replace( '~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color );
729
-    if ( empty( $color ) ) {
728
+    $color = preg_replace('~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color);
729
+    if (empty($color)) {
730 730
         return NULL;
731 731
     }
732 732
 
733
-    $color = str_split( $color );
733
+    $color = str_split($color);
734 734
 
735 735
     $rgb      = array();
736
-    $rgb['R'] = hexdec( $color[0] . $color[1] );
737
-    $rgb['G'] = hexdec( $color[2] . $color[3] );
738
-    $rgb['B'] = hexdec( $color[4] . $color[5] );
736
+    $rgb['R'] = hexdec($color[0] . $color[1]);
737
+    $rgb['G'] = hexdec($color[2] . $color[3]);
738
+    $rgb['B'] = hexdec($color[4] . $color[5]);
739 739
 
740 740
     return $rgb;
741 741
 }
742 742
 
743
-function wpinv_hex_darker( $color, $factor = 30 ) {
744
-    $base  = wpinv_rgb_from_hex( $color );
743
+function wpinv_hex_darker($color, $factor = 30) {
744
+    $base  = wpinv_rgb_from_hex($color);
745 745
     $color = '#';
746 746
 
747
-    foreach ( $base as $k => $v ) {
747
+    foreach ($base as $k => $v) {
748 748
         $amount      = $v / 100;
749
-        $amount      = round( $amount * $factor );
749
+        $amount      = round($amount * $factor);
750 750
         $new_decimal = $v - $amount;
751 751
 
752
-        $new_hex_component = dechex( $new_decimal );
753
-        if ( strlen( $new_hex_component ) < 2 ) {
752
+        $new_hex_component = dechex($new_decimal);
753
+        if (strlen($new_hex_component) < 2) {
754 754
             $new_hex_component = "0" . $new_hex_component;
755 755
         }
756 756
         $color .= $new_hex_component;
@@ -759,18 +759,18 @@  discard block
 block discarded – undo
759 759
     return $color;
760 760
 }
761 761
 
762
-function wpinv_hex_lighter( $color, $factor = 30 ) {
763
-    $base  = wpinv_rgb_from_hex( $color );
762
+function wpinv_hex_lighter($color, $factor = 30) {
763
+    $base  = wpinv_rgb_from_hex($color);
764 764
     $color = '#';
765 765
 
766
-    foreach ( $base as $k => $v ) {
766
+    foreach ($base as $k => $v) {
767 767
         $amount      = 255 - $v;
768 768
         $amount      = $amount / 100;
769
-        $amount      = round( $amount * $factor );
769
+        $amount      = round($amount * $factor);
770 770
         $new_decimal = $v + $amount;
771 771
 
772
-        $new_hex_component = dechex( $new_decimal );
773
-        if ( strlen( $new_hex_component ) < 2 ) {
772
+        $new_hex_component = dechex($new_decimal);
773
+        if (strlen($new_hex_component) < 2) {
774 774
             $new_hex_component = "0" . $new_hex_component;
775 775
         }
776 776
         $color .= $new_hex_component;
@@ -779,22 +779,22 @@  discard block
 block discarded – undo
779 779
     return $color;
780 780
 }
781 781
 
782
-function wpinv_light_or_dark( $color, $dark = '#000000', $light = '#FFFFFF' ) {
783
-    $hex = str_replace( '#', '', $color );
782
+function wpinv_light_or_dark($color, $dark = '#000000', $light = '#FFFFFF') {
783
+    $hex = str_replace('#', '', $color);
784 784
 
785
-    $c_r = hexdec( substr( $hex, 0, 2 ) );
786
-    $c_g = hexdec( substr( $hex, 2, 2 ) );
787
-    $c_b = hexdec( substr( $hex, 4, 2 ) );
785
+    $c_r = hexdec(substr($hex, 0, 2));
786
+    $c_g = hexdec(substr($hex, 2, 2));
787
+    $c_b = hexdec(substr($hex, 4, 2));
788 788
 
789
-    $brightness = ( ( $c_r * 299 ) + ( $c_g * 587 ) + ( $c_b * 114 ) ) / 1000;
789
+    $brightness = (($c_r * 299) + ($c_g * 587) + ($c_b * 114)) / 1000;
790 790
 
791 791
     return $brightness > 155 ? $dark : $light;
792 792
 }
793 793
 
794
-function wpinv_format_hex( $hex ) {
795
-    $hex = trim( str_replace( '#', '', $hex ) );
794
+function wpinv_format_hex($hex) {
795
+    $hex = trim(str_replace('#', '', $hex));
796 796
 
797
-    if ( strlen( $hex ) == 3 ) {
797
+    if (strlen($hex) == 3) {
798 798
         $hex = $hex[0] . $hex[0] . $hex[1] . $hex[1] . $hex[2] . $hex[2];
799 799
     }
800 800
 
@@ -814,12 +814,12 @@  discard block
 block discarded – undo
814 814
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
815 815
  * @return string
816 816
  */
817
-function wpinv_utf8_strimwidth( $str, $start, $width, $trimmaker = '', $encoding = 'UTF-8' ) {
818
-    if ( function_exists( 'mb_strimwidth' ) ) {
819
-        return mb_strimwidth( $str, $start, $width, $trimmaker, $encoding );
817
+function wpinv_utf8_strimwidth($str, $start, $width, $trimmaker = '', $encoding = 'UTF-8') {
818
+    if (function_exists('mb_strimwidth')) {
819
+        return mb_strimwidth($str, $start, $width, $trimmaker, $encoding);
820 820
     }
821 821
     
822
-    return wpinv_utf8_substr( $str, $start, $width, $encoding ) . $trimmaker;
822
+    return wpinv_utf8_substr($str, $start, $width, $encoding) . $trimmaker;
823 823
 }
824 824
 
825 825
 /**
@@ -831,28 +831,28 @@  discard block
 block discarded – undo
831 831
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
832 832
  * @return int Returns the number of characters in string.
833 833
  */
834
-function wpinv_utf8_strlen( $str, $encoding = 'UTF-8' ) {
835
-    if ( function_exists( 'mb_strlen' ) ) {
836
-        return mb_strlen( $str, $encoding );
834
+function wpinv_utf8_strlen($str, $encoding = 'UTF-8') {
835
+    if (function_exists('mb_strlen')) {
836
+        return mb_strlen($str, $encoding);
837 837
     }
838 838
         
839
-    return strlen( $str );
839
+    return strlen($str);
840 840
 }
841 841
 
842
-function wpinv_utf8_strtolower( $str, $encoding = 'UTF-8' ) {
843
-    if ( function_exists( 'mb_strtolower' ) ) {
844
-        return mb_strtolower( $str, $encoding );
842
+function wpinv_utf8_strtolower($str, $encoding = 'UTF-8') {
843
+    if (function_exists('mb_strtolower')) {
844
+        return mb_strtolower($str, $encoding);
845 845
     }
846 846
     
847
-    return strtolower( $str );
847
+    return strtolower($str);
848 848
 }
849 849
 
850
-function wpinv_utf8_strtoupper( $str, $encoding = 'UTF-8' ) {
851
-    if ( function_exists( 'mb_strtoupper' ) ) {
852
-        return mb_strtoupper( $str, $encoding );
850
+function wpinv_utf8_strtoupper($str, $encoding = 'UTF-8') {
851
+    if (function_exists('mb_strtoupper')) {
852
+        return mb_strtoupper($str, $encoding);
853 853
     }
854 854
     
855
-    return strtoupper( $str );
855
+    return strtoupper($str);
856 856
 }
857 857
 
858 858
 /**
@@ -866,12 +866,12 @@  discard block
 block discarded – undo
866 866
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
867 867
  * @return int Returns the position of the first occurrence of search in the string.
868 868
  */
869
-function wpinv_utf8_strpos( $str, $find, $offset = 0, $encoding = 'UTF-8' ) {
870
-    if ( function_exists( 'mb_strpos' ) ) {
871
-        return mb_strpos( $str, $find, $offset, $encoding );
869
+function wpinv_utf8_strpos($str, $find, $offset = 0, $encoding = 'UTF-8') {
870
+    if (function_exists('mb_strpos')) {
871
+        return mb_strpos($str, $find, $offset, $encoding);
872 872
     }
873 873
         
874
-    return strpos( $str, $find, $offset );
874
+    return strpos($str, $find, $offset);
875 875
 }
876 876
 
877 877
 /**
@@ -885,12 +885,12 @@  discard block
 block discarded – undo
885 885
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
886 886
  * @return int Returns the position of the last occurrence of search.
887 887
  */
888
-function wpinv_utf8_strrpos( $str, $find, $offset = 0, $encoding = 'UTF-8' ) {
889
-    if ( function_exists( 'mb_strrpos' ) ) {
890
-        return mb_strrpos( $str, $find, $offset, $encoding );
888
+function wpinv_utf8_strrpos($str, $find, $offset = 0, $encoding = 'UTF-8') {
889
+    if (function_exists('mb_strrpos')) {
890
+        return mb_strrpos($str, $find, $offset, $encoding);
891 891
     }
892 892
         
893
-    return strrpos( $str, $find, $offset );
893
+    return strrpos($str, $find, $offset);
894 894
 }
895 895
 
896 896
 /**
@@ -905,16 +905,16 @@  discard block
 block discarded – undo
905 905
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
906 906
  * @return string
907 907
  */
908
-function wpinv_utf8_substr( $str, $start, $length = null, $encoding = 'UTF-8' ) {
909
-    if ( function_exists( 'mb_substr' ) ) {
910
-        if ( $length === null ) {
911
-            return mb_substr( $str, $start, wpinv_utf8_strlen( $str, $encoding ), $encoding );
908
+function wpinv_utf8_substr($str, $start, $length = null, $encoding = 'UTF-8') {
909
+    if (function_exists('mb_substr')) {
910
+        if ($length === null) {
911
+            return mb_substr($str, $start, wpinv_utf8_strlen($str, $encoding), $encoding);
912 912
         } else {
913
-            return mb_substr( $str, $start, $length, $encoding );
913
+            return mb_substr($str, $start, $length, $encoding);
914 914
         }
915 915
     }
916 916
         
917
-    return substr( $str, $start, $length );
917
+    return substr($str, $start, $length);
918 918
 }
919 919
 
920 920
 /**
@@ -926,48 +926,48 @@  discard block
 block discarded – undo
926 926
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
927 927
  * @return string The width of string.
928 928
  */
929
-function wpinv_utf8_strwidth( $str, $encoding = 'UTF-8' ) {
930
-    if ( function_exists( 'mb_strwidth' ) ) {
931
-        return mb_strwidth( $str, $encoding );
929
+function wpinv_utf8_strwidth($str, $encoding = 'UTF-8') {
930
+    if (function_exists('mb_strwidth')) {
931
+        return mb_strwidth($str, $encoding);
932 932
     }
933 933
     
934
-    return wpinv_utf8_strlen( $str, $encoding );
934
+    return wpinv_utf8_strlen($str, $encoding);
935 935
 }
936 936
 
937
-function wpinv_utf8_ucfirst( $str, $lower_str_end = false, $encoding = 'UTF-8' ) {
938
-    if ( function_exists( 'mb_strlen' ) ) {
939
-        $first_letter = wpinv_utf8_strtoupper( wpinv_utf8_substr( $str, 0, 1, $encoding ), $encoding );
937
+function wpinv_utf8_ucfirst($str, $lower_str_end = false, $encoding = 'UTF-8') {
938
+    if (function_exists('mb_strlen')) {
939
+        $first_letter = wpinv_utf8_strtoupper(wpinv_utf8_substr($str, 0, 1, $encoding), $encoding);
940 940
         $str_end = "";
941 941
         
942
-        if ( $lower_str_end ) {
943
-            $str_end = wpinv_utf8_strtolower( wpinv_utf8_substr( $str, 1, wpinv_utf8_strlen( $str, $encoding ), $encoding ), $encoding );
942
+        if ($lower_str_end) {
943
+            $str_end = wpinv_utf8_strtolower(wpinv_utf8_substr($str, 1, wpinv_utf8_strlen($str, $encoding), $encoding), $encoding);
944 944
         } else {
945
-            $str_end = wpinv_utf8_substr( $str, 1, wpinv_utf8_strlen( $str, $encoding ), $encoding );
945
+            $str_end = wpinv_utf8_substr($str, 1, wpinv_utf8_strlen($str, $encoding), $encoding);
946 946
         }
947 947
 
948 948
         return $first_letter . $str_end;
949 949
     }
950 950
     
951
-    return ucfirst( $str );
951
+    return ucfirst($str);
952 952
 }
953 953
 
954
-function wpinv_utf8_ucwords( $str, $encoding = 'UTF-8' ) {
955
-    if ( function_exists( 'mb_convert_case' ) ) {
956
-        return mb_convert_case( $str, MB_CASE_TITLE, $encoding );
954
+function wpinv_utf8_ucwords($str, $encoding = 'UTF-8') {
955
+    if (function_exists('mb_convert_case')) {
956
+        return mb_convert_case($str, MB_CASE_TITLE, $encoding);
957 957
     }
958 958
     
959
-    return ucwords( $str );
959
+    return ucwords($str);
960 960
 }
961 961
 
962
-function wpinv_period_in_days( $period, $unit ) {
963
-    $period = absint( $period );
962
+function wpinv_period_in_days($period, $unit) {
963
+    $period = absint($period);
964 964
     
965
-    if ( $period > 0 ) {
966
-        if ( in_array( strtolower( $unit ), array( 'w', 'week', 'weeks' ) ) ) {
965
+    if ($period > 0) {
966
+        if (in_array(strtolower($unit), array('w', 'week', 'weeks'))) {
967 967
             $period = $period * 7;
968
-        } else if ( in_array( strtolower( $unit ), array( 'm', 'month', 'months' ) ) ) {
968
+        } else if (in_array(strtolower($unit), array('m', 'month', 'months'))) {
969 969
             $period = $period * 30;
970
-        } else if ( in_array( strtolower( $unit ), array( 'y', 'year', 'years' ) ) ) {
970
+        } else if (in_array(strtolower($unit), array('y', 'year', 'years'))) {
971 971
             $period = $period * 365;
972 972
         }
973 973
     }
@@ -975,14 +975,14 @@  discard block
 block discarded – undo
975 975
     return $period;
976 976
 }
977 977
 
978
-function wpinv_cal_days_in_month( $calendar, $month, $year ) {
979
-    if ( function_exists( 'cal_days_in_month' ) ) {
980
-        return cal_days_in_month( $calendar, $month, $year );
978
+function wpinv_cal_days_in_month($calendar, $month, $year) {
979
+    if (function_exists('cal_days_in_month')) {
980
+        return cal_days_in_month($calendar, $month, $year);
981 981
     }
982 982
 
983 983
     // Fallback in case the calendar extension is not loaded in PHP
984 984
     // Only supports Gregorian calendar
985
-    return date( 't', mktime( 0, 0, 0, $month, 1, $year ) );
985
+    return date('t', mktime(0, 0, 0, $month, 1, $year));
986 986
 }
987 987
 
988 988
 /**
@@ -993,11 +993,11 @@  discard block
 block discarded – undo
993 993
  *
994 994
  * @return string
995 995
  */
996
-function wpi_help_tip( $tip, $allow_html = false ) {
997
-    if ( $allow_html ) {
998
-        $tip = wpi_sanitize_tooltip( $tip );
996
+function wpi_help_tip($tip, $allow_html = false) {
997
+    if ($allow_html) {
998
+        $tip = wpi_sanitize_tooltip($tip);
999 999
     } else {
1000
-        $tip = esc_attr( $tip );
1000
+        $tip = esc_attr($tip);
1001 1001
     }
1002 1002
 
1003 1003
     return '<span class="wpi-help-tip dashicons dashicons-editor-help" title="' . $tip . '"></span>';
@@ -1011,8 +1011,8 @@  discard block
 block discarded – undo
1011 1011
  * @param string $var
1012 1012
  * @return string
1013 1013
  */
1014
-function wpi_sanitize_tooltip( $var ) {
1015
-    return htmlspecialchars( wp_kses( html_entity_decode( $var ), array(
1014
+function wpi_sanitize_tooltip($var) {
1015
+    return htmlspecialchars(wp_kses(html_entity_decode($var), array(
1016 1016
         'br'     => array(),
1017 1017
         'em'     => array(),
1018 1018
         'strong' => array(),
@@ -1022,7 +1022,7 @@  discard block
 block discarded – undo
1022 1022
         'li'     => array(),
1023 1023
         'ol'     => array(),
1024 1024
         'p'      => array(),
1025
-    ) ) );
1025
+    )));
1026 1026
 }
1027 1027
 
1028 1028
 /**
@@ -1032,7 +1032,7 @@  discard block
 block discarded – undo
1032 1032
  */
1033 1033
 function wpinv_get_screen_ids() {
1034 1034
 
1035
-    $screen_id = sanitize_title( __( 'Invoicing', 'invoicing' ) );
1035
+    $screen_id = sanitize_title(__('Invoicing', 'invoicing'));
1036 1036
 
1037 1037
     $screen_ids = array(
1038 1038
         'toplevel_page_' . $screen_id,
@@ -1050,7 +1050,7 @@  discard block
 block discarded – undo
1050 1050
         'invoicing_page_wpi-addons',
1051 1051
     );
1052 1052
 
1053
-    return apply_filters( 'wpinv_screen_ids', $screen_ids );
1053
+    return apply_filters('wpinv_screen_ids', $screen_ids);
1054 1054
 }
1055 1055
 
1056 1056
 /**
@@ -1061,14 +1061,14 @@  discard block
 block discarded – undo
1061 1061
  * @param array|string $list List of values.
1062 1062
  * @return array Sanitized array of values.
1063 1063
  */
1064
-function wpinv_parse_list( $list ) {
1064
+function wpinv_parse_list($list) {
1065 1065
 
1066
-    if ( empty( $list ) ) {
1066
+    if (empty($list)) {
1067 1067
         $list = array();
1068 1068
     }
1069 1069
 
1070
-	if ( ! is_array( $list ) ) {
1071
-		return preg_split( '/[\s,]+/', $list, -1, PREG_SPLIT_NO_EMPTY );
1070
+	if (!is_array($list)) {
1071
+		return preg_split('/[\s,]+/', $list, -1, PREG_SPLIT_NO_EMPTY);
1072 1072
 	}
1073 1073
 
1074 1074
 	return $list;
@@ -1082,16 +1082,16 @@  discard block
 block discarded – undo
1082 1082
  * @param string $key Type of data to fetch.
1083 1083
  * @return mixed Fetched data.
1084 1084
  */
1085
-function wpinv_get_data( $key ) {
1085
+function wpinv_get_data($key) {
1086 1086
     
1087 1087
     // Try fetching it from the cache.
1088
-    $data = wp_cache_get( "wpinv-$key", 'wpinv' );
1089
-    if( $data ) {
1088
+    $data = wp_cache_get("wpinv-$key", 'wpinv');
1089
+    if ($data) {
1090 1090
         return $data;
1091 1091
     }
1092 1092
 
1093
-    $data = apply_filters( "wpinv_get_$key", include WPINV_PLUGIN_DIR . "includes/data/$key.php" );
1094
-	wp_cache_set( "wpinv-$key", $data, 'wpinv' );
1093
+    $data = apply_filters("wpinv_get_$key", include WPINV_PLUGIN_DIR . "includes/data/$key.php");
1094
+	wp_cache_set("wpinv-$key", $data, 'wpinv');
1095 1095
 
1096 1096
 	return $data;
1097 1097
 }
@@ -1105,10 +1105,10 @@  discard block
 block discarded – undo
1105 1105
  * @param bool $first_empty Whether or not the first item in the list should be empty
1106 1106
  * @return mixed Fetched data.
1107 1107
  */
1108
-function wpinv_maybe_add_empty_option( $options, $first_empty ) {
1108
+function wpinv_maybe_add_empty_option($options, $first_empty) {
1109 1109
 
1110
-    if ( ! empty( $options ) && $first_empty ) {
1111
-        return array_merge( array( '' => '' ), $options );
1110
+    if (!empty($options) && $first_empty) {
1111
+        return array_merge(array('' => ''), $options);
1112 1112
     }
1113 1113
     return $options;
1114 1114
 
@@ -1120,21 +1120,21 @@  discard block
 block discarded – undo
1120 1120
  * @param mixed $var Data to sanitize.
1121 1121
  * @return string|array
1122 1122
  */
1123
-function wpinv_clean( $var ) {
1123
+function wpinv_clean($var) {
1124 1124
 
1125
-	if ( is_array( $var ) ) {
1126
-		return array_map( 'wpinv_clean', $var );
1125
+	if (is_array($var)) {
1126
+		return array_map('wpinv_clean', $var);
1127 1127
     }
1128 1128
 
1129
-    if ( is_object( $var ) ) {
1130
-		$object_vars = get_object_vars( $var );
1131
-		foreach ( $object_vars as $property_name => $property_value ) {
1132
-			$var->$property_name = wpinv_clean( $property_value );
1129
+    if (is_object($var)) {
1130
+		$object_vars = get_object_vars($var);
1131
+		foreach ($object_vars as $property_name => $property_value) {
1132
+			$var->$property_name = wpinv_clean($property_value);
1133 1133
         }
1134 1134
         return $var;
1135 1135
 	}
1136 1136
     
1137
-    return is_string( $var ) ? sanitize_text_field( $var ) : $var;
1137
+    return is_string($var) ? sanitize_text_field($var) : $var;
1138 1138
 }
1139 1139
 
1140 1140
 /**
@@ -1143,43 +1143,43 @@  discard block
 block discarded – undo
1143 1143
  * @param string $str Data to convert.
1144 1144
  * @return string|array
1145 1145
  */
1146
-function getpaid_convert_price_string_to_options( $str ) {
1146
+function getpaid_convert_price_string_to_options($str) {
1147 1147
 
1148
-	$raw_options = array_map( 'trim', explode( ',', $str ) );
1149
-    $options     = array();
1148
+	$raw_options = array_map('trim', explode(',', $str));
1149
+    $options = array();
1150 1150
 
1151
-    foreach ( $raw_options as $option ) {
1151
+    foreach ($raw_options as $option) {
1152 1152
 
1153
-        if ( '' == $option ) {
1153
+        if ('' == $option) {
1154 1154
             continue;
1155 1155
         }
1156 1156
 
1157
-        $option = array_map( 'trim', explode( '|', $option ) );
1157
+        $option = array_map('trim', explode('|', $option));
1158 1158
 
1159 1159
         $price = null;
1160 1160
         $label = null;
1161 1161
 
1162
-        if ( isset( $option[0] ) && '' !=  $option[0] ) {
1163
-            $label  = $option[0];
1162
+        if (isset($option[0]) && '' != $option[0]) {
1163
+            $label = $option[0];
1164 1164
         }
1165 1165
 
1166
-        if ( isset( $option[1] ) && '' !=  $option[1] ) {
1166
+        if (isset($option[1]) && '' != $option[1]) {
1167 1167
             $price = $option[1];
1168 1168
         }
1169 1169
 
1170
-        if ( ! isset( $price ) ) {
1170
+        if (!isset($price)) {
1171 1171
             $price = $label;
1172 1172
         }
1173 1173
 
1174
-        if ( ! isset( $price ) || ! is_numeric( $price ) ) {
1174
+        if (!isset($price) || !is_numeric($price)) {
1175 1175
             continue;
1176 1176
         }
1177 1177
 
1178
-        if ( ! isset( $label ) ) {
1178
+        if (!isset($label)) {
1179 1179
             $label = $price;
1180 1180
         }
1181 1181
 
1182
-        $options[ $price ] = $label;
1182
+        $options[$price] = $label;
1183 1183
     }
1184 1184
 
1185 1185
     return $options;
@@ -1188,8 +1188,8 @@  discard block
 block discarded – undo
1188 1188
 /**
1189 1189
  * Returns the help tip.
1190 1190
  */
1191
-function getpaid_get_help_tip( $tip, $additional_classes = '' ) {
1192
-    $additional_classes = sanitize_html_class( $additional_classes );
1193
-    $tip                = esc_attr__( $tip );
1191
+function getpaid_get_help_tip($tip, $additional_classes = '') {
1192
+    $additional_classes = sanitize_html_class($additional_classes);
1193
+    $tip                = esc_attr__($tip);
1194 1194
     return "<span class='wpi-help-tip dashicons dashicons-editor-help $additional_classes' title='$tip'></span>";
1195 1195
 }
1196 1196
\ No newline at end of file
Please login to merge, or discard this patch.
includes/api/class-wpinv-rest-discounts-controller.php 2 patches
Indentation   +971 added lines, -971 removed lines patch added patch discarded remove patch
@@ -20,92 +20,92 @@  discard block
 block discarded – undo
20 20
 class WPInv_REST_Discounts_Controller extends WP_REST_Posts_Controller {
21 21
 
22 22
     /**
23
-	 * Post type.
24
-	 *
25
-	 * @var string
26
-	 */
27
-	protected $post_type = 'wpi_discount';
23
+     * Post type.
24
+     *
25
+     * @var string
26
+     */
27
+    protected $post_type = 'wpi_discount';
28 28
 	
29
-	/**
30
-	 * Cached results of get_item_schema.
31
-	 *
32
-	 * @since 1.0.13
33
-	 * @var array
34
-	 */
35
-	protected $schema;
29
+    /**
30
+     * Cached results of get_item_schema.
31
+     *
32
+     * @since 1.0.13
33
+     * @var array
34
+     */
35
+    protected $schema;
36 36
 
37 37
     /**
38
-	 * Constructor.
39
-	 *
40
-	 * @since 1.0.13
41
-	 *
42
-	 * @param string $namespace Api Namespace
43
-	 */
44
-	public function __construct( $namespace ) {
38
+     * Constructor.
39
+     *
40
+     * @since 1.0.13
41
+     *
42
+     * @param string $namespace Api Namespace
43
+     */
44
+    public function __construct( $namespace ) {
45 45
         
46 46
         // Set api namespace...
47
-		$this->namespace = $namespace;
47
+        $this->namespace = $namespace;
48 48
 
49 49
         // ... and the rest base
50 50
         $this->rest_base = 'discounts';
51 51
 		
52 52
     }
53 53
 	
54
-	/**
55
-	 * Registers the routes for the objects of the controller.
56
-	 *
57
-	 * @since 1.0.13
58
-	 *
59
-	 * @see register_rest_route()
60
-	 */
61
-	public function register_routes() {
62
-
63
-		parent::register_routes();
64
-
65
-		register_rest_route(
66
-			$this->namespace,
67
-			'/' . $this->rest_base . '/discount-types',
68
-			array(
69
-				array(
70
-					'methods'             => WP_REST_Server::READABLE,
71
-					'callback'            => array( $this, 'get_discount_types' ),
72
-					'permission_callback' => '__return_true',
73
-				),
74
-			)
75
-		);
76
-
77
-	}
54
+    /**
55
+     * Registers the routes for the objects of the controller.
56
+     *
57
+     * @since 1.0.13
58
+     *
59
+     * @see register_rest_route()
60
+     */
61
+    public function register_routes() {
62
+
63
+        parent::register_routes();
64
+
65
+        register_rest_route(
66
+            $this->namespace,
67
+            '/' . $this->rest_base . '/discount-types',
68
+            array(
69
+                array(
70
+                    'methods'             => WP_REST_Server::READABLE,
71
+                    'callback'            => array( $this, 'get_discount_types' ),
72
+                    'permission_callback' => '__return_true',
73
+                ),
74
+            )
75
+        );
76
+
77
+    }
78 78
 
79 79
     /**
80
-	 * Checks if a given request has access to read discounts.
80
+     * Checks if a given request has access to read discounts.
81 81
      * 
82
-	 *
83
-	 * @since 1.0.13
84
-	 *
85
-	 * @param WP_REST_Request $request Full details about the request.
86
-	 * @return true|WP_Error True if the request has read access, WP_Error object otherwise.
87
-	 */
88
-	public function get_items_permissions_check( $request ) {
82
+     *
83
+     * @since 1.0.13
84
+     *
85
+     * @param WP_REST_Request $request Full details about the request.
86
+     * @return true|WP_Error True if the request has read access, WP_Error object otherwise.
87
+     */
88
+    public function get_items_permissions_check( $request ) {
89 89
 	
90
-		if ( wpinv_current_user_can_manage_invoicing() ) {
91
-			return true;
92
-		}
90
+        if ( wpinv_current_user_can_manage_invoicing() ) {
91
+            return true;
92
+        }
93 93
 
94
-		return new WP_Error( 'rest_forbidden_context', __( 'Sorry, you are not allowed to view invoice discounts.', 'invoicing' ), array( 'status' => rest_authorization_required_code() ) );
94
+        return new WP_Error( 'rest_forbidden_context', __( 'Sorry, you are not allowed to view invoice discounts.', 'invoicing' ), array( 'status' => rest_authorization_required_code() ) );
95 95
 
96 96
     }
97 97
     
98 98
     /**
99
-	 * Retrieves a collection of discounts.
100
-	 *
101
-	 * @since 1.0.13
102
-	 *
103
-	 * @param WP_REST_Request $request Full details about the request.
104
-	 * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
105
-	 */
106
-	public function get_items( $request ) {
99
+     * Retrieves a collection of discounts.
100
+     *
101
+     * @since 1.0.13
102
+     *
103
+     * @param WP_REST_Request $request Full details about the request.
104
+     * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
105
+     */
106
+    public function get_items( $request ) {
107 107
 		
108
-		// Retrieve the list of registered item query parameters.
108
+        // Retrieve the list of registered item query parameters.
109 109
         $registered = $this->get_collection_params();
110 110
         
111 111
         $args       = array();
@@ -116,52 +116,52 @@  discard block
 block discarded – undo
116 116
                 $args[ $key ] = $request[ $key];
117 117
             }
118 118
 
119
-		} 
120
-
121
-		/**
122
-		 * Filters the wpinv_get_all_discounts arguments for discounts rest requests.
123
-		 *
124
-		 *
125
-		 * @since 1.0.13
126
-		 *
127
-		 *
128
-		 * @param array           $args    Key value array of query var to query value.
129
-		 * @param WP_REST_Request $request The request used.
130
-		 */
119
+        } 
120
+
121
+        /**
122
+         * Filters the wpinv_get_all_discounts arguments for discounts rest requests.
123
+         *
124
+         *
125
+         * @since 1.0.13
126
+         *
127
+         *
128
+         * @param array           $args    Key value array of query var to query value.
129
+         * @param WP_REST_Request $request The request used.
130
+         */
131 131
         $args       = apply_filters( "wpinv_rest_get_discounts_arguments", $args, $request, $this );
132 132
 		
133
-		// Special args
134
-		$args[ 'return' ]   = 'objects';
135
-		$args[ 'paginate' ] = true;
133
+        // Special args
134
+        $args[ 'return' ]   = 'objects';
135
+        $args[ 'paginate' ] = true;
136 136
 
137 137
         // Run the query.
138
-		$query = wpinv_get_all_discounts( $args );
138
+        $query = wpinv_get_all_discounts( $args );
139 139
 		
140
-		// Prepare the retrieved discounts
141
-		$discounts = array();
142
-		foreach( $query->discounts as $discount ) {
143
-
144
-			$data       = $this->prepare_item_for_response( $discount, $request );
145
-			$discounts[]    = $this->prepare_response_for_collection( $data );
146
-
147
-		}
148
-
149
-		// Prepare the response.
150
-		$response = rest_ensure_response( $discounts );
151
-		$response->header( 'X-WP-Total', (int) $query->total );
152
-		$response->header( 'X-WP-TotalPages', (int) $query->max_num_pages );
153
-
154
-		/**
155
-		 * Filters the responses for discount requests.
156
-		 *
157
-		 *
158
-		 * @since 1.0.13
159
-		 *
160
-		 *
161
-		 * @param arrWP_REST_Response $response    Response object.
162
-		 * @param WP_REST_Request     $request The request used.
140
+        // Prepare the retrieved discounts
141
+        $discounts = array();
142
+        foreach( $query->discounts as $discount ) {
143
+
144
+            $data       = $this->prepare_item_for_response( $discount, $request );
145
+            $discounts[]    = $this->prepare_response_for_collection( $data );
146
+
147
+        }
148
+
149
+        // Prepare the response.
150
+        $response = rest_ensure_response( $discounts );
151
+        $response->header( 'X-WP-Total', (int) $query->total );
152
+        $response->header( 'X-WP-TotalPages', (int) $query->max_num_pages );
153
+
154
+        /**
155
+         * Filters the responses for discount requests.
156
+         *
157
+         *
158
+         * @since 1.0.13
159
+         *
160
+         *
161
+         * @param arrWP_REST_Response $response    Response object.
162
+         * @param WP_REST_Request     $request The request used.
163 163
          * @param array               $args Array of args used to retrieve the discounts
164
-		 */
164
+         */
165 165
         $response       = apply_filters( "wpinv_rest_discounts_response", $response, $request, $args );
166 166
 
167 167
         return rest_ensure_response( $response );
@@ -169,25 +169,25 @@  discard block
 block discarded – undo
169 169
     }
170 170
 
171 171
     /**
172
-	 * Get the post, if the ID is valid.
173
-	 *
174
-	 * @since 1.0.13
175
-	 *
176
-	 * @param int $discount_id Supplied ID.
177
-	 * @return WP_Post|WP_Error Post object if ID is valid, WP_Error otherwise.
178
-	 */
179
-	protected function get_post( $discount_id ) {
172
+     * Get the post, if the ID is valid.
173
+     *
174
+     * @since 1.0.13
175
+     *
176
+     * @param int $discount_id Supplied ID.
177
+     * @return WP_Post|WP_Error Post object if ID is valid, WP_Error otherwise.
178
+     */
179
+    protected function get_post( $discount_id ) {
180 180
 		
181
-		$error     = new WP_Error( 'rest_item_invalid_id', __( 'Invalid discount ID.', 'invoicing' ), array( 'status' => 404 ) );
181
+        $error     = new WP_Error( 'rest_item_invalid_id', __( 'Invalid discount ID.', 'invoicing' ), array( 'status' => 404 ) );
182 182
 
183 183
         // Ids start from 1
184 184
         if ( (int) $discount_id <= 0 ) {
185
-			return $error;
186
-		}
185
+            return $error;
186
+        }
187 187
 
188
-		$discount = wpinv_get_discount( (int) $discount_id );
189
-		if ( empty( $discount ) ) {
190
-			return $error;
188
+        $discount = wpinv_get_discount( (int) $discount_id );
189
+        if ( empty( $discount ) ) {
190
+            return $error;
191 191
         }
192 192
 
193 193
         return $discount;
@@ -195,25 +195,25 @@  discard block
 block discarded – undo
195 195
     }
196 196
 
197 197
     /**
198
-	 * Checks if a given request has access to read a discount.
199
-	 *
200
-	 * @since 1.0.13
201
-	 *
202
-	 * @param WP_REST_Request $request Full details about the request.
203
-	 * @return bool|WP_Error True if the request has read access for the invoice item, WP_Error object otherwise.
204
-	 */
205
-	public function get_item_permissions_check( $request ) {
198
+     * Checks if a given request has access to read a discount.
199
+     *
200
+     * @since 1.0.13
201
+     *
202
+     * @param WP_REST_Request $request Full details about the request.
203
+     * @return bool|WP_Error True if the request has read access for the invoice item, WP_Error object otherwise.
204
+     */
205
+    public function get_item_permissions_check( $request ) {
206 206
 
207 207
         // Retrieve the discount object.
208 208
         $discount = $this->get_post( $request['id'] );
209 209
         
210 210
         // Ensure it is valid.
211
-		if ( is_wp_error( $discount ) ) {
212
-			return $discount;
213
-		}
211
+        if ( is_wp_error( $discount ) ) {
212
+            return $discount;
213
+        }
214 214
 
215
-		if ( ! wpinv_current_user_can_manage_invoicing() ) {
216
-			return new WP_Error(
215
+        if ( ! wpinv_current_user_can_manage_invoicing() ) {
216
+            return new WP_Error(
217 217
                 'rest_cannot_view', 
218 218
                 __( 'Sorry, you are not allowed to view this discount.', 'invoicing' ), 
219 219
                 array( 
@@ -222,40 +222,40 @@  discard block
 block discarded – undo
222 222
             );
223 223
         }
224 224
 
225
-		return true;
225
+        return true;
226 226
     }
227 227
     
228 228
     /**
229
-	 * Retrieves a single invoice item.
230
-	 *
231
-	 * @since 1.0.13
232
-	 *
233
-	 * @param WP_REST_Request $request Full details about the request.
234
-	 * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
235
-	 */
236
-	public function get_item( $request ) {
229
+     * Retrieves a single invoice item.
230
+     *
231
+     * @since 1.0.13
232
+     *
233
+     * @param WP_REST_Request $request Full details about the request.
234
+     * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
235
+     */
236
+    public function get_item( $request ) {
237 237
 
238 238
         // Fetch the discount.
239 239
         $discount = $this->get_post( $request['id'] );
240 240
         
241 241
         // Abort early if it does not exist
242
-		if ( is_wp_error( $discount ) ) {
243
-			return $discount;
244
-		}
245
-
246
-		// Prepare the response
247
-		$response = $this->prepare_item_for_response( $discount, $request );
248
-
249
-		/**
250
-		 * Filters the responses for single discount requests.
251
-		 *
252
-		 *
253
-		 * @since 1.0.13
254
-		 * @var WP_HTTP_Response
255
-		 *
256
-		 * @param WP_HTTP_Response $response Response.
257
-		 * @param WP_REST_Request  $request The request used.
258
-		 */
242
+        if ( is_wp_error( $discount ) ) {
243
+            return $discount;
244
+        }
245
+
246
+        // Prepare the response
247
+        $response = $this->prepare_item_for_response( $discount, $request );
248
+
249
+        /**
250
+         * Filters the responses for single discount requests.
251
+         *
252
+         *
253
+         * @since 1.0.13
254
+         * @var WP_HTTP_Response
255
+         *
256
+         * @param WP_HTTP_Response $response Response.
257
+         * @param WP_REST_Request  $request The request used.
258
+         */
259 259
         $response       = apply_filters( "wpinv_rest_get_discount_response", $response, $request );
260 260
 
261 261
         return rest_ensure_response( $response );
@@ -263,26 +263,26 @@  discard block
 block discarded – undo
263 263
     }
264 264
     
265 265
     /**
266
-	 * Checks if a given request has access to create an invoice item.
267
-	 *
268
-	 * @since 1.0.13
269
-	 *
270
-	 * @param WP_REST_Request $request Full details about the request.
271
-	 * @return true|WP_Error True if the request has access to create items, WP_Error object otherwise.
272
-	 */
273
-	public function create_item_permissions_check( $request ) {
266
+     * Checks if a given request has access to create an invoice item.
267
+     *
268
+     * @since 1.0.13
269
+     *
270
+     * @param WP_REST_Request $request Full details about the request.
271
+     * @return true|WP_Error True if the request has access to create items, WP_Error object otherwise.
272
+     */
273
+    public function create_item_permissions_check( $request ) {
274 274
 	
275
-		if ( ! empty( $request['id'] ) ) {
276
-			return new WP_Error( 'rest_item_exists', __( 'Cannot create existing item.', 'invoicing' ), array( 'status' => 400 ) );
277
-		}
275
+        if ( ! empty( $request['id'] ) ) {
276
+            return new WP_Error( 'rest_item_exists', __( 'Cannot create existing item.', 'invoicing' ), array( 'status' => 400 ) );
277
+        }
278 278
 
279
-		if ( wpinv_current_user_can_manage_invoicing() ) {
280
-			return true;
281
-		}
279
+        if ( wpinv_current_user_can_manage_invoicing() ) {
280
+            return true;
281
+        }
282 282
 
283
-		$post_type = get_post_type_object( $this->post_type );
284
-		if ( ! current_user_can( $post_type->cap->create_posts ) ) {
285
-			return new WP_Error( 
283
+        $post_type = get_post_type_object( $this->post_type );
284
+        if ( ! current_user_can( $post_type->cap->create_posts ) ) {
285
+            return new WP_Error( 
286 286
                 'rest_cannot_create', 
287 287
                 __( 'Sorry, you are not allowed to create discounts as this user.', 'invoicing' ), 
288 288
                 array( 
@@ -291,261 +291,261 @@  discard block
 block discarded – undo
291 291
             );
292 292
         }
293 293
 
294
-		return true;
294
+        return true;
295 295
     }
296 296
     
297 297
     /**
298
-	 * Creates a single discount.
299
-	 *
300
-	 * @since 1.0.13
301
-	 *
302
-	 * @param WP_REST_Request $request Full details about the request.
303
-	 * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
304
-	 */
305
-	public function create_item( $request ) {
306
-
307
-		if ( ! empty( $request['id'] ) ) {
308
-			return new WP_Error( 'rest_item_exists', __( 'Cannot create existing discount.', 'invoicing' ), array( 'status' => 400 ) );
309
-		}
298
+     * Creates a single discount.
299
+     *
300
+     * @since 1.0.13
301
+     *
302
+     * @param WP_REST_Request $request Full details about the request.
303
+     * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
304
+     */
305
+    public function create_item( $request ) {
306
+
307
+        if ( ! empty( $request['id'] ) ) {
308
+            return new WP_Error( 'rest_item_exists', __( 'Cannot create existing discount.', 'invoicing' ), array( 'status' => 400 ) );
309
+        }
310 310
 
311
-		$request->set_param( 'context', 'edit' );
311
+        $request->set_param( 'context', 'edit' );
312 312
 
313
-		// Prepare the updated data.
314
-		$discount_data = $this->prepare_item_for_database( $request );
313
+        // Prepare the updated data.
314
+        $discount_data = $this->prepare_item_for_database( $request );
315 315
 
316
-		if ( is_wp_error( $discount_data ) ) {
317
-			return $discount_data;
318
-		}
316
+        if ( is_wp_error( $discount_data ) ) {
317
+            return $discount_data;
318
+        }
319 319
 
320
-		$discount_data['post_type'] = $this->post_type;
320
+        $discount_data['post_type'] = $this->post_type;
321 321
 
322
-		// Try creating the discount.
322
+        // Try creating the discount.
323 323
         $discount = wp_insert_post( $discount_data, true );
324 324
 
325
-		if ( is_wp_error( $discount ) ) {
325
+        if ( is_wp_error( $discount ) ) {
326 326
             return $discount;
327
-		}
328
-
329
-		// Prepare the response
330
-		$response = $this->prepare_item_for_response( $discount, $request );
331
-
332
-		/**
333
-		 * Fires after a single discount is created or updated via the REST API.
334
-		 *
335
-		 * @since 1.0.13
336
-		 *
337
-		 * @param WP_Post   $discount  Inserted or updated discount object.
338
-		 * @param WP_REST_Request $request  Request object.
339
-		 * @param bool            $creating True when creating a post, false when updating.
340
-		 */
341
-		do_action( "wpinv_rest_insert_discount", $discount, $request, true );
342
-
343
-		/**
344
-		 * Filters the responses for creating single item requests.
345
-		 *
346
-		 *
347
-		 * @since 1.0.13
348
-		 *
349
-		 *
350
-		 * @param array           $response Invoice properties.
351
-		 * @param WP_REST_Request $request The request used.
352
-		 */
327
+        }
328
+
329
+        // Prepare the response
330
+        $response = $this->prepare_item_for_response( $discount, $request );
331
+
332
+        /**
333
+         * Fires after a single discount is created or updated via the REST API.
334
+         *
335
+         * @since 1.0.13
336
+         *
337
+         * @param WP_Post   $discount  Inserted or updated discount object.
338
+         * @param WP_REST_Request $request  Request object.
339
+         * @param bool            $creating True when creating a post, false when updating.
340
+         */
341
+        do_action( "wpinv_rest_insert_discount", $discount, $request, true );
342
+
343
+        /**
344
+         * Filters the responses for creating single item requests.
345
+         *
346
+         *
347
+         * @since 1.0.13
348
+         *
349
+         *
350
+         * @param array           $response Invoice properties.
351
+         * @param WP_REST_Request $request The request used.
352
+         */
353 353
         $response       = apply_filters( "wpinv_rest_create_discount_response", $response, $request );
354 354
 
355 355
         return rest_ensure_response( $response );
356
-	}
357
-
358
-	/**
359
-	 * Checks if a given request has access to update a discount.
360
-	 *
361
-	 * @since 1.0.13
362
-	 *
363
-	 * @param WP_REST_Request $request Full details about the request.
364
-	 * @return true|WP_Error True if the request has access to update the item, WP_Error object otherwise.
365
-	 */
366
-	public function update_item_permissions_check( $request ) {
367
-
368
-		// Retrieve the item.
369
-		$item = $this->get_post( $request['id'] );
370
-		if ( is_wp_error( $item ) ) {
371
-			return $item;
372
-		}
373
-
374
-		if ( wpinv_current_user_can_manage_invoicing() ) {
375
-			return true;
376
-		}
377
-
378
-		return new WP_Error( 
379
-			'rest_cannot_edit', 
380
-			__( 'Sorry, you are not allowed to update this discount.', 'invoicing' ), 
381
-			array( 
382
-				'status' => rest_authorization_required_code(),
383
-			)
384
-		);
385
-
386
-	}
387
-
388
-	/**
389
-	 * Updates a single discount.
390
-	 *
391
-	 * @since 1.0.13
392
-	 *
393
-	 * @param WP_REST_Request $request Full details about the request.
394
-	 * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
395
-	 */
396
-	public function update_item( $request ) {
356
+    }
357
+
358
+    /**
359
+     * Checks if a given request has access to update a discount.
360
+     *
361
+     * @since 1.0.13
362
+     *
363
+     * @param WP_REST_Request $request Full details about the request.
364
+     * @return true|WP_Error True if the request has access to update the item, WP_Error object otherwise.
365
+     */
366
+    public function update_item_permissions_check( $request ) {
367
+
368
+        // Retrieve the item.
369
+        $item = $this->get_post( $request['id'] );
370
+        if ( is_wp_error( $item ) ) {
371
+            return $item;
372
+        }
373
+
374
+        if ( wpinv_current_user_can_manage_invoicing() ) {
375
+            return true;
376
+        }
377
+
378
+        return new WP_Error( 
379
+            'rest_cannot_edit', 
380
+            __( 'Sorry, you are not allowed to update this discount.', 'invoicing' ), 
381
+            array( 
382
+                'status' => rest_authorization_required_code(),
383
+            )
384
+        );
385
+
386
+    }
387
+
388
+    /**
389
+     * Updates a single discount.
390
+     *
391
+     * @since 1.0.13
392
+     *
393
+     * @param WP_REST_Request $request Full details about the request.
394
+     * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
395
+     */
396
+    public function update_item( $request ) {
397 397
 		
398
-		// Ensure the item exists.
398
+        // Ensure the item exists.
399 399
         $valid_check = $this->get_post( $request['id'] );
400 400
         
401 401
         // Abort early if it does not exist
402
-		if ( is_wp_error( $valid_check ) ) {
403
-			return $valid_check;
404
-		}
402
+        if ( is_wp_error( $valid_check ) ) {
403
+            return $valid_check;
404
+        }
405 405
 
406
-		$request->set_param( 'context', 'edit' );
406
+        $request->set_param( 'context', 'edit' );
407 407
 
408
-		// Prepare the updated data.
409
-		$data_to_update = $this->prepare_item_for_database( $request );
408
+        // Prepare the updated data.
409
+        $data_to_update = $this->prepare_item_for_database( $request );
410 410
 
411
-		if ( is_wp_error( $data_to_update ) ) {
412
-			return $data_to_update;
413
-		}
411
+        if ( is_wp_error( $data_to_update ) ) {
412
+            return $data_to_update;
413
+        }
414 414
 
415
-		if( empty( $data_to_update['meta_input'] ) ) {
416
-			unset( $data_to_update['meta_input'] );
417
-		}
415
+        if( empty( $data_to_update['meta_input'] ) ) {
416
+            unset( $data_to_update['meta_input'] );
417
+        }
418 418
 
419
-		// Abort if no item data is provided
419
+        // Abort if no item data is provided
420 420
         if( empty( $data_to_update ) ) {
421 421
             return new WP_Error( 'missing_data', __( 'An update request cannot be empty.', 'invoicing' ) );
422
-		}
422
+        }
423 423
 		
424
-		// post_status
425
-		if( ! empty( $data_to_update['post_status'] ) ) {
426
-			wpinv_update_discount_status( $request['id'], $data_to_update['post_status'] );
427
-			unset( $data_to_update['post_status'] );
428
-		}
424
+        // post_status
425
+        if( ! empty( $data_to_update['post_status'] ) ) {
426
+            wpinv_update_discount_status( $request['id'], $data_to_update['post_status'] );
427
+            unset( $data_to_update['post_status'] );
428
+        }
429 429
 
430
-		// Update the item
431
-		if( ! empty( $data_to_update ) ) {
430
+        // Update the item
431
+        if( ! empty( $data_to_update ) ) {
432 432
 
433
-			// Include the item ID
434
-			$data_to_update['ID'] = $request['id'];
433
+            // Include the item ID
434
+            $data_to_update['ID'] = $request['id'];
435 435
 
436
-			$updated = wp_update_post( $data_to_update, true );
436
+            $updated = wp_update_post( $data_to_update, true );
437 437
 
438
-			// Incase the update operation failed...
439
-			if ( is_wp_error( $updated ) ) {
440
-				return $updated;
441
-			}
438
+            // Incase the update operation failed...
439
+            if ( is_wp_error( $updated ) ) {
440
+                return $updated;
441
+            }
442 442
 
443
-		}
443
+        }
444 444
 
445
-		$updated_discount = get_post( $request['id'] );
445
+        $updated_discount = get_post( $request['id'] );
446 446
 
447
-		// Prepare the response
448
-		$response = $this->prepare_item_for_response( $updated_discount, $request );
447
+        // Prepare the response
448
+        $response = $this->prepare_item_for_response( $updated_discount, $request );
449 449
 
450
-		/** This action is documented in includes/class-wpinv-rest-item-controller.php */
451
-		do_action( "wpinv_rest_insert_discount", $updated_discount, $request, false );
450
+        /** This action is documented in includes/class-wpinv-rest-item-controller.php */
451
+        do_action( "wpinv_rest_insert_discount", $updated_discount, $request, false );
452 452
 
453
-		/**
454
-		 * Filters the responses for updating single discount requests.
455
-		 *
456
-		 *
457
-		 * @since 1.0.13
458
-		 *
459
-		 *
460
-		 * @param array           $data_to_update Discount properties.
461
-		 * @param WP_REST_Request $request The request used.
462
-		 */
453
+        /**
454
+         * Filters the responses for updating single discount requests.
455
+         *
456
+         *
457
+         * @since 1.0.13
458
+         *
459
+         *
460
+         * @param array           $data_to_update Discount properties.
461
+         * @param WP_REST_Request $request The request used.
462
+         */
463 463
         $response       = apply_filters( "wpinv_rest_update_discount_response", $response,  $data_to_update, $request );
464 464
 
465 465
         return rest_ensure_response( $response );
466
-	}
467
-
468
-	/**
469
-	 * Checks if a given request has access to delete a discount.
470
-	 *
471
-	 * @since 1.0.13
472
-	 *
473
-	 * @param WP_REST_Request $request Full details about the request.
474
-	 * @return true|WP_Error True if the request has access to delete the discount, WP_Error object otherwise.
475
-	 */
476
-	public function delete_item_permissions_check( $request ) {
477
-
478
-		// Retrieve the discount.
479
-		$discount = $this->get_post( $request['id'] );
480
-		if ( is_wp_error( $discount ) ) {
481
-			return $discount;
482
-		} 
483
-
484
-		// Ensure the current user can delete the discount
485
-		if (! wpinv_current_user_can_manage_invoicing() ) {
486
-			return new WP_Error( 
466
+    }
467
+
468
+    /**
469
+     * Checks if a given request has access to delete a discount.
470
+     *
471
+     * @since 1.0.13
472
+     *
473
+     * @param WP_REST_Request $request Full details about the request.
474
+     * @return true|WP_Error True if the request has access to delete the discount, WP_Error object otherwise.
475
+     */
476
+    public function delete_item_permissions_check( $request ) {
477
+
478
+        // Retrieve the discount.
479
+        $discount = $this->get_post( $request['id'] );
480
+        if ( is_wp_error( $discount ) ) {
481
+            return $discount;
482
+        } 
483
+
484
+        // Ensure the current user can delete the discount
485
+        if (! wpinv_current_user_can_manage_invoicing() ) {
486
+            return new WP_Error( 
487 487
                 'rest_cannot_delete', 
488 488
                 __( 'Sorry, you are not allowed to delete this discount.', 'invoicing' ), 
489 489
                 array( 
490 490
                     'status' => rest_authorization_required_code(),
491 491
                 )
492 492
             );
493
-		}
494
-
495
-		return true;
496
-	}
497
-
498
-	/**
499
-	 * Deletes a single discount.
500
-	 *
501
-	 * @since 1.0.13
502
-	 *
503
-	 * @param WP_REST_Request $request Full details about the request.
504
-	 * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
505
-	 */
506
-	public function delete_item( $request ) {
493
+        }
494
+
495
+        return true;
496
+    }
497
+
498
+    /**
499
+     * Deletes a single discount.
500
+     *
501
+     * @since 1.0.13
502
+     *
503
+     * @param WP_REST_Request $request Full details about the request.
504
+     * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
505
+     */
506
+    public function delete_item( $request ) {
507 507
 		
508
-		// Retrieve the discount.
509
-		$discount = $this->get_post( $request['id'] );
510
-		if ( is_wp_error( $discount ) ) {
511
-			return $discount;
512
-		}
508
+        // Retrieve the discount.
509
+        $discount = $this->get_post( $request['id'] );
510
+        if ( is_wp_error( $discount ) ) {
511
+            return $discount;
512
+        }
513 513
 
514
-		$request->set_param( 'context', 'edit' );
514
+        $request->set_param( 'context', 'edit' );
515 515
 
516
-		// Prepare the discount id
517
-		$id    = $discount->ID;
516
+        // Prepare the discount id
517
+        $id    = $discount->ID;
518 518
 
519
-		// Prepare the response
520
-		$response = $this->prepare_item_for_response( $discount, $request );
519
+        // Prepare the response
520
+        $response = $this->prepare_item_for_response( $discount, $request );
521 521
 
522
-		// Delete the discount...
523
-		wpinv_remove_discount( $id );
522
+        // Delete the discount...
523
+        wpinv_remove_discount( $id );
524 524
 
525
-		/**
526
-		 * Fires immediately after a single discount is deleted via the REST API.
527
-		 *
528
-		 *
529
-		 * @since 1.0.13
530
-		 *
531
-		 * @param WP_POST    $discount  The deleted discount.
532
-		 * @param WP_REST_Request  $request  The request sent to the API.
533
-		 */
534
-		do_action( "wpinv_rest_delete_discount", $discount, $request );
525
+        /**
526
+         * Fires immediately after a single discount is deleted via the REST API.
527
+         *
528
+         *
529
+         * @since 1.0.13
530
+         *
531
+         * @param WP_POST    $discount  The deleted discount.
532
+         * @param WP_REST_Request  $request  The request sent to the API.
533
+         */
534
+        do_action( "wpinv_rest_delete_discount", $discount, $request );
535 535
 
536
-		return $response;
536
+        return $response;
537 537
 
538
-	}
538
+    }
539 539
     
540 540
     
541 541
     /**
542
-	 * Retrieves the query params for the discount collection.
543
-	 *
544
-	 * @since 1.0.13
545
-	 *
546
-	 * @return array Collection parameters.
547
-	 */
548
-	public function get_collection_params() {
542
+     * Retrieves the query params for the discount collection.
543
+     *
544
+     * @since 1.0.13
545
+     *
546
+     * @return array Collection parameters.
547
+     */
548
+    public function get_collection_params() {
549 549
         
550 550
         $query_params               = array(
551 551
 
@@ -559,27 +559,27 @@  discard block
 block discarded – undo
559 559
             
560 560
             // Discount types
561 561
             'type'                  => array(
562
-				'description'       => __( 'Type of discounts to fetch.', 'invoicing' ),
563
-				'type'              => 'array',
564
-				'default'           => array_keys( wpinv_get_discount_types() ),
565
-				'items'             => array(
562
+                'description'       => __( 'Type of discounts to fetch.', 'invoicing' ),
563
+                'type'              => 'array',
564
+                'default'           => array_keys( wpinv_get_discount_types() ),
565
+                'items'             => array(
566 566
                     'enum'          => array_keys( wpinv_get_discount_types() ),
567 567
                     'type'          => 'string',
568 568
                 ),
569
-			),
569
+            ),
570 570
 			
571
-			// Number of results per page
571
+            // Number of results per page
572 572
             'limit'                 => array(
573
-				'description'       => __( 'Number of discounts to fetch.', 'invoicing' ),
574
-				'type'              => 'integer',
575
-				'default'           => (int) get_option( 'posts_per_page' ),
573
+                'description'       => __( 'Number of discounts to fetch.', 'invoicing' ),
574
+                'type'              => 'integer',
575
+                'default'           => (int) get_option( 'posts_per_page' ),
576 576
             ),
577 577
 
578 578
             // Pagination
579 579
             'page'     => array(
580
-				'description'       => __( 'Current page to fetch.', 'invoicing' ),
581
-				'type'              => 'integer',
582
-				'default'           => 1,
580
+                'description'       => __( 'Current page to fetch.', 'invoicing' ),
581
+                'type'              => 'integer',
582
+                'default'           => 1,
583 583
             ),
584 584
 
585 585
             // Exclude certain items
@@ -602,9 +602,9 @@  discard block
 block discarded – undo
602 602
                     'date',
603 603
                     'ID',
604 604
                     'modified',
605
-					'title',
606
-					'relevance',
607
-					'rand'
605
+                    'title',
606
+                    'relevance',
607
+                    'rand'
608 608
                 ),
609 609
             ),
610 610
 
@@ -614,598 +614,598 @@  discard block
 block discarded – undo
614 614
                 'type'        => 'string',
615 615
                 'default'     => 'DESC',
616 616
                 'enum'        => array( 'ASC', 'DESC' ),
617
-			),
617
+            ),
618 618
 			
619
-			// Search term
619
+            // Search term
620 620
             'search'                => array(
621
-				'description'       => __( 'Return discounts that match the search term.', 'invoicing' ),
622
-				'type'              => 'string',
621
+                'description'       => __( 'Return discounts that match the search term.', 'invoicing' ),
622
+                'type'              => 'string',
623 623
             ),
624 624
         );
625 625
 
626
-		/**
627
-		 * Filter collection parameters for the discounts controller.
628
-		 *
629
-		 *
630
-		 * @since 1.0.13
631
-		 *
632
-		 * @param array        $query_params JSON Schema-formatted collection parameters.
633
-		 */
634
-		return apply_filters( "wpinv_rest_discounts_collection_params", $query_params );
626
+        /**
627
+         * Filter collection parameters for the discounts controller.
628
+         *
629
+         *
630
+         * @since 1.0.13
631
+         *
632
+         * @param array        $query_params JSON Schema-formatted collection parameters.
633
+         */
634
+        return apply_filters( "wpinv_rest_discounts_collection_params", $query_params );
635 635
     }
636 636
     
637 637
     /**
638
-	 * Checks if a given post type can be viewed or managed.
639
-	 *
640
-	 * @since 1.0.13
641
-	 *
642
-	 * @param object|string $post_type Post type name or object.
643
-	 * @return bool Whether the post type is allowed in REST.
644
-	 */
645
-	protected function check_is_post_type_allowed( $post_type ) {
646
-		return true;
647
-	}
648
-
649
-	/**
650
-	 * Prepares a single item for create or update.
651
-	 *
652
-	 * @since 1.0.13
653
-	 *
654
-	 * @param WP_REST_Request $request Request object.
655
-	 * @return array|WP_Error Discount Properties or WP_Error.
656
-	 */
657
-	protected function prepare_item_for_database( $request ) {
658
-		$prepared_item 		 = new stdClass();
659
-		$prepared_item->meta_input = array();
660
-
661
-		// Post ID.
662
-		if ( isset( $request['id'] ) ) {
663
-			$existing_item = $this->get_post( $request['id'] );
664
-			if ( is_wp_error( $existing_item ) ) {
665
-				return $existing_item;
666
-			}
667
-
668
-			$prepared_item->ID 		  = $existing_item->ID;
669
-		}
670
-
671
-		$schema = $this->get_item_schema();
672
-
673
-		// item title.
674
-		if ( ! empty( $schema['properties']['title'] ) && isset( $request['title'] ) ) {
675
-			$prepared_item->post_title = sanitize_text_field( $request['title'] );
676
-		}
677
-
678
-		// item status.
679
-		if ( ! empty( $schema['properties']['status'] ) && isset( $request['status'] ) && in_array( $request['status'], array_keys( get_post_stati( array( 'internal' => false ) ) ) ) ) {
680
-			$prepared_item->post_status = sanitize_text_field( $request['status'] );
681
-		}
682
-
683
-		// Code.
684
-		if ( ! empty( $schema['properties']['code'] ) && isset( $request['code'] ) ) {
685
-			$prepared_item->meta_input['_wpi_discount_code'] = trim( $request['code'] );
686
-		}
687
-
688
-		// Type.
689
-		if ( ! empty( $schema['properties']['type'] ) && isset( $request['type'] )  && in_array( $request['type'], array_keys( wpinv_get_discount_types() ) ) ) {
690
-			$prepared_item->meta_input['_wpi_discount_type'] = trim( $request['type'] );
691
-		}
692
-
693
-		// Amount.
694
-		if ( ! empty( $schema['properties']['amount'] ) && isset( $request['amount'] ) ) {
695
-			$prepared_item->meta_input['_wpi_discount_amount'] = floatval( $request['amount'] );
696
-		}
697
-
698
-		// Items.
699
-		if ( ! empty( $schema['properties']['items'] ) && isset( $request['items'] ) ) {
700
-			$prepared_item->meta_input['_wpi_discount_items'] = wpinv_parse_list( $request['items'] );
701
-		}
702
-
703
-		// Excluded Items.
704
-		if ( ! empty( $schema['properties']['exclude_items'] ) && isset( $request['exclude_items'] ) ) {
705
-			$prepared_item->meta_input['_wpi_discount_excluded_items'] = wpinv_parse_list( $request['exclude_items'] );
706
-		}
707
-
708
-		// Start date.
709
-		if ( ! empty( $schema['properties']['start_date'] ) && isset( $request['start_date'] ) ) {
710
-			$prepared_item->meta_input['_wpi_discount_start'] = trim( $request['start_date'] );
711
-		}
712
-
713
-		// End date.
714
-		if ( ! empty( $schema['properties']['end_date'] ) && isset( $request['end_date'] ) ) {
715
-			$prepared_item->meta_input['_wpi_discount_expiration'] = trim( $request['end_date'] );
716
-		}
717
-
718
-		// Minimum amount.
719
-		if ( ! empty( $schema['properties']['minimum_amount'] ) && isset( $request['minimum_amount'] ) ) {
720
-			$prepared_item->meta_input['_wpi_discount_min_total'] = floatval( $request['minimum_amount'] );
721
-		}
722
-
723
-		// Maximum amount.
724
-		if ( ! empty( $schema['properties']['maximum_amount'] ) && isset( $request['maximum_amount'] ) ) {
725
-			$prepared_item->meta_input['_wpi_discount_max_total'] = floatval( $request['maximum_amount'] );
726
-		}
727
-
728
-		// Recurring.
729
-		if ( ! empty( $schema['properties']['recurring'] ) && isset( $request['recurring'] ) ) {
730
-			$prepared_item->meta_input['_wpi_discount_is_recurring'] = empty( (int) $request['recurring'] ) ? 0 : 1;
731
-		}
732
-
733
-		// Maximum uses.
734
-		if ( ! empty( $schema['properties']['max_uses'] ) && isset( $request['max_uses'] ) ) {
735
-			$prepared_item->meta_input['_wpi_discount_max_uses'] = intval( $request['max_uses'] );
736
-		}
737
-
738
-		// Single use.
739
-		if ( ! empty( $schema['properties']['single_use'] ) && isset( $request['single_use'] ) ) {
740
-			$prepared_item->meta_input['_wpi_discount_is_single_use'] = empty( (int) $request['single_use'] ) ? 0 : 1;
741
-		}
742
-
743
-		$discount_data = (array) wp_unslash( $prepared_item );
744
-
745
-		/**
746
-		 * Filters an item before it is inserted via the REST API.
747
-		 *
748
-		 * @since 1.0.13
749
-		 *
750
-		 * @param array        $discount_data An array of discount data
751
-		 * @param WP_REST_Request $request       Request object.
752
-		 */
753
-		return apply_filters( "wpinv_rest_pre_insert_discount", $discount_data, $request );
754
-
755
-	}
756
-
757
-	/**
758
-	 * Prepares a single discount output for response.
759
-	 *
760
-	 * @since 1.0.13
761
-	 *
762
-	 * @param WP_Post   $discount    WP_Post object.
763
-	 * @param WP_REST_Request $request Request object.
764
-	 * @return WP_REST_Response Response object.
765
-	 */
766
-	public function prepare_item_for_response( $discount, $request ) {
767
-
768
-		$GLOBALS['post'] = get_post( $discount->ID );
769
-
770
-		setup_postdata( $discount->ID );
771
-
772
-		// Fetch the fields to include in this response.
773
-		$fields = $this->get_fields_for_response( $request );
774
-
775
-		// Base fields for every discount.
776
-		$data = array();
777
-
778
-		// Set up ID.
779
-		if ( rest_is_field_included( 'id', $fields ) ) {
780
-			$data['id'] = $discount->ID;
781
-		}
782
-
783
-		// Title.
784
-		if ( rest_is_field_included( 'title', $fields ) ) {
785
-			$data['title'] = get_the_title( $discount->ID );
786
-		}
787
-
788
-		// Code.
789
-		if ( rest_is_field_included( 'code', $fields ) ) {
790
-			$data['code'] = wpinv_get_discount_code( $discount->ID );
791
-		}
792
-
793
-		// Type.
794
-		if ( rest_is_field_included( 'type', $fields ) ) {
795
-			$data['type'] = wpinv_get_discount_type( $discount->ID );
796
-		}
797
-
798
-		// Amount.
799
-		if ( rest_is_field_included( 'amount', $fields ) ) {
800
-			$data['amount'] = wpinv_get_discount_amount( $discount->ID );
801
-		}
802
-
803
-		// Status.
804
-		if ( rest_is_field_included( 'status', $fields ) ) {
805
-			$data['status'] = get_post_status( $discount->ID );
806
-		}
807
-
808
-		// Items.
809
-		if ( rest_is_field_included( 'items', $fields ) ) {
810
-			$data['items'] = wpinv_get_discount_item_reqs( $discount->ID );
811
-		}
812
-
813
-		// Excluded Items.
814
-		if ( rest_is_field_included( 'exclude_items', $fields ) ) {
815
-			$data['exclude_items'] = wpinv_get_discount_excluded_items( $discount->ID );
816
-		}
817
-
818
-		// Start date.
819
-		if ( rest_is_field_included( 'start_date', $fields ) ) {
820
-			$data['start_date'] = wpinv_get_discount_start_date( $discount->ID );
821
-		}
822
-
823
-		// End date.
824
-		if ( rest_is_field_included( 'end_date', $fields ) ) {
825
-			$data['end_date'] = wpinv_get_discount_expiration( $discount->ID );
826
-		}
827
-
828
-		// Minimum amount.
829
-		if ( rest_is_field_included( 'minimum_amount', $fields ) ) {
830
-			$data['minimum_amount'] = wpinv_get_discount_min_total( $discount->ID );
831
-		}
832
-
833
-		// Maximum amount.
834
-		if ( rest_is_field_included( 'maximum_amount', $fields ) ) {
835
-			$data['maximum_amount'] = wpinv_get_discount_max_total( $discount->ID );
836
-		}
837
-
838
-		// Recurring.
839
-		if ( rest_is_field_included( 'recurring', $fields ) ) {
840
-			$data['recurring'] = wpinv_discount_is_recurring( $discount->ID );
841
-		}
842
-
843
-		// Maximum uses.
844
-		if ( rest_is_field_included( 'max_uses', $fields ) ) {
845
-			$data['max_uses'] = wpinv_get_discount_max_uses( $discount->ID );
846
-		}
847
-
848
-		// Single use.
849
-		if ( rest_is_field_included( 'single_use', $fields ) ) {
850
-			$data['single_use'] = wpinv_discount_is_single_use( $discount->ID );
851
-		}
852
-
853
-		$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
854
-		$data    = $this->add_additional_fields_to_object( $data, $request );
855
-		$data    = $this->filter_response_by_context( $data, $context );
856
-
857
-		// Wrap the data in a response object.
858
-		$response = rest_ensure_response( $data );
859
-
860
-		$links = $this->prepare_links( $discount );
861
-		$response->add_links( $links );
862
-
863
-		if ( ! empty( $links['self']['href'] ) ) {
864
-			$actions = $this->get_available_actions( $discount, $request );
865
-
866
-			$self = $links['self']['href'];
867
-
868
-			foreach ( $actions as $rel ) {
869
-				$response->add_link( $rel, $self );
870
-			}
871
-		}
872
-
873
-		/**
874
-		 * Filters the discount data for a response.
875
-		 *
876
-		 * @since 1.0.13
877
-		 *
878
-		 * @param WP_REST_Response $response The response object.
879
-		 * @param WP_Post    $discount  The discount post object.
880
-		 * @param WP_REST_Request  $request  Request object.
881
-		 */
882
-		return apply_filters( "wpinv_rest_prepare_discount", $response, $discount, $request );
883
-	}
884
-
885
-	/**
886
-	 * Gets an array of fields to be included on the response.
887
-	 *
888
-	 * Included fields are based on item schema and `_fields=` request argument.
889
-	 *
890
-	 * @since 1.0.13
891
-	 *
892
-	 * @param WP_REST_Request $request Full details about the request.
893
-	 * @return array Fields to be included in the response.
894
-	 */
895
-	public function get_fields_for_response( $request ) {
896
-		$schema     = $this->get_item_schema();
897
-		$properties = isset( $schema['properties'] ) ? $schema['properties'] : array();
898
-
899
-		$additional_fields = $this->get_additional_fields();
900
-		foreach ( $additional_fields as $field_name => $field_options ) {
901
-			// For back-compat, include any field with an empty schema
902
-			// because it won't be present in $this->get_item_schema().
903
-			if ( is_null( $field_options['schema'] ) ) {
904
-				$properties[ $field_name ] = $field_options;
905
-			}
906
-		}
907
-
908
-		// Exclude fields that specify a different context than the request context.
909
-		$context = $request['context'];
910
-		if ( $context ) {
911
-			foreach ( $properties as $name => $options ) {
912
-				if ( ! empty( $options['context'] ) && ! in_array( $context, $options['context'], true ) ) {
913
-					unset( $properties[ $name ] );
914
-				}
915
-			}
916
-		}
917
-
918
-		$fields = array_keys( $properties );
919
-
920
-		if ( ! isset( $request['_fields'] ) ) {
921
-			return $fields;
922
-		}
923
-		$requested_fields = wpinv_parse_list( $request['_fields'] );
924
-		if ( 0 === count( $requested_fields ) ) {
925
-			return $fields;
926
-		}
927
-		// Trim off outside whitespace from the comma delimited list.
928
-		$requested_fields = array_map( 'trim', $requested_fields );
929
-		// Always persist 'id', because it can be needed for add_additional_fields_to_object().
930
-		if ( in_array( 'id', $fields, true ) ) {
931
-			$requested_fields[] = 'id';
932
-		}
933
-		// Return the list of all requested fields which appear in the schema.
934
-		return array_reduce(
935
-			$requested_fields,
936
-			function( $response_fields, $field ) use ( $fields ) {
937
-				if ( in_array( $field, $fields, true ) ) {
938
-					$response_fields[] = $field;
939
-					return $response_fields;
940
-				}
941
-				// Check for nested fields if $field is not a direct match.
942
-				$nested_fields = explode( '.', $field );
943
-				// A nested field is included so long as its top-level property is
944
-				// present in the schema.
945
-				if ( in_array( $nested_fields[0], $fields, true ) ) {
946
-					$response_fields[] = $field;
947
-				}
948
-				return $response_fields;
949
-			},
950
-			array()
951
-		);
952
-	}
953
-
954
-	/**
955
-	 * Retrieves the discount's schema, conforming to JSON Schema.
956
-	 *
957
-	 * @since 1.0.13
958
-	 *
959
-	 * @return array Discount schema data.
960
-	 */
961
-	public function get_item_schema() {
962
-
963
-		// Maybe retrieve the schema from cache.
964
-		if (  empty( $this->schema ) ) {
965
-			return $this->add_additional_fields_schema( $this->schema );
966
-		}
967
-
968
-		$schema = array(
969
-			'$schema'    => 'http://json-schema.org/draft-04/schema#',
970
-			'title'      => $this->post_type,
971
-			'type'       => 'object',
972
-
973
-			// Base properties for every Item.
974
-			'properties' 		  => array(
975
-
976
-				'id'           => array(
977
-					'description' => __( 'Unique identifier for the discount.', 'invoicing' ),
978
-					'type'        => 'integer',
979
-					'context'     => array( 'view', 'edit', 'embed' ),
980
-					'readonly'    => true,
981
-				),
982
-
983
-				'title'			  => array(
984
-					'description' => __( 'The title for the discount.', 'invoicing' ),
985
-					'type'        => 'string',
986
-					'context'     => array( 'view', 'edit' ),
987
-				),
988
-
989
-				'code'        => array(
990
-					'description' => __( 'The discount code.', 'invoicing' ),
991
-					'type'        => 'string',
992
-					'context'     => array( 'view', 'edit', 'embed' ),
993
-					'required'	  => true,
994
-				),
995
-
996
-				'type'        => array(
997
-					'description' => __( 'The type of discount.', 'invoicing' ),
998
-					'type'        => 'string',
999
-					'enum'        => array_keys( wpinv_get_discount_types() ),
1000
-					'context'     => array( 'view', 'edit', 'embed' ),
1001
-					'default'	  => 'percentage',
1002
-				),
1003
-
1004
-				'amount'        => array(
1005
-					'description' => __( 'The discount value.', 'invoicing' ),
1006
-					'type'        => 'number',
1007
-					'context'     => array( 'view', 'edit', 'embed' ),
1008
-					'required'	  => true,
1009
-				),
1010
-
1011
-				'status'       => array(
1012
-					'description' => __( 'A named status for the discount.', 'invoicing' ),
1013
-					'type'        => 'string',
1014
-					'enum'        => array_keys( get_post_stati( array( 'internal' => false ) ) ),
1015
-					'context'     => array( 'view', 'edit' ),
1016
-				),
1017
-
1018
-				'items'       => array(
1019
-					'description' => __( 'Items which need to be in the cart to use this discount or, for "Item Discounts", which items are discounted. If left blank, this discount will be used on any item.', 'invoicing' ),
1020
-					'type'        => 'array',
1021
-					'context'     => array( 'view', 'edit' ),
1022
-				),
1023
-
1024
-				'exclude_items'   => array(
1025
-					'description' => __( 'Items which are NOT allowed to use this discount.', 'invoicing' ),
1026
-					'type'        => 'array',
1027
-					'context'     => array( 'view', 'edit' ),
1028
-				),
1029
-
1030
-				'start_date'       => array(
1031
-					'description' => __( 'The start date for the discount in the format of yyyy-mm-dd hh:mm:ss  . If provided, the discount can only be used after or on this date.', 'invoicing' ),
1032
-					'type'        => 'string',
1033
-					'context'     => array( 'view', 'edit' ),
1034
-				),
1035
-
1036
-				'end_date'        => array(
1037
-					'description' => __( 'The expiration date for the discount.', 'invoicing' ),
1038
-					'type'        => 'string',
1039
-					'context'     => array( 'view', 'edit', 'embed' ),
1040
-				),
638
+     * Checks if a given post type can be viewed or managed.
639
+     *
640
+     * @since 1.0.13
641
+     *
642
+     * @param object|string $post_type Post type name or object.
643
+     * @return bool Whether the post type is allowed in REST.
644
+     */
645
+    protected function check_is_post_type_allowed( $post_type ) {
646
+        return true;
647
+    }
648
+
649
+    /**
650
+     * Prepares a single item for create or update.
651
+     *
652
+     * @since 1.0.13
653
+     *
654
+     * @param WP_REST_Request $request Request object.
655
+     * @return array|WP_Error Discount Properties or WP_Error.
656
+     */
657
+    protected function prepare_item_for_database( $request ) {
658
+        $prepared_item 		 = new stdClass();
659
+        $prepared_item->meta_input = array();
660
+
661
+        // Post ID.
662
+        if ( isset( $request['id'] ) ) {
663
+            $existing_item = $this->get_post( $request['id'] );
664
+            if ( is_wp_error( $existing_item ) ) {
665
+                return $existing_item;
666
+            }
667
+
668
+            $prepared_item->ID 		  = $existing_item->ID;
669
+        }
670
+
671
+        $schema = $this->get_item_schema();
672
+
673
+        // item title.
674
+        if ( ! empty( $schema['properties']['title'] ) && isset( $request['title'] ) ) {
675
+            $prepared_item->post_title = sanitize_text_field( $request['title'] );
676
+        }
677
+
678
+        // item status.
679
+        if ( ! empty( $schema['properties']['status'] ) && isset( $request['status'] ) && in_array( $request['status'], array_keys( get_post_stati( array( 'internal' => false ) ) ) ) ) {
680
+            $prepared_item->post_status = sanitize_text_field( $request['status'] );
681
+        }
682
+
683
+        // Code.
684
+        if ( ! empty( $schema['properties']['code'] ) && isset( $request['code'] ) ) {
685
+            $prepared_item->meta_input['_wpi_discount_code'] = trim( $request['code'] );
686
+        }
687
+
688
+        // Type.
689
+        if ( ! empty( $schema['properties']['type'] ) && isset( $request['type'] )  && in_array( $request['type'], array_keys( wpinv_get_discount_types() ) ) ) {
690
+            $prepared_item->meta_input['_wpi_discount_type'] = trim( $request['type'] );
691
+        }
692
+
693
+        // Amount.
694
+        if ( ! empty( $schema['properties']['amount'] ) && isset( $request['amount'] ) ) {
695
+            $prepared_item->meta_input['_wpi_discount_amount'] = floatval( $request['amount'] );
696
+        }
697
+
698
+        // Items.
699
+        if ( ! empty( $schema['properties']['items'] ) && isset( $request['items'] ) ) {
700
+            $prepared_item->meta_input['_wpi_discount_items'] = wpinv_parse_list( $request['items'] );
701
+        }
702
+
703
+        // Excluded Items.
704
+        if ( ! empty( $schema['properties']['exclude_items'] ) && isset( $request['exclude_items'] ) ) {
705
+            $prepared_item->meta_input['_wpi_discount_excluded_items'] = wpinv_parse_list( $request['exclude_items'] );
706
+        }
707
+
708
+        // Start date.
709
+        if ( ! empty( $schema['properties']['start_date'] ) && isset( $request['start_date'] ) ) {
710
+            $prepared_item->meta_input['_wpi_discount_start'] = trim( $request['start_date'] );
711
+        }
712
+
713
+        // End date.
714
+        if ( ! empty( $schema['properties']['end_date'] ) && isset( $request['end_date'] ) ) {
715
+            $prepared_item->meta_input['_wpi_discount_expiration'] = trim( $request['end_date'] );
716
+        }
717
+
718
+        // Minimum amount.
719
+        if ( ! empty( $schema['properties']['minimum_amount'] ) && isset( $request['minimum_amount'] ) ) {
720
+            $prepared_item->meta_input['_wpi_discount_min_total'] = floatval( $request['minimum_amount'] );
721
+        }
722
+
723
+        // Maximum amount.
724
+        if ( ! empty( $schema['properties']['maximum_amount'] ) && isset( $request['maximum_amount'] ) ) {
725
+            $prepared_item->meta_input['_wpi_discount_max_total'] = floatval( $request['maximum_amount'] );
726
+        }
727
+
728
+        // Recurring.
729
+        if ( ! empty( $schema['properties']['recurring'] ) && isset( $request['recurring'] ) ) {
730
+            $prepared_item->meta_input['_wpi_discount_is_recurring'] = empty( (int) $request['recurring'] ) ? 0 : 1;
731
+        }
732
+
733
+        // Maximum uses.
734
+        if ( ! empty( $schema['properties']['max_uses'] ) && isset( $request['max_uses'] ) ) {
735
+            $prepared_item->meta_input['_wpi_discount_max_uses'] = intval( $request['max_uses'] );
736
+        }
737
+
738
+        // Single use.
739
+        if ( ! empty( $schema['properties']['single_use'] ) && isset( $request['single_use'] ) ) {
740
+            $prepared_item->meta_input['_wpi_discount_is_single_use'] = empty( (int) $request['single_use'] ) ? 0 : 1;
741
+        }
742
+
743
+        $discount_data = (array) wp_unslash( $prepared_item );
744
+
745
+        /**
746
+         * Filters an item before it is inserted via the REST API.
747
+         *
748
+         * @since 1.0.13
749
+         *
750
+         * @param array        $discount_data An array of discount data
751
+         * @param WP_REST_Request $request       Request object.
752
+         */
753
+        return apply_filters( "wpinv_rest_pre_insert_discount", $discount_data, $request );
754
+
755
+    }
756
+
757
+    /**
758
+     * Prepares a single discount output for response.
759
+     *
760
+     * @since 1.0.13
761
+     *
762
+     * @param WP_Post   $discount    WP_Post object.
763
+     * @param WP_REST_Request $request Request object.
764
+     * @return WP_REST_Response Response object.
765
+     */
766
+    public function prepare_item_for_response( $discount, $request ) {
767
+
768
+        $GLOBALS['post'] = get_post( $discount->ID );
769
+
770
+        setup_postdata( $discount->ID );
771
+
772
+        // Fetch the fields to include in this response.
773
+        $fields = $this->get_fields_for_response( $request );
774
+
775
+        // Base fields for every discount.
776
+        $data = array();
777
+
778
+        // Set up ID.
779
+        if ( rest_is_field_included( 'id', $fields ) ) {
780
+            $data['id'] = $discount->ID;
781
+        }
782
+
783
+        // Title.
784
+        if ( rest_is_field_included( 'title', $fields ) ) {
785
+            $data['title'] = get_the_title( $discount->ID );
786
+        }
787
+
788
+        // Code.
789
+        if ( rest_is_field_included( 'code', $fields ) ) {
790
+            $data['code'] = wpinv_get_discount_code( $discount->ID );
791
+        }
792
+
793
+        // Type.
794
+        if ( rest_is_field_included( 'type', $fields ) ) {
795
+            $data['type'] = wpinv_get_discount_type( $discount->ID );
796
+        }
797
+
798
+        // Amount.
799
+        if ( rest_is_field_included( 'amount', $fields ) ) {
800
+            $data['amount'] = wpinv_get_discount_amount( $discount->ID );
801
+        }
802
+
803
+        // Status.
804
+        if ( rest_is_field_included( 'status', $fields ) ) {
805
+            $data['status'] = get_post_status( $discount->ID );
806
+        }
807
+
808
+        // Items.
809
+        if ( rest_is_field_included( 'items', $fields ) ) {
810
+            $data['items'] = wpinv_get_discount_item_reqs( $discount->ID );
811
+        }
812
+
813
+        // Excluded Items.
814
+        if ( rest_is_field_included( 'exclude_items', $fields ) ) {
815
+            $data['exclude_items'] = wpinv_get_discount_excluded_items( $discount->ID );
816
+        }
817
+
818
+        // Start date.
819
+        if ( rest_is_field_included( 'start_date', $fields ) ) {
820
+            $data['start_date'] = wpinv_get_discount_start_date( $discount->ID );
821
+        }
822
+
823
+        // End date.
824
+        if ( rest_is_field_included( 'end_date', $fields ) ) {
825
+            $data['end_date'] = wpinv_get_discount_expiration( $discount->ID );
826
+        }
827
+
828
+        // Minimum amount.
829
+        if ( rest_is_field_included( 'minimum_amount', $fields ) ) {
830
+            $data['minimum_amount'] = wpinv_get_discount_min_total( $discount->ID );
831
+        }
832
+
833
+        // Maximum amount.
834
+        if ( rest_is_field_included( 'maximum_amount', $fields ) ) {
835
+            $data['maximum_amount'] = wpinv_get_discount_max_total( $discount->ID );
836
+        }
837
+
838
+        // Recurring.
839
+        if ( rest_is_field_included( 'recurring', $fields ) ) {
840
+            $data['recurring'] = wpinv_discount_is_recurring( $discount->ID );
841
+        }
842
+
843
+        // Maximum uses.
844
+        if ( rest_is_field_included( 'max_uses', $fields ) ) {
845
+            $data['max_uses'] = wpinv_get_discount_max_uses( $discount->ID );
846
+        }
847
+
848
+        // Single use.
849
+        if ( rest_is_field_included( 'single_use', $fields ) ) {
850
+            $data['single_use'] = wpinv_discount_is_single_use( $discount->ID );
851
+        }
852
+
853
+        $context = ! empty( $request['context'] ) ? $request['context'] : 'view';
854
+        $data    = $this->add_additional_fields_to_object( $data, $request );
855
+        $data    = $this->filter_response_by_context( $data, $context );
856
+
857
+        // Wrap the data in a response object.
858
+        $response = rest_ensure_response( $data );
859
+
860
+        $links = $this->prepare_links( $discount );
861
+        $response->add_links( $links );
862
+
863
+        if ( ! empty( $links['self']['href'] ) ) {
864
+            $actions = $this->get_available_actions( $discount, $request );
865
+
866
+            $self = $links['self']['href'];
867
+
868
+            foreach ( $actions as $rel ) {
869
+                $response->add_link( $rel, $self );
870
+            }
871
+        }
872
+
873
+        /**
874
+         * Filters the discount data for a response.
875
+         *
876
+         * @since 1.0.13
877
+         *
878
+         * @param WP_REST_Response $response The response object.
879
+         * @param WP_Post    $discount  The discount post object.
880
+         * @param WP_REST_Request  $request  Request object.
881
+         */
882
+        return apply_filters( "wpinv_rest_prepare_discount", $response, $discount, $request );
883
+    }
884
+
885
+    /**
886
+     * Gets an array of fields to be included on the response.
887
+     *
888
+     * Included fields are based on item schema and `_fields=` request argument.
889
+     *
890
+     * @since 1.0.13
891
+     *
892
+     * @param WP_REST_Request $request Full details about the request.
893
+     * @return array Fields to be included in the response.
894
+     */
895
+    public function get_fields_for_response( $request ) {
896
+        $schema     = $this->get_item_schema();
897
+        $properties = isset( $schema['properties'] ) ? $schema['properties'] : array();
898
+
899
+        $additional_fields = $this->get_additional_fields();
900
+        foreach ( $additional_fields as $field_name => $field_options ) {
901
+            // For back-compat, include any field with an empty schema
902
+            // because it won't be present in $this->get_item_schema().
903
+            if ( is_null( $field_options['schema'] ) ) {
904
+                $properties[ $field_name ] = $field_options;
905
+            }
906
+        }
907
+
908
+        // Exclude fields that specify a different context than the request context.
909
+        $context = $request['context'];
910
+        if ( $context ) {
911
+            foreach ( $properties as $name => $options ) {
912
+                if ( ! empty( $options['context'] ) && ! in_array( $context, $options['context'], true ) ) {
913
+                    unset( $properties[ $name ] );
914
+                }
915
+            }
916
+        }
917
+
918
+        $fields = array_keys( $properties );
919
+
920
+        if ( ! isset( $request['_fields'] ) ) {
921
+            return $fields;
922
+        }
923
+        $requested_fields = wpinv_parse_list( $request['_fields'] );
924
+        if ( 0 === count( $requested_fields ) ) {
925
+            return $fields;
926
+        }
927
+        // Trim off outside whitespace from the comma delimited list.
928
+        $requested_fields = array_map( 'trim', $requested_fields );
929
+        // Always persist 'id', because it can be needed for add_additional_fields_to_object().
930
+        if ( in_array( 'id', $fields, true ) ) {
931
+            $requested_fields[] = 'id';
932
+        }
933
+        // Return the list of all requested fields which appear in the schema.
934
+        return array_reduce(
935
+            $requested_fields,
936
+            function( $response_fields, $field ) use ( $fields ) {
937
+                if ( in_array( $field, $fields, true ) ) {
938
+                    $response_fields[] = $field;
939
+                    return $response_fields;
940
+                }
941
+                // Check for nested fields if $field is not a direct match.
942
+                $nested_fields = explode( '.', $field );
943
+                // A nested field is included so long as its top-level property is
944
+                // present in the schema.
945
+                if ( in_array( $nested_fields[0], $fields, true ) ) {
946
+                    $response_fields[] = $field;
947
+                }
948
+                return $response_fields;
949
+            },
950
+            array()
951
+        );
952
+    }
953
+
954
+    /**
955
+     * Retrieves the discount's schema, conforming to JSON Schema.
956
+     *
957
+     * @since 1.0.13
958
+     *
959
+     * @return array Discount schema data.
960
+     */
961
+    public function get_item_schema() {
962
+
963
+        // Maybe retrieve the schema from cache.
964
+        if (  empty( $this->schema ) ) {
965
+            return $this->add_additional_fields_schema( $this->schema );
966
+        }
967
+
968
+        $schema = array(
969
+            '$schema'    => 'http://json-schema.org/draft-04/schema#',
970
+            'title'      => $this->post_type,
971
+            'type'       => 'object',
972
+
973
+            // Base properties for every Item.
974
+            'properties' 		  => array(
975
+
976
+                'id'           => array(
977
+                    'description' => __( 'Unique identifier for the discount.', 'invoicing' ),
978
+                    'type'        => 'integer',
979
+                    'context'     => array( 'view', 'edit', 'embed' ),
980
+                    'readonly'    => true,
981
+                ),
982
+
983
+                'title'			  => array(
984
+                    'description' => __( 'The title for the discount.', 'invoicing' ),
985
+                    'type'        => 'string',
986
+                    'context'     => array( 'view', 'edit' ),
987
+                ),
988
+
989
+                'code'        => array(
990
+                    'description' => __( 'The discount code.', 'invoicing' ),
991
+                    'type'        => 'string',
992
+                    'context'     => array( 'view', 'edit', 'embed' ),
993
+                    'required'	  => true,
994
+                ),
995
+
996
+                'type'        => array(
997
+                    'description' => __( 'The type of discount.', 'invoicing' ),
998
+                    'type'        => 'string',
999
+                    'enum'        => array_keys( wpinv_get_discount_types() ),
1000
+                    'context'     => array( 'view', 'edit', 'embed' ),
1001
+                    'default'	  => 'percentage',
1002
+                ),
1003
+
1004
+                'amount'        => array(
1005
+                    'description' => __( 'The discount value.', 'invoicing' ),
1006
+                    'type'        => 'number',
1007
+                    'context'     => array( 'view', 'edit', 'embed' ),
1008
+                    'required'	  => true,
1009
+                ),
1010
+
1011
+                'status'       => array(
1012
+                    'description' => __( 'A named status for the discount.', 'invoicing' ),
1013
+                    'type'        => 'string',
1014
+                    'enum'        => array_keys( get_post_stati( array( 'internal' => false ) ) ),
1015
+                    'context'     => array( 'view', 'edit' ),
1016
+                ),
1017
+
1018
+                'items'       => array(
1019
+                    'description' => __( 'Items which need to be in the cart to use this discount or, for "Item Discounts", which items are discounted. If left blank, this discount will be used on any item.', 'invoicing' ),
1020
+                    'type'        => 'array',
1021
+                    'context'     => array( 'view', 'edit' ),
1022
+                ),
1023
+
1024
+                'exclude_items'   => array(
1025
+                    'description' => __( 'Items which are NOT allowed to use this discount.', 'invoicing' ),
1026
+                    'type'        => 'array',
1027
+                    'context'     => array( 'view', 'edit' ),
1028
+                ),
1029
+
1030
+                'start_date'       => array(
1031
+                    'description' => __( 'The start date for the discount in the format of yyyy-mm-dd hh:mm:ss  . If provided, the discount can only be used after or on this date.', 'invoicing' ),
1032
+                    'type'        => 'string',
1033
+                    'context'     => array( 'view', 'edit' ),
1034
+                ),
1035
+
1036
+                'end_date'        => array(
1037
+                    'description' => __( 'The expiration date for the discount.', 'invoicing' ),
1038
+                    'type'        => 'string',
1039
+                    'context'     => array( 'view', 'edit', 'embed' ),
1040
+                ),
1041 1041
 				
1042
-				'minimum_amount'       => array(
1043
-					'description' => __( 'Minimum amount needed to use this invoice.', 'invoicing' ),
1044
-					'type'        => 'number',
1045
-					'context'     => array( 'view', 'edit', 'embed' ),
1046
-				),
1047
-
1048
-				'maximum_amount'       => array(
1049
-					'description' => __( 'Maximum amount needed to use this invoice.', 'invoicing' ),
1050
-					'type'        => 'number',
1051
-					'context'     => array( 'view', 'edit', 'embed' ),
1052
-				),
1053
-
1054
-				'recurring'       => array(
1055
-					'description' => __( 'Whether the discount is applied to all recurring payments or only the first recurring payment.', 'invoicing' ),
1056
-					'type'        => 'integer',
1057
-					'context'     => array( 'view', 'edit', 'embed' ),
1058
-				),
1059
-
1060
-				'max_uses'        => array(
1061
-					'description' => __( 'The maximum number of times this discount code can be used.', 'invoicing' ),
1062
-					'type'        => 'number',
1063
-					'context'     => array( 'view', 'edit', 'embed' ),
1064
-				),
1065
-
1066
-				'single_use'       => array(
1067
-					'description' => __( 'Whether or not this discount can only be used once per user.', 'invoicing' ),
1068
-					'type'        => 'integer',
1069
-					'context'     => array( 'view', 'edit', 'embed' ),
1070
-				)
1071
-
1072
-			),
1073
-		);
1074
-
1075
-		// Add helpful links to the discount schem.
1076
-		$schema['links'] = $this->get_schema_links();
1077
-
1078
-		/**
1079
-		 * Filters the discount schema for the REST API.
1080
-		 *
1081
-		 * Enables adding extra properties to discounts.
1082
-		 *
1083
-		 * @since 1.0.13
1084
-		 *
1085
-		 * @param array   $schema    The discount schema.
1086
-		 */
1042
+                'minimum_amount'       => array(
1043
+                    'description' => __( 'Minimum amount needed to use this invoice.', 'invoicing' ),
1044
+                    'type'        => 'number',
1045
+                    'context'     => array( 'view', 'edit', 'embed' ),
1046
+                ),
1047
+
1048
+                'maximum_amount'       => array(
1049
+                    'description' => __( 'Maximum amount needed to use this invoice.', 'invoicing' ),
1050
+                    'type'        => 'number',
1051
+                    'context'     => array( 'view', 'edit', 'embed' ),
1052
+                ),
1053
+
1054
+                'recurring'       => array(
1055
+                    'description' => __( 'Whether the discount is applied to all recurring payments or only the first recurring payment.', 'invoicing' ),
1056
+                    'type'        => 'integer',
1057
+                    'context'     => array( 'view', 'edit', 'embed' ),
1058
+                ),
1059
+
1060
+                'max_uses'        => array(
1061
+                    'description' => __( 'The maximum number of times this discount code can be used.', 'invoicing' ),
1062
+                    'type'        => 'number',
1063
+                    'context'     => array( 'view', 'edit', 'embed' ),
1064
+                ),
1065
+
1066
+                'single_use'       => array(
1067
+                    'description' => __( 'Whether or not this discount can only be used once per user.', 'invoicing' ),
1068
+                    'type'        => 'integer',
1069
+                    'context'     => array( 'view', 'edit', 'embed' ),
1070
+                )
1071
+
1072
+            ),
1073
+        );
1074
+
1075
+        // Add helpful links to the discount schem.
1076
+        $schema['links'] = $this->get_schema_links();
1077
+
1078
+        /**
1079
+         * Filters the discount schema for the REST API.
1080
+         *
1081
+         * Enables adding extra properties to discounts.
1082
+         *
1083
+         * @since 1.0.13
1084
+         *
1085
+         * @param array   $schema    The discount schema.
1086
+         */
1087 1087
         $schema = apply_filters( "wpinv_rest_discount_schema", $schema );
1088 1088
 
1089
-		//  Cache the discount schema.
1090
-		$this->schema = $schema;
1089
+        //  Cache the discount schema.
1090
+        $this->schema = $schema;
1091 1091
 		
1092
-		return $this->add_additional_fields_schema( $this->schema );
1093
-	}
1094
-
1095
-	/**
1096
-	 * Retrieve Link Description Objects that should be added to the Schema for the discounts collection.
1097
-	 *
1098
-	 * @since 1.0.13
1099
-	 *
1100
-	 * @return array
1101
-	 */
1102
-	protected function get_schema_links() {
1103
-
1104
-		$href = rest_url( "{$this->namespace}/{$this->rest_base}/{id}" );
1105
-
1106
-		$links = array();
1107
-
1108
-		$links[] = array(
1109
-			'rel'          => 'https://api.w.org/action-publish',
1110
-			'title'        => __( 'The current user can publish this discount.', 'invoicing' ),
1111
-			'href'         => $href,
1112
-			'targetSchema' => array(
1113
-				'type'       => 'object',
1114
-				'properties' => array(
1115
-					'status' => array(
1116
-						'type' => 'string',
1117
-						'enum' => array( 'publish', 'future' ),
1118
-					),
1119
-				),
1120
-			),
1121
-		);
1122
-
1123
-		return $links;
1124
-	}
1125
-
1126
-	/**
1127
-	 * Prepares links for the request.
1128
-	 *
1129
-	 * @since 1.0.13
1130
-	 *
1131
-	 * @param WP_Post $discount Post Object.
1132
-	 * @return array Links for the given discount.
1133
-	 */
1134
-	protected function prepare_links( $discount ) {
1135
-
1136
-		// Prepare the base REST API endpoint for discounts.
1137
-		$base = sprintf( '%s/%s', $this->namespace, $this->rest_base );
1138
-
1139
-		// Entity meta.
1140
-		$links = array(
1141
-			'self'       => array(
1142
-				'href' => rest_url( trailingslashit( $base ) . $discount->ID ),
1143
-			),
1144
-			'collection' => array(
1145
-				'href' => rest_url( $base ),
1146
-			),
1147
-		);
1148
-
1149
-		/**
1150
-		 * Filters the returned discount links for the REST API.
1151
-		 *
1152
-		 * Enables adding extra links to discount API responses.
1153
-		 *
1154
-		 * @since 1.0.13
1155
-		 *
1156
-		 * @param array   $links    Rest links.
1157
-		 */
1158
-		return apply_filters( "wpinv_rest_discount_links", $links );
1159
-
1160
-	}
1161
-
1162
-	/**
1163
-	 * Get the link relations available for the post and current user.
1164
-	 *
1165
-	 * @since 1.0.13
1166
-	 *
1167
-	 * @param WP_Post   $discount    WP_Post object.
1168
-	 * @param WP_REST_Request $request Request object.
1169
-	 * @return array List of link relations.
1170
-	 */
1171
-	protected function get_available_actions( $discount, $request ) {
1172
-
1173
-		if ( 'edit' !== $request['context'] ) {
1174
-			return array();
1175
-		}
1176
-
1177
-		$rels = array();
1178
-
1179
-		// Retrieve the post type object.
1180
-		$post_type = get_post_type_object( $discount->post_type );
1181
-
1182
-		// Mark discount as published.
1183
-		if ( current_user_can( $post_type->cap->publish_posts ) ) {
1184
-			$rels[] = 'https://api.w.org/action-publish';
1185
-		}
1186
-
1187
-		/**
1188
-		 * Filters the available discount link relations for the REST API.
1189
-		 *
1190
-		 * Enables adding extra link relation for the current user and request to discount responses.
1191
-		 *
1192
-		 * @since 1.0.13
1193
-		 *
1194
-		 * @param array   $rels    Available link relations.
1195
-		 */
1196
-		return apply_filters( "wpinv_rest_discount_link_relations", $rels );
1197
-	}
1198
-
1199
-	/**
1200
-	 * Handles rest requests for discount types.
1201
-	 *
1202
-	 * @since 1.0.13
1203
-	 * 
1204
-	 * 
1205
-	 * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
1206
-	 */
1207
-	public function get_discount_types() {
1208
-		return rest_ensure_response( wpinv_get_discount_types() );
1209
-	}
1092
+        return $this->add_additional_fields_schema( $this->schema );
1093
+    }
1094
+
1095
+    /**
1096
+     * Retrieve Link Description Objects that should be added to the Schema for the discounts collection.
1097
+     *
1098
+     * @since 1.0.13
1099
+     *
1100
+     * @return array
1101
+     */
1102
+    protected function get_schema_links() {
1103
+
1104
+        $href = rest_url( "{$this->namespace}/{$this->rest_base}/{id}" );
1105
+
1106
+        $links = array();
1107
+
1108
+        $links[] = array(
1109
+            'rel'          => 'https://api.w.org/action-publish',
1110
+            'title'        => __( 'The current user can publish this discount.', 'invoicing' ),
1111
+            'href'         => $href,
1112
+            'targetSchema' => array(
1113
+                'type'       => 'object',
1114
+                'properties' => array(
1115
+                    'status' => array(
1116
+                        'type' => 'string',
1117
+                        'enum' => array( 'publish', 'future' ),
1118
+                    ),
1119
+                ),
1120
+            ),
1121
+        );
1122
+
1123
+        return $links;
1124
+    }
1125
+
1126
+    /**
1127
+     * Prepares links for the request.
1128
+     *
1129
+     * @since 1.0.13
1130
+     *
1131
+     * @param WP_Post $discount Post Object.
1132
+     * @return array Links for the given discount.
1133
+     */
1134
+    protected function prepare_links( $discount ) {
1135
+
1136
+        // Prepare the base REST API endpoint for discounts.
1137
+        $base = sprintf( '%s/%s', $this->namespace, $this->rest_base );
1138
+
1139
+        // Entity meta.
1140
+        $links = array(
1141
+            'self'       => array(
1142
+                'href' => rest_url( trailingslashit( $base ) . $discount->ID ),
1143
+            ),
1144
+            'collection' => array(
1145
+                'href' => rest_url( $base ),
1146
+            ),
1147
+        );
1148
+
1149
+        /**
1150
+         * Filters the returned discount links for the REST API.
1151
+         *
1152
+         * Enables adding extra links to discount API responses.
1153
+         *
1154
+         * @since 1.0.13
1155
+         *
1156
+         * @param array   $links    Rest links.
1157
+         */
1158
+        return apply_filters( "wpinv_rest_discount_links", $links );
1159
+
1160
+    }
1161
+
1162
+    /**
1163
+     * Get the link relations available for the post and current user.
1164
+     *
1165
+     * @since 1.0.13
1166
+     *
1167
+     * @param WP_Post   $discount    WP_Post object.
1168
+     * @param WP_REST_Request $request Request object.
1169
+     * @return array List of link relations.
1170
+     */
1171
+    protected function get_available_actions( $discount, $request ) {
1172
+
1173
+        if ( 'edit' !== $request['context'] ) {
1174
+            return array();
1175
+        }
1176
+
1177
+        $rels = array();
1178
+
1179
+        // Retrieve the post type object.
1180
+        $post_type = get_post_type_object( $discount->post_type );
1181
+
1182
+        // Mark discount as published.
1183
+        if ( current_user_can( $post_type->cap->publish_posts ) ) {
1184
+            $rels[] = 'https://api.w.org/action-publish';
1185
+        }
1186
+
1187
+        /**
1188
+         * Filters the available discount link relations for the REST API.
1189
+         *
1190
+         * Enables adding extra link relation for the current user and request to discount responses.
1191
+         *
1192
+         * @since 1.0.13
1193
+         *
1194
+         * @param array   $rels    Available link relations.
1195
+         */
1196
+        return apply_filters( "wpinv_rest_discount_link_relations", $rels );
1197
+    }
1198
+
1199
+    /**
1200
+     * Handles rest requests for discount types.
1201
+     *
1202
+     * @since 1.0.13
1203
+     * 
1204
+     * 
1205
+     * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
1206
+     */
1207
+    public function get_discount_types() {
1208
+        return rest_ensure_response( wpinv_get_discount_types() );
1209
+    }
1210 1210
     
1211 1211
 }
1212 1212
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +261 added lines, -261 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
  * @since    1.0.13
9 9
  */
10 10
 
11
-if ( !defined( 'WPINC' ) ) {
11
+if (!defined('WPINC')) {
12 12
     exit;
13 13
 }
14 14
 
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
 	 *
42 42
 	 * @param string $namespace Api Namespace
43 43
 	 */
44
-	public function __construct( $namespace ) {
44
+	public function __construct($namespace) {
45 45
         
46 46
         // Set api namespace...
47 47
 		$this->namespace = $namespace;
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
 			array(
69 69
 				array(
70 70
 					'methods'             => WP_REST_Server::READABLE,
71
-					'callback'            => array( $this, 'get_discount_types' ),
71
+					'callback'            => array($this, 'get_discount_types'),
72 72
 					'permission_callback' => '__return_true',
73 73
 				),
74 74
 			)
@@ -85,13 +85,13 @@  discard block
 block discarded – undo
85 85
 	 * @param WP_REST_Request $request Full details about the request.
86 86
 	 * @return true|WP_Error True if the request has read access, WP_Error object otherwise.
87 87
 	 */
88
-	public function get_items_permissions_check( $request ) {
88
+	public function get_items_permissions_check($request) {
89 89
 	
90
-		if ( wpinv_current_user_can_manage_invoicing() ) {
90
+		if (wpinv_current_user_can_manage_invoicing()) {
91 91
 			return true;
92 92
 		}
93 93
 
94
-		return new WP_Error( 'rest_forbidden_context', __( 'Sorry, you are not allowed to view invoice discounts.', 'invoicing' ), array( 'status' => rest_authorization_required_code() ) );
94
+		return new WP_Error('rest_forbidden_context', __('Sorry, you are not allowed to view invoice discounts.', 'invoicing'), array('status' => rest_authorization_required_code()));
95 95
 
96 96
     }
97 97
     
@@ -103,17 +103,17 @@  discard block
 block discarded – undo
103 103
 	 * @param WP_REST_Request $request Full details about the request.
104 104
 	 * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
105 105
 	 */
106
-	public function get_items( $request ) {
106
+	public function get_items($request) {
107 107
 		
108 108
 		// Retrieve the list of registered item query parameters.
109 109
         $registered = $this->get_collection_params();
110 110
         
111 111
         $args       = array();
112 112
 
113
-        foreach( array_keys( $registered ) as $key ) {
113
+        foreach (array_keys($registered) as $key) {
114 114
 
115
-            if( isset( $request[ $key] ) ) {
116
-                $args[ $key ] = $request[ $key];
115
+            if (isset($request[$key])) {
116
+                $args[$key] = $request[$key];
117 117
             }
118 118
 
119 119
 		} 
@@ -128,28 +128,28 @@  discard block
 block discarded – undo
128 128
 		 * @param array           $args    Key value array of query var to query value.
129 129
 		 * @param WP_REST_Request $request The request used.
130 130
 		 */
131
-        $args       = apply_filters( "wpinv_rest_get_discounts_arguments", $args, $request, $this );
131
+        $args = apply_filters("wpinv_rest_get_discounts_arguments", $args, $request, $this);
132 132
 		
133 133
 		// Special args
134
-		$args[ 'return' ]   = 'objects';
135
-		$args[ 'paginate' ] = true;
134
+		$args['return']   = 'objects';
135
+		$args['paginate'] = true;
136 136
 
137 137
         // Run the query.
138
-		$query = wpinv_get_all_discounts( $args );
138
+		$query = wpinv_get_all_discounts($args);
139 139
 		
140 140
 		// Prepare the retrieved discounts
141 141
 		$discounts = array();
142
-		foreach( $query->discounts as $discount ) {
142
+		foreach ($query->discounts as $discount) {
143 143
 
144
-			$data       = $this->prepare_item_for_response( $discount, $request );
145
-			$discounts[]    = $this->prepare_response_for_collection( $data );
144
+			$data = $this->prepare_item_for_response($discount, $request);
145
+			$discounts[] = $this->prepare_response_for_collection($data);
146 146
 
147 147
 		}
148 148
 
149 149
 		// Prepare the response.
150
-		$response = rest_ensure_response( $discounts );
151
-		$response->header( 'X-WP-Total', (int) $query->total );
152
-		$response->header( 'X-WP-TotalPages', (int) $query->max_num_pages );
150
+		$response = rest_ensure_response($discounts);
151
+		$response->header('X-WP-Total', (int) $query->total);
152
+		$response->header('X-WP-TotalPages', (int) $query->max_num_pages);
153 153
 
154 154
 		/**
155 155
 		 * Filters the responses for discount requests.
@@ -162,9 +162,9 @@  discard block
 block discarded – undo
162 162
 		 * @param WP_REST_Request     $request The request used.
163 163
          * @param array               $args Array of args used to retrieve the discounts
164 164
 		 */
165
-        $response       = apply_filters( "wpinv_rest_discounts_response", $response, $request, $args );
165
+        $response = apply_filters("wpinv_rest_discounts_response", $response, $request, $args);
166 166
 
167
-        return rest_ensure_response( $response );
167
+        return rest_ensure_response($response);
168 168
         
169 169
     }
170 170
 
@@ -176,17 +176,17 @@  discard block
 block discarded – undo
176 176
 	 * @param int $discount_id Supplied ID.
177 177
 	 * @return WP_Post|WP_Error Post object if ID is valid, WP_Error otherwise.
178 178
 	 */
179
-	protected function get_post( $discount_id ) {
179
+	protected function get_post($discount_id) {
180 180
 		
181
-		$error     = new WP_Error( 'rest_item_invalid_id', __( 'Invalid discount ID.', 'invoicing' ), array( 'status' => 404 ) );
181
+		$error = new WP_Error('rest_item_invalid_id', __('Invalid discount ID.', 'invoicing'), array('status' => 404));
182 182
 
183 183
         // Ids start from 1
184
-        if ( (int) $discount_id <= 0 ) {
184
+        if ((int) $discount_id <= 0) {
185 185
 			return $error;
186 186
 		}
187 187
 
188
-		$discount = wpinv_get_discount( (int) $discount_id );
189
-		if ( empty( $discount ) ) {
188
+		$discount = wpinv_get_discount((int) $discount_id);
189
+		if (empty($discount)) {
190 190
 			return $error;
191 191
         }
192 192
 
@@ -202,20 +202,20 @@  discard block
 block discarded – undo
202 202
 	 * @param WP_REST_Request $request Full details about the request.
203 203
 	 * @return bool|WP_Error True if the request has read access for the invoice item, WP_Error object otherwise.
204 204
 	 */
205
-	public function get_item_permissions_check( $request ) {
205
+	public function get_item_permissions_check($request) {
206 206
 
207 207
         // Retrieve the discount object.
208
-        $discount = $this->get_post( $request['id'] );
208
+        $discount = $this->get_post($request['id']);
209 209
         
210 210
         // Ensure it is valid.
211
-		if ( is_wp_error( $discount ) ) {
211
+		if (is_wp_error($discount)) {
212 212
 			return $discount;
213 213
 		}
214 214
 
215
-		if ( ! wpinv_current_user_can_manage_invoicing() ) {
215
+		if (!wpinv_current_user_can_manage_invoicing()) {
216 216
 			return new WP_Error(
217 217
                 'rest_cannot_view', 
218
-                __( 'Sorry, you are not allowed to view this discount.', 'invoicing' ), 
218
+                __('Sorry, you are not allowed to view this discount.', 'invoicing'), 
219 219
                 array( 
220 220
                     'status' => rest_authorization_required_code(),
221 221
                 )
@@ -233,18 +233,18 @@  discard block
 block discarded – undo
233 233
 	 * @param WP_REST_Request $request Full details about the request.
234 234
 	 * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
235 235
 	 */
236
-	public function get_item( $request ) {
236
+	public function get_item($request) {
237 237
 
238 238
         // Fetch the discount.
239
-        $discount = $this->get_post( $request['id'] );
239
+        $discount = $this->get_post($request['id']);
240 240
         
241 241
         // Abort early if it does not exist
242
-		if ( is_wp_error( $discount ) ) {
242
+		if (is_wp_error($discount)) {
243 243
 			return $discount;
244 244
 		}
245 245
 
246 246
 		// Prepare the response
247
-		$response = $this->prepare_item_for_response( $discount, $request );
247
+		$response = $this->prepare_item_for_response($discount, $request);
248 248
 
249 249
 		/**
250 250
 		 * Filters the responses for single discount requests.
@@ -256,9 +256,9 @@  discard block
 block discarded – undo
256 256
 		 * @param WP_HTTP_Response $response Response.
257 257
 		 * @param WP_REST_Request  $request The request used.
258 258
 		 */
259
-        $response       = apply_filters( "wpinv_rest_get_discount_response", $response, $request );
259
+        $response = apply_filters("wpinv_rest_get_discount_response", $response, $request);
260 260
 
261
-        return rest_ensure_response( $response );
261
+        return rest_ensure_response($response);
262 262
 
263 263
     }
264 264
     
@@ -270,21 +270,21 @@  discard block
 block discarded – undo
270 270
 	 * @param WP_REST_Request $request Full details about the request.
271 271
 	 * @return true|WP_Error True if the request has access to create items, WP_Error object otherwise.
272 272
 	 */
273
-	public function create_item_permissions_check( $request ) {
273
+	public function create_item_permissions_check($request) {
274 274
 	
275
-		if ( ! empty( $request['id'] ) ) {
276
-			return new WP_Error( 'rest_item_exists', __( 'Cannot create existing item.', 'invoicing' ), array( 'status' => 400 ) );
275
+		if (!empty($request['id'])) {
276
+			return new WP_Error('rest_item_exists', __('Cannot create existing item.', 'invoicing'), array('status' => 400));
277 277
 		}
278 278
 
279
-		if ( wpinv_current_user_can_manage_invoicing() ) {
279
+		if (wpinv_current_user_can_manage_invoicing()) {
280 280
 			return true;
281 281
 		}
282 282
 
283
-		$post_type = get_post_type_object( $this->post_type );
284
-		if ( ! current_user_can( $post_type->cap->create_posts ) ) {
283
+		$post_type = get_post_type_object($this->post_type);
284
+		if (!current_user_can($post_type->cap->create_posts)) {
285 285
 			return new WP_Error( 
286 286
                 'rest_cannot_create', 
287
-                __( 'Sorry, you are not allowed to create discounts as this user.', 'invoicing' ), 
287
+                __('Sorry, you are not allowed to create discounts as this user.', 'invoicing'), 
288 288
                 array( 
289 289
                     'status' => rest_authorization_required_code(),
290 290
                 )
@@ -302,32 +302,32 @@  discard block
 block discarded – undo
302 302
 	 * @param WP_REST_Request $request Full details about the request.
303 303
 	 * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
304 304
 	 */
305
-	public function create_item( $request ) {
305
+	public function create_item($request) {
306 306
 
307
-		if ( ! empty( $request['id'] ) ) {
308
-			return new WP_Error( 'rest_item_exists', __( 'Cannot create existing discount.', 'invoicing' ), array( 'status' => 400 ) );
307
+		if (!empty($request['id'])) {
308
+			return new WP_Error('rest_item_exists', __('Cannot create existing discount.', 'invoicing'), array('status' => 400));
309 309
 		}
310 310
 
311
-		$request->set_param( 'context', 'edit' );
311
+		$request->set_param('context', 'edit');
312 312
 
313 313
 		// Prepare the updated data.
314
-		$discount_data = $this->prepare_item_for_database( $request );
314
+		$discount_data = $this->prepare_item_for_database($request);
315 315
 
316
-		if ( is_wp_error( $discount_data ) ) {
316
+		if (is_wp_error($discount_data)) {
317 317
 			return $discount_data;
318 318
 		}
319 319
 
320 320
 		$discount_data['post_type'] = $this->post_type;
321 321
 
322 322
 		// Try creating the discount.
323
-        $discount = wp_insert_post( $discount_data, true );
323
+        $discount = wp_insert_post($discount_data, true);
324 324
 
325
-		if ( is_wp_error( $discount ) ) {
325
+		if (is_wp_error($discount)) {
326 326
             return $discount;
327 327
 		}
328 328
 
329 329
 		// Prepare the response
330
-		$response = $this->prepare_item_for_response( $discount, $request );
330
+		$response = $this->prepare_item_for_response($discount, $request);
331 331
 
332 332
 		/**
333 333
 		 * Fires after a single discount is created or updated via the REST API.
@@ -338,7 +338,7 @@  discard block
 block discarded – undo
338 338
 		 * @param WP_REST_Request $request  Request object.
339 339
 		 * @param bool            $creating True when creating a post, false when updating.
340 340
 		 */
341
-		do_action( "wpinv_rest_insert_discount", $discount, $request, true );
341
+		do_action("wpinv_rest_insert_discount", $discount, $request, true);
342 342
 
343 343
 		/**
344 344
 		 * Filters the responses for creating single item requests.
@@ -350,9 +350,9 @@  discard block
 block discarded – undo
350 350
 		 * @param array           $response Invoice properties.
351 351
 		 * @param WP_REST_Request $request The request used.
352 352
 		 */
353
-        $response       = apply_filters( "wpinv_rest_create_discount_response", $response, $request );
353
+        $response = apply_filters("wpinv_rest_create_discount_response", $response, $request);
354 354
 
355
-        return rest_ensure_response( $response );
355
+        return rest_ensure_response($response);
356 356
 	}
357 357
 
358 358
 	/**
@@ -363,21 +363,21 @@  discard block
 block discarded – undo
363 363
 	 * @param WP_REST_Request $request Full details about the request.
364 364
 	 * @return true|WP_Error True if the request has access to update the item, WP_Error object otherwise.
365 365
 	 */
366
-	public function update_item_permissions_check( $request ) {
366
+	public function update_item_permissions_check($request) {
367 367
 
368 368
 		// Retrieve the item.
369
-		$item = $this->get_post( $request['id'] );
370
-		if ( is_wp_error( $item ) ) {
369
+		$item = $this->get_post($request['id']);
370
+		if (is_wp_error($item)) {
371 371
 			return $item;
372 372
 		}
373 373
 
374
-		if ( wpinv_current_user_can_manage_invoicing() ) {
374
+		if (wpinv_current_user_can_manage_invoicing()) {
375 375
 			return true;
376 376
 		}
377 377
 
378 378
 		return new WP_Error( 
379 379
 			'rest_cannot_edit', 
380
-			__( 'Sorry, you are not allowed to update this discount.', 'invoicing' ), 
380
+			__('Sorry, you are not allowed to update this discount.', 'invoicing'), 
381 381
 			array( 
382 382
 				'status' => rest_authorization_required_code(),
383 383
 			)
@@ -393,62 +393,62 @@  discard block
 block discarded – undo
393 393
 	 * @param WP_REST_Request $request Full details about the request.
394 394
 	 * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
395 395
 	 */
396
-	public function update_item( $request ) {
396
+	public function update_item($request) {
397 397
 		
398 398
 		// Ensure the item exists.
399
-        $valid_check = $this->get_post( $request['id'] );
399
+        $valid_check = $this->get_post($request['id']);
400 400
         
401 401
         // Abort early if it does not exist
402
-		if ( is_wp_error( $valid_check ) ) {
402
+		if (is_wp_error($valid_check)) {
403 403
 			return $valid_check;
404 404
 		}
405 405
 
406
-		$request->set_param( 'context', 'edit' );
406
+		$request->set_param('context', 'edit');
407 407
 
408 408
 		// Prepare the updated data.
409
-		$data_to_update = $this->prepare_item_for_database( $request );
409
+		$data_to_update = $this->prepare_item_for_database($request);
410 410
 
411
-		if ( is_wp_error( $data_to_update ) ) {
411
+		if (is_wp_error($data_to_update)) {
412 412
 			return $data_to_update;
413 413
 		}
414 414
 
415
-		if( empty( $data_to_update['meta_input'] ) ) {
416
-			unset( $data_to_update['meta_input'] );
415
+		if (empty($data_to_update['meta_input'])) {
416
+			unset($data_to_update['meta_input']);
417 417
 		}
418 418
 
419 419
 		// Abort if no item data is provided
420
-        if( empty( $data_to_update ) ) {
421
-            return new WP_Error( 'missing_data', __( 'An update request cannot be empty.', 'invoicing' ) );
420
+        if (empty($data_to_update)) {
421
+            return new WP_Error('missing_data', __('An update request cannot be empty.', 'invoicing'));
422 422
 		}
423 423
 		
424 424
 		// post_status
425
-		if( ! empty( $data_to_update['post_status'] ) ) {
426
-			wpinv_update_discount_status( $request['id'], $data_to_update['post_status'] );
427
-			unset( $data_to_update['post_status'] );
425
+		if (!empty($data_to_update['post_status'])) {
426
+			wpinv_update_discount_status($request['id'], $data_to_update['post_status']);
427
+			unset($data_to_update['post_status']);
428 428
 		}
429 429
 
430 430
 		// Update the item
431
-		if( ! empty( $data_to_update ) ) {
431
+		if (!empty($data_to_update)) {
432 432
 
433 433
 			// Include the item ID
434 434
 			$data_to_update['ID'] = $request['id'];
435 435
 
436
-			$updated = wp_update_post( $data_to_update, true );
436
+			$updated = wp_update_post($data_to_update, true);
437 437
 
438 438
 			// Incase the update operation failed...
439
-			if ( is_wp_error( $updated ) ) {
439
+			if (is_wp_error($updated)) {
440 440
 				return $updated;
441 441
 			}
442 442
 
443 443
 		}
444 444
 
445
-		$updated_discount = get_post( $request['id'] );
445
+		$updated_discount = get_post($request['id']);
446 446
 
447 447
 		// Prepare the response
448
-		$response = $this->prepare_item_for_response( $updated_discount, $request );
448
+		$response = $this->prepare_item_for_response($updated_discount, $request);
449 449
 
450 450
 		/** This action is documented in includes/class-wpinv-rest-item-controller.php */
451
-		do_action( "wpinv_rest_insert_discount", $updated_discount, $request, false );
451
+		do_action("wpinv_rest_insert_discount", $updated_discount, $request, false);
452 452
 
453 453
 		/**
454 454
 		 * Filters the responses for updating single discount requests.
@@ -460,9 +460,9 @@  discard block
 block discarded – undo
460 460
 		 * @param array           $data_to_update Discount properties.
461 461
 		 * @param WP_REST_Request $request The request used.
462 462
 		 */
463
-        $response       = apply_filters( "wpinv_rest_update_discount_response", $response,  $data_to_update, $request );
463
+        $response = apply_filters("wpinv_rest_update_discount_response", $response, $data_to_update, $request);
464 464
 
465
-        return rest_ensure_response( $response );
465
+        return rest_ensure_response($response);
466 466
 	}
467 467
 
468 468
 	/**
@@ -473,19 +473,19 @@  discard block
 block discarded – undo
473 473
 	 * @param WP_REST_Request $request Full details about the request.
474 474
 	 * @return true|WP_Error True if the request has access to delete the discount, WP_Error object otherwise.
475 475
 	 */
476
-	public function delete_item_permissions_check( $request ) {
476
+	public function delete_item_permissions_check($request) {
477 477
 
478 478
 		// Retrieve the discount.
479
-		$discount = $this->get_post( $request['id'] );
480
-		if ( is_wp_error( $discount ) ) {
479
+		$discount = $this->get_post($request['id']);
480
+		if (is_wp_error($discount)) {
481 481
 			return $discount;
482 482
 		} 
483 483
 
484 484
 		// Ensure the current user can delete the discount
485
-		if (! wpinv_current_user_can_manage_invoicing() ) {
485
+		if (!wpinv_current_user_can_manage_invoicing()) {
486 486
 			return new WP_Error( 
487 487
                 'rest_cannot_delete', 
488
-                __( 'Sorry, you are not allowed to delete this discount.', 'invoicing' ), 
488
+                __('Sorry, you are not allowed to delete this discount.', 'invoicing'), 
489 489
                 array( 
490 490
                     'status' => rest_authorization_required_code(),
491 491
                 )
@@ -503,24 +503,24 @@  discard block
 block discarded – undo
503 503
 	 * @param WP_REST_Request $request Full details about the request.
504 504
 	 * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
505 505
 	 */
506
-	public function delete_item( $request ) {
506
+	public function delete_item($request) {
507 507
 		
508 508
 		// Retrieve the discount.
509
-		$discount = $this->get_post( $request['id'] );
510
-		if ( is_wp_error( $discount ) ) {
509
+		$discount = $this->get_post($request['id']);
510
+		if (is_wp_error($discount)) {
511 511
 			return $discount;
512 512
 		}
513 513
 
514
-		$request->set_param( 'context', 'edit' );
514
+		$request->set_param('context', 'edit');
515 515
 
516 516
 		// Prepare the discount id
517
-		$id    = $discount->ID;
517
+		$id = $discount->ID;
518 518
 
519 519
 		// Prepare the response
520
-		$response = $this->prepare_item_for_response( $discount, $request );
520
+		$response = $this->prepare_item_for_response($discount, $request);
521 521
 
522 522
 		// Delete the discount...
523
-		wpinv_remove_discount( $id );
523
+		wpinv_remove_discount($id);
524 524
 
525 525
 		/**
526 526
 		 * Fires immediately after a single discount is deleted via the REST API.
@@ -531,7 +531,7 @@  discard block
 block discarded – undo
531 531
 		 * @param WP_POST    $discount  The deleted discount.
532 532
 		 * @param WP_REST_Request  $request  The request sent to the API.
533 533
 		 */
534
-		do_action( "wpinv_rest_delete_discount", $discount, $request );
534
+		do_action("wpinv_rest_delete_discount", $discount, $request);
535 535
 
536 536
 		return $response;
537 537
 
@@ -547,44 +547,44 @@  discard block
 block discarded – undo
547 547
 	 */
548 548
 	public function get_collection_params() {
549 549
         
550
-        $query_params               = array(
550
+        $query_params = array(
551 551
 
552 552
             // Discount status.
553 553
             'status'                => array(
554 554
                 'default'           => 'publish',
555
-                'description'       => __( 'Limit result set to discounts assigned one or more statuses.', 'invoicing' ),
555
+                'description'       => __('Limit result set to discounts assigned one or more statuses.', 'invoicing'),
556 556
                 'type'              => 'array',
557
-                'sanitize_callback' => array( $this, 'sanitize_post_statuses' ),
557
+                'sanitize_callback' => array($this, 'sanitize_post_statuses'),
558 558
             ),
559 559
             
560 560
             // Discount types
561 561
             'type'                  => array(
562
-				'description'       => __( 'Type of discounts to fetch.', 'invoicing' ),
562
+				'description'       => __('Type of discounts to fetch.', 'invoicing'),
563 563
 				'type'              => 'array',
564
-				'default'           => array_keys( wpinv_get_discount_types() ),
564
+				'default'           => array_keys(wpinv_get_discount_types()),
565 565
 				'items'             => array(
566
-                    'enum'          => array_keys( wpinv_get_discount_types() ),
566
+                    'enum'          => array_keys(wpinv_get_discount_types()),
567 567
                     'type'          => 'string',
568 568
                 ),
569 569
 			),
570 570
 			
571 571
 			// Number of results per page
572 572
             'limit'                 => array(
573
-				'description'       => __( 'Number of discounts to fetch.', 'invoicing' ),
573
+				'description'       => __('Number of discounts to fetch.', 'invoicing'),
574 574
 				'type'              => 'integer',
575
-				'default'           => (int) get_option( 'posts_per_page' ),
575
+				'default'           => (int) get_option('posts_per_page'),
576 576
             ),
577 577
 
578 578
             // Pagination
579 579
             'page'     => array(
580
-				'description'       => __( 'Current page to fetch.', 'invoicing' ),
580
+				'description'       => __('Current page to fetch.', 'invoicing'),
581 581
 				'type'              => 'integer',
582 582
 				'default'           => 1,
583 583
             ),
584 584
 
585 585
             // Exclude certain items
586 586
             'exclude'  => array(
587
-                'description' => __( 'Ensure result set excludes specific IDs.', 'invoicing' ),
587
+                'description' => __('Ensure result set excludes specific IDs.', 'invoicing'),
588 588
                 'type'        => 'array',
589 589
                 'items'       => array(
590 590
                     'type' => 'integer',
@@ -594,7 +594,7 @@  discard block
 block discarded – undo
594 594
 
595 595
             // Order discounts by
596 596
             'orderby'  => array(
597
-                'description' => __( 'Sort discounts by object attribute.', 'invoicing' ),
597
+                'description' => __('Sort discounts by object attribute.', 'invoicing'),
598 598
                 'type'        => 'string',
599 599
                 'default'     => 'date',
600 600
                 'enum'        => array(
@@ -610,15 +610,15 @@  discard block
 block discarded – undo
610 610
 
611 611
             // How to order
612 612
             'order'    => array(
613
-                'description' => __( 'Order sort attribute ascending or descending.', 'invoicing' ),
613
+                'description' => __('Order sort attribute ascending or descending.', 'invoicing'),
614 614
                 'type'        => 'string',
615 615
                 'default'     => 'DESC',
616
-                'enum'        => array( 'ASC', 'DESC' ),
616
+                'enum'        => array('ASC', 'DESC'),
617 617
 			),
618 618
 			
619 619
 			// Search term
620 620
             'search'                => array(
621
-				'description'       => __( 'Return discounts that match the search term.', 'invoicing' ),
621
+				'description'       => __('Return discounts that match the search term.', 'invoicing'),
622 622
 				'type'              => 'string',
623 623
             ),
624 624
         );
@@ -631,7 +631,7 @@  discard block
 block discarded – undo
631 631
 		 *
632 632
 		 * @param array        $query_params JSON Schema-formatted collection parameters.
633 633
 		 */
634
-		return apply_filters( "wpinv_rest_discounts_collection_params", $query_params );
634
+		return apply_filters("wpinv_rest_discounts_collection_params", $query_params);
635 635
     }
636 636
     
637 637
     /**
@@ -642,7 +642,7 @@  discard block
 block discarded – undo
642 642
 	 * @param object|string $post_type Post type name or object.
643 643
 	 * @return bool Whether the post type is allowed in REST.
644 644
 	 */
645
-	protected function check_is_post_type_allowed( $post_type ) {
645
+	protected function check_is_post_type_allowed($post_type) {
646 646
 		return true;
647 647
 	}
648 648
 
@@ -654,93 +654,93 @@  discard block
 block discarded – undo
654 654
 	 * @param WP_REST_Request $request Request object.
655 655
 	 * @return array|WP_Error Discount Properties or WP_Error.
656 656
 	 */
657
-	protected function prepare_item_for_database( $request ) {
658
-		$prepared_item 		 = new stdClass();
657
+	protected function prepare_item_for_database($request) {
658
+		$prepared_item = new stdClass();
659 659
 		$prepared_item->meta_input = array();
660 660
 
661 661
 		// Post ID.
662
-		if ( isset( $request['id'] ) ) {
663
-			$existing_item = $this->get_post( $request['id'] );
664
-			if ( is_wp_error( $existing_item ) ) {
662
+		if (isset($request['id'])) {
663
+			$existing_item = $this->get_post($request['id']);
664
+			if (is_wp_error($existing_item)) {
665 665
 				return $existing_item;
666 666
 			}
667 667
 
668
-			$prepared_item->ID 		  = $existing_item->ID;
668
+			$prepared_item->ID = $existing_item->ID;
669 669
 		}
670 670
 
671 671
 		$schema = $this->get_item_schema();
672 672
 
673 673
 		// item title.
674
-		if ( ! empty( $schema['properties']['title'] ) && isset( $request['title'] ) ) {
675
-			$prepared_item->post_title = sanitize_text_field( $request['title'] );
674
+		if (!empty($schema['properties']['title']) && isset($request['title'])) {
675
+			$prepared_item->post_title = sanitize_text_field($request['title']);
676 676
 		}
677 677
 
678 678
 		// item status.
679
-		if ( ! empty( $schema['properties']['status'] ) && isset( $request['status'] ) && in_array( $request['status'], array_keys( get_post_stati( array( 'internal' => false ) ) ) ) ) {
680
-			$prepared_item->post_status = sanitize_text_field( $request['status'] );
679
+		if (!empty($schema['properties']['status']) && isset($request['status']) && in_array($request['status'], array_keys(get_post_stati(array('internal' => false))))) {
680
+			$prepared_item->post_status = sanitize_text_field($request['status']);
681 681
 		}
682 682
 
683 683
 		// Code.
684
-		if ( ! empty( $schema['properties']['code'] ) && isset( $request['code'] ) ) {
685
-			$prepared_item->meta_input['_wpi_discount_code'] = trim( $request['code'] );
684
+		if (!empty($schema['properties']['code']) && isset($request['code'])) {
685
+			$prepared_item->meta_input['_wpi_discount_code'] = trim($request['code']);
686 686
 		}
687 687
 
688 688
 		// Type.
689
-		if ( ! empty( $schema['properties']['type'] ) && isset( $request['type'] )  && in_array( $request['type'], array_keys( wpinv_get_discount_types() ) ) ) {
690
-			$prepared_item->meta_input['_wpi_discount_type'] = trim( $request['type'] );
689
+		if (!empty($schema['properties']['type']) && isset($request['type']) && in_array($request['type'], array_keys(wpinv_get_discount_types()))) {
690
+			$prepared_item->meta_input['_wpi_discount_type'] = trim($request['type']);
691 691
 		}
692 692
 
693 693
 		// Amount.
694
-		if ( ! empty( $schema['properties']['amount'] ) && isset( $request['amount'] ) ) {
695
-			$prepared_item->meta_input['_wpi_discount_amount'] = floatval( $request['amount'] );
694
+		if (!empty($schema['properties']['amount']) && isset($request['amount'])) {
695
+			$prepared_item->meta_input['_wpi_discount_amount'] = floatval($request['amount']);
696 696
 		}
697 697
 
698 698
 		// Items.
699
-		if ( ! empty( $schema['properties']['items'] ) && isset( $request['items'] ) ) {
700
-			$prepared_item->meta_input['_wpi_discount_items'] = wpinv_parse_list( $request['items'] );
699
+		if (!empty($schema['properties']['items']) && isset($request['items'])) {
700
+			$prepared_item->meta_input['_wpi_discount_items'] = wpinv_parse_list($request['items']);
701 701
 		}
702 702
 
703 703
 		// Excluded Items.
704
-		if ( ! empty( $schema['properties']['exclude_items'] ) && isset( $request['exclude_items'] ) ) {
705
-			$prepared_item->meta_input['_wpi_discount_excluded_items'] = wpinv_parse_list( $request['exclude_items'] );
704
+		if (!empty($schema['properties']['exclude_items']) && isset($request['exclude_items'])) {
705
+			$prepared_item->meta_input['_wpi_discount_excluded_items'] = wpinv_parse_list($request['exclude_items']);
706 706
 		}
707 707
 
708 708
 		// Start date.
709
-		if ( ! empty( $schema['properties']['start_date'] ) && isset( $request['start_date'] ) ) {
710
-			$prepared_item->meta_input['_wpi_discount_start'] = trim( $request['start_date'] );
709
+		if (!empty($schema['properties']['start_date']) && isset($request['start_date'])) {
710
+			$prepared_item->meta_input['_wpi_discount_start'] = trim($request['start_date']);
711 711
 		}
712 712
 
713 713
 		// End date.
714
-		if ( ! empty( $schema['properties']['end_date'] ) && isset( $request['end_date'] ) ) {
715
-			$prepared_item->meta_input['_wpi_discount_expiration'] = trim( $request['end_date'] );
714
+		if (!empty($schema['properties']['end_date']) && isset($request['end_date'])) {
715
+			$prepared_item->meta_input['_wpi_discount_expiration'] = trim($request['end_date']);
716 716
 		}
717 717
 
718 718
 		// Minimum amount.
719
-		if ( ! empty( $schema['properties']['minimum_amount'] ) && isset( $request['minimum_amount'] ) ) {
720
-			$prepared_item->meta_input['_wpi_discount_min_total'] = floatval( $request['minimum_amount'] );
719
+		if (!empty($schema['properties']['minimum_amount']) && isset($request['minimum_amount'])) {
720
+			$prepared_item->meta_input['_wpi_discount_min_total'] = floatval($request['minimum_amount']);
721 721
 		}
722 722
 
723 723
 		// Maximum amount.
724
-		if ( ! empty( $schema['properties']['maximum_amount'] ) && isset( $request['maximum_amount'] ) ) {
725
-			$prepared_item->meta_input['_wpi_discount_max_total'] = floatval( $request['maximum_amount'] );
724
+		if (!empty($schema['properties']['maximum_amount']) && isset($request['maximum_amount'])) {
725
+			$prepared_item->meta_input['_wpi_discount_max_total'] = floatval($request['maximum_amount']);
726 726
 		}
727 727
 
728 728
 		// Recurring.
729
-		if ( ! empty( $schema['properties']['recurring'] ) && isset( $request['recurring'] ) ) {
730
-			$prepared_item->meta_input['_wpi_discount_is_recurring'] = empty( (int) $request['recurring'] ) ? 0 : 1;
729
+		if (!empty($schema['properties']['recurring']) && isset($request['recurring'])) {
730
+			$prepared_item->meta_input['_wpi_discount_is_recurring'] = empty((int) $request['recurring']) ? 0 : 1;
731 731
 		}
732 732
 
733 733
 		// Maximum uses.
734
-		if ( ! empty( $schema['properties']['max_uses'] ) && isset( $request['max_uses'] ) ) {
735
-			$prepared_item->meta_input['_wpi_discount_max_uses'] = intval( $request['max_uses'] );
734
+		if (!empty($schema['properties']['max_uses']) && isset($request['max_uses'])) {
735
+			$prepared_item->meta_input['_wpi_discount_max_uses'] = intval($request['max_uses']);
736 736
 		}
737 737
 
738 738
 		// Single use.
739
-		if ( ! empty( $schema['properties']['single_use'] ) && isset( $request['single_use'] ) ) {
740
-			$prepared_item->meta_input['_wpi_discount_is_single_use'] = empty( (int) $request['single_use'] ) ? 0 : 1;
739
+		if (!empty($schema['properties']['single_use']) && isset($request['single_use'])) {
740
+			$prepared_item->meta_input['_wpi_discount_is_single_use'] = empty((int) $request['single_use']) ? 0 : 1;
741 741
 		}
742 742
 
743
-		$discount_data = (array) wp_unslash( $prepared_item );
743
+		$discount_data = (array) wp_unslash($prepared_item);
744 744
 
745 745
 		/**
746 746
 		 * Filters an item before it is inserted via the REST API.
@@ -750,7 +750,7 @@  discard block
 block discarded – undo
750 750
 		 * @param array        $discount_data An array of discount data
751 751
 		 * @param WP_REST_Request $request       Request object.
752 752
 		 */
753
-		return apply_filters( "wpinv_rest_pre_insert_discount", $discount_data, $request );
753
+		return apply_filters("wpinv_rest_pre_insert_discount", $discount_data, $request);
754 754
 
755 755
 	}
756 756
 
@@ -763,110 +763,110 @@  discard block
 block discarded – undo
763 763
 	 * @param WP_REST_Request $request Request object.
764 764
 	 * @return WP_REST_Response Response object.
765 765
 	 */
766
-	public function prepare_item_for_response( $discount, $request ) {
766
+	public function prepare_item_for_response($discount, $request) {
767 767
 
768
-		$GLOBALS['post'] = get_post( $discount->ID );
768
+		$GLOBALS['post'] = get_post($discount->ID);
769 769
 
770
-		setup_postdata( $discount->ID );
770
+		setup_postdata($discount->ID);
771 771
 
772 772
 		// Fetch the fields to include in this response.
773
-		$fields = $this->get_fields_for_response( $request );
773
+		$fields = $this->get_fields_for_response($request);
774 774
 
775 775
 		// Base fields for every discount.
776 776
 		$data = array();
777 777
 
778 778
 		// Set up ID.
779
-		if ( rest_is_field_included( 'id', $fields ) ) {
779
+		if (rest_is_field_included('id', $fields)) {
780 780
 			$data['id'] = $discount->ID;
781 781
 		}
782 782
 
783 783
 		// Title.
784
-		if ( rest_is_field_included( 'title', $fields ) ) {
785
-			$data['title'] = get_the_title( $discount->ID );
784
+		if (rest_is_field_included('title', $fields)) {
785
+			$data['title'] = get_the_title($discount->ID);
786 786
 		}
787 787
 
788 788
 		// Code.
789
-		if ( rest_is_field_included( 'code', $fields ) ) {
790
-			$data['code'] = wpinv_get_discount_code( $discount->ID );
789
+		if (rest_is_field_included('code', $fields)) {
790
+			$data['code'] = wpinv_get_discount_code($discount->ID);
791 791
 		}
792 792
 
793 793
 		// Type.
794
-		if ( rest_is_field_included( 'type', $fields ) ) {
795
-			$data['type'] = wpinv_get_discount_type( $discount->ID );
794
+		if (rest_is_field_included('type', $fields)) {
795
+			$data['type'] = wpinv_get_discount_type($discount->ID);
796 796
 		}
797 797
 
798 798
 		// Amount.
799
-		if ( rest_is_field_included( 'amount', $fields ) ) {
800
-			$data['amount'] = wpinv_get_discount_amount( $discount->ID );
799
+		if (rest_is_field_included('amount', $fields)) {
800
+			$data['amount'] = wpinv_get_discount_amount($discount->ID);
801 801
 		}
802 802
 
803 803
 		// Status.
804
-		if ( rest_is_field_included( 'status', $fields ) ) {
805
-			$data['status'] = get_post_status( $discount->ID );
804
+		if (rest_is_field_included('status', $fields)) {
805
+			$data['status'] = get_post_status($discount->ID);
806 806
 		}
807 807
 
808 808
 		// Items.
809
-		if ( rest_is_field_included( 'items', $fields ) ) {
810
-			$data['items'] = wpinv_get_discount_item_reqs( $discount->ID );
809
+		if (rest_is_field_included('items', $fields)) {
810
+			$data['items'] = wpinv_get_discount_item_reqs($discount->ID);
811 811
 		}
812 812
 
813 813
 		// Excluded Items.
814
-		if ( rest_is_field_included( 'exclude_items', $fields ) ) {
815
-			$data['exclude_items'] = wpinv_get_discount_excluded_items( $discount->ID );
814
+		if (rest_is_field_included('exclude_items', $fields)) {
815
+			$data['exclude_items'] = wpinv_get_discount_excluded_items($discount->ID);
816 816
 		}
817 817
 
818 818
 		// Start date.
819
-		if ( rest_is_field_included( 'start_date', $fields ) ) {
820
-			$data['start_date'] = wpinv_get_discount_start_date( $discount->ID );
819
+		if (rest_is_field_included('start_date', $fields)) {
820
+			$data['start_date'] = wpinv_get_discount_start_date($discount->ID);
821 821
 		}
822 822
 
823 823
 		// End date.
824
-		if ( rest_is_field_included( 'end_date', $fields ) ) {
825
-			$data['end_date'] = wpinv_get_discount_expiration( $discount->ID );
824
+		if (rest_is_field_included('end_date', $fields)) {
825
+			$data['end_date'] = wpinv_get_discount_expiration($discount->ID);
826 826
 		}
827 827
 
828 828
 		// Minimum amount.
829
-		if ( rest_is_field_included( 'minimum_amount', $fields ) ) {
830
-			$data['minimum_amount'] = wpinv_get_discount_min_total( $discount->ID );
829
+		if (rest_is_field_included('minimum_amount', $fields)) {
830
+			$data['minimum_amount'] = wpinv_get_discount_min_total($discount->ID);
831 831
 		}
832 832
 
833 833
 		// Maximum amount.
834
-		if ( rest_is_field_included( 'maximum_amount', $fields ) ) {
835
-			$data['maximum_amount'] = wpinv_get_discount_max_total( $discount->ID );
834
+		if (rest_is_field_included('maximum_amount', $fields)) {
835
+			$data['maximum_amount'] = wpinv_get_discount_max_total($discount->ID);
836 836
 		}
837 837
 
838 838
 		// Recurring.
839
-		if ( rest_is_field_included( 'recurring', $fields ) ) {
840
-			$data['recurring'] = wpinv_discount_is_recurring( $discount->ID );
839
+		if (rest_is_field_included('recurring', $fields)) {
840
+			$data['recurring'] = wpinv_discount_is_recurring($discount->ID);
841 841
 		}
842 842
 
843 843
 		// Maximum uses.
844
-		if ( rest_is_field_included( 'max_uses', $fields ) ) {
845
-			$data['max_uses'] = wpinv_get_discount_max_uses( $discount->ID );
844
+		if (rest_is_field_included('max_uses', $fields)) {
845
+			$data['max_uses'] = wpinv_get_discount_max_uses($discount->ID);
846 846
 		}
847 847
 
848 848
 		// Single use.
849
-		if ( rest_is_field_included( 'single_use', $fields ) ) {
850
-			$data['single_use'] = wpinv_discount_is_single_use( $discount->ID );
849
+		if (rest_is_field_included('single_use', $fields)) {
850
+			$data['single_use'] = wpinv_discount_is_single_use($discount->ID);
851 851
 		}
852 852
 
853
-		$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
854
-		$data    = $this->add_additional_fields_to_object( $data, $request );
855
-		$data    = $this->filter_response_by_context( $data, $context );
853
+		$context = !empty($request['context']) ? $request['context'] : 'view';
854
+		$data    = $this->add_additional_fields_to_object($data, $request);
855
+		$data    = $this->filter_response_by_context($data, $context);
856 856
 
857 857
 		// Wrap the data in a response object.
858
-		$response = rest_ensure_response( $data );
858
+		$response = rest_ensure_response($data);
859 859
 
860
-		$links = $this->prepare_links( $discount );
861
-		$response->add_links( $links );
860
+		$links = $this->prepare_links($discount);
861
+		$response->add_links($links);
862 862
 
863
-		if ( ! empty( $links['self']['href'] ) ) {
864
-			$actions = $this->get_available_actions( $discount, $request );
863
+		if (!empty($links['self']['href'])) {
864
+			$actions = $this->get_available_actions($discount, $request);
865 865
 
866 866
 			$self = $links['self']['href'];
867 867
 
868
-			foreach ( $actions as $rel ) {
869
-				$response->add_link( $rel, $self );
868
+			foreach ($actions as $rel) {
869
+				$response->add_link($rel, $self);
870 870
 			}
871 871
 		}
872 872
 
@@ -879,7 +879,7 @@  discard block
 block discarded – undo
879 879
 		 * @param WP_Post    $discount  The discount post object.
880 880
 		 * @param WP_REST_Request  $request  Request object.
881 881
 		 */
882
-		return apply_filters( "wpinv_rest_prepare_discount", $response, $discount, $request );
882
+		return apply_filters("wpinv_rest_prepare_discount", $response, $discount, $request);
883 883
 	}
884 884
 
885 885
 	/**
@@ -892,57 +892,57 @@  discard block
 block discarded – undo
892 892
 	 * @param WP_REST_Request $request Full details about the request.
893 893
 	 * @return array Fields to be included in the response.
894 894
 	 */
895
-	public function get_fields_for_response( $request ) {
895
+	public function get_fields_for_response($request) {
896 896
 		$schema     = $this->get_item_schema();
897
-		$properties = isset( $schema['properties'] ) ? $schema['properties'] : array();
897
+		$properties = isset($schema['properties']) ? $schema['properties'] : array();
898 898
 
899 899
 		$additional_fields = $this->get_additional_fields();
900
-		foreach ( $additional_fields as $field_name => $field_options ) {
900
+		foreach ($additional_fields as $field_name => $field_options) {
901 901
 			// For back-compat, include any field with an empty schema
902 902
 			// because it won't be present in $this->get_item_schema().
903
-			if ( is_null( $field_options['schema'] ) ) {
904
-				$properties[ $field_name ] = $field_options;
903
+			if (is_null($field_options['schema'])) {
904
+				$properties[$field_name] = $field_options;
905 905
 			}
906 906
 		}
907 907
 
908 908
 		// Exclude fields that specify a different context than the request context.
909 909
 		$context = $request['context'];
910
-		if ( $context ) {
911
-			foreach ( $properties as $name => $options ) {
912
-				if ( ! empty( $options['context'] ) && ! in_array( $context, $options['context'], true ) ) {
913
-					unset( $properties[ $name ] );
910
+		if ($context) {
911
+			foreach ($properties as $name => $options) {
912
+				if (!empty($options['context']) && !in_array($context, $options['context'], true)) {
913
+					unset($properties[$name]);
914 914
 				}
915 915
 			}
916 916
 		}
917 917
 
918
-		$fields = array_keys( $properties );
918
+		$fields = array_keys($properties);
919 919
 
920
-		if ( ! isset( $request['_fields'] ) ) {
920
+		if (!isset($request['_fields'])) {
921 921
 			return $fields;
922 922
 		}
923
-		$requested_fields = wpinv_parse_list( $request['_fields'] );
924
-		if ( 0 === count( $requested_fields ) ) {
923
+		$requested_fields = wpinv_parse_list($request['_fields']);
924
+		if (0 === count($requested_fields)) {
925 925
 			return $fields;
926 926
 		}
927 927
 		// Trim off outside whitespace from the comma delimited list.
928
-		$requested_fields = array_map( 'trim', $requested_fields );
928
+		$requested_fields = array_map('trim', $requested_fields);
929 929
 		// Always persist 'id', because it can be needed for add_additional_fields_to_object().
930
-		if ( in_array( 'id', $fields, true ) ) {
930
+		if (in_array('id', $fields, true)) {
931 931
 			$requested_fields[] = 'id';
932 932
 		}
933 933
 		// Return the list of all requested fields which appear in the schema.
934 934
 		return array_reduce(
935 935
 			$requested_fields,
936
-			function( $response_fields, $field ) use ( $fields ) {
937
-				if ( in_array( $field, $fields, true ) ) {
936
+			function($response_fields, $field) use ($fields) {
937
+				if (in_array($field, $fields, true)) {
938 938
 					$response_fields[] = $field;
939 939
 					return $response_fields;
940 940
 				}
941 941
 				// Check for nested fields if $field is not a direct match.
942
-				$nested_fields = explode( '.', $field );
942
+				$nested_fields = explode('.', $field);
943 943
 				// A nested field is included so long as its top-level property is
944 944
 				// present in the schema.
945
-				if ( in_array( $nested_fields[0], $fields, true ) ) {
945
+				if (in_array($nested_fields[0], $fields, true)) {
946 946
 					$response_fields[] = $field;
947 947
 				}
948 948
 				return $response_fields;
@@ -961,8 +961,8 @@  discard block
 block discarded – undo
961 961
 	public function get_item_schema() {
962 962
 
963 963
 		// Maybe retrieve the schema from cache.
964
-		if (  empty( $this->schema ) ) {
965
-			return $this->add_additional_fields_schema( $this->schema );
964
+		if (empty($this->schema)) {
965
+			return $this->add_additional_fields_schema($this->schema);
966 966
 		}
967 967
 
968 968
 		$schema = array(
@@ -974,99 +974,99 @@  discard block
 block discarded – undo
974 974
 			'properties' 		  => array(
975 975
 
976 976
 				'id'           => array(
977
-					'description' => __( 'Unique identifier for the discount.', 'invoicing' ),
977
+					'description' => __('Unique identifier for the discount.', 'invoicing'),
978 978
 					'type'        => 'integer',
979
-					'context'     => array( 'view', 'edit', 'embed' ),
979
+					'context'     => array('view', 'edit', 'embed'),
980 980
 					'readonly'    => true,
981 981
 				),
982 982
 
983 983
 				'title'			  => array(
984
-					'description' => __( 'The title for the discount.', 'invoicing' ),
984
+					'description' => __('The title for the discount.', 'invoicing'),
985 985
 					'type'        => 'string',
986
-					'context'     => array( 'view', 'edit' ),
986
+					'context'     => array('view', 'edit'),
987 987
 				),
988 988
 
989 989
 				'code'        => array(
990
-					'description' => __( 'The discount code.', 'invoicing' ),
990
+					'description' => __('The discount code.', 'invoicing'),
991 991
 					'type'        => 'string',
992
-					'context'     => array( 'view', 'edit', 'embed' ),
992
+					'context'     => array('view', 'edit', 'embed'),
993 993
 					'required'	  => true,
994 994
 				),
995 995
 
996 996
 				'type'        => array(
997
-					'description' => __( 'The type of discount.', 'invoicing' ),
997
+					'description' => __('The type of discount.', 'invoicing'),
998 998
 					'type'        => 'string',
999
-					'enum'        => array_keys( wpinv_get_discount_types() ),
1000
-					'context'     => array( 'view', 'edit', 'embed' ),
999
+					'enum'        => array_keys(wpinv_get_discount_types()),
1000
+					'context'     => array('view', 'edit', 'embed'),
1001 1001
 					'default'	  => 'percentage',
1002 1002
 				),
1003 1003
 
1004 1004
 				'amount'        => array(
1005
-					'description' => __( 'The discount value.', 'invoicing' ),
1005
+					'description' => __('The discount value.', 'invoicing'),
1006 1006
 					'type'        => 'number',
1007
-					'context'     => array( 'view', 'edit', 'embed' ),
1007
+					'context'     => array('view', 'edit', 'embed'),
1008 1008
 					'required'	  => true,
1009 1009
 				),
1010 1010
 
1011 1011
 				'status'       => array(
1012
-					'description' => __( 'A named status for the discount.', 'invoicing' ),
1012
+					'description' => __('A named status for the discount.', 'invoicing'),
1013 1013
 					'type'        => 'string',
1014
-					'enum'        => array_keys( get_post_stati( array( 'internal' => false ) ) ),
1015
-					'context'     => array( 'view', 'edit' ),
1014
+					'enum'        => array_keys(get_post_stati(array('internal' => false))),
1015
+					'context'     => array('view', 'edit'),
1016 1016
 				),
1017 1017
 
1018 1018
 				'items'       => array(
1019
-					'description' => __( 'Items which need to be in the cart to use this discount or, for "Item Discounts", which items are discounted. If left blank, this discount will be used on any item.', 'invoicing' ),
1019
+					'description' => __('Items which need to be in the cart to use this discount or, for "Item Discounts", which items are discounted. If left blank, this discount will be used on any item.', 'invoicing'),
1020 1020
 					'type'        => 'array',
1021
-					'context'     => array( 'view', 'edit' ),
1021
+					'context'     => array('view', 'edit'),
1022 1022
 				),
1023 1023
 
1024 1024
 				'exclude_items'   => array(
1025
-					'description' => __( 'Items which are NOT allowed to use this discount.', 'invoicing' ),
1025
+					'description' => __('Items which are NOT allowed to use this discount.', 'invoicing'),
1026 1026
 					'type'        => 'array',
1027
-					'context'     => array( 'view', 'edit' ),
1027
+					'context'     => array('view', 'edit'),
1028 1028
 				),
1029 1029
 
1030 1030
 				'start_date'       => array(
1031
-					'description' => __( 'The start date for the discount in the format of yyyy-mm-dd hh:mm:ss  . If provided, the discount can only be used after or on this date.', 'invoicing' ),
1031
+					'description' => __('The start date for the discount in the format of yyyy-mm-dd hh:mm:ss  . If provided, the discount can only be used after or on this date.', 'invoicing'),
1032 1032
 					'type'        => 'string',
1033
-					'context'     => array( 'view', 'edit' ),
1033
+					'context'     => array('view', 'edit'),
1034 1034
 				),
1035 1035
 
1036 1036
 				'end_date'        => array(
1037
-					'description' => __( 'The expiration date for the discount.', 'invoicing' ),
1037
+					'description' => __('The expiration date for the discount.', 'invoicing'),
1038 1038
 					'type'        => 'string',
1039
-					'context'     => array( 'view', 'edit', 'embed' ),
1039
+					'context'     => array('view', 'edit', 'embed'),
1040 1040
 				),
1041 1041
 				
1042 1042
 				'minimum_amount'       => array(
1043
-					'description' => __( 'Minimum amount needed to use this invoice.', 'invoicing' ),
1043
+					'description' => __('Minimum amount needed to use this invoice.', 'invoicing'),
1044 1044
 					'type'        => 'number',
1045
-					'context'     => array( 'view', 'edit', 'embed' ),
1045
+					'context'     => array('view', 'edit', 'embed'),
1046 1046
 				),
1047 1047
 
1048 1048
 				'maximum_amount'       => array(
1049
-					'description' => __( 'Maximum amount needed to use this invoice.', 'invoicing' ),
1049
+					'description' => __('Maximum amount needed to use this invoice.', 'invoicing'),
1050 1050
 					'type'        => 'number',
1051
-					'context'     => array( 'view', 'edit', 'embed' ),
1051
+					'context'     => array('view', 'edit', 'embed'),
1052 1052
 				),
1053 1053
 
1054 1054
 				'recurring'       => array(
1055
-					'description' => __( 'Whether the discount is applied to all recurring payments or only the first recurring payment.', 'invoicing' ),
1055
+					'description' => __('Whether the discount is applied to all recurring payments or only the first recurring payment.', 'invoicing'),
1056 1056
 					'type'        => 'integer',
1057
-					'context'     => array( 'view', 'edit', 'embed' ),
1057
+					'context'     => array('view', 'edit', 'embed'),
1058 1058
 				),
1059 1059
 
1060 1060
 				'max_uses'        => array(
1061
-					'description' => __( 'The maximum number of times this discount code can be used.', 'invoicing' ),
1061
+					'description' => __('The maximum number of times this discount code can be used.', 'invoicing'),
1062 1062
 					'type'        => 'number',
1063
-					'context'     => array( 'view', 'edit', 'embed' ),
1063
+					'context'     => array('view', 'edit', 'embed'),
1064 1064
 				),
1065 1065
 
1066 1066
 				'single_use'       => array(
1067
-					'description' => __( 'Whether or not this discount can only be used once per user.', 'invoicing' ),
1067
+					'description' => __('Whether or not this discount can only be used once per user.', 'invoicing'),
1068 1068
 					'type'        => 'integer',
1069
-					'context'     => array( 'view', 'edit', 'embed' ),
1069
+					'context'     => array('view', 'edit', 'embed'),
1070 1070
 				)
1071 1071
 
1072 1072
 			),
@@ -1084,12 +1084,12 @@  discard block
 block discarded – undo
1084 1084
 		 *
1085 1085
 		 * @param array   $schema    The discount schema.
1086 1086
 		 */
1087
-        $schema = apply_filters( "wpinv_rest_discount_schema", $schema );
1087
+        $schema = apply_filters("wpinv_rest_discount_schema", $schema);
1088 1088
 
1089 1089
 		//  Cache the discount schema.
1090 1090
 		$this->schema = $schema;
1091 1091
 		
1092
-		return $this->add_additional_fields_schema( $this->schema );
1092
+		return $this->add_additional_fields_schema($this->schema);
1093 1093
 	}
1094 1094
 
1095 1095
 	/**
@@ -1101,20 +1101,20 @@  discard block
 block discarded – undo
1101 1101
 	 */
1102 1102
 	protected function get_schema_links() {
1103 1103
 
1104
-		$href = rest_url( "{$this->namespace}/{$this->rest_base}/{id}" );
1104
+		$href = rest_url("{$this->namespace}/{$this->rest_base}/{id}");
1105 1105
 
1106 1106
 		$links = array();
1107 1107
 
1108 1108
 		$links[] = array(
1109 1109
 			'rel'          => 'https://api.w.org/action-publish',
1110
-			'title'        => __( 'The current user can publish this discount.', 'invoicing' ),
1110
+			'title'        => __('The current user can publish this discount.', 'invoicing'),
1111 1111
 			'href'         => $href,
1112 1112
 			'targetSchema' => array(
1113 1113
 				'type'       => 'object',
1114 1114
 				'properties' => array(
1115 1115
 					'status' => array(
1116 1116
 						'type' => 'string',
1117
-						'enum' => array( 'publish', 'future' ),
1117
+						'enum' => array('publish', 'future'),
1118 1118
 					),
1119 1119
 				),
1120 1120
 			),
@@ -1131,18 +1131,18 @@  discard block
 block discarded – undo
1131 1131
 	 * @param WP_Post $discount Post Object.
1132 1132
 	 * @return array Links for the given discount.
1133 1133
 	 */
1134
-	protected function prepare_links( $discount ) {
1134
+	protected function prepare_links($discount) {
1135 1135
 
1136 1136
 		// Prepare the base REST API endpoint for discounts.
1137
-		$base = sprintf( '%s/%s', $this->namespace, $this->rest_base );
1137
+		$base = sprintf('%s/%s', $this->namespace, $this->rest_base);
1138 1138
 
1139 1139
 		// Entity meta.
1140 1140
 		$links = array(
1141 1141
 			'self'       => array(
1142
-				'href' => rest_url( trailingslashit( $base ) . $discount->ID ),
1142
+				'href' => rest_url(trailingslashit($base) . $discount->ID),
1143 1143
 			),
1144 1144
 			'collection' => array(
1145
-				'href' => rest_url( $base ),
1145
+				'href' => rest_url($base),
1146 1146
 			),
1147 1147
 		);
1148 1148
 
@@ -1155,7 +1155,7 @@  discard block
 block discarded – undo
1155 1155
 		 *
1156 1156
 		 * @param array   $links    Rest links.
1157 1157
 		 */
1158
-		return apply_filters( "wpinv_rest_discount_links", $links );
1158
+		return apply_filters("wpinv_rest_discount_links", $links);
1159 1159
 
1160 1160
 	}
1161 1161
 
@@ -1168,19 +1168,19 @@  discard block
 block discarded – undo
1168 1168
 	 * @param WP_REST_Request $request Request object.
1169 1169
 	 * @return array List of link relations.
1170 1170
 	 */
1171
-	protected function get_available_actions( $discount, $request ) {
1171
+	protected function get_available_actions($discount, $request) {
1172 1172
 
1173
-		if ( 'edit' !== $request['context'] ) {
1173
+		if ('edit' !== $request['context']) {
1174 1174
 			return array();
1175 1175
 		}
1176 1176
 
1177 1177
 		$rels = array();
1178 1178
 
1179 1179
 		// Retrieve the post type object.
1180
-		$post_type = get_post_type_object( $discount->post_type );
1180
+		$post_type = get_post_type_object($discount->post_type);
1181 1181
 
1182 1182
 		// Mark discount as published.
1183
-		if ( current_user_can( $post_type->cap->publish_posts ) ) {
1183
+		if (current_user_can($post_type->cap->publish_posts)) {
1184 1184
 			$rels[] = 'https://api.w.org/action-publish';
1185 1185
 		}
1186 1186
 
@@ -1193,7 +1193,7 @@  discard block
 block discarded – undo
1193 1193
 		 *
1194 1194
 		 * @param array   $rels    Available link relations.
1195 1195
 		 */
1196
-		return apply_filters( "wpinv_rest_discount_link_relations", $rels );
1196
+		return apply_filters("wpinv_rest_discount_link_relations", $rels);
1197 1197
 	}
1198 1198
 
1199 1199
 	/**
@@ -1205,7 +1205,7 @@  discard block
 block discarded – undo
1205 1205
 	 * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
1206 1206
 	 */
1207 1207
 	public function get_discount_types() {
1208
-		return rest_ensure_response( wpinv_get_discount_types() );
1208
+		return rest_ensure_response(wpinv_get_discount_types());
1209 1209
 	}
1210 1210
     
1211 1211
 }
1212 1212
\ No newline at end of file
Please login to merge, or discard this patch.
includes/class-wpinv-invoice.php 2 patches
Indentation   +2063 added lines, -2063 removed lines patch added patch discarded remove patch
@@ -11,30 +11,30 @@  discard block
 block discarded – undo
11 11
 class WPInv_Invoice extends GetPaid_Data {
12 12
 
13 13
     /**
14
-	 * Which data store to load.
15
-	 *
16
-	 * @var string
17
-	 */
14
+     * Which data store to load.
15
+     *
16
+     * @var string
17
+     */
18 18
     protected $data_store_name = 'invoice';
19 19
 
20 20
     /**
21
-	 * This is the name of this object type.
22
-	 *
23
-	 * @var string
24
-	 */
21
+     * This is the name of this object type.
22
+     *
23
+     * @var string
24
+     */
25 25
     protected $object_type = 'invoice';
26 26
 
27 27
     /**
28
-	 * Item Data array. This is the core item data exposed in APIs.
29
-	 *
30
-	 * @since 1.0.19
31
-	 * @var array
32
-	 */
33
-	protected $data = array(
34
-		'parent_id'            => 0,
35
-		'status'               => 'wpi-pending',
36
-		'version'              => '',
37
-		'date_created'         => null,
28
+     * Item Data array. This is the core item data exposed in APIs.
29
+     *
30
+     * @since 1.0.19
31
+     * @var array
32
+     */
33
+    protected $data = array(
34
+        'parent_id'            => 0,
35
+        'status'               => 'wpi-pending',
36
+        'version'              => '',
37
+        'date_created'         => null,
38 38
         'date_modified'        => null,
39 39
         'due_date'             => null,
40 40
         'completed_date'       => null,
@@ -76,20 +76,20 @@  discard block
 block discarded – undo
76 76
         'transaction_id'       => '',
77 77
         'currency'             => '',
78 78
         'disable_taxes'        => 0,
79
-		'subscription_id'      => null,
80
-		'is_viewed'            => false,
81
-		'email_cc'             => '',
82
-		'template'             => 'quantity', // hours, amount only
79
+        'subscription_id'      => null,
80
+        'is_viewed'            => false,
81
+        'email_cc'             => '',
82
+        'template'             => 'quantity', // hours, amount only
83 83
     );
84 84
 
85 85
     /**
86
-	 * Stores meta in cache for future reads.
87
-	 *
88
-	 * A group must be set to to enable caching.
89
-	 *
90
-	 * @var string
91
-	 */
92
-	protected $cache_group = 'getpaid_invoices';
86
+     * Stores meta in cache for future reads.
87
+     *
88
+     * A group must be set to to enable caching.
89
+     *
90
+     * @var string
91
+     */
92
+    protected $cache_group = 'getpaid_invoices';
93 93
 
94 94
     /**
95 95
      * Stores a reference to the original WP_Post object
@@ -103,97 +103,97 @@  discard block
 block discarded – undo
103 103
      *
104 104
      * @var int
105 105
      */
106
-	protected $recurring_item = null;
106
+    protected $recurring_item = null;
107 107
 
108
-	/**
108
+    /**
109 109
      * Stores an array of item totals.
110
-	 *
111
-	 * e.g $totals['discount'] = array(
112
-	 * 		'initial'   => 10,
113
-	 * 		'recurring' => 10,
114
-	 * )
110
+     *
111
+     * e.g $totals['discount'] = array(
112
+     * 		'initial'   => 10,
113
+     * 		'recurring' => 10,
114
+     * )
115 115
      *
116 116
      * @var array
117 117
      */
118
-	protected $totals = array();
118
+    protected $totals = array();
119 119
 
120
-	/**
121
-	 * Stores the status transition information.
122
-	 *
123
-	 * @since 1.0.19
124
-	 * @var bool
125
-	 */
126
-	protected $status_transition = false;
120
+    /**
121
+     * Stores the status transition information.
122
+     *
123
+     * @since 1.0.19
124
+     * @var bool
125
+     */
126
+    protected $status_transition = false;
127 127
 
128 128
     /**
129
-	 * Get the invoice if ID is passed, otherwise the invoice is new and empty.
130
-	 *
131
-	 * @param  int/string|object|WPInv_Invoice|WPInv_Legacy_Invoice|WP_Post $invoice Invoice id, key, number or object to read.
132
-	 */
129
+     * Get the invoice if ID is passed, otherwise the invoice is new and empty.
130
+     *
131
+     * @param  int/string|object|WPInv_Invoice|WPInv_Legacy_Invoice|WP_Post $invoice Invoice id, key, number or object to read.
132
+     */
133 133
     public function __construct( $invoice = false ) {
134 134
 
135 135
         parent::__construct( $invoice );
136 136
 
137
-		if ( is_numeric( $invoice ) && getpaid_is_invoice_post_type( get_post_type( $invoice ) ) ) {
138
-			$this->set_id( $invoice );
139
-		} elseif ( $invoice instanceof self ) {
140
-			$this->set_id( $invoice->get_id() );
141
-		} elseif ( ! empty( $invoice->ID ) ) {
142
-			$this->set_id( $invoice->ID );
143
-		} elseif ( is_array( $invoice ) ) {
144
-			$this->set_props( $invoice );
145
-
146
-			if ( isset( $invoice['ID'] ) ) {
147
-				$this->set_id( $invoice['ID'] );
148
-			}
149
-
150
-		} elseif ( is_scalar( $invoice ) && $invoice_id = self::get_discount_id_by_code( $invoice, 'key' ) ) {
151
-			$this->set_id( $invoice_id );
152
-		} elseif ( is_scalar( $invoice ) && $invoice_id = self::get_discount_id_by_code( $invoice, 'number' ) ) {
153
-			$this->set_id( $invoice_id );
154
-		} else {
155
-			$this->set_object_read( true );
156
-		}
137
+        if ( is_numeric( $invoice ) && getpaid_is_invoice_post_type( get_post_type( $invoice ) ) ) {
138
+            $this->set_id( $invoice );
139
+        } elseif ( $invoice instanceof self ) {
140
+            $this->set_id( $invoice->get_id() );
141
+        } elseif ( ! empty( $invoice->ID ) ) {
142
+            $this->set_id( $invoice->ID );
143
+        } elseif ( is_array( $invoice ) ) {
144
+            $this->set_props( $invoice );
145
+
146
+            if ( isset( $invoice['ID'] ) ) {
147
+                $this->set_id( $invoice['ID'] );
148
+            }
149
+
150
+        } elseif ( is_scalar( $invoice ) && $invoice_id = self::get_discount_id_by_code( $invoice, 'key' ) ) {
151
+            $this->set_id( $invoice_id );
152
+        } elseif ( is_scalar( $invoice ) && $invoice_id = self::get_discount_id_by_code( $invoice, 'number' ) ) {
153
+            $this->set_id( $invoice_id );
154
+        } else {
155
+            $this->set_object_read( true );
156
+        }
157 157
 
158 158
         // Load the datastore.
159
-		$this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
159
+        $this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
160 160
 
161
-		if ( $this->get_id() > 0 ) {
161
+        if ( $this->get_id() > 0 ) {
162 162
             $this->post = get_post( $this->get_id() );
163 163
             $this->ID   = $this->get_id();
164
-			$this->data_store->read( $this );
164
+            $this->data_store->read( $this );
165 165
         }
166 166
 
167 167
     }
168 168
 
169 169
     /**
170
-	 * Given a discount code, it returns a discount id.
171
-	 *
172
-	 *
173
-	 * @static
174
-	 * @param string $discount_code
175
-	 * @since 1.0.15
176
-	 * @return int
177
-	 */
178
-	public static function get_discount_id_by_code( $invoice_key_or_number, $field = 'key' ) {
170
+     * Given a discount code, it returns a discount id.
171
+     *
172
+     *
173
+     * @static
174
+     * @param string $discount_code
175
+     * @since 1.0.15
176
+     * @return int
177
+     */
178
+    public static function get_discount_id_by_code( $invoice_key_or_number, $field = 'key' ) {
179 179
         global $wpdb;
180 180
 
181
-		// Trim the code.
181
+        // Trim the code.
182 182
         $key = trim( $invoice_key_or_number );
183 183
 
184 184
         // Valid fields.
185 185
         $fields = array( 'key', 'number' );
186 186
 
187
-		// Ensure a value has been passed.
188
-		if ( empty( $key ) || ! in_array( $field, $fields ) ) {
189
-			return 0;
190
-		}
187
+        // Ensure a value has been passed.
188
+        if ( empty( $key ) || ! in_array( $field, $fields ) ) {
189
+            return 0;
190
+        }
191 191
 
192
-		// Maybe retrieve from the cache.
193
-		$invoice_id   = wp_cache_get( $key, 'getpaid_invoice_keys_' . $field );
194
-		if ( ! empty( $invoice_id ) ) {
195
-			return $invoice_id;
196
-		}
192
+        // Maybe retrieve from the cache.
193
+        $invoice_id   = wp_cache_get( $key, 'getpaid_invoice_keys_' . $field );
194
+        if ( ! empty( $invoice_id ) ) {
195
+            return $invoice_id;
196
+        }
197 197
 
198 198
         // Fetch from the db.
199 199
         $table       = $wpdb->prefix . 'getpaid_invoices';
@@ -201,14 +201,14 @@  discard block
 block discarded – undo
201 201
             $wpdb->prepare( "SELECT `post_id` FROM $table WHERE $field=%s LIMIT 1", $key )
202 202
         );
203 203
 
204
-		if ( empty( $invoice_id ) ) {
205
-			return 0;
206
-		}
204
+        if ( empty( $invoice_id ) ) {
205
+            return 0;
206
+        }
207 207
 
208
-		// Update the cache with our data
209
-		wp_cache_set( $key, $invoice_id, 'getpaid_invoice_keys_' . $field );
208
+        // Update the cache with our data
209
+        wp_cache_set( $key, $invoice_id, 'getpaid_invoice_keys_' . $field );
210 210
 
211
-		return $invoice_id;
211
+        return $invoice_id;
212 212
     }
213 213
 
214 214
     /**
@@ -234,53 +234,53 @@  discard block
 block discarded – undo
234 234
     */
235 235
 
236 236
     /**
237
-	 * Get parent invoice ID.
238
-	 *
239
-	 * @since 1.0.19
240
-	 * @param  string $context View or edit context.
241
-	 * @return int
242
-	 */
243
-	public function get_parent_id( $context = 'view' ) {
244
-		return (int) $this->get_prop( 'parent_id', $context );
237
+     * Get parent invoice ID.
238
+     *
239
+     * @since 1.0.19
240
+     * @param  string $context View or edit context.
241
+     * @return int
242
+     */
243
+    public function get_parent_id( $context = 'view' ) {
244
+        return (int) $this->get_prop( 'parent_id', $context );
245 245
     }
246 246
 
247 247
     /**
248
-	 * Get parent invoice.
249
-	 *
250
-	 * @since 1.0.19
251
-	 * @return WPInv_Invoice
252
-	 */
248
+     * Get parent invoice.
249
+     *
250
+     * @since 1.0.19
251
+     * @return WPInv_Invoice
252
+     */
253 253
     public function get_parent_payment() {
254 254
         return new WPInv_Invoice( $this->get_parent_id() );
255 255
     }
256 256
 
257 257
     /**
258
-	 * Alias for self::get_parent_payment().
259
-	 *
260
-	 * @since 1.0.19
261
-	 * @return WPInv_Invoice
262
-	 */
258
+     * Alias for self::get_parent_payment().
259
+     *
260
+     * @since 1.0.19
261
+     * @return WPInv_Invoice
262
+     */
263 263
     public function get_parent() {
264 264
         return $this->get_parent_payment();
265 265
     }
266 266
 
267 267
     /**
268
-	 * Get invoice status.
269
-	 *
270
-	 * @since 1.0.19
271
-	 * @param  string $context View or edit context.
272
-	 * @return string
273
-	 */
274
-	public function get_status( $context = 'view' ) {
275
-		return $this->get_prop( 'status', $context );
268
+     * Get invoice status.
269
+     *
270
+     * @since 1.0.19
271
+     * @param  string $context View or edit context.
272
+     * @return string
273
+     */
274
+    public function get_status( $context = 'view' ) {
275
+        return $this->get_prop( 'status', $context );
276 276
     }
277 277
 
278 278
     /**
279
-	 * Get invoice status nice name.
280
-	 *
281
-	 * @since 1.0.19
282
-	 * @return string
283
-	 */
279
+     * Get invoice status nice name.
280
+     *
281
+     * @since 1.0.19
282
+     * @return string
283
+     */
284 284
     public function get_status_nicename() {
285 285
         $statuses = wpinv_get_invoice_statuses( true, true, $this );
286 286
 
@@ -294,20 +294,20 @@  discard block
 block discarded – undo
294 294
     }
295 295
 
296 296
     /**
297
-	 * Get plugin version when the invoice was created.
298
-	 *
299
-	 * @since 1.0.19
300
-	 * @param  string $context View or edit context.
301
-	 * @return string
302
-	 */
303
-	public function get_version( $context = 'view' ) {
304
-		return $this->get_prop( 'version', $context );
305
-	}
297
+     * Get plugin version when the invoice was created.
298
+     *
299
+     * @since 1.0.19
300
+     * @param  string $context View or edit context.
301
+     * @return string
302
+     */
303
+    public function get_version( $context = 'view' ) {
304
+        return $this->get_prop( 'version', $context );
305
+    }
306 306
 
307
-	/**
308
-	 * @deprecated
309
-	 */
310
-	public function get_invoice_date( $formatted = true ) {
307
+    /**
308
+     * @deprecated
309
+     */
310
+    public function get_invoice_date( $formatted = true ) {
311 311
         $date_completed = $this->get_date_completed();
312 312
         $invoice_date   = $date_completed != '0000-00-00 00:00:00' ? $date_completed : '';
313 313
 
@@ -324,187 +324,187 @@  discard block
 block discarded – undo
324 324
     }
325 325
 
326 326
     /**
327
-	 * Get date when the invoice was created.
328
-	 *
329
-	 * @since 1.0.19
330
-	 * @param  string $context View or edit context.
331
-	 * @return string
332
-	 */
333
-	public function get_date_created( $context = 'view' ) {
334
-		return $this->get_prop( 'date_created', $context );
335
-	}
327
+     * Get date when the invoice was created.
328
+     *
329
+     * @since 1.0.19
330
+     * @param  string $context View or edit context.
331
+     * @return string
332
+     */
333
+    public function get_date_created( $context = 'view' ) {
334
+        return $this->get_prop( 'date_created', $context );
335
+    }
336 336
 	
337
-	/**
338
-	 * Alias for self::get_date_created().
339
-	 *
340
-	 * @since 1.0.19
341
-	 * @param  string $context View or edit context.
342
-	 * @return string
343
-	 */
344
-	public function get_created_date( $context = 'view' ) {
345
-		return $this->get_date_created( $context );
346
-    }
347
-
348
-    /**
349
-	 * Get GMT date when the invoice was created.
350
-	 *
351
-	 * @since 1.0.19
352
-	 * @param  string $context View or edit context.
353
-	 * @return string
354
-	 */
355
-	public function get_date_created_gmt( $context = 'view' ) {
337
+    /**
338
+     * Alias for self::get_date_created().
339
+     *
340
+     * @since 1.0.19
341
+     * @param  string $context View or edit context.
342
+     * @return string
343
+     */
344
+    public function get_created_date( $context = 'view' ) {
345
+        return $this->get_date_created( $context );
346
+    }
347
+
348
+    /**
349
+     * Get GMT date when the invoice was created.
350
+     *
351
+     * @since 1.0.19
352
+     * @param  string $context View or edit context.
353
+     * @return string
354
+     */
355
+    public function get_date_created_gmt( $context = 'view' ) {
356 356
         $date = $this->get_date_created( $context );
357 357
 
358 358
         if ( $date ) {
359 359
             $date = get_gmt_from_date( $date );
360 360
         }
361
-		return $date;
361
+        return $date;
362 362
     }
363 363
 
364 364
     /**
365
-	 * Get date when the invoice was last modified.
366
-	 *
367
-	 * @since 1.0.19
368
-	 * @param  string $context View or edit context.
369
-	 * @return string
370
-	 */
371
-	public function get_date_modified( $context = 'view' ) {
372
-		return $this->get_prop( 'date_modified', $context );
373
-	}
365
+     * Get date when the invoice was last modified.
366
+     *
367
+     * @since 1.0.19
368
+     * @param  string $context View or edit context.
369
+     * @return string
370
+     */
371
+    public function get_date_modified( $context = 'view' ) {
372
+        return $this->get_prop( 'date_modified', $context );
373
+    }
374 374
 
375
-	/**
376
-	 * Alias for self::get_date_modified().
377
-	 *
378
-	 * @since 1.0.19
379
-	 * @param  string $context View or edit context.
380
-	 * @return string
381
-	 */
382
-	public function get_modified_date( $context = 'view' ) {
383
-		return $this->get_date_modified( $context );
375
+    /**
376
+     * Alias for self::get_date_modified().
377
+     *
378
+     * @since 1.0.19
379
+     * @param  string $context View or edit context.
380
+     * @return string
381
+     */
382
+    public function get_modified_date( $context = 'view' ) {
383
+        return $this->get_date_modified( $context );
384 384
     }
385 385
 
386 386
     /**
387
-	 * Get GMT date when the invoice was last modified.
388
-	 *
389
-	 * @since 1.0.19
390
-	 * @param  string $context View or edit context.
391
-	 * @return string
392
-	 */
393
-	public function get_date_modified_gmt( $context = 'view' ) {
387
+     * Get GMT date when the invoice was last modified.
388
+     *
389
+     * @since 1.0.19
390
+     * @param  string $context View or edit context.
391
+     * @return string
392
+     */
393
+    public function get_date_modified_gmt( $context = 'view' ) {
394 394
         $date = $this->get_date_modified( $context );
395 395
 
396 396
         if ( $date ) {
397 397
             $date = get_gmt_from_date( $date );
398 398
         }
399
-		return $date;
399
+        return $date;
400 400
     }
401 401
 
402 402
     /**
403
-	 * Get the invoice due date.
404
-	 *
405
-	 * @since 1.0.19
406
-	 * @param  string $context View or edit context.
407
-	 * @return string
408
-	 */
409
-	public function get_due_date( $context = 'view' ) {
410
-		return $this->get_prop( 'due_date', $context );
403
+     * Get the invoice due date.
404
+     *
405
+     * @since 1.0.19
406
+     * @param  string $context View or edit context.
407
+     * @return string
408
+     */
409
+    public function get_due_date( $context = 'view' ) {
410
+        return $this->get_prop( 'due_date', $context );
411 411
     }
412 412
 
413 413
     /**
414
-	 * Alias for self::get_due_date().
415
-	 *
416
-	 * @since 1.0.19
417
-	 * @param  string $context View or edit context.
418
-	 * @return string
419
-	 */
420
-	public function get_date_due( $context = 'view' ) {
421
-		return $this->get_due_date( $context );
414
+     * Alias for self::get_due_date().
415
+     *
416
+     * @since 1.0.19
417
+     * @param  string $context View or edit context.
418
+     * @return string
419
+     */
420
+    public function get_date_due( $context = 'view' ) {
421
+        return $this->get_due_date( $context );
422 422
     }
423 423
 
424 424
     /**
425
-	 * Get the invoice GMT due date.
426
-	 *
427
-	 * @since 1.0.19
428
-	 * @param  string $context View or edit context.
429
-	 * @return string
430
-	 */
431
-	public function get_due_date_gmt( $context = 'view' ) {
425
+     * Get the invoice GMT due date.
426
+     *
427
+     * @since 1.0.19
428
+     * @param  string $context View or edit context.
429
+     * @return string
430
+     */
431
+    public function get_due_date_gmt( $context = 'view' ) {
432 432
         $date = $this->get_due_date( $context );
433 433
 
434 434
         if ( $date ) {
435 435
             $date = get_gmt_from_date( $date );
436 436
         }
437
-		return $date;
437
+        return $date;
438 438
     }
439 439
 
440 440
     /**
441
-	 * Alias for self::get_due_date_gmt().
442
-	 *
443
-	 * @since 1.0.19
444
-	 * @param  string $context View or edit context.
445
-	 * @return string
446
-	 */
447
-	public function get_gmt_date_due( $context = 'view' ) {
448
-		return $this->get_due_date_gmt( $context );
441
+     * Alias for self::get_due_date_gmt().
442
+     *
443
+     * @since 1.0.19
444
+     * @param  string $context View or edit context.
445
+     * @return string
446
+     */
447
+    public function get_gmt_date_due( $context = 'view' ) {
448
+        return $this->get_due_date_gmt( $context );
449 449
     }
450 450
 
451 451
     /**
452
-	 * Get date when the invoice was completed.
453
-	 *
454
-	 * @since 1.0.19
455
-	 * @param  string $context View or edit context.
456
-	 * @return string
457
-	 */
458
-	public function get_completed_date( $context = 'view' ) {
459
-		return $this->get_prop( 'completed_date', $context );
452
+     * Get date when the invoice was completed.
453
+     *
454
+     * @since 1.0.19
455
+     * @param  string $context View or edit context.
456
+     * @return string
457
+     */
458
+    public function get_completed_date( $context = 'view' ) {
459
+        return $this->get_prop( 'completed_date', $context );
460 460
     }
461 461
 
462 462
     /**
463
-	 * Alias for self::get_completed_date().
464
-	 *
465
-	 * @since 1.0.19
466
-	 * @param  string $context View or edit context.
467
-	 * @return string
468
-	 */
469
-	public function get_date_completed( $context = 'view' ) {
470
-		return $this->get_completed_date( $context );
463
+     * Alias for self::get_completed_date().
464
+     *
465
+     * @since 1.0.19
466
+     * @param  string $context View or edit context.
467
+     * @return string
468
+     */
469
+    public function get_date_completed( $context = 'view' ) {
470
+        return $this->get_completed_date( $context );
471 471
     }
472 472
 
473 473
     /**
474
-	 * Get GMT date when the invoice was was completed.
475
-	 *
476
-	 * @since 1.0.19
477
-	 * @param  string $context View or edit context.
478
-	 * @return string
479
-	 */
480
-	public function get_completed_date_gmt( $context = 'view' ) {
474
+     * Get GMT date when the invoice was was completed.
475
+     *
476
+     * @since 1.0.19
477
+     * @param  string $context View or edit context.
478
+     * @return string
479
+     */
480
+    public function get_completed_date_gmt( $context = 'view' ) {
481 481
         $date = $this->get_completed_date( $context );
482 482
 
483 483
         if ( $date ) {
484 484
             $date = get_gmt_from_date( $date );
485 485
         }
486
-		return $date;
486
+        return $date;
487 487
     }
488 488
 
489 489
     /**
490
-	 * Alias for self::get_completed_date_gmt().
491
-	 *
492
-	 * @since 1.0.19
493
-	 * @param  string $context View or edit context.
494
-	 * @return string
495
-	 */
496
-	public function get_gmt_completed_date( $context = 'view' ) {
497
-		return $this->get_completed_date_gmt( $context );
490
+     * Alias for self::get_completed_date_gmt().
491
+     *
492
+     * @since 1.0.19
493
+     * @param  string $context View or edit context.
494
+     * @return string
495
+     */
496
+    public function get_gmt_completed_date( $context = 'view' ) {
497
+        return $this->get_completed_date_gmt( $context );
498 498
     }
499 499
 
500 500
     /**
501
-	 * Get the invoice number.
502
-	 *
503
-	 * @since 1.0.19
504
-	 * @param  string $context View or edit context.
505
-	 * @return string
506
-	 */
507
-	public function get_number( $context = 'view' ) {
501
+     * Get the invoice number.
502
+     *
503
+     * @since 1.0.19
504
+     * @param  string $context View or edit context.
505
+     * @return string
506
+     */
507
+    public function get_number( $context = 'view' ) {
508 508
         $number = $this->get_prop( 'number', $context );
509 509
 
510 510
         if ( empty( $number ) ) {
@@ -512,17 +512,17 @@  discard block
 block discarded – undo
512 512
             $this->set_number( $number );
513 513
         }
514 514
 
515
-		return $number;
515
+        return $number;
516 516
     }
517 517
 
518 518
     /**
519
-	 * Get the invoice key.
520
-	 *
521
-	 * @since 1.0.19
522
-	 * @param  string $context View or edit context.
523
-	 * @return string
524
-	 */
525
-	public function get_key( $context = 'view' ) {
519
+     * Get the invoice key.
520
+     *
521
+     * @since 1.0.19
522
+     * @param  string $context View or edit context.
523
+     * @return string
524
+     */
525
+    public function get_key( $context = 'view' ) {
526 526
         $key = $this->get_prop( 'key', $context );
527 527
 
528 528
         if ( empty( $key ) ) {
@@ -530,24 +530,24 @@  discard block
 block discarded – undo
530 530
             $this->set_key( $key );
531 531
         }
532 532
 
533
-		return $key;
533
+        return $key;
534 534
     }
535 535
 
536 536
     /**
537
-	 * Get the invoice type.
538
-	 *
539
-	 * @since 1.0.19
540
-	 * @param  string $context View or edit context.
541
-	 * @return string
542
-	 */
543
-	public function get_type( $context = 'view' ) {
537
+     * Get the invoice type.
538
+     *
539
+     * @since 1.0.19
540
+     * @param  string $context View or edit context.
541
+     * @return string
542
+     */
543
+    public function get_type( $context = 'view' ) {
544 544
         return $this->get_prop( 'type', $context );
545
-	}
545
+    }
546 546
 
547
-	/**
548
-	 * @deprecated
549
-	 */
550
-	public function get_invoice_quote_type( $post_id ) {
547
+    /**
548
+     * @deprecated
549
+     */
550
+    public function get_invoice_quote_type( $post_id ) {
551 551
         if ( empty( $post_id ) ) {
552 552
             return '';
553 553
         }
@@ -564,35 +564,35 @@  discard block
 block discarded – undo
564 564
     }
565 565
 
566 566
     /**
567
-	 * Get the invoice post type.
568
-	 *
569
-	 * @since 1.0.19
570
-	 * @param  string $context View or edit context.
571
-	 * @return string
572
-	 */
573
-	public function get_post_type( $context = 'view' ) {
567
+     * Get the invoice post type.
568
+     *
569
+     * @since 1.0.19
570
+     * @param  string $context View or edit context.
571
+     * @return string
572
+     */
573
+    public function get_post_type( $context = 'view' ) {
574 574
         return $this->get_prop( 'post_type', $context );
575 575
     }
576 576
 
577 577
     /**
578
-	 * Get the invoice mode.
579
-	 *
580
-	 * @since 1.0.19
581
-	 * @param  string $context View or edit context.
582
-	 * @return string
583
-	 */
584
-	public function get_mode( $context = 'view' ) {
578
+     * Get the invoice mode.
579
+     *
580
+     * @since 1.0.19
581
+     * @param  string $context View or edit context.
582
+     * @return string
583
+     */
584
+    public function get_mode( $context = 'view' ) {
585 585
         return $this->get_prop( 'mode', $context );
586 586
     }
587 587
 
588 588
     /**
589
-	 * Get the invoice path.
590
-	 *
591
-	 * @since 1.0.19
592
-	 * @param  string $context View or edit context.
593
-	 * @return string
594
-	 */
595
-	public function get_path( $context = 'view' ) {
589
+     * Get the invoice path.
590
+     *
591
+     * @since 1.0.19
592
+     * @param  string $context View or edit context.
593
+     * @return string
594
+     */
595
+    public function get_path( $context = 'view' ) {
596 596
         $path = $this->get_prop( 'path', $context );
597 597
 
598 598
         if ( empty( $path ) ) {
@@ -600,73 +600,73 @@  discard block
 block discarded – undo
600 600
             $path   = sanitize_title( $prefix . $this->get_id() );
601 601
         }
602 602
 
603
-		return $path;
603
+        return $path;
604 604
     }
605 605
 
606 606
     /**
607
-	 * Get the invoice name/title.
608
-	 *
609
-	 * @since 1.0.19
610
-	 * @param  string $context View or edit context.
611
-	 * @return string
612
-	 */
613
-	public function get_name( $context = 'view' ) {
607
+     * Get the invoice name/title.
608
+     *
609
+     * @since 1.0.19
610
+     * @param  string $context View or edit context.
611
+     * @return string
612
+     */
613
+    public function get_name( $context = 'view' ) {
614 614
         $name = $this->get_prop( 'title', $context );
615 615
 
616
-		return empty( $name ) ? $this->get_number( $context ) : $name;
616
+        return empty( $name ) ? $this->get_number( $context ) : $name;
617 617
     }
618 618
 
619 619
     /**
620
-	 * Alias of self::get_name().
621
-	 *
622
-	 * @since 1.0.19
623
-	 * @param  string $context View or edit context.
624
-	 * @return string
625
-	 */
626
-	public function get_title( $context = 'view' ) {
627
-		return $this->get_name( $context );
620
+     * Alias of self::get_name().
621
+     *
622
+     * @since 1.0.19
623
+     * @param  string $context View or edit context.
624
+     * @return string
625
+     */
626
+    public function get_title( $context = 'view' ) {
627
+        return $this->get_name( $context );
628 628
     }
629 629
 
630 630
     /**
631
-	 * Get the invoice description.
632
-	 *
633
-	 * @since 1.0.19
634
-	 * @param  string $context View or edit context.
635
-	 * @return string
636
-	 */
637
-	public function get_description( $context = 'view' ) {
638
-		return $this->get_prop( 'description', $context );
631
+     * Get the invoice description.
632
+     *
633
+     * @since 1.0.19
634
+     * @param  string $context View or edit context.
635
+     * @return string
636
+     */
637
+    public function get_description( $context = 'view' ) {
638
+        return $this->get_prop( 'description', $context );
639 639
     }
640 640
 
641 641
     /**
642
-	 * Alias of self::get_description().
643
-	 *
644
-	 * @since 1.0.19
645
-	 * @param  string $context View or edit context.
646
-	 * @return string
647
-	 */
648
-	public function get_excerpt( $context = 'view' ) {
649
-		return $this->get_description( $context );
642
+     * Alias of self::get_description().
643
+     *
644
+     * @since 1.0.19
645
+     * @param  string $context View or edit context.
646
+     * @return string
647
+     */
648
+    public function get_excerpt( $context = 'view' ) {
649
+        return $this->get_description( $context );
650 650
     }
651 651
 
652 652
     /**
653
-	 * Alias of self::get_description().
654
-	 *
655
-	 * @since 1.0.19
656
-	 * @param  string $context View or edit context.
657
-	 * @return string
658
-	 */
659
-	public function get_summary( $context = 'view' ) {
660
-		return $this->get_description( $context );
653
+     * Alias of self::get_description().
654
+     *
655
+     * @since 1.0.19
656
+     * @param  string $context View or edit context.
657
+     * @return string
658
+     */
659
+    public function get_summary( $context = 'view' ) {
660
+        return $this->get_description( $context );
661 661
     }
662 662
 
663 663
     /**
664
-	 * Returns the user info.
665
-	 *
666
-	 * @since 1.0.19
664
+     * Returns the user info.
665
+     *
666
+     * @since 1.0.19
667 667
      * @param  string $context View or edit context.
668
-	 * @return array
669
-	 */
668
+     * @return array
669
+     */
670 670
     public function get_user_info( $context = 'view' ) {
671 671
         $user_info = array(
672 672
             'user_id'    => $this->get_user_id( $context ),
@@ -687,598 +687,598 @@  discard block
 block discarded – undo
687 687
     }
688 688
 
689 689
     /**
690
-	 * Get the customer id.
691
-	 *
692
-	 * @since 1.0.19
693
-	 * @param  string $context View or edit context.
694
-	 * @return int
695
-	 */
696
-	public function get_author( $context = 'view' ) {
697
-		return (int) $this->get_prop( 'author', $context );
690
+     * Get the customer id.
691
+     *
692
+     * @since 1.0.19
693
+     * @param  string $context View or edit context.
694
+     * @return int
695
+     */
696
+    public function get_author( $context = 'view' ) {
697
+        return (int) $this->get_prop( 'author', $context );
698 698
     }
699 699
 
700 700
     /**
701
-	 * Alias of self::get_author().
702
-	 *
703
-	 * @since 1.0.19
704
-	 * @param  string $context View or edit context.
705
-	 * @return int
706
-	 */
707
-	public function get_user_id( $context = 'view' ) {
708
-		return $this->get_author( $context );
701
+     * Alias of self::get_author().
702
+     *
703
+     * @since 1.0.19
704
+     * @param  string $context View or edit context.
705
+     * @return int
706
+     */
707
+    public function get_user_id( $context = 'view' ) {
708
+        return $this->get_author( $context );
709 709
     }
710 710
 
711
-     /**
712
-	 * Alias of self::get_author().
713
-	 *
714
-	 * @since 1.0.19
715
-	 * @param  string $context View or edit context.
716
-	 * @return int
717
-	 */
718
-	public function get_customer_id( $context = 'view' ) {
719
-		return $this->get_author( $context );
711
+        /**
712
+         * Alias of self::get_author().
713
+         *
714
+         * @since 1.0.19
715
+         * @param  string $context View or edit context.
716
+         * @return int
717
+         */
718
+    public function get_customer_id( $context = 'view' ) {
719
+        return $this->get_author( $context );
720 720
     }
721 721
 
722 722
     /**
723
-	 * Get the customer's ip.
724
-	 *
725
-	 * @since 1.0.19
726
-	 * @param  string $context View or edit context.
727
-	 * @return string
728
-	 */
729
-	public function get_ip( $context = 'view' ) {
730
-		return $this->get_prop( 'user_ip', $context );
723
+     * Get the customer's ip.
724
+     *
725
+     * @since 1.0.19
726
+     * @param  string $context View or edit context.
727
+     * @return string
728
+     */
729
+    public function get_ip( $context = 'view' ) {
730
+        return $this->get_prop( 'user_ip', $context );
731 731
     }
732 732
 
733 733
     /**
734
-	 * Alias of self::get_ip().
735
-	 *
736
-	 * @since 1.0.19
737
-	 * @param  string $context View or edit context.
738
-	 * @return string
739
-	 */
740
-	public function get_user_ip( $context = 'view' ) {
741
-		return $this->get_ip( $context );
734
+     * Alias of self::get_ip().
735
+     *
736
+     * @since 1.0.19
737
+     * @param  string $context View or edit context.
738
+     * @return string
739
+     */
740
+    public function get_user_ip( $context = 'view' ) {
741
+        return $this->get_ip( $context );
742 742
     }
743 743
 
744
-     /**
745
-	 * Alias of self::get_ip().
746
-	 *
747
-	 * @since 1.0.19
748
-	 * @param  string $context View or edit context.
749
-	 * @return string
750
-	 */
751
-	public function get_customer_ip( $context = 'view' ) {
752
-		return $this->get_ip( $context );
744
+        /**
745
+         * Alias of self::get_ip().
746
+         *
747
+         * @since 1.0.19
748
+         * @param  string $context View or edit context.
749
+         * @return string
750
+         */
751
+    public function get_customer_ip( $context = 'view' ) {
752
+        return $this->get_ip( $context );
753 753
     }
754 754
 
755 755
     /**
756
-	 * Get the customer's first name.
757
-	 *
758
-	 * @since 1.0.19
759
-	 * @param  string $context View or edit context.
760
-	 * @return string
761
-	 */
762
-	public function get_first_name( $context = 'view' ) {
763
-		return $this->get_prop( 'first_name', $context );
756
+     * Get the customer's first name.
757
+     *
758
+     * @since 1.0.19
759
+     * @param  string $context View or edit context.
760
+     * @return string
761
+     */
762
+    public function get_first_name( $context = 'view' ) {
763
+        return $this->get_prop( 'first_name', $context );
764 764
     }
765 765
 
766 766
     /**
767
-	 * Alias of self::get_first_name().
768
-	 *
769
-	 * @since 1.0.19
770
-	 * @param  string $context View or edit context.
771
-	 * @return int
772
-	 */
773
-	public function get_user_first_name( $context = 'view' ) {
774
-		return $this->get_first_name( $context );
767
+     * Alias of self::get_first_name().
768
+     *
769
+     * @since 1.0.19
770
+     * @param  string $context View or edit context.
771
+     * @return int
772
+     */
773
+    public function get_user_first_name( $context = 'view' ) {
774
+        return $this->get_first_name( $context );
775 775
     }
776 776
 
777
-     /**
778
-	 * Alias of self::get_first_name().
779
-	 *
780
-	 * @since 1.0.19
781
-	 * @param  string $context View or edit context.
782
-	 * @return int
783
-	 */
784
-	public function get_customer_first_name( $context = 'view' ) {
785
-		return $this->get_first_name( $context );
777
+        /**
778
+         * Alias of self::get_first_name().
779
+         *
780
+         * @since 1.0.19
781
+         * @param  string $context View or edit context.
782
+         * @return int
783
+         */
784
+    public function get_customer_first_name( $context = 'view' ) {
785
+        return $this->get_first_name( $context );
786 786
     }
787 787
 
788 788
     /**
789
-	 * Get the customer's last name.
790
-	 *
791
-	 * @since 1.0.19
792
-	 * @param  string $context View or edit context.
793
-	 * @return string
794
-	 */
795
-	public function get_last_name( $context = 'view' ) {
796
-		return $this->get_prop( 'last_name', $context );
789
+     * Get the customer's last name.
790
+     *
791
+     * @since 1.0.19
792
+     * @param  string $context View or edit context.
793
+     * @return string
794
+     */
795
+    public function get_last_name( $context = 'view' ) {
796
+        return $this->get_prop( 'last_name', $context );
797 797
     }
798 798
 
799 799
     /**
800
-	 * Alias of self::get_last_name().
801
-	 *
802
-	 * @since 1.0.19
803
-	 * @param  string $context View or edit context.
804
-	 * @return int
805
-	 */
806
-	public function get_user_last_name( $context = 'view' ) {
807
-		return $this->get_last_name( $context );
800
+     * Alias of self::get_last_name().
801
+     *
802
+     * @since 1.0.19
803
+     * @param  string $context View or edit context.
804
+     * @return int
805
+     */
806
+    public function get_user_last_name( $context = 'view' ) {
807
+        return $this->get_last_name( $context );
808 808
     }
809 809
 
810 810
     /**
811
-	 * Alias of self::get_last_name().
812
-	 *
813
-	 * @since 1.0.19
814
-	 * @param  string $context View or edit context.
815
-	 * @return int
816
-	 */
817
-	public function get_customer_last_name( $context = 'view' ) {
818
-		return $this->get_last_name( $context );
811
+     * Alias of self::get_last_name().
812
+     *
813
+     * @since 1.0.19
814
+     * @param  string $context View or edit context.
815
+     * @return int
816
+     */
817
+    public function get_customer_last_name( $context = 'view' ) {
818
+        return $this->get_last_name( $context );
819 819
     }
820 820
 
821 821
     /**
822
-	 * Get the customer's full name.
823
-	 *
824
-	 * @since 1.0.19
825
-	 * @param  string $context View or edit context.
826
-	 * @return string
827
-	 */
828
-	public function get_full_name( $context = 'view' ) {
829
-		return trim( $this->get_first_name( $context ) . ' ' . $this->get_last_name( $context ) );
822
+     * Get the customer's full name.
823
+     *
824
+     * @since 1.0.19
825
+     * @param  string $context View or edit context.
826
+     * @return string
827
+     */
828
+    public function get_full_name( $context = 'view' ) {
829
+        return trim( $this->get_first_name( $context ) . ' ' . $this->get_last_name( $context ) );
830 830
     }
831 831
 
832 832
     /**
833
-	 * Alias of self::get_full_name().
834
-	 *
835
-	 * @since 1.0.19
836
-	 * @param  string $context View or edit context.
837
-	 * @return int
838
-	 */
839
-	public function get_user_full_name( $context = 'view' ) {
840
-		return $this->get_full_name( $context );
833
+     * Alias of self::get_full_name().
834
+     *
835
+     * @since 1.0.19
836
+     * @param  string $context View or edit context.
837
+     * @return int
838
+     */
839
+    public function get_user_full_name( $context = 'view' ) {
840
+        return $this->get_full_name( $context );
841 841
     }
842 842
 
843 843
     /**
844
-	 * Alias of self::get_full_name().
845
-	 *
846
-	 * @since 1.0.19
847
-	 * @param  string $context View or edit context.
848
-	 * @return int
849
-	 */
850
-	public function get_customer_full_name( $context = 'view' ) {
851
-		return $this->get_full_name( $context );
844
+     * Alias of self::get_full_name().
845
+     *
846
+     * @since 1.0.19
847
+     * @param  string $context View or edit context.
848
+     * @return int
849
+     */
850
+    public function get_customer_full_name( $context = 'view' ) {
851
+        return $this->get_full_name( $context );
852 852
     }
853 853
 
854 854
     /**
855
-	 * Get the customer's phone number.
856
-	 *
857
-	 * @since 1.0.19
858
-	 * @param  string $context View or edit context.
859
-	 * @return string
860
-	 */
861
-	public function get_phone( $context = 'view' ) {
862
-		return $this->get_prop( 'phone', $context );
855
+     * Get the customer's phone number.
856
+     *
857
+     * @since 1.0.19
858
+     * @param  string $context View or edit context.
859
+     * @return string
860
+     */
861
+    public function get_phone( $context = 'view' ) {
862
+        return $this->get_prop( 'phone', $context );
863 863
     }
864 864
 
865 865
     /**
866
-	 * Alias of self::get_phone().
867
-	 *
868
-	 * @since 1.0.19
869
-	 * @param  string $context View or edit context.
870
-	 * @return int
871
-	 */
872
-	public function get_phone_number( $context = 'view' ) {
873
-		return $this->get_phone( $context );
866
+     * Alias of self::get_phone().
867
+     *
868
+     * @since 1.0.19
869
+     * @param  string $context View or edit context.
870
+     * @return int
871
+     */
872
+    public function get_phone_number( $context = 'view' ) {
873
+        return $this->get_phone( $context );
874 874
     }
875 875
 
876 876
     /**
877
-	 * Alias of self::get_phone().
878
-	 *
879
-	 * @since 1.0.19
880
-	 * @param  string $context View or edit context.
881
-	 * @return int
882
-	 */
883
-	public function get_user_phone( $context = 'view' ) {
884
-		return $this->get_phone( $context );
877
+     * Alias of self::get_phone().
878
+     *
879
+     * @since 1.0.19
880
+     * @param  string $context View or edit context.
881
+     * @return int
882
+     */
883
+    public function get_user_phone( $context = 'view' ) {
884
+        return $this->get_phone( $context );
885 885
     }
886 886
 
887 887
     /**
888
-	 * Alias of self::get_phone().
889
-	 *
890
-	 * @since 1.0.19
891
-	 * @param  string $context View or edit context.
892
-	 * @return int
893
-	 */
894
-	public function get_customer_phone( $context = 'view' ) {
895
-		return $this->get_phone( $context );
888
+     * Alias of self::get_phone().
889
+     *
890
+     * @since 1.0.19
891
+     * @param  string $context View or edit context.
892
+     * @return int
893
+     */
894
+    public function get_customer_phone( $context = 'view' ) {
895
+        return $this->get_phone( $context );
896 896
     }
897 897
 
898 898
     /**
899
-	 * Get the customer's email address.
900
-	 *
901
-	 * @since 1.0.19
902
-	 * @param  string $context View or edit context.
903
-	 * @return string
904
-	 */
905
-	public function get_email( $context = 'view' ) {
906
-		return $this->get_prop( 'email', $context );
899
+     * Get the customer's email address.
900
+     *
901
+     * @since 1.0.19
902
+     * @param  string $context View or edit context.
903
+     * @return string
904
+     */
905
+    public function get_email( $context = 'view' ) {
906
+        return $this->get_prop( 'email', $context );
907 907
     }
908 908
 
909 909
     /**
910
-	 * Alias of self::get_email().
911
-	 *
912
-	 * @since 1.0.19
913
-	 * @param  string $context View or edit context.
914
-	 * @return string
915
-	 */
916
-	public function get_email_address( $context = 'view' ) {
917
-		return $this->get_email( $context );
910
+     * Alias of self::get_email().
911
+     *
912
+     * @since 1.0.19
913
+     * @param  string $context View or edit context.
914
+     * @return string
915
+     */
916
+    public function get_email_address( $context = 'view' ) {
917
+        return $this->get_email( $context );
918 918
     }
919 919
 
920 920
     /**
921
-	 * Alias of self::get_email().
922
-	 *
923
-	 * @since 1.0.19
924
-	 * @param  string $context View or edit context.
925
-	 * @return int
926
-	 */
927
-	public function get_user_email( $context = 'view' ) {
928
-		return $this->get_email( $context );
921
+     * Alias of self::get_email().
922
+     *
923
+     * @since 1.0.19
924
+     * @param  string $context View or edit context.
925
+     * @return int
926
+     */
927
+    public function get_user_email( $context = 'view' ) {
928
+        return $this->get_email( $context );
929
+    }
930
+
931
+    /**
932
+     * Alias of self::get_email().
933
+     *
934
+     * @since 1.0.19
935
+     * @param  string $context View or edit context.
936
+     * @return int
937
+     */
938
+    public function get_customer_email( $context = 'view' ) {
939
+        return $this->get_email( $context );
940
+    }
941
+
942
+    /**
943
+     * Get the customer's country.
944
+     *
945
+     * @since 1.0.19
946
+     * @param  string $context View or edit context.
947
+     * @return string
948
+     */
949
+    public function get_country( $context = 'view' ) {
950
+        $country = $this->get_prop( 'country', $context );
951
+        return empty( $country ) ? wpinv_get_default_country() : $country;
952
+    }
953
+
954
+    /**
955
+     * Alias of self::get_country().
956
+     *
957
+     * @since 1.0.19
958
+     * @param  string $context View or edit context.
959
+     * @return int
960
+     */
961
+    public function get_user_country( $context = 'view' ) {
962
+        return $this->get_country( $context );
963
+    }
964
+
965
+    /**
966
+     * Alias of self::get_country().
967
+     *
968
+     * @since 1.0.19
969
+     * @param  string $context View or edit context.
970
+     * @return int
971
+     */
972
+    public function get_customer_country( $context = 'view' ) {
973
+        return $this->get_country( $context );
929 974
     }
930 975
 
931 976
     /**
932
-	 * Alias of self::get_email().
933
-	 *
934
-	 * @since 1.0.19
935
-	 * @param  string $context View or edit context.
936
-	 * @return int
937
-	 */
938
-	public function get_customer_email( $context = 'view' ) {
939
-		return $this->get_email( $context );
977
+     * Get the customer's state.
978
+     *
979
+     * @since 1.0.19
980
+     * @param  string $context View or edit context.
981
+     * @return string
982
+     */
983
+    public function get_state( $context = 'view' ) {
984
+        $state = $this->get_prop( 'state', $context );
985
+        return empty( $state ) ? wpinv_get_default_state() : $state;
940 986
     }
941 987
 
942 988
     /**
943
-	 * Get the customer's country.
944
-	 *
945
-	 * @since 1.0.19
946
-	 * @param  string $context View or edit context.
947
-	 * @return string
948
-	 */
949
-	public function get_country( $context = 'view' ) {
950
-		$country = $this->get_prop( 'country', $context );
951
-		return empty( $country ) ? wpinv_get_default_country() : $country;
989
+     * Alias of self::get_state().
990
+     *
991
+     * @since 1.0.19
992
+     * @param  string $context View or edit context.
993
+     * @return int
994
+     */
995
+    public function get_user_state( $context = 'view' ) {
996
+        return $this->get_state( $context );
952 997
     }
953 998
 
954 999
     /**
955
-	 * Alias of self::get_country().
956
-	 *
957
-	 * @since 1.0.19
958
-	 * @param  string $context View or edit context.
959
-	 * @return int
960
-	 */
961
-	public function get_user_country( $context = 'view' ) {
962
-		return $this->get_country( $context );
1000
+     * Alias of self::get_state().
1001
+     *
1002
+     * @since 1.0.19
1003
+     * @param  string $context View or edit context.
1004
+     * @return int
1005
+     */
1006
+    public function get_customer_state( $context = 'view' ) {
1007
+        return $this->get_state( $context );
1008
+    }
1009
+
1010
+    /**
1011
+     * Get the customer's city.
1012
+     *
1013
+     * @since 1.0.19
1014
+     * @param  string $context View or edit context.
1015
+     * @return string
1016
+     */
1017
+    public function get_city( $context = 'view' ) {
1018
+        return $this->get_prop( 'city', $context );
1019
+    }
1020
+
1021
+    /**
1022
+     * Alias of self::get_city().
1023
+     *
1024
+     * @since 1.0.19
1025
+     * @param  string $context View or edit context.
1026
+     * @return string
1027
+     */
1028
+    public function get_user_city( $context = 'view' ) {
1029
+        return $this->get_city( $context );
1030
+    }
1031
+
1032
+    /**
1033
+     * Alias of self::get_city().
1034
+     *
1035
+     * @since 1.0.19
1036
+     * @param  string $context View or edit context.
1037
+     * @return string
1038
+     */
1039
+    public function get_customer_city( $context = 'view' ) {
1040
+        return $this->get_city( $context );
1041
+    }
1042
+
1043
+    /**
1044
+     * Get the customer's zip.
1045
+     *
1046
+     * @since 1.0.19
1047
+     * @param  string $context View or edit context.
1048
+     * @return string
1049
+     */
1050
+    public function get_zip( $context = 'view' ) {
1051
+        return $this->get_prop( 'zip', $context );
1052
+    }
1053
+
1054
+    /**
1055
+     * Alias of self::get_zip().
1056
+     *
1057
+     * @since 1.0.19
1058
+     * @param  string $context View or edit context.
1059
+     * @return string
1060
+     */
1061
+    public function get_user_zip( $context = 'view' ) {
1062
+        return $this->get_zip( $context );
963 1063
     }
964 1064
 
965 1065
     /**
966
-	 * Alias of self::get_country().
967
-	 *
968
-	 * @since 1.0.19
969
-	 * @param  string $context View or edit context.
970
-	 * @return int
971
-	 */
972
-	public function get_customer_country( $context = 'view' ) {
973
-		return $this->get_country( $context );
1066
+     * Alias of self::get_zip().
1067
+     *
1068
+     * @since 1.0.19
1069
+     * @param  string $context View or edit context.
1070
+     * @return string
1071
+     */
1072
+    public function get_customer_zip( $context = 'view' ) {
1073
+        return $this->get_zip( $context );
974 1074
     }
975 1075
 
976 1076
     /**
977
-	 * Get the customer's state.
978
-	 *
979
-	 * @since 1.0.19
980
-	 * @param  string $context View or edit context.
981
-	 * @return string
982
-	 */
983
-	public function get_state( $context = 'view' ) {
984
-		$state = $this->get_prop( 'state', $context );
985
-		return empty( $state ) ? wpinv_get_default_state() : $state;
1077
+     * Get the customer's company.
1078
+     *
1079
+     * @since 1.0.19
1080
+     * @param  string $context View or edit context.
1081
+     * @return string
1082
+     */
1083
+    public function get_company( $context = 'view' ) {
1084
+        return $this->get_prop( 'company', $context );
986 1085
     }
987 1086
 
988 1087
     /**
989
-	 * Alias of self::get_state().
990
-	 *
991
-	 * @since 1.0.19
992
-	 * @param  string $context View or edit context.
993
-	 * @return int
994
-	 */
995
-	public function get_user_state( $context = 'view' ) {
996
-		return $this->get_state( $context );
1088
+     * Alias of self::get_company().
1089
+     *
1090
+     * @since 1.0.19
1091
+     * @param  string $context View or edit context.
1092
+     * @return string
1093
+     */
1094
+    public function get_user_company( $context = 'view' ) {
1095
+        return $this->get_company( $context );
997 1096
     }
998 1097
 
999 1098
     /**
1000
-	 * Alias of self::get_state().
1001
-	 *
1002
-	 * @since 1.0.19
1003
-	 * @param  string $context View or edit context.
1004
-	 * @return int
1005
-	 */
1006
-	public function get_customer_state( $context = 'view' ) {
1007
-		return $this->get_state( $context );
1099
+     * Alias of self::get_company().
1100
+     *
1101
+     * @since 1.0.19
1102
+     * @param  string $context View or edit context.
1103
+     * @return string
1104
+     */
1105
+    public function get_customer_company( $context = 'view' ) {
1106
+        return $this->get_company( $context );
1008 1107
     }
1009 1108
 
1010 1109
     /**
1011
-	 * Get the customer's city.
1012
-	 *
1013
-	 * @since 1.0.19
1014
-	 * @param  string $context View or edit context.
1015
-	 * @return string
1016
-	 */
1017
-	public function get_city( $context = 'view' ) {
1018
-		return $this->get_prop( 'city', $context );
1110
+     * Get the customer's vat number.
1111
+     *
1112
+     * @since 1.0.19
1113
+     * @param  string $context View or edit context.
1114
+     * @return string
1115
+     */
1116
+    public function get_vat_number( $context = 'view' ) {
1117
+        return $this->get_prop( 'vat_number', $context );
1019 1118
     }
1020 1119
 
1021 1120
     /**
1022
-	 * Alias of self::get_city().
1023
-	 *
1024
-	 * @since 1.0.19
1025
-	 * @param  string $context View or edit context.
1026
-	 * @return string
1027
-	 */
1028
-	public function get_user_city( $context = 'view' ) {
1029
-		return $this->get_city( $context );
1121
+     * Alias of self::get_vat_number().
1122
+     *
1123
+     * @since 1.0.19
1124
+     * @param  string $context View or edit context.
1125
+     * @return string
1126
+     */
1127
+    public function get_user_vat_number( $context = 'view' ) {
1128
+        return $this->get_vat_number( $context );
1030 1129
     }
1031 1130
 
1032 1131
     /**
1033
-	 * Alias of self::get_city().
1034
-	 *
1035
-	 * @since 1.0.19
1036
-	 * @param  string $context View or edit context.
1037
-	 * @return string
1038
-	 */
1039
-	public function get_customer_city( $context = 'view' ) {
1040
-		return $this->get_city( $context );
1132
+     * Alias of self::get_vat_number().
1133
+     *
1134
+     * @since 1.0.19
1135
+     * @param  string $context View or edit context.
1136
+     * @return string
1137
+     */
1138
+    public function get_customer_vat_number( $context = 'view' ) {
1139
+        return $this->get_vat_number( $context );
1041 1140
     }
1042 1141
 
1043 1142
     /**
1044
-	 * Get the customer's zip.
1045
-	 *
1046
-	 * @since 1.0.19
1047
-	 * @param  string $context View or edit context.
1048
-	 * @return string
1049
-	 */
1050
-	public function get_zip( $context = 'view' ) {
1051
-		return $this->get_prop( 'zip', $context );
1143
+     * Get the customer's vat rate.
1144
+     *
1145
+     * @since 1.0.19
1146
+     * @param  string $context View or edit context.
1147
+     * @return string
1148
+     */
1149
+    public function get_vat_rate( $context = 'view' ) {
1150
+        return $this->get_prop( 'vat_rate', $context );
1052 1151
     }
1053 1152
 
1054 1153
     /**
1055
-	 * Alias of self::get_zip().
1056
-	 *
1057
-	 * @since 1.0.19
1058
-	 * @param  string $context View or edit context.
1059
-	 * @return string
1060
-	 */
1061
-	public function get_user_zip( $context = 'view' ) {
1062
-		return $this->get_zip( $context );
1154
+     * Alias of self::get_vat_rate().
1155
+     *
1156
+     * @since 1.0.19
1157
+     * @param  string $context View or edit context.
1158
+     * @return string
1159
+     */
1160
+    public function get_user_vat_rate( $context = 'view' ) {
1161
+        return $this->get_vat_rate( $context );
1063 1162
     }
1064 1163
 
1065 1164
     /**
1066
-	 * Alias of self::get_zip().
1067
-	 *
1068
-	 * @since 1.0.19
1069
-	 * @param  string $context View or edit context.
1070
-	 * @return string
1071
-	 */
1072
-	public function get_customer_zip( $context = 'view' ) {
1073
-		return $this->get_zip( $context );
1165
+     * Alias of self::get_vat_rate().
1166
+     *
1167
+     * @since 1.0.19
1168
+     * @param  string $context View or edit context.
1169
+     * @return string
1170
+     */
1171
+    public function get_customer_vat_rate( $context = 'view' ) {
1172
+        return $this->get_vat_rate( $context );
1074 1173
     }
1075 1174
 
1076 1175
     /**
1077
-	 * Get the customer's company.
1078
-	 *
1079
-	 * @since 1.0.19
1080
-	 * @param  string $context View or edit context.
1081
-	 * @return string
1082
-	 */
1083
-	public function get_company( $context = 'view' ) {
1084
-		return $this->get_prop( 'company', $context );
1176
+     * Get the customer's address.
1177
+     *
1178
+     * @since 1.0.19
1179
+     * @param  string $context View or edit context.
1180
+     * @return string
1181
+     */
1182
+    public function get_address( $context = 'view' ) {
1183
+        return $this->get_prop( 'address', $context );
1085 1184
     }
1086 1185
 
1087 1186
     /**
1088
-	 * Alias of self::get_company().
1089
-	 *
1090
-	 * @since 1.0.19
1091
-	 * @param  string $context View or edit context.
1092
-	 * @return string
1093
-	 */
1094
-	public function get_user_company( $context = 'view' ) {
1095
-		return $this->get_company( $context );
1187
+     * Alias of self::get_address().
1188
+     *
1189
+     * @since 1.0.19
1190
+     * @param  string $context View or edit context.
1191
+     * @return string
1192
+     */
1193
+    public function get_user_address( $context = 'view' ) {
1194
+        return $this->get_address( $context );
1096 1195
     }
1097 1196
 
1098 1197
     /**
1099
-	 * Alias of self::get_company().
1100
-	 *
1101
-	 * @since 1.0.19
1102
-	 * @param  string $context View or edit context.
1103
-	 * @return string
1104
-	 */
1105
-	public function get_customer_company( $context = 'view' ) {
1106
-		return $this->get_company( $context );
1198
+     * Alias of self::get_address().
1199
+     *
1200
+     * @since 1.0.19
1201
+     * @param  string $context View or edit context.
1202
+     * @return string
1203
+     */
1204
+    public function get_customer_address( $context = 'view' ) {
1205
+        return $this->get_address( $context );
1107 1206
     }
1108 1207
 
1109 1208
     /**
1110
-	 * Get the customer's vat number.
1111
-	 *
1112
-	 * @since 1.0.19
1113
-	 * @param  string $context View or edit context.
1114
-	 * @return string
1115
-	 */
1116
-	public function get_vat_number( $context = 'view' ) {
1117
-		return $this->get_prop( 'vat_number', $context );
1209
+     * Get whether the customer has viewed the invoice or not.
1210
+     *
1211
+     * @since 1.0.19
1212
+     * @param  string $context View or edit context.
1213
+     * @return bool
1214
+     */
1215
+    public function get_is_viewed( $context = 'view' ) {
1216
+        return (bool) $this->get_prop( 'is_viewed', $context );
1118 1217
     }
1119 1218
 
1120 1219
     /**
1121
-	 * Alias of self::get_vat_number().
1122
-	 *
1123
-	 * @since 1.0.19
1124
-	 * @param  string $context View or edit context.
1125
-	 * @return string
1126
-	 */
1127
-	public function get_user_vat_number( $context = 'view' ) {
1128
-		return $this->get_vat_number( $context );
1220
+     * Get other recipients for invoice communications.
1221
+     *
1222
+     * @since 1.0.19
1223
+     * @param  string $context View or edit context.
1224
+     * @return bool
1225
+     */
1226
+    public function get_email_cc( $context = 'view' ) {
1227
+        return $this->get_prop( 'email_cc', $context );
1129 1228
     }
1130 1229
 
1131 1230
     /**
1132
-	 * Alias of self::get_vat_number().
1133
-	 *
1134
-	 * @since 1.0.19
1135
-	 * @param  string $context View or edit context.
1136
-	 * @return string
1137
-	 */
1138
-	public function get_customer_vat_number( $context = 'view' ) {
1139
-		return $this->get_vat_number( $context );
1231
+     * Get invoice template.
1232
+     *
1233
+     * @since 1.0.19
1234
+     * @param  string $context View or edit context.
1235
+     * @return bool
1236
+     */
1237
+    public function get_template( $context = 'view' ) {
1238
+        return $this->get_prop( 'template', $context );
1140 1239
     }
1141 1240
 
1142 1241
     /**
1143
-	 * Get the customer's vat rate.
1144
-	 *
1145
-	 * @since 1.0.19
1146
-	 * @param  string $context View or edit context.
1147
-	 * @return string
1148
-	 */
1149
-	public function get_vat_rate( $context = 'view' ) {
1150
-		return $this->get_prop( 'vat_rate', $context );
1242
+     * Get whether the customer has confirmed their address.
1243
+     *
1244
+     * @since 1.0.19
1245
+     * @param  string $context View or edit context.
1246
+     * @return bool
1247
+     */
1248
+    public function get_address_confirmed( $context = 'view' ) {
1249
+        return (bool) $this->get_prop( 'address_confirmed', $context );
1151 1250
     }
1152 1251
 
1153 1252
     /**
1154
-	 * Alias of self::get_vat_rate().
1155
-	 *
1156
-	 * @since 1.0.19
1157
-	 * @param  string $context View or edit context.
1158
-	 * @return string
1159
-	 */
1160
-	public function get_user_vat_rate( $context = 'view' ) {
1161
-		return $this->get_vat_rate( $context );
1253
+     * Alias of self::get_address_confirmed().
1254
+     *
1255
+     * @since 1.0.19
1256
+     * @param  string $context View or edit context.
1257
+     * @return bool
1258
+     */
1259
+    public function get_user_address_confirmed( $context = 'view' ) {
1260
+        return $this->get_address_confirmed( $context );
1162 1261
     }
1163 1262
 
1164 1263
     /**
1165
-	 * Alias of self::get_vat_rate().
1166
-	 *
1167
-	 * @since 1.0.19
1168
-	 * @param  string $context View or edit context.
1169
-	 * @return string
1170
-	 */
1171
-	public function get_customer_vat_rate( $context = 'view' ) {
1172
-		return $this->get_vat_rate( $context );
1264
+     * Alias of self::get_address().
1265
+     *
1266
+     * @since 1.0.19
1267
+     * @param  string $context View or edit context.
1268
+     * @return bool
1269
+     */
1270
+    public function get_customer_address_confirmed( $context = 'view' ) {
1271
+        return $this->get_address_confirmed( $context );
1173 1272
     }
1174 1273
 
1175 1274
     /**
1176
-	 * Get the customer's address.
1177
-	 *
1178
-	 * @since 1.0.19
1179
-	 * @param  string $context View or edit context.
1180
-	 * @return string
1181
-	 */
1182
-	public function get_address( $context = 'view' ) {
1183
-		return $this->get_prop( 'address', $context );
1184
-    }
1185
-
1186
-    /**
1187
-	 * Alias of self::get_address().
1188
-	 *
1189
-	 * @since 1.0.19
1190
-	 * @param  string $context View or edit context.
1191
-	 * @return string
1192
-	 */
1193
-	public function get_user_address( $context = 'view' ) {
1194
-		return $this->get_address( $context );
1195
-    }
1196
-
1197
-    /**
1198
-	 * Alias of self::get_address().
1199
-	 *
1200
-	 * @since 1.0.19
1201
-	 * @param  string $context View or edit context.
1202
-	 * @return string
1203
-	 */
1204
-	public function get_customer_address( $context = 'view' ) {
1205
-		return $this->get_address( $context );
1206
-    }
1207
-
1208
-    /**
1209
-	 * Get whether the customer has viewed the invoice or not.
1210
-	 *
1211
-	 * @since 1.0.19
1212
-	 * @param  string $context View or edit context.
1213
-	 * @return bool
1214
-	 */
1215
-	public function get_is_viewed( $context = 'view' ) {
1216
-		return (bool) $this->get_prop( 'is_viewed', $context );
1217
-	}
1218
-
1219
-	/**
1220
-	 * Get other recipients for invoice communications.
1221
-	 *
1222
-	 * @since 1.0.19
1223
-	 * @param  string $context View or edit context.
1224
-	 * @return bool
1225
-	 */
1226
-	public function get_email_cc( $context = 'view' ) {
1227
-		return $this->get_prop( 'email_cc', $context );
1228
-	}
1229
-
1230
-	/**
1231
-	 * Get invoice template.
1232
-	 *
1233
-	 * @since 1.0.19
1234
-	 * @param  string $context View or edit context.
1235
-	 * @return bool
1236
-	 */
1237
-	public function get_template( $context = 'view' ) {
1238
-		return $this->get_prop( 'template', $context );
1239
-	}
1240
-
1241
-	/**
1242
-	 * Get whether the customer has confirmed their address.
1243
-	 *
1244
-	 * @since 1.0.19
1245
-	 * @param  string $context View or edit context.
1246
-	 * @return bool
1247
-	 */
1248
-	public function get_address_confirmed( $context = 'view' ) {
1249
-		return (bool) $this->get_prop( 'address_confirmed', $context );
1250
-    }
1251
-
1252
-    /**
1253
-	 * Alias of self::get_address_confirmed().
1254
-	 *
1255
-	 * @since 1.0.19
1256
-	 * @param  string $context View or edit context.
1257
-	 * @return bool
1258
-	 */
1259
-	public function get_user_address_confirmed( $context = 'view' ) {
1260
-		return $this->get_address_confirmed( $context );
1261
-    }
1262
-
1263
-    /**
1264
-	 * Alias of self::get_address().
1265
-	 *
1266
-	 * @since 1.0.19
1267
-	 * @param  string $context View or edit context.
1268
-	 * @return bool
1269
-	 */
1270
-	public function get_customer_address_confirmed( $context = 'view' ) {
1271
-		return $this->get_address_confirmed( $context );
1272
-    }
1273
-
1274
-    /**
1275
-	 * Get the invoice subtotal.
1276
-	 *
1277
-	 * @since 1.0.19
1278
-	 * @param  string $context View or edit context.
1279
-	 * @return float
1280
-	 */
1281
-	public function get_subtotal( $context = 'view' ) {
1275
+     * Get the invoice subtotal.
1276
+     *
1277
+     * @since 1.0.19
1278
+     * @param  string $context View or edit context.
1279
+     * @return float
1280
+     */
1281
+    public function get_subtotal( $context = 'view' ) {
1282 1282
         $subtotal = (float) $this->get_prop( 'subtotal', $context );
1283 1283
 
1284 1284
         // Backwards compatibility.
@@ -1290,155 +1290,155 @@  discard block
 block discarded – undo
1290 1290
     }
1291 1291
 
1292 1292
     /**
1293
-	 * Get the invoice discount total.
1294
-	 *
1295
-	 * @since 1.0.19
1296
-	 * @param  string $context View or edit context.
1297
-	 * @return float
1298
-	 */
1299
-	public function get_total_discount( $context = 'view' ) {
1300
-		return (float) $this->get_prop( 'total_discount', $context );
1293
+     * Get the invoice discount total.
1294
+     *
1295
+     * @since 1.0.19
1296
+     * @param  string $context View or edit context.
1297
+     * @return float
1298
+     */
1299
+    public function get_total_discount( $context = 'view' ) {
1300
+        return (float) $this->get_prop( 'total_discount', $context );
1301 1301
     }
1302 1302
 
1303 1303
     /**
1304
-	 * Get the invoice tax total.
1305
-	 *
1306
-	 * @since 1.0.19
1307
-	 * @param  string $context View or edit context.
1308
-	 * @return float
1309
-	 */
1310
-	public function get_total_tax( $context = 'view' ) {
1311
-		return (float) $this->get_prop( 'total_tax', $context );
1312
-	}
1304
+     * Get the invoice tax total.
1305
+     *
1306
+     * @since 1.0.19
1307
+     * @param  string $context View or edit context.
1308
+     * @return float
1309
+     */
1310
+    public function get_total_tax( $context = 'view' ) {
1311
+        return (float) $this->get_prop( 'total_tax', $context );
1312
+    }
1313 1313
 
1314
-	/**
1315
-	 * @deprecated
1316
-	 */
1317
-	public function get_final_tax( $currency = false ) {
1318
-		$tax = $this->get_total_tax();
1314
+    /**
1315
+     * @deprecated
1316
+     */
1317
+    public function get_final_tax( $currency = false ) {
1318
+        $tax = $this->get_total_tax();
1319 1319
 
1320 1320
         if ( $currency ) {
1321
-			return wpinv_price( wpinv_format_amount( $tax, NULL, false ), $this->get_currency() );
1321
+            return wpinv_price( wpinv_format_amount( $tax, NULL, false ), $this->get_currency() );
1322 1322
         }
1323 1323
 
1324 1324
         return $tax;
1325 1325
     }
1326 1326
 
1327 1327
     /**
1328
-	 * Get the invoice fees total.
1329
-	 *
1330
-	 * @since 1.0.19
1331
-	 * @param  string $context View or edit context.
1332
-	 * @return float
1333
-	 */
1334
-	public function get_total_fees( $context = 'view' ) {
1335
-		return (float) $this->get_prop( 'total_fees', $context );
1328
+     * Get the invoice fees total.
1329
+     *
1330
+     * @since 1.0.19
1331
+     * @param  string $context View or edit context.
1332
+     * @return float
1333
+     */
1334
+    public function get_total_fees( $context = 'view' ) {
1335
+        return (float) $this->get_prop( 'total_fees', $context );
1336 1336
     }
1337 1337
 
1338 1338
     /**
1339
-	 * Alias for self::get_total_fees().
1340
-	 *
1341
-	 * @since 1.0.19
1342
-	 * @param  string $context View or edit context.
1343
-	 * @return float
1344
-	 */
1345
-	public function get_fees_total( $context = 'view' ) {
1346
-		return $this->get_total_fees( $context );
1339
+     * Alias for self::get_total_fees().
1340
+     *
1341
+     * @since 1.0.19
1342
+     * @param  string $context View or edit context.
1343
+     * @return float
1344
+     */
1345
+    public function get_fees_total( $context = 'view' ) {
1346
+        return $this->get_total_fees( $context );
1347 1347
     }
1348 1348
 
1349 1349
     /**
1350
-	 * Get the invoice total.
1351
-	 *
1352
-	 * @since 1.0.19
1350
+     * Get the invoice total.
1351
+     *
1352
+     * @since 1.0.19
1353 1353
      * @return float
1354
-	 */
1355
-	public function get_total() {
1356
-		$total = $this->is_renewal() ? $this->get_recurring_total() : $this->get_initial_total();
1357
-		return apply_filters( 'getpaid_get_invoice_total_amount', $total, $this  );
1354
+     */
1355
+    public function get_total() {
1356
+        $total = $this->is_renewal() ? $this->get_recurring_total() : $this->get_initial_total();
1357
+        return apply_filters( 'getpaid_get_invoice_total_amount', $total, $this  );
1358 1358
     }
1359 1359
 
1360 1360
     /**
1361
-	 * Get the initial invoice total.
1362
-	 *
1363
-	 * @since 1.0.19
1361
+     * Get the initial invoice total.
1362
+     *
1363
+     * @since 1.0.19
1364 1364
      * @param  string $context View or edit context.
1365 1365
      * @return float
1366
-	 */
1366
+     */
1367 1367
     public function get_initial_total() {
1368 1368
 
1369
-		if ( empty( $this->totals ) ) {
1370
-			$this->recalculate_total();
1371
-		}
1369
+        if ( empty( $this->totals ) ) {
1370
+            $this->recalculate_total();
1371
+        }
1372 1372
 
1373
-		$tax      = $this->totals['tax']['initial'];
1374
-		$fee      = $this->totals['fee']['initial'];
1375
-		$discount = $this->totals['discount']['initial'];
1376
-		$subtotal = $this->totals['subtotal']['initial'];
1377
-		$total    = $tax + $fee - $discount + $subtotal;
1373
+        $tax      = $this->totals['tax']['initial'];
1374
+        $fee      = $this->totals['fee']['initial'];
1375
+        $discount = $this->totals['discount']['initial'];
1376
+        $subtotal = $this->totals['subtotal']['initial'];
1377
+        $total    = $tax + $fee - $discount + $subtotal;
1378 1378
 
1379
-		if ( 0 > $total ) {
1380
-			$total = 0;
1381
-		}
1379
+        if ( 0 > $total ) {
1380
+            $total = 0;
1381
+        }
1382 1382
 
1383 1383
         return apply_filters( 'wpinv_get_initial_invoice_total', $total, $this );
1384
-	}
1384
+    }
1385 1385
 
1386
-	/**
1387
-	 * Get the recurring invoice total.
1388
-	 *
1389
-	 * @since 1.0.19
1386
+    /**
1387
+     * Get the recurring invoice total.
1388
+     *
1389
+     * @since 1.0.19
1390 1390
      * @param  string $context View or edit context.
1391 1391
      * @return float
1392
-	 */
1392
+     */
1393 1393
     public function get_recurring_total() {
1394 1394
 
1395
-		if ( empty( $this->totals ) ) {
1396
-			$this->recalculate_total();
1397
-		}
1395
+        if ( empty( $this->totals ) ) {
1396
+            $this->recalculate_total();
1397
+        }
1398 1398
 
1399
-		$tax      = $this->totals['tax']['recurring'];
1400
-		$fee      = $this->totals['fee']['recurring'];
1401
-		$discount = $this->totals['discount']['recurring'];
1402
-		$subtotal = $this->totals['subtotal']['recurring'];
1403
-		$total    = $tax + $fee - $discount + $subtotal;
1399
+        $tax      = $this->totals['tax']['recurring'];
1400
+        $fee      = $this->totals['fee']['recurring'];
1401
+        $discount = $this->totals['discount']['recurring'];
1402
+        $subtotal = $this->totals['subtotal']['recurring'];
1403
+        $total    = $tax + $fee - $discount + $subtotal;
1404 1404
 
1405
-		if ( 0 > $total ) {
1406
-			$total = 0;
1407
-		}
1405
+        if ( 0 > $total ) {
1406
+            $total = 0;
1407
+        }
1408 1408
 
1409 1409
         return apply_filters( 'wpinv_get_recurring_invoice_total', $total, $this );
1410
-	}
1410
+    }
1411 1411
 
1412
-	/**
1413
-	 * Returns recurring payment details.
1414
-	 *
1415
-	 * @since 1.0.19
1412
+    /**
1413
+     * Returns recurring payment details.
1414
+     *
1415
+     * @since 1.0.19
1416 1416
      * @param  string $field Optionally provide a field to return.
1417
-	 * @param string $currency Whether to include the currency.
1417
+     * @param string $currency Whether to include the currency.
1418 1418
      * @return float
1419
-	 */
1419
+     */
1420 1420
     public function get_recurring_details( $field = '', $currency = false ) {
1421 1421
 
1422
-		// Maybe recalculate totals.
1423
-		if ( empty( $this->totals ) ) {
1424
-			$this->recalculate_total();
1425
-		}
1422
+        // Maybe recalculate totals.
1423
+        if ( empty( $this->totals ) ) {
1424
+            $this->recalculate_total();
1425
+        }
1426 1426
 
1427
-		// Prepare recurring totals.
1427
+        // Prepare recurring totals.
1428 1428
         $data = apply_filters(
1429
-			'wpinv_get_invoice_recurring_details',
1430
-			array(
1431
-				'cart_details' => $this->get_cart_details(),
1432
-				'subtotal'     => $this->totals['subtotal']['recurring'],
1433
-				'discount'     => $this->totals['discount']['recurring'],
1434
-				'tax'          => $this->totals['tax']['recurring'],
1435
-				'fee'          => $this->totals['fee']['recurring'],
1436
-				'total'        => $this->get_recurring_total(),
1437
-			),
1438
-			$this,
1439
-			$field,
1440
-			$currency
1441
-		);
1429
+            'wpinv_get_invoice_recurring_details',
1430
+            array(
1431
+                'cart_details' => $this->get_cart_details(),
1432
+                'subtotal'     => $this->totals['subtotal']['recurring'],
1433
+                'discount'     => $this->totals['discount']['recurring'],
1434
+                'tax'          => $this->totals['tax']['recurring'],
1435
+                'fee'          => $this->totals['fee']['recurring'],
1436
+                'total'        => $this->get_recurring_total(),
1437
+            ),
1438
+            $this,
1439
+            $field,
1440
+            $currency
1441
+        );
1442 1442
 
1443 1443
         if ( isset( $data[$field] ) ) {
1444 1444
             return ( $currency ? wpinv_price( $data[$field], $this->get_currency() ) : $data[$field] );
@@ -1448,145 +1448,145 @@  discard block
 block discarded – undo
1448 1448
     }
1449 1449
 
1450 1450
     /**
1451
-	 * Get the invoice fees.
1452
-	 *
1453
-	 * @since 1.0.19
1454
-	 * @param  string $context View or edit context.
1455
-	 * @return array
1456
-	 */
1457
-	public function get_fees( $context = 'view' ) {
1458
-		return wpinv_parse_list( $this->get_prop( 'fees', $context ) );
1451
+     * Get the invoice fees.
1452
+     *
1453
+     * @since 1.0.19
1454
+     * @param  string $context View or edit context.
1455
+     * @return array
1456
+     */
1457
+    public function get_fees( $context = 'view' ) {
1458
+        return wpinv_parse_list( $this->get_prop( 'fees', $context ) );
1459 1459
     }
1460 1460
 
1461 1461
     /**
1462
-	 * Get the invoice discounts.
1463
-	 *
1464
-	 * @since 1.0.19
1465
-	 * @param  string $context View or edit context.
1466
-	 * @return array
1467
-	 */
1468
-	public function get_discounts( $context = 'view' ) {
1469
-		return wpinv_parse_list( $this->get_prop( 'discounts', $context ) );
1462
+     * Get the invoice discounts.
1463
+     *
1464
+     * @since 1.0.19
1465
+     * @param  string $context View or edit context.
1466
+     * @return array
1467
+     */
1468
+    public function get_discounts( $context = 'view' ) {
1469
+        return wpinv_parse_list( $this->get_prop( 'discounts', $context ) );
1470 1470
     }
1471 1471
 
1472 1472
     /**
1473
-	 * Get the invoice taxes.
1474
-	 *
1475
-	 * @since 1.0.19
1476
-	 * @param  string $context View or edit context.
1477
-	 * @return array
1478
-	 */
1479
-	public function get_taxes( $context = 'view' ) {
1480
-		return wpinv_parse_list( $this->get_prop( 'taxes', $context ) );
1473
+     * Get the invoice taxes.
1474
+     *
1475
+     * @since 1.0.19
1476
+     * @param  string $context View or edit context.
1477
+     * @return array
1478
+     */
1479
+    public function get_taxes( $context = 'view' ) {
1480
+        return wpinv_parse_list( $this->get_prop( 'taxes', $context ) );
1481 1481
     }
1482 1482
 
1483 1483
     /**
1484
-	 * Get the invoice items.
1485
-	 *
1486
-	 * @since 1.0.19
1487
-	 * @param  string $context View or edit context.
1488
-	 * @return GetPaid_Form_Item[]
1489
-	 */
1490
-	public function get_items( $context = 'view' ) {
1484
+     * Get the invoice items.
1485
+     *
1486
+     * @since 1.0.19
1487
+     * @param  string $context View or edit context.
1488
+     * @return GetPaid_Form_Item[]
1489
+     */
1490
+    public function get_items( $context = 'view' ) {
1491 1491
         return $this->get_prop( 'items', $context );
1492 1492
     }
1493 1493
 
1494 1494
     /**
1495
-	 * Get the invoice's payment form.
1496
-	 *
1497
-	 * @since 1.0.19
1498
-	 * @param  string $context View or edit context.
1499
-	 * @return int
1500
-	 */
1501
-	public function get_payment_form( $context = 'view' ) {
1502
-		return intval( $this->get_prop( 'payment_form', $context ) );
1495
+     * Get the invoice's payment form.
1496
+     *
1497
+     * @since 1.0.19
1498
+     * @param  string $context View or edit context.
1499
+     * @return int
1500
+     */
1501
+    public function get_payment_form( $context = 'view' ) {
1502
+        return intval( $this->get_prop( 'payment_form', $context ) );
1503 1503
     }
1504 1504
 
1505 1505
     /**
1506
-	 * Get the invoice's submission id.
1507
-	 *
1508
-	 * @since 1.0.19
1509
-	 * @param  string $context View or edit context.
1510
-	 * @return string
1511
-	 */
1512
-	public function get_submission_id( $context = 'view' ) {
1513
-		return $this->get_prop( 'submission_id', $context );
1506
+     * Get the invoice's submission id.
1507
+     *
1508
+     * @since 1.0.19
1509
+     * @param  string $context View or edit context.
1510
+     * @return string
1511
+     */
1512
+    public function get_submission_id( $context = 'view' ) {
1513
+        return $this->get_prop( 'submission_id', $context );
1514 1514
     }
1515 1515
 
1516 1516
     /**
1517
-	 * Get the invoice's discount code.
1518
-	 *
1519
-	 * @since 1.0.19
1520
-	 * @param  string $context View or edit context.
1521
-	 * @return string
1522
-	 */
1523
-	public function get_discount_code( $context = 'view' ) {
1524
-		return $this->get_prop( 'discount_code', $context );
1517
+     * Get the invoice's discount code.
1518
+     *
1519
+     * @since 1.0.19
1520
+     * @param  string $context View or edit context.
1521
+     * @return string
1522
+     */
1523
+    public function get_discount_code( $context = 'view' ) {
1524
+        return $this->get_prop( 'discount_code', $context );
1525 1525
     }
1526 1526
 
1527 1527
     /**
1528
-	 * Get the invoice's gateway.
1529
-	 *
1530
-	 * @since 1.0.19
1531
-	 * @param  string $context View or edit context.
1532
-	 * @return string
1533
-	 */
1534
-	public function get_gateway( $context = 'view' ) {
1535
-		return $this->get_prop( 'gateway', $context );
1528
+     * Get the invoice's gateway.
1529
+     *
1530
+     * @since 1.0.19
1531
+     * @param  string $context View or edit context.
1532
+     * @return string
1533
+     */
1534
+    public function get_gateway( $context = 'view' ) {
1535
+        return $this->get_prop( 'gateway', $context );
1536 1536
     }
1537 1537
 
1538 1538
     /**
1539
-	 * Get the invoice's gateway display title.
1540
-	 *
1541
-	 * @since 1.0.19
1542
-	 * @return string
1543
-	 */
1539
+     * Get the invoice's gateway display title.
1540
+     *
1541
+     * @since 1.0.19
1542
+     * @return string
1543
+     */
1544 1544
     public function get_gateway_title() {
1545 1545
         $title =  wpinv_get_gateway_checkout_label( $this->get_gateway() );
1546 1546
         return apply_filters( 'wpinv_gateway_title', $title, $this->ID, $this );
1547 1547
     }
1548 1548
 
1549 1549
     /**
1550
-	 * Get the invoice's transaction id.
1551
-	 *
1552
-	 * @since 1.0.19
1553
-	 * @param  string $context View or edit context.
1554
-	 * @return string
1555
-	 */
1556
-	public function get_transaction_id( $context = 'view' ) {
1557
-		return $this->get_prop( 'transaction_id', $context );
1550
+     * Get the invoice's transaction id.
1551
+     *
1552
+     * @since 1.0.19
1553
+     * @param  string $context View or edit context.
1554
+     * @return string
1555
+     */
1556
+    public function get_transaction_id( $context = 'view' ) {
1557
+        return $this->get_prop( 'transaction_id', $context );
1558 1558
     }
1559 1559
 
1560 1560
     /**
1561
-	 * Get the invoice's currency.
1562
-	 *
1563
-	 * @since 1.0.19
1564
-	 * @param  string $context View or edit context.
1565
-	 * @return string
1566
-	 */
1567
-	public function get_currency( $context = 'view' ) {
1561
+     * Get the invoice's currency.
1562
+     *
1563
+     * @since 1.0.19
1564
+     * @param  string $context View or edit context.
1565
+     * @return string
1566
+     */
1567
+    public function get_currency( $context = 'view' ) {
1568 1568
         $currency = $this->get_prop( 'currency', $context );
1569 1569
         return empty( $currency ) ? wpinv_get_currency() : $currency;
1570 1570
     }
1571 1571
 
1572 1572
     /**
1573
-	 * Checks if we are charging taxes for this invoice.
1574
-	 *
1575
-	 * @since 1.0.19
1576
-	 * @param  string $context View or edit context.
1577
-	 * @return bool
1578
-	 */
1579
-	public function get_disable_taxes( $context = 'view' ) {
1573
+     * Checks if we are charging taxes for this invoice.
1574
+     *
1575
+     * @since 1.0.19
1576
+     * @param  string $context View or edit context.
1577
+     * @return bool
1578
+     */
1579
+    public function get_disable_taxes( $context = 'view' ) {
1580 1580
         return (bool) $this->get_prop( 'disable_taxes', $context );
1581 1581
     }
1582 1582
 
1583 1583
     /**
1584
-	 * Retrieves the subscription id for an invoice.
1585
-	 *
1586
-	 * @since 1.0.19
1587
-	 * @param  string $context View or edit context.
1588
-	 * @return int
1589
-	 */
1584
+     * Retrieves the subscription id for an invoice.
1585
+     *
1586
+     * @since 1.0.19
1587
+     * @param  string $context View or edit context.
1588
+     * @return int
1589
+     */
1590 1590
     public function get_subscription_id( $context = 'view' ) {
1591 1591
         $subscription_id = $this->get_prop( 'subscription_id', $context );
1592 1592
 
@@ -1599,12 +1599,12 @@  discard block
 block discarded – undo
1599 1599
     }
1600 1600
 
1601 1601
     /**
1602
-	 * Retrieves the payment meta for an invoice.
1603
-	 *
1604
-	 * @since 1.0.19
1605
-	 * @param  string $context View or edit context.
1606
-	 * @return array
1607
-	 */
1602
+     * Retrieves the payment meta for an invoice.
1603
+     *
1604
+     * @since 1.0.19
1605
+     * @param  string $context View or edit context.
1606
+     * @return array
1607
+     */
1608 1608
     public function get_payment_meta( $context = 'view' ) {
1609 1609
 
1610 1610
         return array(
@@ -1624,11 +1624,11 @@  discard block
 block discarded – undo
1624 1624
     }
1625 1625
 
1626 1626
     /**
1627
-	 * Retrieves the cart details for an invoice.
1628
-	 *
1629
-	 * @since 1.0.19
1630
-	 * @return array
1631
-	 */
1627
+     * Retrieves the cart details for an invoice.
1628
+     *
1629
+     * @since 1.0.19
1630
+     * @return array
1631
+     */
1632 1632
     public function get_cart_details() {
1633 1633
         $items        = $this->get_items();
1634 1634
         $cart_details = array();
@@ -1638,16 +1638,16 @@  discard block
 block discarded – undo
1638 1638
         }
1639 1639
 
1640 1640
         return $cart_details;
1641
-	}
1641
+    }
1642 1642
 
1643
-	/**
1644
-	 * Retrieves the recurring item.
1645
-	 *
1646
-	 * @return null|GetPaid_Form_Item
1647
-	 */
1648
-	public function get_recurring( $object = false ) {
1643
+    /**
1644
+     * Retrieves the recurring item.
1645
+     *
1646
+     * @return null|GetPaid_Form_Item
1647
+     */
1648
+    public function get_recurring( $object = false ) {
1649 1649
 
1650
-		// Are we returning an object?
1650
+        // Are we returning an object?
1651 1651
         if ( $object ) {
1652 1652
             return $this->get_item( $this->recurring_item );
1653 1653
         }
@@ -1655,58 +1655,58 @@  discard block
 block discarded – undo
1655 1655
         return $this->recurring_item;
1656 1656
     }
1657 1657
 
1658
-	/**
1659
-	 * Retrieves the subscription name.
1660
-	 *
1661
-	 * @since 1.0.19
1662
-	 * @return string
1663
-	 */
1664
-	public function get_subscription_name() {
1658
+    /**
1659
+     * Retrieves the subscription name.
1660
+     *
1661
+     * @since 1.0.19
1662
+     * @return string
1663
+     */
1664
+    public function get_subscription_name() {
1665 1665
 
1666
-		// Retrieve the recurring name
1666
+        // Retrieve the recurring name
1667 1667
         $item = $this->get_recurring( true );
1668 1668
 
1669
-		// Abort if it does not exist.
1669
+        // Abort if it does not exist.
1670 1670
         if ( empty( $item ) ) {
1671 1671
             return '';
1672 1672
         }
1673 1673
 
1674
-		// Return the item name.
1674
+        // Return the item name.
1675 1675
         return apply_filters( 'wpinv_invoice_get_subscription_name', $item->get_name(), $this );
1676
-	}
1677
-
1678
-	/**
1679
-	 * Retrieves the view url.
1680
-	 *
1681
-	 * @since 1.0.19
1682
-	 * @return string
1683
-	 */
1684
-	public function get_view_url() {
1676
+    }
1677
+
1678
+    /**
1679
+     * Retrieves the view url.
1680
+     *
1681
+     * @since 1.0.19
1682
+     * @return string
1683
+     */
1684
+    public function get_view_url() {
1685 1685
         $invoice_url = get_permalink( $this->get_id() );
1686
-		$invoice_url = add_query_arg( 'invoice_key', $this->get_key(), $invoice_url );
1686
+        $invoice_url = add_query_arg( 'invoice_key', $this->get_key(), $invoice_url );
1687 1687
         return apply_filters( 'wpinv_get_view_url', $invoice_url, $this );
1688
-	}
1688
+    }
1689 1689
 
1690
-	/**
1691
-	 * Retrieves the payment url.
1692
-	 *
1693
-	 * @since 1.0.19
1694
-	 * @return string
1695
-	 */
1696
-	public function get_checkout_payment_url( $deprecated = false, $secret = false ) {
1690
+    /**
1691
+     * Retrieves the payment url.
1692
+     *
1693
+     * @since 1.0.19
1694
+     * @return string
1695
+     */
1696
+    public function get_checkout_payment_url( $deprecated = false, $secret = false ) {
1697 1697
 
1698
-		// Retrieve the checkout url.
1698
+        // Retrieve the checkout url.
1699 1699
         $pay_url = wpinv_get_checkout_uri();
1700 1700
 
1701
-		// Maybe force ssl.
1701
+        // Maybe force ssl.
1702 1702
         if ( is_ssl() ) {
1703 1703
             $pay_url = str_replace( 'http:', 'https:', $pay_url );
1704 1704
         }
1705 1705
 
1706
-		// Add the invoice key.
1707
-		$pay_url = add_query_arg( 'invoice_key', $this->get_key(), $pay_url );
1706
+        // Add the invoice key.
1707
+        $pay_url = add_query_arg( 'invoice_key', $this->get_key(), $pay_url );
1708 1708
 
1709
-		// (Maybe?) add a secret
1709
+        // (Maybe?) add a secret
1710 1710
         if ( $secret ) {
1711 1711
             $pay_url = add_query_arg( array( '_wpipay' => md5( $this->get_user_id() . '::' . $this->get_email() . '::' . $this->get_key() ) ), $pay_url );
1712 1712
         }
@@ -1715,18 +1715,18 @@  discard block
 block discarded – undo
1715 1715
     }
1716 1716
 
1717 1717
     /**
1718
-	 * Magic method for accessing invoice properties.
1719
-	 *
1720
-	 * @since 1.0.15
1721
-	 * @access public
1722
-	 *
1723
-	 * @param string $key Discount data to retrieve
1724
-	 * @param  string $context View or edit context.
1725
-	 * @return mixed Value of the given invoice property (if set).
1726
-	 */
1727
-	public function get( $key, $context = 'view' ) {
1718
+     * Magic method for accessing invoice properties.
1719
+     *
1720
+     * @since 1.0.15
1721
+     * @access public
1722
+     *
1723
+     * @param string $key Discount data to retrieve
1724
+     * @param  string $context View or edit context.
1725
+     * @return mixed Value of the given invoice property (if set).
1726
+     */
1727
+    public function get( $key, $context = 'view' ) {
1728 1728
         return $this->get_prop( $key, $context );
1729
-	}
1729
+    }
1730 1730
 
1731 1731
     /*
1732 1732
 	|--------------------------------------------------------------------------
@@ -1739,118 +1739,118 @@  discard block
 block discarded – undo
1739 1739
     */
1740 1740
 
1741 1741
     /**
1742
-	 * Magic method for setting invoice properties.
1743
-	 *
1744
-	 * @since 1.0.19
1745
-	 * @access public
1746
-	 *
1747
-	 * @param string $key Discount data to retrieve
1748
-	 * @param  mixed $value new value.
1749
-	 * @return mixed Value of the given invoice property (if set).
1750
-	 */
1751
-	public function set( $key, $value ) {
1742
+     * Magic method for setting invoice properties.
1743
+     *
1744
+     * @since 1.0.19
1745
+     * @access public
1746
+     *
1747
+     * @param string $key Discount data to retrieve
1748
+     * @param  mixed $value new value.
1749
+     * @return mixed Value of the given invoice property (if set).
1750
+     */
1751
+    public function set( $key, $value ) {
1752 1752
 
1753 1753
         $setter = "set_$key";
1754 1754
         if ( is_callable( array( $this, $setter ) ) ) {
1755 1755
             $this->{$setter}( $value );
1756 1756
         }
1757 1757
 
1758
-	}
1759
-
1760
-	/**
1761
-	 * Sets item status.
1762
-	 *
1763
-	 * @since 1.0.19
1764
-	 * @param string $new_status    New status.
1765
-	 * @param string $note          Optional note to add.
1766
-	 * @param bool   $manual_update Is this a manual status change?.
1767
-	 * @return array details of change.
1768
-	 */
1769
-	public function set_status( $new_status, $note = '', $manual_update = false ) {
1770
-		$old_status = $this->get_status();
1771
-
1772
-		$this->set_prop( 'status', $new_status );
1773
-
1774
-		// If setting the status, ensure it's set to a valid status.
1775
-		if ( true === $this->object_read ) {
1776
-
1777
-			// Only allow valid new status.
1778
-			if ( ! array_key_exists( $new_status, wpinv_get_invoice_statuses( false, true ) ) ) {
1779
-				$new_status = 'wpi-pending';
1780
-			}
1781
-
1782
-			// If the old status is set but unknown (e.g. draft) assume its pending for action usage.
1783
-			if ( $old_status && ! array_key_exists( $new_status, wpinv_get_invoice_statuses( false, true ) ) ) {
1784
-				$old_status = 'wpi-pending';
1785
-			}
1786
-		}
1787
-
1788
-		if ( true === $this->object_read && $old_status !== $new_status ) {
1789
-			$this->status_transition = array(
1790
-				'from'   => ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $old_status,
1791
-				'to'     => $new_status,
1792
-				'note'   => $note,
1793
-				'manual' => (bool) $manual_update,
1794
-			);
1795
-
1796
-			if ( $manual_update ) {
1797
-				do_action( 'getpaid_' . $this->object_type .'_edit_status', $this->get_id(), $new_status );
1798
-			}
1799
-
1800
-			$this->maybe_set_date_paid();
1801
-
1802
-		}
1803
-
1804
-		return array(
1805
-			'from' => $old_status,
1806
-			'to'   => $new_status,
1807
-		);
1808
-	}
1809
-
1810
-	/**
1811
-	 * Maybe set date paid.
1812
-	 *
1813
-	 * Sets the date paid variable when transitioning to the payment complete
1814
-	 * order status.
1815
-	 *
1816
-	 * @since 1.0.19
1817
-	 */
1818
-	public function maybe_set_date_paid() {
1819
-
1820
-		if ( ! $this->get_date_completed( 'edit' ) && $this->is_paid() ) {
1821
-			$this->set_date_completed( current_time( 'mysql' ) );
1822
-		}
1823
-	}
1824
-
1825
-    /**
1826
-	 * Set parent invoice ID.
1827
-	 *
1828
-	 * @since 1.0.19
1829
-	 */
1830
-	public function set_parent_id( $value ) {
1831
-		if ( $value && ( $value === $this->get_id() || ! get_post( $value ) ) ) {
1832
-			return;
1833
-		}
1834
-		$this->set_prop( 'parent_id', absint( $value ) );
1835
-    }
1836
-
1837
-    /**
1838
-	 * Set plugin version when the invoice was created.
1839
-	 *
1840
-	 * @since 1.0.19
1841
-	 */
1842
-	public function set_version( $value ) {
1843
-		$this->set_prop( 'version', $value );
1844
-    }
1845
-
1846
-    /**
1847
-	 * Set date when the invoice was created.
1848
-	 *
1849
-	 * @since 1.0.19
1850
-	 * @param string $value Value to set.
1758
+    }
1759
+
1760
+    /**
1761
+     * Sets item status.
1762
+     *
1763
+     * @since 1.0.19
1764
+     * @param string $new_status    New status.
1765
+     * @param string $note          Optional note to add.
1766
+     * @param bool   $manual_update Is this a manual status change?.
1767
+     * @return array details of change.
1768
+     */
1769
+    public function set_status( $new_status, $note = '', $manual_update = false ) {
1770
+        $old_status = $this->get_status();
1771
+
1772
+        $this->set_prop( 'status', $new_status );
1773
+
1774
+        // If setting the status, ensure it's set to a valid status.
1775
+        if ( true === $this->object_read ) {
1776
+
1777
+            // Only allow valid new status.
1778
+            if ( ! array_key_exists( $new_status, wpinv_get_invoice_statuses( false, true ) ) ) {
1779
+                $new_status = 'wpi-pending';
1780
+            }
1781
+
1782
+            // If the old status is set but unknown (e.g. draft) assume its pending for action usage.
1783
+            if ( $old_status && ! array_key_exists( $new_status, wpinv_get_invoice_statuses( false, true ) ) ) {
1784
+                $old_status = 'wpi-pending';
1785
+            }
1786
+        }
1787
+
1788
+        if ( true === $this->object_read && $old_status !== $new_status ) {
1789
+            $this->status_transition = array(
1790
+                'from'   => ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $old_status,
1791
+                'to'     => $new_status,
1792
+                'note'   => $note,
1793
+                'manual' => (bool) $manual_update,
1794
+            );
1795
+
1796
+            if ( $manual_update ) {
1797
+                do_action( 'getpaid_' . $this->object_type .'_edit_status', $this->get_id(), $new_status );
1798
+            }
1799
+
1800
+            $this->maybe_set_date_paid();
1801
+
1802
+        }
1803
+
1804
+        return array(
1805
+            'from' => $old_status,
1806
+            'to'   => $new_status,
1807
+        );
1808
+    }
1809
+
1810
+    /**
1811
+     * Maybe set date paid.
1812
+     *
1813
+     * Sets the date paid variable when transitioning to the payment complete
1814
+     * order status.
1815
+     *
1816
+     * @since 1.0.19
1817
+     */
1818
+    public function maybe_set_date_paid() {
1819
+
1820
+        if ( ! $this->get_date_completed( 'edit' ) && $this->is_paid() ) {
1821
+            $this->set_date_completed( current_time( 'mysql' ) );
1822
+        }
1823
+    }
1824
+
1825
+    /**
1826
+     * Set parent invoice ID.
1827
+     *
1828
+     * @since 1.0.19
1829
+     */
1830
+    public function set_parent_id( $value ) {
1831
+        if ( $value && ( $value === $this->get_id() || ! get_post( $value ) ) ) {
1832
+            return;
1833
+        }
1834
+        $this->set_prop( 'parent_id', absint( $value ) );
1835
+    }
1836
+
1837
+    /**
1838
+     * Set plugin version when the invoice was created.
1839
+     *
1840
+     * @since 1.0.19
1841
+     */
1842
+    public function set_version( $value ) {
1843
+        $this->set_prop( 'version', $value );
1844
+    }
1845
+
1846
+    /**
1847
+     * Set date when the invoice was created.
1848
+     *
1849
+     * @since 1.0.19
1850
+     * @param string $value Value to set.
1851 1851
      * @return bool Whether or not the date was set.
1852
-	 */
1853
-	public function set_date_created( $value ) {
1852
+     */
1853
+    public function set_date_created( $value ) {
1854 1854
         $date = strtotime( $value );
1855 1855
 
1856 1856
         if ( $date && $date !== '0000-00-00 00:00:00' ) {
@@ -1863,13 +1863,13 @@  discard block
 block discarded – undo
1863 1863
     }
1864 1864
 
1865 1865
     /**
1866
-	 * Set date invoice due date.
1867
-	 *
1868
-	 * @since 1.0.19
1869
-	 * @param string $value Value to set.
1866
+     * Set date invoice due date.
1867
+     *
1868
+     * @since 1.0.19
1869
+     * @param string $value Value to set.
1870 1870
      * @return bool Whether or not the date was set.
1871
-	 */
1872
-	public function set_due_date( $value ) {
1871
+     */
1872
+    public function set_due_date( $value ) {
1873 1873
         $date = strtotime( $value );
1874 1874
 
1875 1875
         if ( $date && $date !== '0000-00-00 00:00:00' ) {
@@ -1877,29 +1877,29 @@  discard block
 block discarded – undo
1877 1877
             return true;
1878 1878
         }
1879 1879
 
1880
-		$this->set_prop( 'due_date', '' );
1880
+        $this->set_prop( 'due_date', '' );
1881 1881
         return false;
1882 1882
 
1883 1883
     }
1884 1884
 
1885 1885
     /**
1886
-	 * Alias of self::set_due_date().
1887
-	 *
1888
-	 * @since 1.0.19
1889
-	 * @param  string $value New name.
1890
-	 */
1891
-	public function set_date_due( $value ) {
1892
-		$this->set_due_date( $value );
1886
+     * Alias of self::set_due_date().
1887
+     *
1888
+     * @since 1.0.19
1889
+     * @param  string $value New name.
1890
+     */
1891
+    public function set_date_due( $value ) {
1892
+        $this->set_due_date( $value );
1893 1893
     }
1894 1894
 
1895 1895
     /**
1896
-	 * Set date invoice was completed.
1897
-	 *
1898
-	 * @since 1.0.19
1899
-	 * @param string $value Value to set.
1896
+     * Set date invoice was completed.
1897
+     *
1898
+     * @since 1.0.19
1899
+     * @param string $value Value to set.
1900 1900
      * @return bool Whether or not the date was set.
1901
-	 */
1902
-	public function set_completed_date( $value ) {
1901
+     */
1902
+    public function set_completed_date( $value ) {
1903 1903
         $date = strtotime( $value );
1904 1904
 
1905 1905
         if ( $date && $date !== '0000-00-00 00:00:00'  ) {
@@ -1907,29 +1907,29 @@  discard block
 block discarded – undo
1907 1907
             return true;
1908 1908
         }
1909 1909
 
1910
-		$this->set_prop( 'completed_date', '' );
1910
+        $this->set_prop( 'completed_date', '' );
1911 1911
         return false;
1912 1912
 
1913 1913
     }
1914 1914
 
1915 1915
     /**
1916
-	 * Alias of self::set_completed_date().
1917
-	 *
1918
-	 * @since 1.0.19
1919
-	 * @param  string $value New name.
1920
-	 */
1921
-	public function set_date_completed( $value ) {
1922
-		$this->set_completed_date( $value );
1916
+     * Alias of self::set_completed_date().
1917
+     *
1918
+     * @since 1.0.19
1919
+     * @param  string $value New name.
1920
+     */
1921
+    public function set_date_completed( $value ) {
1922
+        $this->set_completed_date( $value );
1923 1923
     }
1924 1924
 
1925 1925
     /**
1926
-	 * Set date when the invoice was last modified.
1927
-	 *
1928
-	 * @since 1.0.19
1929
-	 * @param string $value Value to set.
1926
+     * Set date when the invoice was last modified.
1927
+     *
1928
+     * @since 1.0.19
1929
+     * @param string $value Value to set.
1930 1930
      * @return bool Whether or not the date was set.
1931
-	 */
1932
-	public function set_date_modified( $value ) {
1931
+     */
1932
+    public function set_date_modified( $value ) {
1933 1933
         $date = strtotime( $value );
1934 1934
 
1935 1935
         if ( $date && $date !== '0000-00-00 00:00:00' ) {
@@ -1937,699 +1937,699 @@  discard block
 block discarded – undo
1937 1937
             return true;
1938 1938
         }
1939 1939
 
1940
-		$this->set_prop( 'date_modified', '' );
1940
+        $this->set_prop( 'date_modified', '' );
1941 1941
         return false;
1942 1942
 
1943 1943
     }
1944 1944
 
1945 1945
     /**
1946
-	 * Set the invoice number.
1947
-	 *
1948
-	 * @since 1.0.19
1949
-	 * @param  string $value New number.
1950
-	 */
1951
-	public function set_number( $value ) {
1946
+     * Set the invoice number.
1947
+     *
1948
+     * @since 1.0.19
1949
+     * @param  string $value New number.
1950
+     */
1951
+    public function set_number( $value ) {
1952 1952
         $number = sanitize_text_field( $value );
1953
-		$this->set_prop( 'number', $number );
1953
+        $this->set_prop( 'number', $number );
1954 1954
     }
1955 1955
 
1956 1956
     /**
1957
-	 * Set the invoice type.
1958
-	 *
1959
-	 * @since 1.0.19
1960
-	 * @param  string $value Type.
1961
-	 */
1962
-	public function set_type( $value ) {
1957
+     * Set the invoice type.
1958
+     *
1959
+     * @since 1.0.19
1960
+     * @param  string $value Type.
1961
+     */
1962
+    public function set_type( $value ) {
1963 1963
         $type = sanitize_text_field( str_replace( 'wpi_', '', $value ) );
1964
-		$this->set_prop( 'type', $type );
1964
+        $this->set_prop( 'type', $type );
1965 1965
     }
1966 1966
 
1967 1967
     /**
1968
-	 * Set the invoice post type.
1969
-	 *
1970
-	 * @since 1.0.19
1971
-	 * @param  string $value Post type.
1972
-	 */
1973
-	public function set_post_type( $value ) {
1968
+     * Set the invoice post type.
1969
+     *
1970
+     * @since 1.0.19
1971
+     * @param  string $value Post type.
1972
+     */
1973
+    public function set_post_type( $value ) {
1974 1974
         if ( getpaid_is_invoice_post_type( $value ) ) {
1975 1975
             $this->set_prop( 'post_type', $value );
1976 1976
         }
1977 1977
     }
1978 1978
 
1979 1979
     /**
1980
-	 * Set the invoice key.
1981
-	 *
1982
-	 * @since 1.0.19
1983
-	 * @param  string $value New key.
1984
-	 */
1985
-	public function set_key( $value ) {
1980
+     * Set the invoice key.
1981
+     *
1982
+     * @since 1.0.19
1983
+     * @param  string $value New key.
1984
+     */
1985
+    public function set_key( $value ) {
1986 1986
         $key = sanitize_text_field( $value );
1987
-		$this->set_prop( 'key', $key );
1987
+        $this->set_prop( 'key', $key );
1988 1988
     }
1989 1989
 
1990 1990
     /**
1991
-	 * Set the invoice mode.
1992
-	 *
1993
-	 * @since 1.0.19
1994
-	 * @param  string $value mode.
1995
-	 */
1996
-	public function set_mode( $value ) {
1991
+     * Set the invoice mode.
1992
+     *
1993
+     * @since 1.0.19
1994
+     * @param  string $value mode.
1995
+     */
1996
+    public function set_mode( $value ) {
1997 1997
         if ( ! in_array( $value, array( 'live', 'test' ) ) ) {
1998 1998
             $this->set_prop( 'value', $value );
1999 1999
         }
2000 2000
     }
2001 2001
 
2002 2002
     /**
2003
-	 * Set the invoice path.
2004
-	 *
2005
-	 * @since 1.0.19
2006
-	 * @param  string $value path.
2007
-	 */
2008
-	public function set_path( $value ) {
2003
+     * Set the invoice path.
2004
+     *
2005
+     * @since 1.0.19
2006
+     * @param  string $value path.
2007
+     */
2008
+    public function set_path( $value ) {
2009 2009
         $this->set_prop( 'path', $value );
2010 2010
     }
2011 2011
 
2012 2012
     /**
2013
-	 * Set the invoice name.
2014
-	 *
2015
-	 * @since 1.0.19
2016
-	 * @param  string $value New name.
2017
-	 */
2018
-	public function set_name( $value ) {
2019
-        $name = sanitize_text_field( $value );
2020
-		$this->set_prop( 'name', $name );
2013
+     * Set the invoice name.
2014
+     *
2015
+     * @since 1.0.19
2016
+     * @param  string $value New name.
2017
+     */
2018
+    public function set_name( $value ) {
2019
+        $name = sanitize_text_field( $value );
2020
+        $this->set_prop( 'name', $name );
2021
+    }
2022
+
2023
+    /**
2024
+     * Alias of self::set_name().
2025
+     *
2026
+     * @since 1.0.19
2027
+     * @param  string $value New name.
2028
+     */
2029
+    public function set_title( $value ) {
2030
+        $this->set_name( $value );
2031
+    }
2032
+
2033
+    /**
2034
+     * Set the invoice description.
2035
+     *
2036
+     * @since 1.0.19
2037
+     * @param  string $value New description.
2038
+     */
2039
+    public function set_description( $value ) {
2040
+        $description = wp_kses_post( $value );
2041
+        return $this->set_prop( 'description', $description );
2042
+    }
2043
+
2044
+    /**
2045
+     * Alias of self::set_description().
2046
+     *
2047
+     * @since 1.0.19
2048
+     * @param  string $value New description.
2049
+     */
2050
+    public function set_excerpt( $value ) {
2051
+        $this->set_description( $value );
2021 2052
     }
2022 2053
 
2023 2054
     /**
2024
-	 * Alias of self::set_name().
2025
-	 *
2026
-	 * @since 1.0.19
2027
-	 * @param  string $value New name.
2028
-	 */
2029
-	public function set_title( $value ) {
2030
-		$this->set_name( $value );
2055
+     * Alias of self::set_description().
2056
+     *
2057
+     * @since 1.0.19
2058
+     * @param  string $value New description.
2059
+     */
2060
+    public function set_summary( $value ) {
2061
+        $this->set_description( $value );
2031 2062
     }
2032 2063
 
2033 2064
     /**
2034
-	 * Set the invoice description.
2035
-	 *
2036
-	 * @since 1.0.19
2037
-	 * @param  string $value New description.
2038
-	 */
2039
-	public function set_description( $value ) {
2040
-        $description = wp_kses_post( $value );
2041
-		return $this->set_prop( 'description', $description );
2065
+     * Set the receiver of the invoice.
2066
+     *
2067
+     * @since 1.0.19
2068
+     * @param  int $value New author.
2069
+     */
2070
+    public function set_author( $value ) {
2071
+        $this->set_prop( 'author', (int) $value );
2042 2072
     }
2043 2073
 
2044 2074
     /**
2045
-	 * Alias of self::set_description().
2046
-	 *
2047
-	 * @since 1.0.19
2048
-	 * @param  string $value New description.
2049
-	 */
2050
-	public function set_excerpt( $value ) {
2051
-		$this->set_description( $value );
2075
+     * Alias of self::set_author().
2076
+     *
2077
+     * @since 1.0.19
2078
+     * @param  int $value New user id.
2079
+     */
2080
+    public function set_user_id( $value ) {
2081
+        $this->set_author( $value );
2052 2082
     }
2053 2083
 
2054 2084
     /**
2055
-	 * Alias of self::set_description().
2056
-	 *
2057
-	 * @since 1.0.19
2058
-	 * @param  string $value New description.
2059
-	 */
2060
-	public function set_summary( $value ) {
2061
-		$this->set_description( $value );
2085
+     * Alias of self::set_author().
2086
+     *
2087
+     * @since 1.0.19
2088
+     * @param  int $value New user id.
2089
+     */
2090
+    public function set_customer_id( $value ) {
2091
+        $this->set_author( $value );
2062 2092
     }
2063 2093
 
2064 2094
     /**
2065
-	 * Set the receiver of the invoice.
2066
-	 *
2067
-	 * @since 1.0.19
2068
-	 * @param  int $value New author.
2069
-	 */
2070
-	public function set_author( $value ) {
2071
-		$this->set_prop( 'author', (int) $value );
2095
+     * Set the customer's ip.
2096
+     *
2097
+     * @since 1.0.19
2098
+     * @param  string $value ip address.
2099
+     */
2100
+    public function set_ip( $value ) {
2101
+        $this->set_prop( 'ip', $value );
2072 2102
     }
2073 2103
 
2074 2104
     /**
2075
-	 * Alias of self::set_author().
2076
-	 *
2077
-	 * @since 1.0.19
2078
-	 * @param  int $value New user id.
2079
-	 */
2080
-	public function set_user_id( $value ) {
2081
-		$this->set_author( $value );
2105
+     * Alias of self::set_ip().
2106
+     *
2107
+     * @since 1.0.19
2108
+     * @param  string $value ip address.
2109
+     */
2110
+    public function set_user_ip( $value ) {
2111
+        $this->set_ip( $value );
2082 2112
     }
2083 2113
 
2084 2114
     /**
2085
-	 * Alias of self::set_author().
2086
-	 *
2087
-	 * @since 1.0.19
2088
-	 * @param  int $value New user id.
2089
-	 */
2090
-	public function set_customer_id( $value ) {
2091
-		$this->set_author( $value );
2115
+     * Set the customer's first name.
2116
+     *
2117
+     * @since 1.0.19
2118
+     * @param  string $value first name.
2119
+     */
2120
+    public function set_first_name( $value ) {
2121
+        $this->set_prop( 'first_name', $value );
2092 2122
     }
2093 2123
 
2094 2124
     /**
2095
-	 * Set the customer's ip.
2096
-	 *
2097
-	 * @since 1.0.19
2098
-	 * @param  string $value ip address.
2099
-	 */
2100
-	public function set_ip( $value ) {
2101
-		$this->set_prop( 'ip', $value );
2125
+     * Alias of self::set_first_name().
2126
+     *
2127
+     * @since 1.0.19
2128
+     * @param  string $value first name.
2129
+     */
2130
+    public function set_user_first_name( $value ) {
2131
+        $this->set_first_name( $value );
2102 2132
     }
2103 2133
 
2104 2134
     /**
2105
-	 * Alias of self::set_ip().
2106
-	 *
2107
-	 * @since 1.0.19
2108
-	 * @param  string $value ip address.
2109
-	 */
2110
-	public function set_user_ip( $value ) {
2111
-		$this->set_ip( $value );
2135
+     * Alias of self::set_first_name().
2136
+     *
2137
+     * @since 1.0.19
2138
+     * @param  string $value first name.
2139
+     */
2140
+    public function set_customer_first_name( $value ) {
2141
+        $this->set_first_name( $value );
2112 2142
     }
2113 2143
 
2114 2144
     /**
2115
-	 * Set the customer's first name.
2116
-	 *
2117
-	 * @since 1.0.19
2118
-	 * @param  string $value first name.
2119
-	 */
2120
-	public function set_first_name( $value ) {
2121
-		$this->set_prop( 'first_name', $value );
2145
+     * Set the customer's last name.
2146
+     *
2147
+     * @since 1.0.19
2148
+     * @param  string $value last name.
2149
+     */
2150
+    public function set_last_name( $value ) {
2151
+        $this->set_prop( 'last_name', $value );
2122 2152
     }
2123 2153
 
2124 2154
     /**
2125
-	 * Alias of self::set_first_name().
2126
-	 *
2127
-	 * @since 1.0.19
2128
-	 * @param  string $value first name.
2129
-	 */
2130
-	public function set_user_first_name( $value ) {
2131
-		$this->set_first_name( $value );
2155
+     * Alias of self::set_last_name().
2156
+     *
2157
+     * @since 1.0.19
2158
+     * @param  string $value last name.
2159
+     */
2160
+    public function set_user_last_name( $value ) {
2161
+        $this->set_last_name( $value );
2132 2162
     }
2133 2163
 
2134 2164
     /**
2135
-	 * Alias of self::set_first_name().
2136
-	 *
2137
-	 * @since 1.0.19
2138
-	 * @param  string $value first name.
2139
-	 */
2140
-	public function set_customer_first_name( $value ) {
2141
-		$this->set_first_name( $value );
2165
+     * Alias of self::set_last_name().
2166
+     *
2167
+     * @since 1.0.19
2168
+     * @param  string $value last name.
2169
+     */
2170
+    public function set_customer_last_name( $value ) {
2171
+        $this->set_last_name( $value );
2142 2172
     }
2143 2173
 
2144 2174
     /**
2145
-	 * Set the customer's last name.
2146
-	 *
2147
-	 * @since 1.0.19
2148
-	 * @param  string $value last name.
2149
-	 */
2150
-	public function set_last_name( $value ) {
2151
-		$this->set_prop( 'last_name', $value );
2175
+     * Set the customer's phone number.
2176
+     *
2177
+     * @since 1.0.19
2178
+     * @param  string $value phone.
2179
+     */
2180
+    public function set_phone( $value ) {
2181
+        $this->set_prop( 'phone', $value );
2152 2182
     }
2153 2183
 
2154 2184
     /**
2155
-	 * Alias of self::set_last_name().
2156
-	 *
2157
-	 * @since 1.0.19
2158
-	 * @param  string $value last name.
2159
-	 */
2160
-	public function set_user_last_name( $value ) {
2161
-		$this->set_last_name( $value );
2185
+     * Alias of self::set_phone().
2186
+     *
2187
+     * @since 1.0.19
2188
+     * @param  string $value phone.
2189
+     */
2190
+    public function set_user_phone( $value ) {
2191
+        $this->set_phone( $value );
2162 2192
     }
2163 2193
 
2164 2194
     /**
2165
-	 * Alias of self::set_last_name().
2166
-	 *
2167
-	 * @since 1.0.19
2168
-	 * @param  string $value last name.
2169
-	 */
2170
-	public function set_customer_last_name( $value ) {
2171
-		$this->set_last_name( $value );
2195
+     * Alias of self::set_phone().
2196
+     *
2197
+     * @since 1.0.19
2198
+     * @param  string $value phone.
2199
+     */
2200
+    public function set_customer_phone( $value ) {
2201
+        $this->set_phone( $value );
2172 2202
     }
2173 2203
 
2174 2204
     /**
2175
-	 * Set the customer's phone number.
2176
-	 *
2177
-	 * @since 1.0.19
2178
-	 * @param  string $value phone.
2179
-	 */
2180
-	public function set_phone( $value ) {
2181
-		$this->set_prop( 'phone', $value );
2205
+     * Alias of self::set_phone().
2206
+     *
2207
+     * @since 1.0.19
2208
+     * @param  string $value phone.
2209
+     */
2210
+    public function set_phone_number( $value ) {
2211
+        $this->set_phone( $value );
2182 2212
     }
2183 2213
 
2184 2214
     /**
2185
-	 * Alias of self::set_phone().
2186
-	 *
2187
-	 * @since 1.0.19
2188
-	 * @param  string $value phone.
2189
-	 */
2190
-	public function set_user_phone( $value ) {
2191
-		$this->set_phone( $value );
2215
+     * Set the customer's email address.
2216
+     *
2217
+     * @since 1.0.19
2218
+     * @param  string $value email address.
2219
+     */
2220
+    public function set_email( $value ) {
2221
+        $this->set_prop( 'email', $value );
2192 2222
     }
2193 2223
 
2194 2224
     /**
2195
-	 * Alias of self::set_phone().
2196
-	 *
2197
-	 * @since 1.0.19
2198
-	 * @param  string $value phone.
2199
-	 */
2200
-	public function set_customer_phone( $value ) {
2201
-		$this->set_phone( $value );
2225
+     * Alias of self::set_email().
2226
+     *
2227
+     * @since 1.0.19
2228
+     * @param  string $value email address.
2229
+     */
2230
+    public function set_user_email( $value ) {
2231
+        $this->set_email( $value );
2202 2232
     }
2203 2233
 
2204 2234
     /**
2205
-	 * Alias of self::set_phone().
2206
-	 *
2207
-	 * @since 1.0.19
2208
-	 * @param  string $value phone.
2209
-	 */
2210
-	public function set_phone_number( $value ) {
2211
-		$this->set_phone( $value );
2235
+     * Alias of self::set_email().
2236
+     *
2237
+     * @since 1.0.19
2238
+     * @param  string $value email address.
2239
+     */
2240
+    public function set_email_address( $value ) {
2241
+        $this->set_email( $value );
2212 2242
     }
2213 2243
 
2214 2244
     /**
2215
-	 * Set the customer's email address.
2216
-	 *
2217
-	 * @since 1.0.19
2218
-	 * @param  string $value email address.
2219
-	 */
2220
-	public function set_email( $value ) {
2221
-		$this->set_prop( 'email', $value );
2245
+     * Alias of self::set_email().
2246
+     *
2247
+     * @since 1.0.19
2248
+     * @param  string $value email address.
2249
+     */
2250
+    public function set_customer_email( $value ) {
2251
+        $this->set_email( $value );
2222 2252
     }
2223 2253
 
2224 2254
     /**
2225
-	 * Alias of self::set_email().
2226
-	 *
2227
-	 * @since 1.0.19
2228
-	 * @param  string $value email address.
2229
-	 */
2230
-	public function set_user_email( $value ) {
2231
-		$this->set_email( $value );
2255
+     * Set the customer's country.
2256
+     *
2257
+     * @since 1.0.19
2258
+     * @param  string $value country.
2259
+     */
2260
+    public function set_country( $value ) {
2261
+        $this->set_prop( 'country', $value );
2232 2262
     }
2233 2263
 
2234 2264
     /**
2235
-	 * Alias of self::set_email().
2236
-	 *
2237
-	 * @since 1.0.19
2238
-	 * @param  string $value email address.
2239
-	 */
2240
-	public function set_email_address( $value ) {
2241
-		$this->set_email( $value );
2265
+     * Alias of self::set_country().
2266
+     *
2267
+     * @since 1.0.19
2268
+     * @param  string $value country.
2269
+     */
2270
+    public function set_user_country( $value ) {
2271
+        $this->set_country( $value );
2242 2272
     }
2243 2273
 
2244 2274
     /**
2245
-	 * Alias of self::set_email().
2246
-	 *
2247
-	 * @since 1.0.19
2248
-	 * @param  string $value email address.
2249
-	 */
2250
-	public function set_customer_email( $value ) {
2251
-		$this->set_email( $value );
2275
+     * Alias of self::set_country().
2276
+     *
2277
+     * @since 1.0.19
2278
+     * @param  string $value country.
2279
+     */
2280
+    public function set_customer_country( $value ) {
2281
+        $this->set_country( $value );
2252 2282
     }
2253 2283
 
2254 2284
     /**
2255
-	 * Set the customer's country.
2256
-	 *
2257
-	 * @since 1.0.19
2258
-	 * @param  string $value country.
2259
-	 */
2260
-	public function set_country( $value ) {
2261
-		$this->set_prop( 'country', $value );
2285
+     * Set the customer's state.
2286
+     *
2287
+     * @since 1.0.19
2288
+     * @param  string $value state.
2289
+     */
2290
+    public function set_state( $value ) {
2291
+        $this->set_prop( 'state', $value );
2262 2292
     }
2263 2293
 
2264 2294
     /**
2265
-	 * Alias of self::set_country().
2266
-	 *
2267
-	 * @since 1.0.19
2268
-	 * @param  string $value country.
2269
-	 */
2270
-	public function set_user_country( $value ) {
2271
-		$this->set_country( $value );
2295
+     * Alias of self::set_state().
2296
+     *
2297
+     * @since 1.0.19
2298
+     * @param  string $value state.
2299
+     */
2300
+    public function set_user_state( $value ) {
2301
+        $this->set_state( $value );
2272 2302
     }
2273 2303
 
2274 2304
     /**
2275
-	 * Alias of self::set_country().
2276
-	 *
2277
-	 * @since 1.0.19
2278
-	 * @param  string $value country.
2279
-	 */
2280
-	public function set_customer_country( $value ) {
2281
-		$this->set_country( $value );
2305
+     * Alias of self::set_state().
2306
+     *
2307
+     * @since 1.0.19
2308
+     * @param  string $value state.
2309
+     */
2310
+    public function set_customer_state( $value ) {
2311
+        $this->set_state( $value );
2282 2312
     }
2283 2313
 
2284 2314
     /**
2285
-	 * Set the customer's state.
2286
-	 *
2287
-	 * @since 1.0.19
2288
-	 * @param  string $value state.
2289
-	 */
2290
-	public function set_state( $value ) {
2291
-		$this->set_prop( 'state', $value );
2315
+     * Set the customer's city.
2316
+     *
2317
+     * @since 1.0.19
2318
+     * @param  string $value city.
2319
+     */
2320
+    public function set_city( $value ) {
2321
+        $this->set_prop( 'city', $value );
2292 2322
     }
2293 2323
 
2294 2324
     /**
2295
-	 * Alias of self::set_state().
2296
-	 *
2297
-	 * @since 1.0.19
2298
-	 * @param  string $value state.
2299
-	 */
2300
-	public function set_user_state( $value ) {
2301
-		$this->set_state( $value );
2325
+     * Alias of self::set_city().
2326
+     *
2327
+     * @since 1.0.19
2328
+     * @param  string $value city.
2329
+     */
2330
+    public function set_user_city( $value ) {
2331
+        $this->set_city( $value );
2302 2332
     }
2303 2333
 
2304 2334
     /**
2305
-	 * Alias of self::set_state().
2306
-	 *
2307
-	 * @since 1.0.19
2308
-	 * @param  string $value state.
2309
-	 */
2310
-	public function set_customer_state( $value ) {
2311
-		$this->set_state( $value );
2335
+     * Alias of self::set_city().
2336
+     *
2337
+     * @since 1.0.19
2338
+     * @param  string $value city.
2339
+     */
2340
+    public function set_customer_city( $value ) {
2341
+        $this->set_city( $value );
2312 2342
     }
2313 2343
 
2314 2344
     /**
2315
-	 * Set the customer's city.
2316
-	 *
2317
-	 * @since 1.0.19
2318
-	 * @param  string $value city.
2319
-	 */
2320
-	public function set_city( $value ) {
2321
-		$this->set_prop( 'city', $value );
2345
+     * Set the customer's zip code.
2346
+     *
2347
+     * @since 1.0.19
2348
+     * @param  string $value zip.
2349
+     */
2350
+    public function set_zip( $value ) {
2351
+        $this->set_prop( 'zip', $value );
2322 2352
     }
2323 2353
 
2324 2354
     /**
2325
-	 * Alias of self::set_city().
2326
-	 *
2327
-	 * @since 1.0.19
2328
-	 * @param  string $value city.
2329
-	 */
2330
-	public function set_user_city( $value ) {
2331
-		$this->set_city( $value );
2355
+     * Alias of self::set_zip().
2356
+     *
2357
+     * @since 1.0.19
2358
+     * @param  string $value zip.
2359
+     */
2360
+    public function set_user_zip( $value ) {
2361
+        $this->set_zip( $value );
2332 2362
     }
2333 2363
 
2334 2364
     /**
2335
-	 * Alias of self::set_city().
2336
-	 *
2337
-	 * @since 1.0.19
2338
-	 * @param  string $value city.
2339
-	 */
2340
-	public function set_customer_city( $value ) {
2341
-		$this->set_city( $value );
2365
+     * Alias of self::set_zip().
2366
+     *
2367
+     * @since 1.0.19
2368
+     * @param  string $value zip.
2369
+     */
2370
+    public function set_customer_zip( $value ) {
2371
+        $this->set_zip( $value );
2342 2372
     }
2343 2373
 
2344 2374
     /**
2345
-	 * Set the customer's zip code.
2346
-	 *
2347
-	 * @since 1.0.19
2348
-	 * @param  string $value zip.
2349
-	 */
2350
-	public function set_zip( $value ) {
2351
-		$this->set_prop( 'zip', $value );
2375
+     * Set the customer's company.
2376
+     *
2377
+     * @since 1.0.19
2378
+     * @param  string $value company.
2379
+     */
2380
+    public function set_company( $value ) {
2381
+        $this->set_prop( 'company', $value );
2352 2382
     }
2353 2383
 
2354 2384
     /**
2355
-	 * Alias of self::set_zip().
2356
-	 *
2357
-	 * @since 1.0.19
2358
-	 * @param  string $value zip.
2359
-	 */
2360
-	public function set_user_zip( $value ) {
2361
-		$this->set_zip( $value );
2385
+     * Alias of self::set_company().
2386
+     *
2387
+     * @since 1.0.19
2388
+     * @param  string $value company.
2389
+     */
2390
+    public function set_user_company( $value ) {
2391
+        $this->set_company( $value );
2362 2392
     }
2363 2393
 
2364 2394
     /**
2365
-	 * Alias of self::set_zip().
2366
-	 *
2367
-	 * @since 1.0.19
2368
-	 * @param  string $value zip.
2369
-	 */
2370
-	public function set_customer_zip( $value ) {
2371
-		$this->set_zip( $value );
2395
+     * Alias of self::set_company().
2396
+     *
2397
+     * @since 1.0.19
2398
+     * @param  string $value company.
2399
+     */
2400
+    public function set_customer_company( $value ) {
2401
+        $this->set_company( $value );
2372 2402
     }
2373 2403
 
2374 2404
     /**
2375
-	 * Set the customer's company.
2376
-	 *
2377
-	 * @since 1.0.19
2378
-	 * @param  string $value company.
2379
-	 */
2380
-	public function set_company( $value ) {
2381
-		$this->set_prop( 'company', $value );
2405
+     * Set the customer's var number.
2406
+     *
2407
+     * @since 1.0.19
2408
+     * @param  string $value var number.
2409
+     */
2410
+    public function set_vat_number( $value ) {
2411
+        $this->set_prop( 'vat_number', $value );
2382 2412
     }
2383 2413
 
2384 2414
     /**
2385
-	 * Alias of self::set_company().
2386
-	 *
2387
-	 * @since 1.0.19
2388
-	 * @param  string $value company.
2389
-	 */
2390
-	public function set_user_company( $value ) {
2391
-		$this->set_company( $value );
2415
+     * Alias of self::set_vat_number().
2416
+     *
2417
+     * @since 1.0.19
2418
+     * @param  string $value var number.
2419
+     */
2420
+    public function set_user_vat_number( $value ) {
2421
+        $this->set_vat_number( $value );
2392 2422
     }
2393 2423
 
2394 2424
     /**
2395
-	 * Alias of self::set_company().
2396
-	 *
2397
-	 * @since 1.0.19
2398
-	 * @param  string $value company.
2399
-	 */
2400
-	public function set_customer_company( $value ) {
2401
-		$this->set_company( $value );
2425
+     * Alias of self::set_vat_number().
2426
+     *
2427
+     * @since 1.0.19
2428
+     * @param  string $value var number.
2429
+     */
2430
+    public function set_customer_vat_number( $value ) {
2431
+        $this->set_vat_number( $value );
2402 2432
     }
2403 2433
 
2404 2434
     /**
2405
-	 * Set the customer's var number.
2406
-	 *
2407
-	 * @since 1.0.19
2408
-	 * @param  string $value var number.
2409
-	 */
2410
-	public function set_vat_number( $value ) {
2411
-		$this->set_prop( 'vat_number', $value );
2435
+     * Set the customer's vat rate.
2436
+     *
2437
+     * @since 1.0.19
2438
+     * @param  string $value var rate.
2439
+     */
2440
+    public function set_vat_rate( $value ) {
2441
+        $this->set_prop( 'vat_rate', $value );
2412 2442
     }
2413 2443
 
2414 2444
     /**
2415
-	 * Alias of self::set_vat_number().
2416
-	 *
2417
-	 * @since 1.0.19
2418
-	 * @param  string $value var number.
2419
-	 */
2420
-	public function set_user_vat_number( $value ) {
2421
-		$this->set_vat_number( $value );
2445
+     * Alias of self::set_vat_rate().
2446
+     *
2447
+     * @since 1.0.19
2448
+     * @param  string $value var number.
2449
+     */
2450
+    public function set_user_vat_rate( $value ) {
2451
+        $this->set_vat_rate( $value );
2422 2452
     }
2423 2453
 
2424 2454
     /**
2425
-	 * Alias of self::set_vat_number().
2426
-	 *
2427
-	 * @since 1.0.19
2428
-	 * @param  string $value var number.
2429
-	 */
2430
-	public function set_customer_vat_number( $value ) {
2431
-		$this->set_vat_number( $value );
2455
+     * Alias of self::set_vat_rate().
2456
+     *
2457
+     * @since 1.0.19
2458
+     * @param  string $value var number.
2459
+     */
2460
+    public function set_customer_vat_rate( $value ) {
2461
+        $this->set_vat_rate( $value );
2432 2462
     }
2433 2463
 
2434 2464
     /**
2435
-	 * Set the customer's vat rate.
2436
-	 *
2437
-	 * @since 1.0.19
2438
-	 * @param  string $value var rate.
2439
-	 */
2440
-	public function set_vat_rate( $value ) {
2441
-		$this->set_prop( 'vat_rate', $value );
2465
+     * Set the customer's address.
2466
+     *
2467
+     * @since 1.0.19
2468
+     * @param  string $value address.
2469
+     */
2470
+    public function set_address( $value ) {
2471
+        $this->set_prop( 'address', $value );
2442 2472
     }
2443 2473
 
2444 2474
     /**
2445
-	 * Alias of self::set_vat_rate().
2446
-	 *
2447
-	 * @since 1.0.19
2448
-	 * @param  string $value var number.
2449
-	 */
2450
-	public function set_user_vat_rate( $value ) {
2451
-		$this->set_vat_rate( $value );
2475
+     * Alias of self::set_address().
2476
+     *
2477
+     * @since 1.0.19
2478
+     * @param  string $value address.
2479
+     */
2480
+    public function set_user_address( $value ) {
2481
+        $this->set_address( $value );
2452 2482
     }
2453 2483
 
2454 2484
     /**
2455
-	 * Alias of self::set_vat_rate().
2456
-	 *
2457
-	 * @since 1.0.19
2458
-	 * @param  string $value var number.
2459
-	 */
2460
-	public function set_customer_vat_rate( $value ) {
2461
-		$this->set_vat_rate( $value );
2485
+     * Alias of self::set_address().
2486
+     *
2487
+     * @since 1.0.19
2488
+     * @param  string $value address.
2489
+     */
2490
+    public function set_customer_address( $value ) {
2491
+        $this->set_address( $value );
2462 2492
     }
2463 2493
 
2464 2494
     /**
2465
-	 * Set the customer's address.
2466
-	 *
2467
-	 * @since 1.0.19
2468
-	 * @param  string $value address.
2469
-	 */
2470
-	public function set_address( $value ) {
2471
-		$this->set_prop( 'address', $value );
2495
+     * Set whether the customer has viewed the invoice or not.
2496
+     *
2497
+     * @since 1.0.19
2498
+     * @param  int|bool $value confirmed.
2499
+     */
2500
+    public function set_is_viewed( $value ) {
2501
+        $this->set_prop( 'is_viewed', $value );
2472 2502
     }
2473 2503
 
2474 2504
     /**
2475
-	 * Alias of self::set_address().
2476
-	 *
2477
-	 * @since 1.0.19
2478
-	 * @param  string $value address.
2479
-	 */
2480
-	public function set_user_address( $value ) {
2481
-		$this->set_address( $value );
2505
+     * Set extra email recipients.
2506
+     *
2507
+     * @since 1.0.19
2508
+     * @param  string $value email recipients.
2509
+     */
2510
+    public function set_email_cc( $value ) {
2511
+        $this->set_prop( 'email_cc', $value );
2482 2512
     }
2483 2513
 
2484 2514
     /**
2485
-	 * Alias of self::set_address().
2486
-	 *
2487
-	 * @since 1.0.19
2488
-	 * @param  string $value address.
2489
-	 */
2490
-	public function set_customer_address( $value ) {
2491
-		$this->set_address( $value );
2515
+     * Set the invoice template.
2516
+     *
2517
+     * @since 1.0.19
2518
+     * @param  string $value email recipients.
2519
+     */
2520
+    public function set_template( $value ) {
2521
+        if ( in_array( $value, array( 'quantity', 'hours', 'amount' ) ) ) {
2522
+            $this->set_prop( 'template', $value );
2523
+        }
2492 2524
     }
2493 2525
 
2494 2526
     /**
2495
-	 * Set whether the customer has viewed the invoice or not.
2496
-	 *
2497
-	 * @since 1.0.19
2498
-	 * @param  int|bool $value confirmed.
2499
-	 */
2500
-	public function set_is_viewed( $value ) {
2501
-		$this->set_prop( 'is_viewed', $value );
2502
-	}
2503
-
2504
-	/**
2505
-	 * Set extra email recipients.
2506
-	 *
2507
-	 * @since 1.0.19
2508
-	 * @param  string $value email recipients.
2509
-	 */
2510
-	public function set_email_cc( $value ) {
2511
-		$this->set_prop( 'email_cc', $value );
2512
-	}
2513
-
2514
-	/**
2515
-	 * Set the invoice template.
2516
-	 *
2517
-	 * @since 1.0.19
2518
-	 * @param  string $value email recipients.
2519
-	 */
2520
-	public function set_template( $value ) {
2521
-		if ( in_array( $value, array( 'quantity', 'hours', 'amount' ) ) ) {
2522
-			$this->set_prop( 'template', $value );
2523
-		}
2524
-	}
2525
-
2526
-	/**
2527
-	 * Set the customer's address confirmed status.
2528
-	 *
2529
-	 * @since 1.0.19
2530
-	 * @param  int|bool $value confirmed.
2531
-	 */
2532
-	public function set_address_confirmed( $value ) {
2533
-		$this->set_prop( 'address_confirmed', $value );
2527
+     * Set the customer's address confirmed status.
2528
+     *
2529
+     * @since 1.0.19
2530
+     * @param  int|bool $value confirmed.
2531
+     */
2532
+    public function set_address_confirmed( $value ) {
2533
+        $this->set_prop( 'address_confirmed', $value );
2534 2534
     }
2535 2535
 
2536 2536
     /**
2537
-	 * Alias of self::set_address_confirmed().
2538
-	 *
2539
-	 * @since 1.0.19
2540
-	 * @param  int|bool $value confirmed.
2541
-	 */
2542
-	public function set_user_address_confirmed( $value ) {
2543
-		$this->set_address_confirmed( $value );
2537
+     * Alias of self::set_address_confirmed().
2538
+     *
2539
+     * @since 1.0.19
2540
+     * @param  int|bool $value confirmed.
2541
+     */
2542
+    public function set_user_address_confirmed( $value ) {
2543
+        $this->set_address_confirmed( $value );
2544 2544
     }
2545 2545
 
2546 2546
     /**
2547
-	 * Alias of self::set_address_confirmed().
2548
-	 *
2549
-	 * @since 1.0.19
2550
-	 * @param  int|bool $value confirmed.
2551
-	 */
2552
-	public function set_customer_address_confirmed( $value ) {
2553
-		$this->set_address_confirmed( $value );
2547
+     * Alias of self::set_address_confirmed().
2548
+     *
2549
+     * @since 1.0.19
2550
+     * @param  int|bool $value confirmed.
2551
+     */
2552
+    public function set_customer_address_confirmed( $value ) {
2553
+        $this->set_address_confirmed( $value );
2554 2554
     }
2555 2555
 
2556 2556
     /**
2557
-	 * Set the invoice sub total.
2558
-	 *
2559
-	 * @since 1.0.19
2560
-	 * @param  float $value sub total.
2561
-	 */
2562
-	public function set_subtotal( $value ) {
2563
-		$this->set_prop( 'subtotal', $value );
2557
+     * Set the invoice sub total.
2558
+     *
2559
+     * @since 1.0.19
2560
+     * @param  float $value sub total.
2561
+     */
2562
+    public function set_subtotal( $value ) {
2563
+        $this->set_prop( 'subtotal', $value );
2564 2564
     }
2565 2565
 
2566 2566
     /**
2567
-	 * Set the invoice discount amount.
2568
-	 *
2569
-	 * @since 1.0.19
2570
-	 * @param  float $value discount total.
2571
-	 */
2572
-	public function set_total_discount( $value ) {
2573
-		$this->set_prop( 'total_discount', $value );
2567
+     * Set the invoice discount amount.
2568
+     *
2569
+     * @since 1.0.19
2570
+     * @param  float $value discount total.
2571
+     */
2572
+    public function set_total_discount( $value ) {
2573
+        $this->set_prop( 'total_discount', $value );
2574 2574
     }
2575 2575
 
2576 2576
     /**
2577
-	 * Alias of self::set_total_discount().
2578
-	 *
2579
-	 * @since 1.0.19
2580
-	 * @param  float $value discount total.
2581
-	 */
2582
-	public function set_discount( $value ) {
2583
-		$this->set_total_discount( $value );
2577
+     * Alias of self::set_total_discount().
2578
+     *
2579
+     * @since 1.0.19
2580
+     * @param  float $value discount total.
2581
+     */
2582
+    public function set_discount( $value ) {
2583
+        $this->set_total_discount( $value );
2584 2584
     }
2585 2585
 
2586 2586
     /**
2587
-	 * Set the invoice tax amount.
2588
-	 *
2589
-	 * @since 1.0.19
2590
-	 * @param  float $value tax total.
2591
-	 */
2592
-	public function set_total_tax( $value ) {
2593
-		$this->set_prop( 'total_tax', $value );
2587
+     * Set the invoice tax amount.
2588
+     *
2589
+     * @since 1.0.19
2590
+     * @param  float $value tax total.
2591
+     */
2592
+    public function set_total_tax( $value ) {
2593
+        $this->set_prop( 'total_tax', $value );
2594 2594
     }
2595 2595
 
2596 2596
     /**
2597
-	 * Alias of self::set_total_tax().
2598
-	 *
2599
-	 * @since 1.0.19
2600
-	 * @param  float $value tax total.
2601
-	 */
2602
-	public function set_tax_total( $value ) {
2603
-		$this->set_total_tax( $value );
2597
+     * Alias of self::set_total_tax().
2598
+     *
2599
+     * @since 1.0.19
2600
+     * @param  float $value tax total.
2601
+     */
2602
+    public function set_tax_total( $value ) {
2603
+        $this->set_total_tax( $value );
2604 2604
     }
2605 2605
 
2606 2606
     /**
2607
-	 * Set the invoice fees amount.
2608
-	 *
2609
-	 * @since 1.0.19
2610
-	 * @param  float $value fees total.
2611
-	 */
2612
-	public function set_total_fees( $value ) {
2613
-		$this->set_prop( 'total_fees', $value );
2607
+     * Set the invoice fees amount.
2608
+     *
2609
+     * @since 1.0.19
2610
+     * @param  float $value fees total.
2611
+     */
2612
+    public function set_total_fees( $value ) {
2613
+        $this->set_prop( 'total_fees', $value );
2614 2614
     }
2615 2615
 
2616 2616
     /**
2617
-	 * Alias of self::set_total_fees().
2618
-	 *
2619
-	 * @since 1.0.19
2620
-	 * @param  float $value fees total.
2621
-	 */
2622
-	public function set_fees_total( $value ) {
2623
-		$this->set_total_fees( $value );
2617
+     * Alias of self::set_total_fees().
2618
+     *
2619
+     * @since 1.0.19
2620
+     * @param  float $value fees total.
2621
+     */
2622
+    public function set_fees_total( $value ) {
2623
+        $this->set_total_fees( $value );
2624 2624
     }
2625 2625
 
2626 2626
     /**
2627
-	 * Set the invoice fees.
2628
-	 *
2629
-	 * @since 1.0.19
2630
-	 * @param  array $value fees.
2631
-	 */
2632
-	public function set_fees( $value ) {
2627
+     * Set the invoice fees.
2628
+     *
2629
+     * @since 1.0.19
2630
+     * @param  array $value fees.
2631
+     */
2632
+    public function set_fees( $value ) {
2633 2633
 
2634 2634
         $this->set_prop( 'fees', array() );
2635 2635
 
@@ -2647,23 +2647,23 @@  discard block
 block discarded – undo
2647 2647
     }
2648 2648
 
2649 2649
     /**
2650
-	 * Set the invoice taxes.
2651
-	 *
2652
-	 * @since 1.0.19
2653
-	 * @param  array $value taxes.
2654
-	 */
2655
-	public function set_taxes( $value ) {
2656
-		$this->set_prop( 'taxes', $value );
2650
+     * Set the invoice taxes.
2651
+     *
2652
+     * @since 1.0.19
2653
+     * @param  array $value taxes.
2654
+     */
2655
+    public function set_taxes( $value ) {
2656
+        $this->set_prop( 'taxes', $value );
2657 2657
     }
2658 2658
 
2659 2659
     /**
2660
-	 * Set the invoice discounts.
2661
-	 *
2662
-	 * @since 1.0.19
2663
-	 * @param  array $value discounts.
2664
-	 */
2665
-	public function set_discounts( $value ) {
2666
-		$this->set_prop( 'discounts', array() );
2660
+     * Set the invoice discounts.
2661
+     *
2662
+     * @since 1.0.19
2663
+     * @param  array $value discounts.
2664
+     */
2665
+    public function set_discounts( $value ) {
2666
+        $this->set_prop( 'discounts', array() );
2667 2667
 
2668 2668
         // Ensure that we have an array.
2669 2669
         if ( ! is_array( $value ) ) {
@@ -2678,12 +2678,12 @@  discard block
 block discarded – undo
2678 2678
     }
2679 2679
 
2680 2680
     /**
2681
-	 * Set the invoice items.
2682
-	 *
2683
-	 * @since 1.0.19
2684
-	 * @param  GetPaid_Form_Item[] $value items.
2685
-	 */
2686
-	public function set_items( $value ) {
2681
+     * Set the invoice items.
2682
+     *
2683
+     * @since 1.0.19
2684
+     * @param  GetPaid_Form_Item[] $value items.
2685
+     */
2686
+    public function set_items( $value ) {
2687 2687
 
2688 2688
         // Remove existing items.
2689 2689
         $this->set_prop( 'items', array() );
@@ -2700,73 +2700,73 @@  discard block
 block discarded – undo
2700 2700
     }
2701 2701
 
2702 2702
     /**
2703
-	 * Set the payment form.
2704
-	 *
2705
-	 * @since 1.0.19
2706
-	 * @param  int $value payment form.
2707
-	 */
2708
-	public function set_payment_form( $value ) {
2709
-		$this->set_prop( 'payment_form', $value );
2703
+     * Set the payment form.
2704
+     *
2705
+     * @since 1.0.19
2706
+     * @param  int $value payment form.
2707
+     */
2708
+    public function set_payment_form( $value ) {
2709
+        $this->set_prop( 'payment_form', $value );
2710 2710
     }
2711 2711
 
2712 2712
     /**
2713
-	 * Set the submission id.
2714
-	 *
2715
-	 * @since 1.0.19
2716
-	 * @param  string $value submission id.
2717
-	 */
2718
-	public function set_submission_id( $value ) {
2719
-		$this->set_prop( 'submission_id', $value );
2713
+     * Set the submission id.
2714
+     *
2715
+     * @since 1.0.19
2716
+     * @param  string $value submission id.
2717
+     */
2718
+    public function set_submission_id( $value ) {
2719
+        $this->set_prop( 'submission_id', $value );
2720 2720
     }
2721 2721
 
2722 2722
     /**
2723
-	 * Set the discount code.
2724
-	 *
2725
-	 * @since 1.0.19
2726
-	 * @param  string $value discount code.
2727
-	 */
2728
-	public function set_discount_code( $value ) {
2729
-		$this->set_prop( 'discount_code', $value );
2723
+     * Set the discount code.
2724
+     *
2725
+     * @since 1.0.19
2726
+     * @param  string $value discount code.
2727
+     */
2728
+    public function set_discount_code( $value ) {
2729
+        $this->set_prop( 'discount_code', $value );
2730 2730
     }
2731 2731
 
2732 2732
     /**
2733
-	 * Set the gateway.
2734
-	 *
2735
-	 * @since 1.0.19
2736
-	 * @param  string $value gateway.
2737
-	 */
2738
-	public function set_gateway( $value ) {
2739
-		$this->set_prop( 'gateway', $value );
2733
+     * Set the gateway.
2734
+     *
2735
+     * @since 1.0.19
2736
+     * @param  string $value gateway.
2737
+     */
2738
+    public function set_gateway( $value ) {
2739
+        $this->set_prop( 'gateway', $value );
2740 2740
     }
2741 2741
 
2742 2742
     /**
2743
-	 * Set the transaction id.
2744
-	 *
2745
-	 * @since 1.0.19
2746
-	 * @param  string $value transaction id.
2747
-	 */
2748
-	public function set_transaction_id( $value ) {
2749
-		$this->set_prop( 'transaction_id', $value );
2743
+     * Set the transaction id.
2744
+     *
2745
+     * @since 1.0.19
2746
+     * @param  string $value transaction id.
2747
+     */
2748
+    public function set_transaction_id( $value ) {
2749
+        $this->set_prop( 'transaction_id', $value );
2750 2750
     }
2751 2751
 
2752 2752
     /**
2753
-	 * Set the currency id.
2754
-	 *
2755
-	 * @since 1.0.19
2756
-	 * @param  string $value currency id.
2757
-	 */
2758
-	public function set_currency( $value ) {
2759
-		$this->set_prop( 'currency', $value );
2753
+     * Set the currency id.
2754
+     *
2755
+     * @since 1.0.19
2756
+     * @param  string $value currency id.
2757
+     */
2758
+    public function set_currency( $value ) {
2759
+        $this->set_prop( 'currency', $value );
2760 2760
     }
2761 2761
 
2762 2762
     /**
2763
-	 * Set the subscription id.
2764
-	 *
2765
-	 * @since 1.0.19
2766
-	 * @param  string $value subscription id.
2767
-	 */
2768
-	public function set_subscription_id( $value ) {
2769
-		$this->set_prop( 'subscription_id', $value );
2763
+     * Set the subscription id.
2764
+     *
2765
+     * @since 1.0.19
2766
+     * @param  string $value subscription id.
2767
+     */
2768
+    public function set_subscription_id( $value ) {
2769
+        $this->set_prop( 'subscription_id', $value );
2770 2770
     }
2771 2771
 
2772 2772
     /*
@@ -2805,12 +2805,12 @@  discard block
 block discarded – undo
2805 2805
      */
2806 2806
     public function is_taxable() {
2807 2807
         return (int) $this->disable_taxes === 0;
2808
-	}
2808
+    }
2809 2809
 
2810
-	/**
2811
-	 * @deprecated
2812
-	 */
2813
-	public function has_vat() {
2810
+    /**
2811
+     * @deprecated
2812
+     */
2813
+    public function has_vat() {
2814 2814
         global $wpinv_euvat, $wpi_country;
2815 2815
 
2816 2816
         $requires_vat = false;
@@ -2821,17 +2821,17 @@  discard block
 block discarded – undo
2821 2821
         }
2822 2822
 
2823 2823
         return apply_filters( 'wpinv_invoice_has_vat', $requires_vat, $this );
2824
-	}
2824
+    }
2825 2825
 
2826
-	/**
2827
-	 * Checks to see if the invoice requires payment.
2828
-	 */
2829
-	public function is_free() {
2826
+    /**
2827
+     * Checks to see if the invoice requires payment.
2828
+     */
2829
+    public function is_free() {
2830 2830
         $is_free = ! ( (float) wpinv_round_amount( $this->get_initial_total() ) > 0 );
2831 2831
 
2832
-		if ( $is_free && $this->is_recurring() ) {
2833
-			$is_free = ! ( (float) wpinv_round_amount( $this->get_recurring_total() ) > 0 );
2834
-		}
2832
+        if ( $is_free && $this->is_recurring() ) {
2833
+            $is_free = ! ( (float) wpinv_round_amount( $this->get_recurring_total() ) > 0 );
2834
+        }
2835 2835
 
2836 2836
         return apply_filters( 'wpinv_invoice_is_free', $is_free, $this );
2837 2837
     }
@@ -2842,30 +2842,30 @@  discard block
 block discarded – undo
2842 2842
     public function is_paid() {
2843 2843
         $is_paid = $this->has_status( array( 'publish', 'wpi-processing', 'wpi-renewal' ) );
2844 2844
         return apply_filters( 'wpinv_invoice_is_paid', $is_paid, $this );
2845
-	}
2845
+    }
2846 2846
 
2847
-	/**
2847
+    /**
2848 2848
      * Checks if the invoice needs payment.
2849 2849
      */
2850
-	public function needs_payment() {
2851
-		$needs_payment = ! $this->is_paid() && ! $this->is_free();
2850
+    public function needs_payment() {
2851
+        $needs_payment = ! $this->is_paid() && ! $this->is_free();
2852 2852
         return apply_filters( 'wpinv_needs_payment', $needs_payment, $this );
2853 2853
     }
2854 2854
 
2855
-	/**
2855
+    /**
2856 2856
      * Checks if the invoice is refunded.
2857 2857
      */
2858
-	public function is_refunded() {
2858
+    public function is_refunded() {
2859 2859
         $is_refunded = $this->has_status( 'wpi-refunded' );
2860 2860
         return apply_filters( 'wpinv_invoice_is_refunded', $is_refunded, $this );
2861
-	}
2861
+    }
2862 2862
 
2863
-	/**
2863
+    /**
2864 2864
      * Checks if the invoice is draft.
2865 2865
      */
2866
-	public function is_draft() {
2866
+    public function is_draft() {
2867 2867
         return $this->has_status( 'draft, auto-draft' );
2868
-	}
2868
+    }
2869 2869
 
2870 2870
     /**
2871 2871
      * Checks if the invoice has a given status.
@@ -2873,9 +2873,9 @@  discard block
 block discarded – undo
2873 2873
     public function has_status( $status ) {
2874 2874
         $status = wpinv_parse_list( $status );
2875 2875
         return apply_filters( 'wpinv_has_status', in_array( $this->get_status(), $status ), $status );
2876
-	}
2876
+    }
2877 2877
 
2878
-	/**
2878
+    /**
2879 2879
      * Checks if the invoice is of a given type.
2880 2880
      */
2881 2881
     public function is_type( $type ) {
@@ -2898,25 +2898,25 @@  discard block
 block discarded – undo
2898 2898
      */
2899 2899
     public function has_free_trial() {
2900 2900
         return $this->is_recurring() && 0 == $this->get_initial_total();
2901
-	}
2901
+    }
2902 2902
 
2903
-	/**
2903
+    /**
2904 2904
      * @deprecated
2905 2905
      */
2906 2906
     public function is_free_trial() {
2907 2907
         $this->has_free_trial();
2908 2908
     }
2909 2909
 
2910
-	/**
2910
+    /**
2911 2911
      * Check if the initial payment if 0.
2912 2912
      *
2913 2913
      */
2914
-	public function is_initial_free() {
2914
+    public function is_initial_free() {
2915 2915
         $is_initial_free = ! ( (float) wpinv_round_amount( $this->get_initial_total() ) > 0 );
2916 2916
         return apply_filters( 'wpinv_invoice_is_initial_free', $is_initial_free, $this->get_cart_details(), $this );
2917 2917
     }
2918 2918
 	
2919
-	/**
2919
+    /**
2920 2920
      * Check if the recurring item has a free trial.
2921 2921
      *
2922 2922
      */
@@ -2929,21 +2929,21 @@  discard block
 block discarded – undo
2929 2929
 
2930 2930
         $item = new WPInv_Item( $this->recurring_item );
2931 2931
         return $item->has_free_trial();
2932
-	}
2932
+    }
2933 2933
 
2934
-	/**
2934
+    /**
2935 2935
      * Check if the free trial is a result of a discount.
2936 2936
      */
2937 2937
     public function is_free_trial_from_discount() {
2938
-		return $this->has_free_trial() && ! $this->item_has_free_trial();
2939
-	}
2938
+        return $this->has_free_trial() && ! $this->item_has_free_trial();
2939
+    }
2940 2940
 	
2941
-	/**
2941
+    /**
2942 2942
      * @deprecated
2943 2943
      */
2944 2944
     public function discount_first_payment_only() {
2945 2945
 
2946
-		$discount_code = $this->get_discount_code();
2946
+        $discount_code = $this->get_discount_code();
2947 2947
         if ( empty( $this->discount_code ) || ! $this->is_recurring() ) {
2948 2948
             return true;
2949 2949
         }
@@ -2975,13 +2975,13 @@  discard block
 block discarded – undo
2975 2975
     public function add_item( $item ) {
2976 2976
 
2977 2977
         // Make sure that it is available for purchase.
2978
-		if ( $item->get_id() > 0 && ! $item->can_purchase() ) {
2979
-			return new WP_Error( 'invalid_item', __( 'This item is not available for purchase', 'invoicing' ) );
2978
+        if ( $item->get_id() > 0 && ! $item->can_purchase() ) {
2979
+            return new WP_Error( 'invalid_item', __( 'This item is not available for purchase', 'invoicing' ) );
2980 2980
         }
2981 2981
 
2982 2982
         // Do we have a recurring item?
2983
-		if ( $item->is_recurring() ) {
2984
-			$this->recurring_item = $item->get_id();
2983
+        if ( $item->is_recurring() ) {
2984
+            $this->recurring_item = $item->get_id();
2985 2985
         }
2986 2986
 
2987 2987
         // Invoice id.
@@ -2996,21 +2996,21 @@  discard block
 block discarded – undo
2996 2996
     }
2997 2997
 
2998 2998
     /**
2999
-	 * Retrieves a specific item.
3000
-	 *
3001
-	 * @since 1.0.19
3002
-	 */
3003
-	public function get_item( $item_id ) {
2999
+     * Retrieves a specific item.
3000
+     *
3001
+     * @since 1.0.19
3002
+     */
3003
+    public function get_item( $item_id ) {
3004 3004
         $items = $this->get_items();
3005
-		return ( ! empty( $item_id ) && isset( $items[ $item_id ] ) ) ? $items[ $item_id ] : null;
3005
+        return ( ! empty( $item_id ) && isset( $items[ $item_id ] ) ) ? $items[ $item_id ] : null;
3006 3006
     }
3007 3007
 
3008 3008
     /**
3009
-	 * Removes a specific item.
3010
-	 *
3011
-	 * @since 1.0.19
3012
-	 */
3013
-	public function remove_item( $item_id ) {
3009
+     * Removes a specific item.
3010
+     *
3011
+     * @since 1.0.19
3012
+     */
3013
+    public function remove_item( $item_id ) {
3014 3014
         $items = $this->get_items();
3015 3015
 
3016 3016
         if ( $item_id == $this->recurring_item ) {
@@ -3038,38 +3038,38 @@  discard block
 block discarded – undo
3038 3038
         if ( isset( $fees[ $fee ] ) && isset( $fees[ $fee ]['amount'] ) ) {
3039 3039
 
3040 3040
             $amount = $fees[ $fee ]['amount'] += $amount;
3041
-			$fees[ $fee ] = array(
3041
+            $fees[ $fee ] = array(
3042 3042
                 'amount'    => $amount,
3043 3043
                 'recurring' => (bool) $recurring,
3044 3044
             );
3045 3045
 
3046
-		} else {
3047
-			$fees[ $fee ] = array(
3046
+        } else {
3047
+            $fees[ $fee ] = array(
3048 3048
                 'amount'    => $amount,
3049 3049
                 'recurring' => (bool) $recurring,
3050 3050
             );
3051
-		}
3051
+        }
3052 3052
 
3053 3053
         $this->set_prop( 'fees', $fee );
3054 3054
 
3055 3055
     }
3056 3056
 
3057 3057
     /**
3058
-	 * Retrieves a specific fee.
3059
-	 *
3060
-	 * @since 1.0.19
3061
-	 */
3062
-	public function get_fee( $fee ) {
3058
+     * Retrieves a specific fee.
3059
+     *
3060
+     * @since 1.0.19
3061
+     */
3062
+    public function get_fee( $fee ) {
3063 3063
         $fees = $this->get_fees();
3064
-		return isset( $fees[ $fee ] ) ? $fees[ $fee ] : null;
3064
+        return isset( $fees[ $fee ] ) ? $fees[ $fee ] : null;
3065 3065
     }
3066 3066
 
3067 3067
     /**
3068
-	 * Removes a specific fee.
3069
-	 *
3070
-	 * @since 1.0.19
3071
-	 */
3072
-	public function remove_fee( $fee ) {
3068
+     * Removes a specific fee.
3069
+     *
3070
+     * @since 1.0.19
3071
+     */
3072
+    public function remove_fee( $fee ) {
3073 3073
         $fees = $this->get_fees();
3074 3074
         if ( isset( $fees[ $fee ] ) ) {
3075 3075
             unset( $fees[ $fee ] );
@@ -3092,44 +3092,44 @@  discard block
 block discarded – undo
3092 3092
         if ( isset( $discounts[ $discount ] ) && isset( $discounts[ $discount ]['amount'] ) ) {
3093 3093
 
3094 3094
             $amount = $discounts[ $discount ]['amount'] += $amount;
3095
-			$discounts[ $discount ] = array(
3095
+            $discounts[ $discount ] = array(
3096 3096
                 'amount'    => $amount,
3097 3097
                 'recurring' => (bool) $recurring,
3098 3098
             );
3099 3099
 
3100
-		} else {
3101
-			$discounts[ $discount ] = array(
3100
+        } else {
3101
+            $discounts[ $discount ] = array(
3102 3102
                 'amount'    => $amount,
3103 3103
                 'recurring' => (bool) $recurring,
3104 3104
             );
3105
-		}
3105
+        }
3106 3106
 
3107 3107
         $this->set_prop( 'discounts', $discount );
3108 3108
 
3109 3109
     }
3110 3110
 
3111 3111
     /**
3112
-	 * Retrieves a specific discount.
3113
-	 *
3114
-	 * @since 1.0.19
3115
-	 */
3116
-	public function get_discount( $discount = false ) {
3112
+     * Retrieves a specific discount.
3113
+     *
3114
+     * @since 1.0.19
3115
+     */
3116
+    public function get_discount( $discount = false ) {
3117 3117
 
3118
-		// Backwards compatibilty.
3119
-		if ( empty( $discount ) ) {
3120
-			return $this->get_total_discount();
3121
-		}
3118
+        // Backwards compatibilty.
3119
+        if ( empty( $discount ) ) {
3120
+            return $this->get_total_discount();
3121
+        }
3122 3122
 
3123 3123
         $discounts = $this->get_discounts();
3124
-		return isset( $discounts[ $discount ] ) ? $discounts[ $discount ] : null;
3124
+        return isset( $discounts[ $discount ] ) ? $discounts[ $discount ] : null;
3125 3125
     }
3126 3126
 
3127 3127
     /**
3128
-	 * Removes a specific discount.
3129
-	 *
3130
-	 * @since 1.0.19
3131
-	 */
3132
-	public function remove_discount( $discount ) {
3128
+     * Removes a specific discount.
3129
+     *
3130
+     * @since 1.0.19
3131
+     */
3132
+    public function remove_discount( $discount ) {
3133 3133
         $discounts = $this->get_discounts();
3134 3134
         if ( isset( $discounts[ $discount ] ) ) {
3135 3135
             unset( $discounts[ $discount ] );
@@ -3155,38 +3155,38 @@  discard block
 block discarded – undo
3155 3155
         if ( isset( $taxes[ $tax ] ) && isset( $taxes[ $tax ]['amount'] ) ) {
3156 3156
 
3157 3157
             $amount = $taxes[ $tax ]['amount'] += $amount;
3158
-			$taxes[ $tax ] = array(
3158
+            $taxes[ $tax ] = array(
3159 3159
                 'amount'    => $amount,
3160 3160
                 'recurring' => (bool) $recurring,
3161 3161
             );
3162 3162
 
3163
-		} else {
3164
-			$taxes[ $tax ] = array(
3163
+        } else {
3164
+            $taxes[ $tax ] = array(
3165 3165
                 'amount'    => $amount,
3166 3166
                 'recurring' => (bool) $recurring,
3167 3167
             );
3168
-		}
3168
+        }
3169 3169
 
3170 3170
         $this->set_prop( 'taxes', $tax );
3171 3171
 
3172 3172
     }
3173 3173
 
3174 3174
     /**
3175
-	 * Retrieves a specific tax.
3176
-	 *
3177
-	 * @since 1.0.19
3178
-	 */
3179
-	public function get_tax( $tax ) {
3175
+     * Retrieves a specific tax.
3176
+     *
3177
+     * @since 1.0.19
3178
+     */
3179
+    public function get_tax( $tax ) {
3180 3180
         $taxes = $this->get_taxes();
3181
-		return isset( $taxes[ $tax ] ) ? $taxes[ $tax ] : null;
3181
+        return isset( $taxes[ $tax ] ) ? $taxes[ $tax ] : null;
3182 3182
     }
3183 3183
 
3184 3184
     /**
3185
-	 * Removes a specific tax.
3186
-	 *
3187
-	 * @since 1.0.19
3188
-	 */
3189
-	public function remove_tax( $tax ) {
3185
+     * Removes a specific tax.
3186
+     *
3187
+     * @since 1.0.19
3188
+     */
3189
+    public function remove_tax( $tax ) {
3190 3190
         $taxes = $this->get_discounts();
3191 3191
         if ( isset( $taxes[ $tax ] ) ) {
3192 3192
             unset( $taxes[ $tax ] );
@@ -3195,160 +3195,160 @@  discard block
 block discarded – undo
3195 3195
     }
3196 3196
 
3197 3197
     /**
3198
-	 * Recalculates the invoice subtotal.
3199
-	 *
3200
-	 * @since 1.0.19
3201
-	 * @return float The recalculated subtotal
3202
-	 */
3203
-	public function recalculate_subtotal() {
3198
+     * Recalculates the invoice subtotal.
3199
+     *
3200
+     * @since 1.0.19
3201
+     * @return float The recalculated subtotal
3202
+     */
3203
+    public function recalculate_subtotal() {
3204 3204
         $items     = $this->get_items();
3205
-		$subtotal  = 0;
3206
-		$recurring = 0;
3205
+        $subtotal  = 0;
3206
+        $recurring = 0;
3207 3207
 
3208 3208
         foreach ( $items as $item ) {
3209
-			$subtotal  += $item->get_sub_total();
3210
-			$recurring += $item->get_recurring_sub_total();
3209
+            $subtotal  += $item->get_sub_total();
3210
+            $recurring += $item->get_recurring_sub_total();
3211 3211
         }
3212 3212
 
3213
-		if ( $this->is_renewal() ) {
3214
-			$this->set_subtotal( $recurring );
3215
-		} else {
3216
-			$this->set_subtotal( $subtotal );
3217
-		}
3213
+        if ( $this->is_renewal() ) {
3214
+            $this->set_subtotal( $recurring );
3215
+        } else {
3216
+            $this->set_subtotal( $subtotal );
3217
+        }
3218 3218
 
3219
-		$this->totals['subtotal'] = array(
3220
-			'initial'   => $subtotal,
3221
-			'recurring' => $recurring,
3222
-		);
3219
+        $this->totals['subtotal'] = array(
3220
+            'initial'   => $subtotal,
3221
+            'recurring' => $recurring,
3222
+        );
3223 3223
 
3224 3224
         return $this->is_renewal() ? $recurring : $subtotal;
3225 3225
     }
3226 3226
 
3227 3227
     /**
3228
-	 * Recalculates the invoice discount total.
3229
-	 *
3230
-	 * @since 1.0.19
3231
-	 * @return float The recalculated discount
3232
-	 */
3233
-	public function recalculate_total_discount() {
3228
+     * Recalculates the invoice discount total.
3229
+     *
3230
+     * @since 1.0.19
3231
+     * @return float The recalculated discount
3232
+     */
3233
+    public function recalculate_total_discount() {
3234 3234
         $discounts = $this->get_discounts();
3235
-		$discount  = 0;
3236
-		$recurring = 0;
3235
+        $discount  = 0;
3236
+        $recurring = 0;
3237 3237
 
3238 3238
         foreach ( $discounts as $data ) {
3239 3239
 
3240
-			if ( $data['recurring'] ) {
3241
-				$recurring += $data['amount'];
3242
-			} else {
3243
-				$discount += $data['amount'];
3244
-			}
3240
+            if ( $data['recurring'] ) {
3241
+                $recurring += $data['amount'];
3242
+            } else {
3243
+                $discount += $data['amount'];
3244
+            }
3245 3245
 
3246
-		}
3246
+        }
3247 3247
 
3248
-		if ( $this->is_renewal() ) {
3249
-			$this->set_total_discount( $recurring );
3250
-		} else {
3251
-			$this->set_total_discount( $discount );
3252
-		}
3248
+        if ( $this->is_renewal() ) {
3249
+            $this->set_total_discount( $recurring );
3250
+        } else {
3251
+            $this->set_total_discount( $discount );
3252
+        }
3253 3253
 
3254
-		$this->totals['discount'] = array(
3255
-			'initial'   => $discount,
3256
-			'recurring' => $recurring,
3257
-		);
3254
+        $this->totals['discount'] = array(
3255
+            'initial'   => $discount,
3256
+            'recurring' => $recurring,
3257
+        );
3258 3258
 
3259
-		return $this->is_renewal() ? $recurring : $discount;
3259
+        return $this->is_renewal() ? $recurring : $discount;
3260 3260
 
3261 3261
     }
3262 3262
 
3263 3263
     /**
3264
-	 * Recalculates the invoice tax total.
3265
-	 *
3266
-	 * @since 1.0.19
3267
-	 * @return float The recalculated tax
3268
-	 */
3269
-	public function recalculate_total_tax() {
3264
+     * Recalculates the invoice tax total.
3265
+     *
3266
+     * @since 1.0.19
3267
+     * @return float The recalculated tax
3268
+     */
3269
+    public function recalculate_total_tax() {
3270 3270
         $taxes     = $this->get_taxes();
3271
-		$tax       = 0;
3272
-		$recurring = 0;
3271
+        $tax       = 0;
3272
+        $recurring = 0;
3273 3273
 
3274 3274
         foreach ( $taxes as $data ) {
3275 3275
 
3276
-			if ( $data['recurring'] ) {
3277
-				$recurring += $data['amount'];
3278
-			} else {
3279
-				$tax += $data['amount'];
3280
-			}
3276
+            if ( $data['recurring'] ) {
3277
+                $recurring += $data['amount'];
3278
+            } else {
3279
+                $tax += $data['amount'];
3280
+            }
3281 3281
 
3282
-		}
3282
+        }
3283 3283
 
3284
-		if ( $this->is_renewal() ) {
3285
-			$this->set_total_tax( $recurring );
3286
-		} else {
3287
-			$this->set_total_tax( $tax );
3288
-		}
3284
+        if ( $this->is_renewal() ) {
3285
+            $this->set_total_tax( $recurring );
3286
+        } else {
3287
+            $this->set_total_tax( $tax );
3288
+        }
3289 3289
 
3290
-		$this->totals['tax'] = array(
3291
-			'initial'   => $tax,
3292
-			'recurring' => $recurring,
3293
-		);
3290
+        $this->totals['tax'] = array(
3291
+            'initial'   => $tax,
3292
+            'recurring' => $recurring,
3293
+        );
3294 3294
 
3295
-		return $this->is_renewal() ? $recurring : $tax;
3295
+        return $this->is_renewal() ? $recurring : $tax;
3296 3296
 
3297 3297
     }
3298 3298
 
3299 3299
     /**
3300
-	 * Recalculates the invoice fees total.
3301
-	 *
3302
-	 * @since 1.0.19
3303
-	 * @return float The recalculated fee
3304
-	 */
3305
-	public function recalculate_total_fees() {
3306
-		$fees      = $this->get_fees();
3307
-		$fee       = 0;
3308
-		$recurring = 0;
3300
+     * Recalculates the invoice fees total.
3301
+     *
3302
+     * @since 1.0.19
3303
+     * @return float The recalculated fee
3304
+     */
3305
+    public function recalculate_total_fees() {
3306
+        $fees      = $this->get_fees();
3307
+        $fee       = 0;
3308
+        $recurring = 0;
3309 3309
 
3310 3310
         foreach ( $fees as $data ) {
3311 3311
 
3312
-			if ( $data['recurring'] ) {
3313
-				$recurring += $data['amount'];
3314
-			} else {
3315
-				$fee += $data['amount'];
3316
-			}
3312
+            if ( $data['recurring'] ) {
3313
+                $recurring += $data['amount'];
3314
+            } else {
3315
+                $fee += $data['amount'];
3316
+            }
3317 3317
 
3318
-		}
3318
+        }
3319 3319
 
3320 3320
         if ( $this->is_renewal() ) {
3321
-			$this->set_total_fees( $recurring );
3322
-		} else {
3323
-			$this->set_total_fees( $fee );
3324
-		}
3321
+            $this->set_total_fees( $recurring );
3322
+        } else {
3323
+            $this->set_total_fees( $fee );
3324
+        }
3325 3325
 
3326
-		$this->totals['fee'] = array(
3327
-			'initial'   => $fee,
3328
-			'recurring' => $recurring,
3329
-		);
3326
+        $this->totals['fee'] = array(
3327
+            'initial'   => $fee,
3328
+            'recurring' => $recurring,
3329
+        );
3330 3330
 
3331 3331
         $this->set_total_fees( $fee );
3332 3332
         return $this->is_renewal() ? $recurring : $fee;
3333 3333
     }
3334 3334
 
3335 3335
     /**
3336
-	 * Recalculates the invoice total.
3337
-	 *
3338
-	 * @since 1.0.19
3336
+     * Recalculates the invoice total.
3337
+     *
3338
+     * @since 1.0.19
3339 3339
      * @return float The invoice total
3340
-	 */
3341
-	public function recalculate_total() {
3340
+     */
3341
+    public function recalculate_total() {
3342 3342
         $this->recalculate_subtotal();
3343 3343
         $this->recalculate_total_fees();
3344 3344
         $this->recalculate_total_discount();
3345 3345
         $this->recalculate_total_tax();
3346
-		return $this->get_total();
3347
-	}
3346
+        return $this->get_total();
3347
+    }
3348 3348
 
3349
-	/**
3350
-	 * @deprecated
3351
-	 */
3349
+    /**
3350
+     * @deprecated
3351
+     */
3352 3352
     public function recalculate_totals( $temp = false ) {
3353 3353
         $this->update_items( $temp );
3354 3354
         $this->save( true );
@@ -3412,9 +3412,9 @@  discard block
 block discarded – undo
3412 3412
         }
3413 3413
 
3414 3414
         return $note_id;
3415
-	}
3415
+    }
3416 3416
 
3417
-	/**
3417
+    /**
3418 3418
      * Generates a unique key for the invoice.
3419 3419
      */
3420 3420
     public function generate_key( $string = '' ) {
@@ -3435,106 +3435,106 @@  discard block
 block discarded – undo
3435 3435
             $number      = $next_number;
3436 3436
         }
3437 3437
 
3438
-		$number = wpinv_format_invoice_number( $number, $this->post_type );
3438
+        $number = wpinv_format_invoice_number( $number, $this->post_type );
3439 3439
 
3440
-		return $number;
3441
-	}
3440
+        return $number;
3441
+    }
3442 3442
 
3443
-	/**
3444
-	 * Handle the status transition.
3445
-	 */
3446
-	protected function status_transition() {
3447
-		$status_transition = $this->status_transition;
3443
+    /**
3444
+     * Handle the status transition.
3445
+     */
3446
+    protected function status_transition() {
3447
+        $status_transition = $this->status_transition;
3448 3448
 
3449
-		// Reset status transition variable.
3450
-		$this->status_transition = false;
3449
+        // Reset status transition variable.
3450
+        $this->status_transition = false;
3451 3451
 
3452
-		if ( $status_transition ) {
3453
-			try {
3452
+        if ( $status_transition ) {
3453
+            try {
3454 3454
 
3455
-				// Fire a hook for the status change.
3456
-				do_action( 'getpaid_invoice_status_' . $status_transition['to'], $this->get_id(), $this, $status_transition );
3455
+                // Fire a hook for the status change.
3456
+                do_action( 'getpaid_invoice_status_' . $status_transition['to'], $this->get_id(), $this, $status_transition );
3457 3457
 
3458
-				// @deprecated this is deprecated and will be removed in the future.
3459
-				do_action( 'wpinv_status_' . $status_transition['to'], $this->get_id(), $status_transition['from'] );
3458
+                // @deprecated this is deprecated and will be removed in the future.
3459
+                do_action( 'wpinv_status_' . $status_transition['to'], $this->get_id(), $status_transition['from'] );
3460 3460
 
3461
-				if ( ! empty( $status_transition['from'] ) ) {
3461
+                if ( ! empty( $status_transition['from'] ) ) {
3462 3462
 
3463
-					/* translators: 1: old invoice status 2: new invoice status */
3464
-					$transition_note = sprintf( __( 'Status changed from %1$s to %2$s.', 'invoicing' ), wpinv_status_nicename( $status_transition['from'] ), wpinv_status_nicename( $status_transition['to'] ) );
3463
+                    /* translators: 1: old invoice status 2: new invoice status */
3464
+                    $transition_note = sprintf( __( 'Status changed from %1$s to %2$s.', 'invoicing' ), wpinv_status_nicename( $status_transition['from'] ), wpinv_status_nicename( $status_transition['to'] ) );
3465 3465
 
3466
-					// Fire another hook.
3467
-					do_action( 'getpaid_invoice_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this );
3468
-					do_action( 'getpaid_invoice_status_changed', $this->get_id(), $status_transition['from'], $status_transition['to'], $this );
3466
+                    // Fire another hook.
3467
+                    do_action( 'getpaid_invoice_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this );
3468
+                    do_action( 'getpaid_invoice_status_changed', $this->get_id(), $status_transition['from'], $status_transition['to'], $this );
3469 3469
 
3470
-					// @deprecated this is deprecated and will be removed in the future.
3471
-					do_action( 'wpinv_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->ID, $status_transition['from'] );
3470
+                    // @deprecated this is deprecated and will be removed in the future.
3471
+                    do_action( 'wpinv_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->ID, $status_transition['from'] );
3472 3472
 
3473
-					// Note the transition occurred.
3474
-					$this->add_note( trim( $status_transition['note'] . ' ' . $transition_note ), 0, $status_transition['manual'] );
3473
+                    // Note the transition occurred.
3474
+                    $this->add_note( trim( $status_transition['note'] . ' ' . $transition_note ), 0, $status_transition['manual'] );
3475 3475
 
3476
-					// Work out if this was for a payment, and trigger a payment_status hook instead.
3477
-					if (
3478
-						in_array( $status_transition['from'], array( 'wpi-cancelled', 'wpi-pending', 'wpi-failed' ), true )
3479
-						&& in_array( $status_transition['to'], array( 'publish', 'wpi-processing', 'wpi-renewal' ), true )
3480
-					) {
3481
-						do_action( 'getpaid_invoice_payment_status_changed', $this->get_id(), $this, $status_transition );
3482
-					}
3483
-				} else {
3484
-					/* translators: %s: new invoice status */
3485
-					$transition_note = sprintf( __( 'Status set to %s.', 'invoicing' ), wpinv_status_nicename( $status_transition['to'] ) );
3476
+                    // Work out if this was for a payment, and trigger a payment_status hook instead.
3477
+                    if (
3478
+                        in_array( $status_transition['from'], array( 'wpi-cancelled', 'wpi-pending', 'wpi-failed' ), true )
3479
+                        && in_array( $status_transition['to'], array( 'publish', 'wpi-processing', 'wpi-renewal' ), true )
3480
+                    ) {
3481
+                        do_action( 'getpaid_invoice_payment_status_changed', $this->get_id(), $this, $status_transition );
3482
+                    }
3483
+                } else {
3484
+                    /* translators: %s: new invoice status */
3485
+                    $transition_note = sprintf( __( 'Status set to %s.', 'invoicing' ), wpinv_status_nicename( $status_transition['to'] ) );
3486 3486
 
3487
-					// Note the transition occurred.
3488
-					$this->add_note( trim( $status_transition['note'] . ' ' . $transition_note ), 0, $status_transition['manual'] );
3487
+                    // Note the transition occurred.
3488
+                    $this->add_note( trim( $status_transition['note'] . ' ' . $transition_note ), 0, $status_transition['manual'] );
3489 3489
 
3490
-				}
3491
-			} catch ( Exception $e ) {
3492
-				$this->add_note( __( 'Error during status transition.', 'invoicing' ) . ' ' . $e->getMessage() );
3493
-			}
3494
-		}
3495
-	}
3490
+                }
3491
+            } catch ( Exception $e ) {
3492
+                $this->add_note( __( 'Error during status transition.', 'invoicing' ) . ' ' . $e->getMessage() );
3493
+            }
3494
+        }
3495
+    }
3496 3496
 
3497
-	/**
3498
-	 * Updates an invoice status.
3499
-	 */
3500
-	public function update_status( $new_status = false, $note = '', $manual = false ) {
3497
+    /**
3498
+     * Updates an invoice status.
3499
+     */
3500
+    public function update_status( $new_status = false, $note = '', $manual = false ) {
3501 3501
 
3502
-		// Fires before updating a status.
3503
-		do_action( 'wpinv_before_invoice_status_change', $this->ID, $new_status, $this->get_status( 'edit' ) );
3502
+        // Fires before updating a status.
3503
+        do_action( 'wpinv_before_invoice_status_change', $this->ID, $new_status, $this->get_status( 'edit' ) );
3504 3504
 
3505
-		// Update the status.
3506
-		$this->set_status( $new_status, $note, $manual );
3505
+        // Update the status.
3506
+        $this->set_status( $new_status, $note, $manual );
3507 3507
 
3508
-		// Save the order.
3509
-		return $this->save();
3508
+        // Save the order.
3509
+        return $this->save();
3510 3510
 
3511
-	}
3511
+    }
3512 3512
 
3513
-	/**
3514
-	 * @deprecated
3515
-	 */
3516
-	public function refresh_item_ids() {
3513
+    /**
3514
+     * @deprecated
3515
+     */
3516
+    public function refresh_item_ids() {
3517 3517
         $item_ids = implode( ',', array_unique( array_keys( $this->get_items() ) ) );
3518 3518
         update_post_meta( $this->get_id(), '_wpinv_item_ids', $item_ids );
3519
-	}
3519
+    }
3520 3520
 
3521
-	/**
3522
-	 * @deprecated
3523
-	 */
3524
-	public function update_items( $temp = false ) {
3521
+    /**
3522
+     * @deprecated
3523
+     */
3524
+    public function update_items( $temp = false ) {
3525 3525
 
3526
-		$this->set_items( $this->get_items() );
3526
+        $this->set_items( $this->get_items() );
3527 3527
 
3528
-		if ( ! $temp ) {
3529
-			$this->save();
3530
-		}
3528
+        if ( ! $temp ) {
3529
+            $this->save();
3530
+        }
3531 3531
 
3532 3532
         return $this;
3533
-	}
3533
+    }
3534 3534
 
3535
-	/**
3536
-	 * @deprecated
3537
-	 */
3535
+    /**
3536
+     * @deprecated
3537
+     */
3538 3538
     public function validate_discount() {
3539 3539
 
3540 3540
         $discount_code = $this->get_discount_code();
@@ -3550,25 +3550,25 @@  discard block
 block discarded – undo
3550 3550
 
3551 3551
     }
3552 3552
 
3553
-	/**
3554
-	 * Refunds an invoice.
3555
-	 */
3553
+    /**
3554
+     * Refunds an invoice.
3555
+     */
3556 3556
     public function refund() {
3557
-		$this->set_status( 'wpi-refunded' );
3557
+        $this->set_status( 'wpi-refunded' );
3558 3558
         $this->save();
3559 3559
     }
3560 3560
 
3561
-	/**
3562
-	 * Save data to the database.
3563
-	 *
3564
-	 * @since 1.0.19
3565
-	 * @return int invoice ID
3566
-	 */
3567
-	public function save() {
3568
-		$this->maybe_set_date_paid();
3569
-		parent::save();
3570
-		$this->status_transition();
3571
-		return $this->get_id();
3572
-	}
3561
+    /**
3562
+     * Save data to the database.
3563
+     *
3564
+     * @since 1.0.19
3565
+     * @return int invoice ID
3566
+     */
3567
+    public function save() {
3568
+        $this->maybe_set_date_paid();
3569
+        parent::save();
3570
+        $this->status_transition();
3571
+        return $this->get_id();
3572
+    }
3573 3573
 
3574 3574
 }
Please login to merge, or discard this patch.
Spacing   +708 added lines, -708 removed lines patch added patch discarded remove patch
@@ -1,8 +1,8 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 // MUST have WordPress.
4
-if ( !defined( 'WPINC' ) ) {
5
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
4
+if (!defined('WPINC')) {
5
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
6 6
 }
7 7
 
8 8
 /**
@@ -130,38 +130,38 @@  discard block
 block discarded – undo
130 130
 	 *
131 131
 	 * @param  int/string|object|WPInv_Invoice|WPInv_Legacy_Invoice|WP_Post $invoice Invoice id, key, number or object to read.
132 132
 	 */
133
-    public function __construct( $invoice = false ) {
133
+    public function __construct($invoice = false) {
134 134
 
135
-        parent::__construct( $invoice );
135
+        parent::__construct($invoice);
136 136
 
137
-		if ( is_numeric( $invoice ) && getpaid_is_invoice_post_type( get_post_type( $invoice ) ) ) {
138
-			$this->set_id( $invoice );
139
-		} elseif ( $invoice instanceof self ) {
140
-			$this->set_id( $invoice->get_id() );
141
-		} elseif ( ! empty( $invoice->ID ) ) {
142
-			$this->set_id( $invoice->ID );
143
-		} elseif ( is_array( $invoice ) ) {
144
-			$this->set_props( $invoice );
137
+		if (is_numeric($invoice) && getpaid_is_invoice_post_type(get_post_type($invoice))) {
138
+			$this->set_id($invoice);
139
+		} elseif ($invoice instanceof self) {
140
+			$this->set_id($invoice->get_id());
141
+		} elseif (!empty($invoice->ID)) {
142
+			$this->set_id($invoice->ID);
143
+		} elseif (is_array($invoice)) {
144
+			$this->set_props($invoice);
145 145
 
146
-			if ( isset( $invoice['ID'] ) ) {
147
-				$this->set_id( $invoice['ID'] );
146
+			if (isset($invoice['ID'])) {
147
+				$this->set_id($invoice['ID']);
148 148
 			}
149 149
 
150
-		} elseif ( is_scalar( $invoice ) && $invoice_id = self::get_discount_id_by_code( $invoice, 'key' ) ) {
151
-			$this->set_id( $invoice_id );
152
-		} elseif ( is_scalar( $invoice ) && $invoice_id = self::get_discount_id_by_code( $invoice, 'number' ) ) {
153
-			$this->set_id( $invoice_id );
150
+		} elseif (is_scalar($invoice) && $invoice_id = self::get_discount_id_by_code($invoice, 'key')) {
151
+			$this->set_id($invoice_id);
152
+		} elseif (is_scalar($invoice) && $invoice_id = self::get_discount_id_by_code($invoice, 'number')) {
153
+			$this->set_id($invoice_id);
154 154
 		} else {
155
-			$this->set_object_read( true );
155
+			$this->set_object_read(true);
156 156
 		}
157 157
 
158 158
         // Load the datastore.
159
-		$this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
159
+		$this->data_store = GetPaid_Data_Store::load($this->data_store_name);
160 160
 
161
-		if ( $this->get_id() > 0 ) {
162
-            $this->post = get_post( $this->get_id() );
161
+		if ($this->get_id() > 0) {
162
+            $this->post = get_post($this->get_id());
163 163
             $this->ID   = $this->get_id();
164
-			$this->data_store->read( $this );
164
+			$this->data_store->read($this);
165 165
         }
166 166
 
167 167
     }
@@ -175,38 +175,38 @@  discard block
 block discarded – undo
175 175
 	 * @since 1.0.15
176 176
 	 * @return int
177 177
 	 */
178
-	public static function get_discount_id_by_code( $invoice_key_or_number, $field = 'key' ) {
178
+	public static function get_discount_id_by_code($invoice_key_or_number, $field = 'key') {
179 179
         global $wpdb;
180 180
 
181 181
 		// Trim the code.
182
-        $key = trim( $invoice_key_or_number );
182
+        $key = trim($invoice_key_or_number);
183 183
 
184 184
         // Valid fields.
185
-        $fields = array( 'key', 'number' );
185
+        $fields = array('key', 'number');
186 186
 
187 187
 		// Ensure a value has been passed.
188
-		if ( empty( $key ) || ! in_array( $field, $fields ) ) {
188
+		if (empty($key) || !in_array($field, $fields)) {
189 189
 			return 0;
190 190
 		}
191 191
 
192 192
 		// Maybe retrieve from the cache.
193
-		$invoice_id   = wp_cache_get( $key, 'getpaid_invoice_keys_' . $field );
194
-		if ( ! empty( $invoice_id ) ) {
193
+		$invoice_id = wp_cache_get($key, 'getpaid_invoice_keys_' . $field);
194
+		if (!empty($invoice_id)) {
195 195
 			return $invoice_id;
196 196
 		}
197 197
 
198 198
         // Fetch from the db.
199 199
         $table       = $wpdb->prefix . 'getpaid_invoices';
200 200
         $invoice_id  = $wpdb->get_var(
201
-            $wpdb->prepare( "SELECT `post_id` FROM $table WHERE $field=%s LIMIT 1", $key )
201
+            $wpdb->prepare("SELECT `post_id` FROM $table WHERE $field=%s LIMIT 1", $key)
202 202
         );
203 203
 
204
-		if ( empty( $invoice_id ) ) {
204
+		if (empty($invoice_id)) {
205 205
 			return 0;
206 206
 		}
207 207
 
208 208
 		// Update the cache with our data
209
-		wp_cache_set( $key, $invoice_id, 'getpaid_invoice_keys_' . $field );
209
+		wp_cache_set($key, $invoice_id, 'getpaid_invoice_keys_' . $field);
210 210
 
211 211
 		return $invoice_id;
212 212
     }
@@ -214,8 +214,8 @@  discard block
 block discarded – undo
214 214
     /**
215 215
      * Checks if an invoice key is set.
216 216
      */
217
-    public function _isset( $key ) {
218
-        return isset( $this->data[$key] ) || method_exists( $this, "get_$key" );
217
+    public function _isset($key) {
218
+        return isset($this->data[$key]) || method_exists($this, "get_$key");
219 219
     }
220 220
 
221 221
     /*
@@ -240,8 +240,8 @@  discard block
 block discarded – undo
240 240
 	 * @param  string $context View or edit context.
241 241
 	 * @return int
242 242
 	 */
243
-	public function get_parent_id( $context = 'view' ) {
244
-		return (int) $this->get_prop( 'parent_id', $context );
243
+	public function get_parent_id($context = 'view') {
244
+		return (int) $this->get_prop('parent_id', $context);
245 245
     }
246 246
 
247 247
     /**
@@ -251,7 +251,7 @@  discard block
 block discarded – undo
251 251
 	 * @return WPInv_Invoice
252 252
 	 */
253 253
     public function get_parent_payment() {
254
-        return new WPInv_Invoice( $this->get_parent_id() );
254
+        return new WPInv_Invoice($this->get_parent_id());
255 255
     }
256 256
 
257 257
     /**
@@ -271,8 +271,8 @@  discard block
 block discarded – undo
271 271
 	 * @param  string $context View or edit context.
272 272
 	 * @return string
273 273
 	 */
274
-	public function get_status( $context = 'view' ) {
275
-		return $this->get_prop( 'status', $context );
274
+	public function get_status($context = 'view') {
275
+		return $this->get_prop('status', $context);
276 276
     }
277 277
 
278 278
     /**
@@ -282,15 +282,15 @@  discard block
 block discarded – undo
282 282
 	 * @return string
283 283
 	 */
284 284
     public function get_status_nicename() {
285
-        $statuses = wpinv_get_invoice_statuses( true, true, $this );
285
+        $statuses = wpinv_get_invoice_statuses(true, true, $this);
286 286
 
287
-        if ( $this->is_quote() && class_exists( 'Wpinv_Quotes_Shared' ) ) {
287
+        if ($this->is_quote() && class_exists('Wpinv_Quotes_Shared')) {
288 288
             $statuses = Wpinv_Quotes_Shared::wpinv_get_quote_statuses();
289 289
         }
290 290
 
291
-        $status = isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : $this->get_status();
291
+        $status = isset($statuses[$this->get_status()]) ? $statuses[$this->get_status()] : $this->get_status();
292 292
 
293
-        return apply_filters( 'wpinv_get_invoice_status_nicename', $status );
293
+        return apply_filters('wpinv_get_invoice_status_nicename', $status);
294 294
     }
295 295
 
296 296
     /**
@@ -300,27 +300,27 @@  discard block
 block discarded – undo
300 300
 	 * @param  string $context View or edit context.
301 301
 	 * @return string
302 302
 	 */
303
-	public function get_version( $context = 'view' ) {
304
-		return $this->get_prop( 'version', $context );
303
+	public function get_version($context = 'view') {
304
+		return $this->get_prop('version', $context);
305 305
 	}
306 306
 
307 307
 	/**
308 308
 	 * @deprecated
309 309
 	 */
310
-	public function get_invoice_date( $formatted = true ) {
310
+	public function get_invoice_date($formatted = true) {
311 311
         $date_completed = $this->get_date_completed();
312 312
         $invoice_date   = $date_completed != '0000-00-00 00:00:00' ? $date_completed : '';
313 313
 
314
-        if ( $invoice_date == '' ) {
314
+        if ($invoice_date == '') {
315 315
             $date_created   = $this->get_date_created();
316 316
             $invoice_date   = $date_created != '0000-00-00 00:00:00' ? $date_created : '';
317 317
         }
318 318
 
319
-        if ( $formatted && $invoice_date ) {
320
-            $invoice_date   = date_i18n( get_option( 'date_format' ), strtotime( $invoice_date ) );
319
+        if ($formatted && $invoice_date) {
320
+            $invoice_date = date_i18n(get_option('date_format'), strtotime($invoice_date));
321 321
         }
322 322
 
323
-        return apply_filters( 'wpinv_get_invoice_date', $invoice_date, $formatted, $this->ID, $this );
323
+        return apply_filters('wpinv_get_invoice_date', $invoice_date, $formatted, $this->ID, $this);
324 324
     }
325 325
 
326 326
     /**
@@ -330,8 +330,8 @@  discard block
 block discarded – undo
330 330
 	 * @param  string $context View or edit context.
331 331
 	 * @return string
332 332
 	 */
333
-	public function get_date_created( $context = 'view' ) {
334
-		return $this->get_prop( 'date_created', $context );
333
+	public function get_date_created($context = 'view') {
334
+		return $this->get_prop('date_created', $context);
335 335
 	}
336 336
 	
337 337
 	/**
@@ -341,8 +341,8 @@  discard block
 block discarded – undo
341 341
 	 * @param  string $context View or edit context.
342 342
 	 * @return string
343 343
 	 */
344
-	public function get_created_date( $context = 'view' ) {
345
-		return $this->get_date_created( $context );
344
+	public function get_created_date($context = 'view') {
345
+		return $this->get_date_created($context);
346 346
     }
347 347
 
348 348
     /**
@@ -352,11 +352,11 @@  discard block
 block discarded – undo
352 352
 	 * @param  string $context View or edit context.
353 353
 	 * @return string
354 354
 	 */
355
-	public function get_date_created_gmt( $context = 'view' ) {
356
-        $date = $this->get_date_created( $context );
355
+	public function get_date_created_gmt($context = 'view') {
356
+        $date = $this->get_date_created($context);
357 357
 
358
-        if ( $date ) {
359
-            $date = get_gmt_from_date( $date );
358
+        if ($date) {
359
+            $date = get_gmt_from_date($date);
360 360
         }
361 361
 		return $date;
362 362
     }
@@ -368,8 +368,8 @@  discard block
 block discarded – undo
368 368
 	 * @param  string $context View or edit context.
369 369
 	 * @return string
370 370
 	 */
371
-	public function get_date_modified( $context = 'view' ) {
372
-		return $this->get_prop( 'date_modified', $context );
371
+	public function get_date_modified($context = 'view') {
372
+		return $this->get_prop('date_modified', $context);
373 373
 	}
374 374
 
375 375
 	/**
@@ -379,8 +379,8 @@  discard block
 block discarded – undo
379 379
 	 * @param  string $context View or edit context.
380 380
 	 * @return string
381 381
 	 */
382
-	public function get_modified_date( $context = 'view' ) {
383
-		return $this->get_date_modified( $context );
382
+	public function get_modified_date($context = 'view') {
383
+		return $this->get_date_modified($context);
384 384
     }
385 385
 
386 386
     /**
@@ -390,11 +390,11 @@  discard block
 block discarded – undo
390 390
 	 * @param  string $context View or edit context.
391 391
 	 * @return string
392 392
 	 */
393
-	public function get_date_modified_gmt( $context = 'view' ) {
394
-        $date = $this->get_date_modified( $context );
393
+	public function get_date_modified_gmt($context = 'view') {
394
+        $date = $this->get_date_modified($context);
395 395
 
396
-        if ( $date ) {
397
-            $date = get_gmt_from_date( $date );
396
+        if ($date) {
397
+            $date = get_gmt_from_date($date);
398 398
         }
399 399
 		return $date;
400 400
     }
@@ -406,8 +406,8 @@  discard block
 block discarded – undo
406 406
 	 * @param  string $context View or edit context.
407 407
 	 * @return string
408 408
 	 */
409
-	public function get_due_date( $context = 'view' ) {
410
-		return $this->get_prop( 'due_date', $context );
409
+	public function get_due_date($context = 'view') {
410
+		return $this->get_prop('due_date', $context);
411 411
     }
412 412
 
413 413
     /**
@@ -417,8 +417,8 @@  discard block
 block discarded – undo
417 417
 	 * @param  string $context View or edit context.
418 418
 	 * @return string
419 419
 	 */
420
-	public function get_date_due( $context = 'view' ) {
421
-		return $this->get_due_date( $context );
420
+	public function get_date_due($context = 'view') {
421
+		return $this->get_due_date($context);
422 422
     }
423 423
 
424 424
     /**
@@ -428,11 +428,11 @@  discard block
 block discarded – undo
428 428
 	 * @param  string $context View or edit context.
429 429
 	 * @return string
430 430
 	 */
431
-	public function get_due_date_gmt( $context = 'view' ) {
432
-        $date = $this->get_due_date( $context );
431
+	public function get_due_date_gmt($context = 'view') {
432
+        $date = $this->get_due_date($context);
433 433
 
434
-        if ( $date ) {
435
-            $date = get_gmt_from_date( $date );
434
+        if ($date) {
435
+            $date = get_gmt_from_date($date);
436 436
         }
437 437
 		return $date;
438 438
     }
@@ -444,8 +444,8 @@  discard block
 block discarded – undo
444 444
 	 * @param  string $context View or edit context.
445 445
 	 * @return string
446 446
 	 */
447
-	public function get_gmt_date_due( $context = 'view' ) {
448
-		return $this->get_due_date_gmt( $context );
447
+	public function get_gmt_date_due($context = 'view') {
448
+		return $this->get_due_date_gmt($context);
449 449
     }
450 450
 
451 451
     /**
@@ -455,8 +455,8 @@  discard block
 block discarded – undo
455 455
 	 * @param  string $context View or edit context.
456 456
 	 * @return string
457 457
 	 */
458
-	public function get_completed_date( $context = 'view' ) {
459
-		return $this->get_prop( 'completed_date', $context );
458
+	public function get_completed_date($context = 'view') {
459
+		return $this->get_prop('completed_date', $context);
460 460
     }
461 461
 
462 462
     /**
@@ -466,8 +466,8 @@  discard block
 block discarded – undo
466 466
 	 * @param  string $context View or edit context.
467 467
 	 * @return string
468 468
 	 */
469
-	public function get_date_completed( $context = 'view' ) {
470
-		return $this->get_completed_date( $context );
469
+	public function get_date_completed($context = 'view') {
470
+		return $this->get_completed_date($context);
471 471
     }
472 472
 
473 473
     /**
@@ -477,11 +477,11 @@  discard block
 block discarded – undo
477 477
 	 * @param  string $context View or edit context.
478 478
 	 * @return string
479 479
 	 */
480
-	public function get_completed_date_gmt( $context = 'view' ) {
481
-        $date = $this->get_completed_date( $context );
480
+	public function get_completed_date_gmt($context = 'view') {
481
+        $date = $this->get_completed_date($context);
482 482
 
483
-        if ( $date ) {
484
-            $date = get_gmt_from_date( $date );
483
+        if ($date) {
484
+            $date = get_gmt_from_date($date);
485 485
         }
486 486
 		return $date;
487 487
     }
@@ -493,8 +493,8 @@  discard block
 block discarded – undo
493 493
 	 * @param  string $context View or edit context.
494 494
 	 * @return string
495 495
 	 */
496
-	public function get_gmt_completed_date( $context = 'view' ) {
497
-		return $this->get_completed_date_gmt( $context );
496
+	public function get_gmt_completed_date($context = 'view') {
497
+		return $this->get_completed_date_gmt($context);
498 498
     }
499 499
 
500 500
     /**
@@ -504,12 +504,12 @@  discard block
 block discarded – undo
504 504
 	 * @param  string $context View or edit context.
505 505
 	 * @return string
506 506
 	 */
507
-	public function get_number( $context = 'view' ) {
508
-        $number = $this->get_prop( 'number', $context );
507
+	public function get_number($context = 'view') {
508
+        $number = $this->get_prop('number', $context);
509 509
 
510
-        if ( empty( $number ) ) {
510
+        if (empty($number)) {
511 511
             $number = $this->generate_number();
512
-            $this->set_number( $number );
512
+            $this->set_number($number);
513 513
         }
514 514
 
515 515
 		return $number;
@@ -522,12 +522,12 @@  discard block
 block discarded – undo
522 522
 	 * @param  string $context View or edit context.
523 523
 	 * @return string
524 524
 	 */
525
-	public function get_key( $context = 'view' ) {
526
-        $key = $this->get_prop( 'key', $context );
525
+	public function get_key($context = 'view') {
526
+        $key = $this->get_prop('key', $context);
527 527
 
528
-        if ( empty( $key ) ) {
529
-            $key = $this->generate_key( $this->post_type );
530
-            $this->set_key( $key );
528
+        if (empty($key)) {
529
+            $key = $this->generate_key($this->post_type);
530
+            $this->set_key($key);
531 531
         }
532 532
 
533 533
 		return $key;
@@ -540,23 +540,23 @@  discard block
 block discarded – undo
540 540
 	 * @param  string $context View or edit context.
541 541
 	 * @return string
542 542
 	 */
543
-	public function get_type( $context = 'view' ) {
544
-        return $this->get_prop( 'type', $context );
543
+	public function get_type($context = 'view') {
544
+        return $this->get_prop('type', $context);
545 545
 	}
546 546
 
547 547
 	/**
548 548
 	 * @deprecated
549 549
 	 */
550
-	public function get_invoice_quote_type( $post_id ) {
551
-        if ( empty( $post_id ) ) {
550
+	public function get_invoice_quote_type($post_id) {
551
+        if (empty($post_id)) {
552 552
             return '';
553 553
         }
554 554
 
555
-        $type = get_post_type( $post_id );
555
+        $type = get_post_type($post_id);
556 556
 
557
-        if ( 'wpi_invoice' === $type ) {
557
+        if ('wpi_invoice' === $type) {
558 558
             $post_type = __('Invoice', 'invoicing');
559
-        } else{
559
+        } else {
560 560
             $post_type = __('Quote', 'invoicing');
561 561
         }
562 562
 
@@ -570,8 +570,8 @@  discard block
 block discarded – undo
570 570
 	 * @param  string $context View or edit context.
571 571
 	 * @return string
572 572
 	 */
573
-	public function get_post_type( $context = 'view' ) {
574
-        return $this->get_prop( 'post_type', $context );
573
+	public function get_post_type($context = 'view') {
574
+        return $this->get_prop('post_type', $context);
575 575
     }
576 576
 
577 577
     /**
@@ -581,8 +581,8 @@  discard block
 block discarded – undo
581 581
 	 * @param  string $context View or edit context.
582 582
 	 * @return string
583 583
 	 */
584
-	public function get_mode( $context = 'view' ) {
585
-        return $this->get_prop( 'mode', $context );
584
+	public function get_mode($context = 'view') {
585
+        return $this->get_prop('mode', $context);
586 586
     }
587 587
 
588 588
     /**
@@ -592,12 +592,12 @@  discard block
 block discarded – undo
592 592
 	 * @param  string $context View or edit context.
593 593
 	 * @return string
594 594
 	 */
595
-	public function get_path( $context = 'view' ) {
596
-        $path = $this->get_prop( 'path', $context );
595
+	public function get_path($context = 'view') {
596
+        $path = $this->get_prop('path', $context);
597 597
 
598
-        if ( empty( $path ) ) {
599
-            $prefix = apply_filters( 'wpinv_post_name_prefix', 'inv-', $this->post_type );
600
-            $path   = sanitize_title( $prefix . $this->get_id() );
598
+        if (empty($path)) {
599
+            $prefix = apply_filters('wpinv_post_name_prefix', 'inv-', $this->post_type);
600
+            $path   = sanitize_title($prefix . $this->get_id());
601 601
         }
602 602
 
603 603
 		return $path;
@@ -610,10 +610,10 @@  discard block
 block discarded – undo
610 610
 	 * @param  string $context View or edit context.
611 611
 	 * @return string
612 612
 	 */
613
-	public function get_name( $context = 'view' ) {
614
-        $name = $this->get_prop( 'title', $context );
613
+	public function get_name($context = 'view') {
614
+        $name = $this->get_prop('title', $context);
615 615
 
616
-		return empty( $name ) ? $this->get_number( $context ) : $name;
616
+		return empty($name) ? $this->get_number($context) : $name;
617 617
     }
618 618
 
619 619
     /**
@@ -623,8 +623,8 @@  discard block
 block discarded – undo
623 623
 	 * @param  string $context View or edit context.
624 624
 	 * @return string
625 625
 	 */
626
-	public function get_title( $context = 'view' ) {
627
-		return $this->get_name( $context );
626
+	public function get_title($context = 'view') {
627
+		return $this->get_name($context);
628 628
     }
629 629
 
630 630
     /**
@@ -634,8 +634,8 @@  discard block
 block discarded – undo
634 634
 	 * @param  string $context View or edit context.
635 635
 	 * @return string
636 636
 	 */
637
-	public function get_description( $context = 'view' ) {
638
-		return $this->get_prop( 'description', $context );
637
+	public function get_description($context = 'view') {
638
+		return $this->get_prop('description', $context);
639 639
     }
640 640
 
641 641
     /**
@@ -645,8 +645,8 @@  discard block
 block discarded – undo
645 645
 	 * @param  string $context View or edit context.
646 646
 	 * @return string
647 647
 	 */
648
-	public function get_excerpt( $context = 'view' ) {
649
-		return $this->get_description( $context );
648
+	public function get_excerpt($context = 'view') {
649
+		return $this->get_description($context);
650 650
     }
651 651
 
652 652
     /**
@@ -656,8 +656,8 @@  discard block
 block discarded – undo
656 656
 	 * @param  string $context View or edit context.
657 657
 	 * @return string
658 658
 	 */
659
-	public function get_summary( $context = 'view' ) {
660
-		return $this->get_description( $context );
659
+	public function get_summary($context = 'view') {
660
+		return $this->get_description($context);
661 661
     }
662 662
 
663 663
     /**
@@ -667,23 +667,23 @@  discard block
 block discarded – undo
667 667
      * @param  string $context View or edit context.
668 668
 	 * @return array
669 669
 	 */
670
-    public function get_user_info( $context = 'view' ) {
670
+    public function get_user_info($context = 'view') {
671 671
         $user_info = array(
672
-            'user_id'    => $this->get_user_id( $context ),
673
-            'email'      => $this->get_email( $context ),
674
-            'first_name' => $this->get_first_name( $context ),
675
-            'last_name'  => $this->get_last_name( $context ),
676
-            'address'    => $this->get_address( $context ),
677
-            'phone'      => $this->get_phone( $context ),
678
-            'city'       => $this->get_city( $context ),
679
-            'country'    => $this->get_country( $context ),
680
-            'state'      => $this->get_state( $context ),
681
-            'zip'        => $this->get_zip( $context ),
682
-            'company'    => $this->get_company( $context ),
683
-            'vat_number' => $this->get_vat_number( $context ),
684
-            'discount'   => $this->get_discount_code( $context ),
672
+            'user_id'    => $this->get_user_id($context),
673
+            'email'      => $this->get_email($context),
674
+            'first_name' => $this->get_first_name($context),
675
+            'last_name'  => $this->get_last_name($context),
676
+            'address'    => $this->get_address($context),
677
+            'phone'      => $this->get_phone($context),
678
+            'city'       => $this->get_city($context),
679
+            'country'    => $this->get_country($context),
680
+            'state'      => $this->get_state($context),
681
+            'zip'        => $this->get_zip($context),
682
+            'company'    => $this->get_company($context),
683
+            'vat_number' => $this->get_vat_number($context),
684
+            'discount'   => $this->get_discount_code($context),
685 685
         );
686
-        return apply_filters( 'wpinv_user_info', $user_info, $this->ID, $this );
686
+        return apply_filters('wpinv_user_info', $user_info, $this->ID, $this);
687 687
     }
688 688
 
689 689
     /**
@@ -693,8 +693,8 @@  discard block
 block discarded – undo
693 693
 	 * @param  string $context View or edit context.
694 694
 	 * @return int
695 695
 	 */
696
-	public function get_author( $context = 'view' ) {
697
-		return (int) $this->get_prop( 'author', $context );
696
+	public function get_author($context = 'view') {
697
+		return (int) $this->get_prop('author', $context);
698 698
     }
699 699
 
700 700
     /**
@@ -704,8 +704,8 @@  discard block
 block discarded – undo
704 704
 	 * @param  string $context View or edit context.
705 705
 	 * @return int
706 706
 	 */
707
-	public function get_user_id( $context = 'view' ) {
708
-		return $this->get_author( $context );
707
+	public function get_user_id($context = 'view') {
708
+		return $this->get_author($context);
709 709
     }
710 710
 
711 711
      /**
@@ -715,8 +715,8 @@  discard block
 block discarded – undo
715 715
 	 * @param  string $context View or edit context.
716 716
 	 * @return int
717 717
 	 */
718
-	public function get_customer_id( $context = 'view' ) {
719
-		return $this->get_author( $context );
718
+	public function get_customer_id($context = 'view') {
719
+		return $this->get_author($context);
720 720
     }
721 721
 
722 722
     /**
@@ -726,8 +726,8 @@  discard block
 block discarded – undo
726 726
 	 * @param  string $context View or edit context.
727 727
 	 * @return string
728 728
 	 */
729
-	public function get_ip( $context = 'view' ) {
730
-		return $this->get_prop( 'user_ip', $context );
729
+	public function get_ip($context = 'view') {
730
+		return $this->get_prop('user_ip', $context);
731 731
     }
732 732
 
733 733
     /**
@@ -737,8 +737,8 @@  discard block
 block discarded – undo
737 737
 	 * @param  string $context View or edit context.
738 738
 	 * @return string
739 739
 	 */
740
-	public function get_user_ip( $context = 'view' ) {
741
-		return $this->get_ip( $context );
740
+	public function get_user_ip($context = 'view') {
741
+		return $this->get_ip($context);
742 742
     }
743 743
 
744 744
      /**
@@ -748,8 +748,8 @@  discard block
 block discarded – undo
748 748
 	 * @param  string $context View or edit context.
749 749
 	 * @return string
750 750
 	 */
751
-	public function get_customer_ip( $context = 'view' ) {
752
-		return $this->get_ip( $context );
751
+	public function get_customer_ip($context = 'view') {
752
+		return $this->get_ip($context);
753 753
     }
754 754
 
755 755
     /**
@@ -759,8 +759,8 @@  discard block
 block discarded – undo
759 759
 	 * @param  string $context View or edit context.
760 760
 	 * @return string
761 761
 	 */
762
-	public function get_first_name( $context = 'view' ) {
763
-		return $this->get_prop( 'first_name', $context );
762
+	public function get_first_name($context = 'view') {
763
+		return $this->get_prop('first_name', $context);
764 764
     }
765 765
 
766 766
     /**
@@ -770,8 +770,8 @@  discard block
 block discarded – undo
770 770
 	 * @param  string $context View or edit context.
771 771
 	 * @return int
772 772
 	 */
773
-	public function get_user_first_name( $context = 'view' ) {
774
-		return $this->get_first_name( $context );
773
+	public function get_user_first_name($context = 'view') {
774
+		return $this->get_first_name($context);
775 775
     }
776 776
 
777 777
      /**
@@ -781,8 +781,8 @@  discard block
 block discarded – undo
781 781
 	 * @param  string $context View or edit context.
782 782
 	 * @return int
783 783
 	 */
784
-	public function get_customer_first_name( $context = 'view' ) {
785
-		return $this->get_first_name( $context );
784
+	public function get_customer_first_name($context = 'view') {
785
+		return $this->get_first_name($context);
786 786
     }
787 787
 
788 788
     /**
@@ -792,8 +792,8 @@  discard block
 block discarded – undo
792 792
 	 * @param  string $context View or edit context.
793 793
 	 * @return string
794 794
 	 */
795
-	public function get_last_name( $context = 'view' ) {
796
-		return $this->get_prop( 'last_name', $context );
795
+	public function get_last_name($context = 'view') {
796
+		return $this->get_prop('last_name', $context);
797 797
     }
798 798
 
799 799
     /**
@@ -803,8 +803,8 @@  discard block
 block discarded – undo
803 803
 	 * @param  string $context View or edit context.
804 804
 	 * @return int
805 805
 	 */
806
-	public function get_user_last_name( $context = 'view' ) {
807
-		return $this->get_last_name( $context );
806
+	public function get_user_last_name($context = 'view') {
807
+		return $this->get_last_name($context);
808 808
     }
809 809
 
810 810
     /**
@@ -814,8 +814,8 @@  discard block
 block discarded – undo
814 814
 	 * @param  string $context View or edit context.
815 815
 	 * @return int
816 816
 	 */
817
-	public function get_customer_last_name( $context = 'view' ) {
818
-		return $this->get_last_name( $context );
817
+	public function get_customer_last_name($context = 'view') {
818
+		return $this->get_last_name($context);
819 819
     }
820 820
 
821 821
     /**
@@ -825,8 +825,8 @@  discard block
 block discarded – undo
825 825
 	 * @param  string $context View or edit context.
826 826
 	 * @return string
827 827
 	 */
828
-	public function get_full_name( $context = 'view' ) {
829
-		return trim( $this->get_first_name( $context ) . ' ' . $this->get_last_name( $context ) );
828
+	public function get_full_name($context = 'view') {
829
+		return trim($this->get_first_name($context) . ' ' . $this->get_last_name($context));
830 830
     }
831 831
 
832 832
     /**
@@ -836,8 +836,8 @@  discard block
 block discarded – undo
836 836
 	 * @param  string $context View or edit context.
837 837
 	 * @return int
838 838
 	 */
839
-	public function get_user_full_name( $context = 'view' ) {
840
-		return $this->get_full_name( $context );
839
+	public function get_user_full_name($context = 'view') {
840
+		return $this->get_full_name($context);
841 841
     }
842 842
 
843 843
     /**
@@ -847,8 +847,8 @@  discard block
 block discarded – undo
847 847
 	 * @param  string $context View or edit context.
848 848
 	 * @return int
849 849
 	 */
850
-	public function get_customer_full_name( $context = 'view' ) {
851
-		return $this->get_full_name( $context );
850
+	public function get_customer_full_name($context = 'view') {
851
+		return $this->get_full_name($context);
852 852
     }
853 853
 
854 854
     /**
@@ -858,8 +858,8 @@  discard block
 block discarded – undo
858 858
 	 * @param  string $context View or edit context.
859 859
 	 * @return string
860 860
 	 */
861
-	public function get_phone( $context = 'view' ) {
862
-		return $this->get_prop( 'phone', $context );
861
+	public function get_phone($context = 'view') {
862
+		return $this->get_prop('phone', $context);
863 863
     }
864 864
 
865 865
     /**
@@ -869,8 +869,8 @@  discard block
 block discarded – undo
869 869
 	 * @param  string $context View or edit context.
870 870
 	 * @return int
871 871
 	 */
872
-	public function get_phone_number( $context = 'view' ) {
873
-		return $this->get_phone( $context );
872
+	public function get_phone_number($context = 'view') {
873
+		return $this->get_phone($context);
874 874
     }
875 875
 
876 876
     /**
@@ -880,8 +880,8 @@  discard block
 block discarded – undo
880 880
 	 * @param  string $context View or edit context.
881 881
 	 * @return int
882 882
 	 */
883
-	public function get_user_phone( $context = 'view' ) {
884
-		return $this->get_phone( $context );
883
+	public function get_user_phone($context = 'view') {
884
+		return $this->get_phone($context);
885 885
     }
886 886
 
887 887
     /**
@@ -891,8 +891,8 @@  discard block
 block discarded – undo
891 891
 	 * @param  string $context View or edit context.
892 892
 	 * @return int
893 893
 	 */
894
-	public function get_customer_phone( $context = 'view' ) {
895
-		return $this->get_phone( $context );
894
+	public function get_customer_phone($context = 'view') {
895
+		return $this->get_phone($context);
896 896
     }
897 897
 
898 898
     /**
@@ -902,8 +902,8 @@  discard block
 block discarded – undo
902 902
 	 * @param  string $context View or edit context.
903 903
 	 * @return string
904 904
 	 */
905
-	public function get_email( $context = 'view' ) {
906
-		return $this->get_prop( 'email', $context );
905
+	public function get_email($context = 'view') {
906
+		return $this->get_prop('email', $context);
907 907
     }
908 908
 
909 909
     /**
@@ -913,8 +913,8 @@  discard block
 block discarded – undo
913 913
 	 * @param  string $context View or edit context.
914 914
 	 * @return string
915 915
 	 */
916
-	public function get_email_address( $context = 'view' ) {
917
-		return $this->get_email( $context );
916
+	public function get_email_address($context = 'view') {
917
+		return $this->get_email($context);
918 918
     }
919 919
 
920 920
     /**
@@ -924,8 +924,8 @@  discard block
 block discarded – undo
924 924
 	 * @param  string $context View or edit context.
925 925
 	 * @return int
926 926
 	 */
927
-	public function get_user_email( $context = 'view' ) {
928
-		return $this->get_email( $context );
927
+	public function get_user_email($context = 'view') {
928
+		return $this->get_email($context);
929 929
     }
930 930
 
931 931
     /**
@@ -935,8 +935,8 @@  discard block
 block discarded – undo
935 935
 	 * @param  string $context View or edit context.
936 936
 	 * @return int
937 937
 	 */
938
-	public function get_customer_email( $context = 'view' ) {
939
-		return $this->get_email( $context );
938
+	public function get_customer_email($context = 'view') {
939
+		return $this->get_email($context);
940 940
     }
941 941
 
942 942
     /**
@@ -946,9 +946,9 @@  discard block
 block discarded – undo
946 946
 	 * @param  string $context View or edit context.
947 947
 	 * @return string
948 948
 	 */
949
-	public function get_country( $context = 'view' ) {
950
-		$country = $this->get_prop( 'country', $context );
951
-		return empty( $country ) ? wpinv_get_default_country() : $country;
949
+	public function get_country($context = 'view') {
950
+		$country = $this->get_prop('country', $context);
951
+		return empty($country) ? wpinv_get_default_country() : $country;
952 952
     }
953 953
 
954 954
     /**
@@ -958,8 +958,8 @@  discard block
 block discarded – undo
958 958
 	 * @param  string $context View or edit context.
959 959
 	 * @return int
960 960
 	 */
961
-	public function get_user_country( $context = 'view' ) {
962
-		return $this->get_country( $context );
961
+	public function get_user_country($context = 'view') {
962
+		return $this->get_country($context);
963 963
     }
964 964
 
965 965
     /**
@@ -969,8 +969,8 @@  discard block
 block discarded – undo
969 969
 	 * @param  string $context View or edit context.
970 970
 	 * @return int
971 971
 	 */
972
-	public function get_customer_country( $context = 'view' ) {
973
-		return $this->get_country( $context );
972
+	public function get_customer_country($context = 'view') {
973
+		return $this->get_country($context);
974 974
     }
975 975
 
976 976
     /**
@@ -980,9 +980,9 @@  discard block
 block discarded – undo
980 980
 	 * @param  string $context View or edit context.
981 981
 	 * @return string
982 982
 	 */
983
-	public function get_state( $context = 'view' ) {
984
-		$state = $this->get_prop( 'state', $context );
985
-		return empty( $state ) ? wpinv_get_default_state() : $state;
983
+	public function get_state($context = 'view') {
984
+		$state = $this->get_prop('state', $context);
985
+		return empty($state) ? wpinv_get_default_state() : $state;
986 986
     }
987 987
 
988 988
     /**
@@ -992,8 +992,8 @@  discard block
 block discarded – undo
992 992
 	 * @param  string $context View or edit context.
993 993
 	 * @return int
994 994
 	 */
995
-	public function get_user_state( $context = 'view' ) {
996
-		return $this->get_state( $context );
995
+	public function get_user_state($context = 'view') {
996
+		return $this->get_state($context);
997 997
     }
998 998
 
999 999
     /**
@@ -1003,8 +1003,8 @@  discard block
 block discarded – undo
1003 1003
 	 * @param  string $context View or edit context.
1004 1004
 	 * @return int
1005 1005
 	 */
1006
-	public function get_customer_state( $context = 'view' ) {
1007
-		return $this->get_state( $context );
1006
+	public function get_customer_state($context = 'view') {
1007
+		return $this->get_state($context);
1008 1008
     }
1009 1009
 
1010 1010
     /**
@@ -1014,8 +1014,8 @@  discard block
 block discarded – undo
1014 1014
 	 * @param  string $context View or edit context.
1015 1015
 	 * @return string
1016 1016
 	 */
1017
-	public function get_city( $context = 'view' ) {
1018
-		return $this->get_prop( 'city', $context );
1017
+	public function get_city($context = 'view') {
1018
+		return $this->get_prop('city', $context);
1019 1019
     }
1020 1020
 
1021 1021
     /**
@@ -1025,8 +1025,8 @@  discard block
 block discarded – undo
1025 1025
 	 * @param  string $context View or edit context.
1026 1026
 	 * @return string
1027 1027
 	 */
1028
-	public function get_user_city( $context = 'view' ) {
1029
-		return $this->get_city( $context );
1028
+	public function get_user_city($context = 'view') {
1029
+		return $this->get_city($context);
1030 1030
     }
1031 1031
 
1032 1032
     /**
@@ -1036,8 +1036,8 @@  discard block
 block discarded – undo
1036 1036
 	 * @param  string $context View or edit context.
1037 1037
 	 * @return string
1038 1038
 	 */
1039
-	public function get_customer_city( $context = 'view' ) {
1040
-		return $this->get_city( $context );
1039
+	public function get_customer_city($context = 'view') {
1040
+		return $this->get_city($context);
1041 1041
     }
1042 1042
 
1043 1043
     /**
@@ -1047,8 +1047,8 @@  discard block
 block discarded – undo
1047 1047
 	 * @param  string $context View or edit context.
1048 1048
 	 * @return string
1049 1049
 	 */
1050
-	public function get_zip( $context = 'view' ) {
1051
-		return $this->get_prop( 'zip', $context );
1050
+	public function get_zip($context = 'view') {
1051
+		return $this->get_prop('zip', $context);
1052 1052
     }
1053 1053
 
1054 1054
     /**
@@ -1058,8 +1058,8 @@  discard block
 block discarded – undo
1058 1058
 	 * @param  string $context View or edit context.
1059 1059
 	 * @return string
1060 1060
 	 */
1061
-	public function get_user_zip( $context = 'view' ) {
1062
-		return $this->get_zip( $context );
1061
+	public function get_user_zip($context = 'view') {
1062
+		return $this->get_zip($context);
1063 1063
     }
1064 1064
 
1065 1065
     /**
@@ -1069,8 +1069,8 @@  discard block
 block discarded – undo
1069 1069
 	 * @param  string $context View or edit context.
1070 1070
 	 * @return string
1071 1071
 	 */
1072
-	public function get_customer_zip( $context = 'view' ) {
1073
-		return $this->get_zip( $context );
1072
+	public function get_customer_zip($context = 'view') {
1073
+		return $this->get_zip($context);
1074 1074
     }
1075 1075
 
1076 1076
     /**
@@ -1080,8 +1080,8 @@  discard block
 block discarded – undo
1080 1080
 	 * @param  string $context View or edit context.
1081 1081
 	 * @return string
1082 1082
 	 */
1083
-	public function get_company( $context = 'view' ) {
1084
-		return $this->get_prop( 'company', $context );
1083
+	public function get_company($context = 'view') {
1084
+		return $this->get_prop('company', $context);
1085 1085
     }
1086 1086
 
1087 1087
     /**
@@ -1091,8 +1091,8 @@  discard block
 block discarded – undo
1091 1091
 	 * @param  string $context View or edit context.
1092 1092
 	 * @return string
1093 1093
 	 */
1094
-	public function get_user_company( $context = 'view' ) {
1095
-		return $this->get_company( $context );
1094
+	public function get_user_company($context = 'view') {
1095
+		return $this->get_company($context);
1096 1096
     }
1097 1097
 
1098 1098
     /**
@@ -1102,8 +1102,8 @@  discard block
 block discarded – undo
1102 1102
 	 * @param  string $context View or edit context.
1103 1103
 	 * @return string
1104 1104
 	 */
1105
-	public function get_customer_company( $context = 'view' ) {
1106
-		return $this->get_company( $context );
1105
+	public function get_customer_company($context = 'view') {
1106
+		return $this->get_company($context);
1107 1107
     }
1108 1108
 
1109 1109
     /**
@@ -1113,8 +1113,8 @@  discard block
 block discarded – undo
1113 1113
 	 * @param  string $context View or edit context.
1114 1114
 	 * @return string
1115 1115
 	 */
1116
-	public function get_vat_number( $context = 'view' ) {
1117
-		return $this->get_prop( 'vat_number', $context );
1116
+	public function get_vat_number($context = 'view') {
1117
+		return $this->get_prop('vat_number', $context);
1118 1118
     }
1119 1119
 
1120 1120
     /**
@@ -1124,8 +1124,8 @@  discard block
 block discarded – undo
1124 1124
 	 * @param  string $context View or edit context.
1125 1125
 	 * @return string
1126 1126
 	 */
1127
-	public function get_user_vat_number( $context = 'view' ) {
1128
-		return $this->get_vat_number( $context );
1127
+	public function get_user_vat_number($context = 'view') {
1128
+		return $this->get_vat_number($context);
1129 1129
     }
1130 1130
 
1131 1131
     /**
@@ -1135,8 +1135,8 @@  discard block
 block discarded – undo
1135 1135
 	 * @param  string $context View or edit context.
1136 1136
 	 * @return string
1137 1137
 	 */
1138
-	public function get_customer_vat_number( $context = 'view' ) {
1139
-		return $this->get_vat_number( $context );
1138
+	public function get_customer_vat_number($context = 'view') {
1139
+		return $this->get_vat_number($context);
1140 1140
     }
1141 1141
 
1142 1142
     /**
@@ -1146,8 +1146,8 @@  discard block
 block discarded – undo
1146 1146
 	 * @param  string $context View or edit context.
1147 1147
 	 * @return string
1148 1148
 	 */
1149
-	public function get_vat_rate( $context = 'view' ) {
1150
-		return $this->get_prop( 'vat_rate', $context );
1149
+	public function get_vat_rate($context = 'view') {
1150
+		return $this->get_prop('vat_rate', $context);
1151 1151
     }
1152 1152
 
1153 1153
     /**
@@ -1157,8 +1157,8 @@  discard block
 block discarded – undo
1157 1157
 	 * @param  string $context View or edit context.
1158 1158
 	 * @return string
1159 1159
 	 */
1160
-	public function get_user_vat_rate( $context = 'view' ) {
1161
-		return $this->get_vat_rate( $context );
1160
+	public function get_user_vat_rate($context = 'view') {
1161
+		return $this->get_vat_rate($context);
1162 1162
     }
1163 1163
 
1164 1164
     /**
@@ -1168,8 +1168,8 @@  discard block
 block discarded – undo
1168 1168
 	 * @param  string $context View or edit context.
1169 1169
 	 * @return string
1170 1170
 	 */
1171
-	public function get_customer_vat_rate( $context = 'view' ) {
1172
-		return $this->get_vat_rate( $context );
1171
+	public function get_customer_vat_rate($context = 'view') {
1172
+		return $this->get_vat_rate($context);
1173 1173
     }
1174 1174
 
1175 1175
     /**
@@ -1179,8 +1179,8 @@  discard block
 block discarded – undo
1179 1179
 	 * @param  string $context View or edit context.
1180 1180
 	 * @return string
1181 1181
 	 */
1182
-	public function get_address( $context = 'view' ) {
1183
-		return $this->get_prop( 'address', $context );
1182
+	public function get_address($context = 'view') {
1183
+		return $this->get_prop('address', $context);
1184 1184
     }
1185 1185
 
1186 1186
     /**
@@ -1190,8 +1190,8 @@  discard block
 block discarded – undo
1190 1190
 	 * @param  string $context View or edit context.
1191 1191
 	 * @return string
1192 1192
 	 */
1193
-	public function get_user_address( $context = 'view' ) {
1194
-		return $this->get_address( $context );
1193
+	public function get_user_address($context = 'view') {
1194
+		return $this->get_address($context);
1195 1195
     }
1196 1196
 
1197 1197
     /**
@@ -1201,8 +1201,8 @@  discard block
 block discarded – undo
1201 1201
 	 * @param  string $context View or edit context.
1202 1202
 	 * @return string
1203 1203
 	 */
1204
-	public function get_customer_address( $context = 'view' ) {
1205
-		return $this->get_address( $context );
1204
+	public function get_customer_address($context = 'view') {
1205
+		return $this->get_address($context);
1206 1206
     }
1207 1207
 
1208 1208
     /**
@@ -1212,8 +1212,8 @@  discard block
 block discarded – undo
1212 1212
 	 * @param  string $context View or edit context.
1213 1213
 	 * @return bool
1214 1214
 	 */
1215
-	public function get_is_viewed( $context = 'view' ) {
1216
-		return (bool) $this->get_prop( 'is_viewed', $context );
1215
+	public function get_is_viewed($context = 'view') {
1216
+		return (bool) $this->get_prop('is_viewed', $context);
1217 1217
 	}
1218 1218
 
1219 1219
 	/**
@@ -1223,8 +1223,8 @@  discard block
 block discarded – undo
1223 1223
 	 * @param  string $context View or edit context.
1224 1224
 	 * @return bool
1225 1225
 	 */
1226
-	public function get_email_cc( $context = 'view' ) {
1227
-		return $this->get_prop( 'email_cc', $context );
1226
+	public function get_email_cc($context = 'view') {
1227
+		return $this->get_prop('email_cc', $context);
1228 1228
 	}
1229 1229
 
1230 1230
 	/**
@@ -1234,8 +1234,8 @@  discard block
 block discarded – undo
1234 1234
 	 * @param  string $context View or edit context.
1235 1235
 	 * @return bool
1236 1236
 	 */
1237
-	public function get_template( $context = 'view' ) {
1238
-		return $this->get_prop( 'template', $context );
1237
+	public function get_template($context = 'view') {
1238
+		return $this->get_prop('template', $context);
1239 1239
 	}
1240 1240
 
1241 1241
 	/**
@@ -1245,8 +1245,8 @@  discard block
 block discarded – undo
1245 1245
 	 * @param  string $context View or edit context.
1246 1246
 	 * @return bool
1247 1247
 	 */
1248
-	public function get_address_confirmed( $context = 'view' ) {
1249
-		return (bool) $this->get_prop( 'address_confirmed', $context );
1248
+	public function get_address_confirmed($context = 'view') {
1249
+		return (bool) $this->get_prop('address_confirmed', $context);
1250 1250
     }
1251 1251
 
1252 1252
     /**
@@ -1256,8 +1256,8 @@  discard block
 block discarded – undo
1256 1256
 	 * @param  string $context View or edit context.
1257 1257
 	 * @return bool
1258 1258
 	 */
1259
-	public function get_user_address_confirmed( $context = 'view' ) {
1260
-		return $this->get_address_confirmed( $context );
1259
+	public function get_user_address_confirmed($context = 'view') {
1260
+		return $this->get_address_confirmed($context);
1261 1261
     }
1262 1262
 
1263 1263
     /**
@@ -1267,8 +1267,8 @@  discard block
 block discarded – undo
1267 1267
 	 * @param  string $context View or edit context.
1268 1268
 	 * @return bool
1269 1269
 	 */
1270
-	public function get_customer_address_confirmed( $context = 'view' ) {
1271
-		return $this->get_address_confirmed( $context );
1270
+	public function get_customer_address_confirmed($context = 'view') {
1271
+		return $this->get_address_confirmed($context);
1272 1272
     }
1273 1273
 
1274 1274
     /**
@@ -1278,12 +1278,12 @@  discard block
 block discarded – undo
1278 1278
 	 * @param  string $context View or edit context.
1279 1279
 	 * @return float
1280 1280
 	 */
1281
-	public function get_subtotal( $context = 'view' ) {
1282
-        $subtotal = (float) $this->get_prop( 'subtotal', $context );
1281
+	public function get_subtotal($context = 'view') {
1282
+        $subtotal = (float) $this->get_prop('subtotal', $context);
1283 1283
 
1284 1284
         // Backwards compatibility.
1285
-        if ( is_bool( $context ) && $context ) {
1286
-            return wpinv_price( wpinv_format_amount( $subtotal ), $this->get_currency() );
1285
+        if (is_bool($context) && $context) {
1286
+            return wpinv_price(wpinv_format_amount($subtotal), $this->get_currency());
1287 1287
         }
1288 1288
 
1289 1289
         return $subtotal;
@@ -1296,8 +1296,8 @@  discard block
 block discarded – undo
1296 1296
 	 * @param  string $context View or edit context.
1297 1297
 	 * @return float
1298 1298
 	 */
1299
-	public function get_total_discount( $context = 'view' ) {
1300
-		return (float) $this->get_prop( 'total_discount', $context );
1299
+	public function get_total_discount($context = 'view') {
1300
+		return (float) $this->get_prop('total_discount', $context);
1301 1301
     }
1302 1302
 
1303 1303
     /**
@@ -1307,18 +1307,18 @@  discard block
 block discarded – undo
1307 1307
 	 * @param  string $context View or edit context.
1308 1308
 	 * @return float
1309 1309
 	 */
1310
-	public function get_total_tax( $context = 'view' ) {
1311
-		return (float) $this->get_prop( 'total_tax', $context );
1310
+	public function get_total_tax($context = 'view') {
1311
+		return (float) $this->get_prop('total_tax', $context);
1312 1312
 	}
1313 1313
 
1314 1314
 	/**
1315 1315
 	 * @deprecated
1316 1316
 	 */
1317
-	public function get_final_tax( $currency = false ) {
1317
+	public function get_final_tax($currency = false) {
1318 1318
 		$tax = $this->get_total_tax();
1319 1319
 
1320
-        if ( $currency ) {
1321
-			return wpinv_price( wpinv_format_amount( $tax, NULL, false ), $this->get_currency() );
1320
+        if ($currency) {
1321
+			return wpinv_price(wpinv_format_amount($tax, NULL, false), $this->get_currency());
1322 1322
         }
1323 1323
 
1324 1324
         return $tax;
@@ -1331,8 +1331,8 @@  discard block
 block discarded – undo
1331 1331
 	 * @param  string $context View or edit context.
1332 1332
 	 * @return float
1333 1333
 	 */
1334
-	public function get_total_fees( $context = 'view' ) {
1335
-		return (float) $this->get_prop( 'total_fees', $context );
1334
+	public function get_total_fees($context = 'view') {
1335
+		return (float) $this->get_prop('total_fees', $context);
1336 1336
     }
1337 1337
 
1338 1338
     /**
@@ -1342,8 +1342,8 @@  discard block
 block discarded – undo
1342 1342
 	 * @param  string $context View or edit context.
1343 1343
 	 * @return float
1344 1344
 	 */
1345
-	public function get_fees_total( $context = 'view' ) {
1346
-		return $this->get_total_fees( $context );
1345
+	public function get_fees_total($context = 'view') {
1346
+		return $this->get_total_fees($context);
1347 1347
     }
1348 1348
 
1349 1349
     /**
@@ -1354,7 +1354,7 @@  discard block
 block discarded – undo
1354 1354
 	 */
1355 1355
 	public function get_total() {
1356 1356
 		$total = $this->is_renewal() ? $this->get_recurring_total() : $this->get_initial_total();
1357
-		return apply_filters( 'getpaid_get_invoice_total_amount', $total, $this  );
1357
+		return apply_filters('getpaid_get_invoice_total_amount', $total, $this);
1358 1358
     }
1359 1359
 
1360 1360
     /**
@@ -1366,7 +1366,7 @@  discard block
 block discarded – undo
1366 1366
 	 */
1367 1367
     public function get_initial_total() {
1368 1368
 
1369
-		if ( empty( $this->totals ) ) {
1369
+		if (empty($this->totals)) {
1370 1370
 			$this->recalculate_total();
1371 1371
 		}
1372 1372
 
@@ -1376,11 +1376,11 @@  discard block
 block discarded – undo
1376 1376
 		$subtotal = $this->totals['subtotal']['initial'];
1377 1377
 		$total    = $tax + $fee - $discount + $subtotal;
1378 1378
 
1379
-		if ( 0 > $total ) {
1379
+		if (0 > $total) {
1380 1380
 			$total = 0;
1381 1381
 		}
1382 1382
 
1383
-        return apply_filters( 'wpinv_get_initial_invoice_total', $total, $this );
1383
+        return apply_filters('wpinv_get_initial_invoice_total', $total, $this);
1384 1384
 	}
1385 1385
 
1386 1386
 	/**
@@ -1392,7 +1392,7 @@  discard block
 block discarded – undo
1392 1392
 	 */
1393 1393
     public function get_recurring_total() {
1394 1394
 
1395
-		if ( empty( $this->totals ) ) {
1395
+		if (empty($this->totals)) {
1396 1396
 			$this->recalculate_total();
1397 1397
 		}
1398 1398
 
@@ -1402,11 +1402,11 @@  discard block
 block discarded – undo
1402 1402
 		$subtotal = $this->totals['subtotal']['recurring'];
1403 1403
 		$total    = $tax + $fee - $discount + $subtotal;
1404 1404
 
1405
-		if ( 0 > $total ) {
1405
+		if (0 > $total) {
1406 1406
 			$total = 0;
1407 1407
 		}
1408 1408
 
1409
-        return apply_filters( 'wpinv_get_recurring_invoice_total', $total, $this );
1409
+        return apply_filters('wpinv_get_recurring_invoice_total', $total, $this);
1410 1410
 	}
1411 1411
 
1412 1412
 	/**
@@ -1417,10 +1417,10 @@  discard block
 block discarded – undo
1417 1417
 	 * @param string $currency Whether to include the currency.
1418 1418
      * @return float
1419 1419
 	 */
1420
-    public function get_recurring_details( $field = '', $currency = false ) {
1420
+    public function get_recurring_details($field = '', $currency = false) {
1421 1421
 
1422 1422
 		// Maybe recalculate totals.
1423
-		if ( empty( $this->totals ) ) {
1423
+		if (empty($this->totals)) {
1424 1424
 			$this->recalculate_total();
1425 1425
 		}
1426 1426
 
@@ -1440,8 +1440,8 @@  discard block
 block discarded – undo
1440 1440
 			$currency
1441 1441
 		);
1442 1442
 
1443
-        if ( isset( $data[$field] ) ) {
1444
-            return ( $currency ? wpinv_price( $data[$field], $this->get_currency() ) : $data[$field] );
1443
+        if (isset($data[$field])) {
1444
+            return ($currency ? wpinv_price($data[$field], $this->get_currency()) : $data[$field]);
1445 1445
         }
1446 1446
 
1447 1447
         return $data;
@@ -1454,8 +1454,8 @@  discard block
 block discarded – undo
1454 1454
 	 * @param  string $context View or edit context.
1455 1455
 	 * @return array
1456 1456
 	 */
1457
-	public function get_fees( $context = 'view' ) {
1458
-		return wpinv_parse_list( $this->get_prop( 'fees', $context ) );
1457
+	public function get_fees($context = 'view') {
1458
+		return wpinv_parse_list($this->get_prop('fees', $context));
1459 1459
     }
1460 1460
 
1461 1461
     /**
@@ -1465,8 +1465,8 @@  discard block
 block discarded – undo
1465 1465
 	 * @param  string $context View or edit context.
1466 1466
 	 * @return array
1467 1467
 	 */
1468
-	public function get_discounts( $context = 'view' ) {
1469
-		return wpinv_parse_list( $this->get_prop( 'discounts', $context ) );
1468
+	public function get_discounts($context = 'view') {
1469
+		return wpinv_parse_list($this->get_prop('discounts', $context));
1470 1470
     }
1471 1471
 
1472 1472
     /**
@@ -1476,8 +1476,8 @@  discard block
 block discarded – undo
1476 1476
 	 * @param  string $context View or edit context.
1477 1477
 	 * @return array
1478 1478
 	 */
1479
-	public function get_taxes( $context = 'view' ) {
1480
-		return wpinv_parse_list( $this->get_prop( 'taxes', $context ) );
1479
+	public function get_taxes($context = 'view') {
1480
+		return wpinv_parse_list($this->get_prop('taxes', $context));
1481 1481
     }
1482 1482
 
1483 1483
     /**
@@ -1487,8 +1487,8 @@  discard block
 block discarded – undo
1487 1487
 	 * @param  string $context View or edit context.
1488 1488
 	 * @return GetPaid_Form_Item[]
1489 1489
 	 */
1490
-	public function get_items( $context = 'view' ) {
1491
-        return $this->get_prop( 'items', $context );
1490
+	public function get_items($context = 'view') {
1491
+        return $this->get_prop('items', $context);
1492 1492
     }
1493 1493
 
1494 1494
     /**
@@ -1498,8 +1498,8 @@  discard block
 block discarded – undo
1498 1498
 	 * @param  string $context View or edit context.
1499 1499
 	 * @return int
1500 1500
 	 */
1501
-	public function get_payment_form( $context = 'view' ) {
1502
-		return intval( $this->get_prop( 'payment_form', $context ) );
1501
+	public function get_payment_form($context = 'view') {
1502
+		return intval($this->get_prop('payment_form', $context));
1503 1503
     }
1504 1504
 
1505 1505
     /**
@@ -1509,8 +1509,8 @@  discard block
 block discarded – undo
1509 1509
 	 * @param  string $context View or edit context.
1510 1510
 	 * @return string
1511 1511
 	 */
1512
-	public function get_submission_id( $context = 'view' ) {
1513
-		return $this->get_prop( 'submission_id', $context );
1512
+	public function get_submission_id($context = 'view') {
1513
+		return $this->get_prop('submission_id', $context);
1514 1514
     }
1515 1515
 
1516 1516
     /**
@@ -1520,8 +1520,8 @@  discard block
 block discarded – undo
1520 1520
 	 * @param  string $context View or edit context.
1521 1521
 	 * @return string
1522 1522
 	 */
1523
-	public function get_discount_code( $context = 'view' ) {
1524
-		return $this->get_prop( 'discount_code', $context );
1523
+	public function get_discount_code($context = 'view') {
1524
+		return $this->get_prop('discount_code', $context);
1525 1525
     }
1526 1526
 
1527 1527
     /**
@@ -1531,8 +1531,8 @@  discard block
 block discarded – undo
1531 1531
 	 * @param  string $context View or edit context.
1532 1532
 	 * @return string
1533 1533
 	 */
1534
-	public function get_gateway( $context = 'view' ) {
1535
-		return $this->get_prop( 'gateway', $context );
1534
+	public function get_gateway($context = 'view') {
1535
+		return $this->get_prop('gateway', $context);
1536 1536
     }
1537 1537
 
1538 1538
     /**
@@ -1542,8 +1542,8 @@  discard block
 block discarded – undo
1542 1542
 	 * @return string
1543 1543
 	 */
1544 1544
     public function get_gateway_title() {
1545
-        $title =  wpinv_get_gateway_checkout_label( $this->get_gateway() );
1546
-        return apply_filters( 'wpinv_gateway_title', $title, $this->ID, $this );
1545
+        $title = wpinv_get_gateway_checkout_label($this->get_gateway());
1546
+        return apply_filters('wpinv_gateway_title', $title, $this->ID, $this);
1547 1547
     }
1548 1548
 
1549 1549
     /**
@@ -1553,8 +1553,8 @@  discard block
 block discarded – undo
1553 1553
 	 * @param  string $context View or edit context.
1554 1554
 	 * @return string
1555 1555
 	 */
1556
-	public function get_transaction_id( $context = 'view' ) {
1557
-		return $this->get_prop( 'transaction_id', $context );
1556
+	public function get_transaction_id($context = 'view') {
1557
+		return $this->get_prop('transaction_id', $context);
1558 1558
     }
1559 1559
 
1560 1560
     /**
@@ -1564,9 +1564,9 @@  discard block
 block discarded – undo
1564 1564
 	 * @param  string $context View or edit context.
1565 1565
 	 * @return string
1566 1566
 	 */
1567
-	public function get_currency( $context = 'view' ) {
1568
-        $currency = $this->get_prop( 'currency', $context );
1569
-        return empty( $currency ) ? wpinv_get_currency() : $currency;
1567
+	public function get_currency($context = 'view') {
1568
+        $currency = $this->get_prop('currency', $context);
1569
+        return empty($currency) ? wpinv_get_currency() : $currency;
1570 1570
     }
1571 1571
 
1572 1572
     /**
@@ -1576,8 +1576,8 @@  discard block
 block discarded – undo
1576 1576
 	 * @param  string $context View or edit context.
1577 1577
 	 * @return bool
1578 1578
 	 */
1579
-	public function get_disable_taxes( $context = 'view' ) {
1580
-        return (bool) $this->get_prop( 'disable_taxes', $context );
1579
+	public function get_disable_taxes($context = 'view') {
1580
+        return (bool) $this->get_prop('disable_taxes', $context);
1581 1581
     }
1582 1582
 
1583 1583
     /**
@@ -1587,12 +1587,12 @@  discard block
 block discarded – undo
1587 1587
 	 * @param  string $context View or edit context.
1588 1588
 	 * @return int
1589 1589
 	 */
1590
-    public function get_subscription_id( $context = 'view' ) {
1591
-        $subscription_id = $this->get_prop( 'subscription_id', $context );
1590
+    public function get_subscription_id($context = 'view') {
1591
+        $subscription_id = $this->get_prop('subscription_id', $context);
1592 1592
 
1593
-        if ( empty( $subscription_id ) && $this->is_renewal() ) {
1593
+        if (empty($subscription_id) && $this->is_renewal()) {
1594 1594
             $parent = $this->get_parent();
1595
-            return $parent->get_subscription_id( $context );
1595
+            return $parent->get_subscription_id($context);
1596 1596
         }
1597 1597
 
1598 1598
         return $subscription_id;
@@ -1605,20 +1605,20 @@  discard block
 block discarded – undo
1605 1605
 	 * @param  string $context View or edit context.
1606 1606
 	 * @return array
1607 1607
 	 */
1608
-    public function get_payment_meta( $context = 'view' ) {
1608
+    public function get_payment_meta($context = 'view') {
1609 1609
 
1610 1610
         return array(
1611
-            'price'        => $this->get_total( $context ),
1612
-            'date'         => $this->get_date_created( $context ),
1613
-            'user_email'   => $this->get_email( $context ),
1614
-            'invoice_key'  => $this->get_key( $context ),
1615
-            'currency'     => $this->get_currency( $context ),
1616
-            'items'        => $this->get_items( $context ),
1617
-            'user_info'    => $this->get_user_info( $context ),
1611
+            'price'        => $this->get_total($context),
1612
+            'date'         => $this->get_date_created($context),
1613
+            'user_email'   => $this->get_email($context),
1614
+            'invoice_key'  => $this->get_key($context),
1615
+            'currency'     => $this->get_currency($context),
1616
+            'items'        => $this->get_items($context),
1617
+            'user_info'    => $this->get_user_info($context),
1618 1618
             'cart_details' => $this->get_cart_details(),
1619
-            'status'       => $this->get_status( $context ),
1620
-            'fees'         => $this->get_fees( $context ),
1621
-            'taxes'        => $this->get_taxes( $context ),
1619
+            'status'       => $this->get_status($context),
1620
+            'fees'         => $this->get_fees($context),
1621
+            'taxes'        => $this->get_taxes($context),
1622 1622
         );
1623 1623
 
1624 1624
     }
@@ -1633,7 +1633,7 @@  discard block
 block discarded – undo
1633 1633
         $items        = $this->get_items();
1634 1634
         $cart_details = array();
1635 1635
 
1636
-        foreach ( $items as $item_id => $item ) {
1636
+        foreach ($items as $item_id => $item) {
1637 1637
             $cart_details[] = $item->prepare_data_for_saving();
1638 1638
         }
1639 1639
 
@@ -1645,11 +1645,11 @@  discard block
 block discarded – undo
1645 1645
 	 *
1646 1646
 	 * @return null|GetPaid_Form_Item
1647 1647
 	 */
1648
-	public function get_recurring( $object = false ) {
1648
+	public function get_recurring($object = false) {
1649 1649
 
1650 1650
 		// Are we returning an object?
1651
-        if ( $object ) {
1652
-            return $this->get_item( $this->recurring_item );
1651
+        if ($object) {
1652
+            return $this->get_item($this->recurring_item);
1653 1653
         }
1654 1654
 
1655 1655
         return $this->recurring_item;
@@ -1664,15 +1664,15 @@  discard block
 block discarded – undo
1664 1664
 	public function get_subscription_name() {
1665 1665
 
1666 1666
 		// Retrieve the recurring name
1667
-        $item = $this->get_recurring( true );
1667
+        $item = $this->get_recurring(true);
1668 1668
 
1669 1669
 		// Abort if it does not exist.
1670
-        if ( empty( $item ) ) {
1670
+        if (empty($item)) {
1671 1671
             return '';
1672 1672
         }
1673 1673
 
1674 1674
 		// Return the item name.
1675
-        return apply_filters( 'wpinv_invoice_get_subscription_name', $item->get_name(), $this );
1675
+        return apply_filters('wpinv_invoice_get_subscription_name', $item->get_name(), $this);
1676 1676
 	}
1677 1677
 
1678 1678
 	/**
@@ -1682,9 +1682,9 @@  discard block
 block discarded – undo
1682 1682
 	 * @return string
1683 1683
 	 */
1684 1684
 	public function get_view_url() {
1685
-        $invoice_url = get_permalink( $this->get_id() );
1686
-		$invoice_url = add_query_arg( 'invoice_key', $this->get_key(), $invoice_url );
1687
-        return apply_filters( 'wpinv_get_view_url', $invoice_url, $this );
1685
+        $invoice_url = get_permalink($this->get_id());
1686
+		$invoice_url = add_query_arg('invoice_key', $this->get_key(), $invoice_url);
1687
+        return apply_filters('wpinv_get_view_url', $invoice_url, $this);
1688 1688
 	}
1689 1689
 
1690 1690
 	/**
@@ -1693,25 +1693,25 @@  discard block
 block discarded – undo
1693 1693
 	 * @since 1.0.19
1694 1694
 	 * @return string
1695 1695
 	 */
1696
-	public function get_checkout_payment_url( $deprecated = false, $secret = false ) {
1696
+	public function get_checkout_payment_url($deprecated = false, $secret = false) {
1697 1697
 
1698 1698
 		// Retrieve the checkout url.
1699 1699
         $pay_url = wpinv_get_checkout_uri();
1700 1700
 
1701 1701
 		// Maybe force ssl.
1702
-        if ( is_ssl() ) {
1703
-            $pay_url = str_replace( 'http:', 'https:', $pay_url );
1702
+        if (is_ssl()) {
1703
+            $pay_url = str_replace('http:', 'https:', $pay_url);
1704 1704
         }
1705 1705
 
1706 1706
 		// Add the invoice key.
1707
-		$pay_url = add_query_arg( 'invoice_key', $this->get_key(), $pay_url );
1707
+		$pay_url = add_query_arg('invoice_key', $this->get_key(), $pay_url);
1708 1708
 
1709 1709
 		// (Maybe?) add a secret
1710
-        if ( $secret ) {
1711
-            $pay_url = add_query_arg( array( '_wpipay' => md5( $this->get_user_id() . '::' . $this->get_email() . '::' . $this->get_key() ) ), $pay_url );
1710
+        if ($secret) {
1711
+            $pay_url = add_query_arg(array('_wpipay' => md5($this->get_user_id() . '::' . $this->get_email() . '::' . $this->get_key())), $pay_url);
1712 1712
         }
1713 1713
 
1714
-        return apply_filters( 'wpinv_get_checkout_payment_url', $pay_url, $this, $deprecated, $secret );
1714
+        return apply_filters('wpinv_get_checkout_payment_url', $pay_url, $this, $deprecated, $secret);
1715 1715
     }
1716 1716
 
1717 1717
     /**
@@ -1724,8 +1724,8 @@  discard block
 block discarded – undo
1724 1724
 	 * @param  string $context View or edit context.
1725 1725
 	 * @return mixed Value of the given invoice property (if set).
1726 1726
 	 */
1727
-	public function get( $key, $context = 'view' ) {
1728
-        return $this->get_prop( $key, $context );
1727
+	public function get($key, $context = 'view') {
1728
+        return $this->get_prop($key, $context);
1729 1729
 	}
1730 1730
 
1731 1731
     /*
@@ -1748,11 +1748,11 @@  discard block
 block discarded – undo
1748 1748
 	 * @param  mixed $value new value.
1749 1749
 	 * @return mixed Value of the given invoice property (if set).
1750 1750
 	 */
1751
-	public function set( $key, $value ) {
1751
+	public function set($key, $value) {
1752 1752
 
1753 1753
         $setter = "set_$key";
1754
-        if ( is_callable( array( $this, $setter ) ) ) {
1755
-            $this->{$setter}( $value );
1754
+        if (is_callable(array($this, $setter))) {
1755
+            $this->{$setter}($value);
1756 1756
         }
1757 1757
 
1758 1758
 	}
@@ -1766,35 +1766,35 @@  discard block
 block discarded – undo
1766 1766
 	 * @param bool   $manual_update Is this a manual status change?.
1767 1767
 	 * @return array details of change.
1768 1768
 	 */
1769
-	public function set_status( $new_status, $note = '', $manual_update = false ) {
1769
+	public function set_status($new_status, $note = '', $manual_update = false) {
1770 1770
 		$old_status = $this->get_status();
1771 1771
 
1772
-		$this->set_prop( 'status', $new_status );
1772
+		$this->set_prop('status', $new_status);
1773 1773
 
1774 1774
 		// If setting the status, ensure it's set to a valid status.
1775
-		if ( true === $this->object_read ) {
1775
+		if (true === $this->object_read) {
1776 1776
 
1777 1777
 			// Only allow valid new status.
1778
-			if ( ! array_key_exists( $new_status, wpinv_get_invoice_statuses( false, true ) ) ) {
1778
+			if (!array_key_exists($new_status, wpinv_get_invoice_statuses(false, true))) {
1779 1779
 				$new_status = 'wpi-pending';
1780 1780
 			}
1781 1781
 
1782 1782
 			// If the old status is set but unknown (e.g. draft) assume its pending for action usage.
1783
-			if ( $old_status && ! array_key_exists( $new_status, wpinv_get_invoice_statuses( false, true ) ) ) {
1783
+			if ($old_status && !array_key_exists($new_status, wpinv_get_invoice_statuses(false, true))) {
1784 1784
 				$old_status = 'wpi-pending';
1785 1785
 			}
1786 1786
 		}
1787 1787
 
1788
-		if ( true === $this->object_read && $old_status !== $new_status ) {
1788
+		if (true === $this->object_read && $old_status !== $new_status) {
1789 1789
 			$this->status_transition = array(
1790
-				'from'   => ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $old_status,
1790
+				'from'   => !empty($this->status_transition['from']) ? $this->status_transition['from'] : $old_status,
1791 1791
 				'to'     => $new_status,
1792 1792
 				'note'   => $note,
1793 1793
 				'manual' => (bool) $manual_update,
1794 1794
 			);
1795 1795
 
1796
-			if ( $manual_update ) {
1797
-				do_action( 'getpaid_' . $this->object_type .'_edit_status', $this->get_id(), $new_status );
1796
+			if ($manual_update) {
1797
+				do_action('getpaid_' . $this->object_type . '_edit_status', $this->get_id(), $new_status);
1798 1798
 			}
1799 1799
 
1800 1800
 			$this->maybe_set_date_paid();
@@ -1817,8 +1817,8 @@  discard block
 block discarded – undo
1817 1817
 	 */
1818 1818
 	public function maybe_set_date_paid() {
1819 1819
 
1820
-		if ( ! $this->get_date_completed( 'edit' ) && $this->is_paid() ) {
1821
-			$this->set_date_completed( current_time( 'mysql' ) );
1820
+		if (!$this->get_date_completed('edit') && $this->is_paid()) {
1821
+			$this->set_date_completed(current_time('mysql'));
1822 1822
 		}
1823 1823
 	}
1824 1824
 
@@ -1827,11 +1827,11 @@  discard block
 block discarded – undo
1827 1827
 	 *
1828 1828
 	 * @since 1.0.19
1829 1829
 	 */
1830
-	public function set_parent_id( $value ) {
1831
-		if ( $value && ( $value === $this->get_id() || ! get_post( $value ) ) ) {
1830
+	public function set_parent_id($value) {
1831
+		if ($value && ($value === $this->get_id() || !get_post($value))) {
1832 1832
 			return;
1833 1833
 		}
1834
-		$this->set_prop( 'parent_id', absint( $value ) );
1834
+		$this->set_prop('parent_id', absint($value));
1835 1835
     }
1836 1836
 
1837 1837
     /**
@@ -1839,8 +1839,8 @@  discard block
 block discarded – undo
1839 1839
 	 *
1840 1840
 	 * @since 1.0.19
1841 1841
 	 */
1842
-	public function set_version( $value ) {
1843
-		$this->set_prop( 'version', $value );
1842
+	public function set_version($value) {
1843
+		$this->set_prop('version', $value);
1844 1844
     }
1845 1845
 
1846 1846
     /**
@@ -1850,15 +1850,15 @@  discard block
 block discarded – undo
1850 1850
 	 * @param string $value Value to set.
1851 1851
      * @return bool Whether or not the date was set.
1852 1852
 	 */
1853
-	public function set_date_created( $value ) {
1854
-        $date = strtotime( $value );
1853
+	public function set_date_created($value) {
1854
+        $date = strtotime($value);
1855 1855
 
1856
-        if ( $date && $date !== '0000-00-00 00:00:00' ) {
1857
-            $this->set_prop( 'date_created', date( 'Y-m-d H:i:s', $date ) );
1856
+        if ($date && $date !== '0000-00-00 00:00:00') {
1857
+            $this->set_prop('date_created', date('Y-m-d H:i:s', $date));
1858 1858
             return true;
1859 1859
         }
1860 1860
 
1861
-        return $this->set_prop( 'date_created', '' );
1861
+        return $this->set_prop('date_created', '');
1862 1862
 
1863 1863
     }
1864 1864
 
@@ -1869,15 +1869,15 @@  discard block
 block discarded – undo
1869 1869
 	 * @param string $value Value to set.
1870 1870
      * @return bool Whether or not the date was set.
1871 1871
 	 */
1872
-	public function set_due_date( $value ) {
1873
-        $date = strtotime( $value );
1872
+	public function set_due_date($value) {
1873
+        $date = strtotime($value);
1874 1874
 
1875
-        if ( $date && $date !== '0000-00-00 00:00:00' ) {
1876
-            $this->set_prop( 'due_date', date( 'Y-m-d H:i:s', $date ) );
1875
+        if ($date && $date !== '0000-00-00 00:00:00') {
1876
+            $this->set_prop('due_date', date('Y-m-d H:i:s', $date));
1877 1877
             return true;
1878 1878
         }
1879 1879
 
1880
-		$this->set_prop( 'due_date', '' );
1880
+		$this->set_prop('due_date', '');
1881 1881
         return false;
1882 1882
 
1883 1883
     }
@@ -1888,8 +1888,8 @@  discard block
 block discarded – undo
1888 1888
 	 * @since 1.0.19
1889 1889
 	 * @param  string $value New name.
1890 1890
 	 */
1891
-	public function set_date_due( $value ) {
1892
-		$this->set_due_date( $value );
1891
+	public function set_date_due($value) {
1892
+		$this->set_due_date($value);
1893 1893
     }
1894 1894
 
1895 1895
     /**
@@ -1899,15 +1899,15 @@  discard block
 block discarded – undo
1899 1899
 	 * @param string $value Value to set.
1900 1900
      * @return bool Whether or not the date was set.
1901 1901
 	 */
1902
-	public function set_completed_date( $value ) {
1903
-        $date = strtotime( $value );
1902
+	public function set_completed_date($value) {
1903
+        $date = strtotime($value);
1904 1904
 
1905
-        if ( $date && $date !== '0000-00-00 00:00:00'  ) {
1906
-            $this->set_prop( 'completed_date', date( 'Y-m-d H:i:s', $date ) );
1905
+        if ($date && $date !== '0000-00-00 00:00:00') {
1906
+            $this->set_prop('completed_date', date('Y-m-d H:i:s', $date));
1907 1907
             return true;
1908 1908
         }
1909 1909
 
1910
-		$this->set_prop( 'completed_date', '' );
1910
+		$this->set_prop('completed_date', '');
1911 1911
         return false;
1912 1912
 
1913 1913
     }
@@ -1918,8 +1918,8 @@  discard block
 block discarded – undo
1918 1918
 	 * @since 1.0.19
1919 1919
 	 * @param  string $value New name.
1920 1920
 	 */
1921
-	public function set_date_completed( $value ) {
1922
-		$this->set_completed_date( $value );
1921
+	public function set_date_completed($value) {
1922
+		$this->set_completed_date($value);
1923 1923
     }
1924 1924
 
1925 1925
     /**
@@ -1929,15 +1929,15 @@  discard block
 block discarded – undo
1929 1929
 	 * @param string $value Value to set.
1930 1930
      * @return bool Whether or not the date was set.
1931 1931
 	 */
1932
-	public function set_date_modified( $value ) {
1933
-        $date = strtotime( $value );
1932
+	public function set_date_modified($value) {
1933
+        $date = strtotime($value);
1934 1934
 
1935
-        if ( $date && $date !== '0000-00-00 00:00:00' ) {
1936
-            $this->set_prop( 'date_modified', date( 'Y-m-d H:i:s', $date ) );
1935
+        if ($date && $date !== '0000-00-00 00:00:00') {
1936
+            $this->set_prop('date_modified', date('Y-m-d H:i:s', $date));
1937 1937
             return true;
1938 1938
         }
1939 1939
 
1940
-		$this->set_prop( 'date_modified', '' );
1940
+		$this->set_prop('date_modified', '');
1941 1941
         return false;
1942 1942
 
1943 1943
     }
@@ -1948,9 +1948,9 @@  discard block
 block discarded – undo
1948 1948
 	 * @since 1.0.19
1949 1949
 	 * @param  string $value New number.
1950 1950
 	 */
1951
-	public function set_number( $value ) {
1952
-        $number = sanitize_text_field( $value );
1953
-		$this->set_prop( 'number', $number );
1951
+	public function set_number($value) {
1952
+        $number = sanitize_text_field($value);
1953
+		$this->set_prop('number', $number);
1954 1954
     }
1955 1955
 
1956 1956
     /**
@@ -1959,9 +1959,9 @@  discard block
 block discarded – undo
1959 1959
 	 * @since 1.0.19
1960 1960
 	 * @param  string $value Type.
1961 1961
 	 */
1962
-	public function set_type( $value ) {
1963
-        $type = sanitize_text_field( str_replace( 'wpi_', '', $value ) );
1964
-		$this->set_prop( 'type', $type );
1962
+	public function set_type($value) {
1963
+        $type = sanitize_text_field(str_replace('wpi_', '', $value));
1964
+		$this->set_prop('type', $type);
1965 1965
     }
1966 1966
 
1967 1967
     /**
@@ -1970,9 +1970,9 @@  discard block
 block discarded – undo
1970 1970
 	 * @since 1.0.19
1971 1971
 	 * @param  string $value Post type.
1972 1972
 	 */
1973
-	public function set_post_type( $value ) {
1974
-        if ( getpaid_is_invoice_post_type( $value ) ) {
1975
-            $this->set_prop( 'post_type', $value );
1973
+	public function set_post_type($value) {
1974
+        if (getpaid_is_invoice_post_type($value)) {
1975
+            $this->set_prop('post_type', $value);
1976 1976
         }
1977 1977
     }
1978 1978
 
@@ -1982,9 +1982,9 @@  discard block
 block discarded – undo
1982 1982
 	 * @since 1.0.19
1983 1983
 	 * @param  string $value New key.
1984 1984
 	 */
1985
-	public function set_key( $value ) {
1986
-        $key = sanitize_text_field( $value );
1987
-		$this->set_prop( 'key', $key );
1985
+	public function set_key($value) {
1986
+        $key = sanitize_text_field($value);
1987
+		$this->set_prop('key', $key);
1988 1988
     }
1989 1989
 
1990 1990
     /**
@@ -1993,9 +1993,9 @@  discard block
 block discarded – undo
1993 1993
 	 * @since 1.0.19
1994 1994
 	 * @param  string $value mode.
1995 1995
 	 */
1996
-	public function set_mode( $value ) {
1997
-        if ( ! in_array( $value, array( 'live', 'test' ) ) ) {
1998
-            $this->set_prop( 'value', $value );
1996
+	public function set_mode($value) {
1997
+        if (!in_array($value, array('live', 'test'))) {
1998
+            $this->set_prop('value', $value);
1999 1999
         }
2000 2000
     }
2001 2001
 
@@ -2005,8 +2005,8 @@  discard block
 block discarded – undo
2005 2005
 	 * @since 1.0.19
2006 2006
 	 * @param  string $value path.
2007 2007
 	 */
2008
-	public function set_path( $value ) {
2009
-        $this->set_prop( 'path', $value );
2008
+	public function set_path($value) {
2009
+        $this->set_prop('path', $value);
2010 2010
     }
2011 2011
 
2012 2012
     /**
@@ -2015,9 +2015,9 @@  discard block
 block discarded – undo
2015 2015
 	 * @since 1.0.19
2016 2016
 	 * @param  string $value New name.
2017 2017
 	 */
2018
-	public function set_name( $value ) {
2019
-        $name = sanitize_text_field( $value );
2020
-		$this->set_prop( 'name', $name );
2018
+	public function set_name($value) {
2019
+        $name = sanitize_text_field($value);
2020
+		$this->set_prop('name', $name);
2021 2021
     }
2022 2022
 
2023 2023
     /**
@@ -2026,8 +2026,8 @@  discard block
 block discarded – undo
2026 2026
 	 * @since 1.0.19
2027 2027
 	 * @param  string $value New name.
2028 2028
 	 */
2029
-	public function set_title( $value ) {
2030
-		$this->set_name( $value );
2029
+	public function set_title($value) {
2030
+		$this->set_name($value);
2031 2031
     }
2032 2032
 
2033 2033
     /**
@@ -2036,9 +2036,9 @@  discard block
 block discarded – undo
2036 2036
 	 * @since 1.0.19
2037 2037
 	 * @param  string $value New description.
2038 2038
 	 */
2039
-	public function set_description( $value ) {
2040
-        $description = wp_kses_post( $value );
2041
-		return $this->set_prop( 'description', $description );
2039
+	public function set_description($value) {
2040
+        $description = wp_kses_post($value);
2041
+		return $this->set_prop('description', $description);
2042 2042
     }
2043 2043
 
2044 2044
     /**
@@ -2047,8 +2047,8 @@  discard block
 block discarded – undo
2047 2047
 	 * @since 1.0.19
2048 2048
 	 * @param  string $value New description.
2049 2049
 	 */
2050
-	public function set_excerpt( $value ) {
2051
-		$this->set_description( $value );
2050
+	public function set_excerpt($value) {
2051
+		$this->set_description($value);
2052 2052
     }
2053 2053
 
2054 2054
     /**
@@ -2057,8 +2057,8 @@  discard block
 block discarded – undo
2057 2057
 	 * @since 1.0.19
2058 2058
 	 * @param  string $value New description.
2059 2059
 	 */
2060
-	public function set_summary( $value ) {
2061
-		$this->set_description( $value );
2060
+	public function set_summary($value) {
2061
+		$this->set_description($value);
2062 2062
     }
2063 2063
 
2064 2064
     /**
@@ -2067,8 +2067,8 @@  discard block
 block discarded – undo
2067 2067
 	 * @since 1.0.19
2068 2068
 	 * @param  int $value New author.
2069 2069
 	 */
2070
-	public function set_author( $value ) {
2071
-		$this->set_prop( 'author', (int) $value );
2070
+	public function set_author($value) {
2071
+		$this->set_prop('author', (int) $value);
2072 2072
     }
2073 2073
 
2074 2074
     /**
@@ -2077,8 +2077,8 @@  discard block
 block discarded – undo
2077 2077
 	 * @since 1.0.19
2078 2078
 	 * @param  int $value New user id.
2079 2079
 	 */
2080
-	public function set_user_id( $value ) {
2081
-		$this->set_author( $value );
2080
+	public function set_user_id($value) {
2081
+		$this->set_author($value);
2082 2082
     }
2083 2083
 
2084 2084
     /**
@@ -2087,8 +2087,8 @@  discard block
 block discarded – undo
2087 2087
 	 * @since 1.0.19
2088 2088
 	 * @param  int $value New user id.
2089 2089
 	 */
2090
-	public function set_customer_id( $value ) {
2091
-		$this->set_author( $value );
2090
+	public function set_customer_id($value) {
2091
+		$this->set_author($value);
2092 2092
     }
2093 2093
 
2094 2094
     /**
@@ -2097,8 +2097,8 @@  discard block
 block discarded – undo
2097 2097
 	 * @since 1.0.19
2098 2098
 	 * @param  string $value ip address.
2099 2099
 	 */
2100
-	public function set_ip( $value ) {
2101
-		$this->set_prop( 'ip', $value );
2100
+	public function set_ip($value) {
2101
+		$this->set_prop('ip', $value);
2102 2102
     }
2103 2103
 
2104 2104
     /**
@@ -2107,8 +2107,8 @@  discard block
 block discarded – undo
2107 2107
 	 * @since 1.0.19
2108 2108
 	 * @param  string $value ip address.
2109 2109
 	 */
2110
-	public function set_user_ip( $value ) {
2111
-		$this->set_ip( $value );
2110
+	public function set_user_ip($value) {
2111
+		$this->set_ip($value);
2112 2112
     }
2113 2113
 
2114 2114
     /**
@@ -2117,8 +2117,8 @@  discard block
 block discarded – undo
2117 2117
 	 * @since 1.0.19
2118 2118
 	 * @param  string $value first name.
2119 2119
 	 */
2120
-	public function set_first_name( $value ) {
2121
-		$this->set_prop( 'first_name', $value );
2120
+	public function set_first_name($value) {
2121
+		$this->set_prop('first_name', $value);
2122 2122
     }
2123 2123
 
2124 2124
     /**
@@ -2127,8 +2127,8 @@  discard block
 block discarded – undo
2127 2127
 	 * @since 1.0.19
2128 2128
 	 * @param  string $value first name.
2129 2129
 	 */
2130
-	public function set_user_first_name( $value ) {
2131
-		$this->set_first_name( $value );
2130
+	public function set_user_first_name($value) {
2131
+		$this->set_first_name($value);
2132 2132
     }
2133 2133
 
2134 2134
     /**
@@ -2137,8 +2137,8 @@  discard block
 block discarded – undo
2137 2137
 	 * @since 1.0.19
2138 2138
 	 * @param  string $value first name.
2139 2139
 	 */
2140
-	public function set_customer_first_name( $value ) {
2141
-		$this->set_first_name( $value );
2140
+	public function set_customer_first_name($value) {
2141
+		$this->set_first_name($value);
2142 2142
     }
2143 2143
 
2144 2144
     /**
@@ -2147,8 +2147,8 @@  discard block
 block discarded – undo
2147 2147
 	 * @since 1.0.19
2148 2148
 	 * @param  string $value last name.
2149 2149
 	 */
2150
-	public function set_last_name( $value ) {
2151
-		$this->set_prop( 'last_name', $value );
2150
+	public function set_last_name($value) {
2151
+		$this->set_prop('last_name', $value);
2152 2152
     }
2153 2153
 
2154 2154
     /**
@@ -2157,8 +2157,8 @@  discard block
 block discarded – undo
2157 2157
 	 * @since 1.0.19
2158 2158
 	 * @param  string $value last name.
2159 2159
 	 */
2160
-	public function set_user_last_name( $value ) {
2161
-		$this->set_last_name( $value );
2160
+	public function set_user_last_name($value) {
2161
+		$this->set_last_name($value);
2162 2162
     }
2163 2163
 
2164 2164
     /**
@@ -2167,8 +2167,8 @@  discard block
 block discarded – undo
2167 2167
 	 * @since 1.0.19
2168 2168
 	 * @param  string $value last name.
2169 2169
 	 */
2170
-	public function set_customer_last_name( $value ) {
2171
-		$this->set_last_name( $value );
2170
+	public function set_customer_last_name($value) {
2171
+		$this->set_last_name($value);
2172 2172
     }
2173 2173
 
2174 2174
     /**
@@ -2177,8 +2177,8 @@  discard block
 block discarded – undo
2177 2177
 	 * @since 1.0.19
2178 2178
 	 * @param  string $value phone.
2179 2179
 	 */
2180
-	public function set_phone( $value ) {
2181
-		$this->set_prop( 'phone', $value );
2180
+	public function set_phone($value) {
2181
+		$this->set_prop('phone', $value);
2182 2182
     }
2183 2183
 
2184 2184
     /**
@@ -2187,8 +2187,8 @@  discard block
 block discarded – undo
2187 2187
 	 * @since 1.0.19
2188 2188
 	 * @param  string $value phone.
2189 2189
 	 */
2190
-	public function set_user_phone( $value ) {
2191
-		$this->set_phone( $value );
2190
+	public function set_user_phone($value) {
2191
+		$this->set_phone($value);
2192 2192
     }
2193 2193
 
2194 2194
     /**
@@ -2197,8 +2197,8 @@  discard block
 block discarded – undo
2197 2197
 	 * @since 1.0.19
2198 2198
 	 * @param  string $value phone.
2199 2199
 	 */
2200
-	public function set_customer_phone( $value ) {
2201
-		$this->set_phone( $value );
2200
+	public function set_customer_phone($value) {
2201
+		$this->set_phone($value);
2202 2202
     }
2203 2203
 
2204 2204
     /**
@@ -2207,8 +2207,8 @@  discard block
 block discarded – undo
2207 2207
 	 * @since 1.0.19
2208 2208
 	 * @param  string $value phone.
2209 2209
 	 */
2210
-	public function set_phone_number( $value ) {
2211
-		$this->set_phone( $value );
2210
+	public function set_phone_number($value) {
2211
+		$this->set_phone($value);
2212 2212
     }
2213 2213
 
2214 2214
     /**
@@ -2217,8 +2217,8 @@  discard block
 block discarded – undo
2217 2217
 	 * @since 1.0.19
2218 2218
 	 * @param  string $value email address.
2219 2219
 	 */
2220
-	public function set_email( $value ) {
2221
-		$this->set_prop( 'email', $value );
2220
+	public function set_email($value) {
2221
+		$this->set_prop('email', $value);
2222 2222
     }
2223 2223
 
2224 2224
     /**
@@ -2227,8 +2227,8 @@  discard block
 block discarded – undo
2227 2227
 	 * @since 1.0.19
2228 2228
 	 * @param  string $value email address.
2229 2229
 	 */
2230
-	public function set_user_email( $value ) {
2231
-		$this->set_email( $value );
2230
+	public function set_user_email($value) {
2231
+		$this->set_email($value);
2232 2232
     }
2233 2233
 
2234 2234
     /**
@@ -2237,8 +2237,8 @@  discard block
 block discarded – undo
2237 2237
 	 * @since 1.0.19
2238 2238
 	 * @param  string $value email address.
2239 2239
 	 */
2240
-	public function set_email_address( $value ) {
2241
-		$this->set_email( $value );
2240
+	public function set_email_address($value) {
2241
+		$this->set_email($value);
2242 2242
     }
2243 2243
 
2244 2244
     /**
@@ -2247,8 +2247,8 @@  discard block
 block discarded – undo
2247 2247
 	 * @since 1.0.19
2248 2248
 	 * @param  string $value email address.
2249 2249
 	 */
2250
-	public function set_customer_email( $value ) {
2251
-		$this->set_email( $value );
2250
+	public function set_customer_email($value) {
2251
+		$this->set_email($value);
2252 2252
     }
2253 2253
 
2254 2254
     /**
@@ -2257,8 +2257,8 @@  discard block
 block discarded – undo
2257 2257
 	 * @since 1.0.19
2258 2258
 	 * @param  string $value country.
2259 2259
 	 */
2260
-	public function set_country( $value ) {
2261
-		$this->set_prop( 'country', $value );
2260
+	public function set_country($value) {
2261
+		$this->set_prop('country', $value);
2262 2262
     }
2263 2263
 
2264 2264
     /**
@@ -2267,8 +2267,8 @@  discard block
 block discarded – undo
2267 2267
 	 * @since 1.0.19
2268 2268
 	 * @param  string $value country.
2269 2269
 	 */
2270
-	public function set_user_country( $value ) {
2271
-		$this->set_country( $value );
2270
+	public function set_user_country($value) {
2271
+		$this->set_country($value);
2272 2272
     }
2273 2273
 
2274 2274
     /**
@@ -2277,8 +2277,8 @@  discard block
 block discarded – undo
2277 2277
 	 * @since 1.0.19
2278 2278
 	 * @param  string $value country.
2279 2279
 	 */
2280
-	public function set_customer_country( $value ) {
2281
-		$this->set_country( $value );
2280
+	public function set_customer_country($value) {
2281
+		$this->set_country($value);
2282 2282
     }
2283 2283
 
2284 2284
     /**
@@ -2287,8 +2287,8 @@  discard block
 block discarded – undo
2287 2287
 	 * @since 1.0.19
2288 2288
 	 * @param  string $value state.
2289 2289
 	 */
2290
-	public function set_state( $value ) {
2291
-		$this->set_prop( 'state', $value );
2290
+	public function set_state($value) {
2291
+		$this->set_prop('state', $value);
2292 2292
     }
2293 2293
 
2294 2294
     /**
@@ -2297,8 +2297,8 @@  discard block
 block discarded – undo
2297 2297
 	 * @since 1.0.19
2298 2298
 	 * @param  string $value state.
2299 2299
 	 */
2300
-	public function set_user_state( $value ) {
2301
-		$this->set_state( $value );
2300
+	public function set_user_state($value) {
2301
+		$this->set_state($value);
2302 2302
     }
2303 2303
 
2304 2304
     /**
@@ -2307,8 +2307,8 @@  discard block
 block discarded – undo
2307 2307
 	 * @since 1.0.19
2308 2308
 	 * @param  string $value state.
2309 2309
 	 */
2310
-	public function set_customer_state( $value ) {
2311
-		$this->set_state( $value );
2310
+	public function set_customer_state($value) {
2311
+		$this->set_state($value);
2312 2312
     }
2313 2313
 
2314 2314
     /**
@@ -2317,8 +2317,8 @@  discard block
 block discarded – undo
2317 2317
 	 * @since 1.0.19
2318 2318
 	 * @param  string $value city.
2319 2319
 	 */
2320
-	public function set_city( $value ) {
2321
-		$this->set_prop( 'city', $value );
2320
+	public function set_city($value) {
2321
+		$this->set_prop('city', $value);
2322 2322
     }
2323 2323
 
2324 2324
     /**
@@ -2327,8 +2327,8 @@  discard block
 block discarded – undo
2327 2327
 	 * @since 1.0.19
2328 2328
 	 * @param  string $value city.
2329 2329
 	 */
2330
-	public function set_user_city( $value ) {
2331
-		$this->set_city( $value );
2330
+	public function set_user_city($value) {
2331
+		$this->set_city($value);
2332 2332
     }
2333 2333
 
2334 2334
     /**
@@ -2337,8 +2337,8 @@  discard block
 block discarded – undo
2337 2337
 	 * @since 1.0.19
2338 2338
 	 * @param  string $value city.
2339 2339
 	 */
2340
-	public function set_customer_city( $value ) {
2341
-		$this->set_city( $value );
2340
+	public function set_customer_city($value) {
2341
+		$this->set_city($value);
2342 2342
     }
2343 2343
 
2344 2344
     /**
@@ -2347,8 +2347,8 @@  discard block
 block discarded – undo
2347 2347
 	 * @since 1.0.19
2348 2348
 	 * @param  string $value zip.
2349 2349
 	 */
2350
-	public function set_zip( $value ) {
2351
-		$this->set_prop( 'zip', $value );
2350
+	public function set_zip($value) {
2351
+		$this->set_prop('zip', $value);
2352 2352
     }
2353 2353
 
2354 2354
     /**
@@ -2357,8 +2357,8 @@  discard block
 block discarded – undo
2357 2357
 	 * @since 1.0.19
2358 2358
 	 * @param  string $value zip.
2359 2359
 	 */
2360
-	public function set_user_zip( $value ) {
2361
-		$this->set_zip( $value );
2360
+	public function set_user_zip($value) {
2361
+		$this->set_zip($value);
2362 2362
     }
2363 2363
 
2364 2364
     /**
@@ -2367,8 +2367,8 @@  discard block
 block discarded – undo
2367 2367
 	 * @since 1.0.19
2368 2368
 	 * @param  string $value zip.
2369 2369
 	 */
2370
-	public function set_customer_zip( $value ) {
2371
-		$this->set_zip( $value );
2370
+	public function set_customer_zip($value) {
2371
+		$this->set_zip($value);
2372 2372
     }
2373 2373
 
2374 2374
     /**
@@ -2377,8 +2377,8 @@  discard block
 block discarded – undo
2377 2377
 	 * @since 1.0.19
2378 2378
 	 * @param  string $value company.
2379 2379
 	 */
2380
-	public function set_company( $value ) {
2381
-		$this->set_prop( 'company', $value );
2380
+	public function set_company($value) {
2381
+		$this->set_prop('company', $value);
2382 2382
     }
2383 2383
 
2384 2384
     /**
@@ -2387,8 +2387,8 @@  discard block
 block discarded – undo
2387 2387
 	 * @since 1.0.19
2388 2388
 	 * @param  string $value company.
2389 2389
 	 */
2390
-	public function set_user_company( $value ) {
2391
-		$this->set_company( $value );
2390
+	public function set_user_company($value) {
2391
+		$this->set_company($value);
2392 2392
     }
2393 2393
 
2394 2394
     /**
@@ -2397,8 +2397,8 @@  discard block
 block discarded – undo
2397 2397
 	 * @since 1.0.19
2398 2398
 	 * @param  string $value company.
2399 2399
 	 */
2400
-	public function set_customer_company( $value ) {
2401
-		$this->set_company( $value );
2400
+	public function set_customer_company($value) {
2401
+		$this->set_company($value);
2402 2402
     }
2403 2403
 
2404 2404
     /**
@@ -2407,8 +2407,8 @@  discard block
 block discarded – undo
2407 2407
 	 * @since 1.0.19
2408 2408
 	 * @param  string $value var number.
2409 2409
 	 */
2410
-	public function set_vat_number( $value ) {
2411
-		$this->set_prop( 'vat_number', $value );
2410
+	public function set_vat_number($value) {
2411
+		$this->set_prop('vat_number', $value);
2412 2412
     }
2413 2413
 
2414 2414
     /**
@@ -2417,8 +2417,8 @@  discard block
 block discarded – undo
2417 2417
 	 * @since 1.0.19
2418 2418
 	 * @param  string $value var number.
2419 2419
 	 */
2420
-	public function set_user_vat_number( $value ) {
2421
-		$this->set_vat_number( $value );
2420
+	public function set_user_vat_number($value) {
2421
+		$this->set_vat_number($value);
2422 2422
     }
2423 2423
 
2424 2424
     /**
@@ -2427,8 +2427,8 @@  discard block
 block discarded – undo
2427 2427
 	 * @since 1.0.19
2428 2428
 	 * @param  string $value var number.
2429 2429
 	 */
2430
-	public function set_customer_vat_number( $value ) {
2431
-		$this->set_vat_number( $value );
2430
+	public function set_customer_vat_number($value) {
2431
+		$this->set_vat_number($value);
2432 2432
     }
2433 2433
 
2434 2434
     /**
@@ -2437,8 +2437,8 @@  discard block
 block discarded – undo
2437 2437
 	 * @since 1.0.19
2438 2438
 	 * @param  string $value var rate.
2439 2439
 	 */
2440
-	public function set_vat_rate( $value ) {
2441
-		$this->set_prop( 'vat_rate', $value );
2440
+	public function set_vat_rate($value) {
2441
+		$this->set_prop('vat_rate', $value);
2442 2442
     }
2443 2443
 
2444 2444
     /**
@@ -2447,8 +2447,8 @@  discard block
 block discarded – undo
2447 2447
 	 * @since 1.0.19
2448 2448
 	 * @param  string $value var number.
2449 2449
 	 */
2450
-	public function set_user_vat_rate( $value ) {
2451
-		$this->set_vat_rate( $value );
2450
+	public function set_user_vat_rate($value) {
2451
+		$this->set_vat_rate($value);
2452 2452
     }
2453 2453
 
2454 2454
     /**
@@ -2457,8 +2457,8 @@  discard block
 block discarded – undo
2457 2457
 	 * @since 1.0.19
2458 2458
 	 * @param  string $value var number.
2459 2459
 	 */
2460
-	public function set_customer_vat_rate( $value ) {
2461
-		$this->set_vat_rate( $value );
2460
+	public function set_customer_vat_rate($value) {
2461
+		$this->set_vat_rate($value);
2462 2462
     }
2463 2463
 
2464 2464
     /**
@@ -2467,8 +2467,8 @@  discard block
 block discarded – undo
2467 2467
 	 * @since 1.0.19
2468 2468
 	 * @param  string $value address.
2469 2469
 	 */
2470
-	public function set_address( $value ) {
2471
-		$this->set_prop( 'address', $value );
2470
+	public function set_address($value) {
2471
+		$this->set_prop('address', $value);
2472 2472
     }
2473 2473
 
2474 2474
     /**
@@ -2477,8 +2477,8 @@  discard block
 block discarded – undo
2477 2477
 	 * @since 1.0.19
2478 2478
 	 * @param  string $value address.
2479 2479
 	 */
2480
-	public function set_user_address( $value ) {
2481
-		$this->set_address( $value );
2480
+	public function set_user_address($value) {
2481
+		$this->set_address($value);
2482 2482
     }
2483 2483
 
2484 2484
     /**
@@ -2487,8 +2487,8 @@  discard block
 block discarded – undo
2487 2487
 	 * @since 1.0.19
2488 2488
 	 * @param  string $value address.
2489 2489
 	 */
2490
-	public function set_customer_address( $value ) {
2491
-		$this->set_address( $value );
2490
+	public function set_customer_address($value) {
2491
+		$this->set_address($value);
2492 2492
     }
2493 2493
 
2494 2494
     /**
@@ -2497,8 +2497,8 @@  discard block
 block discarded – undo
2497 2497
 	 * @since 1.0.19
2498 2498
 	 * @param  int|bool $value confirmed.
2499 2499
 	 */
2500
-	public function set_is_viewed( $value ) {
2501
-		$this->set_prop( 'is_viewed', $value );
2500
+	public function set_is_viewed($value) {
2501
+		$this->set_prop('is_viewed', $value);
2502 2502
 	}
2503 2503
 
2504 2504
 	/**
@@ -2507,8 +2507,8 @@  discard block
 block discarded – undo
2507 2507
 	 * @since 1.0.19
2508 2508
 	 * @param  string $value email recipients.
2509 2509
 	 */
2510
-	public function set_email_cc( $value ) {
2511
-		$this->set_prop( 'email_cc', $value );
2510
+	public function set_email_cc($value) {
2511
+		$this->set_prop('email_cc', $value);
2512 2512
 	}
2513 2513
 
2514 2514
 	/**
@@ -2517,9 +2517,9 @@  discard block
 block discarded – undo
2517 2517
 	 * @since 1.0.19
2518 2518
 	 * @param  string $value email recipients.
2519 2519
 	 */
2520
-	public function set_template( $value ) {
2521
-		if ( in_array( $value, array( 'quantity', 'hours', 'amount' ) ) ) {
2522
-			$this->set_prop( 'template', $value );
2520
+	public function set_template($value) {
2521
+		if (in_array($value, array('quantity', 'hours', 'amount'))) {
2522
+			$this->set_prop('template', $value);
2523 2523
 		}
2524 2524
 	}
2525 2525
 
@@ -2529,8 +2529,8 @@  discard block
 block discarded – undo
2529 2529
 	 * @since 1.0.19
2530 2530
 	 * @param  int|bool $value confirmed.
2531 2531
 	 */
2532
-	public function set_address_confirmed( $value ) {
2533
-		$this->set_prop( 'address_confirmed', $value );
2532
+	public function set_address_confirmed($value) {
2533
+		$this->set_prop('address_confirmed', $value);
2534 2534
     }
2535 2535
 
2536 2536
     /**
@@ -2539,8 +2539,8 @@  discard block
 block discarded – undo
2539 2539
 	 * @since 1.0.19
2540 2540
 	 * @param  int|bool $value confirmed.
2541 2541
 	 */
2542
-	public function set_user_address_confirmed( $value ) {
2543
-		$this->set_address_confirmed( $value );
2542
+	public function set_user_address_confirmed($value) {
2543
+		$this->set_address_confirmed($value);
2544 2544
     }
2545 2545
 
2546 2546
     /**
@@ -2549,8 +2549,8 @@  discard block
 block discarded – undo
2549 2549
 	 * @since 1.0.19
2550 2550
 	 * @param  int|bool $value confirmed.
2551 2551
 	 */
2552
-	public function set_customer_address_confirmed( $value ) {
2553
-		$this->set_address_confirmed( $value );
2552
+	public function set_customer_address_confirmed($value) {
2553
+		$this->set_address_confirmed($value);
2554 2554
     }
2555 2555
 
2556 2556
     /**
@@ -2559,8 +2559,8 @@  discard block
 block discarded – undo
2559 2559
 	 * @since 1.0.19
2560 2560
 	 * @param  float $value sub total.
2561 2561
 	 */
2562
-	public function set_subtotal( $value ) {
2563
-		$this->set_prop( 'subtotal', $value );
2562
+	public function set_subtotal($value) {
2563
+		$this->set_prop('subtotal', $value);
2564 2564
     }
2565 2565
 
2566 2566
     /**
@@ -2569,8 +2569,8 @@  discard block
 block discarded – undo
2569 2569
 	 * @since 1.0.19
2570 2570
 	 * @param  float $value discount total.
2571 2571
 	 */
2572
-	public function set_total_discount( $value ) {
2573
-		$this->set_prop( 'total_discount', $value );
2572
+	public function set_total_discount($value) {
2573
+		$this->set_prop('total_discount', $value);
2574 2574
     }
2575 2575
 
2576 2576
     /**
@@ -2579,8 +2579,8 @@  discard block
 block discarded – undo
2579 2579
 	 * @since 1.0.19
2580 2580
 	 * @param  float $value discount total.
2581 2581
 	 */
2582
-	public function set_discount( $value ) {
2583
-		$this->set_total_discount( $value );
2582
+	public function set_discount($value) {
2583
+		$this->set_total_discount($value);
2584 2584
     }
2585 2585
 
2586 2586
     /**
@@ -2589,8 +2589,8 @@  discard block
 block discarded – undo
2589 2589
 	 * @since 1.0.19
2590 2590
 	 * @param  float $value tax total.
2591 2591
 	 */
2592
-	public function set_total_tax( $value ) {
2593
-		$this->set_prop( 'total_tax', $value );
2592
+	public function set_total_tax($value) {
2593
+		$this->set_prop('total_tax', $value);
2594 2594
     }
2595 2595
 
2596 2596
     /**
@@ -2599,8 +2599,8 @@  discard block
 block discarded – undo
2599 2599
 	 * @since 1.0.19
2600 2600
 	 * @param  float $value tax total.
2601 2601
 	 */
2602
-	public function set_tax_total( $value ) {
2603
-		$this->set_total_tax( $value );
2602
+	public function set_tax_total($value) {
2603
+		$this->set_total_tax($value);
2604 2604
     }
2605 2605
 
2606 2606
     /**
@@ -2609,8 +2609,8 @@  discard block
 block discarded – undo
2609 2609
 	 * @since 1.0.19
2610 2610
 	 * @param  float $value fees total.
2611 2611
 	 */
2612
-	public function set_total_fees( $value ) {
2613
-		$this->set_prop( 'total_fees', $value );
2612
+	public function set_total_fees($value) {
2613
+		$this->set_prop('total_fees', $value);
2614 2614
     }
2615 2615
 
2616 2616
     /**
@@ -2619,8 +2619,8 @@  discard block
 block discarded – undo
2619 2619
 	 * @since 1.0.19
2620 2620
 	 * @param  float $value fees total.
2621 2621
 	 */
2622
-	public function set_fees_total( $value ) {
2623
-		$this->set_total_fees( $value );
2622
+	public function set_fees_total($value) {
2623
+		$this->set_total_fees($value);
2624 2624
     }
2625 2625
 
2626 2626
     /**
@@ -2629,18 +2629,18 @@  discard block
 block discarded – undo
2629 2629
 	 * @since 1.0.19
2630 2630
 	 * @param  array $value fees.
2631 2631
 	 */
2632
-	public function set_fees( $value ) {
2632
+	public function set_fees($value) {
2633 2633
 
2634
-        $this->set_prop( 'fees', array() );
2634
+        $this->set_prop('fees', array());
2635 2635
 
2636 2636
         // Ensure that we have an array.
2637
-        if ( ! is_array( $value ) ) {
2637
+        if (!is_array($value)) {
2638 2638
             return;
2639 2639
         }
2640 2640
 
2641
-        foreach ( $value as $name => $data ) {
2642
-            if ( isset( $data['amount'] ) ) {
2643
-                $this->add_fee( $name, $data['amount'], $data['recurring'] );
2641
+        foreach ($value as $name => $data) {
2642
+            if (isset($data['amount'])) {
2643
+                $this->add_fee($name, $data['amount'], $data['recurring']);
2644 2644
             }
2645 2645
         }
2646 2646
 
@@ -2652,8 +2652,8 @@  discard block
 block discarded – undo
2652 2652
 	 * @since 1.0.19
2653 2653
 	 * @param  array $value taxes.
2654 2654
 	 */
2655
-	public function set_taxes( $value ) {
2656
-		$this->set_prop( 'taxes', $value );
2655
+	public function set_taxes($value) {
2656
+		$this->set_prop('taxes', $value);
2657 2657
     }
2658 2658
 
2659 2659
     /**
@@ -2662,17 +2662,17 @@  discard block
 block discarded – undo
2662 2662
 	 * @since 1.0.19
2663 2663
 	 * @param  array $value discounts.
2664 2664
 	 */
2665
-	public function set_discounts( $value ) {
2666
-		$this->set_prop( 'discounts', array() );
2665
+	public function set_discounts($value) {
2666
+		$this->set_prop('discounts', array());
2667 2667
 
2668 2668
         // Ensure that we have an array.
2669
-        if ( ! is_array( $value ) ) {
2669
+        if (!is_array($value)) {
2670 2670
             return;
2671 2671
         }
2672 2672
 
2673
-        foreach ( $value as $name => $data ) {
2674
-            if ( isset( $data['amount'] ) ) {
2675
-                $this->add_discount( $name, $data['amount'], $data['recurring'] );
2673
+        foreach ($value as $name => $data) {
2674
+            if (isset($data['amount'])) {
2675
+                $this->add_discount($name, $data['amount'], $data['recurring']);
2676 2676
             }
2677 2677
         }
2678 2678
     }
@@ -2683,18 +2683,18 @@  discard block
 block discarded – undo
2683 2683
 	 * @since 1.0.19
2684 2684
 	 * @param  GetPaid_Form_Item[] $value items.
2685 2685
 	 */
2686
-	public function set_items( $value ) {
2686
+	public function set_items($value) {
2687 2687
 
2688 2688
         // Remove existing items.
2689
-        $this->set_prop( 'items', array() );
2689
+        $this->set_prop('items', array());
2690 2690
 
2691 2691
         // Ensure that we have an array.
2692
-        if ( ! is_array( $value ) ) {
2692
+        if (!is_array($value)) {
2693 2693
             return;
2694 2694
         }
2695 2695
 
2696
-        foreach ( $value as $item ) {
2697
-            $this->add_item( $item );
2696
+        foreach ($value as $item) {
2697
+            $this->add_item($item);
2698 2698
         }
2699 2699
 
2700 2700
     }
@@ -2705,8 +2705,8 @@  discard block
 block discarded – undo
2705 2705
 	 * @since 1.0.19
2706 2706
 	 * @param  int $value payment form.
2707 2707
 	 */
2708
-	public function set_payment_form( $value ) {
2709
-		$this->set_prop( 'payment_form', $value );
2708
+	public function set_payment_form($value) {
2709
+		$this->set_prop('payment_form', $value);
2710 2710
     }
2711 2711
 
2712 2712
     /**
@@ -2715,8 +2715,8 @@  discard block
 block discarded – undo
2715 2715
 	 * @since 1.0.19
2716 2716
 	 * @param  string $value submission id.
2717 2717
 	 */
2718
-	public function set_submission_id( $value ) {
2719
-		$this->set_prop( 'submission_id', $value );
2718
+	public function set_submission_id($value) {
2719
+		$this->set_prop('submission_id', $value);
2720 2720
     }
2721 2721
 
2722 2722
     /**
@@ -2725,8 +2725,8 @@  discard block
 block discarded – undo
2725 2725
 	 * @since 1.0.19
2726 2726
 	 * @param  string $value discount code.
2727 2727
 	 */
2728
-	public function set_discount_code( $value ) {
2729
-		$this->set_prop( 'discount_code', $value );
2728
+	public function set_discount_code($value) {
2729
+		$this->set_prop('discount_code', $value);
2730 2730
     }
2731 2731
 
2732 2732
     /**
@@ -2735,8 +2735,8 @@  discard block
 block discarded – undo
2735 2735
 	 * @since 1.0.19
2736 2736
 	 * @param  string $value gateway.
2737 2737
 	 */
2738
-	public function set_gateway( $value ) {
2739
-		$this->set_prop( 'gateway', $value );
2738
+	public function set_gateway($value) {
2739
+		$this->set_prop('gateway', $value);
2740 2740
     }
2741 2741
 
2742 2742
     /**
@@ -2745,8 +2745,8 @@  discard block
 block discarded – undo
2745 2745
 	 * @since 1.0.19
2746 2746
 	 * @param  string $value transaction id.
2747 2747
 	 */
2748
-	public function set_transaction_id( $value ) {
2749
-		$this->set_prop( 'transaction_id', $value );
2748
+	public function set_transaction_id($value) {
2749
+		$this->set_prop('transaction_id', $value);
2750 2750
     }
2751 2751
 
2752 2752
     /**
@@ -2755,8 +2755,8 @@  discard block
 block discarded – undo
2755 2755
 	 * @since 1.0.19
2756 2756
 	 * @param  string $value currency id.
2757 2757
 	 */
2758
-	public function set_currency( $value ) {
2759
-		$this->set_prop( 'currency', $value );
2758
+	public function set_currency($value) {
2759
+		$this->set_prop('currency', $value);
2760 2760
     }
2761 2761
 
2762 2762
     /**
@@ -2765,8 +2765,8 @@  discard block
 block discarded – undo
2765 2765
 	 * @since 1.0.19
2766 2766
 	 * @param  string $value subscription id.
2767 2767
 	 */
2768
-	public function set_subscription_id( $value ) {
2769
-		$this->set_prop( 'subscription_id', $value );
2768
+	public function set_subscription_id($value) {
2769
+		$this->set_prop('subscription_id', $value);
2770 2770
     }
2771 2771
 
2772 2772
     /*
@@ -2783,21 +2783,21 @@  discard block
 block discarded – undo
2783 2783
      */
2784 2784
     public function is_parent() {
2785 2785
         $parent = $this->get_parent_id();
2786
-        return apply_filters( 'wpinv_invoice_is_parent', empty( $parent ), $this );
2786
+        return apply_filters('wpinv_invoice_is_parent', empty($parent), $this);
2787 2787
     }
2788 2788
 
2789 2789
     /**
2790 2790
      * Checks if this is a renewal invoice.
2791 2791
      */
2792 2792
     public function is_renewal() {
2793
-        return ! $this->is_parent();
2793
+        return !$this->is_parent();
2794 2794
     }
2795 2795
 
2796 2796
     /**
2797 2797
      * Checks if this is a recurring invoice.
2798 2798
      */
2799 2799
     public function is_recurring() {
2800
-        return $this->is_renewal() || ! empty( $this->recurring_item );
2800
+        return $this->is_renewal() || !empty($this->recurring_item);
2801 2801
     }
2802 2802
 
2803 2803
     /**
@@ -2815,72 +2815,72 @@  discard block
 block discarded – undo
2815 2815
 
2816 2816
         $requires_vat = false;
2817 2817
 
2818
-        if ( $this->country ) {
2818
+        if ($this->country) {
2819 2819
             $wpi_country        = $this->country;
2820
-            $requires_vat       = $wpinv_euvat->requires_vat( $requires_vat, $this->get_user_id(), $wpinv_euvat->invoice_has_digital_rule( $this ) );
2820
+            $requires_vat       = $wpinv_euvat->requires_vat($requires_vat, $this->get_user_id(), $wpinv_euvat->invoice_has_digital_rule($this));
2821 2821
         }
2822 2822
 
2823
-        return apply_filters( 'wpinv_invoice_has_vat', $requires_vat, $this );
2823
+        return apply_filters('wpinv_invoice_has_vat', $requires_vat, $this);
2824 2824
 	}
2825 2825
 
2826 2826
 	/**
2827 2827
 	 * Checks to see if the invoice requires payment.
2828 2828
 	 */
2829 2829
 	public function is_free() {
2830
-        $is_free = ! ( (float) wpinv_round_amount( $this->get_initial_total() ) > 0 );
2830
+        $is_free = !((float) wpinv_round_amount($this->get_initial_total()) > 0);
2831 2831
 
2832
-		if ( $is_free && $this->is_recurring() ) {
2833
-			$is_free = ! ( (float) wpinv_round_amount( $this->get_recurring_total() ) > 0 );
2832
+		if ($is_free && $this->is_recurring()) {
2833
+			$is_free = !((float) wpinv_round_amount($this->get_recurring_total()) > 0);
2834 2834
 		}
2835 2835
 
2836
-        return apply_filters( 'wpinv_invoice_is_free', $is_free, $this );
2836
+        return apply_filters('wpinv_invoice_is_free', $is_free, $this);
2837 2837
     }
2838 2838
 
2839 2839
     /**
2840 2840
      * Checks if the invoice is paid.
2841 2841
      */
2842 2842
     public function is_paid() {
2843
-        $is_paid = $this->has_status( array( 'publish', 'wpi-processing', 'wpi-renewal' ) );
2844
-        return apply_filters( 'wpinv_invoice_is_paid', $is_paid, $this );
2843
+        $is_paid = $this->has_status(array('publish', 'wpi-processing', 'wpi-renewal'));
2844
+        return apply_filters('wpinv_invoice_is_paid', $is_paid, $this);
2845 2845
 	}
2846 2846
 
2847 2847
 	/**
2848 2848
      * Checks if the invoice needs payment.
2849 2849
      */
2850 2850
 	public function needs_payment() {
2851
-		$needs_payment = ! $this->is_paid() && ! $this->is_free();
2852
-        return apply_filters( 'wpinv_needs_payment', $needs_payment, $this );
2851
+		$needs_payment = !$this->is_paid() && !$this->is_free();
2852
+        return apply_filters('wpinv_needs_payment', $needs_payment, $this);
2853 2853
     }
2854 2854
 
2855 2855
 	/**
2856 2856
      * Checks if the invoice is refunded.
2857 2857
      */
2858 2858
 	public function is_refunded() {
2859
-        $is_refunded = $this->has_status( 'wpi-refunded' );
2860
-        return apply_filters( 'wpinv_invoice_is_refunded', $is_refunded, $this );
2859
+        $is_refunded = $this->has_status('wpi-refunded');
2860
+        return apply_filters('wpinv_invoice_is_refunded', $is_refunded, $this);
2861 2861
 	}
2862 2862
 
2863 2863
 	/**
2864 2864
      * Checks if the invoice is draft.
2865 2865
      */
2866 2866
 	public function is_draft() {
2867
-        return $this->has_status( 'draft, auto-draft' );
2867
+        return $this->has_status('draft, auto-draft');
2868 2868
 	}
2869 2869
 
2870 2870
     /**
2871 2871
      * Checks if the invoice has a given status.
2872 2872
      */
2873
-    public function has_status( $status ) {
2874
-        $status = wpinv_parse_list( $status );
2875
-        return apply_filters( 'wpinv_has_status', in_array( $this->get_status(), $status ), $status );
2873
+    public function has_status($status) {
2874
+        $status = wpinv_parse_list($status);
2875
+        return apply_filters('wpinv_has_status', in_array($this->get_status(), $status), $status);
2876 2876
 	}
2877 2877
 
2878 2878
 	/**
2879 2879
      * Checks if the invoice is of a given type.
2880 2880
      */
2881
-    public function is_type( $type ) {
2882
-        $type = wpinv_parse_list( $type );
2883
-        return in_array( $this->get_type(), $type );
2881
+    public function is_type($type) {
2882
+        $type = wpinv_parse_list($type);
2883
+        return in_array($this->get_type(), $type);
2884 2884
     }
2885 2885
 
2886 2886
     /**
@@ -2889,7 +2889,7 @@  discard block
 block discarded – undo
2889 2889
      * @since 1.0.15
2890 2890
      */
2891 2891
     public function is_quote() {
2892
-        return $this->has_status( 'wpi_quote' );
2892
+        return $this->has_status('wpi_quote');
2893 2893
     }
2894 2894
 
2895 2895
     /**
@@ -2912,8 +2912,8 @@  discard block
 block discarded – undo
2912 2912
      *
2913 2913
      */
2914 2914
 	public function is_initial_free() {
2915
-        $is_initial_free = ! ( (float) wpinv_round_amount( $this->get_initial_total() ) > 0 );
2916
-        return apply_filters( 'wpinv_invoice_is_initial_free', $is_initial_free, $this->get_cart_details(), $this );
2915
+        $is_initial_free = !((float) wpinv_round_amount($this->get_initial_total()) > 0);
2916
+        return apply_filters('wpinv_invoice_is_initial_free', $is_initial_free, $this->get_cart_details(), $this);
2917 2917
     }
2918 2918
 	
2919 2919
 	/**
@@ -2923,11 +2923,11 @@  discard block
 block discarded – undo
2923 2923
     public function item_has_free_trial() {
2924 2924
 
2925 2925
         // Ensure we have a recurring item.
2926
-        if ( ! $this->is_recurring() ) {
2926
+        if (!$this->is_recurring()) {
2927 2927
             return false;
2928 2928
         }
2929 2929
 
2930
-        $item = new WPInv_Item( $this->recurring_item );
2930
+        $item = new WPInv_Item($this->recurring_item);
2931 2931
         return $item->has_free_trial();
2932 2932
 	}
2933 2933
 
@@ -2935,7 +2935,7 @@  discard block
 block discarded – undo
2935 2935
      * Check if the free trial is a result of a discount.
2936 2936
      */
2937 2937
     public function is_free_trial_from_discount() {
2938
-		return $this->has_free_trial() && ! $this->item_has_free_trial();
2938
+		return $this->has_free_trial() && !$this->item_has_free_trial();
2939 2939
 	}
2940 2940
 	
2941 2941
 	/**
@@ -2944,17 +2944,17 @@  discard block
 block discarded – undo
2944 2944
     public function discount_first_payment_only() {
2945 2945
 
2946 2946
 		$discount_code = $this->get_discount_code();
2947
-        if ( empty( $this->discount_code ) || ! $this->is_recurring() ) {
2947
+        if (empty($this->discount_code) || !$this->is_recurring()) {
2948 2948
             return true;
2949 2949
         }
2950 2950
 
2951
-        $discount = wpinv_get_discount_obj( $discount_code );
2951
+        $discount = wpinv_get_discount_obj($discount_code);
2952 2952
 
2953
-        if ( ! $discount || ! $discount->exists() ) {
2953
+        if (!$discount || !$discount->exists()) {
2954 2954
             return true;
2955 2955
         }
2956 2956
 
2957
-        return ! $discount->get_is_recurring();
2957
+        return !$discount->get_is_recurring();
2958 2958
     }
2959 2959
 
2960 2960
     /*
@@ -2972,15 +2972,15 @@  discard block
 block discarded – undo
2972 2972
      * @param GetPaid_Form_Item $item
2973 2973
      * @return WP_Error|Bool
2974 2974
      */
2975
-    public function add_item( $item ) {
2975
+    public function add_item($item) {
2976 2976
 
2977 2977
         // Make sure that it is available for purchase.
2978
-		if ( $item->get_id() > 0 && ! $item->can_purchase() ) {
2979
-			return new WP_Error( 'invalid_item', __( 'This item is not available for purchase', 'invoicing' ) );
2978
+		if ($item->get_id() > 0 && !$item->can_purchase()) {
2979
+			return new WP_Error('invalid_item', __('This item is not available for purchase', 'invoicing'));
2980 2980
         }
2981 2981
 
2982 2982
         // Do we have a recurring item?
2983
-		if ( $item->is_recurring() ) {
2983
+		if ($item->is_recurring()) {
2984 2984
 			$this->recurring_item = $item->get_id();
2985 2985
         }
2986 2986
 
@@ -2989,9 +2989,9 @@  discard block
 block discarded – undo
2989 2989
 
2990 2990
         // Retrieve all items.
2991 2991
         $items = $this->get_items();
2992
-        $items[ $item->get_id() ] = $item;
2992
+        $items[$item->get_id()] = $item;
2993 2993
 
2994
-        $this->set_prop( 'items', $items );
2994
+        $this->set_prop('items', $items);
2995 2995
 
2996 2996
     }
2997 2997
 
@@ -3000,9 +3000,9 @@  discard block
 block discarded – undo
3000 3000
 	 *
3001 3001
 	 * @since 1.0.19
3002 3002
 	 */
3003
-	public function get_item( $item_id ) {
3003
+	public function get_item($item_id) {
3004 3004
         $items = $this->get_items();
3005
-		return ( ! empty( $item_id ) && isset( $items[ $item_id ] ) ) ? $items[ $item_id ] : null;
3005
+		return (!empty($item_id) && isset($items[$item_id])) ? $items[$item_id] : null;
3006 3006
     }
3007 3007
 
3008 3008
     /**
@@ -3010,16 +3010,16 @@  discard block
 block discarded – undo
3010 3010
 	 *
3011 3011
 	 * @since 1.0.19
3012 3012
 	 */
3013
-	public function remove_item( $item_id ) {
3013
+	public function remove_item($item_id) {
3014 3014
         $items = $this->get_items();
3015 3015
 
3016
-        if ( $item_id == $this->recurring_item ) {
3016
+        if ($item_id == $this->recurring_item) {
3017 3017
             $this->recurring_item = null;
3018 3018
         }
3019 3019
 
3020
-        if ( isset( $items[ $item_id ] ) ) {
3021
-            unset( $items[ $item_id ] );
3022
-            $this->set_prop( 'items', $items );
3020
+        if (isset($items[$item_id])) {
3021
+            unset($items[$item_id]);
3022
+            $this->set_prop('items', $items);
3023 3023
         }
3024 3024
     }
3025 3025
 
@@ -3030,27 +3030,27 @@  discard block
 block discarded – undo
3030 3030
      * @param float $value
3031 3031
      * @return WP_Error|Bool
3032 3032
      */
3033
-    public function add_fee( $fee, $value, $recurring = false ) {
3033
+    public function add_fee($fee, $value, $recurring = false) {
3034 3034
 
3035
-        $amount = wpinv_sanitize_amount( $value );
3035
+        $amount = wpinv_sanitize_amount($value);
3036 3036
         $fees   = $this->get_fees();
3037 3037
 
3038
-        if ( isset( $fees[ $fee ] ) && isset( $fees[ $fee ]['amount'] ) ) {
3038
+        if (isset($fees[$fee]) && isset($fees[$fee]['amount'])) {
3039 3039
 
3040
-            $amount = $fees[ $fee ]['amount'] += $amount;
3041
-			$fees[ $fee ] = array(
3040
+            $amount = $fees[$fee]['amount'] += $amount;
3041
+			$fees[$fee] = array(
3042 3042
                 'amount'    => $amount,
3043 3043
                 'recurring' => (bool) $recurring,
3044 3044
             );
3045 3045
 
3046 3046
 		} else {
3047
-			$fees[ $fee ] = array(
3047
+			$fees[$fee] = array(
3048 3048
                 'amount'    => $amount,
3049 3049
                 'recurring' => (bool) $recurring,
3050 3050
             );
3051 3051
 		}
3052 3052
 
3053
-        $this->set_prop( 'fees', $fee );
3053
+        $this->set_prop('fees', $fee);
3054 3054
 
3055 3055
     }
3056 3056
 
@@ -3059,9 +3059,9 @@  discard block
 block discarded – undo
3059 3059
 	 *
3060 3060
 	 * @since 1.0.19
3061 3061
 	 */
3062
-	public function get_fee( $fee ) {
3062
+	public function get_fee($fee) {
3063 3063
         $fees = $this->get_fees();
3064
-		return isset( $fees[ $fee ] ) ? $fees[ $fee ] : null;
3064
+		return isset($fees[$fee]) ? $fees[$fee] : null;
3065 3065
     }
3066 3066
 
3067 3067
     /**
@@ -3069,11 +3069,11 @@  discard block
 block discarded – undo
3069 3069
 	 *
3070 3070
 	 * @since 1.0.19
3071 3071
 	 */
3072
-	public function remove_fee( $fee ) {
3072
+	public function remove_fee($fee) {
3073 3073
         $fees = $this->get_fees();
3074
-        if ( isset( $fees[ $fee ] ) ) {
3075
-            unset( $fees[ $fee ] );
3076
-            $this->set_prop( 'fees', $fees );
3074
+        if (isset($fees[$fee])) {
3075
+            unset($fees[$fee]);
3076
+            $this->set_prop('fees', $fees);
3077 3077
         }
3078 3078
     }
3079 3079
 
@@ -3084,27 +3084,27 @@  discard block
 block discarded – undo
3084 3084
      * @param float $value
3085 3085
      * @return WP_Error|Bool
3086 3086
      */
3087
-    public function add_discount( $discount, $value, $recurring = false ) {
3087
+    public function add_discount($discount, $value, $recurring = false) {
3088 3088
 
3089
-        $amount    = wpinv_sanitize_amount( $value );
3089
+        $amount    = wpinv_sanitize_amount($value);
3090 3090
         $discounts = $this->get_discounts();
3091 3091
 
3092
-        if ( isset( $discounts[ $discount ] ) && isset( $discounts[ $discount ]['amount'] ) ) {
3092
+        if (isset($discounts[$discount]) && isset($discounts[$discount]['amount'])) {
3093 3093
 
3094
-            $amount = $discounts[ $discount ]['amount'] += $amount;
3095
-			$discounts[ $discount ] = array(
3094
+            $amount = $discounts[$discount]['amount'] += $amount;
3095
+			$discounts[$discount] = array(
3096 3096
                 'amount'    => $amount,
3097 3097
                 'recurring' => (bool) $recurring,
3098 3098
             );
3099 3099
 
3100 3100
 		} else {
3101
-			$discounts[ $discount ] = array(
3101
+			$discounts[$discount] = array(
3102 3102
                 'amount'    => $amount,
3103 3103
                 'recurring' => (bool) $recurring,
3104 3104
             );
3105 3105
 		}
3106 3106
 
3107
-        $this->set_prop( 'discounts', $discount );
3107
+        $this->set_prop('discounts', $discount);
3108 3108
 
3109 3109
     }
3110 3110
 
@@ -3113,15 +3113,15 @@  discard block
 block discarded – undo
3113 3113
 	 *
3114 3114
 	 * @since 1.0.19
3115 3115
 	 */
3116
-	public function get_discount( $discount = false ) {
3116
+	public function get_discount($discount = false) {
3117 3117
 
3118 3118
 		// Backwards compatibilty.
3119
-		if ( empty( $discount ) ) {
3119
+		if (empty($discount)) {
3120 3120
 			return $this->get_total_discount();
3121 3121
 		}
3122 3122
 
3123 3123
         $discounts = $this->get_discounts();
3124
-		return isset( $discounts[ $discount ] ) ? $discounts[ $discount ] : null;
3124
+		return isset($discounts[$discount]) ? $discounts[$discount] : null;
3125 3125
     }
3126 3126
 
3127 3127
     /**
@@ -3129,11 +3129,11 @@  discard block
 block discarded – undo
3129 3129
 	 *
3130 3130
 	 * @since 1.0.19
3131 3131
 	 */
3132
-	public function remove_discount( $discount ) {
3132
+	public function remove_discount($discount) {
3133 3133
         $discounts = $this->get_discounts();
3134
-        if ( isset( $discounts[ $discount ] ) ) {
3135
-            unset( $discounts[ $discount ] );
3136
-            $this->set_prop( 'discounts', $discounts );
3134
+        if (isset($discounts[$discount])) {
3135
+            unset($discounts[$discount]);
3136
+            $this->set_prop('discounts', $discounts);
3137 3137
         }
3138 3138
     }
3139 3139
 
@@ -3143,31 +3143,31 @@  discard block
 block discarded – undo
3143 3143
      * @param string $tax
3144 3144
      * @param float $value
3145 3145
      */
3146
-    public function add_tax( $tax, $value, $recurring = true ) {
3146
+    public function add_tax($tax, $value, $recurring = true) {
3147 3147
 
3148
-        if ( ! $this->is_taxable() ) {
3148
+        if (!$this->is_taxable()) {
3149 3149
             return;
3150 3150
         }
3151 3151
 
3152
-        $amount    = wpinv_sanitize_amount( $value );
3152
+        $amount    = wpinv_sanitize_amount($value);
3153 3153
         $taxes     = $this->get_taxes();
3154 3154
 
3155
-        if ( isset( $taxes[ $tax ] ) && isset( $taxes[ $tax ]['amount'] ) ) {
3155
+        if (isset($taxes[$tax]) && isset($taxes[$tax]['amount'])) {
3156 3156
 
3157
-            $amount = $taxes[ $tax ]['amount'] += $amount;
3158
-			$taxes[ $tax ] = array(
3157
+            $amount = $taxes[$tax]['amount'] += $amount;
3158
+			$taxes[$tax] = array(
3159 3159
                 'amount'    => $amount,
3160 3160
                 'recurring' => (bool) $recurring,
3161 3161
             );
3162 3162
 
3163 3163
 		} else {
3164
-			$taxes[ $tax ] = array(
3164
+			$taxes[$tax] = array(
3165 3165
                 'amount'    => $amount,
3166 3166
                 'recurring' => (bool) $recurring,
3167 3167
             );
3168 3168
 		}
3169 3169
 
3170
-        $this->set_prop( 'taxes', $tax );
3170
+        $this->set_prop('taxes', $tax);
3171 3171
 
3172 3172
     }
3173 3173
 
@@ -3176,9 +3176,9 @@  discard block
 block discarded – undo
3176 3176
 	 *
3177 3177
 	 * @since 1.0.19
3178 3178
 	 */
3179
-	public function get_tax( $tax ) {
3179
+	public function get_tax($tax) {
3180 3180
         $taxes = $this->get_taxes();
3181
-		return isset( $taxes[ $tax ] ) ? $taxes[ $tax ] : null;
3181
+		return isset($taxes[$tax]) ? $taxes[$tax] : null;
3182 3182
     }
3183 3183
 
3184 3184
     /**
@@ -3186,11 +3186,11 @@  discard block
 block discarded – undo
3186 3186
 	 *
3187 3187
 	 * @since 1.0.19
3188 3188
 	 */
3189
-	public function remove_tax( $tax ) {
3189
+	public function remove_tax($tax) {
3190 3190
         $taxes = $this->get_discounts();
3191
-        if ( isset( $taxes[ $tax ] ) ) {
3192
-            unset( $taxes[ $tax ] );
3193
-            $this->set_prop( 'taxes', $taxes );
3191
+        if (isset($taxes[$tax])) {
3192
+            unset($taxes[$tax]);
3193
+            $this->set_prop('taxes', $taxes);
3194 3194
         }
3195 3195
     }
3196 3196
 
@@ -3201,19 +3201,19 @@  discard block
 block discarded – undo
3201 3201
 	 * @return float The recalculated subtotal
3202 3202
 	 */
3203 3203
 	public function recalculate_subtotal() {
3204
-        $items     = $this->get_items();
3204
+        $items = $this->get_items();
3205 3205
 		$subtotal  = 0;
3206 3206
 		$recurring = 0;
3207 3207
 
3208
-        foreach ( $items as $item ) {
3208
+        foreach ($items as $item) {
3209 3209
 			$subtotal  += $item->get_sub_total();
3210 3210
 			$recurring += $item->get_recurring_sub_total();
3211 3211
         }
3212 3212
 
3213
-		if ( $this->is_renewal() ) {
3214
-			$this->set_subtotal( $recurring );
3213
+		if ($this->is_renewal()) {
3214
+			$this->set_subtotal($recurring);
3215 3215
 		} else {
3216
-			$this->set_subtotal( $subtotal );
3216
+			$this->set_subtotal($subtotal);
3217 3217
 		}
3218 3218
 
3219 3219
 		$this->totals['subtotal'] = array(
@@ -3235,9 +3235,9 @@  discard block
 block discarded – undo
3235 3235
 		$discount  = 0;
3236 3236
 		$recurring = 0;
3237 3237
 
3238
-        foreach ( $discounts as $data ) {
3238
+        foreach ($discounts as $data) {
3239 3239
 
3240
-			if ( $data['recurring'] ) {
3240
+			if ($data['recurring']) {
3241 3241
 				$recurring += $data['amount'];
3242 3242
 			} else {
3243 3243
 				$discount += $data['amount'];
@@ -3245,10 +3245,10 @@  discard block
 block discarded – undo
3245 3245
 
3246 3246
 		}
3247 3247
 
3248
-		if ( $this->is_renewal() ) {
3249
-			$this->set_total_discount( $recurring );
3248
+		if ($this->is_renewal()) {
3249
+			$this->set_total_discount($recurring);
3250 3250
 		} else {
3251
-			$this->set_total_discount( $discount );
3251
+			$this->set_total_discount($discount);
3252 3252
 		}
3253 3253
 
3254 3254
 		$this->totals['discount'] = array(
@@ -3267,13 +3267,13 @@  discard block
 block discarded – undo
3267 3267
 	 * @return float The recalculated tax
3268 3268
 	 */
3269 3269
 	public function recalculate_total_tax() {
3270
-        $taxes     = $this->get_taxes();
3270
+        $taxes = $this->get_taxes();
3271 3271
 		$tax       = 0;
3272 3272
 		$recurring = 0;
3273 3273
 
3274
-        foreach ( $taxes as $data ) {
3274
+        foreach ($taxes as $data) {
3275 3275
 
3276
-			if ( $data['recurring'] ) {
3276
+			if ($data['recurring']) {
3277 3277
 				$recurring += $data['amount'];
3278 3278
 			} else {
3279 3279
 				$tax += $data['amount'];
@@ -3281,10 +3281,10 @@  discard block
 block discarded – undo
3281 3281
 
3282 3282
 		}
3283 3283
 
3284
-		if ( $this->is_renewal() ) {
3285
-			$this->set_total_tax( $recurring );
3284
+		if ($this->is_renewal()) {
3285
+			$this->set_total_tax($recurring);
3286 3286
 		} else {
3287
-			$this->set_total_tax( $tax );
3287
+			$this->set_total_tax($tax);
3288 3288
 		}
3289 3289
 
3290 3290
 		$this->totals['tax'] = array(
@@ -3307,9 +3307,9 @@  discard block
 block discarded – undo
3307 3307
 		$fee       = 0;
3308 3308
 		$recurring = 0;
3309 3309
 
3310
-        foreach ( $fees as $data ) {
3310
+        foreach ($fees as $data) {
3311 3311
 
3312
-			if ( $data['recurring'] ) {
3312
+			if ($data['recurring']) {
3313 3313
 				$recurring += $data['amount'];
3314 3314
 			} else {
3315 3315
 				$fee += $data['amount'];
@@ -3317,10 +3317,10 @@  discard block
 block discarded – undo
3317 3317
 
3318 3318
 		}
3319 3319
 
3320
-        if ( $this->is_renewal() ) {
3321
-			$this->set_total_fees( $recurring );
3320
+        if ($this->is_renewal()) {
3321
+			$this->set_total_fees($recurring);
3322 3322
 		} else {
3323
-			$this->set_total_fees( $fee );
3323
+			$this->set_total_fees($fee);
3324 3324
 		}
3325 3325
 
3326 3326
 		$this->totals['fee'] = array(
@@ -3328,7 +3328,7 @@  discard block
 block discarded – undo
3328 3328
 			'recurring' => $recurring,
3329 3329
 		);
3330 3330
 
3331
-        $this->set_total_fees( $fee );
3331
+        $this->set_total_fees($fee);
3332 3332
         return $this->is_renewal() ? $recurring : $fee;
3333 3333
     }
3334 3334
 
@@ -3349,9 +3349,9 @@  discard block
 block discarded – undo
3349 3349
 	/**
3350 3350
 	 * @deprecated
3351 3351
 	 */
3352
-    public function recalculate_totals( $temp = false ) {
3353
-        $this->update_items( $temp );
3354
-        $this->save( true );
3352
+    public function recalculate_totals($temp = false) {
3353
+        $this->update_items($temp);
3354
+        $this->save(true);
3355 3355
         return $this;
3356 3356
     }
3357 3357
 
@@ -3368,33 +3368,33 @@  discard block
 block discarded – undo
3368 3368
      * @param string $note The note being added.
3369 3369
      *
3370 3370
      */
3371
-    public function add_note( $note = '', $customer_type = false, $added_by_user = false, $system = false ) {
3371
+    public function add_note($note = '', $customer_type = false, $added_by_user = false, $system = false) {
3372 3372
 
3373 3373
         // Bail if no note specified or this invoice is not yet saved.
3374
-        if ( ! $note || $this->get_id() == 0 ) {
3374
+        if (!$note || $this->get_id() == 0) {
3375 3375
             return false;
3376 3376
         }
3377 3377
 
3378
-        if ( ( ( is_user_logged_in() && wpinv_current_user_can_manage_invoicing() ) || $added_by_user ) && !$system ) {
3379
-            $user                 = get_user_by( 'id', get_current_user_id() );
3378
+        if (((is_user_logged_in() && wpinv_current_user_can_manage_invoicing()) || $added_by_user) && !$system) {
3379
+            $user                 = get_user_by('id', get_current_user_id());
3380 3380
             $comment_author       = $user->display_name;
3381 3381
             $comment_author_email = $user->user_email;
3382 3382
         } else {
3383 3383
             $comment_author       = 'System';
3384 3384
             $comment_author_email = 'system@';
3385
-            $comment_author_email .= isset( $_SERVER['HTTP_HOST'] ) ? str_replace( 'www.', '', $_SERVER['HTTP_HOST'] ) : 'noreply.com';
3386
-            $comment_author_email = sanitize_email( $comment_author_email );
3385
+            $comment_author_email .= isset($_SERVER['HTTP_HOST']) ? str_replace('www.', '', $_SERVER['HTTP_HOST']) : 'noreply.com';
3386
+            $comment_author_email = sanitize_email($comment_author_email);
3387 3387
         }
3388 3388
 
3389
-        do_action( 'wpinv_pre_insert_invoice_note', $this->get_id(), $note, $customer_type );
3389
+        do_action('wpinv_pre_insert_invoice_note', $this->get_id(), $note, $customer_type);
3390 3390
 
3391
-        $note_id = wp_insert_comment( wp_filter_comment( array(
3391
+        $note_id = wp_insert_comment(wp_filter_comment(array(
3392 3392
             'comment_post_ID'      => $this->get_id(),
3393 3393
             'comment_content'      => $note,
3394 3394
             'comment_agent'        => 'GetPaid',
3395 3395
             'user_id'              => is_admin() ? get_current_user_id() : 0,
3396
-            'comment_date'         => current_time( 'mysql' ),
3397
-            'comment_date_gmt'     => current_time( 'mysql', 1 ),
3396
+            'comment_date'         => current_time('mysql'),
3397
+            'comment_date_gmt'     => current_time('mysql', 1),
3398 3398
             'comment_approved'     => 1,
3399 3399
             'comment_parent'       => 0,
3400 3400
             'comment_author'       => $comment_author,
@@ -3402,13 +3402,13 @@  discard block
 block discarded – undo
3402 3402
             'comment_author_url'   => '',
3403 3403
             'comment_author_email' => $comment_author_email,
3404 3404
             'comment_type'         => 'wpinv_note'
3405
-        ) ) );
3405
+        )));
3406 3406
 
3407
-        do_action( 'wpinv_insert_payment_note', $note_id, $this->get_id(), $note );
3407
+        do_action('wpinv_insert_payment_note', $note_id, $this->get_id(), $note);
3408 3408
 
3409
-        if ( $customer_type ) {
3410
-            add_comment_meta( $note_id, '_wpi_customer_note', 1 );
3411
-            do_action( 'wpinv_new_customer_note', array( 'invoice_id' => $this->get_id(), 'user_note' => $note ) );
3409
+        if ($customer_type) {
3410
+            add_comment_meta($note_id, '_wpi_customer_note', 1);
3411
+            do_action('wpinv_new_customer_note', array('invoice_id' => $this->get_id(), 'user_note' => $note));
3412 3412
         }
3413 3413
 
3414 3414
         return $note_id;
@@ -3417,10 +3417,10 @@  discard block
 block discarded – undo
3417 3417
 	/**
3418 3418
      * Generates a unique key for the invoice.
3419 3419
      */
3420
-    public function generate_key( $string = '' ) {
3421
-        $auth_key  = defined( 'AUTH_KEY' ) ? AUTH_KEY : '';
3420
+    public function generate_key($string = '') {
3421
+        $auth_key = defined('AUTH_KEY') ? AUTH_KEY : '';
3422 3422
         return strtolower(
3423
-            md5( $this->get_id() . $string . date( 'Y-m-d H:i:s' ) . $auth_key . uniqid( 'wpinv', true ) )
3423
+            md5($this->get_id() . $string . date('Y-m-d H:i:s') . $auth_key . uniqid('wpinv', true))
3424 3424
         );
3425 3425
     }
3426 3426
 
@@ -3430,12 +3430,12 @@  discard block
 block discarded – undo
3430 3430
     public function generate_number() {
3431 3431
         $number = $this->get_id();
3432 3432
 
3433
-        if ( $this->has_status( 'auto-draft' ) && wpinv_sequential_number_active( $this->post_type ) ) {
3434
-            $next_number = wpinv_get_next_invoice_number( $this->post_type );
3433
+        if ($this->has_status('auto-draft') && wpinv_sequential_number_active($this->post_type)) {
3434
+            $next_number = wpinv_get_next_invoice_number($this->post_type);
3435 3435
             $number      = $next_number;
3436 3436
         }
3437 3437
 
3438
-		$number = wpinv_format_invoice_number( $number, $this->post_type );
3438
+		$number = wpinv_format_invoice_number($number, $this->post_type);
3439 3439
 
3440 3440
 		return $number;
3441 3441
 	}
@@ -3449,47 +3449,47 @@  discard block
 block discarded – undo
3449 3449
 		// Reset status transition variable.
3450 3450
 		$this->status_transition = false;
3451 3451
 
3452
-		if ( $status_transition ) {
3452
+		if ($status_transition) {
3453 3453
 			try {
3454 3454
 
3455 3455
 				// Fire a hook for the status change.
3456
-				do_action( 'getpaid_invoice_status_' . $status_transition['to'], $this->get_id(), $this, $status_transition );
3456
+				do_action('getpaid_invoice_status_' . $status_transition['to'], $this->get_id(), $this, $status_transition);
3457 3457
 
3458 3458
 				// @deprecated this is deprecated and will be removed in the future.
3459
-				do_action( 'wpinv_status_' . $status_transition['to'], $this->get_id(), $status_transition['from'] );
3459
+				do_action('wpinv_status_' . $status_transition['to'], $this->get_id(), $status_transition['from']);
3460 3460
 
3461
-				if ( ! empty( $status_transition['from'] ) ) {
3461
+				if (!empty($status_transition['from'])) {
3462 3462
 
3463 3463
 					/* translators: 1: old invoice status 2: new invoice status */
3464
-					$transition_note = sprintf( __( 'Status changed from %1$s to %2$s.', 'invoicing' ), wpinv_status_nicename( $status_transition['from'] ), wpinv_status_nicename( $status_transition['to'] ) );
3464
+					$transition_note = sprintf(__('Status changed from %1$s to %2$s.', 'invoicing'), wpinv_status_nicename($status_transition['from']), wpinv_status_nicename($status_transition['to']));
3465 3465
 
3466 3466
 					// Fire another hook.
3467
-					do_action( 'getpaid_invoice_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this );
3468
-					do_action( 'getpaid_invoice_status_changed', $this->get_id(), $status_transition['from'], $status_transition['to'], $this );
3467
+					do_action('getpaid_invoice_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this);
3468
+					do_action('getpaid_invoice_status_changed', $this->get_id(), $status_transition['from'], $status_transition['to'], $this);
3469 3469
 
3470 3470
 					// @deprecated this is deprecated and will be removed in the future.
3471
-					do_action( 'wpinv_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->ID, $status_transition['from'] );
3471
+					do_action('wpinv_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->ID, $status_transition['from']);
3472 3472
 
3473 3473
 					// Note the transition occurred.
3474
-					$this->add_note( trim( $status_transition['note'] . ' ' . $transition_note ), 0, $status_transition['manual'] );
3474
+					$this->add_note(trim($status_transition['note'] . ' ' . $transition_note), 0, $status_transition['manual']);
3475 3475
 
3476 3476
 					// Work out if this was for a payment, and trigger a payment_status hook instead.
3477 3477
 					if (
3478
-						in_array( $status_transition['from'], array( 'wpi-cancelled', 'wpi-pending', 'wpi-failed' ), true )
3479
-						&& in_array( $status_transition['to'], array( 'publish', 'wpi-processing', 'wpi-renewal' ), true )
3478
+						in_array($status_transition['from'], array('wpi-cancelled', 'wpi-pending', 'wpi-failed'), true)
3479
+						&& in_array($status_transition['to'], array('publish', 'wpi-processing', 'wpi-renewal'), true)
3480 3480
 					) {
3481
-						do_action( 'getpaid_invoice_payment_status_changed', $this->get_id(), $this, $status_transition );
3481
+						do_action('getpaid_invoice_payment_status_changed', $this->get_id(), $this, $status_transition);
3482 3482
 					}
3483 3483
 				} else {
3484 3484
 					/* translators: %s: new invoice status */
3485
-					$transition_note = sprintf( __( 'Status set to %s.', 'invoicing' ), wpinv_status_nicename( $status_transition['to'] ) );
3485
+					$transition_note = sprintf(__('Status set to %s.', 'invoicing'), wpinv_status_nicename($status_transition['to']));
3486 3486
 
3487 3487
 					// Note the transition occurred.
3488
-					$this->add_note( trim( $status_transition['note'] . ' ' . $transition_note ), 0, $status_transition['manual'] );
3488
+					$this->add_note(trim($status_transition['note'] . ' ' . $transition_note), 0, $status_transition['manual']);
3489 3489
 
3490 3490
 				}
3491
-			} catch ( Exception $e ) {
3492
-				$this->add_note( __( 'Error during status transition.', 'invoicing' ) . ' ' . $e->getMessage() );
3491
+			} catch (Exception $e) {
3492
+				$this->add_note(__('Error during status transition.', 'invoicing') . ' ' . $e->getMessage());
3493 3493
 			}
3494 3494
 		}
3495 3495
 	}
@@ -3497,13 +3497,13 @@  discard block
 block discarded – undo
3497 3497
 	/**
3498 3498
 	 * Updates an invoice status.
3499 3499
 	 */
3500
-	public function update_status( $new_status = false, $note = '', $manual = false ) {
3500
+	public function update_status($new_status = false, $note = '', $manual = false) {
3501 3501
 
3502 3502
 		// Fires before updating a status.
3503
-		do_action( 'wpinv_before_invoice_status_change', $this->ID, $new_status, $this->get_status( 'edit' ) );
3503
+		do_action('wpinv_before_invoice_status_change', $this->ID, $new_status, $this->get_status('edit'));
3504 3504
 
3505 3505
 		// Update the status.
3506
-		$this->set_status( $new_status, $note, $manual );
3506
+		$this->set_status($new_status, $note, $manual);
3507 3507
 
3508 3508
 		// Save the order.
3509 3509
 		return $this->save();
@@ -3514,18 +3514,18 @@  discard block
 block discarded – undo
3514 3514
 	 * @deprecated
3515 3515
 	 */
3516 3516
 	public function refresh_item_ids() {
3517
-        $item_ids = implode( ',', array_unique( array_keys( $this->get_items() ) ) );
3518
-        update_post_meta( $this->get_id(), '_wpinv_item_ids', $item_ids );
3517
+        $item_ids = implode(',', array_unique(array_keys($this->get_items())));
3518
+        update_post_meta($this->get_id(), '_wpinv_item_ids', $item_ids);
3519 3519
 	}
3520 3520
 
3521 3521
 	/**
3522 3522
 	 * @deprecated
3523 3523
 	 */
3524
-	public function update_items( $temp = false ) {
3524
+	public function update_items($temp = false) {
3525 3525
 
3526
-		$this->set_items( $this->get_items() );
3526
+		$this->set_items($this->get_items());
3527 3527
 
3528
-		if ( ! $temp ) {
3528
+		if (!$temp) {
3529 3529
 			$this->save();
3530 3530
 		}
3531 3531
 
@@ -3539,11 +3539,11 @@  discard block
 block discarded – undo
3539 3539
 
3540 3540
         $discount_code = $this->get_discount_code();
3541 3541
 
3542
-        if ( empty( $discount_code ) ) {
3542
+        if (empty($discount_code)) {
3543 3543
             return false;
3544 3544
         }
3545 3545
 
3546
-        $discount = wpinv_get_discount_obj( $discount_code );
3546
+        $discount = wpinv_get_discount_obj($discount_code);
3547 3547
 
3548 3548
         // Ensure it is active.
3549 3549
         return $discount->exists();
@@ -3554,7 +3554,7 @@  discard block
 block discarded – undo
3554 3554
 	 * Refunds an invoice.
3555 3555
 	 */
3556 3556
     public function refund() {
3557
-		$this->set_status( 'wpi-refunded' );
3557
+		$this->set_status('wpi-refunded');
3558 3558
         $this->save();
3559 3559
     }
3560 3560
 
Please login to merge, or discard this patch.
includes/wpinv-invoice-functions.php 1 patch
Spacing   +807 added lines, -807 removed lines patch added patch discarded remove patch
@@ -7,8 +7,8 @@  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
 /**
@@ -16,24 +16,24 @@  discard block
 block discarded – undo
16 16
  */
17 17
 function getpaid_get_invoice_post_types() {
18 18
     $post_types = array(
19
-        'wpi_quote'   => __( 'Quote', 'invoicing' ),
20
-        'wpi_invoice' => __( 'Invoice', 'invoicing' ),
19
+        'wpi_quote'   => __('Quote', 'invoicing'),
20
+        'wpi_invoice' => __('Invoice', 'invoicing'),
21 21
     );
22 22
     
23
-    return apply_filters( 'getpaid_invoice_post_types', $post_types );
23
+    return apply_filters('getpaid_invoice_post_types', $post_types);
24 24
 }
25 25
 
26 26
 /**
27 27
  * Checks if this is an invocing post type.
28 28
  */
29
-function getpaid_is_invoice_post_type( $post_type ) {
30
-    return array_key_exists( $post_type, getpaid_get_invoice_post_types() );
29
+function getpaid_is_invoice_post_type($post_type) {
30
+    return array_key_exists($post_type, getpaid_get_invoice_post_types());
31 31
 }
32 32
 
33 33
 function wpinv_get_invoice_cart_id() {
34 34
     $wpinv_checkout = wpinv_get_checkout_session();
35 35
     
36
-    if ( !empty( $wpinv_checkout['invoice_id'] ) ) {
36
+    if (!empty($wpinv_checkout['invoice_id'])) {
37 37
         return $wpinv_checkout['invoice_id'];
38 38
     }
39 39
     
@@ -47,48 +47,48 @@  discard block
 block discarded – undo
47 47
  * @param  bool  $wp_error       Whether to return false or WP_Error on failure.
48 48
  * @return int|WP_Error|WPInv_Invoice The value 0 or WP_Error on failure. The WPInv_Invoice object on success.
49 49
  */
50
-function wpinv_insert_invoice( $invoice_data = array(), $wp_error = false ) {
51
-    if ( empty( $invoice_data ) ) {
50
+function wpinv_insert_invoice($invoice_data = array(), $wp_error = false) {
51
+    if (empty($invoice_data)) {
52 52
         return false;
53 53
     }
54 54
     
55
-    if ( !( !empty( $invoice_data['cart_details'] ) && is_array( $invoice_data['cart_details'] ) ) ) {
56
-        return $wp_error ? new WP_Error( 'wpinv_invalid_items', __( 'Invoice must have atleast one item.', 'invoicing' ) ) : 0;
55
+    if (!(!empty($invoice_data['cart_details']) && is_array($invoice_data['cart_details']))) {
56
+        return $wp_error ? new WP_Error('wpinv_invalid_items', __('Invoice must have atleast one item.', 'invoicing')) : 0;
57 57
     }
58 58
     
59 59
     // If no user id is provided, default to the current user id
60
-    if ( empty( $invoice_data['user_id'] ) ) {
60
+    if (empty($invoice_data['user_id'])) {
61 61
         $invoice_data['user_id'] = get_current_user_id();
62 62
     }
63 63
     
64
-    $invoice_data['invoice_id'] = !empty( $invoice_data['invoice_id'] ) ? (int)$invoice_data['invoice_id'] : 0;
64
+    $invoice_data['invoice_id'] = !empty($invoice_data['invoice_id']) ? (int) $invoice_data['invoice_id'] : 0;
65 65
     
66
-    if ( empty( $invoice_data['status'] ) ) {
66
+    if (empty($invoice_data['status'])) {
67 67
         $invoice_data['status'] = 'wpi-pending';
68 68
     }
69 69
 
70
-    if ( empty( $invoice_data['post_type'] ) ) {
70
+    if (empty($invoice_data['post_type'])) {
71 71
         $invoice_data['post_type'] = 'wpi_invoice';
72 72
     }
73 73
     
74
-    if ( empty( $invoice_data['ip'] ) ) {
74
+    if (empty($invoice_data['ip'])) {
75 75
         $invoice_data['ip'] = wpinv_get_ip();
76 76
     }
77 77
 
78 78
     // default invoice args, note that status is checked for validity in wpinv_create_invoice()
79 79
     $default_args = array(
80
-        'invoice_id'    => (int)$invoice_data['invoice_id'],
81
-        'user_id'       => (int)$invoice_data['user_id'],
80
+        'invoice_id'    => (int) $invoice_data['invoice_id'],
81
+        'user_id'       => (int) $invoice_data['user_id'],
82 82
         'status'        => $invoice_data['status'],
83 83
         'post_type'     => $invoice_data['post_type'],
84 84
     );
85 85
 
86
-    $invoice = wpinv_create_invoice( $default_args, $invoice_data, true );
87
-    if ( is_wp_error( $invoice ) ) {
86
+    $invoice = wpinv_create_invoice($default_args, $invoice_data, true);
87
+    if (is_wp_error($invoice)) {
88 88
         return $wp_error ? $invoice : 0;
89 89
     }
90 90
     
91
-    if ( empty( $invoice_data['invoice_id'] ) ) {
91
+    if (empty($invoice_data['invoice_id'])) {
92 92
         //$invoice->add_note( wp_sprintf( __( 'Invoice is created with status %s.', 'invoicing' ), wpinv_status_nicename( $invoice->status ) ) );
93 93
     }
94 94
     
@@ -111,24 +111,24 @@  discard block
 block discarded – undo
111 111
         'discount'              => array(),
112 112
     );
113 113
 
114
-    if ( $user_id = (int)$invoice->get_user_id() ) {
115
-        if ( $user_address = wpinv_get_user_address( $user_id ) ) {
116
-            $default_user_info = wp_parse_args( $user_address, $default_user_info );
114
+    if ($user_id = (int) $invoice->get_user_id()) {
115
+        if ($user_address = wpinv_get_user_address($user_id)) {
116
+            $default_user_info = wp_parse_args($user_address, $default_user_info);
117 117
         }
118 118
     }
119 119
     
120
-    if ( empty( $invoice_data['user_info'] ) ) {
120
+    if (empty($invoice_data['user_info'])) {
121 121
         $invoice_data['user_info'] = array();
122 122
     }
123 123
     
124
-    $user_info = wp_parse_args( $invoice_data['user_info'], $default_user_info );
124
+    $user_info = wp_parse_args($invoice_data['user_info'], $default_user_info);
125 125
     
126
-    if ( empty( $user_info['first_name'] ) ) {
126
+    if (empty($user_info['first_name'])) {
127 127
         $user_info['first_name'] = $default_user_info['first_name'];
128 128
         $user_info['last_name'] = $default_user_info['last_name'];
129 129
     }
130 130
     
131
-    if ( empty( $user_info['country'] ) ) {
131
+    if (empty($user_info['country'])) {
132 132
         $user_info['country'] = $default_user_info['country'];
133 133
         $user_info['state'] = $default_user_info['state'];
134 134
         $user_info['city'] = $default_user_info['city'];
@@ -137,13 +137,13 @@  discard block
 block discarded – undo
137 137
         $user_info['phone'] = $default_user_info['phone'];
138 138
     }
139 139
     
140
-    if ( !empty( $user_info['discount'] ) && !is_array( $user_info['discount'] ) ) {
141
-        $user_info['discount'] = (array)$user_info['discount'];
140
+    if (!empty($user_info['discount']) && !is_array($user_info['discount'])) {
141
+        $user_info['discount'] = (array) $user_info['discount'];
142 142
     }
143 143
 
144 144
     // Payment details
145 145
     $payment_details = array();
146
-    if ( !empty( $invoice_data['payment_details'] ) ) {
146
+    if (!empty($invoice_data['payment_details'])) {
147 147
         $default_payment_details = array(
148 148
             'gateway'           => 'manual',
149 149
             'gateway_title'     => '',
@@ -151,56 +151,56 @@  discard block
 block discarded – undo
151 151
             'transaction_id'    => '',
152 152
         );
153 153
         
154
-        $payment_details = wp_parse_args( $invoice_data['payment_details'], $default_payment_details );
154
+        $payment_details = wp_parse_args($invoice_data['payment_details'], $default_payment_details);
155 155
         
156
-        if ( empty( $payment_details['gateway'] ) ) {
156
+        if (empty($payment_details['gateway'])) {
157 157
             $payment_details['gateway'] = 'manual';
158 158
         }
159 159
         
160
-        if ( empty( $payment_details['currency'] ) ) {
160
+        if (empty($payment_details['currency'])) {
161 161
             $payment_details['currency'] = wpinv_get_default_country();
162 162
         }
163 163
         
164
-        if ( empty( $payment_details['gateway_title'] ) ) {
165
-            $payment_details['gateway_title'] = wpinv_get_gateway_checkout_label( $payment_details['gateway'] );
164
+        if (empty($payment_details['gateway_title'])) {
165
+            $payment_details['gateway_title'] = wpinv_get_gateway_checkout_label($payment_details['gateway']);
166 166
         }
167 167
     }
168 168
     
169
-    $invoice->set( 'status', ( !empty( $invoice_data['status'] ) ? $invoice_data['status'] : 'wpi-pending' ) );
170
-    
171
-    if ( !empty( $payment_details ) ) {
172
-        $invoice->set( 'currency', $payment_details['currency'] );
173
-        $invoice->set( 'gateway', $payment_details['gateway'] );
174
-        $invoice->set( 'gateway_title', $payment_details['gateway_title'] );
175
-        $invoice->set( 'transaction_id', $payment_details['transaction_id'] );
176
-    }
177
-    
178
-    $invoice->set( 'user_info', $user_info );
179
-    $invoice->set( 'first_name', $user_info['first_name'] );
180
-    $invoice->set( 'last_name', $user_info['last_name'] );
181
-    $invoice->set( 'address', $user_info['address'] );
182
-    $invoice->set( 'company', $user_info['company'] );
183
-    $invoice->set( 'vat_number', $user_info['vat_number'] );
184
-    $invoice->set( 'phone', $user_info['phone'] );
185
-    $invoice->set( 'city', $user_info['city'] );
186
-    $invoice->set( 'country', $user_info['country'] );
187
-    $invoice->set( 'state', $user_info['state'] );
188
-    $invoice->set( 'zip', $user_info['zip'] );
189
-    $invoice->set( 'discounts', $user_info['discount'] );
190
-    $invoice->set( 'ip', ( !empty( $invoice_data['ip'] ) ? $invoice_data['ip'] : wpinv_get_ip() ) );
191
-    $invoice->set( 'mode', ( wpinv_is_test_mode() ? 'test' : 'live' ) );
192
-    $invoice->set( 'parent_invoice', ( !empty( $invoice_data['parent'] ) ? absint( $invoice_data['parent'] ) : '' ) );
193
-    
194
-    if ( !empty( $invoice_data['cart_details'] ) && is_array( $invoice_data['cart_details'] ) ) {
195
-        foreach ( $invoice_data['cart_details'] as $key => $item ) {
196
-            $item_id        = !empty( $item['id'] ) ? $item['id'] : 0;
197
-            $quantity       = !empty( $item['quantity'] ) ? $item['quantity'] : 1;
198
-            $name           = !empty( $item['name'] ) ? $item['name'] : '';
199
-            $item_price     = isset( $item['item_price'] ) ? $item['item_price'] : '';
169
+    $invoice->set('status', (!empty($invoice_data['status']) ? $invoice_data['status'] : 'wpi-pending'));
170
+    
171
+    if (!empty($payment_details)) {
172
+        $invoice->set('currency', $payment_details['currency']);
173
+        $invoice->set('gateway', $payment_details['gateway']);
174
+        $invoice->set('gateway_title', $payment_details['gateway_title']);
175
+        $invoice->set('transaction_id', $payment_details['transaction_id']);
176
+    }
177
+    
178
+    $invoice->set('user_info', $user_info);
179
+    $invoice->set('first_name', $user_info['first_name']);
180
+    $invoice->set('last_name', $user_info['last_name']);
181
+    $invoice->set('address', $user_info['address']);
182
+    $invoice->set('company', $user_info['company']);
183
+    $invoice->set('vat_number', $user_info['vat_number']);
184
+    $invoice->set('phone', $user_info['phone']);
185
+    $invoice->set('city', $user_info['city']);
186
+    $invoice->set('country', $user_info['country']);
187
+    $invoice->set('state', $user_info['state']);
188
+    $invoice->set('zip', $user_info['zip']);
189
+    $invoice->set('discounts', $user_info['discount']);
190
+    $invoice->set('ip', (!empty($invoice_data['ip']) ? $invoice_data['ip'] : wpinv_get_ip()));
191
+    $invoice->set('mode', (wpinv_is_test_mode() ? 'test' : 'live'));
192
+    $invoice->set('parent_invoice', (!empty($invoice_data['parent']) ? absint($invoice_data['parent']) : ''));
193
+    
194
+    if (!empty($invoice_data['cart_details']) && is_array($invoice_data['cart_details'])) {
195
+        foreach ($invoice_data['cart_details'] as $key => $item) {
196
+            $item_id        = !empty($item['id']) ? $item['id'] : 0;
197
+            $quantity       = !empty($item['quantity']) ? $item['quantity'] : 1;
198
+            $name           = !empty($item['name']) ? $item['name'] : '';
199
+            $item_price     = isset($item['item_price']) ? $item['item_price'] : '';
200 200
             
201
-            $post_item  = new WPInv_Item( $item_id );
202
-            if ( !empty( $post_item ) ) {
203
-                $name       = !empty( $name ) ? $name : $post_item->get_name();
201
+            $post_item = new WPInv_Item($item_id);
202
+            if (!empty($post_item)) {
203
+                $name       = !empty($name) ? $name : $post_item->get_name();
204 204
                 $item_price = $item_price !== '' ? $item_price : $post_item->get_price();
205 205
             } else {
206 206
                 continue;
@@ -210,266 +210,266 @@  discard block
 block discarded – undo
210 210
                 'name'          => $name,
211 211
                 'quantity'      => $quantity,
212 212
                 'item_price'    => $item_price,
213
-                'custom_price'  => isset( $item['custom_price'] ) ? $item['custom_price'] : '',
214
-                'tax'           => !empty( $item['tax'] ) ? $item['tax'] : 0.00,
215
-                'discount'      => isset( $item['discount'] ) ? $item['discount'] : 0,
216
-                'meta'          => isset( $item['meta'] ) ? $item['meta'] : array(),
217
-                'fees'          => isset( $item['fees'] ) ? $item['fees'] : array(),
213
+                'custom_price'  => isset($item['custom_price']) ? $item['custom_price'] : '',
214
+                'tax'           => !empty($item['tax']) ? $item['tax'] : 0.00,
215
+                'discount'      => isset($item['discount']) ? $item['discount'] : 0,
216
+                'meta'          => isset($item['meta']) ? $item['meta'] : array(),
217
+                'fees'          => isset($item['fees']) ? $item['fees'] : array(),
218 218
             );
219 219
 
220
-            $invoice->add_item( $item_id, $args );
220
+            $invoice->add_item($item_id, $args);
221 221
         }
222 222
     }
223 223
 
224
-    $invoice->increase_tax( wpinv_get_cart_fee_tax() );
224
+    $invoice->increase_tax(wpinv_get_cart_fee_tax());
225 225
 
226
-    if ( isset( $invoice_data['post_date'] ) ) {
227
-        $invoice->set( 'date', $invoice_data['post_date'] );
226
+    if (isset($invoice_data['post_date'])) {
227
+        $invoice->set('date', $invoice_data['post_date']);
228 228
     }
229 229
     
230 230
     // Invoice due date
231
-    if ( isset( $invoice_data['due_date'] ) ) {
232
-        $invoice->set( 'due_date', $invoice_data['due_date'] );
231
+    if (isset($invoice_data['due_date'])) {
232
+        $invoice->set('due_date', $invoice_data['due_date']);
233 233
     }
234 234
     
235 235
     $invoice->save();
236 236
     
237 237
     // Add notes
238
-    if ( !empty( $invoice_data['private_note'] ) ) {
239
-        $invoice->add_note( $invoice_data['private_note'] );
238
+    if (!empty($invoice_data['private_note'])) {
239
+        $invoice->add_note($invoice_data['private_note']);
240 240
     }
241
-    if ( !empty( $invoice_data['user_note'] ) ) {
242
-        $invoice->add_note( $invoice_data['user_note'], true );
241
+    if (!empty($invoice_data['user_note'])) {
242
+        $invoice->add_note($invoice_data['user_note'], true);
243 243
     }
244 244
     
245
-    if ( $invoice->is_quote() ) {
245
+    if ($invoice->is_quote()) {
246 246
 
247
-        if ( isset( $invoice_data['valid_until'] ) ) {
248
-            update_post_meta( $invoice->ID, 'wpinv_quote_valid_until', $invoice_data['valid_until'] );
247
+        if (isset($invoice_data['valid_until'])) {
248
+            update_post_meta($invoice->ID, 'wpinv_quote_valid_until', $invoice_data['valid_until']);
249 249
         }
250 250
         return $invoice;
251 251
 
252 252
     }
253 253
 
254
-    do_action( 'wpinv_insert_invoice', $invoice->ID, $invoice_data );
254
+    do_action('wpinv_insert_invoice', $invoice->ID, $invoice_data);
255 255
 
256
-    if ( ! empty( $invoice->ID ) ) {
256
+    if (!empty($invoice->ID)) {
257 257
         global $wpi_userID, $wpinv_ip_address_country;
258 258
         
259
-        if ( isset( $invoice_data['created_via'] ) ) {
260
-            update_post_meta( $invoice->ID, 'wpinv_created_via', $invoice_data['created_via'] );
259
+        if (isset($invoice_data['created_via'])) {
260
+            update_post_meta($invoice->ID, 'wpinv_created_via', $invoice_data['created_via']);
261 261
         }
262 262
 
263 263
         $checkout_session = wpinv_get_checkout_session();
264 264
         
265 265
         $data_session                   = array();
266 266
         $data_session['invoice_id']     = $invoice->ID;
267
-        $data_session['cart_discounts'] = $invoice->get_discounts( true );
267
+        $data_session['cart_discounts'] = $invoice->get_discounts(true);
268 268
         
269
-        wpinv_set_checkout_session( $data_session );
269
+        wpinv_set_checkout_session($data_session);
270 270
         
271
-        $wpi_userID         = (int)$invoice->get_user_id();
271
+        $wpi_userID         = (int) $invoice->get_user_id();
272 272
         
273
-        $_POST['country']   = !empty( $invoice->country ) ? $invoice->country : wpinv_get_default_country();
273
+        $_POST['country']   = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country();
274 274
         $_POST['state']     = $invoice->state;
275 275
 
276
-        $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) );
277
-        $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) );
276
+        $invoice->set('country', sanitize_text_field($_POST['country']));
277
+        $invoice->set('state', sanitize_text_field($_POST['state']));
278 278
         
279 279
         $wpinv_ip_address_country = $invoice->country;
280 280
 
281
-        $invoice = $invoice->recalculate_totals( true );
281
+        $invoice = $invoice->recalculate_totals(true);
282 282
 
283
-        wpinv_set_checkout_session( $checkout_session );
283
+        wpinv_set_checkout_session($checkout_session);
284 284
 
285 285
         return $invoice;
286 286
     }
287 287
     
288
-    if ( $wp_error ) {
289
-        if ( is_wp_error( $invoice ) ) {
288
+    if ($wp_error) {
289
+        if (is_wp_error($invoice)) {
290 290
             return $invoice;
291 291
         } else {
292
-            return new WP_Error( 'wpinv_insert_invoice_error', __( 'Error in insert invoice.', 'invoicing' ) );
292
+            return new WP_Error('wpinv_insert_invoice_error', __('Error in insert invoice.', 'invoicing'));
293 293
         }
294 294
     } else {
295 295
         return 0;
296 296
     }
297 297
 }
298 298
 
299
-function wpinv_update_invoice( $invoice_data = array(), $wp_error = false ) {
300
-    $invoice_ID = !empty( $invoice_data['ID'] ) ? absint( $invoice_data['ID'] ) : NULL;
299
+function wpinv_update_invoice($invoice_data = array(), $wp_error = false) {
300
+    $invoice_ID = !empty($invoice_data['ID']) ? absint($invoice_data['ID']) : NULL;
301 301
 
302
-    if ( !$invoice_ID ) {
303
-        if ( $wp_error ) {
304
-            return new WP_Error( 'invalid_invoice_id', __( 'Invalid invoice ID.', 'invoicing' ) );
302
+    if (!$invoice_ID) {
303
+        if ($wp_error) {
304
+            return new WP_Error('invalid_invoice_id', __('Invalid invoice ID.', 'invoicing'));
305 305
         }
306 306
         return 0;
307 307
     }
308 308
 
309
-    $invoice = wpinv_get_invoice( $invoice_ID );
309
+    $invoice = wpinv_get_invoice($invoice_ID);
310 310
 
311
-    $recurring_item = $invoice->is_recurring() ? $invoice->get_recurring( true ) : NULL;
311
+    $recurring_item = $invoice->is_recurring() ? $invoice->get_recurring(true) : NULL;
312 312
 
313
-    if ( empty( $invoice->ID ) ) {
314
-        if ( $wp_error ) {
315
-            return new WP_Error( 'invalid_invoice', __( 'Invalid invoice.', 'invoicing' ) );
313
+    if (empty($invoice->ID)) {
314
+        if ($wp_error) {
315
+            return new WP_Error('invalid_invoice', __('Invalid invoice.', 'invoicing'));
316 316
         }
317 317
         return 0;
318 318
     }
319 319
 
320
-    if ( ! $invoice->has_status( array( 'wpi-pending' ) ) && ! $invoice->is_quote()  ) {
321
-        if ( $wp_error ) {
322
-            return new WP_Error( 'invalid_invoice_status', __( 'Only invoice with pending payment is allowed to update.', 'invoicing' ) );
320
+    if (!$invoice->has_status(array('wpi-pending')) && !$invoice->is_quote()) {
321
+        if ($wp_error) {
322
+            return new WP_Error('invalid_invoice_status', __('Only invoice with pending payment is allowed to update.', 'invoicing'));
323 323
         }
324 324
         return 0;
325 325
     }
326 326
 
327 327
     // Invoice status
328
-    if ( !empty( $invoice_data['status'] ) ) {
329
-        $invoice->set( 'status', $invoice_data['status'] );
328
+    if (!empty($invoice_data['status'])) {
329
+        $invoice->set('status', $invoice_data['status']);
330 330
     }
331 331
 
332 332
     // Invoice date
333
-    if ( !empty( $invoice_data['post_date'] ) ) {
334
-        $invoice->set( 'date', $invoice_data['post_date'] );
333
+    if (!empty($invoice_data['post_date'])) {
334
+        $invoice->set('date', $invoice_data['post_date']);
335 335
     }
336 336
 
337 337
     // Invoice due date
338
-    if ( isset( $invoice_data['due_date'] ) ) {
339
-        $invoice->set( 'due_date', $invoice_data['due_date'] );
338
+    if (isset($invoice_data['due_date'])) {
339
+        $invoice->set('due_date', $invoice_data['due_date']);
340 340
     }
341 341
 
342 342
     // Invoice IP address
343
-    if ( !empty( $invoice_data['ip'] ) ) {
344
-        $invoice->set( 'ip', $invoice_data['ip'] );
343
+    if (!empty($invoice_data['ip'])) {
344
+        $invoice->set('ip', $invoice_data['ip']);
345 345
     }
346 346
     
347 347
     // User info
348
-    if ( !empty( $invoice_data['user_info'] ) && is_array( $invoice_data['user_info'] ) ) {
349
-        $user_info = wp_parse_args( $invoice_data['user_info'], $invoice->user_info );
348
+    if (!empty($invoice_data['user_info']) && is_array($invoice_data['user_info'])) {
349
+        $user_info = wp_parse_args($invoice_data['user_info'], $invoice->user_info);
350 350
 
351
-        if ( $discounts = $invoice->get_discounts() ) {
351
+        if ($discounts = $invoice->get_discounts()) {
352 352
             $set_discount = $discounts;
353 353
         } else {
354 354
             $set_discount = '';
355 355
         }
356 356
 
357 357
         // Manage discount
358
-        if ( !empty( $invoice_data['user_info']['discount'] ) ) {
358
+        if (!empty($invoice_data['user_info']['discount'])) {
359 359
             // Remove discount
360
-            if ( $invoice_data['user_info']['discount'] == 'none' ) {
360
+            if ($invoice_data['user_info']['discount'] == 'none') {
361 361
                 $set_discount = '';
362 362
             } else {
363 363
                 $set_discount = $invoice_data['user_info']['discount'];
364 364
             }
365 365
 
366
-            $invoice->set( 'discounts', $set_discount );
366
+            $invoice->set('discounts', $set_discount);
367 367
         }
368 368
 
369 369
         $user_info['discount'] = $set_discount;
370 370
 
371
-        $invoice->set( 'user_info', $user_info );
371
+        $invoice->set('user_info', $user_info);
372 372
     }
373 373
 
374
-    if ( !empty( $invoice_data['cart_details'] ) && is_array( $invoice_data['cart_details'] ) && $cart_details = $invoice_data['cart_details'] ) {
375
-        $remove_items = !empty( $cart_details['remove_items'] ) && is_array( $cart_details['remove_items'] ) ? $cart_details['remove_items'] : array();
374
+    if (!empty($invoice_data['cart_details']) && is_array($invoice_data['cart_details']) && $cart_details = $invoice_data['cart_details']) {
375
+        $remove_items = !empty($cart_details['remove_items']) && is_array($cart_details['remove_items']) ? $cart_details['remove_items'] : array();
376 376
 
377
-        if ( !empty( $remove_items[0]['id'] ) ) {
378
-            foreach ( $remove_items as $item ) {
379
-                $item_id        = !empty( $item['id'] ) ? $item['id'] : 0;
380
-                $quantity       = !empty( $item['quantity'] ) ? $item['quantity'] : 1;
381
-                if ( empty( $item_id ) ) {
377
+        if (!empty($remove_items[0]['id'])) {
378
+            foreach ($remove_items as $item) {
379
+                $item_id        = !empty($item['id']) ? $item['id'] : 0;
380
+                $quantity       = !empty($item['quantity']) ? $item['quantity'] : 1;
381
+                if (empty($item_id)) {
382 382
                     continue;
383 383
                 }
384 384
 
385
-                foreach ( $invoice->cart_details as $cart_index => $cart_item ) {
386
-                    if ( $item_id == $cart_item['id'] ) {
385
+                foreach ($invoice->cart_details as $cart_index => $cart_item) {
386
+                    if ($item_id == $cart_item['id']) {
387 387
                         $args = array(
388 388
                             'id'         => $item_id,
389 389
                             'quantity'   => $quantity,
390 390
                             'cart_index' => $cart_index
391 391
                         );
392 392
 
393
-                        $invoice->remove_item( $item_id, $args );
393
+                        $invoice->remove_item($item_id, $args);
394 394
                         break;
395 395
                     }
396 396
                 }
397 397
             }
398 398
         }
399 399
 
400
-        $add_items = !empty( $cart_details['add_items'] ) && is_array( $cart_details['add_items'] ) ? $cart_details['add_items'] : array();
400
+        $add_items = !empty($cart_details['add_items']) && is_array($cart_details['add_items']) ? $cart_details['add_items'] : array();
401 401
 
402
-        if ( !empty( $add_items[0]['id'] ) ) {
403
-            foreach ( $add_items as $item ) {
404
-                $item_id        = !empty( $item['id'] ) ? $item['id'] : 0;
405
-                $post_item      = new WPInv_Item( $item_id );
406
-                if ( empty( $post_item ) ) {
402
+        if (!empty($add_items[0]['id'])) {
403
+            foreach ($add_items as $item) {
404
+                $item_id        = !empty($item['id']) ? $item['id'] : 0;
405
+                $post_item      = new WPInv_Item($item_id);
406
+                if (empty($post_item)) {
407 407
                     continue;
408 408
                 }
409 409
 
410 410
                 $valid_item = true;
411
-                if ( !empty( $recurring_item ) ) {
412
-                    if ( $recurring_item->ID != $item_id ) {
411
+                if (!empty($recurring_item)) {
412
+                    if ($recurring_item->ID != $item_id) {
413 413
                         $valid_item = false;
414 414
                     }
415
-                } else if ( wpinv_is_recurring_item( $item_id ) ) {
415
+                } else if (wpinv_is_recurring_item($item_id)) {
416 416
                     $valid_item = false;
417 417
                 }
418 418
                 
419
-                if ( !$valid_item ) {
420
-                    if ( $wp_error ) {
421
-                        return new WP_Error( 'invalid_invoice_item', __( 'You can not add item because recurring item must be paid individually!', 'invoicing' ) );
419
+                if (!$valid_item) {
420
+                    if ($wp_error) {
421
+                        return new WP_Error('invalid_invoice_item', __('You can not add item because recurring item must be paid individually!', 'invoicing'));
422 422
                     }
423 423
                     return 0;
424 424
                 }
425 425
 
426
-                $quantity       = !empty( $item['quantity'] ) ? $item['quantity'] : 1;
427
-                $name           = !empty( $item['name'] ) ? $item['name'] : $post_item->get_name();
428
-                $item_price     = isset( $item['item_price'] ) ? $item['item_price'] : $post_item->get_price();
426
+                $quantity       = !empty($item['quantity']) ? $item['quantity'] : 1;
427
+                $name           = !empty($item['name']) ? $item['name'] : $post_item->get_name();
428
+                $item_price     = isset($item['item_price']) ? $item['item_price'] : $post_item->get_price();
429 429
 
430 430
                 $args = array(
431 431
                     'name'          => $name,
432 432
                     'quantity'      => $quantity,
433 433
                     'item_price'    => $item_price,
434
-                    'custom_price'  => isset( $item['custom_price'] ) ? $item['custom_price'] : '',
435
-                    'tax'           => !empty( $item['tax'] ) ? $item['tax'] : 0,
436
-                    'discount'      => isset( $item['discount'] ) ? $item['discount'] : 0,
437
-                    'meta'          => isset( $item['meta'] ) ? $item['meta'] : array(),
438
-                    'fees'          => isset( $item['fees'] ) ? $item['fees'] : array(),
434
+                    'custom_price'  => isset($item['custom_price']) ? $item['custom_price'] : '',
435
+                    'tax'           => !empty($item['tax']) ? $item['tax'] : 0,
436
+                    'discount'      => isset($item['discount']) ? $item['discount'] : 0,
437
+                    'meta'          => isset($item['meta']) ? $item['meta'] : array(),
438
+                    'fees'          => isset($item['fees']) ? $item['fees'] : array(),
439 439
                 );
440 440
 
441
-                $invoice->add_item( $item_id, $args );
441
+                $invoice->add_item($item_id, $args);
442 442
             }
443 443
         }
444 444
     }
445 445
     
446 446
     // Payment details
447
-    if ( !empty( $invoice_data['payment_details'] ) && $payment_details = $invoice_data['payment_details'] ) {
448
-        if ( !empty( $payment_details['gateway'] ) ) {
449
-            $invoice->set( 'gateway', $payment_details['gateway'] );
447
+    if (!empty($invoice_data['payment_details']) && $payment_details = $invoice_data['payment_details']) {
448
+        if (!empty($payment_details['gateway'])) {
449
+            $invoice->set('gateway', $payment_details['gateway']);
450 450
         }
451 451
 
452
-        if ( !empty( $payment_details['transaction_id'] ) ) {
453
-            $invoice->set( 'transaction_id', $payment_details['transaction_id'] );
452
+        if (!empty($payment_details['transaction_id'])) {
453
+            $invoice->set('transaction_id', $payment_details['transaction_id']);
454 454
         }
455 455
     }
456 456
 
457
-    do_action( 'wpinv_pre_update_invoice', $invoice->ID, $invoice_data );
457
+    do_action('wpinv_pre_update_invoice', $invoice->ID, $invoice_data);
458 458
 
459 459
     // Parent invoice
460
-    if ( !empty( $invoice_data['parent'] ) ) {
461
-        $invoice->set( 'parent_invoice', $invoice_data['parent'] );
460
+    if (!empty($invoice_data['parent'])) {
461
+        $invoice->set('parent_invoice', $invoice_data['parent']);
462 462
     }
463 463
 
464 464
     // Save invoice data.
465 465
     $invoice->save();
466 466
     
467
-    if ( empty( $invoice->ID ) || is_wp_error( $invoice ) ) {
468
-        if ( $wp_error ) {
469
-            if ( is_wp_error( $invoice ) ) {
467
+    if (empty($invoice->ID) || is_wp_error($invoice)) {
468
+        if ($wp_error) {
469
+            if (is_wp_error($invoice)) {
470 470
                 return $invoice;
471 471
             } else {
472
-                return new WP_Error( 'wpinv_update_invoice_error', __( 'Error in update invoice.', 'invoicing' ) );
472
+                return new WP_Error('wpinv_update_invoice_error', __('Error in update invoice.', 'invoicing'));
473 473
             }
474 474
         } else {
475 475
             return 0;
@@ -477,19 +477,19 @@  discard block
 block discarded – undo
477 477
     }
478 478
 
479 479
     // Add private note
480
-    if ( !empty( $invoice_data['private_note'] ) ) {
481
-        $invoice->add_note( $invoice_data['private_note'] );
480
+    if (!empty($invoice_data['private_note'])) {
481
+        $invoice->add_note($invoice_data['private_note']);
482 482
     }
483 483
 
484 484
     // Add user note
485
-    if ( !empty( $invoice_data['user_note'] ) ) {
486
-        $invoice->add_note( $invoice_data['user_note'], true );
485
+    if (!empty($invoice_data['user_note'])) {
486
+        $invoice->add_note($invoice_data['user_note'], true);
487 487
     }
488 488
 
489
-    if ( $invoice->is_quote() ) {
489
+    if ($invoice->is_quote()) {
490 490
 
491
-        if ( isset( $invoice_data['valid_until'] ) ) {
492
-            update_post_meta( $invoice->ID, 'wpinv_quote_valid_until', $invoice_data['valid_until'] );
491
+        if (isset($invoice_data['valid_until'])) {
492
+            update_post_meta($invoice->ID, 'wpinv_quote_valid_until', $invoice_data['valid_until']);
493 493
         }
494 494
         return $invoice;
495 495
 
@@ -501,466 +501,466 @@  discard block
 block discarded – undo
501 501
 
502 502
     $data_session                   = array();
503 503
     $data_session['invoice_id']     = $invoice->ID;
504
-    $data_session['cart_discounts'] = $invoice->get_discounts( true );
504
+    $data_session['cart_discounts'] = $invoice->get_discounts(true);
505 505
 
506
-    wpinv_set_checkout_session( $data_session );
506
+    wpinv_set_checkout_session($data_session);
507 507
 
508
-    $wpi_userID         = (int)$invoice->get_user_id();
508
+    $wpi_userID         = (int) $invoice->get_user_id();
509 509
 
510
-    $_POST['country']   = !empty( $invoice->country ) ? $invoice->country : wpinv_get_default_country();
510
+    $_POST['country']   = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country();
511 511
     $_POST['state']     = $invoice->state;
512 512
 
513
-    $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) );
514
-    $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) );
513
+    $invoice->set('country', sanitize_text_field($_POST['country']));
514
+    $invoice->set('state', sanitize_text_field($_POST['state']));
515 515
 
516 516
     $wpinv_ip_address_country = $invoice->country;
517 517
 
518
-    $invoice = $invoice->recalculate_totals( true );
518
+    $invoice = $invoice->recalculate_totals(true);
519 519
 
520
-    do_action( 'wpinv_post_update_invoice', $invoice->ID, $invoice_data );
520
+    do_action('wpinv_post_update_invoice', $invoice->ID, $invoice_data);
521 521
 
522
-    wpinv_set_checkout_session( $checkout_session );
522
+    wpinv_set_checkout_session($checkout_session);
523 523
 
524 524
     return $invoice;
525 525
 }
526 526
 
527
-function wpinv_get_invoice( $invoice_id = 0, $cart = false ) {
528
-    if ( $cart && empty( $invoice_id ) ) {
529
-        $invoice_id = (int)wpinv_get_invoice_cart_id();
527
+function wpinv_get_invoice($invoice_id = 0, $cart = false) {
528
+    if ($cart && empty($invoice_id)) {
529
+        $invoice_id = (int) wpinv_get_invoice_cart_id();
530 530
     }
531 531
 
532
-    $invoice = new WPInv_Invoice( $invoice_id );
532
+    $invoice = new WPInv_Invoice($invoice_id);
533 533
 
534
-    if ( $invoice->get_id() != 0 ) {
534
+    if ($invoice->get_id() != 0) {
535 535
         return $invoice;
536 536
     }
537 537
 
538 538
     return NULL;
539 539
 }
540 540
 
541
-function wpinv_get_invoice_cart( $invoice_id = 0 ) {
542
-    return wpinv_get_invoice( $invoice_id, true );
541
+function wpinv_get_invoice_cart($invoice_id = 0) {
542
+    return wpinv_get_invoice($invoice_id, true);
543 543
 }
544 544
 
545
-function wpinv_get_invoice_description( $invoice_id = 0 ) {
546
-    $invoice = new WPInv_Invoice( $invoice_id );
545
+function wpinv_get_invoice_description($invoice_id = 0) {
546
+    $invoice = new WPInv_Invoice($invoice_id);
547 547
     return $invoice->get_description();
548 548
 }
549 549
 
550
-function wpinv_get_invoice_currency_code( $invoice_id = 0 ) {
551
-    $invoice = new WPInv_Invoice( $invoice_id );
550
+function wpinv_get_invoice_currency_code($invoice_id = 0) {
551
+    $invoice = new WPInv_Invoice($invoice_id);
552 552
     return $invoice->get_currency();
553 553
 }
554 554
 
555
-function wpinv_get_payment_user_email( $invoice_id ) {
556
-    $invoice = new WPInv_Invoice( $invoice_id );
555
+function wpinv_get_payment_user_email($invoice_id) {
556
+    $invoice = new WPInv_Invoice($invoice_id);
557 557
     return $invoice->get_email();
558 558
 }
559 559
 
560
-function wpinv_get_user_id( $invoice_id ) {
561
-    $invoice = new WPInv_Invoice( $invoice_id );
560
+function wpinv_get_user_id($invoice_id) {
561
+    $invoice = new WPInv_Invoice($invoice_id);
562 562
     return $invoice->get_user_id();
563 563
 }
564 564
 
565
-function wpinv_get_invoice_status( $invoice_id, $return_label = false ) {
566
-    $invoice = new WPInv_Invoice( $invoice_id );
565
+function wpinv_get_invoice_status($invoice_id, $return_label = false) {
566
+    $invoice = new WPInv_Invoice($invoice_id);
567 567
     
568
-    return $invoice->get_status( $return_label );
568
+    return $invoice->get_status($return_label);
569 569
 }
570 570
 
571
-function wpinv_get_payment_gateway( $invoice_id, $return_label = false ) {
572
-    $invoice = new WPInv_Invoice( $invoice_id );
571
+function wpinv_get_payment_gateway($invoice_id, $return_label = false) {
572
+    $invoice = new WPInv_Invoice($invoice_id);
573 573
     
574
-    return $invoice->get_gateway( $return_label );
574
+    return $invoice->get_gateway($return_label);
575 575
 }
576 576
 
577
-function wpinv_get_payment_gateway_name( $invoice_id ) {
578
-    $invoice = new WPInv_Invoice( $invoice_id );
577
+function wpinv_get_payment_gateway_name($invoice_id) {
578
+    $invoice = new WPInv_Invoice($invoice_id);
579 579
     
580 580
     return $invoice->get_gateway_title();
581 581
 }
582 582
 
583
-function wpinv_get_payment_transaction_id( $invoice_id ) {
584
-    $invoice = new WPInv_Invoice( $invoice_id );
583
+function wpinv_get_payment_transaction_id($invoice_id) {
584
+    $invoice = new WPInv_Invoice($invoice_id);
585 585
     
586 586
     return $invoice->get_transaction_id();
587 587
 }
588 588
 
589
-function wpinv_get_id_by_transaction_id( $key ) {
589
+function wpinv_get_id_by_transaction_id($key) {
590 590
     global $wpdb;
591 591
 
592
-    $invoice_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = %s LIMIT 1", $key ) );
592
+    $invoice_id = $wpdb->get_var($wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = %s LIMIT 1", $key));
593 593
 
594
-    if ( $invoice_id != NULL )
594
+    if ($invoice_id != NULL)
595 595
         return $invoice_id;
596 596
 
597 597
     return 0;
598 598
 }
599 599
 
600
-function wpinv_get_invoice_meta( $invoice_id = 0, $meta_key = '_wpinv_payment_meta', $single = true ) {
601
-    $invoice = new WPInv_Invoice( $invoice_id );
600
+function wpinv_get_invoice_meta($invoice_id = 0, $meta_key = '_wpinv_payment_meta', $single = true) {
601
+    $invoice = new WPInv_Invoice($invoice_id);
602 602
 
603
-    return $invoice->get_meta( $meta_key, $single );
603
+    return $invoice->get_meta($meta_key, $single);
604 604
 }
605 605
 
606
-function wpinv_update_invoice_meta( $invoice_id = 0, $meta_key = '', $meta_value = '', $prev_value = '' ) {
607
-    $invoice = new WPInv_Invoice( $invoice_id );
606
+function wpinv_update_invoice_meta($invoice_id = 0, $meta_key = '', $meta_value = '', $prev_value = '') {
607
+    $invoice = new WPInv_Invoice($invoice_id);
608 608
     
609
-    return $invoice->update_meta( $meta_key, $meta_value, $prev_value );
609
+    return $invoice->update_meta($meta_key, $meta_value, $prev_value);
610 610
 }
611 611
 
612
-function wpinv_get_items( $invoice_id = 0 ) {
613
-    $invoice            = wpinv_get_invoice( $invoice_id );
612
+function wpinv_get_items($invoice_id = 0) {
613
+    $invoice            = wpinv_get_invoice($invoice_id);
614 614
     
615 615
     $items              = $invoice->get_items();
616 616
     $invoice_currency   = $invoice->get_currency();
617 617
 
618
-    if ( !empty( $items ) && is_array( $items ) ) {
619
-        foreach ( $items as $key => $item ) {
618
+    if (!empty($items) && is_array($items)) {
619
+        foreach ($items as $key => $item) {
620 620
             $items[$key]['currency'] = $invoice_currency;
621 621
 
622
-            if ( !isset( $item['subtotal'] ) ) {
622
+            if (!isset($item['subtotal'])) {
623 623
                 $items[$key]['subtotal'] = $items[$key]['amount'] * 1;
624 624
             }
625 625
         }
626 626
     }
627 627
 
628
-    return apply_filters( 'wpinv_get_items', $items, $invoice_id );
628
+    return apply_filters('wpinv_get_items', $items, $invoice_id);
629 629
 }
630 630
 
631
-function wpinv_get_fees( $invoice_id = 0 ) {
632
-    $invoice           = wpinv_get_invoice( $invoice_id );
631
+function wpinv_get_fees($invoice_id = 0) {
632
+    $invoice           = wpinv_get_invoice($invoice_id);
633 633
     $fees              = $invoice->get_fees();
634 634
 
635
-    return apply_filters( 'wpinv_get_fees', $fees, $invoice_id );
635
+    return apply_filters('wpinv_get_fees', $fees, $invoice_id);
636 636
 }
637 637
 
638
-function wpinv_get_invoice_ip( $invoice_id ) {
639
-    $invoice = new WPInv_Invoice( $invoice_id );
638
+function wpinv_get_invoice_ip($invoice_id) {
639
+    $invoice = new WPInv_Invoice($invoice_id);
640 640
     return $invoice->get_ip();
641 641
 }
642 642
 
643
-function wpinv_get_invoice_user_info( $invoice_id ) {
644
-    $invoice = new WPInv_Invoice( $invoice_id );
643
+function wpinv_get_invoice_user_info($invoice_id) {
644
+    $invoice = new WPInv_Invoice($invoice_id);
645 645
     return $invoice->get_user_info();
646 646
 }
647 647
 
648
-function wpinv_subtotal( $invoice_id = 0, $currency = false ) {
649
-    $invoice = new WPInv_Invoice( $invoice_id );
648
+function wpinv_subtotal($invoice_id = 0, $currency = false) {
649
+    $invoice = new WPInv_Invoice($invoice_id);
650 650
 
651
-    return $invoice->get_subtotal( $currency );
651
+    return $invoice->get_subtotal($currency);
652 652
 }
653 653
 
654
-function wpinv_tax( $invoice_id = 0, $currency = false ) {
655
-    $invoice = new WPInv_Invoice( $invoice_id );
654
+function wpinv_tax($invoice_id = 0, $currency = false) {
655
+    $invoice = new WPInv_Invoice($invoice_id);
656 656
 
657
-    return $invoice->get_tax( $currency );
657
+    return $invoice->get_tax($currency);
658 658
 }
659 659
 
660
-function wpinv_discount( $invoice_id = 0, $currency = false, $dash = false ) {
661
-    $invoice = wpinv_get_invoice( $invoice_id );
660
+function wpinv_discount($invoice_id = 0, $currency = false, $dash = false) {
661
+    $invoice = wpinv_get_invoice($invoice_id);
662 662
 
663
-    return $invoice->get_discount( $currency, $dash );
663
+    return $invoice->get_discount($currency, $dash);
664 664
 }
665 665
 
666
-function wpinv_discount_code( $invoice_id = 0 ) {
667
-    $invoice = new WPInv_Invoice( $invoice_id );
666
+function wpinv_discount_code($invoice_id = 0) {
667
+    $invoice = new WPInv_Invoice($invoice_id);
668 668
 
669 669
     return $invoice->get_discount_code();
670 670
 }
671 671
 
672
-function wpinv_payment_total( $invoice_id = 0, $currency = false ) {
673
-    $invoice = new WPInv_Invoice( $invoice_id );
672
+function wpinv_payment_total($invoice_id = 0, $currency = false) {
673
+    $invoice = new WPInv_Invoice($invoice_id);
674 674
 
675
-    return $invoice->get_total( $currency );
675
+    return $invoice->get_total($currency);
676 676
 }
677 677
 
678
-function wpinv_get_date_created( $invoice_id = 0, $format = '' ) {
679
-    $invoice = new WPInv_Invoice( $invoice_id );
678
+function wpinv_get_date_created($invoice_id = 0, $format = '') {
679
+    $invoice = new WPInv_Invoice($invoice_id);
680 680
 
681
-    $format         = !empty( $format ) ? $format : get_option( 'date_format' );
681
+    $format         = !empty($format) ? $format : get_option('date_format');
682 682
     $date_created   = $invoice->get_created_date();
683
-    $date_created   = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n( $format, strtotime( $date_created ) ) : '';
683
+    $date_created   = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n($format, strtotime($date_created)) : '';
684 684
 
685 685
     return $date_created;
686 686
 }
687 687
 
688
-function wpinv_get_invoice_date( $invoice_id = 0, $format = '', $default = true ) {
689
-    $invoice = new WPInv_Invoice( $invoice_id );
688
+function wpinv_get_invoice_date($invoice_id = 0, $format = '', $default = true) {
689
+    $invoice = new WPInv_Invoice($invoice_id);
690 690
     
691
-    $format         = !empty( $format ) ? $format : get_option( 'date_format' );
691
+    $format         = !empty($format) ? $format : get_option('date_format');
692 692
     $date_completed = $invoice->get_completed_date();
693
-    $invoice_date   = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? date_i18n( $format, strtotime( $date_completed ) ) : '';
694
-    if ( $invoice_date == '' && $default ) {
695
-        $invoice_date   = wpinv_get_date_created( $invoice_id, $format );
693
+    $invoice_date   = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? date_i18n($format, strtotime($date_completed)) : '';
694
+    if ($invoice_date == '' && $default) {
695
+        $invoice_date = wpinv_get_date_created($invoice_id, $format);
696 696
     }
697 697
 
698 698
     return $invoice_date;
699 699
 }
700 700
 
701
-function wpinv_get_invoice_vat_number( $invoice_id = 0 ) {
702
-    $invoice = new WPInv_Invoice( $invoice_id );
701
+function wpinv_get_invoice_vat_number($invoice_id = 0) {
702
+    $invoice = new WPInv_Invoice($invoice_id);
703 703
     
704 704
     return $invoice->vat_number;
705 705
 }
706 706
 
707
-function wpinv_insert_payment_note( $invoice_id = 0, $note = '', $user_type = false, $added_by_user = false, $system = false ) {
708
-    $invoice = new WPInv_Invoice( $invoice_id );
707
+function wpinv_insert_payment_note($invoice_id = 0, $note = '', $user_type = false, $added_by_user = false, $system = false) {
708
+    $invoice = new WPInv_Invoice($invoice_id);
709 709
 
710
-    return $invoice->add_note( $note, $user_type, $added_by_user, $system );
710
+    return $invoice->add_note($note, $user_type, $added_by_user, $system);
711 711
 }
712 712
 
713
-function wpinv_get_invoice_notes( $invoice_id = 0, $type = '' ) {
713
+function wpinv_get_invoice_notes($invoice_id = 0, $type = '') {
714 714
     global $invoicing;
715 715
     
716
-    if ( empty( $invoice_id ) ) {
716
+    if (empty($invoice_id)) {
717 717
         return NULL;
718 718
     }
719 719
     
720
-    $notes = $invoicing->notes->get_invoice_notes( $invoice_id, $type );
720
+    $notes = $invoicing->notes->get_invoice_notes($invoice_id, $type);
721 721
     
722
-    return apply_filters( 'wpinv_invoice_notes', $notes, $invoice_id, $type );
722
+    return apply_filters('wpinv_invoice_notes', $notes, $invoice_id, $type);
723 723
 }
724 724
 
725
-function wpinv_get_payment_key( $invoice_id = 0 ) {
726
-	$invoice = new WPInv_Invoice( $invoice_id );
725
+function wpinv_get_payment_key($invoice_id = 0) {
726
+	$invoice = new WPInv_Invoice($invoice_id);
727 727
     return $invoice->get_key();
728 728
 }
729 729
 
730
-function wpinv_get_invoice_number( $invoice_id = 0 ) {
731
-    $invoice = new WPInv_Invoice( $invoice_id );
730
+function wpinv_get_invoice_number($invoice_id = 0) {
731
+    $invoice = new WPInv_Invoice($invoice_id);
732 732
     return $invoice->get_number();
733 733
 }
734 734
 
735
-function wpinv_get_cart_discountable_subtotal( $code_id ) {
735
+function wpinv_get_cart_discountable_subtotal($code_id) {
736 736
     $cart_items = wpinv_get_cart_content_details();
737 737
     $items      = array();
738 738
 
739
-    $excluded_items = wpinv_get_discount_excluded_items( $code_id );
739
+    $excluded_items = wpinv_get_discount_excluded_items($code_id);
740 740
 
741
-    if( $cart_items ) {
741
+    if ($cart_items) {
742 742
 
743
-        foreach( $cart_items as $item ) {
743
+        foreach ($cart_items as $item) {
744 744
 
745
-            if( ! in_array( $item['id'], $excluded_items ) ) {
746
-                $items[] =  $item;
745
+            if (!in_array($item['id'], $excluded_items)) {
746
+                $items[] = $item;
747 747
             }
748 748
         }
749 749
     }
750 750
 
751
-    $subtotal = wpinv_get_cart_items_subtotal( $items );
751
+    $subtotal = wpinv_get_cart_items_subtotal($items);
752 752
 
753
-    return apply_filters( 'wpinv_get_cart_discountable_subtotal', $subtotal );
753
+    return apply_filters('wpinv_get_cart_discountable_subtotal', $subtotal);
754 754
 }
755 755
 
756
-function wpinv_get_cart_items_subtotal( $items ) {
756
+function wpinv_get_cart_items_subtotal($items) {
757 757
     $subtotal = 0.00;
758 758
 
759
-    if ( is_array( $items ) && ! empty( $items ) ) {
760
-        $prices = wp_list_pluck( $items, 'subtotal' );
759
+    if (is_array($items) && !empty($items)) {
760
+        $prices = wp_list_pluck($items, 'subtotal');
761 761
 
762
-        if( is_array( $prices ) ) {
763
-            $subtotal = array_sum( $prices );
762
+        if (is_array($prices)) {
763
+            $subtotal = array_sum($prices);
764 764
         } else {
765 765
             $subtotal = 0.00;
766 766
         }
767 767
 
768
-        if( $subtotal < 0 ) {
768
+        if ($subtotal < 0) {
769 769
             $subtotal = 0.00;
770 770
         }
771 771
     }
772 772
 
773
-    return apply_filters( 'wpinv_get_cart_items_subtotal', $subtotal );
773
+    return apply_filters('wpinv_get_cart_items_subtotal', $subtotal);
774 774
 }
775 775
 
776
-function wpinv_get_cart_subtotal( $items = array() ) {
777
-    $items    = !empty( $items ) ? $items : wpinv_get_cart_content_details();
778
-    $subtotal = wpinv_get_cart_items_subtotal( $items );
776
+function wpinv_get_cart_subtotal($items = array()) {
777
+    $items    = !empty($items) ? $items : wpinv_get_cart_content_details();
778
+    $subtotal = wpinv_get_cart_items_subtotal($items);
779 779
 
780
-    return apply_filters( 'wpinv_get_cart_subtotal', $subtotal );
780
+    return apply_filters('wpinv_get_cart_subtotal', $subtotal);
781 781
 }
782 782
 
783
-function wpinv_cart_subtotal( $items = array(), $currency = '' ) {
783
+function wpinv_cart_subtotal($items = array(), $currency = '') {
784 784
 
785
-    if( empty( $currency ) ) {
785
+    if (empty($currency)) {
786 786
         $currency = wpinv_get_currency();
787 787
     }
788 788
 
789
-    $price = wpinv_price( wpinv_format_amount( wpinv_get_cart_subtotal( $items ) ), $currency );
789
+    $price = wpinv_price(wpinv_format_amount(wpinv_get_cart_subtotal($items)), $currency);
790 790
 
791 791
     return $price;
792 792
 }
793 793
 
794
-function wpinv_get_cart_total( $items = array(), $discounts = false, $invoice = array() ) {
795
-    $subtotal  = (float)wpinv_get_cart_subtotal( $items );
796
-    $discounts = (float)wpinv_get_cart_discounted_amount( $items );
797
-    $cart_tax  = (float)wpinv_get_cart_tax( $items, $invoice );
798
-    $fees      = (float)wpinv_get_cart_fee_total();
799
-    if ( !empty( $invoice ) && $invoice->is_free_trial() ) {
794
+function wpinv_get_cart_total($items = array(), $discounts = false, $invoice = array()) {
795
+    $subtotal  = (float) wpinv_get_cart_subtotal($items);
796
+    $discounts = (float) wpinv_get_cart_discounted_amount($items);
797
+    $cart_tax  = (float) wpinv_get_cart_tax($items, $invoice);
798
+    $fees      = (float) wpinv_get_cart_fee_total();
799
+    if (!empty($invoice) && $invoice->is_free_trial()) {
800 800
         $total = 0;
801 801
     } else {
802
-        $total     = $subtotal - $discounts + $cart_tax + $fees;
802
+        $total = $subtotal - $discounts + $cart_tax + $fees;
803 803
     }
804 804
 
805
-    if ( $total < 0 ) {
805
+    if ($total < 0) {
806 806
         $total = 0.00;
807 807
     }
808 808
     
809
-    $total = (float)apply_filters( 'wpinv_get_cart_total', $total, $items );
809
+    $total = (float) apply_filters('wpinv_get_cart_total', $total, $items);
810 810
 
811
-    return wpinv_sanitize_amount( $total );
811
+    return wpinv_sanitize_amount($total);
812 812
 }
813 813
 
814
-function wpinv_cart_total( $cart_items = array(), $echo = true, $invoice = array() ) {
814
+function wpinv_cart_total($cart_items = array(), $echo = true, $invoice = array()) {
815 815
     global $cart_total;
816
-    $total = wpinv_price( wpinv_format_amount( wpinv_get_cart_total( $cart_items, NULL, $invoice ) ), $invoice->get_currency() );
817
-    $total = apply_filters( 'wpinv_cart_total', $total, $cart_items, $invoice );
816
+    $total = wpinv_price(wpinv_format_amount(wpinv_get_cart_total($cart_items, NULL, $invoice)), $invoice->get_currency());
817
+    $total = apply_filters('wpinv_cart_total', $total, $cart_items, $invoice);
818 818
     
819 819
     $cart_total = $total;
820 820
 
821
-    if ( !$echo ) {
821
+    if (!$echo) {
822 822
         return $total;
823 823
     }
824 824
 
825 825
     echo $total;
826 826
 }
827 827
 
828
-function wpinv_get_cart_tax( $items = array(), $invoice = 0 ) {
828
+function wpinv_get_cart_tax($items = array(), $invoice = 0) {
829 829
 
830
-    if ( ! empty( $invoice ) && ! $invoice->is_taxable() ) {
830
+    if (!empty($invoice) && !$invoice->is_taxable()) {
831 831
         return 0;
832 832
     }
833 833
 
834 834
     $cart_tax = 0;
835
-    $items    = !empty( $items ) ? $items : wpinv_get_cart_content_details();
835
+    $items    = !empty($items) ? $items : wpinv_get_cart_content_details();
836 836
 
837
-    if ( $items ) {
838
-        $taxes = wp_list_pluck( $items, 'tax' );
837
+    if ($items) {
838
+        $taxes = wp_list_pluck($items, 'tax');
839 839
 
840
-        if( is_array( $taxes ) ) {
841
-            $cart_tax = array_sum( $taxes );
840
+        if (is_array($taxes)) {
841
+            $cart_tax = array_sum($taxes);
842 842
         }
843 843
     }
844 844
 
845 845
     $cart_tax += wpinv_get_cart_fee_tax();
846 846
 
847
-    return apply_filters( 'wpinv_get_cart_tax', wpinv_sanitize_amount( $cart_tax ) );
847
+    return apply_filters('wpinv_get_cart_tax', wpinv_sanitize_amount($cart_tax));
848 848
 }
849 849
 
850
-function wpinv_cart_tax( $items = array(), $echo = false, $currency = '', $invoice = 0 ) {
850
+function wpinv_cart_tax($items = array(), $echo = false, $currency = '', $invoice = 0) {
851 851
 
852
-    if ( ! empty( $invoice && ! $invoice->is_taxable() ) ) {
853
-        echo wpinv_price( wpinv_format_amount( 0 ), $currency );
852
+    if (!empty($invoice && !$invoice->is_taxable())) {
853
+        echo wpinv_price(wpinv_format_amount(0), $currency);
854 854
         return;
855 855
     }
856 856
 
857
-    $cart_tax = wpinv_get_cart_tax( $items, $invoice );
858
-    $cart_tax = wpinv_price( wpinv_format_amount( $cart_tax ), $currency );
857
+    $cart_tax = wpinv_get_cart_tax($items, $invoice);
858
+    $cart_tax = wpinv_price(wpinv_format_amount($cart_tax), $currency);
859 859
 
860
-    $tax = apply_filters( 'wpinv_cart_tax', $cart_tax, $items );
860
+    $tax = apply_filters('wpinv_cart_tax', $cart_tax, $items);
861 861
 
862
-    if ( !$echo ) {
862
+    if (!$echo) {
863 863
         return $tax;
864 864
     }
865 865
 
866 866
     echo $tax;
867 867
 }
868 868
 
869
-function wpinv_get_cart_discount_code( $items = array() ) {
869
+function wpinv_get_cart_discount_code($items = array()) {
870 870
     $invoice = wpinv_get_invoice_cart();
871
-    $cart_discount_code = !empty( $invoice ) ? $invoice->get_discount_code() : '';
871
+    $cart_discount_code = !empty($invoice) ? $invoice->get_discount_code() : '';
872 872
     
873
-    return apply_filters( 'wpinv_get_cart_discount_code', $cart_discount_code );
873
+    return apply_filters('wpinv_get_cart_discount_code', $cart_discount_code);
874 874
 }
875 875
 
876
-function wpinv_cart_discount_code( $items = array(), $echo = false ) {
877
-    $cart_discount_code = wpinv_get_cart_discount_code( $items );
876
+function wpinv_cart_discount_code($items = array(), $echo = false) {
877
+    $cart_discount_code = wpinv_get_cart_discount_code($items);
878 878
 
879
-    if ( $cart_discount_code != '' ) {
879
+    if ($cart_discount_code != '') {
880 880
         $cart_discount_code = ' (' . $cart_discount_code . ')';
881 881
     }
882 882
     
883
-    $discount_code = apply_filters( 'wpinv_cart_discount_code', $cart_discount_code, $items );
883
+    $discount_code = apply_filters('wpinv_cart_discount_code', $cart_discount_code, $items);
884 884
 
885
-    if ( !$echo ) {
885
+    if (!$echo) {
886 886
         return $discount_code;
887 887
     }
888 888
 
889 889
     echo $discount_code;
890 890
 }
891 891
 
892
-function wpinv_get_cart_discount( $items = array() ) {
892
+function wpinv_get_cart_discount($items = array()) {
893 893
     $invoice = wpinv_get_invoice_cart();
894
-    $cart_discount = !empty( $invoice ) ? $invoice->get_discount() : 0;
894
+    $cart_discount = !empty($invoice) ? $invoice->get_discount() : 0;
895 895
     
896
-    return apply_filters( 'wpinv_get_cart_discount', wpinv_sanitize_amount( $cart_discount ), $items );
896
+    return apply_filters('wpinv_get_cart_discount', wpinv_sanitize_amount($cart_discount), $items);
897 897
 }
898 898
 
899
-function wpinv_cart_discount( $items = array(), $echo = false ) {
900
-    $cart_discount = wpinv_get_cart_discount( $items );
901
-    $cart_discount = wpinv_price( wpinv_format_amount( $cart_discount ) );
899
+function wpinv_cart_discount($items = array(), $echo = false) {
900
+    $cart_discount = wpinv_get_cart_discount($items);
901
+    $cart_discount = wpinv_price(wpinv_format_amount($cart_discount));
902 902
 
903
-    $discount = apply_filters( 'wpinv_cart_discount', $cart_discount, $items );
903
+    $discount = apply_filters('wpinv_cart_discount', $cart_discount, $items);
904 904
 
905
-    if ( !$echo ) {
905
+    if (!$echo) {
906 906
         return $discount;
907 907
     }
908 908
 
909 909
     echo $discount;
910 910
 }
911 911
 
912
-function wpinv_get_cart_fees( $type = 'all', $item_id = 0 ) {
913
-    $item = new WPInv_Item( $item_id );
912
+function wpinv_get_cart_fees($type = 'all', $item_id = 0) {
913
+    $item = new WPInv_Item($item_id);
914 914
     
915
-    return $item->get_fees( $type, $item_id );
915
+    return $item->get_fees($type, $item_id);
916 916
 }
917 917
 
918 918
 function wpinv_get_cart_fee_total() {
919
-    $total  = 0;
919
+    $total = 0;
920 920
     $fees = wpinv_get_cart_fees();
921 921
     
922
-    if ( $fees ) {
923
-        foreach ( $fees as $fee_id => $fee ) {
922
+    if ($fees) {
923
+        foreach ($fees as $fee_id => $fee) {
924 924
             $total += $fee['amount'];
925 925
         }
926 926
     }
927 927
 
928
-    return apply_filters( 'wpinv_get_cart_fee_total', $total );
928
+    return apply_filters('wpinv_get_cart_fee_total', $total);
929 929
 }
930 930
 
931 931
 function wpinv_get_cart_fee_tax() {
932 932
     $tax  = 0;
933 933
     $fees = wpinv_get_cart_fees();
934 934
 
935
-    if ( $fees ) {
936
-        foreach ( $fees as $fee_id => $fee ) {
937
-            if( ! empty( $fee['no_tax'] ) ) {
935
+    if ($fees) {
936
+        foreach ($fees as $fee_id => $fee) {
937
+            if (!empty($fee['no_tax'])) {
938 938
                 continue;
939 939
             }
940 940
 
941
-            $tax += wpinv_calculate_tax( $fee['amount'] );
941
+            $tax += wpinv_calculate_tax($fee['amount']);
942 942
         }
943 943
     }
944 944
 
945
-    return apply_filters( 'wpinv_get_cart_fee_tax', $tax );
945
+    return apply_filters('wpinv_get_cart_fee_tax', $tax);
946 946
 }
947 947
 
948 948
 function wpinv_cart_has_recurring_item() {
949 949
     $cart_items = wpinv_get_cart_contents();
950 950
     
951
-    if ( empty( $cart_items ) ) {
951
+    if (empty($cart_items)) {
952 952
         return false;
953 953
     }
954 954
     
955 955
     $has_subscription = false;
956
-    foreach( $cart_items as $cart_item ) {
957
-        if ( !empty( $cart_item['id'] ) && wpinv_is_recurring_item( $cart_item['id'] )  ) {
956
+    foreach ($cart_items as $cart_item) {
957
+        if (!empty($cart_item['id']) && wpinv_is_recurring_item($cart_item['id'])) {
958 958
             $has_subscription = true;
959 959
             break;
960 960
         }
961 961
     }
962 962
     
963
-    return apply_filters( 'wpinv_cart_has_recurring_item', $has_subscription, $cart_items );
963
+    return apply_filters('wpinv_cart_has_recurring_item', $has_subscription, $cart_items);
964 964
 }
965 965
 
966 966
 function wpinv_cart_has_free_trial() {
@@ -968,100 +968,100 @@  discard block
 block discarded – undo
968 968
     
969 969
     $free_trial = false;
970 970
     
971
-    if ( !empty( $invoice ) && $invoice->is_free_trial() ) {
971
+    if (!empty($invoice) && $invoice->is_free_trial()) {
972 972
         $free_trial = true;
973 973
     }
974 974
     
975
-    return apply_filters( 'wpinv_cart_has_free_trial', $free_trial, $invoice );
975
+    return apply_filters('wpinv_cart_has_free_trial', $free_trial, $invoice);
976 976
 }
977 977
 
978 978
 function wpinv_get_cart_contents() {
979 979
     $cart_details = wpinv_get_cart_details();
980 980
     
981
-    return apply_filters( 'wpinv_get_cart_contents', $cart_details );
981
+    return apply_filters('wpinv_get_cart_contents', $cart_details);
982 982
 }
983 983
 
984 984
 function wpinv_get_cart_content_details() {
985 985
     global $wpinv_euvat, $wpi_current_id, $wpi_item_id, $wpinv_is_last_cart_item, $wpinv_flat_discount_total;
986 986
     $cart_items = wpinv_get_cart_contents();
987 987
     
988
-    if ( empty( $cart_items ) ) {
988
+    if (empty($cart_items)) {
989 989
         return false;
990 990
     }
991 991
     $invoice = wpinv_get_invoice_cart();
992
-	if ( empty( $invoice ) ) {
992
+	if (empty($invoice)) {
993 993
         return false;
994 994
     }
995 995
 
996 996
     $details = array();
997
-    $length  = count( $cart_items ) - 1;
997
+    $length  = count($cart_items) - 1;
998 998
     
999
-    if ( empty( $_POST['country'] ) ) {
999
+    if (empty($_POST['country'])) {
1000 1000
         $_POST['country'] = $invoice->country;
1001 1001
     }
1002
-    if ( !isset( $_POST['state'] ) ) {
1002
+    if (!isset($_POST['state'])) {
1003 1003
         $_POST['state'] = $invoice->state;
1004 1004
     }
1005 1005
 
1006
-    foreach( $cart_items as $key => $item ) {
1007
-        $item_id            = isset( $item['id'] ) ? sanitize_text_field( $item['id'] ) : '';
1008
-        if ( empty( $item_id ) ) {
1006
+    foreach ($cart_items as $key => $item) {
1007
+        $item_id = isset($item['id']) ? sanitize_text_field($item['id']) : '';
1008
+        if (empty($item_id)) {
1009 1009
             continue;
1010 1010
         }
1011 1011
         
1012 1012
         $wpi_current_id         = $invoice->ID;
1013 1013
         $wpi_item_id            = $item_id;
1014 1014
         
1015
-        if ( isset( $item['custom_price'] ) && $item['custom_price'] !== '' ) {
1015
+        if (isset($item['custom_price']) && $item['custom_price'] !== '') {
1016 1016
             $item_price = $item['custom_price'];
1017 1017
         } else {
1018
-            if ( isset( $item['item_price'] ) && $item['item_price'] !== '' && $item['item_price'] !== false ) {
1018
+            if (isset($item['item_price']) && $item['item_price'] !== '' && $item['item_price'] !== false) {
1019 1019
                 $item_price = $item['item_price'];
1020 1020
             } else {
1021
-                $item_price = wpinv_get_item_price( $item_id );
1021
+                $item_price = wpinv_get_item_price($item_id);
1022 1022
             }
1023 1023
         }
1024
-        $discount           = wpinv_get_cart_item_discount_amount( $item );
1025
-        $discount           = apply_filters( 'wpinv_get_cart_content_details_item_discount_amount', $discount, $item );
1026
-        $quantity           = wpinv_get_cart_item_quantity( $item );
1027
-        $fees               = wpinv_get_cart_fees( 'fee', $item_id );
1024
+        $discount           = wpinv_get_cart_item_discount_amount($item);
1025
+        $discount           = apply_filters('wpinv_get_cart_content_details_item_discount_amount', $discount, $item);
1026
+        $quantity           = wpinv_get_cart_item_quantity($item);
1027
+        $fees               = wpinv_get_cart_fees('fee', $item_id);
1028 1028
         
1029 1029
         $subtotal           = $item_price * $quantity;
1030
-        $tax_rate           = wpinv_get_tax_rate( $_POST['country'], $_POST['state'], $wpi_item_id );
1031
-        $tax_class          = $wpinv_euvat->get_item_class( $item_id );
1032
-        $tax                = wpinv_get_cart_item_tax( $item_id, $subtotal - $discount );
1030
+        $tax_rate           = wpinv_get_tax_rate($_POST['country'], $_POST['state'], $wpi_item_id);
1031
+        $tax_class          = $wpinv_euvat->get_item_class($item_id);
1032
+        $tax                = wpinv_get_cart_item_tax($item_id, $subtotal - $discount);
1033 1033
         
1034
-        if ( ! $invoice->is_taxable() ) {
1034
+        if (!$invoice->is_taxable()) {
1035 1035
             $tax = 0;
1036 1036
         }
1037
-        if ( wpinv_prices_include_tax() ) {
1038
-            $subtotal -= wpinv_round_amount( $tax );
1037
+        if (wpinv_prices_include_tax()) {
1038
+            $subtotal -= wpinv_round_amount($tax);
1039 1039
         }
1040 1040
         
1041
-        $total              = $subtotal - $discount + $tax;
1041
+        $total = $subtotal - $discount + $tax;
1042 1042
         
1043 1043
         // Do not allow totals to go negatve
1044
-        if( $total < 0 ) {
1044
+        if ($total < 0) {
1045 1045
             $total = 0;
1046 1046
         }
1047 1047
         
1048
-        $details[ $key ]  = array(
1048
+        $details[$key] = array(
1049 1049
             'id'                => $item_id,
1050
-            'name'              => !empty($item['name']) ? $item['name'] : get_the_title( $item_id ),
1051
-            'item_price'        => wpinv_round_amount( $item_price ),
1052
-            'custom_price'      => isset( $item['custom_price'] ) ? $item['custom_price'] : '',
1050
+            'name'              => !empty($item['name']) ? $item['name'] : get_the_title($item_id),
1051
+            'item_price'        => wpinv_round_amount($item_price),
1052
+            'custom_price'      => isset($item['custom_price']) ? $item['custom_price'] : '',
1053 1053
             'quantity'          => $quantity,
1054
-            'discount'          => wpinv_round_amount( $discount ),
1055
-            'subtotal'          => wpinv_round_amount( $subtotal ),
1056
-            'tax'               => wpinv_round_amount( $tax ),
1057
-            'price'             => wpinv_round_amount( $total ),
1054
+            'discount'          => wpinv_round_amount($discount),
1055
+            'subtotal'          => wpinv_round_amount($subtotal),
1056
+            'tax'               => wpinv_round_amount($tax),
1057
+            'price'             => wpinv_round_amount($total),
1058 1058
             'vat_rates_class'   => $tax_class,
1059 1059
             'vat_rate'          => $tax_rate,
1060
-            'meta'              => isset( $item['meta'] ) ? $item['meta'] : array(),
1060
+            'meta'              => isset($item['meta']) ? $item['meta'] : array(),
1061 1061
             'fees'              => $fees,
1062 1062
         );
1063 1063
         
1064
-        if ( $wpinv_is_last_cart_item ) {
1064
+        if ($wpinv_is_last_cart_item) {
1065 1065
             $wpinv_is_last_cart_item   = false;
1066 1066
             $wpinv_flat_discount_total = 0.00;
1067 1067
         }
@@ -1070,74 +1070,74 @@  discard block
 block discarded – undo
1070 1070
     return $details;
1071 1071
 }
1072 1072
 
1073
-function wpinv_get_cart_details( $invoice_id = 0 ) {
1073
+function wpinv_get_cart_details($invoice_id = 0) {
1074 1074
     global $ajax_cart_details;
1075 1075
 
1076
-    $invoice      = wpinv_get_invoice_cart( $invoice_id );
1076
+    $invoice      = wpinv_get_invoice_cart($invoice_id);
1077 1077
     $cart_details = $ajax_cart_details;
1078
-    if ( empty( $cart_details ) && ! empty( $invoice->cart_details ) ) {
1078
+    if (empty($cart_details) && !empty($invoice->cart_details)) {
1079 1079
         $cart_details = $invoice->cart_details;
1080 1080
     }
1081 1081
 
1082
-    if ( ! empty( $cart_details ) && is_array( $cart_details ) ) {
1083
-        $invoice_currency = ! empty( $invoice->currency ) ? $invoice->currency : wpinv_get_default_country();
1082
+    if (!empty($cart_details) && is_array($cart_details)) {
1083
+        $invoice_currency = !empty($invoice->currency) ? $invoice->currency : wpinv_get_default_country();
1084 1084
 
1085
-        foreach ( $cart_details as $key => $cart_item ) {
1086
-            $cart_details[ $key ]['currency'] = $invoice_currency;
1085
+        foreach ($cart_details as $key => $cart_item) {
1086
+            $cart_details[$key]['currency'] = $invoice_currency;
1087 1087
 
1088
-            if ( ! isset( $cart_item['subtotal'] ) ) {
1089
-                $cart_details[ $key ]['subtotal'] = $cart_item['price'];
1088
+            if (!isset($cart_item['subtotal'])) {
1089
+                $cart_details[$key]['subtotal'] = $cart_item['price'];
1090 1090
             }
1091 1091
         }
1092 1092
     }
1093 1093
 
1094
-    return apply_filters( 'wpinv_get_cart_details', $cart_details, $invoice_id );
1094
+    return apply_filters('wpinv_get_cart_details', $cart_details, $invoice_id);
1095 1095
 }
1096 1096
 
1097
-function wpinv_record_status_change( $invoice_id, $new_status, $old_status ) {
1098
-    if ( 'wpi_invoice' != get_post_type( $invoice_id ) ) {
1097
+function wpinv_record_status_change($invoice_id, $new_status, $old_status) {
1098
+    if ('wpi_invoice' != get_post_type($invoice_id)) {
1099 1099
         return;
1100 1100
     }
1101 1101
 
1102
-    if ( ( $old_status == 'wpi-pending' && $new_status == 'draft' ) || ( $old_status == 'draft' && $new_status == 'wpi-pending' ) ) {
1102
+    if (($old_status == 'wpi-pending' && $new_status == 'draft') || ($old_status == 'draft' && $new_status == 'wpi-pending')) {
1103 1103
         return;
1104 1104
     }
1105 1105
 
1106
-    $invoice    = wpinv_get_invoice( $invoice_id );
1106
+    $invoice = wpinv_get_invoice($invoice_id);
1107 1107
 
1108
-    if ( wpinv_use_taxes() && $new_status == 'publish' ) {
1108
+    if (wpinv_use_taxes() && $new_status == 'publish') {
1109 1109
         
1110
-        if ( WPInv_EUVat::same_country_rule() == 'no' && wpinv_is_base_country( $invoice->country ) ) {
1111
-            $invoice->add_note( __( 'VAT was reverse charged', 'invoicing' ), false, false, true );
1110
+        if (WPInv_EUVat::same_country_rule() == 'no' && wpinv_is_base_country($invoice->country)) {
1111
+            $invoice->add_note(__('VAT was reverse charged', 'invoicing'), false, false, true);
1112 1112
         }
1113 1113
     }
1114 1114
 
1115
-    $old_status = wpinv_status_nicename( $old_status );
1116
-    $new_status = wpinv_status_nicename( $new_status );
1115
+    $old_status = wpinv_status_nicename($old_status);
1116
+    $new_status = wpinv_status_nicename($new_status);
1117 1117
 
1118
-    $status_change = sprintf( __( 'Invoice status changed from %s to %s', 'invoicing' ), $old_status, $new_status );
1118
+    $status_change = sprintf(__('Invoice status changed from %s to %s', 'invoicing'), $old_status, $new_status);
1119 1119
 
1120 1120
     // Add note
1121
-    return $invoice->add_note( $status_change, false, false, true );
1121
+    return $invoice->add_note($status_change, false, false, true);
1122 1122
 }
1123
-add_action( 'wpinv_update_status', 'wpinv_record_status_change', 100, 3 );
1123
+add_action('wpinv_update_status', 'wpinv_record_status_change', 100, 3);
1124 1124
 
1125
-function wpinv_complete_payment( $invoice_id, $new_status, $old_status ) {
1125
+function wpinv_complete_payment($invoice_id, $new_status, $old_status) {
1126 1126
     global $wpi_has_free_trial;
1127 1127
     
1128 1128
     $wpi_has_free_trial = false;
1129 1129
     
1130
-    if ( $old_status == 'publish' ) {
1130
+    if ($old_status == 'publish') {
1131 1131
         return; // Make sure that payments are only paid once
1132 1132
     }
1133 1133
 
1134 1134
     // Make sure the payment completion is only processed when new status is paid
1135
-    if ( $new_status != 'publish' ) {
1135
+    if ($new_status != 'publish') {
1136 1136
         return;
1137 1137
     }
1138 1138
 
1139
-    $invoice = new WPInv_Invoice( $invoice_id );
1140
-    if ( empty( $invoice ) ) {
1139
+    $invoice = new WPInv_Invoice($invoice_id);
1140
+    if (empty($invoice)) {
1141 1141
         return;
1142 1142
     }
1143 1143
 
@@ -1145,58 +1145,58 @@  discard block
 block discarded – undo
1145 1145
     $completed_date = $invoice->completed_date;
1146 1146
     $cart_details   = $invoice->cart_details;
1147 1147
 
1148
-    do_action( 'wpinv_pre_complete_payment', $invoice_id );
1148
+    do_action('wpinv_pre_complete_payment', $invoice_id);
1149 1149
 
1150
-    if ( is_array( $cart_details ) ) {
1150
+    if (is_array($cart_details)) {
1151 1151
         // Increase purchase count and earnings
1152
-        foreach ( $cart_details as $cart_index => $item ) {
1152
+        foreach ($cart_details as $cart_index => $item) {
1153 1153
             // Ensure these actions only run once, ever
1154
-            if ( empty( $completed_date ) ) {
1155
-                do_action( 'wpinv_complete_item_payment', $item['id'], $invoice_id, $item, $cart_index );
1154
+            if (empty($completed_date)) {
1155
+                do_action('wpinv_complete_item_payment', $item['id'], $invoice_id, $item, $cart_index);
1156 1156
             }
1157 1157
         }
1158 1158
     }
1159 1159
     
1160 1160
     // Check for discount codes and increment their use counts
1161
-    if ( $discounts = $invoice->get_discounts( true ) ) {
1162
-        if( ! empty( $discounts ) ) {
1163
-            foreach( $discounts as $code ) {
1164
-                wpinv_increase_discount_usage( $code );
1161
+    if ($discounts = $invoice->get_discounts(true)) {
1162
+        if (!empty($discounts)) {
1163
+            foreach ($discounts as $code) {
1164
+                wpinv_increase_discount_usage($code);
1165 1165
             }
1166 1166
         }
1167 1167
     }
1168 1168
     
1169 1169
     // Ensure this action only runs once ever
1170
-    if( empty( $completed_date ) ) {
1170
+    if (empty($completed_date)) {
1171 1171
         // Save the completed date
1172
-        $invoice->set( 'completed_date', current_time( 'mysql', 0 ) );
1172
+        $invoice->set('completed_date', current_time('mysql', 0));
1173 1173
         $invoice->save();
1174 1174
 
1175
-        do_action( 'wpinv_complete_payment', $invoice_id );
1175
+        do_action('wpinv_complete_payment', $invoice_id);
1176 1176
     }
1177 1177
 
1178 1178
     // Empty the shopping cart
1179 1179
     wpinv_empty_cart();
1180 1180
 }
1181
-add_action( 'wpinv_update_status', 'wpinv_complete_payment', 100, 3 );
1181
+add_action('wpinv_update_status', 'wpinv_complete_payment', 100, 3);
1182 1182
 
1183
-function wpinv_update_payment_status( $invoice_id, $new_status = 'publish' ) {    
1184
-    $invoice = !empty( $invoice_id ) && is_object( $invoice_id ) ? $invoice_id : wpinv_get_invoice( (int)$invoice_id );
1183
+function wpinv_update_payment_status($invoice_id, $new_status = 'publish') {    
1184
+    $invoice = !empty($invoice_id) && is_object($invoice_id) ? $invoice_id : wpinv_get_invoice((int) $invoice_id);
1185 1185
 
1186
-    if ( empty( $invoice ) ) {
1186
+    if (empty($invoice)) {
1187 1187
         return false;
1188 1188
     }
1189 1189
 
1190
-    return $invoice->update_status( $new_status );
1190
+    return $invoice->update_status($new_status);
1191 1191
 }
1192 1192
 
1193
-function wpinv_cart_has_fees( $type = 'all' ) {
1193
+function wpinv_cart_has_fees($type = 'all') {
1194 1194
     return false;
1195 1195
 }
1196 1196
 
1197 1197
 function wpinv_validate_checkout_fields() {
1198 1198
     // Check if there is $_POST
1199
-    if ( empty( $_POST ) ) {
1199
+    if (empty($_POST)) {
1200 1200
         return false;
1201 1201
     }
1202 1202
 
@@ -1219,28 +1219,28 @@  discard block
 block discarded – undo
1219 1219
     
1220 1220
     $invoice = wpinv_get_invoice_cart();
1221 1221
     $has_subscription = $invoice->is_recurring();
1222
-    if ( empty( $invoice ) ) {
1223
-        wpinv_set_error( 'invalid_invoice', __( 'Your cart is empty.', 'invoicing' ) );
1222
+    if (empty($invoice)) {
1223
+        wpinv_set_error('invalid_invoice', __('Your cart is empty.', 'invoicing'));
1224 1224
         return $gateway;
1225 1225
     }
1226 1226
 
1227 1227
     // Check if a gateway value is present
1228
-    if ( !empty( $_REQUEST['wpi-gateway'] ) ) {
1229
-        $gateway = sanitize_text_field( $_REQUEST['wpi-gateway'] );
1228
+    if (!empty($_REQUEST['wpi-gateway'])) {
1229
+        $gateway = sanitize_text_field($_REQUEST['wpi-gateway']);
1230 1230
 
1231
-        if ( $invoice->is_free() ) {
1231
+        if ($invoice->is_free()) {
1232 1232
             $gateway = 'manual';
1233
-        } elseif ( !wpinv_is_gateway_active( $gateway ) ) {
1234
-            wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway is not enabled', 'invoicing' ) );
1235
-        } elseif ( $has_subscription && !wpinv_gateway_support_subscription( $gateway ) ) {
1236
-            if ( apply_filters( 'wpinv_reject_non_recurring_gateway', true ) ) {
1237
-                wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway does not support subscription payment', 'invoicing' ) );
1233
+        } elseif (!wpinv_is_gateway_active($gateway)) {
1234
+            wpinv_set_error('invalid_gateway', __('The selected payment gateway is not enabled', 'invoicing'));
1235
+        } elseif ($has_subscription && !wpinv_gateway_support_subscription($gateway)) {
1236
+            if (apply_filters('wpinv_reject_non_recurring_gateway', true)) {
1237
+                wpinv_set_error('invalid_gateway', __('The selected payment gateway does not support subscription payment', 'invoicing'));
1238 1238
             }
1239 1239
         }
1240 1240
     }
1241 1241
 
1242
-    if ( $has_subscription && count( wpinv_get_cart_contents() ) > 1 ) {
1243
-        wpinv_set_error( 'subscription_invalid', __( 'Only one subscription may be purchased through payment per checkout.', 'invoicing' ) );
1242
+    if ($has_subscription && count(wpinv_get_cart_contents()) > 1) {
1243
+        wpinv_set_error('subscription_invalid', __('Only one subscription may be purchased through payment per checkout.', 'invoicing'));
1244 1244
     }
1245 1245
 
1246 1246
     return $gateway;
@@ -1252,41 +1252,41 @@  discard block
 block discarded – undo
1252 1252
     // Retrieve the discount stored in cookies
1253 1253
     $discounts = wpinv_get_cart_discounts();
1254 1254
 
1255
-    if ( ! is_array( $discounts ) ) {
1255
+    if (!is_array($discounts)) {
1256 1256
         return NULL;
1257 1257
     }
1258 1258
 
1259
-    $discounts = array_filter( $discounts );
1260
-    $error    = false;
1259
+    $discounts = array_filter($discounts);
1260
+    $error = false;
1261 1261
 
1262
-    if ( empty( $discounts ) ) {
1262
+    if (empty($discounts)) {
1263 1263
         return NULL;
1264 1264
     }
1265 1265
 
1266 1266
     // If we have discounts, loop through them
1267
-    foreach ( $discounts as $discount ) {
1267
+    foreach ($discounts as $discount) {
1268 1268
         // Check if valid
1269
-        if (  ! wpinv_is_discount_valid( $discount, (int) $wpi_cart->get_user_id() ) ) {
1269
+        if (!wpinv_is_discount_valid($discount, (int) $wpi_cart->get_user_id())) {
1270 1270
             // Discount is not valid
1271 1271
             $error = true;
1272 1272
         }
1273 1273
 
1274 1274
     }
1275 1275
 
1276
-    if ( $error && ! wpinv_get_errors() ) {
1277
-        wpinv_set_error( 'invalid_discount', __( 'Discount code you entered is invalid', 'invoicing' ) );
1276
+    if ($error && !wpinv_get_errors()) {
1277
+        wpinv_set_error('invalid_discount', __('Discount code you entered is invalid', 'invoicing'));
1278 1278
     }
1279 1279
 
1280
-    return implode( ',', $discounts );
1280
+    return implode(',', $discounts);
1281 1281
 }
1282 1282
 
1283 1283
 function wpinv_checkout_validate_cc() {
1284 1284
     $card_data = wpinv_checkout_get_cc_info();
1285 1285
 
1286 1286
     // Validate the card zip
1287
-    if ( !empty( $card_data['wpinv_zip'] ) ) {
1288
-        if ( !wpinv_checkout_validate_cc_zip( $card_data['wpinv_zip'], $card_data['wpinv_country'] ) ) {
1289
-            wpinv_set_error( 'invalid_cc_zip', __( 'The zip / postcode you entered for your billing address is invalid', 'invoicing' ) );
1287
+    if (!empty($card_data['wpinv_zip'])) {
1288
+        if (!wpinv_checkout_validate_cc_zip($card_data['wpinv_zip'], $card_data['wpinv_country'])) {
1289
+            wpinv_set_error('invalid_cc_zip', __('The zip / postcode you entered for your billing address is invalid', 'invoicing'));
1290 1290
         }
1291 1291
     }
1292 1292
 
@@ -1296,28 +1296,28 @@  discard block
 block discarded – undo
1296 1296
 
1297 1297
 function wpinv_checkout_get_cc_info() {
1298 1298
 	$cc_info = array();
1299
-	$cc_info['card_name']      = isset( $_POST['card_name'] )       ? sanitize_text_field( $_POST['card_name'] )       : '';
1300
-	$cc_info['card_number']    = isset( $_POST['card_number'] )     ? sanitize_text_field( $_POST['card_number'] )     : '';
1301
-	$cc_info['card_cvc']       = isset( $_POST['card_cvc'] )        ? sanitize_text_field( $_POST['card_cvc'] )        : '';
1302
-	$cc_info['card_exp_month'] = isset( $_POST['card_exp_month'] )  ? sanitize_text_field( $_POST['card_exp_month'] )  : '';
1303
-	$cc_info['card_exp_year']  = isset( $_POST['card_exp_year'] )   ? sanitize_text_field( $_POST['card_exp_year'] )   : '';
1304
-	$cc_info['card_address']   = isset( $_POST['wpinv_address'] )  ? sanitize_text_field( $_POST['wpinv_address'] ) : '';
1305
-	$cc_info['card_city']      = isset( $_POST['wpinv_city'] )     ? sanitize_text_field( $_POST['wpinv_city'] )    : '';
1306
-	$cc_info['card_state']     = isset( $_POST['wpinv_state'] )    ? sanitize_text_field( $_POST['wpinv_state'] )   : '';
1307
-	$cc_info['card_country']   = isset( $_POST['wpinv_country'] )  ? sanitize_text_field( $_POST['wpinv_country'] ) : '';
1308
-	$cc_info['card_zip']       = isset( $_POST['wpinv_zip'] )      ? sanitize_text_field( $_POST['wpinv_zip'] )     : '';
1299
+	$cc_info['card_name']      = isset($_POST['card_name']) ? sanitize_text_field($_POST['card_name']) : '';
1300
+	$cc_info['card_number']    = isset($_POST['card_number']) ? sanitize_text_field($_POST['card_number']) : '';
1301
+	$cc_info['card_cvc']       = isset($_POST['card_cvc']) ? sanitize_text_field($_POST['card_cvc']) : '';
1302
+	$cc_info['card_exp_month'] = isset($_POST['card_exp_month']) ? sanitize_text_field($_POST['card_exp_month']) : '';
1303
+	$cc_info['card_exp_year']  = isset($_POST['card_exp_year']) ? sanitize_text_field($_POST['card_exp_year']) : '';
1304
+	$cc_info['card_address']   = isset($_POST['wpinv_address']) ? sanitize_text_field($_POST['wpinv_address']) : '';
1305
+	$cc_info['card_city']      = isset($_POST['wpinv_city']) ? sanitize_text_field($_POST['wpinv_city']) : '';
1306
+	$cc_info['card_state']     = isset($_POST['wpinv_state']) ? sanitize_text_field($_POST['wpinv_state']) : '';
1307
+	$cc_info['card_country']   = isset($_POST['wpinv_country']) ? sanitize_text_field($_POST['wpinv_country']) : '';
1308
+	$cc_info['card_zip']       = isset($_POST['wpinv_zip']) ? sanitize_text_field($_POST['wpinv_zip']) : '';
1309 1309
 
1310 1310
 	// Return cc info
1311 1311
 	return $cc_info;
1312 1312
 }
1313 1313
 
1314
-function wpinv_checkout_validate_cc_zip( $zip = 0, $country_code = '' ) {
1314
+function wpinv_checkout_validate_cc_zip($zip = 0, $country_code = '') {
1315 1315
     $ret = false;
1316 1316
 
1317
-    if ( empty( $zip ) || empty( $country_code ) )
1317
+    if (empty($zip) || empty($country_code))
1318 1318
         return $ret;
1319 1319
 
1320
-    $country_code = strtoupper( $country_code );
1320
+    $country_code = strtoupper($country_code);
1321 1321
 
1322 1322
     $zip_regex = array(
1323 1323
         "AD" => "AD\d{3}",
@@ -1477,72 +1477,72 @@  discard block
 block discarded – undo
1477 1477
         "ZM" => "\d{5}"
1478 1478
     );
1479 1479
 
1480
-    if ( ! isset ( $zip_regex[ $country_code ] ) || preg_match( "/" . $zip_regex[ $country_code ] . "/i", $zip ) )
1480
+    if (!isset ($zip_regex[$country_code]) || preg_match("/" . $zip_regex[$country_code] . "/i", $zip))
1481 1481
         $ret = true;
1482 1482
 
1483
-    return apply_filters( 'wpinv_is_zip_valid', $ret, $zip, $country_code );
1483
+    return apply_filters('wpinv_is_zip_valid', $ret, $zip, $country_code);
1484 1484
 }
1485 1485
 
1486 1486
 function wpinv_checkout_validate_agree_to_terms() {
1487 1487
     // Validate agree to terms
1488
-    if ( ! isset( $_POST['wpi_agree_to_terms'] ) || $_POST['wpi_agree_to_terms'] != 1 ) {
1488
+    if (!isset($_POST['wpi_agree_to_terms']) || $_POST['wpi_agree_to_terms'] != 1) {
1489 1489
         // User did not agree
1490
-        wpinv_set_error( 'agree_to_terms', apply_filters( 'wpinv_agree_to_terms_text', __( 'You must agree to the terms of use', 'invoicing' ) ) );
1490
+        wpinv_set_error('agree_to_terms', apply_filters('wpinv_agree_to_terms_text', __('You must agree to the terms of use', 'invoicing')));
1491 1491
     }
1492 1492
 }
1493 1493
 
1494 1494
 function wpinv_checkout_validate_invoice_user() {
1495 1495
     global $wpi_cart, $user_ID;
1496 1496
 
1497
-    if(empty($wpi_cart)){
1497
+    if (empty($wpi_cart)) {
1498 1498
         $wpi_cart = wpinv_get_invoice_cart();
1499 1499
     }
1500 1500
 
1501
-    $invoice_user = (int)$wpi_cart->get_user_id();
1501
+    $invoice_user = (int) $wpi_cart->get_user_id();
1502 1502
     $valid_user_data = array(
1503 1503
         'user_id' => $invoice_user
1504 1504
     );
1505 1505
 
1506 1506
     // If guest checkout allowed
1507
-    if ( !wpinv_require_login_to_checkout() ) {
1507
+    if (!wpinv_require_login_to_checkout()) {
1508 1508
         return $valid_user_data;
1509 1509
     }
1510 1510
     
1511 1511
     // Verify there is a user_ID
1512
-    if ( $user_ID == $invoice_user ) {
1512
+    if ($user_ID == $invoice_user) {
1513 1513
         // Get the logged in user data
1514
-        $user_data = get_userdata( $user_ID );
1515
-        $required_fields  = wpinv_checkout_required_fields();
1514
+        $user_data = get_userdata($user_ID);
1515
+        $required_fields = wpinv_checkout_required_fields();
1516 1516
 
1517 1517
         // Loop through required fields and show error messages
1518
-         if ( !empty( $required_fields ) ) {
1519
-            foreach ( $required_fields as $field_name => $value ) {
1520
-                if ( in_array( $value, $required_fields ) && empty( $_POST[ 'wpinv_' . $field_name ] ) ) {
1521
-                    wpinv_set_error( $value['error_id'], $value['error_message'] );
1518
+         if (!empty($required_fields)) {
1519
+            foreach ($required_fields as $field_name => $value) {
1520
+                if (in_array($value, $required_fields) && empty($_POST['wpinv_' . $field_name])) {
1521
+                    wpinv_set_error($value['error_id'], $value['error_message']);
1522 1522
                 }
1523 1523
             }
1524 1524
         }
1525 1525
 
1526 1526
         // Verify data
1527
-        if ( $user_data ) {
1527
+        if ($user_data) {
1528 1528
             // Collected logged in user data
1529 1529
             $valid_user_data = array(
1530 1530
                 'user_id'     => $user_ID,
1531
-                'email'       => isset( $_POST['wpinv_email'] ) ? sanitize_email( $_POST['wpinv_email'] ) : $user_data->user_email,
1532
-                'first_name'  => isset( $_POST['wpinv_first_name'] ) && ! empty( $_POST['wpinv_first_name'] ) ? sanitize_text_field( $_POST['wpinv_first_name'] ) : $user_data->first_name,
1533
-                'last_name'   => isset( $_POST['wpinv_last_name'] ) && ! empty( $_POST['wpinv_last_name']  ) ? sanitize_text_field( $_POST['wpinv_last_name']  ) : $user_data->last_name,
1531
+                'email'       => isset($_POST['wpinv_email']) ? sanitize_email($_POST['wpinv_email']) : $user_data->user_email,
1532
+                'first_name'  => isset($_POST['wpinv_first_name']) && !empty($_POST['wpinv_first_name']) ? sanitize_text_field($_POST['wpinv_first_name']) : $user_data->first_name,
1533
+                'last_name'   => isset($_POST['wpinv_last_name']) && !empty($_POST['wpinv_last_name']) ? sanitize_text_field($_POST['wpinv_last_name']) : $user_data->last_name,
1534 1534
             );
1535 1535
 
1536
-            if ( !empty( $_POST[ 'wpinv_email' ] ) && !is_email( $_POST[ 'wpinv_email' ] ) ) {
1537
-                wpinv_set_error( 'invalid_email', __( 'Please enter a valid email address', 'invoicing' ) );
1536
+            if (!empty($_POST['wpinv_email']) && !is_email($_POST['wpinv_email'])) {
1537
+                wpinv_set_error('invalid_email', __('Please enter a valid email address', 'invoicing'));
1538 1538
             }
1539 1539
         } else {
1540 1540
             // Set invalid user error
1541
-            wpinv_set_error( 'invalid_user', __( 'The user billing information is invalid', 'invoicing' ) );
1541
+            wpinv_set_error('invalid_user', __('The user billing information is invalid', 'invoicing'));
1542 1542
         }
1543 1543
     } else {
1544 1544
         // Set invalid user error
1545
-        wpinv_set_error( 'invalid_user_id', __( 'The invalid invoice user id', 'invoicing' ) );
1545
+        wpinv_set_error('invalid_user_id', __('The invalid invoice user id', 'invoicing'));
1546 1546
     }
1547 1547
 
1548 1548
     // Return user data
@@ -1554,27 +1554,27 @@  discard block
 block discarded – undo
1554 1554
 
1555 1555
     $data = array();
1556 1556
     
1557
-    if ( is_user_logged_in() ) {
1558
-        if ( !wpinv_require_login_to_checkout() || ( wpinv_require_login_to_checkout() && (int)$wpi_cart->get_user_id() === (int)get_current_user_id() ) ) {
1559
-            $data['user_id'] = (int)get_current_user_id();
1557
+    if (is_user_logged_in()) {
1558
+        if (!wpinv_require_login_to_checkout() || (wpinv_require_login_to_checkout() && (int) $wpi_cart->get_user_id() === (int) get_current_user_id())) {
1559
+            $data['user_id'] = (int) get_current_user_id();
1560 1560
         } else {
1561
-            wpinv_set_error( 'logged_in_only', __( 'You are not allowed to pay for this invoice', 'invoicing' ) );
1561
+            wpinv_set_error('logged_in_only', __('You are not allowed to pay for this invoice', 'invoicing'));
1562 1562
         }
1563 1563
     } else {
1564 1564
         // If guest checkout allowed
1565
-        if ( !wpinv_require_login_to_checkout() ) {
1565
+        if (!wpinv_require_login_to_checkout()) {
1566 1566
             $data['user_id'] = 0;
1567 1567
         } else {
1568
-            wpinv_set_error( 'logged_in_only', __( 'You must be logged in to pay for this invoice', 'invoicing' ) );
1568
+            wpinv_set_error('logged_in_only', __('You must be logged in to pay for this invoice', 'invoicing'));
1569 1569
         }
1570 1570
     }
1571 1571
 
1572 1572
     return $data;
1573 1573
 }
1574 1574
 
1575
-function wpinv_checkout_form_get_user( $valid_data = array() ) {
1575
+function wpinv_checkout_form_get_user($valid_data = array()) {
1576 1576
 
1577
-    if ( !empty( $valid_data['current_user']['user_id'] ) ) {
1577
+    if (!empty($valid_data['current_user']['user_id'])) {
1578 1578
         $user = $valid_data['current_user'];
1579 1579
     } else {
1580 1580
         // Set the valid invoice user
@@ -1582,7 +1582,7 @@  discard block
 block discarded – undo
1582 1582
     }
1583 1583
 
1584 1584
     // Verify invoice have an user
1585
-    if ( false === $user || empty( $user ) ) {
1585
+    if (false === $user || empty($user)) {
1586 1586
         return false;
1587 1587
     }
1588 1588
 
@@ -1599,11 +1599,11 @@  discard block
 block discarded – undo
1599 1599
         'zip',
1600 1600
     );
1601 1601
     
1602
-    foreach ( $address_fields as $field ) {
1603
-        $user[$field]  = !empty( $_POST['wpinv_' . $field] ) ? sanitize_text_field( $_POST['wpinv_' . $field] ) : false;
1602
+    foreach ($address_fields as $field) {
1603
+        $user[$field] = !empty($_POST['wpinv_' . $field]) ? sanitize_text_field($_POST['wpinv_' . $field]) : false;
1604 1604
         
1605
-        if ( !empty( $user['user_id'] ) && !empty( $valid_data['current_user']['user_id'] ) && $valid_data['current_user']['user_id'] == $valid_data['invoice_user']['user_id'] ) {
1606
-            update_user_meta( $user['user_id'], '_wpinv_' . $field, $user[$field] );
1605
+        if (!empty($user['user_id']) && !empty($valid_data['current_user']['user_id']) && $valid_data['current_user']['user_id'] == $valid_data['invoice_user']['user_id']) {
1606
+            update_user_meta($user['user_id'], '_wpinv_' . $field, $user[$field]);
1607 1607
         }
1608 1608
     }
1609 1609
 
@@ -1611,26 +1611,26 @@  discard block
 block discarded – undo
1611 1611
     return $user;
1612 1612
 }
1613 1613
 
1614
-function wpinv_set_checkout_session( $invoice_data = array() ) {
1614
+function wpinv_set_checkout_session($invoice_data = array()) {
1615 1615
     global $wpi_session;
1616
-    return $wpi_session->set( 'wpinv_checkout', $invoice_data );
1616
+    return $wpi_session->set('wpinv_checkout', $invoice_data);
1617 1617
 }
1618 1618
 
1619 1619
 function wpinv_get_checkout_session() {
1620 1620
 	global $wpi_session;
1621
-    return $wpi_session->get( 'wpinv_checkout' );
1621
+    return $wpi_session->get('wpinv_checkout');
1622 1622
 }
1623 1623
 
1624 1624
 function wpinv_empty_cart() {
1625 1625
     global $wpi_session;
1626 1626
 
1627 1627
     // Remove cart contents
1628
-    $wpi_session->set( 'wpinv_checkout', NULL );
1628
+    $wpi_session->set('wpinv_checkout', NULL);
1629 1629
 
1630 1630
     // Remove all cart fees
1631
-    $wpi_session->set( 'wpi_cart_fees', NULL );
1631
+    $wpi_session->set('wpi_cart_fees', NULL);
1632 1632
 
1633
-    do_action( 'wpinv_empty_cart' );
1633
+    do_action('wpinv_empty_cart');
1634 1634
 }
1635 1635
 
1636 1636
 function wpinv_process_checkout() {
@@ -1639,7 +1639,7 @@  discard block
 block discarded – undo
1639 1639
     wpinv_clear_errors();
1640 1640
 
1641 1641
     $invoice = wpinv_get_invoice_cart();
1642
-    if ( empty( $invoice ) ) {
1642
+    if (empty($invoice)) {
1643 1643
         return false;
1644 1644
     }
1645 1645
 
@@ -1647,42 +1647,42 @@  discard block
 block discarded – undo
1647 1647
 
1648 1648
     $wpi_checkout_id = $invoice->ID;
1649 1649
 
1650
-    do_action( 'wpinv_pre_process_checkout' );
1650
+    do_action('wpinv_pre_process_checkout');
1651 1651
     
1652
-    if ( !wpinv_get_cart_contents() ) { // Make sure the cart isn't empty
1652
+    if (!wpinv_get_cart_contents()) { // Make sure the cart isn't empty
1653 1653
         $valid_data = false;
1654
-        wpinv_set_error( 'empty_cart', __( 'Your cart is empty', 'invoicing' ) );
1654
+        wpinv_set_error('empty_cart', __('Your cart is empty', 'invoicing'));
1655 1655
     } else {
1656 1656
         // Validate the form $_POST data
1657 1657
         $valid_data = wpinv_validate_checkout_fields();
1658 1658
         
1659 1659
         // Allow themes and plugins to hook to errors
1660
-        do_action( 'wpinv_checkout_error_checks', $valid_data, $_POST );
1660
+        do_action('wpinv_checkout_error_checks', $valid_data, $_POST);
1661 1661
     }
1662 1662
     
1663
-    $is_ajax    = defined( 'DOING_AJAX' ) && DOING_AJAX;
1663
+    $is_ajax = defined('DOING_AJAX') && DOING_AJAX;
1664 1664
     
1665 1665
     // Validate the user
1666
-    $user = wpinv_checkout_form_get_user( $valid_data );
1666
+    $user = wpinv_checkout_form_get_user($valid_data);
1667 1667
 
1668 1668
     // Let extensions validate fields after user is logged in if user has used login/registration form
1669
-    do_action( 'wpinv_checkout_user_error_checks', $user, $valid_data, $_POST );
1669
+    do_action('wpinv_checkout_user_error_checks', $user, $valid_data, $_POST);
1670 1670
     
1671
-    if ( false === $valid_data || wpinv_get_errors() || ! $user ) {
1672
-        if ( $is_ajax && 'wpinv_payment_form' != $_REQUEST['action'] ) {
1673
-            do_action( 'wpinv_ajax_checkout_errors' );
1671
+    if (false === $valid_data || wpinv_get_errors() || !$user) {
1672
+        if ($is_ajax && 'wpinv_payment_form' != $_REQUEST['action']) {
1673
+            do_action('wpinv_ajax_checkout_errors');
1674 1674
             die();
1675 1675
         } else {
1676 1676
             return false;
1677 1677
         }
1678 1678
     }
1679 1679
 
1680
-    if ( $is_ajax && 'wpinv_payment_form' != $_REQUEST['action'] ) {
1680
+    if ($is_ajax && 'wpinv_payment_form' != $_REQUEST['action']) {
1681 1681
         // Save address fields.
1682
-        $address_fields = array( 'first_name', 'last_name', 'phone', 'address', 'city', 'country', 'state', 'zip', 'company' );
1683
-        foreach ( $address_fields as $field ) {
1684
-            if ( isset( $user[$field] ) ) {
1685
-                $invoice->set( $field, $user[$field] );
1682
+        $address_fields = array('first_name', 'last_name', 'phone', 'address', 'city', 'country', 'state', 'zip', 'company');
1683
+        foreach ($address_fields as $field) {
1684
+            if (isset($user[$field])) {
1685
+                $invoice->set($field, $user[$field]);
1686 1686
             }
1687 1687
 
1688 1688
             $invoice->save();
@@ -1690,16 +1690,16 @@  discard block
 block discarded – undo
1690 1690
 
1691 1691
         $response['success']            = true;
1692 1692
         $response['data']['subtotal']   = $invoice->get_subtotal();
1693
-        $response['data']['subtotalf']  = $invoice->get_subtotal( true );
1693
+        $response['data']['subtotalf']  = $invoice->get_subtotal(true);
1694 1694
         $response['data']['discount']   = $invoice->get_discount();
1695
-        $response['data']['discountf']  = $invoice->get_discount( true );
1695
+        $response['data']['discountf']  = $invoice->get_discount(true);
1696 1696
         $response['data']['tax']        = $invoice->get_tax();
1697
-        $response['data']['taxf']       = $invoice->get_tax( true );
1697
+        $response['data']['taxf']       = $invoice->get_tax(true);
1698 1698
         $response['data']['total']      = $invoice->get_total();
1699
-        $response['data']['totalf']     = $invoice->get_total( true );
1700
-	    $response['data']['free']       = $invoice->is_free() && ( ! ( (float) $response['data']['total'] > 0 ) || $invoice->is_free_trial() ) ? true : false;
1699
+        $response['data']['totalf']     = $invoice->get_total(true);
1700
+	    $response['data']['free'] = $invoice->is_free() && (!((float) $response['data']['total'] > 0) || $invoice->is_free_trial()) ? true : false;
1701 1701
 
1702
-        wp_send_json( $response );
1702
+        wp_send_json($response);
1703 1703
     }
1704 1704
     
1705 1705
     $user_info = array(
@@ -1721,42 +1721,42 @@  discard block
 block discarded – undo
1721 1721
     
1722 1722
     // Setup invoice information
1723 1723
     $invoice_data = array(
1724
-        'invoice_id'        => !empty( $invoice ) ? $invoice->ID : 0,
1724
+        'invoice_id'        => !empty($invoice) ? $invoice->ID : 0,
1725 1725
         'items'             => $cart_items,
1726 1726
         'cart_discounts'    => $discounts,
1727
-        'fees'              => wpinv_get_cart_fees(),        // Any arbitrary fees that have been added to the cart
1728
-        'subtotal'          => wpinv_get_cart_subtotal( $cart_items ),    // Amount before taxes and discounts
1729
-        'discount'          => wpinv_get_cart_items_discount_amount( $cart_items, $discounts ), // Discounted amount
1730
-        'tax'               => wpinv_get_cart_tax( $cart_items, $invoice ),               // Taxed amount
1731
-        'price'             => wpinv_get_cart_total( $cart_items, $discounts ),    // Amount after taxes
1727
+        'fees'              => wpinv_get_cart_fees(), // Any arbitrary fees that have been added to the cart
1728
+        'subtotal'          => wpinv_get_cart_subtotal($cart_items), // Amount before taxes and discounts
1729
+        'discount'          => wpinv_get_cart_items_discount_amount($cart_items, $discounts), // Discounted amount
1730
+        'tax'               => wpinv_get_cart_tax($cart_items, $invoice), // Taxed amount
1731
+        'price'             => wpinv_get_cart_total($cart_items, $discounts), // Amount after taxes
1732 1732
         'invoice_key'       => $invoice->get_key() ? $invoice->get_key() : $invoice->generate_key(),
1733 1733
         'user_email'        => $invoice->get_email(),
1734
-        'date'              => date( 'Y-m-d H:i:s', current_time( 'timestamp' ) ),
1735
-        'user_info'         => stripslashes_deep( $user_info ),
1734
+        'date'              => date('Y-m-d H:i:s', current_time('timestamp')),
1735
+        'user_info'         => stripslashes_deep($user_info),
1736 1736
         'post_data'         => $_POST,
1737 1737
         'cart_details'      => $cart_items,
1738 1738
         'gateway'           => $valid_data['gateway'],
1739 1739
         'card_info'         => $valid_data['cc_info']
1740 1740
     );
1741 1741
     
1742
-    $vat_info   = $wpinv_euvat->current_vat_data();
1743
-    if ( is_array( $vat_info ) ) {
1742
+    $vat_info = $wpinv_euvat->current_vat_data();
1743
+    if (is_array($vat_info)) {
1744 1744
         $invoice_data['user_info']['vat_number']        = $vat_info['number'];
1745 1745
         $invoice_data['user_info']['vat_rate']          = wpinv_get_tax_rate($invoice_data['user_info']['country'], $invoice_data['user_info']['state']);
1746
-        $invoice_data['user_info']['adddress_confirmed']    = isset($vat_info['adddress_confirmed']) ? $vat_info['adddress_confirmed'] : false;
1746
+        $invoice_data['user_info']['adddress_confirmed'] = isset($vat_info['adddress_confirmed']) ? $vat_info['adddress_confirmed'] : false;
1747 1747
 
1748 1748
         // Add the VAT rate to each item in the cart
1749
-        foreach( $invoice_data['cart_details'] as $key => $item_data) {
1749
+        foreach ($invoice_data['cart_details'] as $key => $item_data) {
1750 1750
             $rate = wpinv_get_tax_rate($invoice_data['user_info']['country'], $invoice_data['user_info']['state'], $item_data['id']);
1751
-            $invoice_data['cart_details'][$key]['vat_rate'] = wpinv_round_amount( $rate, 4 );
1751
+            $invoice_data['cart_details'][$key]['vat_rate'] = wpinv_round_amount($rate, 4);
1752 1752
         }
1753 1753
     }
1754 1754
     
1755 1755
     // Save vat fields.
1756
-    $address_fields = array( 'vat_number', 'vat_rate', 'adddress_confirmed' );
1757
-    foreach ( $address_fields as $field ) {
1758
-        if ( isset( $invoice_data['user_info'][$field] ) ) {
1759
-            $invoice->set( $field, $invoice_data['user_info'][$field] );
1756
+    $address_fields = array('vat_number', 'vat_rate', 'adddress_confirmed');
1757
+    foreach ($address_fields as $field) {
1758
+        if (isset($invoice_data['user_info'][$field])) {
1759
+            $invoice->set($field, $invoice_data['user_info'][$field]);
1760 1760
         }
1761 1761
     }
1762 1762
     $invoice->save();
@@ -1765,54 +1765,54 @@  discard block
 block discarded – undo
1765 1765
     $valid_data['user'] = $user;
1766 1766
     
1767 1767
     // Allow themes and plugins to hook before the gateway
1768
-    do_action( 'wpinv_checkout_before_gateway', $_POST, $user_info, $valid_data );
1768
+    do_action('wpinv_checkout_before_gateway', $_POST, $user_info, $valid_data);
1769 1769
 
1770 1770
      // If it is free, abort.
1771
-     if ( $invoice->is_free() && ( ! $invoice->is_recurring() || 0 ==  $invoice->get_recurring_details( 'total' ) ) ) {
1771
+     if ($invoice->is_free() && (!$invoice->is_recurring() || 0 == $invoice->get_recurring_details('total'))) {
1772 1772
         $invoice_data['gateway'] = 'manual';
1773 1773
         $_POST['wpi-gateway'] = 'manual';
1774 1774
     }
1775 1775
 
1776 1776
     // Allow the invoice data to be modified before it is sent to the gateway
1777
-    $invoice_data = apply_filters( 'wpinv_data_before_gateway', $invoice_data, $valid_data );
1777
+    $invoice_data = apply_filters('wpinv_data_before_gateway', $invoice_data, $valid_data);
1778 1778
     
1779
-    if ( $invoice_data['price'] && $invoice_data['gateway'] == 'manual' ) {
1779
+    if ($invoice_data['price'] && $invoice_data['gateway'] == 'manual') {
1780 1780
         $mode = 'test';
1781 1781
     } else {
1782
-        $mode = wpinv_is_test_mode( $invoice_data['gateway'] ) ? 'test' : 'live';
1782
+        $mode = wpinv_is_test_mode($invoice_data['gateway']) ? 'test' : 'live';
1783 1783
     }
1784 1784
 
1785 1785
     // Setup the data we're storing in the purchase session
1786 1786
     $session_data = $invoice_data;
1787 1787
     // Make sure credit card numbers are never stored in sessions
1788
-    if ( !empty( $session_data['card_info']['card_number'] ) ) {
1789
-        unset( $session_data['card_info']['card_number'] );
1788
+    if (!empty($session_data['card_info']['card_number'])) {
1789
+        unset($session_data['card_info']['card_number']);
1790 1790
     }
1791 1791
     
1792 1792
     // Used for showing item links to non logged-in users after purchase, and for other plugins needing purchase data.
1793
-    wpinv_set_checkout_session( $invoice_data );
1793
+    wpinv_set_checkout_session($invoice_data);
1794 1794
     
1795 1795
     // Set gateway
1796
-    $invoice->update_meta( '_wpinv_gateway', $invoice_data['gateway'] );
1797
-    $invoice->update_meta( '_wpinv_mode', $mode );
1798
-    $invoice->update_meta( '_wpinv_checkout', date_i18n( 'Y-m-d H:i:s', current_time( 'timestamp' ) ) );
1796
+    $invoice->update_meta('_wpinv_gateway', $invoice_data['gateway']);
1797
+    $invoice->update_meta('_wpinv_mode', $mode);
1798
+    $invoice->update_meta('_wpinv_checkout', date_i18n('Y-m-d H:i:s', current_time('timestamp')));
1799 1799
     
1800
-    do_action( 'wpinv_checkout_before_send_to_gateway', $invoice, $invoice_data );
1800
+    do_action('wpinv_checkout_before_send_to_gateway', $invoice, $invoice_data);
1801 1801
 
1802 1802
     // Send info to the gateway for payment processing
1803
-    wpinv_send_to_gateway( $invoice_data['gateway'], $invoice_data );
1803
+    wpinv_send_to_gateway($invoice_data['gateway'], $invoice_data);
1804 1804
     die();
1805 1805
 }
1806
-add_action( 'wpinv_payment', 'wpinv_process_checkout' );
1806
+add_action('wpinv_payment', 'wpinv_process_checkout');
1807 1807
 
1808
-function wpinv_get_invoices( $args ) {
1809
-    $args = wp_parse_args( $args, array(
1810
-        'status'   => array_keys( wpinv_get_invoice_statuses() ),
1808
+function wpinv_get_invoices($args) {
1809
+    $args = wp_parse_args($args, array(
1810
+        'status'   => array_keys(wpinv_get_invoice_statuses()),
1811 1811
         'type'     => 'wpi_invoice',
1812 1812
         'parent'   => null,
1813 1813
         'user'     => null,
1814 1814
         'email'    => '',
1815
-        'limit'    => get_option( 'posts_per_page' ),
1815
+        'limit'    => get_option('posts_per_page'),
1816 1816
         'offset'   => null,
1817 1817
         'page'     => 1,
1818 1818
         'exclude'  => array(),
@@ -1820,7 +1820,7 @@  discard block
 block discarded – undo
1820 1820
         'order'    => 'DESC',
1821 1821
         'return'   => 'objects',
1822 1822
         'paginate' => false,
1823
-    ) );
1823
+    ));
1824 1824
     
1825 1825
     // Handle some BW compatibility arg names where wp_query args differ in naming.
1826 1826
     $map_legacy = array(
@@ -1833,18 +1833,18 @@  discard block
 block discarded – undo
1833 1833
         'paged'          => 'page',
1834 1834
     );
1835 1835
 
1836
-    foreach ( $map_legacy as $from => $to ) {
1837
-        if ( isset( $args[ $from ] ) ) {
1838
-            $args[ $to ] = $args[ $from ];
1836
+    foreach ($map_legacy as $from => $to) {
1837
+        if (isset($args[$from])) {
1838
+            $args[$to] = $args[$from];
1839 1839
         }
1840 1840
     }
1841 1841
 
1842
-    if ( get_query_var( 'paged' ) )
1842
+    if (get_query_var('paged'))
1843 1843
         $args['page'] = get_query_var('paged');
1844
-    else if ( get_query_var( 'page' ) )
1845
-        $args['page'] = get_query_var( 'page' );
1846
-    else if ( !empty( $args[ 'page' ] ) )
1847
-        $args['page'] = $args[ 'page' ];
1844
+    else if (get_query_var('page'))
1845
+        $args['page'] = get_query_var('page');
1846
+    else if (!empty($args['page']))
1847
+        $args['page'] = $args['page'];
1848 1848
     else
1849 1849
         $args['page'] = 1;
1850 1850
 
@@ -1857,48 +1857,48 @@  discard block
 block discarded – undo
1857 1857
         'post_status'    => $args['status'],
1858 1858
         'posts_per_page' => $args['limit'],
1859 1859
         'meta_query'     => array(),
1860
-        'date_query'     => !empty( $args['date_query'] ) ? $args['date_query'] : array(),
1860
+        'date_query'     => !empty($args['date_query']) ? $args['date_query'] : array(),
1861 1861
         'fields'         => 'ids',
1862 1862
         'orderby'        => $args['orderby'],
1863 1863
         'order'          => $args['order'],
1864 1864
     );
1865 1865
     
1866
-    if ( !empty( $args['user'] ) ) {
1867
-        $wp_query_args['author'] = absint( $args['user'] );
1866
+    if (!empty($args['user'])) {
1867
+        $wp_query_args['author'] = absint($args['user']);
1868 1868
     }
1869 1869
 
1870
-    if ( ! is_null( $args['parent'] ) ) {
1871
-        $wp_query_args['post_parent'] = absint( $args['parent'] );
1870
+    if (!is_null($args['parent'])) {
1871
+        $wp_query_args['post_parent'] = absint($args['parent']);
1872 1872
     }
1873 1873
 
1874
-    if ( ! is_null( $args['offset'] ) ) {
1875
-        $wp_query_args['offset'] = absint( $args['offset'] );
1874
+    if (!is_null($args['offset'])) {
1875
+        $wp_query_args['offset'] = absint($args['offset']);
1876 1876
     } else {
1877
-        $wp_query_args['paged'] = absint( $args['page'] );
1877
+        $wp_query_args['paged'] = absint($args['page']);
1878 1878
     }
1879 1879
 
1880
-    if ( ! empty( $args['exclude'] ) ) {
1881
-        $wp_query_args['post__not_in'] = array_map( 'absint', $args['exclude'] );
1880
+    if (!empty($args['exclude'])) {
1881
+        $wp_query_args['post__not_in'] = array_map('absint', $args['exclude']);
1882 1882
     }
1883 1883
 
1884
-    if ( ! $args['paginate' ] ) {
1884
+    if (!$args['paginate']) {
1885 1885
         $wp_query_args['no_found_rows'] = true;
1886 1886
     }
1887 1887
 
1888 1888
     $wp_query_args = apply_filters('wpinv_get_invoices_args', $wp_query_args, $args);
1889 1889
 
1890 1890
     // Get results.
1891
-    $invoices = new WP_Query( $wp_query_args );
1891
+    $invoices = new WP_Query($wp_query_args);
1892 1892
 
1893
-    if ( 'objects' === $args['return'] ) {
1894
-        $return = array_map( 'wpinv_get_invoice', $invoices->posts );
1895
-    } elseif ( 'self' === $args['return'] ) {
1893
+    if ('objects' === $args['return']) {
1894
+        $return = array_map('wpinv_get_invoice', $invoices->posts);
1895
+    } elseif ('self' === $args['return']) {
1896 1896
         return $invoices;
1897 1897
     } else {
1898 1898
         $return = $invoices->posts;
1899 1899
     }
1900 1900
 
1901
-    if ( $args['paginate' ] ) {
1901
+    if ($args['paginate']) {
1902 1902
         return (object) array(
1903 1903
             'invoices'      => $return,
1904 1904
             'total'         => $invoices->found_posts,
@@ -1911,22 +1911,22 @@  discard block
 block discarded – undo
1911 1911
 
1912 1912
 function wpinv_get_user_invoices_columns() {
1913 1913
     $columns = array(
1914
-            'invoice-number'  => array( 'title' => __( 'ID', 'invoicing' ), 'class' => 'text-left' ),
1915
-            'created-date'    => array( 'title' => __( 'Created Date', 'invoicing' ), 'class' => 'text-left' ),
1916
-            'payment-date'    => array( 'title' => __( 'Payment Date', 'invoicing' ), 'class' => 'text-left' ),
1917
-            'invoice-status'  => array( 'title' => __( 'Status', 'invoicing' ), 'class' => 'text-center' ),
1918
-            'invoice-total'   => array( 'title' => __( 'Total', 'invoicing' ), 'class' => 'text-right' ),
1919
-            'invoice-actions' => array( 'title' => '&nbsp;', 'class' => 'text-center' ),
1914
+            'invoice-number'  => array('title' => __('ID', 'invoicing'), 'class' => 'text-left'),
1915
+            'created-date'    => array('title' => __('Created Date', 'invoicing'), 'class' => 'text-left'),
1916
+            'payment-date'    => array('title' => __('Payment Date', 'invoicing'), 'class' => 'text-left'),
1917
+            'invoice-status'  => array('title' => __('Status', 'invoicing'), 'class' => 'text-center'),
1918
+            'invoice-total'   => array('title' => __('Total', 'invoicing'), 'class' => 'text-right'),
1919
+            'invoice-actions' => array('title' => '&nbsp;', 'class' => 'text-center'),
1920 1920
         );
1921 1921
 
1922
-    return apply_filters( 'wpinv_user_invoices_columns', $columns );
1922
+    return apply_filters('wpinv_user_invoices_columns', $columns);
1923 1923
 }
1924 1924
 
1925
-function wpinv_payment_receipt( $atts, $content = null ) {
1925
+function wpinv_payment_receipt($atts, $content = null) {
1926 1926
     global $wpinv_receipt_args;
1927 1927
 
1928
-    $wpinv_receipt_args = shortcode_atts( array(
1929
-        'error'           => __( 'Sorry, trouble retrieving payment receipt.', 'invoicing' ),
1928
+    $wpinv_receipt_args = shortcode_atts(array(
1929
+        'error'           => __('Sorry, trouble retrieving payment receipt.', 'invoicing'),
1930 1930
         'price'           => true,
1931 1931
         'discount'        => true,
1932 1932
         'items'           => true,
@@ -1935,45 +1935,45 @@  discard block
 block discarded – undo
1935 1935
         'invoice_key'     => false,
1936 1936
         'payment_method'  => true,
1937 1937
         'invoice_id'      => true
1938
-    ), $atts, 'wpinv_receipt' );
1938
+    ), $atts, 'wpinv_receipt');
1939 1939
 
1940 1940
     // Find the invoice.
1941 1941
     $session = wpinv_get_checkout_session();
1942 1942
 
1943
-    if ( isset( $_GET['invoice_key'] ) ) {
1944
-        $invoice_id = wpinv_get_invoice_id_by_key( urldecode( $_GET['invoice_key'] ) );
1945
-    } else if ( isset( $_GET['invoice-id'] ) ) {
1943
+    if (isset($_GET['invoice_key'])) {
1944
+        $invoice_id = wpinv_get_invoice_id_by_key(urldecode($_GET['invoice_key']));
1945
+    } else if (isset($_GET['invoice-id'])) {
1946 1946
         $invoice_id = (int) $_GET['invoice-id'];
1947
-    } else if ( $session && isset( $session['invoice_key'] ) ) {
1948
-        $invoice_id = wpinv_get_invoice_id_by_key( $session['invoice_key'] );
1949
-    } else if ( isset( $wpinv_receipt_args['invoice_key'] ) && $wpinv_receipt_args['invoice_key'] ) {
1950
-        $invoice_id = wpinv_get_invoice_id_by_key( $wpinv_receipt_args['invoice_key'] );
1947
+    } else if ($session && isset($session['invoice_key'])) {
1948
+        $invoice_id = wpinv_get_invoice_id_by_key($session['invoice_key']);
1949
+    } else if (isset($wpinv_receipt_args['invoice_key']) && $wpinv_receipt_args['invoice_key']) {
1950
+        $invoice_id = wpinv_get_invoice_id_by_key($wpinv_receipt_args['invoice_key']);
1951 1951
     }
1952 1952
 
1953 1953
     // Did we find the invoice?
1954
-    if ( empty( $invoice_id ) || ! $invoice = wpinv_get_invoice( $invoice_id ) ) {
1955
-        return '<p class="alert alert-error">' . __( 'We could not find your invoice.', 'invoicing' ) . '</p>';
1954
+    if (empty($invoice_id) || !$invoice = wpinv_get_invoice($invoice_id)) {
1955
+        return '<p class="alert alert-error">' . __('We could not find your invoice.', 'invoicing') . '</p>';
1956 1956
     }
1957 1957
 
1958 1958
     $invoice_key   = $invoice->get_key();
1959
-    $user_can_view = wpinv_can_view_receipt( $invoice_key );
1960
-    if ( $user_can_view && isset( $_GET['invoice-id'] ) ) {
1961
-        $user_can_view  = $_GET['invoice-id'] == $invoice->ID;
1959
+    $user_can_view = wpinv_can_view_receipt($invoice_key);
1960
+    if ($user_can_view && isset($_GET['invoice-id'])) {
1961
+        $user_can_view = $_GET['invoice-id'] == $invoice->ID;
1962 1962
     }
1963 1963
 
1964 1964
     // Key was provided, but user is logged out. Offer them the ability to login and view the receipt
1965
-    if ( ! $user_can_view && ! empty( $invoice_key ) && ! is_user_logged_in() ) {
1965
+    if (!$user_can_view && !empty($invoice_key) && !is_user_logged_in()) {
1966 1966
         // login redirect
1967
-        return '<p class="alert alert-error">' . __( 'You must be logged in to view this receipt', 'invoicing' ) . '</p>';
1967
+        return '<p class="alert alert-error">' . __('You must be logged in to view this receipt', 'invoicing') . '</p>';
1968 1968
     }
1969 1969
 
1970
-    if ( ! apply_filters( 'wpinv_user_can_view_receipt', $user_can_view, $wpinv_receipt_args ) ) {
1970
+    if (!apply_filters('wpinv_user_can_view_receipt', $user_can_view, $wpinv_receipt_args)) {
1971 1971
         return '<p class="alert alert-error">' . $wpinv_receipt_args['error'] . '</p>';
1972 1972
     }
1973 1973
 
1974 1974
     ob_start();
1975 1975
 
1976
-    wpinv_get_template_part( 'wpinv-invoice-receipt' );
1976
+    wpinv_get_template_part('wpinv-invoice-receipt');
1977 1977
 
1978 1978
     $display = ob_get_clean();
1979 1979
 
@@ -1983,148 +1983,148 @@  discard block
 block discarded – undo
1983 1983
 /**
1984 1984
  * Given an invoice key, this function returns the id.
1985 1985
  */
1986
-function wpinv_get_invoice_id_by_key( $key ) {
1986
+function wpinv_get_invoice_id_by_key($key) {
1987 1987
 	global $wpdb;
1988
-    $table      = $wpdb->prefix . 'getpaid_invoices';
1989
-	return (int) $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $table WHERE`key` = %s LIMIT 1", $key ) );
1988
+    $table = $wpdb->prefix . 'getpaid_invoices';
1989
+	return (int) $wpdb->get_var($wpdb->prepare("SELECT post_id FROM $table WHERE`key` = %s LIMIT 1", $key));
1990 1990
 }
1991 1991
 
1992
-function wpinv_can_view_receipt( $invoice_key = '' ) {
1993
-	$return = current_user_can( 'manage_options' );
1992
+function wpinv_can_view_receipt($invoice_key = '') {
1993
+	$return = current_user_can('manage_options');
1994 1994
 
1995
-	if ( empty( $invoice_key ) ) {
1995
+	if (empty($invoice_key)) {
1996 1996
 		return false;
1997 1997
 	}
1998 1998
 
1999 1999
 	global $wpinv_receipt_args;
2000 2000
 
2001
-	$wpinv_receipt_args['id'] = wpinv_get_invoice_id_by_key( $invoice_key );
2002
-	if ( isset( $_GET['invoice-id'] ) ) {
2003
-		$wpinv_receipt_args['id'] = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? (int)$_GET['invoice-id'] : 0;
2001
+	$wpinv_receipt_args['id'] = wpinv_get_invoice_id_by_key($invoice_key);
2002
+	if (isset($_GET['invoice-id'])) {
2003
+		$wpinv_receipt_args['id'] = $invoice_key == wpinv_get_payment_key((int) $_GET['invoice-id']) ? (int) $_GET['invoice-id'] : 0;
2004 2004
 	}
2005 2005
 
2006
-	if ( empty( $wpinv_receipt_args['id'] ) ) {
2006
+	if (empty($wpinv_receipt_args['id'])) {
2007 2007
 		return $return;
2008 2008
 	}
2009 2009
 
2010
-	$invoice = wpinv_get_invoice( $wpinv_receipt_args['id'] );
2011
-	if ( !( !empty( $invoice->ID ) && $invoice->get_key() === $invoice_key ) ) {
2010
+	$invoice = wpinv_get_invoice($wpinv_receipt_args['id']);
2011
+	if (!(!empty($invoice->ID) && $invoice->get_key() === $invoice_key)) {
2012 2012
 		return $return;
2013 2013
 	}
2014 2014
 
2015
-	if ( is_user_logged_in() ) {
2016
-		if ( (int)$invoice->get_user_id() === (int) get_current_user_id() ) {
2015
+	if (is_user_logged_in()) {
2016
+		if ((int) $invoice->get_user_id() === (int) get_current_user_id()) {
2017 2017
 			$return = true;
2018 2018
 		}
2019 2019
 	}
2020 2020
 
2021 2021
 	$session = wpinv_get_checkout_session();
2022
-	if ( isset( $_GET['invoice_key'] ) || ( $session && isset( $session['invoice_key'] ) ) ) {
2023
-		$check_key = isset( $_GET['invoice_key'] ) ? $_GET['invoice_key'] : $session['invoice_key'];
2022
+	if (isset($_GET['invoice_key']) || ($session && isset($session['invoice_key']))) {
2023
+		$check_key = isset($_GET['invoice_key']) ? $_GET['invoice_key'] : $session['invoice_key'];
2024 2024
 
2025
-		if ( wpinv_require_login_to_checkout() ) {
2025
+		if (wpinv_require_login_to_checkout()) {
2026 2026
 			$return = $return && $check_key == $invoice_key;
2027 2027
 		} else {
2028 2028
 			$return = $check_key == $invoice_key;
2029 2029
 		}
2030 2030
 	}
2031 2031
 
2032
-	return (bool) apply_filters( 'wpinv_can_view_receipt', $return, $invoice_key );
2032
+	return (bool) apply_filters('wpinv_can_view_receipt', $return, $invoice_key);
2033 2033
 }
2034 2034
 
2035 2035
 function wpinv_pay_for_invoice() {
2036 2036
     global $wpinv_euvat;
2037 2037
     
2038
-    if ( isset( $_GET['invoice_key'] ) ) {
2038
+    if (isset($_GET['invoice_key'])) {
2039 2039
         $checkout_uri   = wpinv_get_checkout_uri();
2040
-        $invoice_key    = sanitize_text_field( $_GET['invoice_key'] );
2040
+        $invoice_key    = sanitize_text_field($_GET['invoice_key']);
2041 2041
         
2042
-        if ( empty( $invoice_key ) ) {
2043
-            wpinv_set_error( 'invalid_invoice', __( 'Invoice not found', 'invoicing' ) );
2044
-            wp_redirect( $checkout_uri );
2042
+        if (empty($invoice_key)) {
2043
+            wpinv_set_error('invalid_invoice', __('Invoice not found', 'invoicing'));
2044
+            wp_redirect($checkout_uri);
2045 2045
             exit();
2046 2046
         }
2047 2047
         
2048
-        do_action( 'wpinv_check_pay_for_invoice', $invoice_key );
2048
+        do_action('wpinv_check_pay_for_invoice', $invoice_key);
2049 2049
 
2050
-        $invoice_id    = wpinv_get_invoice_id_by_key( $invoice_key );
2051
-        $user_can_view = wpinv_can_view_receipt( $invoice_key );
2052
-        if ( $user_can_view && isset( $_GET['invoice-id'] ) ) {
2053
-            $invoice_id     = (int)$_GET['invoice-id'];
2054
-            $user_can_view  = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? true : false;
2050
+        $invoice_id    = wpinv_get_invoice_id_by_key($invoice_key);
2051
+        $user_can_view = wpinv_can_view_receipt($invoice_key);
2052
+        if ($user_can_view && isset($_GET['invoice-id'])) {
2053
+            $invoice_id     = (int) $_GET['invoice-id'];
2054
+            $user_can_view  = $invoice_key == wpinv_get_payment_key((int) $_GET['invoice-id']) ? true : false;
2055 2055
         }
2056 2056
         
2057
-        if ( $invoice_id && $user_can_view && ( $invoice = wpinv_get_invoice( $invoice_id ) ) ) {
2058
-            if ( $invoice->needs_payment() ) {
2057
+        if ($invoice_id && $user_can_view && ($invoice = wpinv_get_invoice($invoice_id))) {
2058
+            if ($invoice->needs_payment()) {
2059 2059
                 $data                   = array();
2060 2060
                 $data['invoice_id']     = $invoice_id;
2061
-                $data['cart_discounts'] = $invoice->get_discounts( true );
2061
+                $data['cart_discounts'] = $invoice->get_discounts(true);
2062 2062
                 
2063
-                wpinv_set_checkout_session( $data );
2063
+                wpinv_set_checkout_session($data);
2064 2064
                 
2065
-                if ( wpinv_get_option( 'vat_ip_country_default' ) ) {
2065
+                if (wpinv_get_option('vat_ip_country_default')) {
2066 2066
                     $_POST['country']   = $wpinv_euvat->get_country_by_ip();
2067 2067
                     $_POST['state']     = $_POST['country'] == $invoice->country ? $invoice->state : '';
2068 2068
                     
2069
-                    wpinv_recalculate_tax( true );
2069
+                    wpinv_recalculate_tax(true);
2070 2070
                 }
2071 2071
                 
2072 2072
             } else {
2073 2073
                 $checkout_uri = $invoice->get_view_url();
2074 2074
             }
2075 2075
         } else {
2076
-            wpinv_set_error( 'invalid_invoice', __( 'You are not allowed to view this invoice', 'invoicing' ) );
2076
+            wpinv_set_error('invalid_invoice', __('You are not allowed to view this invoice', 'invoicing'));
2077 2077
             
2078
-            $checkout_uri = is_user_logged_in() ? wpinv_get_history_page_uri() : wp_login_url( get_permalink() );
2078
+            $checkout_uri = is_user_logged_in() ? wpinv_get_history_page_uri() : wp_login_url(get_permalink());
2079 2079
         }
2080 2080
         
2081
-        if(wp_redirect( $checkout_uri )){
2081
+        if (wp_redirect($checkout_uri)) {
2082 2082
             exit;
2083 2083
         };
2084 2084
         wpinv_die();
2085 2085
     }
2086 2086
 }
2087
-add_action( 'wpinv_pay_for_invoice', 'wpinv_pay_for_invoice' );
2087
+add_action('wpinv_pay_for_invoice', 'wpinv_pay_for_invoice');
2088 2088
 
2089
-function wpinv_handle_pay_via_invoice_link( $invoice_key ) {
2090
-    if ( !empty( $invoice_key ) && !empty( $_REQUEST['_wpipay'] ) && !is_user_logged_in() && $invoice_id = wpinv_get_invoice_id_by_key( $invoice_key ) ) {
2091
-        if ( $invoice = wpinv_get_invoice( $invoice_id ) ) {
2089
+function wpinv_handle_pay_via_invoice_link($invoice_key) {
2090
+    if (!empty($invoice_key) && !empty($_REQUEST['_wpipay']) && !is_user_logged_in() && $invoice_id = wpinv_get_invoice_id_by_key($invoice_key)) {
2091
+        if ($invoice = wpinv_get_invoice($invoice_id)) {
2092 2092
             $user_id = $invoice->get_user_id();
2093
-            $secret = sanitize_text_field( $_GET['_wpipay'] );
2093
+            $secret = sanitize_text_field($_GET['_wpipay']);
2094 2094
             
2095
-            if ( $secret === md5( $user_id . '::' . $invoice->get_email() . '::' . $invoice_key ) ) { // valid invoice link
2096
-                $redirect_to = remove_query_arg( '_wpipay', get_permalink() );
2095
+            if ($secret === md5($user_id . '::' . $invoice->get_email() . '::' . $invoice_key)) { // valid invoice link
2096
+                $redirect_to = remove_query_arg('_wpipay', get_permalink());
2097 2097
                 
2098
-                wpinv_guest_redirect( $redirect_to, $user_id );
2098
+                wpinv_guest_redirect($redirect_to, $user_id);
2099 2099
                 exit();
2100 2100
             }
2101 2101
         }
2102 2102
     }
2103 2103
 }
2104
-add_action( 'wpinv_check_pay_for_invoice', 'wpinv_handle_pay_via_invoice_link' );
2104
+add_action('wpinv_check_pay_for_invoice', 'wpinv_handle_pay_via_invoice_link');
2105 2105
 
2106
-function wpinv_set_payment_transaction_id( $invoice_id = 0, $transaction_id = '' ) {
2107
-    $invoice_id = is_object( $invoice_id ) && !empty( $invoice_id->ID ) ? $invoice_id : $invoice_id;
2106
+function wpinv_set_payment_transaction_id($invoice_id = 0, $transaction_id = '') {
2107
+    $invoice_id = is_object($invoice_id) && !empty($invoice_id->ID) ? $invoice_id : $invoice_id;
2108 2108
     
2109
-    if ( empty( $invoice_id ) && $invoice_id > 0 ) {
2109
+    if (empty($invoice_id) && $invoice_id > 0) {
2110 2110
         return false;
2111 2111
     }
2112 2112
     
2113
-    if ( empty( $transaction_id ) ) {
2113
+    if (empty($transaction_id)) {
2114 2114
         $transaction_id = $invoice_id;
2115 2115
     }
2116 2116
 
2117
-    $transaction_id = apply_filters( 'wpinv_set_payment_transaction_id', $transaction_id, $invoice_id );
2117
+    $transaction_id = apply_filters('wpinv_set_payment_transaction_id', $transaction_id, $invoice_id);
2118 2118
     
2119
-    return wpinv_update_invoice_meta( $invoice_id, '_wpinv_transaction_id', $transaction_id );
2119
+    return wpinv_update_invoice_meta($invoice_id, '_wpinv_transaction_id', $transaction_id);
2120 2120
 }
2121 2121
 
2122
-function wpinv_invoice_status_label( $status, $status_display = '' ) {
2123
-    if ( empty( $status_display ) ) {
2124
-        $status_display = wpinv_status_nicename( $status );
2122
+function wpinv_invoice_status_label($status, $status_display = '') {
2123
+    if (empty($status_display)) {
2124
+        $status_display = wpinv_status_nicename($status);
2125 2125
     }
2126 2126
     
2127
-    switch ( $status ) {
2127
+    switch ($status) {
2128 2128
         case 'publish' :
2129 2129
         case 'wpi-renewal' :
2130 2130
             $class = 'label-success';
@@ -2149,201 +2149,201 @@  discard block
 block discarded – undo
2149 2149
     
2150 2150
     $label = '<span class="label label-inv-' . $status . ' ' . $class . '">' . $status_display . '</span>';
2151 2151
     
2152
-    return apply_filters( 'wpinv_invoice_status_label', $label, $status, $status_display );
2152
+    return apply_filters('wpinv_invoice_status_label', $label, $status, $status_display);
2153 2153
 }
2154 2154
 
2155
-function wpinv_format_invoice_number( $number, $type = '' ) {
2156
-    $check = apply_filters( 'wpinv_pre_format_invoice_number', null, $number, $type );
2157
-    if ( null !== $check ) {
2155
+function wpinv_format_invoice_number($number, $type = '') {
2156
+    $check = apply_filters('wpinv_pre_format_invoice_number', null, $number, $type);
2157
+    if (null !== $check) {
2158 2158
         return $check;
2159 2159
     }
2160 2160
 
2161
-    if ( !empty( $number ) && !is_numeric( $number ) ) {
2161
+    if (!empty($number) && !is_numeric($number)) {
2162 2162
         return $number;
2163 2163
     }
2164 2164
 
2165
-    $padd  = wpinv_get_option( 'invoice_number_padd' );
2166
-    $prefix  = wpinv_get_option( 'invoice_number_prefix' );
2167
-    $postfix = wpinv_get_option( 'invoice_number_postfix' );
2165
+    $padd = wpinv_get_option('invoice_number_padd');
2166
+    $prefix  = wpinv_get_option('invoice_number_prefix');
2167
+    $postfix = wpinv_get_option('invoice_number_postfix');
2168 2168
     
2169
-    $padd = absint( $padd );
2170
-    $formatted_number = absint( $number );
2169
+    $padd = absint($padd);
2170
+    $formatted_number = absint($number);
2171 2171
     
2172
-    if ( $padd > 0 ) {
2173
-        $formatted_number = zeroise( $formatted_number, $padd );
2172
+    if ($padd > 0) {
2173
+        $formatted_number = zeroise($formatted_number, $padd);
2174 2174
     }    
2175 2175
 
2176 2176
     $formatted_number = $prefix . $formatted_number . $postfix;
2177 2177
 
2178
-    return apply_filters( 'wpinv_format_invoice_number', $formatted_number, $number, $prefix, $postfix, $padd );
2178
+    return apply_filters('wpinv_format_invoice_number', $formatted_number, $number, $prefix, $postfix, $padd);
2179 2179
 }
2180 2180
 
2181
-function wpinv_get_next_invoice_number( $type = '' ) {
2182
-    $check = apply_filters( 'wpinv_get_pre_next_invoice_number', null, $type );
2183
-    if ( null !== $check ) {
2181
+function wpinv_get_next_invoice_number($type = '') {
2182
+    $check = apply_filters('wpinv_get_pre_next_invoice_number', null, $type);
2183
+    if (null !== $check) {
2184 2184
         return $check;
2185 2185
     }
2186 2186
     
2187
-    if ( !wpinv_sequential_number_active() ) {
2187
+    if (!wpinv_sequential_number_active()) {
2188 2188
         return false;
2189 2189
     }
2190 2190
 
2191
-    $number = $last_number = get_option( 'wpinv_last_invoice_number', 0 );
2192
-    $start  = wpinv_get_option( 'invoice_sequence_start', 1 );
2193
-    if ( !absint( $start ) > 0 ) {
2191
+    $number = $last_number = get_option('wpinv_last_invoice_number', 0);
2192
+    $start  = wpinv_get_option('invoice_sequence_start', 1);
2193
+    if (!absint($start) > 0) {
2194 2194
         $start = 1;
2195 2195
     }
2196 2196
     $increment_number = true;
2197 2197
     $save_number = false;
2198 2198
 
2199
-    if ( !empty( $number ) && !is_numeric( $number ) && $number == wpinv_format_invoice_number( $number ) ) {
2200
-        $number = wpinv_clean_invoice_number( $number );
2199
+    if (!empty($number) && !is_numeric($number) && $number == wpinv_format_invoice_number($number)) {
2200
+        $number = wpinv_clean_invoice_number($number);
2201 2201
     }
2202 2202
 
2203
-    if ( empty( $number ) ) {
2204
-        if ( !( $last_number === 0 || $last_number === '0' ) ) {
2205
-            $last_invoice = wpinv_get_invoices( array( 'limit' => 1, 'order' => 'DESC', 'orderby' => 'ID', 'return' => 'posts', 'fields' => 'ids', 'status' => array_keys( wpinv_get_invoice_statuses( true, true ) ) ) );
2203
+    if (empty($number)) {
2204
+        if (!($last_number === 0 || $last_number === '0')) {
2205
+            $last_invoice = wpinv_get_invoices(array('limit' => 1, 'order' => 'DESC', 'orderby' => 'ID', 'return' => 'posts', 'fields' => 'ids', 'status' => array_keys(wpinv_get_invoice_statuses(true, true))));
2206 2206
 
2207
-            if ( !empty( $last_invoice[0] ) && $invoice_number = wpinv_get_invoice_number( $last_invoice[0] ) ) {
2208
-                if ( is_numeric( $invoice_number ) ) {
2207
+            if (!empty($last_invoice[0]) && $invoice_number = wpinv_get_invoice_number($last_invoice[0])) {
2208
+                if (is_numeric($invoice_number)) {
2209 2209
                     $number = $invoice_number;
2210 2210
                 } else {
2211
-                    $number = wpinv_clean_invoice_number( $invoice_number );
2211
+                    $number = wpinv_clean_invoice_number($invoice_number);
2212 2212
                 }
2213 2213
             }
2214 2214
 
2215
-            if ( empty( $number ) ) {
2215
+            if (empty($number)) {
2216 2216
                 $increment_number = false;
2217 2217
                 $number = $start;
2218
-                $save_number = ( $number - 1 );
2218
+                $save_number = ($number - 1);
2219 2219
             } else {
2220 2220
                 $save_number = $number;
2221 2221
             }
2222 2222
         }
2223 2223
     }
2224 2224
 
2225
-    if ( $start > $number ) {
2225
+    if ($start > $number) {
2226 2226
         $increment_number = false;
2227 2227
         $number = $start;
2228
-        $save_number = ( $number - 1 );
2228
+        $save_number = ($number - 1);
2229 2229
     }
2230 2230
 
2231
-    if ( $save_number !== false ) {
2232
-        update_option( 'wpinv_last_invoice_number', $save_number );
2231
+    if ($save_number !== false) {
2232
+        update_option('wpinv_last_invoice_number', $save_number);
2233 2233
     }
2234 2234
     
2235
-    $increment_number = apply_filters( 'wpinv_increment_payment_number', $increment_number, $number );
2235
+    $increment_number = apply_filters('wpinv_increment_payment_number', $increment_number, $number);
2236 2236
 
2237
-    if ( $increment_number ) {
2237
+    if ($increment_number) {
2238 2238
         $number++;
2239 2239
     }
2240 2240
 
2241
-    return apply_filters( 'wpinv_get_next_invoice_number', $number );
2241
+    return apply_filters('wpinv_get_next_invoice_number', $number);
2242 2242
 }
2243 2243
 
2244
-function wpinv_clean_invoice_number( $number, $type = '' ) {
2245
-    $check = apply_filters( 'wpinv_pre_clean_invoice_number', null, $number, $type );
2246
-    if ( null !== $check ) {
2244
+function wpinv_clean_invoice_number($number, $type = '') {
2245
+    $check = apply_filters('wpinv_pre_clean_invoice_number', null, $number, $type);
2246
+    if (null !== $check) {
2247 2247
         return $check;
2248 2248
     }
2249 2249
     
2250
-    $prefix  = wpinv_get_option( 'invoice_number_prefix' );
2251
-    $postfix = wpinv_get_option( 'invoice_number_postfix' );
2250
+    $prefix  = wpinv_get_option('invoice_number_prefix');
2251
+    $postfix = wpinv_get_option('invoice_number_postfix');
2252 2252
 
2253
-    $number = preg_replace( '/' . $prefix . '/', '', $number, 1 );
2253
+    $number = preg_replace('/' . $prefix . '/', '', $number, 1);
2254 2254
 
2255
-    $length      = strlen( $number );
2256
-    $postfix_pos = strrpos( $number, $postfix );
2255
+    $length      = strlen($number);
2256
+    $postfix_pos = strrpos($number, $postfix);
2257 2257
     
2258
-    if ( false !== $postfix_pos ) {
2259
-        $number      = substr_replace( $number, '', $postfix_pos, $length );
2258
+    if (false !== $postfix_pos) {
2259
+        $number = substr_replace($number, '', $postfix_pos, $length);
2260 2260
     }
2261 2261
 
2262
-    $number = intval( $number );
2262
+    $number = intval($number);
2263 2263
 
2264
-    return apply_filters( 'wpinv_clean_invoice_number', $number, $prefix, $postfix );
2264
+    return apply_filters('wpinv_clean_invoice_number', $number, $prefix, $postfix);
2265 2265
 }
2266 2266
 
2267
-function wpinv_save_number_post_saved( $post_ID, $post, $update ) {
2267
+function wpinv_save_number_post_saved($post_ID, $post, $update) {
2268 2268
     global $wpdb;
2269 2269
 
2270
-    if ( !$update && !get_post_meta( $post_ID, '_wpinv_number', true ) ) {
2271
-        wpinv_update_invoice_number( $post_ID, $post->post_status != 'auto-draft', $post->post_type );
2270
+    if (!$update && !get_post_meta($post_ID, '_wpinv_number', true)) {
2271
+        wpinv_update_invoice_number($post_ID, $post->post_status != 'auto-draft', $post->post_type);
2272 2272
     }
2273 2273
 
2274
-    if ( !$update ) {
2275
-        $wpdb->update( $wpdb->posts, array( 'post_name' => wpinv_generate_post_name( $post_ID ) ), array( 'ID' => $post_ID ) );
2276
-        clean_post_cache( $post_ID );
2274
+    if (!$update) {
2275
+        $wpdb->update($wpdb->posts, array('post_name' => wpinv_generate_post_name($post_ID)), array('ID' => $post_ID));
2276
+        clean_post_cache($post_ID);
2277 2277
     }
2278 2278
 }
2279
-add_action( 'save_post_wpi_invoice', 'wpinv_save_number_post_saved', 1, 3 );
2279
+add_action('save_post_wpi_invoice', 'wpinv_save_number_post_saved', 1, 3);
2280 2280
 
2281
-function wpinv_save_number_post_updated( $post_ID, $post_after, $post_before ) {
2282
-    if ( !empty( $post_after->post_type ) && $post_after->post_type == 'wpi_invoice' && $post_before->post_status == 'auto-draft' && $post_after->post_status != $post_before->post_status ) {
2283
-        wpinv_update_invoice_number( $post_ID, true, $post_after->post_type );
2281
+function wpinv_save_number_post_updated($post_ID, $post_after, $post_before) {
2282
+    if (!empty($post_after->post_type) && $post_after->post_type == 'wpi_invoice' && $post_before->post_status == 'auto-draft' && $post_after->post_status != $post_before->post_status) {
2283
+        wpinv_update_invoice_number($post_ID, true, $post_after->post_type);
2284 2284
     }
2285 2285
 }
2286
-add_action( 'post_updated', 'wpinv_save_number_post_updated', 1, 3 );
2286
+add_action('post_updated', 'wpinv_save_number_post_updated', 1, 3);
2287 2287
 
2288
-function wpinv_update_invoice_number( $post_ID, $save_sequential = false, $type = '' ) {
2288
+function wpinv_update_invoice_number($post_ID, $save_sequential = false, $type = '') {
2289 2289
     global $wpdb;
2290 2290
     
2291
-    $check = apply_filters( 'wpinv_pre_update_invoice_number', null, $post_ID, $save_sequential, $type );
2292
-    if ( null !== $check ) {
2291
+    $check = apply_filters('wpinv_pre_update_invoice_number', null, $post_ID, $save_sequential, $type);
2292
+    if (null !== $check) {
2293 2293
         return $check;
2294 2294
     }
2295 2295
 
2296
-    if ( wpinv_sequential_number_active() ) {
2296
+    if (wpinv_sequential_number_active()) {
2297 2297
         $number = wpinv_get_next_invoice_number();
2298 2298
 
2299
-        if ( $save_sequential ) {
2300
-            update_option( 'wpinv_last_invoice_number', $number );
2299
+        if ($save_sequential) {
2300
+            update_option('wpinv_last_invoice_number', $number);
2301 2301
         }
2302 2302
     } else {
2303 2303
         $number = $post_ID;
2304 2304
     }
2305 2305
 
2306
-    $number = wpinv_format_invoice_number( $number );
2306
+    $number = wpinv_format_invoice_number($number);
2307 2307
 
2308
-    update_post_meta( $post_ID, '_wpinv_number', $number );
2308
+    update_post_meta($post_ID, '_wpinv_number', $number);
2309 2309
 
2310
-    $wpdb->update( $wpdb->posts, array( 'post_title' => $number ), array( 'ID' => $post_ID ) );
2310
+    $wpdb->update($wpdb->posts, array('post_title' => $number), array('ID' => $post_ID));
2311 2311
 
2312
-    clean_post_cache( $post_ID );
2312
+    clean_post_cache($post_ID);
2313 2313
 
2314 2314
     return $number;
2315 2315
 }
2316 2316
 
2317
-function wpinv_post_name_prefix( $post_type = 'wpi_invoice' ) {
2318
-    return apply_filters( 'wpinv_post_name_prefix', 'inv-', $post_type );
2317
+function wpinv_post_name_prefix($post_type = 'wpi_invoice') {
2318
+    return apply_filters('wpinv_post_name_prefix', 'inv-', $post_type);
2319 2319
 }
2320 2320
 
2321
-function wpinv_generate_post_name( $post_ID ) {
2322
-    $prefix = wpinv_post_name_prefix( get_post_type( $post_ID ) );
2323
-    $post_name = sanitize_title( $prefix . $post_ID );
2321
+function wpinv_generate_post_name($post_ID) {
2322
+    $prefix = wpinv_post_name_prefix(get_post_type($post_ID));
2323
+    $post_name = sanitize_title($prefix . $post_ID);
2324 2324
 
2325
-    return apply_filters( 'wpinv_generate_post_name', $post_name, $post_ID, $prefix );
2325
+    return apply_filters('wpinv_generate_post_name', $post_name, $post_ID, $prefix);
2326 2326
 }
2327 2327
 
2328
-function wpinv_is_invoice_viewed( $invoice_id ) {
2329
-    if ( empty( $invoice_id ) ) {
2328
+function wpinv_is_invoice_viewed($invoice_id) {
2329
+    if (empty($invoice_id)) {
2330 2330
         return false;
2331 2331
     }
2332 2332
 
2333
-    $viewed_meta = get_post_meta( $invoice_id, '_wpinv_is_viewed', true );
2333
+    $viewed_meta = get_post_meta($invoice_id, '_wpinv_is_viewed', true);
2334 2334
 
2335
-    return apply_filters( 'wpinv_is_invoice_viewed', 1 === (int)$viewed_meta, $invoice_id );
2335
+    return apply_filters('wpinv_is_invoice_viewed', 1 === (int) $viewed_meta, $invoice_id);
2336 2336
 }
2337 2337
 
2338 2338
 function wpinv_mark_invoice_viewed() {
2339 2339
 
2340
-    if ( isset( $_GET['invoice_key'] ) || is_singular( 'wpi_invoice' ) || is_singular( 'wpi_quote' ) ) {
2341
-        $invoice_key = isset( $_GET['invoice_key'] ) ? urldecode($_GET['invoice_key']) : '';
2340
+    if (isset($_GET['invoice_key']) || is_singular('wpi_invoice') || is_singular('wpi_quote')) {
2341
+        $invoice_key = isset($_GET['invoice_key']) ? urldecode($_GET['invoice_key']) : '';
2342 2342
 	    global $post;
2343 2343
 
2344
-        if(!empty($invoice_key)){
2344
+        if (!empty($invoice_key)) {
2345 2345
 	        $invoice_id = wpinv_get_invoice_id_by_key($invoice_key);
2346
-        } else if(!empty( $post ) && ($post->post_type == 'wpi_invoice' || $post->post_type == 'wpi_quote')) {
2346
+        } else if (!empty($post) && ($post->post_type == 'wpi_invoice' || $post->post_type == 'wpi_quote')) {
2347 2347
 			$invoice_id = $post->ID;
2348 2348
         } else {
2349 2349
         	return;
@@ -2351,63 +2351,63 @@  discard block
 block discarded – undo
2351 2351
 
2352 2352
         $invoice = new WPInv_Invoice($invoice_id);
2353 2353
 
2354
-        if(!$invoice_id){
2354
+        if (!$invoice_id) {
2355 2355
             return;
2356 2356
         }
2357 2357
 
2358
-	    if ( is_user_logged_in() ) {
2359
-		    if ( (int)$invoice->get_user_id() === get_current_user_id() ) {
2360
-			    update_post_meta($invoice_id,'_wpinv_is_viewed', 1);
2361
-		    } else if ( !wpinv_require_login_to_checkout() && isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) {
2362
-			    update_post_meta($invoice_id,'_wpinv_is_viewed', 1);
2358
+	    if (is_user_logged_in()) {
2359
+		    if ((int) $invoice->get_user_id() === get_current_user_id()) {
2360
+			    update_post_meta($invoice_id, '_wpinv_is_viewed', 1);
2361
+		    } else if (!wpinv_require_login_to_checkout() && isset($_GET['invoice_key']) && $_GET['invoice_key'] === $invoice->get_key()) {
2362
+			    update_post_meta($invoice_id, '_wpinv_is_viewed', 1);
2363 2363
 		    }
2364 2364
 	    } else {
2365
-		    if ( !wpinv_require_login_to_checkout() && isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) {
2366
-			    update_post_meta($invoice_id,'_wpinv_is_viewed', 1);
2365
+		    if (!wpinv_require_login_to_checkout() && isset($_GET['invoice_key']) && $_GET['invoice_key'] === $invoice->get_key()) {
2366
+			    update_post_meta($invoice_id, '_wpinv_is_viewed', 1);
2367 2367
 		    }
2368 2368
 	    }
2369 2369
     }
2370 2370
 
2371 2371
 }
2372
-add_action( 'template_redirect', 'wpinv_mark_invoice_viewed' );
2372
+add_action('template_redirect', 'wpinv_mark_invoice_viewed');
2373 2373
 
2374 2374
 /**
2375 2375
  * @return WPInv_Subscription
2376 2376
  */
2377
-function wpinv_get_subscription( $invoice, $by_parent = false ) {
2378
-    if ( empty( $invoice ) ) {
2377
+function wpinv_get_subscription($invoice, $by_parent = false) {
2378
+    if (empty($invoice)) {
2379 2379
         return false;
2380 2380
     }
2381 2381
     
2382
-    if ( ! is_object( $invoice ) && is_scalar( $invoice ) ) {
2383
-        $invoice = wpinv_get_invoice( $invoice );
2382
+    if (!is_object($invoice) && is_scalar($invoice)) {
2383
+        $invoice = wpinv_get_invoice($invoice);
2384 2384
     }
2385 2385
     
2386
-    if ( !( is_object( $invoice ) && ! empty( $invoice->ID ) && $invoice->is_recurring() ) ) {
2386
+    if (!(is_object($invoice) && !empty($invoice->ID) && $invoice->is_recurring())) {
2387 2387
         return false;
2388 2388
     }
2389 2389
     
2390
-    $invoice_id = ! $by_parent && ! empty( $invoice->parent_invoice ) ? $invoice->parent_invoice : $invoice->ID;
2390
+    $invoice_id = !$by_parent && !empty($invoice->parent_invoice) ? $invoice->parent_invoice : $invoice->ID;
2391 2391
     
2392 2392
     $subs_db    = new WPInv_Subscriptions_DB;
2393
-    $subs       = $subs_db->get_subscriptions( array( 'parent_payment_id' => $invoice_id, 'number' => 1 ) );
2393
+    $subs       = $subs_db->get_subscriptions(array('parent_payment_id' => $invoice_id, 'number' => 1));
2394 2394
     
2395
-    if ( ! empty( $subs ) ) {
2396
-        return reset( $subs );
2395
+    if (!empty($subs)) {
2396
+        return reset($subs);
2397 2397
     }
2398 2398
     
2399 2399
     return false;
2400 2400
 }
2401 2401
 
2402
-function wpinv_filter_posts_clauses( $clauses, $wp_query ) {
2402
+function wpinv_filter_posts_clauses($clauses, $wp_query) {
2403 2403
     global $wpdb;
2404 2404
 
2405
-    if ( ! empty( $wp_query->query_vars['orderby'] ) && $wp_query->query_vars['orderby'] == 'invoice_date' ) {
2406
-        if ( !empty( $clauses['join'] ) ) {
2405
+    if (!empty($wp_query->query_vars['orderby']) && $wp_query->query_vars['orderby'] == 'invoice_date') {
2406
+        if (!empty($clauses['join'])) {
2407 2407
             $clauses['join'] .= " ";
2408 2408
         }
2409 2409
 
2410
-        if ( !empty( $clauses['fields'] ) ) {
2410
+        if (!empty($clauses['fields'])) {
2411 2411
             $clauses['fields'] .= ", ";
2412 2412
         }
2413 2413
 
@@ -2418,7 +2418,7 @@  discard block
 block discarded – undo
2418 2418
 
2419 2419
     return $clauses;
2420 2420
 }
2421
-add_filter( 'posts_clauses', 'wpinv_filter_posts_clauses', 10, 2 );
2421
+add_filter('posts_clauses', 'wpinv_filter_posts_clauses', 10, 2);
2422 2422
 
2423 2423
 /**
2424 2424
  * Processes an invoice refund.
@@ -2428,27 +2428,27 @@  discard block
 block discarded – undo
2428 2428
  * @param array $status_transition
2429 2429
  * @todo: descrease customer/store earnings
2430 2430
  */
2431
-function getpaid_maybe_process_refund( $invoice_id, $invoice, $status_transition ) {
2431
+function getpaid_maybe_process_refund($invoice_id, $invoice, $status_transition) {
2432 2432
 
2433
-    if ( empty( $status_transition['from'] ) || ! $invoice->has_status( 'wpi-refunded' ) || in_array( $status_transition['from'], array( 'publish', 'wpi-processing', 'wpi-renewal' ) ) ) {
2433
+    if (empty($status_transition['from']) || !$invoice->has_status('wpi-refunded') || in_array($status_transition['from'], array('publish', 'wpi-processing', 'wpi-renewal'))) {
2434 2434
         return;
2435 2435
     }
2436 2436
 
2437 2437
     $discount_code = $invoice->get_discount_code();
2438
-    if ( ! empty( $discount_code ) ) {
2439
-        $discount = wpinv_get_discount_obj( $discount_code );
2438
+    if (!empty($discount_code)) {
2439
+        $discount = wpinv_get_discount_obj($discount_code);
2440 2440
 
2441
-        if ( $discount->exists() ) {
2441
+        if ($discount->exists()) {
2442 2442
             $discount->increase_usage( -1 );
2443 2443
         }
2444 2444
     
2445 2445
     }
2446 2446
 
2447
-    do_action( 'wpinv_pre_refund_invoice', $invoice, $invoice_id );
2448
-    do_action( 'wpinv_refund_invoice', $invoice, $invoice_id );
2449
-    do_action( 'wpinv_post_refund_invoice', $invoice, $invoice_id );
2447
+    do_action('wpinv_pre_refund_invoice', $invoice, $invoice_id);
2448
+    do_action('wpinv_refund_invoice', $invoice, $invoice_id);
2449
+    do_action('wpinv_post_refund_invoice', $invoice, $invoice_id);
2450 2450
 }
2451
-add_action( 'getpaid_invoice_status_wpi-refunded', 'getpaid_maybe_process_refund', 10, 3 );
2451
+add_action('getpaid_invoice_status_wpi-refunded', 'getpaid_maybe_process_refund', 10, 3);
2452 2452
 
2453 2453
 /**
2454 2454
  * Fires when a payment fails.
@@ -2456,22 +2456,22 @@  discard block
 block discarded – undo
2456 2456
  * @param int $invoice_id
2457 2457
  * @param WPInv_Invoice $invoice
2458 2458
  */
2459
-function getpaid_maybe_process_failure( $invoice_id, $invoice ) {
2459
+function getpaid_maybe_process_failure($invoice_id, $invoice) {
2460 2460
 
2461
-    if ( ! $invoice->has_status( 'wpi-failed' ) ) {
2461
+    if (!$invoice->has_status('wpi-failed')) {
2462 2462
         return;
2463 2463
     }
2464 2464
 
2465 2465
     $discount_code = $invoice->get_discount_code();
2466
-    if ( ! empty( $discount_code ) ) {
2467
-        $discount = wpinv_get_discount_obj( $discount_code );
2466
+    if (!empty($discount_code)) {
2467
+        $discount = wpinv_get_discount_obj($discount_code);
2468 2468
 
2469
-        if ( $discount->exists() ) {
2469
+        if ($discount->exists()) {
2470 2470
             $discount->increase_usage( -1 );
2471 2471
         }
2472 2472
 
2473 2473
     }
2474 2474
 
2475
-    do_action( 'wpinv_invoice_payment_failed', $invoice, $invoice_id );
2475
+    do_action('wpinv_invoice_payment_failed', $invoice, $invoice_id);
2476 2476
 }
2477
-add_action( 'getpaid_invoice_status_wpi-failed', 'getpaid_maybe_process_failure', 10, 2 );
2478 2477
\ No newline at end of file
2478
+add_action('getpaid_invoice_status_wpi-failed', 'getpaid_maybe_process_failure', 10, 2);
2479 2479
\ No newline at end of file
Please login to merge, or discard this patch.
includes/data-stores/class-getpaid-data.php 2 patches
Indentation   +913 added lines, -913 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
  */
10 10
 
11 11
 if ( ! defined( 'ABSPATH' ) ) {
12
-	exit;
12
+    exit;
13 13
 }
14 14
 
15 15
 /**
@@ -21,356 +21,356 @@  discard block
 block discarded – undo
21 21
  */
22 22
 abstract class GetPaid_Data {
23 23
 
24
-	/**
25
-	 * ID for this object.
26
-	 *
27
-	 * @since 1.0.19
28
-	 * @var int
29
-	 */
30
-	protected $id = 0;
31
-
32
-	/**
33
-	 * Core data for this object. Name value pairs (name + default value).
34
-	 *
35
-	 * @since 1.0.19
36
-	 * @var array
37
-	 */
38
-	protected $data = array();
39
-
40
-	/**
41
-	 * Core data changes for this object.
42
-	 *
43
-	 * @since 1.0.19
44
-	 * @var array
45
-	 */
46
-	protected $changes = array();
47
-
48
-	/**
49
-	 * This is false until the object is read from the DB.
50
-	 *
51
-	 * @since 1.0.19
52
-	 * @var bool
53
-	 */
54
-	protected $object_read = false;
55
-
56
-	/**
57
-	 * This is the name of this object type.
58
-	 *
59
-	 * @since 1.0.19
60
-	 * @var string
61
-	 */
62
-	protected $object_type = 'data';
63
-
64
-	/**
65
-	 * Extra data for this object. Name value pairs (name + default value).
66
-	 * Used as a standard way for sub classes (like item types) to add
67
-	 * additional information to an inherited class.
68
-	 *
69
-	 * @since 1.0.19
70
-	 * @var array
71
-	 */
72
-	protected $extra_data = array();
73
-
74
-	/**
75
-	 * Set to _data on construct so we can track and reset data if needed.
76
-	 *
77
-	 * @since 1.0.19
78
-	 * @var array
79
-	 */
80
-	protected $default_data = array();
81
-
82
-	/**
83
-	 * Contains a reference to the data store for this class.
84
-	 *
85
-	 * @since 1.0.19
86
-	 * @var GetPaid_Data_Store
87
-	 */
88
-	protected $data_store;
89
-
90
-	/**
91
-	 * Stores meta in cache for future reads.
92
-	 * A group must be set to to enable caching.
93
-	 *
94
-	 * @since 1.0.19
95
-	 * @var string
96
-	 */
97
-	protected $cache_group = '';
98
-
99
-	/**
100
-	 * Stores the last error.
101
-	 *
102
-	 * @since 1.0.19
103
-	 * @var string
104
-	 */
105
-	public $last_error = '';
106
-
107
-	/**
108
-	 * Stores additional meta data.
109
-	 *
110
-	 * @since 1.0.19
111
-	 * @var array
112
-	 */
113
-	protected $meta_data = null;
114
-
115
-	/**
116
-	 * Default constructor.
117
-	 *
118
-	 * @param int|object|array $read ID to load from the DB (optional) or already queried data.
119
-	 */
120
-	public function __construct( $read = 0 ) {
121
-		$this->data         = array_merge( $this->data, $this->extra_data );
122
-		$this->default_data = $this->data;
123
-	}
124
-
125
-	/**
126
-	 * Only store the object ID to avoid serializing the data object instance.
127
-	 *
128
-	 * @return array
129
-	 */
130
-	public function __sleep() {
131
-		return array( 'id' );
132
-	}
133
-
134
-	/**
135
-	 * Re-run the constructor with the object ID.
136
-	 *
137
-	 * If the object no longer exists, remove the ID.
138
-	 */
139
-	public function __wakeup() {
140
-		try {
141
-			$this->__construct( absint( $this->id ) );
142
-		} catch ( Exception $e ) {
143
-			$this->set_id( 0 );
144
-			$this->set_object_read( true );
145
-		}
146
-	}
147
-
148
-	/**
149
-	 * When the object is cloned, make sure meta is duplicated correctly.
150
-	 *
151
-	 * @since 1.0.19
152
-	 */
153
-	public function __clone() {
154
-		$this->maybe_read_meta_data();
155
-		if ( ! empty( $this->meta_data ) ) {
156
-			foreach ( $this->meta_data as $array_key => $meta ) {
157
-				$this->meta_data[ $array_key ] = clone $meta;
158
-				if ( ! empty( $meta->id ) ) {
159
-					$this->meta_data[ $array_key ]->id = null;
160
-				}
161
-			}
162
-		}
163
-	}
164
-
165
-	/**
166
-	 * Get the data store.
167
-	 *
168
-	 * @since  1.0.19
169
-	 * @return object
170
-	 */
171
-	public function get_data_store() {
172
-		return $this->data_store;
173
-	}
174
-
175
-	/**
176
-	 * Get the object type.
177
-	 *
178
-	 * @since  1.0.19
179
-	 * @return string
180
-	 */
181
-	public function get_object_type() {
182
-		return $this->object_type;
183
-	}
184
-
185
-	/**
186
-	 * Returns the unique ID for this object.
187
-	 *
188
-	 * @since  1.0.19
189
-	 * @return int
190
-	 */
191
-	public function get_id() {
192
-		return $this->id;
193
-	}
194
-
195
-	/**
196
-	 * Get form status.
197
-	 *
198
-	 * @since 1.0.19
199
-	 * @param  string $context View or edit context.
200
-	 * @return string
201
-	 */
202
-	public function get_status( $context = 'view' ) {
203
-		return $this->get_prop( 'status', $context );
204
-    }
205
-
206
-	/**
207
-	 * Delete an object, set the ID to 0, and return result.
208
-	 *
209
-	 * @since  1.0.19
210
-	 * @param  bool $force_delete Should the data be deleted permanently.
211
-	 * @return bool result
212
-	 */
213
-	public function delete( $force_delete = false ) {
214
-		if ( $this->data_store ) {
215
-			$this->data_store->delete( $this, array( 'force_delete' => $force_delete ) );
216
-			$this->set_id( 0 );
217
-			return true;
218
-		}
219
-		return false;
220
-	}
221
-
222
-	/**
223
-	 * Save should create or update based on object existence.
224
-	 *
225
-	 * @since  1.0.19
226
-	 * @return int
227
-	 */
228
-	public function save() {
229
-		if ( ! $this->data_store ) {
230
-			return $this->get_id();
231
-		}
232
-
233
-		/**
234
-		 * Trigger action before saving to the DB. Allows you to adjust object props before save.
235
-		 *
236
-		 * @param GetPaid_Data          $this The object being saved.
237
-		 * @param GetPaid_Data_Store_WP $data_store The data store persisting the data.
238
-		 */
239
-		do_action( 'getpaid_before_' . $this->object_type . '_object_save', $this, $this->data_store );
240
-
241
-		if ( $this->get_id() ) {
242
-			$this->data_store->update( $this );
243
-		} else {
244
-			$this->data_store->create( $this );
245
-		}
246
-
247
-		/**
248
-		 * Trigger action after saving to the DB.
249
-		 *
250
-		 * @param GetPaid_Data          $this The object being saved.
251
-		 * @param GetPaid_Data_Store_WP $data_store The data store persisting the data.
252
-		 */
253
-		do_action( 'getpaid_after_' . $this->object_type . '_object_save', $this, $this->data_store );
254
-
255
-		return $this->get_id();
256
-	}
257
-
258
-	/**
259
-	 * Change data to JSON format.
260
-	 *
261
-	 * @since  1.0.19
262
-	 * @return string Data in JSON format.
263
-	 */
264
-	public function __toString() {
265
-		return wp_json_encode( $this->get_data() );
266
-	}
267
-
268
-	/**
269
-	 * Returns all data for this object.
270
-	 *
271
-	 * @since  1.0.19
272
-	 * @return array
273
-	 */
274
-	public function get_data() {
275
-		return array_merge( array( 'id' => $this->get_id() ), $this->data, array( 'meta_data' => $this->get_meta_data() ) );
276
-	}
277
-
278
-	/**
279
-	 * Returns array of expected data keys for this object.
280
-	 *
281
-	 * @since   1.0.19
282
-	 * @return array
283
-	 */
284
-	public function get_data_keys() {
285
-		return array_keys( $this->data );
286
-	}
287
-
288
-	/**
289
-	 * Returns all "extra" data keys for an object (for sub objects like item types).
290
-	 *
291
-	 * @since  1.0.19
292
-	 * @return array
293
-	 */
294
-	public function get_extra_data_keys() {
295
-		return array_keys( $this->extra_data );
296
-	}
297
-
298
-	/**
299
-	 * Filter null meta values from array.
300
-	 *
301
-	 * @since  1.0.19
302
-	 * @param mixed $meta Meta value to check.
303
-	 * @return bool
304
-	 */
305
-	protected function filter_null_meta( $meta ) {
306
-		return ! is_null( $meta->value );
307
-	}
308
-
309
-	/**
310
-	 * Get All Meta Data.
311
-	 *
312
-	 * @since 1.0.19
313
-	 * @return array of objects.
314
-	 */
315
-	public function get_meta_data() {
316
-		$this->maybe_read_meta_data();
317
-		return array_values( array_filter( $this->meta_data, array( $this, 'filter_null_meta' ) ) );
318
-	}
319
-
320
-	/**
321
-	 * Check if the key is an internal one.
322
-	 *
323
-	 * @since  1.0.19
324
-	 * @param  string $key Key to check.
325
-	 * @return bool   true if it's an internal key, false otherwise
326
-	 */
327
-	protected function is_internal_meta_key( $key ) {
328
-		$internal_meta_key = ! empty( $key ) && $this->data_store && in_array( $key, $this->data_store->get_internal_meta_keys(), true );
329
-
330
-		if ( ! $internal_meta_key ) {
331
-			return false;
332
-		}
333
-
334
-		$has_setter_or_getter = is_callable( array( $this, 'set_' . $key ) ) || is_callable( array( $this, 'get_' . $key ) );
335
-
336
-		if ( ! $has_setter_or_getter ) {
337
-			return false;
338
-		}
339
-
340
-		/* translators: %s: $key Key to check */
341
-		getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Generic add/update/get meta methods should not be used for internal meta data, including "%s". Use getters and setters.', 'getpaid' ), $key ), '1.0.19' );
342
-
343
-		return true;
344
-	}
345
-
346
-	/**
347
-	 * Magic method for setting data fields.
348
-	 *
349
-	 * This method does not update custom fields in the database.
350
-	 *
351
-	 * @since 1.0.19
352
-	 * @access public
353
-	 *
354
-	 */
355
-	public function __set( $key, $value ) {
356
-
357
-		if ( 'id' == strtolower( $key ) ) {
358
-			return $this->set_id( $value );
359
-		}
360
-
361
-		if ( method_exists( $this, "set_$key") ) {
362
-
363
-			/* translators: %s: $key Key to set */
364
-			getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Object data such as "%s" should not be accessed directly. Use getters and setters.', 'getpaid' ), $key ), '1.0.19' );
365
-
366
-			call_user_func( array( $this, "set_$key" ), $value );
367
-		} else {
368
-			$this->set_prop( $key, $value );
369
-		}
370
-
371
-	}
372
-
373
-	/**
24
+    /**
25
+     * ID for this object.
26
+     *
27
+     * @since 1.0.19
28
+     * @var int
29
+     */
30
+    protected $id = 0;
31
+
32
+    /**
33
+     * Core data for this object. Name value pairs (name + default value).
34
+     *
35
+     * @since 1.0.19
36
+     * @var array
37
+     */
38
+    protected $data = array();
39
+
40
+    /**
41
+     * Core data changes for this object.
42
+     *
43
+     * @since 1.0.19
44
+     * @var array
45
+     */
46
+    protected $changes = array();
47
+
48
+    /**
49
+     * This is false until the object is read from the DB.
50
+     *
51
+     * @since 1.0.19
52
+     * @var bool
53
+     */
54
+    protected $object_read = false;
55
+
56
+    /**
57
+     * This is the name of this object type.
58
+     *
59
+     * @since 1.0.19
60
+     * @var string
61
+     */
62
+    protected $object_type = 'data';
63
+
64
+    /**
65
+     * Extra data for this object. Name value pairs (name + default value).
66
+     * Used as a standard way for sub classes (like item types) to add
67
+     * additional information to an inherited class.
68
+     *
69
+     * @since 1.0.19
70
+     * @var array
71
+     */
72
+    protected $extra_data = array();
73
+
74
+    /**
75
+     * Set to _data on construct so we can track and reset data if needed.
76
+     *
77
+     * @since 1.0.19
78
+     * @var array
79
+     */
80
+    protected $default_data = array();
81
+
82
+    /**
83
+     * Contains a reference to the data store for this class.
84
+     *
85
+     * @since 1.0.19
86
+     * @var GetPaid_Data_Store
87
+     */
88
+    protected $data_store;
89
+
90
+    /**
91
+     * Stores meta in cache for future reads.
92
+     * A group must be set to to enable caching.
93
+     *
94
+     * @since 1.0.19
95
+     * @var string
96
+     */
97
+    protected $cache_group = '';
98
+
99
+    /**
100
+     * Stores the last error.
101
+     *
102
+     * @since 1.0.19
103
+     * @var string
104
+     */
105
+    public $last_error = '';
106
+
107
+    /**
108
+     * Stores additional meta data.
109
+     *
110
+     * @since 1.0.19
111
+     * @var array
112
+     */
113
+    protected $meta_data = null;
114
+
115
+    /**
116
+     * Default constructor.
117
+     *
118
+     * @param int|object|array $read ID to load from the DB (optional) or already queried data.
119
+     */
120
+    public function __construct( $read = 0 ) {
121
+        $this->data         = array_merge( $this->data, $this->extra_data );
122
+        $this->default_data = $this->data;
123
+    }
124
+
125
+    /**
126
+     * Only store the object ID to avoid serializing the data object instance.
127
+     *
128
+     * @return array
129
+     */
130
+    public function __sleep() {
131
+        return array( 'id' );
132
+    }
133
+
134
+    /**
135
+     * Re-run the constructor with the object ID.
136
+     *
137
+     * If the object no longer exists, remove the ID.
138
+     */
139
+    public function __wakeup() {
140
+        try {
141
+            $this->__construct( absint( $this->id ) );
142
+        } catch ( Exception $e ) {
143
+            $this->set_id( 0 );
144
+            $this->set_object_read( true );
145
+        }
146
+    }
147
+
148
+    /**
149
+     * When the object is cloned, make sure meta is duplicated correctly.
150
+     *
151
+     * @since 1.0.19
152
+     */
153
+    public function __clone() {
154
+        $this->maybe_read_meta_data();
155
+        if ( ! empty( $this->meta_data ) ) {
156
+            foreach ( $this->meta_data as $array_key => $meta ) {
157
+                $this->meta_data[ $array_key ] = clone $meta;
158
+                if ( ! empty( $meta->id ) ) {
159
+                    $this->meta_data[ $array_key ]->id = null;
160
+                }
161
+            }
162
+        }
163
+    }
164
+
165
+    /**
166
+     * Get the data store.
167
+     *
168
+     * @since  1.0.19
169
+     * @return object
170
+     */
171
+    public function get_data_store() {
172
+        return $this->data_store;
173
+    }
174
+
175
+    /**
176
+     * Get the object type.
177
+     *
178
+     * @since  1.0.19
179
+     * @return string
180
+     */
181
+    public function get_object_type() {
182
+        return $this->object_type;
183
+    }
184
+
185
+    /**
186
+     * Returns the unique ID for this object.
187
+     *
188
+     * @since  1.0.19
189
+     * @return int
190
+     */
191
+    public function get_id() {
192
+        return $this->id;
193
+    }
194
+
195
+    /**
196
+     * Get form status.
197
+     *
198
+     * @since 1.0.19
199
+     * @param  string $context View or edit context.
200
+     * @return string
201
+     */
202
+    public function get_status( $context = 'view' ) {
203
+        return $this->get_prop( 'status', $context );
204
+    }
205
+
206
+    /**
207
+     * Delete an object, set the ID to 0, and return result.
208
+     *
209
+     * @since  1.0.19
210
+     * @param  bool $force_delete Should the data be deleted permanently.
211
+     * @return bool result
212
+     */
213
+    public function delete( $force_delete = false ) {
214
+        if ( $this->data_store ) {
215
+            $this->data_store->delete( $this, array( 'force_delete' => $force_delete ) );
216
+            $this->set_id( 0 );
217
+            return true;
218
+        }
219
+        return false;
220
+    }
221
+
222
+    /**
223
+     * Save should create or update based on object existence.
224
+     *
225
+     * @since  1.0.19
226
+     * @return int
227
+     */
228
+    public function save() {
229
+        if ( ! $this->data_store ) {
230
+            return $this->get_id();
231
+        }
232
+
233
+        /**
234
+         * Trigger action before saving to the DB. Allows you to adjust object props before save.
235
+         *
236
+         * @param GetPaid_Data          $this The object being saved.
237
+         * @param GetPaid_Data_Store_WP $data_store The data store persisting the data.
238
+         */
239
+        do_action( 'getpaid_before_' . $this->object_type . '_object_save', $this, $this->data_store );
240
+
241
+        if ( $this->get_id() ) {
242
+            $this->data_store->update( $this );
243
+        } else {
244
+            $this->data_store->create( $this );
245
+        }
246
+
247
+        /**
248
+         * Trigger action after saving to the DB.
249
+         *
250
+         * @param GetPaid_Data          $this The object being saved.
251
+         * @param GetPaid_Data_Store_WP $data_store The data store persisting the data.
252
+         */
253
+        do_action( 'getpaid_after_' . $this->object_type . '_object_save', $this, $this->data_store );
254
+
255
+        return $this->get_id();
256
+    }
257
+
258
+    /**
259
+     * Change data to JSON format.
260
+     *
261
+     * @since  1.0.19
262
+     * @return string Data in JSON format.
263
+     */
264
+    public function __toString() {
265
+        return wp_json_encode( $this->get_data() );
266
+    }
267
+
268
+    /**
269
+     * Returns all data for this object.
270
+     *
271
+     * @since  1.0.19
272
+     * @return array
273
+     */
274
+    public function get_data() {
275
+        return array_merge( array( 'id' => $this->get_id() ), $this->data, array( 'meta_data' => $this->get_meta_data() ) );
276
+    }
277
+
278
+    /**
279
+     * Returns array of expected data keys for this object.
280
+     *
281
+     * @since   1.0.19
282
+     * @return array
283
+     */
284
+    public function get_data_keys() {
285
+        return array_keys( $this->data );
286
+    }
287
+
288
+    /**
289
+     * Returns all "extra" data keys for an object (for sub objects like item types).
290
+     *
291
+     * @since  1.0.19
292
+     * @return array
293
+     */
294
+    public function get_extra_data_keys() {
295
+        return array_keys( $this->extra_data );
296
+    }
297
+
298
+    /**
299
+     * Filter null meta values from array.
300
+     *
301
+     * @since  1.0.19
302
+     * @param mixed $meta Meta value to check.
303
+     * @return bool
304
+     */
305
+    protected function filter_null_meta( $meta ) {
306
+        return ! is_null( $meta->value );
307
+    }
308
+
309
+    /**
310
+     * Get All Meta Data.
311
+     *
312
+     * @since 1.0.19
313
+     * @return array of objects.
314
+     */
315
+    public function get_meta_data() {
316
+        $this->maybe_read_meta_data();
317
+        return array_values( array_filter( $this->meta_data, array( $this, 'filter_null_meta' ) ) );
318
+    }
319
+
320
+    /**
321
+     * Check if the key is an internal one.
322
+     *
323
+     * @since  1.0.19
324
+     * @param  string $key Key to check.
325
+     * @return bool   true if it's an internal key, false otherwise
326
+     */
327
+    protected function is_internal_meta_key( $key ) {
328
+        $internal_meta_key = ! empty( $key ) && $this->data_store && in_array( $key, $this->data_store->get_internal_meta_keys(), true );
329
+
330
+        if ( ! $internal_meta_key ) {
331
+            return false;
332
+        }
333
+
334
+        $has_setter_or_getter = is_callable( array( $this, 'set_' . $key ) ) || is_callable( array( $this, 'get_' . $key ) );
335
+
336
+        if ( ! $has_setter_or_getter ) {
337
+            return false;
338
+        }
339
+
340
+        /* translators: %s: $key Key to check */
341
+        getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Generic add/update/get meta methods should not be used for internal meta data, including "%s". Use getters and setters.', 'getpaid' ), $key ), '1.0.19' );
342
+
343
+        return true;
344
+    }
345
+
346
+    /**
347
+     * Magic method for setting data fields.
348
+     *
349
+     * This method does not update custom fields in the database.
350
+     *
351
+     * @since 1.0.19
352
+     * @access public
353
+     *
354
+     */
355
+    public function __set( $key, $value ) {
356
+
357
+        if ( 'id' == strtolower( $key ) ) {
358
+            return $this->set_id( $value );
359
+        }
360
+
361
+        if ( method_exists( $this, "set_$key") ) {
362
+
363
+            /* translators: %s: $key Key to set */
364
+            getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Object data such as "%s" should not be accessed directly. Use getters and setters.', 'getpaid' ), $key ), '1.0.19' );
365
+
366
+            call_user_func( array( $this, "set_$key" ), $value );
367
+        } else {
368
+            $this->set_prop( $key, $value );
369
+        }
370
+
371
+    }
372
+
373
+    /**
374 374
      * Margic method for retrieving a property.
375 375
      */
376 376
     public function __get( $key ) {
@@ -378,10 +378,10 @@  discard block
 block discarded – undo
378 378
         // Check if we have a helper method for that.
379 379
         if ( method_exists( $this, 'get_' . $key ) ) {
380 380
 
381
-			if ( 'post_type' != $key ) {
382
-				/* translators: %s: $key Key to set */
383
-				getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Object data such as "%s" should not be accessed directly. Use getters and setters.', 'getpaid' ), $key ), '1.0.19' );
384
-			}
381
+            if ( 'post_type' != $key ) {
382
+                /* translators: %s: $key Key to set */
383
+                getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Object data such as "%s" should not be accessed directly. Use getters and setters.', 'getpaid' ), $key ), '1.0.19' );
384
+            }
385 385
 
386 386
             return call_user_func( array( $this, 'get_' . $key ) );
387 387
         }
@@ -391,564 +391,564 @@  discard block
 block discarded – undo
391 391
             return $this->post->$key;
392 392
         }
393 393
 
394
-		return $this->get_prop( $key );
395
-
396
-    }
397
-
398
-	/**
399
-	 * Get Meta Data by Key.
400
-	 *
401
-	 * @since  1.0.19
402
-	 * @param  string $key Meta Key.
403
-	 * @param  bool   $single return first found meta with key, or all with $key.
404
-	 * @param  string $context What the value is for. Valid values are view and edit.
405
-	 * @return mixed
406
-	 */
407
-	public function get_meta( $key = '', $single = true, $context = 'view' ) {
408
-
409
-		// Check if this is an internal meta key.
410
-		if ( $this->is_internal_meta_key( $key ) ) {
411
-			$function = 'get_' . $key;
412
-
413
-			if ( is_callable( array( $this, $function ) ) ) {
414
-				return $this->{$function}();
415
-			}
416
-		}
417
-
418
-		// Read the meta data if not yet read.
419
-		$this->maybe_read_meta_data();
420
-		$meta_data  = $this->get_meta_data();
421
-		$array_keys = array_keys( wp_list_pluck( $meta_data, 'key' ), $key, true );
422
-		$value      = $single ? '' : array();
423
-
424
-		if ( ! empty( $array_keys ) ) {
425
-			// We don't use the $this->meta_data property directly here because we don't want meta with a null value (i.e. meta which has been deleted via $this->delete_meta_data()).
426
-			if ( $single ) {
427
-				$value = $meta_data[ current( $array_keys ) ]->value;
428
-			} else {
429
-				$value = array_intersect_key( $meta_data, array_flip( $array_keys ) );
430
-			}
431
-		}
432
-
433
-		if ( 'view' === $context ) {
434
-			$value = apply_filters( $this->get_hook_prefix() . $key, $value, $this );
435
-		}
436
-
437
-		return $value;
438
-	}
439
-
440
-	/**
441
-	 * See if meta data exists, since get_meta always returns a '' or array().
442
-	 *
443
-	 * @since  1.0.19
444
-	 * @param  string $key Meta Key.
445
-	 * @return boolean
446
-	 */
447
-	public function meta_exists( $key = '' ) {
448
-		$this->maybe_read_meta_data();
449
-		$array_keys = wp_list_pluck( $this->get_meta_data(), 'key' );
450
-		return in_array( $key, $array_keys, true );
451
-	}
452
-
453
-	/**
454
-	 * Set all meta data from array.
455
-	 *
456
-	 * @since 1.0.19
457
-	 * @param array $data Key/Value pairs.
458
-	 */
459
-	public function set_meta_data( $data ) {
460
-		if ( ! empty( $data ) && is_array( $data ) ) {
461
-			$this->maybe_read_meta_data();
462
-			foreach ( $data as $meta ) {
463
-				$meta = (array) $meta;
464
-				if ( isset( $meta['key'], $meta['value'], $meta['id'] ) ) {
465
-					$this->meta_data[] = new GetPaid_Meta_Data(
466
-						array(
467
-							'id'    => $meta['id'],
468
-							'key'   => $meta['key'],
469
-							'value' => $meta['value'],
470
-						)
471
-					);
472
-				}
473
-			}
474
-		}
475
-	}
476
-
477
-	/**
478
-	 * Add meta data.
479
-	 *
480
-	 * @since 1.0.19
481
-	 *
482
-	 * @param string       $key Meta key.
483
-	 * @param string|array $value Meta value.
484
-	 * @param bool         $unique Should this be a unique key?.
485
-	 */
486
-	public function add_meta_data( $key, $value, $unique = false ) {
487
-		if ( $this->is_internal_meta_key( $key ) ) {
488
-			$function = 'set_' . $key;
489
-
490
-			if ( is_callable( array( $this, $function ) ) ) {
491
-				return $this->{$function}( $value );
492
-			}
493
-		}
494
-
495
-		$this->maybe_read_meta_data();
496
-		if ( $unique ) {
497
-			$this->delete_meta_data( $key );
498
-		}
499
-		$this->meta_data[] = new GetPaid_Meta_Data(
500
-			array(
501
-				'key'   => $key,
502
-				'value' => $value,
503
-			)
504
-		);
505
-	}
506
-
507
-	/**
508
-	 * Update meta data by key or ID, if provided.
509
-	 *
510
-	 * @since  1.0.19
511
-	 *
512
-	 * @param  string       $key Meta key.
513
-	 * @param  string|array $value Meta value.
514
-	 * @param  int          $meta_id Meta ID.
515
-	 */
516
-	public function update_meta_data( $key, $value, $meta_id = 0 ) {
517
-		if ( $this->is_internal_meta_key( $key ) ) {
518
-			$function = 'set_' . $key;
519
-
520
-			if ( is_callable( array( $this, $function ) ) ) {
521
-				return $this->{$function}( $value );
522
-			}
523
-		}
524
-
525
-		$this->maybe_read_meta_data();
526
-
527
-		$array_key = false;
528
-
529
-		if ( $meta_id ) {
530
-			$array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), $meta_id, true );
531
-			$array_key  = $array_keys ? current( $array_keys ) : false;
532
-		} else {
533
-			// Find matches by key.
534
-			$matches = array();
535
-			foreach ( $this->meta_data as $meta_data_array_key => $meta ) {
536
-				if ( $meta->key === $key ) {
537
-					$matches[] = $meta_data_array_key;
538
-				}
539
-			}
540
-
541
-			if ( ! empty( $matches ) ) {
542
-				// Set matches to null so only one key gets the new value.
543
-				foreach ( $matches as $meta_data_array_key ) {
544
-					$this->meta_data[ $meta_data_array_key ]->value = null;
545
-				}
546
-				$array_key = current( $matches );
547
-			}
548
-		}
549
-
550
-		if ( false !== $array_key ) {
551
-			$meta        = $this->meta_data[ $array_key ];
552
-			$meta->key   = $key;
553
-			$meta->value = $value;
554
-		} else {
555
-			$this->add_meta_data( $key, $value, true );
556
-		}
557
-	}
558
-
559
-	/**
560
-	 * Delete meta data.
561
-	 *
562
-	 * @since 1.0.19
563
-	 * @param string $key Meta key.
564
-	 */
565
-	public function delete_meta_data( $key ) {
566
-		$this->maybe_read_meta_data();
567
-		$array_keys = array_keys( wp_list_pluck( $this->meta_data, 'key' ), $key, true );
568
-
569
-		if ( $array_keys ) {
570
-			foreach ( $array_keys as $array_key ) {
571
-				$this->meta_data[ $array_key ]->value = null;
572
-			}
573
-		}
574
-	}
575
-
576
-	/**
577
-	 * Delete meta data.
578
-	 *
579
-	 * @since 1.0.19
580
-	 * @param int $mid Meta ID.
581
-	 */
582
-	public function delete_meta_data_by_mid( $mid ) {
583
-		$this->maybe_read_meta_data();
584
-		$array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), (int) $mid, true );
585
-
586
-		if ( $array_keys ) {
587
-			foreach ( $array_keys as $array_key ) {
588
-				$this->meta_data[ $array_key ]->value = null;
589
-			}
590
-		}
591
-	}
592
-
593
-	/**
594
-	 * Read meta data if null.
595
-	 *
596
-	 * @since 1.0.19
597
-	 */
598
-	protected function maybe_read_meta_data() {
599
-		if ( is_null( $this->meta_data ) ) {
600
-			$this->read_meta_data();
601
-		}
602
-	}
603
-
604
-	/**
605
-	 * Read Meta Data from the database. Ignore any internal properties.
606
-	 * Uses it's own caches because get_metadata does not provide meta_ids.
607
-	 *
608
-	 * @since 1.0.19
609
-	 * @param bool $force_read True to force a new DB read (and update cache).
610
-	 */
611
-	public function read_meta_data( $force_read = false ) {
612
-		$this->meta_data = array();
613
-		$cache_loaded    = false;
614
-
615
-		if ( ! $this->get_id() ) {
616
-			return;
617
-		}
618
-
619
-		if ( ! $this->data_store ) {
620
-			return;
621
-		}
622
-
623
-		if ( ! empty( $this->cache_group ) ) {
624
-			$cache_key = GetPaid_Cache_Helper::get_cache_prefix( $this->cache_group ) . GetPaid_Cache_Helper::get_cache_prefix( 'object_' . $this->get_id() ) . 'object_meta_' . $this->get_id();
625
-		}
626
-
627
-		if ( ! $force_read ) {
628
-			if ( ! empty( $this->cache_group ) ) {
629
-				$cached_meta  = wp_cache_get( $cache_key, $this->cache_group );
630
-				$cache_loaded = ! empty( $cached_meta );
631
-			}
632
-		}
633
-
634
-		$raw_meta_data = $cache_loaded ? $cached_meta : $this->data_store->read_meta( $this );
635
-		if ( $raw_meta_data ) {
636
-			foreach ( $raw_meta_data as $meta ) {
637
-				$this->meta_data[] = new GetPaid_Meta_Data(
638
-					array(
639
-						'id'    => (int) $meta->meta_id,
640
-						'key'   => $meta->meta_key,
641
-						'value' => maybe_unserialize( $meta->meta_value ),
642
-					)
643
-				);
644
-			}
645
-
646
-			if ( ! $cache_loaded && ! empty( $this->cache_group ) ) {
647
-				wp_cache_set( $cache_key, $raw_meta_data, $this->cache_group );
648
-			}
649
-		}
650
-	}
651
-
652
-	/**
653
-	 * Update Meta Data in the database.
654
-	 *
655
-	 * @since 1.0.19
656
-	 */
657
-	public function save_meta_data() {
658
-		if ( ! $this->data_store || is_null( $this->meta_data ) ) {
659
-			return;
660
-		}
661
-		foreach ( $this->meta_data as $array_key => $meta ) {
662
-			if ( is_null( $meta->value ) ) {
663
-				if ( ! empty( $meta->id ) ) {
664
-					$this->data_store->delete_meta( $this, $meta );
665
-					unset( $this->meta_data[ $array_key ] );
666
-				}
667
-			} elseif ( empty( $meta->id ) ) {
668
-				$meta->id = $this->data_store->add_meta( $this, $meta );
669
-				$meta->apply_changes();
670
-			} else {
671
-				if ( $meta->get_changes() ) {
672
-					$this->data_store->update_meta( $this, $meta );
673
-					$meta->apply_changes();
674
-				}
675
-			}
676
-		}
677
-		if ( ! empty( $this->cache_group ) ) {
678
-			$cache_key = GetPaid_Cache_Helper::get_cache_prefix( $this->cache_group ) . GetPaid_Cache_Helper::get_cache_prefix( 'object_' . $this->get_id() ) . 'object_meta_' . $this->get_id();
679
-			wp_cache_delete( $cache_key, $this->cache_group );
680
-		}
681
-	}
682
-
683
-	/**
684
-	 * Set ID.
685
-	 *
686
-	 * @since 1.0.19
687
-	 * @param int $id ID.
688
-	 */
689
-	public function set_id( $id ) {
690
-		$this->id = absint( $id );
691
-	}
692
-
693
-	/**
694
-	 * Sets item status.
695
-	 *
696
-	 * @since 1.0.19
697
-	 * @param string $status New status.
698
-	 * @return array details of change.
699
-	 */
700
-	public function set_status( $status ) {
394
+        return $this->get_prop( $key );
395
+
396
+    }
397
+
398
+    /**
399
+     * Get Meta Data by Key.
400
+     *
401
+     * @since  1.0.19
402
+     * @param  string $key Meta Key.
403
+     * @param  bool   $single return first found meta with key, or all with $key.
404
+     * @param  string $context What the value is for. Valid values are view and edit.
405
+     * @return mixed
406
+     */
407
+    public function get_meta( $key = '', $single = true, $context = 'view' ) {
408
+
409
+        // Check if this is an internal meta key.
410
+        if ( $this->is_internal_meta_key( $key ) ) {
411
+            $function = 'get_' . $key;
412
+
413
+            if ( is_callable( array( $this, $function ) ) ) {
414
+                return $this->{$function}();
415
+            }
416
+        }
417
+
418
+        // Read the meta data if not yet read.
419
+        $this->maybe_read_meta_data();
420
+        $meta_data  = $this->get_meta_data();
421
+        $array_keys = array_keys( wp_list_pluck( $meta_data, 'key' ), $key, true );
422
+        $value      = $single ? '' : array();
423
+
424
+        if ( ! empty( $array_keys ) ) {
425
+            // We don't use the $this->meta_data property directly here because we don't want meta with a null value (i.e. meta which has been deleted via $this->delete_meta_data()).
426
+            if ( $single ) {
427
+                $value = $meta_data[ current( $array_keys ) ]->value;
428
+            } else {
429
+                $value = array_intersect_key( $meta_data, array_flip( $array_keys ) );
430
+            }
431
+        }
432
+
433
+        if ( 'view' === $context ) {
434
+            $value = apply_filters( $this->get_hook_prefix() . $key, $value, $this );
435
+        }
436
+
437
+        return $value;
438
+    }
439
+
440
+    /**
441
+     * See if meta data exists, since get_meta always returns a '' or array().
442
+     *
443
+     * @since  1.0.19
444
+     * @param  string $key Meta Key.
445
+     * @return boolean
446
+     */
447
+    public function meta_exists( $key = '' ) {
448
+        $this->maybe_read_meta_data();
449
+        $array_keys = wp_list_pluck( $this->get_meta_data(), 'key' );
450
+        return in_array( $key, $array_keys, true );
451
+    }
452
+
453
+    /**
454
+     * Set all meta data from array.
455
+     *
456
+     * @since 1.0.19
457
+     * @param array $data Key/Value pairs.
458
+     */
459
+    public function set_meta_data( $data ) {
460
+        if ( ! empty( $data ) && is_array( $data ) ) {
461
+            $this->maybe_read_meta_data();
462
+            foreach ( $data as $meta ) {
463
+                $meta = (array) $meta;
464
+                if ( isset( $meta['key'], $meta['value'], $meta['id'] ) ) {
465
+                    $this->meta_data[] = new GetPaid_Meta_Data(
466
+                        array(
467
+                            'id'    => $meta['id'],
468
+                            'key'   => $meta['key'],
469
+                            'value' => $meta['value'],
470
+                        )
471
+                    );
472
+                }
473
+            }
474
+        }
475
+    }
476
+
477
+    /**
478
+     * Add meta data.
479
+     *
480
+     * @since 1.0.19
481
+     *
482
+     * @param string       $key Meta key.
483
+     * @param string|array $value Meta value.
484
+     * @param bool         $unique Should this be a unique key?.
485
+     */
486
+    public function add_meta_data( $key, $value, $unique = false ) {
487
+        if ( $this->is_internal_meta_key( $key ) ) {
488
+            $function = 'set_' . $key;
489
+
490
+            if ( is_callable( array( $this, $function ) ) ) {
491
+                return $this->{$function}( $value );
492
+            }
493
+        }
494
+
495
+        $this->maybe_read_meta_data();
496
+        if ( $unique ) {
497
+            $this->delete_meta_data( $key );
498
+        }
499
+        $this->meta_data[] = new GetPaid_Meta_Data(
500
+            array(
501
+                'key'   => $key,
502
+                'value' => $value,
503
+            )
504
+        );
505
+    }
506
+
507
+    /**
508
+     * Update meta data by key or ID, if provided.
509
+     *
510
+     * @since  1.0.19
511
+     *
512
+     * @param  string       $key Meta key.
513
+     * @param  string|array $value Meta value.
514
+     * @param  int          $meta_id Meta ID.
515
+     */
516
+    public function update_meta_data( $key, $value, $meta_id = 0 ) {
517
+        if ( $this->is_internal_meta_key( $key ) ) {
518
+            $function = 'set_' . $key;
519
+
520
+            if ( is_callable( array( $this, $function ) ) ) {
521
+                return $this->{$function}( $value );
522
+            }
523
+        }
524
+
525
+        $this->maybe_read_meta_data();
526
+
527
+        $array_key = false;
528
+
529
+        if ( $meta_id ) {
530
+            $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), $meta_id, true );
531
+            $array_key  = $array_keys ? current( $array_keys ) : false;
532
+        } else {
533
+            // Find matches by key.
534
+            $matches = array();
535
+            foreach ( $this->meta_data as $meta_data_array_key => $meta ) {
536
+                if ( $meta->key === $key ) {
537
+                    $matches[] = $meta_data_array_key;
538
+                }
539
+            }
540
+
541
+            if ( ! empty( $matches ) ) {
542
+                // Set matches to null so only one key gets the new value.
543
+                foreach ( $matches as $meta_data_array_key ) {
544
+                    $this->meta_data[ $meta_data_array_key ]->value = null;
545
+                }
546
+                $array_key = current( $matches );
547
+            }
548
+        }
549
+
550
+        if ( false !== $array_key ) {
551
+            $meta        = $this->meta_data[ $array_key ];
552
+            $meta->key   = $key;
553
+            $meta->value = $value;
554
+        } else {
555
+            $this->add_meta_data( $key, $value, true );
556
+        }
557
+    }
558
+
559
+    /**
560
+     * Delete meta data.
561
+     *
562
+     * @since 1.0.19
563
+     * @param string $key Meta key.
564
+     */
565
+    public function delete_meta_data( $key ) {
566
+        $this->maybe_read_meta_data();
567
+        $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'key' ), $key, true );
568
+
569
+        if ( $array_keys ) {
570
+            foreach ( $array_keys as $array_key ) {
571
+                $this->meta_data[ $array_key ]->value = null;
572
+            }
573
+        }
574
+    }
575
+
576
+    /**
577
+     * Delete meta data.
578
+     *
579
+     * @since 1.0.19
580
+     * @param int $mid Meta ID.
581
+     */
582
+    public function delete_meta_data_by_mid( $mid ) {
583
+        $this->maybe_read_meta_data();
584
+        $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), (int) $mid, true );
585
+
586
+        if ( $array_keys ) {
587
+            foreach ( $array_keys as $array_key ) {
588
+                $this->meta_data[ $array_key ]->value = null;
589
+            }
590
+        }
591
+    }
592
+
593
+    /**
594
+     * Read meta data if null.
595
+     *
596
+     * @since 1.0.19
597
+     */
598
+    protected function maybe_read_meta_data() {
599
+        if ( is_null( $this->meta_data ) ) {
600
+            $this->read_meta_data();
601
+        }
602
+    }
603
+
604
+    /**
605
+     * Read Meta Data from the database. Ignore any internal properties.
606
+     * Uses it's own caches because get_metadata does not provide meta_ids.
607
+     *
608
+     * @since 1.0.19
609
+     * @param bool $force_read True to force a new DB read (and update cache).
610
+     */
611
+    public function read_meta_data( $force_read = false ) {
612
+        $this->meta_data = array();
613
+        $cache_loaded    = false;
614
+
615
+        if ( ! $this->get_id() ) {
616
+            return;
617
+        }
618
+
619
+        if ( ! $this->data_store ) {
620
+            return;
621
+        }
622
+
623
+        if ( ! empty( $this->cache_group ) ) {
624
+            $cache_key = GetPaid_Cache_Helper::get_cache_prefix( $this->cache_group ) . GetPaid_Cache_Helper::get_cache_prefix( 'object_' . $this->get_id() ) . 'object_meta_' . $this->get_id();
625
+        }
626
+
627
+        if ( ! $force_read ) {
628
+            if ( ! empty( $this->cache_group ) ) {
629
+                $cached_meta  = wp_cache_get( $cache_key, $this->cache_group );
630
+                $cache_loaded = ! empty( $cached_meta );
631
+            }
632
+        }
633
+
634
+        $raw_meta_data = $cache_loaded ? $cached_meta : $this->data_store->read_meta( $this );
635
+        if ( $raw_meta_data ) {
636
+            foreach ( $raw_meta_data as $meta ) {
637
+                $this->meta_data[] = new GetPaid_Meta_Data(
638
+                    array(
639
+                        'id'    => (int) $meta->meta_id,
640
+                        'key'   => $meta->meta_key,
641
+                        'value' => maybe_unserialize( $meta->meta_value ),
642
+                    )
643
+                );
644
+            }
645
+
646
+            if ( ! $cache_loaded && ! empty( $this->cache_group ) ) {
647
+                wp_cache_set( $cache_key, $raw_meta_data, $this->cache_group );
648
+            }
649
+        }
650
+    }
651
+
652
+    /**
653
+     * Update Meta Data in the database.
654
+     *
655
+     * @since 1.0.19
656
+     */
657
+    public function save_meta_data() {
658
+        if ( ! $this->data_store || is_null( $this->meta_data ) ) {
659
+            return;
660
+        }
661
+        foreach ( $this->meta_data as $array_key => $meta ) {
662
+            if ( is_null( $meta->value ) ) {
663
+                if ( ! empty( $meta->id ) ) {
664
+                    $this->data_store->delete_meta( $this, $meta );
665
+                    unset( $this->meta_data[ $array_key ] );
666
+                }
667
+            } elseif ( empty( $meta->id ) ) {
668
+                $meta->id = $this->data_store->add_meta( $this, $meta );
669
+                $meta->apply_changes();
670
+            } else {
671
+                if ( $meta->get_changes() ) {
672
+                    $this->data_store->update_meta( $this, $meta );
673
+                    $meta->apply_changes();
674
+                }
675
+            }
676
+        }
677
+        if ( ! empty( $this->cache_group ) ) {
678
+            $cache_key = GetPaid_Cache_Helper::get_cache_prefix( $this->cache_group ) . GetPaid_Cache_Helper::get_cache_prefix( 'object_' . $this->get_id() ) . 'object_meta_' . $this->get_id();
679
+            wp_cache_delete( $cache_key, $this->cache_group );
680
+        }
681
+    }
682
+
683
+    /**
684
+     * Set ID.
685
+     *
686
+     * @since 1.0.19
687
+     * @param int $id ID.
688
+     */
689
+    public function set_id( $id ) {
690
+        $this->id = absint( $id );
691
+    }
692
+
693
+    /**
694
+     * Sets item status.
695
+     *
696
+     * @since 1.0.19
697
+     * @param string $status New status.
698
+     * @return array details of change.
699
+     */
700
+    public function set_status( $status ) {
701 701
         $old_status = $this->get_status();
702 702
 
703
-		$this->set_prop( 'status', $status );
704
-
705
-		return array(
706
-			'from' => $old_status,
707
-			'to'   => $status,
708
-		);
709
-    }
710
-
711
-	/**
712
-	 * Set all props to default values.
713
-	 *
714
-	 * @since 1.0.19
715
-	 */
716
-	public function set_defaults() {
717
-		$this->data    = $this->default_data;
718
-		$this->changes = array();
719
-		$this->set_object_read( false );
720
-	}
721
-
722
-	/**
723
-	 * Set object read property.
724
-	 *
725
-	 * @since 1.0.19
726
-	 * @param boolean $read Should read?.
727
-	 */
728
-	public function set_object_read( $read = true ) {
729
-		$this->object_read = (bool) $read;
730
-	}
731
-
732
-	/**
733
-	 * Get object read property.
734
-	 *
735
-	 * @since  1.0.19
736
-	 * @return boolean
737
-	 */
738
-	public function get_object_read() {
739
-		return (bool) $this->object_read;
740
-	}
741
-
742
-	/**
743
-	 * Set a collection of props in one go, collect any errors, and return the result.
744
-	 * Only sets using public methods.
745
-	 *
746
-	 * @since  1.0.19
747
-	 *
748
-	 * @param array  $props Key value pairs to set. Key is the prop and should map to a setter function name.
749
-	 * @param string $context In what context to run this.
750
-	 *
751
-	 * @return bool|WP_Error
752
-	 */
753
-	public function set_props( $props, $context = 'set' ) {
754
-		$errors = false;
755
-
756
-		foreach ( $props as $prop => $value ) {
757
-			try {
758
-				/**
759
-				 * Checks if the prop being set is allowed, and the value is not null.
760
-				 */
761
-				if ( is_null( $value ) || in_array( $prop, array( 'prop', 'date_prop', 'meta_data' ), true ) ) {
762
-					continue;
763
-				}
764
-				$setter = "set_$prop";
765
-
766
-				if ( is_callable( array( $this, $setter ) ) ) {
767
-					$this->{$setter}( $value );
768
-				}
769
-			} catch ( Exception $e ) {
770
-				if ( ! $errors ) {
771
-					$errors = new WP_Error();
772
-				}
773
-				$errors->add( $e->getCode(), $e->getMessage() );
774
-				$this->last_error = $e->getMessage();
775
-			}
776
-		}
777
-
778
-		return $errors && count( $errors->get_error_codes() ) ? $errors : true;
779
-	}
780
-
781
-	/**
782
-	 * Sets a prop for a setter method.
783
-	 *
784
-	 * This stores changes in a special array so we can track what needs saving
785
-	 * the the DB later.
786
-	 *
787
-	 * @since 1.0.19
788
-	 * @param string $prop Name of prop to set.
789
-	 * @param mixed  $value Value of the prop.
790
-	 */
791
-	protected function set_prop( $prop, $value ) {
792
-		if ( array_key_exists( $prop, $this->data ) ) {
793
-			if ( true === $this->object_read ) {
794
-				if ( $value !== $this->data[ $prop ] || array_key_exists( $prop, $this->changes ) ) {
795
-					$this->changes[ $prop ] = $value;
796
-				}
797
-			} else {
798
-				$this->data[ $prop ] = $value;
799
-			}
800
-		}
801
-	}
802
-
803
-	/**
804
-	 * Return data changes only.
805
-	 *
806
-	 * @since 1.0.19
807
-	 * @return array
808
-	 */
809
-	public function get_changes() {
810
-		return $this->changes;
811
-	}
812
-
813
-	/**
814
-	 * Merge changes with data and clear.
815
-	 *
816
-	 * @since 1.0.19
817
-	 */
818
-	public function apply_changes() {
819
-		$this->data    = array_replace_recursive( $this->data, $this->changes );
820
-		$this->changes = array();
821
-	}
822
-
823
-	/**
824
-	 * Prefix for action and filter hooks on data.
825
-	 *
826
-	 * @since  1.0.19
827
-	 * @return string
828
-	 */
829
-	protected function get_hook_prefix() {
830
-		return 'wpinv_get_' . $this->object_type . '_';
831
-	}
832
-
833
-	/**
834
-	 * Gets a prop for a getter method.
835
-	 *
836
-	 * Gets the value from either current pending changes, or the data itself.
837
-	 * Context controls what happens to the value before it's returned.
838
-	 *
839
-	 * @since  1.0.19
840
-	 * @param  string $prop Name of prop to get.
841
-	 * @param  string $context What the value is for. Valid values are view and edit.
842
-	 * @return mixed
843
-	 */
844
-	protected function get_prop( $prop, $context = 'view' ) {
845
-		$value = null;
846
-
847
-		if ( array_key_exists( $prop, $this->data ) ) {
848
-			$value = array_key_exists( $prop, $this->changes ) ? $this->changes[ $prop ] : $this->data[ $prop ];
849
-
850
-			if ( 'view' === $context ) {
851
-				$value = apply_filters( $this->get_hook_prefix() . $prop, $value, $this );
852
-			}
853
-		}
854
-
855
-		return $value;
856
-	}
857
-
858
-	/**
859
-	 * Sets a date prop whilst handling formatting and datetime objects.
860
-	 *
861
-	 * @since 1.0.19
862
-	 * @param string         $prop Name of prop to set.
863
-	 * @param string|integer $value Value of the prop.
864
-	 */
865
-	protected function set_date_prop( $prop, $value ) {
866
-
867
-		if ( empty( $value ) ) {
868
-			$this->set_prop( $prop, null );
869
-			return;
870
-		}
871
-		$this->set_prop( $prop, $value );
872
-
873
-	}
874
-
875
-	/**
876
-	 * When invalid data is found, throw an exception unless reading from the DB.
877
-	 *
878
-	 * @throws Exception Data Exception.
879
-	 * @since 1.0.19
880
-	 * @param string $code             Error code.
881
-	 * @param string $message          Error message.
882
-	 */
883
-	protected function error( $code, $message ) {
884
-		throw new Exception( $message, $code );
885
-	}
886
-
887
-	/**
888
-	 * Handle the status transition.
889
-	 */
890
-	protected function status_transition() {
891
-		$status_transition = $this->status_transition;
892
-
893
-		// Reset status transition variable.
894
-		$this->status_transition = false;
895
-
896
-		if ( $status_transition ) {
897
-			try {
898
-
899
-				$object = $this->object_type;
900
-
901
-				if ( 'invoice' == $object ) {
902
-					$this->get_type();
903
-				}
904
-
905
-				do_action( "wpinv_{$object}_status_" . $status_transition['to'], $this->get_id(), $this );
906
-
907
-				if ( ! empty( $status_transition['from'] ) ) {
908
-					/* translators: 1: old status 2: new status */
909
-					$transition_note = sprintf( __( 'Order status changed from %1$s to %2$s.', 'woocommerce' ), wc_get_order_status_name( $status_transition['from'] ), wc_get_order_status_name( $status_transition['to'] ) );
910
-
911
-					// Note the transition occurred.
912
-					$this->add_status_transition_note( $transition_note, $status_transition );
913
-
914
-					do_action( 'woocommerce_order_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this );
915
-					do_action( 'woocommerce_order_status_changed', $this->get_id(), $status_transition['from'], $status_transition['to'], $this );
916
-
917
-					// Work out if this was for a payment, and trigger a payment_status hook instead.
918
-					if (
919
-						in_array( $status_transition['from'], apply_filters( 'woocommerce_valid_order_statuses_for_payment', array( 'pending', 'failed' ), $this ), true )
920
-						&& in_array( $status_transition['to'], wc_get_is_paid_statuses(), true )
921
-					) {
922
-						/**
923
-						 * Fires when the order progresses from a pending payment status to a paid one.
924
-						 *
925
-						 * @since 3.9.0
926
-						 * @param int Order ID
927
-						 * @param WC_Order Order object
928
-						 */
929
-						do_action( 'woocommerce_order_payment_status_changed', $this->get_id(), $this );
930
-					}
931
-				} else {
932
-					/* translators: %s: new order status */
933
-					$transition_note = sprintf( __( 'Order status set to %s.', 'woocommerce' ), wc_get_order_status_name( $status_transition['to'] ) );
934
-
935
-					// Note the transition occurred.
936
-					$this->add_status_transition_note( $transition_note, $status_transition );
937
-				}
938
-			} catch ( Exception $e ) {
939
-				$logger = wc_get_logger();
940
-				$logger->error(
941
-					sprintf(
942
-						'Status transition of order #%d errored!',
943
-						$this->get_id()
944
-					),
945
-					array(
946
-						'order' => $this,
947
-						'error' => $e,
948
-					)
949
-				);
950
-				$this->add_order_note( __( 'Error during status transition.', 'woocommerce' ) . ' ' . $e->getMessage() );
951
-			}
952
-		}
953
-	}
703
+        $this->set_prop( 'status', $status );
704
+
705
+        return array(
706
+            'from' => $old_status,
707
+            'to'   => $status,
708
+        );
709
+    }
710
+
711
+    /**
712
+     * Set all props to default values.
713
+     *
714
+     * @since 1.0.19
715
+     */
716
+    public function set_defaults() {
717
+        $this->data    = $this->default_data;
718
+        $this->changes = array();
719
+        $this->set_object_read( false );
720
+    }
721
+
722
+    /**
723
+     * Set object read property.
724
+     *
725
+     * @since 1.0.19
726
+     * @param boolean $read Should read?.
727
+     */
728
+    public function set_object_read( $read = true ) {
729
+        $this->object_read = (bool) $read;
730
+    }
731
+
732
+    /**
733
+     * Get object read property.
734
+     *
735
+     * @since  1.0.19
736
+     * @return boolean
737
+     */
738
+    public function get_object_read() {
739
+        return (bool) $this->object_read;
740
+    }
741
+
742
+    /**
743
+     * Set a collection of props in one go, collect any errors, and return the result.
744
+     * Only sets using public methods.
745
+     *
746
+     * @since  1.0.19
747
+     *
748
+     * @param array  $props Key value pairs to set. Key is the prop and should map to a setter function name.
749
+     * @param string $context In what context to run this.
750
+     *
751
+     * @return bool|WP_Error
752
+     */
753
+    public function set_props( $props, $context = 'set' ) {
754
+        $errors = false;
755
+
756
+        foreach ( $props as $prop => $value ) {
757
+            try {
758
+                /**
759
+                 * Checks if the prop being set is allowed, and the value is not null.
760
+                 */
761
+                if ( is_null( $value ) || in_array( $prop, array( 'prop', 'date_prop', 'meta_data' ), true ) ) {
762
+                    continue;
763
+                }
764
+                $setter = "set_$prop";
765
+
766
+                if ( is_callable( array( $this, $setter ) ) ) {
767
+                    $this->{$setter}( $value );
768
+                }
769
+            } catch ( Exception $e ) {
770
+                if ( ! $errors ) {
771
+                    $errors = new WP_Error();
772
+                }
773
+                $errors->add( $e->getCode(), $e->getMessage() );
774
+                $this->last_error = $e->getMessage();
775
+            }
776
+        }
777
+
778
+        return $errors && count( $errors->get_error_codes() ) ? $errors : true;
779
+    }
780
+
781
+    /**
782
+     * Sets a prop for a setter method.
783
+     *
784
+     * This stores changes in a special array so we can track what needs saving
785
+     * the the DB later.
786
+     *
787
+     * @since 1.0.19
788
+     * @param string $prop Name of prop to set.
789
+     * @param mixed  $value Value of the prop.
790
+     */
791
+    protected function set_prop( $prop, $value ) {
792
+        if ( array_key_exists( $prop, $this->data ) ) {
793
+            if ( true === $this->object_read ) {
794
+                if ( $value !== $this->data[ $prop ] || array_key_exists( $prop, $this->changes ) ) {
795
+                    $this->changes[ $prop ] = $value;
796
+                }
797
+            } else {
798
+                $this->data[ $prop ] = $value;
799
+            }
800
+        }
801
+    }
802
+
803
+    /**
804
+     * Return data changes only.
805
+     *
806
+     * @since 1.0.19
807
+     * @return array
808
+     */
809
+    public function get_changes() {
810
+        return $this->changes;
811
+    }
812
+
813
+    /**
814
+     * Merge changes with data and clear.
815
+     *
816
+     * @since 1.0.19
817
+     */
818
+    public function apply_changes() {
819
+        $this->data    = array_replace_recursive( $this->data, $this->changes );
820
+        $this->changes = array();
821
+    }
822
+
823
+    /**
824
+     * Prefix for action and filter hooks on data.
825
+     *
826
+     * @since  1.0.19
827
+     * @return string
828
+     */
829
+    protected function get_hook_prefix() {
830
+        return 'wpinv_get_' . $this->object_type . '_';
831
+    }
832
+
833
+    /**
834
+     * Gets a prop for a getter method.
835
+     *
836
+     * Gets the value from either current pending changes, or the data itself.
837
+     * Context controls what happens to the value before it's returned.
838
+     *
839
+     * @since  1.0.19
840
+     * @param  string $prop Name of prop to get.
841
+     * @param  string $context What the value is for. Valid values are view and edit.
842
+     * @return mixed
843
+     */
844
+    protected function get_prop( $prop, $context = 'view' ) {
845
+        $value = null;
846
+
847
+        if ( array_key_exists( $prop, $this->data ) ) {
848
+            $value = array_key_exists( $prop, $this->changes ) ? $this->changes[ $prop ] : $this->data[ $prop ];
849
+
850
+            if ( 'view' === $context ) {
851
+                $value = apply_filters( $this->get_hook_prefix() . $prop, $value, $this );
852
+            }
853
+        }
854
+
855
+        return $value;
856
+    }
857
+
858
+    /**
859
+     * Sets a date prop whilst handling formatting and datetime objects.
860
+     *
861
+     * @since 1.0.19
862
+     * @param string         $prop Name of prop to set.
863
+     * @param string|integer $value Value of the prop.
864
+     */
865
+    protected function set_date_prop( $prop, $value ) {
866
+
867
+        if ( empty( $value ) ) {
868
+            $this->set_prop( $prop, null );
869
+            return;
870
+        }
871
+        $this->set_prop( $prop, $value );
872
+
873
+    }
874
+
875
+    /**
876
+     * When invalid data is found, throw an exception unless reading from the DB.
877
+     *
878
+     * @throws Exception Data Exception.
879
+     * @since 1.0.19
880
+     * @param string $code             Error code.
881
+     * @param string $message          Error message.
882
+     */
883
+    protected function error( $code, $message ) {
884
+        throw new Exception( $message, $code );
885
+    }
886
+
887
+    /**
888
+     * Handle the status transition.
889
+     */
890
+    protected function status_transition() {
891
+        $status_transition = $this->status_transition;
892
+
893
+        // Reset status transition variable.
894
+        $this->status_transition = false;
895
+
896
+        if ( $status_transition ) {
897
+            try {
898
+
899
+                $object = $this->object_type;
900
+
901
+                if ( 'invoice' == $object ) {
902
+                    $this->get_type();
903
+                }
904
+
905
+                do_action( "wpinv_{$object}_status_" . $status_transition['to'], $this->get_id(), $this );
906
+
907
+                if ( ! empty( $status_transition['from'] ) ) {
908
+                    /* translators: 1: old status 2: new status */
909
+                    $transition_note = sprintf( __( 'Order status changed from %1$s to %2$s.', 'woocommerce' ), wc_get_order_status_name( $status_transition['from'] ), wc_get_order_status_name( $status_transition['to'] ) );
910
+
911
+                    // Note the transition occurred.
912
+                    $this->add_status_transition_note( $transition_note, $status_transition );
913
+
914
+                    do_action( 'woocommerce_order_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this );
915
+                    do_action( 'woocommerce_order_status_changed', $this->get_id(), $status_transition['from'], $status_transition['to'], $this );
916
+
917
+                    // Work out if this was for a payment, and trigger a payment_status hook instead.
918
+                    if (
919
+                        in_array( $status_transition['from'], apply_filters( 'woocommerce_valid_order_statuses_for_payment', array( 'pending', 'failed' ), $this ), true )
920
+                        && in_array( $status_transition['to'], wc_get_is_paid_statuses(), true )
921
+                    ) {
922
+                        /**
923
+                         * Fires when the order progresses from a pending payment status to a paid one.
924
+                         *
925
+                         * @since 3.9.0
926
+                         * @param int Order ID
927
+                         * @param WC_Order Order object
928
+                         */
929
+                        do_action( 'woocommerce_order_payment_status_changed', $this->get_id(), $this );
930
+                    }
931
+                } else {
932
+                    /* translators: %s: new order status */
933
+                    $transition_note = sprintf( __( 'Order status set to %s.', 'woocommerce' ), wc_get_order_status_name( $status_transition['to'] ) );
934
+
935
+                    // Note the transition occurred.
936
+                    $this->add_status_transition_note( $transition_note, $status_transition );
937
+                }
938
+            } catch ( Exception $e ) {
939
+                $logger = wc_get_logger();
940
+                $logger->error(
941
+                    sprintf(
942
+                        'Status transition of order #%d errored!',
943
+                        $this->get_id()
944
+                    ),
945
+                    array(
946
+                        'order' => $this,
947
+                        'error' => $e,
948
+                    )
949
+                );
950
+                $this->add_order_note( __( 'Error during status transition.', 'woocommerce' ) . ' ' . $e->getMessage() );
951
+            }
952
+        }
953
+    }
954 954
 }
Please login to merge, or discard this patch.
Spacing   +178 added lines, -178 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
  *
9 9
  */
10 10
 
11
-if ( ! defined( 'ABSPATH' ) ) {
11
+if (!defined('ABSPATH')) {
12 12
 	exit;
13 13
 }
14 14
 
@@ -117,8 +117,8 @@  discard block
 block discarded – undo
117 117
 	 *
118 118
 	 * @param int|object|array $read ID to load from the DB (optional) or already queried data.
119 119
 	 */
120
-	public function __construct( $read = 0 ) {
121
-		$this->data         = array_merge( $this->data, $this->extra_data );
120
+	public function __construct($read = 0) {
121
+		$this->data         = array_merge($this->data, $this->extra_data);
122 122
 		$this->default_data = $this->data;
123 123
 	}
124 124
 
@@ -128,7 +128,7 @@  discard block
 block discarded – undo
128 128
 	 * @return array
129 129
 	 */
130 130
 	public function __sleep() {
131
-		return array( 'id' );
131
+		return array('id');
132 132
 	}
133 133
 
134 134
 	/**
@@ -138,10 +138,10 @@  discard block
 block discarded – undo
138 138
 	 */
139 139
 	public function __wakeup() {
140 140
 		try {
141
-			$this->__construct( absint( $this->id ) );
142
-		} catch ( Exception $e ) {
143
-			$this->set_id( 0 );
144
-			$this->set_object_read( true );
141
+			$this->__construct(absint($this->id));
142
+		} catch (Exception $e) {
143
+			$this->set_id(0);
144
+			$this->set_object_read(true);
145 145
 		}
146 146
 	}
147 147
 
@@ -152,11 +152,11 @@  discard block
 block discarded – undo
152 152
 	 */
153 153
 	public function __clone() {
154 154
 		$this->maybe_read_meta_data();
155
-		if ( ! empty( $this->meta_data ) ) {
156
-			foreach ( $this->meta_data as $array_key => $meta ) {
157
-				$this->meta_data[ $array_key ] = clone $meta;
158
-				if ( ! empty( $meta->id ) ) {
159
-					$this->meta_data[ $array_key ]->id = null;
155
+		if (!empty($this->meta_data)) {
156
+			foreach ($this->meta_data as $array_key => $meta) {
157
+				$this->meta_data[$array_key] = clone $meta;
158
+				if (!empty($meta->id)) {
159
+					$this->meta_data[$array_key]->id = null;
160 160
 				}
161 161
 			}
162 162
 		}
@@ -199,8 +199,8 @@  discard block
 block discarded – undo
199 199
 	 * @param  string $context View or edit context.
200 200
 	 * @return string
201 201
 	 */
202
-	public function get_status( $context = 'view' ) {
203
-		return $this->get_prop( 'status', $context );
202
+	public function get_status($context = 'view') {
203
+		return $this->get_prop('status', $context);
204 204
     }
205 205
 
206 206
 	/**
@@ -210,10 +210,10 @@  discard block
 block discarded – undo
210 210
 	 * @param  bool $force_delete Should the data be deleted permanently.
211 211
 	 * @return bool result
212 212
 	 */
213
-	public function delete( $force_delete = false ) {
214
-		if ( $this->data_store ) {
215
-			$this->data_store->delete( $this, array( 'force_delete' => $force_delete ) );
216
-			$this->set_id( 0 );
213
+	public function delete($force_delete = false) {
214
+		if ($this->data_store) {
215
+			$this->data_store->delete($this, array('force_delete' => $force_delete));
216
+			$this->set_id(0);
217 217
 			return true;
218 218
 		}
219 219
 		return false;
@@ -226,7 +226,7 @@  discard block
 block discarded – undo
226 226
 	 * @return int
227 227
 	 */
228 228
 	public function save() {
229
-		if ( ! $this->data_store ) {
229
+		if (!$this->data_store) {
230 230
 			return $this->get_id();
231 231
 		}
232 232
 
@@ -236,12 +236,12 @@  discard block
 block discarded – undo
236 236
 		 * @param GetPaid_Data          $this The object being saved.
237 237
 		 * @param GetPaid_Data_Store_WP $data_store The data store persisting the data.
238 238
 		 */
239
-		do_action( 'getpaid_before_' . $this->object_type . '_object_save', $this, $this->data_store );
239
+		do_action('getpaid_before_' . $this->object_type . '_object_save', $this, $this->data_store);
240 240
 
241
-		if ( $this->get_id() ) {
242
-			$this->data_store->update( $this );
241
+		if ($this->get_id()) {
242
+			$this->data_store->update($this);
243 243
 		} else {
244
-			$this->data_store->create( $this );
244
+			$this->data_store->create($this);
245 245
 		}
246 246
 
247 247
 		/**
@@ -250,7 +250,7 @@  discard block
 block discarded – undo
250 250
 		 * @param GetPaid_Data          $this The object being saved.
251 251
 		 * @param GetPaid_Data_Store_WP $data_store The data store persisting the data.
252 252
 		 */
253
-		do_action( 'getpaid_after_' . $this->object_type . '_object_save', $this, $this->data_store );
253
+		do_action('getpaid_after_' . $this->object_type . '_object_save', $this, $this->data_store);
254 254
 
255 255
 		return $this->get_id();
256 256
 	}
@@ -262,7 +262,7 @@  discard block
 block discarded – undo
262 262
 	 * @return string Data in JSON format.
263 263
 	 */
264 264
 	public function __toString() {
265
-		return wp_json_encode( $this->get_data() );
265
+		return wp_json_encode($this->get_data());
266 266
 	}
267 267
 
268 268
 	/**
@@ -272,7 +272,7 @@  discard block
 block discarded – undo
272 272
 	 * @return array
273 273
 	 */
274 274
 	public function get_data() {
275
-		return array_merge( array( 'id' => $this->get_id() ), $this->data, array( 'meta_data' => $this->get_meta_data() ) );
275
+		return array_merge(array('id' => $this->get_id()), $this->data, array('meta_data' => $this->get_meta_data()));
276 276
 	}
277 277
 
278 278
 	/**
@@ -282,7 +282,7 @@  discard block
 block discarded – undo
282 282
 	 * @return array
283 283
 	 */
284 284
 	public function get_data_keys() {
285
-		return array_keys( $this->data );
285
+		return array_keys($this->data);
286 286
 	}
287 287
 
288 288
 	/**
@@ -292,7 +292,7 @@  discard block
 block discarded – undo
292 292
 	 * @return array
293 293
 	 */
294 294
 	public function get_extra_data_keys() {
295
-		return array_keys( $this->extra_data );
295
+		return array_keys($this->extra_data);
296 296
 	}
297 297
 
298 298
 	/**
@@ -302,8 +302,8 @@  discard block
 block discarded – undo
302 302
 	 * @param mixed $meta Meta value to check.
303 303
 	 * @return bool
304 304
 	 */
305
-	protected function filter_null_meta( $meta ) {
306
-		return ! is_null( $meta->value );
305
+	protected function filter_null_meta($meta) {
306
+		return !is_null($meta->value);
307 307
 	}
308 308
 
309 309
 	/**
@@ -314,7 +314,7 @@  discard block
 block discarded – undo
314 314
 	 */
315 315
 	public function get_meta_data() {
316 316
 		$this->maybe_read_meta_data();
317
-		return array_values( array_filter( $this->meta_data, array( $this, 'filter_null_meta' ) ) );
317
+		return array_values(array_filter($this->meta_data, array($this, 'filter_null_meta')));
318 318
 	}
319 319
 
320 320
 	/**
@@ -324,21 +324,21 @@  discard block
 block discarded – undo
324 324
 	 * @param  string $key Key to check.
325 325
 	 * @return bool   true if it's an internal key, false otherwise
326 326
 	 */
327
-	protected function is_internal_meta_key( $key ) {
328
-		$internal_meta_key = ! empty( $key ) && $this->data_store && in_array( $key, $this->data_store->get_internal_meta_keys(), true );
327
+	protected function is_internal_meta_key($key) {
328
+		$internal_meta_key = !empty($key) && $this->data_store && in_array($key, $this->data_store->get_internal_meta_keys(), true);
329 329
 
330
-		if ( ! $internal_meta_key ) {
330
+		if (!$internal_meta_key) {
331 331
 			return false;
332 332
 		}
333 333
 
334
-		$has_setter_or_getter = is_callable( array( $this, 'set_' . $key ) ) || is_callable( array( $this, 'get_' . $key ) );
334
+		$has_setter_or_getter = is_callable(array($this, 'set_' . $key)) || is_callable(array($this, 'get_' . $key));
335 335
 
336
-		if ( ! $has_setter_or_getter ) {
336
+		if (!$has_setter_or_getter) {
337 337
 			return false;
338 338
 		}
339 339
 
340 340
 		/* translators: %s: $key Key to check */
341
-		getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Generic add/update/get meta methods should not be used for internal meta data, including "%s". Use getters and setters.', 'getpaid' ), $key ), '1.0.19' );
341
+		getpaid_doing_it_wrong(__FUNCTION__, sprintf(__('Generic add/update/get meta methods should not be used for internal meta data, including "%s". Use getters and setters.', 'getpaid'), $key), '1.0.19');
342 342
 
343 343
 		return true;
344 344
 	}
@@ -352,20 +352,20 @@  discard block
 block discarded – undo
352 352
 	 * @access public
353 353
 	 *
354 354
 	 */
355
-	public function __set( $key, $value ) {
355
+	public function __set($key, $value) {
356 356
 
357
-		if ( 'id' == strtolower( $key ) ) {
358
-			return $this->set_id( $value );
357
+		if ('id' == strtolower($key)) {
358
+			return $this->set_id($value);
359 359
 		}
360 360
 
361
-		if ( method_exists( $this, "set_$key") ) {
361
+		if (method_exists($this, "set_$key")) {
362 362
 
363 363
 			/* translators: %s: $key Key to set */
364
-			getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Object data such as "%s" should not be accessed directly. Use getters and setters.', 'getpaid' ), $key ), '1.0.19' );
364
+			getpaid_doing_it_wrong(__FUNCTION__, sprintf(__('Object data such as "%s" should not be accessed directly. Use getters and setters.', 'getpaid'), $key), '1.0.19');
365 365
 
366
-			call_user_func( array( $this, "set_$key" ), $value );
366
+			call_user_func(array($this, "set_$key"), $value);
367 367
 		} else {
368
-			$this->set_prop( $key, $value );
368
+			$this->set_prop($key, $value);
369 369
 		}
370 370
 
371 371
 	}
@@ -373,25 +373,25 @@  discard block
 block discarded – undo
373 373
 	/**
374 374
      * Margic method for retrieving a property.
375 375
      */
376
-    public function __get( $key ) {
376
+    public function __get($key) {
377 377
 
378 378
         // Check if we have a helper method for that.
379
-        if ( method_exists( $this, 'get_' . $key ) ) {
379
+        if (method_exists($this, 'get_' . $key)) {
380 380
 
381
-			if ( 'post_type' != $key ) {
381
+			if ('post_type' != $key) {
382 382
 				/* translators: %s: $key Key to set */
383
-				getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Object data such as "%s" should not be accessed directly. Use getters and setters.', 'getpaid' ), $key ), '1.0.19' );
383
+				getpaid_doing_it_wrong(__FUNCTION__, sprintf(__('Object data such as "%s" should not be accessed directly. Use getters and setters.', 'getpaid'), $key), '1.0.19');
384 384
 			}
385 385
 
386
-            return call_user_func( array( $this, 'get_' . $key ) );
386
+            return call_user_func(array($this, 'get_' . $key));
387 387
         }
388 388
 
389 389
         // Check if the key is in the associated $post object.
390
-        if ( ! empty( $this->post ) && isset( $this->post->$key ) ) {
390
+        if (!empty($this->post) && isset($this->post->$key)) {
391 391
             return $this->post->$key;
392 392
         }
393 393
 
394
-		return $this->get_prop( $key );
394
+		return $this->get_prop($key);
395 395
 
396 396
     }
397 397
 
@@ -404,13 +404,13 @@  discard block
 block discarded – undo
404 404
 	 * @param  string $context What the value is for. Valid values are view and edit.
405 405
 	 * @return mixed
406 406
 	 */
407
-	public function get_meta( $key = '', $single = true, $context = 'view' ) {
407
+	public function get_meta($key = '', $single = true, $context = 'view') {
408 408
 
409 409
 		// Check if this is an internal meta key.
410
-		if ( $this->is_internal_meta_key( $key ) ) {
410
+		if ($this->is_internal_meta_key($key)) {
411 411
 			$function = 'get_' . $key;
412 412
 
413
-			if ( is_callable( array( $this, $function ) ) ) {
413
+			if (is_callable(array($this, $function))) {
414 414
 				return $this->{$function}();
415 415
 			}
416 416
 		}
@@ -418,20 +418,20 @@  discard block
 block discarded – undo
418 418
 		// Read the meta data if not yet read.
419 419
 		$this->maybe_read_meta_data();
420 420
 		$meta_data  = $this->get_meta_data();
421
-		$array_keys = array_keys( wp_list_pluck( $meta_data, 'key' ), $key, true );
421
+		$array_keys = array_keys(wp_list_pluck($meta_data, 'key'), $key, true);
422 422
 		$value      = $single ? '' : array();
423 423
 
424
-		if ( ! empty( $array_keys ) ) {
424
+		if (!empty($array_keys)) {
425 425
 			// We don't use the $this->meta_data property directly here because we don't want meta with a null value (i.e. meta which has been deleted via $this->delete_meta_data()).
426
-			if ( $single ) {
427
-				$value = $meta_data[ current( $array_keys ) ]->value;
426
+			if ($single) {
427
+				$value = $meta_data[current($array_keys)]->value;
428 428
 			} else {
429
-				$value = array_intersect_key( $meta_data, array_flip( $array_keys ) );
429
+				$value = array_intersect_key($meta_data, array_flip($array_keys));
430 430
 			}
431 431
 		}
432 432
 
433
-		if ( 'view' === $context ) {
434
-			$value = apply_filters( $this->get_hook_prefix() . $key, $value, $this );
433
+		if ('view' === $context) {
434
+			$value = apply_filters($this->get_hook_prefix() . $key, $value, $this);
435 435
 		}
436 436
 
437 437
 		return $value;
@@ -444,10 +444,10 @@  discard block
 block discarded – undo
444 444
 	 * @param  string $key Meta Key.
445 445
 	 * @return boolean
446 446
 	 */
447
-	public function meta_exists( $key = '' ) {
447
+	public function meta_exists($key = '') {
448 448
 		$this->maybe_read_meta_data();
449
-		$array_keys = wp_list_pluck( $this->get_meta_data(), 'key' );
450
-		return in_array( $key, $array_keys, true );
449
+		$array_keys = wp_list_pluck($this->get_meta_data(), 'key');
450
+		return in_array($key, $array_keys, true);
451 451
 	}
452 452
 
453 453
 	/**
@@ -456,12 +456,12 @@  discard block
 block discarded – undo
456 456
 	 * @since 1.0.19
457 457
 	 * @param array $data Key/Value pairs.
458 458
 	 */
459
-	public function set_meta_data( $data ) {
460
-		if ( ! empty( $data ) && is_array( $data ) ) {
459
+	public function set_meta_data($data) {
460
+		if (!empty($data) && is_array($data)) {
461 461
 			$this->maybe_read_meta_data();
462
-			foreach ( $data as $meta ) {
462
+			foreach ($data as $meta) {
463 463
 				$meta = (array) $meta;
464
-				if ( isset( $meta['key'], $meta['value'], $meta['id'] ) ) {
464
+				if (isset($meta['key'], $meta['value'], $meta['id'])) {
465 465
 					$this->meta_data[] = new GetPaid_Meta_Data(
466 466
 						array(
467 467
 							'id'    => $meta['id'],
@@ -483,18 +483,18 @@  discard block
 block discarded – undo
483 483
 	 * @param string|array $value Meta value.
484 484
 	 * @param bool         $unique Should this be a unique key?.
485 485
 	 */
486
-	public function add_meta_data( $key, $value, $unique = false ) {
487
-		if ( $this->is_internal_meta_key( $key ) ) {
486
+	public function add_meta_data($key, $value, $unique = false) {
487
+		if ($this->is_internal_meta_key($key)) {
488 488
 			$function = 'set_' . $key;
489 489
 
490
-			if ( is_callable( array( $this, $function ) ) ) {
491
-				return $this->{$function}( $value );
490
+			if (is_callable(array($this, $function))) {
491
+				return $this->{$function}($value);
492 492
 			}
493 493
 		}
494 494
 
495 495
 		$this->maybe_read_meta_data();
496
-		if ( $unique ) {
497
-			$this->delete_meta_data( $key );
496
+		if ($unique) {
497
+			$this->delete_meta_data($key);
498 498
 		}
499 499
 		$this->meta_data[] = new GetPaid_Meta_Data(
500 500
 			array(
@@ -513,12 +513,12 @@  discard block
 block discarded – undo
513 513
 	 * @param  string|array $value Meta value.
514 514
 	 * @param  int          $meta_id Meta ID.
515 515
 	 */
516
-	public function update_meta_data( $key, $value, $meta_id = 0 ) {
517
-		if ( $this->is_internal_meta_key( $key ) ) {
516
+	public function update_meta_data($key, $value, $meta_id = 0) {
517
+		if ($this->is_internal_meta_key($key)) {
518 518
 			$function = 'set_' . $key;
519 519
 
520
-			if ( is_callable( array( $this, $function ) ) ) {
521
-				return $this->{$function}( $value );
520
+			if (is_callable(array($this, $function))) {
521
+				return $this->{$function}($value);
522 522
 			}
523 523
 		}
524 524
 
@@ -526,33 +526,33 @@  discard block
 block discarded – undo
526 526
 
527 527
 		$array_key = false;
528 528
 
529
-		if ( $meta_id ) {
530
-			$array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), $meta_id, true );
531
-			$array_key  = $array_keys ? current( $array_keys ) : false;
529
+		if ($meta_id) {
530
+			$array_keys = array_keys(wp_list_pluck($this->meta_data, 'id'), $meta_id, true);
531
+			$array_key  = $array_keys ? current($array_keys) : false;
532 532
 		} else {
533 533
 			// Find matches by key.
534 534
 			$matches = array();
535
-			foreach ( $this->meta_data as $meta_data_array_key => $meta ) {
536
-				if ( $meta->key === $key ) {
535
+			foreach ($this->meta_data as $meta_data_array_key => $meta) {
536
+				if ($meta->key === $key) {
537 537
 					$matches[] = $meta_data_array_key;
538 538
 				}
539 539
 			}
540 540
 
541
-			if ( ! empty( $matches ) ) {
541
+			if (!empty($matches)) {
542 542
 				// Set matches to null so only one key gets the new value.
543
-				foreach ( $matches as $meta_data_array_key ) {
544
-					$this->meta_data[ $meta_data_array_key ]->value = null;
543
+				foreach ($matches as $meta_data_array_key) {
544
+					$this->meta_data[$meta_data_array_key]->value = null;
545 545
 				}
546
-				$array_key = current( $matches );
546
+				$array_key = current($matches);
547 547
 			}
548 548
 		}
549 549
 
550
-		if ( false !== $array_key ) {
551
-			$meta        = $this->meta_data[ $array_key ];
550
+		if (false !== $array_key) {
551
+			$meta        = $this->meta_data[$array_key];
552 552
 			$meta->key   = $key;
553 553
 			$meta->value = $value;
554 554
 		} else {
555
-			$this->add_meta_data( $key, $value, true );
555
+			$this->add_meta_data($key, $value, true);
556 556
 		}
557 557
 	}
558 558
 
@@ -562,13 +562,13 @@  discard block
 block discarded – undo
562 562
 	 * @since 1.0.19
563 563
 	 * @param string $key Meta key.
564 564
 	 */
565
-	public function delete_meta_data( $key ) {
565
+	public function delete_meta_data($key) {
566 566
 		$this->maybe_read_meta_data();
567
-		$array_keys = array_keys( wp_list_pluck( $this->meta_data, 'key' ), $key, true );
567
+		$array_keys = array_keys(wp_list_pluck($this->meta_data, 'key'), $key, true);
568 568
 
569
-		if ( $array_keys ) {
570
-			foreach ( $array_keys as $array_key ) {
571
-				$this->meta_data[ $array_key ]->value = null;
569
+		if ($array_keys) {
570
+			foreach ($array_keys as $array_key) {
571
+				$this->meta_data[$array_key]->value = null;
572 572
 			}
573 573
 		}
574 574
 	}
@@ -579,13 +579,13 @@  discard block
 block discarded – undo
579 579
 	 * @since 1.0.19
580 580
 	 * @param int $mid Meta ID.
581 581
 	 */
582
-	public function delete_meta_data_by_mid( $mid ) {
582
+	public function delete_meta_data_by_mid($mid) {
583 583
 		$this->maybe_read_meta_data();
584
-		$array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), (int) $mid, true );
584
+		$array_keys = array_keys(wp_list_pluck($this->meta_data, 'id'), (int) $mid, true);
585 585
 
586
-		if ( $array_keys ) {
587
-			foreach ( $array_keys as $array_key ) {
588
-				$this->meta_data[ $array_key ]->value = null;
586
+		if ($array_keys) {
587
+			foreach ($array_keys as $array_key) {
588
+				$this->meta_data[$array_key]->value = null;
589 589
 			}
590 590
 		}
591 591
 	}
@@ -596,7 +596,7 @@  discard block
 block discarded – undo
596 596
 	 * @since 1.0.19
597 597
 	 */
598 598
 	protected function maybe_read_meta_data() {
599
-		if ( is_null( $this->meta_data ) ) {
599
+		if (is_null($this->meta_data)) {
600 600
 			$this->read_meta_data();
601 601
 		}
602 602
 	}
@@ -608,43 +608,43 @@  discard block
 block discarded – undo
608 608
 	 * @since 1.0.19
609 609
 	 * @param bool $force_read True to force a new DB read (and update cache).
610 610
 	 */
611
-	public function read_meta_data( $force_read = false ) {
611
+	public function read_meta_data($force_read = false) {
612 612
 		$this->meta_data = array();
613 613
 		$cache_loaded    = false;
614 614
 
615
-		if ( ! $this->get_id() ) {
615
+		if (!$this->get_id()) {
616 616
 			return;
617 617
 		}
618 618
 
619
-		if ( ! $this->data_store ) {
619
+		if (!$this->data_store) {
620 620
 			return;
621 621
 		}
622 622
 
623
-		if ( ! empty( $this->cache_group ) ) {
624
-			$cache_key = GetPaid_Cache_Helper::get_cache_prefix( $this->cache_group ) . GetPaid_Cache_Helper::get_cache_prefix( 'object_' . $this->get_id() ) . 'object_meta_' . $this->get_id();
623
+		if (!empty($this->cache_group)) {
624
+			$cache_key = GetPaid_Cache_Helper::get_cache_prefix($this->cache_group) . GetPaid_Cache_Helper::get_cache_prefix('object_' . $this->get_id()) . 'object_meta_' . $this->get_id();
625 625
 		}
626 626
 
627
-		if ( ! $force_read ) {
628
-			if ( ! empty( $this->cache_group ) ) {
629
-				$cached_meta  = wp_cache_get( $cache_key, $this->cache_group );
630
-				$cache_loaded = ! empty( $cached_meta );
627
+		if (!$force_read) {
628
+			if (!empty($this->cache_group)) {
629
+				$cached_meta  = wp_cache_get($cache_key, $this->cache_group);
630
+				$cache_loaded = !empty($cached_meta);
631 631
 			}
632 632
 		}
633 633
 
634
-		$raw_meta_data = $cache_loaded ? $cached_meta : $this->data_store->read_meta( $this );
635
-		if ( $raw_meta_data ) {
636
-			foreach ( $raw_meta_data as $meta ) {
634
+		$raw_meta_data = $cache_loaded ? $cached_meta : $this->data_store->read_meta($this);
635
+		if ($raw_meta_data) {
636
+			foreach ($raw_meta_data as $meta) {
637 637
 				$this->meta_data[] = new GetPaid_Meta_Data(
638 638
 					array(
639 639
 						'id'    => (int) $meta->meta_id,
640 640
 						'key'   => $meta->meta_key,
641
-						'value' => maybe_unserialize( $meta->meta_value ),
641
+						'value' => maybe_unserialize($meta->meta_value),
642 642
 					)
643 643
 				);
644 644
 			}
645 645
 
646
-			if ( ! $cache_loaded && ! empty( $this->cache_group ) ) {
647
-				wp_cache_set( $cache_key, $raw_meta_data, $this->cache_group );
646
+			if (!$cache_loaded && !empty($this->cache_group)) {
647
+				wp_cache_set($cache_key, $raw_meta_data, $this->cache_group);
648 648
 			}
649 649
 		}
650 650
 	}
@@ -655,28 +655,28 @@  discard block
 block discarded – undo
655 655
 	 * @since 1.0.19
656 656
 	 */
657 657
 	public function save_meta_data() {
658
-		if ( ! $this->data_store || is_null( $this->meta_data ) ) {
658
+		if (!$this->data_store || is_null($this->meta_data)) {
659 659
 			return;
660 660
 		}
661
-		foreach ( $this->meta_data as $array_key => $meta ) {
662
-			if ( is_null( $meta->value ) ) {
663
-				if ( ! empty( $meta->id ) ) {
664
-					$this->data_store->delete_meta( $this, $meta );
665
-					unset( $this->meta_data[ $array_key ] );
661
+		foreach ($this->meta_data as $array_key => $meta) {
662
+			if (is_null($meta->value)) {
663
+				if (!empty($meta->id)) {
664
+					$this->data_store->delete_meta($this, $meta);
665
+					unset($this->meta_data[$array_key]);
666 666
 				}
667
-			} elseif ( empty( $meta->id ) ) {
668
-				$meta->id = $this->data_store->add_meta( $this, $meta );
667
+			} elseif (empty($meta->id)) {
668
+				$meta->id = $this->data_store->add_meta($this, $meta);
669 669
 				$meta->apply_changes();
670 670
 			} else {
671
-				if ( $meta->get_changes() ) {
672
-					$this->data_store->update_meta( $this, $meta );
671
+				if ($meta->get_changes()) {
672
+					$this->data_store->update_meta($this, $meta);
673 673
 					$meta->apply_changes();
674 674
 				}
675 675
 			}
676 676
 		}
677
-		if ( ! empty( $this->cache_group ) ) {
678
-			$cache_key = GetPaid_Cache_Helper::get_cache_prefix( $this->cache_group ) . GetPaid_Cache_Helper::get_cache_prefix( 'object_' . $this->get_id() ) . 'object_meta_' . $this->get_id();
679
-			wp_cache_delete( $cache_key, $this->cache_group );
677
+		if (!empty($this->cache_group)) {
678
+			$cache_key = GetPaid_Cache_Helper::get_cache_prefix($this->cache_group) . GetPaid_Cache_Helper::get_cache_prefix('object_' . $this->get_id()) . 'object_meta_' . $this->get_id();
679
+			wp_cache_delete($cache_key, $this->cache_group);
680 680
 		}
681 681
 	}
682 682
 
@@ -686,8 +686,8 @@  discard block
 block discarded – undo
686 686
 	 * @since 1.0.19
687 687
 	 * @param int $id ID.
688 688
 	 */
689
-	public function set_id( $id ) {
690
-		$this->id = absint( $id );
689
+	public function set_id($id) {
690
+		$this->id = absint($id);
691 691
 	}
692 692
 
693 693
 	/**
@@ -697,10 +697,10 @@  discard block
 block discarded – undo
697 697
 	 * @param string $status New status.
698 698
 	 * @return array details of change.
699 699
 	 */
700
-	public function set_status( $status ) {
700
+	public function set_status($status) {
701 701
         $old_status = $this->get_status();
702 702
 
703
-		$this->set_prop( 'status', $status );
703
+		$this->set_prop('status', $status);
704 704
 
705 705
 		return array(
706 706
 			'from' => $old_status,
@@ -716,7 +716,7 @@  discard block
 block discarded – undo
716 716
 	public function set_defaults() {
717 717
 		$this->data    = $this->default_data;
718 718
 		$this->changes = array();
719
-		$this->set_object_read( false );
719
+		$this->set_object_read(false);
720 720
 	}
721 721
 
722 722
 	/**
@@ -725,7 +725,7 @@  discard block
 block discarded – undo
725 725
 	 * @since 1.0.19
726 726
 	 * @param boolean $read Should read?.
727 727
 	 */
728
-	public function set_object_read( $read = true ) {
728
+	public function set_object_read($read = true) {
729 729
 		$this->object_read = (bool) $read;
730 730
 	}
731 731
 
@@ -750,32 +750,32 @@  discard block
 block discarded – undo
750 750
 	 *
751 751
 	 * @return bool|WP_Error
752 752
 	 */
753
-	public function set_props( $props, $context = 'set' ) {
753
+	public function set_props($props, $context = 'set') {
754 754
 		$errors = false;
755 755
 
756
-		foreach ( $props as $prop => $value ) {
756
+		foreach ($props as $prop => $value) {
757 757
 			try {
758 758
 				/**
759 759
 				 * Checks if the prop being set is allowed, and the value is not null.
760 760
 				 */
761
-				if ( is_null( $value ) || in_array( $prop, array( 'prop', 'date_prop', 'meta_data' ), true ) ) {
761
+				if (is_null($value) || in_array($prop, array('prop', 'date_prop', 'meta_data'), true)) {
762 762
 					continue;
763 763
 				}
764 764
 				$setter = "set_$prop";
765 765
 
766
-				if ( is_callable( array( $this, $setter ) ) ) {
767
-					$this->{$setter}( $value );
766
+				if (is_callable(array($this, $setter))) {
767
+					$this->{$setter}($value);
768 768
 				}
769
-			} catch ( Exception $e ) {
770
-				if ( ! $errors ) {
769
+			} catch (Exception $e) {
770
+				if (!$errors) {
771 771
 					$errors = new WP_Error();
772 772
 				}
773
-				$errors->add( $e->getCode(), $e->getMessage() );
773
+				$errors->add($e->getCode(), $e->getMessage());
774 774
 				$this->last_error = $e->getMessage();
775 775
 			}
776 776
 		}
777 777
 
778
-		return $errors && count( $errors->get_error_codes() ) ? $errors : true;
778
+		return $errors && count($errors->get_error_codes()) ? $errors : true;
779 779
 	}
780 780
 
781 781
 	/**
@@ -788,14 +788,14 @@  discard block
 block discarded – undo
788 788
 	 * @param string $prop Name of prop to set.
789 789
 	 * @param mixed  $value Value of the prop.
790 790
 	 */
791
-	protected function set_prop( $prop, $value ) {
792
-		if ( array_key_exists( $prop, $this->data ) ) {
793
-			if ( true === $this->object_read ) {
794
-				if ( $value !== $this->data[ $prop ] || array_key_exists( $prop, $this->changes ) ) {
795
-					$this->changes[ $prop ] = $value;
791
+	protected function set_prop($prop, $value) {
792
+		if (array_key_exists($prop, $this->data)) {
793
+			if (true === $this->object_read) {
794
+				if ($value !== $this->data[$prop] || array_key_exists($prop, $this->changes)) {
795
+					$this->changes[$prop] = $value;
796 796
 				}
797 797
 			} else {
798
-				$this->data[ $prop ] = $value;
798
+				$this->data[$prop] = $value;
799 799
 			}
800 800
 		}
801 801
 	}
@@ -816,7 +816,7 @@  discard block
 block discarded – undo
816 816
 	 * @since 1.0.19
817 817
 	 */
818 818
 	public function apply_changes() {
819
-		$this->data    = array_replace_recursive( $this->data, $this->changes );
819
+		$this->data    = array_replace_recursive($this->data, $this->changes);
820 820
 		$this->changes = array();
821 821
 	}
822 822
 
@@ -841,14 +841,14 @@  discard block
 block discarded – undo
841 841
 	 * @param  string $context What the value is for. Valid values are view and edit.
842 842
 	 * @return mixed
843 843
 	 */
844
-	protected function get_prop( $prop, $context = 'view' ) {
844
+	protected function get_prop($prop, $context = 'view') {
845 845
 		$value = null;
846 846
 
847
-		if ( array_key_exists( $prop, $this->data ) ) {
848
-			$value = array_key_exists( $prop, $this->changes ) ? $this->changes[ $prop ] : $this->data[ $prop ];
847
+		if (array_key_exists($prop, $this->data)) {
848
+			$value = array_key_exists($prop, $this->changes) ? $this->changes[$prop] : $this->data[$prop];
849 849
 
850
-			if ( 'view' === $context ) {
851
-				$value = apply_filters( $this->get_hook_prefix() . $prop, $value, $this );
850
+			if ('view' === $context) {
851
+				$value = apply_filters($this->get_hook_prefix() . $prop, $value, $this);
852 852
 			}
853 853
 		}
854 854
 
@@ -862,13 +862,13 @@  discard block
 block discarded – undo
862 862
 	 * @param string         $prop Name of prop to set.
863 863
 	 * @param string|integer $value Value of the prop.
864 864
 	 */
865
-	protected function set_date_prop( $prop, $value ) {
865
+	protected function set_date_prop($prop, $value) {
866 866
 
867
-		if ( empty( $value ) ) {
868
-			$this->set_prop( $prop, null );
867
+		if (empty($value)) {
868
+			$this->set_prop($prop, null);
869 869
 			return;
870 870
 		}
871
-		$this->set_prop( $prop, $value );
871
+		$this->set_prop($prop, $value);
872 872
 
873 873
 	}
874 874
 
@@ -880,8 +880,8 @@  discard block
 block discarded – undo
880 880
 	 * @param string $code             Error code.
881 881
 	 * @param string $message          Error message.
882 882
 	 */
883
-	protected function error( $code, $message ) {
884
-		throw new Exception( $message, $code );
883
+	protected function error($code, $message) {
884
+		throw new Exception($message, $code);
885 885
 	}
886 886
 
887 887
 	/**
@@ -893,31 +893,31 @@  discard block
 block discarded – undo
893 893
 		// Reset status transition variable.
894 894
 		$this->status_transition = false;
895 895
 
896
-		if ( $status_transition ) {
896
+		if ($status_transition) {
897 897
 			try {
898 898
 
899 899
 				$object = $this->object_type;
900 900
 
901
-				if ( 'invoice' == $object ) {
901
+				if ('invoice' == $object) {
902 902
 					$this->get_type();
903 903
 				}
904 904
 
905
-				do_action( "wpinv_{$object}_status_" . $status_transition['to'], $this->get_id(), $this );
905
+				do_action("wpinv_{$object}_status_" . $status_transition['to'], $this->get_id(), $this);
906 906
 
907
-				if ( ! empty( $status_transition['from'] ) ) {
907
+				if (!empty($status_transition['from'])) {
908 908
 					/* translators: 1: old status 2: new status */
909
-					$transition_note = sprintf( __( 'Order status changed from %1$s to %2$s.', 'woocommerce' ), wc_get_order_status_name( $status_transition['from'] ), wc_get_order_status_name( $status_transition['to'] ) );
909
+					$transition_note = sprintf(__('Order status changed from %1$s to %2$s.', 'woocommerce'), wc_get_order_status_name($status_transition['from']), wc_get_order_status_name($status_transition['to']));
910 910
 
911 911
 					// Note the transition occurred.
912
-					$this->add_status_transition_note( $transition_note, $status_transition );
912
+					$this->add_status_transition_note($transition_note, $status_transition);
913 913
 
914
-					do_action( 'woocommerce_order_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this );
915
-					do_action( 'woocommerce_order_status_changed', $this->get_id(), $status_transition['from'], $status_transition['to'], $this );
914
+					do_action('woocommerce_order_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this);
915
+					do_action('woocommerce_order_status_changed', $this->get_id(), $status_transition['from'], $status_transition['to'], $this);
916 916
 
917 917
 					// Work out if this was for a payment, and trigger a payment_status hook instead.
918 918
 					if (
919
-						in_array( $status_transition['from'], apply_filters( 'woocommerce_valid_order_statuses_for_payment', array( 'pending', 'failed' ), $this ), true )
920
-						&& in_array( $status_transition['to'], wc_get_is_paid_statuses(), true )
919
+						in_array($status_transition['from'], apply_filters('woocommerce_valid_order_statuses_for_payment', array('pending', 'failed'), $this), true)
920
+						&& in_array($status_transition['to'], wc_get_is_paid_statuses(), true)
921 921
 					) {
922 922
 						/**
923 923
 						 * Fires when the order progresses from a pending payment status to a paid one.
@@ -926,16 +926,16 @@  discard block
 block discarded – undo
926 926
 						 * @param int Order ID
927 927
 						 * @param WC_Order Order object
928 928
 						 */
929
-						do_action( 'woocommerce_order_payment_status_changed', $this->get_id(), $this );
929
+						do_action('woocommerce_order_payment_status_changed', $this->get_id(), $this);
930 930
 					}
931 931
 				} else {
932 932
 					/* translators: %s: new order status */
933
-					$transition_note = sprintf( __( 'Order status set to %s.', 'woocommerce' ), wc_get_order_status_name( $status_transition['to'] ) );
933
+					$transition_note = sprintf(__('Order status set to %s.', 'woocommerce'), wc_get_order_status_name($status_transition['to']));
934 934
 
935 935
 					// Note the transition occurred.
936
-					$this->add_status_transition_note( $transition_note, $status_transition );
936
+					$this->add_status_transition_note($transition_note, $status_transition);
937 937
 				}
938
-			} catch ( Exception $e ) {
938
+			} catch (Exception $e) {
939 939
 				$logger = wc_get_logger();
940 940
 				$logger->error(
941 941
 					sprintf(
@@ -947,7 +947,7 @@  discard block
 block discarded – undo
947 947
 						'error' => $e,
948 948
 					)
949 949
 				);
950
-				$this->add_order_note( __( 'Error during status transition.', 'woocommerce' ) . ' ' . $e->getMessage() );
950
+				$this->add_order_note(__('Error during status transition.', 'woocommerce') . ' ' . $e->getMessage());
951 951
 			}
952 952
 		}
953 953
 	}
Please login to merge, or discard this patch.
includes/data-stores/class-getpaid-invoice-data-store.php 2 patches
Indentation   +318 added lines, -318 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
  *
6 6
  */
7 7
 if ( ! defined( 'ABSPATH' ) ) {
8
-	exit;
8
+    exit;
9 9
 }
10 10
 
11 11
 /**
@@ -15,270 +15,270 @@  discard block
 block discarded – undo
15 15
  */
16 16
 class GetPaid_Invoice_Data_Store extends GetPaid_Data_Store_WP {
17 17
 
18
-	/**
19
-	 * Data stored in meta keys, but not considered "meta" for a discount.
20
-	 *
21
-	 * @since 1.0.19
22
-	 * @var array
23
-	 */
24
-	protected $internal_meta_keys = array(
25
-		'_wpinv_subscr_profile_id',
26
-		'_wpinv_taxes',
27
-		'_wpinv_fees',
28
-		'_wpinv_discounts',
29
-		'_wpinv_submission_id',
30
-		'_wpinv_payment_form',
31
-		'_wpinv_is_viewed',
32
-		'wpinv_email_cc'
33
-	);
34
-
35
-	/**
36
-	 * A map of meta keys to data props.
37
-	 *
38
-	 * @since 1.0.19
39
-	 *
40
-	 * @var array
41
-	 */
42
-	protected $meta_key_to_props = array(
43
-		'_wpinv_subscr_profile_id' => 'subscription_id',
44
-		'_wpinv_taxes'             => 'taxes',
45
-		'_wpinv_fees'              => 'fees',
46
-		'_wpinv_discounts'         => 'discounts',
47
-		'_wpinv_submission_id'     => 'submission_id',
48
-		'_wpinv_payment_form'      => 'payment_form',
49
-		'_wpinv_is_viewed'         => 'is_viewed',
50
-		'wpinv_email_cc'           => 'email_cc',
51
-	);
52
-
53
-	/*
18
+    /**
19
+     * Data stored in meta keys, but not considered "meta" for a discount.
20
+     *
21
+     * @since 1.0.19
22
+     * @var array
23
+     */
24
+    protected $internal_meta_keys = array(
25
+        '_wpinv_subscr_profile_id',
26
+        '_wpinv_taxes',
27
+        '_wpinv_fees',
28
+        '_wpinv_discounts',
29
+        '_wpinv_submission_id',
30
+        '_wpinv_payment_form',
31
+        '_wpinv_is_viewed',
32
+        'wpinv_email_cc'
33
+    );
34
+
35
+    /**
36
+     * A map of meta keys to data props.
37
+     *
38
+     * @since 1.0.19
39
+     *
40
+     * @var array
41
+     */
42
+    protected $meta_key_to_props = array(
43
+        '_wpinv_subscr_profile_id' => 'subscription_id',
44
+        '_wpinv_taxes'             => 'taxes',
45
+        '_wpinv_fees'              => 'fees',
46
+        '_wpinv_discounts'         => 'discounts',
47
+        '_wpinv_submission_id'     => 'submission_id',
48
+        '_wpinv_payment_form'      => 'payment_form',
49
+        '_wpinv_is_viewed'         => 'is_viewed',
50
+        'wpinv_email_cc'           => 'email_cc',
51
+    );
52
+
53
+    /*
54 54
 	|--------------------------------------------------------------------------
55 55
 	| CRUD Methods
56 56
 	|--------------------------------------------------------------------------
57 57
 	*/
58
-	/**
59
-	 * Method to create a new invoice in the database.
60
-	 *
61
-	 * @param WPInv_Invoice $invoice Invoice object.
62
-	 */
63
-	public function create( &$invoice ) {
64
-		$invoice->set_version( WPINV_VERSION );
65
-		$invoice->set_date_created( current_time('mysql') );
66
-
67
-		// Create a new post.
68
-		$id = wp_insert_post(
69
-			apply_filters(
70
-				'getpaid_new_invoice_data',
71
-				array(
72
-					'post_date'     => $invoice->get_date_created( 'edit' ),
73
-					'post_type'     => $invoice->get_post_type( 'edit' ),
74
-					'post_status'   => $this->get_post_status( $invoice ),
75
-					'ping_status'   => 'closed',
76
-					'post_author'   => $invoice->get_user_id( 'edit' ),
77
-					'post_title'    => $invoice->get_number( 'edit' ),
78
-					'post_excerpt'  => $invoice->get_description( 'edit' ),
79
-					'post_parent'   => $invoice->get_parent_id( 'edit' ),
80
-					'post_name'     => $invoice->get_path( 'edit' ),
81
-				)
82
-			),
83
-			true
84
-		);
85
-
86
-		if ( $id && ! is_wp_error( $id ) ) {
87
-			$invoice->set_id( $id );
88
-			$this->save_special_fields( $invoice );
89
-			$this->update_post_meta( $invoice );
90
-			$invoice->save_meta_data();
91
-			$invoice->apply_changes();
92
-			$this->clear_caches( $invoice );
93
-			do_action( 'getpaid_new_' . $invoice->get_type(), $invoice->get_id(), $invoice );
94
-			return true;
95
-		}
96
-
97
-		if ( is_wp_error( $id ) ) {
98
-			$invoice->last_error = $id->get_error_message();
99
-		}
100
-
101
-		return false;
102
-	}
103
-
104
-	/**
105
-	 * Method to read an invoice from the database.
106
-	 *
107
-	 * @param WPInv_Invoice $invoice Invoice object.
108
-	 *
109
-	 */
110
-	public function read( &$invoice ) {
111
-
112
-		$invoice->set_defaults();
113
-		$invoice_object = get_post( $invoice->get_id() );
114
-
115
-		if ( ! $invoice->get_id() || ! $invoice_object || ! getpaid_is_invoice_post_type( $invoice_object->post_type ) ) {
116
-			$invoice->last_error = __( 'Invalid invoice.', 'invoicing' );
117
-			return false;
118
-		}
119
-
120
-		$invoice->set_props(
121
-			array(
122
-				'date_created'  => 0 < $invoice_object->post_date ? $invoice_object->post_date : null,
123
-				'date_modified' => 0 < $invoice_object->post_modified ? $invoice_object->post_modified : null,
124
-				'status'        => $invoice_object->post_status,
125
-				'author'        => $invoice_object->post_author,
126
-				'description'   => $invoice_object->post_excerpt,
127
-				'parent_id'     => $invoice_object->post_parent,
128
-				'name'          => $invoice_object->post_title,
129
-				'path'          => $invoice_object->post_name,
130
-				'post_type'     => $invoice_object->post_type,
131
-			)
132
-		);
133
-
134
-		$this->read_object_data( $invoice, $invoice_object );
135
-		$this->add_special_fields( $invoice );
136
-		$invoice->read_meta_data();
137
-		$invoice->set_object_read( true );
138
-		do_action( 'getpaid_read_' . $invoice->get_type(), $invoice->get_id(), $invoice );
139
-
140
-	}
141
-
142
-	/**
143
-	 * Method to update an invoice in the database.
144
-	 *
145
-	 * @param WPInv_Invoice $invoice Invoice object.
146
-	 */
147
-	public function update( &$invoice ) {
148
-		$invoice->save_meta_data();
149
-		$invoice->set_version( WPINV_VERSION );
150
-
151
-		if ( null === $invoice->get_date_created( 'edit' ) ) {
152
-			$invoice->set_date_created(  current_time('mysql') );
153
-		}
154
-
155
-		// Grab the current status so we can compare.
156
-		$previous_status = get_post_status( $invoice->get_id() );
157
-
158
-		$changes = $invoice->get_changes();
159
-
160
-		// Only update the post when the post data changes.
161
-		if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author', 'description', 'parent_id', 'post_excerpt', 'path' ), array_keys( $changes ) ) ) {
162
-			$post_data = array(
163
-				'post_date'         => $invoice->get_date_created( 'edit' ),
164
-				'post_status'       => $invoice->get_status( 'edit' ),
165
-				'post_title'        => $invoice->get_name( 'edit' ),
166
-				'post_author'       => $invoice->get_user_id( 'edit' ),
167
-				'post_modified'     => $invoice->get_date_modified( 'edit' ),
168
-				'post_excerpt'      => $invoice->get_description( 'edit' ),
169
-				'post_parent'       => $invoice->get_parent_id( 'edit' ),
170
-				'post_name'         => $invoice->get_path( 'edit' ),
171
-				'post_type'         => $invoice->get_post_type( 'edit' ),
172
-			);
173
-
174
-			/**
175
-			 * When updating this object, to prevent infinite loops, use $wpdb
176
-			 * to update data, since wp_update_post spawns more calls to the
177
-			 * save_post action.
178
-			 *
179
-			 * This ensures hooks are fired by either WP itself (admin screen save),
180
-			 * or an update purely from CRUD.
181
-			 */
182
-			if ( doing_action( 'save_post' ) ) {
183
-				$GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $invoice->get_id() ) );
184
-				clean_post_cache( $invoice->get_id() );
185
-			} else {
186
-				wp_update_post( array_merge( array( 'ID' => $invoice->get_id() ), $post_data ) );
187
-			}
188
-			$invoice->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook.
189
-		}
190
-		$this->update_post_meta( $invoice );
191
-		$this->save_special_fields( $invoice );
192
-		$invoice->apply_changes();
193
-		$this->clear_caches( $invoice );
194
-
195
-		// Fire a hook depending on the status - this should be considered a creation if it was previously draft status.
196
-		$new_status = $invoice->get_status( 'edit' );
197
-
198
-		if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) {
199
-			do_action( 'getpaid_new_' . $invoice->get_type(), $invoice->get_id(), $invoice );
200
-		} else {
201
-			do_action( 'getpaid_update_' . $invoice->get_type(), $invoice->get_id(), $invoice );
202
-		}
203
-
204
-	}
205
-
206
-	/*
58
+    /**
59
+     * Method to create a new invoice in the database.
60
+     *
61
+     * @param WPInv_Invoice $invoice Invoice object.
62
+     */
63
+    public function create( &$invoice ) {
64
+        $invoice->set_version( WPINV_VERSION );
65
+        $invoice->set_date_created( current_time('mysql') );
66
+
67
+        // Create a new post.
68
+        $id = wp_insert_post(
69
+            apply_filters(
70
+                'getpaid_new_invoice_data',
71
+                array(
72
+                    'post_date'     => $invoice->get_date_created( 'edit' ),
73
+                    'post_type'     => $invoice->get_post_type( 'edit' ),
74
+                    'post_status'   => $this->get_post_status( $invoice ),
75
+                    'ping_status'   => 'closed',
76
+                    'post_author'   => $invoice->get_user_id( 'edit' ),
77
+                    'post_title'    => $invoice->get_number( 'edit' ),
78
+                    'post_excerpt'  => $invoice->get_description( 'edit' ),
79
+                    'post_parent'   => $invoice->get_parent_id( 'edit' ),
80
+                    'post_name'     => $invoice->get_path( 'edit' ),
81
+                )
82
+            ),
83
+            true
84
+        );
85
+
86
+        if ( $id && ! is_wp_error( $id ) ) {
87
+            $invoice->set_id( $id );
88
+            $this->save_special_fields( $invoice );
89
+            $this->update_post_meta( $invoice );
90
+            $invoice->save_meta_data();
91
+            $invoice->apply_changes();
92
+            $this->clear_caches( $invoice );
93
+            do_action( 'getpaid_new_' . $invoice->get_type(), $invoice->get_id(), $invoice );
94
+            return true;
95
+        }
96
+
97
+        if ( is_wp_error( $id ) ) {
98
+            $invoice->last_error = $id->get_error_message();
99
+        }
100
+
101
+        return false;
102
+    }
103
+
104
+    /**
105
+     * Method to read an invoice from the database.
106
+     *
107
+     * @param WPInv_Invoice $invoice Invoice object.
108
+     *
109
+     */
110
+    public function read( &$invoice ) {
111
+
112
+        $invoice->set_defaults();
113
+        $invoice_object = get_post( $invoice->get_id() );
114
+
115
+        if ( ! $invoice->get_id() || ! $invoice_object || ! getpaid_is_invoice_post_type( $invoice_object->post_type ) ) {
116
+            $invoice->last_error = __( 'Invalid invoice.', 'invoicing' );
117
+            return false;
118
+        }
119
+
120
+        $invoice->set_props(
121
+            array(
122
+                'date_created'  => 0 < $invoice_object->post_date ? $invoice_object->post_date : null,
123
+                'date_modified' => 0 < $invoice_object->post_modified ? $invoice_object->post_modified : null,
124
+                'status'        => $invoice_object->post_status,
125
+                'author'        => $invoice_object->post_author,
126
+                'description'   => $invoice_object->post_excerpt,
127
+                'parent_id'     => $invoice_object->post_parent,
128
+                'name'          => $invoice_object->post_title,
129
+                'path'          => $invoice_object->post_name,
130
+                'post_type'     => $invoice_object->post_type,
131
+            )
132
+        );
133
+
134
+        $this->read_object_data( $invoice, $invoice_object );
135
+        $this->add_special_fields( $invoice );
136
+        $invoice->read_meta_data();
137
+        $invoice->set_object_read( true );
138
+        do_action( 'getpaid_read_' . $invoice->get_type(), $invoice->get_id(), $invoice );
139
+
140
+    }
141
+
142
+    /**
143
+     * Method to update an invoice in the database.
144
+     *
145
+     * @param WPInv_Invoice $invoice Invoice object.
146
+     */
147
+    public function update( &$invoice ) {
148
+        $invoice->save_meta_data();
149
+        $invoice->set_version( WPINV_VERSION );
150
+
151
+        if ( null === $invoice->get_date_created( 'edit' ) ) {
152
+            $invoice->set_date_created(  current_time('mysql') );
153
+        }
154
+
155
+        // Grab the current status so we can compare.
156
+        $previous_status = get_post_status( $invoice->get_id() );
157
+
158
+        $changes = $invoice->get_changes();
159
+
160
+        // Only update the post when the post data changes.
161
+        if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author', 'description', 'parent_id', 'post_excerpt', 'path' ), array_keys( $changes ) ) ) {
162
+            $post_data = array(
163
+                'post_date'         => $invoice->get_date_created( 'edit' ),
164
+                'post_status'       => $invoice->get_status( 'edit' ),
165
+                'post_title'        => $invoice->get_name( 'edit' ),
166
+                'post_author'       => $invoice->get_user_id( 'edit' ),
167
+                'post_modified'     => $invoice->get_date_modified( 'edit' ),
168
+                'post_excerpt'      => $invoice->get_description( 'edit' ),
169
+                'post_parent'       => $invoice->get_parent_id( 'edit' ),
170
+                'post_name'         => $invoice->get_path( 'edit' ),
171
+                'post_type'         => $invoice->get_post_type( 'edit' ),
172
+            );
173
+
174
+            /**
175
+             * When updating this object, to prevent infinite loops, use $wpdb
176
+             * to update data, since wp_update_post spawns more calls to the
177
+             * save_post action.
178
+             *
179
+             * This ensures hooks are fired by either WP itself (admin screen save),
180
+             * or an update purely from CRUD.
181
+             */
182
+            if ( doing_action( 'save_post' ) ) {
183
+                $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $invoice->get_id() ) );
184
+                clean_post_cache( $invoice->get_id() );
185
+            } else {
186
+                wp_update_post( array_merge( array( 'ID' => $invoice->get_id() ), $post_data ) );
187
+            }
188
+            $invoice->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook.
189
+        }
190
+        $this->update_post_meta( $invoice );
191
+        $this->save_special_fields( $invoice );
192
+        $invoice->apply_changes();
193
+        $this->clear_caches( $invoice );
194
+
195
+        // Fire a hook depending on the status - this should be considered a creation if it was previously draft status.
196
+        $new_status = $invoice->get_status( 'edit' );
197
+
198
+        if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) {
199
+            do_action( 'getpaid_new_' . $invoice->get_type(), $invoice->get_id(), $invoice );
200
+        } else {
201
+            do_action( 'getpaid_update_' . $invoice->get_type(), $invoice->get_id(), $invoice );
202
+        }
203
+
204
+    }
205
+
206
+    /*
207 207
 	|--------------------------------------------------------------------------
208 208
 	| Additional Methods
209 209
 	|--------------------------------------------------------------------------
210 210
 	*/
211 211
 
212
-	/**
212
+    /**
213 213
      * Retrieves special fields and adds to the invoice.
214
-	 *
215
-	 * @param WPInv_Invoice $invoice Invoice object.
214
+     *
215
+     * @param WPInv_Invoice $invoice Invoice object.
216 216
      */
217 217
     public function add_special_fields( &$invoice ) {
218
-		global $wpdb;
219
-
220
-		// Maybe retrieve from the cache.
221
-		$data   = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_special_fields' );
222
-		$cached = true;
223
-
224
-		// If not found, retrieve from the db.
225
-		if ( empty( $data ) ) {
226
-			$table =  $wpdb->prefix . 'getpaid_invoices';
227
-
228
-			$data  = $wpdb->get_row(
229
-				$wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d LIMIT 1", $invoice->get_id() ),
230
-				ARRAY_A
231
-			);
232
-
233
-			$cached = false;
234
-		}
235
-
236
-		// Abort if the data does not exist.
237
-		if ( empty( $data ) ) {
238
-			return;
239
-		}
240
-
241
-		// Update the cache with our data
242
-		if ( ! $cached ) {
243
-			wp_cache_set( $invoice->get_id(), $data, 'getpaid_invoice_special_fields' );
244
-		}
245
-
246
-		$invoice->set_props( $data );
247
-
248
-	}
249
-
250
-	/**
251
-	 * Gets a list of special fields that need updated based on change state
252
-	 * or if they are present in the database or not.
253
-	 *
254
-	 * @param  WPInv_Invoice $invoice       The Invoice object.
255
-	 * @param  array   $meta_key_to_props   A mapping of prop => value.
256
-	 * @return array                        A mapping of field keys => prop names, filtered by ones that should be updated.
257
-	 */
258
-	protected function get_special_fields_to_update( $invoice, $special_fields ) {
259
-		$props_to_update = array();
260
-		$changed_props   = $invoice->get_changes();
261
-
262
-		// Props should be updated if they are a part of the $changed array or don't exist yet.
263
-		foreach ( $special_fields as $prop => $value ) {
264
-			if ( array_key_exists( $prop, $changed_props ) ) {
265
-				$props_to_update[ $prop ] = $value;
266
-			}
267
-		}
268
-
269
-		return $props_to_update;
270
-	}
271
-
272
-	/**
218
+        global $wpdb;
219
+
220
+        // Maybe retrieve from the cache.
221
+        $data   = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_special_fields' );
222
+        $cached = true;
223
+
224
+        // If not found, retrieve from the db.
225
+        if ( empty( $data ) ) {
226
+            $table =  $wpdb->prefix . 'getpaid_invoices';
227
+
228
+            $data  = $wpdb->get_row(
229
+                $wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d LIMIT 1", $invoice->get_id() ),
230
+                ARRAY_A
231
+            );
232
+
233
+            $cached = false;
234
+        }
235
+
236
+        // Abort if the data does not exist.
237
+        if ( empty( $data ) ) {
238
+            return;
239
+        }
240
+
241
+        // Update the cache with our data
242
+        if ( ! $cached ) {
243
+            wp_cache_set( $invoice->get_id(), $data, 'getpaid_invoice_special_fields' );
244
+        }
245
+
246
+        $invoice->set_props( $data );
247
+
248
+    }
249
+
250
+    /**
251
+     * Gets a list of special fields that need updated based on change state
252
+     * or if they are present in the database or not.
253
+     *
254
+     * @param  WPInv_Invoice $invoice       The Invoice object.
255
+     * @param  array   $meta_key_to_props   A mapping of prop => value.
256
+     * @return array                        A mapping of field keys => prop names, filtered by ones that should be updated.
257
+     */
258
+    protected function get_special_fields_to_update( $invoice, $special_fields ) {
259
+        $props_to_update = array();
260
+        $changed_props   = $invoice->get_changes();
261
+
262
+        // Props should be updated if they are a part of the $changed array or don't exist yet.
263
+        foreach ( $special_fields as $prop => $value ) {
264
+            if ( array_key_exists( $prop, $changed_props ) ) {
265
+                $props_to_update[ $prop ] = $value;
266
+            }
267
+        }
268
+
269
+        return $props_to_update;
270
+    }
271
+
272
+    /**
273 273
      * Saves all special fields.
274
-	 *
275
-	 * @param WPInv_Invoice $invoice Invoice object.
274
+     *
275
+     * @param WPInv_Invoice $invoice Invoice object.
276 276
      */
277 277
     public function save_special_fields( $invoice ) {
278
-		global $wpdb;
278
+        global $wpdb;
279 279
 
280
-		// Fields to update.
281
-		$fields = array (
280
+        // Fields to update.
281
+        $fields = array (
282 282
             'post_id'        => $invoice->get_id(),
283 283
             'number'         => $invoice->get_number( 'edit' ),
284 284
             'key'            => $invoice->get_key( 'edit' ),
@@ -307,121 +307,121 @@  discard block
 block discarded – undo
307 307
             'company'        => $invoice->get_company( 'edit' ),
308 308
             'vat_number'     => $invoice->get_vat_number( 'edit' ),
309 309
             'vat_rate'       => $invoice->get_vat_rate( 'edit' ),
310
-		);
310
+        );
311 311
 
312
-		// Update the cache with our data
313
-		wp_cache_set( $invoice->get_id(), $fields, 'getpaid_invoice_special_fields' );
312
+        // Update the cache with our data
313
+        wp_cache_set( $invoice->get_id(), $fields, 'getpaid_invoice_special_fields' );
314 314
 
315
-		// The invoices table.
316
-		$table = $wpdb->prefix . 'getpaid_invoices';
317
-		$id    = (int) $invoice->get_id();
318
-		if ( $wpdb->get_var( "SELECT `post_id` FROM $table WHERE `post_id`= $id" ) ) {
315
+        // The invoices table.
316
+        $table = $wpdb->prefix . 'getpaid_invoices';
317
+        $id    = (int) $invoice->get_id();
318
+        if ( $wpdb->get_var( "SELECT `post_id` FROM $table WHERE `post_id`= $id" ) ) {
319 319
 
320
-			$to_update = $this->get_special_fields_to_update( $invoice, $fields );
320
+            $to_update = $this->get_special_fields_to_update( $invoice, $fields );
321 321
 
322
-			if ( empty( $to_update ) ) {
323
-				return;
324
-			}
322
+            if ( empty( $to_update ) ) {
323
+                return;
324
+            }
325 325
 
326
-			$changes = array(
327
-				'tax'                => 'total_tax',
328
-				'fees_total'         => 'total_fees',
329
-				'discount'           => 'total_discount',
330
-				'adddress_confirmed' => 'address_confirmed',
331
-			);
326
+            $changes = array(
327
+                'tax'                => 'total_tax',
328
+                'fees_total'         => 'total_fees',
329
+                'discount'           => 'total_discount',
330
+                'adddress_confirmed' => 'address_confirmed',
331
+            );
332 332
 
333
-			foreach ( $changes as $to => $from ) {
334
-				if ( isset( $changes[ $from ] ) ) {
335
-					$changes[ $to ] = $changes[ $from ];
336
-					unset( $changes[ $from ] );
337
-				}
338
-			}
333
+            foreach ( $changes as $to => $from ) {
334
+                if ( isset( $changes[ $from ] ) ) {
335
+                    $changes[ $to ] = $changes[ $from ];
336
+                    unset( $changes[ $from ] );
337
+                }
338
+            }
339 339
 
340
-			$changes['total'] = $invoice->get_total( 'edit' );
340
+            $changes['total'] = $invoice->get_total( 'edit' );
341 341
             $wpdb->update( $table, $fields, array( 'post_id' => $id ) );
342 342
 
343 343
         } else {
344 344
 
345
-			$fields['tax'] = $fields['total_tax'];
346
-			unset( $fields['total_tax'] );
345
+            $fields['tax'] = $fields['total_tax'];
346
+            unset( $fields['total_tax'] );
347 347
 
348
-			$fields['fees_total'] = $fields['total_fees'];
349
-			unset( $fields['total_fees'] );
348
+            $fields['fees_total'] = $fields['total_fees'];
349
+            unset( $fields['total_fees'] );
350 350
 
351
-			$fields['discount'] = $fields['total_discount'];
352
-			unset( $fields['total_discount'] );
351
+            $fields['discount'] = $fields['total_discount'];
352
+            unset( $fields['total_discount'] );
353 353
 
354
-			$fields['adddress_confirmed'] = $fields['address_confirmed'];
355
-			unset( $fields['address_confirmed'] );
354
+            $fields['adddress_confirmed'] = $fields['address_confirmed'];
355
+            unset( $fields['address_confirmed'] );
356 356
 			
357
-			$fields['total']   = $invoice->get_total( 'edit' );
358
-			$fields['post_id'] = $id;
357
+            $fields['total']   = $invoice->get_total( 'edit' );
358
+            $fields['post_id'] = $id;
359 359
             $wpdb->insert( $table, $fields );
360 360
 
361
-		}
361
+        }
362 362
 
363
-	}
363
+    }
364 364
 
365
-	/**
365
+    /**
366 366
      * Set's up cart details.
367
-	 *
368
-	 * @param WPInv_Invoice $invoice Invoice object.
367
+     *
368
+     * @param WPInv_Invoice $invoice Invoice object.
369 369
      */
370 370
     public function add_items( &$invoice ) {
371
-		global $wpdb;
371
+        global $wpdb;
372 372
 
373
-		$table =  $wpdb->prefix . 'getpaid_invoice_items';
373
+        $table =  $wpdb->prefix . 'getpaid_invoice_items';
374 374
         $items = $wpdb->get_results(
375 375
             $wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d", $invoice->get_id() )
376 376
         );
377 377
 
378 378
         if ( empty( $items ) ) {
379 379
             return;
380
-		}
380
+        }
381 381
 
382
-		foreach ( $items as $item_data ) {
383
-			$item = new GetPaid_Form_Item( $item_data->item_id );
382
+        foreach ( $items as $item_data ) {
383
+            $item = new GetPaid_Form_Item( $item_data->item_id );
384 384
 
385
-			// Set item data.
386
-			$item->item_tax      = wpinv_sanitize_amount( $item_data->tax );
387
-			$item->item_discount = wpinv_sanitize_amount( $item_data->tax );
388
-			$item->set_name( $item_data->item_name );
389
-			$item->set_description( $item_data->item_description );
390
-			$item->set_price( $item_data->item_price );
391
-			$item->set_quantity( $item_data->quantity );
385
+            // Set item data.
386
+            $item->item_tax      = wpinv_sanitize_amount( $item_data->tax );
387
+            $item->item_discount = wpinv_sanitize_amount( $item_data->tax );
388
+            $item->set_name( $item_data->item_name );
389
+            $item->set_description( $item_data->item_description );
390
+            $item->set_price( $item_data->item_price );
391
+            $item->set_quantity( $item_data->quantity );
392 392
 
393
-			$invoice->add_item( $item );
394
-		}
393
+            $invoice->add_item( $item );
394
+        }
395 395
 
396
-	}
396
+    }
397 397
 
398
-	/**
398
+    /**
399 399
      * Saves cart details.
400
-	 *
401
-	 * @param WPInv_Invoice $invoice Invoice object.
400
+     *
401
+     * @param WPInv_Invoice $invoice Invoice object.
402 402
      */
403 403
     public function save_items( $invoice ) {
404 404
 
405
-		// Delete previously existing items.
406
-		$this->delete_items( $invoice );
405
+        // Delete previously existing items.
406
+        $this->delete_items( $invoice );
407 407
 
408
-		$table   =  $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items';
408
+        $table   =  $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items';
409 409
         $to_save = $invoice->get_cart_details();
410 410
 
411
-		foreach ( $to_save as $item_data ) {
412
-			$GLOBALS['wpdb']->insert( $table, $item_data );
413
-		}
411
+        foreach ( $to_save as $item_data ) {
412
+            $GLOBALS['wpdb']->insert( $table, $item_data );
413
+        }
414 414
 
415
-	}
415
+    }
416 416
 
417
-	/**
417
+    /**
418 418
      * Deletes an invoice's cart details from the database.
419
-	 *
420
-	 * @param WPInv_Invoice $invoice Invoice object.
419
+     *
420
+     * @param WPInv_Invoice $invoice Invoice object.
421 421
      */
422 422
     public function delete_items( $invoice ) {
423
-		$table =  $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items';
424
-		return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) );
423
+        $table =  $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items';
424
+        return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) );
425 425
     }
426 426
 
427 427
 }
Please login to merge, or discard this 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
  * GetPaid_Invoice_Data_Store class file.
5 5
  *
6 6
  */
7
-if ( ! defined( 'ABSPATH' ) ) {
7
+if (!defined('ABSPATH')) {
8 8
 	exit;
9 9
 }
10 10
 
@@ -60,41 +60,41 @@  discard block
 block discarded – undo
60 60
 	 *
61 61
 	 * @param WPInv_Invoice $invoice Invoice object.
62 62
 	 */
63
-	public function create( &$invoice ) {
64
-		$invoice->set_version( WPINV_VERSION );
65
-		$invoice->set_date_created( current_time('mysql') );
63
+	public function create(&$invoice) {
64
+		$invoice->set_version(WPINV_VERSION);
65
+		$invoice->set_date_created(current_time('mysql'));
66 66
 
67 67
 		// Create a new post.
68 68
 		$id = wp_insert_post(
69 69
 			apply_filters(
70 70
 				'getpaid_new_invoice_data',
71 71
 				array(
72
-					'post_date'     => $invoice->get_date_created( 'edit' ),
73
-					'post_type'     => $invoice->get_post_type( 'edit' ),
74
-					'post_status'   => $this->get_post_status( $invoice ),
72
+					'post_date'     => $invoice->get_date_created('edit'),
73
+					'post_type'     => $invoice->get_post_type('edit'),
74
+					'post_status'   => $this->get_post_status($invoice),
75 75
 					'ping_status'   => 'closed',
76
-					'post_author'   => $invoice->get_user_id( 'edit' ),
77
-					'post_title'    => $invoice->get_number( 'edit' ),
78
-					'post_excerpt'  => $invoice->get_description( 'edit' ),
79
-					'post_parent'   => $invoice->get_parent_id( 'edit' ),
80
-					'post_name'     => $invoice->get_path( 'edit' ),
76
+					'post_author'   => $invoice->get_user_id('edit'),
77
+					'post_title'    => $invoice->get_number('edit'),
78
+					'post_excerpt'  => $invoice->get_description('edit'),
79
+					'post_parent'   => $invoice->get_parent_id('edit'),
80
+					'post_name'     => $invoice->get_path('edit'),
81 81
 				)
82 82
 			),
83 83
 			true
84 84
 		);
85 85
 
86
-		if ( $id && ! is_wp_error( $id ) ) {
87
-			$invoice->set_id( $id );
88
-			$this->save_special_fields( $invoice );
89
-			$this->update_post_meta( $invoice );
86
+		if ($id && !is_wp_error($id)) {
87
+			$invoice->set_id($id);
88
+			$this->save_special_fields($invoice);
89
+			$this->update_post_meta($invoice);
90 90
 			$invoice->save_meta_data();
91 91
 			$invoice->apply_changes();
92
-			$this->clear_caches( $invoice );
93
-			do_action( 'getpaid_new_' . $invoice->get_type(), $invoice->get_id(), $invoice );
92
+			$this->clear_caches($invoice);
93
+			do_action('getpaid_new_' . $invoice->get_type(), $invoice->get_id(), $invoice);
94 94
 			return true;
95 95
 		}
96 96
 
97
-		if ( is_wp_error( $id ) ) {
97
+		if (is_wp_error($id)) {
98 98
 			$invoice->last_error = $id->get_error_message();
99 99
 		}
100 100
 
@@ -107,13 +107,13 @@  discard block
 block discarded – undo
107 107
 	 * @param WPInv_Invoice $invoice Invoice object.
108 108
 	 *
109 109
 	 */
110
-	public function read( &$invoice ) {
110
+	public function read(&$invoice) {
111 111
 
112 112
 		$invoice->set_defaults();
113
-		$invoice_object = get_post( $invoice->get_id() );
113
+		$invoice_object = get_post($invoice->get_id());
114 114
 
115
-		if ( ! $invoice->get_id() || ! $invoice_object || ! getpaid_is_invoice_post_type( $invoice_object->post_type ) ) {
116
-			$invoice->last_error = __( 'Invalid invoice.', 'invoicing' );
115
+		if (!$invoice->get_id() || !$invoice_object || !getpaid_is_invoice_post_type($invoice_object->post_type)) {
116
+			$invoice->last_error = __('Invalid invoice.', 'invoicing');
117 117
 			return false;
118 118
 		}
119 119
 
@@ -131,11 +131,11 @@  discard block
 block discarded – undo
131 131
 			)
132 132
 		);
133 133
 
134
-		$this->read_object_data( $invoice, $invoice_object );
135
-		$this->add_special_fields( $invoice );
134
+		$this->read_object_data($invoice, $invoice_object);
135
+		$this->add_special_fields($invoice);
136 136
 		$invoice->read_meta_data();
137
-		$invoice->set_object_read( true );
138
-		do_action( 'getpaid_read_' . $invoice->get_type(), $invoice->get_id(), $invoice );
137
+		$invoice->set_object_read(true);
138
+		do_action('getpaid_read_' . $invoice->get_type(), $invoice->get_id(), $invoice);
139 139
 
140 140
 	}
141 141
 
@@ -144,31 +144,31 @@  discard block
 block discarded – undo
144 144
 	 *
145 145
 	 * @param WPInv_Invoice $invoice Invoice object.
146 146
 	 */
147
-	public function update( &$invoice ) {
147
+	public function update(&$invoice) {
148 148
 		$invoice->save_meta_data();
149
-		$invoice->set_version( WPINV_VERSION );
149
+		$invoice->set_version(WPINV_VERSION);
150 150
 
151
-		if ( null === $invoice->get_date_created( 'edit' ) ) {
152
-			$invoice->set_date_created(  current_time('mysql') );
151
+		if (null === $invoice->get_date_created('edit')) {
152
+			$invoice->set_date_created(current_time('mysql'));
153 153
 		}
154 154
 
155 155
 		// Grab the current status so we can compare.
156
-		$previous_status = get_post_status( $invoice->get_id() );
156
+		$previous_status = get_post_status($invoice->get_id());
157 157
 
158 158
 		$changes = $invoice->get_changes();
159 159
 
160 160
 		// Only update the post when the post data changes.
161
-		if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author', 'description', 'parent_id', 'post_excerpt', 'path' ), array_keys( $changes ) ) ) {
161
+		if (array_intersect(array('date_created', 'date_modified', 'status', 'name', 'author', 'description', 'parent_id', 'post_excerpt', 'path'), array_keys($changes))) {
162 162
 			$post_data = array(
163
-				'post_date'         => $invoice->get_date_created( 'edit' ),
164
-				'post_status'       => $invoice->get_status( 'edit' ),
165
-				'post_title'        => $invoice->get_name( 'edit' ),
166
-				'post_author'       => $invoice->get_user_id( 'edit' ),
167
-				'post_modified'     => $invoice->get_date_modified( 'edit' ),
168
-				'post_excerpt'      => $invoice->get_description( 'edit' ),
169
-				'post_parent'       => $invoice->get_parent_id( 'edit' ),
170
-				'post_name'         => $invoice->get_path( 'edit' ),
171
-				'post_type'         => $invoice->get_post_type( 'edit' ),
163
+				'post_date'         => $invoice->get_date_created('edit'),
164
+				'post_status'       => $invoice->get_status('edit'),
165
+				'post_title'        => $invoice->get_name('edit'),
166
+				'post_author'       => $invoice->get_user_id('edit'),
167
+				'post_modified'     => $invoice->get_date_modified('edit'),
168
+				'post_excerpt'      => $invoice->get_description('edit'),
169
+				'post_parent'       => $invoice->get_parent_id('edit'),
170
+				'post_name'         => $invoice->get_path('edit'),
171
+				'post_type'         => $invoice->get_post_type('edit'),
172 172
 			);
173 173
 
174 174
 			/**
@@ -179,26 +179,26 @@  discard block
 block discarded – undo
179 179
 			 * This ensures hooks are fired by either WP itself (admin screen save),
180 180
 			 * or an update purely from CRUD.
181 181
 			 */
182
-			if ( doing_action( 'save_post' ) ) {
183
-				$GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $invoice->get_id() ) );
184
-				clean_post_cache( $invoice->get_id() );
182
+			if (doing_action('save_post')) {
183
+				$GLOBALS['wpdb']->update($GLOBALS['wpdb']->posts, $post_data, array('ID' => $invoice->get_id()));
184
+				clean_post_cache($invoice->get_id());
185 185
 			} else {
186
-				wp_update_post( array_merge( array( 'ID' => $invoice->get_id() ), $post_data ) );
186
+				wp_update_post(array_merge(array('ID' => $invoice->get_id()), $post_data));
187 187
 			}
188
-			$invoice->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook.
188
+			$invoice->read_meta_data(true); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook.
189 189
 		}
190
-		$this->update_post_meta( $invoice );
191
-		$this->save_special_fields( $invoice );
190
+		$this->update_post_meta($invoice);
191
+		$this->save_special_fields($invoice);
192 192
 		$invoice->apply_changes();
193
-		$this->clear_caches( $invoice );
193
+		$this->clear_caches($invoice);
194 194
 
195 195
 		// Fire a hook depending on the status - this should be considered a creation if it was previously draft status.
196
-		$new_status = $invoice->get_status( 'edit' );
196
+		$new_status = $invoice->get_status('edit');
197 197
 
198
-		if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) {
199
-			do_action( 'getpaid_new_' . $invoice->get_type(), $invoice->get_id(), $invoice );
198
+		if ($new_status !== $previous_status && in_array($previous_status, array('new', 'auto-draft', 'draft'), true)) {
199
+			do_action('getpaid_new_' . $invoice->get_type(), $invoice->get_id(), $invoice);
200 200
 		} else {
201
-			do_action( 'getpaid_update_' . $invoice->get_type(), $invoice->get_id(), $invoice );
201
+			do_action('getpaid_update_' . $invoice->get_type(), $invoice->get_id(), $invoice);
202 202
 		}
203 203
 
204 204
 	}
@@ -214,19 +214,19 @@  discard block
 block discarded – undo
214 214
 	 *
215 215
 	 * @param WPInv_Invoice $invoice Invoice object.
216 216
      */
217
-    public function add_special_fields( &$invoice ) {
217
+    public function add_special_fields(&$invoice) {
218 218
 		global $wpdb;
219 219
 
220 220
 		// Maybe retrieve from the cache.
221
-		$data   = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_special_fields' );
221
+		$data   = wp_cache_get($invoice->get_id(), 'getpaid_invoice_special_fields');
222 222
 		$cached = true;
223 223
 
224 224
 		// If not found, retrieve from the db.
225
-		if ( empty( $data ) ) {
226
-			$table =  $wpdb->prefix . 'getpaid_invoices';
225
+		if (empty($data)) {
226
+			$table = $wpdb->prefix . 'getpaid_invoices';
227 227
 
228 228
 			$data  = $wpdb->get_row(
229
-				$wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d LIMIT 1", $invoice->get_id() ),
229
+				$wpdb->prepare("SELECT * FROM $table WHERE `post_id`=%d LIMIT 1", $invoice->get_id()),
230 230
 				ARRAY_A
231 231
 			);
232 232
 
@@ -234,16 +234,16 @@  discard block
 block discarded – undo
234 234
 		}
235 235
 
236 236
 		// Abort if the data does not exist.
237
-		if ( empty( $data ) ) {
237
+		if (empty($data)) {
238 238
 			return;
239 239
 		}
240 240
 
241 241
 		// Update the cache with our data
242
-		if ( ! $cached ) {
243
-			wp_cache_set( $invoice->get_id(), $data, 'getpaid_invoice_special_fields' );
242
+		if (!$cached) {
243
+			wp_cache_set($invoice->get_id(), $data, 'getpaid_invoice_special_fields');
244 244
 		}
245 245
 
246
-		$invoice->set_props( $data );
246
+		$invoice->set_props($data);
247 247
 
248 248
 	}
249 249
 
@@ -255,14 +255,14 @@  discard block
 block discarded – undo
255 255
 	 * @param  array   $meta_key_to_props   A mapping of prop => value.
256 256
 	 * @return array                        A mapping of field keys => prop names, filtered by ones that should be updated.
257 257
 	 */
258
-	protected function get_special_fields_to_update( $invoice, $special_fields ) {
258
+	protected function get_special_fields_to_update($invoice, $special_fields) {
259 259
 		$props_to_update = array();
260 260
 		$changed_props   = $invoice->get_changes();
261 261
 
262 262
 		// Props should be updated if they are a part of the $changed array or don't exist yet.
263
-		foreach ( $special_fields as $prop => $value ) {
264
-			if ( array_key_exists( $prop, $changed_props ) ) {
265
-				$props_to_update[ $prop ] = $value;
263
+		foreach ($special_fields as $prop => $value) {
264
+			if (array_key_exists($prop, $changed_props)) {
265
+				$props_to_update[$prop] = $value;
266 266
 			}
267 267
 		}
268 268
 
@@ -274,52 +274,52 @@  discard block
 block discarded – undo
274 274
 	 *
275 275
 	 * @param WPInv_Invoice $invoice Invoice object.
276 276
      */
277
-    public function save_special_fields( $invoice ) {
277
+    public function save_special_fields($invoice) {
278 278
 		global $wpdb;
279 279
 
280 280
 		// Fields to update.
281
-		$fields = array (
281
+		$fields = array(
282 282
             'post_id'        => $invoice->get_id(),
283
-            'number'         => $invoice->get_number( 'edit' ),
284
-            'key'            => $invoice->get_key( 'edit' ),
285
-            'type'           => $invoice->get_type( 'edit' ),
286
-            'mode'           => $invoice->get_mode( 'edit' ),
287
-            'user_ip'        => $invoice->get_user_ip( 'edit' ),
288
-            'first_name'     => $invoice->get_first_name( 'edit' ),
289
-            'last_name'      => $invoice->get_last_name( 'edit' ),
290
-            'address'        => $invoice->get_address( 'edit' ),
291
-            'city'           => $invoice->get_city( 'edit' ),
292
-            'state'          => $invoice->get_state( 'edit' ),
293
-            'country'        => $invoice->get_country( 'edit' ),
294
-            'zip'            => $invoice->get_zip( 'edit' ),
295
-            'address_confirmed' => (int) $invoice->get_address_confirmed( 'edit' ),
296
-            'gateway'        => $invoice->get_gateway( 'edit' ),
297
-            'transaction_id' => $invoice->get_transaction_id( 'edit' ),
298
-            'currency'       => $invoice->get_currency( 'edit' ),
299
-            'subtotal'       => $invoice->get_subtotal( 'edit' ),
300
-            'total_tax'      => $invoice->get_total_tax( 'edit' ),
301
-            'total_fees'     => $invoice->get_total_fees( 'edit' ),
302
-            'total_discount' => $invoice->get_total_discount( 'edit' ),
303
-            'discount_code'  => $invoice->get_discount_code( 'edit' ),
304
-            'disable_taxes'  => (int) $invoice->get_disable_taxes( 'edit' ),
305
-            'due_date'       => $invoice->get_due_date( 'edit' ),
306
-            'completed_date' => $invoice->get_completed_date( 'edit' ),
307
-            'company'        => $invoice->get_company( 'edit' ),
308
-            'vat_number'     => $invoice->get_vat_number( 'edit' ),
309
-            'vat_rate'       => $invoice->get_vat_rate( 'edit' ),
283
+            'number'         => $invoice->get_number('edit'),
284
+            'key'            => $invoice->get_key('edit'),
285
+            'type'           => $invoice->get_type('edit'),
286
+            'mode'           => $invoice->get_mode('edit'),
287
+            'user_ip'        => $invoice->get_user_ip('edit'),
288
+            'first_name'     => $invoice->get_first_name('edit'),
289
+            'last_name'      => $invoice->get_last_name('edit'),
290
+            'address'        => $invoice->get_address('edit'),
291
+            'city'           => $invoice->get_city('edit'),
292
+            'state'          => $invoice->get_state('edit'),
293
+            'country'        => $invoice->get_country('edit'),
294
+            'zip'            => $invoice->get_zip('edit'),
295
+            'address_confirmed' => (int) $invoice->get_address_confirmed('edit'),
296
+            'gateway'        => $invoice->get_gateway('edit'),
297
+            'transaction_id' => $invoice->get_transaction_id('edit'),
298
+            'currency'       => $invoice->get_currency('edit'),
299
+            'subtotal'       => $invoice->get_subtotal('edit'),
300
+            'total_tax'      => $invoice->get_total_tax('edit'),
301
+            'total_fees'     => $invoice->get_total_fees('edit'),
302
+            'total_discount' => $invoice->get_total_discount('edit'),
303
+            'discount_code'  => $invoice->get_discount_code('edit'),
304
+            'disable_taxes'  => (int) $invoice->get_disable_taxes('edit'),
305
+            'due_date'       => $invoice->get_due_date('edit'),
306
+            'completed_date' => $invoice->get_completed_date('edit'),
307
+            'company'        => $invoice->get_company('edit'),
308
+            'vat_number'     => $invoice->get_vat_number('edit'),
309
+            'vat_rate'       => $invoice->get_vat_rate('edit'),
310 310
 		);
311 311
 
312 312
 		// Update the cache with our data
313
-		wp_cache_set( $invoice->get_id(), $fields, 'getpaid_invoice_special_fields' );
313
+		wp_cache_set($invoice->get_id(), $fields, 'getpaid_invoice_special_fields');
314 314
 
315 315
 		// The invoices table.
316 316
 		$table = $wpdb->prefix . 'getpaid_invoices';
317 317
 		$id    = (int) $invoice->get_id();
318
-		if ( $wpdb->get_var( "SELECT `post_id` FROM $table WHERE `post_id`= $id" ) ) {
318
+		if ($wpdb->get_var("SELECT `post_id` FROM $table WHERE `post_id`= $id")) {
319 319
 
320
-			$to_update = $this->get_special_fields_to_update( $invoice, $fields );
320
+			$to_update = $this->get_special_fields_to_update($invoice, $fields);
321 321
 
322
-			if ( empty( $to_update ) ) {
322
+			if (empty($to_update)) {
323 323
 				return;
324 324
 			}
325 325
 
@@ -330,33 +330,33 @@  discard block
 block discarded – undo
330 330
 				'adddress_confirmed' => 'address_confirmed',
331 331
 			);
332 332
 
333
-			foreach ( $changes as $to => $from ) {
334
-				if ( isset( $changes[ $from ] ) ) {
335
-					$changes[ $to ] = $changes[ $from ];
336
-					unset( $changes[ $from ] );
333
+			foreach ($changes as $to => $from) {
334
+				if (isset($changes[$from])) {
335
+					$changes[$to] = $changes[$from];
336
+					unset($changes[$from]);
337 337
 				}
338 338
 			}
339 339
 
340
-			$changes['total'] = $invoice->get_total( 'edit' );
341
-            $wpdb->update( $table, $fields, array( 'post_id' => $id ) );
340
+			$changes['total'] = $invoice->get_total('edit');
341
+            $wpdb->update($table, $fields, array('post_id' => $id));
342 342
 
343 343
         } else {
344 344
 
345 345
 			$fields['tax'] = $fields['total_tax'];
346
-			unset( $fields['total_tax'] );
346
+			unset($fields['total_tax']);
347 347
 
348 348
 			$fields['fees_total'] = $fields['total_fees'];
349
-			unset( $fields['total_fees'] );
349
+			unset($fields['total_fees']);
350 350
 
351 351
 			$fields['discount'] = $fields['total_discount'];
352
-			unset( $fields['total_discount'] );
352
+			unset($fields['total_discount']);
353 353
 
354 354
 			$fields['adddress_confirmed'] = $fields['address_confirmed'];
355
-			unset( $fields['address_confirmed'] );
355
+			unset($fields['address_confirmed']);
356 356
 			
357
-			$fields['total']   = $invoice->get_total( 'edit' );
357
+			$fields['total']   = $invoice->get_total('edit');
358 358
 			$fields['post_id'] = $id;
359
-            $wpdb->insert( $table, $fields );
359
+            $wpdb->insert($table, $fields);
360 360
 
361 361
 		}
362 362
 
@@ -367,30 +367,30 @@  discard block
 block discarded – undo
367 367
 	 *
368 368
 	 * @param WPInv_Invoice $invoice Invoice object.
369 369
      */
370
-    public function add_items( &$invoice ) {
370
+    public function add_items(&$invoice) {
371 371
 		global $wpdb;
372 372
 
373
-		$table =  $wpdb->prefix . 'getpaid_invoice_items';
373
+		$table = $wpdb->prefix . 'getpaid_invoice_items';
374 374
         $items = $wpdb->get_results(
375
-            $wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d", $invoice->get_id() )
375
+            $wpdb->prepare("SELECT * FROM $table WHERE `post_id`=%d", $invoice->get_id())
376 376
         );
377 377
 
378
-        if ( empty( $items ) ) {
378
+        if (empty($items)) {
379 379
             return;
380 380
 		}
381 381
 
382
-		foreach ( $items as $item_data ) {
383
-			$item = new GetPaid_Form_Item( $item_data->item_id );
382
+		foreach ($items as $item_data) {
383
+			$item = new GetPaid_Form_Item($item_data->item_id);
384 384
 
385 385
 			// Set item data.
386
-			$item->item_tax      = wpinv_sanitize_amount( $item_data->tax );
387
-			$item->item_discount = wpinv_sanitize_amount( $item_data->tax );
388
-			$item->set_name( $item_data->item_name );
389
-			$item->set_description( $item_data->item_description );
390
-			$item->set_price( $item_data->item_price );
391
-			$item->set_quantity( $item_data->quantity );
392
-
393
-			$invoice->add_item( $item );
386
+			$item->item_tax      = wpinv_sanitize_amount($item_data->tax);
387
+			$item->item_discount = wpinv_sanitize_amount($item_data->tax);
388
+			$item->set_name($item_data->item_name);
389
+			$item->set_description($item_data->item_description);
390
+			$item->set_price($item_data->item_price);
391
+			$item->set_quantity($item_data->quantity);
392
+
393
+			$invoice->add_item($item);
394 394
 		}
395 395
 
396 396
 	}
@@ -400,16 +400,16 @@  discard block
 block discarded – undo
400 400
 	 *
401 401
 	 * @param WPInv_Invoice $invoice Invoice object.
402 402
      */
403
-    public function save_items( $invoice ) {
403
+    public function save_items($invoice) {
404 404
 
405 405
 		// Delete previously existing items.
406
-		$this->delete_items( $invoice );
406
+		$this->delete_items($invoice);
407 407
 
408
-		$table   =  $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items';
408
+		$table = $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items';
409 409
         $to_save = $invoice->get_cart_details();
410 410
 
411
-		foreach ( $to_save as $item_data ) {
412
-			$GLOBALS['wpdb']->insert( $table, $item_data );
411
+		foreach ($to_save as $item_data) {
412
+			$GLOBALS['wpdb']->insert($table, $item_data);
413 413
 		}
414 414
 
415 415
 	}
@@ -419,9 +419,9 @@  discard block
 block discarded – undo
419 419
 	 *
420 420
 	 * @param WPInv_Invoice $invoice Invoice object.
421 421
      */
422
-    public function delete_items( $invoice ) {
423
-		$table =  $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items';
424
-		return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) );
422
+    public function delete_items($invoice) {
423
+		$table = $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items';
424
+		return $GLOBALS['wpdb']->delete($table, array('post_id' => $invoice->get_id()));
425 425
     }
426 426
 
427 427
 }
Please login to merge, or discard this patch.
includes/class-wpinv-ajax.php 1 patch
Spacing   +371 added lines, -371 removed lines patch added patch discarded remove patch
@@ -7,28 +7,28 @@  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
 class WPInv_Ajax {
15 15
     public static function init() {
16
-        add_action( 'init', array( __CLASS__, 'define_ajax' ), 0 );
17
-        add_action( 'template_redirect', array( __CLASS__, 'do_wpinv_ajax' ), 0 );
16
+        add_action('init', array(__CLASS__, 'define_ajax'), 0);
17
+        add_action('template_redirect', array(__CLASS__, 'do_wpinv_ajax'), 0);
18 18
         self::add_ajax_events();
19 19
     }
20 20
 
21 21
     public static function define_ajax() {
22
-        if ( !empty( $_GET['wpinv-ajax'] ) ) {
23
-            if ( ! defined( 'DOING_AJAX' ) ) {
24
-                define( 'DOING_AJAX', true );
22
+        if (!empty($_GET['wpinv-ajax'])) {
23
+            if (!defined('DOING_AJAX')) {
24
+                define('DOING_AJAX', true);
25 25
             }
26
-            if ( ! defined( 'WC_DOING_AJAX' ) ) {
27
-                define( 'WC_DOING_AJAX', true );
26
+            if (!defined('WC_DOING_AJAX')) {
27
+                define('WC_DOING_AJAX', true);
28 28
             }
29 29
             // Turn off display_errors during AJAX events to prevent malformed JSON
30
-            if ( ! WP_DEBUG || ( WP_DEBUG && ! WP_DEBUG_DISPLAY ) ) {
31
-                /** @scrutinizer ignore-unhandled */ @ini_set( 'display_errors', 0 );
30
+            if (!WP_DEBUG || (WP_DEBUG && !WP_DEBUG_DISPLAY)) {
31
+                /** @scrutinizer ignore-unhandled */ @ini_set('display_errors', 0);
32 32
             }
33 33
             $GLOBALS['wpdb']->hide_errors();
34 34
         }
@@ -37,24 +37,24 @@  discard block
 block discarded – undo
37 37
     public static function do_wpinv_ajax() {
38 38
         global $wp_query;
39 39
 
40
-        if ( !empty( $_GET['wpinv-ajax'] ) ) {
41
-            $wp_query->set( 'wpinv-ajax', sanitize_text_field( $_GET['wpinv-ajax'] ) );
40
+        if (!empty($_GET['wpinv-ajax'])) {
41
+            $wp_query->set('wpinv-ajax', sanitize_text_field($_GET['wpinv-ajax']));
42 42
         }
43 43
 
44
-        if ( $action = $wp_query->get( 'wpinv-ajax' ) ) {
44
+        if ($action = $wp_query->get('wpinv-ajax')) {
45 45
             self::wpinv_ajax_headers();
46
-            do_action( 'wpinv_ajax_' . sanitize_text_field( $action ) );
46
+            do_action('wpinv_ajax_' . sanitize_text_field($action));
47 47
             die();
48 48
         }
49 49
     }
50 50
     
51 51
     private static function wpinv_ajax_headers() {
52 52
         send_origin_headers();
53
-        /** @scrutinizer ignore-unhandled */ @header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) );
54
-        /** @scrutinizer ignore-unhandled */ @header( 'X-Robots-Tag: noindex' );
53
+        /** @scrutinizer ignore-unhandled */ @header('Content-Type: text/html; charset=' . get_option('blog_charset'));
54
+        /** @scrutinizer ignore-unhandled */ @header('X-Robots-Tag: noindex');
55 55
         send_nosniff_header();
56 56
         nocache_headers();
57
-        status_header( 200 );
57
+        status_header(200);
58 58
     }
59 59
     
60 60
     public static function add_ajax_events() {
@@ -82,41 +82,41 @@  discard block
 block discarded – undo
82 82
             'payment_form_refresh_prices' => true,
83 83
         );
84 84
 
85
-        foreach ( $ajax_events as $ajax_event => $nopriv ) {
86
-            add_action( 'wp_ajax_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) );
87
-            add_action( 'wp_ajax_getpaid_' . $ajax_event, array( __CLASS__, $ajax_event ) );
85
+        foreach ($ajax_events as $ajax_event => $nopriv) {
86
+            add_action('wp_ajax_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event));
87
+            add_action('wp_ajax_getpaid_' . $ajax_event, array(__CLASS__, $ajax_event));
88 88
             
89
-            if ( !defined( 'WPI_AJAX_' . strtoupper( $nopriv ) ) ) {
90
-                define( 'WPI_AJAX_' . strtoupper( $nopriv ), 1 );
89
+            if (!defined('WPI_AJAX_' . strtoupper($nopriv))) {
90
+                define('WPI_AJAX_' . strtoupper($nopriv), 1);
91 91
             }
92 92
 
93
-            if ( $nopriv ) {
94
-                add_action( 'wp_ajax_nopriv_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) );
95
-                add_action( 'wp_ajax_nopriv_getpaid_' . $ajax_event, array( __CLASS__, $ajax_event ) );
93
+            if ($nopriv) {
94
+                add_action('wp_ajax_nopriv_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event));
95
+                add_action('wp_ajax_nopriv_getpaid_' . $ajax_event, array(__CLASS__, $ajax_event));
96 96
 
97
-                add_action( 'wpinv_ajax_' . $ajax_event, array( __CLASS__, $ajax_event ) );
97
+                add_action('wpinv_ajax_' . $ajax_event, array(__CLASS__, $ajax_event));
98 98
             }
99 99
         }
100 100
     }
101 101
     
102 102
     public static function add_note() {
103
-        check_ajax_referer( 'add-invoice-note', '_nonce' );
103
+        check_ajax_referer('add-invoice-note', '_nonce');
104 104
 
105
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
105
+        if (!wpinv_current_user_can_manage_invoicing()) {
106 106
             die(-1);
107 107
         }
108 108
 
109
-        $post_id   = absint( $_POST['post_id'] );
110
-        $note      = wp_kses_post( trim( stripslashes( $_POST['note'] ) ) );
111
-        $note_type = sanitize_text_field( $_POST['note_type'] );
109
+        $post_id   = absint($_POST['post_id']);
110
+        $note      = wp_kses_post(trim(stripslashes($_POST['note'])));
111
+        $note_type = sanitize_text_field($_POST['note_type']);
112 112
 
113 113
         $is_customer_note = $note_type == 'customer' ? 1 : 0;
114 114
 
115
-        if ( $post_id > 0 ) {
116
-            $note_id = wpinv_insert_payment_note( $post_id, $note, $is_customer_note );
115
+        if ($post_id > 0) {
116
+            $note_id = wpinv_insert_payment_note($post_id, $note, $is_customer_note);
117 117
 
118
-            if ( $note_id > 0 && !is_wp_error( $note_id ) ) {
119
-                wpinv_get_invoice_note_line_item( $note_id );
118
+            if ($note_id > 0 && !is_wp_error($note_id)) {
119
+                wpinv_get_invoice_note_line_item($note_id);
120 120
             }
121 121
         }
122 122
 
@@ -124,16 +124,16 @@  discard block
 block discarded – undo
124 124
     }
125 125
 
126 126
     public static function delete_note() {
127
-        check_ajax_referer( 'delete-invoice-note', '_nonce' );
127
+        check_ajax_referer('delete-invoice-note', '_nonce');
128 128
 
129
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
129
+        if (!wpinv_current_user_can_manage_invoicing()) {
130 130
             die(-1);
131 131
         }
132 132
 
133
-        $note_id = (int)$_POST['note_id'];
133
+        $note_id = (int) $_POST['note_id'];
134 134
 
135
-        if ( $note_id > 0 ) {
136
-            wp_delete_comment( $note_id, true );
135
+        if ($note_id > 0) {
136
+            wp_delete_comment($note_id, true);
137 137
         }
138 138
 
139 139
         die();
@@ -146,8 +146,8 @@  discard block
 block discarded – undo
146 146
     }
147 147
     
148 148
     public static function checkout() {
149
-        if ( ! defined( 'WPINV_CHECKOUT' ) ) {
150
-            define( 'WPINV_CHECKOUT', true );
149
+        if (!defined('WPINV_CHECKOUT')) {
150
+            define('WPINV_CHECKOUT', true);
151 151
         }
152 152
 
153 153
         wpinv_process_checkout();
@@ -156,53 +156,53 @@  discard block
 block discarded – undo
156 156
     
157 157
     public static function add_invoice_item() {
158 158
         global $wpi_userID, $wpinv_ip_address_country;
159
-        check_ajax_referer( 'invoice-item', '_nonce' );
160
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
159
+        check_ajax_referer('invoice-item', '_nonce');
160
+        if (!wpinv_current_user_can_manage_invoicing()) {
161 161
             die(-1);
162 162
         }
163 163
         
164
-        $item_id    = sanitize_text_field( $_POST['item_id'] );
165
-        $invoice_id = absint( $_POST['invoice_id'] );
164
+        $item_id    = sanitize_text_field($_POST['item_id']);
165
+        $invoice_id = absint($_POST['invoice_id']);
166 166
         
167
-        if ( !is_numeric( $invoice_id ) || !is_numeric( $item_id ) ) {
167
+        if (!is_numeric($invoice_id) || !is_numeric($item_id)) {
168 168
             die();
169 169
         }
170 170
         
171
-        $invoice    = wpinv_get_invoice( $invoice_id );
172
-        if ( empty( $invoice ) ) {
171
+        $invoice = wpinv_get_invoice($invoice_id);
172
+        if (empty($invoice)) {
173 173
             die();
174 174
         }
175 175
         
176
-        if ( $invoice->is_paid() || $invoice->is_refunded() ) {
176
+        if ($invoice->is_paid() || $invoice->is_refunded()) {
177 177
             die(); // Don't allow modify items for paid invoice.
178 178
         }
179 179
         
180
-        if ( !empty( $_POST['user_id'] ) ) {
181
-            $wpi_userID = absint( $_POST['user_id'] ); 
180
+        if (!empty($_POST['user_id'])) {
181
+            $wpi_userID = absint($_POST['user_id']); 
182 182
         }
183 183
 
184
-        $item = new WPInv_Item( $item_id );
185
-        if ( !( !empty( $item ) && $item->post_type == 'wpi_item' ) ) {
184
+        $item = new WPInv_Item($item_id);
185
+        if (!(!empty($item) && $item->post_type == 'wpi_item')) {
186 186
             die();
187 187
         }
188 188
         
189 189
         // Validate item before adding to invoice because recurring item must be paid individually.
190
-        if ( !empty( $invoice->cart_details ) ) {
190
+        if (!empty($invoice->cart_details)) {
191 191
             $valid = true;
192 192
             
193
-            if ( $recurring_item = $invoice->get_recurring() ) {
194
-                if ( $recurring_item != $item_id ) {
193
+            if ($recurring_item = $invoice->get_recurring()) {
194
+                if ($recurring_item != $item_id) {
195 195
                     $valid = false;
196 196
                 }
197
-            } else if ( wpinv_is_recurring_item( $item_id ) ) {
197
+            } else if (wpinv_is_recurring_item($item_id)) {
198 198
                 $valid = false;
199 199
             }
200 200
             
201
-            if ( !$valid ) {
201
+            if (!$valid) {
202 202
                 $response               = array();
203 203
                 $response['success']    = false;
204
-                $response['msg']        = __( 'You can not add item because recurring item must be paid individually!', 'invoicing' );
205
-                wp_send_json( $response );
204
+                $response['msg']        = __('You can not add item because recurring item must be paid individually!', 'invoicing');
205
+                wp_send_json($response);
206 206
             }
207 207
         }
208 208
         
@@ -210,11 +210,11 @@  discard block
 block discarded – undo
210 210
         
211 211
         $data                   = array();
212 212
         $data['invoice_id']     = $invoice_id;
213
-        $data['cart_discounts'] = $invoice->get_discounts( true );
213
+        $data['cart_discounts'] = $invoice->get_discounts(true);
214 214
         
215
-        wpinv_set_checkout_session( $data );
215
+        wpinv_set_checkout_session($data);
216 216
         
217
-        $quantity = wpinv_item_quantities_enabled() && !empty($_POST['qty']) && (int)$_POST['qty'] > 0 ? (int)$_POST['qty'] : 1;
217
+        $quantity = wpinv_item_quantities_enabled() && !empty($_POST['qty']) && (int) $_POST['qty'] > 0 ? (int) $_POST['qty'] : 1;
218 218
 
219 219
         $args = array(
220 220
             'id'            => $item_id,
@@ -227,21 +227,21 @@  discard block
 block discarded – undo
227 227
             'fees'          => array()
228 228
         );
229 229
 
230
-        $invoice->add_item( $item_id, $args );
230
+        $invoice->add_item($item_id, $args);
231 231
         $invoice->save();
232 232
         
233
-        if ( empty( $_POST['country'] ) ) {
233
+        if (empty($_POST['country'])) {
234 234
             $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country();
235 235
         }
236
-        if ( empty( $_POST['state'] ) ) {
236
+        if (empty($_POST['state'])) {
237 237
             $_POST['state'] = $invoice->state;
238 238
         }
239 239
          
240
-        $invoice->country   = sanitize_text_field( $_POST['country'] );
241
-        $invoice->state     = sanitize_text_field( $_POST['state'] );
240
+        $invoice->country   = sanitize_text_field($_POST['country']);
241
+        $invoice->state     = sanitize_text_field($_POST['state']);
242 242
         
243
-        $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) );
244
-        $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) );
243
+        $invoice->set('country', sanitize_text_field($_POST['country']));
244
+        $invoice->set('state', sanitize_text_field($_POST['state']));
245 245
         
246 246
         $wpinv_ip_address_country = $invoice->country;
247 247
 
@@ -249,7 +249,7 @@  discard block
 block discarded – undo
249 249
         
250 250
         $response                       = array();
251 251
         $response['success']            = true;
252
-        $response['data']['items']      = wpinv_admin_get_line_items( $invoice );
252
+        $response['data']['items']      = wpinv_admin_get_line_items($invoice);
253 253
         $response['data']['subtotal']   = $invoice->get_subtotal();
254 254
         $response['data']['subtotalf']  = $invoice->get_subtotal(true);
255 255
         $response['data']['tax']        = $invoice->get_tax();
@@ -261,41 +261,41 @@  discard block
 block discarded – undo
261 261
         
262 262
         wpinv_set_checkout_session($checkout_session);
263 263
         
264
-        wp_send_json( $response );
264
+        wp_send_json($response);
265 265
     }
266 266
 
267 267
 
268 268
     public static function remove_invoice_item() {
269 269
         global $wpi_userID, $wpinv_ip_address_country;
270 270
         
271
-        check_ajax_referer( 'invoice-item', '_nonce' );
272
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
271
+        check_ajax_referer('invoice-item', '_nonce');
272
+        if (!wpinv_current_user_can_manage_invoicing()) {
273 273
             die(-1);
274 274
         }
275 275
         
276
-        $item_id    = sanitize_text_field( $_POST['item_id'] );
277
-        $invoice_id = absint( $_POST['invoice_id'] );
278
-        $cart_index = isset( $_POST['index'] ) && $_POST['index'] >= 0 ? $_POST['index'] : false;
276
+        $item_id    = sanitize_text_field($_POST['item_id']);
277
+        $invoice_id = absint($_POST['invoice_id']);
278
+        $cart_index = isset($_POST['index']) && $_POST['index'] >= 0 ? $_POST['index'] : false;
279 279
         
280
-        if ( !is_numeric( $invoice_id ) || !is_numeric( $item_id ) ) {
280
+        if (!is_numeric($invoice_id) || !is_numeric($item_id)) {
281 281
             die();
282 282
         }
283 283
 
284
-        $invoice    = wpinv_get_invoice( $invoice_id );
285
-        if ( empty( $invoice ) ) {
284
+        $invoice = wpinv_get_invoice($invoice_id);
285
+        if (empty($invoice)) {
286 286
             die();
287 287
         }
288 288
         
289
-        if ( $invoice->is_paid() || $invoice->is_refunded() ) {
289
+        if ($invoice->is_paid() || $invoice->is_refunded()) {
290 290
             die(); // Don't allow modify items for paid invoice.
291 291
         }
292 292
         
293
-        if ( !empty( $_POST['user_id'] ) ) {
294
-            $wpi_userID = absint( $_POST['user_id'] ); 
293
+        if (!empty($_POST['user_id'])) {
294
+            $wpi_userID = absint($_POST['user_id']); 
295 295
         }
296 296
 
297
-        $item       = new WPInv_Item( $item_id );
298
-        if ( !( !empty( $item ) && $item->post_type == 'wpi_item' ) ) {
297
+        $item = new WPInv_Item($item_id);
298
+        if (!(!empty($item) && $item->post_type == 'wpi_item')) {
299 299
             die();
300 300
         }
301 301
         
@@ -303,9 +303,9 @@  discard block
 block discarded – undo
303 303
         
304 304
         $data                   = array();
305 305
         $data['invoice_id']     = $invoice_id;
306
-        $data['cart_discounts'] = $invoice->get_discounts( true );
306
+        $data['cart_discounts'] = $invoice->get_discounts(true);
307 307
         
308
-        wpinv_set_checkout_session( $data );
308
+        wpinv_set_checkout_session($data);
309 309
 
310 310
         $args = array(
311 311
             'id'         => $item_id,
@@ -313,21 +313,21 @@  discard block
 block discarded – undo
313 313
             'cart_index' => $cart_index
314 314
         );
315 315
 
316
-        $invoice->remove_item( $item_id, $args );
316
+        $invoice->remove_item($item_id, $args);
317 317
         $invoice->save();
318 318
         
319
-        if ( empty( $_POST['country'] ) ) {
319
+        if (empty($_POST['country'])) {
320 320
             $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country();
321 321
         }
322
-        if ( empty( $_POST['state'] ) ) {
322
+        if (empty($_POST['state'])) {
323 323
             $_POST['state'] = $invoice->state;
324 324
         }
325 325
          
326
-        $invoice->country   = sanitize_text_field( $_POST['country'] );
327
-        $invoice->state     = sanitize_text_field( $_POST['state'] );
326
+        $invoice->country   = sanitize_text_field($_POST['country']);
327
+        $invoice->state     = sanitize_text_field($_POST['state']);
328 328
         
329
-        $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) );
330
-        $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) );
329
+        $invoice->set('country', sanitize_text_field($_POST['country']));
330
+        $invoice->set('state', sanitize_text_field($_POST['state']));
331 331
         
332 332
         $wpinv_ip_address_country = $invoice->country;
333 333
         
@@ -335,7 +335,7 @@  discard block
 block discarded – undo
335 335
         
336 336
         $response                       = array();
337 337
         $response['success']            = true;
338
-        $response['data']['items']      = wpinv_admin_get_line_items( $invoice );
338
+        $response['data']['items']      = wpinv_admin_get_line_items($invoice);
339 339
         $response['data']['subtotal']   = $invoice->get_subtotal();
340 340
         $response['data']['subtotalf']  = $invoice->get_subtotal(true);
341 341
         $response['data']['tax']        = $invoice->get_tax();
@@ -347,55 +347,55 @@  discard block
 block discarded – undo
347 347
         
348 348
         wpinv_set_checkout_session($checkout_session);
349 349
         
350
-        wp_send_json( $response );
350
+        wp_send_json($response);
351 351
     }
352 352
     
353 353
     public static function create_invoice_item() {
354
-        check_ajax_referer( 'invoice-item', '_nonce' );
355
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
354
+        check_ajax_referer('invoice-item', '_nonce');
355
+        if (!wpinv_current_user_can_manage_invoicing()) {
356 356
             die(-1);
357 357
         }
358 358
         
359
-        $invoice_id = absint( $_POST['invoice_id'] );
359
+        $invoice_id = absint($_POST['invoice_id']);
360 360
 
361 361
         // Find the item
362
-        if ( !is_numeric( $invoice_id ) ) {
362
+        if (!is_numeric($invoice_id)) {
363 363
             die();
364 364
         }        
365 365
         
366
-        $invoice     = wpinv_get_invoice( $invoice_id );
367
-        if ( empty( $invoice ) ) {
366
+        $invoice = wpinv_get_invoice($invoice_id);
367
+        if (empty($invoice)) {
368 368
             die();
369 369
         }
370 370
         
371 371
         // Validate item before adding to invoice because recurring item must be paid individually.
372
-        if ( !empty( $invoice->cart_details ) && $invoice->get_recurring() ) {
372
+        if (!empty($invoice->cart_details) && $invoice->get_recurring()) {
373 373
             $response               = array();
374 374
             $response['success']    = false;
375
-            $response['msg']        = __( 'You can not add item because recurring item must be paid individually!', 'invoicing' );
376
-            wp_send_json( $response );
375
+            $response['msg']        = __('You can not add item because recurring item must be paid individually!', 'invoicing');
376
+            wp_send_json($response);
377 377
         }        
378 378
         
379
-        $save_item = wp_unslash( $_POST['_wpinv_quick'] );
379
+        $save_item = wp_unslash($_POST['_wpinv_quick']);
380 380
         
381 381
         $meta               = array();
382 382
         $meta['type']       = !empty($save_item['type']) ? sanitize_text_field($save_item['type']) : 'custom';
383
-        $meta['price']      = !empty($save_item['price']) ? wpinv_sanitize_amount( $save_item['price'] ) : 0;
383
+        $meta['price']      = !empty($save_item['price']) ? wpinv_sanitize_amount($save_item['price']) : 0;
384 384
         $meta['vat_rule']   = !empty($save_item['vat_rule']) ? sanitize_text_field($save_item['vat_rule']) : 'digital';
385 385
         $meta['vat_class']  = !empty($save_item['vat_class']) ? sanitize_text_field($save_item['vat_class']) : '_standard';
386 386
         
387 387
         $data                   = array();
388 388
         $data['post_title']     = sanitize_text_field($save_item['name']);
389 389
         $data['post_status']    = 'publish';
390
-        $data['post_excerpt']   = ! empty( $save_item['excerpt'] ) ? wp_kses_post( $save_item['excerpt'] ) : '';
390
+        $data['post_excerpt']   = !empty($save_item['excerpt']) ? wp_kses_post($save_item['excerpt']) : '';
391 391
         $data['meta']           = $meta;
392 392
         
393 393
         $item = new WPInv_Item();
394
-        $item->create( $data );
394
+        $item->create($data);
395 395
         
396
-        if ( !empty( $item ) ) {
396
+        if (!empty($item)) {
397 397
             $_POST['item_id']   = $item->ID;
398
-            $_POST['qty']       = !empty($save_item['qty']) && $save_item['qty'] > 0 ? (int)$save_item['qty'] : 1;
398
+            $_POST['qty']       = !empty($save_item['qty']) && $save_item['qty'] > 0 ? (int) $save_item['qty'] : 1;
399 399
             
400 400
             self::add_invoice_item();
401 401
         }
@@ -408,48 +408,48 @@  discard block
 block discarded – undo
408 408
     public static function get_billing_details() {
409 409
 
410 410
         // Verify nonce.
411
-        check_ajax_referer( 'wpinv-nonce' );
411
+        check_ajax_referer('wpinv-nonce');
412 412
 
413 413
         // Can the user manage the plugin?
414
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
414
+        if (!wpinv_current_user_can_manage_invoicing()) {
415 415
             die(-1);
416 416
         }
417 417
 
418 418
         // Do we have a user id?
419 419
         $user_id = $_GET['user_id'];
420 420
 
421
-        if ( empty( $user_id ) || ! is_numeric( $user_id ) ) {
421
+        if (empty($user_id) || !is_numeric($user_id)) {
422 422
             die(-1);
423 423
         }
424 424
 
425 425
         // Fetch the billing details.
426
-        $billing_details    = wpinv_get_user_address( $user_id );
427
-        $billing_details    = apply_filters( 'wpinv_ajax_billing_details', $billing_details, $user_id );
426
+        $billing_details    = wpinv_get_user_address($user_id);
427
+        $billing_details    = apply_filters('wpinv_ajax_billing_details', $billing_details, $user_id);
428 428
 
429 429
         // unset the user id and email.
430
-        $to_ignore = array( 'user_id', 'email' );
430
+        $to_ignore = array('user_id', 'email');
431 431
 
432
-        foreach ( $to_ignore as $key ) {
433
-            if ( isset( $billing_details[ $key ] ) ) {
434
-                unset( $billing_details[ $key ] );
432
+        foreach ($to_ignore as $key) {
433
+            if (isset($billing_details[$key])) {
434
+                unset($billing_details[$key]);
435 435
             }
436 436
         }
437 437
 
438
-        wp_send_json_success( $billing_details );
438
+        wp_send_json_success($billing_details);
439 439
 
440 440
     }
441 441
     
442 442
     public static function admin_recalculate_totals() {
443 443
         global $wpi_userID, $wpinv_ip_address_country;
444 444
         
445
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
446
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
445
+        check_ajax_referer('wpinv-nonce', '_nonce');
446
+        if (!wpinv_current_user_can_manage_invoicing()) {
447 447
             die(-1);
448 448
         }
449 449
         
450
-        $invoice_id = absint( $_POST['invoice_id'] );        
451
-        $invoice    = wpinv_get_invoice( $invoice_id );
452
-        if ( empty( $invoice ) ) {
450
+        $invoice_id = absint($_POST['invoice_id']);        
451
+        $invoice    = wpinv_get_invoice($invoice_id);
452
+        if (empty($invoice)) {
453 453
             die();
454 454
         }
455 455
 
@@ -457,29 +457,29 @@  discard block
 block discarded – undo
457 457
 
458 458
         $data                   = array();
459 459
         $data['invoice_id']     = $invoice_id;
460
-        $data['cart_discounts'] = $invoice->get_discounts( true );
460
+        $data['cart_discounts'] = $invoice->get_discounts(true);
461 461
 
462
-        wpinv_set_checkout_session( $data );
462
+        wpinv_set_checkout_session($data);
463 463
         
464
-        if ( !empty( $_POST['user_id'] ) ) {
465
-            $wpi_userID = absint( $_POST['user_id'] ); 
464
+        if (!empty($_POST['user_id'])) {
465
+            $wpi_userID = absint($_POST['user_id']); 
466 466
         }
467 467
         
468
-        if ( empty( $_POST['country'] ) ) {
468
+        if (empty($_POST['country'])) {
469 469
             $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country();
470 470
         }
471 471
 
472 472
         $disable_taxes = 0;
473
-        if ( ! empty( $_POST['disable_taxes'] ) ) {
473
+        if (!empty($_POST['disable_taxes'])) {
474 474
             $disable_taxes = 1;
475 475
         }
476
-        $invoice->set( 'disable_taxes', $disable_taxes );
476
+        $invoice->set('disable_taxes', $disable_taxes);
477 477
 
478
-        $invoice->country = sanitize_text_field( $_POST['country'] );
479
-        $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) );
480
-        if ( isset( $_POST['state'] ) ) {
481
-            $invoice->state = sanitize_text_field( $_POST['state'] );
482
-            $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) );
478
+        $invoice->country = sanitize_text_field($_POST['country']);
479
+        $invoice->set('country', sanitize_text_field($_POST['country']));
480
+        if (isset($_POST['state'])) {
481
+            $invoice->state = sanitize_text_field($_POST['state']);
482
+            $invoice->set('state', sanitize_text_field($_POST['state']));
483 483
         }
484 484
         
485 485
         $wpinv_ip_address_country = $invoice->country;
@@ -488,7 +488,7 @@  discard block
 block discarded – undo
488 488
         
489 489
         $response                       = array();
490 490
         $response['success']            = true;
491
-        $response['data']['items']      = wpinv_admin_get_line_items( $invoice );
491
+        $response['data']['items']      = wpinv_admin_get_line_items($invoice);
492 492
         $response['data']['subtotal']   = $invoice->get_subtotal();
493 493
         $response['data']['subtotalf']  = $invoice->get_subtotal(true);
494 494
         $response['data']['tax']        = $invoice->get_tax();
@@ -500,25 +500,25 @@  discard block
 block discarded – undo
500 500
         
501 501
         wpinv_set_checkout_session($checkout_session);
502 502
 
503
-        wp_send_json( $response );
503
+        wp_send_json($response);
504 504
     }
505 505
     
506 506
     public static function admin_apply_discount() {
507 507
         global $wpi_userID;
508 508
         
509
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
510
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
509
+        check_ajax_referer('wpinv-nonce', '_nonce');
510
+        if (!wpinv_current_user_can_manage_invoicing()) {
511 511
             die(-1);
512 512
         }
513 513
         
514
-        $invoice_id = absint( $_POST['invoice_id'] );
515
-        $discount_code = sanitize_text_field( $_POST['code'] );
516
-        if ( empty( $invoice_id ) || empty( $discount_code ) ) {
514
+        $invoice_id = absint($_POST['invoice_id']);
515
+        $discount_code = sanitize_text_field($_POST['code']);
516
+        if (empty($invoice_id) || empty($discount_code)) {
517 517
             die();
518 518
         }
519 519
         
520
-        $invoice = wpinv_get_invoice( $invoice_id );
521
-        if ( empty( $invoice ) || ( !empty( $invoice ) && ( $invoice->is_paid() || $invoice->is_refunded() ) ) ) {
520
+        $invoice = wpinv_get_invoice($invoice_id);
521
+        if (empty($invoice) || (!empty($invoice) && ($invoice->is_paid() || $invoice->is_refunded()))) {
522 522
             die();
523 523
         }
524 524
         
@@ -526,49 +526,49 @@  discard block
 block discarded – undo
526 526
         
527 527
         $data                   = array();
528 528
         $data['invoice_id']     = $invoice_id;
529
-        $data['cart_discounts'] = $invoice->get_discounts( true );
529
+        $data['cart_discounts'] = $invoice->get_discounts(true);
530 530
         
531
-        wpinv_set_checkout_session( $data );
531
+        wpinv_set_checkout_session($data);
532 532
         
533 533
         $response               = array();
534 534
         $response['success']    = false;
535
-        $response['msg']        = __( 'This discount is invalid.', 'invoicing' );
535
+        $response['msg']        = __('This discount is invalid.', 'invoicing');
536 536
         $response['data']['code'] = $discount_code;
537 537
         
538
-        if ( wpinv_is_discount_valid( $discount_code, $invoice->get_user_id() ) ) {
539
-            $discounts = wpinv_set_cart_discount( $discount_code );
538
+        if (wpinv_is_discount_valid($discount_code, $invoice->get_user_id())) {
539
+            $discounts = wpinv_set_cart_discount($discount_code);
540 540
             
541 541
             $response['success'] = true;
542
-            $response['msg'] = __( 'Discount has been applied successfully.', 'invoicing' );
543
-        }  else {
542
+            $response['msg'] = __('Discount has been applied successfully.', 'invoicing');
543
+        } else {
544 544
             $errors = wpinv_get_errors();
545
-            if ( !empty( $errors['wpinv-discount-error'] ) ) {
545
+            if (!empty($errors['wpinv-discount-error'])) {
546 546
                 $response['msg'] = $errors['wpinv-discount-error'];
547 547
             }
548
-            wpinv_unset_error( 'wpinv-discount-error' );
548
+            wpinv_unset_error('wpinv-discount-error');
549 549
         }
550 550
         
551 551
         wpinv_set_checkout_session($checkout_session);
552 552
         
553
-        wp_send_json( $response );
553
+        wp_send_json($response);
554 554
     }
555 555
     
556 556
     public static function admin_remove_discount() {
557 557
         global $wpi_userID;
558 558
         
559
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
560
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
559
+        check_ajax_referer('wpinv-nonce', '_nonce');
560
+        if (!wpinv_current_user_can_manage_invoicing()) {
561 561
             die(-1);
562 562
         }
563 563
         
564
-        $invoice_id = absint( $_POST['invoice_id'] );
565
-        $discount_code = sanitize_text_field( $_POST['code'] );
566
-        if ( empty( $invoice_id ) || empty( $discount_code ) ) {
564
+        $invoice_id = absint($_POST['invoice_id']);
565
+        $discount_code = sanitize_text_field($_POST['code']);
566
+        if (empty($invoice_id) || empty($discount_code)) {
567 567
             die();
568 568
         }
569 569
         
570
-        $invoice = wpinv_get_invoice( $invoice_id );
571
-        if ( empty( $invoice ) || ( !empty( $invoice ) && ( $invoice->is_paid() || $invoice->is_refunded() ) ) ) {
570
+        $invoice = wpinv_get_invoice($invoice_id);
571
+        if (empty($invoice) || (!empty($invoice) && ($invoice->is_paid() || $invoice->is_refunded()))) {
572 572
             die();
573 573
         }
574 574
         
@@ -576,21 +576,21 @@  discard block
 block discarded – undo
576 576
         
577 577
         $data                   = array();
578 578
         $data['invoice_id']     = $invoice_id;
579
-        $data['cart_discounts'] = $invoice->get_discounts( true );
579
+        $data['cart_discounts'] = $invoice->get_discounts(true);
580 580
         
581
-        wpinv_set_checkout_session( $data );
581
+        wpinv_set_checkout_session($data);
582 582
         
583 583
         $response               = array();
584 584
         $response['success']    = false;
585 585
         $response['msg']        = NULL;
586 586
         
587
-        $discounts  = wpinv_unset_cart_discount( $discount_code );
587
+        $discounts = wpinv_unset_cart_discount($discount_code);
588 588
         $response['success'] = true;
589
-        $response['msg'] = __( 'Discount has been removed successfully.', 'invoicing' );
589
+        $response['msg'] = __('Discount has been removed successfully.', 'invoicing');
590 590
         
591 591
         wpinv_set_checkout_session($checkout_session);
592 592
         
593
-        wp_send_json( $response );
593
+        wp_send_json($response);
594 594
     }
595 595
 
596 596
     /**
@@ -599,80 +599,80 @@  discard block
 block discarded – undo
599 599
     public static function check_new_user_email() {
600 600
 
601 601
         // Verify nonce.
602
-        check_ajax_referer( 'wpinv-nonce' );
602
+        check_ajax_referer('wpinv-nonce');
603 603
 
604 604
         // Can the user manage the plugin?
605
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
605
+        if (!wpinv_current_user_can_manage_invoicing()) {
606 606
             die(-1);
607 607
         }
608 608
 
609 609
         // We need an email address.
610
-        if ( empty( $_GET['email'] ) ) {
611
-            _e( "Provide the new user's email address", 'invoicing' );
610
+        if (empty($_GET['email'])) {
611
+            _e("Provide the new user's email address", 'invoicing');
612 612
             exit;
613 613
         }
614 614
 
615 615
         // Ensure the email is valid.
616
-        $email = sanitize_text_field( $_GET['email'] );
617
-        if ( ! is_email( $email ) ) {
618
-            _e( 'Invalid email address', 'invoicing' );
616
+        $email = sanitize_text_field($_GET['email']);
617
+        if (!is_email($email)) {
618
+            _e('Invalid email address', 'invoicing');
619 619
             exit;
620 620
         }
621 621
 
622 622
         // And it does not exist.
623
-        if ( email_exists( $email ) ) {
624
-            _e( 'A user with this email address already exists', 'invoicing' );
623
+        if (email_exists($email)) {
624
+            _e('A user with this email address already exists', 'invoicing');
625 625
             exit;
626 626
         }
627 627
 
628
-        wp_send_json_success( true );
628
+        wp_send_json_success(true);
629 629
     }
630 630
     
631 631
     public static function run_tool() {
632
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
633
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
632
+        check_ajax_referer('wpinv-nonce', '_nonce');
633
+        if (!wpinv_current_user_can_manage_invoicing()) {
634 634
             die(-1);
635 635
         }
636 636
         
637
-        $tool = sanitize_text_field( $_POST['tool'] );
637
+        $tool = sanitize_text_field($_POST['tool']);
638 638
         
639
-        do_action( 'wpinv_run_tool' );
639
+        do_action('wpinv_run_tool');
640 640
         
641
-        if ( !empty( $tool ) ) {
642
-            do_action( 'wpinv_tool_' . $tool );
641
+        if (!empty($tool)) {
642
+            do_action('wpinv_tool_' . $tool);
643 643
         }
644 644
     }
645 645
     
646 646
     public static function apply_discount() {
647 647
         global $wpi_userID;
648 648
         
649
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
649
+        check_ajax_referer('wpinv-nonce', '_nonce');
650 650
         
651 651
         $response = array();
652 652
         
653
-        if ( isset( $_POST['code'] ) ) {
654
-            $discount_code = sanitize_text_field( $_POST['code'] );
653
+        if (isset($_POST['code'])) {
654
+            $discount_code = sanitize_text_field($_POST['code']);
655 655
 
656 656
             $response['success']        = false;
657 657
             $response['msg']            = '';
658 658
             $response['data']['code']   = $discount_code;
659 659
             
660 660
             $invoice = wpinv_get_invoice_cart();
661
-            if ( empty( $invoice->ID ) ) {
662
-                $response['msg'] = __( 'Invalid checkout request.', 'invoicing' );
663
-                wp_send_json( $response );
661
+            if (empty($invoice->ID)) {
662
+                $response['msg'] = __('Invalid checkout request.', 'invoicing');
663
+                wp_send_json($response);
664 664
             }
665 665
 
666 666
             $wpi_userID = $invoice->get_user_id();
667 667
 
668
-            if ( wpinv_is_discount_valid( $discount_code, $wpi_userID ) ) {
669
-                $discount       = wpinv_get_discount_by_code( $discount_code );
670
-                $discounts      = wpinv_set_cart_discount( $discount_code );
671
-                $amount         = wpinv_format_discount_rate( wpinv_get_discount_type( $discount->ID ), wpinv_get_discount_amount( $discount->ID ) );
672
-                $total          = wpinv_get_cart_total( null, $discounts );
673
-                $cart_totals    = wpinv_recalculate_tax( true );
668
+            if (wpinv_is_discount_valid($discount_code, $wpi_userID)) {
669
+                $discount       = wpinv_get_discount_by_code($discount_code);
670
+                $discounts      = wpinv_set_cart_discount($discount_code);
671
+                $amount         = wpinv_format_discount_rate(wpinv_get_discount_type($discount->ID), wpinv_get_discount_amount($discount->ID));
672
+                $total          = wpinv_get_cart_total(null, $discounts);
673
+                $cart_totals    = wpinv_recalculate_tax(true);
674 674
             
675
-                if ( !empty( $cart_totals ) ) {
675
+                if (!empty($cart_totals)) {
676 676
                     $response['success']        = true;
677 677
                     $response['data']           = $cart_totals;
678 678
                     $response['data']['code']   = $discount_code;
@@ -681,29 +681,29 @@  discard block
 block discarded – undo
681 681
                 }
682 682
             } else {
683 683
                 $errors = wpinv_get_errors();
684
-                $response['msg']  = $errors['wpinv-discount-error'];
685
-                wpinv_unset_error( 'wpinv-discount-error' );
684
+                $response['msg'] = $errors['wpinv-discount-error'];
685
+                wpinv_unset_error('wpinv-discount-error');
686 686
             }
687 687
 
688 688
             // Allow for custom discount code handling
689
-            $response = apply_filters( 'wpinv_ajax_discount_response', $response );
689
+            $response = apply_filters('wpinv_ajax_discount_response', $response);
690 690
         }
691 691
         
692
-        wp_send_json( $response );
692
+        wp_send_json($response);
693 693
     }
694 694
     
695 695
     public static function remove_discount() {
696
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
696
+        check_ajax_referer('wpinv-nonce', '_nonce');
697 697
         
698 698
         $response = array();
699 699
         
700
-        if ( isset( $_POST['code'] ) ) {
701
-            $discount_code  = sanitize_text_field( $_POST['code'] );
702
-            $discounts      = wpinv_unset_cart_discount( $discount_code );
703
-            $total          = wpinv_get_cart_total( null, $discounts );
704
-            $cart_totals    = wpinv_recalculate_tax( true );
700
+        if (isset($_POST['code'])) {
701
+            $discount_code  = sanitize_text_field($_POST['code']);
702
+            $discounts      = wpinv_unset_cart_discount($discount_code);
703
+            $total          = wpinv_get_cart_total(null, $discounts);
704
+            $cart_totals    = wpinv_recalculate_tax(true);
705 705
             
706
-            if ( !empty( $cart_totals ) ) {
706
+            if (!empty($cart_totals)) {
707 707
                 $response['success']        = true;
708 708
                 $response['data']           = $cart_totals;
709 709
                 $response['data']['code']   = $discount_code;
@@ -712,10 +712,10 @@  discard block
 block discarded – undo
712 712
             }
713 713
             
714 714
             // Allow for custom discount code handling
715
-            $response = apply_filters( 'wpinv_ajax_discount_response', $response );
715
+            $response = apply_filters('wpinv_ajax_discount_response', $response);
716 716
         }
717 717
         
718
-        wp_send_json( $response );
718
+        wp_send_json($response);
719 719
     }
720 720
 
721 721
     /**
@@ -724,30 +724,30 @@  discard block
 block discarded – undo
724 724
     public static function get_payment_form() {
725 725
 
726 726
         // Check nonce.
727
-        if ( ! isset( $_GET['nonce'] ) || ! wp_verify_nonce( $_GET['nonce'], 'getpaid_ajax_form' ) ) {
728
-            _e( 'Error: Reload the page and try again.', 'invoicing' );
727
+        if (!isset($_GET['nonce']) || !wp_verify_nonce($_GET['nonce'], 'getpaid_ajax_form')) {
728
+            _e('Error: Reload the page and try again.', 'invoicing');
729 729
             exit;
730 730
         }
731 731
 
732 732
         // Is the request set up correctly?
733
-		if ( empty( $_GET['form'] ) && empty( $_GET['item'] ) ) {
733
+		if (empty($_GET['form']) && empty($_GET['item'])) {
734 734
 			echo aui()->alert(
735 735
 				array(
736 736
 					'type'    => 'warning',
737
-					'content' => __( 'No payment form or item provided', 'invoicing' ),
737
+					'content' => __('No payment form or item provided', 'invoicing'),
738 738
 				)
739 739
             );
740 740
             exit;
741 741
         }
742 742
 
743 743
         // Payment form or button?
744
-		if ( ! empty( $_GET['form'] ) ) {
745
-            echo getpaid_display_payment_form( $_GET['form'] );
746
-		} else if( $_GET['invoice'] ) {
747
-		    echo getpaid_display_invoice_payment_form( $_GET['invoice'] );
744
+		if (!empty($_GET['form'])) {
745
+            echo getpaid_display_payment_form($_GET['form']);
746
+		} else if ($_GET['invoice']) {
747
+		    echo getpaid_display_invoice_payment_form($_GET['invoice']);
748 748
         } else {
749
-			$items = getpaid_convert_items_to_array( $_GET['item'] );
750
-		    echo getpaid_display_item_payment_form( $items );
749
+			$items = getpaid_convert_items_to_array($_GET['item']);
750
+		    echo getpaid_display_item_payment_form($items);
751 751
         }
752 752
         
753 753
         exit;
@@ -763,11 +763,11 @@  discard block
 block discarded – undo
763 763
         global $invoicing, $wpi_checkout_id, $cart_total;
764 764
 
765 765
         // Check nonce.
766
-        check_ajax_referer( 'getpaid_form_nonce' );
766
+        check_ajax_referer('getpaid_form_nonce');
767 767
 
768 768
         // ... form fields...
769
-        if ( empty( $_POST['getpaid_payment_form_submission'] ) ) {
770
-            _e( 'Error: Reload the page and try again.', 'invoicing' );
769
+        if (empty($_POST['getpaid_payment_form_submission'])) {
770
+            _e('Error: Reload the page and try again.', 'invoicing');
771 771
             exit;
772 772
         }
773 773
 
@@ -775,25 +775,25 @@  discard block
 block discarded – undo
775 775
         $submission = new GetPaid_Payment_Form_Submission();
776 776
 
777 777
         // Do we have an error?
778
-        if ( ! empty( $submission->last_error ) ) {
778
+        if (!empty($submission->last_error)) {
779 779
             echo $submission->last_error;
780 780
             exit;
781 781
         }
782 782
 
783 783
         // We need a billing email.
784
-        if ( ! $submission->has_billing_email() || ! is_email( $submission->get_billing_email() ) ) {
785
-            wp_send_json_error( __( 'Provide a valid billing email.', 'invoicing' ) );
784
+        if (!$submission->has_billing_email() || !is_email($submission->get_billing_email())) {
785
+            wp_send_json_error(__('Provide a valid billing email.', 'invoicing'));
786 786
         }
787 787
 
788 788
         // Prepare items.
789 789
         $items            = $submission->get_items();
790 790
         $prepared_items   = array();
791 791
 
792
-        if ( ! empty( $items ) ) {
792
+        if (!empty($items)) {
793 793
 
794
-            foreach( $items as $item_id => $item ) {
794
+            foreach ($items as $item_id => $item) {
795 795
 
796
-                if ( $item->can_purchase() ) {
796
+                if ($item->can_purchase()) {
797 797
                     $prepared_items[] = array(
798 798
                         'id'           => $item_id,
799 799
                         'item_price'   => $item->get_price(),
@@ -807,90 +807,90 @@  discard block
 block discarded – undo
807 807
 
808 808
         }
809 809
 
810
-        if ( empty( $prepared_items ) ) {
811
-            wp_send_json_error( __( 'You have not selected any items.', 'invoicing' ) );
810
+        if (empty($prepared_items)) {
811
+            wp_send_json_error(__('You have not selected any items.', 'invoicing'));
812 812
         }
813 813
 
814
-        if ( $submission->has_recurring && 1 != count( $prepared_items ) ) {
815
-            wp_send_json_error( __( 'Recurring items should be bought individually.', 'invoicing' ) );
814
+        if ($submission->has_recurring && 1 != count($prepared_items)) {
815
+            wp_send_json_error(__('Recurring items should be bought individually.', 'invoicing'));
816 816
         }
817 817
 
818 818
         // Prepare the submission details.
819 819
         $prepared = array(
820
-            'billing_email'                    => sanitize_email( $submission->get_billing_email() ),
821
-            __( 'Billing Email', 'invoicing' ) => sanitize_email( $submission->get_billing_email() ),
822
-            __( 'Form Id', 'invoicing' )       => absint( $submission->payment_form->get_id() ),
820
+            'billing_email'                    => sanitize_email($submission->get_billing_email()),
821
+            __('Billing Email', 'invoicing') => sanitize_email($submission->get_billing_email()),
822
+            __('Form Id', 'invoicing')       => absint($submission->payment_form->get_id()),
823 823
         );
824 824
 
825 825
         // Address fields.
826 826
         $address_fields = array();
827 827
 
828 828
         // Add discount code.
829
-        if ( $submission->has_discount_code() ) {
830
-            $address_fields['discount'] = array( $submission->get_discount_code() );
829
+        if ($submission->has_discount_code()) {
830
+            $address_fields['discount'] = array($submission->get_discount_code());
831 831
         }
832 832
 
833 833
         // Are all required fields provided?
834 834
         $data = $submission->get_data();
835 835
 
836
-        foreach ( $submission->payment_form->get_elements() as $field ) {
836
+        foreach ($submission->payment_form->get_elements() as $field) {
837 837
 
838
-            if ( ! empty( $field['premade'] ) ) {
838
+            if (!empty($field['premade'])) {
839 839
                 continue;
840 840
             }
841 841
 
842
-            if ( ! $submission->is_required_field_set( $field ) ) {
843
-                wp_send_json_error( __( 'Fill all required fields.', 'invoicing' ) );
842
+            if (!$submission->is_required_field_set($field)) {
843
+                wp_send_json_error(__('Fill all required fields.', 'invoicing'));
844 844
             }
845 845
 
846
-            if ( $field['type'] == 'address' ) {
846
+            if ($field['type'] == 'address') {
847 847
 
848
-                foreach ( $field['fields'] as $address_field ) {
848
+                foreach ($field['fields'] as $address_field) {
849 849
 
850
-                    if ( empty( $address_field['visible'] ) ) {
850
+                    if (empty($address_field['visible'])) {
851 851
                         continue;
852 852
                     }
853 853
 
854
-                    if ( ! empty( $address_field['required'] ) && empty( $data[ $address_field['name'] ] ) ) {
855
-                        wp_send_json_error( __( 'Some required fields have not been filled.', 'invoicing' ) );
854
+                    if (!empty($address_field['required']) && empty($data[$address_field['name']])) {
855
+                        wp_send_json_error(__('Some required fields have not been filled.', 'invoicing'));
856 856
                     }
857 857
 
858
-                    if ( isset( $data[ $address_field['name'] ] ) ) {
859
-                        $label = str_replace( 'wpinv_', '', $address_field['name'] );
860
-                        $address_fields[ $label ] = wpinv_clean( $data[ $address_field['name'] ] );
858
+                    if (isset($data[$address_field['name']])) {
859
+                        $label = str_replace('wpinv_', '', $address_field['name']);
860
+                        $address_fields[$label] = wpinv_clean($data[$address_field['name']]);
861 861
                     }
862 862
 
863 863
                 }
864 864
 
865
-            } else if ( isset( $data[ $field['id'] ] ) ) {
865
+            } else if (isset($data[$field['id']])) {
866 866
                 $label = $field['id'];
867 867
 
868
-                if ( isset( $field['label'] ) ) {
868
+                if (isset($field['label'])) {
869 869
                     $label = $field['label'];
870 870
                 }
871 871
 
872
-                $prepared[ wpinv_clean( $label ) ] = wpinv_clean( $data[ $field['id'] ] );
872
+                $prepared[wpinv_clean($label)] = wpinv_clean($data[$field['id']]);
873 873
             }
874 874
 
875 875
         }
876 876
 
877 877
         // (Maybe) create the user.
878
-        $user = get_user_by( 'email', $prepared['billing_email'] );
878
+        $user = get_user_by('email', $prepared['billing_email']);
879 879
 
880
-        if ( empty( $user ) ) {
881
-            $user = wpinv_create_user( $prepared['billing_email'] );
880
+        if (empty($user)) {
881
+            $user = wpinv_create_user($prepared['billing_email']);
882 882
         }
883 883
 
884
-        if ( is_wp_error( $user ) ) {
885
-            wp_send_json_error( $user->get_error_message() );
884
+        if (is_wp_error($user)) {
885
+            wp_send_json_error($user->get_error_message());
886 886
         }
887 887
 
888
-        if ( is_numeric( $user ) ) {
889
-            $user = get_user_by( 'id', $user );
888
+        if (is_numeric($user)) {
889
+            $user = get_user_by('id', $user);
890 890
         }
891 891
 
892 892
         // Create the invoice.
893
-        if ( ! $submission->has_invoice() ) {
893
+        if (!$submission->has_invoice()) {
894 894
 
895 895
             $invoice = wpinv_insert_invoice(
896 896
                 array(
@@ -907,8 +907,8 @@  discard block
 block discarded – undo
907 907
 
908 908
             $invoice = $submission->get_invoice();
909 909
 
910
-            if ( $invoice->is_paid() ) {
911
-                wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) );
910
+            if ($invoice->is_paid()) {
911
+                wp_send_json_error(__('This invoice has already been paid for.', 'invoicing'));
912 912
             }
913 913
 
914 914
             $invoice = wpinv_update_invoice(
@@ -923,34 +923,34 @@  discard block
 block discarded – undo
923 923
 
924 924
         }
925 925
 
926
-        if ( is_wp_error( $invoice ) ) {
927
-            wp_send_json_error( $invoice->get_error_message() );
926
+        if (is_wp_error($invoice)) {
927
+            wp_send_json_error($invoice->get_error_message());
928 928
         }
929 929
 
930
-        if ( empty( $invoice ) ) {
931
-            wp_send_json_error( __( 'Could not create your invoice.', 'invoicing' ) );
930
+        if (empty($invoice)) {
931
+            wp_send_json_error(__('Could not create your invoice.', 'invoicing'));
932 932
         }
933 933
 
934
-        unset( $prepared['billing_email'] );
935
-        update_post_meta( $invoice->ID, 'payment_form_data', $prepared );
934
+        unset($prepared['billing_email']);
935
+        update_post_meta($invoice->ID, 'payment_form_data', $prepared);
936 936
 
937 937
         $wpi_checkout_id = $invoice->ID;
938 938
         $cart_total = wpinv_price(
939 939
             wpinv_format_amount(
940
-                wpinv_get_cart_total( $invoice->get_cart_details(), NULL, $invoice ) ),
940
+                wpinv_get_cart_total($invoice->get_cart_details(), NULL, $invoice) ),
941 941
                 $invoice->get_currency()
942 942
         );
943 943
 
944 944
         $data                   = array();
945 945
         $data['invoice_id']     = $invoice->ID;
946
-        $data['cart_discounts'] = $invoice->get_discounts( true );
946
+        $data['cart_discounts'] = $invoice->get_discounts(true);
947 947
 
948
-        wpinv_set_checkout_session( $data );
949
-        add_filter( 'wp_redirect', array( $invoicing->form_elements, 'send_redirect_response' ) );
950
-        add_action( 'wpinv_pre_send_back_to_checkout', array( $invoicing->form_elements, 'checkout_error' ) );
948
+        wpinv_set_checkout_session($data);
949
+        add_filter('wp_redirect', array($invoicing->form_elements, 'send_redirect_response'));
950
+        add_action('wpinv_pre_send_back_to_checkout', array($invoicing->form_elements, 'checkout_error'));
951 951
         
952
-        if ( ! defined( 'WPINV_CHECKOUT' ) ) {
953
-            define( 'WPINV_CHECKOUT', true );
952
+        if (!defined('WPINV_CHECKOUT')) {
953
+            define('WPINV_CHECKOUT', true);
954 954
         }
955 955
 
956 956
         wpinv_process_checkout();
@@ -968,51 +968,51 @@  discard block
 block discarded – undo
968 968
     public static function get_payment_form_states_field() {
969 969
         global $invoicing;
970 970
 
971
-        if ( empty( $_GET['country'] ) || empty( $_GET['form'] ) ) {
971
+        if (empty($_GET['country']) || empty($_GET['form'])) {
972 972
             exit;
973 973
         }
974 974
 
975
-        $elements = $invoicing->form_elements->get_form_elements( $_GET['form'] );
975
+        $elements = $invoicing->form_elements->get_form_elements($_GET['form']);
976 976
 
977
-        if ( empty( $elements ) ) {
977
+        if (empty($elements)) {
978 978
             exit;
979 979
         }
980 980
 
981 981
         $address_fields = array();
982
-        foreach ( $elements as $element ) {
983
-            if ( 'address' === $element['type'] ) {
982
+        foreach ($elements as $element) {
983
+            if ('address' === $element['type']) {
984 984
                 $address_fields = $element;
985 985
                 break;
986 986
             }
987 987
         }
988 988
 
989
-        if ( empty( $address_fields ) ) {
989
+        if (empty($address_fields)) {
990 990
             exit;
991 991
         }
992 992
 
993
-        foreach( $address_fields['fields'] as $address_field ) {
993
+        foreach ($address_fields['fields'] as $address_field) {
994 994
 
995
-            if ( 'wpinv_state' == $address_field['name'] ) {
995
+            if ('wpinv_state' == $address_field['name']) {
996 996
 
997 997
                 $label = $address_field['label'];
998 998
 
999
-                if ( ! empty( $address_field['required'] ) ) {
999
+                if (!empty($address_field['required'])) {
1000 1000
                     $label .= "<span class='text-danger'> *</span>";
1001 1001
                 }
1002 1002
 
1003
-                $states = wpinv_get_country_states( $_GET['country'] );
1003
+                $states = wpinv_get_country_states($_GET['country']);
1004 1004
 
1005
-                if ( ! empty( $states ) ) {
1005
+                if (!empty($states)) {
1006 1006
 
1007 1007
                     $html = aui()->select(
1008 1008
                             array(
1009 1009
                                 'options'          => $states,
1010
-                                'name'             => esc_attr( $address_field['name'] ),
1011
-                                'id'               => esc_attr( $address_field['name'] ),
1012
-                                'placeholder'      => esc_attr( $address_field['placeholder'] ),
1010
+                                'name'             => esc_attr($address_field['name']),
1011
+                                'id'               => esc_attr($address_field['name']),
1012
+                                'placeholder'      => esc_attr($address_field['placeholder']),
1013 1013
                                 'required'         => (bool) $address_field['required'],
1014 1014
                                 'no_wrap'          => true,
1015
-                                'label'            => wp_kses_post( $label ),
1015
+                                'label'            => wp_kses_post($label),
1016 1016
                                 'select2'          => false,
1017 1017
                             )
1018 1018
                         );
@@ -1021,10 +1021,10 @@  discard block
 block discarded – undo
1021 1021
 
1022 1022
                     $html = aui()->input(
1023 1023
                             array(
1024
-                                'name'       => esc_attr( $address_field['name'] ),
1025
-                                'id'         => esc_attr( $address_field['name'] ),
1024
+                                'name'       => esc_attr($address_field['name']),
1025
+                                'id'         => esc_attr($address_field['name']),
1026 1026
                                 'required'   => (bool) $address_field['required'],
1027
-                                'label'      => wp_kses_post( $label ),
1027
+                                'label'      => wp_kses_post($label),
1028 1028
                                 'no_wrap'    => true,
1029 1029
                                 'type'       => 'text',
1030 1030
                             )
@@ -1032,7 +1032,7 @@  discard block
 block discarded – undo
1032 1032
 
1033 1033
                 }
1034 1034
 
1035
-                wp_send_json_success( str_replace( 'sr-only', '', $html ) );
1035
+                wp_send_json_success(str_replace('sr-only', '', $html));
1036 1036
                 exit;
1037 1037
 
1038 1038
             }
@@ -1048,24 +1048,24 @@  discard block
 block discarded – undo
1048 1048
     public static function get_aui_states_field() {
1049 1049
 
1050 1050
         // Verify nonce.
1051
-        check_ajax_referer( 'wpinv-nonce' );
1051
+        check_ajax_referer('wpinv-nonce');
1052 1052
 
1053 1053
         // We need a country.
1054
-        if ( empty( $_GET['country'] ) ) {
1054
+        if (empty($_GET['country'])) {
1055 1055
             exit;
1056 1056
         }
1057 1057
 
1058
-        $states = wpinv_get_country_states( trim( $_GET['country'] ) );
1059
-        $state  = isset( $_GET['state'] ) ? trim( $_GET['state'] ) : wpinv_get_default_state();
1058
+        $states = wpinv_get_country_states(trim($_GET['country']));
1059
+        $state  = isset($_GET['state']) ? trim($_GET['state']) : wpinv_get_default_state();
1060 1060
 
1061
-        if ( empty( $states ) ) {
1061
+        if (empty($states)) {
1062 1062
 
1063 1063
             $html = aui()->input(
1064 1064
                 array(
1065 1065
                     'type'        => 'text',
1066 1066
                     'id'          => 'wpinv_state',
1067 1067
                     'name'        => 'wpinv_state',
1068
-                    'label'       => __( 'State', 'invoicing' ),
1068
+                    'label'       => __('State', 'invoicing'),
1069 1069
                     'label_type'  => 'vertical',
1070 1070
                     'placeholder' => 'Liège',
1071 1071
                     'class'       => 'form-control-sm',
@@ -1079,9 +1079,9 @@  discard block
 block discarded – undo
1079 1079
                 array(
1080 1080
                     'id'          => 'wpinv_state',
1081 1081
                     'name'        => 'wpinv_state',
1082
-                    'label'       => __( 'State', 'invoicing' ),
1082
+                    'label'       => __('State', 'invoicing'),
1083 1083
                     'label_type'  => 'vertical',
1084
-                    'placeholder' => __( 'Select a state', 'invoicing' ),
1084
+                    'placeholder' => __('Select a state', 'invoicing'),
1085 1085
                     'class'       => 'form-control-sm',
1086 1086
                     'value'       => $state,
1087 1087
                     'options'     => $states,
@@ -1095,7 +1095,7 @@  discard block
 block discarded – undo
1095 1095
         wp_send_json_success(
1096 1096
             array(
1097 1097
                 'html'   => $html,
1098
-                'select' => ! empty ( $states )
1098
+                'select' => !empty ($states)
1099 1099
             )
1100 1100
         );
1101 1101
 
@@ -1109,11 +1109,11 @@  discard block
 block discarded – undo
1109 1109
     public static function payment_form_refresh_prices() {
1110 1110
 
1111 1111
         // Check nonce.
1112
-        check_ajax_referer( 'getpaid_form_nonce' );
1112
+        check_ajax_referer('getpaid_form_nonce');
1113 1113
 
1114 1114
         // ... form fields...
1115
-        if ( empty( $_POST['getpaid_payment_form_submission'] ) ) {
1116
-            _e( 'Error: Reload the page and try again.', 'invoicing' );
1115
+        if (empty($_POST['getpaid_payment_form_submission'])) {
1116
+            _e('Error: Reload the page and try again.', 'invoicing');
1117 1117
             exit;
1118 1118
         }
1119 1119
 
@@ -1121,7 +1121,7 @@  discard block
 block discarded – undo
1121 1121
         $submission = new GetPaid_Payment_Form_Submission();
1122 1122
 
1123 1123
         // Do we have an error?
1124
-        if ( ! empty( $submission->last_error ) ) {
1124
+        if (!empty($submission->last_error)) {
1125 1125
             echo $submission->last_error;
1126 1126
             exit;
1127 1127
         }
@@ -1132,38 +1132,38 @@  discard block
 block discarded – undo
1132 1132
             'has_recurring' => $submission->has_recurring,
1133 1133
             'is_free'       => $submission->get_payment_details(),
1134 1134
             'totals'        => array(
1135
-                'subtotal'  => wpinv_price( wpinv_format_amount( $submission->subtotal_amount ), $submission->get_currency() ),
1136
-                'discount'  => wpinv_price( wpinv_format_amount( $submission->get_total_discount() ), $submission->get_currency() ),
1137
-                'fees'      => wpinv_price( wpinv_format_amount( $submission->get_total_fees() ), $submission->get_currency() ),
1138
-                'tax'       => wpinv_price( wpinv_format_amount( $submission->get_total_tax() ), $submission->get_currency() ),
1139
-                'total'     => wpinv_price( wpinv_format_amount( $submission->get_total() ), $submission->get_currency() ),
1135
+                'subtotal'  => wpinv_price(wpinv_format_amount($submission->subtotal_amount), $submission->get_currency()),
1136
+                'discount'  => wpinv_price(wpinv_format_amount($submission->get_total_discount()), $submission->get_currency()),
1137
+                'fees'      => wpinv_price(wpinv_format_amount($submission->get_total_fees()), $submission->get_currency()),
1138
+                'tax'       => wpinv_price(wpinv_format_amount($submission->get_total_tax()), $submission->get_currency()),
1139
+                'total'     => wpinv_price(wpinv_format_amount($submission->get_total()), $submission->get_currency()),
1140 1140
             ),
1141 1141
         );
1142 1142
 
1143 1143
         // Add items.
1144 1144
         $items = $submission->get_items();
1145
-        if ( ! empty( $items ) ) {
1145
+        if (!empty($items)) {
1146 1146
             $result['items'] = array();
1147 1147
 
1148
-            foreach( $items as $item_id => $item ) {
1149
-                $result['items']["$item_id"] = wpinv_price( wpinv_format_amount( $item->get_price() * $item->get_qantity() ) );
1148
+            foreach ($items as $item_id => $item) {
1149
+                $result['items']["$item_id"] = wpinv_price(wpinv_format_amount($item->get_price() * $item->get_qantity()));
1150 1150
             }
1151 1151
         }
1152 1152
 
1153 1153
         // Add invoice.
1154
-        if ( $submission->has_invoice() ) {
1154
+        if ($submission->has_invoice()) {
1155 1155
             $result['invoice'] = $submission->get_invoice()->ID;
1156 1156
         }
1157 1157
 
1158 1158
         // Add discount code.
1159
-        if ( $submission->has_discount_code() ) {
1159
+        if ($submission->has_discount_code()) {
1160 1160
             $result['discount_code'] = $submission->get_discount_code();
1161 1161
         }
1162 1162
 
1163 1163
         // Filter the result.
1164
-        $result = apply_filters( 'getpaid_payment_form_ajax_refresh_prices', $result, $submission );
1164
+        $result = apply_filters('getpaid_payment_form_ajax_refresh_prices', $result, $submission);
1165 1165
 
1166
-        wp_send_json_success( $result );
1166
+        wp_send_json_success($result);
1167 1167
     }
1168 1168
 
1169 1169
     /**
@@ -1174,53 +1174,53 @@  discard block
 block discarded – undo
1174 1174
     public static function buy_items() {
1175 1175
         $user_id = get_current_user_id();
1176 1176
 
1177
-        if ( empty( $user_id ) ) { // If not logged in then lets redirect to the login page
1178
-            wp_send_json( array(
1179
-                'success' => wp_login_url( wp_get_referer() )
1180
-            ) );
1177
+        if (empty($user_id)) { // If not logged in then lets redirect to the login page
1178
+            wp_send_json(array(
1179
+                'success' => wp_login_url(wp_get_referer())
1180
+            ));
1181 1181
         } else {
1182 1182
             // Only check nonce if logged in as it could be cached when logged out.
1183
-            if ( ! isset( $_POST['wpinv_buy_nonce'] ) || ! wp_verify_nonce( $_POST['wpinv_buy_nonce'], 'wpinv_buy_items' ) ) {
1184
-                wp_send_json( array(
1185
-                    'error' => __( 'Security checks failed.', 'invoicing' )
1186
-                ) );
1183
+            if (!isset($_POST['wpinv_buy_nonce']) || !wp_verify_nonce($_POST['wpinv_buy_nonce'], 'wpinv_buy_items')) {
1184
+                wp_send_json(array(
1185
+                    'error' => __('Security checks failed.', 'invoicing')
1186
+                ));
1187 1187
                 wp_die();
1188 1188
             }
1189 1189
 
1190 1190
             // allow to set a custom price through post_id
1191 1191
             $items = $_POST['items'];
1192
-            $related_post_id = isset( $_POST['post_id'] ) ? (int)$_POST['post_id'] : 0;
1193
-            $custom_item_price = $related_post_id ? abs( get_post_meta( $related_post_id, '_wpi_custom_price', true ) ) : 0;
1192
+            $related_post_id = isset($_POST['post_id']) ? (int) $_POST['post_id'] : 0;
1193
+            $custom_item_price = $related_post_id ? abs(get_post_meta($related_post_id, '_wpi_custom_price', true)) : 0;
1194 1194
 
1195 1195
             $cart_items = array();
1196
-            if ( $items ) {
1197
-                $items = explode( ',', $items );
1196
+            if ($items) {
1197
+                $items = explode(',', $items);
1198 1198
 
1199
-                foreach( $items as $item ) {
1199
+                foreach ($items as $item) {
1200 1200
                     $item_id = $item;
1201 1201
                     $quantity = 1;
1202 1202
 
1203
-                    if ( strpos( $item, '|' ) !== false ) {
1204
-                        $item_parts = explode( '|', $item );
1203
+                    if (strpos($item, '|') !== false) {
1204
+                        $item_parts = explode('|', $item);
1205 1205
                         $item_id = $item_parts[0];
1206 1206
                         $quantity = $item_parts[1];
1207 1207
                     }
1208 1208
 
1209
-                    if ( $item_id && $quantity ) {
1209
+                    if ($item_id && $quantity) {
1210 1210
                         $cart_items_arr = array(
1211
-                            'id'            => (int)$item_id,
1212
-                            'quantity'      => (int)$quantity
1211
+                            'id'            => (int) $item_id,
1212
+                            'quantity'      => (int) $quantity
1213 1213
                         );
1214 1214
 
1215 1215
                         // If there is a related post id then add it to meta
1216
-                        if ( $related_post_id ) {
1216
+                        if ($related_post_id) {
1217 1217
                             $cart_items_arr['meta'] = array(
1218 1218
                                 'post_id'   => $related_post_id
1219 1219
                             );
1220 1220
                         }
1221 1221
 
1222 1222
                         // If there is a custom price then set it.
1223
-                        if ( $custom_item_price ) {
1223
+                        if ($custom_item_price) {
1224 1224
                             $cart_items_arr['custom_price'] = $custom_item_price;
1225 1225
                         }
1226 1226
 
@@ -1236,37 +1236,37 @@  discard block
 block discarded – undo
1236 1236
              * @param int $related_post_id The related post id if any.
1237 1237
              * @since 1.0.0
1238 1238
              */
1239
-            $cart_items = apply_filters( 'wpinv_buy_cart_items', $cart_items, $related_post_id );
1239
+            $cart_items = apply_filters('wpinv_buy_cart_items', $cart_items, $related_post_id);
1240 1240
 
1241 1241
             // Make sure its not in the cart already, if it is then redirect to checkout.
1242 1242
             $cart_invoice = wpinv_get_invoice_cart();
1243 1243
 
1244
-            if ( isset( $cart_invoice->items ) && !empty( $cart_invoice->items ) && !empty( $cart_items ) && serialize( $cart_invoice->items ) == serialize( $cart_items ) ) {
1245
-                wp_send_json( array(
1244
+            if (isset($cart_invoice->items) && !empty($cart_invoice->items) && !empty($cart_items) && serialize($cart_invoice->items) == serialize($cart_items)) {
1245
+                wp_send_json(array(
1246 1246
                     'success' =>  $cart_invoice->get_checkout_payment_url()
1247
-                ) );
1247
+                ));
1248 1248
                 wp_die();
1249 1249
             }
1250 1250
 
1251 1251
             // Check if user has invoice with same items waiting to be paid.
1252
-            $user_invoices = wpinv_get_users_invoices( $user_id , 10 , false , 'wpi-pending' );
1253
-            if ( !empty( $user_invoices ) ) {
1254
-                foreach( $user_invoices as $user_invoice ) {
1252
+            $user_invoices = wpinv_get_users_invoices($user_id, 10, false, 'wpi-pending');
1253
+            if (!empty($user_invoices)) {
1254
+                foreach ($user_invoices as $user_invoice) {
1255 1255
                     $user_cart_details = array();
1256
-                    $invoice  = wpinv_get_invoice( $user_invoice->ID );
1256
+                    $invoice = wpinv_get_invoice($user_invoice->ID);
1257 1257
                     $cart_details = $invoice->get_cart_details();
1258 1258
 
1259
-                    if ( !empty( $cart_details ) ) {
1260
-                        foreach ( $cart_details as $invoice_item ) {
1259
+                    if (!empty($cart_details)) {
1260
+                        foreach ($cart_details as $invoice_item) {
1261 1261
                             $ii_arr = array();
1262
-                            $ii_arr['id'] = (int)$invoice_item['id'];
1263
-                            $ii_arr['quantity'] = (int)$invoice_item['quantity'];
1262
+                            $ii_arr['id'] = (int) $invoice_item['id'];
1263
+                            $ii_arr['quantity'] = (int) $invoice_item['quantity'];
1264 1264
 
1265
-                            if (isset( $invoice_item['meta'] ) && !empty( $invoice_item['meta'] ) ) {
1265
+                            if (isset($invoice_item['meta']) && !empty($invoice_item['meta'])) {
1266 1266
                                 $ii_arr['meta'] = $invoice_item['meta'];
1267 1267
                             }
1268 1268
 
1269
-                            if ( isset( $invoice_item['custom_price'] ) && !empty( $invoice_item['custom_price'] ) ) {
1269
+                            if (isset($invoice_item['custom_price']) && !empty($invoice_item['custom_price'])) {
1270 1270
                                 $ii_arr['custom_price'] = $invoice_item['custom_price'];
1271 1271
                             }
1272 1272
 
@@ -1274,17 +1274,17 @@  discard block
 block discarded – undo
1274 1274
                         }
1275 1275
                     }
1276 1276
 
1277
-                    if ( !empty( $user_cart_details ) && serialize( $cart_items ) == serialize( $user_cart_details ) ) {
1278
-                        wp_send_json( array(
1277
+                    if (!empty($user_cart_details) && serialize($cart_items) == serialize($user_cart_details)) {
1278
+                        wp_send_json(array(
1279 1279
                             'success' =>  $invoice->get_checkout_payment_url()
1280
-                        ) );
1280
+                        ));
1281 1281
                         wp_die();
1282 1282
                     }
1283 1283
                 }
1284 1284
             }
1285 1285
 
1286 1286
             // Create invoice and send user to checkout
1287
-            if ( !empty( $cart_items ) ) {
1287
+            if (!empty($cart_items)) {
1288 1288
                 $invoice_data = array(
1289 1289
                     'status'        =>  'wpi-pending',
1290 1290
                     'created_via'   =>  'wpi',
@@ -1292,21 +1292,21 @@  discard block
 block discarded – undo
1292 1292
                     'cart_details'  =>  $cart_items,
1293 1293
                 );
1294 1294
 
1295
-                $invoice = wpinv_insert_invoice( $invoice_data, true );
1295
+                $invoice = wpinv_insert_invoice($invoice_data, true);
1296 1296
 
1297
-                if ( !empty( $invoice ) && isset( $invoice->ID ) ) {
1298
-                    wp_send_json( array(
1297
+                if (!empty($invoice) && isset($invoice->ID)) {
1298
+                    wp_send_json(array(
1299 1299
                         'success' =>  $invoice->get_checkout_payment_url()
1300
-                    ) );
1300
+                    ));
1301 1301
                 } else {
1302
-                    wp_send_json( array(
1303
-                        'error' => __( 'Invoice failed to create', 'invoicing' )
1304
-                    ) );
1302
+                    wp_send_json(array(
1303
+                        'error' => __('Invoice failed to create', 'invoicing')
1304
+                    ));
1305 1305
                 }
1306 1306
             } else {
1307
-                wp_send_json( array(
1308
-                    'error' => __( 'Items not valid.', 'invoicing' )
1309
-                ) );
1307
+                wp_send_json(array(
1308
+                    'error' => __('Items not valid.', 'invoicing')
1309
+                ));
1310 1310
             }
1311 1311
         }
1312 1312
 
Please login to merge, or discard this patch.
includes/wpinv-address-functions.php 2 patches
Indentation   +88 added lines, -88 removed lines patch added patch discarded remove patch
@@ -13,9 +13,9 @@  discard block
 block discarded – undo
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
 /**
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
  */
27 27
 function wpinv_sanitize_country( $country ) {
28 28
 
29
-	// Enure the country is specified
29
+    // Enure the country is specified
30 30
     if ( empty( $country ) ) {
31 31
         $country = wpinv_get_default_country();
32 32
     }
@@ -56,9 +56,9 @@  discard block
 block discarded – undo
56 56
 }
57 57
 
58 58
 function wpinv_get_default_state() {
59
-	$state = wpinv_get_option( 'default_state', false );
59
+    $state = wpinv_get_option( 'default_state', false );
60 60
 
61
-	return apply_filters( 'wpinv_default_state', $state );
61
+    return apply_filters( 'wpinv_default_state', $state );
62 62
 }
63 63
 
64 64
 function wpinv_state_name( $state_code = '', $country_code = '' ) {
@@ -166,11 +166,11 @@  discard block
 block discarded – undo
166 166
 
167 167
     $country = wpinv_sanitize_country( $country );
168 168
     
169
-	foreach ( wpinv_get_continents( 'countries' ) as $continent_code => $countries ) {
170
-		if ( false !== array_search( $country, $countries, true ) ) {
171
-			return $continent_code;
172
-		}
173
-	}
169
+    foreach ( wpinv_get_continents( 'countries' ) as $continent_code => $countries ) {
170
+        if ( false !== array_search( $country, $countries, true ) ) {
171
+            return $continent_code;
172
+        }
173
+    }
174 174
 
175 175
     return '';
176 176
     
@@ -462,30 +462,30 @@  discard block
 block discarded – undo
462 462
 }
463 463
 
464 464
 function wpinv_get_states_field() {
465
-	if( empty( $_POST['country'] ) ) {
466
-		$_POST['country'] = wpinv_get_default_country();
467
-	}
468
-	$states = wpinv_get_country_states( sanitize_text_field( $_POST['country'] ) );
465
+    if( empty( $_POST['country'] ) ) {
466
+        $_POST['country'] = wpinv_get_default_country();
467
+    }
468
+    $states = wpinv_get_country_states( sanitize_text_field( $_POST['country'] ) );
469 469
 
470
-	if( !empty( $states ) ) {
471
-		$sanitized_field_name = sanitize_text_field( $_POST['field_name'] );
470
+    if( !empty( $states ) ) {
471
+        $sanitized_field_name = sanitize_text_field( $_POST['field_name'] );
472 472
         
473 473
         $args = array(
474
-			'name'    => $sanitized_field_name,
475
-			'id'      => $sanitized_field_name,
476
-			'class'   => $sanitized_field_name . 'custom-select wpinv-select wpi_select2',
477
-			'options' => array_merge( array( '' => '' ), $states ),
478
-			'show_option_all'  => false,
479
-			'show_option_none' => false
480
-		);
481
-
482
-		$response = wpinv_html_select( $args );
483
-
484
-	} else {
485
-		$response = 'nostates';
486
-	}
474
+            'name'    => $sanitized_field_name,
475
+            'id'      => $sanitized_field_name,
476
+            'class'   => $sanitized_field_name . 'custom-select wpinv-select wpi_select2',
477
+            'options' => array_merge( array( '' => '' ), $states ),
478
+            'show_option_all'  => false,
479
+            'show_option_none' => false
480
+        );
481
+
482
+        $response = wpinv_html_select( $args );
483
+
484
+    } else {
485
+        $response = 'nostates';
486
+    }
487 487
 
488
-	return $response;
488
+    return $response;
489 489
 }
490 490
 
491 491
 function wpinv_default_billing_country( $country = '', $user_id = 0 ) {
@@ -503,46 +503,46 @@  discard block
 block discarded – undo
503 503
  */
504 504
 function wpinv_get_address_formats() {
505 505
 
506
-		return apply_filters( 'wpinv_localisation_address_formats',
507
-			array(
508
-				'default' => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}}\n{{zip}}\n{{country}}",
509
-				'AU'      => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}} {{zip}}\n{{country}}",
510
-				'AT'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
511
-				'BE'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
512
-				'CA'      => "{{company}}\n{{name}}\n{{address}}\n{{city}} {{state_code}}&nbsp;&nbsp;{{zip}}\n{{country}}",
513
-				'CH'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
514
-				'CL'      => "{{company}}\n{{name}}\n{{address}}\n{{state}}\n{{zip}} {{city}}\n{{country}}",
515
-				'CN'      => "{{country}} {{zip}}\n{{state}}, {{city}}, {{address}}\n{{company}}\n{{name}}",
516
-				'CZ'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
517
-				'DE'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
518
-				'EE'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
519
-				'FI'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
520
-				'DK'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
521
-				'FR'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city_upper}}\n{{country}}",
522
-				'HK'      => "{{company}}\n{{first_name}} {{last_name_upper}}\n{{address}}\n{{city_upper}}\n{{state_upper}}\n{{country}}",
523
-				'HU'      => "{{name}}\n{{company}}\n{{city}}\n{{address}}\n{{zip}}\n{{country}}",
524
-				'IN'      => "{{company}}\n{{name}}\n{{address}}\n{{city}} {{zip}}\n{{state}}, {{country}}",
525
-				'IS'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
526
-				'IT'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}}\n{{city}}\n{{state_upper}}\n{{country}}",
527
-				'JP'      => "{{zip}}\n{{state}} {{city}} {{address}}\n{{company}}\n{{last_name}} {{first_name}}\n{{country}}",
528
-				'TW'      => "{{company}}\n{{last_name}} {{first_name}}\n{{address}}\n{{state}}, {{city}} {{zip}}\n{{country}}",
529
-				'LI'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
530
-				'NL'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
531
-				'NZ'      => "{{name}}\n{{company}}\n{{address}}\n{{city}} {{zip}}\n{{country}}",
532
-				'NO'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
533
-				'PL'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
534
-				'PT'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
535
-				'SK'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
536
-				'RS'      => "{{name}}\n{{company}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
537
-				'SI'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
538
-				'ES'      => "{{name}}\n{{company}}\n{{address}}\n{{zip}} {{city}}\n{{state}}\n{{country}}",
539
-				'SE'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
540
-				'TR'      => "{{name}}\n{{company}}\n{{address}}\n{{zip}} {{city}} {{state}}\n{{country}}",
541
-				'UG'      => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}}, {{country}}",
542
-				'US'      => "{{name}}\n{{company}}\n{{address}}\n{{city}}, {{state_code}} {{zip}}\n{{country}}",
543
-				'VN'      => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{country}}",
544
-			)
545
-		);
506
+        return apply_filters( 'wpinv_localisation_address_formats',
507
+            array(
508
+                'default' => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}}\n{{zip}}\n{{country}}",
509
+                'AU'      => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}} {{zip}}\n{{country}}",
510
+                'AT'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
511
+                'BE'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
512
+                'CA'      => "{{company}}\n{{name}}\n{{address}}\n{{city}} {{state_code}}&nbsp;&nbsp;{{zip}}\n{{country}}",
513
+                'CH'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
514
+                'CL'      => "{{company}}\n{{name}}\n{{address}}\n{{state}}\n{{zip}} {{city}}\n{{country}}",
515
+                'CN'      => "{{country}} {{zip}}\n{{state}}, {{city}}, {{address}}\n{{company}}\n{{name}}",
516
+                'CZ'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
517
+                'DE'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
518
+                'EE'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
519
+                'FI'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
520
+                'DK'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
521
+                'FR'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city_upper}}\n{{country}}",
522
+                'HK'      => "{{company}}\n{{first_name}} {{last_name_upper}}\n{{address}}\n{{city_upper}}\n{{state_upper}}\n{{country}}",
523
+                'HU'      => "{{name}}\n{{company}}\n{{city}}\n{{address}}\n{{zip}}\n{{country}}",
524
+                'IN'      => "{{company}}\n{{name}}\n{{address}}\n{{city}} {{zip}}\n{{state}}, {{country}}",
525
+                'IS'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
526
+                'IT'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}}\n{{city}}\n{{state_upper}}\n{{country}}",
527
+                'JP'      => "{{zip}}\n{{state}} {{city}} {{address}}\n{{company}}\n{{last_name}} {{first_name}}\n{{country}}",
528
+                'TW'      => "{{company}}\n{{last_name}} {{first_name}}\n{{address}}\n{{state}}, {{city}} {{zip}}\n{{country}}",
529
+                'LI'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
530
+                'NL'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
531
+                'NZ'      => "{{name}}\n{{company}}\n{{address}}\n{{city}} {{zip}}\n{{country}}",
532
+                'NO'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
533
+                'PL'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
534
+                'PT'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
535
+                'SK'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
536
+                'RS'      => "{{name}}\n{{company}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
537
+                'SI'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
538
+                'ES'      => "{{name}}\n{{company}}\n{{address}}\n{{zip}} {{city}}\n{{state}}\n{{country}}",
539
+                'SE'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
540
+                'TR'      => "{{name}}\n{{company}}\n{{address}}\n{{zip}} {{city}} {{state}}\n{{country}}",
541
+                'UG'      => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}}, {{country}}",
542
+                'US'      => "{{name}}\n{{company}}\n{{address}}\n{{city}}, {{state_code}} {{zip}}\n{{country}}",
543
+                'VN'      => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{country}}",
544
+            )
545
+        );
546 546
 }
547 547
 
548 548
 /**
@@ -559,21 +559,21 @@  discard block
 block discarded – undo
559 559
     }
560 560
 
561 561
     // Get all formats.
562
-	$formats = wpinv_get_address_formats();
562
+    $formats = wpinv_get_address_formats();
563 563
 
564
-	// Get format for the specified country.
565
-	$format = ( $country && isset( $formats[ $country ] ) ) ? $formats[ $country ] : $formats['default'];
564
+    // Get format for the specified country.
565
+    $format = ( $country && isset( $formats[ $country ] ) ) ? $formats[ $country ] : $formats['default'];
566 566
     
567 567
     /**
568
-	 * Filters the address format to use on Invoices.
568
+     * Filters the address format to use on Invoices.
569 569
      * 
570 570
      * New lines will be replaced by a `br` element. Double new lines will be replaced by a paragraph. HTML tags are allowed.
571
-	 *
572
-	 * @since 1.0.13
573
-	 *
574
-	 * @param string $format  The address format to use.
571
+     *
572
+     * @since 1.0.13
573
+     *
574
+     * @param string $format  The address format to use.
575 575
      * @param string $country The country who's address format is being retrieved.
576
-	 */
576
+     */
577 577
     return apply_filters( 'wpinv_get_full_address_format', $format, $country );
578 578
 }
579 579
 
@@ -594,8 +594,8 @@  discard block
 block discarded – undo
594 594
         'country'           => '',
595 595
         'zip'               => '',
596 596
         'first_name'        => '',
597
-		'last_name'         => '',
598
-		'company'           => '',
597
+        'last_name'         => '',
598
+        'company'           => '',
599 599
     );
600 600
 
601 601
     $args    = map_deep( wp_parse_args( $billing_details, $default_args ), 'trim' );
@@ -616,14 +616,14 @@  discard block
 block discarded – undo
616 616
     $args['country_code']= $country;
617 617
 
618 618
     /**
619
-	 * Filters the address format replacements to use on Invoices.
619
+     * Filters the address format replacements to use on Invoices.
620 620
      * 
621
-	 *
622
-	 * @since 1.0.13
623
-	 *
624
-	 * @param array $replacements  The address replacements to use.
621
+     *
622
+     * @since 1.0.13
623
+     *
624
+     * @param array $replacements  The address replacements to use.
625 625
      * @param array $billing_details  The billing details to use.
626
-	 */
626
+     */
627 627
     $replacements = apply_filters( 'wpinv_get_invoice_address_replacements', $args, $billing_details );
628 628
 
629 629
     $return = array();
@@ -646,5 +646,5 @@  discard block
 block discarded – undo
646 646
  * @return string
647 647
  */
648 648
 function wpinv_trim_formatted_address_line( $line ) {
649
-	return trim( $line, ', ' );
649
+    return trim( $line, ', ' );
650 650
 }
651 651
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +108 added lines, -108 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
 /**
@@ -24,66 +24,66 @@  discard block
 block discarded – undo
24 24
  * @param string $country The country code to sanitize
25 25
  * @return array
26 26
  */
27
-function wpinv_sanitize_country( $country ) {
27
+function wpinv_sanitize_country($country) {
28 28
 
29 29
 	// Enure the country is specified
30
-    if ( empty( $country ) ) {
30
+    if (empty($country)) {
31 31
         $country = wpinv_get_default_country();
32 32
     }
33
-    return trim( wpinv_utf8_strtoupper( $country ) );
33
+    return trim(wpinv_utf8_strtoupper($country));
34 34
 
35 35
 }
36 36
 
37
-function wpinv_is_base_country( $country ) {
37
+function wpinv_is_base_country($country) {
38 38
     $base_country = wpinv_get_default_country();
39 39
     
40
-    if ( $base_country === 'UK' ) {
40
+    if ($base_country === 'UK') {
41 41
         $base_country = 'GB';
42 42
     }
43
-    if ( $country == 'UK' ) {
43
+    if ($country == 'UK') {
44 44
         $country = 'GB';
45 45
     }
46 46
 
47
-    return ( $country && $country === $base_country ) ? true : false;
47
+    return ($country && $country === $base_country) ? true : false;
48 48
 }
49 49
 
50
-function wpinv_country_name( $country_code = '' ) { 
50
+function wpinv_country_name($country_code = '') { 
51 51
     $countries = wpinv_get_country_list();
52 52
     $country_code = $country_code == 'UK' ? 'GB' : $country_code;
53
-    $country = isset( $countries[$country_code] ) ? $countries[$country_code] : $country_code;
53
+    $country = isset($countries[$country_code]) ? $countries[$country_code] : $country_code;
54 54
 
55
-    return apply_filters( 'wpinv_country_name', $country, $country_code );
55
+    return apply_filters('wpinv_country_name', $country, $country_code);
56 56
 }
57 57
 
58 58
 function wpinv_get_default_state() {
59
-	$state = wpinv_get_option( 'default_state', false );
59
+	$state = wpinv_get_option('default_state', false);
60 60
 
61
-	return apply_filters( 'wpinv_default_state', $state );
61
+	return apply_filters('wpinv_default_state', $state);
62 62
 }
63 63
 
64
-function wpinv_state_name( $state_code = '', $country_code = '' ) {
64
+function wpinv_state_name($state_code = '', $country_code = '') {
65 65
     $state = $state_code;
66 66
     
67
-    if ( !empty( $country_code ) ) {
68
-        $states = wpinv_get_country_states( $country_code );
67
+    if (!empty($country_code)) {
68
+        $states = wpinv_get_country_states($country_code);
69 69
         
70
-        $state = !empty( $states ) && isset( $states[$state_code] ) ? $states[$state_code] : $state;
70
+        $state = !empty($states) && isset($states[$state_code]) ? $states[$state_code] : $state;
71 71
     }
72 72
 
73
-    return apply_filters( 'wpinv_state_name', $state, $state_code, $country_code );
73
+    return apply_filters('wpinv_state_name', $state, $state_code, $country_code);
74 74
 }
75 75
 
76 76
 function wpinv_store_address() {
77
-    $address = wpinv_get_option( 'store_address', '' );
77
+    $address = wpinv_get_option('store_address', '');
78 78
 
79
-    return apply_filters( 'wpinv_store_address', $address );
79
+    return apply_filters('wpinv_store_address', $address);
80 80
 }
81 81
 
82
-function wpinv_get_user_address( $user_id = 0, $with_default = true ) {
82
+function wpinv_get_user_address($user_id = 0, $with_default = true) {
83 83
     global $wpi_userID;
84 84
     
85
-    if( empty( $user_id ) ) {
86
-        $user_id = !empty( $wpi_userID ) ? $wpi_userID : get_current_user_id();
85
+    if (empty($user_id)) {
86
+        $user_id = !empty($wpi_userID) ? $wpi_userID : get_current_user_id();
87 87
     }
88 88
     
89 89
     $address_fields = array(
@@ -101,29 +101,29 @@  discard block
 block discarded – undo
101 101
         'zip',
102 102
     );
103 103
     
104
-    $user_info = get_userdata( $user_id );
104
+    $user_info = get_userdata($user_id);
105 105
     
106 106
     $address = array();
107 107
     $address['user_id'] = $user_id;
108
-    $address['email'] = !empty( $user_info ) ? $user_info->user_email : '';
109
-    foreach ( $address_fields as $field ) {
110
-        $address[$field] = get_user_meta( $user_id, '_wpinv_' . $field, true );
108
+    $address['email'] = !empty($user_info) ? $user_info->user_email : '';
109
+    foreach ($address_fields as $field) {
110
+        $address[$field] = get_user_meta($user_id, '_wpinv_' . $field, true);
111 111
     }
112 112
 
113
-    if ( !empty( $user_info ) ) {
114
-        if( empty( $address['first_name'] ) )
113
+    if (!empty($user_info)) {
114
+        if (empty($address['first_name']))
115 115
             $address['first_name'] = $user_info->first_name;
116 116
         
117
-        if( empty( $address['last_name'] ) )
117
+        if (empty($address['last_name']))
118 118
             $address['last_name'] = $user_info->last_name;
119 119
     }
120 120
     
121
-    $address['name'] = trim( trim( $address['first_name'] . ' ' . $address['last_name'] ), "," );
121
+    $address['name'] = trim(trim($address['first_name'] . ' ' . $address['last_name']), ",");
122 122
     
123
-    if( empty( $address['state'] ) && $with_default )
123
+    if (empty($address['state']) && $with_default)
124 124
         $address['state'] = wpinv_get_default_state();
125 125
 
126
-    if( empty( $address['country'] ) && $with_default )
126
+    if (empty($address['country']) && $with_default)
127 127
         $address['country'] = wpinv_get_default_country();
128 128
 
129 129
 
@@ -137,16 +137,16 @@  discard block
 block discarded – undo
137 137
  * @param string $return What to return.
138 138
  * @return array
139 139
  */
140
-function wpinv_get_continents( $return = 'all' ) {
140
+function wpinv_get_continents($return = 'all') {
141 141
 
142
-    $continents = wpinv_get_data( 'continents' );
142
+    $continents = wpinv_get_data('continents');
143 143
 
144
-    switch( $return ) {
144
+    switch ($return) {
145 145
         case 'name' :
146
-            return wp_list_pluck( $continents, 'name' );
146
+            return wp_list_pluck($continents, 'name');
147 147
             break;
148 148
         case 'countries' :
149
-            return wp_list_pluck( $continents, 'countries' );
149
+            return wp_list_pluck($continents, 'countries');
150 150
             break;
151 151
         default :
152 152
             return $continents;
@@ -162,12 +162,12 @@  discard block
 block discarded – undo
162 162
  * @param string $country Country code. If no code is specified, defaults to the default country.
163 163
  * @return string
164 164
  */
165
-function wpinv_get_continent_code_for_country( $country = false ) {
165
+function wpinv_get_continent_code_for_country($country = false) {
166 166
 
167
-    $country = wpinv_sanitize_country( $country );
167
+    $country = wpinv_sanitize_country($country);
168 168
     
169
-	foreach ( wpinv_get_continents( 'countries' ) as $continent_code => $countries ) {
170
-		if ( false !== array_search( $country, $countries, true ) ) {
169
+	foreach (wpinv_get_continents('countries') as $continent_code => $countries) {
170
+		if (false !== array_search($country, $countries, true)) {
171 171
 			return $continent_code;
172 172
 		}
173 173
 	}
@@ -183,13 +183,13 @@  discard block
 block discarded – undo
183 183
  * @param string $country Country code. If no code is specified, defaults to the default country.
184 184
  * @return array
185 185
  */
186
-function wpinv_get_country_calling_code( $country = null) {
186
+function wpinv_get_country_calling_code($country = null) {
187 187
 
188
-    $country = wpinv_sanitize_country( $country );
189
-    $codes   = wpinv_get_data( 'phone-codes' );
190
-    $code    = isset( $codes[ $country ] ) ? $codes[ $country ] : '';
188
+    $country = wpinv_sanitize_country($country);
189
+    $codes   = wpinv_get_data('phone-codes');
190
+    $code    = isset($codes[$country]) ? $codes[$country] : '';
191 191
 
192
-    if ( is_array( $code ) ) {
192
+    if (is_array($code)) {
193 193
         return $code[0];
194 194
     }
195 195
     return $code;
@@ -202,8 +202,8 @@  discard block
 block discarded – undo
202 202
  * @param bool $first_empty Whether or not the first item in the list should be empty
203 203
  * @return array
204 204
  */
205
-function wpinv_get_country_list( $first_empty = false ) {
206
-    return wpinv_maybe_add_empty_option( apply_filters( 'wpinv_countries', wpinv_get_data( 'countries' ) ), $first_empty );
205
+function wpinv_get_country_list($first_empty = false) {
206
+    return wpinv_maybe_add_empty_option(apply_filters('wpinv_countries', wpinv_get_data('countries')), $first_empty);
207 207
 }
208 208
 
209 209
 /**
@@ -213,22 +213,22 @@  discard block
 block discarded – undo
213 213
  * @param bool $first_empty Whether or not the first item in the list should be empty
214 214
  * @return array
215 215
  */
216
-function wpinv_get_country_states( $country = null, $first_empty = false ) {
216
+function wpinv_get_country_states($country = null, $first_empty = false) {
217 217
     
218 218
     // Prepare the country.
219
-    $country = wpinv_sanitize_country( $country );
219
+    $country = wpinv_sanitize_country($country);
220 220
 
221 221
     // Fetch all states.
222
-    $all_states = wpinv_get_data( 'states' );
222
+    $all_states = wpinv_get_data('states');
223 223
 
224 224
     // Fetch the specified country's states.
225
-    $states     = isset( $all_states[ $country ] ) ? $all_states[ $country ] : array() ;
226
-    $states     = apply_filters( "wpinv_{$country}_states", $states );
227
-    $states     = apply_filters( 'wpinv_country_states', $states, $country );
225
+    $states     = isset($all_states[$country]) ? $all_states[$country] : array();
226
+    $states     = apply_filters("wpinv_{$country}_states", $states);
227
+    $states     = apply_filters('wpinv_country_states', $states, $country);
228 228
 
229
-    asort( $states );
229
+    asort($states);
230 230
      
231
-    return wpinv_maybe_add_empty_option( $states, $first_empty );
231
+    return wpinv_maybe_add_empty_option($states, $first_empty);
232 232
 }
233 233
 
234 234
 /**
@@ -238,7 +238,7 @@  discard block
 block discarded – undo
238 238
  * @return array
239 239
  */
240 240
 function wpinv_get_us_states_list() {
241
-    return apply_filters( 'wpinv_usa_states', wpinv_get_country_states( 'US' ) );
241
+    return apply_filters('wpinv_usa_states', wpinv_get_country_states('US'));
242 242
 }
243 243
 
244 244
 /**
@@ -248,7 +248,7 @@  discard block
 block discarded – undo
248 248
  * @return array
249 249
  */
250 250
 function wpinv_get_canada_states_list() {
251
-    return apply_filters( 'wpinv_canada_provinces', wpinv_get_country_states( 'CA' ) );
251
+    return apply_filters('wpinv_canada_provinces', wpinv_get_country_states('CA'));
252 252
 }
253 253
 
254 254
 /**
@@ -258,7 +258,7 @@  discard block
 block discarded – undo
258 258
  * @return array
259 259
  */
260 260
 function wpinv_get_australia_states_list() {
261
-    return apply_filters( 'wpinv_australia_states', wpinv_get_country_states( 'AU' ) );
261
+    return apply_filters('wpinv_australia_states', wpinv_get_country_states('AU'));
262 262
 }
263 263
 
264 264
 /**
@@ -268,7 +268,7 @@  discard block
 block discarded – undo
268 268
  * @return array
269 269
  */
270 270
 function wpinv_get_bangladesh_states_list() {
271
-    return apply_filters( 'wpinv_bangladesh_states', wpinv_get_country_states( 'BD' ) );
271
+    return apply_filters('wpinv_bangladesh_states', wpinv_get_country_states('BD'));
272 272
 }
273 273
 
274 274
 /**
@@ -278,7 +278,7 @@  discard block
 block discarded – undo
278 278
  * @return array
279 279
  */
280 280
 function wpinv_get_brazil_states_list() {
281
-    return apply_filters( 'wpinv_brazil_states', wpinv_get_country_states( 'BR' ) );
281
+    return apply_filters('wpinv_brazil_states', wpinv_get_country_states('BR'));
282 282
 }
283 283
 
284 284
 /**
@@ -288,7 +288,7 @@  discard block
 block discarded – undo
288 288
  * @return array
289 289
  */
290 290
 function wpinv_get_bulgaria_states_list() {
291
-    return apply_filters( 'wpinv_bulgaria_states', wpinv_get_country_states( 'BG' ) );
291
+    return apply_filters('wpinv_bulgaria_states', wpinv_get_country_states('BG'));
292 292
 }
293 293
 
294 294
 /**
@@ -298,7 +298,7 @@  discard block
 block discarded – undo
298 298
  * @return array
299 299
  */
300 300
 function wpinv_get_hong_kong_states_list() {
301
-    return apply_filters( 'wpinv_hong_kong_states', wpinv_get_country_states( 'HK' ) );
301
+    return apply_filters('wpinv_hong_kong_states', wpinv_get_country_states('HK'));
302 302
 }
303 303
 
304 304
 /**
@@ -308,7 +308,7 @@  discard block
 block discarded – undo
308 308
  * @return array
309 309
  */
310 310
 function wpinv_get_hungary_states_list() {
311
-    return apply_filters( 'wpinv_hungary_states', wpinv_get_country_states( 'HU' ) );
311
+    return apply_filters('wpinv_hungary_states', wpinv_get_country_states('HU'));
312 312
 }
313 313
 
314 314
 /**
@@ -318,7 +318,7 @@  discard block
 block discarded – undo
318 318
  * @return array
319 319
  */
320 320
 function wpinv_get_japan_states_list() {
321
-    return apply_filters( 'wpinv_japan_states', wpinv_get_country_states( 'JP' ) );
321
+    return apply_filters('wpinv_japan_states', wpinv_get_country_states('JP'));
322 322
 }
323 323
 
324 324
 /**
@@ -328,7 +328,7 @@  discard block
 block discarded – undo
328 328
  * @return array
329 329
  */
330 330
 function wpinv_get_china_states_list() {
331
-    return apply_filters( 'wpinv_china_states', wpinv_get_country_states( 'CN' ) );
331
+    return apply_filters('wpinv_china_states', wpinv_get_country_states('CN'));
332 332
 }
333 333
 
334 334
 /**
@@ -338,7 +338,7 @@  discard block
 block discarded – undo
338 338
  * @return array
339 339
  */
340 340
 function wpinv_get_new_zealand_states_list() {
341
-    return apply_filters( 'wpinv_new_zealand_states', wpinv_get_country_states( 'NZ' ) );
341
+    return apply_filters('wpinv_new_zealand_states', wpinv_get_country_states('NZ'));
342 342
 }
343 343
 
344 344
 /**
@@ -348,7 +348,7 @@  discard block
 block discarded – undo
348 348
  * @return array
349 349
  */
350 350
 function wpinv_get_peru_states_list() {
351
-    return apply_filters( 'wpinv_peru_states', wpinv_get_country_states( 'PE' ) );
351
+    return apply_filters('wpinv_peru_states', wpinv_get_country_states('PE'));
352 352
 }
353 353
 
354 354
 /**
@@ -358,7 +358,7 @@  discard block
 block discarded – undo
358 358
  * @return array
359 359
  */
360 360
 function wpinv_get_indonesia_states_list() {
361
-    return apply_filters( 'wpinv_indonesia_states', wpinv_get_country_states( 'ID' ) );
361
+    return apply_filters('wpinv_indonesia_states', wpinv_get_country_states('ID'));
362 362
 }
363 363
 
364 364
 /**
@@ -368,7 +368,7 @@  discard block
 block discarded – undo
368 368
  * @return array
369 369
  */
370 370
 function wpinv_get_india_states_list() {
371
-    return apply_filters( 'wpinv_india_states', wpinv_get_country_states( 'IN' ) );
371
+    return apply_filters('wpinv_india_states', wpinv_get_country_states('IN'));
372 372
 }
373 373
 
374 374
 /**
@@ -378,7 +378,7 @@  discard block
 block discarded – undo
378 378
  * @return array
379 379
  */
380 380
 function wpinv_get_iran_states_list() {
381
-    return apply_filters( 'wpinv_iran_states', wpinv_get_country_states( 'IR' ) );
381
+    return apply_filters('wpinv_iran_states', wpinv_get_country_states('IR'));
382 382
 }
383 383
 
384 384
 /**
@@ -388,7 +388,7 @@  discard block
 block discarded – undo
388 388
  * @return array
389 389
  */
390 390
 function wpinv_get_italy_states_list() {
391
-    return apply_filters( 'wpinv_italy_states', wpinv_get_country_states( 'IT' ) );
391
+    return apply_filters('wpinv_italy_states', wpinv_get_country_states('IT'));
392 392
 }
393 393
 
394 394
 /**
@@ -398,7 +398,7 @@  discard block
 block discarded – undo
398 398
  * @return array
399 399
  */
400 400
 function wpinv_get_malaysia_states_list() {
401
-    return apply_filters( 'wpinv_malaysia_states', wpinv_get_country_states( 'MY' ) );
401
+    return apply_filters('wpinv_malaysia_states', wpinv_get_country_states('MY'));
402 402
 }
403 403
 
404 404
 /**
@@ -408,7 +408,7 @@  discard block
 block discarded – undo
408 408
  * @return array
409 409
  */
410 410
 function wpinv_get_mexico_states_list() {
411
-    return apply_filters( 'wpinv_mexico_states', wpinv_get_country_states( 'MX' ) );
411
+    return apply_filters('wpinv_mexico_states', wpinv_get_country_states('MX'));
412 412
 }
413 413
 
414 414
 /**
@@ -418,7 +418,7 @@  discard block
 block discarded – undo
418 418
  * @return array
419 419
  */
420 420
 function wpinv_get_nepal_states_list() {
421
-    return apply_filters( 'wpinv_nepal_states', wpinv_get_country_states( 'NP' ) );
421
+    return apply_filters('wpinv_nepal_states', wpinv_get_country_states('NP'));
422 422
 }
423 423
 
424 424
 /**
@@ -428,7 +428,7 @@  discard block
 block discarded – undo
428 428
  * @return array
429 429
  */
430 430
 function wpinv_get_south_africa_states_list() {
431
-    return apply_filters( 'wpinv_south_africa_states', wpinv_get_country_states( 'ZA' ) );
431
+    return apply_filters('wpinv_south_africa_states', wpinv_get_country_states('ZA'));
432 432
 }
433 433
 
434 434
 /**
@@ -438,7 +438,7 @@  discard block
 block discarded – undo
438 438
  * @return array
439 439
  */
440 440
 function wpinv_get_thailand_states_list() {
441
-    return apply_filters( 'wpinv_thailand_states', wpinv_get_country_states( 'TH' ) );
441
+    return apply_filters('wpinv_thailand_states', wpinv_get_country_states('TH'));
442 442
 }
443 443
 
444 444
 /**
@@ -448,7 +448,7 @@  discard block
 block discarded – undo
448 448
  * @return array
449 449
  */
450 450
 function wpinv_get_turkey_states_list() {
451
-    return apply_filters( 'wpinv_turkey_states', wpinv_get_country_states( 'TR' ) );
451
+    return apply_filters('wpinv_turkey_states', wpinv_get_country_states('TR'));
452 452
 }
453 453
 
454 454
 /**
@@ -458,28 +458,28 @@  discard block
 block discarded – undo
458 458
  * @return array
459 459
  */
460 460
 function wpinv_get_spain_states_list() {
461
-    return apply_filters( 'wpinv_spain_states', wpinv_get_country_states( 'ES' ) );
461
+    return apply_filters('wpinv_spain_states', wpinv_get_country_states('ES'));
462 462
 }
463 463
 
464 464
 function wpinv_get_states_field() {
465
-	if( empty( $_POST['country'] ) ) {
465
+	if (empty($_POST['country'])) {
466 466
 		$_POST['country'] = wpinv_get_default_country();
467 467
 	}
468
-	$states = wpinv_get_country_states( sanitize_text_field( $_POST['country'] ) );
468
+	$states = wpinv_get_country_states(sanitize_text_field($_POST['country']));
469 469
 
470
-	if( !empty( $states ) ) {
471
-		$sanitized_field_name = sanitize_text_field( $_POST['field_name'] );
470
+	if (!empty($states)) {
471
+		$sanitized_field_name = sanitize_text_field($_POST['field_name']);
472 472
         
473 473
         $args = array(
474 474
 			'name'    => $sanitized_field_name,
475 475
 			'id'      => $sanitized_field_name,
476 476
 			'class'   => $sanitized_field_name . 'custom-select wpinv-select wpi_select2',
477
-			'options' => array_merge( array( '' => '' ), $states ),
477
+			'options' => array_merge(array('' => ''), $states),
478 478
 			'show_option_all'  => false,
479 479
 			'show_option_none' => false
480 480
 		);
481 481
 
482
-		$response = wpinv_html_select( $args );
482
+		$response = wpinv_html_select($args);
483 483
 
484 484
 	} else {
485 485
 		$response = 'nostates';
@@ -488,10 +488,10 @@  discard block
 block discarded – undo
488 488
 	return $response;
489 489
 }
490 490
 
491
-function wpinv_default_billing_country( $country = '', $user_id = 0 ) {
492
-    $country = !empty( $country ) ? $country : wpinv_get_default_country();
491
+function wpinv_default_billing_country($country = '', $user_id = 0) {
492
+    $country = !empty($country) ? $country : wpinv_get_default_country();
493 493
     
494
-    return apply_filters( 'wpinv_default_billing_country', $country, $user_id );
494
+    return apply_filters('wpinv_default_billing_country', $country, $user_id);
495 495
 }
496 496
 
497 497
 /**
@@ -503,7 +503,7 @@  discard block
 block discarded – undo
503 503
  */
504 504
 function wpinv_get_address_formats() {
505 505
 
506
-		return apply_filters( 'wpinv_localisation_address_formats',
506
+		return apply_filters('wpinv_localisation_address_formats',
507 507
 			array(
508 508
 				'default' => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}}\n{{zip}}\n{{country}}",
509 509
 				'AU'      => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}} {{zip}}\n{{country}}",
@@ -552,9 +552,9 @@  discard block
 block discarded – undo
552 552
  * @see `wpinv_get_invoice_address_replacements`
553 553
  * @return string
554 554
  */
555
-function wpinv_get_full_address_format( $country = false) {
555
+function wpinv_get_full_address_format($country = false) {
556 556
 
557
-    if( empty( $country ) ) {
557
+    if (empty($country)) {
558 558
         $country = wpinv_get_default_country();
559 559
     }
560 560
 
@@ -562,7 +562,7 @@  discard block
 block discarded – undo
562 562
 	$formats = wpinv_get_address_formats();
563 563
 
564 564
 	// Get format for the specified country.
565
-	$format = ( $country && isset( $formats[ $country ] ) ) ? $formats[ $country ] : $formats['default'];
565
+	$format = ($country && isset($formats[$country])) ? $formats[$country] : $formats['default'];
566 566
     
567 567
     /**
568 568
 	 * Filters the address format to use on Invoices.
@@ -574,7 +574,7 @@  discard block
 block discarded – undo
574 574
 	 * @param string $format  The address format to use.
575 575
      * @param string $country The country who's address format is being retrieved.
576 576
 	 */
577
-    return apply_filters( 'wpinv_get_full_address_format', $format, $country );
577
+    return apply_filters('wpinv_get_full_address_format', $format, $country);
578 578
 }
579 579
 
580 580
 /**
@@ -585,7 +585,7 @@  discard block
 block discarded – undo
585 585
  * @param array $billing_details customer's billing details
586 586
  * @return array
587 587
  */
588
-function wpinv_get_invoice_address_replacements( $billing_details ) {
588
+function wpinv_get_invoice_address_replacements($billing_details) {
589 589
 
590 590
     $default_args = array(
591 591
         'address'           => '',
@@ -598,22 +598,22 @@  discard block
 block discarded – undo
598 598
 		'company'           => '',
599 599
     );
600 600
 
601
-    $args    = map_deep( wp_parse_args( $billing_details, $default_args ), 'trim' );
601
+    $args    = map_deep(wp_parse_args($billing_details, $default_args), 'trim');
602 602
     $state   = $args['state'];
603 603
     $country = $args['country'];
604 604
 
605 605
     // Handle full country name.
606
-    $full_country = empty( $country ) ? $country : wpinv_country_name( $country );
606
+    $full_country = empty($country) ? $country : wpinv_country_name($country);
607 607
 
608 608
     // Handle full state name.
609
-    $full_state   = ( $country && $state ) ?  wpinv_state_name( $state, $country ) : $state;
609
+    $full_state   = ($country && $state) ?  wpinv_state_name($state, $country) : $state;
610 610
 
611 611
     $args['postcode']    = $args['zip'];
612 612
     $args['name']        = $args['first_name'] . ' ' . $args['last_name'];
613 613
     $args['state']       = $full_state;
614 614
     $args['state_code']  = $state;
615 615
     $args['country']     = $full_country;
616
-    $args['country_code']= $country;
616
+    $args['country_code'] = $country;
617 617
 
618 618
     /**
619 619
 	 * Filters the address format replacements to use on Invoices.
@@ -624,14 +624,14 @@  discard block
 block discarded – undo
624 624
 	 * @param array $replacements  The address replacements to use.
625 625
      * @param array $billing_details  The billing details to use.
626 626
 	 */
627
-    $replacements = apply_filters( 'wpinv_get_invoice_address_replacements', $args, $billing_details );
627
+    $replacements = apply_filters('wpinv_get_invoice_address_replacements', $args, $billing_details);
628 628
 
629 629
     $return = array();
630 630
 
631
-    foreach( $replacements as $key => $value ) {
632
-        $value  = is_scalar( $value ) ? trim( sanitize_text_field( $value ) ) : '';
631
+    foreach ($replacements as $key => $value) {
632
+        $value = is_scalar($value) ? trim(sanitize_text_field($value)) : '';
633 633
         $return['{{' . $key . '}}'] = $value;
634
-        $return['{{' . $key . '_upper}}'] = wpinv_utf8_strtoupper( $value );
634
+        $return['{{' . $key . '_upper}}'] = wpinv_utf8_strtoupper($value);
635 635
     }
636 636
 
637 637
     return $return;
@@ -645,6 +645,6 @@  discard block
 block discarded – undo
645 645
  * @since 1.0.14
646 646
  * @return string
647 647
  */
648
-function wpinv_trim_formatted_address_line( $line ) {
649
-	return trim( $line, ', ' );
648
+function wpinv_trim_formatted_address_line($line) {
649
+	return trim($line, ', ');
650 650
 }
651 651
\ No newline at end of file
Please login to merge, or discard this patch.
includes/admin/meta-boxes/class-mb-invoice-address.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -1,14 +1,14 @@
 block discarded – undo
1 1
 <?php
2 2
 // MUST have WordPress.
3
-if ( !defined( 'WPINC' ) ) {
4
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
3
+if (!defined('WPINC')) {
4
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
5 5
 }
6 6
 
7 7
 class WPInv_Meta_Box_Billing_Details {
8
-    public static function output( $post ) {
8
+    public static function output($post) {
9 9
         global $user_ID;
10
-        $post_id    = !empty( $post->ID ) ? $post->ID : 0;
11
-        $invoice    = new WPInv_Invoice( $post_id );
10
+        $post_id    = !empty($post->ID) ? $post->ID : 0;
11
+        $invoice    = new WPInv_Invoice($post_id);
12 12
 
13 13
     }
14 14
 }
Please login to merge, or discard this patch.