Passed
Push — master ( 24478c...61f4f6 )
by Stiofan
03:19
created
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,46 +55,46 @@  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() );
77
-    $invoice->set( 'transaction_id', $args['transaction_id'] );
78
-    $invoice->set( 'key', $parent_invoice->generate_key() );
79
-    $invoice->set( 'ip', $parent_invoice->ip );
80
-    $invoice->set( 'user_id', $parent_invoice->get_user_id() );
81
-    $invoice->set( 'first_name', $parent_invoice->get_first_name() );
82
-    $invoice->set( 'last_name', $parent_invoice->get_last_name() );
83
-    $invoice->set( 'phone', $parent_invoice->phone );
84
-    $invoice->set( 'address', $parent_invoice->address );
85
-    $invoice->set( 'city', $parent_invoice->city );
86
-    $invoice->set( 'country', $parent_invoice->country );
87
-    $invoice->set( 'state', $parent_invoice->state );
88
-    $invoice->set( 'zip', $parent_invoice->zip );
89
-    $invoice->set( 'company', $parent_invoice->company );
90
-    $invoice->set( 'vat_number', $parent_invoice->vat_number );
91
-    $invoice->set( 'vat_rate', $parent_invoice->vat_rate );
92
-    $invoice->set( 'adddress_confirmed', $parent_invoice->adddress_confirmed );
93
-
94
-    if ( empty( $args['gateway'] ) ) {
95
-        $invoice->set( 'gateway', $parent_invoice->get_gateway() );
75
+    $invoice->set('parent_invoice', $parent_invoice_id);
76
+    $invoice->set('currency', $parent_invoice->get_currency());
77
+    $invoice->set('transaction_id', $args['transaction_id']);
78
+    $invoice->set('key', $parent_invoice->generate_key());
79
+    $invoice->set('ip', $parent_invoice->ip);
80
+    $invoice->set('user_id', $parent_invoice->get_user_id());
81
+    $invoice->set('first_name', $parent_invoice->get_first_name());
82
+    $invoice->set('last_name', $parent_invoice->get_last_name());
83
+    $invoice->set('phone', $parent_invoice->phone);
84
+    $invoice->set('address', $parent_invoice->address);
85
+    $invoice->set('city', $parent_invoice->city);
86
+    $invoice->set('country', $parent_invoice->country);
87
+    $invoice->set('state', $parent_invoice->state);
88
+    $invoice->set('zip', $parent_invoice->zip);
89
+    $invoice->set('company', $parent_invoice->company);
90
+    $invoice->set('vat_number', $parent_invoice->vat_number);
91
+    $invoice->set('vat_rate', $parent_invoice->vat_rate);
92
+    $invoice->set('adddress_confirmed', $parent_invoice->adddress_confirmed);
93
+
94
+    if (empty($args['gateway'])) {
95
+        $invoice->set('gateway', $parent_invoice->get_gateway());
96 96
     } else {
97
-        $invoice->set( 'gateway', $args['gateway'] );
97
+        $invoice->set('gateway', $args['gateway']);
98 98
     }
99 99
     
100 100
     $recurring_details = $parent_invoice->get_recurring_details();
@@ -102,11 +102,11 @@  discard block
 block discarded – undo
102 102
     // increase the earnings for each item in the subscription
103 103
     $items = $recurring_details['cart_details'];
104 104
     
105
-    if ( $items ) {        
105
+    if ($items) {        
106 106
         $add_items      = array();
107 107
         $cart_details   = array();
108 108
         
109
-        foreach ( $items as $item ) {
109
+        foreach ($items as $item) {
110 110
             $add_item             = array();
111 111
             $add_item['id']       = $item['id'];
112 112
             $add_item['quantity'] = $item['quantity'];
@@ -116,7 +116,7 @@  discard block
 block discarded – undo
116 116
             break;
117 117
         }
118 118
         
119
-        $invoice->set( 'items', $add_items );
119
+        $invoice->set('items', $add_items);
120 120
         $invoice->cart_details = $cart_details;
121 121
     }
122 122
     
@@ -126,277 +126,277 @@  discard block
 block discarded – undo
126 126
     $tax                = $recurring_details['tax'];
127 127
     $discount           = $recurring_details['discount'];
128 128
     
129
-    if ( $discount > 0 ) {
130
-        $invoice->set( 'discount_code', $parent_invoice->discount_code );
129
+    if ($discount > 0) {
130
+        $invoice->set('discount_code', $parent_invoice->discount_code);
131 131
     }
132 132
     
133
-    $invoice->subtotal = wpinv_round_amount( $subtotal );
134
-    $invoice->tax      = wpinv_round_amount( $tax );
135
-    $invoice->discount = wpinv_round_amount( $discount );
136
-    $invoice->total    = wpinv_round_amount( $total );
133
+    $invoice->subtotal = wpinv_round_amount($subtotal);
134
+    $invoice->tax      = wpinv_round_amount($tax);
135
+    $invoice->discount = wpinv_round_amount($discount);
136
+    $invoice->total    = wpinv_round_amount($total);
137 137
     $invoice->save();
138 138
     
139
-    wpinv_update_payment_status( $invoice->ID, 'publish' );
139
+    wpinv_update_payment_status($invoice->ID, 'publish');
140 140
     sleep(1);
141
-    wpinv_update_payment_status( $invoice->ID, 'wpi-renewal' );
141
+    wpinv_update_payment_status($invoice->ID, 'wpi-renewal');
142 142
     
143
-    $invoice = wpinv_get_invoice( $invoice->ID );
143
+    $invoice = wpinv_get_invoice($invoice->ID);
144 144
     
145
-    $subscription_data                      = wpinv_payment_subscription_data( $parent_invoice );
145
+    $subscription_data                      = wpinv_payment_subscription_data($parent_invoice);
146 146
     $subscription_data['recurring_amount']  = $invoice->get_total();
147
-    $subscription_data['created']           = current_time( 'mysql', 0 );
148
-    $subscription_data['expiration']        = $invoice->get_new_expiration( $subscription_data['item_id'] );
147
+    $subscription_data['created']           = current_time('mysql', 0);
148
+    $subscription_data['expiration']        = $invoice->get_new_expiration($subscription_data['item_id']);
149 149
     
150 150
     // Retrieve pending subscription from database and update it's status to active and set proper profile ID
151
-    $invoice->update_subscription( $subscription_data );
151
+    $invoice->update_subscription($subscription_data);
152 152
 
153
-    do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $parent_invoice, $subscription_args );
154
-    do_action( 'wpinv_recurring_record_payment', $invoice->ID, $parent_invoice_id, $subscription_args );
153
+    do_action('wpinv_recurring_add_subscription_payment', $invoice, $parent_invoice, $subscription_args);
154
+    do_action('wpinv_recurring_record_payment', $invoice->ID, $parent_invoice_id, $subscription_args);
155 155
 
156 156
     return $invoice;
157 157
 }
158 158
 
159
-function wpinv_payment_exists( $txn_id = '' ) {
159
+function wpinv_payment_exists($txn_id = '') {
160 160
     global $wpdb;
161 161
 
162
-    if ( empty( $txn_id ) ) {
162
+    if (empty($txn_id)) {
163 163
         return false;
164 164
     }
165 165
 
166
-    $txn_id = esc_sql( $txn_id );
166
+    $txn_id = esc_sql($txn_id);
167 167
 
168
-    $invoice = $wpdb->get_var( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = '{$txn_id}' LIMIT 1" );
168
+    $invoice = $wpdb->get_var("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = '{$txn_id}' LIMIT 1");
169 169
 
170
-    if ( $invoice != null ) {
170
+    if ($invoice != null) {
171 171
         return true;
172 172
     }
173 173
 
174 174
     return false;
175 175
 }
176 176
 
177
-function wpinv_is_subscription_payment( $invoice = '' ) {
178
-    if ( empty( $invoice ) ) {
177
+function wpinv_is_subscription_payment($invoice = '') {
178
+    if (empty($invoice)) {
179 179
         return false;
180 180
     }
181 181
     
182
-    if ( !is_object( $invoice ) && is_scalar( $invoice ) ) {
183
-        $invoice = wpinv_get_invoice( $invoice );
182
+    if (!is_object($invoice) && is_scalar($invoice)) {
183
+        $invoice = wpinv_get_invoice($invoice);
184 184
     }
185 185
     
186
-    if ( empty( $invoice ) ) {
186
+    if (empty($invoice)) {
187 187
         return false;
188 188
     }
189 189
         
190
-    if ( $invoice->is_renewal() ) {
190
+    if ($invoice->is_renewal()) {
191 191
         return true;
192 192
     }
193 193
 
194 194
     return false;
195 195
 }
196 196
 
197
-function wpinv_payment_subscription_data( $invoice = '' ) {
198
-    if ( empty( $invoice ) ) {
197
+function wpinv_payment_subscription_data($invoice = '') {
198
+    if (empty($invoice)) {
199 199
         return false;
200 200
     }
201 201
     
202
-    if ( !is_object( $invoice ) && is_scalar( $invoice ) ) {
203
-        $invoice = wpinv_get_invoice( $invoice );
202
+    if (!is_object($invoice) && is_scalar($invoice)) {
203
+        $invoice = wpinv_get_invoice($invoice);
204 204
     }
205 205
     
206
-    if ( empty( $invoice ) ) {
206
+    if (empty($invoice)) {
207 207
         return false;
208 208
     }    
209 209
 
210 210
     return $invoice->get_subscription_data();
211 211
 }
212 212
 
213
-function wpinv_payment_link_transaction_id( $invoice = '' ) {
214
-    if ( empty( $invoice ) ) {
213
+function wpinv_payment_link_transaction_id($invoice = '') {
214
+    if (empty($invoice)) {
215 215
         return false;
216 216
     }
217 217
     
218
-    if ( !is_object( $invoice ) && is_scalar( $invoice ) ) {
219
-        $invoice = wpinv_get_invoice( $invoice );
218
+    if (!is_object($invoice) && is_scalar($invoice)) {
219
+        $invoice = wpinv_get_invoice($invoice);
220 220
     }
221 221
     
222
-    if ( empty( $invoice ) ) {
222
+    if (empty($invoice)) {
223 223
         return false;
224 224
     }
225 225
 
226
-    return apply_filters( 'wpinv_payment_details_transaction_id-' . $invoice->gateway, $invoice->get_transaction_id(), $invoice->ID, $invoice );
226
+    return apply_filters('wpinv_payment_details_transaction_id-' . $invoice->gateway, $invoice->get_transaction_id(), $invoice->ID, $invoice);
227 227
 }
228 228
 
229
-function wpinv_get_pretty_subscription_period( $period ) {
229
+function wpinv_get_pretty_subscription_period($period) {
230 230
     $frequency = '';
231 231
     //Format period details
232
-    switch ( $period ) {
232
+    switch ($period) {
233 233
         case 'D' :
234 234
         case 'day' :
235
-            $frequency = __( 'Daily', 'invoicing' );
235
+            $frequency = __('Daily', 'invoicing');
236 236
             break;
237 237
         case 'W' :
238 238
         case 'week' :
239
-            $frequency = __( 'Weekly', 'invoicing' );
239
+            $frequency = __('Weekly', 'invoicing');
240 240
             break;
241 241
         case 'M' :
242 242
         case 'month' :
243
-            $frequency = __( 'Monthly', 'invoicing' );
243
+            $frequency = __('Monthly', 'invoicing');
244 244
             break;
245 245
         case 'Y' :
246 246
         case 'year' :
247
-            $frequency = __( 'Yearly', 'invoicing' );
247
+            $frequency = __('Yearly', 'invoicing');
248 248
             break;
249 249
         default :
250
-            $frequency = apply_filters( 'wpinv_pretty_subscription_period', $frequency, $period );
250
+            $frequency = apply_filters('wpinv_pretty_subscription_period', $frequency, $period);
251 251
             break;
252 252
     }
253 253
 
254 254
     return $frequency;
255 255
 }
256 256
 
257
-function wpinv_get_pretty_subscription_period_name( $period ) {
257
+function wpinv_get_pretty_subscription_period_name($period) {
258 258
     $frequency = '';
259 259
     //Format period details
260
-    switch ( $period ) {
260
+    switch ($period) {
261 261
         case 'D' :
262 262
         case 'day' :
263
-            $frequency = __( 'Day', 'invoicing' );
263
+            $frequency = __('Day', 'invoicing');
264 264
             break;
265 265
         case 'W' :
266 266
         case 'week' :
267
-            $frequency = __( 'Week', 'invoicing' );
267
+            $frequency = __('Week', 'invoicing');
268 268
             break;
269 269
         case 'M' :
270 270
         case 'month' :
271
-            $frequency = __( 'Month', 'invoicing' );
271
+            $frequency = __('Month', 'invoicing');
272 272
             break;
273 273
         case 'Y' :
274 274
         case 'year' :
275
-            $frequency = __( 'Year', 'invoicing' );
275
+            $frequency = __('Year', 'invoicing');
276 276
             break;
277 277
         default :
278
-            $frequency = apply_filters( 'wpinv_pretty_subscription_period_name', $frequency, $period );
278
+            $frequency = apply_filters('wpinv_pretty_subscription_period_name', $frequency, $period);
279 279
             break;
280 280
     }
281 281
 
282 282
     return $frequency;
283 283
 }
284 284
 
285
-function wpinv_subscription_initial_payment_desc( $amount, $period, $interval, $trial_period = '', $trial_interval = 0 ) {
285
+function wpinv_subscription_initial_payment_desc($amount, $period, $interval, $trial_period = '', $trial_interval = 0) {
286 286
     $interval   = (int)$interval > 0 ? (int)$interval : 1;
287 287
     
288
-    if ( $trial_interval > 0 && !empty( $trial_period ) ) {
289
-        $amount = __( 'Free', 'invoicing' );
288
+    if ($trial_interval > 0 && !empty($trial_period)) {
289
+        $amount = __('Free', 'invoicing');
290 290
         $interval = $trial_interval;
291 291
         $period = $trial_period;
292 292
     }
293 293
     
294 294
     $description = '';
295
-    switch ( $period ) {
295
+    switch ($period) {
296 296
         case 'D' :
297 297
         case 'day' :
298
-            $description = wp_sprintf( _n( '%s for the first day.', '%s for the first %d days.', $interval, 'invoicing' ), $amount, $interval );
298
+            $description = wp_sprintf(_n('%s for the first day.', '%s for the first %d days.', $interval, 'invoicing'), $amount, $interval);
299 299
             break;
300 300
         case 'W' :
301 301
         case 'week' :
302
-            $description = wp_sprintf( _n( '%s for the first week.', '%s for the first %d weeks.', $interval, 'invoicing' ), $amount, $interval );
302
+            $description = wp_sprintf(_n('%s for the first week.', '%s for the first %d weeks.', $interval, 'invoicing'), $amount, $interval);
303 303
             break;
304 304
         case 'M' :
305 305
         case 'month' :
306
-            $description = wp_sprintf( _n( '%s for the first month.', '%s for the first %d months.', $interval, 'invoicing' ), $amount, $interval );
306
+            $description = wp_sprintf(_n('%s for the first month.', '%s for the first %d months.', $interval, 'invoicing'), $amount, $interval);
307 307
             break;
308 308
         case 'Y' :
309 309
         case 'year' :
310
-            $description = wp_sprintf( _n( '%s for the first year.', '%s for the first %d years.', $interval, 'invoicing' ), $amount, $interval );
310
+            $description = wp_sprintf(_n('%s for the first year.', '%s for the first %d years.', $interval, 'invoicing'), $amount, $interval);
311 311
             break;
312 312
     }
313 313
 
314
-    return apply_filters( 'wpinv_subscription_initial_payment_desc', $description, $amount, $period, $interval, $trial_period, $trial_interval  );
314
+    return apply_filters('wpinv_subscription_initial_payment_desc', $description, $amount, $period, $interval, $trial_period, $trial_interval);
315 315
 }
316 316
 
317
-function wpinv_subscription_recurring_payment_desc( $amount, $period, $interval, $bill_times = 0, $trial_period = '', $trial_interval = 0 ) {
317
+function wpinv_subscription_recurring_payment_desc($amount, $period, $interval, $bill_times = 0, $trial_period = '', $trial_interval = 0) {
318 318
     $interval   = (int)$interval > 0 ? (int)$interval : 1;
319 319
     $bill_times = (int)$bill_times > 0 ? (int)$bill_times : 0;
320 320
     
321 321
     $description = '';
322
-    switch ( $period ) {
322
+    switch ($period) {
323 323
         case 'D' :
324 324
         case 'day' :            
325
-            if ( (int)$bill_times > 0 ) {
326
-                if ( $interval > 1 ) {
327
-                    if ( $bill_times > 1 ) {
328
-                        $description = wp_sprintf( __( '%s for each %d days, for %d installments.', 'invoicing' ), $amount, $interval, $bill_times );
325
+            if ((int)$bill_times > 0) {
326
+                if ($interval > 1) {
327
+                    if ($bill_times > 1) {
328
+                        $description = wp_sprintf(__('%s for each %d days, for %d installments.', 'invoicing'), $amount, $interval, $bill_times);
329 329
                     } else {
330
-                        $description = wp_sprintf( __( '%s for %d days.', 'invoicing' ), $amount, $interval );
330
+                        $description = wp_sprintf(__('%s for %d days.', 'invoicing'), $amount, $interval);
331 331
                     }
332 332
                 } else {
333
-                    $description = wp_sprintf( _n( '%s for one day.', '%s for each day, for %d installments.', $bill_times, 'invoicing' ), $amount, $bill_times );
333
+                    $description = wp_sprintf(_n('%s for one day.', '%s for each day, for %d installments.', $bill_times, 'invoicing'), $amount, $bill_times);
334 334
                 }
335 335
             } else {
336
-                $description = wp_sprintf( _n( '%s for each day.', '%s for each %d days.', $interval, 'invoicing'), $amount, $interval );
336
+                $description = wp_sprintf(_n('%s for each day.', '%s for each %d days.', $interval, 'invoicing'), $amount, $interval);
337 337
             }
338 338
             break;
339 339
         case 'W' :
340 340
         case 'week' :            
341
-            if ( (int)$bill_times > 0 ) {
342
-                if ( $interval > 1 ) {
343
-                    if ( $bill_times > 1 ) {
344
-                        $description = wp_sprintf( __( '%s for each %d weeks, for %d installments.', 'invoicing' ), $amount, $interval, $bill_times );
341
+            if ((int)$bill_times > 0) {
342
+                if ($interval > 1) {
343
+                    if ($bill_times > 1) {
344
+                        $description = wp_sprintf(__('%s for each %d weeks, for %d installments.', 'invoicing'), $amount, $interval, $bill_times);
345 345
                     } else {
346
-                        $description = wp_sprintf( __( '%s for %d weeks.', 'invoicing' ), $amount, $interval );
346
+                        $description = wp_sprintf(__('%s for %d weeks.', 'invoicing'), $amount, $interval);
347 347
                     }
348 348
                 } else {
349
-                    $description = wp_sprintf( _n( '%s for one week.', '%s for each week, for %d installments.', $bill_times, 'invoicing' ), $amount, $bill_times );
349
+                    $description = wp_sprintf(_n('%s for one week.', '%s for each week, for %d installments.', $bill_times, 'invoicing'), $amount, $bill_times);
350 350
                 }
351 351
             } else {
352
-                $description = wp_sprintf( _n( '%s for each week.', '%s for each %d weeks.', $interval, 'invoicing' ), $amount, $interval );
352
+                $description = wp_sprintf(_n('%s for each week.', '%s for each %d weeks.', $interval, 'invoicing'), $amount, $interval);
353 353
             }
354 354
             break;
355 355
         case 'M' :
356 356
         case 'month' :            
357
-            if ( (int)$bill_times > 0 ) {
358
-                if ( $interval > 1 ) {
359
-                    if ( $bill_times > 1 ) {
360
-                        $description = wp_sprintf( __( '%s for each %d months, for %d installments.', 'invoicing' ), $amount, $interval, $bill_times );
357
+            if ((int)$bill_times > 0) {
358
+                if ($interval > 1) {
359
+                    if ($bill_times > 1) {
360
+                        $description = wp_sprintf(__('%s for each %d months, for %d installments.', 'invoicing'), $amount, $interval, $bill_times);
361 361
                     } else {
362
-                        $description = wp_sprintf( __( '%s for %d months.', 'invoicing' ), $amount, $interval );
362
+                        $description = wp_sprintf(__('%s for %d months.', 'invoicing'), $amount, $interval);
363 363
                     }
364 364
                 } else {
365
-                    $description = wp_sprintf( _n( '%s for one month.', '%s for each month, for %d installments.', $bill_times, 'invoicing' ), $amount, $bill_times );
365
+                    $description = wp_sprintf(_n('%s for one month.', '%s for each month, for %d installments.', $bill_times, 'invoicing'), $amount, $bill_times);
366 366
                 }
367 367
             } else {
368
-                $description = wp_sprintf( _n( '%s for each month.', '%s for each %d months.', $interval, 'invoicing' ), $amount, $interval );
368
+                $description = wp_sprintf(_n('%s for each month.', '%s for each %d months.', $interval, 'invoicing'), $amount, $interval);
369 369
             }
370 370
             break;
371 371
         case 'Y' :
372 372
         case 'year' :            
373
-            if ( (int)$bill_times > 0 ) {
374
-                if ( $interval > 1 ) {
375
-                    if ( $bill_times > 1 ) {
376
-                        $description = wp_sprintf( __( '%s for each %d years, for %d installments.', 'invoicing' ), $amount, $interval, $bill_times );
373
+            if ((int)$bill_times > 0) {
374
+                if ($interval > 1) {
375
+                    if ($bill_times > 1) {
376
+                        $description = wp_sprintf(__('%s for each %d years, for %d installments.', 'invoicing'), $amount, $interval, $bill_times);
377 377
                     } else {
378
-                        $description = wp_sprintf( __( '%s for %d years.', 'invoicing'), $amount, $interval );
378
+                        $description = wp_sprintf(__('%s for %d years.', 'invoicing'), $amount, $interval);
379 379
                     }
380 380
                 } else {
381
-                    $description = wp_sprintf( _n( '%s for one year.', '%s for each year, for %d installments.', $bill_times, 'invoicing' ), $amount, $bill_times );
381
+                    $description = wp_sprintf(_n('%s for one year.', '%s for each year, for %d installments.', $bill_times, 'invoicing'), $amount, $bill_times);
382 382
                 }
383 383
             } else {
384
-                $description = wp_sprintf( _n( '%s for each year.', '%s for each %d years.', $interval, 'invoicing' ), $amount, $interval );
384
+                $description = wp_sprintf(_n('%s for each year.', '%s for each %d years.', $interval, 'invoicing'), $amount, $interval);
385 385
             }
386 386
             break;
387 387
     }
388 388
 
389
-    return apply_filters( 'wpinv_subscription_recurring_payment_desc', $description, $amount, $period, $interval, $bill_times, $trial_period, $trial_interval );
389
+    return apply_filters('wpinv_subscription_recurring_payment_desc', $description, $amount, $period, $interval, $bill_times, $trial_period, $trial_interval);
390 390
 }
391 391
 
392
-function wpinv_subscription_payment_desc( $invoice ) {
393
-    if ( empty( $invoice ) ) {
392
+function wpinv_subscription_payment_desc($invoice) {
393
+    if (empty($invoice)) {
394 394
         return NULL;
395 395
     }
396 396
     
397 397
     $description = '';
398
-    if ( $invoice->is_parent() && $item = $invoice->get_recurring( true ) ) {
399
-        if ( $item->has_free_trial() ) {
398
+    if ($invoice->is_parent() && $item = $invoice->get_recurring(true)) {
399
+        if ($item->has_free_trial()) {
400 400
             $trial_period = $item->get_trial_period();
401 401
             $trial_interval = $item->get_trial_interval();
402 402
         } else {
@@ -404,45 +404,45 @@  discard block
 block discarded – undo
404 404
             $trial_interval = 0;
405 405
         }
406 406
         
407
-        $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() );
407
+        $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());
408 408
     }
409 409
     
410
-    return apply_filters( 'wpinv_subscription_payment_desc', $description, $invoice );
410
+    return apply_filters('wpinv_subscription_payment_desc', $description, $invoice);
411 411
 }
412 412
 
413
-function wpinv_get_billing_cycle( $initial, $recurring, $period, $interval, $bill_times, $trial_period = '', $trial_interval = 0, $currency = '' ) {
414
-    $initial_total      = wpinv_round_amount( $initial );
415
-    $recurring_total    = wpinv_round_amount( $recurring );
413
+function wpinv_get_billing_cycle($initial, $recurring, $period, $interval, $bill_times, $trial_period = '', $trial_interval = 0, $currency = '') {
414
+    $initial_total      = wpinv_round_amount($initial);
415
+    $recurring_total    = wpinv_round_amount($recurring);
416 416
     
417
-    if ( $trial_interval > 0 && !empty( $trial_period ) ) {
417
+    if ($trial_interval > 0 && !empty($trial_period)) {
418 418
         // Free trial
419 419
     } else {
420
-        if ( $bill_times == 1 ) {
420
+        if ($bill_times == 1) {
421 421
             $recurring_total = $initial_total;
422
-        } else if ( $bill_times > 1 && $initial_total != $recurring_total ) {
422
+        } else if ($bill_times > 1 && $initial_total != $recurring_total) {
423 423
             $bill_times--;
424 424
         }
425 425
     }
426 426
     
427
-    $initial_amount     = wpinv_price( wpinv_format_amount( $initial_total ), $currency );
428
-    $recurring_amount   = wpinv_price( wpinv_format_amount( $recurring_total ), $currency );
427
+    $initial_amount     = wpinv_price(wpinv_format_amount($initial_total), $currency);
428
+    $recurring_amount   = wpinv_price(wpinv_format_amount($recurring_total), $currency);
429 429
     
430
-    $recurring          = wpinv_subscription_recurring_payment_desc( $recurring_amount, $period, $interval, $bill_times, $trial_period, $trial_interval );
430
+    $recurring          = wpinv_subscription_recurring_payment_desc($recurring_amount, $period, $interval, $bill_times, $trial_period, $trial_interval);
431 431
         
432
-    if ( $initial_total != $recurring_total ) {
433
-        $initial        = wpinv_subscription_initial_payment_desc( $initial_amount, $period, $interval, $trial_period, $trial_interval );
432
+    if ($initial_total != $recurring_total) {
433
+        $initial        = wpinv_subscription_initial_payment_desc($initial_amount, $period, $interval, $trial_period, $trial_interval);
434 434
         
435
-        $description    = wp_sprintf( __( '%s Then %s', 'invoicing' ), $initial, $recurring );
435
+        $description    = wp_sprintf(__('%s Then %s', 'invoicing'), $initial, $recurring);
436 436
     } else {
437 437
         $description    = $recurring;
438 438
     }
439 439
     
440
-    return apply_filters( 'wpinv_get_billing_cycle', $description, $initial, $recurring, $period, $interval, $bill_times, $trial_period, $trial_interval, $currency );
440
+    return apply_filters('wpinv_get_billing_cycle', $description, $initial, $recurring, $period, $interval, $bill_times, $trial_period, $trial_interval, $currency);
441 441
 }
442 442
 
443
-function wpinv_recurring_send_payment_failed( $invoice ) {
444
-    if ( !empty( $invoice->ID ) ) {
445
-        wpinv_failed_invoice_notification( $invoice->ID );
443
+function wpinv_recurring_send_payment_failed($invoice) {
444
+    if (!empty($invoice->ID)) {
445
+        wpinv_failed_invoice_notification($invoice->ID);
446 446
     }
447 447
 }
448
-add_action( 'wpinv_recurring_payment_failed', 'wpinv_recurring_send_payment_failed', 10, 1 );
449 448
\ No newline at end of file
449
+add_action('wpinv_recurring_payment_failed', 'wpinv_recurring_send_payment_failed', 10, 1);
450 450
\ No newline at end of file
Please login to merge, or discard this patch.
includes/wpinv-gateway-functions.php 1 patch
Spacing   +255 added lines, -255 removed lines patch added patch discarded remove patch
@@ -7,206 +7,206 @@  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_get_payment_gateways() {
15 15
     // Default, built-in gateways
16 16
     $gateways = array(
17 17
         'paypal' => array(
18
-            'admin_label'    => __( 'PayPal Standard', 'invoicing' ),
19
-            'checkout_label' => __( 'PayPal Standard', 'invoicing' ),
18
+            'admin_label'    => __('PayPal Standard', 'invoicing'),
19
+            'checkout_label' => __('PayPal Standard', 'invoicing'),
20 20
             'ordering'       => 1,
21 21
         ),
22 22
         'authorizenet' => array(
23
-            'admin_label'    => __( 'Authorize.Net (AIM)', 'invoicing' ),
24
-            'checkout_label' => __( 'Authorize.Net - Credit Card / Debit Card', 'invoicing' ),
23
+            'admin_label'    => __('Authorize.Net (AIM)', 'invoicing'),
24
+            'checkout_label' => __('Authorize.Net - Credit Card / Debit Card', 'invoicing'),
25 25
             'ordering'       => 4,
26 26
         ),
27 27
         'worldpay' => array(
28
-            'admin_label'    => __( 'Worldpay', 'invoicing' ),
29
-            'checkout_label' => __( 'Worldpay - Credit Card / Debit Card', 'invoicing' ),
28
+            'admin_label'    => __('Worldpay', 'invoicing'),
29
+            'checkout_label' => __('Worldpay - Credit Card / Debit Card', 'invoicing'),
30 30
             'ordering'       => 5,
31 31
         ),
32 32
         'bank_transfer' => array(
33
-            'admin_label'    => __( 'Pre Bank Transfer', 'invoicing' ),
34
-            'checkout_label' => __( 'Pre Bank Transfer', 'invoicing' ),
33
+            'admin_label'    => __('Pre Bank Transfer', 'invoicing'),
34
+            'checkout_label' => __('Pre Bank Transfer', 'invoicing'),
35 35
             'ordering'       => 11,
36 36
         ),
37 37
         'manual' => array(
38
-            'admin_label'    => __( 'Test Payment', 'invoicing' ),
39
-            'checkout_label' => __( 'Test Payment', 'invoicing' ),
38
+            'admin_label'    => __('Test Payment', 'invoicing'),
39
+            'checkout_label' => __('Test Payment', 'invoicing'),
40 40
             'ordering'       => 12,
41 41
         ),
42 42
     );
43 43
 
44
-    return apply_filters( 'wpinv_payment_gateways', $gateways );
44
+    return apply_filters('wpinv_payment_gateways', $gateways);
45 45
 }
46 46
 
47
-function wpinv_payment_gateway_titles( $all_gateways ) {
47
+function wpinv_payment_gateway_titles($all_gateways) {
48 48
     global $wpinv_options;
49 49
     
50 50
     $gateways = array();
51
-    foreach ( $all_gateways as $key => $gateway ) {
52
-        if ( !empty( $wpinv_options[$key . '_title'] ) ) {
53
-            $all_gateways[$key]['checkout_label'] = __( $wpinv_options[$key . '_title'], 'invoicing' );
51
+    foreach ($all_gateways as $key => $gateway) {
52
+        if (!empty($wpinv_options[$key . '_title'])) {
53
+            $all_gateways[$key]['checkout_label'] = __($wpinv_options[$key . '_title'], 'invoicing');
54 54
         }
55 55
         
56
-        $gateways[$key] = isset( $wpinv_options[$key . '_ordering'] ) ? $wpinv_options[$key . '_ordering'] : ( isset( $gateway['ordering'] ) ? $gateway['ordering'] : '' );
56
+        $gateways[$key] = isset($wpinv_options[$key . '_ordering']) ? $wpinv_options[$key . '_ordering'] : (isset($gateway['ordering']) ? $gateway['ordering'] : '');
57 57
     }
58 58
 
59
-    asort( $gateways );
59
+    asort($gateways);
60 60
     
61
-    foreach ( $gateways as $gateway => $key ) {
61
+    foreach ($gateways as $gateway => $key) {
62 62
         $gateways[$gateway] = $all_gateways[$gateway];
63 63
     }
64 64
     
65 65
     return $gateways;
66 66
 }
67
-add_filter( 'wpinv_payment_gateways', 'wpinv_payment_gateway_titles', 1000, 1 );
67
+add_filter('wpinv_payment_gateways', 'wpinv_payment_gateway_titles', 1000, 1);
68 68
 
69
-function wpinv_get_enabled_payment_gateways( $sort = false ) {
69
+function wpinv_get_enabled_payment_gateways($sort = false) {
70 70
     $gateways = wpinv_get_payment_gateways();
71
-    $enabled  = wpinv_get_option( 'gateways', false );
71
+    $enabled  = wpinv_get_option('gateways', false);
72 72
 
73 73
     $gateway_list = array();
74 74
 
75
-    foreach ( $gateways as $key => $gateway ) {
76
-        if ( isset( $enabled[ $key ] ) && $enabled[ $key ] == 1 ) {
77
-            $gateway_list[ $key ] = $gateway;
75
+    foreach ($gateways as $key => $gateway) {
76
+        if (isset($enabled[$key]) && $enabled[$key] == 1) {
77
+            $gateway_list[$key] = $gateway;
78 78
         }
79 79
     }
80 80
 
81
-    if ( true === $sort ) {
82
-        uasort( $gateway_list, 'wpinv_sort_gateway_order' );
81
+    if (true === $sort) {
82
+        uasort($gateway_list, 'wpinv_sort_gateway_order');
83 83
         
84 84
         // Reorder our gateways so the default is first
85 85
         $default_gateway_id = wpinv_get_default_gateway();
86 86
 
87
-        if ( wpinv_is_gateway_active( $default_gateway_id ) ) {
88
-            $default_gateway    = array( $default_gateway_id => $gateway_list[ $default_gateway_id ] );
89
-            unset( $gateway_list[ $default_gateway_id ] );
87
+        if (wpinv_is_gateway_active($default_gateway_id)) {
88
+            $default_gateway = array($default_gateway_id => $gateway_list[$default_gateway_id]);
89
+            unset($gateway_list[$default_gateway_id]);
90 90
 
91
-            $gateway_list = array_merge( $default_gateway, $gateway_list );
91
+            $gateway_list = array_merge($default_gateway, $gateway_list);
92 92
         }
93 93
     }
94 94
 
95
-    return apply_filters( 'wpinv_enabled_payment_gateways', $gateway_list );
95
+    return apply_filters('wpinv_enabled_payment_gateways', $gateway_list);
96 96
 }
97 97
 
98
-function wpinv_sort_gateway_order( $a, $b ) {
98
+function wpinv_sort_gateway_order($a, $b) {
99 99
     return $a['ordering'] - $b['ordering'];
100 100
 }
101 101
 
102
-function wpinv_is_gateway_active( $gateway ) {
102
+function wpinv_is_gateway_active($gateway) {
103 103
     $gateways = wpinv_get_enabled_payment_gateways();
104 104
 
105
-    $ret = is_array($gateways) && $gateway ?  array_key_exists( $gateway, $gateways ) : false;
105
+    $ret = is_array($gateways) && $gateway ?  array_key_exists($gateway, $gateways) : false;
106 106
 
107
-    return apply_filters( 'wpinv_is_gateway_active', $ret, $gateway, $gateways );
107
+    return apply_filters('wpinv_is_gateway_active', $ret, $gateway, $gateways);
108 108
 }
109 109
 
110 110
 function wpinv_get_default_gateway() {
111
-    $default = wpinv_get_option( 'default_gateway', 'paypal' );
111
+    $default = wpinv_get_option('default_gateway', 'paypal');
112 112
 
113
-    if ( !wpinv_is_gateway_active( $default ) ) {
113
+    if (!wpinv_is_gateway_active($default)) {
114 114
         $gateways = wpinv_get_enabled_payment_gateways();
115
-        $gateways = array_keys( $gateways );
116
-        $default  = reset( $gateways );
115
+        $gateways = array_keys($gateways);
116
+        $default  = reset($gateways);
117 117
     }
118 118
 
119
-    return apply_filters( 'wpinv_default_gateway', $default );
119
+    return apply_filters('wpinv_default_gateway', $default);
120 120
 }
121 121
 
122
-function wpinv_get_gateway_admin_label( $gateway ) {
122
+function wpinv_get_gateway_admin_label($gateway) {
123 123
     $gateways = wpinv_get_payment_gateways();
124
-    $label    = isset( $gateways[ $gateway ] ) ? $gateways[ $gateway ]['admin_label'] : $gateway;
125
-    $payment  = isset( $_GET['id'] ) ? absint( $_GET['id'] ) : false;
124
+    $label    = isset($gateways[$gateway]) ? $gateways[$gateway]['admin_label'] : $gateway;
125
+    $payment  = isset($_GET['id']) ? absint($_GET['id']) : false;
126 126
 
127
-    if( $gateway == 'manual' && $payment ) {
128
-        if( !( (float)wpinv_payment_total( $payment ) > 0 ) ) {
129
-            $label = __( 'Free Purchase', 'invoicing' );
127
+    if ($gateway == 'manual' && $payment) {
128
+        if (!((float)wpinv_payment_total($payment) > 0)) {
129
+            $label = __('Free Purchase', 'invoicing');
130 130
         }
131 131
     }
132 132
 
133
-    return apply_filters( 'wpinv_gateway_admin_label', $label, $gateway );
133
+    return apply_filters('wpinv_gateway_admin_label', $label, $gateway);
134 134
 }
135 135
 
136
-function wpinv_get_gateway_description( $gateway ) {
136
+function wpinv_get_gateway_description($gateway) {
137 137
     global $wpinv_options;
138 138
 
139
-    $description = isset( $wpinv_options[$gateway . '_desc'] ) ? $wpinv_options[$gateway . '_desc'] : '';
139
+    $description = isset($wpinv_options[$gateway . '_desc']) ? $wpinv_options[$gateway . '_desc'] : '';
140 140
 
141
-    return apply_filters( 'wpinv_gateway_description', $description, $gateway );
141
+    return apply_filters('wpinv_gateway_description', $description, $gateway);
142 142
 }
143 143
 
144
-function wpinv_get_gateway_button_label( $gateway ) {
145
-    return apply_filters( 'wpinv_gateway_' . $gateway . '_button_label', '' );
144
+function wpinv_get_gateway_button_label($gateway) {
145
+    return apply_filters('wpinv_gateway_' . $gateway . '_button_label', '');
146 146
 }
147 147
 
148
-function wpinv_get_gateway_checkout_label( $gateway ) {
148
+function wpinv_get_gateway_checkout_label($gateway) {
149 149
     $gateways = wpinv_get_payment_gateways();
150
-    $label    = isset( $gateways[ $gateway ] ) ? $gateways[ $gateway ]['checkout_label'] : $gateway;
150
+    $label    = isset($gateways[$gateway]) ? $gateways[$gateway]['checkout_label'] : $gateway;
151 151
 
152
-    if( $gateway == 'manual' ) {
153
-        $label = __( 'Manual Payment', 'invoicing' );
152
+    if ($gateway == 'manual') {
153
+        $label = __('Manual Payment', 'invoicing');
154 154
     }
155 155
 
156
-    return apply_filters( 'wpinv_gateway_checkout_label', $label, $gateway );
156
+    return apply_filters('wpinv_gateway_checkout_label', $label, $gateway);
157 157
 }
158 158
 
159
-function wpinv_settings_sections_gateways( $settings ) {
159
+function wpinv_settings_sections_gateways($settings) {
160 160
     $gateways = wpinv_get_payment_gateways();
161 161
     
162 162
     if (!empty($gateways)) {
163
-        foreach  ($gateways as $key => $gateway) {
163
+        foreach ($gateways as $key => $gateway) {
164 164
             $settings[$key] = $gateway['admin_label'];
165 165
         }
166 166
     }
167 167
     
168 168
     return $settings;    
169 169
 }
170
-add_filter( 'wpinv_settings_sections_gateways', 'wpinv_settings_sections_gateways', 10, 1 );
170
+add_filter('wpinv_settings_sections_gateways', 'wpinv_settings_sections_gateways', 10, 1);
171 171
 
172
-function wpinv_settings_gateways( $settings ) {
172
+function wpinv_settings_gateways($settings) {
173 173
     $gateways = wpinv_get_payment_gateways();
174 174
     
175 175
     if (!empty($gateways)) {
176
-        foreach  ($gateways as $key => $gateway) {
176
+        foreach ($gateways as $key => $gateway) {
177 177
             $setting = array();
178 178
             $setting[$key . '_header'] = array(
179 179
                     'id'   => 'gateway_header',
180
-                    'name' => '<h3>' . wp_sprintf( __( '%s Settings', 'invoicing' ), $gateway['admin_label'] ) . '</h3>',
180
+                    'name' => '<h3>' . wp_sprintf(__('%s Settings', 'invoicing'), $gateway['admin_label']) . '</h3>',
181 181
                     'custom' => $key,
182 182
                     'type' => 'gateway_header',
183 183
                 );
184 184
             $setting[$key . '_active'] = array(
185 185
                     'id'   => $key . '_active',
186
-                    'name' => __( 'Active', 'invoicing' ),
187
-                    'desc' => wp_sprintf( __( 'Enable %s', 'invoicing' ), $gateway['admin_label'] ),
186
+                    'name' => __('Active', 'invoicing'),
187
+                    'desc' => wp_sprintf(__('Enable %s', 'invoicing'), $gateway['admin_label']),
188 188
                     'type' => 'checkbox',
189 189
                 );
190 190
                 
191 191
             $setting[$key . '_title'] = array(
192 192
                     'id'   => $key . '_title',
193
-                    'name' => __( 'Title', 'invoicing' ),
194
-                    'desc' => __( 'This controls the title which the user sees during checkout.', 'invoicing' ),
193
+                    'name' => __('Title', 'invoicing'),
194
+                    'desc' => __('This controls the title which the user sees during checkout.', 'invoicing'),
195 195
                     'type' => 'text',
196 196
                     'std' => isset($gateway['checkout_label']) ? $gateway['checkout_label'] : ''
197 197
                 );
198 198
             
199 199
             $setting[$key . '_desc'] = array(
200 200
                     'id'   => $key . '_desc',
201
-                    'name' => __( 'Description', 'invoicing' ),
202
-                    'desc' => __( 'This controls the description which the user sees during checkout.', 'invoicing' ),
201
+                    'name' => __('Description', 'invoicing'),
202
+                    'desc' => __('This controls the description which the user sees during checkout.', 'invoicing'),
203 203
                     'type' => 'text',
204 204
                     'size' => 'large'
205 205
                 );
206 206
                 
207 207
             $setting[$key . '_ordering'] = array(
208 208
                     'id'   => $key . '_ordering',
209
-                    'name' => __( 'Display Order', 'invoicing' ),
209
+                    'name' => __('Display Order', 'invoicing'),
210 210
                     'type' => 'number',
211 211
                     'size' => 'small',
212 212
                     'std'  => isset($gateway['ordering']) ? $gateway['ordering'] : '10',
@@ -215,8 +215,8 @@  discard block
 block discarded – undo
215 215
                     'step' => '1'
216 216
                 );
217 217
                 
218
-            $setting = apply_filters( 'wpinv_gateway_settings', $setting, $key );
219
-            $setting = apply_filters( 'wpinv_gateway_settings_' . $key, $setting );
218
+            $setting = apply_filters('wpinv_gateway_settings', $setting, $key);
219
+            $setting = apply_filters('wpinv_gateway_settings_' . $key, $setting);
220 220
             
221 221
             $settings[$key] = $setting;
222 222
         }
@@ -224,106 +224,106 @@  discard block
 block discarded – undo
224 224
     
225 225
     return $settings;    
226 226
 }
227
-add_filter( 'wpinv_settings_gateways', 'wpinv_settings_gateways', 10, 1 );
227
+add_filter('wpinv_settings_gateways', 'wpinv_settings_gateways', 10, 1);
228 228
 
229
-function wpinv_gateway_header_callback( $args ) {
230
-    echo '<input type="hidden" id="wpinv_settings[save_gateway]" name="wpinv_settings[save_gateway]" value="' . esc_attr( $args['custom'] ) . '" />';
229
+function wpinv_gateway_header_callback($args) {
230
+    echo '<input type="hidden" id="wpinv_settings[save_gateway]" name="wpinv_settings[save_gateway]" value="' . esc_attr($args['custom']) . '" />';
231 231
 }
232 232
 
233
-function wpinv_get_gateway_supports( $gateway ) {
233
+function wpinv_get_gateway_supports($gateway) {
234 234
     $gateways = wpinv_get_enabled_payment_gateways();
235
-    $supports = isset( $gateways[ $gateway ]['supports'] ) ? $gateways[ $gateway ]['supports'] : array();
236
-    return apply_filters( 'wpinv_gateway_supports', $supports, $gateway );
235
+    $supports = isset($gateways[$gateway]['supports']) ? $gateways[$gateway]['supports'] : array();
236
+    return apply_filters('wpinv_gateway_supports', $supports, $gateway);
237 237
 }
238 238
 
239
-function wpinv_gateway_supports_buy_now( $gateway ) {
240
-    $supports = wpinv_get_gateway_supports( $gateway );
241
-    $ret = in_array( 'buy_now', $supports );
242
-    return apply_filters( 'wpinv_gateway_supports_buy_now', $ret, $gateway );
239
+function wpinv_gateway_supports_buy_now($gateway) {
240
+    $supports = wpinv_get_gateway_supports($gateway);
241
+    $ret = in_array('buy_now', $supports);
242
+    return apply_filters('wpinv_gateway_supports_buy_now', $ret, $gateway);
243 243
 }
244 244
 
245 245
 function wpinv_shop_supports_buy_now() {
246 246
     $gateways = wpinv_get_enabled_payment_gateways();
247 247
     $ret      = false;
248 248
 
249
-    if ( !wpinv_use_taxes()  && $gateways ) {
250
-        foreach ( $gateways as $gateway_id => $gateway ) {
251
-            if ( wpinv_gateway_supports_buy_now( $gateway_id ) ) {
249
+    if (!wpinv_use_taxes() && $gateways) {
250
+        foreach ($gateways as $gateway_id => $gateway) {
251
+            if (wpinv_gateway_supports_buy_now($gateway_id)) {
252 252
                 $ret = true;
253 253
                 break;
254 254
             }
255 255
         }
256 256
     }
257 257
 
258
-    return apply_filters( 'wpinv_shop_supports_buy_now', $ret );
258
+    return apply_filters('wpinv_shop_supports_buy_now', $ret);
259 259
 }
260 260
 
261
-function wpinv_send_to_gateway( $gateway, $payment_data ) {
262
-    $payment_data['gateway_nonce'] = wp_create_nonce( 'wpi-gateway' );
261
+function wpinv_send_to_gateway($gateway, $payment_data) {
262
+    $payment_data['gateway_nonce'] = wp_create_nonce('wpi-gateway');
263 263
 
264 264
     // $gateway must match the ID used when registering the gateway
265
-    do_action( 'wpinv_gateway_' . $gateway, $payment_data );
265
+    do_action('wpinv_gateway_' . $gateway, $payment_data);
266 266
 }
267 267
 
268 268
 function wpinv_show_gateways() {
269 269
     $gateways = wpinv_get_enabled_payment_gateways();
270 270
     $show_gateways = false;
271 271
 
272
-    $chosen_gateway = isset( $_GET['payment-mode'] ) ? preg_replace('/[^a-zA-Z0-9-_]+/', '', $_GET['payment-mode'] ) : false;
272
+    $chosen_gateway = isset($_GET['payment-mode']) ? preg_replace('/[^a-zA-Z0-9-_]+/', '', $_GET['payment-mode']) : false;
273 273
 
274
-    if ( count( $gateways ) > 1 && empty( $chosen_gateway ) ) {
274
+    if (count($gateways) > 1 && empty($chosen_gateway)) {
275 275
         $show_gateways = true;
276
-        if ( wpinv_get_cart_total() <= 0 ) {
276
+        if (wpinv_get_cart_total() <= 0) {
277 277
             $show_gateways = false;
278 278
         }
279 279
     }
280 280
     
281
-    if ( !$show_gateways && wpinv_cart_has_recurring_item() ) {
281
+    if (!$show_gateways && wpinv_cart_has_recurring_item()) {
282 282
         $show_gateways = true;
283 283
     }
284 284
 
285
-    return apply_filters( 'wpinv_show_gateways', $show_gateways );
285
+    return apply_filters('wpinv_show_gateways', $show_gateways);
286 286
 }
287 287
 
288
-function wpinv_get_chosen_gateway( $invoice_id = 0 ) {
289
-	$gateways = array_keys( wpinv_get_enabled_payment_gateways() );
288
+function wpinv_get_chosen_gateway($invoice_id = 0) {
289
+	$gateways = array_keys(wpinv_get_enabled_payment_gateways());
290 290
 
291 291
     $chosen = false;
292
-    if ( $invoice_id > 0 && $invoice = wpinv_get_invoice( $invoice_id ) ) {
292
+    if ($invoice_id > 0 && $invoice = wpinv_get_invoice($invoice_id)) {
293 293
         $chosen = $invoice->get_gateway();
294 294
     }
295 295
 
296
-	$chosen   = isset( $_REQUEST['payment-mode'] ) ? sanitize_text_field( $_REQUEST['payment-mode'] ) : $chosen;
296
+	$chosen = isset($_REQUEST['payment-mode']) ? sanitize_text_field($_REQUEST['payment-mode']) : $chosen;
297 297
 
298
-	if ( false !== $chosen ) {
299
-		$chosen = preg_replace('/[^a-zA-Z0-9-_]+/', '', $chosen );
298
+	if (false !== $chosen) {
299
+		$chosen = preg_replace('/[^a-zA-Z0-9-_]+/', '', $chosen);
300 300
 	}
301 301
 
302
-	if ( ! empty ( $chosen ) ) {
303
-		$enabled_gateway = urldecode( $chosen );
304
-	} else if (  !empty( $invoice ) && (float)$invoice->get_subtotal() <= 0 ) {
302
+	if (!empty ($chosen)) {
303
+		$enabled_gateway = urldecode($chosen);
304
+	} else if (!empty($invoice) && (float)$invoice->get_subtotal() <= 0) {
305 305
 		$enabled_gateway = 'manual';
306 306
 	} else {
307 307
 		$enabled_gateway = wpinv_get_default_gateway();
308 308
 	}
309 309
     
310
-    if ( !wpinv_is_gateway_active( $enabled_gateway ) && !empty( $gateways ) ) {
311
-        if(wpinv_is_gateway_active( wpinv_get_default_gateway()) ){
310
+    if (!wpinv_is_gateway_active($enabled_gateway) && !empty($gateways)) {
311
+        if (wpinv_is_gateway_active(wpinv_get_default_gateway())) {
312 312
             $enabled_gateway = wpinv_get_default_gateway();
313
-        }else{
313
+        } else {
314 314
             $enabled_gateway = $gateways[0];
315 315
         }
316 316
 
317 317
     }
318 318
 
319
-	return apply_filters( 'wpinv_chosen_gateway', $enabled_gateway );
319
+	return apply_filters('wpinv_chosen_gateway', $enabled_gateway);
320 320
 }
321 321
 
322
-function wpinv_record_gateway_error( $title = '', $message = '', $parent = 0 ) {
323
-    return wpinv_error_log( $message, $title );
322
+function wpinv_record_gateway_error($title = '', $message = '', $parent = 0) {
323
+    return wpinv_error_log($message, $title);
324 324
 }
325 325
 
326
-function wpinv_count_sales_by_gateway( $gateway_id = 'paypal', $status = 'publish' ) {
326
+function wpinv_count_sales_by_gateway($gateway_id = 'paypal', $status = 'publish') {
327 327
 	$ret  = 0;
328 328
 	$args = array(
329 329
 		'meta_key'    => '_wpinv_gateway',
@@ -334,48 +334,48 @@  discard block
 block discarded – undo
334 334
 		'fields'      => 'ids'
335 335
 	);
336 336
 
337
-	$payments = new WP_Query( $args );
337
+	$payments = new WP_Query($args);
338 338
 
339
-	if( $payments )
339
+	if ($payments)
340 340
 		$ret = $payments->post_count;
341 341
 	return $ret;
342 342
 }
343 343
 
344
-function wpinv_settings_update_gateways( $input ) {
344
+function wpinv_settings_update_gateways($input) {
345 345
     global $wpinv_options;
346 346
     
347
-    if ( !empty( $input['save_gateway'] ) ) {
348
-        $gateways = wpinv_get_option( 'gateways', false );
347
+    if (!empty($input['save_gateway'])) {
348
+        $gateways = wpinv_get_option('gateways', false);
349 349
         $gateways = !empty($gateways) ? $gateways : array();
350 350
         $gateway = $input['save_gateway'];
351 351
         
352
-        if ( !empty( $input[$gateway . '_active'] ) ) {
352
+        if (!empty($input[$gateway . '_active'])) {
353 353
             $gateways[$gateway] = 1;
354 354
         } else {
355
-            if ( isset( $gateways[$gateway] ) ) {
356
-                unset( $gateways[$gateway] );
355
+            if (isset($gateways[$gateway])) {
356
+                unset($gateways[$gateway]);
357 357
             }
358 358
         }
359 359
         
360 360
         $input['gateways'] = $gateways;
361 361
     }
362 362
     
363
-    if ( !empty( $input['default_gateway'] ) ) {
363
+    if (!empty($input['default_gateway'])) {
364 364
         $gateways = wpinv_get_payment_gateways();
365 365
         
366
-        foreach ( $gateways as $key => $gateway ) {
367
-            $active   = 0;
368
-            if ( !empty( $input['gateways'] ) && !empty( $input['gateways'][$key] ) ) {
366
+        foreach ($gateways as $key => $gateway) {
367
+            $active = 0;
368
+            if (!empty($input['gateways']) && !empty($input['gateways'][$key])) {
369 369
                 $active = 1;
370 370
             }
371 371
             
372 372
             $input[$key . '_active'] = $active;
373 373
             
374
-            if ( empty( $wpinv_options[$key . '_title'] ) ) {
374
+            if (empty($wpinv_options[$key . '_title'])) {
375 375
                 $input[$key . '_title'] = $gateway['checkout_label'];
376 376
             }
377 377
             
378
-            if ( !isset( $wpinv_options[$key . '_ordering'] ) && isset( $gateway['ordering'] ) ) {
378
+            if (!isset($wpinv_options[$key . '_ordering']) && isset($gateway['ordering'])) {
379 379
                 $input[$key . '_ordering'] = $gateway['ordering'];
380 380
             }
381 381
         }
@@ -383,26 +383,26 @@  discard block
 block discarded – undo
383 383
     
384 384
     return $input;
385 385
 }
386
-add_filter( 'wpinv_settings_tab_gateways_sanitize', 'wpinv_settings_update_gateways', 10, 1 );
386
+add_filter('wpinv_settings_tab_gateways_sanitize', 'wpinv_settings_update_gateways', 10, 1);
387 387
 
388 388
 // PayPal Standard settings
389
-function wpinv_gateway_settings_paypal( $setting ) {    
390
-    $setting['paypal_desc']['std'] = __( 'Pay via PayPal: you can pay with your credit card if you don\'t have a PayPal account.', 'invoicing' );
389
+function wpinv_gateway_settings_paypal($setting) {    
390
+    $setting['paypal_desc']['std'] = __('Pay via PayPal: you can pay with your credit card if you don\'t have a PayPal account.', 'invoicing');
391 391
     
392 392
     $setting['paypal_sandbox'] = array(
393 393
             'type' => 'checkbox',
394 394
             'id'   => 'paypal_sandbox',
395
-            'name' => __( 'PayPal Sandbox', 'invoicing' ),
396
-            'desc' => __( 'PayPal sandbox can be used to test payments.', 'invoicing' ),
395
+            'name' => __('PayPal Sandbox', 'invoicing'),
396
+            'desc' => __('PayPal sandbox can be used to test payments.', 'invoicing'),
397 397
             'std'  => 1
398 398
         );
399 399
         
400 400
     $setting['paypal_email'] = array(
401 401
             'type' => 'text',
402 402
             'id'   => 'paypal_email',
403
-            'name' => __( 'PayPal Email', 'invoicing' ),
404
-            'desc' => __( 'Please enter your PayPal account\'s email address. Ex: [email protected]', 'invoicing' ),
405
-            'std' => __( '[email protected]', 'invoicing' ),
403
+            'name' => __('PayPal Email', 'invoicing'),
404
+            'desc' => __('Please enter your PayPal account\'s email address. Ex: [email protected]', 'invoicing'),
405
+            'std' => __('[email protected]', 'invoicing'),
406 406
         );
407 407
     /*
408 408
     $setting['paypal_ipn_url'] = array(
@@ -416,123 +416,123 @@  discard block
 block discarded – undo
416 416
         
417 417
     return $setting;
418 418
 }
419
-add_filter( 'wpinv_gateway_settings_paypal', 'wpinv_gateway_settings_paypal', 10, 1 );
419
+add_filter('wpinv_gateway_settings_paypal', 'wpinv_gateway_settings_paypal', 10, 1);
420 420
 
421 421
 // Pre Bank Transfer settings
422
-function wpinv_gateway_settings_bank_transfer( $setting ) {
423
-    $setting['bank_transfer_desc']['std'] = __( 'Make your payment directly into our bank account. Please use your Invoice ID as the payment reference. Your invoice won\'t be processed until the funds have cleared in our account.', 'invoicing' );
422
+function wpinv_gateway_settings_bank_transfer($setting) {
423
+    $setting['bank_transfer_desc']['std'] = __('Make your payment directly into our bank account. Please use your Invoice ID as the payment reference. Your invoice won\'t be processed until the funds have cleared in our account.', 'invoicing');
424 424
     
425 425
     $setting['bank_transfer_ac_name'] = array(
426 426
             'type' => 'text',
427 427
             'id' => 'bank_transfer_ac_name',
428
-            'name' => __( 'Account Name', 'invoicing' ),
429
-            'desc' => __( 'Enter the bank account name to which you want to transfer payment.', 'invoicing' ),
430
-            'std'  =>  __( 'Mr. John Martin', 'invoicing' ),
428
+            'name' => __('Account Name', 'invoicing'),
429
+            'desc' => __('Enter the bank account name to which you want to transfer payment.', 'invoicing'),
430
+            'std'  =>  __('Mr. John Martin', 'invoicing'),
431 431
         );
432 432
     
433 433
     $setting['bank_transfer_ac_no'] = array(
434 434
             'type' => 'text',
435 435
             'id' => 'bank_transfer_ac_no',
436
-            'name' => __( 'Account Number', 'invoicing' ),
437
-            'desc' => __( 'Enter your bank account number.', 'invoicing' ),
438
-            'std'  =>  __( 'TEST1234567890', 'invoicing' ),
436
+            'name' => __('Account Number', 'invoicing'),
437
+            'desc' => __('Enter your bank account number.', 'invoicing'),
438
+            'std'  =>  __('TEST1234567890', 'invoicing'),
439 439
         );
440 440
     
441 441
     $setting['bank_transfer_bank_name'] = array(
442 442
             'type' => 'text',
443 443
             'id'   => 'bank_transfer_bank_name',
444
-            'name' => __( 'Bank Name', 'invoicing' ),
445
-            'desc' => __( 'Enter the bank name to which you want to transfer payment.', 'invoicing' ),
446
-            'std' => __( 'ICICI Bank', 'invoicing' ),
444
+            'name' => __('Bank Name', 'invoicing'),
445
+            'desc' => __('Enter the bank name to which you want to transfer payment.', 'invoicing'),
446
+            'std' => __('ICICI Bank', 'invoicing'),
447 447
         );
448 448
     
449 449
     $setting['bank_transfer_ifsc'] = array(
450 450
             'type' => 'text',
451 451
             'id'   => 'bank_transfer_ifsc',
452
-            'name' => __( 'IFSC Code', 'invoicing' ),
453
-            'desc' => __( 'Enter your bank IFSC code.', 'invoicing' ),
454
-            'std'  =>  __( 'ICIC0001234', 'invoicing' ),
452
+            'name' => __('IFSC Code', 'invoicing'),
453
+            'desc' => __('Enter your bank IFSC code.', 'invoicing'),
454
+            'std'  =>  __('ICIC0001234', 'invoicing'),
455 455
         );
456 456
         
457 457
     $setting['bank_transfer_iban'] = array(
458 458
             'type' => 'text',
459 459
             'id'   => 'bank_transfer_iban',
460
-            'name' => __( 'IBAN', 'invoicing' ),
461
-            'desc' => __( 'Enter your International Bank Account Number(IBAN).', 'invoicing' ),
462
-            'std'  =>  __( 'GB29NWBK60161331926819', 'invoicing' ),
460
+            'name' => __('IBAN', 'invoicing'),
461
+            'desc' => __('Enter your International Bank Account Number(IBAN).', 'invoicing'),
462
+            'std'  =>  __('GB29NWBK60161331926819', 'invoicing'),
463 463
         );
464 464
         
465 465
     $setting['bank_transfer_bic'] = array(
466 466
             'type' => 'text',
467 467
             'id'   => 'bank_transfer_bic',
468
-            'name' => __( 'BIC/Swift Code', 'invoicing' ),
469
-            'std'  =>  __( 'ICICGB2L129', 'invoicing' ),
468
+            'name' => __('BIC/Swift Code', 'invoicing'),
469
+            'std'  =>  __('ICICGB2L129', 'invoicing'),
470 470
         );
471 471
 
472 472
     $setting['bank_transfer_sort_code'] = array(
473 473
         'type' => 'text',
474 474
         'id'   => 'bank_transfer_sort_code',
475
-        'name' => __( 'Sort Code', 'invoicing' ),
476
-        'std'  =>  __( '12-34-56', 'invoicing' ),
475
+        'name' => __('Sort Code', 'invoicing'),
476
+        'std'  =>  __('12-34-56', 'invoicing'),
477 477
     );
478 478
         
479 479
     $setting['bank_transfer_info'] = array(
480 480
             'id'   => 'bank_transfer_info',
481
-            'name' => __( 'Instructions', 'invoicing' ),
482
-            'desc' => __( 'Instructions that will be added to the thank you page and emails.', 'invoicing' ),
481
+            'name' => __('Instructions', 'invoicing'),
482
+            'desc' => __('Instructions that will be added to the thank you page and emails.', 'invoicing'),
483 483
             'type' => 'textarea',
484
-            'std' => __( 'Make your payment directly into our bank account. Please use your Invoice ID as the payment reference. Your invoice won\'t be processed until the funds have cleared in our account.', 'invoicing' ),
484
+            'std' => __('Make your payment directly into our bank account. Please use your Invoice ID as the payment reference. Your invoice won\'t be processed until the funds have cleared in our account.', 'invoicing'),
485 485
             'cols' => 37,
486 486
             'rows' => 5
487 487
         );
488 488
         
489 489
     return $setting;
490 490
 }
491
-add_filter( 'wpinv_gateway_settings_bank_transfer', 'wpinv_gateway_settings_bank_transfer', 10, 1 );
491
+add_filter('wpinv_gateway_settings_bank_transfer', 'wpinv_gateway_settings_bank_transfer', 10, 1);
492 492
 
493 493
 // Authorize.Net settings
494
-function wpinv_gateway_settings_authorizenet( $setting ) {
495
-    $setting['authorizenet_active']['desc'] = $setting['authorizenet_active']['desc'] . ' ' . __( '( currencies supported: AUD, CAD, CHF, DKK, EUR, GBP, JPY, NOK, NZD, PLN, SEK, USD, ZAR )', 'invoicing' );
496
-    $setting['authorizenet_desc']['std'] = __( 'Pay using a Authorize.Net to process credit card / debit card transactions.', 'invoicing' );
494
+function wpinv_gateway_settings_authorizenet($setting) {
495
+    $setting['authorizenet_active']['desc'] = $setting['authorizenet_active']['desc'] . ' ' . __('( currencies supported: AUD, CAD, CHF, DKK, EUR, GBP, JPY, NOK, NZD, PLN, SEK, USD, ZAR )', 'invoicing');
496
+    $setting['authorizenet_desc']['std'] = __('Pay using a Authorize.Net to process credit card / debit card transactions.', 'invoicing');
497 497
     
498 498
     $setting['authorizenet_sandbox'] = array(
499 499
             'type' => 'checkbox',
500 500
             'id'   => 'authorizenet_sandbox',
501
-            'name' => __( 'Authorize.Net Test Mode', 'invoicing' ),
502
-            'desc' => __( 'Enable Authorize.Net test mode to test payments.', 'invoicing' ),
501
+            'name' => __('Authorize.Net Test Mode', 'invoicing'),
502
+            'desc' => __('Enable Authorize.Net test mode to test payments.', 'invoicing'),
503 503
             'std'  => 1
504 504
         );
505 505
         
506 506
     $setting['authorizenet_login_id'] = array(
507 507
             'type' => 'text',
508 508
             'id'   => 'authorizenet_login_id',
509
-            'name' => __( 'API Login ID', 'invoicing' ),
510
-            'desc' => __( 'API Login ID can be obtained from Authorize.Net Account > Settings > Security Settings > General Security Settings > API Credentials & Keys. Example : 2j4rBekUnD', 'invoicing' ),
509
+            'name' => __('API Login ID', 'invoicing'),
510
+            'desc' => __('API Login ID can be obtained from Authorize.Net Account > Settings > Security Settings > General Security Settings > API Credentials & Keys. Example : 2j4rBekUnD', 'invoicing'),
511 511
             'std' => '2j4rBekUnD',
512 512
         );
513 513
     
514 514
     $setting['authorizenet_transaction_key'] = array(
515 515
             'type' => 'text',
516 516
             'id'   => 'authorizenet_transaction_key',
517
-            'name' => __( 'Transaction Key', 'invoicing' ),
518
-            'desc' => __( 'Transaction Key can be obtained from Authorize.Net Account > Settings > Security Settings > General Security Settings > API Credentials & Keys. Example : 4vyBUOJgR74679xa', 'invoicing' ),
517
+            'name' => __('Transaction Key', 'invoicing'),
518
+            'desc' => __('Transaction Key can be obtained from Authorize.Net Account > Settings > Security Settings > General Security Settings > API Credentials & Keys. Example : 4vyBUOJgR74679xa', 'invoicing'),
519 519
             'std' => '4vyBUOJgR74679xa',
520 520
         );
521 521
         
522 522
     $setting['authorizenet_md5_hash'] = array(
523 523
             'type' => 'text',
524 524
             'id'   => 'authorizenet_md5_hash',
525
-            'name' => __( 'MD5-Hash', 'invoicing' ),
526
-            'desc' => __( 'The MD5 Hash security feature allows you to authenticate transaction responses from the Authorize.Net. If you are accepting recurring payments then md5 hash will helps to validate response from Authorize.net. It can be obtained from Authorize.Net Account > Settings > Security Settings > General Settings > MD5 Hash.', 'invoicing' ),
525
+            'name' => __('MD5-Hash', 'invoicing'),
526
+            'desc' => __('The MD5 Hash security feature allows you to authenticate transaction responses from the Authorize.Net. If you are accepting recurring payments then md5 hash will helps to validate response from Authorize.net. It can be obtained from Authorize.Net Account > Settings > Security Settings > General Settings > MD5 Hash.', 'invoicing'),
527 527
             'std' => '',
528 528
         );
529 529
         
530 530
     $setting['authorizenet_ipn_url'] = array(
531 531
             'type' => 'ipn_url',
532 532
             'id'   => 'authorizenet_ipn_url',
533
-            'name' => __( 'Silent Post URL', 'invoicing' ),
534
-            'std' => wpinv_get_ipn_url( 'authorizenet' ),
535
-            'desc' => __( 'If you are accepting recurring payments then you must set this url at Authorize.Net Account > Settings > Transaction Format Settings > Transaction Response Settings > Silent Post URL.', 'invoicing' ),
533
+            'name' => __('Silent Post URL', 'invoicing'),
534
+            'std' => wpinv_get_ipn_url('authorizenet'),
535
+            'desc' => __('If you are accepting recurring payments then you must set this url at Authorize.Net Account > Settings > Transaction Format Settings > Transaction Response Settings > Silent Post URL.', 'invoicing'),
536 536
             'size' => 'large',
537 537
             'custom' => 'authorizenet',
538 538
             'readonly' => true
@@ -540,25 +540,25 @@  discard block
 block discarded – undo
540 540
         
541 541
     return $setting;
542 542
 }
543
-add_filter( 'wpinv_gateway_settings_authorizenet', 'wpinv_gateway_settings_authorizenet', 10, 1 );
543
+add_filter('wpinv_gateway_settings_authorizenet', 'wpinv_gateway_settings_authorizenet', 10, 1);
544 544
 
545 545
 // Worldpay settings
546
-function wpinv_gateway_settings_worldpay( $setting ) {
547
-    $setting['worldpay_desc']['std'] = __( 'Pay using a Worldpay account to process credit card / debit card transactions.', 'invoicing' );
546
+function wpinv_gateway_settings_worldpay($setting) {
547
+    $setting['worldpay_desc']['std'] = __('Pay using a Worldpay account to process credit card / debit card transactions.', 'invoicing');
548 548
     
549 549
     $setting['worldpay_sandbox'] = array(
550 550
             'type' => 'checkbox',
551 551
             'id'   => 'worldpay_sandbox',
552
-            'name' => __( 'Worldpay Test Mode', 'invoicing' ),
553
-            'desc' => __( 'This provides a special Test Environment to enable you to test your installation and integration to your website before going live.', 'invoicing' ),
552
+            'name' => __('Worldpay Test Mode', 'invoicing'),
553
+            'desc' => __('This provides a special Test Environment to enable you to test your installation and integration to your website before going live.', 'invoicing'),
554 554
             'std'  => 1
555 555
         );
556 556
         
557 557
     $setting['worldpay_instId'] = array(
558 558
             'type' => 'text',
559 559
             'id'   => 'worldpay_instId',
560
-            'name' => __( 'Installation Id', 'invoicing' ),
561
-            'desc' => __( 'Your installation id. Ex: 211616', 'invoicing' ),
560
+            'name' => __('Installation Id', 'invoicing'),
561
+            'desc' => __('Your installation id. Ex: 211616', 'invoicing'),
562 562
             'std' => '211616',
563 563
         );
564 564
     /*
@@ -574,9 +574,9 @@  discard block
 block discarded – undo
574 574
     $setting['worldpay_ipn_url'] = array(
575 575
             'type' => 'ipn_url',
576 576
             'id'   => 'worldpay_ipn_url',
577
-            'name' => __( 'Worldpay Callback Url', 'invoicing' ),
578
-            'std' => wpinv_get_ipn_url( 'worldpay' ),
579
-            'desc' => wp_sprintf( __( 'Login to your Worldpay Merchant Interface then enable Payment Response & Shopper Response. Next, go to the Payment Response URL field and type "%s" or "%s" for a dynamic payment response.', 'invoicing' ), '<font style="color:#000;font-style:normal">' . wpinv_get_ipn_url( 'worldpay' ) . '</font>', '<font style="color:#000;font-style:normal">&lt;wpdisplay item=MC_callback&gt;</font>' ),
577
+            'name' => __('Worldpay Callback Url', 'invoicing'),
578
+            'std' => wpinv_get_ipn_url('worldpay'),
579
+            'desc' => wp_sprintf(__('Login to your Worldpay Merchant Interface then enable Payment Response & Shopper Response. Next, go to the Payment Response URL field and type "%s" or "%s" for a dynamic payment response.', 'invoicing'), '<font style="color:#000;font-style:normal">' . wpinv_get_ipn_url('worldpay') . '</font>', '<font style="color:#000;font-style:normal">&lt;wpdisplay item=MC_callback&gt;</font>'),
580 580
             'size' => 'large',
581 581
             'custom' => 'worldpay',
582 582
             'readonly' => true
@@ -584,95 +584,95 @@  discard block
 block discarded – undo
584 584
         
585 585
     return $setting;
586 586
 }
587
-add_filter( 'wpinv_gateway_settings_worldpay', 'wpinv_gateway_settings_worldpay', 10, 1 );
587
+add_filter('wpinv_gateway_settings_worldpay', 'wpinv_gateway_settings_worldpay', 10, 1);
588 588
 
589
-function wpinv_ipn_url_callback( $args ) {    
590
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
589
+function wpinv_ipn_url_callback($args) {    
590
+    $sanitize_id = wpinv_sanitize_key($args['id']);
591 591
     
592 592
     $attrs = $args['readonly'] ? ' readonly' : '';
593 593
 
594
-    $html = '<input style="background-color:#fefefe" type="text" ' . $attrs . ' value="' . esc_attr( $args['std'] ) . '" name="wpinv_settings[' . $sanitize_id . ']" id="wpinv_settings[' . $sanitize_id . ']" class="large-text">';
595
-    $html .= '<label for="wpinv_settings[' . $sanitize_id . ']">'  . $args['desc'] . '</label>';
594
+    $html = '<input style="background-color:#fefefe" type="text" ' . $attrs . ' value="' . esc_attr($args['std']) . '" name="wpinv_settings[' . $sanitize_id . ']" id="wpinv_settings[' . $sanitize_id . ']" class="large-text">';
595
+    $html .= '<label for="wpinv_settings[' . $sanitize_id . ']">' . $args['desc'] . '</label>';
596 596
 
597 597
     echo $html;
598 598
 }
599 599
 
600
-function wpinv_is_test_mode( $gateway = '' ) {
601
-    if ( empty( $gateway ) ) {
600
+function wpinv_is_test_mode($gateway = '') {
601
+    if (empty($gateway)) {
602 602
         return false;
603 603
     }
604 604
     
605
-    $is_test_mode = wpinv_get_option( $gateway . '_sandbox', false );
605
+    $is_test_mode = wpinv_get_option($gateway . '_sandbox', false);
606 606
     
607
-    return apply_filters( 'wpinv_is_test_mode', $is_test_mode, $gateway );
607
+    return apply_filters('wpinv_is_test_mode', $is_test_mode, $gateway);
608 608
 }
609 609
 
610
-function wpinv_get_ipn_url( $gateway = '', $args = array() ) {
611
-    $data = array( 'wpi-listener' => 'IPN' );
610
+function wpinv_get_ipn_url($gateway = '', $args = array()) {
611
+    $data = array('wpi-listener' => 'IPN');
612 612
     
613
-    if ( !empty( $gateway ) ) {
614
-        $data['wpi-gateway'] = wpinv_sanitize_key( $gateway );
613
+    if (!empty($gateway)) {
614
+        $data['wpi-gateway'] = wpinv_sanitize_key($gateway);
615 615
     }
616 616
     
617
-    $args = !empty( $args ) && is_array( $args ) ? array_merge( $data, $args ) : $data;
617
+    $args = !empty($args) && is_array($args) ? array_merge($data, $args) : $data;
618 618
     
619
-    $ipn_url = add_query_arg( $args,  home_url( 'index.php' ) );
619
+    $ipn_url = add_query_arg($args, home_url('index.php'));
620 620
     
621
-    return apply_filters( 'wpinv_ipn_url', $ipn_url );
621
+    return apply_filters('wpinv_ipn_url', $ipn_url);
622 622
 }
623 623
 
624 624
 function wpinv_listen_for_payment_ipn() {
625 625
     // Regular PayPal IPN
626
-    if ( isset( $_GET['wpi-listener'] ) && $_GET['wpi-listener'] == 'IPN' ) {
627
-        do_action( 'wpinv_verify_payment_ipn' );
626
+    if (isset($_GET['wpi-listener']) && $_GET['wpi-listener'] == 'IPN') {
627
+        do_action('wpinv_verify_payment_ipn');
628 628
         
629
-        if ( !empty( $_GET['wpi-gateway'] ) ) {
630
-            wpinv_error_log( sanitize_text_field( $_GET['wpi-gateway'] ), 'wpinv_listen_for_payment_ipn()', __FILE__, __LINE__ );
631
-            do_action( 'wpinv_verify_' . sanitize_text_field( $_GET['wpi-gateway'] ) . '_ipn' );
629
+        if (!empty($_GET['wpi-gateway'])) {
630
+            wpinv_error_log(sanitize_text_field($_GET['wpi-gateway']), 'wpinv_listen_for_payment_ipn()', __FILE__, __LINE__);
631
+            do_action('wpinv_verify_' . sanitize_text_field($_GET['wpi-gateway']) . '_ipn');
632 632
         }
633 633
     }
634 634
 }
635
-add_action( 'init', 'wpinv_listen_for_payment_ipn' );
635
+add_action('init', 'wpinv_listen_for_payment_ipn');
636 636
 
637 637
 function wpinv_get_bank_instructions() {
638
-    $bank_instructions = wpinv_get_option( 'bank_transfer_info' );
638
+    $bank_instructions = wpinv_get_option('bank_transfer_info');
639 639
     
640
-    return apply_filters( 'wpinv_bank_instructions', $bank_instructions );
640
+    return apply_filters('wpinv_bank_instructions', $bank_instructions);
641 641
 }
642 642
 
643
-function wpinv_get_bank_info( $filtered = false ) {
643
+function wpinv_get_bank_info($filtered = false) {
644 644
     $bank_fields = array(
645
-        'bank_transfer_ac_name'     => __( 'Account Name', 'invoicing' ),
646
-        'bank_transfer_ac_no'       => __( 'Account Number', 'invoicing' ),
647
-        'bank_transfer_bank_name'   => __( 'Bank Name', 'invoicing' ),
648
-        'bank_transfer_ifsc'        => __( 'IFSC code', 'invoicing' ),
649
-        'bank_transfer_iban'        => __( 'IBAN', 'invoicing' ),
650
-        'bank_transfer_bic'         => __( 'BIC/Swift code', 'invoicing' ),
651
-        'bank_transfer_sort_code'   => __( 'Sort Code', 'invoicing' )
645
+        'bank_transfer_ac_name'     => __('Account Name', 'invoicing'),
646
+        'bank_transfer_ac_no'       => __('Account Number', 'invoicing'),
647
+        'bank_transfer_bank_name'   => __('Bank Name', 'invoicing'),
648
+        'bank_transfer_ifsc'        => __('IFSC code', 'invoicing'),
649
+        'bank_transfer_iban'        => __('IBAN', 'invoicing'),
650
+        'bank_transfer_bic'         => __('BIC/Swift code', 'invoicing'),
651
+        'bank_transfer_sort_code'   => __('Sort Code', 'invoicing')
652 652
     );
653 653
     
654 654
     $bank_info = array();
655
-    foreach ( $bank_fields as $field => $label ) {
656
-        if ( $filtered && !( $value = wpinv_get_option( $field ) ) ) {
655
+    foreach ($bank_fields as $field => $label) {
656
+        if ($filtered && !($value = wpinv_get_option($field))) {
657 657
             continue;
658 658
         }
659 659
         
660
-        $bank_info[$field] = array( 'label' => $label, 'value' => $value );
660
+        $bank_info[$field] = array('label' => $label, 'value' => $value);
661 661
     }
662 662
     
663
-    return apply_filters( 'wpinv_bank_info', $bank_info, $filtered );
663
+    return apply_filters('wpinv_bank_info', $bank_info, $filtered);
664 664
 }
665 665
 
666
-function wpinv_process_before_send_to_gateway( $invoice, $invoice_data = array() ) {
667
-    if ( !empty( $invoice ) && $invoice->is_recurring() && $subscription_item = $invoice->get_recurring( true ) ) {        
666
+function wpinv_process_before_send_to_gateway($invoice, $invoice_data = array()) {
667
+    if (!empty($invoice) && $invoice->is_recurring() && $subscription_item = $invoice->get_recurring(true)) {        
668 668
         $args                          = array();
669 669
         $args['item_id']               = $subscription_item->ID;
670
-        $args['initial_amount']        = wpinv_round_amount( $invoice->get_total() );
671
-        $args['recurring_amount']      = wpinv_round_amount( $invoice->get_recurring_details( 'total' ) );
670
+        $args['initial_amount']        = wpinv_round_amount($invoice->get_total());
671
+        $args['recurring_amount']      = wpinv_round_amount($invoice->get_recurring_details('total'));
672 672
         $args['currency']              = $invoice->get_currency();
673 673
         $args['period']                = $subscription_item->get_recurring_period();
674 674
         $args['interval']              = $subscription_item->get_recurring_interval();
675
-        if ( $subscription_item->has_free_trial() ) {
675
+        if ($subscription_item->has_free_trial()) {
676 676
             $args['trial_period']      = $subscription_item->get_trial_period();
677 677
             $args['trial_interval']    = $subscription_item->get_trial_interval();
678 678
         } else {
@@ -681,25 +681,25 @@  discard block
 block discarded – undo
681 681
         }
682 682
         $args['bill_times']            = (int)$subscription_item->get_recurring_limit();
683 683
         
684
-        $invoice->update_subscription( $args );
684
+        $invoice->update_subscription($args);
685 685
     }
686 686
 }
687
-add_action( 'wpinv_checkout_before_send_to_gateway', 'wpinv_process_before_send_to_gateway', 10, 2 );
687
+add_action('wpinv_checkout_before_send_to_gateway', 'wpinv_process_before_send_to_gateway', 10, 2);
688 688
 
689
-function wpinv_get_post_data( $method = 'request' ) {
689
+function wpinv_get_post_data($method = 'request') {
690 690
     $data       = array();
691 691
     $request    = $_REQUEST;
692 692
     
693
-    if ( $method == 'post' ) {
694
-        if ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] != 'POST' ) {
693
+    if ($method == 'post') {
694
+        if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] != 'POST') {
695 695
             return $data;
696 696
         }
697 697
         
698 698
         $request = $_POST;
699 699
     }
700 700
     
701
-    if ( $method == 'get' ) {
702
-        if ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] != 'GET' ) {
701
+    if ($method == 'get') {
702
+        if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] != 'GET') {
703 703
             return $data;
704 704
         }
705 705
         
@@ -710,11 +710,11 @@  discard block
 block discarded – undo
710 710
     $post_data = '';
711 711
     
712 712
     // Fallback just in case post_max_size is lower than needed
713
-    if ( ini_get( 'allow_url_fopen' ) ) {
714
-        $post_data = file_get_contents( 'php://input' );
713
+    if (ini_get('allow_url_fopen')) {
714
+        $post_data = file_get_contents('php://input');
715 715
     } else {
716 716
         // If allow_url_fopen is not enabled, then make sure that post_max_size is large enough
717
-        ini_set( 'post_max_size', '12M' );
717
+        ini_set('post_max_size', '12M');
718 718
     }
719 719
     // Start the encoded data collection with notification command
720 720
     $encoded_data = 'cmd=_notify-validate';
@@ -723,58 +723,58 @@  discard block
 block discarded – undo
723 723
     $arg_separator = wpinv_get_php_arg_separator_output();
724 724
 
725 725
     // Verify there is a post_data
726
-    if ( $post_data || strlen( $post_data ) > 0 ) {
726
+    if ($post_data || strlen($post_data) > 0) {
727 727
         // Append the data
728 728
         $encoded_data .= $arg_separator . $post_data;
729 729
     } else {
730 730
         // Check if POST is empty
731
-        if ( empty( $request ) ) {
731
+        if (empty($request)) {
732 732
             // Nothing to do
733 733
             return;
734 734
         } else {
735 735
             // Loop through each POST
736
-            foreach ( $request as $key => $value ) {
736
+            foreach ($request as $key => $value) {
737 737
                 // Encode the value and append the data
738
-                $encoded_data .= $arg_separator . "$key=" . urlencode( $value );
738
+                $encoded_data .= $arg_separator . "$key=" . urlencode($value);
739 739
             }
740 740
         }
741 741
     }
742 742
 
743 743
     // Convert collected post data to an array
744
-    parse_str( $encoded_data, $data );
744
+    parse_str($encoded_data, $data);
745 745
 
746
-    foreach ( $data as $key => $value ) {
747
-        if ( false !== strpos( $key, 'amp;' ) ) {
748
-            $new_key = str_replace( '&amp;', '&', $key );
749
-            $new_key = str_replace( 'amp;', '&' , $new_key );
746
+    foreach ($data as $key => $value) {
747
+        if (false !== strpos($key, 'amp;')) {
748
+            $new_key = str_replace('&amp;', '&', $key);
749
+            $new_key = str_replace('amp;', '&', $new_key);
750 750
 
751
-            unset( $data[ $key ] );
752
-            $data[ $new_key ] = sanitize_text_field( $value );
751
+            unset($data[$key]);
752
+            $data[$new_key] = sanitize_text_field($value);
753 753
         }
754 754
     }
755 755
     
756 756
     return $data;
757 757
 }
758 758
 
759
-function wpinv_gateway_support_subscription( $gateway ) {
759
+function wpinv_gateway_support_subscription($gateway) {
760 760
     $return = false;
761 761
     
762
-    if ( wpinv_is_gateway_active( $gateway ) ) {
763
-        $return = apply_filters( 'wpinv_' . $gateway . '_support_subscription', false );
762
+    if (wpinv_is_gateway_active($gateway)) {
763
+        $return = apply_filters('wpinv_' . $gateway . '_support_subscription', false);
764 764
     }
765 765
     
766 766
     return $return;
767 767
 }
768 768
 
769
-function wpinv_payment_gateways_on_cart( $gateways = array() ) {
770
-    if ( !empty( $gateways ) && wpinv_cart_has_recurring_item() ) {
771
-        foreach ( $gateways as $gateway => $info ) {
772
-            if ( !wpinv_gateway_support_subscription( $gateway ) ) {
773
-                unset( $gateways[$gateway] );
769
+function wpinv_payment_gateways_on_cart($gateways = array()) {
770
+    if (!empty($gateways) && wpinv_cart_has_recurring_item()) {
771
+        foreach ($gateways as $gateway => $info) {
772
+            if (!wpinv_gateway_support_subscription($gateway)) {
773
+                unset($gateways[$gateway]);
774 774
             }
775 775
         }
776 776
     }
777 777
     
778 778
     return $gateways;
779 779
 }
780
-add_filter( 'wpinv_payment_gateways_on_cart', 'wpinv_payment_gateways_on_cart', 10, 1 );
781 780
\ No newline at end of file
781
+add_filter('wpinv_payment_gateways_on_cart', 'wpinv_payment_gateways_on_cart', 10, 1);
782 782
\ No newline at end of file
Please login to merge, or discard this patch.
includes/wpinv-template-functions.php 1 patch
Spacing   +696 added lines, -696 removed lines patch added patch discarded remove patch
@@ -7,101 +7,101 @@  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; // Exit if invoice is not set.
56 56
     }
57 57
     
58
-    if ( $invoice->post_type == 'wpi_invoice' ) {
59
-        if ( $invoice->needs_payment() ) {
60
-            ?> <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><?php
58
+    if ($invoice->post_type == 'wpi_invoice') {
59
+        if ($invoice->needs_payment()) {
60
+            ?> <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><?php
61 61
         }
62 62
     }
63 63
     do_action('wpinv_invoice_display_left_actions', $invoice);
64 64
 }
65 65
 
66
-function wpinv_invoice_display_right_actions( $invoice ) {
67
-    if ( empty( $invoice ) ) {
66
+function wpinv_invoice_display_right_actions($invoice) {
67
+    if (empty($invoice)) {
68 68
         return; // Exit if invoice is not set.
69 69
     }
70 70
 
71
-    if ( $invoice->post_type == 'wpi_invoice' ) { ?>
72
-        <a class="btn btn-primary btn-sm" onclick="window.print();" href="javascript:void(0)"><?php _e( 'Print Invoice', 'invoicing' ); ?></a>
73
-        <?php if ( is_user_logged_in() ) { ?>
74
-        &nbsp;&nbsp;<a class="btn btn-warning btn-sm" href="<?php echo esc_url( wpinv_get_history_page_uri() ); ?>"><?php _e( 'Invoice History', 'invoicing' ); ?></a>
71
+    if ($invoice->post_type == 'wpi_invoice') { ?>
72
+        <a class="btn btn-primary btn-sm" onclick="window.print();" href="javascript:void(0)"><?php _e('Print Invoice', 'invoicing'); ?></a>
73
+        <?php if (is_user_logged_in()) { ?>
74
+        &nbsp;&nbsp;<a class="btn btn-warning btn-sm" href="<?php echo esc_url(wpinv_get_history_page_uri()); ?>"><?php _e('Invoice History', 'invoicing'); ?></a>
75 75
         <?php }
76 76
     }
77 77
     do_action('wpinv_invoice_display_right_actions', $invoice);
78 78
 }
79 79
 
80
-function wpinv_before_invoice_content( $content ) {
80
+function wpinv_before_invoice_content($content) {
81 81
     global $post;
82 82
 
83
-    if ( !empty( $post ) && $post->post_type == 'wpi_invoice' && is_singular( 'wpi_invoice' ) && is_main_query() ) {
83
+    if (!empty($post) && $post->post_type == 'wpi_invoice' && is_singular('wpi_invoice') && is_main_query()) {
84 84
         ob_start();
85
-        do_action( 'wpinv_before_invoice_content', $post->ID );
85
+        do_action('wpinv_before_invoice_content', $post->ID);
86 86
         $content = ob_get_clean() . $content;
87 87
     }
88 88
 
89 89
     return $content;
90 90
 }
91
-add_filter( 'the_content', 'wpinv_before_invoice_content' );
91
+add_filter('the_content', 'wpinv_before_invoice_content');
92 92
 
93
-function wpinv_after_invoice_content( $content ) {
93
+function wpinv_after_invoice_content($content) {
94 94
     global $post;
95 95
 
96
-    if ( !empty( $post ) && $post->post_type == 'wpi_invoice' && is_singular( 'wpi_invoice' ) && is_main_query() ) {
96
+    if (!empty($post) && $post->post_type == 'wpi_invoice' && is_singular('wpi_invoice') && is_main_query()) {
97 97
         ob_start();
98
-        do_action( 'wpinv_after_invoice_content', $post->ID );
98
+        do_action('wpinv_after_invoice_content', $post->ID);
99 99
         $content .= ob_get_clean();
100 100
     }
101 101
 
102 102
     return $content;
103 103
 }
104
-add_filter( 'the_content', 'wpinv_after_invoice_content' );
104
+add_filter('the_content', 'wpinv_after_invoice_content');
105 105
 
106 106
 function wpinv_get_templates_dir() {
107 107
     return WPINV_PLUGIN_DIR . 'templates';
@@ -111,105 +111,105 @@  discard block
 block discarded – undo
111 111
     return WPINV_PLUGIN_URL . 'templates';
112 112
 }
113 113
 
114
-function wpinv_get_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) {
115
-    if ( ! empty( $args ) && is_array( $args ) ) {
116
-		extract( $args );
114
+function wpinv_get_template($template_name, $args = array(), $template_path = '', $default_path = '') {
115
+    if (!empty($args) && is_array($args)) {
116
+		extract($args);
117 117
 	}
118 118
 
119
-	$located = wpinv_locate_template( $template_name, $template_path, $default_path );
119
+	$located = wpinv_locate_template($template_name, $template_path, $default_path);
120 120
 	// Allow 3rd party plugin filter template file from their plugin.
121
-	$located = apply_filters( 'wpinv_get_template', $located, $template_name, $args, $template_path, $default_path );
121
+	$located = apply_filters('wpinv_get_template', $located, $template_name, $args, $template_path, $default_path);
122 122
 
123
-	if ( ! file_exists( $located ) ) {
124
-        _doing_it_wrong( __FUNCTION__, sprintf( '<code>%s</code> does not exist.', $located ), '2.1' );
123
+	if (!file_exists($located)) {
124
+        _doing_it_wrong(__FUNCTION__, sprintf('<code>%s</code> does not exist.', $located), '2.1');
125 125
 		return;
126 126
 	}
127 127
 
128
-	do_action( 'wpinv_before_template_part', $template_name, $template_path, $located, $args );
128
+	do_action('wpinv_before_template_part', $template_name, $template_path, $located, $args);
129 129
 
130
-	include( $located );
130
+	include($located);
131 131
 
132
-	do_action( 'wpinv_after_template_part', $template_name, $template_path, $located, $args );
132
+	do_action('wpinv_after_template_part', $template_name, $template_path, $located, $args);
133 133
 }
134 134
 
135
-function wpinv_get_template_html( $template_name, $args = array(), $template_path = '', $default_path = '' ) {
135
+function wpinv_get_template_html($template_name, $args = array(), $template_path = '', $default_path = '') {
136 136
 	ob_start();
137
-	wpinv_get_template( $template_name, $args, $template_path, $default_path );
137
+	wpinv_get_template($template_name, $args, $template_path, $default_path);
138 138
 	return ob_get_clean();
139 139
 }
140 140
 
141
-function wpinv_locate_template( $template_name, $template_path = '', $default_path = '' ) {
142
-    if ( ! $template_path ) {
141
+function wpinv_locate_template($template_name, $template_path = '', $default_path = '') {
142
+    if (!$template_path) {
143 143
         $template_path = wpinv_template_path();
144 144
     }
145 145
 
146
-    if ( ! $default_path ) {
146
+    if (!$default_path) {
147 147
         $default_path = WPINV_PLUGIN_DIR . 'templates/';
148 148
     }
149 149
 
150 150
     // Look within passed path within the theme - this is priority.
151 151
     $template = locate_template(
152 152
         array(
153
-            trailingslashit( $template_path ) . $template_name,
153
+            trailingslashit($template_path) . $template_name,
154 154
             $template_name
155 155
         )
156 156
     );
157 157
 
158 158
     // Get default templates/
159
-    if ( !$template && $default_path ) {
160
-        $template = trailingslashit( $default_path ) . $template_name;
159
+    if (!$template && $default_path) {
160
+        $template = trailingslashit($default_path) . $template_name;
161 161
     }
162 162
 
163 163
     // Return what we found.
164
-    return apply_filters( 'wpinv_locate_template', $template, $template_name, $template_path );
164
+    return apply_filters('wpinv_locate_template', $template, $template_name, $template_path);
165 165
 }
166 166
 
167
-function wpinv_get_template_part( $slug, $name = null, $load = true ) {
168
-	do_action( 'get_template_part_' . $slug, $slug, $name );
167
+function wpinv_get_template_part($slug, $name = null, $load = true) {
168
+	do_action('get_template_part_' . $slug, $slug, $name);
169 169
 
170 170
 	// Setup possible parts
171 171
 	$templates = array();
172
-	if ( isset( $name ) )
172
+	if (isset($name))
173 173
 		$templates[] = $slug . '-' . $name . '.php';
174 174
 	$templates[] = $slug . '.php';
175 175
 
176 176
 	// Allow template parts to be filtered
177
-	$templates = apply_filters( 'wpinv_get_template_part', $templates, $slug, $name );
177
+	$templates = apply_filters('wpinv_get_template_part', $templates, $slug, $name);
178 178
 
179 179
 	// Return the part that is found
180
-	return wpinv_locate_tmpl( $templates, $load, false );
180
+	return wpinv_locate_tmpl($templates, $load, false);
181 181
 }
182 182
 
183
-function wpinv_locate_tmpl( $template_names, $load = false, $require_once = true ) {
183
+function wpinv_locate_tmpl($template_names, $load = false, $require_once = true) {
184 184
 	// No file found yet
185 185
 	$located = false;
186 186
 
187 187
 	// Try to find a template file
188
-	foreach ( (array)$template_names as $template_name ) {
188
+	foreach ((array)$template_names as $template_name) {
189 189
 
190 190
 		// Continue if template is empty
191
-		if ( empty( $template_name ) )
191
+		if (empty($template_name))
192 192
 			continue;
193 193
 
194 194
 		// Trim off any slashes from the template name
195
-		$template_name = ltrim( $template_name, '/' );
195
+		$template_name = ltrim($template_name, '/');
196 196
 
197 197
 		// try locating this template file by looping through the template paths
198
-		foreach( wpinv_get_theme_template_paths() as $template_path ) {
198
+		foreach (wpinv_get_theme_template_paths() as $template_path) {
199 199
 
200
-			if( file_exists( $template_path . $template_name ) ) {
200
+			if (file_exists($template_path . $template_name)) {
201 201
 				$located = $template_path . $template_name;
202 202
 				break;
203 203
 			}
204 204
 		}
205 205
 
206
-		if( !empty( $located ) ) {
206
+		if (!empty($located)) {
207 207
 			break;
208 208
 		}
209 209
 	}
210 210
 
211
-	if ( ( true == $load ) && ! empty( $located ) )
212
-		load_template( $located, $require_once );
211
+	if ((true == $load) && !empty($located))
212
+		load_template($located, $require_once);
213 213
 
214 214
 	return $located;
215 215
 }
@@ -218,143 +218,143 @@  discard block
 block discarded – undo
218 218
 	$template_dir = wpinv_get_theme_template_dir_name();
219 219
 
220 220
 	$file_paths = array(
221
-		1 => trailingslashit( get_stylesheet_directory() ) . $template_dir,
222
-		10 => trailingslashit( get_template_directory() ) . $template_dir,
221
+		1 => trailingslashit(get_stylesheet_directory()) . $template_dir,
222
+		10 => trailingslashit(get_template_directory()) . $template_dir,
223 223
 		100 => wpinv_get_templates_dir()
224 224
 	);
225 225
 
226
-	$file_paths = apply_filters( 'wpinv_template_paths', $file_paths );
226
+	$file_paths = apply_filters('wpinv_template_paths', $file_paths);
227 227
 
228 228
 	// sort the file paths based on priority
229
-	ksort( $file_paths, SORT_NUMERIC );
229
+	ksort($file_paths, SORT_NUMERIC);
230 230
 
231
-	return array_map( 'trailingslashit', $file_paths );
231
+	return array_map('trailingslashit', $file_paths);
232 232
 }
233 233
 
234 234
 function wpinv_get_theme_template_dir_name() {
235
-	return trailingslashit( apply_filters( 'wpinv_templates_dir', 'wpinv_templates' ) );
235
+	return trailingslashit(apply_filters('wpinv_templates_dir', 'wpinv_templates'));
236 236
 }
237 237
 
238 238
 function wpinv_checkout_meta_tags() {
239 239
 
240 240
 	$pages   = array();
241
-	$pages[] = wpinv_get_option( 'success_page' );
242
-	$pages[] = wpinv_get_option( 'failure_page' );
243
-	$pages[] = wpinv_get_option( 'invoice_history_page' );
241
+	$pages[] = wpinv_get_option('success_page');
242
+	$pages[] = wpinv_get_option('failure_page');
243
+	$pages[] = wpinv_get_option('invoice_history_page');
244 244
 
245
-	if( !wpinv_is_checkout() && !is_page( $pages ) ) {
245
+	if (!wpinv_is_checkout() && !is_page($pages)) {
246 246
 		return;
247 247
 	}
248 248
 
249 249
 	echo '<meta name="robots" content="noindex,nofollow" />' . "\n";
250 250
 }
251
-add_action( 'wp_head', 'wpinv_checkout_meta_tags' );
251
+add_action('wp_head', 'wpinv_checkout_meta_tags');
252 252
 
253
-function wpinv_add_body_classes( $class ) {
253
+function wpinv_add_body_classes($class) {
254 254
 	$classes = (array)$class;
255 255
 
256
-	if( wpinv_is_checkout() ) {
256
+	if (wpinv_is_checkout()) {
257 257
 		$classes[] = 'wpinv-checkout';
258 258
 		$classes[] = 'wpinv-page';
259 259
 	}
260 260
 
261
-	if( wpinv_is_success_page() ) {
261
+	if (wpinv_is_success_page()) {
262 262
 		$classes[] = 'wpinv-success';
263 263
 		$classes[] = 'wpinv-page';
264 264
 	}
265 265
 
266
-	if( wpinv_is_failed_transaction_page() ) {
266
+	if (wpinv_is_failed_transaction_page()) {
267 267
 		$classes[] = 'wpinv-failed-transaction';
268 268
 		$classes[] = 'wpinv-page';
269 269
 	}
270 270
 
271
-	if( wpinv_is_invoice_history_page() ) {
271
+	if (wpinv_is_invoice_history_page()) {
272 272
 		$classes[] = 'wpinv-history';
273 273
 		$classes[] = 'wpinv-page';
274 274
 	}
275 275
 
276
-	if( wpinv_is_test_mode() ) {
276
+	if (wpinv_is_test_mode()) {
277 277
 		$classes[] = 'wpinv-test-mode';
278 278
 		$classes[] = 'wpinv-page';
279 279
 	}
280 280
 
281
-	return array_unique( $classes );
281
+	return array_unique($classes);
282 282
 }
283
-add_filter( 'body_class', 'wpinv_add_body_classes' );
283
+add_filter('body_class', 'wpinv_add_body_classes');
284 284
 
285
-function wpinv_html_dropdown( $name = 'wpinv_discounts', $selected = 0, $status = '' ) {
286
-    $args = array( 'nopaging' => true );
285
+function wpinv_html_dropdown($name = 'wpinv_discounts', $selected = 0, $status = '') {
286
+    $args = array('nopaging' => true);
287 287
 
288
-    if ( ! empty( $status ) )
288
+    if (!empty($status))
289 289
         $args['post_status'] = $status;
290 290
 
291
-    $discounts = wpinv_get_discounts( $args );
291
+    $discounts = wpinv_get_discounts($args);
292 292
     $options   = array();
293 293
 
294
-    if ( $discounts ) {
295
-        foreach ( $discounts as $discount ) {
296
-            $options[ absint( $discount->ID ) ] = esc_html( get_the_title( $discount->ID ) );
294
+    if ($discounts) {
295
+        foreach ($discounts as $discount) {
296
+            $options[absint($discount->ID)] = esc_html(get_the_title($discount->ID));
297 297
         }
298 298
     } else {
299
-        $options[0] = __( 'No discounts found', 'invoicing' );
299
+        $options[0] = __('No discounts found', 'invoicing');
300 300
     }
301 301
 
302
-    $output = wpinv_html_select( array(
302
+    $output = wpinv_html_select(array(
303 303
         'name'             => $name,
304 304
         'selected'         => $selected,
305 305
         'options'          => $options,
306 306
         'show_option_all'  => false,
307 307
         'show_option_none' => false,
308
-    ) );
308
+    ));
309 309
 
310 310
     return $output;
311 311
 }
312 312
 
313
-function wpinv_html_year_dropdown( $name = 'year', $selected = 0, $years_before = 5, $years_after = 0 ) {
314
-    $current     = date( 'Y' );
315
-    $start_year  = $current - absint( $years_before );
316
-    $end_year    = $current + absint( $years_after );
317
-    $selected    = empty( $selected ) ? date( 'Y' ) : $selected;
313
+function wpinv_html_year_dropdown($name = 'year', $selected = 0, $years_before = 5, $years_after = 0) {
314
+    $current     = date('Y');
315
+    $start_year  = $current - absint($years_before);
316
+    $end_year    = $current + absint($years_after);
317
+    $selected    = empty($selected) ? date('Y') : $selected;
318 318
     $options     = array();
319 319
 
320
-    while ( $start_year <= $end_year ) {
321
-        $options[ absint( $start_year ) ] = $start_year;
320
+    while ($start_year <= $end_year) {
321
+        $options[absint($start_year)] = $start_year;
322 322
         $start_year++;
323 323
     }
324 324
 
325
-    $output = wpinv_html_select( array(
325
+    $output = wpinv_html_select(array(
326 326
         'name'             => $name,
327 327
         'selected'         => $selected,
328 328
         'options'          => $options,
329 329
         'show_option_all'  => false,
330 330
         'show_option_none' => false
331
-    ) );
331
+    ));
332 332
 
333 333
     return $output;
334 334
 }
335 335
 
336
-function wpinv_html_month_dropdown( $name = 'month', $selected = 0 ) {
336
+function wpinv_html_month_dropdown($name = 'month', $selected = 0) {
337 337
     $month   = 1;
338 338
     $options = array();
339
-    $selected = empty( $selected ) ? date( 'n' ) : $selected;
339
+    $selected = empty($selected) ? date('n') : $selected;
340 340
 
341
-    while ( $month <= 12 ) {
342
-        $options[ absint( $month ) ] = wpinv_month_num_to_name( $month );
341
+    while ($month <= 12) {
342
+        $options[absint($month)] = wpinv_month_num_to_name($month);
343 343
         $month++;
344 344
     }
345 345
 
346
-    $output = wpinv_html_select( array(
346
+    $output = wpinv_html_select(array(
347 347
         'name'             => $name,
348 348
         'selected'         => $selected,
349 349
         'options'          => $options,
350 350
         'show_option_all'  => false,
351 351
         'show_option_none' => false
352
-    ) );
352
+    ));
353 353
 
354 354
     return $output;
355 355
 }
356 356
 
357
-function wpinv_html_select( $args = array() ) {
357
+function wpinv_html_select($args = array()) {
358 358
     $defaults = array(
359 359
         'options'          => array(),
360 360
         'name'             => null,
@@ -364,8 +364,8 @@  discard block
 block discarded – undo
364 364
         'chosen'           => false,
365 365
         'placeholder'      => null,
366 366
         'multiple'         => false,
367
-        'show_option_all'  => _x( 'All', 'all dropdown items', 'invoicing' ),
368
-        'show_option_none' => _x( 'None', 'no dropdown items', 'invoicing' ),
367
+        'show_option_all'  => _x('All', 'all dropdown items', 'invoicing'),
368
+        'show_option_none' => _x('None', 'no dropdown items', 'invoicing'),
369 369
         'data'             => array(),
370 370
         'onchange'         => null,
371 371
         'required'         => false,
@@ -373,78 +373,78 @@  discard block
 block discarded – undo
373 373
         'readonly'         => false,
374 374
     );
375 375
 
376
-    $args = wp_parse_args( $args, $defaults );
376
+    $args = wp_parse_args($args, $defaults);
377 377
 
378 378
     $data_elements = '';
379
-    foreach ( $args['data'] as $key => $value ) {
380
-        $data_elements .= ' data-' . esc_attr( $key ) . '="' . esc_attr( $value ) . '"';
379
+    foreach ($args['data'] as $key => $value) {
380
+        $data_elements .= ' data-' . esc_attr($key) . '="' . esc_attr($value) . '"';
381 381
     }
382 382
 
383
-    if( $args['multiple'] ) {
383
+    if ($args['multiple']) {
384 384
         $multiple = ' MULTIPLE';
385 385
     } else {
386 386
         $multiple = '';
387 387
     }
388 388
 
389
-    if( $args['chosen'] ) {
389
+    if ($args['chosen']) {
390 390
         $args['class'] .= ' wpinv-select-chosen';
391 391
     }
392 392
 
393
-    if( $args['placeholder'] ) {
393
+    if ($args['placeholder']) {
394 394
         $placeholder = $args['placeholder'];
395 395
     } else {
396 396
         $placeholder = '';
397 397
     }
398 398
     
399 399
     $options = '';
400
-    if( !empty( $args['onchange'] ) ) {
401
-        $options .= ' onchange="' . esc_attr( $args['onchange'] ) . '"';
400
+    if (!empty($args['onchange'])) {
401
+        $options .= ' onchange="' . esc_attr($args['onchange']) . '"';
402 402
     }
403 403
     
404
-    if( !empty( $args['required'] ) ) {
404
+    if (!empty($args['required'])) {
405 405
         $options .= ' required="required"';
406 406
     }
407 407
     
408
-    if( !empty( $args['disabled'] ) ) {
408
+    if (!empty($args['disabled'])) {
409 409
         $options .= ' disabled';
410 410
     }
411 411
     
412
-    if( !empty( $args['readonly'] ) ) {
412
+    if (!empty($args['readonly'])) {
413 413
         $options .= ' readonly';
414 414
     }
415 415
 
416
-    $class  = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) );
417
-    $output = '<select name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['id'] ) . '" class="wpinv-select ' . $class . '"' . $multiple . ' data-placeholder="' . $placeholder . '" ' . trim( $options ) . $data_elements . '>';
416
+    $class  = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class'])));
417
+    $output = '<select name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['id']) . '" class="wpinv-select ' . $class . '"' . $multiple . ' data-placeholder="' . $placeholder . '" ' . trim($options) . $data_elements . '>';
418 418
 
419
-    if ( $args['show_option_all'] ) {
420
-        if( $args['multiple'] ) {
421
-            $selected = selected( true, in_array( 0, $args['selected'] ), false );
419
+    if ($args['show_option_all']) {
420
+        if ($args['multiple']) {
421
+            $selected = selected(true, in_array(0, $args['selected']), false);
422 422
         } else {
423
-            $selected = selected( $args['selected'], 0, false );
423
+            $selected = selected($args['selected'], 0, false);
424 424
         }
425
-        $output .= '<option value="all"' . $selected . '>' . esc_html( $args['show_option_all'] ) . '</option>';
425
+        $output .= '<option value="all"' . $selected . '>' . esc_html($args['show_option_all']) . '</option>';
426 426
     }
427 427
 
428
-    if ( !empty( $args['options'] ) ) {
428
+    if (!empty($args['options'])) {
429 429
 
430
-        if ( $args['show_option_none'] ) {
431
-            if( $args['multiple'] ) {
432
-                $selected = selected( true, in_array( "", $args['selected'] ), false );
430
+        if ($args['show_option_none']) {
431
+            if ($args['multiple']) {
432
+                $selected = selected(true, in_array("", $args['selected']), false);
433 433
             } else {
434
-                $selected = selected( $args['selected'] === "", true, false );
434
+                $selected = selected($args['selected'] === "", true, false);
435 435
             }
436
-            $output .= '<option value=""' . $selected . '>' . esc_html( $args['show_option_none'] ) . '</option>';
436
+            $output .= '<option value=""' . $selected . '>' . esc_html($args['show_option_none']) . '</option>';
437 437
         }
438 438
 
439
-        foreach( $args['options'] as $key => $option ) {
439
+        foreach ($args['options'] as $key => $option) {
440 440
 
441
-            if( $args['multiple'] && is_array( $args['selected'] ) ) {
442
-                $selected = selected( true, (bool)in_array( $key, $args['selected'] ), false );
441
+            if ($args['multiple'] && is_array($args['selected'])) {
442
+                $selected = selected(true, (bool)in_array($key, $args['selected']), false);
443 443
             } else {
444
-                $selected = selected( $args['selected'], $key, false );
444
+                $selected = selected($args['selected'], $key, false);
445 445
             }
446 446
 
447
-            $output .= '<option value="' . esc_attr( $key ) . '"' . $selected . '>' . esc_html( $option ) . '</option>';
447
+            $output .= '<option value="' . esc_attr($key) . '"' . $selected . '>' . esc_html($option) . '</option>';
448 448
         }
449 449
     }
450 450
 
@@ -453,7 +453,7 @@  discard block
 block discarded – undo
453 453
     return $output;
454 454
 }
455 455
 
456
-function wpinv_item_dropdown( $args = array() ) {
456
+function wpinv_item_dropdown($args = array()) {
457 457
     $defaults = array(
458 458
         'name'              => 'wpi_item',
459 459
         'id'                => 'wpi_item',
@@ -462,15 +462,15 @@  discard block
 block discarded – undo
462 462
         'selected'          => 0,
463 463
         'chosen'            => false,
464 464
         'number'            => 100,
465
-        'placeholder'       => __( 'Choose a item', 'invoicing' ),
466
-        'data'              => array( 'search-type' => 'item' ),
465
+        'placeholder'       => __('Choose a item', 'invoicing'),
466
+        'data'              => array('search-type' => 'item'),
467 467
         'show_option_all'   => false,
468 468
         'show_option_none'  => false,
469 469
         'with_packages'     => true,
470 470
         'show_recurring'    => false,
471 471
     );
472 472
 
473
-    $args = wp_parse_args( $args, $defaults );
473
+    $args = wp_parse_args($args, $defaults);
474 474
 
475 475
     $item_args = array(
476 476
         'post_type'      => 'wpi_item',
@@ -479,7 +479,7 @@  discard block
 block discarded – undo
479 479
         'posts_per_page' => $args['number']
480 480
     );
481 481
     
482
-    if ( !$args['with_packages'] ) {
482
+    if (!$args['with_packages']) {
483 483
         $item_args['meta_query'] = array(
484 484
             array(
485 485
                 'key'       => '_wpinv_type',
@@ -489,42 +489,42 @@  discard block
 block discarded – undo
489 489
         );
490 490
     }
491 491
 
492
-    $items      = get_posts( $item_args );
492
+    $items      = get_posts($item_args);
493 493
     $options    = array();
494
-    if ( $items ) {
495
-        foreach ( $items as $item ) {
496
-            $title = esc_html( $item->post_title );
494
+    if ($items) {
495
+        foreach ($items as $item) {
496
+            $title = esc_html($item->post_title);
497 497
             
498
-            if ( !empty( $args['show_recurring'] ) ) {
499
-                $title .= wpinv_get_item_suffix( $item->ID, false );
498
+            if (!empty($args['show_recurring'])) {
499
+                $title .= wpinv_get_item_suffix($item->ID, false);
500 500
             }
501 501
             
502
-            $options[ absint( $item->ID ) ] = $title;
502
+            $options[absint($item->ID)] = $title;
503 503
         }
504 504
     }
505 505
 
506 506
     // This ensures that any selected items are included in the drop down
507
-    if( is_array( $args['selected'] ) ) {
508
-        foreach( $args['selected'] as $item ) {
509
-            if( ! in_array( $item, $options ) ) {
510
-                $title = get_the_title( $item );
511
-                if ( !empty( $args['show_recurring'] ) ) {
512
-                    $title .= wpinv_get_item_suffix( $item, false );
507
+    if (is_array($args['selected'])) {
508
+        foreach ($args['selected'] as $item) {
509
+            if (!in_array($item, $options)) {
510
+                $title = get_the_title($item);
511
+                if (!empty($args['show_recurring'])) {
512
+                    $title .= wpinv_get_item_suffix($item, false);
513 513
                 }
514 514
                 $options[$item] = $title;
515 515
             }
516 516
         }
517
-    } elseif ( is_numeric( $args['selected'] ) && $args['selected'] !== 0 ) {
518
-        if ( ! in_array( $args['selected'], $options ) ) {
519
-            $title = get_the_title( $args['selected'] );
520
-            if ( !empty( $args['show_recurring'] ) ) {
521
-                $title .= wpinv_get_item_suffix( $args['selected'], false );
517
+    } elseif (is_numeric($args['selected']) && $args['selected'] !== 0) {
518
+        if (!in_array($args['selected'], $options)) {
519
+            $title = get_the_title($args['selected']);
520
+            if (!empty($args['show_recurring'])) {
521
+                $title .= wpinv_get_item_suffix($args['selected'], false);
522 522
             }
523
-            $options[$args['selected']] = get_the_title( $args['selected'] );
523
+            $options[$args['selected']] = get_the_title($args['selected']);
524 524
         }
525 525
     }
526 526
 
527
-    $output = wpinv_html_select( array(
527
+    $output = wpinv_html_select(array(
528 528
         'name'             => $args['name'],
529 529
         'selected'         => $args['selected'],
530 530
         'id'               => $args['id'],
@@ -536,12 +536,12 @@  discard block
 block discarded – undo
536 536
         'show_option_all'  => $args['show_option_all'],
537 537
         'show_option_none' => $args['show_option_none'],
538 538
         'data'             => $args['data'],
539
-    ) );
539
+    ));
540 540
 
541 541
     return $output;
542 542
 }
543 543
 
544
-function wpinv_html_checkbox( $args = array() ) {
544
+function wpinv_html_checkbox($args = array()) {
545 545
     $defaults = array(
546 546
         'name'     => null,
547 547
         'current'  => null,
@@ -552,38 +552,38 @@  discard block
 block discarded – undo
552 552
         )
553 553
     );
554 554
 
555
-    $args = wp_parse_args( $args, $defaults );
555
+    $args = wp_parse_args($args, $defaults);
556 556
 
557
-    $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) );
557
+    $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class'])));
558 558
     $options = '';
559
-    if ( ! empty( $args['options']['disabled'] ) ) {
559
+    if (!empty($args['options']['disabled'])) {
560 560
         $options .= ' disabled="disabled"';
561
-    } elseif ( ! empty( $args['options']['readonly'] ) ) {
561
+    } elseif (!empty($args['options']['readonly'])) {
562 562
         $options .= ' readonly';
563 563
     }
564 564
 
565
-    $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 ) . ' />';
565
+    $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) . ' />';
566 566
 
567 567
     return $output;
568 568
 }
569 569
 
570
-function wpinv_html_text( $args = array() ) {
570
+function wpinv_html_text($args = array()) {
571 571
     // Backwards compatibility
572
-    if ( func_num_args() > 1 ) {
572
+    if (func_num_args() > 1) {
573 573
         $args = func_get_args();
574 574
 
575 575
         $name  = $args[0];
576
-        $value = isset( $args[1] ) ? $args[1] : '';
577
-        $label = isset( $args[2] ) ? $args[2] : '';
578
-        $desc  = isset( $args[3] ) ? $args[3] : '';
576
+        $value = isset($args[1]) ? $args[1] : '';
577
+        $label = isset($args[2]) ? $args[2] : '';
578
+        $desc  = isset($args[3]) ? $args[3] : '';
579 579
     }
580 580
 
581 581
     $defaults = array(
582 582
         'id'           => '',
583
-        'name'         => isset( $name )  ? $name  : 'text',
584
-        'value'        => isset( $value ) ? $value : null,
585
-        'label'        => isset( $label ) ? $label : null,
586
-        'desc'         => isset( $desc )  ? $desc  : null,
583
+        'name'         => isset($name) ? $name : 'text',
584
+        'value'        => isset($value) ? $value : null,
585
+        'label'        => isset($label) ? $label : null,
586
+        'desc'         => isset($desc) ? $desc : null,
587 587
         'placeholder'  => '',
588 588
         'class'        => 'regular-text',
589 589
         'disabled'     => false,
@@ -593,51 +593,51 @@  discard block
 block discarded – undo
593 593
         'data'         => false
594 594
     );
595 595
 
596
-    $args = wp_parse_args( $args, $defaults );
596
+    $args = wp_parse_args($args, $defaults);
597 597
 
598
-    $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) );
598
+    $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class'])));
599 599
     $options = '';
600
-    if( $args['required'] ) {
600
+    if ($args['required']) {
601 601
         $options .= ' required="required"';
602 602
     }
603
-    if( $args['readonly'] ) {
603
+    if ($args['readonly']) {
604 604
         $options .= ' readonly';
605 605
     }
606
-    if( $args['readonly'] ) {
606
+    if ($args['readonly']) {
607 607
         $options .= ' readonly';
608 608
     }
609 609
 
610 610
     $data = '';
611
-    if ( !empty( $args['data'] ) ) {
612
-        foreach ( $args['data'] as $key => $value ) {
613
-            $data .= 'data-' . wpinv_sanitize_key( $key ) . '="' . esc_attr( $value ) . '" ';
611
+    if (!empty($args['data'])) {
612
+        foreach ($args['data'] as $key => $value) {
613
+            $data .= 'data-' . wpinv_sanitize_key($key) . '="' . esc_attr($value) . '" ';
614 614
         }
615 615
     }
616 616
 
617
-    $output = '<span id="wpinv-' . wpinv_sanitize_key( $args['name'] ) . '-wrap">';
618
-    $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key( $args['id'] ) . '">' . esc_html( $args['label'] ) . '</label>';
619
-    if ( ! empty( $args['desc'] ) ) {
620
-        $output .= '<span class="wpinv-description">' . esc_html( $args['desc'] ) . '</span>';
617
+    $output = '<span id="wpinv-' . wpinv_sanitize_key($args['name']) . '-wrap">';
618
+    $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key($args['id']) . '">' . esc_html($args['label']) . '</label>';
619
+    if (!empty($args['desc'])) {
620
+        $output .= '<span class="wpinv-description">' . esc_html($args['desc']) . '</span>';
621 621
     }
622 622
 
623
-    $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 ) . '/>';
623
+    $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) . '/>';
624 624
 
625 625
     $output .= '</span>';
626 626
 
627 627
     return $output;
628 628
 }
629 629
 
630
-function wpinv_html_date_field( $args = array() ) {
631
-    if( empty( $args['class'] ) ) {
630
+function wpinv_html_date_field($args = array()) {
631
+    if (empty($args['class'])) {
632 632
         $args['class'] = 'wpiDatepicker';
633
-    } elseif( ! strpos( $args['class'], 'wpiDatepicker' ) ) {
633
+    } elseif (!strpos($args['class'], 'wpiDatepicker')) {
634 634
         $args['class'] .= ' wpiDatepicker';
635 635
     }
636 636
 
637
-    return wpinv_html_text( $args );
637
+    return wpinv_html_text($args);
638 638
 }
639 639
 
640
-function wpinv_html_textarea( $args = array() ) {
640
+function wpinv_html_textarea($args = array()) {
641 641
     $defaults = array(
642 642
         'name'        => 'textarea',
643 643
         'value'       => null,
@@ -647,31 +647,31 @@  discard block
 block discarded – undo
647 647
         'disabled'    => false
648 648
     );
649 649
 
650
-    $args = wp_parse_args( $args, $defaults );
650
+    $args = wp_parse_args($args, $defaults);
651 651
 
652
-    $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) );
652
+    $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class'])));
653 653
     $disabled = '';
654
-    if( $args['disabled'] ) {
654
+    if ($args['disabled']) {
655 655
         $disabled = ' disabled="disabled"';
656 656
     }
657 657
 
658
-    $output = '<span id="wpinv-' . wpinv_sanitize_key( $args['name'] ) . '-wrap">';
659
-    $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key( $args['name'] ) . '">' . esc_html( $args['label'] ) . '</label>';
660
-    $output .= '<textarea name="' . esc_attr( $args['name'] ) . '" id="' . wpinv_sanitize_key( $args['name'] ) . '" class="' . $class . '"' . $disabled . '>' . esc_attr( $args['value'] ) . '</textarea>';
658
+    $output = '<span id="wpinv-' . wpinv_sanitize_key($args['name']) . '-wrap">';
659
+    $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key($args['name']) . '">' . esc_html($args['label']) . '</label>';
660
+    $output .= '<textarea name="' . esc_attr($args['name']) . '" id="' . wpinv_sanitize_key($args['name']) . '" class="' . $class . '"' . $disabled . '>' . esc_attr($args['value']) . '</textarea>';
661 661
 
662
-    if ( ! empty( $args['desc'] ) ) {
663
-        $output .= '<span class="wpinv-description">' . esc_html( $args['desc'] ) . '</span>';
662
+    if (!empty($args['desc'])) {
663
+        $output .= '<span class="wpinv-description">' . esc_html($args['desc']) . '</span>';
664 664
     }
665 665
     $output .= '</span>';
666 666
 
667 667
     return $output;
668 668
 }
669 669
 
670
-function wpinv_html_ajax_user_search( $args = array() ) {
670
+function wpinv_html_ajax_user_search($args = array()) {
671 671
     $defaults = array(
672 672
         'name'        => 'user_id',
673 673
         'value'       => null,
674
-        'placeholder' => __( 'Enter username', 'invoicing' ),
674
+        'placeholder' => __('Enter username', 'invoicing'),
675 675
         'label'       => null,
676 676
         'desc'        => null,
677 677
         'class'       => '',
@@ -680,13 +680,13 @@  discard block
 block discarded – undo
680 680
         'data'        => false
681 681
     );
682 682
 
683
-    $args = wp_parse_args( $args, $defaults );
683
+    $args = wp_parse_args($args, $defaults);
684 684
 
685 685
     $args['class'] = 'wpinv-ajax-user-search ' . $args['class'];
686 686
 
687 687
     $output  = '<span class="wpinv_user_search_wrap">';
688
-        $output .= wpinv_html_text( $args );
689
-        $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>';
688
+        $output .= wpinv_html_text($args);
689
+        $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>';
690 690
     $output .= '</span>';
691 691
 
692 692
     return $output;
@@ -695,7 +695,7 @@  discard block
 block discarded – undo
695 695
 function wpinv_ip_geolocation() {
696 696
     global $wpinv_euvat;
697 697
     
698
-    $ip         = !empty( $_GET['ip'] ) ? sanitize_text_field( $_GET['ip'] ) : '';    
698
+    $ip         = !empty($_GET['ip']) ? sanitize_text_field($_GET['ip']) : '';    
699 699
     $content    = '';
700 700
     $iso        = '';
701 701
     $country    = '';
@@ -706,69 +706,69 @@  discard block
 block discarded – undo
706 706
     $credit     = '';
707 707
     $address    = '';
708 708
     
709
-    if ( wpinv_get_option( 'vat_ip_lookup' ) == 'geoip2' && $geoip2_city = $wpinv_euvat->geoip2_city_record( $ip ) ) {
709
+    if (wpinv_get_option('vat_ip_lookup') == 'geoip2' && $geoip2_city = $wpinv_euvat->geoip2_city_record($ip)) {
710 710
         try {
711 711
             $iso        = $geoip2_city->country->isoCode;
712 712
             $country    = $geoip2_city->country->name;
713
-            $region     = !empty( $geoip2_city->subdivisions ) && !empty( $geoip2_city->subdivisions[0]->name ) ? $geoip2_city->subdivisions[0]->name : '';
713
+            $region     = !empty($geoip2_city->subdivisions) && !empty($geoip2_city->subdivisions[0]->name) ? $geoip2_city->subdivisions[0]->name : '';
714 714
             $city       = $geoip2_city->city->name;
715 715
             $longitude  = $geoip2_city->location->longitude;
716 716
             $latitude   = $geoip2_city->location->latitude;
717
-            $credit     = __( 'Geolocated using the information by MaxMind, available from <a href="http://www.maxmind.com" target="_blank">www.maxmind.com</a>', 'invoicing' );
718
-        } catch( Exception $e ) { }
717
+            $credit     = __('Geolocated using the information by MaxMind, available from <a href="http://www.maxmind.com" target="_blank">www.maxmind.com</a>', 'invoicing');
718
+        } catch (Exception $e) { }
719 719
     }
720 720
     
721
-    if ( !( $iso && $longitude && $latitude ) && function_exists( 'simplexml_load_file' ) ) {
721
+    if (!($iso && $longitude && $latitude) && function_exists('simplexml_load_file')) {
722 722
         try {
723
-            $load_xml = simplexml_load_file( 'http://www.geoplugin.net/xml.gp?ip=' . $ip );
723
+            $load_xml = simplexml_load_file('http://www.geoplugin.net/xml.gp?ip=' . $ip);
724 724
             
725
-            if ( !empty( $load_xml ) && isset( $load_xml->geoplugin_countryCode ) && !empty( $load_xml->geoplugin_latitude ) && !empty( $load_xml->geoplugin_longitude ) ) {
725
+            if (!empty($load_xml) && isset($load_xml->geoplugin_countryCode) && !empty($load_xml->geoplugin_latitude) && !empty($load_xml->geoplugin_longitude)) {
726 726
                 $iso        = $load_xml->geoplugin_countryCode;
727 727
                 $country    = $load_xml->geoplugin_countryName;
728
-                $region     = !empty( $load_xml->geoplugin_regionName ) ? $load_xml->geoplugin_regionName : '';
729
-                $city       = !empty( $load_xml->geoplugin_city ) ? $load_xml->geoplugin_city : '';
728
+                $region     = !empty($load_xml->geoplugin_regionName) ? $load_xml->geoplugin_regionName : '';
729
+                $city       = !empty($load_xml->geoplugin_city) ? $load_xml->geoplugin_city : '';
730 730
                 $longitude  = $load_xml->geoplugin_longitude;
731 731
                 $latitude   = $load_xml->geoplugin_latitude;
732 732
                 $credit     = $load_xml->geoplugin_credit;
733
-                $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;
733
+                $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;
734 734
             }
735
-        } catch( Exception $e ) { }
735
+        } catch (Exception $e) { }
736 736
     }
737 737
     
738
-    if ( $iso && $longitude && $latitude ) {
739
-        if ( $city ) {
738
+    if ($iso && $longitude && $latitude) {
739
+        if ($city) {
740 740
             $address .= $city . ', ';
741 741
         }
742 742
         
743
-        if ( $region ) {
743
+        if ($region) {
744 744
             $address .= $region . ', ';
745 745
         }
746 746
         
747 747
         $address .= $country . ' (' . $iso . ')';
748
-        $content = '<p>'. sprintf( __( '<b>Address:</b> %s', 'invoicing' ), $address ) . '</p>';
749
-        $content .= '<p>'. $credit . '</p>';
748
+        $content = '<p>' . sprintf(__('<b>Address:</b> %s', 'invoicing'), $address) . '</p>';
749
+        $content .= '<p>' . $credit . '</p>';
750 750
     } else {
751
-        $content = '<p>'. sprintf( __( 'Unable to find geolocation for the IP address: %s', 'invoicing' ), $ip ) . '</p>';
751
+        $content = '<p>' . sprintf(__('Unable to find geolocation for the IP address: %s', 'invoicing'), $ip) . '</p>';
752 752
     }
753 753
     ?>
754 754
 <!DOCTYPE html>
755
-<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>
755
+<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>
756 756
 <body>
757
-    <?php if ( $latitude && $latitude ) { ?>
757
+    <?php if ($latitude && $latitude) { ?>
758 758
     <div id="map"></div>
759 759
         <script src="//cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.0-rc.1/leaflet.js"></script>
760 760
         <script type="text/javascript">
761 761
         var osmUrl = 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
762 762
             osmAttrib = '&copy; <a href="http://openstreetmap.org/copyright">OpenStreetMap</a> contributors',
763 763
             osm = L.tileLayer(osmUrl, {maxZoom: 18, attribution: osmAttrib}),
764
-            latlng = new L.LatLng(<?php echo $latitude;?>, <?php echo $longitude;?>);
764
+            latlng = new L.LatLng(<?php echo $latitude; ?>, <?php echo $longitude; ?>);
765 765
 
766 766
         var map = new L.Map('map', {center: latlng, zoom: 12, layers: [osm]});
767 767
 
768 768
         var marker = new L.Marker(latlng);
769 769
         map.addLayer(marker);
770 770
 
771
-        marker.bindPopup("<p><?php esc_attr_e( $address );?></p>");
771
+        marker.bindPopup("<p><?php esc_attr_e($address); ?></p>");
772 772
     </script>
773 773
     <?php } ?>
774 774
     <div style="height:100px"><?php echo $content; ?></div>
@@ -776,18 +776,18 @@  discard block
 block discarded – undo
776 776
 <?php
777 777
     exit;
778 778
 }
779
-add_action( 'wp_ajax_wpinv_ip_geolocation', 'wpinv_ip_geolocation' );
780
-add_action( 'wp_ajax_nopriv_wpinv_ip_geolocation', 'wpinv_ip_geolocation' );
779
+add_action('wp_ajax_wpinv_ip_geolocation', 'wpinv_ip_geolocation');
780
+add_action('wp_ajax_nopriv_wpinv_ip_geolocation', 'wpinv_ip_geolocation');
781 781
 
782 782
 // Set up the template for the invoice.
783
-function wpinv_template( $template ) {
783
+function wpinv_template($template) {
784 784
     global $post, $wp_query;
785 785
     
786
-    if ( ( is_single() || is_404() ) && !empty( $post->ID ) && (get_post_type( $post->ID ) == 'wpi_invoice' or get_post_type( $post->ID ) == 'wpi_quote')) {
787
-        if ( wpinv_user_can_view_invoice( $post->ID ) ) {
788
-            $template = wpinv_get_template_part( 'wpinv-invoice-print', false, false );
786
+    if ((is_single() || is_404()) && !empty($post->ID) && (get_post_type($post->ID) == 'wpi_invoice' or get_post_type($post->ID) == 'wpi_quote')) {
787
+        if (wpinv_user_can_view_invoice($post->ID)) {
788
+            $template = wpinv_get_template_part('wpinv-invoice-print', false, false);
789 789
         } else {
790
-            $template = wpinv_get_template_part( 'wpinv-invalid-access', false, false );
790
+            $template = wpinv_get_template_part('wpinv-invalid-access', false, false);
791 791
         }
792 792
     }
793 793
 
@@ -796,7 +796,7 @@  discard block
 block discarded – undo
796 796
 
797 797
 function wpinv_get_business_address() {
798 798
     $business_address   = wpinv_store_address();
799
-    $business_address   = !empty( $business_address ) ? wpautop( wp_kses_post( $business_address ) ) : '';
799
+    $business_address   = !empty($business_address) ? wpautop(wp_kses_post($business_address)) : '';
800 800
     
801 801
     /*
802 802
     $default_country    = wpinv_get_default_country();
@@ -820,7 +820,7 @@  discard block
 block discarded – undo
820 820
     
821 821
     $business_address = $business_address ? '<div class="address">' . $business_address . '</div>' : '';
822 822
     
823
-    return apply_filters( 'wpinv_get_business_address', $business_address );
823
+    return apply_filters('wpinv_get_business_address', $business_address);
824 824
 }
825 825
 
826 826
 function wpinv_display_from_address() {
@@ -830,188 +830,188 @@  discard block
 block discarded – undo
830 830
     if (empty($from_name)) {
831 831
         $from_name = wpinv_get_business_name();
832 832
     }
833
-    ?><div class="from col-xs-2"><strong><?php _e( 'From:', 'invoicing' ) ?></strong></div>
833
+    ?><div class="from col-xs-2"><strong><?php _e('From:', 'invoicing') ?></strong></div>
834 834
     <div class="wrapper col-xs-10">
835
-        <div class="name"><?php echo esc_html( $from_name ); ?></div>
836
-        <?php if ( $address = wpinv_get_business_address() ) { ?>
837
-        <div class="address"><?php echo wpautop( wp_kses_post( $address ) );?></div>
835
+        <div class="name"><?php echo esc_html($from_name); ?></div>
836
+        <?php if ($address = wpinv_get_business_address()) { ?>
837
+        <div class="address"><?php echo wpautop(wp_kses_post($address)); ?></div>
838 838
         <?php } ?>
839
-        <?php if ( $email_from = wpinv_mail_get_from_address() ) { ?>
840
-        <div class="email_from"><?php echo wp_sprintf( __( 'Email: %s', 'invoicing' ), $email_from );?></div>
839
+        <?php if ($email_from = wpinv_mail_get_from_address()) { ?>
840
+        <div class="email_from"><?php echo wp_sprintf(__('Email: %s', 'invoicing'), $email_from); ?></div>
841 841
         <?php } ?>
842 842
     </div>
843 843
     <?php
844 844
 }
845 845
 
846
-function wpinv_watermark( $id = 0 ) {
847
-    $output = wpinv_get_watermark( $id );
846
+function wpinv_watermark($id = 0) {
847
+    $output = wpinv_get_watermark($id);
848 848
     
849
-    return apply_filters( 'wpinv_get_watermark', $output, $id );
849
+    return apply_filters('wpinv_get_watermark', $output, $id);
850 850
 }
851 851
 
852
-function wpinv_get_watermark( $id ) {
853
-    if ( !$id > 0 ) {
852
+function wpinv_get_watermark($id) {
853
+    if (!$id > 0) {
854 854
         return NULL;
855 855
     }
856
-    $invoice = wpinv_get_invoice( $id );
856
+    $invoice = wpinv_get_invoice($id);
857 857
     
858
-    if ( !empty( $invoice ) && "wpi_invoice" === $invoice->post_type ) {
859
-        if ( $invoice->is_paid() ) {
860
-            return __( 'Paid', 'invoicing' );
858
+    if (!empty($invoice) && "wpi_invoice" === $invoice->post_type) {
859
+        if ($invoice->is_paid()) {
860
+            return __('Paid', 'invoicing');
861 861
         }
862
-        if ( $invoice->is_refunded() ) {
863
-            return __( 'Refunded', 'invoicing' );
862
+        if ($invoice->is_refunded()) {
863
+            return __('Refunded', 'invoicing');
864 864
         }
865
-        if ( $invoice->has_status( array( 'wpi-cancelled' ) ) ) {
866
-            return __( 'Cancelled', 'invoicing' );
865
+        if ($invoice->has_status(array('wpi-cancelled'))) {
866
+            return __('Cancelled', 'invoicing');
867 867
         }
868 868
     }
869 869
     
870 870
     return NULL;
871 871
 }
872 872
 
873
-function wpinv_display_invoice_details( $invoice ) {
873
+function wpinv_display_invoice_details($invoice) {
874 874
     global $wpinv_euvat;
875 875
     
876 876
     $invoice_id = $invoice->ID;
877 877
     $vat_name   = $wpinv_euvat->get_vat_name();
878 878
     $use_taxes  = wpinv_use_taxes();
879 879
     
880
-    $invoice_status = wpinv_get_invoice_status( $invoice_id );
880
+    $invoice_status = wpinv_get_invoice_status($invoice_id);
881 881
     
882
-    if($invoice->post_type == 'wpi_invoice') $type = 'Invoice';
883
-    elseif($invoice->post_type == 'wpi_quote') $type = 'Quote';
882
+    if ($invoice->post_type == 'wpi_invoice') $type = 'Invoice';
883
+    elseif ($invoice->post_type == 'wpi_quote') $type = 'Quote';
884 884
     ?>
885 885
     <table class="table table-bordered table-sm">
886
-        <?php if ( $invoice_number = wpinv_get_invoice_number( $invoice_id ) ) { ?>
886
+        <?php if ($invoice_number = wpinv_get_invoice_number($invoice_id)) { ?>
887 887
             <tr class="wpi-row-number">
888
-                <th><?php echo sprintf(__( '%s Number', 'invoicing' ), $type); ?></th>
889
-                <td><?php echo esc_html( $invoice_number ); ?></td>
888
+                <th><?php echo sprintf(__('%s Number', 'invoicing'), $type); ?></th>
889
+                <td><?php echo esc_html($invoice_number); ?></td>
890 890
             </tr>
891 891
         <?php } ?>
892 892
         <tr class="wpi-row-status">
893
-            <th><?php echo wp_sprintf(__( '%s Status', 'invoicing' ), $type); ?></th>
894
-            <td><?php echo wpinv_invoice_status_label( $invoice_status, wpinv_get_invoice_status( $invoice_id, true ) ); ?></td>
893
+            <th><?php echo wp_sprintf(__('%s Status', 'invoicing'), $type); ?></th>
894
+            <td><?php echo wpinv_invoice_status_label($invoice_status, wpinv_get_invoice_status($invoice_id, true)); ?></td>
895 895
         </tr>
896
-        <?php if ( $invoice->is_renewal() ) { ?>
896
+        <?php if ($invoice->is_renewal()) { ?>
897 897
         <tr class="wpi-row-parent">
898
-            <th><?php echo wp_sprintf(__( 'Parent %s', 'invoicing' ), $type); ?></th>
899
-            <td><?php echo wpinv_invoice_link( $invoice->parent_invoice ); ?></td>
898
+            <th><?php echo wp_sprintf(__('Parent %s', 'invoicing'), $type); ?></th>
899
+            <td><?php echo wpinv_invoice_link($invoice->parent_invoice); ?></td>
900 900
         </tr>
901 901
         <?php } ?>
902 902
         <tr class="wpi-row-gateway">
903
-            <th><?php _e( 'Payment Method', 'invoicing' ); ?></th>
904
-            <td><?php echo wpinv_get_payment_gateway_name( $invoice_id ); ?></td>
903
+            <th><?php _e('Payment Method', 'invoicing'); ?></th>
904
+            <td><?php echo wpinv_get_payment_gateway_name($invoice_id); ?></td>
905 905
         </tr>
906
-        <?php if ( $invoice_date = wpinv_get_invoice_date( $invoice_id ) ) { ?>
906
+        <?php if ($invoice_date = wpinv_get_invoice_date($invoice_id)) { ?>
907 907
             <tr class="wpi-row-date">
908
-                <th><?php echo wp_sprintf(__( '%s Date', 'invoicing' ), $type); ?></th>
908
+                <th><?php echo wp_sprintf(__('%s Date', 'invoicing'), $type); ?></th>
909 909
                 <td><?php echo $invoice_date; ?></td>
910 910
             </tr>
911 911
         <?php } ?>
912
-        <?php if ( wpinv_get_option( 'overdue_active' ) && $invoice->needs_payment() && ( $due_date = $invoice->get_due_date( true ) ) ) { ?>
912
+        <?php if (wpinv_get_option('overdue_active') && $invoice->needs_payment() && ($due_date = $invoice->get_due_date(true))) { ?>
913 913
             <tr class="wpi-row-date">
914
-                <th><?php _e( 'Due Date', 'invoicing' ); ?></th>
914
+                <th><?php _e('Due Date', 'invoicing'); ?></th>
915 915
                 <td><?php echo $due_date; ?></td>
916 916
             </tr>
917 917
         <?php } ?>
918
-        <?php if ( $owner_vat_number = $wpinv_euvat->get_vat_number() ) { ?>
918
+        <?php if ($owner_vat_number = $wpinv_euvat->get_vat_number()) { ?>
919 919
             <tr class="wpi-row-ovatno">
920
-                <th><?php echo wp_sprintf( __( 'Owner %s Number', 'invoicing' ), $vat_name ); ?></th>
920
+                <th><?php echo wp_sprintf(__('Owner %s Number', 'invoicing'), $vat_name); ?></th>
921 921
                 <td><?php echo $owner_vat_number; ?></td>
922 922
             </tr>
923 923
         <?php } ?>
924
-        <?php if ( $use_taxes && $user_vat_number = wpinv_get_invoice_vat_number( $invoice_id ) ) { ?>
924
+        <?php if ($use_taxes && $user_vat_number = wpinv_get_invoice_vat_number($invoice_id)) { ?>
925 925
             <tr class="wpi-row-uvatno">
926
-                <th><?php echo wp_sprintf( __( 'Your %s Number', 'invoicing' ), $vat_name ); ?></th>
926
+                <th><?php echo wp_sprintf(__('Your %s Number', 'invoicing'), $vat_name); ?></th>
927 927
                 <td><?php echo $user_vat_number; ?></td>
928 928
             </tr>
929 929
         <?php } ?>
930 930
         <tr class="table-active tr-total wpi-row-total">
931
-            <th><strong><?php _e( 'Total Amount', 'invoicing' ) ?></strong></th>
932
-            <td><strong><?php echo wpinv_payment_total( $invoice_id, true ); ?></strong></td>
931
+            <th><strong><?php _e('Total Amount', 'invoicing') ?></strong></th>
932
+            <td><strong><?php echo wpinv_payment_total($invoice_id, true); ?></strong></td>
933 933
         </tr>
934 934
     </table>
935 935
 <?php
936 936
 }
937 937
 
938
-function wpinv_display_to_address( $invoice_id = 0 ) {
939
-    $invoice = wpinv_get_invoice( $invoice_id );
938
+function wpinv_display_to_address($invoice_id = 0) {
939
+    $invoice = wpinv_get_invoice($invoice_id);
940 940
     
941
-    if ( empty( $invoice ) ) {
941
+    if (empty($invoice)) {
942 942
         return NULL;
943 943
     }
944 944
     
945 945
     $billing_details = $invoice->get_user_info();
946
-    $output = '<div class="to col-xs-2"><strong>' . __( 'To:', 'invoicing' ) . '</strong></div>';
946
+    $output = '<div class="to col-xs-2"><strong>' . __('To:', 'invoicing') . '</strong></div>';
947 947
     $output .= '<div class="wrapper col-xs-10">';
948 948
     
949 949
     ob_start();
950
-    do_action( 'wpinv_display_to_address_top', $invoice );
950
+    do_action('wpinv_display_to_address_top', $invoice);
951 951
     $output .= ob_get_clean();
952 952
     
953
-    $output .= '<div class="name">' . esc_html( trim( $billing_details['first_name'] . ' ' . $billing_details['last_name'] ) ) . '</div>';
954
-    if ( $company = $billing_details['company'] ) {
955
-        $output .= '<div class="company">' . wpautop( wp_kses_post( $company ) ) . '</div>';
953
+    $output .= '<div class="name">' . esc_html(trim($billing_details['first_name'] . ' ' . $billing_details['last_name'])) . '</div>';
954
+    if ($company = $billing_details['company']) {
955
+        $output .= '<div class="company">' . wpautop(wp_kses_post($company)) . '</div>';
956 956
     }
957 957
     $address_row = '';
958
-    if ( $address = $billing_details['address'] ) {
959
-        $address_row .= wpautop( wp_kses_post( $address ) );
958
+    if ($address = $billing_details['address']) {
959
+        $address_row .= wpautop(wp_kses_post($address));
960 960
     }
961 961
     
962 962
     $address_fields = array();
963
-    if ( !empty( $billing_details['city'] ) ) {
963
+    if (!empty($billing_details['city'])) {
964 964
         $address_fields[] = $billing_details['city'];
965 965
     }
966 966
     
967
-    $billing_country = !empty( $billing_details['country'] ) ? $billing_details['country'] : '';
968
-    if ( !empty( $billing_details['state'] ) ) {
969
-        $address_fields[] = wpinv_state_name( $billing_details['state'], $billing_country );
967
+    $billing_country = !empty($billing_details['country']) ? $billing_details['country'] : '';
968
+    if (!empty($billing_details['state'])) {
969
+        $address_fields[] = wpinv_state_name($billing_details['state'], $billing_country);
970 970
     }
971 971
     
972
-    if ( !empty( $billing_country ) ) {
973
-        $address_fields[] = wpinv_country_name( $billing_country );
972
+    if (!empty($billing_country)) {
973
+        $address_fields[] = wpinv_country_name($billing_country);
974 974
     }
975 975
     
976
-    if ( !empty( $address_fields ) ) {
977
-        $address_fields = implode( ", ", $address_fields );
976
+    if (!empty($address_fields)) {
977
+        $address_fields = implode(", ", $address_fields);
978 978
         
979
-        if ( !empty( $billing_details['zip'] ) ) {
979
+        if (!empty($billing_details['zip'])) {
980 980
             $address_fields .= ' ' . $billing_details['zip'];
981 981
         }
982 982
         
983
-        $address_row .= wpautop( wp_kses_post( $address_fields ) );
983
+        $address_row .= wpautop(wp_kses_post($address_fields));
984 984
     }
985 985
     
986
-    if ( $address_row ) {
986
+    if ($address_row) {
987 987
         $output .= '<div class="address">' . $address_row . '</div>';
988 988
     }
989 989
     
990
-    if ( $phone = $invoice->get_phone() ) {
991
-        $output .= '<div class="phone">' . wp_sprintf( __( 'Phone: %s', 'invoicing' ), esc_html( $phone ) ) . '</div>';
990
+    if ($phone = $invoice->get_phone()) {
991
+        $output .= '<div class="phone">' . wp_sprintf(__('Phone: %s', 'invoicing'), esc_html($phone)) . '</div>';
992 992
     }
993
-    if ( $email = $invoice->get_email() ) {
994
-        $output .= '<div class="email">' . wp_sprintf( __( 'Email: %s' , 'invoicing'), esc_html( $email ) ) . '</div>';
993
+    if ($email = $invoice->get_email()) {
994
+        $output .= '<div class="email">' . wp_sprintf(__('Email: %s', 'invoicing'), esc_html($email)) . '</div>';
995 995
     }
996 996
     
997 997
     ob_start();
998
-    do_action( 'wpinv_display_to_address_bottom', $invoice );
998
+    do_action('wpinv_display_to_address_bottom', $invoice);
999 999
     $output .= ob_get_clean();
1000 1000
     
1001 1001
     $output .= '</div>';
1002
-    $output = apply_filters( 'wpinv_display_to_address', $output, $invoice );
1002
+    $output = apply_filters('wpinv_display_to_address', $output, $invoice);
1003 1003
 
1004 1004
     echo $output;
1005 1005
 }
1006 1006
 
1007
-function wpinv_display_line_items( $invoice_id = 0 ) {
1007
+function wpinv_display_line_items($invoice_id = 0) {
1008 1008
     global $wpinv_euvat, $ajax_cart_details;
1009
-    $invoice            = wpinv_get_invoice( $invoice_id );
1009
+    $invoice            = wpinv_get_invoice($invoice_id);
1010 1010
     $quantities_enabled = wpinv_item_quantities_enabled();
1011 1011
     $use_taxes          = wpinv_use_taxes();
1012 1012
     $zero_tax           = !(float)$invoice->get_tax() > 0 ? true : false;
1013
-    $tax_label           = $use_taxes && $invoice->has_vat() ? $wpinv_euvat->get_vat_name() : __( 'Tax', 'invoicing' );
1014
-    $tax_title          = !$zero_tax && $use_taxes ? ( wpinv_prices_include_tax() ? wp_sprintf( __( '(%s Incl.)', 'invoicing' ), $tax_label ) : wp_sprintf( __( '(%s Excl.)', 'invoicing' ), $tax_label ) ) : '';
1013
+    $tax_label = $use_taxes && $invoice->has_vat() ? $wpinv_euvat->get_vat_name() : __('Tax', 'invoicing');
1014
+    $tax_title          = !$zero_tax && $use_taxes ? (wpinv_prices_include_tax() ? wp_sprintf(__('(%s Incl.)', 'invoicing'), $tax_label) : wp_sprintf(__('(%s Excl.)', 'invoicing'), $tax_label)) : '';
1015 1015
     
1016 1016
     $cart_details       = $invoice->get_cart_details();
1017 1017
     $ajax_cart_details  = $cart_details;
@@ -1020,68 +1020,68 @@  discard block
 block discarded – undo
1020 1020
     <table class="table table-sm table-bordered table-responsive">
1021 1021
         <thead>
1022 1022
             <tr>
1023
-                <th class="name"><strong><?php _e( "Item Name", "invoicing" );?></strong></th>
1024
-                <th class="rate"><strong><?php _e( "Price", "invoicing" );?></strong></th>
1023
+                <th class="name"><strong><?php _e("Item Name", "invoicing"); ?></strong></th>
1024
+                <th class="rate"><strong><?php _e("Price", "invoicing"); ?></strong></th>
1025 1025
                 <?php if ($quantities_enabled) { ?>
1026
-                    <th class="qty"><strong><?php _e( "Qty", "invoicing" );?></strong></th>
1026
+                    <th class="qty"><strong><?php _e("Qty", "invoicing"); ?></strong></th>
1027 1027
                 <?php } ?>
1028 1028
                 <?php if ($use_taxes && !$zero_tax) { ?>
1029 1029
                     <th class="tax"><strong><?php echo $tax_label . ' <span class="normal small">(%)</span>'; ?></strong></th>
1030 1030
                 <?php } ?>
1031
-                <th class="total"><strong><?php echo __( "Item Total", "invoicing" ) . ' <span class="normal small">' . $tax_title . '<span>';?></strong></th>
1031
+                <th class="total"><strong><?php echo __("Item Total", "invoicing") . ' <span class="normal small">' . $tax_title . '<span>'; ?></strong></th>
1032 1032
             </tr>
1033 1033
         </thead>
1034 1034
         <tbody>
1035 1035
         <?php 
1036
-            if ( !empty( $cart_details ) ) {
1037
-                do_action( 'wpinv_display_line_items_start', $invoice );
1036
+            if (!empty($cart_details)) {
1037
+                do_action('wpinv_display_line_items_start', $invoice);
1038 1038
                 
1039 1039
                 $count = 0;
1040 1040
                 $cols  = 3;
1041
-                foreach ( $cart_details as $key => $cart_item ) {
1042
-                    $item_id    = !empty($cart_item['id']) ? absint( $cart_item['id'] ) : '';
1043
-                    $item_price = isset($cart_item["item_price"]) ? wpinv_round_amount( $cart_item["item_price"] ) : 0;
1044
-                    $line_total = isset($cart_item["subtotal"]) ? wpinv_round_amount( $cart_item["subtotal"] ) : 0;
1045
-                    $quantity   = !empty($cart_item['quantity']) && (int)$cart_item['quantity'] > 0 ? absint( $cart_item['quantity'] ) : 1;
1041
+                foreach ($cart_details as $key => $cart_item) {
1042
+                    $item_id    = !empty($cart_item['id']) ? absint($cart_item['id']) : '';
1043
+                    $item_price = isset($cart_item["item_price"]) ? wpinv_round_amount($cart_item["item_price"]) : 0;
1044
+                    $line_total = isset($cart_item["subtotal"]) ? wpinv_round_amount($cart_item["subtotal"]) : 0;
1045
+                    $quantity   = !empty($cart_item['quantity']) && (int)$cart_item['quantity'] > 0 ? absint($cart_item['quantity']) : 1;
1046 1046
                     
1047
-                    $item       = $item_id ? new WPInv_Item( $item_id ) : NULL;
1047
+                    $item       = $item_id ? new WPInv_Item($item_id) : NULL;
1048 1048
                     $summary    = '';
1049 1049
                     $cols       = 3;
1050
-                    if ( !empty($item) ) {
1050
+                    if (!empty($item)) {
1051 1051
                         $item_name  = $item->get_name();
1052 1052
                         $summary    = $item->get_summary();
1053 1053
                     }
1054
-                    $item_name  = !empty($cart_item['name']) ? $cart_item['name'] : $item_name;
1054
+                    $item_name = !empty($cart_item['name']) ? $cart_item['name'] : $item_name;
1055 1055
                     
1056 1056
                     if (!empty($item) && $item->is_package() && !empty($cart_item['meta']['post_id'])) {
1057
-                        $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>';
1058
-                        $summary = wp_sprintf( __( '%s: %s', 'invoicing' ), $item->get_custom_singular_name(), $post_link );
1057
+                        $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>';
1058
+                        $summary = wp_sprintf(__('%s: %s', 'invoicing'), $item->get_custom_singular_name(), $post_link);
1059 1059
                     }
1060
-                    $summary = apply_filters( 'wpinv_print_invoice_line_item_summary', $summary, $cart_item, $item, $invoice );
1060
+                    $summary = apply_filters('wpinv_print_invoice_line_item_summary', $summary, $cart_item, $item, $invoice);
1061 1061
                     
1062 1062
                     $item_tax       = '';
1063 1063
                     $tax_rate       = '';
1064
-                    if ( $use_taxes && $cart_item['tax'] > 0 && $cart_item['subtotal'] > 0 ) {
1065
-                        $item_tax = wpinv_price( wpinv_format_amount( $cart_item['tax'] ) );
1066
-                        $tax_rate = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : ( $cart_item['tax'] / $cart_item['subtotal'] ) * 100;
1067
-                        $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount( $tax_rate, 4 ) : '';
1064
+                    if ($use_taxes && $cart_item['tax'] > 0 && $cart_item['subtotal'] > 0) {
1065
+                        $item_tax = wpinv_price(wpinv_format_amount($cart_item['tax']));
1066
+                        $tax_rate = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : ($cart_item['tax'] / $cart_item['subtotal']) * 100;
1067
+                        $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount($tax_rate, 4) : '';
1068 1068
                         $tax_rate = $tax_rate != '' ? ' <small class="tax-rate">(' . $tax_rate . '%)</small>' : '';
1069 1069
                     }
1070 1070
                     
1071 1071
                     $line_item_tax = $item_tax . $tax_rate;
1072 1072
                     
1073
-                    if ( $line_item_tax === '' ) {
1073
+                    if ($line_item_tax === '') {
1074 1074
                         $line_item_tax = 0; // Zero tax
1075 1075
                     }
1076 1076
                     
1077
-                    $line_item = '<tr class="row-' . ( ($count % 2 == 0) ? 'even' : 'odd' ) . ' wpinv-item">';
1078
-                        $line_item .= '<td class="name">' . esc_html__( $item_name, 'invoicing' ) . wpinv_get_item_suffix( $item );
1079
-                        if ( $summary !== '' ) {
1080
-                            $line_item .= '<br/><small class="meta">' . wpautop( wp_kses_post( $summary ) ) . '</small>';
1077
+                    $line_item = '<tr class="row-' . (($count % 2 == 0) ? 'even' : 'odd') . ' wpinv-item">';
1078
+                        $line_item .= '<td class="name">' . esc_html__($item_name, 'invoicing') . wpinv_get_item_suffix($item);
1079
+                        if ($summary !== '') {
1080
+                            $line_item .= '<br/><small class="meta">' . wpautop(wp_kses_post($summary)) . '</small>';
1081 1081
                         }
1082 1082
                         $line_item .= '</td>';
1083 1083
                         
1084
-                        $line_item .= '<td class="rate">' . esc_html__( wpinv_price( wpinv_format_amount( $item_price ), $invoice->get_currency() ) ) . '</td>';
1084
+                        $line_item .= '<td class="rate">' . esc_html__(wpinv_price(wpinv_format_amount($item_price), $invoice->get_currency())) . '</td>';
1085 1085
                         if ($quantities_enabled) {
1086 1086
                             $cols++;
1087 1087
                             $line_item .= '<td class="qty">' . $quantity . '</td>';
@@ -1090,55 +1090,55 @@  discard block
 block discarded – undo
1090 1090
                             $cols++;
1091 1091
                             $line_item .= '<td class="tax">' . $line_item_tax . '</td>';
1092 1092
                         }
1093
-                        $line_item .= '<td class="total">' . esc_html__( wpinv_price( wpinv_format_amount( $line_total ), $invoice->get_currency() ) ) . '</td>';
1093
+                        $line_item .= '<td class="total">' . esc_html__(wpinv_price(wpinv_format_amount($line_total), $invoice->get_currency())) . '</td>';
1094 1094
                     $line_item .= '</tr>';
1095 1095
                     
1096
-                    echo apply_filters( 'wpinv_display_line_item', $line_item, $cart_item, $invoice, $cols );
1096
+                    echo apply_filters('wpinv_display_line_item', $line_item, $cart_item, $invoice, $cols);
1097 1097
 
1098 1098
                     $count++;
1099 1099
                 }
1100 1100
                 
1101
-                do_action( 'wpinv_display_before_subtotal', $invoice, $cols );
1101
+                do_action('wpinv_display_before_subtotal', $invoice, $cols);
1102 1102
                 ?>
1103 1103
                 <tr class="row-sub-total row_odd">
1104
-                    <td class="rate" colspan="<?php echo ( $cols - 1 ); ?>"><?php echo apply_filters( 'wpinv_print_cart_subtotal_label', '<strong>' . __( 'Sub Total', 'invoicing' ) . ':</strong>', $invoice ); ?></td>
1105
-                    <td class="total"><strong><?php _e( wpinv_subtotal( $invoice_id, true ) ) ?></strong></td>
1104
+                    <td class="rate" colspan="<?php echo ($cols - 1); ?>"><?php echo apply_filters('wpinv_print_cart_subtotal_label', '<strong>' . __('Sub Total', 'invoicing') . ':</strong>', $invoice); ?></td>
1105
+                    <td class="total"><strong><?php _e(wpinv_subtotal($invoice_id, true)) ?></strong></td>
1106 1106
                 </tr>
1107 1107
                 <?php
1108
-                do_action( 'wpinv_display_after_subtotal', $invoice, $cols );
1108
+                do_action('wpinv_display_after_subtotal', $invoice, $cols);
1109 1109
                 
1110
-                if ( wpinv_discount( $invoice_id, false ) > 0 ) {
1111
-                    do_action( 'wpinv_display_before_discount', $invoice, $cols );
1110
+                if (wpinv_discount($invoice_id, false) > 0) {
1111
+                    do_action('wpinv_display_before_discount', $invoice, $cols);
1112 1112
                     ?>
1113 1113
                         <tr class="row-discount">
1114
-                            <td class="rate" colspan="<?php echo ( $cols - 1 ); ?>"><?php wpinv_get_discount_label( wpinv_discount_code( $invoice_id ) ); ?>:</td>
1115
-                            <td class="total"><?php echo wpinv_discount( $invoice_id, true, true ); ?></td>
1114
+                            <td class="rate" colspan="<?php echo ($cols - 1); ?>"><?php wpinv_get_discount_label(wpinv_discount_code($invoice_id)); ?>:</td>
1115
+                            <td class="total"><?php echo wpinv_discount($invoice_id, true, true); ?></td>
1116 1116
                         </tr>
1117 1117
                     <?php
1118
-                    do_action( 'wpinv_display_after_discount', $invoice, $cols );
1118
+                    do_action('wpinv_display_after_discount', $invoice, $cols);
1119 1119
                 }
1120 1120
                 
1121
-                if ( $use_taxes ) {
1122
-                    do_action( 'wpinv_display_before_tax', $invoice, $cols );
1121
+                if ($use_taxes) {
1122
+                    do_action('wpinv_display_before_tax', $invoice, $cols);
1123 1123
                     ?>
1124 1124
                     <tr class="row-tax">
1125
-                        <td class="rate" colspan="<?php echo ( $cols - 1 ); ?>"><?php echo apply_filters( 'wpinv_print_cart_tax_label', '<strong>' . $tax_label . ':</strong>', $invoice ); ?></td>
1126
-                        <td class="total"><?php _e( wpinv_tax( $invoice_id, true ) ) ?></td>
1125
+                        <td class="rate" colspan="<?php echo ($cols - 1); ?>"><?php echo apply_filters('wpinv_print_cart_tax_label', '<strong>' . $tax_label . ':</strong>', $invoice); ?></td>
1126
+                        <td class="total"><?php _e(wpinv_tax($invoice_id, true)) ?></td>
1127 1127
                     </tr>
1128 1128
                     <?php
1129
-                    do_action( 'wpinv_display_after_tax', $invoice, $cols );
1129
+                    do_action('wpinv_display_after_tax', $invoice, $cols);
1130 1130
                 }
1131 1131
                 
1132
-                do_action( 'wpinv_display_before_total', $invoice, $cols );
1132
+                do_action('wpinv_display_before_total', $invoice, $cols);
1133 1133
                 ?>
1134 1134
                 <tr class="table-active row-total">
1135
-                    <td class="rate" colspan="<?php echo ( $cols - 1 ); ?>"><?php echo apply_filters( 'wpinv_print_cart_total_label', '<strong>' . __( 'Total', 'invoicing' ) . ':</strong>', $invoice ); ?></td>
1136
-                    <td class="total"><strong><?php _e( wpinv_payment_total( $invoice_id, true ) ) ?></strong></td>
1135
+                    <td class="rate" colspan="<?php echo ($cols - 1); ?>"><?php echo apply_filters('wpinv_print_cart_total_label', '<strong>' . __('Total', 'invoicing') . ':</strong>', $invoice); ?></td>
1136
+                    <td class="total"><strong><?php _e(wpinv_payment_total($invoice_id, true)) ?></strong></td>
1137 1137
                 </tr>
1138 1138
                 <?php
1139
-                do_action( 'wpinv_display_after_total', $invoice, $cols );
1139
+                do_action('wpinv_display_after_total', $invoice, $cols);
1140 1140
                 
1141
-                do_action( 'wpinv_display_line_end', $invoice, $cols );
1141
+                do_action('wpinv_display_line_end', $invoice, $cols);
1142 1142
             }
1143 1143
         ?>
1144 1144
         </tbody>
@@ -1147,35 +1147,35 @@  discard block
 block discarded – undo
1147 1147
     echo ob_get_clean();
1148 1148
 }
1149 1149
 
1150
-function wpinv_display_invoice_totals( $invoice_id = 0 ) {    
1150
+function wpinv_display_invoice_totals($invoice_id = 0) {    
1151 1151
     $use_taxes = wpinv_use_taxes();
1152 1152
     
1153
-    do_action( 'wpinv_before_display_totals_table', $invoice_id ); 
1153
+    do_action('wpinv_before_display_totals_table', $invoice_id); 
1154 1154
     ?>
1155 1155
     <table class="table table-sm table-bordered table-responsive">
1156 1156
         <tbody>
1157
-            <?php do_action( 'wpinv_before_display_totals' ); ?>
1157
+            <?php do_action('wpinv_before_display_totals'); ?>
1158 1158
             <tr class="row-sub-total">
1159
-                <td class="rate"><strong><?php _e( 'Sub Total', 'invoicing' ); ?></strong></td>
1160
-                <td class="total"><strong><?php _e( wpinv_subtotal( $invoice_id, true ) ) ?></strong></td>
1159
+                <td class="rate"><strong><?php _e('Sub Total', 'invoicing'); ?></strong></td>
1160
+                <td class="total"><strong><?php _e(wpinv_subtotal($invoice_id, true)) ?></strong></td>
1161 1161
             </tr>
1162
-            <?php do_action( 'wpinv_after_display_totals' ); ?>
1163
-            <?php if ( wpinv_discount( $invoice_id, false ) > 0 ) { ?>
1162
+            <?php do_action('wpinv_after_display_totals'); ?>
1163
+            <?php if (wpinv_discount($invoice_id, false) > 0) { ?>
1164 1164
                 <tr class="row-discount">
1165
-                    <td class="rate"><?php wpinv_get_discount_label( wpinv_discount_code( $invoice_id ) ); ?></td>
1166
-                    <td class="total"><?php echo wpinv_discount( $invoice_id, true, true ); ?></td>
1165
+                    <td class="rate"><?php wpinv_get_discount_label(wpinv_discount_code($invoice_id)); ?></td>
1166
+                    <td class="total"><?php echo wpinv_discount($invoice_id, true, true); ?></td>
1167 1167
                 </tr>
1168
-            <?php do_action( 'wpinv_after_display_discount' ); ?>
1168
+            <?php do_action('wpinv_after_display_discount'); ?>
1169 1169
             <?php } ?>
1170
-            <?php if ( $use_taxes ) { ?>
1170
+            <?php if ($use_taxes) { ?>
1171 1171
             <tr class="row-tax">
1172
-                <td class="rate"><?php _e( 'Tax', 'invoicing' ); ?></td>
1173
-                <td class="total"><?php _e( wpinv_tax( $invoice_id, true ) ) ?></td>
1172
+                <td class="rate"><?php _e('Tax', 'invoicing'); ?></td>
1173
+                <td class="total"><?php _e(wpinv_tax($invoice_id, true)) ?></td>
1174 1174
             </tr>
1175
-            <?php do_action( 'wpinv_after_display_tax' ); ?>
1175
+            <?php do_action('wpinv_after_display_tax'); ?>
1176 1176
             <?php } ?>
1177
-            <?php if ( $fees = wpinv_get_fees( $invoice_id ) ) { ?>
1178
-                <?php foreach ( $fees as $fee ) { ?>
1177
+            <?php if ($fees = wpinv_get_fees($invoice_id)) { ?>
1178
+                <?php foreach ($fees as $fee) { ?>
1179 1179
                     <tr class="row-fee">
1180 1180
                         <td class="rate"><?php echo $fee['label']; ?></td>
1181 1181
                         <td class="total"><?php echo $fee['amount_display']; ?></td>
@@ -1183,73 +1183,73 @@  discard block
 block discarded – undo
1183 1183
                 <?php } ?>
1184 1184
             <?php } ?>
1185 1185
             <tr class="table-active row-total">
1186
-                <td class="rate"><strong><?php _e( 'Total', 'invoicing' ) ?></strong></td>
1187
-                <td class="total"><strong><?php _e( wpinv_payment_total( $invoice_id, true ) ) ?></strong></td>
1186
+                <td class="rate"><strong><?php _e('Total', 'invoicing') ?></strong></td>
1187
+                <td class="total"><strong><?php _e(wpinv_payment_total($invoice_id, true)) ?></strong></td>
1188 1188
             </tr>
1189
-            <?php do_action( 'wpinv_after_totals' ); ?>
1189
+            <?php do_action('wpinv_after_totals'); ?>
1190 1190
         </tbody>
1191 1191
 
1192 1192
     </table>
1193 1193
 
1194
-    <?php do_action( 'wpinv_after_totals_table' );
1194
+    <?php do_action('wpinv_after_totals_table');
1195 1195
 }
1196 1196
 
1197
-function wpinv_display_payments_info( $invoice_id = 0, $echo = true ) {
1198
-    $invoice = wpinv_get_invoice( $invoice_id );
1197
+function wpinv_display_payments_info($invoice_id = 0, $echo = true) {
1198
+    $invoice = wpinv_get_invoice($invoice_id);
1199 1199
     
1200 1200
     ob_start();
1201
-    do_action( 'wpinv_before_display_payments_info', $invoice_id );
1202
-    if ( ( $gateway_title = $invoice->get_gateway_title() ) || $invoice->is_paid() || $invoice->is_refunded() ) {
1201
+    do_action('wpinv_before_display_payments_info', $invoice_id);
1202
+    if (($gateway_title = $invoice->get_gateway_title()) || $invoice->is_paid() || $invoice->is_refunded()) {
1203 1203
         ?>
1204 1204
         <div class="wpi-payment-info">
1205
-            <p class="wpi-payment-gateway"><?php echo wp_sprintf( __( 'Payment via %s', 'invoicing' ), $gateway_title ? $gateway_title : __( 'Manually', 'invoicing' ) ); ?></p>
1206
-            <?php if ( $gateway_title ) { ?>
1207
-            <p class="wpi-payment-transid"><?php echo wp_sprintf( __( 'Transaction ID: %s', 'invoicing' ), $invoice->get_transaction_id() ); ?></p>
1205
+            <p class="wpi-payment-gateway"><?php echo wp_sprintf(__('Payment via %s', 'invoicing'), $gateway_title ? $gateway_title : __('Manually', 'invoicing')); ?></p>
1206
+            <?php if ($gateway_title) { ?>
1207
+            <p class="wpi-payment-transid"><?php echo wp_sprintf(__('Transaction ID: %s', 'invoicing'), $invoice->get_transaction_id()); ?></p>
1208 1208
             <?php } ?>
1209 1209
         </div>
1210 1210
         <?php
1211 1211
     }
1212
-    do_action( 'wpinv_after_display_payments_info', $invoice_id );
1212
+    do_action('wpinv_after_display_payments_info', $invoice_id);
1213 1213
     $outout = ob_get_clean();
1214 1214
     
1215
-    if ( $echo ) {
1215
+    if ($echo) {
1216 1216
         echo $outout;
1217 1217
     } else {
1218 1218
         return $outout;
1219 1219
     }
1220 1220
 }
1221 1221
 
1222
-function wpinv_display_style( $invoice ) {
1223
-    wp_register_style( 'wpinv-single-style', WPINV_PLUGIN_URL . 'assets/css/invoice.css', array(), WPINV_VERSION );
1222
+function wpinv_display_style($invoice) {
1223
+    wp_register_style('wpinv-single-style', WPINV_PLUGIN_URL . 'assets/css/invoice.css', array(), WPINV_VERSION);
1224 1224
     
1225
-    wp_print_styles( 'open-sans' );
1226
-    wp_print_styles( 'wpinv-single-style' );
1225
+    wp_print_styles('open-sans');
1226
+    wp_print_styles('wpinv-single-style');
1227 1227
 }
1228
-add_action( 'wpinv_invoice_print_head', 'wpinv_display_style' );
1229
-add_action( 'wpinv_invalid_invoice_head', 'wpinv_display_style' );
1228
+add_action('wpinv_invoice_print_head', 'wpinv_display_style');
1229
+add_action('wpinv_invalid_invoice_head', 'wpinv_display_style');
1230 1230
 
1231 1231
 function wpinv_checkout_billing_details() {  
1232 1232
     $invoice_id = (int)wpinv_get_invoice_cart_id();
1233 1233
     if (empty($invoice_id)) {
1234
-        wpinv_error_log( 'Invoice id not found', 'ERROR', __FILE__, __LINE__ );
1234
+        wpinv_error_log('Invoice id not found', 'ERROR', __FILE__, __LINE__);
1235 1235
         return null;
1236 1236
     }
1237 1237
     
1238
-    $invoice = wpinv_get_invoice_cart( $invoice_id );
1238
+    $invoice = wpinv_get_invoice_cart($invoice_id);
1239 1239
     if (empty($invoice)) {
1240
-        wpinv_error_log( 'Invoice not found', 'ERROR', __FILE__, __LINE__ );
1240
+        wpinv_error_log('Invoice not found', 'ERROR', __FILE__, __LINE__);
1241 1241
         return null;
1242 1242
     }
1243 1243
     $user_id        = $invoice->get_user_id();
1244 1244
     $user_info      = $invoice->get_user_info();
1245
-    $address_info   = wpinv_get_user_address( $user_id );
1245
+    $address_info   = wpinv_get_user_address($user_id);
1246 1246
     
1247
-    if ( empty( $user_info['first_name'] ) && !empty( $user_info['first_name'] ) ) {
1247
+    if (empty($user_info['first_name']) && !empty($user_info['first_name'])) {
1248 1248
         $user_info['first_name'] = $user_info['first_name'];
1249 1249
         $user_info['last_name'] = $user_info['last_name'];
1250 1250
     }
1251 1251
     
1252
-    if ( ( ( empty( $user_info['country'] ) && !empty( $address_info['country'] ) ) || ( empty( $user_info['state'] ) && !empty( $address_info['state'] ) && $user_info['country'] == $address_info['country'] ) ) ) {
1252
+    if (((empty($user_info['country']) && !empty($address_info['country'])) || (empty($user_info['state']) && !empty($address_info['state']) && $user_info['country'] == $address_info['country']))) {
1253 1253
         $user_info['country']   = $address_info['country'];
1254 1254
         $user_info['state']     = $address_info['state'];
1255 1255
         $user_info['city']      = $address_info['city'];
@@ -1265,103 +1265,103 @@  discard block
 block discarded – undo
1265 1265
         'address'
1266 1266
     );
1267 1267
     
1268
-    foreach ( $address_fields as $field ) {
1269
-        if ( empty( $user_info[$field] ) ) {
1268
+    foreach ($address_fields as $field) {
1269
+        if (empty($user_info[$field])) {
1270 1270
             $user_info[$field] = $address_info[$field];
1271 1271
         }
1272 1272
     }
1273 1273
     
1274
-    return apply_filters( 'wpinv_checkout_billing_details', $user_info, $invoice );
1274
+    return apply_filters('wpinv_checkout_billing_details', $user_info, $invoice);
1275 1275
 }
1276 1276
 
1277 1277
 function wpinv_admin_get_line_items($invoice = array()) {
1278 1278
     $item_quantities    = wpinv_item_quantities_enabled();
1279 1279
     $use_taxes          = wpinv_use_taxes();
1280 1280
     
1281
-    if ( empty( $invoice ) ) {
1281
+    if (empty($invoice)) {
1282 1282
         return NULL;
1283 1283
     }
1284 1284
     
1285 1285
     $cart_items = $invoice->get_cart_details();
1286
-    if ( empty( $cart_items ) ) {
1286
+    if (empty($cart_items)) {
1287 1287
         return NULL;
1288 1288
     }
1289 1289
     ob_start();
1290 1290
     
1291
-    do_action( 'wpinv_admin_before_line_items', $cart_items, $invoice );
1291
+    do_action('wpinv_admin_before_line_items', $cart_items, $invoice);
1292 1292
     
1293 1293
     $count = 0;
1294
-    foreach ( $cart_items as $key => $cart_item ) {
1294
+    foreach ($cart_items as $key => $cart_item) {
1295 1295
         $item_id    = $cart_item['id'];
1296
-        $wpi_item   = $item_id > 0 ? new WPInv_Item( $item_id ) : NULL;
1296
+        $wpi_item   = $item_id > 0 ? new WPInv_Item($item_id) : NULL;
1297 1297
         
1298 1298
         if (empty($wpi_item)) {
1299 1299
             continue;
1300 1300
         }
1301 1301
         
1302
-        $item_price     = wpinv_price( wpinv_format_amount( $cart_item['item_price'] ) );
1303
-        $quantity       = !empty( $cart_item['quantity'] ) && $cart_item['quantity'] > 0 ? $cart_item['quantity'] : 1;
1304
-        $item_subtotal  = wpinv_price( wpinv_format_amount( $cart_item['subtotal'] ) );
1302
+        $item_price     = wpinv_price(wpinv_format_amount($cart_item['item_price']));
1303
+        $quantity       = !empty($cart_item['quantity']) && $cart_item['quantity'] > 0 ? $cart_item['quantity'] : 1;
1304
+        $item_subtotal  = wpinv_price(wpinv_format_amount($cart_item['subtotal']));
1305 1305
         $can_remove     = true;
1306 1306
         
1307 1307
         $summary = '';
1308 1308
         if ($wpi_item->is_package() && !empty($cart_item['meta']['post_id'])) {
1309
-            $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>';
1310
-            $summary = wp_sprintf( __( '%s: %s', 'invoicing' ), $wpi_item->get_custom_singular_name(), $post_link );
1309
+            $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>';
1310
+            $summary = wp_sprintf(__('%s: %s', 'invoicing'), $wpi_item->get_custom_singular_name(), $post_link);
1311 1311
         }
1312
-        $summary = apply_filters( 'wpinv_admin_invoice_line_item_summary', $summary, $cart_item, $wpi_item, $invoice );
1312
+        $summary = apply_filters('wpinv_admin_invoice_line_item_summary', $summary, $cart_item, $wpi_item, $invoice);
1313 1313
         
1314 1314
         $item_tax       = '';
1315 1315
         $tax_rate       = '';
1316
-        if ( $cart_item['tax'] > 0 && $cart_item['subtotal'] > 0 ) {
1317
-            $item_tax = wpinv_price( wpinv_format_amount( $cart_item['tax'] ) );
1318
-            $tax_rate = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : ( $cart_item['tax'] / $cart_item['subtotal'] ) * 100;
1319
-            $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount( $tax_rate, 4 ) : '';
1316
+        if ($cart_item['tax'] > 0 && $cart_item['subtotal'] > 0) {
1317
+            $item_tax = wpinv_price(wpinv_format_amount($cart_item['tax']));
1318
+            $tax_rate = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : ($cart_item['tax'] / $cart_item['subtotal']) * 100;
1319
+            $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount($tax_rate, 4) : '';
1320 1320
             $tax_rate = $tax_rate != '' ? ' <span class="tax-rate">(' . $tax_rate . '%)</span>' : '';
1321 1321
         }
1322 1322
         $line_item_tax = $item_tax . $tax_rate;
1323 1323
         
1324
-        if ( $line_item_tax === '' ) {
1324
+        if ($line_item_tax === '') {
1325 1325
             $line_item_tax = 0; // Zero tax
1326 1326
         }
1327 1327
 
1328
-        $line_item = '<tr class="item item-' . ( ($count % 2 == 0) ? 'even' : 'odd' ) . '" data-item-id="' . $item_id . '">';
1328
+        $line_item = '<tr class="item item-' . (($count % 2 == 0) ? 'even' : 'odd') . '" data-item-id="' . $item_id . '">';
1329 1329
             $line_item .= '<td class="id">' . $item_id . '</td>';
1330
-            $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 );
1331
-            if ( $summary !== '' ) {
1332
-                $line_item .= '<span class="meta">' . wpautop( wp_kses_post( $summary ) ) . '</span>';
1330
+            $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);
1331
+            if ($summary !== '') {
1332
+                $line_item .= '<span class="meta">' . wpautop(wp_kses_post($summary)) . '</span>';
1333 1333
             }
1334 1334
             $line_item .= '</td>';
1335 1335
             $line_item .= '<td class="price">' . $item_price . '</td>';
1336 1336
             
1337
-            if ( $item_quantities ) {
1338
-                if ( count( $cart_items ) == 1 && $quantity <= 1 ) {
1337
+            if ($item_quantities) {
1338
+                if (count($cart_items) == 1 && $quantity <= 1) {
1339 1339
                     $can_remove = false;
1340 1340
                 }
1341 1341
                 $line_item .= '<td class="qty" data-quantity="' . $quantity . '">&nbsp;&times;&nbsp;' . $quantity . '</td>';
1342 1342
             } else {
1343
-                if ( count( $cart_items ) == 1 ) {
1343
+                if (count($cart_items) == 1) {
1344 1344
                     $can_remove = false;
1345 1345
                 }
1346 1346
             }
1347 1347
             $line_item .= '<td class="total">' . $item_subtotal . '</td>';
1348 1348
             
1349
-            if ( $use_taxes ) {
1349
+            if ($use_taxes) {
1350 1350
                 $line_item .= '<td class="tax">' . $line_item_tax . '</td>';
1351 1351
             }
1352 1352
             $line_item .= '<td class="action">';
1353
-            if ( !$invoice->is_paid() && !$invoice->is_refunded() && $can_remove ) {
1353
+            if (!$invoice->is_paid() && !$invoice->is_refunded() && $can_remove) {
1354 1354
                 $line_item .= '<i class="fa fa-remove wpinv-item-remove"></i>';
1355 1355
             }
1356 1356
             $line_item .= '</td>';
1357 1357
         $line_item .= '</tr>';
1358 1358
         
1359
-        echo apply_filters( 'wpinv_admin_line_item', $line_item, $cart_item, $invoice );
1359
+        echo apply_filters('wpinv_admin_line_item', $line_item, $cart_item, $invoice);
1360 1360
         
1361 1361
         $count++;
1362 1362
     } 
1363 1363
     
1364
-    do_action( 'wpinv_admin_after_line_items', $cart_items, $invoice );
1364
+    do_action('wpinv_admin_after_line_items', $cart_items, $invoice);
1365 1365
     
1366 1366
     return ob_get_clean();
1367 1367
 }
@@ -1372,35 +1372,35 @@  discard block
 block discarded – undo
1372 1372
     // Set current invoice id.
1373 1373
     $wpi_checkout_id = wpinv_get_invoice_cart_id();
1374 1374
     
1375
-    $form_action  = esc_url( wpinv_get_checkout_uri() );
1375
+    $form_action = esc_url(wpinv_get_checkout_uri());
1376 1376
 
1377 1377
     ob_start();
1378 1378
         echo '<div id="wpinv_checkout_wrap">';
1379 1379
         
1380
-        if ( wpinv_get_cart_contents() || wpinv_cart_has_fees() ) {
1380
+        if (wpinv_get_cart_contents() || wpinv_cart_has_fees()) {
1381 1381
             ?>
1382 1382
             <div id="wpinv_checkout_form_wrap" class="wpinv_clearfix table-responsive">
1383
-                <?php do_action( 'wpinv_before_checkout_form' ); ?>
1383
+                <?php do_action('wpinv_before_checkout_form'); ?>
1384 1384
                 <form id="wpinv_checkout_form" class="wpi-form" action="<?php echo $form_action; ?>" method="POST">
1385 1385
                     <?php
1386
-                    do_action( 'wpinv_checkout_form_top' );
1387
-                    do_action( 'wpinv_checkout_billing_info' );
1388
-                    do_action( 'wpinv_checkout_cart' );
1389
-                    do_action( 'wpinv_payment_mode_select'  );
1390
-                    do_action( 'wpinv_checkout_form_bottom' )
1386
+                    do_action('wpinv_checkout_form_top');
1387
+                    do_action('wpinv_checkout_billing_info');
1388
+                    do_action('wpinv_checkout_cart');
1389
+                    do_action('wpinv_payment_mode_select');
1390
+                    do_action('wpinv_checkout_form_bottom')
1391 1391
                     ?>
1392 1392
                 </form>
1393
-                <?php do_action( 'wpinv_after_purchase_form' ); ?>
1393
+                <?php do_action('wpinv_after_purchase_form'); ?>
1394 1394
             </div><!--end #wpinv_checkout_form_wrap-->
1395 1395
         <?php
1396 1396
         } else {
1397
-            do_action( 'wpinv_cart_empty' );
1397
+            do_action('wpinv_cart_empty');
1398 1398
         }
1399 1399
         echo '</div><!--end #wpinv_checkout_wrap-->';
1400 1400
     return ob_get_clean();
1401 1401
 }
1402 1402
 
1403
-function wpinv_checkout_cart( $cart_details = array(), $echo = true ) {
1403
+function wpinv_checkout_cart($cart_details = array(), $echo = true) {
1404 1404
     global $ajax_cart_details;
1405 1405
     $ajax_cart_details = $cart_details;
1406 1406
     /*
@@ -1415,25 +1415,25 @@  discard block
 block discarded – undo
1415 1415
     }
1416 1416
     */
1417 1417
     ob_start();
1418
-    do_action( 'wpinv_before_checkout_cart' );
1418
+    do_action('wpinv_before_checkout_cart');
1419 1419
     echo '<div id="wpinv_checkout_cart_form" method="post">';
1420 1420
         echo '<div id="wpinv_checkout_cart_wrap">';
1421
-            wpinv_get_template_part( 'wpinv-checkout-cart' );
1421
+            wpinv_get_template_part('wpinv-checkout-cart');
1422 1422
         echo '</div>';
1423 1423
     echo '</div>';
1424
-    do_action( 'wpinv_after_checkout_cart' );
1424
+    do_action('wpinv_after_checkout_cart');
1425 1425
     $content = ob_get_clean();
1426 1426
     
1427
-    if ( $echo ) {
1427
+    if ($echo) {
1428 1428
         echo $content;
1429 1429
     } else {
1430 1430
         return $content;
1431 1431
     }
1432 1432
 }
1433
-add_action( 'wpinv_checkout_cart', 'wpinv_checkout_cart', 10 );
1433
+add_action('wpinv_checkout_cart', 'wpinv_checkout_cart', 10);
1434 1434
 
1435 1435
 function wpinv_empty_cart_message() {
1436
-	return apply_filters( 'wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __( 'Your cart is empty.', 'invoicing' ) . '</span>' );
1436
+	return apply_filters('wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __('Your cart is empty.', 'invoicing') . '</span>');
1437 1437
 }
1438 1438
 
1439 1439
 /**
@@ -1445,91 +1445,91 @@  discard block
 block discarded – undo
1445 1445
 function wpinv_empty_checkout_cart() {
1446 1446
 	echo wpinv_empty_cart_message();
1447 1447
 }
1448
-add_action( 'wpinv_cart_empty', 'wpinv_empty_checkout_cart' );
1448
+add_action('wpinv_cart_empty', 'wpinv_empty_checkout_cart');
1449 1449
 
1450 1450
 function wpinv_save_cart_button() {
1451
-    if ( wpinv_is_cart_saving_disabled() )
1451
+    if (wpinv_is_cart_saving_disabled())
1452 1452
         return;
1453 1453
 ?>
1454
-    <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>
1454
+    <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>
1455 1455
 <?php
1456 1456
 }
1457 1457
 
1458 1458
 function wpinv_update_cart_button() {
1459
-    if ( !wpinv_item_quantities_enabled() )
1459
+    if (!wpinv_item_quantities_enabled())
1460 1460
         return;
1461 1461
 ?>
1462
-    <input type="submit" name="wpinv_update_cart_submit" class="wpinv-submit wpinv-no-js button" value="<?php _e( 'Update Cart', 'invoicing' ); ?>"/>
1462
+    <input type="submit" name="wpinv_update_cart_submit" class="wpinv-submit wpinv-no-js button" value="<?php _e('Update Cart', 'invoicing'); ?>"/>
1463 1463
     <input type="hidden" name="wpi_action" value="update_cart"/>
1464 1464
 <?php
1465 1465
 }
1466 1466
 
1467 1467
 function wpinv_checkout_cart_columns() {
1468 1468
     $default = 3;
1469
-    if ( wpinv_item_quantities_enabled() ) {
1469
+    if (wpinv_item_quantities_enabled()) {
1470 1470
         $default++;
1471 1471
     }
1472 1472
     
1473
-    if ( wpinv_use_taxes() ) {
1473
+    if (wpinv_use_taxes()) {
1474 1474
         $default++;
1475 1475
     }
1476 1476
 
1477
-    return apply_filters( 'wpinv_checkout_cart_columns', $default );
1477
+    return apply_filters('wpinv_checkout_cart_columns', $default);
1478 1478
 }
1479 1479
 
1480 1480
 function wpinv_display_cart_messages() {
1481 1481
     global $wpi_session;
1482 1482
 
1483
-    $messages = $wpi_session->get( 'wpinv_cart_messages' );
1483
+    $messages = $wpi_session->get('wpinv_cart_messages');
1484 1484
 
1485
-    if ( $messages ) {
1486
-        foreach ( $messages as $message_id => $message ) {
1485
+    if ($messages) {
1486
+        foreach ($messages as $message_id => $message) {
1487 1487
             // Try and detect what type of message this is
1488
-            if ( strpos( strtolower( $message ), 'error' ) ) {
1488
+            if (strpos(strtolower($message), 'error')) {
1489 1489
                 $type = 'error';
1490
-            } elseif ( strpos( strtolower( $message ), 'success' ) ) {
1490
+            } elseif (strpos(strtolower($message), 'success')) {
1491 1491
                 $type = 'success';
1492 1492
             } else {
1493 1493
                 $type = 'info';
1494 1494
             }
1495 1495
 
1496
-            $classes = apply_filters( 'wpinv_' . $type . '_class', array( 'wpinv_errors', 'wpinv-alert', 'wpinv-alert-' . $type ) );
1496
+            $classes = apply_filters('wpinv_' . $type . '_class', array('wpinv_errors', 'wpinv-alert', 'wpinv-alert-' . $type));
1497 1497
 
1498
-            echo '<div class="' . implode( ' ', $classes ) . '">';
1498
+            echo '<div class="' . implode(' ', $classes) . '">';
1499 1499
                 // Loop message codes and display messages
1500 1500
                     echo '<p class="wpinv_error" id="wpinv_msg_' . $message_id . '">' . $message . '</p>';
1501 1501
             echo '</div>';
1502 1502
         }
1503 1503
 
1504 1504
         // Remove all of the cart saving messages
1505
-        $wpi_session->set( 'wpinv_cart_messages', null );
1505
+        $wpi_session->set('wpinv_cart_messages', null);
1506 1506
     }
1507 1507
 }
1508
-add_action( 'wpinv_before_checkout_cart', 'wpinv_display_cart_messages' );
1508
+add_action('wpinv_before_checkout_cart', 'wpinv_display_cart_messages');
1509 1509
 
1510 1510
 function wpinv_discount_field() {
1511
-    if ( isset( $_GET['wpi-gateway'] ) && wpinv_is_ajax_disabled() ) {
1511
+    if (isset($_GET['wpi-gateway']) && wpinv_is_ajax_disabled()) {
1512 1512
         return; // Only show before a payment method has been selected if ajax is disabled
1513 1513
     }
1514 1514
 
1515
-    if ( !wpinv_is_checkout() ) {
1515
+    if (!wpinv_is_checkout()) {
1516 1516
         return;
1517 1517
     }
1518 1518
 
1519
-    if ( wpinv_has_active_discounts() && wpinv_get_cart_total() ) {
1519
+    if (wpinv_has_active_discounts() && wpinv_get_cart_total()) {
1520 1520
     ?>
1521 1521
     <div id="wpinv-discount-field" class="panel panel-default">
1522 1522
         <div class="panel-body">
1523 1523
             <p>
1524
-                <label class="wpinv-label" for="wpinv_discount_code"><strong><?php _e( 'Discount', 'invoicing' ); ?></strong></label>
1525
-                <span class="wpinv-description"><?php _e( 'Enter a discount code if you have one.', 'invoicing' ); ?></span>
1524
+                <label class="wpinv-label" for="wpinv_discount_code"><strong><?php _e('Discount', 'invoicing'); ?></strong></label>
1525
+                <span class="wpinv-description"><?php _e('Enter a discount code if you have one.', 'invoicing'); ?></span>
1526 1526
             </p>
1527 1527
             <div class="form-group row">
1528 1528
                 <div class="col-sm-4">
1529
-                    <input class="wpinv-input form-control" type="text" id="wpinv_discount_code" name="wpinv_discount_code" placeholder="<?php _e( 'Enter discount code', 'invoicing' ); ?>"/>
1529
+                    <input class="wpinv-input form-control" type="text" id="wpinv_discount_code" name="wpinv_discount_code" placeholder="<?php _e('Enter discount code', 'invoicing'); ?>"/>
1530 1530
                 </div>
1531 1531
                 <div class="col-sm-3">
1532
-                    <button id="wpi-apply-discount" type="button" class="btn btn-success btn-sm"><?php _e( 'Apply Discount', 'invoicing' ); ?></button>
1532
+                    <button id="wpi-apply-discount" type="button" class="btn btn-success btn-sm"><?php _e('Apply Discount', 'invoicing'); ?></button>
1533 1533
                 </div>
1534 1534
                 <div style="clear:both"></div>
1535 1535
                 <div class="col-sm-12 wpinv-discount-msg">
@@ -1542,10 +1542,10 @@  discard block
 block discarded – undo
1542 1542
 <?php
1543 1543
     }
1544 1544
 }
1545
-add_action( 'wpinv_after_checkout_cart', 'wpinv_discount_field', -10 );
1545
+add_action('wpinv_after_checkout_cart', 'wpinv_discount_field', -10);
1546 1546
 
1547 1547
 function wpinv_agree_to_terms_js() {
1548
-    if ( wpinv_get_option( 'show_agree_to_terms', false ) ) {
1548
+    if (wpinv_get_option('show_agree_to_terms', false)) {
1549 1549
 ?>
1550 1550
 <script type="text/javascript">
1551 1551
     jQuery(document).ready(function($){
@@ -1560,126 +1560,126 @@  discard block
 block discarded – undo
1560 1560
 <?php
1561 1561
     }
1562 1562
 }
1563
-add_action( 'wpinv_checkout_form_top', 'wpinv_agree_to_terms_js' );
1563
+add_action('wpinv_checkout_form_top', 'wpinv_agree_to_terms_js');
1564 1564
 
1565 1565
 function wpinv_payment_mode_select() {
1566
-    $gateways = wpinv_get_enabled_payment_gateways( true );
1567
-    $gateways = apply_filters( 'wpinv_payment_gateways_on_cart', $gateways );
1566
+    $gateways = wpinv_get_enabled_payment_gateways(true);
1567
+    $gateways = apply_filters('wpinv_payment_gateways_on_cart', $gateways);
1568 1568
     $page_URL = wpinv_get_current_page_url();
1569
-    $invoice = wpinv_get_invoice( 0, true );
1569
+    $invoice = wpinv_get_invoice(0, true);
1570 1570
     
1571 1571
     do_action('wpinv_payment_mode_top');
1572 1572
     $invoice_id = (int)$invoice->ID;
1573
-    $chosen_gateway = wpinv_get_chosen_gateway( $invoice_id );
1573
+    $chosen_gateway = wpinv_get_chosen_gateway($invoice_id);
1574 1574
     ?>
1575
-    <div id="wpinv_payment_mode_select" data-gateway="<?php echo $chosen_gateway; ?>" <?php echo ( $invoice->is_free() ? 'style="display:none;"' : '' ); ?>>
1576
-            <?php do_action( 'wpinv_payment_mode_before_gateways_wrap' ); ?>
1575
+    <div id="wpinv_payment_mode_select" data-gateway="<?php echo $chosen_gateway; ?>" <?php echo ($invoice->is_free() ? 'style="display:none;"' : ''); ?>>
1576
+            <?php do_action('wpinv_payment_mode_before_gateways_wrap'); ?>
1577 1577
             <div id="wpinv-payment-mode-wrap" class="panel panel-default">
1578
-                <div class="panel-heading"><h3 class="panel-title"><?php _e( 'Select Payment Method', 'invoicing' ); ?></h3></div>
1578
+                <div class="panel-heading"><h3 class="panel-title"><?php _e('Select Payment Method', 'invoicing'); ?></h3></div>
1579 1579
                 <div class="panel-body list-group wpi-payment_methods">
1580 1580
                     <?php
1581
-                    do_action( 'wpinv_payment_mode_before_gateways' );
1581
+                    do_action('wpinv_payment_mode_before_gateways');
1582 1582
                     
1583
-                    if(!empty($gateways)){
1584
-	                    foreach ( $gateways as $gateway_id => $gateway ) {
1585
-		                    $checked = checked( $gateway_id, $chosen_gateway, false );
1586
-		                    $button_label = wpinv_get_gateway_button_label( $gateway_id );
1587
-		                    $description = wpinv_get_gateway_description( $gateway_id );
1583
+                    if (!empty($gateways)) {
1584
+	                    foreach ($gateways as $gateway_id => $gateway) {
1585
+		                    $checked = checked($gateway_id, $chosen_gateway, false);
1586
+		                    $button_label = wpinv_get_gateway_button_label($gateway_id);
1587
+		                    $description = wpinv_get_gateway_description($gateway_id);
1588 1588
 		                    ?>
1589 1589
 		                    <div class="list-group-item">
1590 1590
 			                    <div class="radio">
1591
-				                    <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>
1591
+				                    <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>
1592 1592
 			                    </div>
1593
-			                    <div style="display:none;" class="payment_box wpi_gateway_<?php echo esc_attr( $gateway_id );?>" role="alert">
1594
-				                    <?php if ( !empty( $description ) ) { ?>
1595
-					                    <div class="wpi-gateway-desc alert alert-info"><?php echo $description;?></div>
1593
+			                    <div style="display:none;" class="payment_box wpi_gateway_<?php echo esc_attr($gateway_id); ?>" role="alert">
1594
+				                    <?php if (!empty($description)) { ?>
1595
+					                    <div class="wpi-gateway-desc alert alert-info"><?php echo $description; ?></div>
1596 1596
 				                    <?php } ?>
1597
-				                    <?php do_action( 'wpinv_' . $gateway_id . '_cc_form', $invoice_id ) ;?>
1597
+				                    <?php do_action('wpinv_' . $gateway_id . '_cc_form', $invoice_id); ?>
1598 1598
 			                    </div>
1599 1599
 		                    </div>
1600 1600
 		                    <?php
1601 1601
 	                    }
1602
-                    }else{
1603
-	                    echo '<div class="alert alert-warning">'. __('No payment gateway active','invoicing') .'</div>';
1602
+                    } else {
1603
+	                    echo '<div class="alert alert-warning">' . __('No payment gateway active', 'invoicing') . '</div>';
1604 1604
                     }
1605 1605
 
1606
-                    do_action( 'wpinv_payment_mode_after_gateways' );
1606
+                    do_action('wpinv_payment_mode_after_gateways');
1607 1607
                     ?>
1608 1608
                 </div>
1609 1609
             </div>
1610
-            <?php do_action( 'wpinv_payment_mode_after_gateways_wrap' ); ?>
1610
+            <?php do_action('wpinv_payment_mode_after_gateways_wrap'); ?>
1611 1611
     </div>
1612 1612
     <?php
1613 1613
     do_action('wpinv_payment_mode_bottom');
1614 1614
 }
1615
-add_action( 'wpinv_payment_mode_select', 'wpinv_payment_mode_select' );
1615
+add_action('wpinv_payment_mode_select', 'wpinv_payment_mode_select');
1616 1616
 
1617 1617
 function wpinv_checkout_billing_info() {    
1618
-    if ( wpinv_is_checkout() ) {
1618
+    if (wpinv_is_checkout()) {
1619 1619
         $logged_in          = is_user_logged_in();
1620 1620
         $billing_details    = wpinv_checkout_billing_details();
1621
-        $selected_country   = !empty( $billing_details['country'] ) ? $billing_details['country'] : wpinv_default_billing_country();
1621
+        $selected_country   = !empty($billing_details['country']) ? $billing_details['country'] : wpinv_default_billing_country();
1622 1622
         ?>
1623 1623
         <div id="wpinv-fields" class="clearfix">
1624 1624
             <div id="wpi-billing" class="wpi-billing clearfix panel panel-default">
1625
-                <div class="panel-heading"><h3 class="panel-title"><?php _e( 'Billing Details', 'invoicing' );?></h3></div>
1625
+                <div class="panel-heading"><h3 class="panel-title"><?php _e('Billing Details', 'invoicing'); ?></h3></div>
1626 1626
                 <div id="wpinv-fields-box" class="panel-body">
1627
-                    <?php do_action( 'wpinv_checkout_billing_fields_first', $billing_details ); ?>
1627
+                    <?php do_action('wpinv_checkout_billing_fields_first', $billing_details); ?>
1628 1628
                     <p class="wpi-cart-field wpi-col2 wpi-colf">
1629
-                        <label for="wpinv_first_name" class="wpi-label"><?php _e( 'First Name', 'invoicing' );?><?php if ( wpinv_get_option( 'fname_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label>
1629
+                        <label for="wpinv_first_name" class="wpi-label"><?php _e('First Name', 'invoicing'); ?><?php if (wpinv_get_option('fname_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label>
1630 1630
                         <?php
1631
-                        echo wpinv_html_text( array(
1631
+                        echo wpinv_html_text(array(
1632 1632
                                 'id'            => 'wpinv_first_name',
1633 1633
                                 'name'          => 'wpinv_first_name',
1634 1634
                                 'value'         => $billing_details['first_name'],
1635 1635
                                 'class'         => 'wpi-input form-control',
1636
-                                'placeholder'   => __( 'First name', 'invoicing' ),
1637
-                                'required'      => (bool)wpinv_get_option( 'fname_mandatory' ),
1638
-                            ) );
1636
+                                'placeholder'   => __('First name', 'invoicing'),
1637
+                                'required'      => (bool)wpinv_get_option('fname_mandatory'),
1638
+                            ));
1639 1639
                         ?>
1640 1640
                     </p>
1641 1641
                     <p class="wpi-cart-field wpi-col2 wpi-coll">
1642
-                        <label for="wpinv_last_name" class="wpi-label"><?php _e( 'Last Name', 'invoicing' );?><?php if ( wpinv_get_option( 'lname_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label>
1642
+                        <label for="wpinv_last_name" class="wpi-label"><?php _e('Last Name', 'invoicing'); ?><?php if (wpinv_get_option('lname_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label>
1643 1643
                         <?php
1644
-                        echo wpinv_html_text( array(
1644
+                        echo wpinv_html_text(array(
1645 1645
                                 'id'            => 'wpinv_last_name',
1646 1646
                                 'name'          => 'wpinv_last_name',
1647 1647
                                 'value'         => $billing_details['last_name'],
1648 1648
                                 'class'         => 'wpi-input form-control',
1649
-                                'placeholder'   => __( 'Last name', 'invoicing' ),
1650
-                                'required'      => (bool)wpinv_get_option( 'lname_mandatory' ),
1651
-                            ) );
1649
+                                'placeholder'   => __('Last name', 'invoicing'),
1650
+                                'required'      => (bool)wpinv_get_option('lname_mandatory'),
1651
+                            ));
1652 1652
                         ?>
1653 1653
                     </p>
1654 1654
                     <p class="wpi-cart-field wpi-col2 wpi-colf">
1655
-                        <label for="wpinv_address" class="wpi-label"><?php _e( 'Address', 'invoicing' );?><?php if ( wpinv_get_option( 'address_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label>
1655
+                        <label for="wpinv_address" class="wpi-label"><?php _e('Address', 'invoicing'); ?><?php if (wpinv_get_option('address_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label>
1656 1656
                         <?php
1657
-                        echo wpinv_html_text( array(
1657
+                        echo wpinv_html_text(array(
1658 1658
                                 'id'            => 'wpinv_address',
1659 1659
                                 'name'          => 'wpinv_address',
1660 1660
                                 'value'         => $billing_details['address'],
1661 1661
                                 'class'         => 'wpi-input form-control',
1662
-                                'placeholder'   => __( 'Address', 'invoicing' ),
1663
-                                'required'      => (bool)wpinv_get_option( 'address_mandatory' ),
1664
-                            ) );
1662
+                                'placeholder'   => __('Address', 'invoicing'),
1663
+                                'required'      => (bool)wpinv_get_option('address_mandatory'),
1664
+                            ));
1665 1665
                         ?>
1666 1666
                     </p>
1667 1667
                     <p class="wpi-cart-field wpi-col2 wpi-coll">
1668
-                        <label for="wpinv_city" class="wpi-label"><?php _e( 'City', 'invoicing' );?><?php if ( wpinv_get_option( 'city_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label>
1668
+                        <label for="wpinv_city" class="wpi-label"><?php _e('City', 'invoicing'); ?><?php if (wpinv_get_option('city_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label>
1669 1669
                         <?php
1670
-                        echo wpinv_html_text( array(
1670
+                        echo wpinv_html_text(array(
1671 1671
                                 'id'            => 'wpinv_city',
1672 1672
                                 'name'          => 'wpinv_city',
1673 1673
                                 'value'         => $billing_details['city'],
1674 1674
                                 'class'         => 'wpi-input form-control',
1675
-                                'placeholder'   => __( 'City', 'invoicing' ),
1676
-                                'required'      => (bool)wpinv_get_option( 'city_mandatory' ),
1677
-                            ) );
1675
+                                'placeholder'   => __('City', 'invoicing'),
1676
+                                'required'      => (bool)wpinv_get_option('city_mandatory'),
1677
+                            ));
1678 1678
                         ?>
1679 1679
                     </p>
1680 1680
                     <p id="wpinv_country_box" class="wpi-cart-field wpi-col2 wpi-colf">
1681
-                        <label for="wpinv_country" class="wpi-label"><?php _e( 'Country', 'invoicing' );?><?php if ( wpinv_get_option( 'country_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label>
1682
-                        <?php echo wpinv_html_select( array(
1681
+                        <label for="wpinv_country" class="wpi-label"><?php _e('Country', 'invoicing'); ?><?php if (wpinv_get_option('country_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label>
1682
+                        <?php echo wpinv_html_select(array(
1683 1683
                             'options'          => wpinv_get_country_list(),
1684 1684
                             'name'             => 'wpinv_country',
1685 1685
                             'id'               => 'wpinv_country',
@@ -1687,16 +1687,16 @@  discard block
 block discarded – undo
1687 1687
                             'show_option_all'  => false,
1688 1688
                             'show_option_none' => false,
1689 1689
                             'class'            => 'wpi-input form-control',
1690
-                            'placeholder'      => __( 'Choose a country', 'invoicing' ),
1691
-                            'required'         => (bool)wpinv_get_option( 'country_mandatory' ),
1692
-                        ) ); ?>
1690
+                            'placeholder'      => __('Choose a country', 'invoicing'),
1691
+                            'required'         => (bool)wpinv_get_option('country_mandatory'),
1692
+                        )); ?>
1693 1693
                     </p>
1694 1694
                     <p id="wpinv_state_box" class="wpi-cart-field wpi-col2 wpi-coll">
1695
-                        <label for="wpinv_state" class="wpi-label"><?php _e( 'State / Province', 'invoicing' );?><?php if ( wpinv_get_option( 'state_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label>
1695
+                        <label for="wpinv_state" class="wpi-label"><?php _e('State / Province', 'invoicing'); ?><?php if (wpinv_get_option('state_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label>
1696 1696
                         <?php
1697
-                        $states = wpinv_get_country_states( $selected_country );
1698
-                        if( !empty( $states ) ) {
1699
-                            echo wpinv_html_select( array(
1697
+                        $states = wpinv_get_country_states($selected_country);
1698
+                        if (!empty($states)) {
1699
+                            echo wpinv_html_select(array(
1700 1700
                                 'options'          => $states,
1701 1701
                                 'name'             => 'wpinv_state',
1702 1702
                                 'id'               => 'wpinv_state',
@@ -1704,61 +1704,61 @@  discard block
 block discarded – undo
1704 1704
                                 'show_option_all'  => false,
1705 1705
                                 'show_option_none' => false,
1706 1706
                                 'class'            => 'wpi-input form-control',
1707
-                                'placeholder'      => __( 'Choose a state', 'invoicing' ),
1708
-                                'required'         => (bool)wpinv_get_option( 'state_mandatory' ),
1709
-                            ) );
1707
+                                'placeholder'      => __('Choose a state', 'invoicing'),
1708
+                                'required'         => (bool)wpinv_get_option('state_mandatory'),
1709
+                            ));
1710 1710
                         } else {
1711
-                            echo wpinv_html_text( array(
1711
+                            echo wpinv_html_text(array(
1712 1712
                                 'name'          => 'wpinv_state',
1713 1713
                                 'value'         => $billing_details['state'],
1714 1714
                                 'id'            => 'wpinv_state',
1715 1715
                                 'class'         => 'wpi-input form-control',
1716
-                                'placeholder'   => __( 'State / Province', 'invoicing' ),
1717
-                                'required'      => (bool)wpinv_get_option( 'state_mandatory' ),
1718
-                            ) );
1716
+                                'placeholder'   => __('State / Province', 'invoicing'),
1717
+                                'required'      => (bool)wpinv_get_option('state_mandatory'),
1718
+                            ));
1719 1719
                         }
1720 1720
                         ?>
1721 1721
                     </p>
1722 1722
                     <p class="wpi-cart-field wpi-col2 wpi-colf">
1723
-                        <label for="wpinv_zip" class="wpi-label"><?php _e( 'ZIP / Postcode', 'invoicing' );?><?php if ( wpinv_get_option( 'zip_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label>
1723
+                        <label for="wpinv_zip" class="wpi-label"><?php _e('ZIP / Postcode', 'invoicing'); ?><?php if (wpinv_get_option('zip_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label>
1724 1724
                         <?php
1725
-                        echo wpinv_html_text( array(
1725
+                        echo wpinv_html_text(array(
1726 1726
                                 'name'          => 'wpinv_zip',
1727 1727
                                 'value'         => $billing_details['zip'],
1728 1728
                                 'id'            => 'wpinv_zip',
1729 1729
                                 'class'         => 'wpi-input form-control',
1730
-                                'placeholder'   => __( 'ZIP / Postcode', 'invoicing' ),
1731
-                                'required'      => (bool)wpinv_get_option( 'zip_mandatory' ),
1732
-                            ) );
1730
+                                'placeholder'   => __('ZIP / Postcode', 'invoicing'),
1731
+                                'required'      => (bool)wpinv_get_option('zip_mandatory'),
1732
+                            ));
1733 1733
                         ?>
1734 1734
                     </p>
1735 1735
                     <p class="wpi-cart-field wpi-col2 wpi-coll">
1736
-                        <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>
1736
+                        <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>
1737 1737
                         <?php
1738
-                        echo wpinv_html_text( array(
1738
+                        echo wpinv_html_text(array(
1739 1739
                                 'id'            => 'wpinv_phone',
1740 1740
                                 'name'          => 'wpinv_phone',
1741 1741
                                 'value'         => $billing_details['phone'],
1742 1742
                                 'class'         => 'wpi-input form-control',
1743
-                                'placeholder'   => __( 'Phone', 'invoicing' ),
1744
-                                'required'      => (bool)wpinv_get_option( 'phone_mandatory' ),
1745
-                            ) );
1743
+                                'placeholder'   => __('Phone', 'invoicing'),
1744
+                                'required'      => (bool)wpinv_get_option('phone_mandatory'),
1745
+                            ));
1746 1746
                         ?>
1747 1747
                     </p>
1748
-                    <?php do_action( 'wpinv_checkout_billing_fields_last', $billing_details ); ?>
1748
+                    <?php do_action('wpinv_checkout_billing_fields_last', $billing_details); ?>
1749 1749
                     <div class="clearfix"></div>
1750 1750
                 </div>
1751 1751
             </div>
1752
-            <?php do_action( 'wpinv_after_billing_fields', $billing_details ); ?>
1752
+            <?php do_action('wpinv_after_billing_fields', $billing_details); ?>
1753 1753
         </div>
1754 1754
         <?php
1755 1755
     }
1756 1756
 }
1757
-add_action( 'wpinv_checkout_billing_info', 'wpinv_checkout_billing_info' );
1757
+add_action('wpinv_checkout_billing_info', 'wpinv_checkout_billing_info');
1758 1758
 
1759 1759
 function wpinv_checkout_hidden_fields() {
1760 1760
 ?>
1761
-    <?php if ( is_user_logged_in() ) { ?>
1761
+    <?php if (is_user_logged_in()) { ?>
1762 1762
     <input type="hidden" name="wpinv_user_id" value="<?php echo get_current_user_id(); ?>"/>
1763 1763
     <?php } ?>
1764 1764
     <input type="hidden" name="wpi_action" value="payment" />
@@ -1768,9 +1768,9 @@  discard block
 block discarded – undo
1768 1768
 function wpinv_checkout_button_purchase() {
1769 1769
     ob_start();
1770 1770
 ?>
1771
-    <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' ) ?>"/>
1771
+    <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') ?>"/>
1772 1772
 <?php
1773
-    return apply_filters( 'wpinv_checkout_button_purchase', ob_get_clean() );
1773
+    return apply_filters('wpinv_checkout_button_purchase', ob_get_clean());
1774 1774
 }
1775 1775
 
1776 1776
 function wpinv_checkout_total() {
@@ -1779,96 +1779,96 @@  discard block
 block discarded – undo
1779 1779
 <div id="wpinv_checkout_total" class="panel panel-info">
1780 1780
     <div class="panel-body">
1781 1781
     <?php
1782
-    do_action( 'wpinv_purchase_form_before_checkout_total' );
1782
+    do_action('wpinv_purchase_form_before_checkout_total');
1783 1783
     ?>
1784
-    <strong><?php _e( 'Invoice Total:', 'invoicing' ) ?></strong> <span class="wpinv-chdeckout-total"><?php echo $cart_total;?></span>
1784
+    <strong><?php _e('Invoice Total:', 'invoicing') ?></strong> <span class="wpinv-chdeckout-total"><?php echo $cart_total; ?></span>
1785 1785
     <?php
1786
-    do_action( 'wpinv_purchase_form_after_checkout_total' );
1786
+    do_action('wpinv_purchase_form_after_checkout_total');
1787 1787
     ?>
1788 1788
     </div>
1789 1789
 </div>
1790 1790
 <?php
1791 1791
 }
1792
-add_action( 'wpinv_checkout_form_bottom', 'wpinv_checkout_total', 9998 );
1792
+add_action('wpinv_checkout_form_bottom', 'wpinv_checkout_total', 9998);
1793 1793
 
1794 1794
 function wpinv_checkout_submit() {
1795 1795
 ?>
1796 1796
 <div id="wpinv_purchase_submit" class="panel panel-success">
1797 1797
     <div class="panel-body text-center">
1798 1798
     <?php
1799
-    do_action( 'wpinv_purchase_form_before_submit' );
1799
+    do_action('wpinv_purchase_form_before_submit');
1800 1800
     wpinv_checkout_hidden_fields();
1801 1801
     echo wpinv_checkout_button_purchase();
1802
-    do_action( 'wpinv_purchase_form_after_submit' );
1802
+    do_action('wpinv_purchase_form_after_submit');
1803 1803
     ?>
1804 1804
     </div>
1805 1805
 </div>
1806 1806
 <?php
1807 1807
 }
1808
-add_action( 'wpinv_checkout_form_bottom', 'wpinv_checkout_submit', 9999 );
1808
+add_action('wpinv_checkout_form_bottom', 'wpinv_checkout_submit', 9999);
1809 1809
 
1810
-function wpinv_receipt_billing_address( $invoice_id = 0 ) {
1811
-    $invoice = wpinv_get_invoice( $invoice_id );
1810
+function wpinv_receipt_billing_address($invoice_id = 0) {
1811
+    $invoice = wpinv_get_invoice($invoice_id);
1812 1812
     
1813
-    if ( empty( $invoice ) ) {
1813
+    if (empty($invoice)) {
1814 1814
         return NULL;
1815 1815
     }
1816 1816
     
1817 1817
     $billing_details = $invoice->get_user_info();
1818 1818
     $address_row = '';
1819
-    if ( $address = $billing_details['address'] ) {
1820
-        $address_row .= wpautop( wp_kses_post( $address ) );
1819
+    if ($address = $billing_details['address']) {
1820
+        $address_row .= wpautop(wp_kses_post($address));
1821 1821
     }
1822 1822
     
1823 1823
     $address_fields = array();
1824
-    if ( !empty( $billing_details['city'] ) ) {
1824
+    if (!empty($billing_details['city'])) {
1825 1825
         $address_fields[] = $billing_details['city'];
1826 1826
     }
1827 1827
     
1828
-    $billing_country = !empty( $billing_details['country'] ) ? $billing_details['country'] : '';
1829
-    if ( !empty( $billing_details['state'] ) ) {
1830
-        $address_fields[] = wpinv_state_name( $billing_details['state'], $billing_country );
1828
+    $billing_country = !empty($billing_details['country']) ? $billing_details['country'] : '';
1829
+    if (!empty($billing_details['state'])) {
1830
+        $address_fields[] = wpinv_state_name($billing_details['state'], $billing_country);
1831 1831
     }
1832 1832
     
1833
-    if ( !empty( $billing_country ) ) {
1834
-        $address_fields[] = wpinv_country_name( $billing_country );
1833
+    if (!empty($billing_country)) {
1834
+        $address_fields[] = wpinv_country_name($billing_country);
1835 1835
     }
1836 1836
     
1837
-    if ( !empty( $address_fields ) ) {
1838
-        $address_fields = implode( ", ", $address_fields );
1837
+    if (!empty($address_fields)) {
1838
+        $address_fields = implode(", ", $address_fields);
1839 1839
         
1840
-        if ( !empty( $billing_details['zip'] ) ) {
1840
+        if (!empty($billing_details['zip'])) {
1841 1841
             $address_fields .= ' ' . $billing_details['zip'];
1842 1842
         }
1843 1843
         
1844
-        $address_row .= wpautop( wp_kses_post( $address_fields ) );
1844
+        $address_row .= wpautop(wp_kses_post($address_fields));
1845 1845
     }
1846 1846
     ob_start();
1847 1847
     ?>
1848 1848
     <table class="table table-bordered table-sm wpi-billing-details">
1849 1849
         <tbody>
1850 1850
             <tr class="wpi-receipt-name">
1851
-                <th class="text-left"><?php _e( 'Name', 'invoicing' ); ?></th>
1852
-                <td><?php echo esc_html( trim( $billing_details['first_name'] . ' ' . $billing_details['last_name'] ) ) ;?></td>
1851
+                <th class="text-left"><?php _e('Name', 'invoicing'); ?></th>
1852
+                <td><?php echo esc_html(trim($billing_details['first_name'] . ' ' . $billing_details['last_name'])); ?></td>
1853 1853
             </tr>
1854 1854
             <tr class="wpi-receipt-email">
1855
-                <th class="text-left"><?php _e( 'Email', 'invoicing' ); ?></th>
1856
-                <td><?php echo $billing_details['email'] ;?></td>
1855
+                <th class="text-left"><?php _e('Email', 'invoicing'); ?></th>
1856
+                <td><?php echo $billing_details['email']; ?></td>
1857 1857
             </tr>
1858
-            <?php if ( $billing_details['company'] ) { ?>
1858
+            <?php if ($billing_details['company']) { ?>
1859 1859
             <tr class="wpi-receipt-company">
1860
-                <th class="text-left"><?php _e( 'Company', 'invoicing' ); ?></th>
1861
-                <td><?php echo esc_html( $billing_details['company'] ) ;?></td>
1860
+                <th class="text-left"><?php _e('Company', 'invoicing'); ?></th>
1861
+                <td><?php echo esc_html($billing_details['company']); ?></td>
1862 1862
             </tr>
1863 1863
             <?php } ?>
1864 1864
             <tr class="wpi-receipt-address">
1865
-                <th class="text-left"><?php _e( 'Address', 'invoicing' ); ?></th>
1866
-                <td><?php echo $address_row ;?></td>
1865
+                <th class="text-left"><?php _e('Address', 'invoicing'); ?></th>
1866
+                <td><?php echo $address_row; ?></td>
1867 1867
             </tr>
1868
-            <?php if ( $billing_details['phone'] ) { ?>
1868
+            <?php if ($billing_details['phone']) { ?>
1869 1869
             <tr class="wpi-receipt-phone">
1870
-                <th class="text-left"><?php _e( 'Phone', 'invoicing' ); ?></th>
1871
-                <td><?php echo esc_html( $billing_details['phone'] ) ;?></td>
1870
+                <th class="text-left"><?php _e('Phone', 'invoicing'); ?></th>
1871
+                <td><?php echo esc_html($billing_details['phone']); ?></td>
1872 1872
             </tr>
1873 1873
             <?php } ?>
1874 1874
         </tbody>
@@ -1876,103 +1876,103 @@  discard block
 block discarded – undo
1876 1876
     <?php
1877 1877
     $output = ob_get_clean();
1878 1878
     
1879
-    $output = apply_filters( 'wpinv_receipt_billing_address', $output, $invoice_id );
1879
+    $output = apply_filters('wpinv_receipt_billing_address', $output, $invoice_id);
1880 1880
 
1881 1881
     echo $output;
1882 1882
 }
1883 1883
 
1884
-function wpinv_filter_success_page_content( $content ) {
1885
-    if ( isset( $_GET['payment-confirm'] ) && wpinv_is_success_page() ) {
1886
-        if ( has_filter( 'wpinv_payment_confirm_' . sanitize_text_field( $_GET['payment-confirm'] ) ) ) {
1887
-            $content = apply_filters( 'wpinv_payment_confirm_' . sanitize_text_field( $_GET['payment-confirm'] ), $content );
1884
+function wpinv_filter_success_page_content($content) {
1885
+    if (isset($_GET['payment-confirm']) && wpinv_is_success_page()) {
1886
+        if (has_filter('wpinv_payment_confirm_' . sanitize_text_field($_GET['payment-confirm']))) {
1887
+            $content = apply_filters('wpinv_payment_confirm_' . sanitize_text_field($_GET['payment-confirm']), $content);
1888 1888
         }
1889 1889
     }
1890 1890
 
1891 1891
     return $content;
1892 1892
 }
1893
-add_filter( 'the_content', 'wpinv_filter_success_page_content', 99999 );
1893
+add_filter('the_content', 'wpinv_filter_success_page_content', 99999);
1894 1894
 
1895
-function wpinv_receipt_actions( $invoice ) {
1896
-    if ( !empty( $invoice ) ) {
1895
+function wpinv_receipt_actions($invoice) {
1896
+    if (!empty($invoice)) {
1897 1897
         $actions = array();
1898 1898
 
1899
-        if ( wpinv_user_can_view_invoice( $invoice->ID ) ) {
1900
-            $actions['print']   = array(
1901
-                'url'  => $invoice->get_view_url( true ),
1902
-                'name' => __( 'Print Invoice', 'invoicing' ),
1899
+        if (wpinv_user_can_view_invoice($invoice->ID)) {
1900
+            $actions['print'] = array(
1901
+                'url'  => $invoice->get_view_url(true),
1902
+                'name' => __('Print Invoice', 'invoicing'),
1903 1903
                 'class' => 'btn-primary',
1904 1904
             );
1905 1905
         }
1906 1906
 
1907
-        if ( is_user_logged_in() ) {
1907
+        if (is_user_logged_in()) {
1908 1908
             $actions['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,43 +2075,43 @@  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 === __( 'System', '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 === __('System', '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;
2105
-            <?php if($note->comment_author !== 'System') {?>
2106
-                <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;
2105
+            <?php if ($note->comment_author !== 'System') {?>
2106
+                <a href="#" class="delete_note"><?php _e('Delete note', 'invoicing'); ?></a>
2107 2107
             <?php } ?>
2108 2108
         </p>
2109 2109
     </li>
2110 2110
     <?php
2111 2111
     $note_content = ob_get_clean();
2112
-    $note_content = apply_filters( 'wpinv_get_invoice_note_line_item', $note_content, $note, $echo );
2112
+    $note_content = apply_filters('wpinv_get_invoice_note_line_item', $note_content, $note, $echo);
2113 2113
     
2114
-    if ( $echo ) {
2114
+    if ($echo) {
2115 2115
         echo $note_content;
2116 2116
     } else {
2117 2117
         return $note_content;
@@ -2121,33 +2121,33 @@  discard block
 block discarded – undo
2121 2121
 function wpinv_invalid_invoice_content() {
2122 2122
     global $post;
2123 2123
 
2124
-    $invoice = wpinv_get_invoice( $post->ID );
2124
+    $invoice = wpinv_get_invoice($post->ID);
2125 2125
 
2126
-    $error = __( 'This invoice is only viewable by clicking on the invoice link that sent to you via email.', 'invoicing' );
2127
-    if ( !empty( $invoice->ID ) && $invoice->has_status( array_keys( wpinv_get_invoice_statuses() ) ) ) {
2128
-        if ( is_user_logged_in() ) {
2129
-            if ( wpinv_require_login_to_checkout() ) {
2130
-                if ( isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) {
2131
-                    $error = __( 'You are not allowed to view this invoice.', 'invoicing' );
2126
+    $error = __('This invoice is only viewable by clicking on the invoice link that sent to you via email.', 'invoicing');
2127
+    if (!empty($invoice->ID) && $invoice->has_status(array_keys(wpinv_get_invoice_statuses()))) {
2128
+        if (is_user_logged_in()) {
2129
+            if (wpinv_require_login_to_checkout()) {
2130
+                if (isset($_GET['invoice_key']) && $_GET['invoice_key'] === $invoice->get_key()) {
2131
+                    $error = __('You are not allowed to view this invoice.', 'invoicing');
2132 2132
                 }
2133 2133
             }
2134 2134
         } else {
2135
-            if ( wpinv_require_login_to_checkout() ) {
2136
-                if ( isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) {
2137
-                    $error = __( 'You must be logged in to view this invoice.', 'invoicing' );
2135
+            if (wpinv_require_login_to_checkout()) {
2136
+                if (isset($_GET['invoice_key']) && $_GET['invoice_key'] === $invoice->get_key()) {
2137
+                    $error = __('You must be logged in to view this invoice.', 'invoicing');
2138 2138
                 }
2139 2139
             }
2140 2140
         }
2141 2141
     } else {
2142
-        $error = __( 'This invoice is deleted or does not exist.', 'invoicing' );
2142
+        $error = __('This invoice is deleted or does not exist.', 'invoicing');
2143 2143
     }
2144 2144
     ?>
2145 2145
     <div class="row wpinv-row-invalid">
2146 2146
         <div class="col-md-6 col-md-offset-3 wpinv-message error">
2147
-            <h3><?php _e( 'Access Denied', 'invoicing' ); ?></h3>
2147
+            <h3><?php _e('Access Denied', 'invoicing'); ?></h3>
2148 2148
             <p class="wpinv-msg-text"><?php echo $error; ?></p>
2149 2149
         </div>
2150 2150
     </div>
2151 2151
     <?php
2152 2152
 }
2153
-add_action( 'wpinv_invalid_invoice_content', 'wpinv_invalid_invoice_content' );
2154 2153
\ No newline at end of file
2154
+add_action('wpinv_invalid_invoice_content', 'wpinv_invalid_invoice_content');
2155 2155
\ No newline at end of file
Please login to merge, or discard this patch.
invoicing.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -10,19 +10,19 @@
 block discarded – undo
10 10
 */
11 11
 
12 12
 // MUST have WordPress.
13
-if ( !defined( 'WPINC' ) ) {
14
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
13
+if (!defined('WPINC')) {
14
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
15 15
 }
16 16
 
17
-if ( !defined( 'WPINV_VERSION' ) ) {
18
-    define( 'WPINV_VERSION', '1.0.0' );
17
+if (!defined('WPINV_VERSION')) {
18
+    define('WPINV_VERSION', '1.0.0');
19 19
 }
20 20
 
21
-if ( !defined( 'WPINV_PLUGIN_FILE' ) ) {
22
-    define( 'WPINV_PLUGIN_FILE', __FILE__ );
21
+if (!defined('WPINV_PLUGIN_FILE')) {
22
+    define('WPINV_PLUGIN_FILE', __FILE__);
23 23
 }
24 24
 
25
-require plugin_dir_path( __FILE__ ) . 'includes/class-wpinv.php';
25
+require plugin_dir_path(__FILE__) . 'includes/class-wpinv.php';
26 26
 
27 27
 function wpinv_run() {
28 28
     global $invoicing;
Please login to merge, or discard this patch.