Completed
Branch master (d48fb4)
by Stiofan
03:49
created
includes/wpinv-tax-functions.php 1 patch
Spacing   +163 added lines, -163 removed lines patch added patch discarded remove patch
@@ -1,121 +1,121 @@  discard block
 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
 function wpinv_use_taxes() {
8
-    $ret = wpinv_get_option( 'enable_taxes', false );
8
+    $ret = wpinv_get_option('enable_taxes', false);
9 9
     
10
-    return (bool) apply_filters( 'wpinv_use_taxes', $ret );
10
+    return (bool)apply_filters('wpinv_use_taxes', $ret);
11 11
 }
12 12
 
13 13
 function wpinv_get_tax_rates() {
14
-    $rates = get_option( 'wpinv_tax_rates', array() );
14
+    $rates = get_option('wpinv_tax_rates', array());
15 15
     
16
-    return apply_filters( 'wpinv_get_tax_rates', $rates );
16
+    return apply_filters('wpinv_get_tax_rates', $rates);
17 17
 }
18 18
 
19
-function wpinv_get_tax_rate( $country = false, $state = false, $item_id = 0 ) {
19
+function wpinv_get_tax_rate($country = false, $state = false, $item_id = 0) {
20 20
     global $wpinv_euvat, $wpi_tax_rates, $wpi_userID;
21
-    $wpi_tax_rates = !empty( $wpi_tax_rates ) ? $wpi_tax_rates : array();
21
+    $wpi_tax_rates = !empty($wpi_tax_rates) ? $wpi_tax_rates : array();
22 22
     
23
-    if ( !empty( $wpi_tax_rates ) && !empty( $item_id ) && isset( $wpi_tax_rates[$item_id] ) ) {
23
+    if (!empty($wpi_tax_rates) && !empty($item_id) && isset($wpi_tax_rates[$item_id])) {
24 24
         return $wpi_tax_rates[$item_id];
25 25
     }
26 26
     
27
-    if ( !$wpinv_euvat->item_is_taxable( $item_id, $country, $state ) ) {
27
+    if (!$wpinv_euvat->item_is_taxable($item_id, $country, $state)) {
28 28
         $wpi_tax_rates[$item_id] = 0;
29 29
         return 0;
30 30
     }
31 31
     
32 32
     $is_global = false;
33
-    if ( $item_id == 'global' ) {
33
+    if ($item_id == 'global') {
34 34
         $is_global = true;
35 35
         $item_id = 0;
36 36
     }
37 37
     
38
-    $rate           = (float)wpinv_get_option( 'tax_rate', 0 );
39
-    $user_address   = wpinv_get_user_address( $wpi_userID );
38
+    $rate           = (float)wpinv_get_option('tax_rate', 0);
39
+    $user_address   = wpinv_get_user_address($wpi_userID);
40 40
     
41
-    if( empty( $country ) ) {
42
-        if( !empty( $_POST['wpinv_country'] ) ) {
41
+    if (empty($country)) {
42
+        if (!empty($_POST['wpinv_country'])) {
43 43
             $country = $_POST['wpinv_country'];
44
-        } elseif( !empty( $_POST['wpinv_country'] ) ) {
44
+        } elseif (!empty($_POST['wpinv_country'])) {
45 45
             $country = $_POST['wpinv_country'];
46
-        } elseif( !empty( $_POST['country'] ) ) {
46
+        } elseif (!empty($_POST['country'])) {
47 47
             $country = $_POST['country'];
48
-        } elseif( is_user_logged_in() && !empty( $user_address ) ) {
48
+        } elseif (is_user_logged_in() && !empty($user_address)) {
49 49
             $country = $user_address['country'];
50 50
         }
51
-        $country = !empty( $country ) ? $country : wpinv_get_default_country();
51
+        $country = !empty($country) ? $country : wpinv_get_default_country();
52 52
     }
53 53
 
54
-    if( empty( $state ) ) {
55
-        if( !empty( $_POST['wpinv_state'] ) ) {
54
+    if (empty($state)) {
55
+        if (!empty($_POST['wpinv_state'])) {
56 56
             $state = $_POST['wpinv_state'];
57
-        } elseif( !empty( $_POST['wpinv_state'] ) ) {
57
+        } elseif (!empty($_POST['wpinv_state'])) {
58 58
             $state = $_POST['wpinv_state'];
59
-        } elseif( !empty( $_POST['state'] ) ) {
59
+        } elseif (!empty($_POST['state'])) {
60 60
             $state = $_POST['state'];
61
-        } elseif( is_user_logged_in() && !empty( $user_address ) ) {
61
+        } elseif (is_user_logged_in() && !empty($user_address)) {
62 62
             $state = $user_address['state'];
63 63
         }
64
-        $state = !empty( $state ) ? $state : wpinv_get_default_state();
64
+        $state = !empty($state) ? $state : wpinv_get_default_state();
65 65
     }
66 66
     
67
-    if( !empty( $country ) ) {
68
-        $tax_rates   = wpinv_get_tax_rates();
67
+    if (!empty($country)) {
68
+        $tax_rates = wpinv_get_tax_rates();
69 69
 
70
-        if( !empty( $tax_rates ) ) {
70
+        if (!empty($tax_rates)) {
71 71
             // Locate the tax rate for this country / state, if it exists
72
-            foreach( $tax_rates as $key => $tax_rate ) {
73
-                if( $country != $tax_rate['country'] )
72
+            foreach ($tax_rates as $key => $tax_rate) {
73
+                if ($country != $tax_rate['country'])
74 74
                     continue;
75 75
 
76
-                if( !empty( $tax_rate['global'] ) ) {
77
-                    if( !empty( $tax_rate['rate'] ) ) {
78
-                        $rate = number_format( $tax_rate['rate'], 4 );
76
+                if (!empty($tax_rate['global'])) {
77
+                    if (!empty($tax_rate['rate'])) {
78
+                        $rate = number_format($tax_rate['rate'], 4);
79 79
                     }
80 80
                 } else {
81 81
 
82
-                    if( empty( $tax_rate['state'] ) || strtolower( $state ) != strtolower( $tax_rate['state'] ) )
82
+                    if (empty($tax_rate['state']) || strtolower($state) != strtolower($tax_rate['state']))
83 83
                         continue;
84 84
 
85 85
                     $state_rate = $tax_rate['rate'];
86
-                    if( 0 !== $state_rate || !empty( $state_rate ) ) {
87
-                        $rate = number_format( $state_rate, 4 );
86
+                    if (0 !== $state_rate || !empty($state_rate)) {
87
+                        $rate = number_format($state_rate, 4);
88 88
                     }
89 89
                 }
90 90
             }
91 91
         }
92 92
     }
93 93
     
94
-    $rate = apply_filters( 'wpinv_tax_rate', $rate, $country, $state, $item_id );
94
+    $rate = apply_filters('wpinv_tax_rate', $rate, $country, $state, $item_id);
95 95
     
96
-    if ( !empty( $item_id ) ) {
96
+    if (!empty($item_id)) {
97 97
         $wpi_tax_rates[$item_id] = $rate;
98
-    } else if ( $is_global ) {
98
+    } else if ($is_global) {
99 99
         $wpi_tax_rates['global'] = $rate;
100 100
     }
101 101
     
102 102
     return $rate;
103 103
 }
104 104
 
105
-function wpinv_get_formatted_tax_rate( $country = false, $state = false, $item_id ) {
106
-    $rate = wpinv_get_tax_rate( $country, $state, $item_id );
107
-    $rate = round( $rate, 4 );
105
+function wpinv_get_formatted_tax_rate($country = false, $state = false, $item_id) {
106
+    $rate = wpinv_get_tax_rate($country, $state, $item_id);
107
+    $rate = round($rate, 4);
108 108
     $formatted = $rate .= '%';
109
-    return apply_filters( 'wpinv_formatted_tax_rate', $formatted, $rate, $country, $state, $item_id );
109
+    return apply_filters('wpinv_formatted_tax_rate', $formatted, $rate, $country, $state, $item_id);
110 110
 }
111 111
 
112
-function wpinv_calculate_tax( $amount = 0, $country = false, $state = false, $item_id = 0 ) {
113
-    $rate = wpinv_get_tax_rate( $country, $state, $item_id );
112
+function wpinv_calculate_tax($amount = 0, $country = false, $state = false, $item_id = 0) {
113
+    $rate = wpinv_get_tax_rate($country, $state, $item_id);
114 114
     $tax  = 0.00;
115 115
 
116
-    if ( wpinv_use_taxes() ) {        
117
-        if ( wpinv_prices_include_tax() ) {
118
-            $pre_tax = ( $amount / ( ( 1 + $rate ) * 0.01 ) );
116
+    if (wpinv_use_taxes()) {        
117
+        if (wpinv_prices_include_tax()) {
118
+            $pre_tax = ($amount / ((1 + $rate) * 0.01));
119 119
             $tax     = $amount - $pre_tax;
120 120
         } else {
121 121
             $tax = $amount * $rate * 0.01;
@@ -123,46 +123,46 @@  discard block
 block discarded – undo
123 123
 
124 124
     }
125 125
 
126
-    return apply_filters( 'wpinv_taxed_amount', $tax, $rate, $country, $state, $item_id );
126
+    return apply_filters('wpinv_taxed_amount', $tax, $rate, $country, $state, $item_id);
127 127
 }
128 128
 
129 129
 function wpinv_prices_include_tax() {
130 130
     return false; // TODO
131
-    $ret = ( wpinv_get_option( 'prices_include_tax', false ) == 'yes' && wpinv_use_taxes() );
131
+    $ret = (wpinv_get_option('prices_include_tax', false) == 'yes' && wpinv_use_taxes());
132 132
 
133
-    return apply_filters( 'wpinv_prices_include_tax', $ret );
133
+    return apply_filters('wpinv_prices_include_tax', $ret);
134 134
 }
135 135
 
136
-function wpinv_sales_tax_for_year( $year = null ) {
137
-    return wpinv_price( wpinv_format_amount( wpinv_get_sales_tax_for_year( $year ) ) );
136
+function wpinv_sales_tax_for_year($year = null) {
137
+    return wpinv_price(wpinv_format_amount(wpinv_get_sales_tax_for_year($year)));
138 138
 }
139 139
 
140
-function wpinv_get_sales_tax_for_year( $year = null ) {
140
+function wpinv_get_sales_tax_for_year($year = null) {
141 141
     global $wpdb;
142 142
 
143 143
     // Start at zero
144 144
     $tax = 0;
145 145
 
146
-    if ( ! empty( $year ) ) {
146
+    if (!empty($year)) {
147 147
         $args = array(
148 148
             'post_type'      => 'wpi_invoice',
149
-            'post_status'    => array( 'publish', 'revoked' ),
149
+            'post_status'    => array('publish', 'revoked'),
150 150
             'posts_per_page' => -1,
151 151
             'year'           => $year,
152 152
             'fields'         => 'ids'
153 153
         );
154 154
 
155
-        $payments    = get_posts( $args );
156
-        $payment_ids = implode( ',', $payments );
155
+        $payments    = get_posts($args);
156
+        $payment_ids = implode(',', $payments);
157 157
 
158
-        if ( count( $payments ) > 0 ) {
158
+        if (count($payments) > 0) {
159 159
             $sql = "SELECT SUM( meta_value ) FROM $wpdb->postmeta WHERE meta_key = '_wpinv_tax' AND post_id IN( $payment_ids )";
160
-            $tax = $wpdb->get_var( $sql );
160
+            $tax = $wpdb->get_var($sql);
161 161
         }
162 162
 
163 163
     }
164 164
 
165
-    return apply_filters( 'wpinv_get_sales_tax_for_year', $tax, $year );
165
+    return apply_filters('wpinv_get_sales_tax_for_year', $tax, $year);
166 166
 }
167 167
 
168 168
 function wpinv_is_cart_taxed() {
@@ -171,33 +171,33 @@  discard block
 block discarded – undo
171 171
 
172 172
 function wpinv_prices_show_tax_on_checkout() {
173 173
     return false; // TODO
174
-    $ret = ( wpinv_get_option( 'checkout_include_tax', false ) == 'yes' && wpinv_use_taxes() );
174
+    $ret = (wpinv_get_option('checkout_include_tax', false) == 'yes' && wpinv_use_taxes());
175 175
 
176
-    return apply_filters( 'wpinv_taxes_on_prices_on_checkout', $ret );
176
+    return apply_filters('wpinv_taxes_on_prices_on_checkout', $ret);
177 177
 }
178 178
 
179 179
 function wpinv_display_tax_rate() {
180
-    $ret = wpinv_use_taxes() && wpinv_get_option( 'display_tax_rate', false );
180
+    $ret = wpinv_use_taxes() && wpinv_get_option('display_tax_rate', false);
181 181
 
182
-    return apply_filters( 'wpinv_display_tax_rate', $ret );
182
+    return apply_filters('wpinv_display_tax_rate', $ret);
183 183
 }
184 184
 
185 185
 function wpinv_cart_needs_tax_address_fields() {
186
-    if( !wpinv_is_cart_taxed() )
186
+    if (!wpinv_is_cart_taxed())
187 187
         return false;
188 188
 
189
-    return ! did_action( 'wpinv_after_cc_fields', 'wpinv_default_cc_address_fields' );
189
+    return !did_action('wpinv_after_cc_fields', 'wpinv_default_cc_address_fields');
190 190
 }
191 191
 
192
-function wpinv_item_is_tax_exclusive( $item_id = 0 ) {
193
-    $ret = (bool)get_post_meta( $item_id, '_wpinv_tax_exclusive', false );
194
-    return apply_filters( 'wpinv_is_tax_exclusive', $ret, $item_id );
192
+function wpinv_item_is_tax_exclusive($item_id = 0) {
193
+    $ret = (bool)get_post_meta($item_id, '_wpinv_tax_exclusive', false);
194
+    return apply_filters('wpinv_is_tax_exclusive', $ret, $item_id);
195 195
 }
196 196
 
197
-function wpinv_currency_decimal_filter( $decimals = 2 ) {
197
+function wpinv_currency_decimal_filter($decimals = 2) {
198 198
     $currency = wpinv_get_currency();
199 199
 
200
-    switch ( $currency ) {
200
+    switch ($currency) {
201 201
         case 'RIAL' :
202 202
         case 'JPY' :
203 203
         case 'TWD' :
@@ -206,48 +206,48 @@  discard block
 block discarded – undo
206 206
             break;
207 207
     }
208 208
 
209
-    return apply_filters( 'wpinv_currency_decimal_count', $decimals, $currency );
209
+    return apply_filters('wpinv_currency_decimal_count', $decimals, $currency);
210 210
 }
211 211
 
212 212
 function wpinv_tax_amount() {
213 213
     $output = 0.00;
214 214
     
215
-    return apply_filters( 'wpinv_tax_amount', $output );
215
+    return apply_filters('wpinv_tax_amount', $output);
216 216
 }
217 217
 
218 218
 function wpinv_recalculated_tax() {
219
-    define( 'WPINV_RECALCTAX', true );
219
+    define('WPINV_RECALCTAX', true);
220 220
 }
221
-add_action( 'wp_ajax_wpinv_recalculate_tax', 'wpinv_recalculated_tax', 1 );
221
+add_action('wp_ajax_wpinv_recalculate_tax', 'wpinv_recalculated_tax', 1);
222 222
 
223
-function wpinv_recalculate_tax( $return = false ) {
223
+function wpinv_recalculate_tax($return = false) {
224 224
     $invoice_id = (int)wpinv_get_invoice_cart_id();
225
-    if ( empty( $invoice_id ) ) {
225
+    if (empty($invoice_id)) {
226 226
         return false;
227 227
     }
228 228
     
229
-    $invoice = wpinv_get_invoice_cart( $invoice_id );
229
+    $invoice = wpinv_get_invoice_cart($invoice_id);
230 230
 
231
-    if ( empty( $invoice ) ) {
231
+    if (empty($invoice)) {
232 232
         return false;
233 233
     }
234 234
 
235
-    if ( empty( $_POST['country'] ) ) {
235
+    if (empty($_POST['country'])) {
236 236
         $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country();
237 237
     }
238 238
         
239 239
     $invoice->country = sanitize_text_field($_POST['country']);
240
-    $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) );
240
+    $invoice->set('country', sanitize_text_field($_POST['country']));
241 241
     if (isset($_POST['state'])) {
242 242
         $invoice->state = sanitize_text_field($_POST['state']);
243
-        $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) );
243
+        $invoice->set('state', sanitize_text_field($_POST['state']));
244 244
     }
245 245
 
246 246
     $invoice->cart_details  = wpinv_get_cart_content_details();
247 247
     
248
-    $subtotal               = wpinv_get_cart_subtotal( $invoice->cart_details );
249
-    $tax                    = wpinv_get_cart_tax( $invoice->cart_details );
250
-    $total                  = wpinv_get_cart_total( $invoice->cart_details );
248
+    $subtotal               = wpinv_get_cart_subtotal($invoice->cart_details);
249
+    $tax                    = wpinv_get_cart_tax($invoice->cart_details);
250
+    $total                  = wpinv_get_cart_total($invoice->cart_details);
251 251
 
252 252
     $invoice->tax           = $tax;
253 253
     $invoice->subtotal      = $subtotal;
@@ -255,60 +255,60 @@  discard block
 block discarded – undo
255 255
 
256 256
     $invoice->save();
257 257
     
258
-    if ( $invoice->is_free_trial() ) {
258
+    if ($invoice->is_free_trial()) {
259 259
         $total = 0;
260 260
     }
261 261
     
262 262
     $response = array(
263
-        'total'        => html_entity_decode( wpinv_price( wpinv_format_amount( $total ) ), ENT_COMPAT, 'UTF-8' ),
263
+        'total'        => html_entity_decode(wpinv_price(wpinv_format_amount($total)), ENT_COMPAT, 'UTF-8'),
264 264
         'total_raw'    => $total,
265
-        'html'         => wpinv_checkout_cart( $invoice->cart_details, false ),
265
+        'html'         => wpinv_checkout_cart($invoice->cart_details, false),
266 266
     );
267 267
     
268
-    if ( $return ) {
268
+    if ($return) {
269 269
         return $response;
270 270
     }
271 271
 
272
-    wp_send_json( $response );
272
+    wp_send_json($response);
273 273
 }
274
-add_action( 'wp_ajax_wpinv_recalculate_tax', 'wpinv_recalculate_tax' );
275
-add_action( 'wp_ajax_nopriv_wpinv_recalculate_tax', 'wpinv_recalculate_tax' );
274
+add_action('wp_ajax_wpinv_recalculate_tax', 'wpinv_recalculate_tax');
275
+add_action('wp_ajax_nopriv_wpinv_recalculate_tax', 'wpinv_recalculate_tax');
276 276
 
277 277
 // VAT Settings
278
-function wpinv_vat_rate_add_callback( $args ) {
278
+function wpinv_vat_rate_add_callback($args) {
279 279
     ?>
280
-    <p class="wpi-vat-rate-actions"><input id="wpi_vat_rate_add" type="button" value="<?php esc_attr_e( 'Add', 'invoicing' );?>" class="button button-primary" />&nbsp;&nbsp;<i style="display:none;" class="fa fa-refresh fa-spin"></i></p>
280
+    <p class="wpi-vat-rate-actions"><input id="wpi_vat_rate_add" type="button" value="<?php esc_attr_e('Add', 'invoicing'); ?>" class="button button-primary" />&nbsp;&nbsp;<i style="display:none;" class="fa fa-refresh fa-spin"></i></p>
281 281
     <?php
282 282
 }
283 283
 
284
-function wpinv_vat_rate_delete_callback( $args ) {
284
+function wpinv_vat_rate_delete_callback($args) {
285 285
     global $wpinv_euvat;
286 286
     
287 287
     $vat_classes = $wpinv_euvat->get_rate_classes();
288
-    $vat_class = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' && isset( $vat_classes[$_REQUEST['wpi_sub']] )? sanitize_text_field( $_REQUEST['wpi_sub'] ) : '';
289
-    if ( isset( $vat_classes[$vat_class] ) ) {
288
+    $vat_class = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' && isset($vat_classes[$_REQUEST['wpi_sub']]) ? sanitize_text_field($_REQUEST['wpi_sub']) : '';
289
+    if (isset($vat_classes[$vat_class])) {
290 290
     ?>
291
-    <p class="wpi-vat-rate-actions"><input id="wpi_vat_rate_delete" type="button" value="<?php echo wp_sprintf( esc_attr__( 'Delete class "%s"', 'invoicing' ), $vat_classes[$vat_class] );?>" class="button button-primary" />&nbsp;&nbsp;<i style="display:none;" class="fa fa-refresh fa-spin"></i></p>
291
+    <p class="wpi-vat-rate-actions"><input id="wpi_vat_rate_delete" type="button" value="<?php echo wp_sprintf(esc_attr__('Delete class "%s"', 'invoicing'), $vat_classes[$vat_class]); ?>" class="button button-primary" />&nbsp;&nbsp;<i style="display:none;" class="fa fa-refresh fa-spin"></i></p>
292 292
     <?php
293 293
     }
294 294
 }
295 295
 
296
-function wpinv_vat_rates_callback( $args ) {
296
+function wpinv_vat_rates_callback($args) {
297 297
     global $wpinv_euvat;
298 298
     
299 299
     $vat_classes    = $wpinv_euvat->get_rate_classes();
300
-    $vat_class      = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' && isset( $vat_classes[$_REQUEST['wpi_sub']] )? sanitize_text_field( $_REQUEST['wpi_sub'] ) : '_standard';
300
+    $vat_class      = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' && isset($vat_classes[$_REQUEST['wpi_sub']]) ? sanitize_text_field($_REQUEST['wpi_sub']) : '_standard';
301 301
     
302 302
     $eu_states      = $wpinv_euvat->get_eu_states();
303 303
     $countries      = wpinv_get_country_list();
304 304
     $vat_groups     = $wpinv_euvat->get_vat_groups();
305
-    $rates          = $wpinv_euvat->get_vat_rates( $vat_class );
305
+    $rates          = $wpinv_euvat->get_vat_rates($vat_class);
306 306
     ob_start();
307 307
 ?>
308 308
 </td><tr>
309 309
     <td colspan="2" class="wpinv_vat_tdbox">
310
-    <input type="hidden" name="wpi_vat_class" value="<?php echo $vat_class;?>" />
311
-    <p><?php echo ( isset( $args['desc'] ) ? $args['desc'] : '' ); ?></p>
310
+    <input type="hidden" name="wpi_vat_class" value="<?php echo $vat_class; ?>" />
311
+    <p><?php echo (isset($args['desc']) ? $args['desc'] : ''); ?></p>
312 312
     <table id="wpinv_vat_rates" class="wp-list-table widefat fixed posts">
313 313
         <colgroup>
314 314
             <col width="50px" />
@@ -320,43 +320,43 @@  discard block
 block discarded – undo
320 320
         </colgroup>
321 321
         <thead>
322 322
             <tr>
323
-                <th scope="col" colspan="2" class="wpinv_vat_country_name"><?php _e( 'Country', 'invoicing' ); ?></th>
324
-                <th scope="col" class="wpinv_vat_global" title="<?php esc_attr_e( 'Apply rate to whole country', 'invoicing' ); ?>"><?php _e( 'Country Wide', 'invoicing' ); ?></th>
325
-                <th scope="col" class="wpinv_vat_rate"><?php _e( 'Rate %', 'invoicing' ); ?></th> 
326
-                <th scope="col" class="wpinv_vat_name"><?php _e( 'VAT Name', 'invoicing' ); ?></th>
327
-                <th scope="col" class="wpinv_vat_group"><?php _e( 'Tax Group', 'invoicing' ); ?></th>
323
+                <th scope="col" colspan="2" class="wpinv_vat_country_name"><?php _e('Country', 'invoicing'); ?></th>
324
+                <th scope="col" class="wpinv_vat_global" title="<?php esc_attr_e('Apply rate to whole country', 'invoicing'); ?>"><?php _e('Country Wide', 'invoicing'); ?></th>
325
+                <th scope="col" class="wpinv_vat_rate"><?php _e('Rate %', 'invoicing'); ?></th> 
326
+                <th scope="col" class="wpinv_vat_name"><?php _e('VAT Name', 'invoicing'); ?></th>
327
+                <th scope="col" class="wpinv_vat_group"><?php _e('Tax Group', 'invoicing'); ?></th>
328 328
             </tr>
329 329
         </thead>
330 330
         <tbody>
331
-        <?php if( !empty( $eu_states ) ) { ?>
331
+        <?php if (!empty($eu_states)) { ?>
332 332
         <?php 
333
-        foreach ( $eu_states as $state ) { 
334
-            $country_name = isset( $countries[$state] ) ? $countries[$state] : '';
333
+        foreach ($eu_states as $state) { 
334
+            $country_name = isset($countries[$state]) ? $countries[$state] : '';
335 335
             
336 336
             // Filter the rate for each country
337
-            $country_rate = array_filter( $rates, function( $rate ) use( $state ) { return $rate['country'] === $state; } );
337
+            $country_rate = array_filter($rates, function($rate) use($state) { return $rate['country'] === $state; } );
338 338
             
339 339
             // If one does not exist create a default
340
-            $country_rate = is_array( $country_rate ) && count( $country_rate ) > 0 ? reset( $country_rate ) : array();
340
+            $country_rate = is_array($country_rate) && count($country_rate) > 0 ? reset($country_rate) : array();
341 341
             
342
-            $vat_global = isset( $country_rate['global'] ) ? !empty( $country_rate['global'] ) : true;
343
-            $vat_rate = isset( $country_rate['rate'] ) ? $country_rate['rate'] : '';
344
-            $vat_name = !empty( $country_rate['name'] ) ? esc_attr( stripslashes( $country_rate['name'] ) ) : '';
345
-            $vat_group = !empty( $country_rate['group'] ) ? $country_rate['group'] : ( $vat_class === '_standard' ? 'standard' : 'reduced' );
342
+            $vat_global = isset($country_rate['global']) ? !empty($country_rate['global']) : true;
343
+            $vat_rate = isset($country_rate['rate']) ? $country_rate['rate'] : '';
344
+            $vat_name = !empty($country_rate['name']) ? esc_attr(stripslashes($country_rate['name'])) : '';
345
+            $vat_group = !empty($country_rate['group']) ? $country_rate['group'] : ($vat_class === '_standard' ? 'standard' : 'reduced');
346 346
         ?>
347 347
         <tr>
348 348
             <td class="wpinv_vat_country"><?php echo $state; ?><input type="hidden" name="vat_rates[<?php echo $state; ?>][country]" value="<?php echo $state; ?>" /><input type="hidden" name="vat_rates[<?php echo $state; ?>][state]" value="" /></td>
349 349
             <td class="wpinv_vat_country_name"><?php echo $country_name; ?></td>
350 350
             <td class="wpinv_vat_global">
351
-                <input type="checkbox" name="vat_rates[<?php echo $state;?>][global]" id="vat_rates[<?php echo $state;?>][global]" value="1" <?php checked( true, $vat_global );?> disabled="disabled" />
352
-                <label for="tax_rates[<?php echo $state;?>][global]"><?php _e( 'Apply to whole country', 'invoicing' ); ?></label>
353
-                <input type="hidden" name="vat_rates[<?php echo $state;?>][global]" value="1" checked="checked" />
351
+                <input type="checkbox" name="vat_rates[<?php echo $state; ?>][global]" id="vat_rates[<?php echo $state; ?>][global]" value="1" <?php checked(true, $vat_global); ?> disabled="disabled" />
352
+                <label for="tax_rates[<?php echo $state; ?>][global]"><?php _e('Apply to whole country', 'invoicing'); ?></label>
353
+                <input type="hidden" name="vat_rates[<?php echo $state; ?>][global]" value="1" checked="checked" />
354 354
             </td>
355
-            <td class="wpinv_vat_rate"><input type="number" class="small-text" step="0.10" min="0.00" name="vat_rates[<?php echo $state;?>][rate]" value="<?php echo $vat_rate; ?>" /></td>
356
-            <td class="wpinv_vat_name"><input type="text" class="regular-text" name="vat_rates[<?php echo $state;?>][name]" value="<?php echo $vat_name; ?>" /></td>
355
+            <td class="wpinv_vat_rate"><input type="number" class="small-text" step="0.10" min="0.00" name="vat_rates[<?php echo $state; ?>][rate]" value="<?php echo $vat_rate; ?>" /></td>
356
+            <td class="wpinv_vat_name"><input type="text" class="regular-text" name="vat_rates[<?php echo $state; ?>][name]" value="<?php echo $vat_name; ?>" /></td>
357 357
             <td class="wpinv_vat_group">
358 358
             <?php
359
-            echo wpinv_html_select( array(
359
+            echo wpinv_html_select(array(
360 360
                                         'name'             => 'vat_rates[' . $state . '][group]',
361 361
                                         'selected'         => $vat_group,
362 362
                                         'id'               => 'vat_rates[' . $state . '][group]',
@@ -366,14 +366,14 @@  discard block
 block discarded – undo
366 366
                                         'chosen'           => false,
367 367
                                         'show_option_all'  => false,
368 368
                                         'show_option_none' => false
369
-                                    ) );
369
+                                    ));
370 370
             ?>
371 371
             </td>
372 372
         </tr>
373 373
         <?php } ?>
374 374
         <tr>
375 375
             <td colspan="6" style="background-color:#fafafa;">
376
-                <span><input id="wpi_vat_get_rates_group" type="button" class="button-secondary" value="<?php esc_attr_e( 'Update EU VAT Rates', 'invoicing' ); ?>" />&nbsp;&nbsp;<i style="display:none" class="fa fa-refresh fa-spin"></i></span><span id="wpinv-rates-error-wrap" class="wpinv_errors" style="display:none;"></span>
376
+                <span><input id="wpi_vat_get_rates_group" type="button" class="button-secondary" value="<?php esc_attr_e('Update EU VAT Rates', 'invoicing'); ?>" />&nbsp;&nbsp;<i style="display:none" class="fa fa-refresh fa-spin"></i></span><span id="wpinv-rates-error-wrap" class="wpinv_errors" style="display:none;"></span>
377 377
             </td>
378 378
         </tr>
379 379
         <?php } ?>
@@ -385,35 +385,35 @@  discard block
 block discarded – undo
385 385
     echo $content;
386 386
 }
387 387
 
388
-function wpinv_vat_number_callback( $args ) {
388
+function wpinv_vat_number_callback($args) {
389 389
     global $wpinv_euvat;
390 390
     
391 391
     $vat_number     = $wpinv_euvat->get_vat_number();
392 392
     $vat_valid      = $wpinv_euvat->is_vat_validated();
393 393
 
394
-    $size           = ( isset( $args['size'] ) && !is_null( $args['size'] ) ) ? $args['size'] : 'regular';
395
-    $validated_text = $vat_valid ? __( 'VAT number validated', 'invoicing' ) : __( 'VAT number not validated', 'invoicing' );
394
+    $size           = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular';
395
+    $validated_text = $vat_valid ? __('VAT number validated', 'invoicing') : __('VAT number not validated', 'invoicing');
396 396
     $disabled       = $vat_valid ? 'disabled="disabled"' : " ";
397 397
     
398
-    $html = '<input type="text" class="' . $size . '-text" id="wpinv_settings[' . $args['id'] . ']" name="wpinv_settings[' . $args['id'] . ']" placeholder="GB123456789" value="' . esc_attr( stripslashes( $vat_number ) ) . '"/>';
399
-    $html .= '<span>&nbsp;<input type="button" id="wpinv_vat_validate" class="wpinv_validate_vat_button button-secondary" ' . $disabled . ' value="' . esc_attr__( 'Validate VAT Number', 'invoicing' ) . '" /></span>';
398
+    $html = '<input type="text" class="' . $size . '-text" id="wpinv_settings[' . $args['id'] . ']" name="wpinv_settings[' . $args['id'] . ']" placeholder="GB123456789" value="' . esc_attr(stripslashes($vat_number)) . '"/>';
399
+    $html .= '<span>&nbsp;<input type="button" id="wpinv_vat_validate" class="wpinv_validate_vat_button button-secondary" ' . $disabled . ' value="' . esc_attr__('Validate VAT Number', 'invoicing') . '" /></span>';
400 400
     $html .= '<span class="wpinv-vat-stat wpinv-vat-stat-' . (int)$vat_valid . '"><i class="fa"></i> <font>' . $validated_text . '</font></span>';
401
-    $html .= '<label for="wpinv_settings[' . $args['id'] . ']">' . '<p>' . __( 'Enter your VAT number including country identifier, eg: GB123456789 (Settings must be saved after validation)', 'invoicing' ).'</p>' . '</label>';
402
-    $html .= '<input type="hidden" name="_wpi_nonce" value="' . wp_create_nonce( 'vat_validation' ) . '">';
401
+    $html .= '<label for="wpinv_settings[' . $args['id'] . ']">' . '<p>' . __('Enter your VAT number including country identifier, eg: GB123456789 (Settings must be saved after validation)', 'invoicing') . '</p>' . '</label>';
402
+    $html .= '<input type="hidden" name="_wpi_nonce" value="' . wp_create_nonce('vat_validation') . '">';
403 403
 
404 404
     echo $html;
405 405
 }
406 406
 
407
-function wpinv_eu_fallback_rate_callback( $args ) {
407
+function wpinv_eu_fallback_rate_callback($args) {
408 408
     global $wpinv_options;
409 409
 
410
-    $value = isset( $wpinv_options[$args['id']] ) ? $wpinv_options[ $args['id'] ] : ( isset( $args['std'] ) ? $args['std'] : '' );
411
-    $size = ( isset( $args['size'] ) && !is_null( $args['size'] ) ) ? $args['size'] : 'small';
410
+    $value = isset($wpinv_options[$args['id']]) ? $wpinv_options[$args['id']] : (isset($args['std']) ? $args['std'] : '');
411
+    $size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'small';
412 412
     
413
-    $html = '<input type="number" min="0", max="99.99" step="0.10" class="' . $size . '-text" id="wpinv_settings_' . $args['section'] . '_' . $args['id'] . '" name="wpinv_settings[' . $args['id'] . ']" value="' . esc_attr( stripslashes( $value ) ) . '" />';
414
-    $html .= '<span>&nbsp;<input id="wpi_add_eu_states" type="button" class="button-secondary" value="' . esc_attr__( 'Add EU Member States', 'invoicing' ) . '" /></span>';
415
-    $html .= '<span>&nbsp;<input id="wpi_remove_eu_states" type="button" class="button-secondary" value="' . esc_attr__( 'Remove EU Member States', 'invoicing' ) . '" /></span>';
416
-    $html .= '<span>&nbsp;<input id="wpi_vat_get_rates" type="button" class="button-secondary" value="' . esc_attr__( 'Update EU VAT Rates', 'invoicing' ) . '" />&nbsp;&nbsp;<i style="display:none" class="fa fa-refresh fa-spin"></i></span>';
413
+    $html = '<input type="number" min="0", max="99.99" step="0.10" class="' . $size . '-text" id="wpinv_settings_' . $args['section'] . '_' . $args['id'] . '" name="wpinv_settings[' . $args['id'] . ']" value="' . esc_attr(stripslashes($value)) . '" />';
414
+    $html .= '<span>&nbsp;<input id="wpi_add_eu_states" type="button" class="button-secondary" value="' . esc_attr__('Add EU Member States', 'invoicing') . '" /></span>';
415
+    $html .= '<span>&nbsp;<input id="wpi_remove_eu_states" type="button" class="button-secondary" value="' . esc_attr__('Remove EU Member States', 'invoicing') . '" /></span>';
416
+    $html .= '<span>&nbsp;<input id="wpi_vat_get_rates" type="button" class="button-secondary" value="' . esc_attr__('Update EU VAT Rates', 'invoicing') . '" />&nbsp;&nbsp;<i style="display:none" class="fa fa-refresh fa-spin"></i></span>';
417 417
     $html .= '<p><label for="wpinv_settings_' . $args['section'] . '_' . $args['id'] . '">' . $args['desc'] . '</label></p>';
418 418
     echo $html;
419 419
     ?>
@@ -421,36 +421,36 @@  discard block
 block discarded – undo
421 421
     <?php
422 422
 }
423 423
 
424
-function wpinv_vat_ip_lookup_callback( $args ) {
424
+function wpinv_vat_ip_lookup_callback($args) {
425 425
     global $wpinv_options, $wpinv_euvat;
426 426
 
427
-    $value =  isset( $wpinv_options[ $args['id'] ] ) ? $wpinv_options[ $args['id'] ]  : ( isset( $args['std'] ) ? $args['std'] : 'default' );
427
+    $value = isset($wpinv_options[$args['id']]) ? $wpinv_options[$args['id']] : (isset($args['std']) ? $args['std'] : 'default');
428 428
     
429 429
     $options = array();
430
-    if ( function_exists( 'geoip_country_code_by_name' ) ) {
431
-        $options['geoip'] = __( 'PHP GeoIP extension', 'invoicing' );
430
+    if (function_exists('geoip_country_code_by_name')) {
431
+        $options['geoip'] = __('PHP GeoIP extension', 'invoicing');
432 432
     }
433 433
     
434 434
     $geoip2_database = $wpinv_euvat->geoip2_country_dbfile();
435 435
     
436
-    if ( !function_exists( 'bcadd' ) ) {
437
-        $geoip2_message = __( 'GeoIP2 service requires the BC Math PHP extension, it is not loaded in your version of PHP!', 'invoicing' );
436
+    if (!function_exists('bcadd')) {
437
+        $geoip2_message = __('GeoIP2 service requires the BC Math PHP extension, it is not loaded in your version of PHP!', 'invoicing');
438 438
     } else {
439
-        $geoip2_message = ini_get('safe_mode') ? __( 'GeoIP2 is not supported with PHP safe mode enabled!', 'invoicing' ) : '';
439
+        $geoip2_message = ini_get('safe_mode') ? __('GeoIP2 is not supported with PHP safe mode enabled!', 'invoicing') : '';
440 440
     }
441 441
     
442
-    if ( $geoip2_database !== false && empty( $geoip2_message ) ) {
443
-        $options['geoip2'] = __( 'GeoIP2 Database', 'invoicing' );
442
+    if ($geoip2_database !== false && empty($geoip2_message)) {
443
+        $options['geoip2'] = __('GeoIP2 Database', 'invoicing');
444 444
     }
445 445
     
446
-    if ( function_exists( 'simplexml_load_file' ) ) {
447
-        $options['geoplugin'] = __( 'geoPlugin Web Service', 'invoicing' );
446
+    if (function_exists('simplexml_load_file')) {
447
+        $options['geoplugin'] = __('geoPlugin Web Service', 'invoicing');
448 448
     }
449 449
     
450
-    $options['site']    = __( 'Use default country', 'invoicing' );
451
-    $options['default'] = __( 'Auto', 'invoicing' );
450
+    $options['site']    = __('Use default country', 'invoicing');
451
+    $options['default'] = __('Auto', 'invoicing');
452 452
 
453
-    $html = wpinv_html_select( array(
453
+    $html = wpinv_html_select(array(
454 454
         'name'             => "wpinv_settings[{$args['id']}]",
455 455
         'selected'         => $value,
456 456
         'id'               => "wpinv_settings[{$args['id']}]",
@@ -463,23 +463,23 @@  discard block
 block discarded – undo
463 463
     ));
464 464
     
465 465
     $desc = '<label for="wpinv_settings[' . $args['id'] . ']">';
466
-    $desc .= __( 'Select the option Invoicing should use to determine the country from the IP address of the user.', 'invoicing' );
466
+    $desc .= __('Select the option Invoicing should use to determine the country from the IP address of the user.', 'invoicing');
467 467
     $desc .= '<p>';
468
-    if ( empty( $geoip2_message ) ) {
469
-        if ( $geoip2_database ) {
468
+    if (empty($geoip2_message)) {
469
+        if ($geoip2_database) {
470 470
             $last_updated = '';
471
-            if ( $time_updated = wpinv_get_option( 'wpinv_geoip2_date_updated' ) ) {
472
-                $date_updated = date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), $time_updated );
473
-                $last_updated = '<br>' . sprintf( __( 'The GeoIP2 database was last updated on: <b>%s</b>', 'invoicing' ), $date_updated );
471
+            if ($time_updated = wpinv_get_option('wpinv_geoip2_date_updated')) {
472
+                $date_updated = date_i18n(get_option('date_format') . ' ' . get_option('time_format'), $time_updated);
473
+                $last_updated = '<br>' . sprintf(__('The GeoIP2 database was last updated on: <b>%s</b>', 'invoicing'), $date_updated);
474 474
             }
475
-            $desc .= __(  'GeoIP2 database exists:', 'invoicing' ) . $last_updated . '&nbsp;<input type="button" id="wpi_geoip2" action="update" class="wpinv-refresh-geoip2-btn button-secondary" value="' . __( 'Update GeoIP2 database now (~55MB)', 'invoicing' ) . '"></input>';
475
+            $desc .= __('GeoIP2 database exists:', 'invoicing') . $last_updated . '&nbsp;<input type="button" id="wpi_geoip2" action="update" class="wpinv-refresh-geoip2-btn button-secondary" value="' . __('Update GeoIP2 database now (~55MB)', 'invoicing') . '"></input>';
476 476
         } else {
477
-            $desc .= __( 'GeoIP2 database does not exist:', 'invoicing' ) . '&nbsp;<input type="button" id="wpi_geoip2" action="download" class="wpinv-download-geoip2-btn button-secondary" value="' . __( 'Download GeoIP2 database now', 'invoicing' ) . ' (~53MB)"></input><br>' . __(  'After downloading the GeoIP2 database the GeoIP2 lookup option will show.', 'invoicing' );
477
+            $desc .= __('GeoIP2 database does not exist:', 'invoicing') . '&nbsp;<input type="button" id="wpi_geoip2" action="download" class="wpinv-download-geoip2-btn button-secondary" value="' . __('Download GeoIP2 database now', 'invoicing') . ' (~53MB)"></input><br>' . __('After downloading the GeoIP2 database the GeoIP2 lookup option will show.', 'invoicing');
478 478
         }
479 479
     } else {
480 480
         $desc .= $geoip2_message;
481 481
     }
482
-    $desc .= '</p><p>'. __( 'GeoPlugin is a great free service please consider supporting them: ', 'invoicing' ) . ' <a href="http://www.geoplugin.com/" target="_blank">GeoPlugin.com</a></p>';
482
+    $desc .= '</p><p>' . __('GeoPlugin is a great free service please consider supporting them: ', 'invoicing') . ' <a href="http://www.geoplugin.com/" target="_blank">GeoPlugin.com</a></p>';
483 483
     $desc .= '</label>';
484 484
     
485 485
     $html .= $desc;
Please login to merge, or discard this patch.
includes/wpinv-user-functions.php 1 patch
Spacing   +62 added lines, -62 removed lines patch added patch discarded remove patch
@@ -1,28 +1,28 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // Exit if accessed directly
3
-if ( ! defined( 'ABSPATH' ) ) exit;
3
+if (!defined('ABSPATH')) exit;
4 4
 
5
-function wpinv_user_invoices( $current_page = 1 ) {    
5
+function wpinv_user_invoices($current_page = 1) {    
6 6
     global $current_page;
7
-    wpinv_get_template_part( 'wpinv-invoice-history' );
7
+    wpinv_get_template_part('wpinv-invoice-history');
8 8
 }
9 9
 
10
-function wpinv_get_users_invoices( $user = 0, $number = 20, $pagination = false, $status = 'complete' ) {
11
-    if ( empty( $user ) ) {
10
+function wpinv_get_users_invoices($user = 0, $number = 20, $pagination = false, $status = 'complete') {
11
+    if (empty($user)) {
12 12
         $user = get_current_user_id();
13 13
     }
14 14
 
15
-    if ( 0 === $user ) {
15
+    if (0 === $user) {
16 16
         return false;
17 17
     }
18 18
 
19 19
     $status = $status === 'complete' ? 'publish' : $status;
20 20
 
21
-    if ( $pagination ) {
22
-        if ( get_query_var( 'paged' ) )
21
+    if ($pagination) {
22
+        if (get_query_var('paged'))
23 23
             $paged = get_query_var('paged');
24
-        else if ( get_query_var( 'page' ) )
25
-            $paged = get_query_var( 'page' );
24
+        else if (get_query_var('page'))
25
+            $paged = get_query_var('page');
26 26
         else
27 27
             $paged = 1;
28 28
     }
@@ -31,21 +31,21 @@  discard block
 block discarded – undo
31 31
         'post_type'      => 'wpi_invoice',
32 32
         'posts_per_page' => 20,
33 33
         'paged'          => null,
34
-        'post_status'    => array( 'complete', 'publish', 'pending' ),
34
+        'post_status'    => array('complete', 'publish', 'pending'),
35 35
         'user'           => $user,
36 36
         'order'          => 'date',
37 37
     );
38 38
 
39
-    $invoices = get_posts( $args );
39
+    $invoices = get_posts($args);
40 40
 
41 41
     // No invoices
42
-    if ( ! $invoices )
42
+    if (!$invoices)
43 43
         return false;
44 44
 
45 45
     return $invoices;
46 46
 }
47 47
 
48
-function wpinv_dropdown_users( $args = '' ) {
48
+function wpinv_dropdown_users($args = '') {
49 49
     $defaults = array(
50 50
         'show_option_all' => '', 'show_option_none' => '', 'hide_if_only_one_author' => '',
51 51
         'orderby' => 'display_name', 'order' => 'ASC',
@@ -56,18 +56,18 @@  discard block
 block discarded – undo
56 56
         'option_none_value' => -1
57 57
     );
58 58
 
59
-    $defaults['selected'] = is_author() ? get_query_var( 'author' ) : 0;
59
+    $defaults['selected'] = is_author() ? get_query_var('author') : 0;
60 60
 
61
-    $r = wp_parse_args( $args, $defaults );
61
+    $r = wp_parse_args($args, $defaults);
62 62
 
63
-    $query_args = wp_array_slice_assoc( $r, array( 'blog_id', 'include', 'exclude', 'orderby', 'order', 'who' ) );
63
+    $query_args = wp_array_slice_assoc($r, array('blog_id', 'include', 'exclude', 'orderby', 'order', 'who'));
64 64
 
65
-    $fields = array( 'ID', 'user_login', 'user_email' );
65
+    $fields = array('ID', 'user_login', 'user_email');
66 66
 
67
-    $show = ! empty( $r['show'] ) ? $r['show'] : 'display_name';
68
-    if ( 'display_name_with_login' === $show ) {
67
+    $show = !empty($r['show']) ? $r['show'] : 'display_name';
68
+    if ('display_name_with_login' === $show) {
69 69
         $fields[] = 'display_name';
70
-    } else if ( 'display_name_with_email' === $show ) {
70
+    } else if ('display_name_with_email' === $show) {
71 71
         $fields[] = 'display_name';
72 72
     } else {
73 73
         $fields[] = $show;
@@ -79,99 +79,99 @@  discard block
 block discarded – undo
79 79
     $show_option_none = $r['show_option_none'];
80 80
     $option_none_value = $r['option_none_value'];
81 81
 
82
-    $query_args = apply_filters( 'wpinv_dropdown_users_args', $query_args, $r );
82
+    $query_args = apply_filters('wpinv_dropdown_users_args', $query_args, $r);
83 83
 
84
-    $users = get_users( $query_args );
84
+    $users = get_users($query_args);
85 85
 
86 86
     $output = '';
87
-    if ( ! empty( $users ) && ( empty( $r['hide_if_only_one_author'] ) || count( $users ) > 1 ) ) {
88
-        $name = esc_attr( $r['name'] );
89
-        if ( $r['multi'] && ! $r['id'] ) {
87
+    if (!empty($users) && (empty($r['hide_if_only_one_author']) || count($users) > 1)) {
88
+        $name = esc_attr($r['name']);
89
+        if ($r['multi'] && !$r['id']) {
90 90
             $id = '';
91 91
         } else {
92
-            $id = $r['id'] ? " id='" . esc_attr( $r['id'] ) . "'" : " id='$name'";
92
+            $id = $r['id'] ? " id='" . esc_attr($r['id']) . "'" : " id='$name'";
93 93
         }
94 94
         $output = "<select name='{$name}'{$id} class='" . $r['class'] . "'>\n";
95 95
 
96
-        if ( $show_option_all ) {
96
+        if ($show_option_all) {
97 97
             $output .= "\t<option value='0'>$show_option_all</option>\n";
98 98
         }
99 99
 
100
-        if ( $show_option_none ) {
101
-            $_selected = selected( $option_none_value, $r['selected'], false );
102
-            $output .= "\t<option value='" . esc_attr( $option_none_value ) . "'$_selected>$show_option_none</option>\n";
100
+        if ($show_option_none) {
101
+            $_selected = selected($option_none_value, $r['selected'], false);
102
+            $output .= "\t<option value='" . esc_attr($option_none_value) . "'$_selected>$show_option_none</option>\n";
103 103
         }
104 104
 
105
-        if ( $r['include_selected'] && ( $r['selected'] > 0 ) ) {
105
+        if ($r['include_selected'] && ($r['selected'] > 0)) {
106 106
             $found_selected = false;
107
-            $r['selected'] = (int) $r['selected'];
108
-            foreach ( (array) $users as $user ) {
109
-                $user->ID = (int) $user->ID;
110
-                if ( $user->ID === $r['selected'] ) {
107
+            $r['selected'] = (int)$r['selected'];
108
+            foreach ((array)$users as $user) {
109
+                $user->ID = (int)$user->ID;
110
+                if ($user->ID === $r['selected']) {
111 111
                     $found_selected = true;
112 112
                 }
113 113
             }
114 114
 
115
-            if ( ! $found_selected ) {
116
-                $users[] = get_userdata( $r['selected'] );
115
+            if (!$found_selected) {
116
+                $users[] = get_userdata($r['selected']);
117 117
             }
118 118
         }
119 119
 
120
-        foreach ( (array) $users as $user ) {
121
-            if ( 'display_name_with_login' === $show ) {
120
+        foreach ((array)$users as $user) {
121
+            if ('display_name_with_login' === $show) {
122 122
                 /* translators: 1: display name, 2: user_login */
123
-                $display = sprintf( _x( '%1$s (%2$s)', 'user dropdown' ), $user->display_name, $user->user_login );
124
-            } elseif ( 'display_name_with_email' === $show ) {
123
+                $display = sprintf(_x('%1$s (%2$s)', 'user dropdown'), $user->display_name, $user->user_login);
124
+            } elseif ('display_name_with_email' === $show) {
125 125
                 /* translators: 1: display name, 2: user_email */
126
-                if ( $user->display_name == $user->user_email ) {
126
+                if ($user->display_name == $user->user_email) {
127 127
                     $display = $user->display_name;
128 128
                 } else {
129
-                    $display = sprintf( _x( '%1$s (%2$s)', 'user dropdown' ), $user->display_name, $user->user_email );
129
+                    $display = sprintf(_x('%1$s (%2$s)', 'user dropdown'), $user->display_name, $user->user_email);
130 130
                 }
131
-            } elseif ( ! empty( $user->$show ) ) {
131
+            } elseif (!empty($user->$show)) {
132 132
                 $display = $user->$show;
133 133
             } else {
134 134
                 $display = '(' . $user->user_login . ')';
135 135
             }
136 136
 
137
-            $_selected = selected( $user->ID, $r['selected'], false );
138
-            $output .= "\t<option value='$user->ID'$_selected>" . esc_html( $display ) . "</option>\n";
137
+            $_selected = selected($user->ID, $r['selected'], false);
138
+            $output .= "\t<option value='$user->ID'$_selected>" . esc_html($display) . "</option>\n";
139 139
         }
140 140
 
141 141
         $output .= "</select>";
142 142
     }
143 143
 
144
-    $html = apply_filters( 'wpinv_dropdown_users', $output );
144
+    $html = apply_filters('wpinv_dropdown_users', $output);
145 145
 
146
-    if ( $r['echo'] ) {
146
+    if ($r['echo']) {
147 147
         echo $html;
148 148
     }
149 149
     return $html;
150 150
 }
151 151
 
152
-function wpinv_guest_redirect( $redirect_to, $user_id = 0 ) {
153
-    if ( (int)wpinv_get_option( 'guest_checkout' ) && $user_id > 0 ) {
154
-        wpinv_login_user( $user_id );
152
+function wpinv_guest_redirect($redirect_to, $user_id = 0) {
153
+    if ((int)wpinv_get_option('guest_checkout') && $user_id > 0) {
154
+        wpinv_login_user($user_id);
155 155
     } else {
156
-        $redirect_to = wp_login_url( $redirect_to );
156
+        $redirect_to = wp_login_url($redirect_to);
157 157
     }
158 158
     
159
-    $redirect_to = apply_filters( 'wpinv_invoice_link_guest_redirect', $redirect_to, $user_id );
159
+    $redirect_to = apply_filters('wpinv_invoice_link_guest_redirect', $redirect_to, $user_id);
160 160
     
161
-    wp_redirect( $redirect_to );
161
+    wp_redirect($redirect_to);
162 162
 }
163 163
 
164
-function wpinv_login_user( $user_id ) {
165
-    if ( is_user_logged_in() ) {
164
+function wpinv_login_user($user_id) {
165
+    if (is_user_logged_in()) {
166 166
         return true;
167 167
     }
168 168
     
169
-    $user = get_user_by( 'id', $user_id );
169
+    $user = get_user_by('id', $user_id);
170 170
     
171
-    if ( !empty( $user ) && !is_wp_error( $user ) && !empty( $user->user_login ) ) {
172
-        wp_set_current_user( $user_id, $user->user_login );
173
-        wp_set_auth_cookie( $user_id );
174
-        do_action( 'wp_login', $user->user_login );
171
+    if (!empty($user) && !is_wp_error($user) && !empty($user->user_login)) {
172
+        wp_set_current_user($user_id, $user->user_login);
173
+        wp_set_auth_cookie($user_id);
174
+        do_action('wp_login', $user->user_login);
175 175
         
176 176
         return true;
177 177
     }
Please login to merge, or discard this patch.
includes/wpinv-payment-functions.php 1 patch
Spacing   +160 added lines, -160 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2
-function wpinv_get_subscriptions( $args = array() ) {
3
-    if ( empty( $args['parent_invoice_id'] ) ) {
2
+function wpinv_get_subscriptions($args = array()) {
3
+    if (empty($args['parent_invoice_id'])) {
4 4
         return false;
5 5
     }
6 6
     
@@ -14,18 +14,18 @@  discard block
 block discarded – undo
14 14
     );
15 15
 
16 16
     $args['post_parent']    = $args['parent_invoice_id'];
17
-    $args                   = wp_parse_args( $args, $defaults );
17
+    $args                   = wp_parse_args($args, $defaults);
18 18
 
19
-    if( $args['numberposts'] < 1 ) {
19
+    if ($args['numberposts'] < 1) {
20 20
         $args['numberposts'] = 999999999999;
21 21
     }
22 22
 
23
-    $posts          = get_posts( $args );
23
+    $posts          = get_posts($args);
24 24
     $subscriptions  = array();
25
-    if ( !empty( $posts ) ) {
26
-        foreach ( $posts as $post ) {
27
-            if ( !empty( $post->ID ) ) {
28
-                $subscriptions[] = wpinv_get_invoice( $post->ID );
25
+    if (!empty($posts)) {
26
+        foreach ($posts as $post) {
27
+            if (!empty($post->ID)) {
28
+                $subscriptions[] = wpinv_get_invoice($post->ID);
29 29
             }
30 30
         }
31 31
     }
@@ -33,19 +33,19 @@  discard block
 block discarded – undo
33 33
     
34 34
     return $subscriptions;
35 35
 }
36
-function wpinv_get_subscription( $id = 0, $by_profile_id = false ) {
36
+function wpinv_get_subscription($id = 0, $by_profile_id = false) {
37 37
     global $wpdb;
38 38
 
39
-    if ( empty( $id ) ) {
39
+    if (empty($id)) {
40 40
         return false;
41 41
     }
42 42
 
43
-    $id = esc_sql( $id );
43
+    $id = esc_sql($id);
44 44
 
45
-    $invoice_id = $wpdb->get_var( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_profile_id' AND meta_value = '{$id}' LIMIT 1" );
45
+    $invoice_id = $wpdb->get_var("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_profile_id' AND meta_value = '{$id}' LIMIT 1");
46 46
 
47
-    if ( $invoice_id != null ) {
48
-        return wpinv_get_invoice( $invoice_id );
47
+    if ($invoice_id != null) {
48
+        return wpinv_get_invoice($invoice_id);
49 49
     }
50 50
 
51 51
     return false;
@@ -55,49 +55,49 @@  discard block
 block discarded – undo
55 55
  * Records a new payment on the subscription
56 56
  * 
57 57
  */
58
-function wpinv_recurring_add_subscription_payment( $parent_invoice_id, $subscription_args = array() ) {    
59
-    $args = wp_parse_args( $subscription_args, array(
58
+function wpinv_recurring_add_subscription_payment($parent_invoice_id, $subscription_args = array()) {    
59
+    $args = wp_parse_args($subscription_args, array(
60 60
         'amount'         => '',
61 61
         'transaction_id' => '',
62 62
         'gateway'        => ''
63
-    ) );
63
+    ));
64 64
 
65
-    if ( wpinv_payment_exists( $args['transaction_id'] ) ) {
65
+    if (wpinv_payment_exists($args['transaction_id'])) {
66 66
         return false;
67 67
     }
68 68
     
69
-    $parent_invoice = wpinv_get_invoice( $parent_invoice_id );
70
-    if ( empty( $parent_invoice ) ) {
69
+    $parent_invoice = wpinv_get_invoice($parent_invoice_id);
70
+    if (empty($parent_invoice)) {
71 71
         return;
72 72
     }
73 73
 
74 74
     $invoice = new WPInv_Invoice();
75
-    $invoice->set( 'parent_invoice', $parent_invoice_id );
76
-    $invoice->set( 'currency', $parent_invoice->get_currency() );
75
+    $invoice->set('parent_invoice', $parent_invoice_id);
76
+    $invoice->set('currency', $parent_invoice->get_currency());
77 77
     //$invoice->set( 'status', 'publish' );
78
-    $invoice->set( 'transaction_id', $args['transaction_id'] );
79
-    $invoice->set( 'key', $parent_invoice->get_key() );
78
+    $invoice->set('transaction_id', $args['transaction_id']);
79
+    $invoice->set('key', $parent_invoice->get_key());
80 80
     
81
-    $invoice->set( 'ip', $parent_invoice->ip );
82
-    $invoice->set( 'user_id', $parent_invoice->get_user_id() );
83
-    $invoice->set( 'first_name', $parent_invoice->get_first_name() );
84
-    $invoice->set( 'last_name', $parent_invoice->get_last_name() );
81
+    $invoice->set('ip', $parent_invoice->ip);
82
+    $invoice->set('user_id', $parent_invoice->get_user_id());
83
+    $invoice->set('first_name', $parent_invoice->get_first_name());
84
+    $invoice->set('last_name', $parent_invoice->get_last_name());
85 85
     ///$invoice->set( 'email', $parent_invoice->get_email() );
86
-    $invoice->set( 'phone', $parent_invoice->phone );
87
-    $invoice->set( 'address', $parent_invoice->address );
88
-    $invoice->set( 'city', $parent_invoice->city );
89
-    $invoice->set( 'country', $parent_invoice->country );
90
-    $invoice->set( 'state', $parent_invoice->state );
91
-    $invoice->set( 'zip', $parent_invoice->zip );
92
-    $invoice->set( 'company', $parent_invoice->company );
93
-    $invoice->set( 'vat_number', $parent_invoice->vat_number );
94
-    $invoice->set( 'vat_rate', $parent_invoice->vat_rate );
95
-    $invoice->set( 'adddress_confirmed', $parent_invoice->adddress_confirmed );
96
-
97
-    if ( empty( $args['gateway'] ) ) {
98
-        $invoice->set( 'gateway', $parent_invoice->get_gateway() );
86
+    $invoice->set('phone', $parent_invoice->phone);
87
+    $invoice->set('address', $parent_invoice->address);
88
+    $invoice->set('city', $parent_invoice->city);
89
+    $invoice->set('country', $parent_invoice->country);
90
+    $invoice->set('state', $parent_invoice->state);
91
+    $invoice->set('zip', $parent_invoice->zip);
92
+    $invoice->set('company', $parent_invoice->company);
93
+    $invoice->set('vat_number', $parent_invoice->vat_number);
94
+    $invoice->set('vat_rate', $parent_invoice->vat_rate);
95
+    $invoice->set('adddress_confirmed', $parent_invoice->adddress_confirmed);
96
+
97
+    if (empty($args['gateway'])) {
98
+        $invoice->set('gateway', $parent_invoice->get_gateway());
99 99
     } else {
100
-        $invoice->set( 'gateway', $args['gateway'] );
100
+        $invoice->set('gateway', $args['gateway']);
101 101
     }
102 102
     
103 103
     $recurring_details = $parent_invoice->get_recurring_details();
@@ -105,11 +105,11 @@  discard block
 block discarded – undo
105 105
     // increase the earnings for each item in the subscription
106 106
     $items = $recurring_details['cart_details'];
107 107
     
108
-    if ( $items ) {        
108
+    if ($items) {        
109 109
         $add_items      = array();
110 110
         $cart_details   = array();
111 111
         
112
-        foreach ( $items as $item ) {
112
+        foreach ($items as $item) {
113 113
             $add_item             = array();
114 114
             $add_item['id']       = $item['id'];
115 115
             $add_item['quantity'] = $item['quantity'];
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
             break;
120 120
         }
121 121
         
122
-        $invoice->set( 'items', $add_items );
122
+        $invoice->set('items', $add_items);
123 123
         $invoice->cart_details = $cart_details;
124 124
     }
125 125
     
@@ -129,277 +129,277 @@  discard block
 block discarded – undo
129 129
     $tax                = $recurring_details['tax'];
130 130
     $discount           = $recurring_details['discount'];
131 131
     
132
-    if ( $discount > 0 ) {
133
-        $invoice->set( 'discount_code', $parent_invoice->discount_code );
132
+    if ($discount > 0) {
133
+        $invoice->set('discount_code', $parent_invoice->discount_code);
134 134
     }
135 135
     
136
-    $invoice->subtotal = wpinv_format_amount( $subtotal, NULL, true );
137
-    $invoice->tax      = wpinv_format_amount( $tax, NULL, true );
138
-    $invoice->discount = wpinv_format_amount( $discount, NULL, true );
139
-    $invoice->total    = wpinv_format_amount( $total, NULL, true );
136
+    $invoice->subtotal = wpinv_format_amount($subtotal, NULL, true);
137
+    $invoice->tax      = wpinv_format_amount($tax, NULL, true);
138
+    $invoice->discount = wpinv_format_amount($discount, NULL, true);
139
+    $invoice->total    = wpinv_format_amount($total, NULL, true);
140 140
     $invoice->save();
141 141
     
142
-    wpinv_update_payment_status( $invoice->ID, 'publish' );
142
+    wpinv_update_payment_status($invoice->ID, 'publish');
143 143
     sleep(1);
144
-    wpinv_update_payment_status( $invoice->ID, 'renewal' );
144
+    wpinv_update_payment_status($invoice->ID, 'renewal');
145 145
     
146
-    $invoice = wpinv_get_invoice( $invoice->ID );
146
+    $invoice = wpinv_get_invoice($invoice->ID);
147 147
     
148
-    $subscription_data                      = wpinv_payment_subscription_data( $parent_invoice );
148
+    $subscription_data                      = wpinv_payment_subscription_data($parent_invoice);
149 149
     $subscription_data['recurring_amount']  = $invoice->get_total();
150
-    $subscription_data['created']           = current_time( 'mysql', 0 );
151
-    $subscription_data['expiration']        = $invoice->get_new_expiration( $subscription_data['item_id'] );
150
+    $subscription_data['created']           = current_time('mysql', 0);
151
+    $subscription_data['expiration']        = $invoice->get_new_expiration($subscription_data['item_id']);
152 152
     
153 153
     // Retrieve pending subscription from database and update it's status to active and set proper profile ID
154
-    $invoice->update_subscription( $subscription_data );
154
+    $invoice->update_subscription($subscription_data);
155 155
 
156
-    do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $parent_invoice, $subscription_args );
157
-    do_action( 'wpinv_recurring_record_payment', $invoice->ID, $parent_invoice_id, $subscription_args );
156
+    do_action('wpinv_recurring_add_subscription_payment', $invoice, $parent_invoice, $subscription_args);
157
+    do_action('wpinv_recurring_record_payment', $invoice->ID, $parent_invoice_id, $subscription_args);
158 158
 
159 159
     return $invoice;
160 160
 }
161 161
 
162
-function wpinv_payment_exists( $txn_id = '' ) {
162
+function wpinv_payment_exists($txn_id = '') {
163 163
     global $wpdb;
164 164
 
165
-    if ( empty( $txn_id ) ) {
165
+    if (empty($txn_id)) {
166 166
         return false;
167 167
     }
168 168
 
169
-    $txn_id = esc_sql( $txn_id );
169
+    $txn_id = esc_sql($txn_id);
170 170
 
171
-    $invoice = $wpdb->get_var( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = '{$txn_id}' LIMIT 1" );
171
+    $invoice = $wpdb->get_var("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = '{$txn_id}' LIMIT 1");
172 172
 
173
-    if ( $invoice != null ) {
173
+    if ($invoice != null) {
174 174
         return true;
175 175
     }
176 176
 
177 177
     return false;
178 178
 }
179 179
 
180
-function wpinv_is_subscription_payment( $invoice = '' ) {
181
-    if ( empty( $invoice ) ) {
180
+function wpinv_is_subscription_payment($invoice = '') {
181
+    if (empty($invoice)) {
182 182
         return false;
183 183
     }
184 184
     
185
-    if ( !is_object( $invoice ) && is_scalar( $invoice ) ) {
186
-        $invoice = wpinv_get_invoice( $invoice );
185
+    if (!is_object($invoice) && is_scalar($invoice)) {
186
+        $invoice = wpinv_get_invoice($invoice);
187 187
     }
188 188
     
189
-    if ( empty( $invoice ) ) {
189
+    if (empty($invoice)) {
190 190
         return false;
191 191
     }
192 192
         
193
-    if ( $invoice->is_renewal() ) {
193
+    if ($invoice->is_renewal()) {
194 194
         return true;
195 195
     }
196 196
 
197 197
     return false;
198 198
 }
199 199
 
200
-function wpinv_payment_subscription_data( $invoice = '' ) {
201
-    if ( empty( $invoice ) ) {
200
+function wpinv_payment_subscription_data($invoice = '') {
201
+    if (empty($invoice)) {
202 202
         return false;
203 203
     }
204 204
     
205
-    if ( !is_object( $invoice ) && is_scalar( $invoice ) ) {
206
-        $invoice = wpinv_get_invoice( $invoice );
205
+    if (!is_object($invoice) && is_scalar($invoice)) {
206
+        $invoice = wpinv_get_invoice($invoice);
207 207
     }
208 208
     
209
-    if ( empty( $invoice ) ) {
209
+    if (empty($invoice)) {
210 210
         return false;
211 211
     }    
212 212
 
213 213
     return $invoice->get_subscription_data();
214 214
 }
215 215
 
216
-function wpinv_payment_link_transaction_id( $invoice = '' ) {
217
-    if ( empty( $invoice ) ) {
216
+function wpinv_payment_link_transaction_id($invoice = '') {
217
+    if (empty($invoice)) {
218 218
         return false;
219 219
     }
220 220
     
221
-    if ( !is_object( $invoice ) && is_scalar( $invoice ) ) {
222
-        $invoice = wpinv_get_invoice( $invoice );
221
+    if (!is_object($invoice) && is_scalar($invoice)) {
222
+        $invoice = wpinv_get_invoice($invoice);
223 223
     }
224 224
     
225
-    if ( empty( $invoice ) ) {
225
+    if (empty($invoice)) {
226 226
         return false;
227 227
     }
228 228
 
229
-    return apply_filters( 'wpinv_payment_details_transaction_id-' . $invoice->gateway, $invoice->get_transaction_id(), $invoice->ID, $invoice );
229
+    return apply_filters('wpinv_payment_details_transaction_id-' . $invoice->gateway, $invoice->get_transaction_id(), $invoice->ID, $invoice);
230 230
 }
231 231
 
232
-function wpinv_get_pretty_subscription_period( $period ) {
232
+function wpinv_get_pretty_subscription_period($period) {
233 233
     $frequency = '';
234 234
     //Format period details
235
-    switch ( $period ) {
235
+    switch ($period) {
236 236
         case 'D' :
237 237
         case 'day' :
238
-            $frequency = __( 'Daily', 'invoicing' );
238
+            $frequency = __('Daily', 'invoicing');
239 239
             break;
240 240
         case 'W' :
241 241
         case 'week' :
242
-            $frequency = __( 'Weekly', 'invoicing' );
242
+            $frequency = __('Weekly', 'invoicing');
243 243
             break;
244 244
         case 'M' :
245 245
         case 'month' :
246
-            $frequency = __( 'Monthly', 'invoicing' );
246
+            $frequency = __('Monthly', 'invoicing');
247 247
             break;
248 248
         case 'Y' :
249 249
         case 'year' :
250
-            $frequency = __( 'Yearly', 'invoicing' );
250
+            $frequency = __('Yearly', 'invoicing');
251 251
             break;
252 252
         default :
253
-            $frequency = apply_filters( 'wpinv_pretty_subscription_period', $frequency, $period );
253
+            $frequency = apply_filters('wpinv_pretty_subscription_period', $frequency, $period);
254 254
             break;
255 255
     }
256 256
 
257 257
     return $frequency;
258 258
 }
259 259
 
260
-function wpinv_get_pretty_subscription_period_name( $period ) {
260
+function wpinv_get_pretty_subscription_period_name($period) {
261 261
     $frequency = '';
262 262
     //Format period details
263
-    switch ( $period ) {
263
+    switch ($period) {
264 264
         case 'D' :
265 265
         case 'day' :
266
-            $frequency = __( 'Day', 'invoicing' );
266
+            $frequency = __('Day', 'invoicing');
267 267
             break;
268 268
         case 'W' :
269 269
         case 'week' :
270
-            $frequency = __( 'Week', 'invoicing' );
270
+            $frequency = __('Week', 'invoicing');
271 271
             break;
272 272
         case 'M' :
273 273
         case 'month' :
274
-            $frequency = __( 'Month', 'invoicing' );
274
+            $frequency = __('Month', 'invoicing');
275 275
             break;
276 276
         case 'Y' :
277 277
         case 'year' :
278
-            $frequency = __( 'Year', 'invoicing' );
278
+            $frequency = __('Year', 'invoicing');
279 279
             break;
280 280
         default :
281
-            $frequency = apply_filters( 'wpinv_pretty_subscription_period_name', $frequency, $period );
281
+            $frequency = apply_filters('wpinv_pretty_subscription_period_name', $frequency, $period);
282 282
             break;
283 283
     }
284 284
 
285 285
     return $frequency;
286 286
 }
287 287
 
288
-function wpinv_subscription_initial_payment_desc( $amount, $period, $interval, $trial_period = '', $trial_interval = 0 ) {
288
+function wpinv_subscription_initial_payment_desc($amount, $period, $interval, $trial_period = '', $trial_interval = 0) {
289 289
     $interval   = (int)$interval > 0 ? (int)$interval : 1;
290 290
     
291
-    if ( $trial_interval > 0 && !empty( $trial_period ) ) {
292
-        $amount = __( 'Free', 'invoicing' );
291
+    if ($trial_interval > 0 && !empty($trial_period)) {
292
+        $amount = __('Free', 'invoicing');
293 293
         $interval = $trial_interval;
294 294
         $period = $trial_period;
295 295
     }
296 296
     
297 297
     $description = '';
298
-    switch ( $period ) {
298
+    switch ($period) {
299 299
         case 'D' :
300 300
         case 'day' :
301
-            $description = wp_sprintf( _n( '%s for the first day.', '%s for the first %d days.', $interval, 'invoicing' ), $amount, $interval );
301
+            $description = wp_sprintf(_n('%s for the first day.', '%s for the first %d days.', $interval, 'invoicing'), $amount, $interval);
302 302
             break;
303 303
         case 'W' :
304 304
         case 'week' :
305
-            $description = wp_sprintf( _n( '%s for the first week.', '%s for the first %d weeks.', $interval, 'invoicing' ), $amount, $interval );
305
+            $description = wp_sprintf(_n('%s for the first week.', '%s for the first %d weeks.', $interval, 'invoicing'), $amount, $interval);
306 306
             break;
307 307
         case 'M' :
308 308
         case 'month' :
309
-            $description = wp_sprintf( _n( '%s for the first month.', '%s for the first %d months.', $interval, 'invoicing' ), $amount, $interval );
309
+            $description = wp_sprintf(_n('%s for the first month.', '%s for the first %d months.', $interval, 'invoicing'), $amount, $interval);
310 310
             break;
311 311
         case 'Y' :
312 312
         case 'year' :
313
-            $description = wp_sprintf( _n( '%s for the first year.', '%s for the first %d years.', $interval, 'invoicing' ), $amount, $interval );
313
+            $description = wp_sprintf(_n('%s for the first year.', '%s for the first %d years.', $interval, 'invoicing'), $amount, $interval);
314 314
             break;
315 315
     }
316 316
 
317
-    return apply_filters( 'wpinv_subscription_initial_payment_desc', $description, $amount, $period, $interval, $trial_period, $trial_interval  );
317
+    return apply_filters('wpinv_subscription_initial_payment_desc', $description, $amount, $period, $interval, $trial_period, $trial_interval);
318 318
 }
319 319
 
320
-function wpinv_subscription_recurring_payment_desc( $amount, $period, $interval, $bill_times = 0, $trial_period = '', $trial_interval = 0 ) {
320
+function wpinv_subscription_recurring_payment_desc($amount, $period, $interval, $bill_times = 0, $trial_period = '', $trial_interval = 0) {
321 321
     $interval   = (int)$interval > 0 ? (int)$interval : 1;
322 322
     $bill_times = (int)$bill_times > 0 ? (int)$bill_times : 0;
323 323
     
324 324
     $description = '';
325
-    switch ( $period ) {
325
+    switch ($period) {
326 326
         case 'D' :
327 327
         case 'day' :            
328
-            if ( (int)$bill_times > 0 ) {
329
-                if ( $interval > 1 ) {
330
-                    if ( $bill_times > 1 ) {
331
-                        $description = wp_sprintf( __( '%s for each %d days, for %d installments.', 'invoicing' ), $amount, $interval, $bill_times );
328
+            if ((int)$bill_times > 0) {
329
+                if ($interval > 1) {
330
+                    if ($bill_times > 1) {
331
+                        $description = wp_sprintf(__('%s for each %d days, for %d installments.', 'invoicing'), $amount, $interval, $bill_times);
332 332
                     } else {
333
-                        $description = wp_sprintf( __( '%s for %d days.', 'invoicing' ), $amount, $interval );
333
+                        $description = wp_sprintf(__('%s for %d days.', 'invoicing'), $amount, $interval);
334 334
                     }
335 335
                 } else {
336
-                    $description = wp_sprintf( _n( '%s for one day.', '%s for each day, for %d installments.', $bill_times, 'invoicing' ), $amount, $bill_times );
336
+                    $description = wp_sprintf(_n('%s for one day.', '%s for each day, for %d installments.', $bill_times, 'invoicing'), $amount, $bill_times);
337 337
                 }
338 338
             } else {
339
-                $description = wp_sprintf( _n( '%s for each day.', '%s for each %d days.', $interval, 'invoicing'), $amount, $interval );
339
+                $description = wp_sprintf(_n('%s for each day.', '%s for each %d days.', $interval, 'invoicing'), $amount, $interval);
340 340
             }
341 341
             break;
342 342
         case 'W' :
343 343
         case 'week' :            
344
-            if ( (int)$bill_times > 0 ) {
345
-                if ( $interval > 1 ) {
346
-                    if ( $bill_times > 1 ) {
347
-                        $description = wp_sprintf( __( '%s for each %d weeks, for %d installments.', 'invoicing' ), $amount, $interval, $bill_times );
344
+            if ((int)$bill_times > 0) {
345
+                if ($interval > 1) {
346
+                    if ($bill_times > 1) {
347
+                        $description = wp_sprintf(__('%s for each %d weeks, for %d installments.', 'invoicing'), $amount, $interval, $bill_times);
348 348
                     } else {
349
-                        $description = wp_sprintf( __( '%s for %d weeks.', 'invoicing' ), $amount, $interval );
349
+                        $description = wp_sprintf(__('%s for %d weeks.', 'invoicing'), $amount, $interval);
350 350
                     }
351 351
                 } else {
352
-                    $description = wp_sprintf( _n( '%s for one week.', '%s for each week, for %d installments.', $bill_times, 'invoicing' ), $amount, $bill_times );
352
+                    $description = wp_sprintf(_n('%s for one week.', '%s for each week, for %d installments.', $bill_times, 'invoicing'), $amount, $bill_times);
353 353
                 }
354 354
             } else {
355
-                $description = wp_sprintf( _n( '%s for each week.', '%s for each %d weeks.', $interval, 'invoicing' ), $amount, $interval );
355
+                $description = wp_sprintf(_n('%s for each week.', '%s for each %d weeks.', $interval, 'invoicing'), $amount, $interval);
356 356
             }
357 357
             break;
358 358
         case 'M' :
359 359
         case 'month' :            
360
-            if ( (int)$bill_times > 0 ) {
361
-                if ( $interval > 1 ) {
362
-                    if ( $bill_times > 1 ) {
363
-                        $description = wp_sprintf( __( '%s for each %d months, for %d installments.', 'invoicing' ), $amount, $interval, $bill_times );
360
+            if ((int)$bill_times > 0) {
361
+                if ($interval > 1) {
362
+                    if ($bill_times > 1) {
363
+                        $description = wp_sprintf(__('%s for each %d months, for %d installments.', 'invoicing'), $amount, $interval, $bill_times);
364 364
                     } else {
365
-                        $description = wp_sprintf( __( '%s for %d months.', 'invoicing' ), $amount, $interval );
365
+                        $description = wp_sprintf(__('%s for %d months.', 'invoicing'), $amount, $interval);
366 366
                     }
367 367
                 } else {
368
-                    $description = wp_sprintf( _n( '%s for one month.', '%s for each month, for %d installments.', $bill_times, 'invoicing' ), $amount, $bill_times );
368
+                    $description = wp_sprintf(_n('%s for one month.', '%s for each month, for %d installments.', $bill_times, 'invoicing'), $amount, $bill_times);
369 369
                 }
370 370
             } else {
371
-                $description = wp_sprintf( _n( '%s for each month.', '%s for each %d months.', $interval, 'invoicing' ), $amount, $interval );
371
+                $description = wp_sprintf(_n('%s for each month.', '%s for each %d months.', $interval, 'invoicing'), $amount, $interval);
372 372
             }
373 373
             break;
374 374
         case 'Y' :
375 375
         case 'year' :            
376
-            if ( (int)$bill_times > 0 ) {
377
-                if ( $interval > 1 ) {
378
-                    if ( $bill_times > 1 ) {
379
-                        $description = wp_sprintf( __( '%s for each %d years, for %d installments.', 'invoicing' ), $amount, $interval, $bill_times );
376
+            if ((int)$bill_times > 0) {
377
+                if ($interval > 1) {
378
+                    if ($bill_times > 1) {
379
+                        $description = wp_sprintf(__('%s for each %d years, for %d installments.', 'invoicing'), $amount, $interval, $bill_times);
380 380
                     } else {
381
-                        $description = wp_sprintf( __( '%s for %d years.', 'invoicing'), $amount, $interval );
381
+                        $description = wp_sprintf(__('%s for %d years.', 'invoicing'), $amount, $interval);
382 382
                     }
383 383
                 } else {
384
-                    $description = wp_sprintf( _n( '%s for one year.', '%s for each year, for %d installments.', $bill_times, 'invoicing' ), $amount, $bill_times );
384
+                    $description = wp_sprintf(_n('%s for one year.', '%s for each year, for %d installments.', $bill_times, 'invoicing'), $amount, $bill_times);
385 385
                 }
386 386
             } else {
387
-                $description = wp_sprintf( _n( '%s for each year.', '%s for each %d years.', $interval, 'invoicing' ), $amount, $interval );
387
+                $description = wp_sprintf(_n('%s for each year.', '%s for each %d years.', $interval, 'invoicing'), $amount, $interval);
388 388
             }
389 389
             break;
390 390
     }
391 391
 
392
-    return apply_filters( 'wpinv_subscription_recurring_payment_desc', $description, $amount, $period, $interval, $bill_times, $trial_period, $trial_interval );
392
+    return apply_filters('wpinv_subscription_recurring_payment_desc', $description, $amount, $period, $interval, $bill_times, $trial_period, $trial_interval);
393 393
 }
394 394
 
395
-function wpinv_subscription_payment_desc( $invoice ) {
396
-    if ( empty( $invoice ) ) {
395
+function wpinv_subscription_payment_desc($invoice) {
396
+    if (empty($invoice)) {
397 397
         return NULL;
398 398
     }
399 399
     
400 400
     $description = '';
401
-    if ( $invoice->is_parent() && $item = $invoice->get_recurring( true ) ) {
402
-        if ( $item->has_free_trial() ) {
401
+    if ($invoice->is_parent() && $item = $invoice->get_recurring(true)) {
402
+        if ($item->has_free_trial()) {
403 403
             $trial_period = $item->get_trial_period();
404 404
             $trial_interval = $item->get_trial_interval();
405 405
         } else {
@@ -407,45 +407,45 @@  discard block
 block discarded – undo
407 407
             $trial_interval = 0;
408 408
         }
409 409
         
410
-        $description = wpinv_get_billing_cycle( $invoice->get_total(), $invoice->get_recurring_details( 'total' ), $item->get_recurring_period(), $item->get_recurring_interval(), $item->get_recurring_limit(), $trial_period, $trial_interval, $invoice->get_currency() );
410
+        $description = wpinv_get_billing_cycle($invoice->get_total(), $invoice->get_recurring_details('total'), $item->get_recurring_period(), $item->get_recurring_interval(), $item->get_recurring_limit(), $trial_period, $trial_interval, $invoice->get_currency());
411 411
     }
412 412
     
413
-    return apply_filters( 'wpinv_subscription_payment_desc', $description, $invoice );
413
+    return apply_filters('wpinv_subscription_payment_desc', $description, $invoice);
414 414
 }
415 415
 
416
-function wpinv_get_billing_cycle( $initial, $recurring, $period, $interval, $bill_times, $trial_period = '', $trial_interval = 0, $currency = '' ) {
417
-    $initial_total      = wpinv_format_amount( $initial );
418
-    $recurring_total    = wpinv_format_amount( $recurring );
416
+function wpinv_get_billing_cycle($initial, $recurring, $period, $interval, $bill_times, $trial_period = '', $trial_interval = 0, $currency = '') {
417
+    $initial_total      = wpinv_format_amount($initial);
418
+    $recurring_total    = wpinv_format_amount($recurring);
419 419
     
420
-    if ( $trial_interval > 0 && !empty( $trial_period ) ) {
420
+    if ($trial_interval > 0 && !empty($trial_period)) {
421 421
         // Free trial
422 422
     } else {
423
-        if ( $bill_times == 1 ) {
423
+        if ($bill_times == 1) {
424 424
             $recurring_total = $initial_total;
425
-        } else if ( $bill_times > 1 && $initial_total != $recurring_total ) {
425
+        } else if ($bill_times > 1 && $initial_total != $recurring_total) {
426 426
             $bill_times--;
427 427
         }
428 428
     }
429 429
     
430
-    $initial_amount     = wpinv_price( $initial_total, $currency );
431
-    $recurring_amount   = wpinv_price( $recurring_total, $currency );
430
+    $initial_amount     = wpinv_price($initial_total, $currency);
431
+    $recurring_amount   = wpinv_price($recurring_total, $currency);
432 432
     
433
-    $recurring          = wpinv_subscription_recurring_payment_desc( $recurring_amount, $period, $interval, $bill_times, $trial_period, $trial_interval );
433
+    $recurring          = wpinv_subscription_recurring_payment_desc($recurring_amount, $period, $interval, $bill_times, $trial_period, $trial_interval);
434 434
         
435
-    if ( $initial_total != $recurring_total ) {
436
-        $initial        = wpinv_subscription_initial_payment_desc( $initial_amount, $period, $interval, $trial_period, $trial_interval );
435
+    if ($initial_total != $recurring_total) {
436
+        $initial        = wpinv_subscription_initial_payment_desc($initial_amount, $period, $interval, $trial_period, $trial_interval);
437 437
         
438
-        $description    = wp_sprintf( __( '%s Then %s', 'invoicing' ), $initial, $recurring );
438
+        $description    = wp_sprintf(__('%s Then %s', 'invoicing'), $initial, $recurring);
439 439
     } else {
440 440
         $description    = $recurring;
441 441
     }
442 442
     
443
-    return apply_filters( 'wpinv_get_billing_cycle', $description, $initial, $recurring, $period, $interval, $bill_times, $trial_period, $trial_interval, $currency );
443
+    return apply_filters('wpinv_get_billing_cycle', $description, $initial, $recurring, $period, $interval, $bill_times, $trial_period, $trial_interval, $currency);
444 444
 }
445 445
 
446
-function wpinv_recurring_send_payment_failed( $invoice ) {
447
-    if ( !empty( $invoice->ID ) ) {
448
-        wpinv_failed_invoice_notification( $invoice->ID );
446
+function wpinv_recurring_send_payment_failed($invoice) {
447
+    if (!empty($invoice->ID)) {
448
+        wpinv_failed_invoice_notification($invoice->ID);
449 449
     }
450 450
 }
451
-add_action( 'wpinv_recurring_payment_failed', 'wpinv_recurring_send_payment_failed', 10, 1 );
452 451
\ No newline at end of file
452
+add_action('wpinv_recurring_payment_failed', 'wpinv_recurring_send_payment_failed', 10, 1);
453 453
\ No newline at end of file
Please login to merge, or discard this patch.
includes/wpinv-template-functions.php 1 patch
Spacing   +666 added lines, -666 removed lines patch added patch discarded remove patch
@@ -7,105 +7,105 @@  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
-if ( !is_admin() ) {
15
-    add_filter( 'template_include', 'wpinv_template', 10, 1 );
16
-    add_action( 'wpinv_invoice_print_body_start', 'wpinv_display_invoice_top_bar' );
17
-    add_action( 'wpinv_invoice_top_bar_left', 'wpinv_invoice_display_left_actions' );
18
-    add_action( 'wpinv_invoice_top_bar_right', 'wpinv_invoice_display_right_actions' );
14
+if (!is_admin()) {
15
+    add_filter('template_include', 'wpinv_template', 10, 1);
16
+    add_action('wpinv_invoice_print_body_start', 'wpinv_display_invoice_top_bar');
17
+    add_action('wpinv_invoice_top_bar_left', 'wpinv_invoice_display_left_actions');
18
+    add_action('wpinv_invoice_top_bar_right', 'wpinv_invoice_display_right_actions');
19 19
 }
20 20
 
21 21
 function wpinv_template_path() {
22
-    return apply_filters( 'wpinv_template_path', 'invoicing/' );
22
+    return apply_filters('wpinv_template_path', 'invoicing/');
23 23
 }
24 24
 
25
-function wpinv_post_class( $classes, $class, $post_id ) {
25
+function wpinv_post_class($classes, $class, $post_id) {
26 26
     global $pagenow, $typenow;
27 27
 
28
-    if ( $pagenow == 'edit.php' && $typenow == 'wpi_item' && get_post_type( $post_id ) == $typenow && get_post_meta( $post_id, '_wpinv_type', true ) == 'package' ) {
28
+    if ($pagenow == 'edit.php' && $typenow == 'wpi_item' && get_post_type($post_id) == $typenow && get_post_meta($post_id, '_wpinv_type', true) == 'package') {
29 29
         $classes[] = 'wpi-gd-package';
30 30
     }
31 31
     return $classes;
32 32
 }
33
-add_filter( 'post_class', 'wpinv_post_class', 10, 3 );
33
+add_filter('post_class', 'wpinv_post_class', 10, 3);
34 34
 
35
-function wpinv_display_invoice_top_bar( $invoice ) {
36
-    if ( empty( $invoice ) ) {
35
+function wpinv_display_invoice_top_bar($invoice) {
36
+    if (empty($invoice)) {
37 37
         return;
38 38
     }
39 39
     ?>
40 40
     <div class="row wpinv-top-bar no-print">
41 41
         <div class="container">
42 42
             <div class="col-xs-6">
43
-                <?php do_action( 'wpinv_invoice_top_bar_left', $invoice );?>
43
+                <?php do_action('wpinv_invoice_top_bar_left', $invoice); ?>
44 44
             </div>
45 45
             <div class="col-xs-6 text-right">
46
-                <?php do_action( 'wpinv_invoice_top_bar_right', $invoice );?>
46
+                <?php do_action('wpinv_invoice_top_bar_right', $invoice); ?>
47 47
             </div>
48 48
         </div>
49 49
     </div>
50 50
     <?php
51 51
 }
52 52
 
53
-function wpinv_invoice_display_left_actions( $invoice ) {
54
-    if ( empty( $invoice ) ) {
53
+function wpinv_invoice_display_left_actions($invoice) {
54
+    if (empty($invoice)) {
55 55
         return;
56 56
     }
57 57
     
58 58
     $user_id = (int)$invoice->get_user_id();
59 59
     $current_user_id = (int)get_current_user_id();
60 60
     
61
-    if ( $user_id > 0 && $user_id == $current_user_id && $invoice->needs_payment() ) {
61
+    if ($user_id > 0 && $user_id == $current_user_id && $invoice->needs_payment()) {
62 62
     ?>
63
-    <a class="btn btn-success btn-sm" title="<?php esc_attr_e( 'Pay This Invoice', 'invoicing' ); ?>" href="<?php echo esc_url( $invoice->get_checkout_payment_url() ); ?>"><?php _e( 'Pay For Invoice', 'invoicing' ); ?></a>
63
+    <a class="btn btn-success btn-sm" title="<?php esc_attr_e('Pay This Invoice', 'invoicing'); ?>" href="<?php echo esc_url($invoice->get_checkout_payment_url()); ?>"><?php _e('Pay For Invoice', 'invoicing'); ?></a>
64 64
     <?php
65 65
     }
66 66
 }
67 67
 
68
-function wpinv_invoice_display_right_actions( $invoice ) {
69
-    if ( empty( $invoice ) ) {
68
+function wpinv_invoice_display_right_actions($invoice) {
69
+    if (empty($invoice)) {
70 70
         return;
71 71
     }
72 72
     
73 73
     $user_id = (int)$invoice->get_user_id();
74 74
     $current_user_id = (int)get_current_user_id();
75 75
     
76
-    if ( $user_id > 0 && $user_id == $current_user_id ) {
76
+    if ($user_id > 0 && $user_id == $current_user_id) {
77 77
     ?>
78
-    <a class="btn btn-primary btn-sm" onclick="window.print();" href="javascript:void(0)"><?php _e( 'Print Invoice', 'invoicing' ); ?></a>
79
-    <a class="btn btn-warning btn-sm" href="<?php echo esc_url( wpinv_get_history_page_uri() ); ?>"><?php _e( 'Invoice History', 'invoicing' ); ?></a>
78
+    <a class="btn btn-primary btn-sm" onclick="window.print();" href="javascript:void(0)"><?php _e('Print Invoice', 'invoicing'); ?></a>
79
+    <a class="btn btn-warning btn-sm" href="<?php echo esc_url(wpinv_get_history_page_uri()); ?>"><?php _e('Invoice History', 'invoicing'); ?></a>
80 80
     <?php } ?>
81 81
     <?php
82 82
 }
83 83
 
84
-function wpinv_before_invoice_content( $content ) {
84
+function wpinv_before_invoice_content($content) {
85 85
     global $post;
86 86
 
87
-    if ( $post && $post->post_type == 'wpi_invoice' && is_singular( 'wpi_invoice' ) && is_main_query() ) {
87
+    if ($post && $post->post_type == 'wpi_invoice' && is_singular('wpi_invoice') && is_main_query()) {
88 88
         ob_start();
89
-        do_action( 'wpinv_before_invoice_content', $post->ID );
89
+        do_action('wpinv_before_invoice_content', $post->ID);
90 90
         $content = ob_get_clean() . $content;
91 91
     }
92 92
 
93 93
     return $content;
94 94
 }
95
-add_filter( 'the_content', 'wpinv_before_invoice_content' );
95
+add_filter('the_content', 'wpinv_before_invoice_content');
96 96
 
97
-function wpinv_after_invoice_content( $content ) {
97
+function wpinv_after_invoice_content($content) {
98 98
     global $post;
99 99
 
100
-    if ( $post && $post->post_type == 'wpi_invoice' && is_singular( 'wpi_invoice' ) && is_main_query() ) {
100
+    if ($post && $post->post_type == 'wpi_invoice' && is_singular('wpi_invoice') && is_main_query()) {
101 101
         ob_start();
102
-        do_action( 'wpinv_after_invoice_content', $post->ID );
102
+        do_action('wpinv_after_invoice_content', $post->ID);
103 103
         $content .= ob_get_clean();
104 104
     }
105 105
 
106 106
     return $content;
107 107
 }
108
-add_filter( 'the_content', 'wpinv_after_invoice_content' );
108
+add_filter('the_content', 'wpinv_after_invoice_content');
109 109
 
110 110
 function wpinv_get_templates_dir() {
111 111
     return WPINV_PLUGIN_DIR . 'templates';
@@ -115,105 +115,105 @@  discard block
 block discarded – undo
115 115
     return WPINV_PLUGIN_URL . 'templates';
116 116
 }
117 117
 
118
-function wpinv_get_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) {
119
-    if ( ! empty( $args ) && is_array( $args ) ) {
120
-		extract( $args );
118
+function wpinv_get_template($template_name, $args = array(), $template_path = '', $default_path = '') {
119
+    if (!empty($args) && is_array($args)) {
120
+		extract($args);
121 121
 	}
122 122
 
123
-	$located = wpinv_locate_template( $template_name, $template_path, $default_path );
124
-	if ( ! file_exists( $located ) ) {
125
-        _doing_it_wrong( __FUNCTION__, sprintf( '<code>%s</code> does not exist.', $located ), '2.1' );
123
+	$located = wpinv_locate_template($template_name, $template_path, $default_path);
124
+	if (!file_exists($located)) {
125
+        _doing_it_wrong(__FUNCTION__, sprintf('<code>%s</code> does not exist.', $located), '2.1');
126 126
 		return;
127 127
 	}
128 128
 
129 129
 	// Allow 3rd party plugin filter template file from their plugin.
130
-	$located = apply_filters( 'wpinv_get_template', $located, $template_name, $args, $template_path, $default_path );
130
+	$located = apply_filters('wpinv_get_template', $located, $template_name, $args, $template_path, $default_path);
131 131
 
132
-	do_action( 'wpinv_before_template_part', $template_name, $template_path, $located, $args );
132
+	do_action('wpinv_before_template_part', $template_name, $template_path, $located, $args);
133 133
 
134
-	include( $located );
134
+	include($located);
135 135
 
136
-	do_action( 'wpinv_after_template_part', $template_name, $template_path, $located, $args );
136
+	do_action('wpinv_after_template_part', $template_name, $template_path, $located, $args);
137 137
 }
138 138
 
139
-function wpinv_get_template_html( $template_name, $args = array(), $template_path = '', $default_path = '' ) {
139
+function wpinv_get_template_html($template_name, $args = array(), $template_path = '', $default_path = '') {
140 140
 	ob_start();
141
-	wpinv_get_template( $template_name, $args, $template_path, $default_path );
141
+	wpinv_get_template($template_name, $args, $template_path, $default_path);
142 142
 	return ob_get_clean();
143 143
 }
144 144
 
145
-function wpinv_locate_template( $template_name, $template_path = '', $default_path = '' ) {
146
-    if ( ! $template_path ) {
145
+function wpinv_locate_template($template_name, $template_path = '', $default_path = '') {
146
+    if (!$template_path) {
147 147
         $template_path = wpinv_template_path();
148 148
     }
149 149
 
150
-    if ( ! $default_path ) {
150
+    if (!$default_path) {
151 151
         $default_path = WPINV_PLUGIN_DIR . 'templates/';
152 152
     }
153 153
 
154 154
     // Look within passed path within the theme - this is priority.
155 155
     $template = locate_template(
156 156
         array(
157
-            trailingslashit( $template_path ) . $template_name,
157
+            trailingslashit($template_path) . $template_name,
158 158
             $template_name
159 159
         )
160 160
     );
161 161
 
162 162
     // Get default templates/
163
-    if ( !$template && $default_path ) {
164
-        $template = trailingslashit( $default_path ) . $template_name;
163
+    if (!$template && $default_path) {
164
+        $template = trailingslashit($default_path) . $template_name;
165 165
     }
166 166
 
167 167
     // Return what we found.
168
-    return apply_filters( 'wpinv_locate_template', $template, $template_name, $template_path );
168
+    return apply_filters('wpinv_locate_template', $template, $template_name, $template_path);
169 169
 }
170 170
 
171
-function wpinv_get_template_part( $slug, $name = null, $load = true ) {
172
-	do_action( 'get_template_part_' . $slug, $slug, $name );
171
+function wpinv_get_template_part($slug, $name = null, $load = true) {
172
+	do_action('get_template_part_' . $slug, $slug, $name);
173 173
 
174 174
 	// Setup possible parts
175 175
 	$templates = array();
176
-	if ( isset( $name ) )
176
+	if (isset($name))
177 177
 		$templates[] = $slug . '-' . $name . '.php';
178 178
 	$templates[] = $slug . '.php';
179 179
 
180 180
 	// Allow template parts to be filtered
181
-	$templates = apply_filters( 'wpinv_get_template_part', $templates, $slug, $name );
181
+	$templates = apply_filters('wpinv_get_template_part', $templates, $slug, $name);
182 182
 
183 183
 	// Return the part that is found
184
-	return wpinv_locate_tmpl( $templates, $load, false );
184
+	return wpinv_locate_tmpl($templates, $load, false);
185 185
 }
186 186
 
187
-function wpinv_locate_tmpl( $template_names, $load = false, $require_once = true ) {
187
+function wpinv_locate_tmpl($template_names, $load = false, $require_once = true) {
188 188
 	// No file found yet
189 189
 	$located = false;
190 190
 
191 191
 	// Try to find a template file
192
-	foreach ( (array)$template_names as $template_name ) {
192
+	foreach ((array)$template_names as $template_name) {
193 193
 
194 194
 		// Continue if template is empty
195
-		if ( empty( $template_name ) )
195
+		if (empty($template_name))
196 196
 			continue;
197 197
 
198 198
 		// Trim off any slashes from the template name
199
-		$template_name = ltrim( $template_name, '/' );
199
+		$template_name = ltrim($template_name, '/');
200 200
 
201 201
 		// try locating this template file by looping through the template paths
202
-		foreach( wpinv_get_theme_template_paths() as $template_path ) {
202
+		foreach (wpinv_get_theme_template_paths() as $template_path) {
203 203
 
204
-			if( file_exists( $template_path . $template_name ) ) {
204
+			if (file_exists($template_path . $template_name)) {
205 205
 				$located = $template_path . $template_name;
206 206
 				break;
207 207
 			}
208 208
 		}
209 209
 
210
-		if( $located ) {
210
+		if ($located) {
211 211
 			break;
212 212
 		}
213 213
 	}
214 214
 
215
-	if ( ( true == $load ) && ! empty( $located ) )
216
-		load_template( $located, $require_once );
215
+	if ((true == $load) && !empty($located))
216
+		load_template($located, $require_once);
217 217
 
218 218
 	return $located;
219 219
 }
@@ -222,143 +222,143 @@  discard block
 block discarded – undo
222 222
 	$template_dir = wpinv_get_theme_template_dir_name();
223 223
 
224 224
 	$file_paths = array(
225
-		1 => trailingslashit( get_stylesheet_directory() ) . $template_dir,
226
-		10 => trailingslashit( get_template_directory() ) . $template_dir,
225
+		1 => trailingslashit(get_stylesheet_directory()) . $template_dir,
226
+		10 => trailingslashit(get_template_directory()) . $template_dir,
227 227
 		100 => wpinv_get_templates_dir()
228 228
 	);
229 229
 
230
-	$file_paths = apply_filters( 'wpinv_template_paths', $file_paths );
230
+	$file_paths = apply_filters('wpinv_template_paths', $file_paths);
231 231
 
232 232
 	// sort the file paths based on priority
233
-	ksort( $file_paths, SORT_NUMERIC );
233
+	ksort($file_paths, SORT_NUMERIC);
234 234
 
235
-	return array_map( 'trailingslashit', $file_paths );
235
+	return array_map('trailingslashit', $file_paths);
236 236
 }
237 237
 
238 238
 function wpinv_get_theme_template_dir_name() {
239
-	return trailingslashit( apply_filters( 'wpinv_templates_dir', 'wpinv_templates' ) );
239
+	return trailingslashit(apply_filters('wpinv_templates_dir', 'wpinv_templates'));
240 240
 }
241 241
 
242 242
 function wpinv_checkout_meta_tags() {
243 243
 
244 244
 	$pages   = array();
245
-	$pages[] = wpinv_get_option( 'success_page' );
246
-	$pages[] = wpinv_get_option( 'failure_page' );
247
-	$pages[] = wpinv_get_option( 'invoice_history_page' );
245
+	$pages[] = wpinv_get_option('success_page');
246
+	$pages[] = wpinv_get_option('failure_page');
247
+	$pages[] = wpinv_get_option('invoice_history_page');
248 248
 
249
-	if( !wpinv_is_checkout() && !is_page( $pages ) ) {
249
+	if (!wpinv_is_checkout() && !is_page($pages)) {
250 250
 		return;
251 251
 	}
252 252
 
253 253
 	echo '<meta name="robots" content="noindex,nofollow" />' . "\n";
254 254
 }
255
-add_action( 'wp_head', 'wpinv_checkout_meta_tags' );
255
+add_action('wp_head', 'wpinv_checkout_meta_tags');
256 256
 
257
-function wpinv_add_body_classes( $class ) {
257
+function wpinv_add_body_classes($class) {
258 258
 	$classes = (array)$class;
259 259
 
260
-	if( wpinv_is_checkout() ) {
260
+	if (wpinv_is_checkout()) {
261 261
 		$classes[] = 'wpinv-checkout';
262 262
 		$classes[] = 'wpinv-page';
263 263
 	}
264 264
 
265
-	if( wpinv_is_success_page() ) {
265
+	if (wpinv_is_success_page()) {
266 266
 		$classes[] = 'wpinv-success';
267 267
 		$classes[] = 'wpinv-page';
268 268
 	}
269 269
 
270
-	if( wpinv_is_failed_transaction_page() ) {
270
+	if (wpinv_is_failed_transaction_page()) {
271 271
 		$classes[] = 'wpinv-failed-transaction';
272 272
 		$classes[] = 'wpinv-page';
273 273
 	}
274 274
 
275
-	if( wpinv_is_invoice_history_page() ) {
275
+	if (wpinv_is_invoice_history_page()) {
276 276
 		$classes[] = 'wpinv-history';
277 277
 		$classes[] = 'wpinv-page';
278 278
 	}
279 279
 
280
-	if( wpinv_is_test_mode() ) {
280
+	if (wpinv_is_test_mode()) {
281 281
 		$classes[] = 'wpinv-test-mode';
282 282
 		$classes[] = 'wpinv-page';
283 283
 	}
284 284
 
285
-	return array_unique( $classes );
285
+	return array_unique($classes);
286 286
 }
287
-add_filter( 'body_class', 'wpinv_add_body_classes' );
287
+add_filter('body_class', 'wpinv_add_body_classes');
288 288
 
289
-function wpinv_html_dropdown( $name = 'wpinv_discounts', $selected = 0, $status = '' ) {
290
-    $args = array( 'nopaging' => true );
289
+function wpinv_html_dropdown($name = 'wpinv_discounts', $selected = 0, $status = '') {
290
+    $args = array('nopaging' => true);
291 291
 
292
-    if ( ! empty( $status ) )
292
+    if (!empty($status))
293 293
         $args['post_status'] = $status;
294 294
 
295
-    $discounts = wpinv_get_discounts( $args );
295
+    $discounts = wpinv_get_discounts($args);
296 296
     $options   = array();
297 297
 
298
-    if ( $discounts ) {
299
-        foreach ( $discounts as $discount ) {
300
-            $options[ absint( $discount->ID ) ] = esc_html( get_the_title( $discount->ID ) );
298
+    if ($discounts) {
299
+        foreach ($discounts as $discount) {
300
+            $options[absint($discount->ID)] = esc_html(get_the_title($discount->ID));
301 301
         }
302 302
     } else {
303
-        $options[0] = __( 'No discounts found', 'invoicing' );
303
+        $options[0] = __('No discounts found', 'invoicing');
304 304
     }
305 305
 
306
-    $output = wpinv_html_select( array(
306
+    $output = wpinv_html_select(array(
307 307
         'name'             => $name,
308 308
         'selected'         => $selected,
309 309
         'options'          => $options,
310 310
         'show_option_all'  => false,
311 311
         'show_option_none' => false,
312
-    ) );
312
+    ));
313 313
 
314 314
     return $output;
315 315
 }
316 316
 
317
-function wpinv_html_year_dropdown( $name = 'year', $selected = 0, $years_before = 5, $years_after = 0 ) {
318
-    $current     = date( 'Y' );
319
-    $start_year  = $current - absint( $years_before );
320
-    $end_year    = $current + absint( $years_after );
321
-    $selected    = empty( $selected ) ? date( 'Y' ) : $selected;
317
+function wpinv_html_year_dropdown($name = 'year', $selected = 0, $years_before = 5, $years_after = 0) {
318
+    $current     = date('Y');
319
+    $start_year  = $current - absint($years_before);
320
+    $end_year    = $current + absint($years_after);
321
+    $selected    = empty($selected) ? date('Y') : $selected;
322 322
     $options     = array();
323 323
 
324
-    while ( $start_year <= $end_year ) {
325
-        $options[ absint( $start_year ) ] = $start_year;
324
+    while ($start_year <= $end_year) {
325
+        $options[absint($start_year)] = $start_year;
326 326
         $start_year++;
327 327
     }
328 328
 
329
-    $output = wpinv_html_select( array(
329
+    $output = wpinv_html_select(array(
330 330
         'name'             => $name,
331 331
         'selected'         => $selected,
332 332
         'options'          => $options,
333 333
         'show_option_all'  => false,
334 334
         'show_option_none' => false
335
-    ) );
335
+    ));
336 336
 
337 337
     return $output;
338 338
 }
339 339
 
340
-function wpinv_html_month_dropdown( $name = 'month', $selected = 0 ) {
340
+function wpinv_html_month_dropdown($name = 'month', $selected = 0) {
341 341
     $month   = 1;
342 342
     $options = array();
343
-    $selected = empty( $selected ) ? date( 'n' ) : $selected;
343
+    $selected = empty($selected) ? date('n') : $selected;
344 344
 
345
-    while ( $month <= 12 ) {
346
-        $options[ absint( $month ) ] = wpinv_month_num_to_name( $month );
345
+    while ($month <= 12) {
346
+        $options[absint($month)] = wpinv_month_num_to_name($month);
347 347
         $month++;
348 348
     }
349 349
 
350
-    $output = wpinv_html_select( array(
350
+    $output = wpinv_html_select(array(
351 351
         'name'             => $name,
352 352
         'selected'         => $selected,
353 353
         'options'          => $options,
354 354
         'show_option_all'  => false,
355 355
         'show_option_none' => false
356
-    ) );
356
+    ));
357 357
 
358 358
     return $output;
359 359
 }
360 360
 
361
-function wpinv_html_select( $args = array() ) {
361
+function wpinv_html_select($args = array()) {
362 362
     $defaults = array(
363 363
         'options'          => array(),
364 364
         'name'             => null,
@@ -368,8 +368,8 @@  discard block
 block discarded – undo
368 368
         'chosen'           => false,
369 369
         'placeholder'      => null,
370 370
         'multiple'         => false,
371
-        'show_option_all'  => _x( 'All', 'all dropdown items', 'invoicing' ),
372
-        'show_option_none' => _x( 'None', 'no dropdown items', 'invoicing' ),
371
+        'show_option_all'  => _x('All', 'all dropdown items', 'invoicing'),
372
+        'show_option_none' => _x('None', 'no dropdown items', 'invoicing'),
373 373
         'data'             => array(),
374 374
         'onchange'         => null,
375 375
         'required'         => false,
@@ -377,78 +377,78 @@  discard block
 block discarded – undo
377 377
         'readonly'         => false,
378 378
     );
379 379
 
380
-    $args = wp_parse_args( $args, $defaults );
380
+    $args = wp_parse_args($args, $defaults);
381 381
 
382 382
     $data_elements = '';
383
-    foreach ( $args['data'] as $key => $value ) {
384
-        $data_elements .= ' data-' . esc_attr( $key ) . '="' . esc_attr( $value ) . '"';
383
+    foreach ($args['data'] as $key => $value) {
384
+        $data_elements .= ' data-' . esc_attr($key) . '="' . esc_attr($value) . '"';
385 385
     }
386 386
 
387
-    if( $args['multiple'] ) {
387
+    if ($args['multiple']) {
388 388
         $multiple = ' MULTIPLE';
389 389
     } else {
390 390
         $multiple = '';
391 391
     }
392 392
 
393
-    if( $args['chosen'] ) {
393
+    if ($args['chosen']) {
394 394
         $args['class'] .= ' wpinv-select-chosen';
395 395
     }
396 396
 
397
-    if( $args['placeholder'] ) {
397
+    if ($args['placeholder']) {
398 398
         $placeholder = $args['placeholder'];
399 399
     } else {
400 400
         $placeholder = '';
401 401
     }
402 402
     
403 403
     $options = '';
404
-    if( !empty( $args['onchange'] ) ) {
405
-        $options .= ' onchange="' . esc_attr( $args['onchange'] ) . '"';
404
+    if (!empty($args['onchange'])) {
405
+        $options .= ' onchange="' . esc_attr($args['onchange']) . '"';
406 406
     }
407 407
     
408
-    if( !empty( $args['required'] ) ) {
408
+    if (!empty($args['required'])) {
409 409
         $options .= ' required="required"';
410 410
     }
411 411
     
412
-    if( !empty( $args['disabled'] ) ) {
412
+    if (!empty($args['disabled'])) {
413 413
         $options .= ' disabled';
414 414
     }
415 415
     
416
-    if( !empty( $args['readonly'] ) ) {
416
+    if (!empty($args['readonly'])) {
417 417
         $options .= ' readonly';
418 418
     }
419 419
 
420
-    $class  = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) );
421
-    $output = '<select name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['id'] ) . '" class="wpinv-select ' . $class . '"' . $multiple . ' data-placeholder="' . $placeholder . '" ' . trim( $options ) . $data_elements . '>';
420
+    $class  = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class'])));
421
+    $output = '<select name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['id']) . '" class="wpinv-select ' . $class . '"' . $multiple . ' data-placeholder="' . $placeholder . '" ' . trim($options) . $data_elements . '>';
422 422
 
423
-    if ( $args['show_option_all'] ) {
424
-        if( $args['multiple'] ) {
425
-            $selected = selected( true, in_array( 0, $args['selected'] ), false );
423
+    if ($args['show_option_all']) {
424
+        if ($args['multiple']) {
425
+            $selected = selected(true, in_array(0, $args['selected']), false);
426 426
         } else {
427
-            $selected = selected( $args['selected'], 0, false );
427
+            $selected = selected($args['selected'], 0, false);
428 428
         }
429
-        $output .= '<option value="all"' . $selected . '>' . esc_html( $args['show_option_all'] ) . '</option>';
429
+        $output .= '<option value="all"' . $selected . '>' . esc_html($args['show_option_all']) . '</option>';
430 430
     }
431 431
 
432
-    if ( !empty( $args['options'] ) ) {
432
+    if (!empty($args['options'])) {
433 433
 
434
-        if ( $args['show_option_none'] ) {
435
-            if( $args['multiple'] ) {
436
-                $selected = selected( true, in_array( "", $args['selected'] ), false );
434
+        if ($args['show_option_none']) {
435
+            if ($args['multiple']) {
436
+                $selected = selected(true, in_array("", $args['selected']), false);
437 437
             } else {
438
-                $selected = selected( $args['selected'] === "", true, false );
438
+                $selected = selected($args['selected'] === "", true, false);
439 439
             }
440
-            $output .= '<option value=""' . $selected . '>' . esc_html( $args['show_option_none'] ) . '</option>';
440
+            $output .= '<option value=""' . $selected . '>' . esc_html($args['show_option_none']) . '</option>';
441 441
         }
442 442
 
443
-        foreach( $args['options'] as $key => $option ) {
443
+        foreach ($args['options'] as $key => $option) {
444 444
 
445
-            if( $args['multiple'] && is_array( $args['selected'] ) ) {
446
-                $selected = selected( true, (bool)in_array( $key, $args['selected'] ), false );
445
+            if ($args['multiple'] && is_array($args['selected'])) {
446
+                $selected = selected(true, (bool)in_array($key, $args['selected']), false);
447 447
             } else {
448
-                $selected = selected( $args['selected'], $key, false );
448
+                $selected = selected($args['selected'], $key, false);
449 449
             }
450 450
 
451
-            $output .= '<option value="' . esc_attr( $key ) . '"' . $selected . '>' . esc_html( $option ) . '</option>';
451
+            $output .= '<option value="' . esc_attr($key) . '"' . $selected . '>' . esc_html($option) . '</option>';
452 452
         }
453 453
     }
454 454
 
@@ -457,7 +457,7 @@  discard block
 block discarded – undo
457 457
     return $output;
458 458
 }
459 459
 
460
-function wpinv_item_dropdown( $args = array() ) {
460
+function wpinv_item_dropdown($args = array()) {
461 461
     $defaults = array(
462 462
         'name'              => 'wpi_item',
463 463
         'id'                => 'wpi_item',
@@ -466,15 +466,15 @@  discard block
 block discarded – undo
466 466
         'selected'          => 0,
467 467
         'chosen'            => false,
468 468
         'number'            => 100,
469
-        'placeholder'       => __( 'Choose a item', 'invoicing' ),
470
-        'data'              => array( 'search-type' => 'item' ),
469
+        'placeholder'       => __('Choose a item', 'invoicing'),
470
+        'data'              => array('search-type' => 'item'),
471 471
         'show_option_all'   => false,
472 472
         'show_option_none'  => false,
473 473
         'with_packages'     => true,
474 474
         'show_recurring'    => false,
475 475
     );
476 476
 
477
-    $args = wp_parse_args( $args, $defaults );
477
+    $args = wp_parse_args($args, $defaults);
478 478
 
479 479
     $item_args = array(
480 480
         'post_type'      => 'wpi_item',
@@ -483,7 +483,7 @@  discard block
 block discarded – undo
483 483
         'posts_per_page' => $args['number']
484 484
     );
485 485
     
486
-    if ( !$args['with_packages'] ) {
486
+    if (!$args['with_packages']) {
487 487
         $item_args['meta_query'] = array(
488 488
             array(
489 489
                 'key'       => '_wpinv_type',
@@ -493,42 +493,42 @@  discard block
 block discarded – undo
493 493
         );
494 494
     }
495 495
 
496
-    $items      = get_posts( $item_args );
496
+    $items      = get_posts($item_args);
497 497
     $options    = array();
498
-    if ( $items ) {
499
-        foreach ( $items as $item ) {
500
-            $title = esc_html( $item->post_title );
498
+    if ($items) {
499
+        foreach ($items as $item) {
500
+            $title = esc_html($item->post_title);
501 501
             
502
-            if ( !empty( $args['show_recurring'] ) ) {
503
-                $title .= wpinv_get_item_suffix( $item->ID, false );
502
+            if (!empty($args['show_recurring'])) {
503
+                $title .= wpinv_get_item_suffix($item->ID, false);
504 504
             }
505 505
             
506
-            $options[ absint( $item->ID ) ] = $title;
506
+            $options[absint($item->ID)] = $title;
507 507
         }
508 508
     }
509 509
 
510 510
     // This ensures that any selected items are included in the drop down
511
-    if( is_array( $args['selected'] ) ) {
512
-        foreach( $args['selected'] as $item ) {
513
-            if( ! in_array( $item, $options ) ) {
514
-                $title = get_the_title( $item );
515
-                if ( !empty( $args['show_recurring'] ) ) {
516
-                    $title .= wpinv_get_item_suffix( $item, false );
511
+    if (is_array($args['selected'])) {
512
+        foreach ($args['selected'] as $item) {
513
+            if (!in_array($item, $options)) {
514
+                $title = get_the_title($item);
515
+                if (!empty($args['show_recurring'])) {
516
+                    $title .= wpinv_get_item_suffix($item, false);
517 517
                 }
518 518
                 $options[$item] = $title;
519 519
             }
520 520
         }
521
-    } elseif ( is_numeric( $args['selected'] ) && $args['selected'] !== 0 ) {
522
-        if ( ! in_array( $args['selected'], $options ) ) {
523
-            $title = get_the_title( $args['selected'] );
524
-            if ( !empty( $args['show_recurring'] ) ) {
525
-                $title .= wpinv_get_item_suffix( $args['selected'], false );
521
+    } elseif (is_numeric($args['selected']) && $args['selected'] !== 0) {
522
+        if (!in_array($args['selected'], $options)) {
523
+            $title = get_the_title($args['selected']);
524
+            if (!empty($args['show_recurring'])) {
525
+                $title .= wpinv_get_item_suffix($args['selected'], false);
526 526
             }
527
-            $options[$args['selected']] = get_the_title( $args['selected'] );
527
+            $options[$args['selected']] = get_the_title($args['selected']);
528 528
         }
529 529
     }
530 530
 
531
-    $output = wpinv_html_select( array(
531
+    $output = wpinv_html_select(array(
532 532
         'name'             => $args['name'],
533 533
         'selected'         => $args['selected'],
534 534
         'id'               => $args['id'],
@@ -540,12 +540,12 @@  discard block
 block discarded – undo
540 540
         'show_option_all'  => $args['show_option_all'],
541 541
         'show_option_none' => $args['show_option_none'],
542 542
         'data'             => $args['data'],
543
-    ) );
543
+    ));
544 544
 
545 545
     return $output;
546 546
 }
547 547
 
548
-function wpinv_html_checkbox( $args = array() ) {
548
+function wpinv_html_checkbox($args = array()) {
549 549
     $defaults = array(
550 550
         'name'     => null,
551 551
         'current'  => null,
@@ -556,38 +556,38 @@  discard block
 block discarded – undo
556 556
         )
557 557
     );
558 558
 
559
-    $args = wp_parse_args( $args, $defaults );
559
+    $args = wp_parse_args($args, $defaults);
560 560
 
561
-    $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) );
561
+    $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class'])));
562 562
     $options = '';
563
-    if ( ! empty( $args['options']['disabled'] ) ) {
563
+    if (!empty($args['options']['disabled'])) {
564 564
         $options .= ' disabled="disabled"';
565
-    } elseif ( ! empty( $args['options']['readonly'] ) ) {
565
+    } elseif (!empty($args['options']['readonly'])) {
566 566
         $options .= ' readonly';
567 567
     }
568 568
 
569
-    $output = '<input type="checkbox"' . $options . ' name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['name'] ) . '" class="' . $class . ' ' . esc_attr( $args['name'] ) . '" ' . checked( 1, $args['current'], false ) . ' />';
569
+    $output = '<input type="checkbox"' . $options . ' name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['name']) . '" class="' . $class . ' ' . esc_attr($args['name']) . '" ' . checked(1, $args['current'], false) . ' />';
570 570
 
571 571
     return $output;
572 572
 }
573 573
 
574
-function wpinv_html_text( $args = array() ) {
574
+function wpinv_html_text($args = array()) {
575 575
     // Backwards compatibility
576
-    if ( func_num_args() > 1 ) {
576
+    if (func_num_args() > 1) {
577 577
         $args = func_get_args();
578 578
 
579 579
         $name  = $args[0];
580
-        $value = isset( $args[1] ) ? $args[1] : '';
581
-        $label = isset( $args[2] ) ? $args[2] : '';
582
-        $desc  = isset( $args[3] ) ? $args[3] : '';
580
+        $value = isset($args[1]) ? $args[1] : '';
581
+        $label = isset($args[2]) ? $args[2] : '';
582
+        $desc  = isset($args[3]) ? $args[3] : '';
583 583
     }
584 584
 
585 585
     $defaults = array(
586 586
         'id'           => '',
587
-        'name'         => isset( $name )  ? $name  : 'text',
588
-        'value'        => isset( $value ) ? $value : null,
589
-        'label'        => isset( $label ) ? $label : null,
590
-        'desc'         => isset( $desc )  ? $desc  : null,
587
+        'name'         => isset($name) ? $name : 'text',
588
+        'value'        => isset($value) ? $value : null,
589
+        'label'        => isset($label) ? $label : null,
590
+        'desc'         => isset($desc) ? $desc : null,
591 591
         'placeholder'  => '',
592 592
         'class'        => 'regular-text',
593 593
         'disabled'     => false,
@@ -597,51 +597,51 @@  discard block
 block discarded – undo
597 597
         'data'         => false
598 598
     );
599 599
 
600
-    $args = wp_parse_args( $args, $defaults );
600
+    $args = wp_parse_args($args, $defaults);
601 601
 
602
-    $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) );
602
+    $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class'])));
603 603
     $options = '';
604
-    if( $args['required'] ) {
604
+    if ($args['required']) {
605 605
         $options .= ' required="required"';
606 606
     }
607
-    if( $args['readonly'] ) {
607
+    if ($args['readonly']) {
608 608
         $options .= ' readonly';
609 609
     }
610
-    if( $args['readonly'] ) {
610
+    if ($args['readonly']) {
611 611
         $options .= ' readonly';
612 612
     }
613 613
 
614 614
     $data = '';
615
-    if ( !empty( $args['data'] ) ) {
616
-        foreach ( $args['data'] as $key => $value ) {
617
-            $data .= 'data-' . wpinv_sanitize_key( $key ) . '="' . esc_attr( $value ) . '" ';
615
+    if (!empty($args['data'])) {
616
+        foreach ($args['data'] as $key => $value) {
617
+            $data .= 'data-' . wpinv_sanitize_key($key) . '="' . esc_attr($value) . '" ';
618 618
         }
619 619
     }
620 620
 
621
-    $output = '<span id="wpinv-' . wpinv_sanitize_key( $args['name'] ) . '-wrap">';
622
-    $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key( $args['id'] ) . '">' . esc_html( $args['label'] ) . '</label>';
623
-    if ( ! empty( $args['desc'] ) ) {
624
-        $output .= '<span class="wpinv-description">' . esc_html( $args['desc'] ) . '</span>';
621
+    $output = '<span id="wpinv-' . wpinv_sanitize_key($args['name']) . '-wrap">';
622
+    $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key($args['id']) . '">' . esc_html($args['label']) . '</label>';
623
+    if (!empty($args['desc'])) {
624
+        $output .= '<span class="wpinv-description">' . esc_html($args['desc']) . '</span>';
625 625
     }
626 626
 
627
-    $output .= '<input type="text" name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['id'] )  . '" autocomplete="' . esc_attr( $args['autocomplete'] )  . '" value="' . esc_attr( $args['value'] ) . '" placeholder="' . esc_attr( $args['placeholder'] ) . '" class="' . $class . '" ' . $data . ' ' . trim( $options ) . '/>';
627
+    $output .= '<input type="text" name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['id']) . '" autocomplete="' . esc_attr($args['autocomplete']) . '" value="' . esc_attr($args['value']) . '" placeholder="' . esc_attr($args['placeholder']) . '" class="' . $class . '" ' . $data . ' ' . trim($options) . '/>';
628 628
 
629 629
     $output .= '</span>';
630 630
 
631 631
     return $output;
632 632
 }
633 633
 
634
-function wpinv_html_date_field( $args = array() ) {
635
-    if( empty( $args['class'] ) ) {
634
+function wpinv_html_date_field($args = array()) {
635
+    if (empty($args['class'])) {
636 636
         $args['class'] = 'wpiDatepicker';
637
-    } elseif( ! strpos( $args['class'], 'wpiDatepicker' ) ) {
637
+    } elseif (!strpos($args['class'], 'wpiDatepicker')) {
638 638
         $args['class'] .= ' wpiDatepicker';
639 639
     }
640 640
 
641
-    return wpinv_html_text( $args );
641
+    return wpinv_html_text($args);
642 642
 }
643 643
 
644
-function wpinv_html_textarea( $args = array() ) {
644
+function wpinv_html_textarea($args = array()) {
645 645
     $defaults = array(
646 646
         'name'        => 'textarea',
647 647
         'value'       => null,
@@ -651,31 +651,31 @@  discard block
 block discarded – undo
651 651
         'disabled'    => false
652 652
     );
653 653
 
654
-    $args = wp_parse_args( $args, $defaults );
654
+    $args = wp_parse_args($args, $defaults);
655 655
 
656
-    $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) );
656
+    $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class'])));
657 657
     $disabled = '';
658
-    if( $args['disabled'] ) {
658
+    if ($args['disabled']) {
659 659
         $disabled = ' disabled="disabled"';
660 660
     }
661 661
 
662
-    $output = '<span id="wpinv-' . wpinv_sanitize_key( $args['name'] ) . '-wrap">';
663
-    $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key( $args['name'] ) . '">' . esc_html( $args['label'] ) . '</label>';
664
-    $output .= '<textarea name="' . esc_attr( $args['name'] ) . '" id="' . wpinv_sanitize_key( $args['name'] ) . '" class="' . $class . '"' . $disabled . '>' . esc_attr( $args['value'] ) . '</textarea>';
662
+    $output = '<span id="wpinv-' . wpinv_sanitize_key($args['name']) . '-wrap">';
663
+    $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key($args['name']) . '">' . esc_html($args['label']) . '</label>';
664
+    $output .= '<textarea name="' . esc_attr($args['name']) . '" id="' . wpinv_sanitize_key($args['name']) . '" class="' . $class . '"' . $disabled . '>' . esc_attr($args['value']) . '</textarea>';
665 665
 
666
-    if ( ! empty( $args['desc'] ) ) {
667
-        $output .= '<span class="wpinv-description">' . esc_html( $args['desc'] ) . '</span>';
666
+    if (!empty($args['desc'])) {
667
+        $output .= '<span class="wpinv-description">' . esc_html($args['desc']) . '</span>';
668 668
     }
669 669
     $output .= '</span>';
670 670
 
671 671
     return $output;
672 672
 }
673 673
 
674
-function wpinv_html_ajax_user_search( $args = array() ) {
674
+function wpinv_html_ajax_user_search($args = array()) {
675 675
     $defaults = array(
676 676
         'name'        => 'user_id',
677 677
         'value'       => null,
678
-        'placeholder' => __( 'Enter username', 'invoicing' ),
678
+        'placeholder' => __('Enter username', 'invoicing'),
679 679
         'label'       => null,
680 680
         'desc'        => null,
681 681
         'class'       => '',
@@ -684,13 +684,13 @@  discard block
 block discarded – undo
684 684
         'data'        => false
685 685
     );
686 686
 
687
-    $args = wp_parse_args( $args, $defaults );
687
+    $args = wp_parse_args($args, $defaults);
688 688
 
689 689
     $args['class'] = 'wpinv-ajax-user-search ' . $args['class'];
690 690
 
691 691
     $output  = '<span class="wpinv_user_search_wrap">';
692
-        $output .= wpinv_html_text( $args );
693
-        $output .= '<span class="wpinv_user_search_results hidden"><a class="wpinv-ajax-user-cancel" title="' . __( 'Cancel', 'invoicing' ) . '" aria-label="' . __( 'Cancel', 'invoicing' ) . '" href="#">x</a><span></span></span>';
692
+        $output .= wpinv_html_text($args);
693
+        $output .= '<span class="wpinv_user_search_results hidden"><a class="wpinv-ajax-user-cancel" title="' . __('Cancel', 'invoicing') . '" aria-label="' . __('Cancel', 'invoicing') . '" href="#">x</a><span></span></span>';
694 694
     $output .= '</span>';
695 695
 
696 696
     return $output;
@@ -699,7 +699,7 @@  discard block
 block discarded – undo
699 699
 function wpinv_ip_geolocation() {
700 700
     global $wpinv_euvat;
701 701
     
702
-    $ip         = !empty( $_GET['ip'] ) ? sanitize_text_field( $_GET['ip'] ) : '';    
702
+    $ip         = !empty($_GET['ip']) ? sanitize_text_field($_GET['ip']) : '';    
703 703
     $content    = '';
704 704
     $iso        = '';
705 705
     $country    = '';
@@ -709,70 +709,70 @@  discard block
 block discarded – undo
709 709
     $latitude   = '';
710 710
     $credit     = '';
711 711
     
712
-    if ( wpinv_get_option( 'vat_ip_lookup' ) == 'geoip2' && $geoip2_city = $wpinv_euvat->geoip2_city_record( $ip ) ) {
712
+    if (wpinv_get_option('vat_ip_lookup') == 'geoip2' && $geoip2_city = $wpinv_euvat->geoip2_city_record($ip)) {
713 713
         try {
714 714
             $iso        = $geoip2_city->country->isoCode;
715 715
             $country    = $geoip2_city->country->name;
716
-            $region     = !empty( $geoip2_city->subdivisions ) && !empty( $geoip2_city->subdivisions[0]->name ) ? $geoip2_city->subdivisions[0]->name : '';
716
+            $region     = !empty($geoip2_city->subdivisions) && !empty($geoip2_city->subdivisions[0]->name) ? $geoip2_city->subdivisions[0]->name : '';
717 717
             $city       = $geoip2_city->city->name;
718 718
             $longitude  = $geoip2_city->location->longitude;
719 719
             $latitude   = $geoip2_city->location->latitude;
720
-            $credit     = __( 'Geolocated using the information by MaxMind, available from <a href="http://www.maxmind.com" target="_blank">www.maxmind.com</a>', 'invoicing' );
721
-        } catch( Exception $e ) { }
720
+            $credit     = __('Geolocated using the information by MaxMind, available from <a href="http://www.maxmind.com" target="_blank">www.maxmind.com</a>', 'invoicing');
721
+        } catch (Exception $e) { }
722 722
     }
723 723
     
724
-    if ( !( $iso && $longitude && $latitude ) && function_exists( 'simplexml_load_file' ) ) {
724
+    if (!($iso && $longitude && $latitude) && function_exists('simplexml_load_file')) {
725 725
         try {
726
-            $load_xml = simplexml_load_file( 'http://www.geoplugin.net/xml.gp?ip=' . $ip );
726
+            $load_xml = simplexml_load_file('http://www.geoplugin.net/xml.gp?ip=' . $ip);
727 727
             
728
-            if ( !empty( $load_xml ) && isset( $load_xml->geoplugin_countryCode ) && !empty( $load_xml->geoplugin_latitude ) && !empty( $load_xml->geoplugin_longitude ) ) {
728
+            if (!empty($load_xml) && isset($load_xml->geoplugin_countryCode) && !empty($load_xml->geoplugin_latitude) && !empty($load_xml->geoplugin_longitude)) {
729 729
                 $iso        = $load_xml->geoplugin_countryCode;
730 730
                 $country    = $load_xml->geoplugin_countryName;
731
-                $region     = !empty( $load_xml->geoplugin_regionName ) ? $load_xml->geoplugin_regionName : '';
732
-                $city       = !empty( $load_xml->geoplugin_city ) ? $load_xml->geoplugin_city : '';
731
+                $region     = !empty($load_xml->geoplugin_regionName) ? $load_xml->geoplugin_regionName : '';
732
+                $city       = !empty($load_xml->geoplugin_city) ? $load_xml->geoplugin_city : '';
733 733
                 $longitude  = $load_xml->geoplugin_longitude;
734 734
                 $latitude   = $load_xml->geoplugin_latitude;
735 735
                 $credit     = $load_xml->geoplugin_credit;
736
-                $credit     = __( 'Geolocated using the information by geoPlugin, available from <a href="http://www.geoplugin.com" target="_blank">www.geoplugin.com</a>', 'invoicing' ) . '<br>' . $load_xml->geoplugin_credit;
736
+                $credit     = __('Geolocated using the information by geoPlugin, available from <a href="http://www.geoplugin.com" target="_blank">www.geoplugin.com</a>', 'invoicing') . '<br>' . $load_xml->geoplugin_credit;
737 737
             }
738
-        } catch( Exception $e ) { }
738
+        } catch (Exception $e) { }
739 739
     }
740 740
     
741
-    if ( $iso && $longitude && $latitude ) {
741
+    if ($iso && $longitude && $latitude) {
742 742
         $address = '';
743
-        if ( $city ) {
743
+        if ($city) {
744 744
             $address .= $city . ', ';
745 745
         }
746 746
         
747
-        if ( $region ) {
747
+        if ($region) {
748 748
             $address .= $region . ', ';
749 749
         }
750 750
         
751 751
         $address .= $country . ' (' . $iso . ')';
752
-        $content = '<p>'. sprintf( __( '<b>Address:</b> %s', 'invoicing' ), $address ) . '</p>';
753
-        $content .= '<p>'. $credit . '</p>';
752
+        $content = '<p>' . sprintf(__('<b>Address:</b> %s', 'invoicing'), $address) . '</p>';
753
+        $content .= '<p>' . $credit . '</p>';
754 754
     } else {
755
-        $content = '<p>'. sprintf( __( 'Unable to find geolocation for the IP address: %s', 'invoicing' ), $ip ) . '</p>';
755
+        $content = '<p>' . sprintf(__('Unable to find geolocation for the IP address: %s', 'invoicing'), $ip) . '</p>';
756 756
     }
757 757
     ?>
758 758
 <!DOCTYPE html>
759
-<html><head><title><?php echo sprintf( __( 'IP: %s', 'invoicing' ), $ip );?></title><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"><link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.0-rc.1/leaflet.css" /><style>html,body{height:100%;margin:0;padding:0;width:100%}body{text-align:center;background:#fff;color:#222;font-size:small;}body,p{font-family: arial,sans-serif}#map{margin:auto;width:100%;height:calc(100% - 120px);min-height:240px}</style></head>
759
+<html><head><title><?php echo sprintf(__('IP: %s', 'invoicing'), $ip); ?></title><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"><link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.0-rc.1/leaflet.css" /><style>html,body{height:100%;margin:0;padding:0;width:100%}body{text-align:center;background:#fff;color:#222;font-size:small;}body,p{font-family: arial,sans-serif}#map{margin:auto;width:100%;height:calc(100% - 120px);min-height:240px}</style></head>
760 760
 <body>
761
-    <?php if ( $latitude && $latitude ) { ?>
761
+    <?php if ($latitude && $latitude) { ?>
762 762
     <div id="map"></div>
763 763
         <script src="//cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.0-rc.1/leaflet.js"></script>
764 764
         <script type="text/javascript">
765 765
         var osmUrl = 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
766 766
             osmAttrib = '&copy; <a href="http://openstreetmap.org/copyright">OpenStreetMap</a> contributors',
767 767
             osm = L.tileLayer(osmUrl, {maxZoom: 18, attribution: osmAttrib}),
768
-            latlng = new L.LatLng(<?php echo $latitude;?>, <?php echo $longitude;?>);
768
+            latlng = new L.LatLng(<?php echo $latitude; ?>, <?php echo $longitude; ?>);
769 769
 
770 770
         var map = new L.Map('map', {center: latlng, zoom: 12, layers: [osm]});
771 771
 
772 772
         var marker = new L.Marker(latlng);
773 773
         map.addLayer(marker);
774 774
 
775
-        marker.bindPopup("<p><?php esc_attr_e( $address );?></p>");
775
+        marker.bindPopup("<p><?php esc_attr_e($address); ?></p>");
776 776
     </script>
777 777
     <?php } ?>
778 778
     <div style="height:100px"><?php echo $content; ?></div>
@@ -780,31 +780,31 @@  discard block
 block discarded – undo
780 780
 <?php
781 781
     exit;
782 782
 }
783
-add_action( 'wp_ajax_wpinv_ip_geolocation', 'wpinv_ip_geolocation' );
784
-add_action( 'wp_ajax_nopriv_wpinv_ip_geolocation', 'wpinv_ip_geolocation' );
783
+add_action('wp_ajax_wpinv_ip_geolocation', 'wpinv_ip_geolocation');
784
+add_action('wp_ajax_nopriv_wpinv_ip_geolocation', 'wpinv_ip_geolocation');
785 785
 
786 786
 // Set up the template for the invoice.
787
-function wpinv_template( $template ) {
787
+function wpinv_template($template) {
788 788
     global $post, $wp_query;
789 789
     
790
-    if ( ( is_single() || is_404() ) && !empty( $post->ID ) && get_post_type( $post->ID ) == 'wpi_invoice' ) {
791
-        if ( wpinv_user_can_print_invoice( $post->ID ) ) {
792
-            $template = wpinv_get_template_part( 'wpinv-invoice-print', false, false );
790
+    if ((is_single() || is_404()) && !empty($post->ID) && get_post_type($post->ID) == 'wpi_invoice') {
791
+        if (wpinv_user_can_print_invoice($post->ID)) {
792
+            $template = wpinv_get_template_part('wpinv-invoice-print', false, false);
793 793
         } else {
794
-            if ( !is_user_logged_in() && !empty( $_REQUEST['_wpipay'] ) && $invoice = wpinv_get_invoice( $post->ID ) ) {
794
+            if (!is_user_logged_in() && !empty($_REQUEST['_wpipay']) && $invoice = wpinv_get_invoice($post->ID)) {
795 795
                 $user_id = $invoice->get_user_id();
796
-                $secret = sanitize_text_field( $_GET['_wpipay'] );
796
+                $secret = sanitize_text_field($_GET['_wpipay']);
797 797
 
798
-                if ( $secret === md5( $user_id . '::' . $invoice->get_email() . '::' . $invoice->get_key() ) ) { // valid invoice link
799
-                    $redirect_to = remove_query_arg( '_wpipay', get_permalink() );
798
+                if ($secret === md5($user_id . '::' . $invoice->get_email() . '::' . $invoice->get_key())) { // valid invoice link
799
+                    $redirect_to = remove_query_arg('_wpipay', get_permalink());
800 800
 
801
-                    wpinv_guest_redirect( $redirect_to, $user_id );
801
+                    wpinv_guest_redirect($redirect_to, $user_id);
802 802
                     wpinv_die();
803 803
                 }
804 804
             }
805
-            $redirect_to = is_user_logged_in() ? wpinv_get_history_page_uri() : wp_login_url( get_permalink() );
805
+            $redirect_to = is_user_logged_in() ? wpinv_get_history_page_uri() : wp_login_url(get_permalink());
806 806
 
807
-            wp_redirect( $redirect_to );
807
+            wp_redirect($redirect_to);
808 808
             wpinv_die();
809 809
         }
810 810
     }
@@ -814,7 +814,7 @@  discard block
 block discarded – undo
814 814
 
815 815
 function wpinv_get_business_address() {
816 816
     $business_address   = wpinv_store_address();
817
-    $business_address   = !empty( $business_address ) ? wpautop( wp_kses_post( $business_address ) ) : '';
817
+    $business_address   = !empty($business_address) ? wpautop(wp_kses_post($business_address)) : '';
818 818
     
819 819
     /*
820 820
     $default_country    = wpinv_get_default_country();
@@ -838,7 +838,7 @@  discard block
 block discarded – undo
838 838
     
839 839
     $business_address = $business_address ? '<div class="address">' . $business_address . '</div>' : '';
840 840
     
841
-    return apply_filters( 'wpinv_get_business_address', $business_address );
841
+    return apply_filters('wpinv_get_business_address', $business_address);
842 842
 }
843 843
 
844 844
 function wpinv_display_from_address() {
@@ -848,181 +848,181 @@  discard block
 block discarded – undo
848 848
     if (empty($from_name)) {
849 849
         $from_name = wpinv_get_business_name();
850 850
     }
851
-    ?><div class="from col-xs-2"><strong><?php _e( 'From:', 'invoicing' ) ?></strong></div>
851
+    ?><div class="from col-xs-2"><strong><?php _e('From:', 'invoicing') ?></strong></div>
852 852
     <div class="wrapper col-xs-10">
853
-        <div class="name"><?php echo esc_html( $from_name ); ?></div>
854
-        <?php if ( $address = wpinv_get_business_address() ) { ?>
855
-        <div class="address"><?php echo wpautop( wp_kses_post( $address ) );?></div>
853
+        <div class="name"><?php echo esc_html($from_name); ?></div>
854
+        <?php if ($address = wpinv_get_business_address()) { ?>
855
+        <div class="address"><?php echo wpautop(wp_kses_post($address)); ?></div>
856 856
         <?php } ?>
857
-        <?php if ( $email_from = wpinv_mail_get_from_address() ) { ?>
858
-        <div class="email_from"><?php echo wp_sprintf( __( 'Email: %s' ), $email_from );?></div>
857
+        <?php if ($email_from = wpinv_mail_get_from_address()) { ?>
858
+        <div class="email_from"><?php echo wp_sprintf(__('Email: %s'), $email_from); ?></div>
859 859
         <?php } ?>
860 860
     </div>
861 861
     <?php
862 862
 }
863 863
 
864
-function wpinv_watermark( $id = 0 ) {
865
-    $output = wpinv_get_watermark( $id );
864
+function wpinv_watermark($id = 0) {
865
+    $output = wpinv_get_watermark($id);
866 866
     
867
-    return apply_filters( 'wpinv_get_watermark', $output, $id );
867
+    return apply_filters('wpinv_get_watermark', $output, $id);
868 868
 }
869 869
 
870
-function wpinv_get_watermark( $id ) {
871
-    if ( !$id > 0 ) {
870
+function wpinv_get_watermark($id) {
871
+    if (!$id > 0) {
872 872
         return NULL;
873 873
     }
874
-    $invoice = wpinv_get_invoice( $id );
874
+    $invoice = wpinv_get_invoice($id);
875 875
     
876
-    if ( !empty( $invoice ) ) {
877
-        if ( $invoice->is_paid() ) {
878
-            return __( 'Paid', 'invoicing' );
876
+    if (!empty($invoice)) {
877
+        if ($invoice->is_paid()) {
878
+            return __('Paid', 'invoicing');
879 879
         }
880
-        if ( $invoice->has_status( array( 'cancelled' ) ) ) {
881
-            return __( 'Cancelled', 'invoicing' );
880
+        if ($invoice->has_status(array('cancelled'))) {
881
+            return __('Cancelled', 'invoicing');
882 882
         }
883 883
     }
884 884
     
885 885
     return NULL;
886 886
 }
887 887
 
888
-function wpinv_display_invoice_details( $invoice ) {
888
+function wpinv_display_invoice_details($invoice) {
889 889
     global $wpinv_euvat;
890 890
     
891 891
     $invoice_id = $invoice->ID;
892 892
     $vat_name   = $wpinv_euvat->get_vat_name();
893 893
     
894
-    $invoice_status = wpinv_get_invoice_status( $invoice_id );
894
+    $invoice_status = wpinv_get_invoice_status($invoice_id);
895 895
     ?>
896 896
     <table class="table table-bordered table-sm">
897
-        <?php if ( $invoice_number = wpinv_get_invoice_number( $invoice_id ) ) { ?>
897
+        <?php if ($invoice_number = wpinv_get_invoice_number($invoice_id)) { ?>
898 898
             <tr class="wpi-row-number">
899
-                <th><?php _e( 'Invoice Number', 'invoicing' ); ?></th>
900
-                <td><?php echo esc_html( $invoice_number ); ?></td>
899
+                <th><?php _e('Invoice Number', 'invoicing'); ?></th>
900
+                <td><?php echo esc_html($invoice_number); ?></td>
901 901
             </tr>
902 902
         <?php } ?>
903 903
         <tr class="wpi-row-status">
904
-            <th><?php _e( 'Invoice Status', 'invoicing' ); ?></th>
905
-            <td><?php echo wpinv_invoice_status_label( $invoice_status, wpinv_get_invoice_status( $invoice_id, true ) ); ?></td>
904
+            <th><?php _e('Invoice Status', 'invoicing'); ?></th>
905
+            <td><?php echo wpinv_invoice_status_label($invoice_status, wpinv_get_invoice_status($invoice_id, true)); ?></td>
906 906
         </tr>
907
-        <?php if ( $invoice->is_renewal() ) { ?>
907
+        <?php if ($invoice->is_renewal()) { ?>
908 908
         <tr class="wpi-row-parent">
909
-            <th><?php _e( 'Parent Invoice', 'invoicing' ); ?></th>
910
-            <td><?php echo wpinv_invoice_link( $invoice->parent_invoice ); ?></td>
909
+            <th><?php _e('Parent Invoice', 'invoicing'); ?></th>
910
+            <td><?php echo wpinv_invoice_link($invoice->parent_invoice); ?></td>
911 911
         </tr>
912 912
         <?php } ?>
913 913
         <tr class="wpi-row-gateway">
914
-            <th><?php _e( 'Payment Method', 'invoicing' ); ?></th>
915
-            <td><?php echo wpinv_get_payment_gateway_name( $invoice_id ); ?></td>
914
+            <th><?php _e('Payment Method', 'invoicing'); ?></th>
915
+            <td><?php echo wpinv_get_payment_gateway_name($invoice_id); ?></td>
916 916
         </tr>
917
-        <?php if ( $invoice_date = wpinv_get_invoice_date( $invoice_id ) ) { ?>
917
+        <?php if ($invoice_date = wpinv_get_invoice_date($invoice_id)) { ?>
918 918
             <tr class="wpi-row-date">
919
-                <th><?php _e( 'Invoice Date', 'invoicing' ); ?></th>
919
+                <th><?php _e('Invoice Date', 'invoicing'); ?></th>
920 920
                 <td><?php echo $invoice_date; ?></td>
921 921
             </tr>
922 922
         <?php } ?>
923
-        <?php if ( wpinv_get_option( 'overdue_active' ) && $invoice->needs_payment() && ( $due_date = $invoice->get_due_date( true ) ) ) { ?>
923
+        <?php if (wpinv_get_option('overdue_active') && $invoice->needs_payment() && ($due_date = $invoice->get_due_date(true))) { ?>
924 924
             <tr class="wpi-row-date">
925
-                <th><?php _e( 'Due Date', 'invoicing' ); ?></th>
925
+                <th><?php _e('Due Date', 'invoicing'); ?></th>
926 926
                 <td><?php echo $due_date; ?></td>
927 927
             </tr>
928 928
         <?php } ?>
929
-        <?php if ( $owner_vat_number = $wpinv_euvat->get_vat_number() ) { ?>
929
+        <?php if ($owner_vat_number = $wpinv_euvat->get_vat_number()) { ?>
930 930
             <tr class="wpi-row-ovatno">
931
-                <th><?php echo wp_sprintf( __( 'Owner %s Number', 'invoicing' ), $vat_name ); ?></th>
931
+                <th><?php echo wp_sprintf(__('Owner %s Number', 'invoicing'), $vat_name); ?></th>
932 932
                 <td><?php echo $owner_vat_number; ?></td>
933 933
             </tr>
934 934
         <?php } ?>
935
-        <?php if ( $user_vat_number = wpinv_get_invoice_vat_number( $invoice_id ) ) { ?>
935
+        <?php if ($user_vat_number = wpinv_get_invoice_vat_number($invoice_id)) { ?>
936 936
             <tr class="wpi-row-uvatno">
937
-                <th><?php echo wp_sprintf( __( 'Your %s Number', 'invoicing' ), $vat_name ); ?></th>
937
+                <th><?php echo wp_sprintf(__('Your %s Number', 'invoicing'), $vat_name); ?></th>
938 938
                 <td><?php echo $user_vat_number; ?></td>
939 939
             </tr>
940 940
         <?php } ?>
941 941
         <tr class="table-active tr-total wpi-row-total">
942
-            <th><strong><?php _e( 'Total Amount', 'invoicing' ) ?></strong></th>
943
-            <td><strong><?php echo wpinv_payment_total( $invoice_id, true ); ?></strong></td>
942
+            <th><strong><?php _e('Total Amount', 'invoicing') ?></strong></th>
943
+            <td><strong><?php echo wpinv_payment_total($invoice_id, true); ?></strong></td>
944 944
         </tr>
945 945
     </table>
946 946
 <?php
947 947
 }
948 948
 
949
-function wpinv_display_to_address( $invoice_id = 0 ) {
950
-    $invoice = wpinv_get_invoice( $invoice_id );
949
+function wpinv_display_to_address($invoice_id = 0) {
950
+    $invoice = wpinv_get_invoice($invoice_id);
951 951
     
952
-    if ( empty( $invoice ) ) {
952
+    if (empty($invoice)) {
953 953
         return NULL;
954 954
     }
955 955
     
956 956
     $billing_details = $invoice->get_user_info();
957
-    $output = '<div class="to col-xs-2"><strong>' . __( 'To:', 'invoicing' ) . '</strong></div>';
957
+    $output = '<div class="to col-xs-2"><strong>' . __('To:', 'invoicing') . '</strong></div>';
958 958
     $output .= '<div class="wrapper col-xs-10">';
959 959
     
960 960
     ob_start();
961
-    do_action( 'wpinv_display_to_address_top', $invoice );
961
+    do_action('wpinv_display_to_address_top', $invoice);
962 962
     $output .= ob_get_clean();
963 963
     
964
-    $output .= '<div class="name">' . esc_html( trim( $billing_details['first_name'] . ' ' . $billing_details['last_name'] ) ) . '</div>';
965
-    if ( $company = $billing_details['company'] ) {
966
-        $output .= '<div class="company">' . wpautop( wp_kses_post( $company ) ) . '</div>';
964
+    $output .= '<div class="name">' . esc_html(trim($billing_details['first_name'] . ' ' . $billing_details['last_name'])) . '</div>';
965
+    if ($company = $billing_details['company']) {
966
+        $output .= '<div class="company">' . wpautop(wp_kses_post($company)) . '</div>';
967 967
     }
968 968
     $address_row = '';
969
-    if ( $address = $billing_details['address'] ) {
970
-        $address_row .= wpautop( wp_kses_post( $address ) );
969
+    if ($address = $billing_details['address']) {
970
+        $address_row .= wpautop(wp_kses_post($address));
971 971
     }
972 972
     
973 973
     $address_fields = array();
974
-    if ( !empty( $billing_details['city'] ) ) {
974
+    if (!empty($billing_details['city'])) {
975 975
         $address_fields[] = $billing_details['city'];
976 976
     }
977 977
     
978
-    $billing_country = !empty( $billing_details['country'] ) ? $billing_details['country'] : '';
979
-    if ( !empty( $billing_details['state'] ) ) {
980
-        $address_fields[] = wpinv_state_name( $billing_details['state'], $billing_country );
978
+    $billing_country = !empty($billing_details['country']) ? $billing_details['country'] : '';
979
+    if (!empty($billing_details['state'])) {
980
+        $address_fields[] = wpinv_state_name($billing_details['state'], $billing_country);
981 981
     }
982 982
     
983
-    if ( !empty( $billing_country ) ) {
984
-        $address_fields[] = wpinv_country_name( $billing_country );
983
+    if (!empty($billing_country)) {
984
+        $address_fields[] = wpinv_country_name($billing_country);
985 985
     }
986 986
     
987
-    if ( !empty( $address_fields ) ) {
988
-        $address_fields = implode( ", ", $address_fields );
987
+    if (!empty($address_fields)) {
988
+        $address_fields = implode(", ", $address_fields);
989 989
         
990
-        if ( !empty( $billing_details['zip'] ) ) {
990
+        if (!empty($billing_details['zip'])) {
991 991
             $address_fields .= ' ' . $billing_details['zip'];
992 992
         }
993 993
         
994
-        $address_row .= wpautop( wp_kses_post( $address_fields ) );
994
+        $address_row .= wpautop(wp_kses_post($address_fields));
995 995
     }
996 996
     
997
-    if ( $address_row ) {
997
+    if ($address_row) {
998 998
         $output .= '<div class="address">' . $address_row . '</div>';
999 999
     }
1000 1000
     
1001
-    if ( $phone = $invoice->get_phone() ) {
1002
-        $output .= '<div class="phone">' . wp_sprintf( __( 'Phone: %s' ), esc_html( $phone ) ) . '</div>';
1001
+    if ($phone = $invoice->get_phone()) {
1002
+        $output .= '<div class="phone">' . wp_sprintf(__('Phone: %s'), esc_html($phone)) . '</div>';
1003 1003
     }
1004
-    if ( $email = $invoice->get_email() ) {
1005
-        $output .= '<div class="email">' . wp_sprintf( __( 'Email: %s' ), esc_html( $email ) ) . '</div>';
1004
+    if ($email = $invoice->get_email()) {
1005
+        $output .= '<div class="email">' . wp_sprintf(__('Email: %s'), esc_html($email)) . '</div>';
1006 1006
     }
1007 1007
     
1008 1008
     ob_start();
1009
-    do_action( 'wpinv_display_to_address_bottom', $invoice );
1009
+    do_action('wpinv_display_to_address_bottom', $invoice);
1010 1010
     $output .= ob_get_clean();
1011 1011
     
1012 1012
     $output .= '</div>';
1013
-    $output = apply_filters( 'wpinv_display_to_address', $output, $invoice );
1013
+    $output = apply_filters('wpinv_display_to_address', $output, $invoice);
1014 1014
 
1015 1015
     echo $output;
1016 1016
 }
1017 1017
 
1018
-function wpinv_display_line_items( $invoice_id = 0 ) {
1018
+function wpinv_display_line_items($invoice_id = 0) {
1019 1019
     global $wpinv_euvat, $ajax_cart_details;
1020
-    $invoice            = wpinv_get_invoice( $invoice_id );
1020
+    $invoice            = wpinv_get_invoice($invoice_id);
1021 1021
     $quantities_enabled = wpinv_item_quantities_enabled();
1022 1022
     $use_taxes          = wpinv_use_taxes();
1023 1023
     $zero_tax           = !(float)$invoice->get_tax() > 0 ? true : false;
1024
-    $tax_label           = $use_taxes && $invoice->has_vat() ? $wpinv_euvat->get_vat_name() : __( 'Tax', 'invoicing' );
1025
-    $tax_title          = !$zero_tax && $use_taxes ? ( wpinv_prices_include_tax() ? wp_sprintf( __( '(%s Incl.)', 'invoicing' ), $tax_label ) : wp_sprintf( __( '(%s Excl.)', 'invoicing' ), $tax_label ) ) : '';
1024
+    $tax_label = $use_taxes && $invoice->has_vat() ? $wpinv_euvat->get_vat_name() : __('Tax', 'invoicing');
1025
+    $tax_title          = !$zero_tax && $use_taxes ? (wpinv_prices_include_tax() ? wp_sprintf(__('(%s Incl.)', 'invoicing'), $tax_label) : wp_sprintf(__('(%s Excl.)', 'invoicing'), $tax_label)) : '';
1026 1026
     
1027 1027
     $cart_details       = $invoice->get_cart_details();
1028 1028
     $ajax_cart_details  = $cart_details;
@@ -1031,67 +1031,67 @@  discard block
 block discarded – undo
1031 1031
     <table class="table table-sm table-bordered table-responsive">
1032 1032
         <thead>
1033 1033
             <tr>
1034
-                <th class="name"><strong><?php _e( "Item Name", "invoicing" );?></strong></th>
1035
-                <th class="rate"><strong><?php _e( "Price", "invoicing" );?></strong></th>
1034
+                <th class="name"><strong><?php _e("Item Name", "invoicing"); ?></strong></th>
1035
+                <th class="rate"><strong><?php _e("Price", "invoicing"); ?></strong></th>
1036 1036
                 <?php if ($quantities_enabled) { ?>
1037
-                    <th class="qty"><strong><?php _e( "Qty", "invoicing" );?></strong></th>
1037
+                    <th class="qty"><strong><?php _e("Qty", "invoicing"); ?></strong></th>
1038 1038
                 <?php } ?>
1039 1039
                 <?php if ($use_taxes && !$zero_tax) { ?>
1040 1040
                     <th class="tax"><strong><?php echo $tax_label . ' <span class="normal small">(%)</span>'; ?></strong></th>
1041 1041
                 <?php } ?>
1042
-                <th class="total"><strong><?php echo __( "Item Total", "invoicing" ) . ' <span class="normal small">' . $tax_title . '<span>';?></strong></th>
1042
+                <th class="total"><strong><?php echo __("Item Total", "invoicing") . ' <span class="normal small">' . $tax_title . '<span>'; ?></strong></th>
1043 1043
             </tr>
1044 1044
         </thead>
1045 1045
         <tbody>
1046 1046
         <?php 
1047
-            if ( !empty( $cart_details ) ) {
1048
-                do_action( 'wpinv_display_line_items_start', $invoice );
1047
+            if (!empty($cart_details)) {
1048
+                do_action('wpinv_display_line_items_start', $invoice);
1049 1049
                 
1050 1050
                 $count = 0;
1051
-                foreach ( $cart_details as $key => $cart_item ) {
1052
-                    $item_id    = !empty($cart_item['id']) ? absint( $cart_item['id'] ) : '';
1053
-                    $item_price = isset($cart_item["item_price"]) ? wpinv_format_amount( $cart_item["item_price"] ) : 0;
1054
-                    $line_total = isset($cart_item["subtotal"]) ? wpinv_format_amount( $cart_item["subtotal"] ) : 0;
1055
-                    $quantity   = !empty($cart_item['quantity']) && (int)$cart_item['quantity'] > 0 ? absint( $cart_item['quantity'] ) : 1;
1051
+                foreach ($cart_details as $key => $cart_item) {
1052
+                    $item_id    = !empty($cart_item['id']) ? absint($cart_item['id']) : '';
1053
+                    $item_price = isset($cart_item["item_price"]) ? wpinv_format_amount($cart_item["item_price"]) : 0;
1054
+                    $line_total = isset($cart_item["subtotal"]) ? wpinv_format_amount($cart_item["subtotal"]) : 0;
1055
+                    $quantity   = !empty($cart_item['quantity']) && (int)$cart_item['quantity'] > 0 ? absint($cart_item['quantity']) : 1;
1056 1056
                     
1057
-                    $item       = $item_id ? new WPInv_Item( $item_id ) : NULL;
1057
+                    $item       = $item_id ? new WPInv_Item($item_id) : NULL;
1058 1058
                     $summary    = '';
1059 1059
                     $cols       = 3;
1060
-                    if ( !empty($item) ) {
1060
+                    if (!empty($item)) {
1061 1061
                         $item_name  = $item->get_name();
1062 1062
                         $summary    = $item->get_summary();
1063 1063
                     }
1064
-                    $item_name  = !empty($cart_item['name']) ? $cart_item['name'] : $item_name;
1064
+                    $item_name = !empty($cart_item['name']) ? $cart_item['name'] : $item_name;
1065 1065
                     
1066 1066
                     if (!empty($item) && $item->is_package() && !empty($cart_item['meta']['post_id'])) {
1067
-                        $post_link = '<a href="' . get_edit_post_link( $cart_item['meta']['post_id'] ) .'" target="_blank">' . (!empty($cart_item['meta']['invoice_title']) ? $cart_item['meta']['invoice_title'] : get_the_title( $cart_item['meta']['post_id']) ) . '</a>';
1068
-                        $summary = wp_sprintf( __( '%s: %s', 'invoicing' ), $item->get_cpt_singular_name(), $post_link );
1067
+                        $post_link = '<a href="' . get_edit_post_link($cart_item['meta']['post_id']) . '" target="_blank">' . (!empty($cart_item['meta']['invoice_title']) ? $cart_item['meta']['invoice_title'] : get_the_title($cart_item['meta']['post_id'])) . '</a>';
1068
+                        $summary = wp_sprintf(__('%s: %s', 'invoicing'), $item->get_cpt_singular_name(), $post_link);
1069 1069
                     }
1070
-                    $summary = apply_filters( 'wpinv_print_invoice_line_item_summary', $summary, $cart_item, $item, $invoice );
1070
+                    $summary = apply_filters('wpinv_print_invoice_line_item_summary', $summary, $cart_item, $item, $invoice);
1071 1071
                     
1072 1072
                     $item_tax       = '';
1073 1073
                     $tax_rate       = '';
1074
-                    if ( $use_taxes && $cart_item['tax'] > 0 && $cart_item['subtotal'] > 0 ) {
1075
-                        $item_tax = wpinv_price( wpinv_format_amount( $cart_item['tax'] ) );
1076
-                        $tax_rate = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : ( $cart_item['tax'] / $cart_item['subtotal'] ) * 100;
1077
-                        $tax_rate = $tax_rate > 0 ? (float)wpinv_format_amount( $tax_rate, 2 ) : '';
1074
+                    if ($use_taxes && $cart_item['tax'] > 0 && $cart_item['subtotal'] > 0) {
1075
+                        $item_tax = wpinv_price(wpinv_format_amount($cart_item['tax']));
1076
+                        $tax_rate = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : ($cart_item['tax'] / $cart_item['subtotal']) * 100;
1077
+                        $tax_rate = $tax_rate > 0 ? (float)wpinv_format_amount($tax_rate, 2) : '';
1078 1078
                         $tax_rate = $tax_rate != '' ? ' <small class="tax-rate">(' . $tax_rate . '%)</small>' : '';
1079 1079
                     }
1080 1080
                     
1081 1081
                     $line_item_tax = $item_tax . $tax_rate;
1082 1082
                     
1083
-                    if ( $line_item_tax === '' ) {
1083
+                    if ($line_item_tax === '') {
1084 1084
                         $line_item_tax = 0; // Zero tax
1085 1085
                     }
1086 1086
                     
1087
-                    $line_item = '<tr class="row-' . ( ($count % 2 == 0) ? 'even' : 'odd' ) . ' wpinv-item">';
1088
-                        $line_item .= '<td class="name">' . esc_html__( $item_name, 'invoicing' ) . wpinv_get_item_suffix( $item );
1089
-                        if ( $summary !== '' ) {
1090
-                            $line_item .= '<br/><small class="meta">' . wpautop( wp_kses_post( $summary ) ) . '</small>';
1087
+                    $line_item = '<tr class="row-' . (($count % 2 == 0) ? 'even' : 'odd') . ' wpinv-item">';
1088
+                        $line_item .= '<td class="name">' . esc_html__($item_name, 'invoicing') . wpinv_get_item_suffix($item);
1089
+                        if ($summary !== '') {
1090
+                            $line_item .= '<br/><small class="meta">' . wpautop(wp_kses_post($summary)) . '</small>';
1091 1091
                         }
1092 1092
                         $line_item .= '</td>';
1093 1093
                         
1094
-                        $line_item .= '<td class="rate">' . esc_html__( wpinv_price( $item_price, $invoice->get_currency() ) ) . '</td>';
1094
+                        $line_item .= '<td class="rate">' . esc_html__(wpinv_price($item_price, $invoice->get_currency())) . '</td>';
1095 1095
                         if ($quantities_enabled) {
1096 1096
                             $cols++;
1097 1097
                             $line_item .= '<td class="qty">' . $quantity . '</td>';
@@ -1100,55 +1100,55 @@  discard block
 block discarded – undo
1100 1100
                             $cols++;
1101 1101
                             $line_item .= '<td class="tax">' . $line_item_tax . '</td>';
1102 1102
                         }
1103
-                        $line_item .= '<td class="total">' . esc_html__( wpinv_price( $line_total, $invoice->get_currency() ) ) . '</td>';
1103
+                        $line_item .= '<td class="total">' . esc_html__(wpinv_price($line_total, $invoice->get_currency())) . '</td>';
1104 1104
                     $line_item .= '</tr>';
1105 1105
                     
1106
-                    echo apply_filters( 'wpinv_display_line_item', $line_item, $cart_item, $invoice, $cols );
1106
+                    echo apply_filters('wpinv_display_line_item', $line_item, $cart_item, $invoice, $cols);
1107 1107
 
1108 1108
                     $count++;
1109 1109
                 }
1110 1110
                 
1111
-                do_action( 'wpinv_display_before_subtotal', $invoice, $cols );
1111
+                do_action('wpinv_display_before_subtotal', $invoice, $cols);
1112 1112
                 ?>
1113 1113
                 <tr class="row-sub-total row_odd">
1114
-                    <td class="rate" colspan="<?php echo ( $cols - 1 ); ?>"><?php echo apply_filters( 'wpinv_print_cart_subtotal_label', '<strong>' . __( 'Sub Total', 'invoicing' ) . ':</strong>', $invoice ); ?></td>
1115
-                    <td class="total"><strong><?php _e( wpinv_subtotal( $invoice_id, true ) ) ?></strong></td>
1114
+                    <td class="rate" colspan="<?php echo ($cols - 1); ?>"><?php echo apply_filters('wpinv_print_cart_subtotal_label', '<strong>' . __('Sub Total', 'invoicing') . ':</strong>', $invoice); ?></td>
1115
+                    <td class="total"><strong><?php _e(wpinv_subtotal($invoice_id, true)) ?></strong></td>
1116 1116
                 </tr>
1117 1117
                 <?php
1118
-                do_action( 'wpinv_display_after_subtotal', $invoice, $cols );
1118
+                do_action('wpinv_display_after_subtotal', $invoice, $cols);
1119 1119
                 
1120
-                if ( wpinv_discount( $invoice_id, false ) > 0 ) {
1121
-                    do_action( 'wpinv_display_before_discount', $invoice, $cols );
1120
+                if (wpinv_discount($invoice_id, false) > 0) {
1121
+                    do_action('wpinv_display_before_discount', $invoice, $cols);
1122 1122
                     ?>
1123 1123
                         <tr class="row-discount">
1124
-                            <td class="rate" colspan="<?php echo ( $cols - 1 ); ?>"><?php wpinv_get_discount_label( wpinv_discount_code( $invoice_id ) ); ?>:</td>
1125
-                            <td class="total"><?php echo wpinv_discount( $invoice_id, true, true ); ?></td>
1124
+                            <td class="rate" colspan="<?php echo ($cols - 1); ?>"><?php wpinv_get_discount_label(wpinv_discount_code($invoice_id)); ?>:</td>
1125
+                            <td class="total"><?php echo wpinv_discount($invoice_id, true, true); ?></td>
1126 1126
                         </tr>
1127 1127
                     <?php
1128
-                    do_action( 'wpinv_display_after_discount', $invoice, $cols );
1128
+                    do_action('wpinv_display_after_discount', $invoice, $cols);
1129 1129
                 }
1130 1130
                 
1131
-                if ( $use_taxes ) {
1132
-                    do_action( 'wpinv_display_before_tax', $invoice, $cols );
1131
+                if ($use_taxes) {
1132
+                    do_action('wpinv_display_before_tax', $invoice, $cols);
1133 1133
                     ?>
1134 1134
                     <tr class="row-tax">
1135
-                        <td class="rate" colspan="<?php echo ( $cols - 1 ); ?>"><?php echo apply_filters( 'wpinv_print_cart_tax_label', '<strong>' . $tax_label . ':</strong>', $invoice ); ?></td>
1136
-                        <td class="total"><?php _e( wpinv_tax( $invoice_id, true ) ) ?></td>
1135
+                        <td class="rate" colspan="<?php echo ($cols - 1); ?>"><?php echo apply_filters('wpinv_print_cart_tax_label', '<strong>' . $tax_label . ':</strong>', $invoice); ?></td>
1136
+                        <td class="total"><?php _e(wpinv_tax($invoice_id, true)) ?></td>
1137 1137
                     </tr>
1138 1138
                     <?php
1139
-                    do_action( 'wpinv_display_after_tax', $invoice, $cols );
1139
+                    do_action('wpinv_display_after_tax', $invoice, $cols);
1140 1140
                 }
1141 1141
                 
1142
-                do_action( 'wpinv_display_before_total', $invoice, $cols );
1142
+                do_action('wpinv_display_before_total', $invoice, $cols);
1143 1143
                 ?>
1144 1144
                 <tr class="table-active row-total">
1145
-                    <td class="rate" colspan="<?php echo ( $cols - 1 ); ?>"><?php echo apply_filters( 'wpinv_print_cart_total_label', '<strong>' . __( 'Total', 'invoicing' ) . ':</strong>', $invoice ); ?></td>
1146
-                    <td class="total"><strong><?php _e( wpinv_payment_total( $invoice_id, true ) ) ?></strong></td>
1145
+                    <td class="rate" colspan="<?php echo ($cols - 1); ?>"><?php echo apply_filters('wpinv_print_cart_total_label', '<strong>' . __('Total', 'invoicing') . ':</strong>', $invoice); ?></td>
1146
+                    <td class="total"><strong><?php _e(wpinv_payment_total($invoice_id, true)) ?></strong></td>
1147 1147
                 </tr>
1148 1148
                 <?php
1149
-                do_action( 'wpinv_display_after_total', $invoice, $cols );
1149
+                do_action('wpinv_display_after_total', $invoice, $cols);
1150 1150
                 
1151
-                do_action( 'wpinv_display_line_end', $invoice, $cols );
1151
+                do_action('wpinv_display_line_end', $invoice, $cols);
1152 1152
             }
1153 1153
         ?>
1154 1154
         </tbody>
@@ -1157,35 +1157,35 @@  discard block
 block discarded – undo
1157 1157
     echo ob_get_clean();
1158 1158
 }
1159 1159
 
1160
-function wpinv_display_invoice_totals( $invoice_id = 0 ) {    
1160
+function wpinv_display_invoice_totals($invoice_id = 0) {    
1161 1161
     $use_taxes = wpinv_use_taxes();
1162 1162
     
1163
-    do_action( 'wpinv_before_display_totals_table', $invoice_id ); 
1163
+    do_action('wpinv_before_display_totals_table', $invoice_id); 
1164 1164
     ?>
1165 1165
     <table class="table table-sm table-bordered table-responsive">
1166 1166
         <tbody>
1167
-            <?php do_action( 'wpinv_before_display_totals' ); ?>
1167
+            <?php do_action('wpinv_before_display_totals'); ?>
1168 1168
             <tr class="row-sub-total">
1169
-                <td class="rate"><strong><?php _e( 'Sub Total', 'invoicing' ); ?></strong></td>
1170
-                <td class="total"><strong><?php _e( wpinv_subtotal( $invoice_id, true ) ) ?></strong></td>
1169
+                <td class="rate"><strong><?php _e('Sub Total', 'invoicing'); ?></strong></td>
1170
+                <td class="total"><strong><?php _e(wpinv_subtotal($invoice_id, true)) ?></strong></td>
1171 1171
             </tr>
1172
-            <?php do_action( 'wpinv_after_display_totals' ); ?>
1173
-            <?php if ( wpinv_discount( $invoice_id, false ) > 0 ) { ?>
1172
+            <?php do_action('wpinv_after_display_totals'); ?>
1173
+            <?php if (wpinv_discount($invoice_id, false) > 0) { ?>
1174 1174
                 <tr class="row-discount">
1175
-                    <td class="rate"><?php wpinv_get_discount_label( wpinv_discount_code( $invoice_id ) ); ?></td>
1176
-                    <td class="total"><?php echo wpinv_discount( $invoice_id, true, true ); ?></td>
1175
+                    <td class="rate"><?php wpinv_get_discount_label(wpinv_discount_code($invoice_id)); ?></td>
1176
+                    <td class="total"><?php echo wpinv_discount($invoice_id, true, true); ?></td>
1177 1177
                 </tr>
1178
-            <?php do_action( 'wpinv_after_display_discount' ); ?>
1178
+            <?php do_action('wpinv_after_display_discount'); ?>
1179 1179
             <?php } ?>
1180
-            <?php if ( $use_taxes ) { ?>
1180
+            <?php if ($use_taxes) { ?>
1181 1181
             <tr class="row-tax">
1182
-                <td class="rate"><?php _e( 'Tax', 'invoicing' ); ?></td>
1183
-                <td class="total"><?php _e( wpinv_tax( $invoice_id, true ) ) ?></td>
1182
+                <td class="rate"><?php _e('Tax', 'invoicing'); ?></td>
1183
+                <td class="total"><?php _e(wpinv_tax($invoice_id, true)) ?></td>
1184 1184
             </tr>
1185
-            <?php do_action( 'wpinv_after_display_tax' ); ?>
1185
+            <?php do_action('wpinv_after_display_tax'); ?>
1186 1186
             <?php } ?>
1187
-            <?php if ( $fees = wpinv_get_fees( $invoice_id ) ) { ?>
1188
-                <?php foreach ( $fees as $fee ) { ?>
1187
+            <?php if ($fees = wpinv_get_fees($invoice_id)) { ?>
1188
+                <?php foreach ($fees as $fee) { ?>
1189 1189
                     <tr class="row-fee">
1190 1190
                         <td class="rate"><?php echo $fee['label']; ?></td>
1191 1191
                         <td class="total"><?php echo $fee['amount_display']; ?></td>
@@ -1193,72 +1193,72 @@  discard block
 block discarded – undo
1193 1193
                 <?php } ?>
1194 1194
             <?php } ?>
1195 1195
             <tr class="table-active row-total">
1196
-                <td class="rate"><strong><?php _e( 'Total', 'invoicing' ) ?></strong></td>
1197
-                <td class="total"><strong><?php _e( wpinv_payment_total( $invoice_id, true ) ) ?></strong></td>
1196
+                <td class="rate"><strong><?php _e('Total', 'invoicing') ?></strong></td>
1197
+                <td class="total"><strong><?php _e(wpinv_payment_total($invoice_id, true)) ?></strong></td>
1198 1198
             </tr>
1199
-            <?php do_action( 'wpinv_after_totals' ); ?>
1199
+            <?php do_action('wpinv_after_totals'); ?>
1200 1200
         </tbody>
1201 1201
 
1202 1202
     </table>
1203 1203
 
1204
-    <?php do_action( 'wpinv_after_totals_table' );
1204
+    <?php do_action('wpinv_after_totals_table');
1205 1205
 }
1206 1206
 
1207
-function wpinv_display_payments_info( $invoice_id = 0, $echo = true ) {
1208
-    $invoice = wpinv_get_invoice( $invoice_id );
1207
+function wpinv_display_payments_info($invoice_id = 0, $echo = true) {
1208
+    $invoice = wpinv_get_invoice($invoice_id);
1209 1209
     
1210 1210
     ob_start();
1211
-    do_action( 'wpinv_before_display_payments_info', $invoice_id );
1212
-    if ( ( $gateway_title = $invoice->get_gateway_title() ) || $invoice->is_paid() ) {
1211
+    do_action('wpinv_before_display_payments_info', $invoice_id);
1212
+    if (($gateway_title = $invoice->get_gateway_title()) || $invoice->is_paid()) {
1213 1213
         ?>
1214 1214
         <div class="wpi-payment-info">
1215
-            <p class="wpi-payment-gateway"><?php echo wp_sprintf( __( 'Payment via %s', 'invoicing' ), $gateway_title ? $gateway_title : __( 'Manually', 'invoicing' ) ); ?></p>
1216
-            <?php if ( $gateway_title ) { ?>
1217
-            <p class="wpi-payment-transid"><?php echo wp_sprintf( __( 'Transaction ID: %s', 'invoicing' ), $invoice->get_transaction_id() ); ?></p>
1215
+            <p class="wpi-payment-gateway"><?php echo wp_sprintf(__('Payment via %s', 'invoicing'), $gateway_title ? $gateway_title : __('Manually', 'invoicing')); ?></p>
1216
+            <?php if ($gateway_title) { ?>
1217
+            <p class="wpi-payment-transid"><?php echo wp_sprintf(__('Transaction ID: %s', 'invoicing'), $invoice->get_transaction_id()); ?></p>
1218 1218
             <?php } ?>
1219 1219
         </div>
1220 1220
         <?php
1221 1221
     }
1222
-    do_action( 'wpinv_after_display_payments_info', $invoice_id );
1222
+    do_action('wpinv_after_display_payments_info', $invoice_id);
1223 1223
     $outout = ob_get_clean();
1224 1224
     
1225
-    if ( $echo ) {
1225
+    if ($echo) {
1226 1226
         echo $outout;
1227 1227
     } else {
1228 1228
         return $outout;
1229 1229
     }
1230 1230
 }
1231 1231
 
1232
-function wpinv_display_style( $invoice ) {
1233
-    wp_register_style( 'wpinv-single-style', WPINV_PLUGIN_URL . 'assets/css/invoice.css', array(), WPINV_VERSION );
1232
+function wpinv_display_style($invoice) {
1233
+    wp_register_style('wpinv-single-style', WPINV_PLUGIN_URL . 'assets/css/invoice.css', array(), WPINV_VERSION);
1234 1234
     
1235
-    wp_print_styles( 'open-sans' );
1236
-    wp_print_styles( 'wpinv-single-style' );
1235
+    wp_print_styles('open-sans');
1236
+    wp_print_styles('wpinv-single-style');
1237 1237
 }
1238
-add_action( 'wpinv_invoice_print_head', 'wpinv_display_style' );
1238
+add_action('wpinv_invoice_print_head', 'wpinv_display_style');
1239 1239
 
1240 1240
 function wpinv_checkout_billing_details() {  
1241 1241
     $invoice_id = (int)wpinv_get_invoice_cart_id();
1242 1242
     if (empty($invoice_id)) {
1243
-        wpinv_error_log( 'Invoice id not found', 'ERROR', __FILE__, __LINE__ );
1243
+        wpinv_error_log('Invoice id not found', 'ERROR', __FILE__, __LINE__);
1244 1244
         return null;
1245 1245
     }
1246 1246
     
1247
-    $invoice = wpinv_get_invoice_cart( $invoice_id );
1247
+    $invoice = wpinv_get_invoice_cart($invoice_id);
1248 1248
     if (empty($invoice)) {
1249
-        wpinv_error_log( 'Invoice not found', 'ERROR', __FILE__, __LINE__ );
1249
+        wpinv_error_log('Invoice not found', 'ERROR', __FILE__, __LINE__);
1250 1250
         return null;
1251 1251
     }
1252 1252
     $user_id        = $invoice->get_user_id();
1253 1253
     $user_info      = $invoice->get_user_info();
1254
-    $address_info   = wpinv_get_user_address( $user_id );
1254
+    $address_info   = wpinv_get_user_address($user_id);
1255 1255
     
1256
-    if ( empty( $user_info['first_name'] ) && !empty( $user_info['first_name'] ) ) {
1256
+    if (empty($user_info['first_name']) && !empty($user_info['first_name'])) {
1257 1257
         $user_info['first_name'] = $user_info['first_name'];
1258 1258
         $user_info['last_name'] = $user_info['last_name'];
1259 1259
     }
1260 1260
     
1261
-    if ( ( ( empty( $user_info['country'] ) && !empty( $address_info['country'] ) ) || ( empty( $user_info['state'] ) && !empty( $address_info['state'] ) && $user_info['country'] == $address_info['country'] ) ) ) {
1261
+    if (((empty($user_info['country']) && !empty($address_info['country'])) || (empty($user_info['state']) && !empty($address_info['state']) && $user_info['country'] == $address_info['country']))) {
1262 1262
         $user_info['country']   = $address_info['country'];
1263 1263
         $user_info['state']     = $address_info['state'];
1264 1264
         $user_info['city']      = $address_info['city'];
@@ -1274,103 +1274,103 @@  discard block
 block discarded – undo
1274 1274
         'address'
1275 1275
     );
1276 1276
     
1277
-    foreach ( $address_fields as $field ) {
1278
-        if ( empty( $user_info[$field] ) ) {
1277
+    foreach ($address_fields as $field) {
1278
+        if (empty($user_info[$field])) {
1279 1279
             $user_info[$field] = $address_info[$field];
1280 1280
         }
1281 1281
     }
1282 1282
     
1283
-    return apply_filters( 'wpinv_checkout_billing_details', $user_info, $invoice );
1283
+    return apply_filters('wpinv_checkout_billing_details', $user_info, $invoice);
1284 1284
 }
1285 1285
 
1286 1286
 function wpinv_admin_get_line_items($invoice = array()) {
1287 1287
     $item_quantities    = wpinv_item_quantities_enabled();
1288 1288
     $use_taxes          = wpinv_use_taxes();
1289 1289
     
1290
-    if ( empty( $invoice ) ) {
1290
+    if (empty($invoice)) {
1291 1291
         return NULL;
1292 1292
     }
1293 1293
     
1294 1294
     $cart_items = $invoice->get_cart_details();
1295
-    if ( empty( $cart_items ) ) {
1295
+    if (empty($cart_items)) {
1296 1296
         return NULL;
1297 1297
     }
1298 1298
     ob_start();
1299 1299
     
1300
-    do_action( 'wpinv_admin_before_line_items', $cart_items, $invoice );
1300
+    do_action('wpinv_admin_before_line_items', $cart_items, $invoice);
1301 1301
     
1302 1302
     $count = 0;
1303
-    foreach ( $cart_items as $key => $cart_item ) {
1303
+    foreach ($cart_items as $key => $cart_item) {
1304 1304
         $item_id    = $cart_item['id'];
1305
-        $wpi_item   = $item_id > 0 ? new WPInv_Item( $item_id ) : NULL;
1305
+        $wpi_item   = $item_id > 0 ? new WPInv_Item($item_id) : NULL;
1306 1306
         
1307 1307
         if (empty($wpi_item)) {
1308 1308
             continue;
1309 1309
         }
1310 1310
         
1311
-        $item_price     = wpinv_price( wpinv_format_amount( $cart_item['item_price'] ) );
1312
-        $quantity       = !empty( $cart_item['quantity'] ) && $cart_item['quantity'] > 0 ? $cart_item['quantity'] : 1;
1313
-        $item_subtotal  = wpinv_price( wpinv_format_amount( $cart_item['subtotal'] ) );
1311
+        $item_price     = wpinv_price(wpinv_format_amount($cart_item['item_price']));
1312
+        $quantity       = !empty($cart_item['quantity']) && $cart_item['quantity'] > 0 ? $cart_item['quantity'] : 1;
1313
+        $item_subtotal  = wpinv_price(wpinv_format_amount($cart_item['subtotal']));
1314 1314
         $can_remove     = true;
1315 1315
         
1316 1316
         $summary = '';
1317 1317
         if ($wpi_item->is_package() && !empty($cart_item['meta']['post_id'])) {
1318
-            $post_link = '<a href="' . get_edit_post_link( $cart_item['meta']['post_id'] ) .'" target="_blank">' . (!empty($cart_item['meta']['invoice_title']) ? $cart_item['meta']['invoice_title'] : get_the_title( $cart_item['meta']['post_id']) ) . '</a>';
1319
-            $summary = wp_sprintf( __( '%s: %s', 'invoicing' ), $wpi_item->get_cpt_singular_name(), $post_link );
1318
+            $post_link = '<a href="' . get_edit_post_link($cart_item['meta']['post_id']) . '" target="_blank">' . (!empty($cart_item['meta']['invoice_title']) ? $cart_item['meta']['invoice_title'] : get_the_title($cart_item['meta']['post_id'])) . '</a>';
1319
+            $summary = wp_sprintf(__('%s: %s', 'invoicing'), $wpi_item->get_cpt_singular_name(), $post_link);
1320 1320
         }
1321
-        $summary = apply_filters( 'wpinv_admin_invoice_line_item_summary', $summary, $cart_item, $wpi_item, $invoice );
1321
+        $summary = apply_filters('wpinv_admin_invoice_line_item_summary', $summary, $cart_item, $wpi_item, $invoice);
1322 1322
         
1323 1323
         $item_tax       = '';
1324 1324
         $tax_rate       = '';
1325
-        if ( $cart_item['tax'] > 0 && $cart_item['subtotal'] > 0 ) {
1326
-            $item_tax = wpinv_price( wpinv_format_amount( $cart_item['tax'] ) );
1327
-            $tax_rate = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : ( $cart_item['tax'] / $cart_item['subtotal'] ) * 100;
1328
-            $tax_rate = $tax_rate > 0 ? (float)wpinv_format_amount( $tax_rate, 2 ) : '';
1325
+        if ($cart_item['tax'] > 0 && $cart_item['subtotal'] > 0) {
1326
+            $item_tax = wpinv_price(wpinv_format_amount($cart_item['tax']));
1327
+            $tax_rate = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : ($cart_item['tax'] / $cart_item['subtotal']) * 100;
1328
+            $tax_rate = $tax_rate > 0 ? (float)wpinv_format_amount($tax_rate, 2) : '';
1329 1329
             $tax_rate = $tax_rate != '' ? ' <span class="tax-rate">(' . $tax_rate . '%)</span>' : '';
1330 1330
         }
1331 1331
         $line_item_tax = $item_tax . $tax_rate;
1332 1332
         
1333
-        if ( $line_item_tax === '' ) {
1333
+        if ($line_item_tax === '') {
1334 1334
             $line_item_tax = 0; // Zero tax
1335 1335
         }
1336 1336
 
1337
-        $line_item = '<tr class="item item-' . ( ($count % 2 == 0) ? 'even' : 'odd' ) . '" data-item-id="' . $item_id . '">';
1337
+        $line_item = '<tr class="item item-' . (($count % 2 == 0) ? 'even' : 'odd') . '" data-item-id="' . $item_id . '">';
1338 1338
             $line_item .= '<td class="id">' . $item_id . '</td>';
1339
-            $line_item .= '<td class="title"><a href="' . get_edit_post_link( $item_id ) . '" target="_blank">' . $cart_item['name'] . '</a>' . wpinv_get_item_suffix( $wpi_item );
1340
-            if ( $summary !== '' ) {
1341
-                $line_item .= '<span class="meta">' . wpautop( wp_kses_post( $summary ) ) . '</span>';
1339
+            $line_item .= '<td class="title"><a href="' . get_edit_post_link($item_id) . '" target="_blank">' . $cart_item['name'] . '</a>' . wpinv_get_item_suffix($wpi_item);
1340
+            if ($summary !== '') {
1341
+                $line_item .= '<span class="meta">' . wpautop(wp_kses_post($summary)) . '</span>';
1342 1342
             }
1343 1343
             $line_item .= '</td>';
1344 1344
             $line_item .= '<td class="price">' . $item_price . '</td>';
1345 1345
             
1346
-            if ( $item_quantities ) {
1347
-                if ( count( $cart_items ) == 1 && $quantity <= 1 ) {
1346
+            if ($item_quantities) {
1347
+                if (count($cart_items) == 1 && $quantity <= 1) {
1348 1348
                     $can_remove = false;
1349 1349
                 }
1350 1350
                 $line_item .= '<td class="qty" data-quantity="' . $quantity . '">&nbsp;&times;&nbsp;' . $quantity . '</td>';
1351 1351
             } else {
1352
-                if ( count( $cart_items ) == 1 ) {
1352
+                if (count($cart_items) == 1) {
1353 1353
                     $can_remove = false;
1354 1354
                 }
1355 1355
             }
1356 1356
             $line_item .= '<td class="total">' . $item_subtotal . '</td>';
1357 1357
             
1358
-            if ( $use_taxes ) {
1358
+            if ($use_taxes) {
1359 1359
                 $line_item .= '<td class="tax">' . $line_item_tax . '</td>';
1360 1360
             }
1361 1361
             $line_item .= '<td class="action">';
1362
-            if ( !$invoice->is_paid() && $can_remove ) {
1362
+            if (!$invoice->is_paid() && $can_remove) {
1363 1363
                 $line_item .= '<i class="fa fa-remove wpinv-item-remove"></i>';
1364 1364
             }
1365 1365
             $line_item .= '</td>';
1366 1366
         $line_item .= '</tr>';
1367 1367
         
1368
-        echo apply_filters( 'wpinv_admin_line_item', $line_item, $cart_item, $invoice );
1368
+        echo apply_filters('wpinv_admin_line_item', $line_item, $cart_item, $invoice);
1369 1369
         
1370 1370
         $count++;
1371 1371
     } 
1372 1372
     
1373
-    do_action( 'wpinv_admin_after_line_items', $cart_items, $invoice );
1373
+    do_action('wpinv_admin_after_line_items', $cart_items, $invoice);
1374 1374
     
1375 1375
     return ob_get_clean();
1376 1376
 }
@@ -1381,35 +1381,35 @@  discard block
 block discarded – undo
1381 1381
     // Set current invoice id.
1382 1382
     $wpi_checkout_id = wpinv_get_invoice_cart_id();
1383 1383
     
1384
-    $form_action  = esc_url( wpinv_get_checkout_uri() );
1384
+    $form_action = esc_url(wpinv_get_checkout_uri());
1385 1385
 
1386 1386
     ob_start();
1387 1387
         echo '<div id="wpinv_checkout_wrap">';
1388 1388
         
1389
-        if ( wpinv_get_cart_contents() || wpinv_cart_has_fees() ) {
1389
+        if (wpinv_get_cart_contents() || wpinv_cart_has_fees()) {
1390 1390
             ?>
1391 1391
             <div id="wpinv_checkout_form_wrap" class="wpinv_clearfix table-responsive">
1392
-                <?php do_action( 'wpinv_before_checkout_form' ); ?>
1392
+                <?php do_action('wpinv_before_checkout_form'); ?>
1393 1393
                 <form id="wpinv_checkout_form" class="wpi-form" action="<?php echo $form_action; ?>" method="POST">
1394 1394
                     <?php
1395
-                    do_action( 'wpinv_checkout_form_top' );
1396
-                    do_action( 'wpinv_checkout_billing_info' );
1397
-                    do_action( 'wpinv_checkout_cart' );
1398
-                    do_action( 'wpinv_payment_mode_select'  );
1399
-                    do_action( 'wpinv_checkout_form_bottom' )
1395
+                    do_action('wpinv_checkout_form_top');
1396
+                    do_action('wpinv_checkout_billing_info');
1397
+                    do_action('wpinv_checkout_cart');
1398
+                    do_action('wpinv_payment_mode_select');
1399
+                    do_action('wpinv_checkout_form_bottom')
1400 1400
                     ?>
1401 1401
                 </form>
1402
-                <?php do_action( 'wpinv_after_purchase_form' ); ?>
1402
+                <?php do_action('wpinv_after_purchase_form'); ?>
1403 1403
             </div><!--end #wpinv_checkout_form_wrap-->
1404 1404
         <?php
1405 1405
         } else {
1406
-            do_action( 'wpinv_cart_empty' );
1406
+            do_action('wpinv_cart_empty');
1407 1407
         }
1408 1408
         echo '</div><!--end #wpinv_checkout_wrap-->';
1409 1409
     return ob_get_clean();
1410 1410
 }
1411 1411
 
1412
-function wpinv_checkout_cart( $cart_details = array(), $echo = true ) {
1412
+function wpinv_checkout_cart($cart_details = array(), $echo = true) {
1413 1413
     global $ajax_cart_details;
1414 1414
     $ajax_cart_details = $cart_details;
1415 1415
     /*
@@ -1424,25 +1424,25 @@  discard block
 block discarded – undo
1424 1424
     }
1425 1425
     */
1426 1426
     ob_start();
1427
-    do_action( 'wpinv_before_checkout_cart' );
1427
+    do_action('wpinv_before_checkout_cart');
1428 1428
     echo '<div id="wpinv_checkout_cart_form" method="post">';
1429 1429
         echo '<div id="wpinv_checkout_cart_wrap">';
1430
-            wpinv_get_template_part( 'wpinv-checkout-cart' );
1430
+            wpinv_get_template_part('wpinv-checkout-cart');
1431 1431
         echo '</div>';
1432 1432
     echo '</div>';
1433
-    do_action( 'wpinv_after_checkout_cart' );
1433
+    do_action('wpinv_after_checkout_cart');
1434 1434
     $content = ob_get_clean();
1435 1435
     
1436
-    if ( $echo ) {
1436
+    if ($echo) {
1437 1437
         echo $content;
1438 1438
     } else {
1439 1439
         return $content;
1440 1440
     }
1441 1441
 }
1442
-add_action( 'wpinv_checkout_cart', 'wpinv_checkout_cart', 10 );
1442
+add_action('wpinv_checkout_cart', 'wpinv_checkout_cart', 10);
1443 1443
 
1444 1444
 function wpinv_empty_cart_message() {
1445
-	return apply_filters( 'wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __( 'Your cart is empty.', 'invoicing' ) . '</span>' );
1445
+	return apply_filters('wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __('Your cart is empty.', 'invoicing') . '</span>');
1446 1446
 }
1447 1447
 
1448 1448
 /**
@@ -1454,91 +1454,91 @@  discard block
 block discarded – undo
1454 1454
 function wpinv_empty_checkout_cart() {
1455 1455
 	echo wpinv_empty_cart_message();
1456 1456
 }
1457
-add_action( 'wpinv_cart_empty', 'wpinv_empty_checkout_cart' );
1457
+add_action('wpinv_cart_empty', 'wpinv_empty_checkout_cart');
1458 1458
 
1459 1459
 function wpinv_save_cart_button() {
1460
-    if ( wpinv_is_cart_saving_disabled() )
1460
+    if (wpinv_is_cart_saving_disabled())
1461 1461
         return;
1462 1462
 ?>
1463
-    <a class="wpinv-cart-saving-button wpinv-submit button" id="wpinv-save-cart-button" href="<?php echo esc_url( add_query_arg( 'wpi_action', 'save_cart' ) ); ?>"><?php _e( 'Save Cart', 'invoicing' ); ?></a>
1463
+    <a class="wpinv-cart-saving-button wpinv-submit button" id="wpinv-save-cart-button" href="<?php echo esc_url(add_query_arg('wpi_action', 'save_cart')); ?>"><?php _e('Save Cart', 'invoicing'); ?></a>
1464 1464
 <?php
1465 1465
 }
1466 1466
 
1467 1467
 function wpinv_update_cart_button() {
1468
-    if ( !wpinv_item_quantities_enabled() )
1468
+    if (!wpinv_item_quantities_enabled())
1469 1469
         return;
1470 1470
 ?>
1471
-    <input type="submit" name="wpinv_update_cart_submit" class="wpinv-submit wpinv-no-js button" value="<?php _e( 'Update Cart', 'invoicing' ); ?>"/>
1471
+    <input type="submit" name="wpinv_update_cart_submit" class="wpinv-submit wpinv-no-js button" value="<?php _e('Update Cart', 'invoicing'); ?>"/>
1472 1472
     <input type="hidden" name="wpi_action" value="update_cart"/>
1473 1473
 <?php
1474 1474
 }
1475 1475
 
1476 1476
 function wpinv_checkout_cart_columns() {
1477 1477
     $default = 3;
1478
-    if ( wpinv_item_quantities_enabled() ) {
1478
+    if (wpinv_item_quantities_enabled()) {
1479 1479
         $default++;
1480 1480
     }
1481 1481
     
1482
-    if ( wpinv_use_taxes() ) {
1482
+    if (wpinv_use_taxes()) {
1483 1483
         $default++;
1484 1484
     }
1485 1485
 
1486
-    return apply_filters( 'wpinv_checkout_cart_columns', $default );
1486
+    return apply_filters('wpinv_checkout_cart_columns', $default);
1487 1487
 }
1488 1488
 
1489 1489
 function wpinv_display_cart_messages() {
1490 1490
     global $wpi_session;
1491 1491
 
1492
-    $messages = $wpi_session->get( 'wpinv_cart_messages' );
1492
+    $messages = $wpi_session->get('wpinv_cart_messages');
1493 1493
 
1494
-    if ( $messages ) {
1495
-        foreach ( $messages as $message_id => $message ) {
1494
+    if ($messages) {
1495
+        foreach ($messages as $message_id => $message) {
1496 1496
             // Try and detect what type of message this is
1497
-            if ( strpos( strtolower( $message ), 'error' ) ) {
1497
+            if (strpos(strtolower($message), 'error')) {
1498 1498
                 $type = 'error';
1499
-            } elseif ( strpos( strtolower( $message ), 'success' ) ) {
1499
+            } elseif (strpos(strtolower($message), 'success')) {
1500 1500
                 $type = 'success';
1501 1501
             } else {
1502 1502
                 $type = 'info';
1503 1503
             }
1504 1504
 
1505
-            $classes = apply_filters( 'wpinv_' . $type . '_class', array( 'wpinv_errors', 'wpinv-alert', 'wpinv-alert-' . $type ) );
1505
+            $classes = apply_filters('wpinv_' . $type . '_class', array('wpinv_errors', 'wpinv-alert', 'wpinv-alert-' . $type));
1506 1506
 
1507
-            echo '<div class="' . implode( ' ', $classes ) . '">';
1507
+            echo '<div class="' . implode(' ', $classes) . '">';
1508 1508
                 // Loop message codes and display messages
1509 1509
                     echo '<p class="wpinv_error" id="wpinv_msg_' . $message_id . '">' . $message . '</p>';
1510 1510
             echo '</div>';
1511 1511
         }
1512 1512
 
1513 1513
         // Remove all of the cart saving messages
1514
-        $wpi_session->set( 'wpinv_cart_messages', null );
1514
+        $wpi_session->set('wpinv_cart_messages', null);
1515 1515
     }
1516 1516
 }
1517
-add_action( 'wpinv_before_checkout_cart', 'wpinv_display_cart_messages' );
1517
+add_action('wpinv_before_checkout_cart', 'wpinv_display_cart_messages');
1518 1518
 
1519 1519
 function wpinv_discount_field() {
1520
-    if ( isset( $_GET['wpi-gateway'] ) && wpinv_is_ajax_disabled() ) {
1520
+    if (isset($_GET['wpi-gateway']) && wpinv_is_ajax_disabled()) {
1521 1521
         return; // Only show before a payment method has been selected if ajax is disabled
1522 1522
     }
1523 1523
 
1524
-    if ( !wpinv_is_checkout() ) {
1524
+    if (!wpinv_is_checkout()) {
1525 1525
         return;
1526 1526
     }
1527 1527
 
1528
-    if ( wpinv_has_active_discounts() && wpinv_get_cart_total() ) {
1528
+    if (wpinv_has_active_discounts() && wpinv_get_cart_total()) {
1529 1529
     ?>
1530 1530
     <div id="wpinv-discount-field" class="panel panel-default">
1531 1531
         <div class="panel-body">
1532 1532
             <p>
1533
-                <label class="wpinv-label" for="wpinv_discount_code"><strong><?php _e( 'Discount', 'invoicing' ); ?></strong></label>
1534
-                <span class="wpinv-description"><?php _e( 'Enter a discount code if you have one.', 'invoicing' ); ?></span>
1533
+                <label class="wpinv-label" for="wpinv_discount_code"><strong><?php _e('Discount', 'invoicing'); ?></strong></label>
1534
+                <span class="wpinv-description"><?php _e('Enter a discount code if you have one.', 'invoicing'); ?></span>
1535 1535
             </p>
1536 1536
             <div class="form-group row">
1537 1537
                 <div class="col-sm-4">
1538
-                    <input class="wpinv-input form-control" type="text" id="wpinv_discount_code" name="wpinv_discount_code" placeholder="<?php _e( 'Enter discount code', 'invoicing' ); ?>"/>
1538
+                    <input class="wpinv-input form-control" type="text" id="wpinv_discount_code" name="wpinv_discount_code" placeholder="<?php _e('Enter discount code', 'invoicing'); ?>"/>
1539 1539
                 </div>
1540 1540
                 <div class="col-sm-3">
1541
-                    <button id="wpi-apply-discount" type="button" class="btn btn-success btn-sm"><?php _e( 'Apply Discount', 'invoicing' ); ?></button>
1541
+                    <button id="wpi-apply-discount" type="button" class="btn btn-success btn-sm"><?php _e('Apply Discount', 'invoicing'); ?></button>
1542 1542
                 </div>
1543 1543
                 <div class="col-sm-12 wpinv-discount-msg">
1544 1544
                     <div class="alert alert-success"><i class="fa fa-check-circle"></i><span class="wpi-msg"></span></div>
@@ -1550,10 +1550,10 @@  discard block
 block discarded – undo
1550 1550
 <?php
1551 1551
     }
1552 1552
 }
1553
-add_action( 'wpinv_after_checkout_cart', 'wpinv_discount_field', -10 );
1553
+add_action('wpinv_after_checkout_cart', 'wpinv_discount_field', -10);
1554 1554
 
1555 1555
 function wpinv_agree_to_terms_js() {
1556
-    if ( wpinv_get_option( 'show_agree_to_terms', false ) ) {
1556
+    if (wpinv_get_option('show_agree_to_terms', false)) {
1557 1557
 ?>
1558 1558
 <script type="text/javascript">
1559 1559
     jQuery(document).ready(function($){
@@ -1568,124 +1568,124 @@  discard block
 block discarded – undo
1568 1568
 <?php
1569 1569
     }
1570 1570
 }
1571
-add_action( 'wpinv_checkout_form_top', 'wpinv_agree_to_terms_js' );
1571
+add_action('wpinv_checkout_form_top', 'wpinv_agree_to_terms_js');
1572 1572
 
1573 1573
 function wpinv_payment_mode_select() {
1574
-    $gateways = wpinv_get_enabled_payment_gateways( true );
1575
-    $gateways = apply_filters( 'wpinv_payment_gateways_on_cart', $gateways );
1574
+    $gateways = wpinv_get_enabled_payment_gateways(true);
1575
+    $gateways = apply_filters('wpinv_payment_gateways_on_cart', $gateways);
1576 1576
     $page_URL = wpinv_get_current_page_url();
1577 1577
     
1578 1578
     do_action('wpinv_payment_mode_top');
1579 1579
     $invoice_id = (int)wpinv_get_invoice_cart_id();
1580 1580
     ?>
1581 1581
     <div id="wpinv_payment_mode_select">
1582
-            <?php do_action( 'wpinv_payment_mode_before_gateways_wrap' ); ?>
1582
+            <?php do_action('wpinv_payment_mode_before_gateways_wrap'); ?>
1583 1583
             <div id="wpinv-payment-mode-wrap" class="panel panel-default">
1584
-                <div class="panel-heading"><h3 class="panel-title"><?php _e( 'Select Payment Method', 'invoicing' ); ?></h3></div>
1584
+                <div class="panel-heading"><h3 class="panel-title"><?php _e('Select Payment Method', 'invoicing'); ?></h3></div>
1585 1585
                 <div class="panel-body list-group wpi-payment_methods">
1586 1586
                     <?php
1587
-                    do_action( 'wpinv_payment_mode_before_gateways' );
1588
-                    $chosen_gateway = wpinv_get_chosen_gateway( $invoice_id );
1587
+                    do_action('wpinv_payment_mode_before_gateways');
1588
+                    $chosen_gateway = wpinv_get_chosen_gateway($invoice_id);
1589 1589
                     
1590
-                    if(!empty($gateways)){
1591
-	                    foreach ( $gateways as $gateway_id => $gateway ) {
1592
-		                    $checked = checked( $gateway_id, $chosen_gateway, false );
1593
-		                    $button_label = wpinv_get_gateway_button_label( $gateway_id );
1594
-		                    $description = wpinv_get_gateway_description( $gateway_id );
1590
+                    if (!empty($gateways)) {
1591
+	                    foreach ($gateways as $gateway_id => $gateway) {
1592
+		                    $checked = checked($gateway_id, $chosen_gateway, false);
1593
+		                    $button_label = wpinv_get_gateway_button_label($gateway_id);
1594
+		                    $description = wpinv_get_gateway_description($gateway_id);
1595 1595
 		                    ?>
1596 1596
 		                    <div class="list-group-item">
1597 1597
 			                    <div class="radio">
1598
-				                    <label><input type="radio" data-button-text="<?php echo esc_attr( $button_label );?>" value="<?php echo esc_attr( $gateway_id ) ;?>" <?php echo $checked ;?> id="wpi_gateway_<?php echo esc_attr( $gateway_id );?>" name="wpi-gateway" class="wpi-pmethod"><?php echo esc_html( $gateway['checkout_label'] ); ?></label>
1598
+				                    <label><input type="radio" data-button-text="<?php echo esc_attr($button_label); ?>" value="<?php echo esc_attr($gateway_id); ?>" <?php echo $checked; ?> id="wpi_gateway_<?php echo esc_attr($gateway_id); ?>" name="wpi-gateway" class="wpi-pmethod"><?php echo esc_html($gateway['checkout_label']); ?></label>
1599 1599
 			                    </div>
1600
-			                    <div style="display:none;" class="payment_box wpi_gateway_<?php echo esc_attr( $gateway_id );?>" role="alert">
1601
-				                    <?php if ( !empty( $description ) ) { ?>
1602
-					                    <div class="wpi-gateway-desc alert alert-info"><?php echo $description;?></div>
1600
+			                    <div style="display:none;" class="payment_box wpi_gateway_<?php echo esc_attr($gateway_id); ?>" role="alert">
1601
+				                    <?php if (!empty($description)) { ?>
1602
+					                    <div class="wpi-gateway-desc alert alert-info"><?php echo $description; ?></div>
1603 1603
 				                    <?php } ?>
1604
-				                    <?php do_action( 'wpinv_' . $gateway_id . '_cc_form', $invoice_id ) ;?>
1604
+				                    <?php do_action('wpinv_' . $gateway_id . '_cc_form', $invoice_id); ?>
1605 1605
 			                    </div>
1606 1606
 		                    </div>
1607 1607
 		                    <?php
1608 1608
 	                    }
1609
-                    }else{
1610
-	                    echo '<div class="alert alert-warning">'. __('No payment gateway active','invoicing') .'</div>';
1609
+                    } else {
1610
+	                    echo '<div class="alert alert-warning">' . __('No payment gateway active', 'invoicing') . '</div>';
1611 1611
                     }
1612 1612
 
1613
-                    do_action( 'wpinv_payment_mode_after_gateways' );
1613
+                    do_action('wpinv_payment_mode_after_gateways');
1614 1614
                     ?>
1615 1615
                 </div>
1616 1616
             </div>
1617
-            <?php do_action( 'wpinv_payment_mode_after_gateways_wrap' ); ?>
1617
+            <?php do_action('wpinv_payment_mode_after_gateways_wrap'); ?>
1618 1618
     </div>
1619 1619
     <?php
1620 1620
     do_action('wpinv_payment_mode_bottom');
1621 1621
 }
1622
-add_action( 'wpinv_payment_mode_select', 'wpinv_payment_mode_select' );
1622
+add_action('wpinv_payment_mode_select', 'wpinv_payment_mode_select');
1623 1623
 
1624 1624
 function wpinv_checkout_billing_info() {    
1625
-    if ( wpinv_is_checkout() ) {
1625
+    if (wpinv_is_checkout()) {
1626 1626
         $logged_in          = is_user_logged_in();
1627 1627
         $billing_details    = wpinv_checkout_billing_details();
1628
-        $selected_country   = !empty( $billing_details['country'] ) ? $billing_details['country'] : wpinv_default_billing_country();
1628
+        $selected_country   = !empty($billing_details['country']) ? $billing_details['country'] : wpinv_default_billing_country();
1629 1629
         ?>
1630 1630
         <div id="wpinv-fields" class="clearfix">
1631 1631
             <div id="wpi-billing" class="wpi-billing clearfix panel panel-default">
1632
-                <div class="panel-heading"><h3 class="panel-title"><?php _e( 'Billing Details', 'invoicing' );?></h3></div>
1632
+                <div class="panel-heading"><h3 class="panel-title"><?php _e('Billing Details', 'invoicing'); ?></h3></div>
1633 1633
                 <div id="wpinv-fields-box" class="panel-body">
1634
-                    <?php do_action( 'wpinv_checkout_billing_fields_first', $billing_details ); ?>
1634
+                    <?php do_action('wpinv_checkout_billing_fields_first', $billing_details); ?>
1635 1635
                     <p class="wpi-cart-field wpi-col2 wpi-colf">
1636
-                        <label for="wpinv_first_name" class="wpi-label"><?php _e( 'First Name', 'invoicing' );?><span class="wpi-required">*</span></label>
1636
+                        <label for="wpinv_first_name" class="wpi-label"><?php _e('First Name', 'invoicing'); ?><span class="wpi-required">*</span></label>
1637 1637
                         <?php
1638
-                        echo wpinv_html_text( array(
1638
+                        echo wpinv_html_text(array(
1639 1639
                                 'id'            => 'wpinv_first_name',
1640 1640
                                 'name'          => 'wpinv_first_name',
1641 1641
                                 'value'         => $billing_details['first_name'],
1642 1642
                                 'class'         => 'wpi-input form-control required',
1643
-                                'placeholder'   => __( 'First name', 'invoicing' ),
1643
+                                'placeholder'   => __('First name', 'invoicing'),
1644 1644
                                 'required'      => true,
1645
-                            ) );
1645
+                            ));
1646 1646
                         ?>
1647 1647
                     </p>
1648 1648
                     <p class="wpi-cart-field wpi-col2 wpi-coll">
1649
-                        <label for="wpinv_last_name" class="wpi-label"><?php _e( 'Last Name', 'invoicing' );?></label>
1649
+                        <label for="wpinv_last_name" class="wpi-label"><?php _e('Last Name', 'invoicing'); ?></label>
1650 1650
                         <?php
1651
-                        echo wpinv_html_text( array(
1651
+                        echo wpinv_html_text(array(
1652 1652
                                 'id'            => 'wpinv_last_name',
1653 1653
                                 'name'          => 'wpinv_last_name',
1654 1654
                                 'value'         => $billing_details['last_name'],
1655 1655
                                 'class'         => 'wpi-input form-control',
1656
-                                'placeholder'   => __( 'Last name', 'invoicing' ),
1657
-                            ) );
1656
+                                'placeholder'   => __('Last name', 'invoicing'),
1657
+                            ));
1658 1658
                         ?>
1659 1659
                     </p>
1660 1660
                     <p class="wpi-cart-field wpi-col2 wpi-colf">
1661
-                        <label for="wpinv_address" class="wpi-label"><?php _e( 'Address', 'invoicing' );?><span class="wpi-required">*</span></label>
1661
+                        <label for="wpinv_address" class="wpi-label"><?php _e('Address', 'invoicing'); ?><span class="wpi-required">*</span></label>
1662 1662
                         <?php
1663
-                        echo wpinv_html_text( array(
1663
+                        echo wpinv_html_text(array(
1664 1664
                                 'id'            => 'wpinv_address',
1665 1665
                                 'name'          => 'wpinv_address',
1666 1666
                                 'value'         => $billing_details['address'],
1667 1667
                                 'class'         => 'wpi-input form-control required',
1668
-                                'placeholder'   => __( 'Address', 'invoicing' ),
1668
+                                'placeholder'   => __('Address', 'invoicing'),
1669 1669
                                 'required'      => true,
1670
-                            ) );
1670
+                            ));
1671 1671
                         ?>
1672 1672
                     </p>
1673 1673
                     <p class="wpi-cart-field wpi-col2 wpi-coll">
1674
-                        <label for="wpinv_city" class="wpi-label"><?php _e( 'City', 'invoicing' );?><span class="wpi-required">*</span></label>
1674
+                        <label for="wpinv_city" class="wpi-label"><?php _e('City', 'invoicing'); ?><span class="wpi-required">*</span></label>
1675 1675
                         <?php
1676
-                        echo wpinv_html_text( array(
1676
+                        echo wpinv_html_text(array(
1677 1677
                                 'id'            => 'wpinv_city',
1678 1678
                                 'name'          => 'wpinv_city',
1679 1679
                                 'value'         => $billing_details['city'],
1680 1680
                                 'class'         => 'wpi-input form-control required',
1681
-                                'placeholder'   => __( 'City', 'invoicing' ),
1681
+                                'placeholder'   => __('City', 'invoicing'),
1682 1682
                                 'required'      => true,
1683
-                            ) );
1683
+                            ));
1684 1684
                         ?>
1685 1685
                     </p>
1686 1686
                     <p id="wpinv_country_box" class="wpi-cart-field wpi-col2 wpi-colf">
1687
-                        <label for="wpinv_country" class="wpi-label"><?php _e( 'Country', 'invoicing' );?><span class="wpi-required">*</span></label>
1688
-                        <?php echo wpinv_html_select( array(
1687
+                        <label for="wpinv_country" class="wpi-label"><?php _e('Country', 'invoicing'); ?><span class="wpi-required">*</span></label>
1688
+                        <?php echo wpinv_html_select(array(
1689 1689
                             'options'          => wpinv_get_country_list(),
1690 1690
                             'name'             => 'wpinv_country',
1691 1691
                             'id'               => 'wpinv_country',
@@ -1693,16 +1693,16 @@  discard block
 block discarded – undo
1693 1693
                             'show_option_all'  => false,
1694 1694
                             'show_option_none' => false,
1695 1695
                             'class'            => 'wpi-input form-control required',
1696
-                            'placeholder'      => __( 'Choose a country', 'invoicing' ),
1696
+                            'placeholder'      => __('Choose a country', 'invoicing'),
1697 1697
                             'required'          => true,
1698
-                        ) ); ?>
1698
+                        )); ?>
1699 1699
                     </p>
1700 1700
                     <p id="wpinv_state_box" class="wpi-cart-field wpi-col2 wpi-coll">
1701
-                        <label for="wpinv_state" class="wpi-label"><?php _e( 'State / Province', 'invoicing' );?><span class="wpi-required">*</span></label>
1701
+                        <label for="wpinv_state" class="wpi-label"><?php _e('State / Province', 'invoicing'); ?><span class="wpi-required">*</span></label>
1702 1702
                         <?php
1703
-                        $states = wpinv_get_country_states( $selected_country );
1704
-                        if( !empty( $states ) ) {
1705
-                            echo wpinv_html_select( array(
1703
+                        $states = wpinv_get_country_states($selected_country);
1704
+                        if (!empty($states)) {
1705
+                            echo wpinv_html_select(array(
1706 1706
                                 'options'          => $states,
1707 1707
                                 'name'             => 'wpinv_state',
1708 1708
                                 'id'               => 'wpinv_state',
@@ -1710,60 +1710,60 @@  discard block
 block discarded – undo
1710 1710
                                 'show_option_all'  => false,
1711 1711
                                 'show_option_none' => false,
1712 1712
                                 'class'            => 'wpi-input form-control required',
1713
-                                'placeholder'      => __( 'Choose a state', 'invoicing' ),
1713
+                                'placeholder'      => __('Choose a state', 'invoicing'),
1714 1714
                                 'required'         => true,
1715
-                            ) );
1715
+                            ));
1716 1716
                         } else {
1717
-                            echo wpinv_html_text( array(
1717
+                            echo wpinv_html_text(array(
1718 1718
                                 'name'          => 'wpinv_state',
1719 1719
                                 'value'         => $billing_details['state'],
1720 1720
                                 'id'            => 'wpinv_state',
1721 1721
                                 'class'         => 'wpi-input form-control required',
1722
-                                'placeholder'   => __( 'State / Province', 'invoicing' ),
1722
+                                'placeholder'   => __('State / Province', 'invoicing'),
1723 1723
                                 'required'      => true,
1724
-                            ) );
1724
+                            ));
1725 1725
                         }
1726 1726
                         ?>
1727 1727
                     </p>
1728 1728
                     <p class="wpi-cart-field wpi-col2 wpi-colf">
1729
-                        <label for="wpinv_zip" class="wpi-label"><?php _e( 'ZIP / Postcode', 'invoicing' );?></label>
1729
+                        <label for="wpinv_zip" class="wpi-label"><?php _e('ZIP / Postcode', 'invoicing'); ?></label>
1730 1730
                         <?php
1731
-                        echo wpinv_html_text( array(
1731
+                        echo wpinv_html_text(array(
1732 1732
                                 'name'          => 'wpinv_zip',
1733 1733
                                 'value'         => $billing_details['zip'],
1734 1734
                                 'id'            => 'wpinv_zip',
1735 1735
                                 'class'         => 'wpi-input form-control',
1736
-                                'placeholder'   => __( 'ZIP / Postcode', 'invoicing' ),
1737
-                            ) );
1736
+                                'placeholder'   => __('ZIP / Postcode', 'invoicing'),
1737
+                            ));
1738 1738
                         ?>
1739 1739
                     </p>
1740 1740
                     <p class="wpi-cart-field wpi-col2 wpi-coll">
1741
-                        <label for="wpinv_phone" class="wpi-label"><?php _e( 'Phone', 'invoicing' );?><?php if ( wpinv_get_option( 'phone_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label>
1741
+                        <label for="wpinv_phone" class="wpi-label"><?php _e('Phone', 'invoicing'); ?><?php if (wpinv_get_option('phone_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label>
1742 1742
                         <?php
1743
-                        echo wpinv_html_text( array(
1743
+                        echo wpinv_html_text(array(
1744 1744
                                 'id'            => 'wpinv_phone',
1745 1745
                                 'name'          => 'wpinv_phone',
1746 1746
                                 'value'         => $billing_details['phone'],
1747 1747
                                 'class'         => 'wpi-input form-control',
1748
-                                'placeholder'   => __( 'Phone', 'invoicing' ),
1749
-                                'required'      => (bool)wpinv_get_option( 'phone_mandatory' ),
1750
-                            ) );
1748
+                                'placeholder'   => __('Phone', 'invoicing'),
1749
+                                'required'      => (bool)wpinv_get_option('phone_mandatory'),
1750
+                            ));
1751 1751
                         ?>
1752 1752
                     </p>
1753
-                    <?php do_action( 'wpinv_checkout_billing_fields_last', $billing_details ); ?>
1753
+                    <?php do_action('wpinv_checkout_billing_fields_last', $billing_details); ?>
1754 1754
                     <div class="clearfix"></div>
1755 1755
                 </div>
1756 1756
             </div>
1757
-            <?php do_action( 'wpinv_after_billing_fields', $billing_details ); ?>
1757
+            <?php do_action('wpinv_after_billing_fields', $billing_details); ?>
1758 1758
         </div>
1759 1759
         <?php
1760 1760
     }
1761 1761
 }
1762
-add_action( 'wpinv_checkout_billing_info', 'wpinv_checkout_billing_info' );
1762
+add_action('wpinv_checkout_billing_info', 'wpinv_checkout_billing_info');
1763 1763
 
1764 1764
 function wpinv_checkout_hidden_fields() {
1765 1765
 ?>
1766
-    <?php if ( is_user_logged_in() ) { ?>
1766
+    <?php if (is_user_logged_in()) { ?>
1767 1767
     <input type="hidden" name="wpinv_user_id" value="<?php echo get_current_user_id(); ?>"/>
1768 1768
     <?php } ?>
1769 1769
     <input type="hidden" name="wpi_action" value="payment" />
@@ -1773,9 +1773,9 @@  discard block
 block discarded – undo
1773 1773
 function wpinv_checkout_button_purchase() {
1774 1774
     ob_start();
1775 1775
 ?>
1776
-    <input type="submit" class="btn btn-success wpinv-submit" id="wpinv-payment-button" data-value="<?php esc_attr_e( 'Proceed to Pay', 'invoicing' ) ?>" name="wpinv_payment" value="<?php esc_attr_e( 'Proceed to Pay', 'invoicing' ) ?>"/>
1776
+    <input type="submit" class="btn btn-success wpinv-submit" id="wpinv-payment-button" data-value="<?php esc_attr_e('Proceed to Pay', 'invoicing') ?>" name="wpinv_payment" value="<?php esc_attr_e('Proceed to Pay', 'invoicing') ?>"/>
1777 1777
 <?php
1778
-    return apply_filters( 'wpinv_checkout_button_purchase', ob_get_clean() );
1778
+    return apply_filters('wpinv_checkout_button_purchase', ob_get_clean());
1779 1779
 }
1780 1780
 
1781 1781
 function wpinv_checkout_total() {
@@ -1784,96 +1784,96 @@  discard block
 block discarded – undo
1784 1784
 <div id="wpinv_checkout_total" class="panel panel-info">
1785 1785
     <div class="panel-body">
1786 1786
     <?php
1787
-    do_action( 'wpinv_purchase_form_before_checkout_total' );
1787
+    do_action('wpinv_purchase_form_before_checkout_total');
1788 1788
     ?>
1789
-    <strong><?php _e( 'Invoice Total:', 'invoicing' ) ?></strong> <span class="wpinv-chdeckout-total"><?php echo $cart_total;?></span>
1789
+    <strong><?php _e('Invoice Total:', 'invoicing') ?></strong> <span class="wpinv-chdeckout-total"><?php echo $cart_total; ?></span>
1790 1790
     <?php
1791
-    do_action( 'wpinv_purchase_form_after_checkout_total' );
1791
+    do_action('wpinv_purchase_form_after_checkout_total');
1792 1792
     ?>
1793 1793
     </div>
1794 1794
 </div>
1795 1795
 <?php
1796 1796
 }
1797
-add_action( 'wpinv_checkout_form_bottom', 'wpinv_checkout_total', 9998 );
1797
+add_action('wpinv_checkout_form_bottom', 'wpinv_checkout_total', 9998);
1798 1798
 
1799 1799
 function wpinv_checkout_submit() {
1800 1800
 ?>
1801 1801
 <div id="wpinv_purchase_submit" class="panel panel-success">
1802 1802
     <div class="panel-body text-center">
1803 1803
     <?php
1804
-    do_action( 'wpinv_purchase_form_before_submit' );
1804
+    do_action('wpinv_purchase_form_before_submit');
1805 1805
     wpinv_checkout_hidden_fields();
1806 1806
     echo wpinv_checkout_button_purchase();
1807
-    do_action( 'wpinv_purchase_form_after_submit' );
1807
+    do_action('wpinv_purchase_form_after_submit');
1808 1808
     ?>
1809 1809
     </div>
1810 1810
 </div>
1811 1811
 <?php
1812 1812
 }
1813
-add_action( 'wpinv_checkout_form_bottom', 'wpinv_checkout_submit', 9999 );
1813
+add_action('wpinv_checkout_form_bottom', 'wpinv_checkout_submit', 9999);
1814 1814
 
1815
-function wpinv_receipt_billing_address( $invoice_id = 0 ) {
1816
-    $invoice = wpinv_get_invoice( $invoice_id );
1815
+function wpinv_receipt_billing_address($invoice_id = 0) {
1816
+    $invoice = wpinv_get_invoice($invoice_id);
1817 1817
     
1818
-    if ( empty( $invoice ) ) {
1818
+    if (empty($invoice)) {
1819 1819
         return NULL;
1820 1820
     }
1821 1821
     
1822 1822
     $billing_details = $invoice->get_user_info();
1823 1823
     $address_row = '';
1824
-    if ( $address = $billing_details['address'] ) {
1825
-        $address_row .= wpautop( wp_kses_post( $address ) );
1824
+    if ($address = $billing_details['address']) {
1825
+        $address_row .= wpautop(wp_kses_post($address));
1826 1826
     }
1827 1827
     
1828 1828
     $address_fields = array();
1829
-    if ( !empty( $billing_details['city'] ) ) {
1829
+    if (!empty($billing_details['city'])) {
1830 1830
         $address_fields[] = $billing_details['city'];
1831 1831
     }
1832 1832
     
1833
-    $billing_country = !empty( $billing_details['country'] ) ? $billing_details['country'] : '';
1834
-    if ( !empty( $billing_details['state'] ) ) {
1835
-        $address_fields[] = wpinv_state_name( $billing_details['state'], $billing_country );
1833
+    $billing_country = !empty($billing_details['country']) ? $billing_details['country'] : '';
1834
+    if (!empty($billing_details['state'])) {
1835
+        $address_fields[] = wpinv_state_name($billing_details['state'], $billing_country);
1836 1836
     }
1837 1837
     
1838
-    if ( !empty( $billing_country ) ) {
1839
-        $address_fields[] = wpinv_country_name( $billing_country );
1838
+    if (!empty($billing_country)) {
1839
+        $address_fields[] = wpinv_country_name($billing_country);
1840 1840
     }
1841 1841
     
1842
-    if ( !empty( $address_fields ) ) {
1843
-        $address_fields = implode( ", ", $address_fields );
1842
+    if (!empty($address_fields)) {
1843
+        $address_fields = implode(", ", $address_fields);
1844 1844
         
1845
-        if ( !empty( $billing_details['zip'] ) ) {
1845
+        if (!empty($billing_details['zip'])) {
1846 1846
             $address_fields .= ' ' . $billing_details['zip'];
1847 1847
         }
1848 1848
         
1849
-        $address_row .= wpautop( wp_kses_post( $address_fields ) );
1849
+        $address_row .= wpautop(wp_kses_post($address_fields));
1850 1850
     }
1851 1851
     ob_start();
1852 1852
     ?>
1853 1853
     <table class="table table-bordered table-sm wpi-billing-details">
1854 1854
         <tbody>
1855 1855
             <tr class="wpi-receipt-name">
1856
-                <th class="text-left"><?php _e( 'Name', 'invoicing' ); ?></th>
1857
-                <td><?php echo esc_html( trim( $billing_details['first_name'] . ' ' . $billing_details['last_name'] ) ) ;?></td>
1856
+                <th class="text-left"><?php _e('Name', 'invoicing'); ?></th>
1857
+                <td><?php echo esc_html(trim($billing_details['first_name'] . ' ' . $billing_details['last_name'])); ?></td>
1858 1858
             </tr>
1859 1859
             <tr class="wpi-receipt-email">
1860
-                <th class="text-left"><?php _e( 'Email', 'invoicing' ); ?></th>
1861
-                <td><?php echo $billing_details['email'] ;?></td>
1860
+                <th class="text-left"><?php _e('Email', 'invoicing'); ?></th>
1861
+                <td><?php echo $billing_details['email']; ?></td>
1862 1862
             </tr>
1863
-            <?php if ( $billing_details['company'] ) { ?>
1863
+            <?php if ($billing_details['company']) { ?>
1864 1864
             <tr class="wpi-receipt-company">
1865
-                <th class="text-left"><?php _e( 'Company', 'invoicing' ); ?></th>
1866
-                <td><?php echo esc_html( $billing_details['company'] ) ;?></td>
1865
+                <th class="text-left"><?php _e('Company', 'invoicing'); ?></th>
1866
+                <td><?php echo esc_html($billing_details['company']); ?></td>
1867 1867
             </tr>
1868 1868
             <?php } ?>
1869 1869
             <tr class="wpi-receipt-address">
1870
-                <th class="text-left"><?php _e( 'Address', 'invoicing' ); ?></th>
1871
-                <td><?php echo $address_row ;?></td>
1870
+                <th class="text-left"><?php _e('Address', 'invoicing'); ?></th>
1871
+                <td><?php echo $address_row; ?></td>
1872 1872
             </tr>
1873
-            <?php if ( $billing_details['phone'] ) { ?>
1873
+            <?php if ($billing_details['phone']) { ?>
1874 1874
             <tr class="wpi-receipt-phone">
1875
-                <th class="text-left"><?php _e( 'Phone', 'invoicing' ); ?></th>
1876
-                <td><?php echo esc_html( $billing_details['phone'] ) ;?></td>
1875
+                <th class="text-left"><?php _e('Phone', 'invoicing'); ?></th>
1876
+                <td><?php echo esc_html($billing_details['phone']); ?></td>
1877 1877
             </tr>
1878 1878
             <?php } ?>
1879 1879
         </tbody>
@@ -1881,98 +1881,98 @@  discard block
 block discarded – undo
1881 1881
     <?php
1882 1882
     $output = ob_get_clean();
1883 1883
     
1884
-    $output = apply_filters( 'wpinv_receipt_billing_address', $output, $invoice_id );
1884
+    $output = apply_filters('wpinv_receipt_billing_address', $output, $invoice_id);
1885 1885
 
1886 1886
     echo $output;
1887 1887
 }
1888 1888
 
1889
-function wpinv_filter_success_page_content( $content ) {
1890
-    if ( isset( $_GET['payment-confirm'] ) && wpinv_is_success_page() ) {
1891
-        if ( has_filter( 'wpinv_payment_confirm_' . sanitize_text_field( $_GET['payment-confirm'] ) ) ) {
1892
-            $content = apply_filters( 'wpinv_payment_confirm_' . sanitize_text_field( $_GET['payment-confirm'] ), $content );
1889
+function wpinv_filter_success_page_content($content) {
1890
+    if (isset($_GET['payment-confirm']) && wpinv_is_success_page()) {
1891
+        if (has_filter('wpinv_payment_confirm_' . sanitize_text_field($_GET['payment-confirm']))) {
1892
+            $content = apply_filters('wpinv_payment_confirm_' . sanitize_text_field($_GET['payment-confirm']), $content);
1893 1893
         }
1894 1894
     }
1895 1895
 
1896 1896
     return $content;
1897 1897
 }
1898
-add_filter( 'the_content', 'wpinv_filter_success_page_content', 99999 );
1898
+add_filter('the_content', 'wpinv_filter_success_page_content', 99999);
1899 1899
 
1900
-function wpinv_receipt_actions( $invoice ) {
1901
-    if ( !empty( $invoice ) ) {
1900
+function wpinv_receipt_actions($invoice) {
1901
+    if (!empty($invoice)) {
1902 1902
         $actions = array(
1903 1903
             'print'   => array(
1904 1904
                 'url'  => $invoice->get_view_url(),
1905
-                'name' => __( 'Print Invoice', 'invoicing' ),
1905
+                'name' => __('Print Invoice', 'invoicing'),
1906 1906
                 'class' => 'btn-primary',
1907 1907
             ),
1908 1908
             'history'   => array(
1909 1909
                 'url'  => wpinv_get_history_page_uri(),
1910
-                'name' => __( 'Invoice History', 'invoicing' ),
1910
+                'name' => __('Invoice History', 'invoicing'),
1911 1911
                 'class' => 'btn-warning',
1912 1912
             )
1913 1913
         );
1914 1914
 
1915
-        $actions = apply_filters( 'wpinv_invoice_receipt_actions', $actions, $invoice );
1915
+        $actions = apply_filters('wpinv_invoice_receipt_actions', $actions, $invoice);
1916 1916
         
1917
-        if ( !empty( $actions ) ) {
1917
+        if (!empty($actions)) {
1918 1918
         ?>
1919 1919
         <div class="wpinv-receipt-actions text-right">
1920
-            <?php foreach ( $actions as $key => $action ) { $class = !empty($action['class']) ? sanitize_html_class( $action['class'] ) : ''; ?>
1921
-            <a href="<?php echo esc_url( $action['url'] );?>" class="btn btn-sm <?php echo $class . ' ' . sanitize_html_class( $key );?>" <?php echo ( !empty($action['attrs']) ? $action['attrs'] : '' ) ;?>><?php echo esc_html( $action['name'] );?></a>
1920
+            <?php foreach ($actions as $key => $action) { $class = !empty($action['class']) ? sanitize_html_class($action['class']) : ''; ?>
1921
+            <a href="<?php echo esc_url($action['url']); ?>" class="btn btn-sm <?php echo $class . ' ' . sanitize_html_class($key); ?>" <?php echo (!empty($action['attrs']) ? $action['attrs'] : ''); ?>><?php echo esc_html($action['name']); ?></a>
1922 1922
             <?php } ?>
1923 1923
         </div>
1924 1924
         <?php
1925 1925
         }
1926 1926
     }
1927 1927
 }
1928
-add_action( 'wpinv_receipt_start', 'wpinv_receipt_actions', -10, 1 );
1928
+add_action('wpinv_receipt_start', 'wpinv_receipt_actions', -10, 1);
1929 1929
 
1930
-function wpinv_invoice_link( $invoice_id ) {
1931
-    $invoice = wpinv_get_invoice( $invoice_id );
1930
+function wpinv_invoice_link($invoice_id) {
1931
+    $invoice = wpinv_get_invoice($invoice_id);
1932 1932
     
1933
-    if ( empty( $invoice ) ) {
1933
+    if (empty($invoice)) {
1934 1934
         return NULL;
1935 1935
     }
1936 1936
     
1937
-    $invoice_link = '<a href="' . esc_url( $invoice->get_view_url() ) . '">' . $invoice->get_number() . '</a>';
1937
+    $invoice_link = '<a href="' . esc_url($invoice->get_view_url()) . '">' . $invoice->get_number() . '</a>';
1938 1938
     
1939
-    return apply_filters( 'wpinv_get_invoice_link', $invoice_link, $invoice );
1939
+    return apply_filters('wpinv_get_invoice_link', $invoice_link, $invoice);
1940 1940
 }
1941 1941
 
1942
-function wpinv_invoice_subscription_details( $invoice ) {
1943
-    if ( !empty( $invoice ) && $invoice->is_recurring() && !wpinv_is_subscription_payment( $invoice ) ) {
1942
+function wpinv_invoice_subscription_details($invoice) {
1943
+    if (!empty($invoice) && $invoice->is_recurring() && !wpinv_is_subscription_payment($invoice)) {
1944 1944
         $total_payments = (int)$invoice->get_total_payments();
1945 1945
         $payments       = $invoice->get_child_payments();
1946 1946
         
1947 1947
         $subscription   = $invoice->get_subscription_data();
1948 1948
         
1949
-        if ( !( !empty( $subscription ) && !empty( $subscription['item_id'] ) ) ) {
1949
+        if (!(!empty($subscription) && !empty($subscription['item_id']))) {
1950 1950
             return;
1951 1951
         }
1952 1952
         
1953
-        $billing_cycle  = wpinv_get_billing_cycle( $subscription['initial_amount'], $subscription['recurring_amount'], $subscription['period'], $subscription['interval'], $subscription['bill_times'], $subscription['trial_period'], $subscription['trial_interval'], $invoice->get_currency() );
1954
-        $times_billed   = $total_payments . ' / ' . ( ( (int)$subscription['bill_times'] == 0 ) ? __( 'Until cancelled', 'invoicing' ) : $subscription['bill_times'] );
1953
+        $billing_cycle  = wpinv_get_billing_cycle($subscription['initial_amount'], $subscription['recurring_amount'], $subscription['period'], $subscription['interval'], $subscription['bill_times'], $subscription['trial_period'], $subscription['trial_interval'], $invoice->get_currency());
1954
+        $times_billed   = $total_payments . ' / ' . (((int)$subscription['bill_times'] == 0) ? __('Until cancelled', 'invoicing') : $subscription['bill_times']);
1955 1955
         
1956 1956
         $subscription_status = $invoice->get_subscription_status();
1957 1957
         
1958 1958
         $status_desc = '';
1959
-        if ( $subscription_status == 'trialing' && $trial_end_date = $invoice->get_trial_end_date() ) {
1960
-            $status_desc = wp_sprintf( __( 'Until: %s', 'invoicing' ), $trial_end_date );
1961
-        } else if ( $subscription_status == 'cancelled' && $cancelled_date = $invoice->get_cancelled_date() ) {
1962
-            $status_desc = wp_sprintf( __( 'On: %s', 'invoicing' ), $cancelled_date );
1959
+        if ($subscription_status == 'trialing' && $trial_end_date = $invoice->get_trial_end_date()) {
1960
+            $status_desc = wp_sprintf(__('Until: %s', 'invoicing'), $trial_end_date);
1961
+        } else if ($subscription_status == 'cancelled' && $cancelled_date = $invoice->get_cancelled_date()) {
1962
+            $status_desc = wp_sprintf(__('On: %s', 'invoicing'), $cancelled_date);
1963 1963
         }
1964 1964
         $status_desc = $status_desc != '' ? '<span class="meta">' . $status_desc . '</span>' : '';
1965 1965
         ?>
1966 1966
         <div class="wpinv-subscriptions-details">
1967
-            <h3 class="wpinv-subscriptions-t"><?php echo apply_filters( 'wpinv_subscription_details_title', __( 'Subscription Details', 'invoicing' ) ); ?></h3>
1967
+            <h3 class="wpinv-subscriptions-t"><?php echo apply_filters('wpinv_subscription_details_title', __('Subscription Details', 'invoicing')); ?></h3>
1968 1968
             <table class="table">
1969 1969
                 <thead>
1970 1970
                     <tr>
1971
-                        <th><?php _e( 'Billing Cycle', 'invoicing' ) ;?></th>
1972
-                        <th><?php _e( 'Start Date', 'invoicing' ) ;?></th>
1973
-                        <th><?php _e( 'Expiration Date', 'invoicing' ) ;?></th>
1974
-                        <th class="text-center"><?php _e( 'Times Billed', 'invoicing' ) ;?></th>
1975
-                        <th class="text-center"><?php _e( 'Status', 'invoicing' ) ;?></th>
1971
+                        <th><?php _e('Billing Cycle', 'invoicing'); ?></th>
1972
+                        <th><?php _e('Start Date', 'invoicing'); ?></th>
1973
+                        <th><?php _e('Expiration Date', 'invoicing'); ?></th>
1974
+                        <th class="text-center"><?php _e('Times Billed', 'invoicing'); ?></th>
1975
+                        <th class="text-center"><?php _e('Status', 'invoicing'); ?></th>
1976 1976
                     </tr>
1977 1977
                 </thead>
1978 1978
                 <tbody>
@@ -1981,32 +1981,32 @@  discard block
 block discarded – undo
1981 1981
                         <td><?php echo $invoice->get_subscription_start(); ?></td>
1982 1982
                         <td><?php echo $invoice->get_subscription_end(); ?></td>
1983 1983
                         <td class="text-center"><?php echo $times_billed; ?></td>
1984
-                        <td class="text-center wpi-sub-status"><?php echo $invoice->get_subscription_status_label() ;?>
1984
+                        <td class="text-center wpi-sub-status"><?php echo $invoice->get_subscription_status_label(); ?>
1985 1985
                         <?php echo $status_desc; ?>
1986 1986
                         </td>
1987 1987
                     </tr>
1988 1988
                 </tbody>
1989 1989
             </table>
1990 1990
         </div>
1991
-        <?php if ( !empty( $payments ) ) { ?>
1991
+        <?php if (!empty($payments)) { ?>
1992 1992
         <div class="wpinv-renewal-payments">
1993
-            <h3 class="wpinv-renewals-t"><?php echo apply_filters( 'wpinv_renewal_payments_title', __( 'Renewal Payments', 'invoicing' ) ); ?></h3>
1993
+            <h3 class="wpinv-renewals-t"><?php echo apply_filters('wpinv_renewal_payments_title', __('Renewal Payments', 'invoicing')); ?></h3>
1994 1994
             <table class="table">
1995 1995
                 <thead>
1996 1996
                     <tr>
1997 1997
                         <th>#</th>
1998
-                        <th><?php _e( 'Invoice', 'invoicing' ) ;?></th>
1999
-                        <th><?php _e( 'Date', 'invoicing' ) ;?></th>
2000
-                        <th class="text-right"><?php _e( 'Amount', 'invoicing' ) ;?></th>
1998
+                        <th><?php _e('Invoice', 'invoicing'); ?></th>
1999
+                        <th><?php _e('Date', 'invoicing'); ?></th>
2000
+                        <th class="text-right"><?php _e('Amount', 'invoicing'); ?></th>
2001 2001
                     </tr>
2002 2002
                 </thead>
2003 2003
                 <tbody>
2004
-                    <?php foreach ( $payments as $key => $invoice_id ) { ?>
2004
+                    <?php foreach ($payments as $key => $invoice_id) { ?>
2005 2005
                     <tr>
2006
-                        <th scope="row"><?php echo ( $key + 1 );?></th>
2007
-                        <td><?php echo wpinv_invoice_link( $invoice_id ) ;?></td>
2008
-                        <td><?php echo wpinv_get_invoice_date( $invoice_id ); ?></td>
2009
-                        <td class="text-right"><?php echo wpinv_payment_total( $invoice_id, true ); ?></td>
2006
+                        <th scope="row"><?php echo ($key + 1); ?></th>
2007
+                        <td><?php echo wpinv_invoice_link($invoice_id); ?></td>
2008
+                        <td><?php echo wpinv_get_invoice_date($invoice_id); ?></td>
2009
+                        <td class="text-right"><?php echo wpinv_payment_total($invoice_id, true); ?></td>
2010 2010
                     </tr>
2011 2011
                     <?php } ?>
2012 2012
                     <tr><td colspan="4" style="padding:0"></td></tr>
@@ -2018,52 +2018,52 @@  discard block
 block discarded – undo
2018 2018
     }
2019 2019
 }
2020 2020
 
2021
-function wpinv_cart_total_label( $label, $invoice ) {
2022
-    if ( empty( $invoice ) ) {
2021
+function wpinv_cart_total_label($label, $invoice) {
2022
+    if (empty($invoice)) {
2023 2023
         return $label;
2024 2024
     }
2025 2025
     
2026 2026
     $prefix_label = '';
2027
-    if ( $invoice->is_parent() && $item_id = $invoice->get_recurring() ) {        
2028
-        $prefix_label   = '<span class="label label-primary label-recurring">' . __( 'Recurring Payment', 'invoicing' ) . '</span> ' . wpinv_subscription_payment_desc( $invoice );
2029
-    } else if ( $invoice->is_renewal() ) {
2030
-        $prefix_label   = '<span class="label label-primary label-renewal">' . __( 'Renewal Payment', 'invoicing' ) . '</span> ';        
2027
+    if ($invoice->is_parent() && $item_id = $invoice->get_recurring()) {        
2028
+        $prefix_label   = '<span class="label label-primary label-recurring">' . __('Recurring Payment', 'invoicing') . '</span> ' . wpinv_subscription_payment_desc($invoice);
2029
+    } else if ($invoice->is_renewal()) {
2030
+        $prefix_label   = '<span class="label label-primary label-renewal">' . __('Renewal Payment', 'invoicing') . '</span> ';        
2031 2031
     }
2032 2032
     
2033
-    if ( $prefix_label != '' ) {
2034
-        $label  = '<span class="wpinv-cart-sub-desc">' . $prefix_label . '</span> ' . $label;
2033
+    if ($prefix_label != '') {
2034
+        $label = '<span class="wpinv-cart-sub-desc">' . $prefix_label . '</span> ' . $label;
2035 2035
     }
2036 2036
     
2037 2037
     return $label;
2038 2038
 }
2039
-add_filter( 'wpinv_cart_total_label', 'wpinv_cart_total_label', 10, 2 );
2040
-add_filter( 'wpinv_email_cart_total_label', 'wpinv_cart_total_label', 10, 2 );
2041
-add_filter( 'wpinv_print_cart_total_label', 'wpinv_cart_total_label', 10, 2 );
2039
+add_filter('wpinv_cart_total_label', 'wpinv_cart_total_label', 10, 2);
2040
+add_filter('wpinv_email_cart_total_label', 'wpinv_cart_total_label', 10, 2);
2041
+add_filter('wpinv_print_cart_total_label', 'wpinv_cart_total_label', 10, 2);
2042 2042
 
2043
-add_action( 'wpinv_invoice_print_middle', 'wpinv_invoice_subscription_details', 10, 1 );
2043
+add_action('wpinv_invoice_print_middle', 'wpinv_invoice_subscription_details', 10, 1);
2044 2044
 
2045
-function wpinv_invoice_print_description( $invoice ) {
2046
-    if ( empty( $invoice ) ) {
2045
+function wpinv_invoice_print_description($invoice) {
2046
+    if (empty($invoice)) {
2047 2047
         return NULL;
2048 2048
     }
2049
-    if ( $description = wpinv_get_invoice_description( $invoice->ID ) ) {
2049
+    if ($description = wpinv_get_invoice_description($invoice->ID)) {
2050 2050
         ?>
2051 2051
         <div class="row wpinv-lower">
2052 2052
             <div class="col-sm-12 wpinv-description">
2053
-                <?php echo wpautop( $description ); ?>
2053
+                <?php echo wpautop($description); ?>
2054 2054
             </div>
2055 2055
         </div>
2056 2056
         <?php
2057 2057
     }
2058 2058
 }
2059
-add_action( 'wpinv_invoice_print_middle', 'wpinv_invoice_print_description', 10.1, 1 );
2059
+add_action('wpinv_invoice_print_middle', 'wpinv_invoice_print_description', 10.1, 1);
2060 2060
 
2061
-function wpinv_invoice_print_payment_info( $invoice ) {
2062
-    if ( empty( $invoice ) ) {
2061
+function wpinv_invoice_print_payment_info($invoice) {
2062
+    if (empty($invoice)) {
2063 2063
         return NULL;
2064 2064
     }
2065 2065
     
2066
-    if ( $payments_info = wpinv_display_payments_info( $invoice->ID, false ) ) {
2066
+    if ($payments_info = wpinv_display_payments_info($invoice->ID, false)) {
2067 2067
         ?>
2068 2068
         <div class="row wpinv-payments">
2069 2069
             <div class="col-sm-12">
@@ -2075,40 +2075,40 @@  discard block
 block discarded – undo
2075 2075
 }
2076 2076
 // add_action( 'wpinv_invoice_print_after_line_items', 'wpinv_invoice_print_payment_info', 10, 1 );
2077 2077
 
2078
-function wpinv_get_invoice_note_line_item( $note, $echo = true ) {
2079
-    if ( empty( $note ) ) {
2078
+function wpinv_get_invoice_note_line_item($note, $echo = true) {
2079
+    if (empty($note)) {
2080 2080
         return NULL;
2081 2081
     }
2082 2082
     
2083
-    if ( is_int( $note ) ) {
2084
-        $note = get_comment( $note );
2083
+    if (is_int($note)) {
2084
+        $note = get_comment($note);
2085 2085
     }
2086 2086
     
2087
-    if ( !( is_object( $note ) && is_a( $note, 'WP_Comment' ) ) ) {
2087
+    if (!(is_object($note) && is_a($note, 'WP_Comment'))) {
2088 2088
         return NULL;
2089 2089
     }
2090 2090
     
2091
-    $note_classes   = array( 'note' );
2092
-    $note_classes[] = get_comment_meta( $note->comment_ID, '_wpi_customer_note', true ) ? 'customer-note' : '';
2093
-    $note_classes[] = $note->comment_author === __( 'GeoDirectory', 'invoicing' ) ? 'system-note' : '';
2094
-    $note_classes   = apply_filters( 'wpinv_invoice_note_class', array_filter( $note_classes ), $note );
2095
-    $note_classes   = !empty( $note_classes ) ? implode( ' ', $note_classes ) : '';
2091
+    $note_classes   = array('note');
2092
+    $note_classes[] = get_comment_meta($note->comment_ID, '_wpi_customer_note', true) ? 'customer-note' : '';
2093
+    $note_classes[] = $note->comment_author === __('GeoDirectory', 'invoicing') ? 'system-note' : '';
2094
+    $note_classes   = apply_filters('wpinv_invoice_note_class', array_filter($note_classes), $note);
2095
+    $note_classes   = !empty($note_classes) ? implode(' ', $note_classes) : '';
2096 2096
     
2097 2097
     ob_start();
2098 2098
     ?>
2099
-    <li rel="<?php echo absint( $note->comment_ID ) ; ?>" class="<?php echo esc_attr( $note_classes ); ?>">
2099
+    <li rel="<?php echo absint($note->comment_ID); ?>" class="<?php echo esc_attr($note_classes); ?>">
2100 2100
         <div class="note_content">
2101
-            <?php echo wpautop( wptexturize( wp_kses_post( $note->comment_content ) ) ); ?>
2101
+            <?php echo wpautop(wptexturize(wp_kses_post($note->comment_content))); ?>
2102 2102
         </div>
2103 2103
         <p class="meta">
2104
-            <abbr class="exact-date" title="<?php echo $note->comment_date; ?>"><?php printf( __( '%1$s - %2$s at %3$s', 'invoicing' ), $note->comment_author, date_i18n( get_option( 'date_format' ), strtotime( $note->comment_date ) ), date_i18n( get_option( 'time_format' ), strtotime( $note->comment_date ) ) ); ?></abbr>&nbsp;&nbsp;<a href="#" class="delete_note"><?php _e( 'Delete note', 'invoicing' ); ?></a>
2104
+            <abbr class="exact-date" title="<?php echo $note->comment_date; ?>"><?php printf(__('%1$s - %2$s at %3$s', 'invoicing'), $note->comment_author, date_i18n(get_option('date_format'), strtotime($note->comment_date)), date_i18n(get_option('time_format'), strtotime($note->comment_date))); ?></abbr>&nbsp;&nbsp;<a href="#" class="delete_note"><?php _e('Delete note', 'invoicing'); ?></a>
2105 2105
         </p>
2106 2106
     </li>
2107 2107
     <?php
2108 2108
     $note_content = ob_get_clean();
2109
-    $note_content = apply_filters( 'wpinv_get_invoice_note_line_item', $note_content, $note, $echo );
2109
+    $note_content = apply_filters('wpinv_get_invoice_note_line_item', $note_content, $note, $echo);
2110 2110
     
2111
-    if ( $echo ) {
2111
+    if ($echo) {
2112 2112
         echo $note_content;
2113 2113
     } else {
2114 2114
         return $note_content;
Please login to merge, or discard this patch.
includes/wpinv-post-types.php 1 patch
Spacing   +96 added lines, -96 removed lines patch added patch discarded remove patch
@@ -7,36 +7,36 @@  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
-add_action( 'init', 'wpinv_register_post_types', 1 );
14
+add_action('init', 'wpinv_register_post_types', 1);
15 15
 function wpinv_register_post_types() {    
16 16
     $labels = array(
17
-        'name'               => _x( 'Invoices', 'post type general name', 'invoicing' ),
18
-        'singular_name'      => _x( 'Invoice', 'post type singular name', 'invoicing' ),
19
-        'menu_name'          => _x( 'Invoices', 'admin menu', 'invoicing' ),
20
-        'name_admin_bar'     => _x( 'Invoice', 'add new on admin bar', 'invoicing' ),
21
-        'add_new'            => _x( 'Add New', 'book', 'invoicing' ),
22
-        'add_new_item'       => __( 'Add New Invoice', 'invoicing' ),
23
-        'new_item'           => __( 'New Invoice', 'invoicing' ),
24
-        'edit_item'          => __( 'Edit Invoice', 'invoicing' ),
25
-        'view_item'          => __( 'View Invoice', 'invoicing' ),
26
-        'all_items'          => __( 'Invoices', 'invoicing' ),
27
-        'search_items'       => __( 'Search Invoices', 'invoicing' ),
28
-        'parent_item_colon'  => __( 'Parent Invoices:', 'invoicing' ),
29
-        'not_found'          => __( 'No invoices found.', 'invoicing' ),
30
-        'not_found_in_trash' => __( 'No invoices found in trash.', 'invoicing' )
17
+        'name'               => _x('Invoices', 'post type general name', 'invoicing'),
18
+        'singular_name'      => _x('Invoice', 'post type singular name', 'invoicing'),
19
+        'menu_name'          => _x('Invoices', 'admin menu', 'invoicing'),
20
+        'name_admin_bar'     => _x('Invoice', 'add new on admin bar', 'invoicing'),
21
+        'add_new'            => _x('Add New', 'book', 'invoicing'),
22
+        'add_new_item'       => __('Add New Invoice', 'invoicing'),
23
+        'new_item'           => __('New Invoice', 'invoicing'),
24
+        'edit_item'          => __('Edit Invoice', 'invoicing'),
25
+        'view_item'          => __('View Invoice', 'invoicing'),
26
+        'all_items'          => __('Invoices', 'invoicing'),
27
+        'search_items'       => __('Search Invoices', 'invoicing'),
28
+        'parent_item_colon'  => __('Parent Invoices:', 'invoicing'),
29
+        'not_found'          => __('No invoices found.', 'invoicing'),
30
+        'not_found_in_trash' => __('No invoices found in trash.', 'invoicing')
31 31
     );
32
-    $labels = apply_filters( 'wpinv_labels', $labels );
32
+    $labels = apply_filters('wpinv_labels', $labels);
33 33
     
34 34
     $menu_icon = WPINV_PLUGIN_URL . '/assets/images/favicon.ico';
35
-    $menu_icon = apply_filters( 'wpinv_menu_icon_invoice', $menu_icon );
35
+    $menu_icon = apply_filters('wpinv_menu_icon_invoice', $menu_icon);
36 36
 
37 37
     $args = array(
38 38
         'labels'             => $labels,
39
-        'description'        => __( 'This is where invoices are stored.', 'invoicing' ),
39
+        'description'        => __('This is where invoices are stored.', 'invoicing'),
40 40
         'public'             => true,
41 41
         'can_export'         => true,
42 42
         '_builtin'           => false,
@@ -50,68 +50,68 @@  discard block
 block discarded – undo
50 50
         'has_archive'        => false,
51 51
         'hierarchical'       => false,
52 52
         'menu_position'      => null,
53
-        'supports'           => array( 'title', 'author' ),
53
+        'supports'           => array('title', 'author'),
54 54
         'menu_icon'          => $menu_icon,
55 55
     );
56 56
             
57
-    $args = apply_filters( 'wpinv_register_post_type_invoice', $args );
57
+    $args = apply_filters('wpinv_register_post_type_invoice', $args);
58 58
     
59
-    register_post_type( 'wpi_invoice', $args );
59
+    register_post_type('wpi_invoice', $args);
60 60
     
61 61
     $items_labels = array(
62
-        'name'               => _x( 'Items', 'post type general name', 'invoicing' ),
63
-        'singular_name'      => _x( 'Item', 'post type singular name', 'invoicing' ),
64
-        'menu_name'          => _x( 'Items', 'admin menu', 'invoicing' ),
65
-        'add_new'            => _x( 'Add New', 'wpi_item', 'invoicing' ),
66
-        'add_new_item'       => __( 'Add New Item', 'invoicing' ),
67
-        'new_item'           => __( 'New Item', 'invoicing' ),
68
-        'edit_item'          => __( 'Edit Item', 'invoicing' ),
69
-        'view_item'          => __( 'View Item', 'invoicing' ),
70
-        'all_items'          => __( 'Items', 'invoicing' ),
71
-        'search_items'       => __( 'Search Items', 'invoicing' ),
62
+        'name'               => _x('Items', 'post type general name', 'invoicing'),
63
+        'singular_name'      => _x('Item', 'post type singular name', 'invoicing'),
64
+        'menu_name'          => _x('Items', 'admin menu', 'invoicing'),
65
+        'add_new'            => _x('Add New', 'wpi_item', 'invoicing'),
66
+        'add_new_item'       => __('Add New Item', 'invoicing'),
67
+        'new_item'           => __('New Item', 'invoicing'),
68
+        'edit_item'          => __('Edit Item', 'invoicing'),
69
+        'view_item'          => __('View Item', 'invoicing'),
70
+        'all_items'          => __('Items', 'invoicing'),
71
+        'search_items'       => __('Search Items', 'invoicing'),
72 72
         'parent_item_colon'  => '',
73
-        'not_found'          => __( 'No items found.', 'invoicing' ),
74
-        'not_found_in_trash' => __( 'No items found in trash.', 'invoicing' )
73
+        'not_found'          => __('No items found.', 'invoicing'),
74
+        'not_found_in_trash' => __('No items found in trash.', 'invoicing')
75 75
     );
76
-    $items_labels = apply_filters( 'wpinv_items_labels', $items_labels );
76
+    $items_labels = apply_filters('wpinv_items_labels', $items_labels);
77 77
     
78 78
     $invoice_item_args = array(
79 79
         'labels'                => $items_labels,
80 80
         'public'                => false,
81 81
         'show_ui'               => true,
82 82
         'show_in_menu'          => 'wpinv',
83
-        'supports'              => array( 'title', 'excerpt' ),
83
+        'supports'              => array('title', 'excerpt'),
84 84
         'register_meta_box_cb'  => 'wpinv_register_item_meta_boxes',
85 85
         'rewrite'               => false,
86 86
         'query_var'             => false,
87 87
         'map_meta_cap'          => true,
88 88
         'can_export'            => true,
89 89
     );
90
-    $invoice_item_args = apply_filters( 'wpinv_register_post_type_invoice_item', $invoice_item_args );
90
+    $invoice_item_args = apply_filters('wpinv_register_post_type_invoice_item', $invoice_item_args);
91 91
 
92
-    register_post_type( 'wpi_item', $invoice_item_args );
92
+    register_post_type('wpi_item', $invoice_item_args);
93 93
     
94 94
     $labels = array(
95
-        'name'               => _x( 'Discounts', 'post type general name', 'invoicing' ),
96
-        'singular_name'      => _x( 'Discount', 'post type singular name', 'invoicing' ),
97
-        'menu_name'          => _x( 'Discounts', 'admin menu', 'invoicing' ),
98
-        'name_admin_bar'     => _x( 'Discount', 'add new on admin bar', 'invoicing' ),
99
-        'add_new'            => _x( 'Add New', 'book', 'invoicing' ),
100
-        'add_new_item'       => __( 'Add New Discount', 'invoicing' ),
101
-        'new_item'           => __( 'New Discount', 'invoicing' ),
102
-        'edit_item'          => __( 'Edit Discount', 'invoicing' ),
103
-        'view_item'          => __( 'View Discount', 'invoicing' ),
104
-        'all_items'          => __( 'Discounts', 'invoicing' ),
105
-        'search_items'       => __( 'Search Discounts', 'invoicing' ),
106
-        'parent_item_colon'  => __( 'Parent Discounts:', 'invoicing' ),
107
-        'not_found'          => __( 'No discounts found.', 'invoicing' ),
108
-        'not_found_in_trash' => __( 'No discounts found in trash.', 'invoicing' )
95
+        'name'               => _x('Discounts', 'post type general name', 'invoicing'),
96
+        'singular_name'      => _x('Discount', 'post type singular name', 'invoicing'),
97
+        'menu_name'          => _x('Discounts', 'admin menu', 'invoicing'),
98
+        'name_admin_bar'     => _x('Discount', 'add new on admin bar', 'invoicing'),
99
+        'add_new'            => _x('Add New', 'book', 'invoicing'),
100
+        'add_new_item'       => __('Add New Discount', 'invoicing'),
101
+        'new_item'           => __('New Discount', 'invoicing'),
102
+        'edit_item'          => __('Edit Discount', 'invoicing'),
103
+        'view_item'          => __('View Discount', 'invoicing'),
104
+        'all_items'          => __('Discounts', 'invoicing'),
105
+        'search_items'       => __('Search Discounts', 'invoicing'),
106
+        'parent_item_colon'  => __('Parent Discounts:', 'invoicing'),
107
+        'not_found'          => __('No discounts found.', 'invoicing'),
108
+        'not_found_in_trash' => __('No discounts found in trash.', 'invoicing')
109 109
     );
110
-    $labels = apply_filters( 'wpinv_discounts_labels', $labels );
110
+    $labels = apply_filters('wpinv_discounts_labels', $labels);
111 111
     
112 112
     $args = array(
113 113
         'labels'             => $labels,
114
-        'description'        => __( 'This is where you can add new discounts that users can use in invoices.', 'invoicing' ),
114
+        'description'        => __('This is where you can add new discounts that users can use in invoices.', 'invoicing'),
115 115
         'public'             => false,
116 116
         'can_export'         => true,
117 117
         '_builtin'           => false,
@@ -125,7 +125,7 @@  discard block
 block discarded – undo
125 125
         'map_meta_cap'       => true,
126 126
         'has_archive'        => false,
127 127
         'hierarchical'       => false,
128
-        'supports'           => array( 'title', 'excerpt' ),
128
+        'supports'           => array('title', 'excerpt'),
129 129
         'register_meta_box_cb'  => 'wpinv_register_discount_meta_boxes',
130 130
         'show_in_nav_menus'  => false,
131 131
         'show_in_admin_bar'  => true,
@@ -133,99 +133,99 @@  discard block
 block discarded – undo
133 133
         'menu_position'      => null,
134 134
     );
135 135
             
136
-    $args = apply_filters( 'wpinv_register_post_type_discount', $args );
136
+    $args = apply_filters('wpinv_register_post_type_discount', $args);
137 137
     
138
-    register_post_type( 'wpi_discount', $args );
138
+    register_post_type('wpi_discount', $args);
139 139
 }
140 140
 
141 141
 function wpinv_get_default_labels() {
142 142
     $defaults = array(
143
-       'singular' => __( 'Invoice', 'invoicing' ),
144
-       'plural'   => __( 'Invoices', 'invoicing' )
143
+       'singular' => __('Invoice', 'invoicing'),
144
+       'plural'   => __('Invoices', 'invoicing')
145 145
     );
146 146
     
147
-    return apply_filters( 'wpinv_default_invoices_name', $defaults );
147
+    return apply_filters('wpinv_default_invoices_name', $defaults);
148 148
 }
149 149
 
150
-function wpinv_get_label_singular( $lowercase = false ) {
150
+function wpinv_get_label_singular($lowercase = false) {
151 151
     $defaults = wpinv_get_default_labels();
152 152
     
153
-    return ($lowercase) ? strtolower( $defaults['singular'] ) : $defaults['singular'];
153
+    return ($lowercase) ? strtolower($defaults['singular']) : $defaults['singular'];
154 154
 }
155 155
 
156
-function wpinv_get_label_plural( $lowercase = false ) {
156
+function wpinv_get_label_plural($lowercase = false) {
157 157
     $defaults = wpinv_get_default_labels();
158 158
     
159
-    return ( $lowercase ) ? strtolower( $defaults['plural'] ) : $defaults['plural'];
159
+    return ($lowercase) ? strtolower($defaults['plural']) : $defaults['plural'];
160 160
 }
161 161
 
162
-function wpinv_change_default_title( $title ) {
163
-     if ( !is_admin() ) {
162
+function wpinv_change_default_title($title) {
163
+     if (!is_admin()) {
164 164
         $label = wpinv_get_label_singular();
165
-        $title = sprintf( __( 'Enter %s name here', 'invoicing' ), $label );
165
+        $title = sprintf(__('Enter %s name here', 'invoicing'), $label);
166 166
         return $title;
167 167
      }
168 168
 
169 169
      $screen = get_current_screen();
170 170
 
171
-     if ( 'wpi_invoice' == $screen->post_type ) {
171
+     if ('wpi_invoice' == $screen->post_type) {
172 172
         $label = wpinv_get_label_singular();
173
-        $title = sprintf( __( 'Enter %s name here', 'invoicing' ), $label );
173
+        $title = sprintf(__('Enter %s name here', 'invoicing'), $label);
174 174
      }
175 175
 
176 176
      return $title;
177 177
 }
178
-add_filter( 'enter_title_here', 'wpinv_change_default_title' );
178
+add_filter('enter_title_here', 'wpinv_change_default_title');
179 179
 
180 180
 function wpinv_register_post_status() {
181
-    register_post_status( 'processing', array(
182
-        'label'                     => _x( 'Processing', 'Invoice status', 'invoicing' ),
181
+    register_post_status('processing', array(
182
+        'label'                     => _x('Processing', 'Invoice status', 'invoicing'),
183 183
         'public'                    => true,
184 184
         'exclude_from_search'       => true,
185 185
         'show_in_admin_all_list'    => true,
186 186
         'show_in_admin_status_list' => true,
187
-        'label_count'               => _n_noop( 'Processing <span class="count">(%s)</span>', 'Processing <span class="count">(%s)</span>', 'invoicing' )
188
-    ) );
189
-    register_post_status( 'onhold', array(
190
-        'label'                     => _x( 'On Hold', 'Invoice status', 'invoicing' ),
187
+        'label_count'               => _n_noop('Processing <span class="count">(%s)</span>', 'Processing <span class="count">(%s)</span>', 'invoicing')
188
+    ));
189
+    register_post_status('onhold', array(
190
+        'label'                     => _x('On Hold', 'Invoice status', 'invoicing'),
191 191
         'public'                    => true,
192 192
         'exclude_from_search'       => true,
193 193
         'show_in_admin_all_list'    => true,
194 194
         'show_in_admin_status_list' => true,
195
-        'label_count'               => _n_noop( 'On Hold <span class="count">(%s)</span>', 'On Hold <span class="count">(%s)</span>', 'invoicing' )
196
-    ) );
197
-    register_post_status( 'cancelled', array(
198
-        'label'                     => _x( 'Cancelled', 'Invoice status', 'invoicing' ),
195
+        'label_count'               => _n_noop('On Hold <span class="count">(%s)</span>', 'On Hold <span class="count">(%s)</span>', 'invoicing')
196
+    ));
197
+    register_post_status('cancelled', array(
198
+        'label'                     => _x('Cancelled', 'Invoice status', 'invoicing'),
199 199
         'public'                    => true,
200 200
         'exclude_from_search'       => true,
201 201
         'show_in_admin_all_list'    => true,
202 202
         'show_in_admin_status_list' => true,
203
-        'label_count'               => _n_noop( 'Cancelled <span class="count">(%s)</span>', 'Cancelled <span class="count">(%s)</span>', 'invoicing' )
204
-    ) );
205
-    register_post_status( 'refunded', array(
206
-        'label'                     => _x( 'Refunded', 'Invoice status', 'invoicing' ),
203
+        'label_count'               => _n_noop('Cancelled <span class="count">(%s)</span>', 'Cancelled <span class="count">(%s)</span>', 'invoicing')
204
+    ));
205
+    register_post_status('refunded', array(
206
+        'label'                     => _x('Refunded', 'Invoice status', 'invoicing'),
207 207
         'public'                    => true,
208 208
         'exclude_from_search'       => true,
209 209
         'show_in_admin_all_list'    => true,
210 210
         'show_in_admin_status_list' => true,
211
-        'label_count'               => _n_noop( 'Refunded <span class="count">(%s)</span>', 'Refunded <span class="count">(%s)</span>', 'invoicing' )
212
-    ) );
213
-    register_post_status( 'failed', array(
214
-        'label'                     => _x( 'Failed', 'Invoice status', 'invoicing' ),
211
+        'label_count'               => _n_noop('Refunded <span class="count">(%s)</span>', 'Refunded <span class="count">(%s)</span>', 'invoicing')
212
+    ));
213
+    register_post_status('failed', array(
214
+        'label'                     => _x('Failed', 'Invoice status', 'invoicing'),
215 215
         'public'                    => true,
216 216
         'exclude_from_search'       => true,
217 217
         'show_in_admin_all_list'    => true,
218 218
         'show_in_admin_status_list' => true,
219
-        'label_count'               => _n_noop( 'Failed <span class="count">(%s)</span>', 'Failed <span class="count">(%s)</span>', 'invoicing' )
220
-    ) );
221
-    register_post_status( 'renewal', array(
222
-        'label'                     => _x( 'Renewal', 'Invoice status', 'invoicing' ),
219
+        'label_count'               => _n_noop('Failed <span class="count">(%s)</span>', 'Failed <span class="count">(%s)</span>', 'invoicing')
220
+    ));
221
+    register_post_status('renewal', array(
222
+        'label'                     => _x('Renewal', 'Invoice status', 'invoicing'),
223 223
         'public'                    => true,
224 224
         'exclude_from_search'       => true,
225 225
         'show_in_admin_all_list'    => true,
226 226
         'show_in_admin_status_list' => true,
227
-        'label_count'               => _n_noop( 'Renewal <span class="count">(%s)</span>', 'Renewal <span class="count">(%s)</span>', 'invoicing' )
228
-    ) );
227
+        'label_count'               => _n_noop('Renewal <span class="count">(%s)</span>', 'Renewal <span class="count">(%s)</span>', 'invoicing')
228
+    ));
229 229
 }
230
-add_action( 'init', 'wpinv_register_post_status', 10 );
230
+add_action('init', 'wpinv_register_post_status', 10);
231 231
 
Please login to merge, or discard this patch.
includes/class-wpinv-notes.php 1 patch
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if (!defined('ABSPATH')) {
3 3
     exit; // Exit if accessed directly
4 4
 }
5 5
 
@@ -14,65 +14,65 @@  discard block
 block discarded – undo
14 14
     }
15 15
     
16 16
     public function init() {
17
-        do_action( 'wpinv_class_notes_init', $this );
17
+        do_action('wpinv_class_notes_init', $this);
18 18
     }
19 19
     
20 20
     public function includes() {
21
-        do_action( 'wpinv_class_notes_includes', $this );
21
+        do_action('wpinv_class_notes_includes', $this);
22 22
     }
23 23
     
24 24
     public function actions() {
25 25
         // Secure inovice notes
26
-        add_action( 'pre_get_comments', array( $this, 'set_invoice_note_type' ), 11, 1 );
26
+        add_action('pre_get_comments', array($this, 'set_invoice_note_type'), 11, 1);
27 27
         
28
-        do_action( 'wpinv_class_notes_actions', $this );
28
+        do_action('wpinv_class_notes_actions', $this);
29 29
     }
30 30
         
31
-    public function set_invoice_note_type( $query ) {
32
-        $post_ID        = !empty( $query->query_vars['post_ID'] ) ? $query->query_vars['post_ID'] : $query->query_vars['post_id'];
31
+    public function set_invoice_note_type($query) {
32
+        $post_ID = !empty($query->query_vars['post_ID']) ? $query->query_vars['post_ID'] : $query->query_vars['post_id'];
33 33
         
34
-        if ( $post_ID && get_post_type( $post_ID ) == $this->invoice_post_type ) {
34
+        if ($post_ID && get_post_type($post_ID) == $this->invoice_post_type) {
35 35
             $query->query_vars['type__in']      = $this->comment_type;
36 36
             $query->query_vars['type__not_in']  = '';
37 37
         } else {        
38
-            if ( isset( $query->query_vars['type__in'] ) && $type_in = $query->query_vars['type__in'] ) {
39
-                if ( is_array( $type_in ) && in_array( $this->comment_type, $type_in ) ) {
40
-                    $key = array_search( $this->comment_type, $type_in );
41
-                    unset( $query->query_vars['type__in'][$key] );
42
-                } else if ( !is_array( $type_in ) && $type_in == $this->comment_type ) {
38
+            if (isset($query->query_vars['type__in']) && $type_in = $query->query_vars['type__in']) {
39
+                if (is_array($type_in) && in_array($this->comment_type, $type_in)) {
40
+                    $key = array_search($this->comment_type, $type_in);
41
+                    unset($query->query_vars['type__in'][$key]);
42
+                } else if (!is_array($type_in) && $type_in == $this->comment_type) {
43 43
                     $query->query_vars['type__in'] = '';
44 44
                 }
45 45
             }
46 46
             
47
-            if ( isset( $query->query_vars['type__not_in'] ) && $type_not_in = $query->query_vars['type__not_in'] ) {
48
-                if ( is_array( $type_not_in ) && !in_array( $this->comment_type, $type_not_in ) ) {
47
+            if (isset($query->query_vars['type__not_in']) && $type_not_in = $query->query_vars['type__not_in']) {
48
+                if (is_array($type_not_in) && !in_array($this->comment_type, $type_not_in)) {
49 49
                     $query->query_vars['type__not_in'][] = $this->comment_type;
50
-                } else if ( !is_array( $type_not_in ) && $type_not_in != $this->comment_type ) {
50
+                } else if (!is_array($type_not_in) && $type_not_in != $this->comment_type) {
51 51
                     $query->query_vars['type__not_in'] = (array)$query->query_vars['type__not_in'];
52 52
                     $query->query_vars['type__not_in'][] = $this->comment_type;
53 53
                 }
54 54
             } else {
55
-                $query->query_vars['type__not_in']  = $this->comment_type;
55
+                $query->query_vars['type__not_in'] = $this->comment_type;
56 56
             }
57 57
         }
58 58
         
59 59
         return $query;
60 60
     }
61 61
     
62
-    public function get_invoice_notes( $invoice_id = 0, $type = '' ) {
62
+    public function get_invoice_notes($invoice_id = 0, $type = '') {
63 63
         $args = array( 
64 64
             'post_id'   => $invoice_id,
65 65
             'order'     => 'comment_date_gmt',
66 66
             'order'     => 'DESC',
67 67
         );
68 68
         
69
-        if ( $type == 'customer' ) {
69
+        if ($type == 'customer') {
70 70
             $args['meta_key']   = '_wpi_customer_note';
71 71
             $args['meta_value'] = 1;
72 72
         }
73 73
         
74
-        $args   = apply_filters( 'wpinv_invoice_notes_args', $args, $this, $invoice_id, $type );
74
+        $args = apply_filters('wpinv_invoice_notes_args', $args, $this, $invoice_id, $type);
75 75
         
76
-        return get_comments( $args );
76
+        return get_comments($args);
77 77
     }
78 78
 }
Please login to merge, or discard this patch.
includes/class-wpinv-reports.php 1 patch
Spacing   +169 added lines, -169 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if (!defined('ABSPATH')) {
3 3
     exit; // Exit if accessed directly
4 4
 }
5 5
 
@@ -21,68 +21,68 @@  discard block
 block discarded – undo
21 21
     public function init() {
22 22
         global $wp_filesystem;
23 23
 
24
-        if ( empty( $wp_filesystem ) ) {
25
-            require_once( ABSPATH . '/wp-admin/includes/file.php' );
24
+        if (empty($wp_filesystem)) {
25
+            require_once(ABSPATH . '/wp-admin/includes/file.php');
26 26
             WP_Filesystem();
27 27
             global $wp_filesystem;
28 28
         }
29 29
         $this->wp_filesystem    = $wp_filesystem;
30 30
         
31 31
         $this->export_dir       = $this->export_location();
32
-        $this->export_url       = $this->export_location( true );
32
+        $this->export_url       = $this->export_location(true);
33 33
         $this->export           = 'invoicing';
34 34
         $this->filetype         = 'csv';
35 35
         $this->per_page         = 20;
36 36
         
37
-        do_action( 'wpinv_class_reports_init', $this );
37
+        do_action('wpinv_class_reports_init', $this);
38 38
     }
39 39
     
40 40
     public function includes() {
41
-        do_action( 'wpinv_class_reports_includes', $this );
41
+        do_action('wpinv_class_reports_includes', $this);
42 42
     }
43 43
     
44 44
     public function actions() {
45
-        if ( is_admin() ) {
46
-            add_action( 'admin_menu', array( $this, 'add_submenu' ), 10 );
47
-            add_action( 'wpinv_reports_tab_export', array( $this, 'export' ) );
48
-            add_action( 'wp_ajax_wpinv_ajax_export', array( $this, 'ajax_export' ) );
45
+        if (is_admin()) {
46
+            add_action('admin_menu', array($this, 'add_submenu'), 10);
47
+            add_action('wpinv_reports_tab_export', array($this, 'export'));
48
+            add_action('wp_ajax_wpinv_ajax_export', array($this, 'ajax_export'));
49 49
             
50 50
             // Export Invoices.
51
-            add_action( 'wpinv_export_set_params_invoices', array( $this, 'set_invoices_export' ) );
52
-            add_filter( 'wpinv_export_get_columns_invoices', array( $this, 'get_invoices_columns' ) );
53
-            add_filter( 'wpinv_export_get_data_invoices', array( $this, 'get_invoices_data' ) );
54
-            add_filter( 'wpinv_get_export_status_invoices', array( $this, 'invoices_export_status' ) );
51
+            add_action('wpinv_export_set_params_invoices', array($this, 'set_invoices_export'));
52
+            add_filter('wpinv_export_get_columns_invoices', array($this, 'get_invoices_columns'));
53
+            add_filter('wpinv_export_get_data_invoices', array($this, 'get_invoices_data'));
54
+            add_filter('wpinv_get_export_status_invoices', array($this, 'invoices_export_status'));
55 55
         }
56
-        do_action( 'wpinv_class_reports_actions', $this );
56
+        do_action('wpinv_class_reports_actions', $this);
57 57
     }
58 58
     
59 59
     public function add_submenu() {
60 60
         global $wpi_reports_page;
61
-        $wpi_reports_page = add_submenu_page( 'wpinv', __( 'Reports', 'invoicing' ), __( 'Reports', 'invoicing' ), 'manage_options', 'wpinv-reports', array( $this, 'reports_page' ) );
61
+        $wpi_reports_page = add_submenu_page('wpinv', __('Reports', 'invoicing'), __('Reports', 'invoicing'), 'manage_options', 'wpinv-reports', array($this, 'reports_page'));
62 62
     }
63 63
     
64 64
     public function reports_page() {
65
-        if ( !wp_script_is( 'postbox', 'enqueued' ) ) {
66
-            wp_enqueue_script( 'postbox' );
65
+        if (!wp_script_is('postbox', 'enqueued')) {
66
+            wp_enqueue_script('postbox');
67 67
         }
68
-        if ( !wp_script_is( 'jquery-ui-datepicker', 'enqueued' ) ) {
69
-            wp_enqueue_script( 'jquery-ui-datepicker' );
68
+        if (!wp_script_is('jquery-ui-datepicker', 'enqueued')) {
69
+            wp_enqueue_script('jquery-ui-datepicker');
70 70
         }
71 71
         
72
-        $current_page = admin_url( 'admin.php?page=wpinv-reports' );
73
-        $active_tab = isset( $_GET['tab'] ) ? $_GET['tab'] : 'export';
72
+        $current_page = admin_url('admin.php?page=wpinv-reports');
73
+        $active_tab = isset($_GET['tab']) ? $_GET['tab'] : 'export';
74 74
         ?>
75 75
         <div class="wrap wpi-reports-wrap">
76
-            <h1><?php echo esc_html( __( 'Reports', 'invoicing' ) ); ?></h1>
76
+            <h1><?php echo esc_html(__('Reports', 'invoicing')); ?></h1>
77 77
             <h2 class="nav-tab-wrapper wp-clearfix">
78
-                <a href="<?php echo add_query_arg( array( 'tab' => 'export', 'settings-updated' => false ), $current_page ); ?>" class="nav-tab <?php echo $active_tab == 'export' ? 'nav-tab-active' : ''; ?>"><?php _e( 'Export', 'invoicing' ); ?></a>
79
-                <?php do_action( 'wpinv_reports_page_tabs' ); ;?>
78
+                <a href="<?php echo add_query_arg(array('tab' => 'export', 'settings-updated' => false), $current_page); ?>" class="nav-tab <?php echo $active_tab == 'export' ? 'nav-tab-active' : ''; ?>"><?php _e('Export', 'invoicing'); ?></a>
79
+                <?php do_action('wpinv_reports_page_tabs'); ;?>
80 80
             </h2>
81 81
             <div class="wpi-reports-content wpi-reports-<?php echo $active_tab; ?>">
82 82
             <?php
83
-                do_action( 'wpinv_reports_page_top' );
84
-                do_action( 'wpinv_reports_tab_' . $active_tab );
85
-                do_action( 'wpinv_reports_page_bottom' );
83
+                do_action('wpinv_reports_page_top');
84
+                do_action('wpinv_reports_tab_' . $active_tab);
85
+                do_action('wpinv_reports_page_bottom');
86 86
             ?>
87 87
         </div>
88 88
         <?php
@@ -90,97 +90,97 @@  discard block
 block discarded – undo
90 90
     
91 91
     public function export() {
92 92
         $statuses = wpinv_get_invoice_statuses();
93
-        $statuses = array_merge( array( 'any' => __( 'All Statuses', 'invoicing' ) ), $statuses );
93
+        $statuses = array_merge(array('any' => __('All Statuses', 'invoicing')), $statuses);
94 94
         ?>
95 95
         <div class="metabox-holder">
96 96
             <div id="post-body">
97 97
                 <div id="post-body-content">
98
-                    <?php do_action( 'wpinv_reports_tab_export_content_top' ); ?>
98
+                    <?php do_action('wpinv_reports_tab_export_content_top'); ?>
99 99
                     
100 100
                     <div class="postbox wpi-export-invoices">
101
-                        <h2 class="hndle ui-sortabled-handle"><span><?php _e( 'Invoices','invoicing' ); ?></span></h2>
101
+                        <h2 class="hndle ui-sortabled-handle"><span><?php _e('Invoices', 'invoicing'); ?></span></h2>
102 102
                         <div class="inside">
103
-                            <p><?php _e( 'Download a CSV of all payment invoices.', 'invoicing' ); ?></p>
103
+                            <p><?php _e('Download a CSV of all payment invoices.', 'invoicing'); ?></p>
104 104
                             <form id="wpi-export-invoices" class="wpi-export-form" method="post">
105
-                                <?php echo wpinv_html_date_field( array( 
105
+                                <?php echo wpinv_html_date_field(array( 
106 106
                                     'id' => 'wpi_export_from_date', 
107 107
                                     'name' => 'from_date',
108 108
                                     'data' => array(
109 109
                                         'dateFormat' => 'yy-mm-dd'
110 110
                                     ),
111
-                                    'placeholder' => __( 'From date', 'invoicing' ) )
111
+                                    'placeholder' => __('From date', 'invoicing') )
112 112
                                 ); ?>
113
-                                <?php echo wpinv_html_date_field( array( 
113
+                                <?php echo wpinv_html_date_field(array( 
114 114
                                     'id' => 'wpi_export_to_date',
115 115
                                     'name' => 'to_date',
116 116
                                     'data' => array(
117 117
                                         'dateFormat' => 'yy-mm-dd'
118 118
                                     ),
119
-                                    'placeholder' => __( 'To date', 'invoicing' ) )
119
+                                    'placeholder' => __('To date', 'invoicing') )
120 120
                                 ); ?>
121 121
                                 <span id="wpinv-status-wrap">
122
-                                <?php echo wpinv_html_select( array(
122
+                                <?php echo wpinv_html_select(array(
123 123
                                     'options'          => $statuses,
124 124
                                     'name'             => 'status',
125 125
                                     'id'               => 'wpi_export_status',
126 126
                                     'show_option_all'  => false,
127 127
                                     'show_option_none' => false,
128 128
                                     'class'            => '',
129
-                                ) ); ?>
130
-                                <?php wp_nonce_field( 'wpi_ajax_export', 'wpi_ajax_export' ); ?>
129
+                                )); ?>
130
+                                <?php wp_nonce_field('wpi_ajax_export', 'wpi_ajax_export'); ?>
131 131
                                 </span>
132 132
                                 <span id="wpinv-submit-wrap">
133 133
                                     <input type="hidden" value="invoices" name="export" />
134
-                                    <input type="submit" value="<?php _e( 'Generate CSV', 'invoicing' ); ?>" class="button-primary" />
134
+                                    <input type="submit" value="<?php _e('Generate CSV', 'invoicing'); ?>" class="button-primary" />
135 135
                                 </span>
136 136
                             </form>
137 137
                         </div>
138 138
                     </div>
139 139
                     
140
-                    <?php do_action( 'wpinv_reports_tab_export_content_bottom' ); ?>
140
+                    <?php do_action('wpinv_reports_tab_export_content_bottom'); ?>
141 141
                 </div>
142 142
             </div>
143 143
         </div>
144 144
         <?php
145 145
     }
146 146
     
147
-    public function export_location( $relative = false ) {
147
+    public function export_location($relative = false) {
148 148
         $upload_dir         = wp_upload_dir();
149
-        $export_location    = $relative ? trailingslashit( $upload_dir['baseurl'] ) . 'cache' : trailingslashit( $upload_dir['basedir'] ) . 'cache';
150
-        $export_location    = apply_filters( 'wpinv_export_location', $export_location, $relative );
149
+        $export_location    = $relative ? trailingslashit($upload_dir['baseurl']) . 'cache' : trailingslashit($upload_dir['basedir']) . 'cache';
150
+        $export_location    = apply_filters('wpinv_export_location', $export_location, $relative);
151 151
         
152
-        return trailingslashit( $export_location );
152
+        return trailingslashit($export_location);
153 153
     }
154 154
     
155 155
     public function check_export_location() {
156 156
         try {
157
-            if ( empty( $this->wp_filesystem ) ) {
158
-                return __( 'Filesystem ERROR: Could not access filesystem.', 'invoicing' );
157
+            if (empty($this->wp_filesystem)) {
158
+                return __('Filesystem ERROR: Could not access filesystem.', 'invoicing');
159 159
             }
160 160
 
161
-            if ( is_wp_error( $this->wp_filesystem ) ) {
162
-                return __( 'Filesystem ERROR: ' . $this->wp_filesystem->get_error_message(), 'invoicing' );
161
+            if (is_wp_error($this->wp_filesystem)) {
162
+                return __('Filesystem ERROR: ' . $this->wp_filesystem->get_error_message(), 'invoicing');
163 163
             }
164 164
         
165
-            $is_dir         = $this->wp_filesystem->is_dir( $this->export_dir );
166
-            $is_writeable   = $is_dir && is_writeable( $this->export_dir );
165
+            $is_dir         = $this->wp_filesystem->is_dir($this->export_dir);
166
+            $is_writeable   = $is_dir && is_writeable($this->export_dir);
167 167
             
168
-            if ( $is_dir && $is_writeable ) {
168
+            if ($is_dir && $is_writeable) {
169 169
                return true;
170
-            } else if ( $is_dir && !$is_writeable ) {
171
-               if ( !$this->wp_filesystem->chmod( $this->export_dir, FS_CHMOD_DIR ) ) {
172
-                   return wp_sprintf( __( 'Filesystem ERROR: Export location %s is not writable, check your file permissions.', 'invoicing' ), $this->export_dir );
170
+            } else if ($is_dir && !$is_writeable) {
171
+               if (!$this->wp_filesystem->chmod($this->export_dir, FS_CHMOD_DIR)) {
172
+                   return wp_sprintf(__('Filesystem ERROR: Export location %s is not writable, check your file permissions.', 'invoicing'), $this->export_dir);
173 173
                }
174 174
                
175 175
                return true;
176 176
             } else {
177
-                if ( !$this->wp_filesystem->mkdir( $this->export_dir, FS_CHMOD_DIR ) ) {
178
-                    return wp_sprintf( __( 'Filesystem ERROR: Could not create directory %s. This is usually due to inconsistent file permissions.', 'invoicing' ), $this->export_dir );
177
+                if (!$this->wp_filesystem->mkdir($this->export_dir, FS_CHMOD_DIR)) {
178
+                    return wp_sprintf(__('Filesystem ERROR: Could not create directory %s. This is usually due to inconsistent file permissions.', 'invoicing'), $this->export_dir);
179 179
                 }
180 180
                 
181 181
                 return true;
182 182
             }
183
-        } catch ( Exception $e ) {
183
+        } catch (Exception $e) {
184 184
             return $e->getMessage();
185 185
         }
186 186
     }
@@ -188,130 +188,130 @@  discard block
 block discarded – undo
188 188
     public function ajax_export() {
189 189
         $response               = array();
190 190
         $response['success']    = false;
191
-        $response['msg']        = __( 'Invalid export request found.', 'invoicing' );
191
+        $response['msg']        = __('Invalid export request found.', 'invoicing');
192 192
         
193
-        if ( empty( $_POST['data'] ) || !current_user_can( 'manage_options' ) ) {
194
-            wp_send_json( $response );
193
+        if (empty($_POST['data']) || !current_user_can('manage_options')) {
194
+            wp_send_json($response);
195 195
         }
196 196
 
197
-        parse_str( $_POST['data'], $data );
197
+        parse_str($_POST['data'], $data);
198 198
         
199
-        $data['step']   = !empty( $_POST['step'] ) ? absint( $_POST['step'] ) : 1;
199
+        $data['step'] = !empty($_POST['step']) ? absint($_POST['step']) : 1;
200 200
 
201 201
         $_REQUEST = (array)$data;
202
-        if ( !( !empty( $_REQUEST['wpi_ajax_export'] ) && wp_verify_nonce( $_REQUEST['wpi_ajax_export'], 'wpi_ajax_export' ) ) ) {
203
-            $response['msg']    = __( 'Security check failed.', 'invoicing' );
204
-            wp_send_json( $response );
202
+        if (!(!empty($_REQUEST['wpi_ajax_export']) && wp_verify_nonce($_REQUEST['wpi_ajax_export'], 'wpi_ajax_export'))) {
203
+            $response['msg'] = __('Security check failed.', 'invoicing');
204
+            wp_send_json($response);
205 205
         }
206 206
         
207
-        if ( ( $error = $this->check_export_location( true ) ) !== true ) {
208
-            $response['msg'] = __( 'Filesystem ERROR: ' . $error, 'invoicing' );
209
-            wp_send_json( $response );
207
+        if (($error = $this->check_export_location(true)) !== true) {
208
+            $response['msg'] = __('Filesystem ERROR: ' . $error, 'invoicing');
209
+            wp_send_json($response);
210 210
         }
211 211
                         
212
-        $this->set_export_params( $_REQUEST );
212
+        $this->set_export_params($_REQUEST);
213 213
         
214 214
         $return = $this->process_export_step();
215 215
         $done   = $this->get_export_status();
216 216
         
217
-        if ( $return ) {
217
+        if ($return) {
218 218
             $this->step += 1;
219 219
             
220 220
             $response['success']    = true;
221 221
             $response['msg']        = '';
222 222
             
223
-            if ( $done >= 100 ) {
223
+            if ($done >= 100) {
224 224
                 $this->step     = 'done';
225
-                $new_filename   = 'wpi-' . $this->export . '-' . date( 'y-m-d-H-i' ) . '.' . $this->filetype;
225
+                $new_filename   = 'wpi-' . $this->export . '-' . date('y-m-d-H-i') . '.' . $this->filetype;
226 226
                 $new_file       = $this->export_dir . $new_filename;
227 227
                 
228
-                if ( file_exists( $this->file ) ) {
229
-                    $this->wp_filesystem->move( $this->file, $new_file, true );
228
+                if (file_exists($this->file)) {
229
+                    $this->wp_filesystem->move($this->file, $new_file, true);
230 230
                 }
231 231
                 
232
-                if ( file_exists( $new_file ) ) {
233
-                    $response['data']['file'] = array( 'u' => $this->export_url . $new_filename, 's' => size_format( filesize( $new_file ), 2 ) );
232
+                if (file_exists($new_file)) {
233
+                    $response['data']['file'] = array('u' => $this->export_url . $new_filename, 's' => size_format(filesize($new_file), 2));
234 234
                 }
235 235
             }
236 236
             
237 237
             $response['data']['step']   = $this->step;
238 238
             $response['data']['done']   = $done;
239 239
         } else {
240
-            $response['msg']    = __( 'No data found for export.', 'invoicing' );
240
+            $response['msg'] = __('No data found for export.', 'invoicing');
241 241
         }
242 242
 
243
-        wp_send_json( $response );
243
+        wp_send_json($response);
244 244
     }
245 245
     
246
-    public function set_export_params( $request ) {
246
+    public function set_export_params($request) {
247 247
         $this->empty    = false;
248
-        $this->step     = !empty( $request['step'] ) ? absint( $request['step'] ) : 1;
249
-        $this->export   = !empty( $request['export'] ) ? $request['export'] : $this->export;
248
+        $this->step     = !empty($request['step']) ? absint($request['step']) : 1;
249
+        $this->export   = !empty($request['export']) ? $request['export'] : $this->export;
250 250
         $this->filename = 'wpi-' . $this->export . '-' . $request['wpi_ajax_export'] . '.' . $this->filetype;
251 251
         $this->file     = $this->export_dir . $this->filename;
252 252
         
253
-        do_action( 'wpinv_export_set_params_' . $this->export, $request );
253
+        do_action('wpinv_export_set_params_' . $this->export, $request);
254 254
     }
255 255
     
256 256
     public function get_columns() {
257 257
         $columns = array(
258
-            'id'   => __( 'ID',   'invoicing' ),
259
-            'date' => __( 'Date', 'invoicing' )
258
+            'id'   => __('ID', 'invoicing'),
259
+            'date' => __('Date', 'invoicing')
260 260
         );
261 261
         
262
-        return apply_filters( 'wpinv_export_get_columns_' . $this->export, $columns );
262
+        return apply_filters('wpinv_export_get_columns_' . $this->export, $columns);
263 263
     }
264 264
     
265 265
     protected function get_export_file() {
266 266
         $file = '';
267 267
 
268
-        if ( $this->wp_filesystem->exists( $this->file ) ) {
269
-            $file = $this->wp_filesystem->get_contents( $this->file );
268
+        if ($this->wp_filesystem->exists($this->file)) {
269
+            $file = $this->wp_filesystem->get_contents($this->file);
270 270
         } else {
271
-            $this->wp_filesystem->put_contents( $this->file, '' );
271
+            $this->wp_filesystem->put_contents($this->file, '');
272 272
         }
273 273
 
274 274
         return $file;
275 275
     }
276 276
     
277
-    protected function attach_export_data( $data = '' ) {
278
-        $filedata   = $this->get_export_file();
279
-        $filedata   .= $data;
277
+    protected function attach_export_data($data = '') {
278
+        $filedata = $this->get_export_file();
279
+        $filedata .= $data;
280 280
         
281
-        $this->wp_filesystem->put_contents( $this->file, $filedata );
281
+        $this->wp_filesystem->put_contents($this->file, $filedata);
282 282
 
283
-        $rows       = file( $this->file, FILE_SKIP_EMPTY_LINES );
283
+        $rows       = file($this->file, FILE_SKIP_EMPTY_LINES);
284 284
         $columns    = $this->get_columns();
285
-        $columns    = empty( $columns ) ? 0 : 1;
285
+        $columns    = empty($columns) ? 0 : 1;
286 286
 
287
-        $this->empty = count( $rows ) == $columns ? true : false;
287
+        $this->empty = count($rows) == $columns ? true : false;
288 288
     }
289 289
     
290 290
     public function print_columns() {
291 291
         $column_data    = '';
292 292
         $columns        = $this->get_columns();
293 293
         $i              = 1;
294
-        foreach( $columns as $key => $column ) {
295
-            $column_data .= '"' . addslashes( $column ) . '"';
296
-            $column_data .= $i == count( $columns ) ? '' : ',';
294
+        foreach ($columns as $key => $column) {
295
+            $column_data .= '"' . addslashes($column) . '"';
296
+            $column_data .= $i == count($columns) ? '' : ',';
297 297
             $i++;
298 298
         }
299 299
         $column_data .= "\r\n";
300 300
 
301
-        $this->attach_export_data( $column_data );
301
+        $this->attach_export_data($column_data);
302 302
 
303 303
         return $column_data;
304 304
     }
305 305
     
306 306
     public function process_export_step() {
307
-        if ( $this->step < 2 ) {
308
-            @unlink( $this->file );
307
+        if ($this->step < 2) {
308
+            @unlink($this->file);
309 309
             $this->print_columns();
310 310
         }
311 311
         
312 312
         $return = $this->print_rows();
313 313
         
314
-        if ( $return ) {
314
+        if ($return) {
315 315
             return true;
316 316
         } else {
317 317
             return false;
@@ -320,23 +320,23 @@  discard block
 block discarded – undo
320 320
     
321 321
     public function get_export_status() {
322 322
         $status = 100;
323
-        return apply_filters( 'wpinv_get_export_status_' . $this->export, $status );
323
+        return apply_filters('wpinv_get_export_status_' . $this->export, $status);
324 324
     }
325 325
     
326 326
     public function get_export_data() {
327 327
         $data = array(
328 328
             0 => array(
329 329
                 'id'   => '',
330
-                'data' => date( 'F j, Y' )
330
+                'data' => date('F j, Y')
331 331
             ),
332 332
             1 => array(
333 333
                 'id'   => '',
334
-                'data' => date( 'F j, Y' )
334
+                'data' => date('F j, Y')
335 335
             )
336 336
         );
337 337
 
338
-        $data = apply_filters( 'wpinv_export_get_data', $data );
339
-        $data = apply_filters( 'wpinv_export_get_data_' . $this->export, $data );
338
+        $data = apply_filters('wpinv_export_get_data', $data);
339
+        $data = apply_filters('wpinv_export_get_data_' . $this->export, $data);
340 340
 
341 341
         return $data;
342 342
     }
@@ -346,20 +346,20 @@  discard block
 block discarded – undo
346 346
         $data       = $this->get_export_data();
347 347
         $columns    = $this->get_columns();
348 348
 
349
-        if ( $data ) {
350
-            foreach ( $data as $row ) {
349
+        if ($data) {
350
+            foreach ($data as $row) {
351 351
                 $i = 1;
352
-                foreach ( $row as $key => $column ) {
353
-                    if ( array_key_exists( $key, $columns ) ) {
354
-                        $row_data .= '"' . addslashes( preg_replace( "/\"/","'", $column ) ) . '"';
355
-                        $row_data .= $i == count( $columns ) ? '' : ',';
352
+                foreach ($row as $key => $column) {
353
+                    if (array_key_exists($key, $columns)) {
354
+                        $row_data .= '"' . addslashes(preg_replace("/\"/", "'", $column)) . '"';
355
+                        $row_data .= $i == count($columns) ? '' : ',';
356 356
                         $i++;
357 357
                     }
358 358
                 }
359 359
                 $row_data .= "\r\n";
360 360
             }
361 361
 
362
-            $this->attach_export_data( $row_data );
362
+            $this->attach_export_data($row_data);
363 363
 
364 364
             return $row_data;
365 365
         }
@@ -368,46 +368,46 @@  discard block
 block discarded – undo
368 368
     }
369 369
     
370 370
     // Export Invoices.
371
-    public function set_invoices_export( $request ) {
372
-        $this->from_date    = isset( $request['from_date'] ) ? sanitize_text_field( $request['from_date'] ) : '';
373
-        $this->to_date      = isset( $request['to_date'] ) ? sanitize_text_field( $request['to_date'] ) : '';
374
-        $this->status       = isset( $request['status'] ) ? sanitize_text_field( $request['status'] ) : 'publich';
371
+    public function set_invoices_export($request) {
372
+        $this->from_date    = isset($request['from_date']) ? sanitize_text_field($request['from_date']) : '';
373
+        $this->to_date      = isset($request['to_date']) ? sanitize_text_field($request['to_date']) : '';
374
+        $this->status       = isset($request['status']) ? sanitize_text_field($request['status']) : 'publich';
375 375
     }
376 376
     
377
-    public function get_invoices_columns( $columns = array() ) {
377
+    public function get_invoices_columns($columns = array()) {
378 378
         $columns = array(
379
-            'id'            => __( 'ID',   'invoicing' ),
380
-            'number'        => __( 'Number',   'invoicing' ),
381
-            'date'          => __( 'Date', 'invoicing' ),
382
-            'amount'        => __( 'Amount', 'invoicing' ),
383
-            'status_nicename'  => __( 'Status Nicename', 'invoicing' ),
384
-            'status'        => __( 'Status', 'invoicing' ),
385
-            'tax'           => __( 'Tax', 'invoicing' ),
386
-            'discount'      => __( 'Discount', 'invoicing' ),
387
-            'user_id'       => __( 'User ID', 'invoicing' ),
388
-            'email'         => __( 'Email', 'invoicing' ),
389
-            'first_name'    => __( 'First Name', 'invoicing' ),
390
-            'last_name'     => __( 'Last Name', 'invoicing' ),
391
-            'address'       => __( 'Address', 'invoicing' ),
392
-            'city'          => __( 'City', 'invoicing' ),
393
-            'state'         => __( 'State', 'invoicing' ),
394
-            'country'       => __( 'Country', 'invoicing' ),
395
-            'zip'           => __( 'Zipcode', 'invoicing' ),
396
-            'phone'         => __( 'Phone', 'invoicing' ),
397
-            'company'       => __( 'Company', 'invoicing' ),
398
-            'vat_number'    => __( 'Vat Number', 'invoicing' ),
399
-            'ip'            => __( 'IP', 'invoicing' ),
400
-            'gateway'       => __( 'Gateway', 'invoicing' ),
401
-            'gateway_nicename'       => __( 'Gateway Nicename', 'invoicing' ),
402
-            'transaction_id'=> __( 'Transaction ID', 'invoicing' ),
403
-            'currency'      => __( 'Currency', 'invoicing' ),
404
-            'due_date'      => __( 'Due Date', 'invoicing' ),
379
+            'id'            => __('ID', 'invoicing'),
380
+            'number'        => __('Number', 'invoicing'),
381
+            'date'          => __('Date', 'invoicing'),
382
+            'amount'        => __('Amount', 'invoicing'),
383
+            'status_nicename'  => __('Status Nicename', 'invoicing'),
384
+            'status'        => __('Status', 'invoicing'),
385
+            'tax'           => __('Tax', 'invoicing'),
386
+            'discount'      => __('Discount', 'invoicing'),
387
+            'user_id'       => __('User ID', 'invoicing'),
388
+            'email'         => __('Email', 'invoicing'),
389
+            'first_name'    => __('First Name', 'invoicing'),
390
+            'last_name'     => __('Last Name', 'invoicing'),
391
+            'address'       => __('Address', 'invoicing'),
392
+            'city'          => __('City', 'invoicing'),
393
+            'state'         => __('State', 'invoicing'),
394
+            'country'       => __('Country', 'invoicing'),
395
+            'zip'           => __('Zipcode', 'invoicing'),
396
+            'phone'         => __('Phone', 'invoicing'),
397
+            'company'       => __('Company', 'invoicing'),
398
+            'vat_number'    => __('Vat Number', 'invoicing'),
399
+            'ip'            => __('IP', 'invoicing'),
400
+            'gateway'       => __('Gateway', 'invoicing'),
401
+            'gateway_nicename'       => __('Gateway Nicename', 'invoicing'),
402
+            'transaction_id'=> __('Transaction ID', 'invoicing'),
403
+            'currency'      => __('Currency', 'invoicing'),
404
+            'due_date'      => __('Due Date', 'invoicing'),
405 405
         );
406 406
 
407 407
         return $columns;
408 408
     }
409 409
         
410
-    public function get_invoices_data( $response = array() ) {
410
+    public function get_invoices_data($response = array()) {
411 411
         $args = array(
412 412
             'limit'    => $this->per_page,
413 413
             'page'     => $this->step,
@@ -415,35 +415,35 @@  discard block
 block discarded – undo
415 415
             'orderby'  => 'date',
416 416
         );
417 417
         
418
-        if ( $this->status != 'any' ) {
418
+        if ($this->status != 'any') {
419 419
             $args['status'] = $this->status;
420 420
         }
421 421
 
422
-        if ( !empty( $this->from_date ) || !empty( $this->to_date ) ) {
422
+        if (!empty($this->from_date) || !empty($this->to_date)) {
423 423
             $args['date_query'] = array(
424 424
                 array(
425
-                    'after'     => date( 'Y-n-d 00:00:00', strtotime( $this->from_date ) ),
426
-                    'before'    => date( 'Y-n-d 23:59:59', strtotime( $this->to_date ) ),
425
+                    'after'     => date('Y-n-d 00:00:00', strtotime($this->from_date)),
426
+                    'before'    => date('Y-n-d 23:59:59', strtotime($this->to_date)),
427 427
                     'inclusive' => true
428 428
                 )
429 429
             );
430 430
         }
431 431
 
432
-        $invoices = wpinv_get_invoices( $args );
432
+        $invoices = wpinv_get_invoices($args);
433 433
         
434 434
         $data = array();
435 435
         
436
-        if ( !empty( $invoices ) ) {
437
-            foreach ( $invoices as $invoice ) {
436
+        if (!empty($invoices)) {
437
+            foreach ($invoices as $invoice) {
438 438
                 $row = array(
439 439
                     'id'            => $invoice->ID,
440 440
                     'number'        => $invoice->get_number(),
441
-                    'date'          => $invoice->get_invoice_date( false ),
442
-                    'amount'        => wpinv_format_amount( $invoice->get_total(), NULL, true ),
443
-                    'status_nicename' => $invoice->get_status( true ),
441
+                    'date'          => $invoice->get_invoice_date(false),
442
+                    'amount'        => wpinv_format_amount($invoice->get_total(), NULL, true),
443
+                    'status_nicename' => $invoice->get_status(true),
444 444
                     'status'        => $invoice->get_status(),
445
-                    'tax'           => $invoice->get_tax() > 0 ? wpinv_format_amount( $invoice->get_tax(), NULL, true ) : '',
446
-                    'discount'      => $invoice->get_discount() > 0 ? wpinv_format_amount( $invoice->get_discount(), NULL, true ) : '',
445
+                    'tax'           => $invoice->get_tax() > 0 ? wpinv_format_amount($invoice->get_tax(), NULL, true) : '',
446
+                    'discount'      => $invoice->get_discount() > 0 ? wpinv_format_amount($invoice->get_discount(), NULL, true) : '',
447 447
                     'user_id'       => $invoice->get_user_id(),
448 448
                     'email'         => $invoice->get_email(),
449 449
                     'first_name'    => $invoice->get_first_name(),
@@ -464,7 +464,7 @@  discard block
 block discarded – undo
464 464
                     'due_date'      => $invoice->needs_payment() ? $invoice->get_due_date() : '',
465 465
                 );
466 466
                 
467
-                $data[] = apply_filters( 'wpinv_export_invoice_row', $row, $invoice );
467
+                $data[] = apply_filters('wpinv_export_invoice_row', $row, $invoice);
468 468
             }
469 469
 
470 470
             return $data;
@@ -480,29 +480,29 @@  discard block
 block discarded – undo
480 480
             'return'   => 'ids',
481 481
         );
482 482
         
483
-        if ( $this->status != 'any' ) {
483
+        if ($this->status != 'any') {
484 484
             $args['status'] = $this->status;
485 485
         }
486 486
 
487
-        if ( !empty( $this->from_date ) || !empty( $this->to_date ) ) {
487
+        if (!empty($this->from_date) || !empty($this->to_date)) {
488 488
             $args['date_query'] = array(
489 489
                 array(
490
-                    'after'     => date( 'Y-n-d 00:00:00', strtotime( $this->from_date ) ),
491
-                    'before'    => date( 'Y-n-d 23:59:59', strtotime( $this->to_date ) ),
490
+                    'after'     => date('Y-n-d 00:00:00', strtotime($this->from_date)),
491
+                    'before'    => date('Y-n-d 23:59:59', strtotime($this->to_date)),
492 492
                     'inclusive' => true
493 493
                 )
494 494
             );
495 495
         }
496 496
 
497
-        $invoices   = wpinv_get_invoices( $args );
498
-        $total      = !empty( $invoices ) ? count( $invoices ) : 0;
497
+        $invoices   = wpinv_get_invoices($args);
498
+        $total      = !empty($invoices) ? count($invoices) : 0;
499 499
         $status     = 100;
500 500
 
501
-        if ( $total > 0 ) {
502
-            $status = ( ( $this->per_page * $this->step ) / $total ) * 100;
501
+        if ($total > 0) {
502
+            $status = (($this->per_page * $this->step) / $total) * 100;
503 503
         }
504 504
 
505
-        if ( $status > 100 ) {
505
+        if ($status > 100) {
506 506
             $status = 100;
507 507
         }
508 508
 
Please login to merge, or discard this patch.
includes/wpinv-helper-functions.php 1 patch
Spacing   +236 added lines, -236 removed lines patch added patch discarded remove patch
@@ -7,112 +7,112 @@  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 ) {
44
+function wpinv_sanitize_amount($amount) {
45 45
     $is_negative   = false;
46 46
     $thousands_sep = wpinv_thousands_seperator();
47 47
     $decimal_sep   = wpinv_decimal_seperator();
48 48
 
49 49
     // Sanitize the amount
50
-    if ( $decimal_sep == ',' && false !== ( $found = strpos( $amount, $decimal_sep ) ) ) {
51
-        if ( ( $thousands_sep == '.' || $thousands_sep == ' ' ) && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) {
52
-            $amount = str_replace( $thousands_sep, '', $amount );
53
-        } elseif( empty( $thousands_sep ) && false !== ( $found = strpos( $amount, '.' ) ) ) {
54
-            $amount = str_replace( '.', '', $amount );
50
+    if ($decimal_sep == ',' && false !== ($found = strpos($amount, $decimal_sep))) {
51
+        if (($thousands_sep == '.' || $thousands_sep == ' ') && false !== ($found = strpos($amount, $thousands_sep))) {
52
+            $amount = str_replace($thousands_sep, '', $amount);
53
+        } elseif (empty($thousands_sep) && false !== ($found = strpos($amount, '.'))) {
54
+            $amount = str_replace('.', '', $amount);
55 55
         }
56 56
 
57
-        $amount = str_replace( $decimal_sep, '.', $amount );
58
-    } elseif( $thousands_sep == ',' && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) {
59
-        $amount = str_replace( $thousands_sep, '', $amount );
57
+        $amount = str_replace($decimal_sep, '.', $amount);
58
+    } elseif ($thousands_sep == ',' && false !== ($found = strpos($amount, $thousands_sep))) {
59
+        $amount = str_replace($thousands_sep, '', $amount);
60 60
     }
61 61
 
62
-    if( $amount < 0 ) {
62
+    if ($amount < 0) {
63 63
         $is_negative = true;
64 64
     }
65 65
 
66
-    $amount   = preg_replace( '/[^0-9\.]/', '', $amount );
66
+    $amount   = preg_replace('/[^0-9\.]/', '', $amount);
67 67
 
68
-    $decimals = apply_filters( 'wpinv_sanitize_amount_decimals', 2, $amount );
69
-    $amount   = number_format( (double) $amount, $decimals, '.', '' );
68
+    $decimals = apply_filters('wpinv_sanitize_amount_decimals', 2, $amount);
69
+    $amount   = number_format((double)$amount, $decimals, '.', '');
70 70
 
71
-    if( $is_negative ) {
71
+    if ($is_negative) {
72 72
         $amount *= -1;
73 73
     }
74 74
 
75
-    return apply_filters( 'wpinv_sanitize_amount', $amount );
75
+    return apply_filters('wpinv_sanitize_amount', $amount);
76 76
 }
77 77
 
78
-function wpinv_get_invoice_statuses( $trashed = false ) {
78
+function wpinv_get_invoice_statuses($trashed = false) {
79 79
     $invoice_statuses = array(
80
-        'pending'       => __( 'Pending Payment', 'invoicing' ),
81
-        'publish'       => __( 'Paid', 'invoicing' ),
82
-        'processing'    => __( 'Processing', 'invoicing' ),
83
-        'onhold'        => __( 'On Hold', 'invoicing' ),
84
-        'refunded'      => __( 'Refunded', 'invoicing' ),
85
-        'cancelled'     => __( 'Cancelled', 'invoicing' ),
86
-        'failed'        => __( 'Failed', 'invoicing' ),
87
-        'renewal'       => __( 'Renewal Payment', 'invoicing' )
80
+        'pending'       => __('Pending Payment', 'invoicing'),
81
+        'publish'       => __('Paid', 'invoicing'),
82
+        'processing'    => __('Processing', 'invoicing'),
83
+        'onhold'        => __('On Hold', 'invoicing'),
84
+        'refunded'      => __('Refunded', 'invoicing'),
85
+        'cancelled'     => __('Cancelled', 'invoicing'),
86
+        'failed'        => __('Failed', 'invoicing'),
87
+        'renewal'       => __('Renewal Payment', 'invoicing')
88 88
     );
89 89
     
90
-    if ( $trashed ) {
91
-        $invoice_statuses['trash'] = __( 'Trash', 'invoicing' );
90
+    if ($trashed) {
91
+        $invoice_statuses['trash'] = __('Trash', 'invoicing');
92 92
     }
93 93
 
94
-    return apply_filters( 'wpinv_statuses', $invoice_statuses );
94
+    return apply_filters('wpinv_statuses', $invoice_statuses);
95 95
 }
96 96
 
97
-function wpinv_status_nicename( $status ) {
97
+function wpinv_status_nicename($status) {
98 98
     $statuses = wpinv_get_invoice_statuses();
99
-    $status   = isset( $statuses[$status] ) ? $statuses[$status] : __( $status, 'invoicing' );
99
+    $status   = isset($statuses[$status]) ? $statuses[$status] : __($status, 'invoicing');
100 100
 
101 101
     return $status;
102 102
 }
103 103
 
104 104
 function wpinv_get_currency() {
105
-    $currency = wpinv_get_option( 'currency', 'USD' );
105
+    $currency = wpinv_get_option('currency', 'USD');
106 106
     
107
-    return apply_filters( 'wpinv_currency', $currency );
107
+    return apply_filters('wpinv_currency', $currency);
108 108
 }
109 109
 
110
-function wpinv_currency_symbol( $currency = '' ) {
111
-    if ( empty( $currency ) ) {
110
+function wpinv_currency_symbol($currency = '') {
111
+    if (empty($currency)) {
112 112
         $currency = wpinv_get_currency();
113 113
     }
114 114
     
115
-    $symbols = apply_filters( 'wpinv_currency_symbols', array(
115
+    $symbols = apply_filters('wpinv_currency_symbols', array(
116 116
         'AED' => 'د.إ',
117 117
         'ARS' => '&#36;',
118 118
         'AUD' => '&#36;',
@@ -164,78 +164,78 @@  discard block
 block discarded – undo
164 164
         'USD' => '&#36;',
165 165
         'VND' => '&#8363;',
166 166
         'ZAR' => '&#82;',
167
-    ) );
167
+    ));
168 168
 
169
-    $currency_symbol = isset( $symbols[$currency] ) ? $symbols[$currency] : '&#36;';
169
+    $currency_symbol = isset($symbols[$currency]) ? $symbols[$currency] : '&#36;';
170 170
 
171
-    return apply_filters( 'wpinv_currency_symbol', $currency_symbol, $currency );
171
+    return apply_filters('wpinv_currency_symbol', $currency_symbol, $currency);
172 172
 }
173 173
 
174 174
 function wpinv_currency_position() {
175
-    $position = wpinv_get_option( 'currency_position', 'left' );
175
+    $position = wpinv_get_option('currency_position', 'left');
176 176
     
177
-    return apply_filters( 'wpinv_currency_position', $position );
177
+    return apply_filters('wpinv_currency_position', $position);
178 178
 }
179 179
 
180 180
 function wpinv_thousands_seperator() {
181
-    $thousand_sep = wpinv_get_option( 'thousands_seperator', ',' );
181
+    $thousand_sep = wpinv_get_option('thousands_seperator', ',');
182 182
     
183
-    return apply_filters( 'wpinv_thousands_seperator', $thousand_sep );
183
+    return apply_filters('wpinv_thousands_seperator', $thousand_sep);
184 184
 }
185 185
 
186 186
 function wpinv_decimal_seperator() {
187
-    $decimal_sep = wpinv_get_option( 'decimal_seperator', '.' );
187
+    $decimal_sep = wpinv_get_option('decimal_seperator', '.');
188 188
     
189
-    return apply_filters( 'wpinv_decimal_seperator', $decimal_sep );
189
+    return apply_filters('wpinv_decimal_seperator', $decimal_sep);
190 190
 }
191 191
 
192 192
 function wpinv_decimals() {
193
-    $decimals = wpinv_get_option( 'decimals', 2 );
193
+    $decimals = wpinv_get_option('decimals', 2);
194 194
     
195
-    return apply_filters( 'wpinv_decimals', $decimals );
195
+    return apply_filters('wpinv_decimals', $decimals);
196 196
 }
197 197
 
198 198
 function wpinv_get_currencies() {
199 199
     $currencies = array(
200
-        'USD'  => __( 'US Dollars (&#36;)', 'invoicing' ),
201
-        'EUR'  => __( 'Euros (&euro;)', 'invoicing' ),
202
-        'GBP'  => __( 'Pounds Sterling (&pound;)', 'invoicing' ),
203
-        'AUD'  => __( 'Australian Dollars (&#36;)', 'invoicing' ),
204
-        'BRL'  => __( 'Brazilian Real (R&#36;)', 'invoicing' ),
205
-        'CAD'  => __( 'Canadian Dollars (&#36;)', 'invoicing' ),
206
-        'CLP'  => __( 'Chilean Peso (&#36;)', 'invoicing' ),
207
-        'CNY'  => __( 'Chinese Yuan (&yen;)', 'invoicing' ),
208
-        'CZK'  => __( 'Czech Koruna (&#75;&#269;)', 'invoicing' ),
209
-        'DKK'  => __( 'Danish Krone (DKK)', 'invoicing' ),
210
-        'HKD'  => __( 'Hong Kong Dollar (&#36;)', 'invoicing' ),
211
-        'HUF'  => __( 'Hungarian Forint (&#70;&#116;)', 'invoicing' ),
212
-        'INR'  => __( 'Indian Rupee (&#8377;)', 'invoicing' ),
213
-        'ILS'  => __( 'Israeli Shekel (&#8362;)', 'invoicing' ),
214
-        'JPY'  => __( 'Japanese Yen (&yen;)', 'invoicing' ),
215
-        'MYR'  => __( 'Malaysian Ringgit (&#82;&#77;)', 'invoicing' ),
216
-        'MXN'  => __( 'Mexican Peso (&#36;)', 'invoicing' ),
217
-        'NZD'  => __( 'New Zealand Dollar (&#36;)', 'invoicing' ),
218
-        'NOK'  => __( 'Norwegian Krone (&#107;&#114;)', 'invoicing' ),
219
-        'PHP'  => __( 'Philippine Peso (&#8369;)', 'invoicing' ),
220
-        'PLN'  => __( 'Polish Zloty (&#122;&#322;)', 'invoicing' ),
221
-        'SGD'  => __( 'Singapore Dollar (&#36;)', 'invoicing' ),
222
-        'SEK'  => __( 'Swedish Krona (&#107;&#114;)', 'invoicing' ),
223
-        'CHF'  => __( 'Swiss Franc (&#67;&#72;&#70;)', 'invoicing' ),
224
-        'TWD'  => __( 'Taiwan New Dollar (&#78;&#84;&#36;)', 'invoicing' ),
225
-        'THB'  => __( 'Thai Baht (&#3647;)', 'invoicing' ),
226
-        'TRY'  => __( 'Turkish Lira (&#8378;)', 'invoicing' ),
227
-        'RIAL' => __( 'Iranian Rial (&#65020;)', 'invoicing' ),
228
-        'RUB'  => __( 'Russian Ruble (&#8381;)', 'invoicing' ),
229
-        'ZAR'  => __( 'South African Rand (&#82;)', 'invoicing' )
200
+        'USD'  => __('US Dollars (&#36;)', 'invoicing'),
201
+        'EUR'  => __('Euros (&euro;)', 'invoicing'),
202
+        'GBP'  => __('Pounds Sterling (&pound;)', 'invoicing'),
203
+        'AUD'  => __('Australian Dollars (&#36;)', 'invoicing'),
204
+        'BRL'  => __('Brazilian Real (R&#36;)', 'invoicing'),
205
+        'CAD'  => __('Canadian Dollars (&#36;)', 'invoicing'),
206
+        'CLP'  => __('Chilean Peso (&#36;)', 'invoicing'),
207
+        'CNY'  => __('Chinese Yuan (&yen;)', 'invoicing'),
208
+        'CZK'  => __('Czech Koruna (&#75;&#269;)', 'invoicing'),
209
+        'DKK'  => __('Danish Krone (DKK)', 'invoicing'),
210
+        'HKD'  => __('Hong Kong Dollar (&#36;)', 'invoicing'),
211
+        'HUF'  => __('Hungarian Forint (&#70;&#116;)', 'invoicing'),
212
+        'INR'  => __('Indian Rupee (&#8377;)', 'invoicing'),
213
+        'ILS'  => __('Israeli Shekel (&#8362;)', 'invoicing'),
214
+        'JPY'  => __('Japanese Yen (&yen;)', 'invoicing'),
215
+        'MYR'  => __('Malaysian Ringgit (&#82;&#77;)', 'invoicing'),
216
+        'MXN'  => __('Mexican Peso (&#36;)', 'invoicing'),
217
+        'NZD'  => __('New Zealand Dollar (&#36;)', 'invoicing'),
218
+        'NOK'  => __('Norwegian Krone (&#107;&#114;)', 'invoicing'),
219
+        'PHP'  => __('Philippine Peso (&#8369;)', 'invoicing'),
220
+        'PLN'  => __('Polish Zloty (&#122;&#322;)', 'invoicing'),
221
+        'SGD'  => __('Singapore Dollar (&#36;)', 'invoicing'),
222
+        'SEK'  => __('Swedish Krona (&#107;&#114;)', 'invoicing'),
223
+        'CHF'  => __('Swiss Franc (&#67;&#72;&#70;)', 'invoicing'),
224
+        'TWD'  => __('Taiwan New Dollar (&#78;&#84;&#36;)', 'invoicing'),
225
+        'THB'  => __('Thai Baht (&#3647;)', 'invoicing'),
226
+        'TRY'  => __('Turkish Lira (&#8378;)', 'invoicing'),
227
+        'RIAL' => __('Iranian Rial (&#65020;)', 'invoicing'),
228
+        'RUB'  => __('Russian Ruble (&#8381;)', 'invoicing'),
229
+        'ZAR'  => __('South African Rand (&#82;)', 'invoicing')
230 230
     );
231 231
     
232
-    asort( $currencies );
232
+    asort($currencies);
233 233
 
234
-    return apply_filters( 'wpinv_currencies', $currencies );
234
+    return apply_filters('wpinv_currencies', $currencies);
235 235
 }
236 236
 
237
-function wpinv_price( $amount = '', $currency = '' ) {
238
-    if( empty( $currency ) ) {
237
+function wpinv_price($amount = '', $currency = '') {
238
+    if (empty($currency)) {
239 239
         $currency = wpinv_get_currency();
240 240
     }
241 241
 
@@ -243,14 +243,14 @@  discard block
 block discarded – undo
243 243
 
244 244
     $negative = $amount < 0;
245 245
 
246
-    if ( $negative ) {
247
-        $amount = substr( $amount, 1 );
246
+    if ($negative) {
247
+        $amount = substr($amount, 1);
248 248
     }
249 249
 
250
-    $symbol = wpinv_currency_symbol( $currency );
250
+    $symbol = wpinv_currency_symbol($currency);
251 251
 
252
-    if ( $position == 'left' || $position == 'left_space' ) {
253
-        switch ( $currency ) {
252
+    if ($position == 'left' || $position == 'left_space') {
253
+        switch ($currency) {
254 254
             case "GBP" :
255 255
             case "BRL" :
256 256
             case "EUR" :
@@ -262,15 +262,15 @@  discard block
 block discarded – undo
262 262
             case "NZD" :
263 263
             case "SGD" :
264 264
             case "JPY" :
265
-                $price = $position == 'left_space' ? $symbol . ' ' .  $amount : $symbol . $amount;
265
+                $price = $position == 'left_space' ? $symbol . ' ' . $amount : $symbol . $amount;
266 266
                 break;
267 267
             default :
268 268
                 //$price = $currency . ' ' . $amount;
269
-                $price = $position == 'left_space' ? $symbol . ' ' .  $amount : $symbol . $amount;
269
+                $price = $position == 'left_space' ? $symbol . ' ' . $amount : $symbol . $amount;
270 270
                 break;
271 271
         }
272 272
     } else {
273
-        switch ( $currency ) {
273
+        switch ($currency) {
274 274
             case "GBP" :
275 275
             case "BRL" :
276 276
             case "EUR" :
@@ -281,82 +281,82 @@  discard block
 block discarded – undo
281 281
             case "MXN" :
282 282
             case "SGD" :
283 283
             case "JPY" :
284
-                $price = $position == 'right_space' ? $amount . ' ' .  $symbol : $amount . $symbol;
284
+                $price = $position == 'right_space' ? $amount . ' ' . $symbol : $amount . $symbol;
285 285
                 break;
286 286
             default :
287 287
                 //$price = $amount . ' ' . $currency;
288
-                $price = $position == 'right_space' ? $amount . ' ' .  $symbol : $amount . $symbol;
288
+                $price = $position == 'right_space' ? $amount . ' ' . $symbol : $amount . $symbol;
289 289
                 break;
290 290
         }
291 291
     }
292 292
     
293
-    if ( $negative ) {
293
+    if ($negative) {
294 294
         $price = '-' . $price;
295 295
     }
296 296
     
297
-    $price = apply_filters( 'wpinv_' . strtolower( $currency ) . '_currency_filter_' . $position, $price, $currency, $amount );
297
+    $price = apply_filters('wpinv_' . strtolower($currency) . '_currency_filter_' . $position, $price, $currency, $amount);
298 298
 
299 299
     return $price;
300 300
 }
301 301
 
302
-function wpinv_format_amount( $amount, $decimals = NULL, $calculate = false ) {
302
+function wpinv_format_amount($amount, $decimals = NULL, $calculate = false) {
303 303
     $thousands_sep = wpinv_thousands_seperator();
304 304
     $decimal_sep   = wpinv_decimal_seperator();
305 305
 
306
-    if ( $decimals === NULL ) {
306
+    if ($decimals === NULL) {
307 307
         $decimals = wpinv_decimals();
308 308
     }
309 309
 
310
-    if ( $decimal_sep == ',' && false !== ( $sep_found = strpos( $amount, $decimal_sep ) ) ) {
311
-        $whole = substr( $amount, 0, $sep_found );
312
-        $part = substr( $amount, $sep_found + 1, ( strlen( $amount ) - 1 ) );
310
+    if ($decimal_sep == ',' && false !== ($sep_found = strpos($amount, $decimal_sep))) {
311
+        $whole = substr($amount, 0, $sep_found);
312
+        $part = substr($amount, $sep_found + 1, (strlen($amount) - 1));
313 313
         $amount = $whole . '.' . $part;
314 314
     }
315 315
 
316
-    if ( $thousands_sep == ',' && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) {
317
-        $amount = str_replace( ',', '', $amount );
316
+    if ($thousands_sep == ',' && false !== ($found = strpos($amount, $thousands_sep))) {
317
+        $amount = str_replace(',', '', $amount);
318 318
     }
319 319
 
320
-    if ( $thousands_sep == ' ' && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) {
321
-        $amount = str_replace( ' ', '', $amount );
320
+    if ($thousands_sep == ' ' && false !== ($found = strpos($amount, $thousands_sep))) {
321
+        $amount = str_replace(' ', '', $amount);
322 322
     }
323 323
 
324
-    if ( empty( $amount ) ) {
324
+    if (empty($amount)) {
325 325
         $amount = 0;
326 326
     }
327 327
     
328
-    $decimals  = apply_filters( 'wpinv_amount_format_decimals', $decimals ? $decimals : 0, $amount, $calculate );
329
-    $formatted = number_format( (float)$amount, $decimals, $decimal_sep, $thousands_sep );
328
+    $decimals  = apply_filters('wpinv_amount_format_decimals', $decimals ? $decimals : 0, $amount, $calculate);
329
+    $formatted = number_format((float)$amount, $decimals, $decimal_sep, $thousands_sep);
330 330
     
331
-    if ( $calculate ) {
332
-        if ( $thousands_sep === "," ) {
333
-            $formatted = str_replace( ",", "", $formatted );
331
+    if ($calculate) {
332
+        if ($thousands_sep === ",") {
333
+            $formatted = str_replace(",", "", $formatted);
334 334
         }
335 335
         
336
-        if ( $decimal_sep === "," ) {
337
-            $formatted = str_replace( ",", ".", $formatted );
336
+        if ($decimal_sep === ",") {
337
+            $formatted = str_replace(",", ".", $formatted);
338 338
         }
339 339
     }
340 340
 
341
-    return apply_filters( 'wpinv_amount_format', $formatted, $amount, $decimals, $decimal_sep, $thousands_sep, $calculate );
341
+    return apply_filters('wpinv_amount_format', $formatted, $amount, $decimals, $decimal_sep, $thousands_sep, $calculate);
342 342
 }
343 343
 
344
-function wpinv_sanitize_key( $key ) {
344
+function wpinv_sanitize_key($key) {
345 345
     $raw_key = $key;
346
-    $key = preg_replace( '/[^a-zA-Z0-9_\-\.\:\/]/', '', $key );
346
+    $key = preg_replace('/[^a-zA-Z0-9_\-\.\:\/]/', '', $key);
347 347
 
348
-    return apply_filters( 'wpinv_sanitize_key', $key, $raw_key );
348
+    return apply_filters('wpinv_sanitize_key', $key, $raw_key);
349 349
 }
350 350
 
351
-function wpinv_get_file_extension( $str ) {
352
-    $parts = explode( '.', $str );
353
-    return end( $parts );
351
+function wpinv_get_file_extension($str) {
352
+    $parts = explode('.', $str);
353
+    return end($parts);
354 354
 }
355 355
 
356
-function wpinv_string_is_image_url( $str ) {
357
-    $ext = wpinv_get_file_extension( $str );
356
+function wpinv_string_is_image_url($str) {
357
+    $ext = wpinv_get_file_extension($str);
358 358
 
359
-    switch ( strtolower( $ext ) ) {
359
+    switch (strtolower($ext)) {
360 360
         case 'jpeg';
361 361
         case 'jpg';
362 362
             $return = true;
@@ -372,32 +372,32 @@  discard block
 block discarded – undo
372 372
             break;
373 373
     }
374 374
 
375
-    return (bool)apply_filters( 'wpinv_string_is_image', $return, $str );
375
+    return (bool)apply_filters('wpinv_string_is_image', $return, $str);
376 376
 }
377 377
 
378
-function wpinv_error_log( $log, $title = '', $file = '', $line = '', $exit = false ) {
379
-    $should_log = apply_filters( 'wpinv_log_errors', WP_DEBUG );
378
+function wpinv_error_log($log, $title = '', $file = '', $line = '', $exit = false) {
379
+    $should_log = apply_filters('wpinv_log_errors', WP_DEBUG);
380 380
     
381
-    if ( true === $should_log ) {
381
+    if (true === $should_log) {
382 382
         $label = '';
383
-        if ( $file && $file !== '' ) {
384
-            $label .= basename( $file ) . ( $line ? '(' . $line . ')' : '' );
383
+        if ($file && $file !== '') {
384
+            $label .= basename($file) . ($line ? '(' . $line . ')' : '');
385 385
         }
386 386
         
387
-        if ( $title && $title !== '' ) {
387
+        if ($title && $title !== '') {
388 388
             $label = $label !== '' ? $label . ' ' : '';
389 389
             $label .= $title . ' ';
390 390
         }
391 391
         
392
-        $label = $label !== '' ? trim( $label ) . ' : ' : '';
392
+        $label = $label !== '' ? trim($label) . ' : ' : '';
393 393
         
394
-        if ( is_array( $log ) || is_object( $log ) ) {
395
-            error_log( $label . print_r( $log, true ) );
394
+        if (is_array($log) || is_object($log)) {
395
+            error_log($label . print_r($log, true));
396 396
         } else {
397
-            error_log( $label . $log );
397
+            error_log($label . $log);
398 398
         }
399 399
         
400
-        if ( $exit ) {
400
+        if ($exit) {
401 401
             exit;
402 402
         }
403 403
     }
@@ -405,65 +405,65 @@  discard block
 block discarded – undo
405 405
 
406 406
 function wpinv_is_ajax_disabled() {
407 407
     $retval = false;
408
-    return apply_filters( 'wpinv_is_ajax_disabled', $retval );
408
+    return apply_filters('wpinv_is_ajax_disabled', $retval);
409 409
 }
410 410
 
411
-function wpinv_get_current_page_url( $nocache = false ) {
411
+function wpinv_get_current_page_url($nocache = false) {
412 412
     global $wp;
413 413
 
414
-    if ( get_option( 'permalink_structure' ) ) {
415
-        $base = trailingslashit( home_url( $wp->request ) );
414
+    if (get_option('permalink_structure')) {
415
+        $base = trailingslashit(home_url($wp->request));
416 416
     } else {
417
-        $base = add_query_arg( $wp->query_string, '', trailingslashit( home_url( $wp->request ) ) );
418
-        $base = remove_query_arg( array( 'post_type', 'name' ), $base );
417
+        $base = add_query_arg($wp->query_string, '', trailingslashit(home_url($wp->request)));
418
+        $base = remove_query_arg(array('post_type', 'name'), $base);
419 419
     }
420 420
 
421 421
     $scheme = is_ssl() ? 'https' : 'http';
422
-    $uri    = set_url_scheme( $base, $scheme );
422
+    $uri    = set_url_scheme($base, $scheme);
423 423
 
424
-    if ( is_front_page() ) {
425
-        $uri = home_url( '/' );
426
-    } elseif ( wpinv_is_checkout( array(), false ) ) {
424
+    if (is_front_page()) {
425
+        $uri = home_url('/');
426
+    } elseif (wpinv_is_checkout(array(), false)) {
427 427
         $uri = wpinv_get_checkout_uri();
428 428
     }
429 429
 
430
-    $uri = apply_filters( 'wpinv_get_current_page_url', $uri );
430
+    $uri = apply_filters('wpinv_get_current_page_url', $uri);
431 431
 
432
-    if ( $nocache ) {
433
-        $uri = wpinv_add_cache_busting( $uri );
432
+    if ($nocache) {
433
+        $uri = wpinv_add_cache_busting($uri);
434 434
     }
435 435
 
436 436
     return $uri;
437 437
 }
438 438
 
439 439
 function wpinv_get_php_arg_separator_output() {
440
-	return ini_get( 'arg_separator.output' );
440
+	return ini_get('arg_separator.output');
441 441
 }
442 442
 
443
-function wpinv_rgb_from_hex( $color ) {
444
-    $color = str_replace( '#', '', $color );
443
+function wpinv_rgb_from_hex($color) {
444
+    $color = str_replace('#', '', $color);
445 445
     // Convert shorthand colors to full format, e.g. "FFF" -> "FFFFFF"
446
-    $color = preg_replace( '~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color );
446
+    $color = preg_replace('~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color);
447 447
 
448 448
     $rgb      = array();
449
-    $rgb['R'] = hexdec( $color{0}.$color{1} );
450
-    $rgb['G'] = hexdec( $color{2}.$color{3} );
451
-    $rgb['B'] = hexdec( $color{4}.$color{5} );
449
+    $rgb['R'] = hexdec($color{0} . $color{1} );
450
+    $rgb['G'] = hexdec($color{2} . $color{3} );
451
+    $rgb['B'] = hexdec($color{4} . $color{5} );
452 452
 
453 453
     return $rgb;
454 454
 }
455 455
 
456
-function wpinv_hex_darker( $color, $factor = 30 ) {
457
-    $base  = wpinv_rgb_from_hex( $color );
456
+function wpinv_hex_darker($color, $factor = 30) {
457
+    $base  = wpinv_rgb_from_hex($color);
458 458
     $color = '#';
459 459
 
460
-    foreach ( $base as $k => $v ) {
460
+    foreach ($base as $k => $v) {
461 461
         $amount      = $v / 100;
462
-        $amount      = round( $amount * $factor );
462
+        $amount      = round($amount * $factor);
463 463
         $new_decimal = $v - $amount;
464 464
 
465
-        $new_hex_component = dechex( $new_decimal );
466
-        if ( strlen( $new_hex_component ) < 2 ) {
465
+        $new_hex_component = dechex($new_decimal);
466
+        if (strlen($new_hex_component) < 2) {
467 467
             $new_hex_component = "0" . $new_hex_component;
468 468
         }
469 469
         $color .= $new_hex_component;
@@ -472,18 +472,18 @@  discard block
 block discarded – undo
472 472
     return $color;
473 473
 }
474 474
 
475
-function wpinv_hex_lighter( $color, $factor = 30 ) {
476
-    $base  = wpinv_rgb_from_hex( $color );
475
+function wpinv_hex_lighter($color, $factor = 30) {
476
+    $base  = wpinv_rgb_from_hex($color);
477 477
     $color = '#';
478 478
 
479
-    foreach ( $base as $k => $v ) {
479
+    foreach ($base as $k => $v) {
480 480
         $amount      = 255 - $v;
481 481
         $amount      = $amount / 100;
482
-        $amount      = round( $amount * $factor );
482
+        $amount      = round($amount * $factor);
483 483
         $new_decimal = $v + $amount;
484 484
 
485
-        $new_hex_component = dechex( $new_decimal );
486
-        if ( strlen( $new_hex_component ) < 2 ) {
485
+        $new_hex_component = dechex($new_decimal);
486
+        if (strlen($new_hex_component) < 2) {
487 487
             $new_hex_component = "0" . $new_hex_component;
488 488
         }
489 489
         $color .= $new_hex_component;
@@ -492,22 +492,22 @@  discard block
 block discarded – undo
492 492
     return $color;
493 493
 }
494 494
 
495
-function wpinv_light_or_dark( $color, $dark = '#000000', $light = '#FFFFFF' ) {
496
-    $hex = str_replace( '#', '', $color );
495
+function wpinv_light_or_dark($color, $dark = '#000000', $light = '#FFFFFF') {
496
+    $hex = str_replace('#', '', $color);
497 497
 
498
-    $c_r = hexdec( substr( $hex, 0, 2 ) );
499
-    $c_g = hexdec( substr( $hex, 2, 2 ) );
500
-    $c_b = hexdec( substr( $hex, 4, 2 ) );
498
+    $c_r = hexdec(substr($hex, 0, 2));
499
+    $c_g = hexdec(substr($hex, 2, 2));
500
+    $c_b = hexdec(substr($hex, 4, 2));
501 501
 
502
-    $brightness = ( ( $c_r * 299 ) + ( $c_g * 587 ) + ( $c_b * 114 ) ) / 1000;
502
+    $brightness = (($c_r * 299) + ($c_g * 587) + ($c_b * 114)) / 1000;
503 503
 
504 504
     return $brightness > 155 ? $dark : $light;
505 505
 }
506 506
 
507
-function wpinv_format_hex( $hex ) {
508
-    $hex = trim( str_replace( '#', '', $hex ) );
507
+function wpinv_format_hex($hex) {
508
+    $hex = trim(str_replace('#', '', $hex));
509 509
 
510
-    if ( strlen( $hex ) == 3 ) {
510
+    if (strlen($hex) == 3) {
511 511
         $hex = $hex[0] . $hex[0] . $hex[1] . $hex[1] . $hex[2] . $hex[2];
512 512
     }
513 513
 
@@ -527,12 +527,12 @@  discard block
 block discarded – undo
527 527
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
528 528
  * @return string
529 529
  */
530
-function wpinv_utf8_strimwidth( $str, $start, $width, $trimmaker = '', $encoding = 'UTF-8' ) {
531
-    if ( function_exists( 'mb_strimwidth' ) ) {
532
-        return mb_strimwidth( $str, $start, $width, $trimmaker, $encoding );
530
+function wpinv_utf8_strimwidth($str, $start, $width, $trimmaker = '', $encoding = 'UTF-8') {
531
+    if (function_exists('mb_strimwidth')) {
532
+        return mb_strimwidth($str, $start, $width, $trimmaker, $encoding);
533 533
     }
534 534
     
535
-    return wpinv_utf8_substr( $str, $start, $width, $encoding ) . $trimmaker;
535
+    return wpinv_utf8_substr($str, $start, $width, $encoding) . $trimmaker;
536 536
 }
537 537
 
538 538
 /**
@@ -544,28 +544,28 @@  discard block
 block discarded – undo
544 544
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
545 545
  * @return int Returns the number of characters in string.
546 546
  */
547
-function wpinv_utf8_strlen( $str, $encoding = 'UTF-8' ) {
548
-    if ( function_exists( 'mb_strlen' ) ) {
549
-        return mb_strlen( $str, $encoding );
547
+function wpinv_utf8_strlen($str, $encoding = 'UTF-8') {
548
+    if (function_exists('mb_strlen')) {
549
+        return mb_strlen($str, $encoding);
550 550
     }
551 551
         
552
-    return strlen( $str );
552
+    return strlen($str);
553 553
 }
554 554
 
555
-function wpinv_utf8_strtolower( $str, $encoding = 'UTF-8' ) {
556
-    if ( function_exists( 'mb_strtolower' ) ) {
557
-        return mb_strtolower( $str, $encoding );
555
+function wpinv_utf8_strtolower($str, $encoding = 'UTF-8') {
556
+    if (function_exists('mb_strtolower')) {
557
+        return mb_strtolower($str, $encoding);
558 558
     }
559 559
     
560
-    return strtolower( $str );
560
+    return strtolower($str);
561 561
 }
562 562
 
563
-function wpinv_utf8_strtoupper( $str, $encoding = 'UTF-8' ) {
564
-    if ( function_exists( 'mb_strtoupper' ) ) {
565
-        return mb_strtoupper( $str, $encoding );
563
+function wpinv_utf8_strtoupper($str, $encoding = 'UTF-8') {
564
+    if (function_exists('mb_strtoupper')) {
565
+        return mb_strtoupper($str, $encoding);
566 566
     }
567 567
     
568
-    return strtoupper( $str );
568
+    return strtoupper($str);
569 569
 }
570 570
 
571 571
 /**
@@ -579,12 +579,12 @@  discard block
 block discarded – undo
579 579
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
580 580
  * @return int Returns the position of the first occurrence of search in the string.
581 581
  */
582
-function wpinv_utf8_strpos( $str, $find, $offset = 0, $encoding = 'UTF-8' ) {
583
-    if ( function_exists( 'mb_strpos' ) ) {
584
-        return mb_strpos( $str, $find, $offset, $encoding );
582
+function wpinv_utf8_strpos($str, $find, $offset = 0, $encoding = 'UTF-8') {
583
+    if (function_exists('mb_strpos')) {
584
+        return mb_strpos($str, $find, $offset, $encoding);
585 585
     }
586 586
         
587
-    return strpos( $str, $find, $offset );
587
+    return strpos($str, $find, $offset);
588 588
 }
589 589
 
590 590
 /**
@@ -598,12 +598,12 @@  discard block
 block discarded – undo
598 598
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
599 599
  * @return int Returns the position of the last occurrence of search.
600 600
  */
601
-function wpinv_utf8_strrpos( $str, $find, $offset = 0, $encoding = 'UTF-8' ) {
602
-    if ( function_exists( 'mb_strrpos' ) ) {
603
-        return mb_strrpos( $str, $find, $offset, $encoding );
601
+function wpinv_utf8_strrpos($str, $find, $offset = 0, $encoding = 'UTF-8') {
602
+    if (function_exists('mb_strrpos')) {
603
+        return mb_strrpos($str, $find, $offset, $encoding);
604 604
     }
605 605
         
606
-    return strrpos( $str, $find, $offset );
606
+    return strrpos($str, $find, $offset);
607 607
 }
608 608
 
609 609
 /**
@@ -618,16 +618,16 @@  discard block
 block discarded – undo
618 618
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
619 619
  * @return string
620 620
  */
621
-function wpinv_utf8_substr( $str, $start, $length = null, $encoding = 'UTF-8' ) {
622
-    if ( function_exists( 'mb_substr' ) ) {
623
-        if ( $length === null ) {
624
-            return mb_substr( $str, $start, wpinv_utf8_strlen( $str, $encoding ), $encoding );
621
+function wpinv_utf8_substr($str, $start, $length = null, $encoding = 'UTF-8') {
622
+    if (function_exists('mb_substr')) {
623
+        if ($length === null) {
624
+            return mb_substr($str, $start, wpinv_utf8_strlen($str, $encoding), $encoding);
625 625
         } else {
626
-            return mb_substr( $str, $start, $length, $encoding );
626
+            return mb_substr($str, $start, $length, $encoding);
627 627
         }
628 628
     }
629 629
         
630
-    return substr( $str, $start, $length );
630
+    return substr($str, $start, $length);
631 631
 }
632 632
 
633 633
 /**
@@ -639,48 +639,48 @@  discard block
 block discarded – undo
639 639
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
640 640
  * @return string The width of string.
641 641
  */
642
-function wpinv_utf8_strwidth( $str, $encoding = 'UTF-8' ) {
643
-    if ( function_exists( 'mb_strwidth' ) ) {
644
-        return mb_strwidth( $str, $encoding );
642
+function wpinv_utf8_strwidth($str, $encoding = 'UTF-8') {
643
+    if (function_exists('mb_strwidth')) {
644
+        return mb_strwidth($str, $encoding);
645 645
     }
646 646
     
647
-    return wpinv_utf8_strlen( $str, $encoding );
647
+    return wpinv_utf8_strlen($str, $encoding);
648 648
 }
649 649
 
650
-function wpinv_utf8_ucfirst( $str, $lower_str_end = false, $encoding = 'UTF-8' ) {
651
-    if ( function_exists( 'mb_strlen' ) ) {
652
-        $first_letter = wpinv_utf8_strtoupper( wpinv_utf8_substr( $str, 0, 1, $encoding ), $encoding );
650
+function wpinv_utf8_ucfirst($str, $lower_str_end = false, $encoding = 'UTF-8') {
651
+    if (function_exists('mb_strlen')) {
652
+        $first_letter = wpinv_utf8_strtoupper(wpinv_utf8_substr($str, 0, 1, $encoding), $encoding);
653 653
         $str_end = "";
654 654
         
655
-        if ( $lower_str_end ) {
656
-            $str_end = wpinv_utf8_strtolower( wpinv_utf8_substr( $str, 1, wpinv_utf8_strlen( $str, $encoding ), $encoding ), $encoding );
655
+        if ($lower_str_end) {
656
+            $str_end = wpinv_utf8_strtolower(wpinv_utf8_substr($str, 1, wpinv_utf8_strlen($str, $encoding), $encoding), $encoding);
657 657
         } else {
658
-            $str_end = wpinv_utf8_substr( $str, 1, wpinv_utf8_strlen( $str, $encoding ), $encoding );
658
+            $str_end = wpinv_utf8_substr($str, 1, wpinv_utf8_strlen($str, $encoding), $encoding);
659 659
         }
660 660
 
661 661
         return $first_letter . $str_end;
662 662
     }
663 663
     
664
-    return ucfirst( $str );
664
+    return ucfirst($str);
665 665
 }
666 666
 
667
-function wpinv_utf8_ucwords( $str, $encoding = 'UTF-8' ) {
668
-    if ( function_exists( 'mb_convert_case' ) ) {
669
-        return mb_convert_case( $str, MB_CASE_TITLE, $encoding );
667
+function wpinv_utf8_ucwords($str, $encoding = 'UTF-8') {
668
+    if (function_exists('mb_convert_case')) {
669
+        return mb_convert_case($str, MB_CASE_TITLE, $encoding);
670 670
     }
671 671
     
672
-    return ucwords( $str );
672
+    return ucwords($str);
673 673
 }
674 674
 
675
-function wpinv_period_in_days( $period, $unit ) {
676
-    $period = absint( $period );
675
+function wpinv_period_in_days($period, $unit) {
676
+    $period = absint($period);
677 677
     
678
-    if ( $period > 0 ) {
679
-        if ( in_array( strtolower( $unit ), array( 'w', 'week', 'weeks' ) ) ) {
678
+    if ($period > 0) {
679
+        if (in_array(strtolower($unit), array('w', 'week', 'weeks'))) {
680 680
             $period = $period * 7;
681
-        } else if ( in_array( strtolower( $unit ), array( 'm', 'month', 'months' ) ) ) {
681
+        } else if (in_array(strtolower($unit), array('m', 'month', 'months'))) {
682 682
             $period = $period * 30;
683
-        } else if ( in_array( strtolower( $unit ), array( 'y', 'year', 'years' ) ) ) {
683
+        } else if (in_array(strtolower($unit), array('y', 'year', 'years'))) {
684 684
             $period = $period * 365;
685 685
         }
686 686
     }
Please login to merge, or discard this patch.
includes/class-wpinv-invoice.php 1 patch
Spacing   +774 added lines, -774 removed lines patch added patch discarded remove patch
@@ -7,12 +7,12 @@  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
 final class WPInv_Invoice {
15
-    public $ID  = 0;
15
+    public $ID = 0;
16 16
     public $title;
17 17
     
18 18
     public $pending;
@@ -64,17 +64,17 @@  discard block
 block discarded – undo
64 64
     public $full_name = '';
65 65
     public $parent_invoice = 0;
66 66
     
67
-    public function __construct( $invoice_id = false ) {
68
-        if( empty( $invoice_id ) ) {
67
+    public function __construct($invoice_id = false) {
68
+        if (empty($invoice_id)) {
69 69
             return false;
70 70
         }
71 71
 
72
-        $this->setup_invoice( $invoice_id );
72
+        $this->setup_invoice($invoice_id);
73 73
     }
74 74
 
75
-    public function get( $key ) {
76
-        if ( method_exists( $this, 'get_' . $key ) ) {
77
-            $value = call_user_func( array( $this, 'get_' . $key ) );
75
+    public function get($key) {
76
+        if (method_exists($this, 'get_' . $key)) {
77
+            $value = call_user_func(array($this, 'get_' . $key));
78 78
         } else {
79 79
             $value = $this->$key;
80 80
         }
@@ -82,51 +82,51 @@  discard block
 block discarded – undo
82 82
         return $value;
83 83
     }
84 84
 
85
-    public function set( $key, $value ) {
86
-        $ignore = array( 'items', 'cart_details', 'fees', '_ID' );
85
+    public function set($key, $value) {
86
+        $ignore = array('items', 'cart_details', 'fees', '_ID');
87 87
 
88
-        if ( $key === 'status' ) {
88
+        if ($key === 'status') {
89 89
             $this->old_status = $this->status;
90 90
         }
91 91
 
92
-        if ( ! in_array( $key, $ignore ) ) {
93
-            $this->pending[ $key ] = $value;
92
+        if (!in_array($key, $ignore)) {
93
+            $this->pending[$key] = $value;
94 94
         }
95 95
 
96
-        if( '_ID' !== $key ) {
96
+        if ('_ID' !== $key) {
97 97
             $this->$key = $value;
98 98
         }
99 99
     }
100 100
 
101
-    public function _isset( $name ) {
102
-        if ( property_exists( $this, $name) ) {
103
-            return false === empty( $this->$name );
101
+    public function _isset($name) {
102
+        if (property_exists($this, $name)) {
103
+            return false === empty($this->$name);
104 104
         } else {
105 105
             return null;
106 106
         }
107 107
     }
108 108
 
109
-    private function setup_invoice( $invoice_id ) {
109
+    private function setup_invoice($invoice_id) {
110 110
         $this->pending = array();
111 111
 
112
-        if ( empty( $invoice_id ) ) {
112
+        if (empty($invoice_id)) {
113 113
             return false;
114 114
         }
115 115
 
116
-        $invoice = get_post( $invoice_id );
116
+        $invoice = get_post($invoice_id);
117 117
 
118
-        if( !$invoice || is_wp_error( $invoice ) ) {
118
+        if (!$invoice || is_wp_error($invoice)) {
119 119
             return false;
120 120
         }
121 121
 
122
-        if( 'wpi_invoice' !== $invoice->post_type ) {
122
+        if ('wpi_invoice' !== $invoice->post_type) {
123 123
             return false;
124 124
         }
125 125
 
126
-        do_action( 'wpinv_pre_setup_invoice', $this, $invoice_id );
126
+        do_action('wpinv_pre_setup_invoice', $this, $invoice_id);
127 127
         
128 128
         // Primary Identifier
129
-        $this->ID              = absint( $invoice_id );
129
+        $this->ID              = absint($invoice_id);
130 130
         
131 131
         // We have a payment, get the generic payment_meta item to reduce calls to it
132 132
         $this->payment_meta    = $this->get_meta();
@@ -137,7 +137,7 @@  discard block
 block discarded – undo
137 137
         $this->post_status     = $this->status;
138 138
         $this->mode            = $this->setup_mode();
139 139
         $this->parent_invoice  = $invoice->post_parent;
140
-        $this->post_name       = $this->setup_post_name( $invoice );
140
+        $this->post_name       = $this->setup_post_name($invoice);
141 141
         $this->status_nicename = $this->setup_status_nicename();
142 142
 
143 143
         // Items
@@ -159,8 +159,8 @@  discard block
 block discarded – undo
159 159
         
160 160
         // User based
161 161
         $this->ip              = $this->setup_ip();
162
-        $this->user_id         = !empty( $invoice->post_author ) ? $invoice->post_author : get_current_user_id();///$this->setup_user_id();
163
-        $this->email           = get_the_author_meta( 'email', $this->user_id );
162
+        $this->user_id         = !empty($invoice->post_author) ? $invoice->post_author : get_current_user_id(); ///$this->setup_user_id();
163
+        $this->email           = get_the_author_meta('email', $this->user_id);
164 164
         
165 165
         $this->user_info       = $this->setup_user_info();
166 166
                 
@@ -169,7 +169,7 @@  discard block
 block discarded – undo
169 169
         $this->company         = $this->user_info['company'];
170 170
         $this->vat_number      = $this->user_info['vat_number'];
171 171
         $this->vat_rate        = $this->user_info['vat_rate'];
172
-        $this->adddress_confirmed  = $this->user_info['adddress_confirmed'];
172
+        $this->adddress_confirmed = $this->user_info['adddress_confirmed'];
173 173
         $this->address         = $this->user_info['address'];
174 174
         $this->city            = $this->user_info['city'];
175 175
         $this->country         = $this->user_info['country'];
@@ -184,48 +184,48 @@  discard block
 block discarded – undo
184 184
         // Other Identifiers
185 185
         $this->key             = $this->setup_invoice_key();
186 186
         $this->number          = $this->setup_invoice_number();
187
-        $this->title           = !empty( $invoice->post_title ) ? $invoice->post_title : $this->number;
187
+        $this->title           = !empty($invoice->post_title) ? $invoice->post_title : $this->number;
188 188
         
189
-        $this->full_name       = trim( $this->first_name . ' '. $this->last_name );
189
+        $this->full_name       = trim($this->first_name . ' ' . $this->last_name);
190 190
         
191 191
         // Allow extensions to add items to this object via hook
192
-        do_action( 'wpinv_setup_invoice', $this, $invoice_id );
192
+        do_action('wpinv_setup_invoice', $this, $invoice_id);
193 193
 
194 194
         return true;
195 195
     }
196 196
     
197 197
     private function setup_status_nicename() {
198
-        $all_invoice_statuses  = wpinv_get_invoice_statuses();
198
+        $all_invoice_statuses = wpinv_get_invoice_statuses();
199 199
         
200
-        $status = array_key_exists( $this->status, $all_invoice_statuses ) ? $all_invoice_statuses[$this->status] : ucfirst( $this->status );
200
+        $status = array_key_exists($this->status, $all_invoice_statuses) ? $all_invoice_statuses[$this->status] : ucfirst($this->status);
201 201
 
202 202
         return $status;
203 203
     }
204 204
     
205
-    private function setup_post_name( $post = NULL ) {
205
+    private function setup_post_name($post = NULL) {
206 206
         $post_name = '';
207 207
         
208
-        if ( !empty( $post ) ) {
209
-            if( !empty( $post->post_name ) ) {
208
+        if (!empty($post)) {
209
+            if (!empty($post->post_name)) {
210 210
                 $post_name = $post->post_name;
211
-            } else if ( !empty( $post->ID ) && !empty( $post->post_title ) ) {
212
-                $post_name = sanitize_title( $post->post_title );
211
+            } else if (!empty($post->ID) && !empty($post->post_title)) {
212
+                $post_name = sanitize_title($post->post_title);
213 213
                 
214 214
                 global $wpdb;
215
-                $wpdb->update( $wpdb->posts, array( 'post_name' => $post_name ), array( 'ID' => $post->ID ) );
215
+                $wpdb->update($wpdb->posts, array('post_name' => $post_name), array('ID' => $post->ID));
216 216
             }
217 217
         }
218 218
 
219
-        $this->post_name   = $post_name;
219
+        $this->post_name = $post_name;
220 220
     }
221 221
     
222 222
     private function setup_due_date() {
223
-        $due_date = $this->get_meta( '_wpinv_due_date' );
223
+        $due_date = $this->get_meta('_wpinv_due_date');
224 224
         
225
-        if ( empty( $due_date ) ) {
226
-            $overdue_time = strtotime( $this->date ) + ( DAY_IN_SECONDS * absint( wpinv_get_option( 'overdue_days' ) ) );
227
-            $due_date = date_i18n( 'Y-m-d', $overdue_time );
228
-        } else if ( $due_date == 'none' ) {
225
+        if (empty($due_date)) {
226
+            $overdue_time = strtotime($this->date) + (DAY_IN_SECONDS * absint(wpinv_get_option('overdue_days')));
227
+            $due_date = date_i18n('Y-m-d', $overdue_time);
228
+        } else if ($due_date == 'none') {
229 229
             $due_date = '';
230 230
         }
231 231
         
@@ -233,63 +233,63 @@  discard block
 block discarded – undo
233 233
     }
234 234
     
235 235
     private function setup_completed_date() {
236
-        $invoice = get_post( $this->ID );
236
+        $invoice = get_post($this->ID);
237 237
 
238
-        if ( 'pending' == $invoice->post_status || 'preapproved' == $invoice->post_status ) {
238
+        if ('pending' == $invoice->post_status || 'preapproved' == $invoice->post_status) {
239 239
             return false; // This invoice was never paid
240 240
         }
241 241
 
242
-        $date = ( $date = $this->get_meta( '_wpinv_completed_date', true ) ) ? $date : $invoice->modified_date;
242
+        $date = ($date = $this->get_meta('_wpinv_completed_date', true)) ? $date : $invoice->modified_date;
243 243
 
244 244
         return $date;
245 245
     }
246 246
     
247 247
     private function setup_cart_details() {
248
-        $cart_details = isset( $this->payment_meta['cart_details'] ) ? maybe_unserialize( $this->payment_meta['cart_details'] ) : array();
248
+        $cart_details = isset($this->payment_meta['cart_details']) ? maybe_unserialize($this->payment_meta['cart_details']) : array();
249 249
         return $cart_details;
250 250
     }
251 251
     
252 252
     public function array_convert() {
253
-        return get_object_vars( $this );
253
+        return get_object_vars($this);
254 254
     }
255 255
     
256 256
     private function setup_items() {
257
-        $items = isset( $this->payment_meta['items'] ) ? maybe_unserialize( $this->payment_meta['items'] ) : array();
257
+        $items = isset($this->payment_meta['items']) ? maybe_unserialize($this->payment_meta['items']) : array();
258 258
         return $items;
259 259
     }
260 260
     
261 261
     private function setup_fees() {
262
-        $payment_fees = isset( $this->payment_meta['fees'] ) ? $this->payment_meta['fees'] : array();
262
+        $payment_fees = isset($this->payment_meta['fees']) ? $this->payment_meta['fees'] : array();
263 263
         return $payment_fees;
264 264
     }
265 265
         
266 266
     private function setup_currency() {
267
-        $currency = isset( $this->payment_meta['currency'] ) ? $this->payment_meta['currency'] : apply_filters( 'wpinv_currency_default', wpinv_get_currency(), $this );
267
+        $currency = isset($this->payment_meta['currency']) ? $this->payment_meta['currency'] : apply_filters('wpinv_currency_default', wpinv_get_currency(), $this);
268 268
         return $currency;
269 269
     }
270 270
     
271 271
     private function setup_discount() {
272 272
         //$discount = $this->get_meta( '_wpinv_discount', true );
273
-        $discount = $this->subtotal - ( $this->total - $this->tax - $this->fees_total );
274
-        if ( $discount < 0 ) {
273
+        $discount = $this->subtotal - ($this->total - $this->tax - $this->fees_total);
274
+        if ($discount < 0) {
275 275
             $discount = 0;
276 276
         }
277
-        $discount = wpinv_format_amount( $discount, NULL, true );
277
+        $discount = wpinv_format_amount($discount, NULL, true);
278 278
         
279 279
         return $discount;
280 280
     }
281 281
     
282 282
     private function setup_discount_code() {
283
-        $discount_code = !empty( $this->discounts ) ? $this->discounts : $this->get_meta( '_wpinv_discount_code', true );
283
+        $discount_code = !empty($this->discounts) ? $this->discounts : $this->get_meta('_wpinv_discount_code', true);
284 284
         return $discount_code;
285 285
     }
286 286
     
287 287
     private function setup_tax() {
288
-        $tax = $this->get_meta( '_wpinv_tax', true );
288
+        $tax = $this->get_meta('_wpinv_tax', true);
289 289
 
290 290
         // We don't have tax as it's own meta and no meta was passed
291
-        if ( '' === $tax ) {            
292
-            $tax = isset( $this->payment_meta['tax'] ) ? $this->payment_meta['tax'] : 0;
291
+        if ('' === $tax) {            
292
+            $tax = isset($this->payment_meta['tax']) ? $this->payment_meta['tax'] : 0;
293 293
         }
294 294
 
295 295
         return $tax;
@@ -303,9 +303,9 @@  discard block
 block discarded – undo
303 303
         $subtotal     = 0;
304 304
         $cart_details = $this->cart_details;
305 305
 
306
-        if ( is_array( $cart_details ) ) {
307
-            foreach ( $cart_details as $item ) {
308
-                if ( isset( $item['subtotal'] ) ) {
306
+        if (is_array($cart_details)) {
307
+            foreach ($cart_details as $item) {
308
+                if (isset($item['subtotal'])) {
309 309
                     $subtotal += $item['subtotal'];
310 310
                 }
311 311
             }
@@ -319,18 +319,18 @@  discard block
 block discarded – undo
319 319
     }
320 320
     
321 321
     private function setup_discounts() {
322
-        $discounts = ! empty( $this->payment_meta['user_info']['discount'] ) ? $this->payment_meta['user_info']['discount'] : array();
322
+        $discounts = !empty($this->payment_meta['user_info']['discount']) ? $this->payment_meta['user_info']['discount'] : array();
323 323
         return $discounts;
324 324
     }
325 325
     
326 326
     private function setup_total() {
327
-        $amount = $this->get_meta( '_wpinv_total', true );
327
+        $amount = $this->get_meta('_wpinv_total', true);
328 328
 
329
-        if ( empty( $amount ) && '0.00' != $amount ) {
330
-            $meta   = $this->get_meta( '_wpinv_payment_meta', true );
331
-            $meta   = maybe_unserialize( $meta );
329
+        if (empty($amount) && '0.00' != $amount) {
330
+            $meta   = $this->get_meta('_wpinv_payment_meta', true);
331
+            $meta   = maybe_unserialize($meta);
332 332
 
333
-            if ( isset( $meta['amount'] ) ) {
333
+            if (isset($meta['amount'])) {
334 334
                 $amount = $meta['amount'];
335 335
             }
336 336
         }
@@ -339,13 +339,13 @@  discard block
 block discarded – undo
339 339
     }
340 340
     
341 341
     private function setup_mode() {
342
-        return $this->get_meta( '_wpinv_mode' );
342
+        return $this->get_meta('_wpinv_mode');
343 343
     }
344 344
 
345 345
     private function setup_gateway() {
346
-        $gateway = $this->get_meta( '_wpinv_gateway' );
346
+        $gateway = $this->get_meta('_wpinv_gateway');
347 347
         
348
-        if ( empty( $gateway ) && 'publish' === $this->status || 'complete' === $this->status ) {
348
+        if (empty($gateway) && 'publish' === $this->status || 'complete' === $this->status) {
349 349
             $gateway = 'manual';
350 350
         }
351 351
         
@@ -353,23 +353,23 @@  discard block
 block discarded – undo
353 353
     }
354 354
     
355 355
     private function setup_gateway_title() {
356
-        $gateway_title = wpinv_get_gateway_checkout_label( $this->gateway );
356
+        $gateway_title = wpinv_get_gateway_checkout_label($this->gateway);
357 357
         return $gateway_title;
358 358
     }
359 359
 
360 360
     private function setup_transaction_id() {
361
-        $transaction_id = $this->get_meta( '_wpinv_transaction_id' );
361
+        $transaction_id = $this->get_meta('_wpinv_transaction_id');
362 362
 
363
-        if ( empty( $transaction_id ) || (int) $transaction_id === (int) $this->ID ) {
363
+        if (empty($transaction_id) || (int)$transaction_id === (int)$this->ID) {
364 364
             $gateway        = $this->gateway;
365
-            $transaction_id = apply_filters( 'wpinv_get_invoice_transaction_id-' . $gateway, $this->ID );
365
+            $transaction_id = apply_filters('wpinv_get_invoice_transaction_id-' . $gateway, $this->ID);
366 366
         }
367 367
 
368 368
         return $transaction_id;
369 369
     }
370 370
 
371 371
     private function setup_ip() {
372
-        $ip = $this->get_meta( '_wpinv_user_ip' );
372
+        $ip = $this->get_meta('_wpinv_user_ip');
373 373
         return $ip;
374 374
     }
375 375
 
@@ -379,62 +379,62 @@  discard block
 block discarded – undo
379 379
     ///}
380 380
         
381 381
     private function setup_first_name() {
382
-        $first_name = $this->get_meta( '_wpinv_first_name' );
382
+        $first_name = $this->get_meta('_wpinv_first_name');
383 383
         return $first_name;
384 384
     }
385 385
     
386 386
     private function setup_last_name() {
387
-        $last_name = $this->get_meta( '_wpinv_last_name' );
387
+        $last_name = $this->get_meta('_wpinv_last_name');
388 388
         return $last_name;
389 389
     }
390 390
     
391 391
     private function setup_company() {
392
-        $company = $this->get_meta( '_wpinv_company' );
392
+        $company = $this->get_meta('_wpinv_company');
393 393
         return $company;
394 394
     }
395 395
     
396 396
     private function setup_vat_number() {
397
-        $vat_number = $this->get_meta( '_wpinv_vat_number' );
397
+        $vat_number = $this->get_meta('_wpinv_vat_number');
398 398
         return $vat_number;
399 399
     }
400 400
     
401 401
     private function setup_vat_rate() {
402
-        $vat_rate = $this->get_meta( '_wpinv_vat_rate' );
402
+        $vat_rate = $this->get_meta('_wpinv_vat_rate');
403 403
         return $vat_rate;
404 404
     }
405 405
     
406 406
     private function setup_adddress_confirmed() {
407
-        $adddress_confirmed = $this->get_meta( '_wpinv_adddress_confirmed' );
407
+        $adddress_confirmed = $this->get_meta('_wpinv_adddress_confirmed');
408 408
         return $adddress_confirmed;
409 409
     }
410 410
     
411 411
     private function setup_phone() {
412
-        $phone = $this->get_meta( '_wpinv_phone' );
412
+        $phone = $this->get_meta('_wpinv_phone');
413 413
         return $phone;
414 414
     }
415 415
     
416 416
     private function setup_address() {
417
-        $address = $this->get_meta( '_wpinv_address', true );
417
+        $address = $this->get_meta('_wpinv_address', true);
418 418
         return $address;
419 419
     }
420 420
     
421 421
     private function setup_city() {
422
-        $city = $this->get_meta( '_wpinv_city', true );
422
+        $city = $this->get_meta('_wpinv_city', true);
423 423
         return $city;
424 424
     }
425 425
     
426 426
     private function setup_country() {
427
-        $country = $this->get_meta( '_wpinv_country', true );
427
+        $country = $this->get_meta('_wpinv_country', true);
428 428
         return $country;
429 429
     }
430 430
     
431 431
     private function setup_state() {
432
-        $state = $this->get_meta( '_wpinv_state', true );
432
+        $state = $this->get_meta('_wpinv_state', true);
433 433
         return $state;
434 434
     }
435 435
     
436 436
     private function setup_zip() {
437
-        $zip = $this->get_meta( '_wpinv_zip', true );
437
+        $zip = $this->get_meta('_wpinv_zip', true);
438 438
         return $zip;
439 439
     }
440 440
 
@@ -443,7 +443,7 @@  discard block
 block discarded – undo
443 443
             'user_id'        => $this->user_id,
444 444
             'first_name'     => $this->first_name,
445 445
             'last_name'      => $this->last_name,
446
-            'email'          => get_the_author_meta( 'email', $this->user_id ),
446
+            'email'          => get_the_author_meta('email', $this->user_id),
447 447
             'phone'          => $this->phone,
448 448
             'address'        => $this->address,
449 449
             'city'           => $this->city,
@@ -458,12 +458,12 @@  discard block
 block discarded – undo
458 458
         );
459 459
         
460 460
         $user_info = array();
461
-        if ( isset( $this->payment_meta['user_info'] ) ) {
462
-            $user_info = maybe_unserialize( $this->payment_meta['user_info'] );
461
+        if (isset($this->payment_meta['user_info'])) {
462
+            $user_info = maybe_unserialize($this->payment_meta['user_info']);
463 463
             
464
-            if ( !empty( $user_info ) && isset( $user_info['user_id'] ) && $post = get_post( $this->ID ) ) {
464
+            if (!empty($user_info) && isset($user_info['user_id']) && $post = get_post($this->ID)) {
465 465
                 $this->user_id = $post->post_author;
466
-                $this->email = get_the_author_meta( 'email', $this->user_id );
466
+                $this->email = get_the_author_meta('email', $this->user_id);
467 467
                 
468 468
                 $user_info['user_id'] = $this->user_id;
469 469
                 $user_info['email'] = $this->email;
@@ -472,13 +472,13 @@  discard block
 block discarded – undo
472 472
             }
473 473
         }
474 474
         
475
-        $user_info    = wp_parse_args( $user_info, $defaults );
475
+        $user_info = wp_parse_args($user_info, $defaults);
476 476
         
477 477
         // Get the user, but only if it's been created
478
-        $user = get_userdata( $this->user_id );
478
+        $user = get_userdata($this->user_id);
479 479
         
480
-        if ( !empty( $user ) && $user->ID > 0 ) {
481
-            if ( empty( $user_info ) ) {
480
+        if (!empty($user) && $user->ID > 0) {
481
+            if (empty($user_info)) {
482 482
                 $user_info = array(
483 483
                     'user_id'    => $user->ID,
484 484
                     'first_name' => $user->first_name,
@@ -487,23 +487,23 @@  discard block
 block discarded – undo
487 487
                     'discount'   => '',
488 488
                 );
489 489
             } else {
490
-                foreach ( $user_info as $key => $value ) {
491
-                    if ( ! empty( $value ) ) {
490
+                foreach ($user_info as $key => $value) {
491
+                    if (!empty($value)) {
492 492
                         continue;
493 493
                     }
494 494
 
495
-                    switch( $key ) {
495
+                    switch ($key) {
496 496
                         case 'user_id':
497
-                            $user_info[ $key ] = $user->ID;
497
+                            $user_info[$key] = $user->ID;
498 498
                             break;
499 499
                         case 'first_name':
500
-                            $user_info[ $key ] = $user->first_name;
500
+                            $user_info[$key] = $user->first_name;
501 501
                             break;
502 502
                         case 'last_name':
503
-                            $user_info[ $key ] = $user->last_name;
503
+                            $user_info[$key] = $user->last_name;
504 504
                             break;
505 505
                         case 'email':
506
-                            $user_info[ $key ] = $user->user_email;
506
+                            $user_info[$key] = $user->user_email;
507 507
                             break;
508 508
                     }
509 509
                 }
@@ -514,16 +514,16 @@  discard block
 block discarded – undo
514 514
     }
515 515
 
516 516
     private function setup_invoice_key() {
517
-        $key = $this->get_meta( '_wpinv_key', true );
517
+        $key = $this->get_meta('_wpinv_key', true);
518 518
         
519 519
         return $key;
520 520
     }
521 521
 
522 522
     private function setup_invoice_number() {
523
-        $number = $this->get_meta( '_wpinv_number', true );
523
+        $number = $this->get_meta('_wpinv_number', true);
524 524
 
525
-        if ( !$number ) {
526
-            $number = wpinv_format_invoice_number( $this->ID );
525
+        if (!$number) {
526
+            $number = wpinv_format_invoice_number($this->ID);
527 527
         }
528 528
 
529 529
         return $number;
@@ -534,18 +534,18 @@  discard block
 block discarded – undo
534 534
 
535 535
         if ($number = $this->get_number()) {
536 536
             $invoice_title = $number;
537
-        } else if ( ! empty( $this->ID ) ) {
538
-            $invoice_title = wpinv_format_invoice_number( $this->ID );
537
+        } else if (!empty($this->ID)) {
538
+            $invoice_title = wpinv_format_invoice_number($this->ID);
539 539
         } else {
540
-            $invoice_title = wpinv_format_invoice_number( 0 );
540
+            $invoice_title = wpinv_format_invoice_number(0);
541 541
         }
542 542
 
543
-        if ( empty( $this->key ) ) {
543
+        if (empty($this->key)) {
544 544
             $this->key = self::generate_key();
545 545
             $this->pending['key'] = $this->key;
546 546
         }
547 547
 
548
-        if ( empty( $this->ip ) ) {
548
+        if (empty($this->ip)) {
549 549
             $this->ip = wpinv_get_ip();
550 550
             $this->pending['ip'] = $this->ip;
551 551
         }
@@ -577,75 +577,75 @@  discard block
 block discarded – undo
577 577
             'fees'         => $this->fees,
578 578
         );
579 579
         
580
-        $post_name      = sanitize_title( $invoice_title );
580
+        $post_name = sanitize_title($invoice_title);
581 581
 
582 582
         $post_data = array(
583 583
                         'post_title'    => $invoice_title,
584 584
                         'post_status'   => $this->status,
585 585
                         'post_author'   => $this->user_id,
586 586
                         'post_type'     => 'wpi_invoice',
587
-                        'post_date'     => ! empty( $this->date ) && $this->date != '0000-00-00 00:00:00' ? $this->date : current_time( 'mysql' ),
588
-                        'post_date_gmt' => ! empty( $this->date ) && $this->date != '0000-00-00 00:00:00' ? get_gmt_from_date( $this->date ) : current_time( 'mysql', 1 ),
587
+                        'post_date'     => !empty($this->date) && $this->date != '0000-00-00 00:00:00' ? $this->date : current_time('mysql'),
588
+                        'post_date_gmt' => !empty($this->date) && $this->date != '0000-00-00 00:00:00' ? get_gmt_from_date($this->date) : current_time('mysql', 1),
589 589
                         'post_parent'   => $this->parent_invoice,
590 590
                     );
591
-        $args = apply_filters( 'wpinv_insert_invoice_args', $post_data, $this );
591
+        $args = apply_filters('wpinv_insert_invoice_args', $post_data, $this);
592 592
 
593 593
         // Create a blank invoice
594
-        if ( !empty( $this->ID ) ) {
594
+        if (!empty($this->ID)) {
595 595
             $args['ID']         = $this->ID;
596 596
             $args['post_name']  = $post_name;
597 597
             
598
-            $invoice_id = wp_update_post( $args );
598
+            $invoice_id = wp_update_post($args);
599 599
         } else {
600
-            $invoice_id = wp_insert_post( $args );
600
+            $invoice_id = wp_insert_post($args);
601 601
             
602
-            $post_title = wpinv_format_invoice_number( $invoice_id );
602
+            $post_title = wpinv_format_invoice_number($invoice_id);
603 603
             global $wpdb;
604
-            $wpdb->update( $wpdb->posts, array( 'post_title' => $post_title, 'post_name' => sanitize_title( $post_title ) ), array( 'ID' => $invoice_id ) );
605
-            clean_post_cache( $invoice_id );
604
+            $wpdb->update($wpdb->posts, array('post_title' => $post_title, 'post_name' => sanitize_title($post_title)), array('ID' => $invoice_id));
605
+            clean_post_cache($invoice_id);
606 606
         }
607 607
 
608
-        if ( !empty( $invoice_id ) ) {             
608
+        if (!empty($invoice_id)) {             
609 609
             $this->ID  = $invoice_id;
610 610
             $this->_ID = $invoice_id;
611 611
             
612 612
             ///$this->pending['user_id'] = $this->user_id;
613
-            if ( isset( $this->pending['number'] ) ) {
613
+            if (isset($this->pending['number'])) {
614 614
                 $this->pending['number'] = $post_name;
615 615
             }
616 616
             
617
-            $this->payment_meta = apply_filters( 'wpinv_payment_meta', $this->payment_meta, $payment_data );
618
-            if ( ! empty( $this->payment_meta['fees'] ) ) {
619
-                $this->fees = array_merge( $this->fees, $this->payment_meta['fees'] );
620
-                foreach( $this->fees as $fee ) {
621
-                    $this->increase_fees( $fee['amount'] );
617
+            $this->payment_meta = apply_filters('wpinv_payment_meta', $this->payment_meta, $payment_data);
618
+            if (!empty($this->payment_meta['fees'])) {
619
+                $this->fees = array_merge($this->fees, $this->payment_meta['fees']);
620
+                foreach ($this->fees as $fee) {
621
+                    $this->increase_fees($fee['amount']);
622 622
                 }
623 623
             }
624 624
 
625
-            $this->update_meta( '_wpinv_payment_meta', $this->payment_meta );            
625
+            $this->update_meta('_wpinv_payment_meta', $this->payment_meta);            
626 626
             $this->new = true;
627 627
         }
628 628
 
629 629
         return $this->ID;
630 630
     }
631 631
 
632
-    public function save( $setup = false ) {
632
+    public function save($setup = false) {
633 633
         global $wpi_session;
634 634
         
635 635
         $saved = false;
636
-        if ( empty( $this->items ) ) {
636
+        if (empty($this->items)) {
637 637
             return $saved; // Don't save empty invoice.
638 638
         }
639 639
         
640
-        if ( empty( $this->key ) ) {
640
+        if (empty($this->key)) {
641 641
             $this->key = self::generate_key();
642 642
             $this->pending['key'] = $this->key;
643 643
         }
644 644
         
645
-        if ( empty( $this->ID ) ) {
645
+        if (empty($this->ID)) {
646 646
             $invoice_id = $this->insert_invoice();
647 647
 
648
-            if ( false === $invoice_id ) {
648
+            if (false === $invoice_id) {
649 649
                 $saved = false;
650 650
             } else {
651 651
                 $this->ID = $invoice_id;
@@ -653,27 +653,27 @@  discard block
 block discarded – undo
653 653
         }        
654 654
 
655 655
         // If we have something pending, let's save it
656
-        if ( !empty( $this->pending ) ) {
656
+        if (!empty($this->pending)) {
657 657
             $total_increase = 0;
658 658
             $total_decrease = 0;
659 659
 
660
-            foreach ( $this->pending as $key => $value ) {
661
-                switch( $key ) {
660
+            foreach ($this->pending as $key => $value) {
661
+                switch ($key) {
662 662
                     case 'items':
663 663
                         // Update totals for pending items
664
-                        foreach ( $this->pending[ $key ] as $item ) {
665
-                            switch( $item['action'] ) {
664
+                        foreach ($this->pending[$key] as $item) {
665
+                            switch ($item['action']) {
666 666
                                 case 'add':
667 667
                                     $price = $item['price'];
668 668
                                     $taxes = $item['tax'];
669 669
 
670
-                                    if ( 'publish' === $this->status || 'complete' === $this->status || 'revoked' === $this->status ) {
670
+                                    if ('publish' === $this->status || 'complete' === $this->status || 'revoked' === $this->status) {
671 671
                                         $total_increase += $price;
672 672
                                     }
673 673
                                     break;
674 674
 
675 675
                                 case 'remove':
676
-                                    if ( 'publish' === $this->status || 'complete' === $this->status || 'revoked' === $this->status ) {
676
+                                    if ('publish' === $this->status || 'complete' === $this->status || 'revoked' === $this->status) {
677 677
                                         $total_decrease += $item['price'];
678 678
                                     }
679 679
                                     break;
@@ -681,16 +681,16 @@  discard block
 block discarded – undo
681 681
                         }
682 682
                         break;
683 683
                     case 'fees':
684
-                        if ( 'publish' !== $this->status && 'complete' !== $this->status && 'revoked' !== $this->status ) {
684
+                        if ('publish' !== $this->status && 'complete' !== $this->status && 'revoked' !== $this->status) {
685 685
                             break;
686 686
                         }
687 687
 
688
-                        if ( empty( $this->pending[ $key ] ) ) {
688
+                        if (empty($this->pending[$key])) {
689 689
                             break;
690 690
                         }
691 691
 
692
-                        foreach ( $this->pending[ $key ] as $fee ) {
693
-                            switch( $fee['action'] ) {
692
+                        foreach ($this->pending[$key] as $fee) {
693
+                            switch ($fee['action']) {
694 694
                                 case 'add':
695 695
                                     $total_increase += $fee['amount'];
696 696
                                     break;
@@ -702,86 +702,86 @@  discard block
 block discarded – undo
702 702
                         }
703 703
                         break;
704 704
                     case 'status':
705
-                        $this->update_status( $this->status );
705
+                        $this->update_status($this->status);
706 706
                         break;
707 707
                     case 'gateway':
708
-                        $this->update_meta( '_wpinv_gateway', $this->gateway );
708
+                        $this->update_meta('_wpinv_gateway', $this->gateway);
709 709
                         break;
710 710
                     case 'mode':
711
-                        $this->update_meta( '_wpinv_mode', $this->mode );
711
+                        $this->update_meta('_wpinv_mode', $this->mode);
712 712
                         break;
713 713
                     case 'transaction_id':
714
-                        $this->update_meta( '_wpinv_transaction_id', $this->transaction_id );
714
+                        $this->update_meta('_wpinv_transaction_id', $this->transaction_id);
715 715
                         break;
716 716
                     case 'ip':
717
-                        $this->update_meta( '_wpinv_user_ip', $this->ip );
717
+                        $this->update_meta('_wpinv_user_ip', $this->ip);
718 718
                         break;
719 719
                     ///case 'user_id':
720 720
                         ///$this->update_meta( '_wpinv_user_id', $this->user_id );
721 721
                         ///$this->user_info['user_id'] = $this->user_id;
722 722
                         ///break;
723 723
                     case 'first_name':
724
-                        $this->update_meta( '_wpinv_first_name', $this->first_name );
724
+                        $this->update_meta('_wpinv_first_name', $this->first_name);
725 725
                         $this->user_info['first_name'] = $this->first_name;
726 726
                         break;
727 727
                     case 'last_name':
728
-                        $this->update_meta( '_wpinv_last_name', $this->last_name );
728
+                        $this->update_meta('_wpinv_last_name', $this->last_name);
729 729
                         $this->user_info['last_name'] = $this->last_name;
730 730
                         break;
731 731
                     case 'phone':
732
-                        $this->update_meta( '_wpinv_phone', $this->phone );
732
+                        $this->update_meta('_wpinv_phone', $this->phone);
733 733
                         $this->user_info['phone'] = $this->phone;
734 734
                         break;
735 735
                     case 'address':
736
-                        $this->update_meta( '_wpinv_address', $this->address );
736
+                        $this->update_meta('_wpinv_address', $this->address);
737 737
                         $this->user_info['address'] = $this->address;
738 738
                         break;
739 739
                     case 'city':
740
-                        $this->update_meta( '_wpinv_city', $this->city );
740
+                        $this->update_meta('_wpinv_city', $this->city);
741 741
                         $this->user_info['city'] = $this->city;
742 742
                         break;
743 743
                     case 'country':
744
-                        $this->update_meta( '_wpinv_country', $this->country );
744
+                        $this->update_meta('_wpinv_country', $this->country);
745 745
                         $this->user_info['country'] = $this->country;
746 746
                         break;
747 747
                     case 'state':
748
-                        $this->update_meta( '_wpinv_state', $this->state );
748
+                        $this->update_meta('_wpinv_state', $this->state);
749 749
                         $this->user_info['state'] = $this->state;
750 750
                         break;
751 751
                     case 'zip':
752
-                        $this->update_meta( '_wpinv_zip', $this->zip );
752
+                        $this->update_meta('_wpinv_zip', $this->zip);
753 753
                         $this->user_info['zip'] = $this->zip;
754 754
                         break;
755 755
                     case 'company':
756
-                        $this->update_meta( '_wpinv_company', $this->company );
756
+                        $this->update_meta('_wpinv_company', $this->company);
757 757
                         $this->user_info['company'] = $this->company;
758 758
                         break;
759 759
                     case 'vat_number':
760
-                        $this->update_meta( '_wpinv_vat_number', $this->vat_number );
760
+                        $this->update_meta('_wpinv_vat_number', $this->vat_number);
761 761
                         $this->user_info['vat_number'] = $this->vat_number;
762 762
                         
763
-                        $vat_info = $wpi_session->get( 'user_vat_data' );
764
-                        if ( $this->vat_number && !empty( $vat_info ) && isset( $vat_info['number'] ) && isset( $vat_info['valid'] ) && $vat_info['number'] == $this->vat_number ) {
765
-                            $adddress_confirmed = isset( $vat_info['adddress_confirmed'] ) ? $vat_info['adddress_confirmed'] : false;
766
-                            $this->update_meta( '_wpinv_adddress_confirmed', (bool)$adddress_confirmed );
763
+                        $vat_info = $wpi_session->get('user_vat_data');
764
+                        if ($this->vat_number && !empty($vat_info) && isset($vat_info['number']) && isset($vat_info['valid']) && $vat_info['number'] == $this->vat_number) {
765
+                            $adddress_confirmed = isset($vat_info['adddress_confirmed']) ? $vat_info['adddress_confirmed'] : false;
766
+                            $this->update_meta('_wpinv_adddress_confirmed', (bool)$adddress_confirmed);
767 767
                             $this->user_info['adddress_confirmed'] = (bool)$adddress_confirmed;
768 768
                         }
769 769
     
770 770
                         break;
771 771
                     case 'vat_rate':
772
-                        $this->update_meta( '_wpinv_vat_rate', $this->vat_rate );
772
+                        $this->update_meta('_wpinv_vat_rate', $this->vat_rate);
773 773
                         $this->user_info['vat_rate'] = $this->vat_rate;
774 774
                         break;
775 775
                     case 'adddress_confirmed':
776
-                        $this->update_meta( '_wpinv_adddress_confirmed', $this->adddress_confirmed );
776
+                        $this->update_meta('_wpinv_adddress_confirmed', $this->adddress_confirmed);
777 777
                         $this->user_info['adddress_confirmed'] = $this->adddress_confirmed;
778 778
                         break;
779 779
                     
780 780
                     case 'key':
781
-                        $this->update_meta( '_wpinv_key', $this->key );
781
+                        $this->update_meta('_wpinv_key', $this->key);
782 782
                         break;
783 783
                     case 'number':
784
-                        $this->update_meta( '_wpinv_number', $this->number );
784
+                        $this->update_meta('_wpinv_number', $this->number);
785 785
                         break;
786 786
                     case 'date':
787 787
                         $args = array(
@@ -790,34 +790,34 @@  discard block
 block discarded – undo
790 790
                             'edit_date' => true,
791 791
                         );
792 792
 
793
-                        wp_update_post( $args );
793
+                        wp_update_post($args);
794 794
                         break;
795 795
                     case 'due_date':
796
-                        if ( empty( $this->due_date ) ) {
796
+                        if (empty($this->due_date)) {
797 797
                             $this->due_date = 'none';
798 798
                         }
799 799
                         
800
-                        $this->update_meta( '_wpinv_due_date', $this->due_date );
800
+                        $this->update_meta('_wpinv_due_date', $this->due_date);
801 801
                         break;
802 802
                     case 'completed_date':
803
-                        $this->update_meta( '_wpinv_completed_date', $this->completed_date );
803
+                        $this->update_meta('_wpinv_completed_date', $this->completed_date);
804 804
                         break;
805 805
                     case 'discounts':
806
-                        if ( ! is_array( $this->discounts ) ) {
807
-                            $this->discounts = explode( ',', $this->discounts );
806
+                        if (!is_array($this->discounts)) {
807
+                            $this->discounts = explode(',', $this->discounts);
808 808
                         }
809 809
 
810
-                        $this->user_info['discount'] = implode( ',', $this->discounts );
810
+                        $this->user_info['discount'] = implode(',', $this->discounts);
811 811
                         break;
812 812
                         
813 813
                     //case 'tax':
814 814
                         //$this->update_meta( '_wpinv_tax', wpinv_format_amount( $this->tax, NULL, true ) );
815 815
                         //break;
816 816
                     case 'discount':
817
-                        $this->update_meta( '_wpinv_discount', wpinv_format_amount( $this->discount, NULL, true ) );
817
+                        $this->update_meta('_wpinv_discount', wpinv_format_amount($this->discount, NULL, true));
818 818
                         break;
819 819
                     case 'discount_code':
820
-                        $this->update_meta( '_wpinv_discount_code', $this->discount_code );
820
+                        $this->update_meta('_wpinv_discount_code', $this->discount_code);
821 821
                         break;
822 822
                     //case 'fees':
823 823
                         //$this->update_meta( '_wpinv_fees', $this->fees );
@@ -827,19 +827,19 @@  discard block
 block discarded – undo
827 827
                             'ID'          => $this->ID,
828 828
                             'post_parent' => $this->parent_invoice,
829 829
                         );
830
-                        wp_update_post( $args );
830
+                        wp_update_post($args);
831 831
                         break;
832 832
                     default:
833
-                        do_action( 'wpinv_save', $this, $key );
833
+                        do_action('wpinv_save', $this, $key);
834 834
                         break;
835 835
                 }
836 836
             }       
837 837
 
838
-            $this->update_meta( '_wpinv_subtotal', wpinv_format_amount( $this->subtotal, NULL, true ) );
839
-            $this->update_meta( '_wpinv_total', wpinv_format_amount( $this->total, NULL, true ) );
840
-            $this->update_meta( '_wpinv_tax', wpinv_format_amount( $this->tax, NULL, true ) );
838
+            $this->update_meta('_wpinv_subtotal', wpinv_format_amount($this->subtotal, NULL, true));
839
+            $this->update_meta('_wpinv_total', wpinv_format_amount($this->total, NULL, true));
840
+            $this->update_meta('_wpinv_tax', wpinv_format_amount($this->tax, NULL, true));
841 841
             
842
-            $this->items    = array_values( $this->items );
842
+            $this->items = array_values($this->items);
843 843
             
844 844
             $new_meta = array(
845 845
                 'items'         => $this->items,
@@ -850,12 +850,12 @@  discard block
 block discarded – undo
850 850
             );
851 851
             
852 852
             $meta        = $this->get_meta();
853
-            $merged_meta = array_merge( $meta, $new_meta );
853
+            $merged_meta = array_merge($meta, $new_meta);
854 854
 
855 855
             // Only save the payment meta if it's changed
856
-            if ( md5( serialize( $meta ) ) !== md5( serialize( $merged_meta) ) ) {
857
-                $updated     = $this->update_meta( '_wpinv_payment_meta', $merged_meta );
858
-                if ( false !== $updated ) {
856
+            if (md5(serialize($meta)) !== md5(serialize($merged_meta))) {
857
+                $updated = $this->update_meta('_wpinv_payment_meta', $merged_meta);
858
+                if (false !== $updated) {
859 859
                     $saved = true;
860 860
                 }
861 861
             }
@@ -863,15 +863,15 @@  discard block
 block discarded – undo
863 863
             $this->pending = array();
864 864
             $saved         = true;
865 865
         } else {
866
-            $this->update_meta( '_wpinv_subtotal', wpinv_format_amount( $this->subtotal, NULL, true ) );
867
-            $this->update_meta( '_wpinv_total', wpinv_format_amount( $this->total, NULL, true ) );
868
-            $this->update_meta( '_wpinv_tax', wpinv_format_amount( $this->tax, NULL, true ) );
866
+            $this->update_meta('_wpinv_subtotal', wpinv_format_amount($this->subtotal, NULL, true));
867
+            $this->update_meta('_wpinv_total', wpinv_format_amount($this->total, NULL, true));
868
+            $this->update_meta('_wpinv_tax', wpinv_format_amount($this->tax, NULL, true));
869 869
         }
870 870
         
871
-        do_action( 'wpinv_invoice_save', $this, $saved );
871
+        do_action('wpinv_invoice_save', $this, $saved);
872 872
 
873
-        if ( true === $saved || $setup ) {
874
-            $this->setup_invoice( $this->ID );
873
+        if (true === $saved || $setup) {
874
+            $this->setup_invoice($this->ID);
875 875
         }
876 876
         
877 877
         $this->refresh_item_ids();
@@ -879,7 +879,7 @@  discard block
 block discarded – undo
879 879
         return $saved;
880 880
     }
881 881
     
882
-    public function add_fee( $args, $global = true ) {
882
+    public function add_fee($args, $global = true) {
883 883
         $default_args = array(
884 884
             'label'       => '',
885 885
             'amount'      => 0,
@@ -889,75 +889,75 @@  discard block
 block discarded – undo
889 889
             'item_id'     => 0,
890 890
         );
891 891
 
892
-        $fee = wp_parse_args( $args, $default_args );
892
+        $fee = wp_parse_args($args, $default_args);
893 893
         
894
-        if ( !empty( $fee['label'] ) ) {
894
+        if (!empty($fee['label'])) {
895 895
             return false;
896 896
         }
897 897
         
898
-        $fee['id']  = sanitize_title( $fee['label'] );
898
+        $fee['id'] = sanitize_title($fee['label']);
899 899
         
900
-        $this->fees[]               = $fee;
900
+        $this->fees[] = $fee;
901 901
         
902 902
         $added_fee               = $fee;
903 903
         $added_fee['action']     = 'add';
904 904
         $this->pending['fees'][] = $added_fee;
905
-        reset( $this->fees );
905
+        reset($this->fees);
906 906
 
907
-        $this->increase_fees( $fee['amount'] );
907
+        $this->increase_fees($fee['amount']);
908 908
         return true;
909 909
     }
910 910
 
911
-    public function remove_fee( $key ) {
911
+    public function remove_fee($key) {
912 912
         $removed = false;
913 913
 
914
-        if ( is_numeric( $key ) ) {
915
-            $removed = $this->remove_fee_by( 'index', $key );
914
+        if (is_numeric($key)) {
915
+            $removed = $this->remove_fee_by('index', $key);
916 916
         }
917 917
 
918 918
         return $removed;
919 919
     }
920 920
 
921
-    public function remove_fee_by( $key, $value, $global = false ) {
922
-        $allowed_fee_keys = apply_filters( 'wpinv_fee_keys', array(
921
+    public function remove_fee_by($key, $value, $global = false) {
922
+        $allowed_fee_keys = apply_filters('wpinv_fee_keys', array(
923 923
             'index', 'label', 'amount', 'type',
924
-        ) );
924
+        ));
925 925
 
926
-        if ( ! in_array( $key, $allowed_fee_keys ) ) {
926
+        if (!in_array($key, $allowed_fee_keys)) {
927 927
             return false;
928 928
         }
929 929
 
930 930
         $removed = false;
931
-        if ( 'index' === $key && array_key_exists( $value, $this->fees ) ) {
932
-            $removed_fee             = $this->fees[ $value ];
931
+        if ('index' === $key && array_key_exists($value, $this->fees)) {
932
+            $removed_fee             = $this->fees[$value];
933 933
             $removed_fee['action']   = 'remove';
934 934
             $this->pending['fees'][] = $removed_fee;
935 935
 
936
-            $this->decrease_fees( $removed_fee['amount'] );
936
+            $this->decrease_fees($removed_fee['amount']);
937 937
 
938
-            unset( $this->fees[ $value ] );
938
+            unset($this->fees[$value]);
939 939
             $removed = true;
940
-        } else if ( 'index' !== $key ) {
941
-            foreach ( $this->fees as $index => $fee ) {
942
-                if ( isset( $fee[ $key ] ) && $fee[ $key ] == $value ) {
940
+        } else if ('index' !== $key) {
941
+            foreach ($this->fees as $index => $fee) {
942
+                if (isset($fee[$key]) && $fee[$key] == $value) {
943 943
                     $removed_fee             = $fee;
944 944
                     $removed_fee['action']   = 'remove';
945 945
                     $this->pending['fees'][] = $removed_fee;
946 946
 
947
-                    $this->decrease_fees( $removed_fee['amount'] );
947
+                    $this->decrease_fees($removed_fee['amount']);
948 948
 
949
-                    unset( $this->fees[ $index ] );
949
+                    unset($this->fees[$index]);
950 950
                     $removed = true;
951 951
 
952
-                    if ( false === $global ) {
952
+                    if (false === $global) {
953 953
                         break;
954 954
                     }
955 955
                 }
956 956
             }
957 957
         }
958 958
 
959
-        if ( true === $removed ) {
960
-            $this->fees = array_values( $this->fees );
959
+        if (true === $removed) {
960
+            $this->fees = array_values($this->fees);
961 961
         }
962 962
 
963 963
         return $removed;
@@ -965,35 +965,35 @@  discard block
 block discarded – undo
965 965
 
966 966
     
967 967
 
968
-    public function add_note( $note = '', $customer_type = false, $added_by_user = false, $system = false ) {
968
+    public function add_note($note = '', $customer_type = false, $added_by_user = false, $system = false) {
969 969
         // Bail if no note specified
970
-        if( !$note ) {
970
+        if (!$note) {
971 971
             return false;
972 972
         }
973 973
 
974
-        if ( empty( $this->ID ) )
974
+        if (empty($this->ID))
975 975
             return false;
976 976
         
977
-        if ( ( ( is_user_logged_in() && current_user_can( 'manage_options' ) ) || $added_by_user ) && !$system ) {
978
-            $user                 = get_user_by( 'id', get_current_user_id() );
977
+        if (((is_user_logged_in() && current_user_can('manage_options')) || $added_by_user) && !$system) {
978
+            $user                 = get_user_by('id', get_current_user_id());
979 979
             $comment_author       = $user->display_name;
980 980
             $comment_author_email = $user->user_email;
981 981
         } else {
982
-            $comment_author       = __( 'System', 'invoicing' );
983
-            $comment_author_email = strtolower( __( 'System', 'invoicing' ) ) . '@';
984
-            $comment_author_email .= isset( $_SERVER['HTTP_HOST'] ) ? str_replace( 'www.', '', $_SERVER['HTTP_HOST'] ) : 'noreply.com';
985
-            $comment_author_email = sanitize_email( $comment_author_email );
982
+            $comment_author       = __('System', 'invoicing');
983
+            $comment_author_email = strtolower(__('System', 'invoicing')) . '@';
984
+            $comment_author_email .= isset($_SERVER['HTTP_HOST']) ? str_replace('www.', '', $_SERVER['HTTP_HOST']) : 'noreply.com';
985
+            $comment_author_email = sanitize_email($comment_author_email);
986 986
         }
987 987
 
988
-        do_action( 'wpinv_pre_insert_invoice_note', $this->ID, $note, $customer_type );
988
+        do_action('wpinv_pre_insert_invoice_note', $this->ID, $note, $customer_type);
989 989
 
990
-        $note_id = wp_insert_comment( wp_filter_comment( array(
990
+        $note_id = wp_insert_comment(wp_filter_comment(array(
991 991
             'comment_post_ID'      => $this->ID,
992 992
             'comment_content'      => $note,
993 993
             'comment_agent'        => 'GeoDirectory',
994 994
             'user_id'              => is_admin() ? get_current_user_id() : 0,
995
-            'comment_date'         => current_time( 'mysql' ),
996
-            'comment_date_gmt'     => current_time( 'mysql', 1 ),
995
+            'comment_date'         => current_time('mysql'),
996
+            'comment_date_gmt'     => current_time('mysql', 1),
997 997
             'comment_approved'     => 1,
998 998
             'comment_parent'       => 0,
999 999
             'comment_author'       => $comment_author,
@@ -1001,53 +1001,53 @@  discard block
 block discarded – undo
1001 1001
             'comment_author_url'   => '',
1002 1002
             'comment_author_email' => $comment_author_email,
1003 1003
             'comment_type'         => 'wpinv_note'
1004
-        ) ) );
1004
+        )));
1005 1005
 
1006
-        do_action( 'wpinv_insert_payment_note', $note_id, $this->ID, $note );
1006
+        do_action('wpinv_insert_payment_note', $note_id, $this->ID, $note);
1007 1007
         
1008
-        if ( $customer_type ) {
1009
-            add_comment_meta( $note_id, '_wpi_customer_note', 1 );
1008
+        if ($customer_type) {
1009
+            add_comment_meta($note_id, '_wpi_customer_note', 1);
1010 1010
 
1011
-            do_action( 'wpinv_new_customer_note', array( 'invoice_id' => $this->ID, 'user_note' => $note ) );
1011
+            do_action('wpinv_new_customer_note', array('invoice_id' => $this->ID, 'user_note' => $note));
1012 1012
         }
1013 1013
 
1014 1014
         return $note_id;
1015 1015
     }
1016 1016
 
1017
-    private function increase_subtotal( $amount = 0.00 ) {
1018
-        $amount          = (float) $amount;
1017
+    private function increase_subtotal($amount = 0.00) {
1018
+        $amount          = (float)$amount;
1019 1019
         $this->subtotal += $amount;
1020
-        $this->subtotal  = wpinv_format_amount( $this->subtotal, NULL, true );
1020
+        $this->subtotal  = wpinv_format_amount($this->subtotal, NULL, true);
1021 1021
 
1022 1022
         $this->recalculate_total();
1023 1023
     }
1024 1024
 
1025
-    private function decrease_subtotal( $amount = 0.00 ) {
1026
-        $amount          = (float) $amount;
1025
+    private function decrease_subtotal($amount = 0.00) {
1026
+        $amount          = (float)$amount;
1027 1027
         $this->subtotal -= $amount;
1028
-        $this->subtotal  = wpinv_format_amount( $this->subtotal, NULL, true );
1028
+        $this->subtotal  = wpinv_format_amount($this->subtotal, NULL, true);
1029 1029
 
1030
-        if ( $this->subtotal < 0 ) {
1030
+        if ($this->subtotal < 0) {
1031 1031
             $this->subtotal = 0;
1032 1032
         }
1033 1033
 
1034 1034
         $this->recalculate_total();
1035 1035
     }
1036 1036
 
1037
-    private function increase_fees( $amount = 0.00 ) {
1037
+    private function increase_fees($amount = 0.00) {
1038 1038
         $amount            = (float)$amount;
1039 1039
         $this->fees_total += $amount;
1040
-        $this->fees_total  = wpinv_format_amount( $this->fees_total, NULL, true );
1040
+        $this->fees_total  = wpinv_format_amount($this->fees_total, NULL, true);
1041 1041
 
1042 1042
         $this->recalculate_total();
1043 1043
     }
1044 1044
 
1045
-    private function decrease_fees( $amount = 0.00 ) {
1046
-        $amount            = (float) $amount;
1045
+    private function decrease_fees($amount = 0.00) {
1046
+        $amount            = (float)$amount;
1047 1047
         $this->fees_total -= $amount;
1048
-        $this->fees_total  = wpinv_format_amount( $this->fees_total, NULL, true );
1048
+        $this->fees_total  = wpinv_format_amount($this->fees_total, NULL, true);
1049 1049
 
1050
-        if ( $this->fees_total < 0 ) {
1050
+        if ($this->fees_total < 0) {
1051 1051
             $this->fees_total = 0;
1052 1052
         }
1053 1053
 
@@ -1058,54 +1058,54 @@  discard block
 block discarded – undo
1058 1058
         global $wpi_nosave;
1059 1059
         
1060 1060
         $this->total = $this->subtotal + $this->tax + $this->fees_total;
1061
-        $this->total = wpinv_format_amount( $this->total, NULL, true );
1061
+        $this->total = wpinv_format_amount($this->total, NULL, true);
1062 1062
         
1063
-        do_action( 'wpinv_invoice_recalculate_total', $this, $wpi_nosave );
1063
+        do_action('wpinv_invoice_recalculate_total', $this, $wpi_nosave);
1064 1064
     }
1065 1065
     
1066
-    public function increase_tax( $amount = 0.00 ) {
1067
-        $amount       = (float) $amount;
1066
+    public function increase_tax($amount = 0.00) {
1067
+        $amount       = (float)$amount;
1068 1068
         $this->tax   += $amount;
1069 1069
 
1070 1070
         $this->recalculate_total();
1071 1071
     }
1072 1072
 
1073
-    public function decrease_tax( $amount = 0.00 ) {
1074
-        $amount     = (float) $amount;
1073
+    public function decrease_tax($amount = 0.00) {
1074
+        $amount     = (float)$amount;
1075 1075
         $this->tax -= $amount;
1076 1076
 
1077
-        if ( $this->tax < 0 ) {
1077
+        if ($this->tax < 0) {
1078 1078
             $this->tax = 0;
1079 1079
         }
1080 1080
 
1081 1081
         $this->recalculate_total();
1082 1082
     }
1083 1083
 
1084
-    public function update_status( $new_status = false, $note = '', $manual = false ) {
1085
-        $old_status = ! empty( $this->old_status ) ? $this->old_status : get_post_status( $this->ID );
1084
+    public function update_status($new_status = false, $note = '', $manual = false) {
1085
+        $old_status = !empty($this->old_status) ? $this->old_status : get_post_status($this->ID);
1086 1086
         
1087
-        if ( $old_status === $new_status && in_array( $new_status, array_keys( wpinv_get_invoice_statuses() ) ) ) {
1087
+        if ($old_status === $new_status && in_array($new_status, array_keys(wpinv_get_invoice_statuses()))) {
1088 1088
             return false; // Don't permit status changes that aren't changes
1089 1089
         }
1090 1090
 
1091
-        $do_change = apply_filters( 'wpinv_should_update_invoice_status', true, $this->ID, $new_status, $old_status );
1091
+        $do_change = apply_filters('wpinv_should_update_invoice_status', true, $this->ID, $new_status, $old_status);
1092 1092
         $updated = false;
1093 1093
 
1094
-        if ( $do_change ) {
1095
-            do_action( 'wpinv_before_invoice_status_change', $this->ID, $new_status, $old_status );
1094
+        if ($do_change) {
1095
+            do_action('wpinv_before_invoice_status_change', $this->ID, $new_status, $old_status);
1096 1096
 
1097 1097
             $update_post_data                   = array();
1098 1098
             $update_post_data['ID']             = $this->ID;
1099 1099
             $update_post_data['post_status']    = $new_status;
1100
-            $update_post_data['edit_date']      = current_time( 'mysql', 0 );
1101
-            $update_post_data['edit_date_gmt']  = current_time( 'mysql', 1 );
1100
+            $update_post_data['edit_date']      = current_time('mysql', 0);
1101
+            $update_post_data['edit_date_gmt']  = current_time('mysql', 1);
1102 1102
             
1103
-            $update_post_data = apply_filters( 'wpinv_update_invoice_status_fields', $update_post_data, $this->ID );
1103
+            $update_post_data = apply_filters('wpinv_update_invoice_status_fields', $update_post_data, $this->ID);
1104 1104
 
1105
-            $updated = wp_update_post( $update_post_data );     
1105
+            $updated = wp_update_post($update_post_data);     
1106 1106
            
1107 1107
             // Process any specific status functions
1108
-            switch( $new_status ) {
1108
+            switch ($new_status) {
1109 1109
                 case 'refunded':
1110 1110
                     $this->process_refund();
1111 1111
                     break;
@@ -1118,9 +1118,9 @@  discard block
 block discarded – undo
1118 1118
             }
1119 1119
             
1120 1120
             // Status was changed.
1121
-            do_action( 'wpinv_status_' . $new_status, $this->ID, $old_status );
1122
-            do_action( 'wpinv_status_' . $old_status . '_to_' . $new_status, $this->ID, $old_status );
1123
-            do_action( 'wpinv_update_status', $this->ID, $new_status, $old_status );
1121
+            do_action('wpinv_status_' . $new_status, $this->ID, $old_status);
1122
+            do_action('wpinv_status_' . $old_status . '_to_' . $new_status, $this->ID, $old_status);
1123
+            do_action('wpinv_update_status', $this->ID, $new_status, $old_status);
1124 1124
         }
1125 1125
 
1126 1126
         return $updated;
@@ -1134,72 +1134,72 @@  discard block
 block discarded – undo
1134 1134
         $this->save();
1135 1135
     }
1136 1136
 
1137
-    public function update_meta( $meta_key = '', $meta_value = '', $prev_value = '' ) {
1138
-        if ( empty( $meta_key ) ) {
1137
+    public function update_meta($meta_key = '', $meta_value = '', $prev_value = '') {
1138
+        if (empty($meta_key)) {
1139 1139
             return false;
1140 1140
         }
1141 1141
 
1142
-        if ( $meta_key == 'key' || $meta_key == 'date' ) {
1142
+        if ($meta_key == 'key' || $meta_key == 'date') {
1143 1143
             $current_meta = $this->get_meta();
1144
-            $current_meta[ $meta_key ] = $meta_value;
1144
+            $current_meta[$meta_key] = $meta_value;
1145 1145
 
1146 1146
             $meta_key     = '_wpinv_payment_meta';
1147 1147
             $meta_value   = $current_meta;
1148 1148
         }
1149 1149
 
1150
-        $meta_value = apply_filters( 'wpinv_update_payment_meta_' . $meta_key, $meta_value, $this->ID );
1150
+        $meta_value = apply_filters('wpinv_update_payment_meta_' . $meta_key, $meta_value, $this->ID);
1151 1151
         
1152
-        if ( $meta_key == '_wpinv_completed_date' && !empty( $meta_value ) ) {
1152
+        if ($meta_key == '_wpinv_completed_date' && !empty($meta_value)) {
1153 1153
             $args = array(
1154 1154
                 'ID'                => $this->ID,
1155 1155
                 'post_date'         => $meta_value,
1156 1156
                 'edit_date'         => true,
1157
-                'post_date_gmt'     => get_gmt_from_date( $meta_value ),
1157
+                'post_date_gmt'     => get_gmt_from_date($meta_value),
1158 1158
                 'post_modified'     => $meta_value,
1159
-                'post_modified_gmt' => get_gmt_from_date( $meta_value )
1159
+                'post_modified_gmt' => get_gmt_from_date($meta_value)
1160 1160
             );
1161
-            wp_update_post( $args );
1161
+            wp_update_post($args);
1162 1162
         }
1163 1163
         
1164
-        return update_post_meta( $this->ID, $meta_key, $meta_value, $prev_value );
1164
+        return update_post_meta($this->ID, $meta_key, $meta_value, $prev_value);
1165 1165
     }
1166 1166
 
1167 1167
     private function process_refund() {
1168 1168
         $process_refund = true;
1169 1169
 
1170 1170
         // If the payment was not in publish or revoked status, don't decrement stats as they were never incremented
1171
-        if ( ( 'publish' != $this->old_status && 'revoked' != $this->old_status ) || 'refunded' != $this->status ) {
1171
+        if (('publish' != $this->old_status && 'revoked' != $this->old_status) || 'refunded' != $this->status) {
1172 1172
             $process_refund = false;
1173 1173
         }
1174 1174
 
1175 1175
         // Allow extensions to filter for their own payment types, Example: Recurring Payments
1176
-        $process_refund = apply_filters( 'wpinv_should_process_refund', $process_refund, $this );
1176
+        $process_refund = apply_filters('wpinv_should_process_refund', $process_refund, $this);
1177 1177
 
1178
-        if ( false === $process_refund ) {
1178
+        if (false === $process_refund) {
1179 1179
             return;
1180 1180
         }
1181 1181
 
1182
-        do_action( 'wpinv_pre_refund_invoice', $this );
1182
+        do_action('wpinv_pre_refund_invoice', $this);
1183 1183
         
1184
-        $decrease_store_earnings = apply_filters( 'wpinv_decrease_store_earnings_on_refund', true, $this );
1185
-        $decrease_customer_value = apply_filters( 'wpinv_decrease_customer_value_on_refund', true, $this );
1186
-        $decrease_purchase_count = apply_filters( 'wpinv_decrease_customer_purchase_count_on_refund', true, $this );
1184
+        $decrease_store_earnings = apply_filters('wpinv_decrease_store_earnings_on_refund', true, $this);
1185
+        $decrease_customer_value = apply_filters('wpinv_decrease_customer_value_on_refund', true, $this);
1186
+        $decrease_purchase_count = apply_filters('wpinv_decrease_customer_purchase_count_on_refund', true, $this);
1187 1187
         
1188
-        do_action( 'wpinv_post_refund_invoice', $this );
1188
+        do_action('wpinv_post_refund_invoice', $this);
1189 1189
     }
1190 1190
 
1191 1191
     private function process_failure() {
1192 1192
         $discounts = $this->discounts;
1193
-        if ( empty( $discounts ) ) {
1193
+        if (empty($discounts)) {
1194 1194
             return;
1195 1195
         }
1196 1196
 
1197
-        if ( ! is_array( $discounts ) ) {
1198
-            $discounts = array_map( 'trim', explode( ',', $discounts ) );
1197
+        if (!is_array($discounts)) {
1198
+            $discounts = array_map('trim', explode(',', $discounts));
1199 1199
         }
1200 1200
 
1201
-        foreach ( $discounts as $discount ) {
1202
-            wpinv_decrease_discount_usage( $discount );
1201
+        foreach ($discounts as $discount) {
1202
+            wpinv_decrease_discount_usage($discount);
1203 1203
         }
1204 1204
     }
1205 1205
     
@@ -1207,89 +1207,89 @@  discard block
 block discarded – undo
1207 1207
         $process_pending = true;
1208 1208
 
1209 1209
         // If the payment was not in publish or revoked status, don't decrement stats as they were never incremented
1210
-        if ( ( 'publish' != $this->old_status && 'revoked' != $this->old_status ) || 'pending' != $this->status ) {
1210
+        if (('publish' != $this->old_status && 'revoked' != $this->old_status) || 'pending' != $this->status) {
1211 1211
             $process_pending = false;
1212 1212
         }
1213 1213
 
1214 1214
         // Allow extensions to filter for their own payment types, Example: Recurring Payments
1215
-        $process_pending = apply_filters( 'wpinv_should_process_pending', $process_pending, $this );
1215
+        $process_pending = apply_filters('wpinv_should_process_pending', $process_pending, $this);
1216 1216
 
1217
-        if ( false === $process_pending ) {
1217
+        if (false === $process_pending) {
1218 1218
             return;
1219 1219
         }
1220 1220
 
1221
-        $decrease_store_earnings = apply_filters( 'wpinv_decrease_store_earnings_on_pending', true, $this );
1222
-        $decrease_customer_value = apply_filters( 'wpinv_decrease_customer_value_on_pending', true, $this );
1223
-        $decrease_purchase_count = apply_filters( 'wpinv_decrease_customer_purchase_count_on_pending', true, $this );
1221
+        $decrease_store_earnings = apply_filters('wpinv_decrease_store_earnings_on_pending', true, $this);
1222
+        $decrease_customer_value = apply_filters('wpinv_decrease_customer_value_on_pending', true, $this);
1223
+        $decrease_purchase_count = apply_filters('wpinv_decrease_customer_purchase_count_on_pending', true, $this);
1224 1224
 
1225 1225
         $this->completed_date = false;
1226
-        $this->update_meta( '_wpinv_completed_date', '' );
1226
+        $this->update_meta('_wpinv_completed_date', '');
1227 1227
     }
1228 1228
     
1229 1229
     // get data
1230
-    public function get_meta( $meta_key = '_wpinv_payment_meta', $single = true ) {
1231
-        $meta = get_post_meta( $this->ID, $meta_key, $single );
1230
+    public function get_meta($meta_key = '_wpinv_payment_meta', $single = true) {
1231
+        $meta = get_post_meta($this->ID, $meta_key, $single);
1232 1232
 
1233
-        if ( $meta_key === '_wpinv_payment_meta' ) {
1234
-            if ( empty( $meta['key'] ) ) {
1233
+        if ($meta_key === '_wpinv_payment_meta') {
1234
+            if (empty($meta['key'])) {
1235 1235
                 $meta['key'] = $this->setup_invoice_key();
1236 1236
             }
1237 1237
 
1238
-            if ( empty( $meta['date'] ) ) {
1239
-                $meta['date'] = get_post_field( 'post_date', $this->ID );
1238
+            if (empty($meta['date'])) {
1239
+                $meta['date'] = get_post_field('post_date', $this->ID);
1240 1240
             }
1241 1241
         }
1242 1242
 
1243
-        $meta = apply_filters( 'wpinv_get_invoice_meta_' . $meta_key, $meta, $this->ID );
1243
+        $meta = apply_filters('wpinv_get_invoice_meta_' . $meta_key, $meta, $this->ID);
1244 1244
 
1245
-        return apply_filters( 'wpinv_get_invoice_meta', $meta, $this->ID, $meta_key );
1245
+        return apply_filters('wpinv_get_invoice_meta', $meta, $this->ID, $meta_key);
1246 1246
     }
1247 1247
     
1248 1248
     public function get_description() {
1249
-        $post = get_post( $this->ID );
1249
+        $post = get_post($this->ID);
1250 1250
         
1251
-        $description = !empty( $post ) ? $post->post_content : '';
1252
-        return apply_filters( 'wpinv_get_description', $description, $this->ID, $this );
1251
+        $description = !empty($post) ? $post->post_content : '';
1252
+        return apply_filters('wpinv_get_description', $description, $this->ID, $this);
1253 1253
     }
1254 1254
     
1255
-    public function get_status( $nicename = false ) {
1256
-        if ( !$nicename ) {
1255
+    public function get_status($nicename = false) {
1256
+        if (!$nicename) {
1257 1257
             $status = $this->status;
1258 1258
         } else {
1259 1259
             $status = $this->status_nicename;
1260 1260
         }
1261 1261
         
1262
-        return apply_filters( 'wpinv_get_status', $status, $nicename, $this->ID, $this );
1262
+        return apply_filters('wpinv_get_status', $status, $nicename, $this->ID, $this);
1263 1263
     }
1264 1264
     
1265 1265
     public function get_cart_details() {
1266
-        return apply_filters( 'wpinv_cart_details', $this->cart_details, $this->ID, $this );
1266
+        return apply_filters('wpinv_cart_details', $this->cart_details, $this->ID, $this);
1267 1267
     }
1268 1268
     
1269
-    public function get_subtotal( $currency = false ) {
1270
-        $subtotal = wpinv_format_amount( $this->subtotal, NULL, !$currency );
1269
+    public function get_subtotal($currency = false) {
1270
+        $subtotal = wpinv_format_amount($this->subtotal, NULL, !$currency);
1271 1271
         
1272
-        if ( $currency ) {
1273
-            $subtotal = wpinv_price( $subtotal, $this->get_currency() );
1272
+        if ($currency) {
1273
+            $subtotal = wpinv_price($subtotal, $this->get_currency());
1274 1274
         }
1275 1275
         
1276
-        return apply_filters( 'wpinv_get_invoice_subtotal', $subtotal, $this->ID, $this, $currency );
1276
+        return apply_filters('wpinv_get_invoice_subtotal', $subtotal, $this->ID, $this, $currency);
1277 1277
     }
1278 1278
     
1279
-    public function get_total( $currency = false ) {        
1280
-        if ( $this->is_free_trial() ) {
1281
-            $total = wpinv_format_amount( 0, NULL, !$currency );
1279
+    public function get_total($currency = false) {        
1280
+        if ($this->is_free_trial()) {
1281
+            $total = wpinv_format_amount(0, NULL, !$currency);
1282 1282
         } else {
1283
-            $total = wpinv_format_amount( $this->total, NULL, !$currency );
1283
+            $total = wpinv_format_amount($this->total, NULL, !$currency);
1284 1284
         }
1285
-        if ( $currency ) {
1286
-            $total = wpinv_price( $total, $this->get_currency() );
1285
+        if ($currency) {
1286
+            $total = wpinv_price($total, $this->get_currency());
1287 1287
         }
1288 1288
         
1289
-        return apply_filters( 'wpinv_get_invoice_total', $total, $this->ID, $this, $currency );
1289
+        return apply_filters('wpinv_get_invoice_total', $total, $this->ID, $this, $currency);
1290 1290
     }
1291 1291
     
1292
-    public function get_recurring_details( $field = '', $currency = false ) {        
1292
+    public function get_recurring_details($field = '', $currency = false) {        
1293 1293
         $data                 = array();
1294 1294
         $data['cart_details'] = $this->cart_details;
1295 1295
         $data['subtotal']     = $this->get_subtotal();
@@ -1297,45 +1297,45 @@  discard block
 block discarded – undo
1297 1297
         $data['tax']          = $this->get_tax();
1298 1298
         $data['total']        = $this->get_total();
1299 1299
     
1300
-        if ( !empty( $this->cart_details ) && ( $this->is_parent() || $this->is_renewal() ) ) {
1300
+        if (!empty($this->cart_details) && ($this->is_parent() || $this->is_renewal())) {
1301 1301
             $is_free_trial = $this->is_free_trial();
1302
-            $discounts = $this->get_discounts( true );
1302
+            $discounts = $this->get_discounts(true);
1303 1303
             
1304
-            if ( $is_free_trial || !empty( $discounts ) ) {
1304
+            if ($is_free_trial || !empty($discounts)) {
1305 1305
                 $first_use_only = false;
1306 1306
                 
1307
-                if ( !empty( $discounts ) ) {
1308
-                    foreach ( $discounts as $key => $code ) {
1309
-                        if ( wpinv_discount_is_recurring( $code, true ) ) {
1307
+                if (!empty($discounts)) {
1308
+                    foreach ($discounts as $key => $code) {
1309
+                        if (wpinv_discount_is_recurring($code, true)) {
1310 1310
                             $first_use_only = true;
1311 1311
                             break;
1312 1312
                         }
1313 1313
                     }
1314 1314
                 }
1315 1315
                     
1316
-                if ( !$first_use_only ) {
1317
-                    $data['subtotal'] = wpinv_format_amount( $this->subtotal, NULL, true );
1318
-                    $data['discount'] = wpinv_format_amount( $this->discount, NULL, true );
1319
-                    $data['tax']      = wpinv_format_amount( $this->tax, NULL, true );
1320
-                    $data['total']    = wpinv_format_amount( $this->total, NULL, true );
1316
+                if (!$first_use_only) {
1317
+                    $data['subtotal'] = wpinv_format_amount($this->subtotal, NULL, true);
1318
+                    $data['discount'] = wpinv_format_amount($this->discount, NULL, true);
1319
+                    $data['tax']      = wpinv_format_amount($this->tax, NULL, true);
1320
+                    $data['total']    = wpinv_format_amount($this->total, NULL, true);
1321 1321
                 } else {
1322 1322
                     $cart_subtotal   = 0;
1323 1323
                     $cart_discount   = 0;
1324 1324
                     $cart_tax        = 0;
1325 1325
 
1326
-                    foreach ( $this->cart_details as $key => $item ) {
1327
-                        $item_quantity  = $item['quantity'] > 0 ? absint( $item['quantity'] ) : 1;
1328
-                        $item_subtotal  = !empty( $item['subtotal'] ) ? $item['subtotal'] : $item['item_price'] * $item_quantity;
1326
+                    foreach ($this->cart_details as $key => $item) {
1327
+                        $item_quantity  = $item['quantity'] > 0 ? absint($item['quantity']) : 1;
1328
+                        $item_subtotal  = !empty($item['subtotal']) ? $item['subtotal'] : $item['item_price'] * $item_quantity;
1329 1329
                         $item_discount  = 0;
1330
-                        $item_tax       = $item_subtotal > 0 && !empty( $item['vat_rate'] ) ? ( $item_subtotal * 0.01 * (float)$item['vat_rate'] ) : 0;
1330
+                        $item_tax       = $item_subtotal > 0 && !empty($item['vat_rate']) ? ($item_subtotal * 0.01 * (float)$item['vat_rate']) : 0;
1331 1331
                         
1332
-                        if ( wpinv_prices_include_tax() ) {
1333
-                            $item_subtotal -= wpinv_format_amount( $item_tax, NULL, true );
1332
+                        if (wpinv_prices_include_tax()) {
1333
+                            $item_subtotal -= wpinv_format_amount($item_tax, NULL, true);
1334 1334
                         }
1335 1335
                         
1336 1336
                         $item_total     = $item_subtotal - $item_discount + $item_tax;
1337 1337
                         // Do not allow totals to go negative
1338
-                        if ( $item_total < 0 ) {
1338
+                        if ($item_total < 0) {
1339 1339
                             $item_total = 0;
1340 1340
                         }
1341 1341
                         
@@ -1343,107 +1343,107 @@  discard block
 block discarded – undo
1343 1343
                         $cart_discount  += (float)($item_discount);
1344 1344
                         $cart_tax       += (float)($item_tax);
1345 1345
                         
1346
-                        $data['cart_details'][$key]['discount']   = wpinv_format_amount( $item_discount, NULL, true );
1347
-                        $data['cart_details'][$key]['tax']        = wpinv_format_amount( $item_tax, NULL, true );
1348
-                        $data['cart_details'][$key]['price']      = wpinv_format_amount( $item_total, NULL, true );
1346
+                        $data['cart_details'][$key]['discount']   = wpinv_format_amount($item_discount, NULL, true);
1347
+                        $data['cart_details'][$key]['tax']        = wpinv_format_amount($item_tax, NULL, true);
1348
+                        $data['cart_details'][$key]['price']      = wpinv_format_amount($item_total, NULL, true);
1349 1349
                     }
1350 1350
                     
1351
-                    $data['subtotal'] = wpinv_format_amount( $cart_subtotal, NULL, true );
1352
-                    $data['discount'] = wpinv_format_amount( $cart_discount, NULL, true );
1353
-                    $data['tax']      = wpinv_format_amount( $cart_tax, NULL, true );
1354
-                    $data['total']    = wpinv_format_amount( ( $data['subtotal'] + $data['tax'] ), NULL, true );
1351
+                    $data['subtotal'] = wpinv_format_amount($cart_subtotal, NULL, true);
1352
+                    $data['discount'] = wpinv_format_amount($cart_discount, NULL, true);
1353
+                    $data['tax']      = wpinv_format_amount($cart_tax, NULL, true);
1354
+                    $data['total']    = wpinv_format_amount(($data['subtotal'] + $data['tax']), NULL, true);
1355 1355
                 }
1356 1356
             }
1357 1357
         }
1358 1358
         
1359
-        $data = apply_filters( 'wpinv_get_invoice_recurring_details', $data, $this, $field, $currency );
1359
+        $data = apply_filters('wpinv_get_invoice_recurring_details', $data, $this, $field, $currency);
1360 1360
 
1361
-        if ( isset( $data[$field] ) ) {
1362
-            return ( $currency ? wpinv_price( $data[$field], $this->get_currency() ) : $data[$field] );
1361
+        if (isset($data[$field])) {
1362
+            return ($currency ? wpinv_price($data[$field], $this->get_currency()) : $data[$field]);
1363 1363
         }
1364 1364
         
1365 1365
         return $data;
1366 1366
     }
1367 1367
     
1368
-    public function get_final_tax( $currency = false ) {        
1369
-        $final_total = wpinv_format_amount( $this->tax, NULL, !$currency );
1370
-        if ( $currency ) {
1371
-            $final_total = wpinv_price( $final_total, $this->get_currency() );
1368
+    public function get_final_tax($currency = false) {        
1369
+        $final_total = wpinv_format_amount($this->tax, NULL, !$currency);
1370
+        if ($currency) {
1371
+            $final_total = wpinv_price($final_total, $this->get_currency());
1372 1372
         }
1373 1373
         
1374
-        return apply_filters( 'wpinv_get_invoice_final_total', $final_total, $this, $currency );
1374
+        return apply_filters('wpinv_get_invoice_final_total', $final_total, $this, $currency);
1375 1375
     }
1376 1376
     
1377
-    public function get_discounts( $array = false ) {
1377
+    public function get_discounts($array = false) {
1378 1378
         $discounts = $this->discounts;
1379
-        if ( $array && $discounts ) {
1380
-            $discounts = explode( ',', $discounts );
1379
+        if ($array && $discounts) {
1380
+            $discounts = explode(',', $discounts);
1381 1381
         }
1382
-        return apply_filters( 'wpinv_payment_discounts', $discounts, $this->ID, $this, $array );
1382
+        return apply_filters('wpinv_payment_discounts', $discounts, $this->ID, $this, $array);
1383 1383
     }
1384 1384
     
1385
-    public function get_discount( $currency = false, $dash = false ) {
1386
-        if ( !empty( $this->discounts ) ) {
1385
+    public function get_discount($currency = false, $dash = false) {
1386
+        if (!empty($this->discounts)) {
1387 1387
             global $ajax_cart_details;
1388 1388
             $ajax_cart_details = $this->get_cart_details();
1389 1389
 
1390
-            $this->discount = wpinv_get_cart_items_discount_amount( $this->items , $this->discounts );
1390
+            $this->discount = wpinv_get_cart_items_discount_amount($this->items, $this->discounts);
1391 1391
         }
1392
-        $discount   = wpinv_format_amount( $this->discount, NULL, !$currency );
1392
+        $discount   = wpinv_format_amount($this->discount, NULL, !$currency);
1393 1393
         $dash       = $dash && $discount > 0 ? '&ndash;' : '';
1394 1394
         
1395
-        if ( $currency ) {
1396
-            $discount = wpinv_price( $discount, $this->get_currency() );
1395
+        if ($currency) {
1396
+            $discount = wpinv_price($discount, $this->get_currency());
1397 1397
         }
1398 1398
         
1399
-        $discount   = $dash . $discount;
1399
+        $discount = $dash . $discount;
1400 1400
         
1401
-        return apply_filters( 'wpinv_get_invoice_discount', $discount, $this->ID, $this, $currency, $dash );
1401
+        return apply_filters('wpinv_get_invoice_discount', $discount, $this->ID, $this, $currency, $dash);
1402 1402
     }
1403 1403
     
1404 1404
     public function get_discount_code() {
1405 1405
         return $this->discount_code;
1406 1406
     }
1407 1407
     
1408
-    public function get_tax( $currency = false ) {
1409
-        $tax = wpinv_format_amount( $this->tax, NULL, !$currency );
1408
+    public function get_tax($currency = false) {
1409
+        $tax = wpinv_format_amount($this->tax, NULL, !$currency);
1410 1410
         
1411
-        if ( $currency ) {
1412
-            $tax = wpinv_price( $tax, $this->get_currency() );
1411
+        if ($currency) {
1412
+            $tax = wpinv_price($tax, $this->get_currency());
1413 1413
         }
1414 1414
         
1415
-        return apply_filters( 'wpinv_get_invoice_tax', $tax, $this->ID, $this, $currency );
1415
+        return apply_filters('wpinv_get_invoice_tax', $tax, $this->ID, $this, $currency);
1416 1416
     }
1417 1417
     
1418
-    public function get_fees( $type = 'all' ) {
1419
-        $fees    = array();
1418
+    public function get_fees($type = 'all') {
1419
+        $fees = array();
1420 1420
 
1421
-        if ( ! empty( $this->fees ) && is_array( $this->fees ) ) {
1422
-            foreach ( $this->fees as $fee ) {
1423
-                if( 'all' != $type && ! empty( $fee['type'] ) && $type != $fee['type'] ) {
1421
+        if (!empty($this->fees) && is_array($this->fees)) {
1422
+            foreach ($this->fees as $fee) {
1423
+                if ('all' != $type && !empty($fee['type']) && $type != $fee['type']) {
1424 1424
                     continue;
1425 1425
                 }
1426 1426
 
1427
-                $fee['label'] = stripslashes( $fee['label'] );
1428
-                $fee['amount_display'] = wpinv_price( $fee['amount'], $this->get_currency() );
1429
-                $fees[]    = $fee;
1427
+                $fee['label'] = stripslashes($fee['label']);
1428
+                $fee['amount_display'] = wpinv_price($fee['amount'], $this->get_currency());
1429
+                $fees[] = $fee;
1430 1430
             }
1431 1431
         }
1432 1432
 
1433
-        return apply_filters( 'wpinv_get_invoice_fees', $fees, $this->ID, $this );
1433
+        return apply_filters('wpinv_get_invoice_fees', $fees, $this->ID, $this);
1434 1434
     }
1435 1435
     
1436
-    public function get_fees_total( $type = 'all' ) {
1437
-        $fees_total = (float) 0.00;
1436
+    public function get_fees_total($type = 'all') {
1437
+        $fees_total = (float)0.00;
1438 1438
 
1439
-        $payment_fees = isset( $this->payment_meta['fees'] ) ? $this->payment_meta['fees'] : array();
1440
-        if ( ! empty( $payment_fees ) ) {
1441
-            foreach ( $payment_fees as $fee ) {
1442
-                $fees_total += (float) $fee['amount'];
1439
+        $payment_fees = isset($this->payment_meta['fees']) ? $this->payment_meta['fees'] : array();
1440
+        if (!empty($payment_fees)) {
1441
+            foreach ($payment_fees as $fee) {
1442
+                $fees_total += (float)$fee['amount'];
1443 1443
             }
1444 1444
         }
1445 1445
 
1446
-        return apply_filters( 'wpinv_get_invoice_fees_total', $fees_total, $this->ID, $this );
1446
+        return apply_filters('wpinv_get_invoice_fees_total', $fees_total, $this->ID, $this);
1447 1447
         /*
1448 1448
         $fees = $this->get_fees( $type );
1449 1449
 
@@ -1463,116 +1463,116 @@  discard block
 block discarded – undo
1463 1463
     }
1464 1464
 
1465 1465
     public function get_user_id() {
1466
-        return apply_filters( 'wpinv_user_id', $this->user_id, $this->ID, $this );
1466
+        return apply_filters('wpinv_user_id', $this->user_id, $this->ID, $this);
1467 1467
     }
1468 1468
     
1469 1469
     public function get_first_name() {
1470
-        return apply_filters( 'wpinv_first_name', $this->first_name, $this->ID, $this );
1470
+        return apply_filters('wpinv_first_name', $this->first_name, $this->ID, $this);
1471 1471
     }
1472 1472
     
1473 1473
     public function get_last_name() {
1474
-        return apply_filters( 'wpinv_last_name', $this->last_name, $this->ID, $this );
1474
+        return apply_filters('wpinv_last_name', $this->last_name, $this->ID, $this);
1475 1475
     }
1476 1476
     
1477 1477
     public function get_user_full_name() {
1478
-        return apply_filters( 'wpinv_user_full_name', $this->full_name, $this->ID, $this );
1478
+        return apply_filters('wpinv_user_full_name', $this->full_name, $this->ID, $this);
1479 1479
     }
1480 1480
     
1481 1481
     public function get_user_info() {
1482
-        return apply_filters( 'wpinv_user_info', $this->user_info, $this->ID, $this );
1482
+        return apply_filters('wpinv_user_info', $this->user_info, $this->ID, $this);
1483 1483
     }
1484 1484
     
1485 1485
     public function get_email() {
1486
-        return apply_filters( 'wpinv_user_email', $this->email, $this->ID, $this );
1486
+        return apply_filters('wpinv_user_email', $this->email, $this->ID, $this);
1487 1487
     }
1488 1488
     
1489 1489
     public function get_address() {
1490
-        return apply_filters( 'wpinv_address', $this->address, $this->ID, $this );
1490
+        return apply_filters('wpinv_address', $this->address, $this->ID, $this);
1491 1491
     }
1492 1492
     
1493 1493
     public function get_phone() {
1494
-        return apply_filters( 'wpinv_phone', $this->phone, $this->ID, $this );
1494
+        return apply_filters('wpinv_phone', $this->phone, $this->ID, $this);
1495 1495
     }
1496 1496
     
1497 1497
     public function get_number() {
1498
-        return apply_filters( 'wpinv_number', $this->number, $this->ID, $this );
1498
+        return apply_filters('wpinv_number', $this->number, $this->ID, $this);
1499 1499
     }
1500 1500
     
1501 1501
     public function get_items() {
1502
-        return apply_filters( 'wpinv_payment_meta_items', $this->items, $this->ID, $this );
1502
+        return apply_filters('wpinv_payment_meta_items', $this->items, $this->ID, $this);
1503 1503
     }
1504 1504
     
1505 1505
     public function get_key() {
1506
-        return apply_filters( 'wpinv_key', $this->key, $this->ID, $this );
1506
+        return apply_filters('wpinv_key', $this->key, $this->ID, $this);
1507 1507
     }
1508 1508
     
1509 1509
     public function get_transaction_id() {
1510
-        return apply_filters( 'wpinv_get_invoice_transaction_id', $this->transaction_id, $this->ID, $this );
1510
+        return apply_filters('wpinv_get_invoice_transaction_id', $this->transaction_id, $this->ID, $this);
1511 1511
     }
1512 1512
     
1513 1513
     public function get_gateway() {
1514
-        return apply_filters( 'wpinv_gateway', $this->gateway, $this->ID, $this );
1514
+        return apply_filters('wpinv_gateway', $this->gateway, $this->ID, $this);
1515 1515
     }
1516 1516
     
1517 1517
     public function get_gateway_title() {
1518
-        $this->gateway_title = !empty( $this->gateway_title ) ? $this->gateway_title : wpinv_get_gateway_checkout_label( $this->gateway );
1518
+        $this->gateway_title = !empty($this->gateway_title) ? $this->gateway_title : wpinv_get_gateway_checkout_label($this->gateway);
1519 1519
         
1520
-        return apply_filters( 'wpinv_gateway_title', $this->gateway_title, $this->ID, $this );
1520
+        return apply_filters('wpinv_gateway_title', $this->gateway_title, $this->ID, $this);
1521 1521
     }
1522 1522
     
1523 1523
     public function get_currency() {
1524
-        return apply_filters( 'wpinv_currency_code', $this->currency, $this->ID, $this );
1524
+        return apply_filters('wpinv_currency_code', $this->currency, $this->ID, $this);
1525 1525
     }
1526 1526
     
1527 1527
     public function get_created_date() {
1528
-        return apply_filters( 'wpinv_created_date', $this->date, $this->ID, $this );
1528
+        return apply_filters('wpinv_created_date', $this->date, $this->ID, $this);
1529 1529
     }
1530 1530
     
1531
-    public function get_due_date( $display = false ) {
1532
-        $due_date = apply_filters( 'wpinv_due_date', $this->due_date, $this->ID, $this );
1531
+    public function get_due_date($display = false) {
1532
+        $due_date = apply_filters('wpinv_due_date', $this->due_date, $this->ID, $this);
1533 1533
         
1534
-        if ( !$display || empty( $due_date ) ) {
1534
+        if (!$display || empty($due_date)) {
1535 1535
             return $due_date;
1536 1536
         }
1537 1537
         
1538
-        return date_i18n( get_option( 'date_format' ), strtotime( $due_date ) );
1538
+        return date_i18n(get_option('date_format'), strtotime($due_date));
1539 1539
     }
1540 1540
     
1541 1541
     public function get_completed_date() {
1542
-        return apply_filters( 'wpinv_completed_date', $this->completed_date, $this->ID, $this );
1542
+        return apply_filters('wpinv_completed_date', $this->completed_date, $this->ID, $this);
1543 1543
     }
1544 1544
     
1545
-    public function get_invoice_date( $formatted = true ) {
1545
+    public function get_invoice_date($formatted = true) {
1546 1546
         $date_completed = $this->completed_date;
1547 1547
         $invoice_date   = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? $date_completed : '';
1548 1548
         
1549
-        if ( $invoice_date == '' ) {
1549
+        if ($invoice_date == '') {
1550 1550
             $date_created   = $this->date;
1551 1551
             $invoice_date   = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? $date_created : '';
1552 1552
         }
1553 1553
         
1554
-        if ( $formatted && $invoice_date ) {
1555
-            $invoice_date   = date_i18n( get_option( 'date_format' ), strtotime( $invoice_date ) );
1554
+        if ($formatted && $invoice_date) {
1555
+            $invoice_date = date_i18n(get_option('date_format'), strtotime($invoice_date));
1556 1556
         }
1557 1557
 
1558
-        return apply_filters( 'wpinv_get_invoice_date', $invoice_date, $formatted, $this->ID, $this );
1558
+        return apply_filters('wpinv_get_invoice_date', $invoice_date, $formatted, $this->ID, $this);
1559 1559
     }
1560 1560
     
1561 1561
     public function get_ip() {
1562
-        return apply_filters( 'wpinv_user_ip', $this->ip, $this->ID, $this );
1562
+        return apply_filters('wpinv_user_ip', $this->ip, $this->ID, $this);
1563 1563
     }
1564 1564
         
1565
-    public function has_status( $status ) {
1566
-        return apply_filters( 'wpinv_has_status', ( is_array( $status ) && in_array( $this->get_status(), $status ) ) || $this->get_status() === $status ? true : false, $this, $status );
1565
+    public function has_status($status) {
1566
+        return apply_filters('wpinv_has_status', (is_array($status) && in_array($this->get_status(), $status)) || $this->get_status() === $status ? true : false, $this, $status);
1567 1567
     }
1568 1568
     
1569
-    public function add_item( $item_id = 0, $args = array() ) {
1569
+    public function add_item($item_id = 0, $args = array()) {
1570 1570
         global $wpi_current_id, $wpi_item_id;
1571 1571
         
1572
-        $item = new WPInv_Item( $item_id );
1572
+        $item = new WPInv_Item($item_id);
1573 1573
 
1574 1574
         // Bail if this post isn't a item
1575
-        if( !$item || $item->post_type !== 'wpi_item' ) {
1575
+        if (!$item || $item->post_type !== 'wpi_item') {
1576 1576
             return false;
1577 1577
         }
1578 1578
         
@@ -1590,8 +1590,8 @@  discard block
 block discarded – undo
1590 1590
             'fees'      => array()
1591 1591
         );
1592 1592
 
1593
-        $args = wp_parse_args( apply_filters( 'wpinv_add_item_args', $args, $item->ID ), $defaults );
1594
-        $args['quantity']   = $has_quantities && $args['quantity'] > 0 ? absint( $args['quantity'] ) : 1;
1593
+        $args = wp_parse_args(apply_filters('wpinv_add_item_args', $args, $item->ID), $defaults);
1594
+        $args['quantity'] = $has_quantities && $args['quantity'] > 0 ? absint($args['quantity']) : 1;
1595 1595
 
1596 1596
         $wpi_current_id         = $this->ID;
1597 1597
         $wpi_item_id            = $item->ID;
@@ -1601,20 +1601,20 @@  discard block
 block discarded – undo
1601 1601
         $_POST['wpinv_state']   = $this->state;
1602 1602
         
1603 1603
         if ($has_quantities) {
1604
-            $this->cart_details = !empty( $this->cart_details ) ? array_values( $this->cart_details ) : $this->cart_details;
1604
+            $this->cart_details = !empty($this->cart_details) ? array_values($this->cart_details) : $this->cart_details;
1605 1605
             
1606
-            foreach ( $this->items as $key => $cart_item ) {
1607
-                if ( (int)$item_id !== (int)$cart_item['id'] ) {
1606
+            foreach ($this->items as $key => $cart_item) {
1607
+                if ((int)$item_id !== (int)$cart_item['id']) {
1608 1608
                     continue;
1609 1609
                 }
1610 1610
 
1611
-                $this->items[ $key ]['quantity'] += $args['quantity'];
1611
+                $this->items[$key]['quantity'] += $args['quantity'];
1612 1612
                 break;
1613 1613
             }
1614 1614
             
1615 1615
             $found_cart_key = false;
1616
-            foreach ( $this->cart_details as $cart_key => $cart_item ) {
1617
-                if ( $item_id != $cart_item['id'] ) {
1616
+            foreach ($this->cart_details as $cart_key => $cart_item) {
1617
+                if ($item_id != $cart_item['id']) {
1618 1618
                     continue;
1619 1619
                 }
1620 1620
 
@@ -1626,29 +1626,29 @@  discard block
 block discarded – undo
1626 1626
         if ($has_quantities && $found_cart_key !== false) {
1627 1627
             $cart_item          = $this->cart_details[$found_cart_key];
1628 1628
             $item_price         = $cart_item['item_price'];
1629
-            $quantity           = !empty( $cart_item['quantity'] ) ? $cart_item['quantity'] : 1;
1630
-            $tax_rate           = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : 0;
1629
+            $quantity           = !empty($cart_item['quantity']) ? $cart_item['quantity'] : 1;
1630
+            $tax_rate           = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : 0;
1631 1631
             
1632 1632
             $new_quantity       = $quantity + $args['quantity'];
1633 1633
             $subtotal           = $item_price * $new_quantity;
1634 1634
             
1635 1635
             $args['quantity']   = $new_quantity;
1636
-            $discount           = !empty( $args['discount'] ) ? $args['discount'] : 0;
1637
-            $tax                = $subtotal > 0 && $tax_rate > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0;
1636
+            $discount           = !empty($args['discount']) ? $args['discount'] : 0;
1637
+            $tax                = $subtotal > 0 && $tax_rate > 0 ? (($subtotal - $discount) * 0.01 * (float)$tax_rate) : 0;
1638 1638
             
1639 1639
             $discount_increased = $discount > 0 && $subtotal > 0 && $discount > (float)$cart_item['discount'] ? $discount - (float)$cart_item['discount'] : 0;
1640 1640
             $tax_increased      = $tax > 0 && $subtotal > 0 && $tax > (float)$cart_item['tax'] ? $tax - (float)$cart_item['tax'] : 0;
1641 1641
             // The total increase equals the number removed * the item_price
1642
-            $total_increased    = wpinv_format_amount( $item_price, NULL, true );
1642
+            $total_increased    = wpinv_format_amount($item_price, NULL, true);
1643 1643
             
1644
-            if ( wpinv_prices_include_tax() ) {
1645
-                $subtotal -= wpinv_format_amount( $tax, NULL, true );
1644
+            if (wpinv_prices_include_tax()) {
1645
+                $subtotal -= wpinv_format_amount($tax, NULL, true);
1646 1646
             }
1647 1647
 
1648
-            $total              = $subtotal - $discount + $tax;
1648
+            $total = $subtotal - $discount + $tax;
1649 1649
 
1650 1650
             // Do not allow totals to go negative
1651
-            if( $total < 0 ) {
1651
+            if ($total < 0) {
1652 1652
                 $total = 0;
1653 1653
             }
1654 1654
             
@@ -1664,20 +1664,20 @@  discard block
 block discarded – undo
1664 1664
             $this->cart_details[$found_cart_key] = $cart_item;
1665 1665
         } else {
1666 1666
             // Allow overriding the price
1667
-            if( false !== $args['item_price'] ) {
1667
+            if (false !== $args['item_price']) {
1668 1668
                 $item_price = $args['item_price'];
1669 1669
             } else {
1670
-                $item_price = wpinv_get_item_price( $item->ID );
1670
+                $item_price = wpinv_get_item_price($item->ID);
1671 1671
             }
1672 1672
 
1673 1673
             // Sanitizing the price here so we don't have a dozen calls later
1674
-            $item_price = wpinv_sanitize_amount( $item_price );
1675
-            $subtotal   = wpinv_format_amount( $item_price * $args['quantity'], NULL, true );
1674
+            $item_price = wpinv_sanitize_amount($item_price);
1675
+            $subtotal   = wpinv_format_amount($item_price * $args['quantity'], NULL, true);
1676 1676
         
1677
-            $discount   = !empty( $args['discount'] ) ? $args['discount'] : 0;
1678
-            $tax_class  = !empty( $args['vat_class'] ) ? $args['vat_class'] : '';
1679
-            $tax_rate   = !empty( $args['vat_rate'] ) ? $args['vat_rate'] : 0;
1680
-            $tax        = $subtotal > 0 && $tax_rate > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0;
1677
+            $discount   = !empty($args['discount']) ? $args['discount'] : 0;
1678
+            $tax_class  = !empty($args['vat_class']) ? $args['vat_class'] : '';
1679
+            $tax_rate   = !empty($args['vat_rate']) ? $args['vat_rate'] : 0;
1680
+            $tax        = $subtotal > 0 && $tax_rate > 0 ? (($subtotal - $discount) * 0.01 * (float)$tax_rate) : 0;
1681 1681
 
1682 1682
             // Setup the items meta item
1683 1683
             $new_item = array(
@@ -1685,28 +1685,28 @@  discard block
 block discarded – undo
1685 1685
                 'quantity' => $args['quantity'],
1686 1686
             );
1687 1687
 
1688
-            $this->items[]  = $new_item;
1688
+            $this->items[] = $new_item;
1689 1689
 
1690
-            if ( wpinv_prices_include_tax() ) {
1691
-                $subtotal -= wpinv_format_amount( $tax, NULL, true );
1690
+            if (wpinv_prices_include_tax()) {
1691
+                $subtotal -= wpinv_format_amount($tax, NULL, true);
1692 1692
             }
1693 1693
 
1694
-            $total      = $subtotal - $discount + $tax;
1694
+            $total = $subtotal - $discount + $tax;
1695 1695
 
1696 1696
             // Do not allow totals to go negative
1697
-            if( $total < 0 ) {
1697
+            if ($total < 0) {
1698 1698
                 $total = 0;
1699 1699
             }
1700 1700
         
1701 1701
             $this->cart_details[] = array(
1702 1702
                 'name'        => !empty($args['name']) ? $args['name'] : $item->get_name(),
1703 1703
                 'id'          => $item->ID,
1704
-                'item_price'  => wpinv_format_amount( $item_price, NULL, true ),
1704
+                'item_price'  => wpinv_format_amount($item_price, NULL, true),
1705 1705
                 'quantity'    => $args['quantity'],
1706 1706
                 'discount'    => $discount,
1707
-                'subtotal'    => wpinv_format_amount( $subtotal, NULL, true ),
1708
-                'tax'         => wpinv_format_amount( $tax, NULL, true ),
1709
-                'price'       => wpinv_format_amount( $total, NULL, true ),
1707
+                'subtotal'    => wpinv_format_amount($subtotal, NULL, true),
1708
+                'tax'         => wpinv_format_amount($tax, NULL, true),
1709
+                'price'       => wpinv_format_amount($total, NULL, true),
1710 1710
                 'vat_rate'    => $tax_rate,
1711 1711
                 'vat_class'   => $tax_class,
1712 1712
                 'meta'        => $args['meta'],
@@ -1716,69 +1716,69 @@  discard block
 block discarded – undo
1716 1716
             $subtotal = $subtotal - $discount;
1717 1717
         }
1718 1718
         
1719
-        $added_item = end( $this->cart_details );
1720
-        $added_item['action']  = 'add';
1719
+        $added_item = end($this->cart_details);
1720
+        $added_item['action'] = 'add';
1721 1721
         
1722 1722
         $this->pending['items'][] = $added_item;
1723 1723
         
1724
-        $this->increase_subtotal( $subtotal );
1725
-        $this->increase_tax( $tax );
1724
+        $this->increase_subtotal($subtotal);
1725
+        $this->increase_tax($tax);
1726 1726
 
1727 1727
         return true;
1728 1728
     }
1729 1729
     
1730
-    public function remove_item( $item_id, $args = array() ) {
1730
+    public function remove_item($item_id, $args = array()) {
1731 1731
         // Set some defaults
1732 1732
         $defaults = array(
1733 1733
             'quantity'   => 1,
1734 1734
             'item_price' => false,
1735 1735
             'cart_index' => false,
1736 1736
         );
1737
-        $args = wp_parse_args( $args, $defaults );
1737
+        $args = wp_parse_args($args, $defaults);
1738 1738
 
1739 1739
         // Bail if this post isn't a item
1740
-        if ( get_post_type( $item_id ) !== 'wpi_item' ) {
1740
+        if (get_post_type($item_id) !== 'wpi_item') {
1741 1741
             return false;
1742 1742
         }
1743 1743
         
1744
-        $this->cart_details = !empty( $this->cart_details ) ? array_values( $this->cart_details ) : $this->cart_details;
1744
+        $this->cart_details = !empty($this->cart_details) ? array_values($this->cart_details) : $this->cart_details;
1745 1745
 
1746
-        foreach ( $this->items as $key => $item ) {
1747
-            if ( !empty($item['id']) && (int)$item_id !== (int)$item['id'] ) {
1746
+        foreach ($this->items as $key => $item) {
1747
+            if (!empty($item['id']) && (int)$item_id !== (int)$item['id']) {
1748 1748
                 continue;
1749 1749
             }
1750 1750
 
1751
-            if ( false !== $args['cart_index'] ) {
1752
-                $cart_index = absint( $args['cart_index'] );
1753
-                $cart_item  = ! empty( $this->cart_details[ $cart_index ] ) ? $this->cart_details[ $cart_index ] : false;
1751
+            if (false !== $args['cart_index']) {
1752
+                $cart_index = absint($args['cart_index']);
1753
+                $cart_item  = !empty($this->cart_details[$cart_index]) ? $this->cart_details[$cart_index] : false;
1754 1754
 
1755
-                if ( ! empty( $cart_item ) ) {
1755
+                if (!empty($cart_item)) {
1756 1756
                     // If the cart index item isn't the same item ID, don't remove it
1757
-                    if ( !empty($cart_item['id']) && $cart_item['id'] != $item['id'] ) {
1757
+                    if (!empty($cart_item['id']) && $cart_item['id'] != $item['id']) {
1758 1758
                         continue;
1759 1759
                     }
1760 1760
                 }
1761 1761
             }
1762 1762
 
1763
-            $item_quantity = $this->items[ $key ]['quantity'];
1764
-            if ( $item_quantity > $args['quantity'] ) {
1765
-                $this->items[ $key ]['quantity'] -= $args['quantity'];
1763
+            $item_quantity = $this->items[$key]['quantity'];
1764
+            if ($item_quantity > $args['quantity']) {
1765
+                $this->items[$key]['quantity'] -= $args['quantity'];
1766 1766
                 break;
1767 1767
             } else {
1768
-                unset( $this->items[ $key ] );
1768
+                unset($this->items[$key]);
1769 1769
                 break;
1770 1770
             }
1771 1771
         }
1772 1772
 
1773 1773
         $found_cart_key = false;
1774
-        if ( false === $args['cart_index'] ) {
1775
-            foreach ( $this->cart_details as $cart_key => $item ) {
1776
-                if ( $item_id != $item['id'] ) {
1774
+        if (false === $args['cart_index']) {
1775
+            foreach ($this->cart_details as $cart_key => $item) {
1776
+                if ($item_id != $item['id']) {
1777 1777
                     continue;
1778 1778
                 }
1779 1779
 
1780
-                if ( false !== $args['item_price'] ) {
1781
-                    if ( isset( $item['item_price'] ) && (float) $args['item_price'] != (float) $item['item_price'] ) {
1780
+                if (false !== $args['item_price']) {
1781
+                    if (isset($item['item_price']) && (float)$args['item_price'] != (float)$item['item_price']) {
1782 1782
                         continue;
1783 1783
                     }
1784 1784
                 }
@@ -1787,13 +1787,13 @@  discard block
 block discarded – undo
1787 1787
                 break;
1788 1788
             }
1789 1789
         } else {
1790
-            $cart_index = absint( $args['cart_index'] );
1790
+            $cart_index = absint($args['cart_index']);
1791 1791
 
1792
-            if ( ! array_key_exists( $cart_index, $this->cart_details ) ) {
1792
+            if (!array_key_exists($cart_index, $this->cart_details)) {
1793 1793
                 return false; // Invalid cart index passed.
1794 1794
             }
1795 1795
 
1796
-            if ( (int) $this->cart_details[ $cart_index ]['id'] > 0 && (int) $this->cart_details[ $cart_index ]['id'] !== (int) $item_id ) {
1796
+            if ((int)$this->cart_details[$cart_index]['id'] > 0 && (int)$this->cart_details[$cart_index]['id'] !== (int)$item_id) {
1797 1797
                 return false; // We still need the proper Item ID to be sure.
1798 1798
             }
1799 1799
 
@@ -1801,41 +1801,41 @@  discard block
 block discarded – undo
1801 1801
         }
1802 1802
         
1803 1803
         $cart_item  = $this->cart_details[$found_cart_key];
1804
-        $quantity   = !empty( $cart_item['quantity'] ) ? $cart_item['quantity'] : 1;
1804
+        $quantity   = !empty($cart_item['quantity']) ? $cart_item['quantity'] : 1;
1805 1805
         
1806
-        if ( count( $this->cart_details ) == 1 && ( $quantity - $args['quantity'] ) < 1 ) {
1806
+        if (count($this->cart_details) == 1 && ($quantity - $args['quantity']) < 1) {
1807 1807
             return false; // Invoice must contain at least one item.
1808 1808
         }
1809 1809
         
1810
-        $discounts  = $this->get_discounts();
1810
+        $discounts = $this->get_discounts();
1811 1811
         
1812
-        if ( $quantity > $args['quantity'] ) {
1812
+        if ($quantity > $args['quantity']) {
1813 1813
             $item_price         = $cart_item['item_price'];
1814
-            $tax_rate           = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : 0;
1814
+            $tax_rate           = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : 0;
1815 1815
             
1816
-            $new_quantity       = max( $quantity - $args['quantity'], 1);
1816
+            $new_quantity       = max($quantity - $args['quantity'], 1);
1817 1817
             $subtotal           = $item_price * $new_quantity;
1818 1818
             
1819 1819
             $args['quantity']   = $new_quantity;
1820
-            $discount           = !empty( $cart_item['discount'] ) ? $cart_item['discount'] : 0;
1821
-            $tax                = $subtotal > 0 && $tax_rate > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0;
1820
+            $discount           = !empty($cart_item['discount']) ? $cart_item['discount'] : 0;
1821
+            $tax                = $subtotal > 0 && $tax_rate > 0 ? (($subtotal - $discount) * 0.01 * (float)$tax_rate) : 0;
1822 1822
             
1823
-            $discount_decrease  = (float)$cart_item['discount'] > 0 && $quantity > 0 ? wpinv_format_amount( ( (float)$cart_item['discount'] / $quantity ), NULL, true ) : 0;
1823
+            $discount_decrease  = (float)$cart_item['discount'] > 0 && $quantity > 0 ? wpinv_format_amount(((float)$cart_item['discount'] / $quantity), NULL, true) : 0;
1824 1824
             $discount_decrease  = $discount > 0 && $subtotal > 0 && (float)$cart_item['discount'] > $discount ? (float)$cart_item['discount'] - $discount : $discount_decrease; 
1825
-            $tax_decrease       = (float)$cart_item['tax'] > 0 && $quantity > 0 ? wpinv_format_amount( ( (float)$cart_item['tax'] / $quantity ), NULL, true ) : 0;
1825
+            $tax_decrease       = (float)$cart_item['tax'] > 0 && $quantity > 0 ? wpinv_format_amount(((float)$cart_item['tax'] / $quantity), NULL, true) : 0;
1826 1826
             $tax_decrease       = $tax > 0 && $subtotal > 0 && (float)$cart_item['tax'] > $tax ? (float)$cart_item['tax'] - $tax : $tax_decrease;
1827 1827
             
1828 1828
             // The total increase equals the number removed * the item_price
1829
-            $total_decrease     = wpinv_format_amount( $item_price, NULL, true );
1829
+            $total_decrease     = wpinv_format_amount($item_price, NULL, true);
1830 1830
             
1831
-            if ( wpinv_prices_include_tax() ) {
1832
-                $subtotal -= wpinv_format_amount( $tax, NULL, true );
1831
+            if (wpinv_prices_include_tax()) {
1832
+                $subtotal -= wpinv_format_amount($tax, NULL, true);
1833 1833
             }
1834 1834
 
1835
-            $total              = $subtotal - $discount + $tax;
1835
+            $total = $subtotal - $discount + $tax;
1836 1836
 
1837 1837
             // Do not allow totals to go negative
1838
-            if( $total < 0 ) {
1838
+            if ($total < 0) {
1839 1839
                 $total = 0;
1840 1840
             }
1841 1841
             
@@ -1854,16 +1854,16 @@  discard block
 block discarded – undo
1854 1854
             
1855 1855
             $this->cart_details[$found_cart_key] = $cart_item;
1856 1856
             
1857
-            $remove_item = end( $this->cart_details );
1857
+            $remove_item = end($this->cart_details);
1858 1858
         } else {
1859 1859
             $item_price     = $cart_item['item_price'];
1860
-            $discount       = !empty( $cart_item['discount'] ) ? $cart_item['discount'] : 0;
1861
-            $tax            = !empty( $cart_item['tax'] ) ? $cart_item['tax'] : 0;
1860
+            $discount       = !empty($cart_item['discount']) ? $cart_item['discount'] : 0;
1861
+            $tax            = !empty($cart_item['tax']) ? $cart_item['tax'] : 0;
1862 1862
         
1863
-            $subtotal_decrease  = ( $item_price * $quantity ) - $discount;
1863
+            $subtotal_decrease  = ($item_price * $quantity) - $discount;
1864 1864
             $tax_decrease       = $tax;
1865 1865
 
1866
-            unset( $this->cart_details[$found_cart_key] );
1866
+            unset($this->cart_details[$found_cart_key]);
1867 1867
             
1868 1868
             $remove_item             = $args;
1869 1869
             $remove_item['id']       = $item_id;
@@ -1874,8 +1874,8 @@  discard block
 block discarded – undo
1874 1874
         $remove_item['action']      = 'remove';
1875 1875
         $this->pending['items'][]   = $remove_item;
1876 1876
                
1877
-        $this->decrease_subtotal( $subtotal_decrease );
1878
-        $this->decrease_tax( $tax_decrease );
1877
+        $this->decrease_subtotal($subtotal_decrease);
1878
+        $this->decrease_tax($tax_decrease);
1879 1879
         
1880 1880
         return true;
1881 1881
     }
@@ -1883,7 +1883,7 @@  discard block
 block discarded – undo
1883 1883
     public function update_items($temp = false) {
1884 1884
         global $wpinv_euvat, $wpi_current_id, $wpi_item_id, $wpi_nosave;
1885 1885
         
1886
-        if ( !empty( $this->cart_details ) ) {
1886
+        if (!empty($this->cart_details)) {
1887 1887
             $wpi_nosave             = $temp;
1888 1888
             $cart_subtotal          = 0;
1889 1889
             $cart_discount          = 0;
@@ -1893,41 +1893,41 @@  discard block
 block discarded – undo
1893 1893
             $_POST['wpinv_country'] = $this->country;
1894 1894
             $_POST['wpinv_state']   = $this->state;
1895 1895
             
1896
-            foreach ( $this->cart_details as $key => $item ) {
1896
+            foreach ($this->cart_details as $key => $item) {
1897 1897
                 $item_price = $item['item_price'];
1898
-                $quantity   = wpinv_item_quantities_enabled() && $item['quantity'] > 0 ? absint( $item['quantity'] ) : 1;
1899
-                $amount     = wpinv_format_amount( $item_price * $quantity, NULL, true );
1898
+                $quantity   = wpinv_item_quantities_enabled() && $item['quantity'] > 0 ? absint($item['quantity']) : 1;
1899
+                $amount     = wpinv_format_amount($item_price * $quantity, NULL, true);
1900 1900
                 $subtotal   = $item_price * $quantity;
1901 1901
                 
1902 1902
                 $wpi_current_id         = $this->ID;
1903 1903
                 $wpi_item_id            = $item['id'];
1904 1904
                 
1905
-                $discount   = wpinv_get_cart_item_discount_amount( $item, $this->get_discounts() );
1905
+                $discount   = wpinv_get_cart_item_discount_amount($item, $this->get_discounts());
1906 1906
                 
1907
-                $tax_rate   = wpinv_get_tax_rate( $this->country, $this->state, $wpi_item_id );
1908
-                $tax_class  = $wpinv_euvat->get_item_class( $wpi_item_id );
1909
-                $tax        = $item_price > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0;
1907
+                $tax_rate   = wpinv_get_tax_rate($this->country, $this->state, $wpi_item_id);
1908
+                $tax_class  = $wpinv_euvat->get_item_class($wpi_item_id);
1909
+                $tax        = $item_price > 0 ? (($subtotal - $discount) * 0.01 * (float)$tax_rate) : 0;
1910 1910
 
1911
-                if ( wpinv_prices_include_tax() ) {
1912
-                    $subtotal -= wpinv_format_amount( $tax, NULL, true );
1911
+                if (wpinv_prices_include_tax()) {
1912
+                    $subtotal -= wpinv_format_amount($tax, NULL, true);
1913 1913
                 }
1914 1914
 
1915
-                $total      = $subtotal - $discount + $tax;
1915
+                $total = $subtotal - $discount + $tax;
1916 1916
 
1917 1917
                 // Do not allow totals to go negative
1918
-                if( $total < 0 ) {
1918
+                if ($total < 0) {
1919 1919
                     $total = 0;
1920 1920
                 }
1921 1921
 
1922 1922
                 $cart_details[] = array(
1923 1923
                     'id'          => $item['id'],
1924 1924
                     'name'        => $item['name'],
1925
-                    'item_price'  => wpinv_format_amount( $item_price, NULL, true ),
1925
+                    'item_price'  => wpinv_format_amount($item_price, NULL, true),
1926 1926
                     'quantity'    => $quantity,
1927 1927
                     'discount'    => $discount,
1928
-                    'subtotal'    => wpinv_format_amount( $subtotal, NULL, true ),
1929
-                    'tax'         => wpinv_format_amount( $tax, NULL, true ),
1930
-                    'price'       => wpinv_format_amount( $total, NULL, true ),
1928
+                    'subtotal'    => wpinv_format_amount($subtotal, NULL, true),
1929
+                    'tax'         => wpinv_format_amount($tax, NULL, true),
1930
+                    'price'       => wpinv_format_amount($total, NULL, true),
1931 1931
                     'vat_rate'    => $tax_rate,
1932 1932
                     'vat_class'   => $tax_class,
1933 1933
                     'meta'        => isset($item['meta']) ? $item['meta'] : array(),
@@ -1938,9 +1938,9 @@  discard block
 block discarded – undo
1938 1938
                 $cart_discount  += (float)($discount);
1939 1939
                 $cart_tax       += (float)($tax);
1940 1940
             }
1941
-            $this->subtotal = wpinv_format_amount( $cart_subtotal, NULL, true );
1942
-            $this->tax      = wpinv_format_amount( $cart_tax, NULL, true );
1943
-            $this->discount = wpinv_format_amount( $cart_discount, NULL, true );
1941
+            $this->subtotal = wpinv_format_amount($cart_subtotal, NULL, true);
1942
+            $this->tax      = wpinv_format_amount($cart_tax, NULL, true);
1943
+            $this->discount = wpinv_format_amount($cart_discount, NULL, true);
1944 1944
             
1945 1945
             $this->recalculate_total();
1946 1946
             
@@ -1952,221 +1952,221 @@  discard block
 block discarded – undo
1952 1952
     
1953 1953
     public function recalculate_totals($temp = false) {        
1954 1954
         $this->update_items($temp);
1955
-        $this->save( true );
1955
+        $this->save(true);
1956 1956
         
1957 1957
         return $this;
1958 1958
     }
1959 1959
     
1960 1960
     public function needs_payment() {
1961
-        $valid_invoice_statuses = apply_filters( 'wpinv_valid_invoice_statuses_for_payment', array( 'pending' ), $this );
1961
+        $valid_invoice_statuses = apply_filters('wpinv_valid_invoice_statuses_for_payment', array('pending'), $this);
1962 1962
 
1963
-        if ( $this->has_status( $valid_invoice_statuses ) && ( $this->get_total() > 0 || $this->is_free_trial() ) ) {
1963
+        if ($this->has_status($valid_invoice_statuses) && ($this->get_total() > 0 || $this->is_free_trial())) {
1964 1964
             $needs_payment = true;
1965 1965
         } else {
1966 1966
             $needs_payment = false;
1967 1967
         }
1968 1968
 
1969
-        return apply_filters( 'wpinv_needs_payment', $needs_payment, $this, $valid_invoice_statuses );
1969
+        return apply_filters('wpinv_needs_payment', $needs_payment, $this, $valid_invoice_statuses);
1970 1970
     }
1971 1971
     
1972
-    public function get_checkout_payment_url( $on_checkout = false, $secret = false ) {
1972
+    public function get_checkout_payment_url($on_checkout = false, $secret = false) {
1973 1973
         $pay_url = wpinv_get_checkout_uri();
1974 1974
 
1975
-        if ( is_ssl() ) {
1976
-            $pay_url = str_replace( 'http:', 'https:', $pay_url );
1975
+        if (is_ssl()) {
1976
+            $pay_url = str_replace('http:', 'https:', $pay_url);
1977 1977
         }
1978 1978
         
1979 1979
         $key = $this->get_key();
1980 1980
 
1981
-        if ( $on_checkout ) {
1982
-            $pay_url = add_query_arg( 'invoice_key', $key, $pay_url );
1981
+        if ($on_checkout) {
1982
+            $pay_url = add_query_arg('invoice_key', $key, $pay_url);
1983 1983
         } else {
1984
-            $pay_url = add_query_arg( array( 'wpi_action' => 'pay_for_invoice', 'invoice_key' => $key ), $pay_url );
1984
+            $pay_url = add_query_arg(array('wpi_action' => 'pay_for_invoice', 'invoice_key' => $key), $pay_url);
1985 1985
         }
1986 1986
         
1987
-        if ( $secret ) {
1988
-            $pay_url = add_query_arg( array( '_wpipay' => md5( $this->get_user_id() . '::' . $this->get_email() . '::' . $key ) ), $pay_url );
1987
+        if ($secret) {
1988
+            $pay_url = add_query_arg(array('_wpipay' => md5($this->get_user_id() . '::' . $this->get_email() . '::' . $key)), $pay_url);
1989 1989
         }
1990 1990
 
1991
-        return apply_filters( 'wpinv_get_checkout_payment_url', $pay_url, $this );
1991
+        return apply_filters('wpinv_get_checkout_payment_url', $pay_url, $this);
1992 1992
     }
1993 1993
     
1994
-    public function get_view_url( $secret = false ) {
1995
-        $print_url = get_permalink( $this->ID );
1994
+    public function get_view_url($secret = false) {
1995
+        $print_url = get_permalink($this->ID);
1996 1996
         
1997
-        if ( $secret ) {
1998
-            $print_url = add_query_arg( array( '_wpipay' => md5( $this->get_user_id() . '::' . $this->get_email() . '::' . $this->get_key() ) ), $print_url );
1997
+        if ($secret) {
1998
+            $print_url = add_query_arg(array('_wpipay' => md5($this->get_user_id() . '::' . $this->get_email() . '::' . $this->get_key())), $print_url);
1999 1999
         }
2000 2000
 
2001
-        return apply_filters( 'wpinv_get_view_url', $print_url, $this );
2001
+        return apply_filters('wpinv_get_view_url', $print_url, $this);
2002 2002
     }
2003 2003
     
2004
-    public function generate_key( $string = '' ) {
2005
-        $auth_key  = defined( 'AUTH_KEY' ) ? AUTH_KEY : '';
2006
-        return strtolower( md5( $string . date( 'Y-m-d H:i:s' ) . $auth_key . uniqid( 'wpinv', true ) ) );  // Unique key
2004
+    public function generate_key($string = '') {
2005
+        $auth_key = defined('AUTH_KEY') ? AUTH_KEY : '';
2006
+        return strtolower(md5($string . date('Y-m-d H:i:s') . $auth_key . uniqid('wpinv', true))); // Unique key
2007 2007
     }
2008 2008
     
2009 2009
     public function is_recurring() {
2010
-        if ( empty( $this->cart_details ) ) {
2010
+        if (empty($this->cart_details)) {
2011 2011
             return false;
2012 2012
         }
2013 2013
         
2014 2014
         $has_subscription = false;
2015
-        foreach( $this->cart_details as $cart_item ) {
2016
-            if ( !empty( $cart_item['id'] ) && wpinv_is_recurring_item( $cart_item['id'] )  ) {
2015
+        foreach ($this->cart_details as $cart_item) {
2016
+            if (!empty($cart_item['id']) && wpinv_is_recurring_item($cart_item['id'])) {
2017 2017
                 $has_subscription = true;
2018 2018
                 break;
2019 2019
             }
2020 2020
         }
2021 2021
         
2022
-        if ( count( $this->cart_details ) > 1 ) {
2022
+        if (count($this->cart_details) > 1) {
2023 2023
             $has_subscription = false;
2024 2024
         }
2025 2025
 
2026
-        return apply_filters( 'wpinv_invoice_has_recurring_item', $has_subscription, $this->cart_details );
2026
+        return apply_filters('wpinv_invoice_has_recurring_item', $has_subscription, $this->cart_details);
2027 2027
     }
2028 2028
     
2029 2029
     public function is_free_trial() {
2030 2030
         $is_free_trial = false;
2031 2031
         
2032
-        if ( $this->is_parent() && $item = $this->get_recurring( true ) ) {
2033
-            if ( !empty( $item ) && $item->has_free_trial() ) {
2032
+        if ($this->is_parent() && $item = $this->get_recurring(true)) {
2033
+            if (!empty($item) && $item->has_free_trial()) {
2034 2034
                 $is_free_trial = true;
2035 2035
             }
2036 2036
         }
2037 2037
 
2038
-        return apply_filters( 'wpinv_invoice_is_free_trial', $is_free_trial, $this->cart_details );
2038
+        return apply_filters('wpinv_invoice_is_free_trial', $is_free_trial, $this->cart_details);
2039 2039
     }
2040 2040
     
2041
-    public function get_recurring( $object = false ) {
2041
+    public function get_recurring($object = false) {
2042 2042
         $item = NULL;
2043 2043
         
2044
-        if ( empty( $this->cart_details ) ) {
2044
+        if (empty($this->cart_details)) {
2045 2045
             return $item;
2046 2046
         }
2047 2047
         
2048
-        foreach( $this->cart_details as $cart_item ) {
2049
-            if ( !empty( $cart_item['id'] ) && wpinv_is_recurring_item( $cart_item['id'] )  ) {
2048
+        foreach ($this->cart_details as $cart_item) {
2049
+            if (!empty($cart_item['id']) && wpinv_is_recurring_item($cart_item['id'])) {
2050 2050
                 $item = $cart_item['id'];
2051 2051
                 break;
2052 2052
             }
2053 2053
         }
2054 2054
         
2055
-        if ( $object ) {
2056
-            $item = $item ? new WPInv_Item( $item ) : NULL;
2055
+        if ($object) {
2056
+            $item = $item ? new WPInv_Item($item) : NULL;
2057 2057
             
2058
-            apply_filters( 'wpinv_invoice_get_recurring_item', $item, $this );
2058
+            apply_filters('wpinv_invoice_get_recurring_item', $item, $this);
2059 2059
         }
2060 2060
 
2061
-        return apply_filters( 'wpinv_invoice_get_recurring_item_id', $item, $this );
2061
+        return apply_filters('wpinv_invoice_get_recurring_item_id', $item, $this);
2062 2062
     }
2063 2063
     
2064 2064
     public function get_subscription_name() {
2065
-        $item = $this->get_recurring( true );
2065
+        $item = $this->get_recurring(true);
2066 2066
         
2067
-        if ( empty( $item ) ) {
2067
+        if (empty($item)) {
2068 2068
             return NULL;
2069 2069
         }
2070 2070
         
2071
-        if ( !($name = $item->get_name()) ) {
2071
+        if (!($name = $item->get_name())) {
2072 2072
             $name = $item->post_name;
2073 2073
         }
2074 2074
 
2075
-        return apply_filters( 'wpinv_invoice_get_subscription_name', $name, $this );
2075
+        return apply_filters('wpinv_invoice_get_subscription_name', $name, $this);
2076 2076
     }
2077 2077
         
2078 2078
     public function get_expiration() {
2079
-        $expiration = $this->get_meta( '_wpinv_subscr_expiration', true );
2079
+        $expiration = $this->get_meta('_wpinv_subscr_expiration', true);
2080 2080
         return $expiration;
2081 2081
     }
2082 2082
     
2083
-    public function get_cancelled_date( $formatted = true ) {
2084
-        $cancelled_date = $this->get_subscription_status() == 'cancelled' ? $this->get_meta( '_wpinv_subscr_cancelled_on', true ) : '';
2083
+    public function get_cancelled_date($formatted = true) {
2084
+        $cancelled_date = $this->get_subscription_status() == 'cancelled' ? $this->get_meta('_wpinv_subscr_cancelled_on', true) : '';
2085 2085
         
2086
-        if ( $formatted && $cancelled_date ) {
2087
-            $cancelled_date = date_i18n( get_option( 'date_format' ), strtotime( $cancelled_date ) );
2086
+        if ($formatted && $cancelled_date) {
2087
+            $cancelled_date = date_i18n(get_option('date_format'), strtotime($cancelled_date));
2088 2088
         }
2089 2089
         
2090 2090
         return $cancelled_date;
2091 2091
     }
2092 2092
     
2093
-    public function get_trial_end_date( $formatted = true ) {
2094
-        if ( !$this->is_free_trial() || !$this->is_paid() ) {
2093
+    public function get_trial_end_date($formatted = true) {
2094
+        if (!$this->is_free_trial() || !$this->is_paid()) {
2095 2095
             return NULL;
2096 2096
         }
2097 2097
         
2098
-        $trial_end_date = $this->get_subscription_status() == 'trialing' ? $this->get_meta( '_wpinv_subscr_trial_end', true ) : '';
2098
+        $trial_end_date = $this->get_subscription_status() == 'trialing' ? $this->get_meta('_wpinv_subscr_trial_end', true) : '';
2099 2099
         
2100
-        if ( empty( $trial_end_date ) ) {
2101
-            $trial_start_time = strtotime( $this->get_subscription_start() );
2102
-            $trial_start_time += ( wpinv_period_in_days( $this->get_subscription_trial_interval(), $this->get_subscription_trial_period() ) * DAY_IN_SECONDS ) ;
2100
+        if (empty($trial_end_date)) {
2101
+            $trial_start_time = strtotime($this->get_subscription_start());
2102
+            $trial_start_time += (wpinv_period_in_days($this->get_subscription_trial_interval(), $this->get_subscription_trial_period()) * DAY_IN_SECONDS);
2103 2103
             
2104
-            $trial_end_date = date_i18n( 'Y-m-d H:i:s', $trial_start_time );
2104
+            $trial_end_date = date_i18n('Y-m-d H:i:s', $trial_start_time);
2105 2105
         }
2106 2106
         
2107
-        if ( $formatted && $trial_end_date ) {
2108
-            $trial_end_date = date_i18n( get_option( 'date_format' ), strtotime( $trial_end_date ) );
2107
+        if ($formatted && $trial_end_date) {
2108
+            $trial_end_date = date_i18n(get_option('date_format'), strtotime($trial_end_date));
2109 2109
         }
2110 2110
         
2111 2111
         return $trial_end_date;
2112 2112
     }
2113 2113
     
2114
-    public function get_subscription_created( $default = true ) {
2115
-        $created = $this->get_meta( '_wpinv_subscr_created', true );
2114
+    public function get_subscription_created($default = true) {
2115
+        $created = $this->get_meta('_wpinv_subscr_created', true);
2116 2116
         
2117
-        if ( empty( $created ) && $default ) {
2117
+        if (empty($created) && $default) {
2118 2118
             $created = $this->date;
2119 2119
         }
2120 2120
         return $created;
2121 2121
     }
2122 2122
     
2123
-    public function get_subscription_start( $formatted = true ) {
2124
-        if ( !$this->is_paid() ) {
2123
+    public function get_subscription_start($formatted = true) {
2124
+        if (!$this->is_paid()) {
2125 2125
             return '-';
2126 2126
         }
2127
-        $start   = $this->get_subscription_created();
2127
+        $start = $this->get_subscription_created();
2128 2128
         
2129
-        if ( $formatted ) {
2130
-            $date = date_i18n( get_option( 'date_format' ), strtotime( $start ) );
2129
+        if ($formatted) {
2130
+            $date = date_i18n(get_option('date_format'), strtotime($start));
2131 2131
         } else {
2132
-            $date = date_i18n( 'Y-m-d H:i:s', strtotime( $start ) );
2132
+            $date = date_i18n('Y-m-d H:i:s', strtotime($start));
2133 2133
         }
2134 2134
 
2135 2135
         return $date;
2136 2136
     }
2137 2137
     
2138
-    public function get_subscription_end( $formatted = true ) {
2139
-        if ( !$this->is_paid() ) {
2138
+    public function get_subscription_end($formatted = true) {
2139
+        if (!$this->is_paid()) {
2140 2140
             return '-';
2141 2141
         }
2142 2142
         $start          = $this->get_subscription_created();
2143 2143
         $interval       = $this->get_subscription_interval();
2144
-        $period         = $this->get_subscription_period( true );
2144
+        $period         = $this->get_subscription_period(true);
2145 2145
         $bill_times     = (int)$this->get_bill_times();
2146 2146
         
2147
-        if ( $bill_times == 0 ) {
2148
-            return $formatted ? __( 'Until cancelled', 'invoicing' ) : $bill_times;
2147
+        if ($bill_times == 0) {
2148
+            return $formatted ? __('Until cancelled', 'invoicing') : $bill_times;
2149 2149
         }
2150 2150
         
2151
-        $total_period = $start . '+' . ( $interval * $bill_times ) . ' ' . $period;
2151
+        $total_period = $start . '+' . ($interval * $bill_times) . ' ' . $period;
2152 2152
         
2153
-        $end_time = strtotime( $start . '+' . ( $interval * $bill_times ) . ' ' . $period );
2153
+        $end_time = strtotime($start . '+' . ($interval * $bill_times) . ' ' . $period);
2154 2154
         
2155
-        if ( $this->is_free_trial() ) {
2156
-            $end_time += ( wpinv_period_in_days( $this->get_subscription_trial_interval(), $this->get_subscription_trial_period() ) * DAY_IN_SECONDS ) ;
2155
+        if ($this->is_free_trial()) {
2156
+            $end_time += (wpinv_period_in_days($this->get_subscription_trial_interval(), $this->get_subscription_trial_period()) * DAY_IN_SECONDS);
2157 2157
         }
2158 2158
         
2159
-        if ( $formatted ) {
2160
-            $date = date_i18n( get_option( 'date_format' ), $end_time );
2159
+        if ($formatted) {
2160
+            $date = date_i18n(get_option('date_format'), $end_time);
2161 2161
         } else {
2162
-            $date = date_i18n( 'Y-m-d H:i:s', $end_time );
2162
+            $date = date_i18n('Y-m-d H:i:s', $end_time);
2163 2163
         }
2164 2164
 
2165 2165
         return $date;
2166 2166
     }
2167 2167
     
2168 2168
     public function get_expiration_time() {
2169
-        return strtotime( $this->get_expiration(), current_time( 'timestamp' ) );
2169
+        return strtotime($this->get_expiration(), current_time('timestamp'));
2170 2170
     }
2171 2171
     
2172 2172
     public function get_original_invoice_id() {        
@@ -2178,125 +2178,125 @@  discard block
 block discarded – undo
2178 2178
         return $subscription_data['bill_times'];
2179 2179
     }
2180 2180
 
2181
-    public function get_child_payments( $self = false ) {
2182
-        $invoices = get_posts( array(
2181
+    public function get_child_payments($self = false) {
2182
+        $invoices = get_posts(array(
2183 2183
             'post_type'         => 'wpi_invoice',
2184 2184
             'post_parent'       => (int)$this->ID,
2185 2185
             'posts_per_page'    => '999',
2186
-            'post_status'       => array( 'publish', 'complete', 'processing', 'renewal' ),
2186
+            'post_status'       => array('publish', 'complete', 'processing', 'renewal'),
2187 2187
             'orderby'           => 'ID',
2188 2188
             'order'             => 'DESC',
2189 2189
             'fields'            => 'ids'
2190
-        ) );
2190
+        ));
2191 2191
         
2192
-        if ( $this->is_free_trial() ) {
2192
+        if ($this->is_free_trial()) {
2193 2193
             $self = false;
2194 2194
         }
2195 2195
         
2196
-        if ( $self && $this->is_paid() ) {
2197
-            if ( !empty( $invoices ) ) {
2196
+        if ($self && $this->is_paid()) {
2197
+            if (!empty($invoices)) {
2198 2198
                 $invoices[] = (int)$this->ID;
2199 2199
             } else {
2200
-                $invoices = array( $this->ID );
2200
+                $invoices = array($this->ID);
2201 2201
             }
2202 2202
             
2203
-            $invoices = array_unique( $invoices );
2203
+            $invoices = array_unique($invoices);
2204 2204
         }
2205 2205
 
2206 2206
         return $invoices;
2207 2207
     }
2208 2208
 
2209
-    public function get_total_payments( $self = true ) {
2210
-        return count( $this->get_child_payments( $self ) );
2209
+    public function get_total_payments($self = true) {
2210
+        return count($this->get_child_payments($self));
2211 2211
     }
2212 2212
     
2213
-    public function get_subscriptions( $limit = -1 ) {
2214
-        $subscriptions = wpinv_get_subscriptions( array( 'parent_invoice_id' => $this->ID, 'numberposts' => $limit ) );
2213
+    public function get_subscriptions($limit = -1) {
2214
+        $subscriptions = wpinv_get_subscriptions(array('parent_invoice_id' => $this->ID, 'numberposts' => $limit));
2215 2215
 
2216 2216
         return $subscriptions;
2217 2217
     }
2218 2218
     
2219 2219
     public function get_subscription_id() {
2220
-        $subscription_id = $this->get_meta( '_wpinv_subscr_profile_id', true );
2220
+        $subscription_id = $this->get_meta('_wpinv_subscr_profile_id', true);
2221 2221
         
2222
-        if ( empty( $subscription_id ) && !empty( $this->parent_invoice ) ) {
2223
-            $parent_invoice = wpinv_get_invoice( $this->parent_invoice );
2222
+        if (empty($subscription_id) && !empty($this->parent_invoice)) {
2223
+            $parent_invoice = wpinv_get_invoice($this->parent_invoice);
2224 2224
             
2225
-            $subscription_id = $parent_invoice->get_meta( '_wpinv_subscr_profile_id', true );
2225
+            $subscription_id = $parent_invoice->get_meta('_wpinv_subscr_profile_id', true);
2226 2226
         }
2227 2227
         
2228 2228
         return $subscription_id;
2229 2229
     }
2230 2230
     
2231 2231
     public function get_subscription_status() {
2232
-        $subscription_status = $this->get_meta( '_wpinv_subscr_status', true );
2232
+        $subscription_status = $this->get_meta('_wpinv_subscr_status', true);
2233 2233
 
2234
-        if ( empty( $subscription_status ) ) {
2234
+        if (empty($subscription_status)) {
2235 2235
             $status = 'pending';
2236 2236
             
2237
-            if ( $this->is_paid() ) {        
2237
+            if ($this->is_paid()) {        
2238 2238
                 $bill_times   = (int)$this->get_bill_times();
2239 2239
                 $times_billed = (int)$this->get_total_payments();
2240
-                $expiration = $this->get_subscription_end( false );
2241
-                $expired = $bill_times != 0 && $expiration != '' && $expiration != '-' && strtotime( date_i18n( 'Y-m-d', strtotime( $expiration ) ) ) < strtotime( date_i18n( 'Y-m-d', current_time( 'timestamp' ) ) ) ? true : false;
2240
+                $expiration = $this->get_subscription_end(false);
2241
+                $expired = $bill_times != 0 && $expiration != '' && $expiration != '-' && strtotime(date_i18n('Y-m-d', strtotime($expiration))) < strtotime(date_i18n('Y-m-d', current_time('timestamp'))) ? true : false;
2242 2242
                 
2243
-                if ( (int)$bill_times == 0 ) {
2243
+                if ((int)$bill_times == 0) {
2244 2244
                     $status = $expired ? 'expired' : 'active';
2245
-                } else if ( $bill_times > 0 && $times_billed >= $bill_times ) {
2245
+                } else if ($bill_times > 0 && $times_billed >= $bill_times) {
2246 2246
                     $status = 'completed';
2247
-                } else if ( $expired ) {
2247
+                } else if ($expired) {
2248 2248
                     $status = 'expired';
2249
-                } else if ( $bill_times > 0 ) {
2249
+                } else if ($bill_times > 0) {
2250 2250
                     $status = 'active';
2251 2251
                 } else {
2252 2252
                     $status = 'pending';
2253 2253
                 }
2254 2254
             }
2255 2255
             
2256
-            if ( $status && $status != $subscription_status ) {
2256
+            if ($status && $status != $subscription_status) {
2257 2257
                 $subscription_status = $status;
2258 2258
                 
2259
-                $this->update_meta( '_wpinv_subscr_status', $status );
2259
+                $this->update_meta('_wpinv_subscr_status', $status);
2260 2260
             }
2261 2261
         }
2262 2262
         
2263 2263
         return $subscription_status;
2264 2264
     }
2265 2265
     
2266
-    public function get_subscription_status_label( $status = '' ) {
2267
-        $status = !empty( $status ) ? $status : $this->get_subscription_status();
2266
+    public function get_subscription_status_label($status = '') {
2267
+        $status = !empty($status) ? $status : $this->get_subscription_status();
2268 2268
 
2269
-        switch( $status ) {
2269
+        switch ($status) {
2270 2270
             case 'active' :
2271
-                $status_label = __( 'Active', 'invoicing' );
2271
+                $status_label = __('Active', 'invoicing');
2272 2272
                 break;
2273 2273
 
2274 2274
             case 'cancelled' :
2275
-                $status_label = __( 'Cancelled', 'invoicing' );
2275
+                $status_label = __('Cancelled', 'invoicing');
2276 2276
                 break;
2277 2277
                 
2278 2278
             case 'completed' :
2279
-                $status_label = __( 'Completed', 'invoicing' );
2279
+                $status_label = __('Completed', 'invoicing');
2280 2280
                 break;
2281 2281
 
2282 2282
             case 'expired' :
2283
-                $status_label = __( 'Expired', 'invoicing' );
2283
+                $status_label = __('Expired', 'invoicing');
2284 2284
                 break;
2285 2285
 
2286 2286
             case 'pending' :
2287
-                $status_label = __( 'Pending', 'invoicing' );
2287
+                $status_label = __('Pending', 'invoicing');
2288 2288
                 break;
2289 2289
 
2290 2290
             case 'failing' :
2291
-                $status_label = __( 'Failing', 'invoicing' );
2291
+                $status_label = __('Failing', 'invoicing');
2292 2292
                 break;
2293 2293
                 
2294 2294
             case 'stopped' :
2295
-                $status_label = __( 'Stopped', 'invoicing' );
2295
+                $status_label = __('Stopped', 'invoicing');
2296 2296
                 break;
2297 2297
                 
2298 2298
             case 'trialing' :
2299
-                $status_label = __( 'Trialing', 'invoicing' );
2299
+                $status_label = __('Trialing', 'invoicing');
2300 2300
                 break;
2301 2301
 
2302 2302
             default:
@@ -2307,15 +2307,15 @@  discard block
 block discarded – undo
2307 2307
         return $status_label;
2308 2308
     }
2309 2309
     
2310
-    public function get_subscription_period( $full = false ) {
2311
-        $period = $this->get_meta( '_wpinv_subscr_period', true );
2310
+    public function get_subscription_period($full = false) {
2311
+        $period = $this->get_meta('_wpinv_subscr_period', true);
2312 2312
         
2313
-        if ( !in_array( $period, array( 'D', 'W', 'M', 'Y' ) ) ) {
2313
+        if (!in_array($period, array('D', 'W', 'M', 'Y'))) {
2314 2314
             $period = 'D';
2315 2315
         }
2316 2316
         
2317
-        if ( $full ) {
2318
-            switch( $period ) {
2317
+        if ($full) {
2318
+            switch ($period) {
2319 2319
                 case 'D':
2320 2320
                     $period = 'day';
2321 2321
                 break;
@@ -2335,28 +2335,28 @@  discard block
 block discarded – undo
2335 2335
     }
2336 2336
     
2337 2337
     public function get_subscription_interval() {
2338
-        $interval = (int)$this->get_meta( '_wpinv_subscr_interval', true );
2338
+        $interval = (int)$this->get_meta('_wpinv_subscr_interval', true);
2339 2339
         
2340
-        if ( !$interval > 0 ) {
2340
+        if (!$interval > 0) {
2341 2341
             $interval = 1;
2342 2342
         }
2343 2343
         
2344 2344
         return $interval;
2345 2345
     }
2346 2346
     
2347
-    public function get_subscription_trial_period( $full = false ) {
2348
-        if ( !$this->is_free_trial() ) {
2347
+    public function get_subscription_trial_period($full = false) {
2348
+        if (!$this->is_free_trial()) {
2349 2349
             return '';
2350 2350
         }
2351 2351
         
2352
-        $period = $this->get_meta( '_wpinv_subscr_trial_period', true );
2352
+        $period = $this->get_meta('_wpinv_subscr_trial_period', true);
2353 2353
         
2354
-        if ( !in_array( $period, array( 'D', 'W', 'M', 'Y' ) ) ) {
2354
+        if (!in_array($period, array('D', 'W', 'M', 'Y'))) {
2355 2355
             $period = 'D';
2356 2356
         }
2357 2357
         
2358
-        if ( $full ) {
2359
-            switch( $period ) {
2358
+        if ($full) {
2359
+            switch ($period) {
2360 2360
                 case 'D':
2361 2361
                     $period = 'day';
2362 2362
                 break;
@@ -2376,13 +2376,13 @@  discard block
 block discarded – undo
2376 2376
     }
2377 2377
     
2378 2378
     public function get_subscription_trial_interval() {
2379
-        if ( !$this->is_free_trial() ) {
2379
+        if (!$this->is_free_trial()) {
2380 2380
             return 0;
2381 2381
         }
2382 2382
         
2383
-        $interval = (int)$this->get_meta( '_wpinv_subscr_trial_interval', true );
2383
+        $interval = (int)$this->get_meta('_wpinv_subscr_trial_interval', true);
2384 2384
         
2385
-        if ( !$interval > 0 ) {
2385
+        if (!$interval > 0) {
2386 2386
             $interval = 1;
2387 2387
         }
2388 2388
         
@@ -2394,8 +2394,8 @@  discard block
 block discarded – undo
2394 2394
             'status' => 'failing'
2395 2395
         );
2396 2396
 
2397
-        if ( $this->update_subscription( $args ) ) {
2398
-            do_action( 'wpinv_subscription_failing', $this->ID, $this );
2397
+        if ($this->update_subscription($args)) {
2398
+            do_action('wpinv_subscription_failing', $this->ID, $this);
2399 2399
             return true;
2400 2400
         }
2401 2401
 
@@ -2407,8 +2407,8 @@  discard block
 block discarded – undo
2407 2407
             'status' => 'stopped'
2408 2408
         );
2409 2409
 
2410
-        if ( $this->update_subscription( $args ) ) {
2411
-            do_action( 'wpinv_subscription_stopped', $this->ID, $this );
2410
+        if ($this->update_subscription($args)) {
2411
+            do_action('wpinv_subscription_stopped', $this->ID, $this);
2412 2412
             return true;
2413 2413
         }
2414 2414
 
@@ -2420,8 +2420,8 @@  discard block
 block discarded – undo
2420 2420
             'status' => 'active'
2421 2421
         );
2422 2422
 
2423
-        if ( $this->update_subscription( $args ) ) {
2424
-            do_action( 'wpinv_subscription_restarted', $this->ID, $this );
2423
+        if ($this->update_subscription($args)) {
2424
+            do_action('wpinv_subscription_restarted', $this->ID, $this);
2425 2425
             return true;
2426 2426
         }
2427 2427
 
@@ -2433,23 +2433,23 @@  discard block
 block discarded – undo
2433 2433
             'status' => 'cancelled'
2434 2434
         );
2435 2435
 
2436
-        if ( $this->update_subscription( $args ) ) {
2437
-            if ( is_user_logged_in() ) {
2438
-                $userdata = get_userdata( get_current_user_id() );
2436
+        if ($this->update_subscription($args)) {
2437
+            if (is_user_logged_in()) {
2438
+                $userdata = get_userdata(get_current_user_id());
2439 2439
                 $user     = $userdata->user_login;
2440 2440
             } else {
2441
-                $user = __( 'gateway', 'invoicing' );
2441
+                $user = __('gateway', 'invoicing');
2442 2442
             }
2443 2443
             
2444 2444
             $subscription_id = $this->get_subscription_id();
2445
-            if ( !$subscription_id ) {
2445
+            if (!$subscription_id) {
2446 2446
                 $subscription_id = $this->ID;
2447 2447
             }
2448 2448
 
2449
-            $note = sprintf( __( 'Subscription %s has been cancelled by %s', 'invoicing' ), $subscription_id, $user );
2450
-            $this->add_note( $note );
2449
+            $note = sprintf(__('Subscription %s has been cancelled by %s', 'invoicing'), $subscription_id, $user);
2450
+            $this->add_note($note);
2451 2451
 
2452
-            do_action( 'wpinv_subscription_cancelled', $this->ID, $this );
2452
+            do_action('wpinv_subscription_cancelled', $this->ID, $this);
2453 2453
             return true;
2454 2454
         }
2455 2455
 
@@ -2457,11 +2457,11 @@  discard block
 block discarded – undo
2457 2457
     }
2458 2458
 
2459 2459
     public function can_cancel() {
2460
-        return apply_filters( 'wpinv_subscription_can_cancel', false, $this );
2460
+        return apply_filters('wpinv_subscription_can_cancel', false, $this);
2461 2461
     }
2462 2462
     
2463
-    public function add_subscription( $data = array() ) {
2464
-        if ( empty( $this->ID ) ) {
2463
+    public function add_subscription($data = array()) {
2464
+        if (empty($this->ID)) {
2465 2465
             return false;
2466 2466
         }
2467 2467
 
@@ -2480,85 +2480,85 @@  discard block
 block discarded – undo
2480 2480
             'profile_id'        => '',
2481 2481
         );
2482 2482
 
2483
-        $args = wp_parse_args( $data, $defaults );
2483
+        $args = wp_parse_args($data, $defaults);
2484 2484
 
2485
-        if ( $args['expiration'] && strtotime( 'NOW', current_time( 'timestamp' ) ) > strtotime( $args['expiration'], current_time( 'timestamp' ) ) ) {
2486
-            if ( 'active' == $args['status'] || $args['status'] == 'trialing' ) {
2485
+        if ($args['expiration'] && strtotime('NOW', current_time('timestamp')) > strtotime($args['expiration'], current_time('timestamp'))) {
2486
+            if ('active' == $args['status'] || $args['status'] == 'trialing') {
2487 2487
                 $args['status'] = 'expired';
2488 2488
             }
2489 2489
         }
2490 2490
 
2491
-        do_action( 'wpinv_subscription_pre_create', $args, $data, $this );
2491
+        do_action('wpinv_subscription_pre_create', $args, $data, $this);
2492 2492
         
2493
-        if ( !empty( $args ) ) {
2494
-            foreach ( $args as $key => $value ) {
2495
-                $this->update_meta( '_wpinv_subscr_' . $key, $value );
2493
+        if (!empty($args)) {
2494
+            foreach ($args as $key => $value) {
2495
+                $this->update_meta('_wpinv_subscr_' . $key, $value);
2496 2496
             }
2497 2497
         }
2498 2498
 
2499
-        do_action( 'wpinv_subscription_post_create', $args, $data, $this );
2499
+        do_action('wpinv_subscription_post_create', $args, $data, $this);
2500 2500
 
2501 2501
         return true;
2502 2502
     }
2503 2503
     
2504
-    public function update_subscription( $args = array() ) {
2505
-        if ( empty( $this->ID ) ) {
2504
+    public function update_subscription($args = array()) {
2505
+        if (empty($this->ID)) {
2506 2506
             return false;
2507 2507
         }
2508 2508
 
2509
-        if ( !empty( $args['expiration'] ) && $args['expiration'] && strtotime( 'NOW', current_time( 'timestamp' ) ) > strtotime( $args['expiration'], current_time( 'timestamp' ) ) ) {
2510
-            if ( !isset( $args['status'] ) || ( isset( $args['status'] ) && ( 'active' == $args['status'] || $args['status'] == 'trialing' ) ) ) {
2509
+        if (!empty($args['expiration']) && $args['expiration'] && strtotime('NOW', current_time('timestamp')) > strtotime($args['expiration'], current_time('timestamp'))) {
2510
+            if (!isset($args['status']) || (isset($args['status']) && ('active' == $args['status'] || $args['status'] == 'trialing'))) {
2511 2511
                 $args['status'] = 'expired';
2512 2512
             }
2513 2513
         }
2514 2514
 
2515
-        if ( isset( $args['status'] ) && $args['status'] == 'cancelled' && empty( $args['cancelled_on'] ) ) {
2516
-            $args['cancelled_on'] = date_i18n( 'Y-m-d H:i:s', current_time( 'timestamp' ) );
2515
+        if (isset($args['status']) && $args['status'] == 'cancelled' && empty($args['cancelled_on'])) {
2516
+            $args['cancelled_on'] = date_i18n('Y-m-d H:i:s', current_time('timestamp'));
2517 2517
         }
2518 2518
 
2519
-        do_action( 'wpinv_subscription_pre_update', $args, $this );
2519
+        do_action('wpinv_subscription_pre_update', $args, $this);
2520 2520
         
2521
-        if ( !empty( $args ) ) {
2522
-            foreach ( $args as $key => $value ) {
2523
-                $this->update_meta( '_wpinv_subscr_' . $key, $value );
2521
+        if (!empty($args)) {
2522
+            foreach ($args as $key => $value) {
2523
+                $this->update_meta('_wpinv_subscr_' . $key, $value);
2524 2524
             }
2525 2525
         }
2526 2526
 
2527
-        do_action( 'wpinv_subscription_post_update', $args, $this );
2527
+        do_action('wpinv_subscription_post_update', $args, $this);
2528 2528
 
2529 2529
         return true;
2530 2530
     }
2531 2531
     
2532 2532
     public function renew_subscription() {
2533 2533
         $parent_invoice = $this->get_parent_payment();
2534
-        $parent_invoice = empty( $parent_invoice ) ? $this : $parent_invoice;
2534
+        $parent_invoice = empty($parent_invoice) ? $this : $parent_invoice;
2535 2535
         
2536
-        $current_time   = current_time( 'timestamp' );
2536
+        $current_time   = current_time('timestamp');
2537 2537
         $start          = $this->get_subscription_created();
2538
-        $start          = $start ? strtotime( $start ) : $current_time;
2538
+        $start          = $start ? strtotime($start) : $current_time;
2539 2539
         $expires        = $this->get_expiration_time();
2540 2540
         
2541
-        if ( !$expires ) {
2542
-            $expires    = strtotime( '+' . $parent_invoice->get_subscription_interval() . ' ' . $parent_invoice->get_subscription_period( true ), $start );
2541
+        if (!$expires) {
2542
+            $expires    = strtotime('+' . $parent_invoice->get_subscription_interval() . ' ' . $parent_invoice->get_subscription_period(true), $start);
2543 2543
         }
2544 2544
         
2545
-        $expiration     = date_i18n( 'Y-m-d 23:59:59', $expires );
2546
-        $expiration     = apply_filters( 'wpinv_subscription_renewal_expiration', $expiration, $this->ID, $this );
2545
+        $expiration     = date_i18n('Y-m-d 23:59:59', $expires);
2546
+        $expiration     = apply_filters('wpinv_subscription_renewal_expiration', $expiration, $this->ID, $this);
2547 2547
         $bill_times     = $parent_invoice->get_bill_times();
2548 2548
         $times_billed   = $parent_invoice->get_total_payments();
2549 2549
         
2550
-        if ( $parent_invoice->get_subscription_status() == 'trialing' && ( $times_billed > 0 || strtotime( date_i18n( 'Y-m-d' ) ) < strtotime( $parent_invoice->get_trial_end_date( false ) ) ) ) {
2550
+        if ($parent_invoice->get_subscription_status() == 'trialing' && ($times_billed > 0 || strtotime(date_i18n('Y-m-d')) < strtotime($parent_invoice->get_trial_end_date(false)))) {
2551 2551
             $args = array(
2552 2552
                 'status'     => 'active',
2553 2553
             );
2554 2554
 
2555
-            $parent_invoice->update_subscription( $args );
2555
+            $parent_invoice->update_subscription($args);
2556 2556
         }
2557 2557
         
2558
-        do_action( 'wpinv_subscription_pre_renew', $this->ID, $expiration, $this );
2558
+        do_action('wpinv_subscription_pre_renew', $this->ID, $expiration, $this);
2559 2559
 
2560
-        $status       = 'active';
2561
-        if ( $bill_times > 0 && $times_billed >= $bill_times ) {
2560
+        $status = 'active';
2561
+        if ($bill_times > 0 && $times_billed >= $bill_times) {
2562 2562
             $this->complete_subscription();
2563 2563
             $status = 'completed';
2564 2564
         }
@@ -2568,10 +2568,10 @@  discard block
 block discarded – undo
2568 2568
             'status'     => $status,
2569 2569
         );
2570 2570
 
2571
-        $this->update_subscription( $args );
2571
+        $this->update_subscription($args);
2572 2572
 
2573
-        do_action( 'wpinv_subscription_post_renew', $this->ID, $expiration, $this );
2574
-        do_action( 'wpinv_recurring_set_subscription_status', $this->ID, $status, $this );
2573
+        do_action('wpinv_subscription_post_renew', $this->ID, $expiration, $this);
2574
+        do_action('wpinv_recurring_set_subscription_status', $this->ID, $status, $this);
2575 2575
     }
2576 2576
     
2577 2577
     public function complete_subscription() {
@@ -2579,8 +2579,8 @@  discard block
 block discarded – undo
2579 2579
             'status' => 'completed'
2580 2580
         );
2581 2581
 
2582
-        if ( $this->update_subscription( $args ) ) {
2583
-            do_action( 'wpinv_subscription_completed', $this->ID, $this );
2582
+        if ($this->update_subscription($args)) {
2583
+            do_action('wpinv_subscription_completed', $this->ID, $this);
2584 2584
         }
2585 2585
     }
2586 2586
     
@@ -2589,44 +2589,44 @@  discard block
 block discarded – undo
2589 2589
             'status' => 'expired'
2590 2590
         );
2591 2591
 
2592
-        if ( $this->update_subscription( $args ) ) {
2593
-            do_action( 'wpinv_subscription_expired', $this->ID, $this );
2592
+        if ($this->update_subscription($args)) {
2593
+            do_action('wpinv_subscription_expired', $this->ID, $this);
2594 2594
         }
2595 2595
     }
2596 2596
 
2597 2597
     public function get_cancel_url() {
2598
-        $url = wp_nonce_url( add_query_arg( array( 'wpi_action' => 'cancel_subscription', 'sub_id' => $this->ID ) ), 'wpinv-recurring-cancel' );
2598
+        $url = wp_nonce_url(add_query_arg(array('wpi_action' => 'cancel_subscription', 'sub_id' => $this->ID)), 'wpinv-recurring-cancel');
2599 2599
 
2600
-        return apply_filters( 'wpinv_subscription_cancel_url', $url, $this );
2600
+        return apply_filters('wpinv_subscription_cancel_url', $url, $this);
2601 2601
     }
2602 2602
 
2603 2603
     public function can_update() {
2604
-        return apply_filters( 'wpinv_subscription_can_update', false, $this );
2604
+        return apply_filters('wpinv_subscription_can_update', false, $this);
2605 2605
     }
2606 2606
 
2607 2607
     public function get_update_url() {
2608
-        $url = add_query_arg( array( 'action' => 'update', 'sub_id' => $this->ID ) );
2608
+        $url = add_query_arg(array('action' => 'update', 'sub_id' => $this->ID));
2609 2609
 
2610
-        return apply_filters( 'wpinv_subscription_update_url', $url, $this );
2610
+        return apply_filters('wpinv_subscription_update_url', $url, $this);
2611 2611
     }
2612 2612
 
2613 2613
     public function is_parent() {
2614
-        $is_parent = empty( $this->parent_invoice ) ? true : false;
2614
+        $is_parent = empty($this->parent_invoice) ? true : false;
2615 2615
 
2616
-        return apply_filters( 'wpinv_invoice_is_parent', $is_parent, $this );
2616
+        return apply_filters('wpinv_invoice_is_parent', $is_parent, $this);
2617 2617
     }
2618 2618
     
2619 2619
     public function is_renewal() {
2620 2620
         $is_renewal = $this->parent_invoice && $this->parent_invoice != $this->ID ? true : false;
2621 2621
 
2622
-        return apply_filters( 'wpinv_invoice_is_renewal', $is_renewal, $this );
2622
+        return apply_filters('wpinv_invoice_is_renewal', $is_renewal, $this);
2623 2623
     }
2624 2624
     
2625 2625
     public function get_parent_payment() {
2626 2626
         $parent_payment = NULL;
2627 2627
         
2628
-        if ( $this->is_renewal() ) {
2629
-            $parent_payment = wpinv_get_invoice( $this->parent_invoice );
2628
+        if ($this->is_renewal()) {
2629
+            $parent_payment = wpinv_get_invoice($this->parent_invoice);
2630 2630
         }
2631 2631
         
2632 2632
         return $parent_payment;
@@ -2637,100 +2637,100 @@  discard block
 block discarded – undo
2637 2637
         
2638 2638
         $subscription_status = $this->get_subscription_status();
2639 2639
 
2640
-        if( ! $this->is_subscription_expired() && ( $subscription_status == 'active' || $subscription_status == 'cancelled' || $subscription_status == 'trialing' ) ) {
2640
+        if (!$this->is_subscription_expired() && ($subscription_status == 'active' || $subscription_status == 'cancelled' || $subscription_status == 'trialing')) {
2641 2641
             $ret = true;
2642 2642
         }
2643 2643
 
2644
-        return apply_filters( 'wpinv_subscription_is_active', $ret, $this->ID, $this );
2644
+        return apply_filters('wpinv_subscription_is_active', $ret, $this->ID, $this);
2645 2645
     }
2646 2646
 
2647 2647
     public function is_subscription_expired() {
2648 2648
         $ret = false;
2649 2649
         $subscription_status = $this->get_subscription_status();
2650 2650
 
2651
-        if ( $subscription_status == 'expired' ) {
2651
+        if ($subscription_status == 'expired') {
2652 2652
             $ret = true;
2653
-        } else if ( 'active' === $subscription_status || 'cancelled' === $subscription_status || 'trialing' == $subscription_status ) {
2653
+        } else if ('active' === $subscription_status || 'cancelled' === $subscription_status || 'trialing' == $subscription_status) {
2654 2654
             $ret        = false;
2655 2655
             $expiration = $this->get_expiration_time();
2656 2656
 
2657
-            if ( $expiration && strtotime( 'NOW', current_time( 'timestamp' ) ) > $expiration ) {
2657
+            if ($expiration && strtotime('NOW', current_time('timestamp')) > $expiration) {
2658 2658
                 $ret = true;
2659 2659
 
2660
-                if ( 'active' === $subscription_status || 'trialing' === $subscription_status ) {
2660
+                if ('active' === $subscription_status || 'trialing' === $subscription_status) {
2661 2661
                     $this->expire_subscription();
2662 2662
                 }
2663 2663
             }
2664 2664
         }
2665 2665
 
2666
-        return apply_filters( 'wpinv_subscription_is_expired', $ret, $this->ID, $this );
2666
+        return apply_filters('wpinv_subscription_is_expired', $ret, $this->ID, $this);
2667 2667
     }
2668 2668
     
2669
-    public function get_new_expiration( $item_id = 0, $trial = true ) {
2670
-        $item   = new WPInv_Item( $item_id );
2669
+    public function get_new_expiration($item_id = 0, $trial = true) {
2670
+        $item   = new WPInv_Item($item_id);
2671 2671
         $interval = $item->get_recurring_interval();
2672
-        $period = $item->get_recurring_period( true );
2672
+        $period = $item->get_recurring_period(true);
2673 2673
         
2674
-        $expiration_time = strtotime( '+' . $interval . ' ' . $period );
2674
+        $expiration_time = strtotime('+' . $interval . ' ' . $period);
2675 2675
         
2676
-        if ( $trial && $this->is_free_trial() && $item->has_free_trial() ) {
2677
-            $expiration_time += ( wpinv_period_in_days( $item->get_trial_interval(), $item->get_trial_period() ) * DAY_IN_SECONDS ) ;
2676
+        if ($trial && $this->is_free_trial() && $item->has_free_trial()) {
2677
+            $expiration_time += (wpinv_period_in_days($item->get_trial_interval(), $item->get_trial_period()) * DAY_IN_SECONDS);
2678 2678
         }
2679 2679
 
2680
-        return date_i18n( 'Y-m-d 23:59:59', $expiration_time );
2680
+        return date_i18n('Y-m-d 23:59:59', $expiration_time);
2681 2681
     }
2682 2682
     
2683
-    public function get_subscription_data( $filed = '' ) {
2684
-        $fields = array( 'item_id', 'status', 'period', 'initial_amount', 'recurring_amount', 'interval', 'bill_times', 'trial_period', 'trial_interval', 'expiration', 'profile_id', 'created', 'cancelled_on' );
2683
+    public function get_subscription_data($filed = '') {
2684
+        $fields = array('item_id', 'status', 'period', 'initial_amount', 'recurring_amount', 'interval', 'bill_times', 'trial_period', 'trial_interval', 'expiration', 'profile_id', 'created', 'cancelled_on');
2685 2685
         
2686 2686
         $subscription_meta = array();
2687
-        foreach ( $fields as $field ) {
2688
-            $subscription_meta[ $field ] = $this->get_meta( '_wpinv_subscr_' . $field );
2687
+        foreach ($fields as $field) {
2688
+            $subscription_meta[$field] = $this->get_meta('_wpinv_subscr_' . $field);
2689 2689
         }
2690 2690
         
2691
-        $item = $this->get_recurring( true );
2691
+        $item = $this->get_recurring(true);
2692 2692
         
2693
-        if ( !empty( $item ) ) {
2694
-            if ( empty( $subscription_meta['item_id'] ) ) {
2693
+        if (!empty($item)) {
2694
+            if (empty($subscription_meta['item_id'])) {
2695 2695
                 $subscription_meta['item_id'] = $item->ID;
2696 2696
             }
2697
-            if ( empty( $subscription_meta['period'] ) ) {
2697
+            if (empty($subscription_meta['period'])) {
2698 2698
                 $subscription_meta['period'] = $item->get_recurring_period();
2699 2699
             }
2700
-            if ( empty( $subscription_meta['interval'] ) ) {
2700
+            if (empty($subscription_meta['interval'])) {
2701 2701
                 $subscription_meta['interval'] = $item->get_recurring_interval();
2702 2702
             }
2703
-            if ( $item->has_free_trial() ) {
2704
-                if ( empty( $subscription_meta['trial_period'] ) ) {
2703
+            if ($item->has_free_trial()) {
2704
+                if (empty($subscription_meta['trial_period'])) {
2705 2705
                     $subscription_meta['trial_period'] = $item->get_trial_period();
2706 2706
                 }
2707
-                if ( empty( $subscription_meta['trial_interval'] ) ) {
2707
+                if (empty($subscription_meta['trial_interval'])) {
2708 2708
                     $subscription_meta['trial_interval'] = $item->get_trial_interval();
2709 2709
                 }
2710 2710
             } else {
2711 2711
                 $subscription_meta['trial_period']      = '';
2712 2712
                 $subscription_meta['trial_interval']    = 0;
2713 2713
             }
2714
-            if ( !$subscription_meta['bill_times'] && $subscription_meta['bill_times'] !== 0 ) {
2714
+            if (!$subscription_meta['bill_times'] && $subscription_meta['bill_times'] !== 0) {
2715 2715
                 $subscription_meta['bill_times'] = $item->get_recurring_limit();
2716 2716
             }
2717
-            if ( $subscription_meta['initial_amount'] === '' || $subscription_meta['recurring_amount'] === '' ) {
2718
-                $subscription_meta['initial_amount']    = wpinv_format_amount( $this->get_total() );
2719
-                $subscription_meta['recurring_amount']  = wpinv_format_amount( $this->get_recurring_details( 'total' ) );
2717
+            if ($subscription_meta['initial_amount'] === '' || $subscription_meta['recurring_amount'] === '') {
2718
+                $subscription_meta['initial_amount']    = wpinv_format_amount($this->get_total());
2719
+                $subscription_meta['recurring_amount']  = wpinv_format_amount($this->get_recurring_details('total'));
2720 2720
             }
2721 2721
         }
2722 2722
         
2723
-        if ( $filed === '' ) {
2724
-            return apply_filters( 'wpinv_get_invoice_subscription_data', $subscription_meta, $this );
2723
+        if ($filed === '') {
2724
+            return apply_filters('wpinv_get_invoice_subscription_data', $subscription_meta, $this);
2725 2725
         }
2726 2726
         
2727
-        $value = isset( $subscription_meta[$filed] ) ? $subscription_meta[$filed] : '';
2727
+        $value = isset($subscription_meta[$filed]) ? $subscription_meta[$filed] : '';
2728 2728
         
2729
-        return apply_filters( 'wpinv_invoice_subscription_data_value', $value, $subscription_meta, $this );
2729
+        return apply_filters('wpinv_invoice_subscription_data_value', $value, $subscription_meta, $this);
2730 2730
     }
2731 2731
     
2732 2732
     public function is_paid() {
2733
-        if ( $this->has_status( array( 'publish', 'complete', 'processing', 'renewal' ) ) ) {
2733
+        if ($this->has_status(array('publish', 'complete', 'processing', 'renewal'))) {
2734 2734
             return true;
2735 2735
         }
2736 2736
         
@@ -2742,28 +2742,28 @@  discard block
 block discarded – undo
2742 2742
         
2743 2743
         $requires_vat = false;
2744 2744
         
2745
-        if ( $this->country ) {
2745
+        if ($this->country) {
2746 2746
             $wpi_country        = $this->country;
2747 2747
             
2748
-            $requires_vat       = $wpinv_euvat->requires_vat( $requires_vat, $this->get_user_id(), $wpinv_euvat->invoice_has_digital_rule( $this ) );
2748
+            $requires_vat       = $wpinv_euvat->requires_vat($requires_vat, $this->get_user_id(), $wpinv_euvat->invoice_has_digital_rule($this));
2749 2749
         }
2750 2750
         
2751
-        return apply_filters( 'wpinv_invoice_has_vat', $requires_vat, $this );
2751
+        return apply_filters('wpinv_invoice_has_vat', $requires_vat, $this);
2752 2752
     }
2753 2753
     
2754 2754
     public function refresh_item_ids() {
2755 2755
         $item_ids = array();
2756 2756
         
2757
-        if ( !empty( $this->cart_details ) ) {
2758
-            foreach ( $this->cart_details as $key => $item ) {
2759
-                if ( !empty( $item['id'] ) ) {
2757
+        if (!empty($this->cart_details)) {
2758
+            foreach ($this->cart_details as $key => $item) {
2759
+                if (!empty($item['id'])) {
2760 2760
                     $item_ids[] = $item['id'];
2761 2761
                 }
2762 2762
             }
2763 2763
         }
2764 2764
         
2765
-        $item_ids = !empty( $item_ids ) ? implode( ',', array_unique( $item_ids ) ) : '';
2765
+        $item_ids = !empty($item_ids) ? implode(',', array_unique($item_ids)) : '';
2766 2766
         
2767
-        update_post_meta( $this->ID, '_wpinv_item_ids', $item_ids );
2767
+        update_post_meta($this->ID, '_wpinv_item_ids', $item_ids);
2768 2768
     }
2769 2769
 }
Please login to merge, or discard this patch.