Passed
Pull Request — master (#126)
by Kiran
03:46
created
includes/gateways/bank_transfer.php 1 patch
Spacing   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -1,12 +1,12 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // Exit if accessed directly
3
-if ( ! defined( 'ABSPATH' ) ) exit;
3
+if (!defined('ABSPATH')) exit;
4 4
 
5
-add_action( 'wpinv_bank_transfer_cc_form', '__return_false' );
5
+add_action('wpinv_bank_transfer_cc_form', '__return_false');
6 6
 
7
-function wpinv_process_bank_transfer_payment( $purchase_data ) {
8
-    if( ! wp_verify_nonce( $purchase_data['gateway_nonce'], 'wpi-gateway' ) ) {
9
-        wp_die( __( 'Nonce verification has failed', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
7
+function wpinv_process_bank_transfer_payment($purchase_data) {
8
+    if (!wp_verify_nonce($purchase_data['gateway_nonce'], 'wpi-gateway')) {
9
+        wp_die(__('Nonce verification has failed', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
10 10
     }
11 11
 
12 12
     // Collect payment data
@@ -24,39 +24,39 @@  discard block
 block discarded – undo
24 24
     );
25 25
 
26 26
     // Record the pending payment
27
-    $invoice = wpinv_get_invoice( $purchase_data['invoice_id'] );
27
+    $invoice = wpinv_get_invoice($purchase_data['invoice_id']);
28 28
     
29
-    if ( !empty( $invoice ) ) {
30
-        wpinv_set_payment_transaction_id( $invoice->ID, $invoice->generate_key() );
31
-        wpinv_update_payment_status( $invoice, 'wpi-pending' );
29
+    if (!empty($invoice)) {
30
+        wpinv_set_payment_transaction_id($invoice->ID, $invoice->generate_key());
31
+        wpinv_update_payment_status($invoice, 'wpi-pending');
32 32
         
33 33
         // Empty the shopping cart
34 34
         wpinv_empty_cart();
35 35
         
36
-        do_action( 'wpinv_send_to_success_page', $invoice->ID, $payment_data );
36
+        do_action('wpinv_send_to_success_page', $invoice->ID, $payment_data);
37 37
         
38
-        wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
38
+        wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key()));
39 39
     } else {
40
-        wpinv_record_gateway_error( __( 'Payment Error', 'invoicing' ), sprintf( __( 'Payment creation failed while processing a bank transfer payment. Payment data: %s', 'invoicing' ), json_encode( $payment_data ) ), $invoice );
40
+        wpinv_record_gateway_error(__('Payment Error', 'invoicing'), sprintf(__('Payment creation failed while processing a bank transfer payment. Payment data: %s', 'invoicing'), json_encode($payment_data)), $invoice);
41 41
         // If errors are present, send the user back to the purchase page so they can be corrected
42
-        wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] );
42
+        wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']);
43 43
     }
44 44
 }
45
-add_action( 'wpinv_gateway_bank_transfer', 'wpinv_process_bank_transfer_payment' );
45
+add_action('wpinv_gateway_bank_transfer', 'wpinv_process_bank_transfer_payment');
46 46
 
47
-function wpinv_show_bank_info( $invoice ) {
48
-    if ( !empty( $invoice ) && $invoice->gateway == 'bank_transfer' && $invoice->status == 'wpi-pending' ) {
49
-        $bank_info = wpinv_get_bank_info( true );
47
+function wpinv_show_bank_info($invoice) {
48
+    if (!empty($invoice) && $invoice->gateway == 'bank_transfer' && $invoice->status == 'wpi-pending') {
49
+        $bank_info = wpinv_get_bank_info(true);
50 50
         ?>
51 51
         <div class="wpinv-bank-details">
52
-            <?php if ( $instructions = wpinv_get_bank_instructions() ) { ?>
53
-            <div class="alert bg-info"><?php echo wpautop( wp_kses_post( $instructions ) ); ?></div>
52
+            <?php if ($instructions = wpinv_get_bank_instructions()) { ?>
53
+            <div class="alert bg-info"><?php echo wpautop(wp_kses_post($instructions)); ?></div>
54 54
             <?php } ?>
55
-            <?php if ( !empty( $bank_info ) ) { ?>
56
-            <h3 class="wpinv-bank-t"><?php echo apply_filters( 'wpinv_receipt_bank_details_title', __( 'Our Bank Details', 'invoicing' ) ); ?></h3>
55
+            <?php if (!empty($bank_info)) { ?>
56
+            <h3 class="wpinv-bank-t"><?php echo apply_filters('wpinv_receipt_bank_details_title', __('Our Bank Details', 'invoicing')); ?></h3>
57 57
             <table class="table table-bordered table-sm wpi-bank-details">
58
-                <?php foreach ( $bank_info as $key => $info ) { ?>
59
-                <tr class="wpi-<?php echo sanitize_html_class( $key );?>"><th class="text-left"><?php echo $info['label'] ;?></th><td><?php echo $info['value'] ;?></td></tr>
58
+                <?php foreach ($bank_info as $key => $info) { ?>
59
+                <tr class="wpi-<?php echo sanitize_html_class($key); ?>"><th class="text-left"><?php echo $info['label']; ?></th><td><?php echo $info['value']; ?></td></tr>
60 60
                 <?php } ?>
61 61
             </table>
62 62
             <?php } ?>
@@ -64,26 +64,26 @@  discard block
 block discarded – undo
64 64
         <?php
65 65
     }
66 66
 }
67
-add_action( 'wpinv_before_receipt_details', 'wpinv_show_bank_info', 10, 1 );
67
+add_action('wpinv_before_receipt_details', 'wpinv_show_bank_info', 10, 1);
68 68
 
69
-function wpinv_invoice_print_bank_info( $invoice ) {
70
-    if ( !empty( $invoice ) && $invoice->gateway == 'bank_transfer' && $invoice->status == 'wpi-pending' ) {
69
+function wpinv_invoice_print_bank_info($invoice) {
70
+    if (!empty($invoice) && $invoice->gateway == 'bank_transfer' && $invoice->status == 'wpi-pending') {
71 71
         ?>
72 72
         <div class="row wpinv-bank-info">
73
-            <?php echo wpinv_show_bank_info( $invoice ); ?>
73
+            <?php echo wpinv_show_bank_info($invoice); ?>
74 74
         </div>
75 75
         <?php
76 76
     }
77 77
 }
78
-add_action( 'wpinv_invoice_print_after_top_content', 'wpinv_invoice_print_bank_info', 10, 1 );
78
+add_action('wpinv_invoice_print_after_top_content', 'wpinv_invoice_print_bank_info', 10, 1);
79 79
 
80
-function wpinv_bank_transfer_send_notification( $invoice_ID, $payment_data = array() ) {
81
-    if ( !empty( $payment_data['gateway'] ) && $payment_data['gateway'] == 'bank_transfer' ) {
80
+function wpinv_bank_transfer_send_notification($invoice_ID, $payment_data = array()) {
81
+    if (!empty($payment_data['gateway']) && $payment_data['gateway'] == 'bank_transfer') {
82 82
         // Send invoice to user.
83
-        wpinv_user_invoice_notification( $invoice_ID );
83
+        wpinv_user_invoice_notification($invoice_ID);
84 84
         
85 85
         // Send invoice to admin.
86
-        wpinv_new_invoice_notification( $invoice_ID );
86
+        wpinv_new_invoice_notification($invoice_ID);
87 87
     }
88 88
 }
89
-add_action( 'wpinv_send_to_success_page', 'wpinv_bank_transfer_send_notification', 10, 2 );
90 89
\ No newline at end of file
90
+add_action('wpinv_send_to_success_page', 'wpinv_bank_transfer_send_notification', 10, 2);
91 91
\ No newline at end of file
Please login to merge, or discard this patch.
includes/class-wpinv-invoice.php 1 patch
Spacing   +611 added lines, -611 removed lines patch added patch discarded remove patch
@@ -7,12 +7,12 @@  discard block
 block discarded – undo
7 7
  */
8 8
  
9 9
 // MUST have WordPress.
10
-if ( !defined( 'WPINC' ) ) {
11
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
10
+if (!defined('WPINC')) {
11
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
12 12
 }
13 13
 
14 14
 final class WPInv_Invoice {
15
-    public $ID  = 0;
15
+    public $ID = 0;
16 16
     public $title;
17 17
     public $post_type;
18 18
     
@@ -65,17 +65,17 @@  discard block
 block discarded – undo
65 65
     public $full_name = '';
66 66
     public $parent_invoice = 0;
67 67
     
68
-    public function __construct( $invoice_id = false ) {
69
-        if( empty( $invoice_id ) ) {
68
+    public function __construct($invoice_id = false) {
69
+        if (empty($invoice_id)) {
70 70
             return false;
71 71
         }
72 72
 
73
-        $this->setup_invoice( $invoice_id );
73
+        $this->setup_invoice($invoice_id);
74 74
     }
75 75
 
76
-    public function get( $key ) {
77
-        if ( method_exists( $this, 'get_' . $key ) ) {
78
-            $value = call_user_func( array( $this, 'get_' . $key ) );
76
+    public function get($key) {
77
+        if (method_exists($this, 'get_' . $key)) {
78
+            $value = call_user_func(array($this, 'get_' . $key));
79 79
         } else {
80 80
             $value = $this->$key;
81 81
         }
@@ -83,51 +83,51 @@  discard block
 block discarded – undo
83 83
         return $value;
84 84
     }
85 85
 
86
-    public function set( $key, $value ) {
87
-        $ignore = array( 'items', 'cart_details', 'fees', '_ID' );
86
+    public function set($key, $value) {
87
+        $ignore = array('items', 'cart_details', 'fees', '_ID');
88 88
 
89
-        if ( $key === 'status' ) {
89
+        if ($key === 'status') {
90 90
             $this->old_status = $this->status;
91 91
         }
92 92
 
93
-        if ( ! in_array( $key, $ignore ) ) {
94
-            $this->pending[ $key ] = $value;
93
+        if (!in_array($key, $ignore)) {
94
+            $this->pending[$key] = $value;
95 95
         }
96 96
 
97
-        if( '_ID' !== $key ) {
97
+        if ('_ID' !== $key) {
98 98
             $this->$key = $value;
99 99
         }
100 100
     }
101 101
 
102
-    public function _isset( $name ) {
103
-        if ( property_exists( $this, $name) ) {
104
-            return false === empty( $this->$name );
102
+    public function _isset($name) {
103
+        if (property_exists($this, $name)) {
104
+            return false === empty($this->$name);
105 105
         } else {
106 106
             return null;
107 107
         }
108 108
     }
109 109
 
110
-    private function setup_invoice( $invoice_id ) {
110
+    private function setup_invoice($invoice_id) {
111 111
         $this->pending = array();
112 112
 
113
-        if ( empty( $invoice_id ) ) {
113
+        if (empty($invoice_id)) {
114 114
             return false;
115 115
         }
116 116
 
117
-        $invoice = get_post( $invoice_id );
117
+        $invoice = get_post($invoice_id);
118 118
 
119
-        if( !$invoice || is_wp_error( $invoice ) ) {
119
+        if (!$invoice || is_wp_error($invoice)) {
120 120
             return false;
121 121
         }
122 122
 
123
-        if( !('wpi_invoice' == $invoice->post_type OR 'wpi_quote' == $invoice->post_type) ) {
123
+        if (!('wpi_invoice' == $invoice->post_type OR 'wpi_quote' == $invoice->post_type)) {
124 124
             return false;
125 125
         }
126 126
 
127
-        do_action( 'wpinv_pre_setup_invoice', $this, $invoice_id );
127
+        do_action('wpinv_pre_setup_invoice', $this, $invoice_id);
128 128
         
129 129
         // Primary Identifier
130
-        $this->ID              = absint( $invoice_id );
130
+        $this->ID              = absint($invoice_id);
131 131
         $this->post_type       = $invoice->post_type;
132 132
         
133 133
         // We have a payment, get the generic payment_meta item to reduce calls to it
@@ -139,7 +139,7 @@  discard block
 block discarded – undo
139 139
         $this->post_status     = $this->status;
140 140
         $this->mode            = $this->setup_mode();
141 141
         $this->parent_invoice  = $invoice->post_parent;
142
-        $this->post_name       = $this->setup_post_name( $invoice );
142
+        $this->post_name       = $this->setup_post_name($invoice);
143 143
         $this->status_nicename = $this->setup_status_nicename($invoice->post_status);
144 144
 
145 145
         // Items
@@ -161,8 +161,8 @@  discard block
 block discarded – undo
161 161
         
162 162
         // User based
163 163
         $this->ip              = $this->setup_ip();
164
-        $this->user_id         = !empty( $invoice->post_author ) ? $invoice->post_author : get_current_user_id();///$this->setup_user_id();
165
-        $this->email           = get_the_author_meta( 'email', $this->user_id );
164
+        $this->user_id         = !empty($invoice->post_author) ? $invoice->post_author : get_current_user_id(); ///$this->setup_user_id();
165
+        $this->email           = get_the_author_meta('email', $this->user_id);
166 166
         
167 167
         $this->user_info       = $this->setup_user_info();
168 168
                 
@@ -171,7 +171,7 @@  discard block
 block discarded – undo
171 171
         $this->company         = $this->user_info['company'];
172 172
         $this->vat_number      = $this->user_info['vat_number'];
173 173
         $this->vat_rate        = $this->user_info['vat_rate'];
174
-        $this->adddress_confirmed  = $this->user_info['adddress_confirmed'];
174
+        $this->adddress_confirmed = $this->user_info['adddress_confirmed'];
175 175
         $this->address         = $this->user_info['address'];
176 176
         $this->city            = $this->user_info['city'];
177 177
         $this->country         = $this->user_info['country'];
@@ -186,35 +186,35 @@  discard block
 block discarded – undo
186 186
         // Other Identifiers
187 187
         $this->key             = $this->setup_invoice_key();
188 188
         $this->number          = $this->setup_invoice_number();
189
-        $this->title           = !empty( $invoice->post_title ) ? $invoice->post_title : $this->number;
189
+        $this->title           = !empty($invoice->post_title) ? $invoice->post_title : $this->number;
190 190
         
191
-        $this->full_name       = trim( $this->first_name . ' '. $this->last_name );
191
+        $this->full_name       = trim($this->first_name . ' ' . $this->last_name);
192 192
         
193 193
         // Allow extensions to add items to this object via hook
194
-        do_action( 'wpinv_setup_invoice', $this, $invoice_id );
194
+        do_action('wpinv_setup_invoice', $this, $invoice_id);
195 195
 
196 196
         return true;
197 197
     }
198 198
     
199
-    private function setup_status_nicename( $status ) {
200
-        $all_invoice_statuses  = wpinv_get_invoice_statuses( true, $this );
201
-        $status   = isset( $all_invoice_statuses[$status] ) ? $all_invoice_statuses[$status] : __( $status, 'invoicing' );
199
+    private function setup_status_nicename($status) {
200
+        $all_invoice_statuses = wpinv_get_invoice_statuses(true, $this);
201
+        $status = isset($all_invoice_statuses[$status]) ? $all_invoice_statuses[$status] : __($status, 'invoicing');
202 202
 
203
-        return apply_filters( 'setup_status_nicename', $status );
203
+        return apply_filters('setup_status_nicename', $status);
204 204
     }
205 205
     
206
-    private function setup_post_name( $post = NULL ) {
206
+    private function setup_post_name($post = NULL) {
207 207
         global $wpdb;
208 208
         
209 209
         $post_name = '';
210 210
         
211
-        if ( !empty( $post ) ) {
212
-            if( !empty( $post->post_name ) ) {
211
+        if (!empty($post)) {
212
+            if (!empty($post->post_name)) {
213 213
                 $post_name = $post->post_name;
214
-            } else if ( !empty( $post->ID ) ) {
215
-                $post_name = wpinv_generate_post_name( $post->ID );
214
+            } else if (!empty($post->ID)) {
215
+                $post_name = wpinv_generate_post_name($post->ID);
216 216
 
217
-                $wpdb->update( $wpdb->posts, array( 'post_name' => $post_name ), array( 'ID' => $post->ID ) );
217
+                $wpdb->update($wpdb->posts, array('post_name' => $post_name), array('ID' => $post->ID));
218 218
             }
219 219
         }
220 220
 
@@ -222,12 +222,12 @@  discard block
 block discarded – undo
222 222
     }
223 223
     
224 224
     private function setup_due_date() {
225
-        $due_date = $this->get_meta( '_wpinv_due_date' );
225
+        $due_date = $this->get_meta('_wpinv_due_date');
226 226
         
227
-        if ( empty( $due_date ) ) {
228
-            $overdue_time = strtotime( $this->date ) + ( DAY_IN_SECONDS * absint( wpinv_get_option( 'overdue_days' ) ) );
229
-            $due_date = date_i18n( 'Y-m-d', $overdue_time );
230
-        } else if ( $due_date == 'none' ) {
227
+        if (empty($due_date)) {
228
+            $overdue_time = strtotime($this->date) + (DAY_IN_SECONDS * absint(wpinv_get_option('overdue_days')));
229
+            $due_date = date_i18n('Y-m-d', $overdue_time);
230
+        } else if ($due_date == 'none') {
231 231
             $due_date = '';
232 232
         }
233 233
         
@@ -235,66 +235,66 @@  discard block
 block discarded – undo
235 235
     }
236 236
     
237 237
     private function setup_completed_date() {
238
-        $invoice = get_post( $this->ID );
238
+        $invoice = get_post($this->ID);
239 239
 
240
-        if ( 'wpi-pending' == $invoice->post_status || 'preapproved' == $invoice->post_status ) {
240
+        if ('wpi-pending' == $invoice->post_status || 'preapproved' == $invoice->post_status) {
241 241
             return false; // This invoice was never paid
242 242
         }
243 243
 
244
-        $date = ( $date = $this->get_meta( '_wpinv_completed_date', true ) ) ? $date : $invoice->modified_date;
244
+        $date = ($date = $this->get_meta('_wpinv_completed_date', true)) ? $date : $invoice->modified_date;
245 245
 
246 246
         return $date;
247 247
     }
248 248
     
249 249
     private function setup_cart_details() {
250
-        $cart_details = isset( $this->payment_meta['cart_details'] ) ? maybe_unserialize( $this->payment_meta['cart_details'] ) : array();
250
+        $cart_details = isset($this->payment_meta['cart_details']) ? maybe_unserialize($this->payment_meta['cart_details']) : array();
251 251
         return $cart_details;
252 252
     }
253 253
     
254 254
     public function array_convert() {
255
-        return get_object_vars( $this );
255
+        return get_object_vars($this);
256 256
     }
257 257
     
258 258
     private function setup_items() {
259
-        $items = isset( $this->payment_meta['items'] ) ? maybe_unserialize( $this->payment_meta['items'] ) : array();
259
+        $items = isset($this->payment_meta['items']) ? maybe_unserialize($this->payment_meta['items']) : array();
260 260
         return $items;
261 261
     }
262 262
     
263 263
     private function setup_fees() {
264
-        $payment_fees = isset( $this->payment_meta['fees'] ) ? $this->payment_meta['fees'] : array();
264
+        $payment_fees = isset($this->payment_meta['fees']) ? $this->payment_meta['fees'] : array();
265 265
         return $payment_fees;
266 266
     }
267 267
         
268 268
     private function setup_currency() {
269
-        $currency = isset( $this->payment_meta['currency'] ) ? $this->payment_meta['currency'] : apply_filters( 'wpinv_currency_default', wpinv_get_currency(), $this );
269
+        $currency = isset($this->payment_meta['currency']) ? $this->payment_meta['currency'] : apply_filters('wpinv_currency_default', wpinv_get_currency(), $this);
270 270
         return $currency;
271 271
     }
272 272
     
273 273
     private function setup_discount() {
274 274
         //$discount = $this->get_meta( '_wpinv_discount', true );
275
-        $discount = (float)$this->subtotal - ( (float)$this->total - (float)$this->tax - (float)$this->fees_total );
276
-        if ( $discount < 0 ) {
275
+        $discount = (float)$this->subtotal - ((float)$this->total - (float)$this->tax - (float)$this->fees_total);
276
+        if ($discount < 0) {
277 277
             $discount = 0;
278 278
         }
279
-        $discount = wpinv_round_amount( $discount );
279
+        $discount = wpinv_round_amount($discount);
280 280
         
281 281
         return $discount;
282 282
     }
283 283
     
284 284
     private function setup_discount_code() {
285
-        $discount_code = !empty( $this->discounts ) ? $this->discounts : $this->get_meta( '_wpinv_discount_code', true );
285
+        $discount_code = !empty($this->discounts) ? $this->discounts : $this->get_meta('_wpinv_discount_code', true);
286 286
         return $discount_code;
287 287
     }
288 288
     
289 289
     private function setup_tax() {
290
-        $tax = $this->get_meta( '_wpinv_tax', true );
290
+        $tax = $this->get_meta('_wpinv_tax', true);
291 291
 
292 292
         // We don't have tax as it's own meta and no meta was passed
293
-        if ( '' === $tax ) {            
294
-            $tax = isset( $this->payment_meta['tax'] ) ? $this->payment_meta['tax'] : 0;
293
+        if ('' === $tax) {            
294
+            $tax = isset($this->payment_meta['tax']) ? $this->payment_meta['tax'] : 0;
295 295
         }
296 296
         
297
-        if ( $tax < 0 ) {
297
+        if ($tax < 0) {
298 298
             $tax = 0;
299 299
         }
300 300
 
@@ -305,9 +305,9 @@  discard block
 block discarded – undo
305 305
         $subtotal     = 0;
306 306
         $cart_details = $this->cart_details;
307 307
 
308
-        if ( is_array( $cart_details ) ) {
309
-            foreach ( $cart_details as $item ) {
310
-                if ( isset( $item['subtotal'] ) ) {
308
+        if (is_array($cart_details)) {
309
+            foreach ($cart_details as $item) {
310
+                if (isset($item['subtotal'])) {
311 311
                     $subtotal += $item['subtotal'];
312 312
                 }
313 313
             }
@@ -321,23 +321,23 @@  discard block
 block discarded – undo
321 321
     }
322 322
     
323 323
     private function setup_discounts() {
324
-        $discounts = ! empty( $this->payment_meta['user_info']['discount'] ) ? $this->payment_meta['user_info']['discount'] : array();
324
+        $discounts = !empty($this->payment_meta['user_info']['discount']) ? $this->payment_meta['user_info']['discount'] : array();
325 325
         return $discounts;
326 326
     }
327 327
     
328 328
     private function setup_total() {
329
-        $amount = $this->get_meta( '_wpinv_total', true );
329
+        $amount = $this->get_meta('_wpinv_total', true);
330 330
 
331
-        if ( empty( $amount ) && '0.00' != $amount ) {
332
-            $meta   = $this->get_meta( '_wpinv_payment_meta', true );
333
-            $meta   = maybe_unserialize( $meta );
331
+        if (empty($amount) && '0.00' != $amount) {
332
+            $meta   = $this->get_meta('_wpinv_payment_meta', true);
333
+            $meta   = maybe_unserialize($meta);
334 334
 
335
-            if ( isset( $meta['amount'] ) ) {
335
+            if (isset($meta['amount'])) {
336 336
                 $amount = $meta['amount'];
337 337
             }
338 338
         }
339 339
 
340
-        if($amount < 0){
340
+        if ($amount < 0) {
341 341
             $amount = 0;
342 342
         }
343 343
 
@@ -345,13 +345,13 @@  discard block
 block discarded – undo
345 345
     }
346 346
     
347 347
     private function setup_mode() {
348
-        return $this->get_meta( '_wpinv_mode' );
348
+        return $this->get_meta('_wpinv_mode');
349 349
     }
350 350
 
351 351
     private function setup_gateway() {
352
-        $gateway = $this->get_meta( '_wpinv_gateway' );
352
+        $gateway = $this->get_meta('_wpinv_gateway');
353 353
         
354
-        if ( empty( $gateway ) && 'publish' === $this->status ) {
354
+        if (empty($gateway) && 'publish' === $this->status) {
355 355
             $gateway = 'manual';
356 356
         }
357 357
         
@@ -359,23 +359,23 @@  discard block
 block discarded – undo
359 359
     }
360 360
     
361 361
     private function setup_gateway_title() {
362
-        $gateway_title = wpinv_get_gateway_checkout_label( $this->gateway );
362
+        $gateway_title = wpinv_get_gateway_checkout_label($this->gateway);
363 363
         return $gateway_title;
364 364
     }
365 365
 
366 366
     private function setup_transaction_id() {
367
-        $transaction_id = $this->get_meta( '_wpinv_transaction_id' );
367
+        $transaction_id = $this->get_meta('_wpinv_transaction_id');
368 368
 
369
-        if ( empty( $transaction_id ) || (int) $transaction_id === (int) $this->ID ) {
369
+        if (empty($transaction_id) || (int)$transaction_id === (int)$this->ID) {
370 370
             $gateway        = $this->gateway;
371
-            $transaction_id = apply_filters( 'wpinv_get_invoice_transaction_id-' . $gateway, $this->ID );
371
+            $transaction_id = apply_filters('wpinv_get_invoice_transaction_id-' . $gateway, $this->ID);
372 372
         }
373 373
 
374 374
         return $transaction_id;
375 375
     }
376 376
 
377 377
     private function setup_ip() {
378
-        $ip = $this->get_meta( '_wpinv_user_ip' );
378
+        $ip = $this->get_meta('_wpinv_user_ip');
379 379
         return $ip;
380 380
     }
381 381
 
@@ -385,62 +385,62 @@  discard block
 block discarded – undo
385 385
     ///}
386 386
         
387 387
     private function setup_first_name() {
388
-        $first_name = $this->get_meta( '_wpinv_first_name' );
388
+        $first_name = $this->get_meta('_wpinv_first_name');
389 389
         return $first_name;
390 390
     }
391 391
     
392 392
     private function setup_last_name() {
393
-        $last_name = $this->get_meta( '_wpinv_last_name' );
393
+        $last_name = $this->get_meta('_wpinv_last_name');
394 394
         return $last_name;
395 395
     }
396 396
     
397 397
     private function setup_company() {
398
-        $company = $this->get_meta( '_wpinv_company' );
398
+        $company = $this->get_meta('_wpinv_company');
399 399
         return $company;
400 400
     }
401 401
     
402 402
     private function setup_vat_number() {
403
-        $vat_number = $this->get_meta( '_wpinv_vat_number' );
403
+        $vat_number = $this->get_meta('_wpinv_vat_number');
404 404
         return $vat_number;
405 405
     }
406 406
     
407 407
     private function setup_vat_rate() {
408
-        $vat_rate = $this->get_meta( '_wpinv_vat_rate' );
408
+        $vat_rate = $this->get_meta('_wpinv_vat_rate');
409 409
         return $vat_rate;
410 410
     }
411 411
     
412 412
     private function setup_adddress_confirmed() {
413
-        $adddress_confirmed = $this->get_meta( '_wpinv_adddress_confirmed' );
413
+        $adddress_confirmed = $this->get_meta('_wpinv_adddress_confirmed');
414 414
         return $adddress_confirmed;
415 415
     }
416 416
     
417 417
     private function setup_phone() {
418
-        $phone = $this->get_meta( '_wpinv_phone' );
418
+        $phone = $this->get_meta('_wpinv_phone');
419 419
         return $phone;
420 420
     }
421 421
     
422 422
     private function setup_address() {
423
-        $address = $this->get_meta( '_wpinv_address', true );
423
+        $address = $this->get_meta('_wpinv_address', true);
424 424
         return $address;
425 425
     }
426 426
     
427 427
     private function setup_city() {
428
-        $city = $this->get_meta( '_wpinv_city', true );
428
+        $city = $this->get_meta('_wpinv_city', true);
429 429
         return $city;
430 430
     }
431 431
     
432 432
     private function setup_country() {
433
-        $country = $this->get_meta( '_wpinv_country', true );
433
+        $country = $this->get_meta('_wpinv_country', true);
434 434
         return $country;
435 435
     }
436 436
     
437 437
     private function setup_state() {
438
-        $state = $this->get_meta( '_wpinv_state', true );
438
+        $state = $this->get_meta('_wpinv_state', true);
439 439
         return $state;
440 440
     }
441 441
     
442 442
     private function setup_zip() {
443
-        $zip = $this->get_meta( '_wpinv_zip', true );
443
+        $zip = $this->get_meta('_wpinv_zip', true);
444 444
         return $zip;
445 445
     }
446 446
 
@@ -449,7 +449,7 @@  discard block
 block discarded – undo
449 449
             'user_id'        => $this->user_id,
450 450
             'first_name'     => $this->first_name,
451 451
             'last_name'      => $this->last_name,
452
-            'email'          => get_the_author_meta( 'email', $this->user_id ),
452
+            'email'          => get_the_author_meta('email', $this->user_id),
453 453
             'phone'          => $this->phone,
454 454
             'address'        => $this->address,
455 455
             'city'           => $this->city,
@@ -464,12 +464,12 @@  discard block
 block discarded – undo
464 464
         );
465 465
         
466 466
         $user_info = array();
467
-        if ( isset( $this->payment_meta['user_info'] ) ) {
468
-            $user_info = maybe_unserialize( $this->payment_meta['user_info'] );
467
+        if (isset($this->payment_meta['user_info'])) {
468
+            $user_info = maybe_unserialize($this->payment_meta['user_info']);
469 469
             
470
-            if ( !empty( $user_info ) && isset( $user_info['user_id'] ) && $post = get_post( $this->ID ) ) {
470
+            if (!empty($user_info) && isset($user_info['user_id']) && $post = get_post($this->ID)) {
471 471
                 $this->user_id = $post->post_author;
472
-                $this->email = get_the_author_meta( 'email', $this->user_id );
472
+                $this->email = get_the_author_meta('email', $this->user_id);
473 473
                 
474 474
                 $user_info['user_id'] = $this->user_id;
475 475
                 $user_info['email'] = $this->email;
@@ -478,13 +478,13 @@  discard block
 block discarded – undo
478 478
             }
479 479
         }
480 480
         
481
-        $user_info    = wp_parse_args( $user_info, $defaults );
481
+        $user_info = wp_parse_args($user_info, $defaults);
482 482
         
483 483
         // Get the user, but only if it's been created
484
-        $user = get_userdata( $this->user_id );
484
+        $user = get_userdata($this->user_id);
485 485
         
486
-        if ( !empty( $user ) && $user->ID > 0 ) {
487
-            if ( empty( $user_info ) ) {
486
+        if (!empty($user) && $user->ID > 0) {
487
+            if (empty($user_info)) {
488 488
                 $user_info = array(
489 489
                     'user_id'    => $user->ID,
490 490
                     'first_name' => $user->first_name,
@@ -493,23 +493,23 @@  discard block
 block discarded – undo
493 493
                     'discount'   => '',
494 494
                 );
495 495
             } else {
496
-                foreach ( $user_info as $key => $value ) {
497
-                    if ( ! empty( $value ) ) {
496
+                foreach ($user_info as $key => $value) {
497
+                    if (!empty($value)) {
498 498
                         continue;
499 499
                     }
500 500
 
501
-                    switch( $key ) {
501
+                    switch ($key) {
502 502
                         case 'user_id':
503
-                            $user_info[ $key ] = $user->ID;
503
+                            $user_info[$key] = $user->ID;
504 504
                             break;
505 505
                         case 'first_name':
506
-                            $user_info[ $key ] = $user->first_name;
506
+                            $user_info[$key] = $user->first_name;
507 507
                             break;
508 508
                         case 'last_name':
509
-                            $user_info[ $key ] = $user->last_name;
509
+                            $user_info[$key] = $user->last_name;
510 510
                             break;
511 511
                         case 'email':
512
-                            $user_info[ $key ] = $user->user_email;
512
+                            $user_info[$key] = $user->user_email;
513 513
                             break;
514 514
                     }
515 515
                 }
@@ -520,25 +520,25 @@  discard block
 block discarded – undo
520 520
     }
521 521
 
522 522
     private function setup_invoice_key() {
523
-        $key = $this->get_meta( '_wpinv_key', true );
523
+        $key = $this->get_meta('_wpinv_key', true);
524 524
         
525 525
         return $key;
526 526
     }
527 527
 
528 528
     private function setup_invoice_number() {
529
-        $number = $this->get_meta( '_wpinv_number', true );
529
+        $number = $this->get_meta('_wpinv_number', true);
530 530
 
531
-        if ( !$number ) {
531
+        if (!$number) {
532 532
             $number = $this->ID;
533 533
 
534
-            if ( $this->status == 'auto-draft' ) {
535
-                if ( wpinv_sequential_number_active( $this->post_type ) ) {
536
-                    $next_number = wpinv_get_next_invoice_number( $this->post_type );
534
+            if ($this->status == 'auto-draft') {
535
+                if (wpinv_sequential_number_active($this->post_type)) {
536
+                    $next_number = wpinv_get_next_invoice_number($this->post_type);
537 537
                     $number      = $next_number;
538 538
                 }
539 539
             }
540 540
             
541
-            $number = wpinv_format_invoice_number( $number, $this->post_type );
541
+            $number = wpinv_format_invoice_number($number, $this->post_type);
542 542
         }
543 543
 
544 544
         return $number;
@@ -547,10 +547,10 @@  discard block
 block discarded – undo
547 547
     private function insert_invoice() {
548 548
         global $wpdb;
549 549
 
550
-        if ( empty( $this->post_type ) ) {
551
-            if ( !empty( $this->ID ) && $post_type = get_post_type( $this->ID ) ) {
550
+        if (empty($this->post_type)) {
551
+            if (!empty($this->ID) && $post_type = get_post_type($this->ID)) {
552 552
                 $this->post_type = $post_type;
553
-            } else if ( !empty( $this->parent_invoice ) && $post_type = get_post_type( $this->parent_invoice ) ) {
553
+            } else if (!empty($this->parent_invoice) && $post_type = get_post_type($this->parent_invoice)) {
554 554
                 $this->post_type = $post_type;
555 555
             } else {
556 556
                 $this->post_type = 'wpi_invoice';
@@ -558,16 +558,16 @@  discard block
 block discarded – undo
558 558
         }
559 559
 
560 560
         $invoice_number = $this->ID;
561
-        if ( $number = $this->get_meta( '_wpinv_number', true ) ) {
561
+        if ($number = $this->get_meta('_wpinv_number', true)) {
562 562
             $invoice_number = $number;
563 563
         }
564 564
 
565
-        if ( empty( $this->key ) ) {
565
+        if (empty($this->key)) {
566 566
             $this->key = self::generate_key();
567 567
             $this->pending['key'] = $this->key;
568 568
         }
569 569
 
570
-        if ( empty( $this->ip ) ) {
570
+        if (empty($this->ip)) {
571 571
             $this->ip = wpinv_get_ip();
572 572
             $this->pending['ip'] = $this->ip;
573 573
         }
@@ -604,61 +604,61 @@  discard block
 block discarded – undo
604 604
                         'post_status'   => $this->status,
605 605
                         'post_author'   => $this->user_id,
606 606
                         'post_type'     => $this->post_type,
607
-                        'post_date'     => ! empty( $this->date ) && $this->date != '0000-00-00 00:00:00' ? $this->date : current_time( 'mysql' ),
608
-                        'post_date_gmt' => ! empty( $this->date ) && $this->date != '0000-00-00 00:00:00' ? get_gmt_from_date( $this->date ) : current_time( 'mysql', 1 ),
607
+                        'post_date'     => !empty($this->date) && $this->date != '0000-00-00 00:00:00' ? $this->date : current_time('mysql'),
608
+                        'post_date_gmt' => !empty($this->date) && $this->date != '0000-00-00 00:00:00' ? get_gmt_from_date($this->date) : current_time('mysql', 1),
609 609
                         'post_parent'   => $this->parent_invoice,
610 610
                     );
611
-        $args = apply_filters( 'wpinv_insert_invoice_args', $post_data, $this );
611
+        $args = apply_filters('wpinv_insert_invoice_args', $post_data, $this);
612 612
 
613 613
         // Create a blank invoice
614
-        if ( !empty( $this->ID ) ) {
615
-            $args['ID']         = $this->ID;
614
+        if (!empty($this->ID)) {
615
+            $args['ID'] = $this->ID;
616 616
 
617
-            $invoice_id = wp_update_post( $args, true );
617
+            $invoice_id = wp_update_post($args, true);
618 618
         } else {
619
-            $invoice_id = wp_insert_post( $args, true );
619
+            $invoice_id = wp_insert_post($args, true);
620 620
         }
621 621
 
622
-        if ( is_wp_error( $invoice_id ) ) {
622
+        if (is_wp_error($invoice_id)) {
623 623
             return false;
624 624
         }
625 625
 
626
-        if ( !empty( $invoice_id ) ) {
626
+        if (!empty($invoice_id)) {
627 627
             $this->ID  = $invoice_id;
628 628
             $this->_ID = $invoice_id;
629 629
 
630
-            $this->payment_meta = apply_filters( 'wpinv_payment_meta', $this->payment_meta, $payment_data );
631
-            if ( ! empty( $this->payment_meta['fees'] ) ) {
632
-                $this->fees = array_merge( $this->fees, $this->payment_meta['fees'] );
633
-                foreach( $this->fees as $fee ) {
634
-                    $this->increase_fees( $fee['amount'] );
630
+            $this->payment_meta = apply_filters('wpinv_payment_meta', $this->payment_meta, $payment_data);
631
+            if (!empty($this->payment_meta['fees'])) {
632
+                $this->fees = array_merge($this->fees, $this->payment_meta['fees']);
633
+                foreach ($this->fees as $fee) {
634
+                    $this->increase_fees($fee['amount']);
635 635
                 }
636 636
             }
637 637
 
638
-            $this->update_meta( '_wpinv_payment_meta', $this->payment_meta );            
638
+            $this->update_meta('_wpinv_payment_meta', $this->payment_meta);            
639 639
             $this->new = true;
640 640
         }
641 641
 
642 642
         return $this->ID;
643 643
     }
644 644
 
645
-    public function save( $setup = false ) {
645
+    public function save($setup = false) {
646 646
         global $wpi_session;
647 647
         
648 648
         $saved = false;
649
-        if ( empty( $this->items ) ) {
649
+        if (empty($this->items)) {
650 650
             return $saved; // Don't save empty invoice.
651 651
         }
652 652
         
653
-        if ( empty( $this->key ) ) {
653
+        if (empty($this->key)) {
654 654
             $this->key = self::generate_key();
655 655
             $this->pending['key'] = $this->key;
656 656
         }
657 657
         
658
-        if ( empty( $this->ID ) ) {
658
+        if (empty($this->ID)) {
659 659
             $invoice_id = $this->insert_invoice();
660 660
 
661
-            if ( false === $invoice_id ) {
661
+            if (false === $invoice_id) {
662 662
                 $saved = false;
663 663
             } else {
664 664
                 $this->ID = $invoice_id;
@@ -666,27 +666,27 @@  discard block
 block discarded – undo
666 666
         }
667 667
 
668 668
         // If we have something pending, let's save it
669
-        if ( !empty( $this->pending ) ) {
669
+        if (!empty($this->pending)) {
670 670
             $total_increase = 0;
671 671
             $total_decrease = 0;
672 672
 
673
-            foreach ( $this->pending as $key => $value ) {
674
-                switch( $key ) {
673
+            foreach ($this->pending as $key => $value) {
674
+                switch ($key) {
675 675
                     case 'items':
676 676
                         // Update totals for pending items
677
-                        foreach ( $this->pending[ $key ] as $item ) {
678
-                            switch( $item['action'] ) {
677
+                        foreach ($this->pending[$key] as $item) {
678
+                            switch ($item['action']) {
679 679
                                 case 'add':
680 680
                                     $price = $item['price'];
681 681
                                     $taxes = $item['tax'];
682 682
 
683
-                                    if ( 'publish' === $this->status ) {
683
+                                    if ('publish' === $this->status) {
684 684
                                         $total_increase += $price;
685 685
                                     }
686 686
                                     break;
687 687
 
688 688
                                 case 'remove':
689
-                                    if ( 'publish' === $this->status ) {
689
+                                    if ('publish' === $this->status) {
690 690
                                         $total_decrease += $item['price'];
691 691
                                     }
692 692
                                     break;
@@ -694,16 +694,16 @@  discard block
 block discarded – undo
694 694
                         }
695 695
                         break;
696 696
                     case 'fees':
697
-                        if ( 'publish' !== $this->status ) {
697
+                        if ('publish' !== $this->status) {
698 698
                             break;
699 699
                         }
700 700
 
701
-                        if ( empty( $this->pending[ $key ] ) ) {
701
+                        if (empty($this->pending[$key])) {
702 702
                             break;
703 703
                         }
704 704
 
705
-                        foreach ( $this->pending[ $key ] as $fee ) {
706
-                            switch( $fee['action'] ) {
705
+                        foreach ($this->pending[$key] as $fee) {
706
+                            switch ($fee['action']) {
707 707
                                 case 'add':
708 708
                                     $total_increase += $fee['amount'];
709 709
                                     break;
@@ -715,83 +715,83 @@  discard block
 block discarded – undo
715 715
                         }
716 716
                         break;
717 717
                     case 'status':
718
-                        $this->update_status( $this->status );
718
+                        $this->update_status($this->status);
719 719
                         break;
720 720
                     case 'gateway':
721
-                        $this->update_meta( '_wpinv_gateway', $this->gateway );
721
+                        $this->update_meta('_wpinv_gateway', $this->gateway);
722 722
                         break;
723 723
                     case 'mode':
724
-                        $this->update_meta( '_wpinv_mode', $this->mode );
724
+                        $this->update_meta('_wpinv_mode', $this->mode);
725 725
                         break;
726 726
                     case 'transaction_id':
727
-                        $this->update_meta( '_wpinv_transaction_id', $this->transaction_id );
727
+                        $this->update_meta('_wpinv_transaction_id', $this->transaction_id);
728 728
                         break;
729 729
                     case 'ip':
730
-                        $this->update_meta( '_wpinv_user_ip', $this->ip );
730
+                        $this->update_meta('_wpinv_user_ip', $this->ip);
731 731
                         break;
732 732
                     ///case 'user_id':
733 733
                         ///$this->update_meta( '_wpinv_user_id', $this->user_id );
734 734
                         ///$this->user_info['user_id'] = $this->user_id;
735 735
                         ///break;
736 736
                     case 'first_name':
737
-                        $this->update_meta( '_wpinv_first_name', $this->first_name );
737
+                        $this->update_meta('_wpinv_first_name', $this->first_name);
738 738
                         $this->user_info['first_name'] = $this->first_name;
739 739
                         break;
740 740
                     case 'last_name':
741
-                        $this->update_meta( '_wpinv_last_name', $this->last_name );
741
+                        $this->update_meta('_wpinv_last_name', $this->last_name);
742 742
                         $this->user_info['last_name'] = $this->last_name;
743 743
                         break;
744 744
                     case 'phone':
745
-                        $this->update_meta( '_wpinv_phone', $this->phone );
745
+                        $this->update_meta('_wpinv_phone', $this->phone);
746 746
                         $this->user_info['phone'] = $this->phone;
747 747
                         break;
748 748
                     case 'address':
749
-                        $this->update_meta( '_wpinv_address', $this->address );
749
+                        $this->update_meta('_wpinv_address', $this->address);
750 750
                         $this->user_info['address'] = $this->address;
751 751
                         break;
752 752
                     case 'city':
753
-                        $this->update_meta( '_wpinv_city', $this->city );
753
+                        $this->update_meta('_wpinv_city', $this->city);
754 754
                         $this->user_info['city'] = $this->city;
755 755
                         break;
756 756
                     case 'country':
757
-                        $this->update_meta( '_wpinv_country', $this->country );
757
+                        $this->update_meta('_wpinv_country', $this->country);
758 758
                         $this->user_info['country'] = $this->country;
759 759
                         break;
760 760
                     case 'state':
761
-                        $this->update_meta( '_wpinv_state', $this->state );
761
+                        $this->update_meta('_wpinv_state', $this->state);
762 762
                         $this->user_info['state'] = $this->state;
763 763
                         break;
764 764
                     case 'zip':
765
-                        $this->update_meta( '_wpinv_zip', $this->zip );
765
+                        $this->update_meta('_wpinv_zip', $this->zip);
766 766
                         $this->user_info['zip'] = $this->zip;
767 767
                         break;
768 768
                     case 'company':
769
-                        $this->update_meta( '_wpinv_company', $this->company );
769
+                        $this->update_meta('_wpinv_company', $this->company);
770 770
                         $this->user_info['company'] = $this->company;
771 771
                         break;
772 772
                     case 'vat_number':
773
-                        $this->update_meta( '_wpinv_vat_number', $this->vat_number );
773
+                        $this->update_meta('_wpinv_vat_number', $this->vat_number);
774 774
                         $this->user_info['vat_number'] = $this->vat_number;
775 775
                         
776
-                        $vat_info = $wpi_session->get( 'user_vat_data' );
777
-                        if ( $this->vat_number && !empty( $vat_info ) && isset( $vat_info['number'] ) && isset( $vat_info['valid'] ) && $vat_info['number'] == $this->vat_number ) {
778
-                            $adddress_confirmed = isset( $vat_info['adddress_confirmed'] ) ? $vat_info['adddress_confirmed'] : false;
779
-                            $this->update_meta( '_wpinv_adddress_confirmed', (bool)$adddress_confirmed );
776
+                        $vat_info = $wpi_session->get('user_vat_data');
777
+                        if ($this->vat_number && !empty($vat_info) && isset($vat_info['number']) && isset($vat_info['valid']) && $vat_info['number'] == $this->vat_number) {
778
+                            $adddress_confirmed = isset($vat_info['adddress_confirmed']) ? $vat_info['adddress_confirmed'] : false;
779
+                            $this->update_meta('_wpinv_adddress_confirmed', (bool)$adddress_confirmed);
780 780
                             $this->user_info['adddress_confirmed'] = (bool)$adddress_confirmed;
781 781
                         }
782 782
     
783 783
                         break;
784 784
                     case 'vat_rate':
785
-                        $this->update_meta( '_wpinv_vat_rate', $this->vat_rate );
785
+                        $this->update_meta('_wpinv_vat_rate', $this->vat_rate);
786 786
                         $this->user_info['vat_rate'] = $this->vat_rate;
787 787
                         break;
788 788
                     case 'adddress_confirmed':
789
-                        $this->update_meta( '_wpinv_adddress_confirmed', $this->adddress_confirmed );
789
+                        $this->update_meta('_wpinv_adddress_confirmed', $this->adddress_confirmed);
790 790
                         $this->user_info['adddress_confirmed'] = $this->adddress_confirmed;
791 791
                         break;
792 792
                     
793 793
                     case 'key':
794
-                        $this->update_meta( '_wpinv_key', $this->key );
794
+                        $this->update_meta('_wpinv_key', $this->key);
795 795
                         break;
796 796
                     case 'date':
797 797
                         $args = array(
@@ -800,49 +800,49 @@  discard block
 block discarded – undo
800 800
                             'edit_date' => true,
801 801
                         );
802 802
 
803
-                        wp_update_post( $args );
803
+                        wp_update_post($args);
804 804
                         break;
805 805
                     case 'due_date':
806
-                        if ( empty( $this->due_date ) ) {
806
+                        if (empty($this->due_date)) {
807 807
                             $this->due_date = 'none';
808 808
                         }
809 809
                         
810
-                        $this->update_meta( '_wpinv_due_date', $this->due_date );
810
+                        $this->update_meta('_wpinv_due_date', $this->due_date);
811 811
                         break;
812 812
                     case 'completed_date':
813
-                        $this->update_meta( '_wpinv_completed_date', $this->completed_date );
813
+                        $this->update_meta('_wpinv_completed_date', $this->completed_date);
814 814
                         break;
815 815
                     case 'discounts':
816
-                        if ( ! is_array( $this->discounts ) ) {
817
-                            $this->discounts = explode( ',', $this->discounts );
816
+                        if (!is_array($this->discounts)) {
817
+                            $this->discounts = explode(',', $this->discounts);
818 818
                         }
819 819
 
820
-                        $this->user_info['discount'] = implode( ',', $this->discounts );
820
+                        $this->user_info['discount'] = implode(',', $this->discounts);
821 821
                         break;
822 822
                     case 'discount':
823
-                        $this->update_meta( '_wpinv_discount', wpinv_round_amount( $this->discount ) );
823
+                        $this->update_meta('_wpinv_discount', wpinv_round_amount($this->discount));
824 824
                         break;
825 825
                     case 'discount_code':
826
-                        $this->update_meta( '_wpinv_discount_code', $this->discount_code );
826
+                        $this->update_meta('_wpinv_discount_code', $this->discount_code);
827 827
                         break;
828 828
                     case 'parent_invoice':
829 829
                         $args = array(
830 830
                             'ID'          => $this->ID,
831 831
                             'post_parent' => $this->parent_invoice,
832 832
                         );
833
-                        wp_update_post( $args );
833
+                        wp_update_post($args);
834 834
                         break;
835 835
                     default:
836
-                        do_action( 'wpinv_save', $this, $key );
836
+                        do_action('wpinv_save', $this, $key);
837 837
                         break;
838 838
                 }
839 839
             }
840 840
 
841
-            $this->update_meta( '_wpinv_subtotal', wpinv_round_amount( $this->subtotal ) );
842
-            $this->update_meta( '_wpinv_total', wpinv_round_amount( $this->total ) );
843
-            $this->update_meta( '_wpinv_tax', wpinv_round_amount( $this->tax ) );
841
+            $this->update_meta('_wpinv_subtotal', wpinv_round_amount($this->subtotal));
842
+            $this->update_meta('_wpinv_total', wpinv_round_amount($this->total));
843
+            $this->update_meta('_wpinv_tax', wpinv_round_amount($this->tax));
844 844
             
845
-            $this->items    = array_values( $this->items );
845
+            $this->items = array_values($this->items);
846 846
             
847 847
             $new_meta = array(
848 848
                 'items'         => $this->items,
@@ -853,12 +853,12 @@  discard block
 block discarded – undo
853 853
             );
854 854
             
855 855
             $meta        = $this->get_meta();
856
-            $merged_meta = array_merge( $meta, $new_meta );
856
+            $merged_meta = array_merge($meta, $new_meta);
857 857
 
858 858
             // Only save the payment meta if it's changed
859
-            if ( md5( serialize( $meta ) ) !== md5( serialize( $merged_meta) ) ) {
860
-                $updated     = $this->update_meta( '_wpinv_payment_meta', $merged_meta );
861
-                if ( false !== $updated ) {
859
+            if (md5(serialize($meta)) !== md5(serialize($merged_meta))) {
860
+                $updated = $this->update_meta('_wpinv_payment_meta', $merged_meta);
861
+                if (false !== $updated) {
862 862
                     $saved = true;
863 863
                 }
864 864
             }
@@ -866,15 +866,15 @@  discard block
 block discarded – undo
866 866
             $this->pending = array();
867 867
             $saved         = true;
868 868
         } else {
869
-            $this->update_meta( '_wpinv_subtotal', wpinv_round_amount( $this->subtotal ) );
870
-            $this->update_meta( '_wpinv_total', wpinv_round_amount( $this->total ) );
871
-            $this->update_meta( '_wpinv_tax', wpinv_round_amount( $this->tax ) );
869
+            $this->update_meta('_wpinv_subtotal', wpinv_round_amount($this->subtotal));
870
+            $this->update_meta('_wpinv_total', wpinv_round_amount($this->total));
871
+            $this->update_meta('_wpinv_tax', wpinv_round_amount($this->tax));
872 872
         }
873 873
         
874
-        do_action( 'wpinv_invoice_save', $this, $saved );
874
+        do_action('wpinv_invoice_save', $this, $saved);
875 875
 
876
-        if ( true === $saved || $setup ) {
877
-            $this->setup_invoice( $this->ID );
876
+        if (true === $saved || $setup) {
877
+            $this->setup_invoice($this->ID);
878 878
         }
879 879
         
880 880
         $this->refresh_item_ids();
@@ -882,7 +882,7 @@  discard block
 block discarded – undo
882 882
         return $saved;
883 883
     }
884 884
     
885
-    public function add_fee( $args, $global = true ) {
885
+    public function add_fee($args, $global = true) {
886 886
         $default_args = array(
887 887
             'label'       => '',
888 888
             'amount'      => 0,
@@ -892,75 +892,75 @@  discard block
 block discarded – undo
892 892
             'item_id'     => 0,
893 893
         );
894 894
 
895
-        $fee = wp_parse_args( $args, $default_args );
895
+        $fee = wp_parse_args($args, $default_args);
896 896
         
897
-        if ( empty( $fee['label'] ) ) {
897
+        if (empty($fee['label'])) {
898 898
             return false;
899 899
         }
900 900
         
901
-        $fee['id']  = sanitize_title( $fee['label'] );
901
+        $fee['id'] = sanitize_title($fee['label']);
902 902
         
903
-        $this->fees[]               = $fee;
903
+        $this->fees[] = $fee;
904 904
         
905 905
         $added_fee               = $fee;
906 906
         $added_fee['action']     = 'add';
907 907
         $this->pending['fees'][] = $added_fee;
908
-        reset( $this->fees );
908
+        reset($this->fees);
909 909
 
910
-        $this->increase_fees( $fee['amount'] );
910
+        $this->increase_fees($fee['amount']);
911 911
         return true;
912 912
     }
913 913
 
914
-    public function remove_fee( $key ) {
914
+    public function remove_fee($key) {
915 915
         $removed = false;
916 916
 
917
-        if ( is_numeric( $key ) ) {
918
-            $removed = $this->remove_fee_by( 'index', $key );
917
+        if (is_numeric($key)) {
918
+            $removed = $this->remove_fee_by('index', $key);
919 919
         }
920 920
 
921 921
         return $removed;
922 922
     }
923 923
 
924
-    public function remove_fee_by( $key, $value, $global = false ) {
925
-        $allowed_fee_keys = apply_filters( 'wpinv_fee_keys', array(
924
+    public function remove_fee_by($key, $value, $global = false) {
925
+        $allowed_fee_keys = apply_filters('wpinv_fee_keys', array(
926 926
             'index', 'label', 'amount', 'type',
927
-        ) );
927
+        ));
928 928
 
929
-        if ( ! in_array( $key, $allowed_fee_keys ) ) {
929
+        if (!in_array($key, $allowed_fee_keys)) {
930 930
             return false;
931 931
         }
932 932
 
933 933
         $removed = false;
934
-        if ( 'index' === $key && array_key_exists( $value, $this->fees ) ) {
935
-            $removed_fee             = $this->fees[ $value ];
934
+        if ('index' === $key && array_key_exists($value, $this->fees)) {
935
+            $removed_fee             = $this->fees[$value];
936 936
             $removed_fee['action']   = 'remove';
937 937
             $this->pending['fees'][] = $removed_fee;
938 938
 
939
-            $this->decrease_fees( $removed_fee['amount'] );
939
+            $this->decrease_fees($removed_fee['amount']);
940 940
 
941
-            unset( $this->fees[ $value ] );
941
+            unset($this->fees[$value]);
942 942
             $removed = true;
943
-        } else if ( 'index' !== $key ) {
944
-            foreach ( $this->fees as $index => $fee ) {
945
-                if ( isset( $fee[ $key ] ) && $fee[ $key ] == $value ) {
943
+        } else if ('index' !== $key) {
944
+            foreach ($this->fees as $index => $fee) {
945
+                if (isset($fee[$key]) && $fee[$key] == $value) {
946 946
                     $removed_fee             = $fee;
947 947
                     $removed_fee['action']   = 'remove';
948 948
                     $this->pending['fees'][] = $removed_fee;
949 949
 
950
-                    $this->decrease_fees( $removed_fee['amount'] );
950
+                    $this->decrease_fees($removed_fee['amount']);
951 951
 
952
-                    unset( $this->fees[ $index ] );
952
+                    unset($this->fees[$index]);
953 953
                     $removed = true;
954 954
 
955
-                    if ( false === $global ) {
955
+                    if (false === $global) {
956 956
                         break;
957 957
                     }
958 958
                 }
959 959
             }
960 960
         }
961 961
 
962
-        if ( true === $removed ) {
963
-            $this->fees = array_values( $this->fees );
962
+        if (true === $removed) {
963
+            $this->fees = array_values($this->fees);
964 964
         }
965 965
 
966 966
         return $removed;
@@ -968,35 +968,35 @@  discard block
 block discarded – undo
968 968
 
969 969
     
970 970
 
971
-    public function add_note( $note = '', $customer_type = false, $added_by_user = false, $system = false ) {
971
+    public function add_note($note = '', $customer_type = false, $added_by_user = false, $system = false) {
972 972
         // Bail if no note specified
973
-        if( !$note ) {
973
+        if (!$note) {
974 974
             return false;
975 975
         }
976 976
 
977
-        if ( empty( $this->ID ) )
977
+        if (empty($this->ID))
978 978
             return false;
979 979
         
980
-        if ( ( ( is_user_logged_in() && current_user_can( 'manage_options' ) ) || $added_by_user ) && !$system ) {
981
-            $user                 = get_user_by( 'id', get_current_user_id() );
980
+        if (((is_user_logged_in() && current_user_can('manage_options')) || $added_by_user) && !$system) {
981
+            $user                 = get_user_by('id', get_current_user_id());
982 982
             $comment_author       = $user->display_name;
983 983
             $comment_author_email = $user->user_email;
984 984
         } else {
985 985
             $comment_author       = 'System';
986 986
             $comment_author_email = 'system@';
987
-            $comment_author_email .= isset( $_SERVER['HTTP_HOST'] ) ? str_replace( 'www.', '', $_SERVER['HTTP_HOST'] ) : 'noreply.com';
988
-            $comment_author_email = sanitize_email( $comment_author_email );
987
+            $comment_author_email .= isset($_SERVER['HTTP_HOST']) ? str_replace('www.', '', $_SERVER['HTTP_HOST']) : 'noreply.com';
988
+            $comment_author_email = sanitize_email($comment_author_email);
989 989
         }
990 990
 
991
-        do_action( 'wpinv_pre_insert_invoice_note', $this->ID, $note, $customer_type );
991
+        do_action('wpinv_pre_insert_invoice_note', $this->ID, $note, $customer_type);
992 992
 
993
-        $note_id = wp_insert_comment( wp_filter_comment( array(
993
+        $note_id = wp_insert_comment(wp_filter_comment(array(
994 994
             'comment_post_ID'      => $this->ID,
995 995
             'comment_content'      => $note,
996 996
             'comment_agent'        => 'WPInvoicing',
997 997
             'user_id'              => is_admin() ? get_current_user_id() : 0,
998
-            'comment_date'         => current_time( 'mysql' ),
999
-            'comment_date_gmt'     => current_time( 'mysql', 1 ),
998
+            'comment_date'         => current_time('mysql'),
999
+            'comment_date_gmt'     => current_time('mysql', 1),
1000 1000
             'comment_approved'     => 1,
1001 1001
             'comment_parent'       => 0,
1002 1002
             'comment_author'       => $comment_author,
@@ -1004,53 +1004,53 @@  discard block
 block discarded – undo
1004 1004
             'comment_author_url'   => '',
1005 1005
             'comment_author_email' => $comment_author_email,
1006 1006
             'comment_type'         => 'wpinv_note'
1007
-        ) ) );
1007
+        )));
1008 1008
 
1009
-        do_action( 'wpinv_insert_payment_note', $note_id, $this->ID, $note );
1009
+        do_action('wpinv_insert_payment_note', $note_id, $this->ID, $note);
1010 1010
         
1011
-        if ( $customer_type ) {
1012
-            add_comment_meta( $note_id, '_wpi_customer_note', 1 );
1011
+        if ($customer_type) {
1012
+            add_comment_meta($note_id, '_wpi_customer_note', 1);
1013 1013
 
1014
-            do_action( 'wpinv_new_customer_note', array( 'invoice_id' => $this->ID, 'user_note' => $note ) );
1014
+            do_action('wpinv_new_customer_note', array('invoice_id' => $this->ID, 'user_note' => $note));
1015 1015
         }
1016 1016
 
1017 1017
         return $note_id;
1018 1018
     }
1019 1019
 
1020
-    private function increase_subtotal( $amount = 0.00 ) {
1021
-        $amount          = (float) $amount;
1020
+    private function increase_subtotal($amount = 0.00) {
1021
+        $amount          = (float)$amount;
1022 1022
         $this->subtotal += $amount;
1023
-        $this->subtotal  = wpinv_round_amount( $this->subtotal );
1023
+        $this->subtotal  = wpinv_round_amount($this->subtotal);
1024 1024
 
1025 1025
         $this->recalculate_total();
1026 1026
     }
1027 1027
 
1028
-    private function decrease_subtotal( $amount = 0.00 ) {
1029
-        $amount          = (float) $amount;
1028
+    private function decrease_subtotal($amount = 0.00) {
1029
+        $amount          = (float)$amount;
1030 1030
         $this->subtotal -= $amount;
1031
-        $this->subtotal  = wpinv_round_amount( $this->subtotal );
1031
+        $this->subtotal  = wpinv_round_amount($this->subtotal);
1032 1032
 
1033
-        if ( $this->subtotal < 0 ) {
1033
+        if ($this->subtotal < 0) {
1034 1034
             $this->subtotal = 0;
1035 1035
         }
1036 1036
 
1037 1037
         $this->recalculate_total();
1038 1038
     }
1039 1039
 
1040
-    private function increase_fees( $amount = 0.00 ) {
1040
+    private function increase_fees($amount = 0.00) {
1041 1041
         $amount            = (float)$amount;
1042 1042
         $this->fees_total += $amount;
1043
-        $this->fees_total  = wpinv_round_amount( $this->fees_total );
1043
+        $this->fees_total  = wpinv_round_amount($this->fees_total);
1044 1044
 
1045 1045
         $this->recalculate_total();
1046 1046
     }
1047 1047
 
1048
-    private function decrease_fees( $amount = 0.00 ) {
1049
-        $amount            = (float) $amount;
1048
+    private function decrease_fees($amount = 0.00) {
1049
+        $amount            = (float)$amount;
1050 1050
         $this->fees_total -= $amount;
1051
-        $this->fees_total  = wpinv_round_amount( $this->fees_total );
1051
+        $this->fees_total  = wpinv_round_amount($this->fees_total);
1052 1052
 
1053
-        if ( $this->fees_total < 0 ) {
1053
+        if ($this->fees_total < 0) {
1054 1054
             $this->fees_total = 0;
1055 1055
         }
1056 1056
 
@@ -1061,54 +1061,54 @@  discard block
 block discarded – undo
1061 1061
         global $wpi_nosave;
1062 1062
         
1063 1063
         $this->total = $this->subtotal + $this->tax + $this->fees_total;
1064
-        $this->total = wpinv_round_amount( $this->total );
1064
+        $this->total = wpinv_round_amount($this->total);
1065 1065
         
1066
-        do_action( 'wpinv_invoice_recalculate_total', $this, $wpi_nosave );
1066
+        do_action('wpinv_invoice_recalculate_total', $this, $wpi_nosave);
1067 1067
     }
1068 1068
     
1069
-    public function increase_tax( $amount = 0.00 ) {
1070
-        $amount       = (float) $amount;
1069
+    public function increase_tax($amount = 0.00) {
1070
+        $amount       = (float)$amount;
1071 1071
         $this->tax   += $amount;
1072 1072
 
1073 1073
         $this->recalculate_total();
1074 1074
     }
1075 1075
 
1076
-    public function decrease_tax( $amount = 0.00 ) {
1077
-        $amount     = (float) $amount;
1076
+    public function decrease_tax($amount = 0.00) {
1077
+        $amount     = (float)$amount;
1078 1078
         $this->tax -= $amount;
1079 1079
 
1080
-        if ( $this->tax < 0 ) {
1080
+        if ($this->tax < 0) {
1081 1081
             $this->tax = 0;
1082 1082
         }
1083 1083
 
1084 1084
         $this->recalculate_total();
1085 1085
     }
1086 1086
 
1087
-    public function update_status( $new_status = false, $note = '', $manual = false ) {
1088
-        $old_status = ! empty( $this->old_status ) ? $this->old_status : get_post_status( $this->ID );
1087
+    public function update_status($new_status = false, $note = '', $manual = false) {
1088
+        $old_status = !empty($this->old_status) ? $this->old_status : get_post_status($this->ID);
1089 1089
         
1090
-        if ( $old_status === $new_status && in_array( $new_status, array_keys( wpinv_get_invoice_statuses() ) ) ) {
1090
+        if ($old_status === $new_status && in_array($new_status, array_keys(wpinv_get_invoice_statuses()))) {
1091 1091
             return false; // Don't permit status changes that aren't changes
1092 1092
         }
1093 1093
 
1094
-        $do_change = apply_filters( 'wpinv_should_update_invoice_status', true, $this->ID, $new_status, $old_status );
1094
+        $do_change = apply_filters('wpinv_should_update_invoice_status', true, $this->ID, $new_status, $old_status);
1095 1095
         $updated = false;
1096 1096
 
1097
-        if ( $do_change ) {
1098
-            do_action( 'wpinv_before_invoice_status_change', $this->ID, $new_status, $old_status );
1097
+        if ($do_change) {
1098
+            do_action('wpinv_before_invoice_status_change', $this->ID, $new_status, $old_status);
1099 1099
 
1100 1100
             $update_post_data                   = array();
1101 1101
             $update_post_data['ID']             = $this->ID;
1102 1102
             $update_post_data['post_status']    = $new_status;
1103
-            $update_post_data['edit_date']      = current_time( 'mysql', 0 );
1104
-            $update_post_data['edit_date_gmt']  = current_time( 'mysql', 1 );
1103
+            $update_post_data['edit_date']      = current_time('mysql', 0);
1104
+            $update_post_data['edit_date_gmt']  = current_time('mysql', 1);
1105 1105
             
1106
-            $update_post_data = apply_filters( 'wpinv_update_invoice_status_fields', $update_post_data, $this->ID );
1106
+            $update_post_data = apply_filters('wpinv_update_invoice_status_fields', $update_post_data, $this->ID);
1107 1107
 
1108
-            $updated = wp_update_post( $update_post_data );     
1108
+            $updated = wp_update_post($update_post_data);     
1109 1109
            
1110 1110
             // Process any specific status functions
1111
-            switch( $new_status ) {
1111
+            switch ($new_status) {
1112 1112
                 case 'wpi-refunded':
1113 1113
                     $this->process_refund();
1114 1114
                     break;
@@ -1121,9 +1121,9 @@  discard block
 block discarded – undo
1121 1121
             }
1122 1122
             
1123 1123
             // Status was changed.
1124
-            do_action( 'wpinv_status_' . $new_status, $this->ID, $old_status );
1125
-            do_action( 'wpinv_status_' . $old_status . '_to_' . $new_status, $this->ID, $old_status );
1126
-            do_action( 'wpinv_update_status', $this->ID, $new_status, $old_status );
1124
+            do_action('wpinv_status_' . $new_status, $this->ID, $old_status);
1125
+            do_action('wpinv_status_' . $old_status . '_to_' . $new_status, $this->ID, $old_status);
1126
+            do_action('wpinv_update_status', $this->ID, $new_status, $old_status);
1127 1127
         }
1128 1128
 
1129 1129
         return $updated;
@@ -1137,20 +1137,20 @@  discard block
 block discarded – undo
1137 1137
         $this->save();
1138 1138
     }
1139 1139
 
1140
-    public function update_meta( $meta_key = '', $meta_value = '', $prev_value = '' ) {
1141
-        if ( empty( $meta_key ) ) {
1140
+    public function update_meta($meta_key = '', $meta_value = '', $prev_value = '') {
1141
+        if (empty($meta_key)) {
1142 1142
             return false;
1143 1143
         }
1144 1144
 
1145
-        if ( $meta_key == 'key' || $meta_key == 'date' ) {
1145
+        if ($meta_key == 'key' || $meta_key == 'date') {
1146 1146
             $current_meta = $this->get_meta();
1147
-            $current_meta[ $meta_key ] = $meta_value;
1147
+            $current_meta[$meta_key] = $meta_value;
1148 1148
 
1149 1149
             $meta_key     = '_wpinv_payment_meta';
1150 1150
             $meta_value   = $current_meta;
1151 1151
         }
1152 1152
 
1153
-        $meta_value = apply_filters( 'wpinv_update_payment_meta_' . $meta_key, $meta_value, $this->ID );
1153
+        $meta_value = apply_filters('wpinv_update_payment_meta_' . $meta_key, $meta_value, $this->ID);
1154 1154
         
1155 1155
         // Do not update created date on invoice marked as paid.
1156 1156
         /*if ( $meta_key == '_wpinv_completed_date' && !empty( $meta_value ) ) {
@@ -1165,45 +1165,45 @@  discard block
 block discarded – undo
1165 1165
             wp_update_post( $args );
1166 1166
         }*/
1167 1167
         
1168
-        return update_post_meta( $this->ID, $meta_key, $meta_value, $prev_value );
1168
+        return update_post_meta($this->ID, $meta_key, $meta_value, $prev_value);
1169 1169
     }
1170 1170
 
1171 1171
     private function process_refund() {
1172 1172
         $process_refund = true;
1173 1173
 
1174 1174
         // If the payment was not in publish, don't decrement stats as they were never incremented
1175
-        if ( 'publish' != $this->old_status || 'wpi-refunded' != $this->status ) {
1175
+        if ('publish' != $this->old_status || 'wpi-refunded' != $this->status) {
1176 1176
             $process_refund = false;
1177 1177
         }
1178 1178
 
1179 1179
         // Allow extensions to filter for their own payment types, Example: Recurring Payments
1180
-        $process_refund = apply_filters( 'wpinv_should_process_refund', $process_refund, $this );
1180
+        $process_refund = apply_filters('wpinv_should_process_refund', $process_refund, $this);
1181 1181
 
1182
-        if ( false === $process_refund ) {
1182
+        if (false === $process_refund) {
1183 1183
             return;
1184 1184
         }
1185 1185
 
1186
-        do_action( 'wpinv_pre_refund_invoice', $this );
1186
+        do_action('wpinv_pre_refund_invoice', $this);
1187 1187
         
1188
-        $decrease_store_earnings = apply_filters( 'wpinv_decrease_store_earnings_on_refund', true, $this );
1189
-        $decrease_customer_value = apply_filters( 'wpinv_decrease_customer_value_on_refund', true, $this );
1190
-        $decrease_purchase_count = apply_filters( 'wpinv_decrease_customer_purchase_count_on_refund', true, $this );
1188
+        $decrease_store_earnings = apply_filters('wpinv_decrease_store_earnings_on_refund', true, $this);
1189
+        $decrease_customer_value = apply_filters('wpinv_decrease_customer_value_on_refund', true, $this);
1190
+        $decrease_purchase_count = apply_filters('wpinv_decrease_customer_purchase_count_on_refund', true, $this);
1191 1191
         
1192
-        do_action( 'wpinv_post_refund_invoice', $this );
1192
+        do_action('wpinv_post_refund_invoice', $this);
1193 1193
     }
1194 1194
 
1195 1195
     private function process_failure() {
1196 1196
         $discounts = $this->discounts;
1197
-        if ( empty( $discounts ) ) {
1197
+        if (empty($discounts)) {
1198 1198
             return;
1199 1199
         }
1200 1200
 
1201
-        if ( ! is_array( $discounts ) ) {
1202
-            $discounts = array_map( 'trim', explode( ',', $discounts ) );
1201
+        if (!is_array($discounts)) {
1202
+            $discounts = array_map('trim', explode(',', $discounts));
1203 1203
         }
1204 1204
 
1205
-        foreach ( $discounts as $discount ) {
1206
-            wpinv_decrease_discount_usage( $discount );
1205
+        foreach ($discounts as $discount) {
1206
+            wpinv_decrease_discount_usage($discount);
1207 1207
         }
1208 1208
     }
1209 1209
     
@@ -1211,92 +1211,92 @@  discard block
 block discarded – undo
1211 1211
         $process_pending = true;
1212 1212
 
1213 1213
         // If the payment was not in publish or revoked status, don't decrement stats as they were never incremented
1214
-        if ( ( 'publish' != $this->old_status && 'revoked' != $this->old_status ) || 'wpi-pending' != $this->status ) {
1214
+        if (('publish' != $this->old_status && 'revoked' != $this->old_status) || 'wpi-pending' != $this->status) {
1215 1215
             $process_pending = false;
1216 1216
         }
1217 1217
 
1218 1218
         // Allow extensions to filter for their own payment types, Example: Recurring Payments
1219
-        $process_pending = apply_filters( 'wpinv_should_process_pending', $process_pending, $this );
1219
+        $process_pending = apply_filters('wpinv_should_process_pending', $process_pending, $this);
1220 1220
 
1221
-        if ( false === $process_pending ) {
1221
+        if (false === $process_pending) {
1222 1222
             return;
1223 1223
         }
1224 1224
 
1225
-        $decrease_store_earnings = apply_filters( 'wpinv_decrease_store_earnings_on_pending', true, $this );
1226
-        $decrease_customer_value = apply_filters( 'wpinv_decrease_customer_value_on_pending', true, $this );
1227
-        $decrease_purchase_count = apply_filters( 'wpinv_decrease_customer_purchase_count_on_pending', true, $this );
1225
+        $decrease_store_earnings = apply_filters('wpinv_decrease_store_earnings_on_pending', true, $this);
1226
+        $decrease_customer_value = apply_filters('wpinv_decrease_customer_value_on_pending', true, $this);
1227
+        $decrease_purchase_count = apply_filters('wpinv_decrease_customer_purchase_count_on_pending', true, $this);
1228 1228
 
1229 1229
         $this->completed_date = '';
1230
-        $this->update_meta( '_wpinv_completed_date', '' );
1230
+        $this->update_meta('_wpinv_completed_date', '');
1231 1231
     }
1232 1232
     
1233 1233
     // get data
1234
-    public function get_meta( $meta_key = '_wpinv_payment_meta', $single = true ) {
1235
-        $meta = get_post_meta( $this->ID, $meta_key, $single );
1234
+    public function get_meta($meta_key = '_wpinv_payment_meta', $single = true) {
1235
+        $meta = get_post_meta($this->ID, $meta_key, $single);
1236 1236
 
1237
-        if ( $meta_key === '_wpinv_payment_meta' ) {
1237
+        if ($meta_key === '_wpinv_payment_meta') {
1238 1238
 
1239
-            if(!is_array($meta)){$meta = array();} // we need this to be an array so make sure it is.
1239
+            if (!is_array($meta)) {$meta = array(); } // we need this to be an array so make sure it is.
1240 1240
 
1241
-            if ( empty( $meta['key'] ) ) {
1241
+            if (empty($meta['key'])) {
1242 1242
                 $meta['key'] = $this->setup_invoice_key();
1243 1243
             }
1244 1244
 
1245
-            if ( empty( $meta['date'] ) ) {
1246
-                $meta['date'] = get_post_field( 'post_date', $this->ID );
1245
+            if (empty($meta['date'])) {
1246
+                $meta['date'] = get_post_field('post_date', $this->ID);
1247 1247
             }
1248 1248
         }
1249 1249
 
1250
-        $meta = apply_filters( 'wpinv_get_invoice_meta_' . $meta_key, $meta, $this->ID );
1250
+        $meta = apply_filters('wpinv_get_invoice_meta_' . $meta_key, $meta, $this->ID);
1251 1251
 
1252
-        return apply_filters( 'wpinv_get_invoice_meta', $meta, $this->ID, $meta_key );
1252
+        return apply_filters('wpinv_get_invoice_meta', $meta, $this->ID, $meta_key);
1253 1253
     }
1254 1254
     
1255 1255
     public function get_description() {
1256
-        $post = get_post( $this->ID );
1256
+        $post = get_post($this->ID);
1257 1257
         
1258
-        $description = !empty( $post ) ? $post->post_content : '';
1259
-        return apply_filters( 'wpinv_get_description', $description, $this->ID, $this );
1258
+        $description = !empty($post) ? $post->post_content : '';
1259
+        return apply_filters('wpinv_get_description', $description, $this->ID, $this);
1260 1260
     }
1261 1261
     
1262
-    public function get_status( $nicename = false ) {
1263
-        if ( !$nicename ) {
1262
+    public function get_status($nicename = false) {
1263
+        if (!$nicename) {
1264 1264
             $status = $this->status;
1265 1265
         } else {
1266 1266
             $status = $this->status_nicename;
1267 1267
         }
1268 1268
         
1269
-        return apply_filters( 'wpinv_get_status', $status, $nicename, $this->ID, $this );
1269
+        return apply_filters('wpinv_get_status', $status, $nicename, $this->ID, $this);
1270 1270
     }
1271 1271
     
1272 1272
     public function get_cart_details() {
1273
-        return apply_filters( 'wpinv_cart_details', $this->cart_details, $this->ID, $this );
1273
+        return apply_filters('wpinv_cart_details', $this->cart_details, $this->ID, $this);
1274 1274
     }
1275 1275
     
1276
-    public function get_subtotal( $currency = false ) {
1277
-        $subtotal = wpinv_round_amount( $this->subtotal );
1276
+    public function get_subtotal($currency = false) {
1277
+        $subtotal = wpinv_round_amount($this->subtotal);
1278 1278
         
1279
-        if ( $currency ) {
1280
-            $subtotal = wpinv_price( wpinv_format_amount( $subtotal, NULL, !$currency ), $this->get_currency() );
1279
+        if ($currency) {
1280
+            $subtotal = wpinv_price(wpinv_format_amount($subtotal, NULL, !$currency), $this->get_currency());
1281 1281
         }
1282 1282
         
1283
-        return apply_filters( 'wpinv_get_invoice_subtotal', $subtotal, $this->ID, $this, $currency );
1283
+        return apply_filters('wpinv_get_invoice_subtotal', $subtotal, $this->ID, $this, $currency);
1284 1284
     }
1285 1285
     
1286
-    public function get_total( $currency = false ) {        
1287
-        if ( $this->is_free_trial() ) {
1288
-            $total = wpinv_round_amount( 0 );
1286
+    public function get_total($currency = false) {        
1287
+        if ($this->is_free_trial()) {
1288
+            $total = wpinv_round_amount(0);
1289 1289
         } else {
1290
-            $total = wpinv_round_amount( $this->total );
1290
+            $total = wpinv_round_amount($this->total);
1291 1291
         }
1292
-        if ( $currency ) {
1293
-            $total = wpinv_price( wpinv_format_amount( $total, NULL, !$currency ), $this->get_currency() );
1292
+        if ($currency) {
1293
+            $total = wpinv_price(wpinv_format_amount($total, NULL, !$currency), $this->get_currency());
1294 1294
         }
1295 1295
         
1296
-        return apply_filters( 'wpinv_get_invoice_total', $total, $this->ID, $this, $currency );
1296
+        return apply_filters('wpinv_get_invoice_total', $total, $this->ID, $this, $currency);
1297 1297
     }
1298 1298
     
1299
-    public function get_recurring_details( $field = '', $currency = false ) {        
1299
+    public function get_recurring_details($field = '', $currency = false) {        
1300 1300
         $data                 = array();
1301 1301
         $data['cart_details'] = $this->cart_details;
1302 1302
         $data['subtotal']     = $this->get_subtotal();
@@ -1304,45 +1304,45 @@  discard block
 block discarded – undo
1304 1304
         $data['tax']          = $this->get_tax();
1305 1305
         $data['total']        = $this->get_total();
1306 1306
     
1307
-        if ( !empty( $this->cart_details ) && ( $this->is_parent() || $this->is_renewal() ) ) {
1307
+        if (!empty($this->cart_details) && ($this->is_parent() || $this->is_renewal())) {
1308 1308
             $is_free_trial = $this->is_free_trial();
1309
-            $discounts = $this->get_discounts( true );
1309
+            $discounts = $this->get_discounts(true);
1310 1310
             
1311
-            if ( $is_free_trial || !empty( $discounts ) ) {
1311
+            if ($is_free_trial || !empty($discounts)) {
1312 1312
                 $first_use_only = false;
1313 1313
                 
1314
-                if ( !empty( $discounts ) ) {
1315
-                    foreach ( $discounts as $key => $code ) {
1316
-                        if ( wpinv_discount_is_recurring( $code, true ) ) {
1314
+                if (!empty($discounts)) {
1315
+                    foreach ($discounts as $key => $code) {
1316
+                        if (wpinv_discount_is_recurring($code, true)) {
1317 1317
                             $first_use_only = true;
1318 1318
                             break;
1319 1319
                         }
1320 1320
                     }
1321 1321
                 }
1322 1322
                     
1323
-                if ( !$first_use_only ) {
1324
-                    $data['subtotal'] = wpinv_round_amount( $this->subtotal );
1325
-                    $data['discount'] = wpinv_round_amount( $this->discount );
1326
-                    $data['tax']      = wpinv_round_amount( $this->tax );
1327
-                    $data['total']    = wpinv_round_amount( $this->total );
1323
+                if (!$first_use_only) {
1324
+                    $data['subtotal'] = wpinv_round_amount($this->subtotal);
1325
+                    $data['discount'] = wpinv_round_amount($this->discount);
1326
+                    $data['tax']      = wpinv_round_amount($this->tax);
1327
+                    $data['total']    = wpinv_round_amount($this->total);
1328 1328
                 } else {
1329 1329
                     $cart_subtotal   = 0;
1330 1330
                     $cart_discount   = 0;
1331 1331
                     $cart_tax        = 0;
1332 1332
 
1333
-                    foreach ( $this->cart_details as $key => $item ) {
1334
-                        $item_quantity  = $item['quantity'] > 0 ? absint( $item['quantity'] ) : 1;
1335
-                        $item_subtotal  = !empty( $item['subtotal'] ) ? $item['subtotal'] : $item['item_price'] * $item_quantity;
1333
+                    foreach ($this->cart_details as $key => $item) {
1334
+                        $item_quantity  = $item['quantity'] > 0 ? absint($item['quantity']) : 1;
1335
+                        $item_subtotal  = !empty($item['subtotal']) ? $item['subtotal'] : $item['item_price'] * $item_quantity;
1336 1336
                         $item_discount  = 0;
1337
-                        $item_tax       = $item_subtotal > 0 && !empty( $item['vat_rate'] ) ? ( $item_subtotal * 0.01 * (float)$item['vat_rate'] ) : 0;
1337
+                        $item_tax       = $item_subtotal > 0 && !empty($item['vat_rate']) ? ($item_subtotal * 0.01 * (float)$item['vat_rate']) : 0;
1338 1338
                         
1339
-                        if ( wpinv_prices_include_tax() ) {
1340
-                            $item_subtotal -= wpinv_round_amount( $item_tax );
1339
+                        if (wpinv_prices_include_tax()) {
1340
+                            $item_subtotal -= wpinv_round_amount($item_tax);
1341 1341
                         }
1342 1342
                         
1343 1343
                         $item_total     = $item_subtotal - $item_discount + $item_tax;
1344 1344
                         // Do not allow totals to go negative
1345
-                        if ( $item_total < 0 ) {
1345
+                        if ($item_total < 0) {
1346 1346
                             $item_total = 0;
1347 1347
                         }
1348 1348
                         
@@ -1350,113 +1350,113 @@  discard block
 block discarded – undo
1350 1350
                         $cart_discount  += (float)($item_discount);
1351 1351
                         $cart_tax       += (float)($item_tax);
1352 1352
                         
1353
-                        $data['cart_details'][$key]['discount']   = wpinv_round_amount( $item_discount );
1354
-                        $data['cart_details'][$key]['tax']        = wpinv_round_amount( $item_tax );
1355
-                        $data['cart_details'][$key]['price']      = wpinv_round_amount( $item_total );
1353
+                        $data['cart_details'][$key]['discount']   = wpinv_round_amount($item_discount);
1354
+                        $data['cart_details'][$key]['tax']        = wpinv_round_amount($item_tax);
1355
+                        $data['cart_details'][$key]['price']      = wpinv_round_amount($item_total);
1356 1356
                     }
1357 1357
                     
1358
-                    $data['subtotal'] = wpinv_round_amount( $cart_subtotal );
1359
-                    $data['discount'] = wpinv_round_amount( $cart_discount );
1360
-                    $data['tax']      = wpinv_round_amount( $cart_tax );
1361
-                    $data['total']    = wpinv_round_amount( $data['subtotal'] + $data['tax'] );
1358
+                    $data['subtotal'] = wpinv_round_amount($cart_subtotal);
1359
+                    $data['discount'] = wpinv_round_amount($cart_discount);
1360
+                    $data['tax']      = wpinv_round_amount($cart_tax);
1361
+                    $data['total']    = wpinv_round_amount($data['subtotal'] + $data['tax']);
1362 1362
                 }
1363 1363
             }
1364 1364
         }
1365 1365
         
1366
-        $data = apply_filters( 'wpinv_get_invoice_recurring_details', $data, $this, $field, $currency );
1366
+        $data = apply_filters('wpinv_get_invoice_recurring_details', $data, $this, $field, $currency);
1367 1367
 
1368
-        if ( isset( $data[$field] ) ) {
1369
-            return ( $currency ? wpinv_price( $data[$field], $this->get_currency() ) : $data[$field] );
1368
+        if (isset($data[$field])) {
1369
+            return ($currency ? wpinv_price($data[$field], $this->get_currency()) : $data[$field]);
1370 1370
         }
1371 1371
         
1372 1372
         return $data;
1373 1373
     }
1374 1374
     
1375
-    public function get_final_tax( $currency = false ) {        
1376
-        $final_total = wpinv_round_amount( $this->tax );
1377
-        if ( $currency ) {
1378
-            $final_total = wpinv_price( wpinv_format_amount( $final_total, NULL, !$currency ), $this->get_currency() );
1375
+    public function get_final_tax($currency = false) {        
1376
+        $final_total = wpinv_round_amount($this->tax);
1377
+        if ($currency) {
1378
+            $final_total = wpinv_price(wpinv_format_amount($final_total, NULL, !$currency), $this->get_currency());
1379 1379
         }
1380 1380
         
1381
-        return apply_filters( 'wpinv_get_invoice_final_total', $final_total, $this, $currency );
1381
+        return apply_filters('wpinv_get_invoice_final_total', $final_total, $this, $currency);
1382 1382
     }
1383 1383
     
1384
-    public function get_discounts( $array = false ) {
1384
+    public function get_discounts($array = false) {
1385 1385
         $discounts = $this->discounts;
1386
-        if ( $array && $discounts ) {
1387
-            $discounts = explode( ',', $discounts );
1386
+        if ($array && $discounts) {
1387
+            $discounts = explode(',', $discounts);
1388 1388
         }
1389
-        return apply_filters( 'wpinv_payment_discounts', $discounts, $this->ID, $this, $array );
1389
+        return apply_filters('wpinv_payment_discounts', $discounts, $this->ID, $this, $array);
1390 1390
     }
1391 1391
     
1392
-    public function get_discount( $currency = false, $dash = false ) {
1393
-        if ( !empty( $this->discounts ) ) {
1392
+    public function get_discount($currency = false, $dash = false) {
1393
+        if (!empty($this->discounts)) {
1394 1394
             global $ajax_cart_details;
1395 1395
             $ajax_cart_details = $this->get_cart_details();
1396 1396
             
1397
-            if ( !empty( $ajax_cart_details ) && count( $ajax_cart_details ) == count( $this->items ) ) {
1397
+            if (!empty($ajax_cart_details) && count($ajax_cart_details) == count($this->items)) {
1398 1398
                 $cart_items = $ajax_cart_details;
1399 1399
             } else {
1400 1400
                 $cart_items = $this->items;
1401 1401
             }
1402 1402
 
1403
-            $this->discount = wpinv_get_cart_items_discount_amount( $cart_items , $this->discounts );
1403
+            $this->discount = wpinv_get_cart_items_discount_amount($cart_items, $this->discounts);
1404 1404
         }
1405
-        $discount   = wpinv_round_amount( $this->discount );
1405
+        $discount   = wpinv_round_amount($this->discount);
1406 1406
         $dash       = $dash && $discount > 0 ? '&ndash;' : '';
1407 1407
         
1408
-        if ( $currency ) {
1409
-            $discount = wpinv_price( wpinv_format_amount( $discount, NULL, !$currency ), $this->get_currency() );
1408
+        if ($currency) {
1409
+            $discount = wpinv_price(wpinv_format_amount($discount, NULL, !$currency), $this->get_currency());
1410 1410
         }
1411 1411
         
1412
-        $discount   = $dash . $discount;
1412
+        $discount = $dash . $discount;
1413 1413
         
1414
-        return apply_filters( 'wpinv_get_invoice_discount', $discount, $this->ID, $this, $currency, $dash );
1414
+        return apply_filters('wpinv_get_invoice_discount', $discount, $this->ID, $this, $currency, $dash);
1415 1415
     }
1416 1416
     
1417 1417
     public function get_discount_code() {
1418 1418
         return $this->discount_code;
1419 1419
     }
1420 1420
     
1421
-    public function get_tax( $currency = false ) {
1422
-        $tax = wpinv_round_amount( $this->tax );
1421
+    public function get_tax($currency = false) {
1422
+        $tax = wpinv_round_amount($this->tax);
1423 1423
         
1424
-        if ( $currency ) {
1425
-            $tax = wpinv_price( wpinv_format_amount( $tax, NULL, !$currency ), $this->get_currency() );
1424
+        if ($currency) {
1425
+            $tax = wpinv_price(wpinv_format_amount($tax, NULL, !$currency), $this->get_currency());
1426 1426
         }
1427 1427
         
1428
-        return apply_filters( 'wpinv_get_invoice_tax', $tax, $this->ID, $this, $currency );
1428
+        return apply_filters('wpinv_get_invoice_tax', $tax, $this->ID, $this, $currency);
1429 1429
     }
1430 1430
     
1431
-    public function get_fees( $type = 'all' ) {
1432
-        $fees    = array();
1431
+    public function get_fees($type = 'all') {
1432
+        $fees = array();
1433 1433
 
1434
-        if ( ! empty( $this->fees ) && is_array( $this->fees ) ) {
1435
-            foreach ( $this->fees as $fee ) {
1436
-                if( 'all' != $type && ! empty( $fee['type'] ) && $type != $fee['type'] ) {
1434
+        if (!empty($this->fees) && is_array($this->fees)) {
1435
+            foreach ($this->fees as $fee) {
1436
+                if ('all' != $type && !empty($fee['type']) && $type != $fee['type']) {
1437 1437
                     continue;
1438 1438
                 }
1439 1439
 
1440
-                $fee['label'] = stripslashes( $fee['label'] );
1441
-                $fee['amount_display'] = wpinv_price( $fee['amount'], $this->get_currency() );
1442
-                $fees[]    = $fee;
1440
+                $fee['label'] = stripslashes($fee['label']);
1441
+                $fee['amount_display'] = wpinv_price($fee['amount'], $this->get_currency());
1442
+                $fees[] = $fee;
1443 1443
             }
1444 1444
         }
1445 1445
 
1446
-        return apply_filters( 'wpinv_get_invoice_fees', $fees, $this->ID, $this );
1446
+        return apply_filters('wpinv_get_invoice_fees', $fees, $this->ID, $this);
1447 1447
     }
1448 1448
     
1449
-    public function get_fees_total( $type = 'all' ) {
1450
-        $fees_total = (float) 0.00;
1449
+    public function get_fees_total($type = 'all') {
1450
+        $fees_total = (float)0.00;
1451 1451
 
1452
-        $payment_fees = isset( $this->payment_meta['fees'] ) ? $this->payment_meta['fees'] : array();
1453
-        if ( ! empty( $payment_fees ) ) {
1454
-            foreach ( $payment_fees as $fee ) {
1455
-                $fees_total += (float) $fee['amount'];
1452
+        $payment_fees = isset($this->payment_meta['fees']) ? $this->payment_meta['fees'] : array();
1453
+        if (!empty($payment_fees)) {
1454
+            foreach ($payment_fees as $fee) {
1455
+                $fees_total += (float)$fee['amount'];
1456 1456
             }
1457 1457
         }
1458 1458
 
1459
-        return apply_filters( 'wpinv_get_invoice_fees_total', $fees_total, $this->ID, $this );
1459
+        return apply_filters('wpinv_get_invoice_fees_total', $fees_total, $this->ID, $this);
1460 1460
         /*
1461 1461
         $fees = $this->get_fees( $type );
1462 1462
 
@@ -1476,116 +1476,116 @@  discard block
 block discarded – undo
1476 1476
     }
1477 1477
 
1478 1478
     public function get_user_id() {
1479
-        return apply_filters( 'wpinv_user_id', $this->user_id, $this->ID, $this );
1479
+        return apply_filters('wpinv_user_id', $this->user_id, $this->ID, $this);
1480 1480
     }
1481 1481
     
1482 1482
     public function get_first_name() {
1483
-        return apply_filters( 'wpinv_first_name', $this->first_name, $this->ID, $this );
1483
+        return apply_filters('wpinv_first_name', $this->first_name, $this->ID, $this);
1484 1484
     }
1485 1485
     
1486 1486
     public function get_last_name() {
1487
-        return apply_filters( 'wpinv_last_name', $this->last_name, $this->ID, $this );
1487
+        return apply_filters('wpinv_last_name', $this->last_name, $this->ID, $this);
1488 1488
     }
1489 1489
     
1490 1490
     public function get_user_full_name() {
1491
-        return apply_filters( 'wpinv_user_full_name', $this->full_name, $this->ID, $this );
1491
+        return apply_filters('wpinv_user_full_name', $this->full_name, $this->ID, $this);
1492 1492
     }
1493 1493
     
1494 1494
     public function get_user_info() {
1495
-        return apply_filters( 'wpinv_user_info', $this->user_info, $this->ID, $this );
1495
+        return apply_filters('wpinv_user_info', $this->user_info, $this->ID, $this);
1496 1496
     }
1497 1497
     
1498 1498
     public function get_email() {
1499
-        return apply_filters( 'wpinv_user_email', $this->email, $this->ID, $this );
1499
+        return apply_filters('wpinv_user_email', $this->email, $this->ID, $this);
1500 1500
     }
1501 1501
     
1502 1502
     public function get_address() {
1503
-        return apply_filters( 'wpinv_address', $this->address, $this->ID, $this );
1503
+        return apply_filters('wpinv_address', $this->address, $this->ID, $this);
1504 1504
     }
1505 1505
     
1506 1506
     public function get_phone() {
1507
-        return apply_filters( 'wpinv_phone', $this->phone, $this->ID, $this );
1507
+        return apply_filters('wpinv_phone', $this->phone, $this->ID, $this);
1508 1508
     }
1509 1509
     
1510 1510
     public function get_number() {
1511
-        return apply_filters( 'wpinv_number', $this->number, $this->ID, $this );
1511
+        return apply_filters('wpinv_number', $this->number, $this->ID, $this);
1512 1512
     }
1513 1513
     
1514 1514
     public function get_items() {
1515
-        return apply_filters( 'wpinv_payment_meta_items', $this->items, $this->ID, $this );
1515
+        return apply_filters('wpinv_payment_meta_items', $this->items, $this->ID, $this);
1516 1516
     }
1517 1517
     
1518 1518
     public function get_key() {
1519
-        return apply_filters( 'wpinv_key', $this->key, $this->ID, $this );
1519
+        return apply_filters('wpinv_key', $this->key, $this->ID, $this);
1520 1520
     }
1521 1521
     
1522 1522
     public function get_transaction_id() {
1523
-        return apply_filters( 'wpinv_get_invoice_transaction_id', $this->transaction_id, $this->ID, $this );
1523
+        return apply_filters('wpinv_get_invoice_transaction_id', $this->transaction_id, $this->ID, $this);
1524 1524
     }
1525 1525
     
1526 1526
     public function get_gateway() {
1527
-        return apply_filters( 'wpinv_gateway', $this->gateway, $this->ID, $this );
1527
+        return apply_filters('wpinv_gateway', $this->gateway, $this->ID, $this);
1528 1528
     }
1529 1529
     
1530 1530
     public function get_gateway_title() {
1531
-        $this->gateway_title = !empty( $this->gateway_title ) ? $this->gateway_title : wpinv_get_gateway_checkout_label( $this->gateway );
1531
+        $this->gateway_title = !empty($this->gateway_title) ? $this->gateway_title : wpinv_get_gateway_checkout_label($this->gateway);
1532 1532
         
1533
-        return apply_filters( 'wpinv_gateway_title', $this->gateway_title, $this->ID, $this );
1533
+        return apply_filters('wpinv_gateway_title', $this->gateway_title, $this->ID, $this);
1534 1534
     }
1535 1535
     
1536 1536
     public function get_currency() {
1537
-        return apply_filters( 'wpinv_currency_code', $this->currency, $this->ID, $this );
1537
+        return apply_filters('wpinv_currency_code', $this->currency, $this->ID, $this);
1538 1538
     }
1539 1539
     
1540 1540
     public function get_created_date() {
1541
-        return apply_filters( 'wpinv_created_date', $this->date, $this->ID, $this );
1541
+        return apply_filters('wpinv_created_date', $this->date, $this->ID, $this);
1542 1542
     }
1543 1543
     
1544
-    public function get_due_date( $display = false ) {
1545
-        $due_date = apply_filters( 'wpinv_due_date', $this->due_date, $this->ID, $this );
1544
+    public function get_due_date($display = false) {
1545
+        $due_date = apply_filters('wpinv_due_date', $this->due_date, $this->ID, $this);
1546 1546
         
1547
-        if ( !$display || empty( $due_date ) ) {
1547
+        if (!$display || empty($due_date)) {
1548 1548
             return $due_date;
1549 1549
         }
1550 1550
         
1551
-        return date_i18n( get_option( 'date_format' ), strtotime( $due_date ) );
1551
+        return date_i18n(get_option('date_format'), strtotime($due_date));
1552 1552
     }
1553 1553
     
1554 1554
     public function get_completed_date() {
1555
-        return apply_filters( 'wpinv_completed_date', $this->completed_date, $this->ID, $this );
1555
+        return apply_filters('wpinv_completed_date', $this->completed_date, $this->ID, $this);
1556 1556
     }
1557 1557
     
1558
-    public function get_invoice_date( $formatted = true ) {
1558
+    public function get_invoice_date($formatted = true) {
1559 1559
         $date_completed = $this->completed_date;
1560 1560
         $invoice_date   = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? $date_completed : '';
1561 1561
         
1562
-        if ( $invoice_date == '' ) {
1562
+        if ($invoice_date == '') {
1563 1563
             $date_created   = $this->date;
1564 1564
             $invoice_date   = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? $date_created : '';
1565 1565
         }
1566 1566
         
1567
-        if ( $formatted && $invoice_date ) {
1568
-            $invoice_date   = date_i18n( get_option( 'date_format' ), strtotime( $invoice_date ) );
1567
+        if ($formatted && $invoice_date) {
1568
+            $invoice_date = date_i18n(get_option('date_format'), strtotime($invoice_date));
1569 1569
         }
1570 1570
 
1571
-        return apply_filters( 'wpinv_get_invoice_date', $invoice_date, $formatted, $this->ID, $this );
1571
+        return apply_filters('wpinv_get_invoice_date', $invoice_date, $formatted, $this->ID, $this);
1572 1572
     }
1573 1573
     
1574 1574
     public function get_ip() {
1575
-        return apply_filters( 'wpinv_user_ip', $this->ip, $this->ID, $this );
1575
+        return apply_filters('wpinv_user_ip', $this->ip, $this->ID, $this);
1576 1576
     }
1577 1577
         
1578
-    public function has_status( $status ) {
1579
-        return apply_filters( 'wpinv_has_status', ( is_array( $status ) && in_array( $this->get_status(), $status ) ) || $this->get_status() === $status ? true : false, $this, $status );
1578
+    public function has_status($status) {
1579
+        return apply_filters('wpinv_has_status', (is_array($status) && in_array($this->get_status(), $status)) || $this->get_status() === $status ? true : false, $this, $status);
1580 1580
     }
1581 1581
     
1582
-    public function add_item( $item_id = 0, $args = array() ) {
1582
+    public function add_item($item_id = 0, $args = array()) {
1583 1583
         global $wpi_current_id, $wpi_item_id;
1584 1584
         
1585
-        $item = new WPInv_Item( $item_id );
1585
+        $item = new WPInv_Item($item_id);
1586 1586
 
1587 1587
         // Bail if this post isn't a item
1588
-        if( !$item || $item->post_type !== 'wpi_item' ) {
1588
+        if (!$item || $item->post_type !== 'wpi_item') {
1589 1589
             return false;
1590 1590
         }
1591 1591
         
@@ -1604,8 +1604,8 @@  discard block
 block discarded – undo
1604 1604
             'fees'          => array()
1605 1605
         );
1606 1606
 
1607
-        $args = wp_parse_args( apply_filters( 'wpinv_add_item_args', $args, $item->ID ), $defaults );
1608
-        $args['quantity']   = $has_quantities && $args['quantity'] > 0 ? absint( $args['quantity'] ) : 1;
1607
+        $args = wp_parse_args(apply_filters('wpinv_add_item_args', $args, $item->ID), $defaults);
1608
+        $args['quantity'] = $has_quantities && $args['quantity'] > 0 ? absint($args['quantity']) : 1;
1609 1609
 
1610 1610
         $wpi_current_id         = $this->ID;
1611 1611
         $wpi_item_id            = $item->ID;
@@ -1617,19 +1617,19 @@  discard block
 block discarded – undo
1617 1617
         $found_cart_key         = false;
1618 1618
         
1619 1619
         if ($has_quantities) {
1620
-            $this->cart_details = !empty( $this->cart_details ) ? array_values( $this->cart_details ) : $this->cart_details;
1620
+            $this->cart_details = !empty($this->cart_details) ? array_values($this->cart_details) : $this->cart_details;
1621 1621
             
1622
-            foreach ( $this->items as $key => $cart_item ) {
1623
-                if ( (int)$item_id !== (int)$cart_item['id'] ) {
1622
+            foreach ($this->items as $key => $cart_item) {
1623
+                if ((int)$item_id !== (int)$cart_item['id']) {
1624 1624
                     continue;
1625 1625
                 }
1626 1626
 
1627
-                $this->items[ $key ]['quantity'] += $args['quantity'];
1627
+                $this->items[$key]['quantity'] += $args['quantity'];
1628 1628
                 break;
1629 1629
             }
1630 1630
             
1631
-            foreach ( $this->cart_details as $cart_key => $cart_item ) {
1632
-                if ( $item_id != $cart_item['id'] ) {
1631
+            foreach ($this->cart_details as $cart_key => $cart_item) {
1632
+                if ($item_id != $cart_item['id']) {
1633 1633
                     continue;
1634 1634
                 }
1635 1635
 
@@ -1641,29 +1641,29 @@  discard block
 block discarded – undo
1641 1641
         if ($has_quantities && $found_cart_key !== false) {
1642 1642
             $cart_item          = $this->cart_details[$found_cart_key];
1643 1643
             $item_price         = $cart_item['item_price'];
1644
-            $quantity           = !empty( $cart_item['quantity'] ) ? $cart_item['quantity'] : 1;
1645
-            $tax_rate           = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : 0;
1644
+            $quantity           = !empty($cart_item['quantity']) ? $cart_item['quantity'] : 1;
1645
+            $tax_rate           = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : 0;
1646 1646
             
1647 1647
             $new_quantity       = $quantity + $args['quantity'];
1648 1648
             $subtotal           = $item_price * $new_quantity;
1649 1649
             
1650 1650
             $args['quantity']   = $new_quantity;
1651
-            $discount           = !empty( $args['discount'] ) ? $args['discount'] : 0;
1652
-            $tax                = $subtotal > 0 && $tax_rate > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0;
1651
+            $discount           = !empty($args['discount']) ? $args['discount'] : 0;
1652
+            $tax                = $subtotal > 0 && $tax_rate > 0 ? (($subtotal - $discount) * 0.01 * (float)$tax_rate) : 0;
1653 1653
             
1654 1654
             $discount_increased = $discount > 0 && $subtotal > 0 && $discount > (float)$cart_item['discount'] ? $discount - (float)$cart_item['discount'] : 0;
1655 1655
             $tax_increased      = $tax > 0 && $subtotal > 0 && $tax > (float)$cart_item['tax'] ? $tax - (float)$cart_item['tax'] : 0;
1656 1656
             // The total increase equals the number removed * the item_price
1657
-            $total_increased    = wpinv_round_amount( $item_price );
1657
+            $total_increased    = wpinv_round_amount($item_price);
1658 1658
             
1659
-            if ( wpinv_prices_include_tax() ) {
1660
-                $subtotal -= wpinv_round_amount( $tax );
1659
+            if (wpinv_prices_include_tax()) {
1660
+                $subtotal -= wpinv_round_amount($tax);
1661 1661
             }
1662 1662
 
1663
-            $total              = $subtotal - $discount + $tax;
1663
+            $total = $subtotal - $discount + $tax;
1664 1664
 
1665 1665
             // Do not allow totals to go negative
1666
-            if( $total < 0 ) {
1666
+            if ($total < 0) {
1667 1667
                 $total = 0;
1668 1668
             }
1669 1669
             
@@ -1679,25 +1679,25 @@  discard block
 block discarded – undo
1679 1679
             $this->cart_details[$found_cart_key] = $cart_item;
1680 1680
         } else {
1681 1681
             // Set custom price.
1682
-            if ( $args['custom_price'] !== '' ) {
1682
+            if ($args['custom_price'] !== '') {
1683 1683
                 $item_price = $args['custom_price'];
1684 1684
             } else {
1685 1685
                 // Allow overriding the price
1686
-                if ( false !== $args['item_price'] ) {
1686
+                if (false !== $args['item_price']) {
1687 1687
                     $item_price = $args['item_price'];
1688 1688
                 } else {
1689
-                    $item_price = wpinv_get_item_price( $item->ID );
1689
+                    $item_price = wpinv_get_item_price($item->ID);
1690 1690
                 }
1691 1691
             }
1692 1692
 
1693 1693
             // Sanitizing the price here so we don't have a dozen calls later
1694
-            $item_price = wpinv_sanitize_amount( $item_price );
1695
-            $subtotal   = wpinv_round_amount( $item_price * $args['quantity'] );
1694
+            $item_price = wpinv_sanitize_amount($item_price);
1695
+            $subtotal   = wpinv_round_amount($item_price * $args['quantity']);
1696 1696
         
1697
-            $discount   = !empty( $args['discount'] ) ? $args['discount'] : 0;
1698
-            $tax_class  = !empty( $args['vat_class'] ) ? $args['vat_class'] : '';
1699
-            $tax_rate   = !empty( $args['vat_rate'] ) ? $args['vat_rate'] : 0;
1700
-            $tax        = $subtotal > 0 && $tax_rate > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0;
1697
+            $discount   = !empty($args['discount']) ? $args['discount'] : 0;
1698
+            $tax_class  = !empty($args['vat_class']) ? $args['vat_class'] : '';
1699
+            $tax_rate   = !empty($args['vat_rate']) ? $args['vat_rate'] : 0;
1700
+            $tax        = $subtotal > 0 && $tax_rate > 0 ? (($subtotal - $discount) * 0.01 * (float)$tax_rate) : 0;
1701 1701
 
1702 1702
             // Setup the items meta item
1703 1703
             $new_item = array(
@@ -1705,29 +1705,29 @@  discard block
 block discarded – undo
1705 1705
                 'quantity' => $args['quantity'],
1706 1706
             );
1707 1707
 
1708
-            $this->items[]  = $new_item;
1708
+            $this->items[] = $new_item;
1709 1709
 
1710
-            if ( wpinv_prices_include_tax() ) {
1711
-                $subtotal -= wpinv_round_amount( $tax );
1710
+            if (wpinv_prices_include_tax()) {
1711
+                $subtotal -= wpinv_round_amount($tax);
1712 1712
             }
1713 1713
 
1714
-            $total      = $subtotal - $discount + $tax;
1714
+            $total = $subtotal - $discount + $tax;
1715 1715
 
1716 1716
             // Do not allow totals to go negative
1717
-            if( $total < 0 ) {
1717
+            if ($total < 0) {
1718 1718
                 $total = 0;
1719 1719
             }
1720 1720
         
1721 1721
             $this->cart_details[] = array(
1722 1722
                 'name'          => !empty($args['name']) ? $args['name'] : $item->get_name(),
1723 1723
                 'id'            => $item->ID,
1724
-                'item_price'    => wpinv_round_amount( $item_price ),
1725
-                'custom_price'  => ( $args['custom_price'] !== '' ? wpinv_round_amount( $args['custom_price'] ) : '' ),
1724
+                'item_price'    => wpinv_round_amount($item_price),
1725
+                'custom_price'  => ($args['custom_price'] !== '' ? wpinv_round_amount($args['custom_price']) : ''),
1726 1726
                 'quantity'      => $args['quantity'],
1727 1727
                 'discount'      => $discount,
1728
-                'subtotal'      => wpinv_round_amount( $subtotal ),
1729
-                'tax'           => wpinv_round_amount( $tax ),
1730
-                'price'         => wpinv_round_amount( $total ),
1728
+                'subtotal'      => wpinv_round_amount($subtotal),
1729
+                'tax'           => wpinv_round_amount($tax),
1730
+                'price'         => wpinv_round_amount($total),
1731 1731
                 'vat_rate'      => $tax_rate,
1732 1732
                 'vat_class'     => $tax_class,
1733 1733
                 'meta'          => $args['meta'],
@@ -1737,18 +1737,18 @@  discard block
 block discarded – undo
1737 1737
             $subtotal = $subtotal - $discount;
1738 1738
         }
1739 1739
         
1740
-        $added_item = end( $this->cart_details );
1741
-        $added_item['action']  = 'add';
1740
+        $added_item = end($this->cart_details);
1741
+        $added_item['action'] = 'add';
1742 1742
         
1743 1743
         $this->pending['items'][] = $added_item;
1744 1744
         
1745
-        $this->increase_subtotal( $subtotal );
1746
-        $this->increase_tax( $tax );
1745
+        $this->increase_subtotal($subtotal);
1746
+        $this->increase_tax($tax);
1747 1747
 
1748 1748
         return true;
1749 1749
     }
1750 1750
     
1751
-    public function remove_item( $item_id, $args = array() ) {
1751
+    public function remove_item($item_id, $args = array()) {
1752 1752
         // Set some defaults
1753 1753
         $defaults = array(
1754 1754
             'quantity'      => 1,
@@ -1756,51 +1756,51 @@  discard block
 block discarded – undo
1756 1756
             'custom_price'  => '',
1757 1757
             'cart_index'    => false,
1758 1758
         );
1759
-        $args = wp_parse_args( $args, $defaults );
1759
+        $args = wp_parse_args($args, $defaults);
1760 1760
 
1761 1761
         // Bail if this post isn't a item
1762
-        if ( get_post_type( $item_id ) !== 'wpi_item' ) {
1762
+        if (get_post_type($item_id) !== 'wpi_item') {
1763 1763
             return false;
1764 1764
         }
1765 1765
         
1766
-        $this->cart_details = !empty( $this->cart_details ) ? array_values( $this->cart_details ) : $this->cart_details;
1766
+        $this->cart_details = !empty($this->cart_details) ? array_values($this->cart_details) : $this->cart_details;
1767 1767
 
1768
-        foreach ( $this->items as $key => $item ) {
1769
-            if ( !empty($item['id']) && (int)$item_id !== (int)$item['id'] ) {
1768
+        foreach ($this->items as $key => $item) {
1769
+            if (!empty($item['id']) && (int)$item_id !== (int)$item['id']) {
1770 1770
                 continue;
1771 1771
             }
1772 1772
 
1773
-            if ( false !== $args['cart_index'] ) {
1774
-                $cart_index = absint( $args['cart_index'] );
1775
-                $cart_item  = ! empty( $this->cart_details[ $cart_index ] ) ? $this->cart_details[ $cart_index ] : false;
1773
+            if (false !== $args['cart_index']) {
1774
+                $cart_index = absint($args['cart_index']);
1775
+                $cart_item  = !empty($this->cart_details[$cart_index]) ? $this->cart_details[$cart_index] : false;
1776 1776
 
1777
-                if ( ! empty( $cart_item ) ) {
1777
+                if (!empty($cart_item)) {
1778 1778
                     // If the cart index item isn't the same item ID, don't remove it
1779
-                    if ( !empty($cart_item['id']) && $cart_item['id'] != $item['id'] ) {
1779
+                    if (!empty($cart_item['id']) && $cart_item['id'] != $item['id']) {
1780 1780
                         continue;
1781 1781
                     }
1782 1782
                 }
1783 1783
             }
1784 1784
 
1785
-            $item_quantity = $this->items[ $key ]['quantity'];
1786
-            if ( $item_quantity > $args['quantity'] ) {
1787
-                $this->items[ $key ]['quantity'] -= $args['quantity'];
1785
+            $item_quantity = $this->items[$key]['quantity'];
1786
+            if ($item_quantity > $args['quantity']) {
1787
+                $this->items[$key]['quantity'] -= $args['quantity'];
1788 1788
                 break;
1789 1789
             } else {
1790
-                unset( $this->items[ $key ] );
1790
+                unset($this->items[$key]);
1791 1791
                 break;
1792 1792
             }
1793 1793
         }
1794 1794
 
1795 1795
         $found_cart_key = false;
1796
-        if ( false === $args['cart_index'] ) {
1797
-            foreach ( $this->cart_details as $cart_key => $item ) {
1798
-                if ( $item_id != $item['id'] ) {
1796
+        if (false === $args['cart_index']) {
1797
+            foreach ($this->cart_details as $cart_key => $item) {
1798
+                if ($item_id != $item['id']) {
1799 1799
                     continue;
1800 1800
                 }
1801 1801
 
1802
-                if ( false !== $args['item_price'] ) {
1803
-                    if ( isset( $item['item_price'] ) && (float) $args['item_price'] != (float) $item['item_price'] ) {
1802
+                if (false !== $args['item_price']) {
1803
+                    if (isset($item['item_price']) && (float)$args['item_price'] != (float)$item['item_price']) {
1804 1804
                         continue;
1805 1805
                     }
1806 1806
                 }
@@ -1809,13 +1809,13 @@  discard block
 block discarded – undo
1809 1809
                 break;
1810 1810
             }
1811 1811
         } else {
1812
-            $cart_index = absint( $args['cart_index'] );
1812
+            $cart_index = absint($args['cart_index']);
1813 1813
 
1814
-            if ( ! array_key_exists( $cart_index, $this->cart_details ) ) {
1814
+            if (!array_key_exists($cart_index, $this->cart_details)) {
1815 1815
                 return false; // Invalid cart index passed.
1816 1816
             }
1817 1817
 
1818
-            if ( (int) $this->cart_details[ $cart_index ]['id'] > 0 && (int) $this->cart_details[ $cart_index ]['id'] !== (int) $item_id ) {
1818
+            if ((int)$this->cart_details[$cart_index]['id'] > 0 && (int)$this->cart_details[$cart_index]['id'] !== (int)$item_id) {
1819 1819
                 return false; // We still need the proper Item ID to be sure.
1820 1820
             }
1821 1821
 
@@ -1823,41 +1823,41 @@  discard block
 block discarded – undo
1823 1823
         }
1824 1824
         
1825 1825
         $cart_item  = $this->cart_details[$found_cart_key];
1826
-        $quantity   = !empty( $cart_item['quantity'] ) ? $cart_item['quantity'] : 1;
1826
+        $quantity   = !empty($cart_item['quantity']) ? $cart_item['quantity'] : 1;
1827 1827
         
1828
-        if ( count( $this->cart_details ) == 1 && ( $quantity - $args['quantity'] ) < 1 ) {
1828
+        if (count($this->cart_details) == 1 && ($quantity - $args['quantity']) < 1) {
1829 1829
             return false; // Invoice must contain at least one item.
1830 1830
         }
1831 1831
         
1832
-        $discounts  = $this->get_discounts();
1832
+        $discounts = $this->get_discounts();
1833 1833
         
1834
-        if ( $quantity > $args['quantity'] ) {
1834
+        if ($quantity > $args['quantity']) {
1835 1835
             $item_price         = $cart_item['item_price'];
1836
-            $tax_rate           = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : 0;
1836
+            $tax_rate           = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : 0;
1837 1837
             
1838
-            $new_quantity       = max( $quantity - $args['quantity'], 1);
1838
+            $new_quantity       = max($quantity - $args['quantity'], 1);
1839 1839
             $subtotal           = $item_price * $new_quantity;
1840 1840
             
1841 1841
             $args['quantity']   = $new_quantity;
1842
-            $discount           = !empty( $cart_item['discount'] ) ? $cart_item['discount'] : 0;
1843
-            $tax                = $subtotal > 0 && $tax_rate > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0;
1842
+            $discount           = !empty($cart_item['discount']) ? $cart_item['discount'] : 0;
1843
+            $tax                = $subtotal > 0 && $tax_rate > 0 ? (($subtotal - $discount) * 0.01 * (float)$tax_rate) : 0;
1844 1844
             
1845
-            $discount_decrease  = (float)$cart_item['discount'] > 0 && $quantity > 0 ? wpinv_round_amount( ( (float)$cart_item['discount'] / $quantity ) ) : 0;
1845
+            $discount_decrease  = (float)$cart_item['discount'] > 0 && $quantity > 0 ? wpinv_round_amount(((float)$cart_item['discount'] / $quantity)) : 0;
1846 1846
             $discount_decrease  = $discount > 0 && $subtotal > 0 && (float)$cart_item['discount'] > $discount ? (float)$cart_item['discount'] - $discount : $discount_decrease; 
1847
-            $tax_decrease       = (float)$cart_item['tax'] > 0 && $quantity > 0 ? wpinv_round_amount( ( (float)$cart_item['tax'] / $quantity ) ) : 0;
1847
+            $tax_decrease       = (float)$cart_item['tax'] > 0 && $quantity > 0 ? wpinv_round_amount(((float)$cart_item['tax'] / $quantity)) : 0;
1848 1848
             $tax_decrease       = $tax > 0 && $subtotal > 0 && (float)$cart_item['tax'] > $tax ? (float)$cart_item['tax'] - $tax : $tax_decrease;
1849 1849
             
1850 1850
             // The total increase equals the number removed * the item_price
1851
-            $total_decrease     = wpinv_round_amount( $item_price );
1851
+            $total_decrease     = wpinv_round_amount($item_price);
1852 1852
             
1853
-            if ( wpinv_prices_include_tax() ) {
1854
-                $subtotal -= wpinv_round_amount( $tax );
1853
+            if (wpinv_prices_include_tax()) {
1854
+                $subtotal -= wpinv_round_amount($tax);
1855 1855
             }
1856 1856
 
1857
-            $total              = $subtotal - $discount + $tax;
1857
+            $total = $subtotal - $discount + $tax;
1858 1858
 
1859 1859
             // Do not allow totals to go negative
1860
-            if( $total < 0 ) {
1860
+            if ($total < 0) {
1861 1861
                 $total = 0;
1862 1862
             }
1863 1863
             
@@ -1876,16 +1876,16 @@  discard block
 block discarded – undo
1876 1876
             
1877 1877
             $this->cart_details[$found_cart_key] = $cart_item;
1878 1878
             
1879
-            $remove_item = end( $this->cart_details );
1879
+            $remove_item = end($this->cart_details);
1880 1880
         } else {
1881 1881
             $item_price     = $cart_item['item_price'];
1882
-            $discount       = !empty( $cart_item['discount'] ) ? $cart_item['discount'] : 0;
1883
-            $tax            = !empty( $cart_item['tax'] ) ? $cart_item['tax'] : 0;
1882
+            $discount       = !empty($cart_item['discount']) ? $cart_item['discount'] : 0;
1883
+            $tax            = !empty($cart_item['tax']) ? $cart_item['tax'] : 0;
1884 1884
         
1885
-            $subtotal_decrease  = ( $item_price * $quantity ) - $discount;
1885
+            $subtotal_decrease  = ($item_price * $quantity) - $discount;
1886 1886
             $tax_decrease       = $tax;
1887 1887
 
1888
-            unset( $this->cart_details[$found_cart_key] );
1888
+            unset($this->cart_details[$found_cart_key]);
1889 1889
             
1890 1890
             $remove_item             = $args;
1891 1891
             $remove_item['id']       = $item_id;
@@ -1896,8 +1896,8 @@  discard block
 block discarded – undo
1896 1896
         $remove_item['action']      = 'remove';
1897 1897
         $this->pending['items'][]   = $remove_item;
1898 1898
                
1899
-        $this->decrease_subtotal( $subtotal_decrease );
1900
-        $this->decrease_tax( $tax_decrease );
1899
+        $this->decrease_subtotal($subtotal_decrease);
1900
+        $this->decrease_tax($tax_decrease);
1901 1901
         
1902 1902
         return true;
1903 1903
     }
@@ -1905,7 +1905,7 @@  discard block
 block discarded – undo
1905 1905
     public function update_items($temp = false) {
1906 1906
         global $wpinv_euvat, $wpi_current_id, $wpi_item_id, $wpi_nosave;
1907 1907
         
1908
-        if ( !empty( $this->cart_details ) ) {
1908
+        if (!empty($this->cart_details)) {
1909 1909
             $wpi_nosave             = $temp;
1910 1910
             $cart_subtotal          = 0;
1911 1911
             $cart_discount          = 0;
@@ -1915,42 +1915,42 @@  discard block
 block discarded – undo
1915 1915
             $_POST['wpinv_country'] = $this->country;
1916 1916
             $_POST['wpinv_state']   = $this->state;
1917 1917
             
1918
-            foreach ( $this->cart_details as $key => $item ) {
1918
+            foreach ($this->cart_details as $key => $item) {
1919 1919
                 $item_price = $item['item_price'];
1920
-                $quantity   = wpinv_item_quantities_enabled() && $item['quantity'] > 0 ? absint( $item['quantity'] ) : 1;
1921
-                $amount     = wpinv_round_amount( $item_price * $quantity );
1920
+                $quantity   = wpinv_item_quantities_enabled() && $item['quantity'] > 0 ? absint($item['quantity']) : 1;
1921
+                $amount     = wpinv_round_amount($item_price * $quantity);
1922 1922
                 $subtotal   = $item_price * $quantity;
1923 1923
                 
1924 1924
                 $wpi_current_id         = $this->ID;
1925 1925
                 $wpi_item_id            = $item['id'];
1926 1926
                 
1927
-                $discount   = wpinv_get_cart_item_discount_amount( $item, $this->get_discounts() );
1927
+                $discount   = wpinv_get_cart_item_discount_amount($item, $this->get_discounts());
1928 1928
                 
1929
-                $tax_rate   = wpinv_get_tax_rate( $this->country, $this->state, $wpi_item_id );
1930
-                $tax_class  = $wpinv_euvat->get_item_class( $wpi_item_id );
1931
-                $tax        = $item_price > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0;
1929
+                $tax_rate   = wpinv_get_tax_rate($this->country, $this->state, $wpi_item_id);
1930
+                $tax_class  = $wpinv_euvat->get_item_class($wpi_item_id);
1931
+                $tax        = $item_price > 0 ? (($subtotal - $discount) * 0.01 * (float)$tax_rate) : 0;
1932 1932
 
1933
-                if ( wpinv_prices_include_tax() ) {
1934
-                    $subtotal -= wpinv_round_amount( $tax );
1933
+                if (wpinv_prices_include_tax()) {
1934
+                    $subtotal -= wpinv_round_amount($tax);
1935 1935
                 }
1936 1936
 
1937
-                $total      = $subtotal - $discount + $tax;
1937
+                $total = $subtotal - $discount + $tax;
1938 1938
 
1939 1939
                 // Do not allow totals to go negative
1940
-                if( $total < 0 ) {
1940
+                if ($total < 0) {
1941 1941
                     $total = 0;
1942 1942
                 }
1943 1943
 
1944 1944
                 $cart_details[] = array(
1945 1945
                     'id'          => $item['id'],
1946 1946
                     'name'        => $item['name'],
1947
-                    'item_price'  => wpinv_round_amount( $item_price ),
1948
-                    'custom_price'=> ( isset( $item['custom_price'] ) ? $item['custom_price'] : '' ),
1947
+                    'item_price'  => wpinv_round_amount($item_price),
1948
+                    'custom_price'=> (isset($item['custom_price']) ? $item['custom_price'] : ''),
1949 1949
                     'quantity'    => $quantity,
1950 1950
                     'discount'    => $discount,
1951
-                    'subtotal'    => wpinv_round_amount( $subtotal ),
1952
-                    'tax'         => wpinv_round_amount( $tax ),
1953
-                    'price'       => wpinv_round_amount( $total ),
1951
+                    'subtotal'    => wpinv_round_amount($subtotal),
1952
+                    'tax'         => wpinv_round_amount($tax),
1953
+                    'price'       => wpinv_round_amount($total),
1954 1954
                     'vat_rate'    => $tax_rate,
1955 1955
                     'vat_class'   => $tax_class,
1956 1956
                     'meta'        => isset($item['meta']) ? $item['meta'] : array(),
@@ -1961,15 +1961,15 @@  discard block
 block discarded – undo
1961 1961
                 $cart_discount  += (float)($discount);
1962 1962
                 $cart_tax       += (float)($tax);
1963 1963
             }
1964
-            if ( $cart_subtotal < 0 ) {
1964
+            if ($cart_subtotal < 0) {
1965 1965
                 $cart_subtotal = 0;
1966 1966
             }
1967
-            if ( $cart_tax < 0 ) {
1967
+            if ($cart_tax < 0) {
1968 1968
                 $cart_tax = 0;
1969 1969
             }
1970
-            $this->subtotal = wpinv_round_amount( $cart_subtotal );
1971
-            $this->tax      = wpinv_round_amount( $cart_tax );
1972
-            $this->discount = wpinv_round_amount( $cart_discount );
1970
+            $this->subtotal = wpinv_round_amount($cart_subtotal);
1971
+            $this->tax      = wpinv_round_amount($cart_tax);
1972
+            $this->discount = wpinv_round_amount($cart_discount);
1973 1973
             
1974 1974
             $this->recalculate_total();
1975 1975
             
@@ -1981,197 +1981,197 @@  discard block
 block discarded – undo
1981 1981
     
1982 1982
     public function recalculate_totals($temp = false) {        
1983 1983
         $this->update_items($temp);
1984
-        $this->save( true );
1984
+        $this->save(true);
1985 1985
         
1986 1986
         return $this;
1987 1987
     }
1988 1988
     
1989 1989
     public function needs_payment() {
1990
-        $valid_invoice_statuses = apply_filters( 'wpinv_valid_invoice_statuses_for_payment', array( 'wpi-pending' ), $this );
1990
+        $valid_invoice_statuses = apply_filters('wpinv_valid_invoice_statuses_for_payment', array('wpi-pending'), $this);
1991 1991
 
1992
-        if ( $this->has_status( $valid_invoice_statuses ) && ( $this->get_total() > 0 || $this->is_free_trial() || $this->is_free() || $this->is_initial_free() ) ) {
1992
+        if ($this->has_status($valid_invoice_statuses) && ($this->get_total() > 0 || $this->is_free_trial() || $this->is_free() || $this->is_initial_free())) {
1993 1993
             $needs_payment = true;
1994 1994
         } else {
1995 1995
             $needs_payment = false;
1996 1996
         }
1997 1997
 
1998
-        return apply_filters( 'wpinv_needs_payment', $needs_payment, $this, $valid_invoice_statuses );
1998
+        return apply_filters('wpinv_needs_payment', $needs_payment, $this, $valid_invoice_statuses);
1999 1999
     }
2000 2000
     
2001
-    public function get_checkout_payment_url( $with_key = false, $secret = false ) {
2001
+    public function get_checkout_payment_url($with_key = false, $secret = false) {
2002 2002
         $pay_url = wpinv_get_checkout_uri();
2003 2003
 
2004
-        if ( is_ssl() ) {
2005
-            $pay_url = str_replace( 'http:', 'https:', $pay_url );
2004
+        if (is_ssl()) {
2005
+            $pay_url = str_replace('http:', 'https:', $pay_url);
2006 2006
         }
2007 2007
         
2008 2008
         $key = $this->get_key();
2009 2009
 
2010
-        if ( $with_key ) {
2011
-            $pay_url = add_query_arg( 'invoice_key', $key, $pay_url );
2010
+        if ($with_key) {
2011
+            $pay_url = add_query_arg('invoice_key', $key, $pay_url);
2012 2012
         } else {
2013
-            $pay_url = add_query_arg( array( 'wpi_action' => 'pay_for_invoice', 'invoice_key' => $key ), $pay_url );
2013
+            $pay_url = add_query_arg(array('wpi_action' => 'pay_for_invoice', 'invoice_key' => $key), $pay_url);
2014 2014
         }
2015 2015
         
2016
-        if ( $secret ) {
2017
-            $pay_url = add_query_arg( array( '_wpipay' => md5( $this->get_user_id() . '::' . $this->get_email() . '::' . $key ) ), $pay_url );
2016
+        if ($secret) {
2017
+            $pay_url = add_query_arg(array('_wpipay' => md5($this->get_user_id() . '::' . $this->get_email() . '::' . $key)), $pay_url);
2018 2018
         }
2019 2019
 
2020
-        return apply_filters( 'wpinv_get_checkout_payment_url', $pay_url, $this, $with_key, $secret );
2020
+        return apply_filters('wpinv_get_checkout_payment_url', $pay_url, $this, $with_key, $secret);
2021 2021
     }
2022 2022
     
2023
-    public function get_view_url( $with_key = false ) {
2024
-        $invoice_url = get_permalink( $this->ID );
2023
+    public function get_view_url($with_key = false) {
2024
+        $invoice_url = get_permalink($this->ID);
2025 2025
 
2026
-        if ( $with_key ) {
2027
-            $invoice_url = add_query_arg( 'invoice_key', $this->get_key(), $invoice_url );
2026
+        if ($with_key) {
2027
+            $invoice_url = add_query_arg('invoice_key', $this->get_key(), $invoice_url);
2028 2028
         }
2029 2029
 
2030
-        return apply_filters( 'wpinv_get_view_url', $invoice_url, $this, $with_key );
2030
+        return apply_filters('wpinv_get_view_url', $invoice_url, $this, $with_key);
2031 2031
     }
2032 2032
     
2033
-    public function generate_key( $string = '' ) {
2034
-        $auth_key  = defined( 'AUTH_KEY' ) ? AUTH_KEY : '';
2035
-        return strtolower( md5( $string . date( 'Y-m-d H:i:s' ) . $auth_key . uniqid( 'wpinv', true ) ) );  // Unique key
2033
+    public function generate_key($string = '') {
2034
+        $auth_key = defined('AUTH_KEY') ? AUTH_KEY : '';
2035
+        return strtolower(md5($string . date('Y-m-d H:i:s') . $auth_key . uniqid('wpinv', true))); // Unique key
2036 2036
     }
2037 2037
     
2038 2038
     public function is_recurring() {
2039
-        if ( empty( $this->cart_details ) ) {
2039
+        if (empty($this->cart_details)) {
2040 2040
             return false;
2041 2041
         }
2042 2042
         
2043 2043
         $has_subscription = false;
2044
-        foreach( $this->cart_details as $cart_item ) {
2045
-            if ( !empty( $cart_item['id'] ) && wpinv_is_recurring_item( $cart_item['id'] )  ) {
2044
+        foreach ($this->cart_details as $cart_item) {
2045
+            if (!empty($cart_item['id']) && wpinv_is_recurring_item($cart_item['id'])) {
2046 2046
                 $has_subscription = true;
2047 2047
                 break;
2048 2048
             }
2049 2049
         }
2050 2050
         
2051
-        if ( count( $this->cart_details ) > 1 ) {
2051
+        if (count($this->cart_details) > 1) {
2052 2052
             $has_subscription = false;
2053 2053
         }
2054 2054
 
2055
-        return apply_filters( 'wpinv_invoice_has_recurring_item', $has_subscription, $this->cart_details );
2055
+        return apply_filters('wpinv_invoice_has_recurring_item', $has_subscription, $this->cart_details);
2056 2056
     }
2057 2057
     
2058 2058
     public function is_free_trial() {
2059 2059
         $is_free_trial = false;
2060 2060
         
2061
-        if ( $this->is_parent() && $item = $this->get_recurring( true ) ) {
2062
-            if ( !empty( $item ) && $item->has_free_trial() ) {
2061
+        if ($this->is_parent() && $item = $this->get_recurring(true)) {
2062
+            if (!empty($item) && $item->has_free_trial()) {
2063 2063
                 $is_free_trial = true;
2064 2064
             }
2065 2065
         }
2066 2066
 
2067
-        return apply_filters( 'wpinv_invoice_is_free_trial', $is_free_trial, $this->cart_details );
2067
+        return apply_filters('wpinv_invoice_is_free_trial', $is_free_trial, $this->cart_details);
2068 2068
     }
2069 2069
     
2070 2070
     public function is_initial_free() {
2071 2071
         $is_initial_free = false;
2072 2072
         
2073
-        if ( ! ( (float)wpinv_round_amount( $this->get_total() ) > 0 ) && $this->is_parent() && $this->is_recurring() && ! $this->is_free_trial() && ! $this->is_free() ) {
2073
+        if (!((float)wpinv_round_amount($this->get_total()) > 0) && $this->is_parent() && $this->is_recurring() && !$this->is_free_trial() && !$this->is_free()) {
2074 2074
             $is_initial_free = true;
2075 2075
         }
2076 2076
 
2077
-        return apply_filters( 'wpinv_invoice_is_initial_free', $is_initial_free, $this->cart_details );
2077
+        return apply_filters('wpinv_invoice_is_initial_free', $is_initial_free, $this->cart_details);
2078 2078
     }
2079 2079
     
2080
-    public function get_recurring( $object = false ) {
2080
+    public function get_recurring($object = false) {
2081 2081
         $item = NULL;
2082 2082
         
2083
-        if ( empty( $this->cart_details ) ) {
2083
+        if (empty($this->cart_details)) {
2084 2084
             return $item;
2085 2085
         }
2086 2086
         
2087
-        foreach( $this->cart_details as $cart_item ) {
2088
-            if ( !empty( $cart_item['id'] ) && wpinv_is_recurring_item( $cart_item['id'] )  ) {
2087
+        foreach ($this->cart_details as $cart_item) {
2088
+            if (!empty($cart_item['id']) && wpinv_is_recurring_item($cart_item['id'])) {
2089 2089
                 $item = $cart_item['id'];
2090 2090
                 break;
2091 2091
             }
2092 2092
         }
2093 2093
         
2094
-        if ( $object ) {
2095
-            $item = $item ? new WPInv_Item( $item ) : NULL;
2094
+        if ($object) {
2095
+            $item = $item ? new WPInv_Item($item) : NULL;
2096 2096
             
2097
-            apply_filters( 'wpinv_invoice_get_recurring_item', $item, $this );
2097
+            apply_filters('wpinv_invoice_get_recurring_item', $item, $this);
2098 2098
         }
2099 2099
 
2100
-        return apply_filters( 'wpinv_invoice_get_recurring_item_id', $item, $this );
2100
+        return apply_filters('wpinv_invoice_get_recurring_item_id', $item, $this);
2101 2101
     }
2102 2102
     
2103 2103
     public function get_subscription_name() {
2104
-        $item = $this->get_recurring( true );
2104
+        $item = $this->get_recurring(true);
2105 2105
         
2106
-        if ( empty( $item ) ) {
2106
+        if (empty($item)) {
2107 2107
             return NULL;
2108 2108
         }
2109 2109
         
2110
-        if ( !($name = $item->get_name()) ) {
2110
+        if (!($name = $item->get_name())) {
2111 2111
             $name = $item->post_name;
2112 2112
         }
2113 2113
 
2114
-        return apply_filters( 'wpinv_invoice_get_subscription_name', $name, $this );
2114
+        return apply_filters('wpinv_invoice_get_subscription_name', $name, $this);
2115 2115
     }
2116 2116
     
2117 2117
     public function get_subscription_id() {
2118
-        $subscription_id = $this->get_meta( '_wpinv_subscr_profile_id', true );
2118
+        $subscription_id = $this->get_meta('_wpinv_subscr_profile_id', true);
2119 2119
         
2120
-        if ( empty( $subscription_id ) && !empty( $this->parent_invoice ) ) {
2121
-            $parent_invoice = wpinv_get_invoice( $this->parent_invoice );
2120
+        if (empty($subscription_id) && !empty($this->parent_invoice)) {
2121
+            $parent_invoice = wpinv_get_invoice($this->parent_invoice);
2122 2122
             
2123
-            $subscription_id = $parent_invoice->get_meta( '_wpinv_subscr_profile_id', true );
2123
+            $subscription_id = $parent_invoice->get_meta('_wpinv_subscr_profile_id', true);
2124 2124
         }
2125 2125
         
2126 2126
         return $subscription_id;
2127 2127
     }
2128 2128
     
2129 2129
     public function is_parent() {
2130
-        $is_parent = empty( $this->parent_invoice ) ? true : false;
2130
+        $is_parent = empty($this->parent_invoice) ? true : false;
2131 2131
 
2132
-        return apply_filters( 'wpinv_invoice_is_parent', $is_parent, $this );
2132
+        return apply_filters('wpinv_invoice_is_parent', $is_parent, $this);
2133 2133
     }
2134 2134
     
2135 2135
     public function is_renewal() {
2136 2136
         $is_renewal = $this->parent_invoice && $this->parent_invoice != $this->ID ? true : false;
2137 2137
 
2138
-        return apply_filters( 'wpinv_invoice_is_renewal', $is_renewal, $this );
2138
+        return apply_filters('wpinv_invoice_is_renewal', $is_renewal, $this);
2139 2139
     }
2140 2140
     
2141 2141
     public function get_parent_payment() {
2142 2142
         $parent_payment = NULL;
2143 2143
         
2144
-        if ( $this->is_renewal() ) {
2145
-            $parent_payment = wpinv_get_invoice( $this->parent_invoice );
2144
+        if ($this->is_renewal()) {
2145
+            $parent_payment = wpinv_get_invoice($this->parent_invoice);
2146 2146
         }
2147 2147
         
2148 2148
         return $parent_payment;
2149 2149
     }
2150 2150
     
2151 2151
     public function is_paid() {
2152
-        $is_paid = $this->has_status( array( 'publish', 'wpi-processing', 'wpi-renewal' ) );
2152
+        $is_paid = $this->has_status(array('publish', 'wpi-processing', 'wpi-renewal'));
2153 2153
 
2154
-        return apply_filters( 'wpinv_invoice_is_paid', $is_paid, $this );
2154
+        return apply_filters('wpinv_invoice_is_paid', $is_paid, $this);
2155 2155
     }
2156 2156
     
2157 2157
     public function is_refunded() {
2158
-        $is_refunded = $this->has_status( array( 'wpi-refunded' ) );
2158
+        $is_refunded = $this->has_status(array('wpi-refunded'));
2159 2159
 
2160
-        return apply_filters( 'wpinv_invoice_is_refunded', $is_refunded, $this );
2160
+        return apply_filters('wpinv_invoice_is_refunded', $is_refunded, $this);
2161 2161
     }
2162 2162
     
2163 2163
     public function is_free() {
2164 2164
         $is_free = false;
2165 2165
         
2166
-        if ( !( (float)wpinv_round_amount( $this->get_total() ) > 0 ) ) {
2167
-            if ( $this->is_parent() && $this->is_recurring() ) {
2168
-                $is_free = (float)wpinv_round_amount( $this->get_recurring_details( 'total' ) ) > 0 ? false : true;
2166
+        if (!((float)wpinv_round_amount($this->get_total()) > 0)) {
2167
+            if ($this->is_parent() && $this->is_recurring()) {
2168
+                $is_free = (float)wpinv_round_amount($this->get_recurring_details('total')) > 0 ? false : true;
2169 2169
             } else {
2170 2170
                 $is_free = true;
2171 2171
             }
2172 2172
         }
2173 2173
         
2174
-        return apply_filters( 'wpinv_invoice_is_free', $is_free, $this );
2174
+        return apply_filters('wpinv_invoice_is_free', $is_free, $this);
2175 2175
     }
2176 2176
     
2177 2177
     public function has_vat() {
@@ -2179,41 +2179,41 @@  discard block
 block discarded – undo
2179 2179
         
2180 2180
         $requires_vat = false;
2181 2181
         
2182
-        if ( $this->country ) {
2182
+        if ($this->country) {
2183 2183
             $wpi_country        = $this->country;
2184 2184
             
2185
-            $requires_vat       = $wpinv_euvat->requires_vat( $requires_vat, $this->get_user_id(), $wpinv_euvat->invoice_has_digital_rule( $this ) );
2185
+            $requires_vat       = $wpinv_euvat->requires_vat($requires_vat, $this->get_user_id(), $wpinv_euvat->invoice_has_digital_rule($this));
2186 2186
         }
2187 2187
         
2188
-        return apply_filters( 'wpinv_invoice_has_vat', $requires_vat, $this );
2188
+        return apply_filters('wpinv_invoice_has_vat', $requires_vat, $this);
2189 2189
     }
2190 2190
     
2191 2191
     public function refresh_item_ids() {
2192 2192
         $item_ids = array();
2193 2193
         
2194
-        if ( !empty( $this->cart_details ) ) {
2195
-            foreach ( $this->cart_details as $key => $item ) {
2196
-                if ( !empty( $item['id'] ) ) {
2194
+        if (!empty($this->cart_details)) {
2195
+            foreach ($this->cart_details as $key => $item) {
2196
+                if (!empty($item['id'])) {
2197 2197
                     $item_ids[] = $item['id'];
2198 2198
                 }
2199 2199
             }
2200 2200
         }
2201 2201
         
2202
-        $item_ids = !empty( $item_ids ) ? implode( ',', array_unique( $item_ids ) ) : '';
2202
+        $item_ids = !empty($item_ids) ? implode(',', array_unique($item_ids)) : '';
2203 2203
         
2204
-        update_post_meta( $this->ID, '_wpinv_item_ids', $item_ids );
2204
+        update_post_meta($this->ID, '_wpinv_item_ids', $item_ids);
2205 2205
     }
2206 2206
     
2207
-    public function get_invoice_quote_type( $post_id ) {
2208
-        if ( empty( $post_id ) ) {
2207
+    public function get_invoice_quote_type($post_id) {
2208
+        if (empty($post_id)) {
2209 2209
             return '';
2210 2210
         }
2211 2211
 
2212
-        $type = get_post_type( $post_id );
2212
+        $type = get_post_type($post_id);
2213 2213
 
2214
-        if ( 'wpi_invoice' === $type ) {
2214
+        if ('wpi_invoice' === $type) {
2215 2215
             $post_type = __('Invoice', 'invoicing');
2216
-        } else{
2216
+        } else {
2217 2217
             $post_type = __('Quote', 'invoicing');
2218 2218
         }
2219 2219
 
Please login to merge, or discard this patch.
includes/class-wpinv-subscriptions-db.php 1 patch
Spacing   +154 added lines, -154 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // Exit if accessed directly.
3
-if (!defined( 'ABSPATH' ) ) exit;
3
+if (!defined('ABSPATH')) exit;
4 4
 
5 5
 /**
6 6
  * The Subscriptions DB Class
@@ -68,8 +68,8 @@  discard block
 block discarded – undo
68 68
             'transaction_id'    => '',
69 69
             'parent_payment_id' => 0,
70 70
             'product_id'        => 0,
71
-            'created'           => date( 'Y-m-d H:i:s' ),
72
-            'expiration'        => date( 'Y-m-d H:i:s' ),
71
+            'created'           => date('Y-m-d H:i:s'),
72
+            'expiration'        => date('Y-m-d H:i:s'),
73 73
             'trial_period'      => '',
74 74
             'status'            => '',
75 75
             'profile_id'        => '',
@@ -82,11 +82,11 @@  discard block
 block discarded – undo
82 82
      * @access  public
83 83
      * @since   1.0.0
84 84
      */
85
-    public function get_subscriptions( $args = array() ) {
85
+    public function get_subscriptions($args = array()) {
86 86
         global $wpdb;
87 87
 
88 88
         $defaults = array(
89
-            'number'       => get_option( 'posts_per_page' ),
89
+            'number'       => get_option('posts_per_page'),
90 90
             'offset'       => 0,
91 91
             'search'       => '',
92 92
             'customer_id'  => 0,
@@ -94,21 +94,21 @@  discard block
 block discarded – undo
94 94
             'order'        => 'DESC'
95 95
         );
96 96
 
97
-        $args  = wp_parse_args( $args, $defaults );
97
+        $args = wp_parse_args($args, $defaults);
98 98
 
99
-        if( $args['number'] < 1 ) {
99
+        if ($args['number'] < 1) {
100 100
             $args['number'] = 999999999999;
101 101
         }
102 102
 
103 103
         $where = ' WHERE 1=1 ';
104 104
 
105 105
         // specific customers
106
-        if( ! empty( $args['id'] ) ) {
106
+        if (!empty($args['id'])) {
107 107
 
108
-            if( is_array( $args['id'] ) ) {
109
-                $ids = implode( ',', array_map('intval', $args['id'] ) );
108
+            if (is_array($args['id'])) {
109
+                $ids = implode(',', array_map('intval', $args['id']));
110 110
             } else {
111
-                $ids = intval( $args['id'] );
111
+                $ids = intval($args['id']);
112 112
             }
113 113
 
114 114
             $where .= " AND `id` IN( {$ids} ) ";
@@ -116,12 +116,12 @@  discard block
 block discarded – undo
116 116
         }
117 117
 
118 118
         // Specific products
119
-        if( ! empty( $args['product_id'] ) ) {
119
+        if (!empty($args['product_id'])) {
120 120
 
121
-            if( is_array( $args['product_id'] ) ) {
122
-                $product_ids = implode( ',', array_map('intval', $args['product_id'] ) );
121
+            if (is_array($args['product_id'])) {
122
+                $product_ids = implode(',', array_map('intval', $args['product_id']));
123 123
             } else {
124
-                $product_ids = intval( $args['product_id'] );
124
+                $product_ids = intval($args['product_id']);
125 125
             }
126 126
 
127 127
             $where .= " AND `product_id` IN( {$product_ids} ) ";
@@ -129,12 +129,12 @@  discard block
 block discarded – undo
129 129
         }
130 130
 
131 131
         // Specific parent payments
132
-        if( ! empty( $args['parent_payment_id'] ) ) {
132
+        if (!empty($args['parent_payment_id'])) {
133 133
 
134
-            if( is_array( $args['parent_payment_id'] ) ) {
135
-                $parent_payment_ids = implode( ',', array_map('intval', $args['parent_payment_id'] ) );
134
+            if (is_array($args['parent_payment_id'])) {
135
+                $parent_payment_ids = implode(',', array_map('intval', $args['parent_payment_id']));
136 136
             } else {
137
-                $parent_payment_ids = intval( $args['parent_payment_id'] );
137
+                $parent_payment_ids = intval($args['parent_payment_id']);
138 138
             }
139 139
 
140 140
             $where .= " AND `parent_payment_id` IN( {$parent_payment_ids} ) ";
@@ -142,12 +142,12 @@  discard block
 block discarded – undo
142 142
         }
143 143
 
144 144
         // Specific transaction IDs
145
-        if( ! empty( $args['transaction_id'] ) ) {
145
+        if (!empty($args['transaction_id'])) {
146 146
 
147
-            if( is_array( $args['transaction_id'] ) ) {
148
-                $transaction_ids = implode( "','", array_map('sanitize_text_field', $args['transaction_id'] ) );
147
+            if (is_array($args['transaction_id'])) {
148
+                $transaction_ids = implode("','", array_map('sanitize_text_field', $args['transaction_id']));
149 149
             } else {
150
-                $transaction_ids = sanitize_text_field( $args['transaction_id'] );
150
+                $transaction_ids = sanitize_text_field($args['transaction_id']);
151 151
             }
152 152
 
153 153
             $where .= " AND `transaction_id` IN ( '{$transaction_ids}' ) ";
@@ -155,12 +155,12 @@  discard block
 block discarded – undo
155 155
         }
156 156
 
157 157
         // Subscriptoins for specific customers
158
-        if( ! empty( $args['customer_id'] ) ) {
158
+        if (!empty($args['customer_id'])) {
159 159
 
160
-            if( is_array( $args['customer_id'] ) ) {
161
-                $customer_ids = implode( ',', array_map('intval', $args['customer_id'] ) );
160
+            if (is_array($args['customer_id'])) {
161
+                $customer_ids = implode(',', array_map('intval', $args['customer_id']));
162 162
             } else {
163
-                $customer_ids = intval( $args['customer_id'] );
163
+                $customer_ids = intval($args['customer_id']);
164 164
             }
165 165
 
166 166
             $where .= " AND `customer_id` IN( {$customer_ids} ) ";
@@ -168,12 +168,12 @@  discard block
 block discarded – undo
168 168
         }
169 169
 
170 170
         // Subscriptions for specific profile IDs
171
-        if( ! empty( $args['profile_id'] ) ) {
171
+        if (!empty($args['profile_id'])) {
172 172
 
173
-            if( is_array( $args['profile_id'] ) ) {
174
-                $profile_ids = implode( "','", array_map('sanitize_text_field', $args['profile_id'] ) );
173
+            if (is_array($args['profile_id'])) {
174
+                $profile_ids = implode("','", array_map('sanitize_text_field', $args['profile_id']));
175 175
             } else {
176
-                $profile_ids = sanitize_text_field( $args['profile_id'] );
176
+                $profile_ids = sanitize_text_field($args['profile_id']);
177 177
             }
178 178
 
179 179
             $where .= " AND `profile_id` IN( '{$profile_ids}' ) ";
@@ -181,12 +181,12 @@  discard block
 block discarded – undo
181 181
         }
182 182
 
183 183
         // Subscriptions for specific statuses
184
-        if( ! empty( $args['status'] ) ) {
184
+        if (!empty($args['status'])) {
185 185
 
186
-            if( is_array( $args['status'] ) ) {
187
-                $statuses = implode( "','", array_map( 'sanitize_text_field', $args['status'] ) );
186
+            if (is_array($args['status'])) {
187
+                $statuses = implode("','", array_map('sanitize_text_field', $args['status']));
188 188
             } else {
189
-                $statuses = sanitize_text_field( $args['status'] );
189
+                $statuses = sanitize_text_field($args['status']);
190 190
             }
191 191
 
192 192
             $where .= " AND `status` IN( '{$statuses}' ) ";
@@ -194,21 +194,21 @@  discard block
 block discarded – undo
194 194
         }
195 195
 
196 196
         // Subscriptions created for a specific date or in a date range
197
-        if( ! empty( $args['date'] ) ) {
197
+        if (!empty($args['date'])) {
198 198
 
199
-            if( is_array( $args['date'] ) ) {
199
+            if (is_array($args['date'])) {
200 200
 
201
-                if( ! empty( $args['date']['start'] ) ) {
201
+                if (!empty($args['date']['start'])) {
202 202
 
203
-                    $start = date( 'Y-m-d H:i:s', strtotime( $args['date']['start'] ) );
203
+                    $start = date('Y-m-d H:i:s', strtotime($args['date']['start']));
204 204
 
205 205
                     $where .= " AND `created` >= '{$start}'";
206 206
 
207 207
                 }
208 208
 
209
-                if( ! empty( $args['date']['end'] ) ) {
209
+                if (!empty($args['date']['end'])) {
210 210
 
211
-                    $end = date( 'Y-m-d H:i:s', strtotime( $args['date']['end'] ) );
211
+                    $end = date('Y-m-d H:i:s', strtotime($args['date']['end']));
212 212
 
213 213
                     $where .= " AND `created` <= '{$end}'";
214 214
 
@@ -216,9 +216,9 @@  discard block
 block discarded – undo
216 216
 
217 217
             } else {
218 218
 
219
-                $year  = date( 'Y', strtotime( $args['date'] ) );
220
-                $month = date( 'm', strtotime( $args['date'] ) );
221
-                $day   = date( 'd', strtotime( $args['date'] ) );
219
+                $year  = date('Y', strtotime($args['date']));
220
+                $month = date('m', strtotime($args['date']));
221
+                $day   = date('d', strtotime($args['date']));
222 222
 
223 223
                 $where .= " AND $year = YEAR ( created ) AND $month = MONTH ( created ) AND $day = DAY ( created )";
224 224
             }
@@ -226,21 +226,21 @@  discard block
 block discarded – undo
226 226
         }
227 227
 
228 228
         // Subscriptions with a specific expiration date or in an expiration date range
229
-        if( ! empty( $args['expiration'] ) ) {
229
+        if (!empty($args['expiration'])) {
230 230
 
231
-            if( is_array( $args['expiration'] ) ) {
231
+            if (is_array($args['expiration'])) {
232 232
 
233
-                if( ! empty( $args['expiration']['start'] ) ) {
233
+                if (!empty($args['expiration']['start'])) {
234 234
 
235
-                    $start = date( 'Y-m-d H:i:s', strtotime( $args['expiration']['start'] ) );
235
+                    $start = date('Y-m-d H:i:s', strtotime($args['expiration']['start']));
236 236
 
237 237
                     $where .= " AND `expiration` >= '{$start}'";
238 238
 
239 239
                 }
240 240
 
241
-                if( ! empty( $args['expiration']['end'] ) ) {
241
+                if (!empty($args['expiration']['end'])) {
242 242
 
243
-                    $end = date( 'Y-m-d H:i:s', strtotime( $args['expiration']['end'] ) );
243
+                    $end = date('Y-m-d H:i:s', strtotime($args['expiration']['end']));
244 244
 
245 245
                     $where .= " AND `expiration` <= '{$end}'";
246 246
 
@@ -248,73 +248,73 @@  discard block
 block discarded – undo
248 248
 
249 249
             } else {
250 250
 
251
-                $year  = date( 'Y', strtotime( $args['expiration'] ) );
252
-                $month = date( 'm', strtotime( $args['expiration'] ) );
253
-                $day   = date( 'd', strtotime( $args['expiration'] ) );
251
+                $year  = date('Y', strtotime($args['expiration']));
252
+                $month = date('m', strtotime($args['expiration']));
253
+                $day   = date('d', strtotime($args['expiration']));
254 254
 
255 255
                 $where .= " AND $year = YEAR ( expiration ) AND $month = MONTH ( expiration ) AND $day = DAY ( expiration )";
256 256
             }
257 257
 
258 258
         }
259 259
 
260
-        if ( ! empty( $args['search'] ) ) {
260
+        if (!empty($args['search'])) {
261 261
 
262
-            if( false !== strpos( 'id:', $args['search'] ) ) {
262
+            if (false !== strpos('id:', $args['search'])) {
263 263
 
264
-                $args['search'] = trim( str_replace( 'id:', '', $args['search'] ) );
265
-                $where .= " AND `id` = '" . esc_sql( $args['search'] ) . "'";
264
+                $args['search'] = trim(str_replace('id:', '', $args['search']));
265
+                $where .= " AND `id` = '" . esc_sql($args['search']) . "'";
266 266
 
267
-            } else if( false !== strpos( $args['search'], 'txn:' ) ) {
267
+            } else if (false !== strpos($args['search'], 'txn:')) {
268 268
 
269
-                $args['search'] = trim( str_replace( 'txn:', '', $args['search'] ) );
270
-                $where .= " AND `transaction_id` = '" . esc_sql( $args['search'] ) . "'";
269
+                $args['search'] = trim(str_replace('txn:', '', $args['search']));
270
+                $where .= " AND `transaction_id` = '" . esc_sql($args['search']) . "'";
271 271
 
272
-            } else if( false !== strpos( $args['search'], 'profile_id:' ) ) {
272
+            } else if (false !== strpos($args['search'], 'profile_id:')) {
273 273
 
274
-                $args['search'] = trim( str_replace( 'profile_id:', '', $args['search'] ) );
275
-                $where .= " AND `profile_id` = '" . esc_sql( $args['search'] ) . "'";
274
+                $args['search'] = trim(str_replace('profile_id:', '', $args['search']));
275
+                $where .= " AND `profile_id` = '" . esc_sql($args['search']) . "'";
276 276
 
277
-            } else if( false !== strpos( $args['search'], 'product_id:' ) ) {
277
+            } else if (false !== strpos($args['search'], 'product_id:')) {
278 278
 
279
-                $args['search'] = trim( str_replace( 'product_id:', '', $args['search'] ) );
280
-                $where .= " AND `product_id` = '" . esc_sql( $args['search'] ) . "'";
279
+                $args['search'] = trim(str_replace('product_id:', '', $args['search']));
280
+                $where .= " AND `product_id` = '" . esc_sql($args['search']) . "'";
281 281
 
282
-            } else if( false !== strpos( $args['search'], 'customer_id:' ) ) {
282
+            } else if (false !== strpos($args['search'], 'customer_id:')) {
283 283
 
284
-                $args['search'] = trim( str_replace( 'customer_id:', '', $args['search'] ) );
285
-                $where .= " AND `customer_id` = '" . esc_sql( $args['search'] ) . "'";
284
+                $args['search'] = trim(str_replace('customer_id:', '', $args['search']));
285
+                $where .= " AND `customer_id` = '" . esc_sql($args['search']) . "'";
286 286
 
287 287
             } else {
288 288
 
289
-                $where .= " AND ( `parent_payment_id` LIKE '%%" . esc_sql( $args['search'] ) . "%%' OR `profile_id` LIKE '%%" . esc_sql( $args['search'] ) . "%%' OR `transaction_id` LIKE '%%" . esc_sql( $args['search'] ) . "%%' OR `product_id` LIKE '%%" . esc_sql( $args['search'] ) . "%%' OR `id` = '" . esc_sql( $args['search'] ) . "' )";
289
+                $where .= " AND ( `parent_payment_id` LIKE '%%" . esc_sql($args['search']) . "%%' OR `profile_id` LIKE '%%" . esc_sql($args['search']) . "%%' OR `transaction_id` LIKE '%%" . esc_sql($args['search']) . "%%' OR `product_id` LIKE '%%" . esc_sql($args['search']) . "%%' OR `id` = '" . esc_sql($args['search']) . "' )";
290 290
 
291 291
             }
292 292
 
293 293
         }
294 294
 
295
-        $args['orderby'] = ! array_key_exists( $args['orderby'], $this->get_columns() ) ? 'id' : $args['orderby'];
295
+        $args['orderby'] = !array_key_exists($args['orderby'], $this->get_columns()) ? 'id' : $args['orderby'];
296 296
 
297
-        if( 'amount' == $args['orderby'] ) {
297
+        if ('amount' == $args['orderby']) {
298 298
             $args['orderby'] = 'amount+0';
299 299
         }
300 300
 
301
-        $cache_key = md5( 'wpinv_subscriptions_' . serialize( $args ) );
301
+        $cache_key = md5('wpinv_subscriptions_' . serialize($args));
302 302
 
303
-        $subscriptions = wp_cache_get( $cache_key, 'subscriptions' );
303
+        $subscriptions = wp_cache_get($cache_key, 'subscriptions');
304 304
 
305
-        $args['orderby'] = esc_sql( $args['orderby'] );
306
-        $args['order']   = esc_sql( $args['order'] );
305
+        $args['orderby'] = esc_sql($args['orderby']);
306
+        $args['order']   = esc_sql($args['order']);
307 307
 
308
-        if( $subscriptions === false ) {
309
-            $subscriptions = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM  $this->table_name $where ORDER BY {$args['orderby']} {$args['order']} LIMIT %d,%d;", absint( $args['offset'] ), absint( $args['number'] ) ), OBJECT );
308
+        if ($subscriptions === false) {
309
+            $subscriptions = $wpdb->get_results($wpdb->prepare("SELECT * FROM  $this->table_name $where ORDER BY {$args['orderby']} {$args['order']} LIMIT %d,%d;", absint($args['offset']), absint($args['number'])), OBJECT);
310 310
 
311
-            if( ! empty( $subscriptions ) ) {
311
+            if (!empty($subscriptions)) {
312 312
 
313
-                foreach( $subscriptions as $key => $subscription ) {
314
-                    $subscriptions[ $key ] = new WPInv_Subscription( $subscription );
313
+                foreach ($subscriptions as $key => $subscription) {
314
+                    $subscriptions[$key] = new WPInv_Subscription($subscription);
315 315
                 }
316 316
 
317
-                wp_cache_set( $cache_key, $subscriptions, 'subscriptions', 3600 );
317
+                wp_cache_set($cache_key, $subscriptions, 'subscriptions', 3600);
318 318
 
319 319
             }
320 320
 
@@ -329,19 +329,19 @@  discard block
 block discarded – undo
329 329
      * @access  public
330 330
      * @since   1.0.0
331 331
      */
332
-    public function count( $args = array() ) {
332
+    public function count($args = array()) {
333 333
 
334 334
         global $wpdb;
335 335
 
336 336
         $where = ' WHERE 1=1 ';
337 337
 
338 338
         // specific customers
339
-        if( ! empty( $args['id'] ) ) {
339
+        if (!empty($args['id'])) {
340 340
 
341
-            if( is_array( $args['id'] ) ) {
342
-                $ids = implode( ',', array_map('intval', $args['id'] ) );
341
+            if (is_array($args['id'])) {
342
+                $ids = implode(',', array_map('intval', $args['id']));
343 343
             } else {
344
-                $ids = intval( $args['id'] );
344
+                $ids = intval($args['id']);
345 345
             }
346 346
 
347 347
             $where .= " AND `id` IN( {$ids} ) ";
@@ -349,12 +349,12 @@  discard block
 block discarded – undo
349 349
         }
350 350
 
351 351
         // Specific products
352
-        if( ! empty( $args['product_id'] ) ) {
352
+        if (!empty($args['product_id'])) {
353 353
 
354
-            if( is_array( $args['product_id'] ) ) {
355
-                $product_ids = implode( ',', array_map('intval', $args['product_id'] ) );
354
+            if (is_array($args['product_id'])) {
355
+                $product_ids = implode(',', array_map('intval', $args['product_id']));
356 356
             } else {
357
-                $product_ids = intval( $args['product_id'] );
357
+                $product_ids = intval($args['product_id']);
358 358
             }
359 359
 
360 360
             $where .= " AND `product_id` IN( {$product_ids} ) ";
@@ -362,12 +362,12 @@  discard block
 block discarded – undo
362 362
         }
363 363
 
364 364
         // Specific parent payments
365
-        if( ! empty( $args['parent_payment_id'] ) ) {
365
+        if (!empty($args['parent_payment_id'])) {
366 366
 
367
-            if( is_array( $args['parent_payment_id'] ) ) {
368
-                $parent_payment_ids = implode( ',', array_map('intval', $args['parent_payment_id'] ) );
367
+            if (is_array($args['parent_payment_id'])) {
368
+                $parent_payment_ids = implode(',', array_map('intval', $args['parent_payment_id']));
369 369
             } else {
370
-                $parent_payment_ids = intval( $args['parent_payment_id'] );
370
+                $parent_payment_ids = intval($args['parent_payment_id']);
371 371
             }
372 372
 
373 373
             $where .= " AND `parent_payment_id` IN( {$parent_payment_ids} ) ";
@@ -375,12 +375,12 @@  discard block
 block discarded – undo
375 375
         }
376 376
 
377 377
         // Subscriptoins for specific customers
378
-        if( ! empty( $args['customer_id'] ) ) {
378
+        if (!empty($args['customer_id'])) {
379 379
 
380
-            if( is_array( $args['customer_id'] ) ) {
381
-                $customer_ids = implode( ',', array_map('intval', $args['customer_id'] ) );
380
+            if (is_array($args['customer_id'])) {
381
+                $customer_ids = implode(',', array_map('intval', $args['customer_id']));
382 382
             } else {
383
-                $customer_ids = intval( $args['customer_id'] );
383
+                $customer_ids = intval($args['customer_id']);
384 384
             }
385 385
 
386 386
             $where .= " AND `customer_id` IN( {$customer_ids} ) ";
@@ -388,12 +388,12 @@  discard block
 block discarded – undo
388 388
         }
389 389
 
390 390
         // Subscriptions for specific profile IDs
391
-        if( ! empty( $args['profile_id'] ) ) {
391
+        if (!empty($args['profile_id'])) {
392 392
 
393
-            if( is_array( $args['profile_id'] ) ) {
394
-                $profile_ids = implode( ',', array_map('intval', $args['profile_id'] ) );
393
+            if (is_array($args['profile_id'])) {
394
+                $profile_ids = implode(',', array_map('intval', $args['profile_id']));
395 395
             } else {
396
-                $profile_ids = intval( $args['profile_id'] );
396
+                $profile_ids = intval($args['profile_id']);
397 397
             }
398 398
 
399 399
             $where .= " AND `profile_id` IN( {$profile_ids} ) ";
@@ -401,12 +401,12 @@  discard block
 block discarded – undo
401 401
         }
402 402
 
403 403
         // Specific transaction IDs
404
-        if( ! empty( $args['transaction_id'] ) ) {
404
+        if (!empty($args['transaction_id'])) {
405 405
 
406
-            if( is_array( $args['transaction_id'] ) ) {
407
-                $transaction_ids = implode( ',', array_map('sanitize_text_field', $args['transaction_id'] ) );
406
+            if (is_array($args['transaction_id'])) {
407
+                $transaction_ids = implode(',', array_map('sanitize_text_field', $args['transaction_id']));
408 408
             } else {
409
-                $transaction_ids = sanitize_text_field( $args['transaction_id'] );
409
+                $transaction_ids = sanitize_text_field($args['transaction_id']);
410 410
             }
411 411
 
412 412
             $where .= " AND `transaction_id` IN( {$transaction_ids} ) ";
@@ -414,10 +414,10 @@  discard block
 block discarded – undo
414 414
         }
415 415
 
416 416
         // Subscriptions for specific statuses
417
-        if( ! empty( $args['status'] ) ) {
417
+        if (!empty($args['status'])) {
418 418
 
419
-            if( is_array( $args['status'] ) ) {
420
-                $statuses = implode( ',', $args['status'] );
419
+            if (is_array($args['status'])) {
420
+                $statuses = implode(',', $args['status']);
421 421
                 $where  .= " AND `status` IN( {$statuses} ) ";
422 422
             } else {
423 423
                 $statuses = $args['status'];
@@ -429,21 +429,21 @@  discard block
 block discarded – undo
429 429
         }
430 430
 
431 431
         // Subscriptions created for a specific date or in a date range
432
-        if( ! empty( $args['date'] ) ) {
432
+        if (!empty($args['date'])) {
433 433
 
434
-            if( is_array( $args['date'] ) ) {
434
+            if (is_array($args['date'])) {
435 435
 
436
-                if( ! empty( $args['date']['start'] ) ) {
436
+                if (!empty($args['date']['start'])) {
437 437
 
438
-                    $start = date( 'Y-m-d H:i:s', strtotime( $args['date']['start'] ) );
438
+                    $start = date('Y-m-d H:i:s', strtotime($args['date']['start']));
439 439
 
440 440
                     $where .= " AND `created` >= '{$start}'";
441 441
 
442 442
                 }
443 443
 
444
-                if( ! empty( $args['date']['end'] ) ) {
444
+                if (!empty($args['date']['end'])) {
445 445
 
446
-                    $end = date( 'Y-m-d H:i:s', strtotime( $args['date']['end'] ) );
446
+                    $end = date('Y-m-d H:i:s', strtotime($args['date']['end']));
447 447
 
448 448
                     $where .= " AND `created` <= '{$end}'";
449 449
 
@@ -451,9 +451,9 @@  discard block
 block discarded – undo
451 451
 
452 452
             } else {
453 453
 
454
-                $year  = date( 'Y', strtotime( $args['date'] ) );
455
-                $month = date( 'm', strtotime( $args['date'] ) );
456
-                $day   = date( 'd', strtotime( $args['date'] ) );
454
+                $year  = date('Y', strtotime($args['date']));
455
+                $month = date('m', strtotime($args['date']));
456
+                $day   = date('d', strtotime($args['date']));
457 457
 
458 458
                 $where .= " AND $year = YEAR ( created ) AND $month = MONTH ( created ) AND $day = DAY ( created )";
459 459
             }
@@ -461,21 +461,21 @@  discard block
 block discarded – undo
461 461
         }
462 462
 
463 463
         // Subscriptions with a specific expiration date or in an expiration date range
464
-        if( ! empty( $args['expiration'] ) ) {
464
+        if (!empty($args['expiration'])) {
465 465
 
466
-            if( is_array( $args['expiration'] ) ) {
466
+            if (is_array($args['expiration'])) {
467 467
 
468
-                if( ! empty( $args['expiration']['start'] ) ) {
468
+                if (!empty($args['expiration']['start'])) {
469 469
 
470
-                    $start = date( 'Y-m-d H:i:s', strtotime( $args['expiration']['start'] ) );
470
+                    $start = date('Y-m-d H:i:s', strtotime($args['expiration']['start']));
471 471
 
472 472
                     $where .= " AND `expiration` >= '{$start}'";
473 473
 
474 474
                 }
475 475
 
476
-                if( ! empty( $args['expiration']['end'] ) ) {
476
+                if (!empty($args['expiration']['end'])) {
477 477
 
478
-                    $end = date( 'Y-m-d H:i:s', strtotime( $args['expiration']['end'] ) );
478
+                    $end = date('Y-m-d H:i:s', strtotime($args['expiration']['end']));
479 479
 
480 480
                     $where .= " AND `expiration` <= '{$end}'";
481 481
 
@@ -483,64 +483,64 @@  discard block
 block discarded – undo
483 483
 
484 484
             } else {
485 485
 
486
-                $year  = date( 'Y', strtotime( $args['expiration'] ) );
487
-                $month = date( 'm', strtotime( $args['expiration'] ) );
488
-                $day   = date( 'd', strtotime( $args['expiration'] ) );
486
+                $year  = date('Y', strtotime($args['expiration']));
487
+                $month = date('m', strtotime($args['expiration']));
488
+                $day   = date('d', strtotime($args['expiration']));
489 489
 
490 490
                 $where .= " AND $year = YEAR ( expiration ) AND $month = MONTH ( expiration ) AND $day = DAY ( expiration )";
491 491
             }
492 492
 
493 493
         }
494 494
 
495
-        if ( ! empty( $args['search'] ) ) {
495
+        if (!empty($args['search'])) {
496 496
 
497
-            if( false !== strpos( 'id:', $args['search'] ) ) {
497
+            if (false !== strpos('id:', $args['search'])) {
498 498
 
499
-                $args['search'] = trim( str_replace( 'id:', '', $args['search'] ) );
500
-                $where .= " AND `id` = '" . esc_sql( $args['search'] ) . "'";
499
+                $args['search'] = trim(str_replace('id:', '', $args['search']));
500
+                $where .= " AND `id` = '" . esc_sql($args['search']) . "'";
501 501
 
502
-            } else if( false !== strpos( $args['search'], 'txn:' ) ) {
502
+            } else if (false !== strpos($args['search'], 'txn:')) {
503 503
 
504
-                $args['search'] = trim( str_replace( 'txn:', '', $args['search'] ) );
505
-                $where .= " AND `transaction_id` = '" . esc_sql( $args['search'] ) . "'";
504
+                $args['search'] = trim(str_replace('txn:', '', $args['search']));
505
+                $where .= " AND `transaction_id` = '" . esc_sql($args['search']) . "'";
506 506
 
507
-            } else if( false !== strpos( $args['search'], 'profile_id:' ) ) {
507
+            } else if (false !== strpos($args['search'], 'profile_id:')) {
508 508
 
509
-                $args['search'] = trim( str_replace( 'profile_id:', '', $args['search'] ) );
510
-                $where .= " AND `profile_id` = '" . esc_sql( $args['search'] ) . "'";
509
+                $args['search'] = trim(str_replace('profile_id:', '', $args['search']));
510
+                $where .= " AND `profile_id` = '" . esc_sql($args['search']) . "'";
511 511
 
512
-            } else if( false !== strpos( $args['search'], 'product_id:' ) ) {
512
+            } else if (false !== strpos($args['search'], 'product_id:')) {
513 513
 
514
-                $args['search'] = trim( str_replace( 'product_id:', '', $args['search'] ) );
515
-                $where .= " AND `product_id` = '" . esc_sql( $args['search'] ) . "'";
514
+                $args['search'] = trim(str_replace('product_id:', '', $args['search']));
515
+                $where .= " AND `product_id` = '" . esc_sql($args['search']) . "'";
516 516
 
517
-            } else if( false !== strpos( $args['search'], 'customer_id:' ) ) {
517
+            } else if (false !== strpos($args['search'], 'customer_id:')) {
518 518
 
519
-                $args['search'] = trim( str_replace( 'customer_id:', '', $args['search'] ) );
520
-                $where .= " AND `customer_id` = '" . esc_sql( $args['search'] ) . "'";
519
+                $args['search'] = trim(str_replace('customer_id:', '', $args['search']));
520
+                $where .= " AND `customer_id` = '" . esc_sql($args['search']) . "'";
521 521
 
522 522
             } else {
523 523
 
524
-                $where .= " AND ( `parent_payment_id` LIKE '%%" . esc_sql( $args['search'] ) . "%%' OR `profile_id` LIKE '%%" . esc_sql( $args['search'] ) . "%%' OR `transaction_id` LIKE '%%" . esc_sql( $args['search'] ) . "%%' OR `product_id` LIKE '%%" . esc_sql( $args['search'] ) . "%%' OR `id` = '" . esc_sql( $args['search'] ) . "' )";
524
+                $where .= " AND ( `parent_payment_id` LIKE '%%" . esc_sql($args['search']) . "%%' OR `profile_id` LIKE '%%" . esc_sql($args['search']) . "%%' OR `transaction_id` LIKE '%%" . esc_sql($args['search']) . "%%' OR `product_id` LIKE '%%" . esc_sql($args['search']) . "%%' OR `id` = '" . esc_sql($args['search']) . "' )";
525 525
 
526 526
             }
527 527
 
528 528
         }
529 529
 
530
-        $cache_key = md5( 'wpinv_subscriptions_count' . serialize( $args ) );
530
+        $cache_key = md5('wpinv_subscriptions_count' . serialize($args));
531 531
 
532
-        $count = wp_cache_get( $cache_key, 'subscriptions' );
532
+        $count = wp_cache_get($cache_key, 'subscriptions');
533 533
 
534
-        if( $count === false ) {
534
+        if ($count === false) {
535 535
 
536 536
             $sql   = "SELECT COUNT($this->primary_key) FROM " . $this->table_name . "{$where};";
537
-            $count = $wpdb->get_var( $sql );
537
+            $count = $wpdb->get_var($sql);
538 538
 
539
-            wp_cache_set( $cache_key, $count, 'subscriptions', 3600 );
539
+            wp_cache_set($cache_key, $count, 'subscriptions', 3600);
540 540
 
541 541
         }
542 542
 
543
-        return absint( $count );
543
+        return absint($count);
544 544
 
545 545
     }
546 546
 
@@ -553,7 +553,7 @@  discard block
 block discarded – undo
553 553
     public function create_table() {
554 554
         global $wpdb;
555 555
 
556
-        require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
556
+        require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
557 557
 
558 558
         $sql = "CREATE TABLE " . $this->table_name . " (
559 559
         id bigint(20) NOT NULL AUTO_INCREMENT,
@@ -578,9 +578,9 @@  discard block
 block discarded – undo
578 578
         KEY customer_and_status ( customer_id, status)
579 579
         ) CHARACTER SET utf8 COLLATE utf8_general_ci;";
580 580
 
581
-        dbDelta( $sql );
581
+        dbDelta($sql);
582 582
 
583
-        update_option( $this->table_name . '_db_version', $this->version );
583
+        update_option($this->table_name . '_db_version', $this->version);
584 584
     }
585 585
 
586 586
 }
587 587
\ No newline at end of file
Please login to merge, or discard this patch.
includes/class-wpinv-subscriptions.php 1 patch
Spacing   +69 added lines, -69 removed lines patch added patch discarded remove patch
@@ -1,11 +1,11 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // Exit if accessed directly.
3
-if (!defined( 'ABSPATH' ) ) exit;
3
+if (!defined('ABSPATH')) exit;
4 4
 
5 5
 function wpinv_subscription_init() {
6 6
     return WPInv_Subscriptions::instance();
7 7
 }
8
-add_action( 'plugins_loaded', 'wpinv_subscription_init', 100 );
8
+add_action('plugins_loaded', 'wpinv_subscription_init', 100);
9 9
 
10 10
 /**
11 11
  * WPInv_Subscriptions Class.
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
      * Main WPInv_Subscriptions Instance
21 21
      */
22 22
     public static function instance() {
23
-        if ( ! isset( self::$instance ) ) {
23
+        if (!isset(self::$instance)) {
24 24
             self::$instance = new WPInv_Subscriptions;
25 25
 
26 26
             self::$instance->init();
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
      *
35 35
      * @since 1.0.0
36 36
      */
37
-    private function __construct(){
37
+    private function __construct() {
38 38
 
39 39
     }
40 40
 
@@ -63,8 +63,8 @@  discard block
 block discarded – undo
63 63
     private function setup_constants() {
64 64
 
65 65
         // Make sure CAL_GREGORIAN is defined.
66
-        if ( ! defined( 'CAL_GREGORIAN' ) ) {
67
-            define( 'CAL_GREGORIAN', 1 );
66
+        if (!defined('CAL_GREGORIAN')) {
67
+            define('CAL_GREGORIAN', 1);
68 68
         }
69 69
     }
70 70
 
@@ -76,13 +76,13 @@  discard block
 block discarded – undo
76 76
      */
77 77
     private function actions() {
78 78
 
79
-        add_action( 'admin_menu', array( $this, 'wpinv_subscriptions_list' ), 10 );
80
-        add_action( 'admin_notices', array( $this, 'notices' ) );
81
-        add_action( 'init', array( $this, 'wpinv_post_actions' ) );
82
-        add_action( 'init', array( $this, 'wpinv_get_actions' ) );
83
-        add_action( 'wpinv_cancel_subscription', array( $this, 'wpinv_process_cancellation' ) );
84
-        add_action( 'wpi-pending_wpi_invoice', array( $this, 'wpinv_add_update_subscription' ), 10, 2 );
85
-        add_action( 'wpinv_subscriptions_front_notices', array( $this, 'notices' ) );
79
+        add_action('admin_menu', array($this, 'wpinv_subscriptions_list'), 10);
80
+        add_action('admin_notices', array($this, 'notices'));
81
+        add_action('init', array($this, 'wpinv_post_actions'));
82
+        add_action('init', array($this, 'wpinv_get_actions'));
83
+        add_action('wpinv_cancel_subscription', array($this, 'wpinv_process_cancellation'));
84
+        add_action('wpi-pending_wpi_invoice', array($this, 'wpinv_add_update_subscription'), 10, 2);
85
+        add_action('wpinv_subscriptions_front_notices', array($this, 'notices'));
86 86
     }
87 87
 
88 88
     /**
@@ -104,8 +104,8 @@  discard block
 block discarded – undo
104 104
     public function wpinv_subscriptions_list() {
105 105
         add_submenu_page(
106 106
             'wpinv',
107
-            __( 'Subscriptions', 'invoicing' ),
108
-            __( 'Subscriptions', 'invoicing' ),
107
+            __('Subscriptions', 'invoicing'),
108
+            __('Subscriptions', 'invoicing'),
109 109
             'manage_invoicing',
110 110
             'wpinv-subscriptions',
111 111
             'wpinv_subscriptions_page'
@@ -114,37 +114,37 @@  discard block
 block discarded – undo
114 114
 
115 115
     public function notices() {
116 116
 
117
-        if( empty( $_GET['wpinv-message'] ) ) {
117
+        if (empty($_GET['wpinv-message'])) {
118 118
             return;
119 119
         }
120 120
 
121 121
         $type    = 'updated';
122 122
         $message = '';
123 123
 
124
-        switch( strtolower( $_GET['wpinv-message'] ) ) {
124
+        switch (strtolower($_GET['wpinv-message'])) {
125 125
 
126 126
             case 'updated' :
127 127
 
128
-                $message = __( 'Subscription updated successfully.', 'invoicing' );
128
+                $message = __('Subscription updated successfully.', 'invoicing');
129 129
 
130 130
                 break;
131 131
 
132 132
             case 'deleted' :
133 133
 
134
-                $message = __( 'Subscription deleted successfully.', 'invoicing' );
134
+                $message = __('Subscription deleted successfully.', 'invoicing');
135 135
 
136 136
                 break;
137 137
 
138 138
             case 'cancelled' :
139 139
 
140
-                $message = __( 'Subscription cancelled successfully.', 'invoicing' );
140
+                $message = __('Subscription cancelled successfully.', 'invoicing');
141 141
 
142 142
                 break;
143 143
 
144 144
         }
145 145
 
146
-        if ( ! empty( $message ) ) {
147
-            echo '<div class="' . esc_attr( $type ) . '"><p>' . $message . '</p></div>';
146
+        if (!empty($message)) {
147
+            echo '<div class="' . esc_attr($type) . '"><p>' . $message . '</p></div>';
148 148
         }
149 149
 
150 150
     }
@@ -157,8 +157,8 @@  discard block
 block discarded – undo
157 157
      * @return void
158 158
      */
159 159
     function wpinv_get_actions() {
160
-        if ( isset( $_GET['wpinv_action'] ) ) {
161
-            do_action( 'wpinv_' . $_GET['wpinv_action'], $_GET );
160
+        if (isset($_GET['wpinv_action'])) {
161
+            do_action('wpinv_' . $_GET['wpinv_action'], $_GET);
162 162
         }
163 163
     }
164 164
 
@@ -170,8 +170,8 @@  discard block
 block discarded – undo
170 170
      * @return void
171 171
      */
172 172
     function wpinv_post_actions() {
173
-        if ( isset( $_POST['wpinv_action'] ) ) {
174
-            do_action( 'wpinv_' . $_POST['wpinv_action'], $_POST );
173
+        if (isset($_POST['wpinv_action'])) {
174
+            do_action('wpinv_' . $_POST['wpinv_action'], $_POST);
175 175
         }
176 176
     }
177 177
 
@@ -182,24 +182,24 @@  discard block
 block discarded – undo
182 182
      * @param int $frequency_count The frequency of the period.
183 183
      * @return mixed|string|void
184 184
      */
185
-    public static function wpinv_get_pretty_subscription_frequency( $period, $frequency_count = 1) {
185
+    public static function wpinv_get_pretty_subscription_frequency($period, $frequency_count = 1) {
186 186
         $frequency = '';
187 187
         //Format period details
188
-        switch ( $period ) {
188
+        switch ($period) {
189 189
             case 'day' :
190
-                $frequency = sprintf( _n('%d Day', '%d Days', $frequency_count, 'invoicing'), $frequency_count);
190
+                $frequency = sprintf(_n('%d Day', '%d Days', $frequency_count, 'invoicing'), $frequency_count);
191 191
                 break;
192 192
             case 'week' :
193
-                $frequency = sprintf( _n('%d Week', '%d Weeks', $frequency_count, 'invoicing'), $frequency_count);
193
+                $frequency = sprintf(_n('%d Week', '%d Weeks', $frequency_count, 'invoicing'), $frequency_count);
194 194
                 break;
195 195
             case 'month' :
196
-                $frequency = sprintf( _n('%d Month', '%d Months', $frequency_count, 'invoicing'), $frequency_count);
196
+                $frequency = sprintf(_n('%d Month', '%d Months', $frequency_count, 'invoicing'), $frequency_count);
197 197
                 break;
198 198
             case 'year' :
199
-                $frequency = sprintf( _n('%d Year', '%d Years', $frequency_count, 'invoicing'), $frequency_count);
199
+                $frequency = sprintf(_n('%d Year', '%d Years', $frequency_count, 'invoicing'), $frequency_count);
200 200
                 break;
201 201
             default :
202
-                $frequency = apply_filters( 'wpinv_recurring_subscription_frequency', $frequency, $period, $frequency_count );
202
+                $frequency = apply_filters('wpinv_recurring_subscription_frequency', $frequency, $period, $frequency_count);
203 203
                 break;
204 204
         }
205 205
 
@@ -214,50 +214,50 @@  discard block
 block discarded – undo
214 214
      * @since       1.0.0
215 215
      * @return      void
216 216
      */
217
-    public function wpinv_process_cancellation( $data ) {
217
+    public function wpinv_process_cancellation($data) {
218 218
 
219 219
 
220
-        if( empty( $data['sub_id'] ) ) {
220
+        if (empty($data['sub_id'])) {
221 221
             return;
222 222
         }
223 223
 
224
-        if( ! is_user_logged_in() ) {
224
+        if (!is_user_logged_in()) {
225 225
             return;
226 226
         }
227 227
 
228
-        if( ! wp_verify_nonce( $data['_wpnonce'], 'wpinv-recurring-cancel' ) ) {
229
-            wp_die( __( 'Error', 'invoicing' ), __( 'Nonce verification failed', 'invoicing' ), array( 'response' => 403 ) );
228
+        if (!wp_verify_nonce($data['_wpnonce'], 'wpinv-recurring-cancel')) {
229
+            wp_die(__('Error', 'invoicing'), __('Nonce verification failed', 'invoicing'), array('response' => 403));
230 230
         }
231 231
 
232
-        $data['sub_id'] = absint( $data['sub_id'] );
233
-        $subscription   = new WPInv_Subscription( $data['sub_id'] );
232
+        $data['sub_id'] = absint($data['sub_id']);
233
+        $subscription   = new WPInv_Subscription($data['sub_id']);
234 234
 
235
-        if( ! $subscription->can_cancel() ) {
236
-            wp_die( __( 'Error', 'invoicing' ), __( 'This subscription cannot be cancelled', 'invoicing' ), array( 'response' => 403 ) );
235
+        if (!$subscription->can_cancel()) {
236
+            wp_die(__('Error', 'invoicing'), __('This subscription cannot be cancelled', 'invoicing'), array('response' => 403));
237 237
         }
238 238
 
239 239
         try {
240 240
 
241
-            do_action( 'wpinv_recurring_cancel_' . $subscription->gateway . '_subscription', $subscription, true );
241
+            do_action('wpinv_recurring_cancel_' . $subscription->gateway . '_subscription', $subscription, true);
242 242
 
243 243
             $subscription->cancel();
244 244
 
245
-            if( is_admin() ) {
245
+            if (is_admin()) {
246 246
 
247
-                wp_redirect( admin_url( 'admin.php?page=wpinv-subscriptions&wpinv-message=cancelled&id=' . $subscription->id ) );
247
+                wp_redirect(admin_url('admin.php?page=wpinv-subscriptions&wpinv-message=cancelled&id=' . $subscription->id));
248 248
                 exit;
249 249
 
250 250
             } else {
251 251
 
252
-                $redirect = remove_query_arg( array( '_wpnonce', 'wpinv_action', 'sub_id' ), add_query_arg( array( 'wpinv-message' => 'cancelled' ) ) );
253
-                $redirect = apply_filters( 'wpinv_recurring_cancellation_redirect', $redirect, $subscription );
254
-                wp_safe_redirect( $redirect );
252
+                $redirect = remove_query_arg(array('_wpnonce', 'wpinv_action', 'sub_id'), add_query_arg(array('wpinv-message' => 'cancelled')));
253
+                $redirect = apply_filters('wpinv_recurring_cancellation_redirect', $redirect, $subscription);
254
+                wp_safe_redirect($redirect);
255 255
                 exit;
256 256
 
257 257
             }
258 258
 
259
-        } catch ( Exception $e ) {
260
-            wp_die( __( 'Error', 'invoicing' ), $e->getMessage(), array( 'response' => 403 ) );
259
+        } catch (Exception $e) {
260
+            wp_die(__('Error', 'invoicing'), $e->getMessage(), array('response' => 403));
261 261
         }
262 262
 
263 263
     }
@@ -269,51 +269,51 @@  discard block
 block discarded – undo
269 269
      * @since       1.0.0
270 270
      * @return      void
271 271
      */
272
-    public function wpinv_add_update_subscription( $invoice_id, $post ) {
273
-        remove_action( 'save_post', __FUNCTION__ );
272
+    public function wpinv_add_update_subscription($invoice_id, $post) {
273
+        remove_action('save_post', __FUNCTION__);
274 274
 
275
-        if ( ! ( ! empty( $invoice_id ) && 'wpi_invoice' == get_post_type( $invoice_id ) ) ) {
275
+        if (!(!empty($invoice_id) && 'wpi_invoice' == get_post_type($invoice_id))) {
276 276
             return;
277 277
         }
278 278
 
279
-        if ( defined( 'DOING_AUTOSAVE' ) ) {
279
+        if (defined('DOING_AUTOSAVE')) {
280 280
             return;
281 281
         }
282 282
 
283
-        if ( ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) {
283
+        if ((defined('DOING_AJAX') && DOING_AJAX) || isset($_REQUEST['bulk_edit'])) {
284 284
             return;
285 285
         }
286 286
 
287
-        $invoice = new WPInv_Invoice( $invoice_id );
287
+        $invoice = new WPInv_Invoice($invoice_id);
288 288
 
289
-        if ( ! ( ! empty( $invoice->ID ) && $invoice->is_recurring() ) ) {
289
+        if (!(!empty($invoice->ID) && $invoice->is_recurring())) {
290 290
             return;
291 291
         }
292 292
 
293
-        $item    = $invoice->get_recurring( true );
294
-        if ( empty( $item ) ) {
293
+        $item = $invoice->get_recurring(true);
294
+        if (empty($item)) {
295 295
             return;
296 296
         }
297 297
 
298
-        $invoice_date       = $invoice->get_invoice_date( false );
298
+        $invoice_date       = $invoice->get_invoice_date(false);
299 299
         $status             = 'pending';
300 300
 
301
-        $period             = $item->get_recurring_period( true );
301
+        $period             = $item->get_recurring_period(true);
302 302
         $interval           = $item->get_recurring_interval();
303 303
         $bill_times         = (int)$item->get_recurring_limit();
304 304
         $add_period         = $interval . ' ' . $period;
305 305
         $trial_period       = '';
306 306
 
307
-        if ( $invoice->is_free_trial() ) {
307
+        if ($invoice->is_free_trial()) {
308 308
             $status         = 'trialling';
309
-            $trial_period   = $item->get_trial_period( true );
309
+            $trial_period   = $item->get_trial_period(true);
310 310
             $free_interval  = $item->get_trial_interval();
311 311
             $trial_period   = $free_interval . ' ' . $trial_period;
312 312
 
313 313
             $add_period     = $trial_period;
314 314
         }
315 315
 
316
-        $expiration         = date_i18n( 'Y-m-d H:i:s', strtotime( '+' . $add_period  . ' 23:59:59', strtotime( $invoice_date ) ) );
316
+        $expiration         = date_i18n('Y-m-d H:i:s', strtotime('+' . $add_period . ' 23:59:59', strtotime($invoice_date)));
317 317
 
318 318
         $args = array(
319 319
             'product_id'        => $item->ID,
@@ -323,7 +323,7 @@  discard block
 block discarded – undo
323 323
             'frequency'         => $interval,
324 324
             'period'            => $period,
325 325
             'initial_amount'    => $invoice->get_total(),
326
-            'recurring_amount'  => $invoice->get_recurring_details( 'total' ),
326
+            'recurring_amount'  => $invoice->get_recurring_details('total'),
327 327
             'bill_times'        => $bill_times,
328 328
             'created'           => $invoice_date,
329 329
             'expiration'        => $expiration,
@@ -333,12 +333,12 @@  discard block
 block discarded – undo
333 333
         );
334 334
 
335 335
         $subs_db      = new WPInv_Subscriptions_DB;
336
-        $subs         = $subs_db->get_subscriptions( array( 'parent_payment_id' => $invoice->ID, 'number' => 1 ) );
337
-        $subscription = reset( $subs );
336
+        $subs         = $subs_db->get_subscriptions(array('parent_payment_id' => $invoice->ID, 'number' => 1));
337
+        $subscription = reset($subs);
338 338
 
339
-        if ( empty( $subscription ) || $subscription->id <= 0 ) {
339
+        if (empty($subscription) || $subscription->id <= 0) {
340 340
             $subscription = new WPInv_Subscription();
341
-            $subscription->create( $args );
341
+            $subscription->create($args);
342 342
         }
343 343
     }
344 344
 }
345 345
\ No newline at end of file
Please login to merge, or discard this patch.
includes/wpinv-invoice-functions.php 1 patch
Spacing   +736 added lines, -736 removed lines patch added patch discarded remove patch
@@ -7,40 +7,40 @@  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_invoice_cart_id() {
15 15
     $wpinv_checkout = wpinv_get_checkout_session();
16 16
     
17
-    if ( !empty( $wpinv_checkout['invoice_id'] ) ) {
17
+    if (!empty($wpinv_checkout['invoice_id'])) {
18 18
         return $wpinv_checkout['invoice_id'];
19 19
     }
20 20
     
21 21
     return NULL;
22 22
 }
23 23
 
24
-function wpinv_insert_invoice( $invoice_data = array(), $wp_error = false ) {
25
-    if ( empty( $invoice_data ) ) {
24
+function wpinv_insert_invoice($invoice_data = array(), $wp_error = false) {
25
+    if (empty($invoice_data)) {
26 26
         return false;
27 27
     }
28 28
     
29
-    if ( !( !empty( $invoice_data['cart_details'] ) && is_array( $invoice_data['cart_details'] ) ) ) {
30
-        return $wp_error ? new WP_Error( 'wpinv_invalid_items', __( 'Invoice must have atleast on item.', 'invoicing' ) ) : 0;
29
+    if (!(!empty($invoice_data['cart_details']) && is_array($invoice_data['cart_details']))) {
30
+        return $wp_error ? new WP_Error('wpinv_invalid_items', __('Invoice must have atleast on item.', 'invoicing')) : 0;
31 31
     }
32 32
     
33
-    if ( empty( $invoice_data['user_id'] ) ) {
33
+    if (empty($invoice_data['user_id'])) {
34 34
         $invoice_data['user_id'] = get_current_user_id();
35 35
     }
36 36
     
37
-    $invoice_data['invoice_id'] = !empty( $invoice_data['invoice_id'] ) ? (int)$invoice_data['invoice_id'] : 0;
37
+    $invoice_data['invoice_id'] = !empty($invoice_data['invoice_id']) ? (int)$invoice_data['invoice_id'] : 0;
38 38
     
39
-    if ( empty( $invoice_data['status'] ) ) {
39
+    if (empty($invoice_data['status'])) {
40 40
         $invoice_data['status'] = 'wpi-pending';
41 41
     }
42 42
     
43
-    if ( empty( $invoice_data['ip'] ) ) {
43
+    if (empty($invoice_data['ip'])) {
44 44
         $invoice_data['ip'] = wpinv_get_ip();
45 45
     }
46 46
 
@@ -51,12 +51,12 @@  discard block
 block discarded – undo
51 51
         'status'        => $invoice_data['status'],
52 52
     );
53 53
 
54
-    $invoice = wpinv_create_invoice( $default_args, $invoice_data, true );
55
-    if ( is_wp_error( $invoice ) ) {
54
+    $invoice = wpinv_create_invoice($default_args, $invoice_data, true);
55
+    if (is_wp_error($invoice)) {
56 56
         return $wp_error ? $invoice : 0;
57 57
     }
58 58
     
59
-    if ( empty( $invoice_data['invoice_id'] ) ) {
59
+    if (empty($invoice_data['invoice_id'])) {
60 60
         //$invoice->add_note( wp_sprintf( __( 'Invoice is created with status %s.', 'invoicing' ), wpinv_status_nicename( $invoice->status ) ) );
61 61
     }
62 62
     
@@ -79,24 +79,24 @@  discard block
 block discarded – undo
79 79
         'discount'              => array(),
80 80
     );
81 81
 
82
-    if ( $user_id = (int)$invoice->get_user_id() ) {
83
-        if ( $user_address = wpinv_get_user_address( $user_id ) ) {
84
-            $default_user_info = wp_parse_args( $user_address, $default_user_info );
82
+    if ($user_id = (int)$invoice->get_user_id()) {
83
+        if ($user_address = wpinv_get_user_address($user_id)) {
84
+            $default_user_info = wp_parse_args($user_address, $default_user_info);
85 85
         }
86 86
     }
87 87
     
88
-    if ( empty( $invoice_data['user_info'] ) ) {
88
+    if (empty($invoice_data['user_info'])) {
89 89
         $invoice_data['user_info'] = array();
90 90
     }
91 91
     
92
-    $user_info = wp_parse_args( $invoice_data['user_info'], $default_user_info );
92
+    $user_info = wp_parse_args($invoice_data['user_info'], $default_user_info);
93 93
     
94
-    if ( empty( $user_info['first_name'] ) ) {
94
+    if (empty($user_info['first_name'])) {
95 95
         $user_info['first_name'] = $default_user_info['first_name'];
96 96
         $user_info['last_name'] = $default_user_info['last_name'];
97 97
     }
98 98
     
99
-    if ( empty( $user_info['country'] ) ) {
99
+    if (empty($user_info['country'])) {
100 100
         $user_info['country'] = $default_user_info['country'];
101 101
         $user_info['state'] = $default_user_info['state'];
102 102
         $user_info['city'] = $default_user_info['city'];
@@ -105,13 +105,13 @@  discard block
 block discarded – undo
105 105
         $user_info['phone'] = $default_user_info['phone'];
106 106
     }
107 107
     
108
-    if ( !empty( $user_info['discount'] ) && !is_array( $user_info['discount'] ) ) {
108
+    if (!empty($user_info['discount']) && !is_array($user_info['discount'])) {
109 109
         $user_info['discount'] = (array)$user_info['discount'];
110 110
     }
111 111
 
112 112
     // Payment details
113 113
     $payment_details = array();
114
-    if ( !empty( $invoice_data['payment_details'] ) ) {
114
+    if (!empty($invoice_data['payment_details'])) {
115 115
         $default_payment_details = array(
116 116
             'gateway'           => 'manual',
117 117
             'gateway_title'     => '',
@@ -119,56 +119,56 @@  discard block
 block discarded – undo
119 119
             'transaction_id'    => '',
120 120
         );
121 121
         
122
-        $payment_details = wp_parse_args( $invoice_data['payment_details'], $default_payment_details );
122
+        $payment_details = wp_parse_args($invoice_data['payment_details'], $default_payment_details);
123 123
         
124
-        if ( empty( $payment_details['gateway'] ) ) {
124
+        if (empty($payment_details['gateway'])) {
125 125
             $payment_details['gateway'] = 'manual';
126 126
         }
127 127
         
128
-        if ( empty( $payment_details['currency'] ) ) {
128
+        if (empty($payment_details['currency'])) {
129 129
             $payment_details['currency'] = wpinv_get_default_country();
130 130
         }
131 131
         
132
-        if ( empty( $payment_details['gateway_title'] ) ) {
133
-            $payment_details['gateway_title'] = wpinv_get_gateway_checkout_label( $payment_details['gateway'] );
132
+        if (empty($payment_details['gateway_title'])) {
133
+            $payment_details['gateway_title'] = wpinv_get_gateway_checkout_label($payment_details['gateway']);
134 134
         }
135 135
     }
136 136
     
137
-    $invoice->set( 'status', ( !empty( $invoice_data['status'] ) ? $invoice_data['status'] : 'wpi-pending' ) );
138
-    
139
-    if ( !empty( $payment_details ) ) {
140
-        $invoice->set( 'currency', $payment_details['currency'] );
141
-        $invoice->set( 'gateway', $payment_details['gateway'] );
142
-        $invoice->set( 'gateway_title', $payment_details['gateway_title'] );
143
-        $invoice->set( 'transaction_id', $payment_details['transaction_id'] );
144
-    }
145
-    
146
-    $invoice->set( 'user_info', $user_info );
147
-    $invoice->set( 'first_name', $user_info['first_name'] );
148
-    $invoice->set( 'last_name', $user_info['last_name'] );
149
-    $invoice->set( 'address', $user_info['address'] );
150
-    $invoice->set( 'company', $user_info['company'] );
151
-    $invoice->set( 'vat_number', $user_info['vat_number'] );
152
-    $invoice->set( 'phone', $user_info['phone'] );
153
-    $invoice->set( 'city', $user_info['city'] );
154
-    $invoice->set( 'country', $user_info['country'] );
155
-    $invoice->set( 'state', $user_info['state'] );
156
-    $invoice->set( 'zip', $user_info['zip'] );
157
-    $invoice->set( 'discounts', $user_info['discount'] );
158
-    $invoice->set( 'ip', ( !empty( $invoice_data['ip'] ) ? $invoice_data['ip'] : wpinv_get_ip() ) );
159
-    $invoice->set( 'mode', ( wpinv_is_test_mode() ? 'test' : 'live' ) );
160
-    $invoice->set( 'parent_invoice', ( !empty( $invoice_data['parent'] ) ? absint( $invoice_data['parent'] ) : '' ) );
161
-    
162
-    if ( !empty( $invoice_data['cart_details'] ) && is_array( $invoice_data['cart_details'] ) ) {
163
-        foreach ( $invoice_data['cart_details'] as $key => $item ) {
164
-            $item_id        = !empty( $item['id'] ) ? $item['id'] : 0;
165
-            $quantity       = !empty( $item['quantity'] ) ? $item['quantity'] : 1;
166
-            $name           = !empty( $item['name'] ) ? $item['name'] : '';
167
-            $item_price     = isset( $item['item_price'] ) ? $item['item_price'] : '';
137
+    $invoice->set('status', (!empty($invoice_data['status']) ? $invoice_data['status'] : 'wpi-pending'));
138
+    
139
+    if (!empty($payment_details)) {
140
+        $invoice->set('currency', $payment_details['currency']);
141
+        $invoice->set('gateway', $payment_details['gateway']);
142
+        $invoice->set('gateway_title', $payment_details['gateway_title']);
143
+        $invoice->set('transaction_id', $payment_details['transaction_id']);
144
+    }
145
+    
146
+    $invoice->set('user_info', $user_info);
147
+    $invoice->set('first_name', $user_info['first_name']);
148
+    $invoice->set('last_name', $user_info['last_name']);
149
+    $invoice->set('address', $user_info['address']);
150
+    $invoice->set('company', $user_info['company']);
151
+    $invoice->set('vat_number', $user_info['vat_number']);
152
+    $invoice->set('phone', $user_info['phone']);
153
+    $invoice->set('city', $user_info['city']);
154
+    $invoice->set('country', $user_info['country']);
155
+    $invoice->set('state', $user_info['state']);
156
+    $invoice->set('zip', $user_info['zip']);
157
+    $invoice->set('discounts', $user_info['discount']);
158
+    $invoice->set('ip', (!empty($invoice_data['ip']) ? $invoice_data['ip'] : wpinv_get_ip()));
159
+    $invoice->set('mode', (wpinv_is_test_mode() ? 'test' : 'live'));
160
+    $invoice->set('parent_invoice', (!empty($invoice_data['parent']) ? absint($invoice_data['parent']) : ''));
161
+    
162
+    if (!empty($invoice_data['cart_details']) && is_array($invoice_data['cart_details'])) {
163
+        foreach ($invoice_data['cart_details'] as $key => $item) {
164
+            $item_id        = !empty($item['id']) ? $item['id'] : 0;
165
+            $quantity       = !empty($item['quantity']) ? $item['quantity'] : 1;
166
+            $name           = !empty($item['name']) ? $item['name'] : '';
167
+            $item_price     = isset($item['item_price']) ? $item['item_price'] : '';
168 168
             
169
-            $post_item  = new WPInv_Item( $item_id );
170
-            if ( !empty( $post_item ) ) {
171
-                $name       = !empty( $name ) ? $name : $post_item->get_name();
169
+            $post_item = new WPInv_Item($item_id);
170
+            if (!empty($post_item)) {
171
+                $name       = !empty($name) ? $name : $post_item->get_name();
172 172
                 $item_price = $item_price !== '' ? $item_price : $post_item->get_price();
173 173
             } else {
174 174
                 continue;
@@ -178,253 +178,253 @@  discard block
 block discarded – undo
178 178
                 'name'          => $name,
179 179
                 'quantity'      => $quantity,
180 180
                 'item_price'    => $item_price,
181
-                'custom_price'  => isset( $item['custom_price'] ) ? $item['custom_price'] : '',
182
-                'tax'           => !empty( $item['tax'] ) ? $item['tax'] : 0.00,
183
-                'discount'      => isset( $item['discount'] ) ? $item['discount'] : 0,
184
-                'meta'          => isset( $item['meta'] ) ? $item['meta'] : array(),
185
-                'fees'          => isset( $item['fees'] ) ? $item['fees'] : array(),
181
+                'custom_price'  => isset($item['custom_price']) ? $item['custom_price'] : '',
182
+                'tax'           => !empty($item['tax']) ? $item['tax'] : 0.00,
183
+                'discount'      => isset($item['discount']) ? $item['discount'] : 0,
184
+                'meta'          => isset($item['meta']) ? $item['meta'] : array(),
185
+                'fees'          => isset($item['fees']) ? $item['fees'] : array(),
186 186
             );
187 187
 
188
-            $invoice->add_item( $item_id, $args );
188
+            $invoice->add_item($item_id, $args);
189 189
         }
190 190
     }
191 191
 
192
-    $invoice->increase_tax( wpinv_get_cart_fee_tax() );
192
+    $invoice->increase_tax(wpinv_get_cart_fee_tax());
193 193
 
194
-    if ( isset( $invoice_data['post_date'] ) ) {
195
-        $invoice->set( 'date', $invoice_data['post_date'] );
194
+    if (isset($invoice_data['post_date'])) {
195
+        $invoice->set('date', $invoice_data['post_date']);
196 196
     }
197 197
     
198 198
     // Invoice due date
199
-    if ( isset( $invoice_data['due_date'] ) ) {
200
-        $invoice->set( 'due_date', $invoice_data['due_date'] );
199
+    if (isset($invoice_data['due_date'])) {
200
+        $invoice->set('due_date', $invoice_data['due_date']);
201 201
     }
202 202
     
203 203
     $invoice->save();
204 204
     
205 205
     // Add notes
206
-    if ( !empty( $invoice_data['private_note'] ) ) {
207
-        $invoice->add_note( $invoice_data['private_note'] );
206
+    if (!empty($invoice_data['private_note'])) {
207
+        $invoice->add_note($invoice_data['private_note']);
208 208
     }
209
-    if ( !empty( $invoice_data['user_note'] ) ) {
210
-        $invoice->add_note( $invoice_data['user_note'], true );
209
+    if (!empty($invoice_data['user_note'])) {
210
+        $invoice->add_note($invoice_data['user_note'], true);
211 211
     }
212 212
     
213
-    do_action( 'wpinv_insert_invoice', $invoice->ID, $invoice_data );
213
+    do_action('wpinv_insert_invoice', $invoice->ID, $invoice_data);
214 214
 
215
-    if ( ! empty( $invoice->ID ) ) {
215
+    if (!empty($invoice->ID)) {
216 216
         global $wpi_userID, $wpinv_ip_address_country;
217 217
         
218 218
         $checkout_session = wpinv_get_checkout_session();
219 219
         
220 220
         $data_session                   = array();
221 221
         $data_session['invoice_id']     = $invoice->ID;
222
-        $data_session['cart_discounts'] = $invoice->get_discounts( true );
222
+        $data_session['cart_discounts'] = $invoice->get_discounts(true);
223 223
         
224
-        wpinv_set_checkout_session( $data_session );
224
+        wpinv_set_checkout_session($data_session);
225 225
         
226 226
         $wpi_userID         = (int)$invoice->get_user_id();
227 227
         
228
-        $_POST['country']   = !empty( $invoice->country ) ? $invoice->country : wpinv_get_default_country();
228
+        $_POST['country']   = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country();
229 229
         $_POST['state']     = $invoice->state;
230 230
 
231
-        $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) );
232
-        $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) );
231
+        $invoice->set('country', sanitize_text_field($_POST['country']));
232
+        $invoice->set('state', sanitize_text_field($_POST['state']));
233 233
         
234 234
         $wpinv_ip_address_country = $invoice->country;
235 235
         
236
-        $invoice = $invoice->recalculate_totals( true );
236
+        $invoice = $invoice->recalculate_totals(true);
237 237
         
238
-        wpinv_set_checkout_session( $checkout_session );
238
+        wpinv_set_checkout_session($checkout_session);
239 239
                     
240 240
         return $invoice;
241 241
     }
242 242
     
243
-    if ( $wp_error ) {
244
-        if ( is_wp_error( $invoice ) ) {
243
+    if ($wp_error) {
244
+        if (is_wp_error($invoice)) {
245 245
             return $invoice;
246 246
         } else {
247
-            return new WP_Error( 'wpinv_insert_invoice_error', __( 'Error in insert invoice.', 'invoicing' ) );
247
+            return new WP_Error('wpinv_insert_invoice_error', __('Error in insert invoice.', 'invoicing'));
248 248
         }
249 249
     } else {
250 250
         return 0;
251 251
     }
252 252
 }
253 253
 
254
-function wpinv_update_invoice( $invoice_data = array(), $wp_error = false ) {
255
-    $invoice_ID = !empty( $invoice_data['ID'] ) ? absint( $invoice_data['ID'] ) : NULL;
254
+function wpinv_update_invoice($invoice_data = array(), $wp_error = false) {
255
+    $invoice_ID = !empty($invoice_data['ID']) ? absint($invoice_data['ID']) : NULL;
256 256
 
257
-    if ( !$invoice_ID ) {
258
-        if ( $wp_error ) {
259
-            return new WP_Error( 'invalid_invoice_id', __( 'Invalid invoice ID.', 'invoicing' ) );
257
+    if (!$invoice_ID) {
258
+        if ($wp_error) {
259
+            return new WP_Error('invalid_invoice_id', __('Invalid invoice ID.', 'invoicing'));
260 260
         }
261 261
         return 0;
262 262
     }
263 263
 
264
-    $invoice = wpinv_get_invoice( $invoice_ID );
264
+    $invoice = wpinv_get_invoice($invoice_ID);
265 265
 
266
-    $recurring_item = $invoice->is_recurring() ? $invoice->get_recurring( true ) : NULL;
266
+    $recurring_item = $invoice->is_recurring() ? $invoice->get_recurring(true) : NULL;
267 267
 
268
-    if ( empty( $invoice->ID ) ) {
269
-        if ( $wp_error ) {
270
-            return new WP_Error( 'invalid_invoice', __( 'Invalid invoice.', 'invoicing' ) );
268
+    if (empty($invoice->ID)) {
269
+        if ($wp_error) {
270
+            return new WP_Error('invalid_invoice', __('Invalid invoice.', 'invoicing'));
271 271
         }
272 272
         return 0;
273 273
     }
274 274
 
275
-    if ( !$invoice->has_status( array( 'wpi-pending' ) ) ) {
276
-        if ( $wp_error ) {
277
-            return new WP_Error( 'invalid_invoice_status', __( 'Only invoice with pending payment is allowed to update.', 'invoicing' ) );
275
+    if (!$invoice->has_status(array('wpi-pending'))) {
276
+        if ($wp_error) {
277
+            return new WP_Error('invalid_invoice_status', __('Only invoice with pending payment is allowed to update.', 'invoicing'));
278 278
         }
279 279
         return 0;
280 280
     }
281 281
 
282 282
     // Invoice status
283
-    if ( !empty( $invoice_data['status'] ) ) {
284
-        $invoice->set( 'status', $invoice_data['status'] );
283
+    if (!empty($invoice_data['status'])) {
284
+        $invoice->set('status', $invoice_data['status']);
285 285
     }
286 286
 
287 287
     // Invoice date
288
-    if ( !empty( $invoice_data['post_date'] ) ) {
289
-        $invoice->set( 'date', $invoice_data['post_date'] );
288
+    if (!empty($invoice_data['post_date'])) {
289
+        $invoice->set('date', $invoice_data['post_date']);
290 290
     }
291 291
 
292 292
     // Invoice due date
293
-    if ( isset( $invoice_data['due_date'] ) ) {
294
-        $invoice->set( 'due_date', $invoice_data['due_date'] );
293
+    if (isset($invoice_data['due_date'])) {
294
+        $invoice->set('due_date', $invoice_data['due_date']);
295 295
     }
296 296
 
297 297
     // Invoice IP address
298
-    if ( !empty( $invoice_data['ip'] ) ) {
299
-        $invoice->set( 'ip', $invoice_data['ip'] );
298
+    if (!empty($invoice_data['ip'])) {
299
+        $invoice->set('ip', $invoice_data['ip']);
300 300
     }
301 301
     
302 302
     // User info
303
-    if ( !empty( $invoice_data['user_info'] ) && is_array( $invoice_data['user_info'] ) ) {
304
-        $user_info = wp_parse_args( $invoice_data['user_info'], $invoice->user_info );
303
+    if (!empty($invoice_data['user_info']) && is_array($invoice_data['user_info'])) {
304
+        $user_info = wp_parse_args($invoice_data['user_info'], $invoice->user_info);
305 305
 
306
-        if ( $discounts = $invoice->get_discounts() ) {
306
+        if ($discounts = $invoice->get_discounts()) {
307 307
             $set_discount = $discounts;
308 308
         } else {
309 309
             $set_discount = '';
310 310
         }
311 311
 
312 312
         // Manage discount
313
-        if ( !empty( $invoice_data['user_info']['discount'] ) ) {
313
+        if (!empty($invoice_data['user_info']['discount'])) {
314 314
             // Remove discount
315
-            if ( $invoice_data['user_info']['discount'] == 'none' ) {
315
+            if ($invoice_data['user_info']['discount'] == 'none') {
316 316
                 $set_discount = '';
317 317
             } else {
318 318
                 $set_discount = $invoice_data['user_info']['discount'];
319 319
             }
320 320
 
321
-            $invoice->set( 'discounts', $set_discount );
321
+            $invoice->set('discounts', $set_discount);
322 322
         }
323 323
 
324 324
         $user_info['discount'] = $set_discount;
325 325
 
326
-        $invoice->set( 'user_info', $user_info );
326
+        $invoice->set('user_info', $user_info);
327 327
     }
328 328
 
329
-    if ( !empty( $invoice_data['cart_details'] ) && is_array( $invoice_data['cart_details'] ) && $cart_details = $invoice_data['cart_details'] ) {
330
-        $remove_items = !empty( $cart_details['remove_items'] ) && is_array( $cart_details['remove_items'] ) ? $cart_details['remove_items'] : array();
329
+    if (!empty($invoice_data['cart_details']) && is_array($invoice_data['cart_details']) && $cart_details = $invoice_data['cart_details']) {
330
+        $remove_items = !empty($cart_details['remove_items']) && is_array($cart_details['remove_items']) ? $cart_details['remove_items'] : array();
331 331
 
332
-        if ( !empty( $remove_items[0]['id'] ) ) {
333
-            foreach ( $remove_items as $item ) {
334
-                $item_id        = !empty( $item['id'] ) ? $item['id'] : 0;
335
-                $quantity       = !empty( $item['quantity'] ) ? $item['quantity'] : 1;
336
-                if ( empty( $item_id ) ) {
332
+        if (!empty($remove_items[0]['id'])) {
333
+            foreach ($remove_items as $item) {
334
+                $item_id        = !empty($item['id']) ? $item['id'] : 0;
335
+                $quantity       = !empty($item['quantity']) ? $item['quantity'] : 1;
336
+                if (empty($item_id)) {
337 337
                     continue;
338 338
                 }
339 339
 
340
-                foreach ( $invoice->cart_details as $cart_index => $cart_item ) {
341
-                    if ( $item_id == $cart_item['id'] ) {
340
+                foreach ($invoice->cart_details as $cart_index => $cart_item) {
341
+                    if ($item_id == $cart_item['id']) {
342 342
                         $args = array(
343 343
                             'id'         => $item_id,
344 344
                             'quantity'   => $quantity,
345 345
                             'cart_index' => $cart_index
346 346
                         );
347 347
 
348
-                        $invoice->remove_item( $item_id, $args );
348
+                        $invoice->remove_item($item_id, $args);
349 349
                         break;
350 350
                     }
351 351
                 }
352 352
             }
353 353
         }
354 354
 
355
-        $add_items = !empty( $cart_details['add_items'] ) && is_array( $cart_details['add_items'] ) ? $cart_details['add_items'] : array();
355
+        $add_items = !empty($cart_details['add_items']) && is_array($cart_details['add_items']) ? $cart_details['add_items'] : array();
356 356
 
357
-        if ( !empty( $add_items[0]['id'] ) ) {
358
-            foreach ( $add_items as $item ) {
359
-                $item_id        = !empty( $item['id'] ) ? $item['id'] : 0;
360
-                $post_item      = new WPInv_Item( $item_id );
361
-                if ( empty( $post_item ) ) {
357
+        if (!empty($add_items[0]['id'])) {
358
+            foreach ($add_items as $item) {
359
+                $item_id        = !empty($item['id']) ? $item['id'] : 0;
360
+                $post_item      = new WPInv_Item($item_id);
361
+                if (empty($post_item)) {
362 362
                     continue;
363 363
                 }
364 364
 
365 365
                 $valid_item = true;
366
-                if ( !empty( $recurring_item ) ) {
367
-                    if ( $recurring_item->ID != $item_id ) {
366
+                if (!empty($recurring_item)) {
367
+                    if ($recurring_item->ID != $item_id) {
368 368
                         $valid_item = false;
369 369
                     }
370
-                } else if ( wpinv_is_recurring_item( $item_id ) ) {
370
+                } else if (wpinv_is_recurring_item($item_id)) {
371 371
                     $valid_item = false;
372 372
                 }
373 373
                 
374
-                if ( !$valid_item ) {
375
-                    if ( $wp_error ) {
376
-                        return new WP_Error( 'invalid_invoice_item', __( 'You can not add item because recurring item must be paid individually!', 'invoicing' ) );
374
+                if (!$valid_item) {
375
+                    if ($wp_error) {
376
+                        return new WP_Error('invalid_invoice_item', __('You can not add item because recurring item must be paid individually!', 'invoicing'));
377 377
                     }
378 378
                     return 0;
379 379
                 }
380 380
 
381
-                $quantity       = !empty( $item['quantity'] ) ? $item['quantity'] : 1;
382
-                $name           = !empty( $item['name'] ) ? $item['name'] : $post_item->get_name();
383
-                $item_price     = isset( $item['item_price'] ) ? $item['item_price'] : $post_item->get_price();
381
+                $quantity       = !empty($item['quantity']) ? $item['quantity'] : 1;
382
+                $name           = !empty($item['name']) ? $item['name'] : $post_item->get_name();
383
+                $item_price     = isset($item['item_price']) ? $item['item_price'] : $post_item->get_price();
384 384
 
385 385
                 $args = array(
386 386
                     'name'          => $name,
387 387
                     'quantity'      => $quantity,
388 388
                     'item_price'    => $item_price,
389
-                    'custom_price'  => isset( $item['custom_price'] ) ? $item['custom_price'] : '',
390
-                    'tax'           => !empty( $item['tax'] ) ? $item['tax'] : 0,
391
-                    'discount'      => isset( $item['discount'] ) ? $item['discount'] : 0,
392
-                    'meta'          => isset( $item['meta'] ) ? $item['meta'] : array(),
393
-                    'fees'          => isset( $item['fees'] ) ? $item['fees'] : array(),
389
+                    'custom_price'  => isset($item['custom_price']) ? $item['custom_price'] : '',
390
+                    'tax'           => !empty($item['tax']) ? $item['tax'] : 0,
391
+                    'discount'      => isset($item['discount']) ? $item['discount'] : 0,
392
+                    'meta'          => isset($item['meta']) ? $item['meta'] : array(),
393
+                    'fees'          => isset($item['fees']) ? $item['fees'] : array(),
394 394
                 );
395 395
 
396
-                $invoice->add_item( $item_id, $args );
396
+                $invoice->add_item($item_id, $args);
397 397
             }
398 398
         }
399 399
     }
400 400
     
401 401
     // Payment details
402
-    if ( !empty( $invoice_data['payment_details'] ) && $payment_details = $invoice_data['payment_details'] ) {
403
-        if ( !empty( $payment_details['gateway'] ) ) {
404
-            $invoice->set( 'gateway', $payment_details['gateway'] );
402
+    if (!empty($invoice_data['payment_details']) && $payment_details = $invoice_data['payment_details']) {
403
+        if (!empty($payment_details['gateway'])) {
404
+            $invoice->set('gateway', $payment_details['gateway']);
405 405
         }
406 406
 
407
-        if ( !empty( $payment_details['transaction_id'] ) ) {
408
-            $invoice->set( 'transaction_id', $payment_details['transaction_id'] );
407
+        if (!empty($payment_details['transaction_id'])) {
408
+            $invoice->set('transaction_id', $payment_details['transaction_id']);
409 409
         }
410 410
     }
411 411
 
412
-    do_action( 'wpinv_pre_update_invoice', $invoice->ID, $invoice_data );
412
+    do_action('wpinv_pre_update_invoice', $invoice->ID, $invoice_data);
413 413
 
414 414
     // Parent invoice
415
-    if ( !empty( $invoice_data['parent'] ) ) {
416
-        $invoice->set( 'parent_invoice', $invoice_data['parent'] );
415
+    if (!empty($invoice_data['parent'])) {
416
+        $invoice->set('parent_invoice', $invoice_data['parent']);
417 417
     }
418 418
 
419 419
     // Save invoice data.
420 420
     $invoice->save();
421 421
     
422
-    if ( empty( $invoice->ID ) || is_wp_error( $invoice ) ) {
423
-        if ( $wp_error ) {
424
-            if ( is_wp_error( $invoice ) ) {
422
+    if (empty($invoice->ID) || is_wp_error($invoice)) {
423
+        if ($wp_error) {
424
+            if (is_wp_error($invoice)) {
425 425
                 return $invoice;
426 426
             } else {
427
-                return new WP_Error( 'wpinv_update_invoice_error', __( 'Error in update invoice.', 'invoicing' ) );
427
+                return new WP_Error('wpinv_update_invoice_error', __('Error in update invoice.', 'invoicing'));
428 428
             }
429 429
         } else {
430 430
             return 0;
@@ -432,13 +432,13 @@  discard block
 block discarded – undo
432 432
     }
433 433
 
434 434
     // Add private note
435
-    if ( !empty( $invoice_data['private_note'] ) ) {
436
-        $invoice->add_note( $invoice_data['private_note'] );
435
+    if (!empty($invoice_data['private_note'])) {
436
+        $invoice->add_note($invoice_data['private_note']);
437 437
     }
438 438
 
439 439
     // Add user note
440
-    if ( !empty( $invoice_data['user_note'] ) ) {
441
-        $invoice->add_note( $invoice_data['user_note'], true );
440
+    if (!empty($invoice_data['user_note'])) {
441
+        $invoice->add_note($invoice_data['user_note'], true);
442 442
     }
443 443
 
444 444
     global $wpi_userID, $wpinv_ip_address_country;
@@ -447,445 +447,445 @@  discard block
 block discarded – undo
447 447
 
448 448
     $data_session                   = array();
449 449
     $data_session['invoice_id']     = $invoice->ID;
450
-    $data_session['cart_discounts'] = $invoice->get_discounts( true );
450
+    $data_session['cart_discounts'] = $invoice->get_discounts(true);
451 451
 
452
-    wpinv_set_checkout_session( $data_session );
452
+    wpinv_set_checkout_session($data_session);
453 453
 
454 454
     $wpi_userID         = (int)$invoice->get_user_id();
455 455
 
456
-    $_POST['country']   = !empty( $invoice->country ) ? $invoice->country : wpinv_get_default_country();
456
+    $_POST['country']   = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country();
457 457
     $_POST['state']     = $invoice->state;
458 458
 
459
-    $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) );
460
-    $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) );
459
+    $invoice->set('country', sanitize_text_field($_POST['country']));
460
+    $invoice->set('state', sanitize_text_field($_POST['state']));
461 461
 
462 462
     $wpinv_ip_address_country = $invoice->country;
463 463
 
464
-    $invoice = $invoice->recalculate_totals( true );
464
+    $invoice = $invoice->recalculate_totals(true);
465 465
 
466
-    do_action( 'wpinv_post_update_invoice', $invoice->ID, $invoice_data );
466
+    do_action('wpinv_post_update_invoice', $invoice->ID, $invoice_data);
467 467
 
468
-    wpinv_set_checkout_session( $checkout_session );
468
+    wpinv_set_checkout_session($checkout_session);
469 469
 
470 470
     return $invoice;
471 471
 }
472 472
 
473
-function wpinv_get_invoice( $invoice_id = 0, $cart = false ) {
474
-    if ( $cart && empty( $invoice_id ) ) {
473
+function wpinv_get_invoice($invoice_id = 0, $cart = false) {
474
+    if ($cart && empty($invoice_id)) {
475 475
         $invoice_id = (int)wpinv_get_invoice_cart_id();
476 476
     }
477 477
 
478
-    $invoice = new WPInv_Invoice( $invoice_id );
478
+    $invoice = new WPInv_Invoice($invoice_id);
479 479
     return $invoice;
480 480
 }
481 481
 
482
-function wpinv_get_invoice_cart( $invoice_id = 0 ) {
483
-    return wpinv_get_invoice( $invoice_id, true );
482
+function wpinv_get_invoice_cart($invoice_id = 0) {
483
+    return wpinv_get_invoice($invoice_id, true);
484 484
 }
485 485
 
486
-function wpinv_get_invoice_description( $invoice_id = 0 ) {
487
-    $invoice = new WPInv_Invoice( $invoice_id );
486
+function wpinv_get_invoice_description($invoice_id = 0) {
487
+    $invoice = new WPInv_Invoice($invoice_id);
488 488
     return $invoice->get_description();
489 489
 }
490 490
 
491
-function wpinv_get_invoice_currency_code( $invoice_id = 0 ) {
492
-    $invoice = new WPInv_Invoice( $invoice_id );
491
+function wpinv_get_invoice_currency_code($invoice_id = 0) {
492
+    $invoice = new WPInv_Invoice($invoice_id);
493 493
     return $invoice->get_currency();
494 494
 }
495 495
 
496
-function wpinv_get_payment_user_email( $invoice_id ) {
497
-    $invoice = new WPInv_Invoice( $invoice_id );
496
+function wpinv_get_payment_user_email($invoice_id) {
497
+    $invoice = new WPInv_Invoice($invoice_id);
498 498
     return $invoice->get_email();
499 499
 }
500 500
 
501
-function wpinv_get_user_id( $invoice_id ) {
502
-    $invoice = new WPInv_Invoice( $invoice_id );
501
+function wpinv_get_user_id($invoice_id) {
502
+    $invoice = new WPInv_Invoice($invoice_id);
503 503
     return $invoice->get_user_id();
504 504
 }
505 505
 
506
-function wpinv_get_invoice_status( $invoice_id, $return_label = false ) {
507
-    $invoice = new WPInv_Invoice( $invoice_id );
506
+function wpinv_get_invoice_status($invoice_id, $return_label = false) {
507
+    $invoice = new WPInv_Invoice($invoice_id);
508 508
     
509
-    return $invoice->get_status( $return_label );
509
+    return $invoice->get_status($return_label);
510 510
 }
511 511
 
512
-function wpinv_get_payment_gateway( $invoice_id, $return_label = false ) {
513
-    $invoice = new WPInv_Invoice( $invoice_id );
512
+function wpinv_get_payment_gateway($invoice_id, $return_label = false) {
513
+    $invoice = new WPInv_Invoice($invoice_id);
514 514
     
515
-    return $invoice->get_gateway( $return_label );
515
+    return $invoice->get_gateway($return_label);
516 516
 }
517 517
 
518
-function wpinv_get_payment_gateway_name( $invoice_id ) {
519
-    $invoice = new WPInv_Invoice( $invoice_id );
518
+function wpinv_get_payment_gateway_name($invoice_id) {
519
+    $invoice = new WPInv_Invoice($invoice_id);
520 520
     
521 521
     return $invoice->get_gateway_title();
522 522
 }
523 523
 
524
-function wpinv_get_payment_transaction_id( $invoice_id ) {
525
-    $invoice = new WPInv_Invoice( $invoice_id );
524
+function wpinv_get_payment_transaction_id($invoice_id) {
525
+    $invoice = new WPInv_Invoice($invoice_id);
526 526
     
527 527
     return $invoice->get_transaction_id();
528 528
 }
529 529
 
530
-function wpinv_get_id_by_transaction_id( $key ) {
530
+function wpinv_get_id_by_transaction_id($key) {
531 531
     global $wpdb;
532 532
 
533
-    $invoice_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = %s LIMIT 1", $key ) );
533
+    $invoice_id = $wpdb->get_var($wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = %s LIMIT 1", $key));
534 534
 
535
-    if ( $invoice_id != NULL )
535
+    if ($invoice_id != NULL)
536 536
         return $invoice_id;
537 537
 
538 538
     return 0;
539 539
 }
540 540
 
541
-function wpinv_get_invoice_meta( $invoice_id = 0, $meta_key = '_wpinv_payment_meta', $single = true ) {
542
-    $invoice = new WPInv_Invoice( $invoice_id );
541
+function wpinv_get_invoice_meta($invoice_id = 0, $meta_key = '_wpinv_payment_meta', $single = true) {
542
+    $invoice = new WPInv_Invoice($invoice_id);
543 543
 
544
-    return $invoice->get_meta( $meta_key, $single );
544
+    return $invoice->get_meta($meta_key, $single);
545 545
 }
546 546
 
547
-function wpinv_update_invoice_meta( $invoice_id = 0, $meta_key = '', $meta_value = '', $prev_value = '' ) {
548
-    $invoice = new WPInv_Invoice( $invoice_id );
547
+function wpinv_update_invoice_meta($invoice_id = 0, $meta_key = '', $meta_value = '', $prev_value = '') {
548
+    $invoice = new WPInv_Invoice($invoice_id);
549 549
     
550
-    return $invoice->update_meta( $meta_key, $meta_value, $prev_value );
550
+    return $invoice->update_meta($meta_key, $meta_value, $prev_value);
551 551
 }
552 552
 
553
-function wpinv_get_items( $invoice_id = 0 ) {
554
-    $invoice            = wpinv_get_invoice( $invoice_id );
553
+function wpinv_get_items($invoice_id = 0) {
554
+    $invoice            = wpinv_get_invoice($invoice_id);
555 555
     
556 556
     $items              = $invoice->get_items();
557 557
     $invoice_currency   = $invoice->get_currency();
558 558
 
559
-    if ( !empty( $items ) && is_array( $items ) ) {
560
-        foreach ( $items as $key => $item ) {
559
+    if (!empty($items) && is_array($items)) {
560
+        foreach ($items as $key => $item) {
561 561
             $items[$key]['currency'] = $invoice_currency;
562 562
 
563
-            if ( !isset( $cart_item['subtotal'] ) ) {
563
+            if (!isset($cart_item['subtotal'])) {
564 564
                 $items[$key]['subtotal'] = $items[$key]['amount'] * 1;
565 565
             }
566 566
         }
567 567
     }
568 568
 
569
-    return apply_filters( 'wpinv_get_items', $items, $invoice_id );
569
+    return apply_filters('wpinv_get_items', $items, $invoice_id);
570 570
 }
571 571
 
572
-function wpinv_get_fees( $invoice_id = 0 ) {
573
-    $invoice           = wpinv_get_invoice( $invoice_id );
572
+function wpinv_get_fees($invoice_id = 0) {
573
+    $invoice           = wpinv_get_invoice($invoice_id);
574 574
     $fees              = $invoice->get_fees();
575 575
 
576
-    return apply_filters( 'wpinv_get_fees', $fees, $invoice_id );
576
+    return apply_filters('wpinv_get_fees', $fees, $invoice_id);
577 577
 }
578 578
 
579
-function wpinv_get_invoice_ip( $invoice_id ) {
580
-    $invoice = new WPInv_Invoice( $invoice_id );
579
+function wpinv_get_invoice_ip($invoice_id) {
580
+    $invoice = new WPInv_Invoice($invoice_id);
581 581
     return $invoice->get_ip();
582 582
 }
583 583
 
584
-function wpinv_get_invoice_user_info( $invoice_id ) {
585
-    $invoice = new WPInv_Invoice( $invoice_id );
584
+function wpinv_get_invoice_user_info($invoice_id) {
585
+    $invoice = new WPInv_Invoice($invoice_id);
586 586
     return $invoice->get_user_info();
587 587
 }
588 588
 
589
-function wpinv_subtotal( $invoice_id = 0, $currency = false ) {
590
-    $invoice = new WPInv_Invoice( $invoice_id );
589
+function wpinv_subtotal($invoice_id = 0, $currency = false) {
590
+    $invoice = new WPInv_Invoice($invoice_id);
591 591
 
592
-    return $invoice->get_subtotal( $currency );
592
+    return $invoice->get_subtotal($currency);
593 593
 }
594 594
 
595
-function wpinv_tax( $invoice_id = 0, $currency = false ) {
596
-    $invoice = new WPInv_Invoice( $invoice_id );
595
+function wpinv_tax($invoice_id = 0, $currency = false) {
596
+    $invoice = new WPInv_Invoice($invoice_id);
597 597
 
598
-    return $invoice->get_tax( $currency );
598
+    return $invoice->get_tax($currency);
599 599
 }
600 600
 
601
-function wpinv_discount( $invoice_id = 0, $currency = false, $dash = false ) {
602
-    $invoice = wpinv_get_invoice( $invoice_id );
601
+function wpinv_discount($invoice_id = 0, $currency = false, $dash = false) {
602
+    $invoice = wpinv_get_invoice($invoice_id);
603 603
 
604
-    return $invoice->get_discount( $currency, $dash );
604
+    return $invoice->get_discount($currency, $dash);
605 605
 }
606 606
 
607
-function wpinv_discount_code( $invoice_id = 0 ) {
608
-    $invoice = new WPInv_Invoice( $invoice_id );
607
+function wpinv_discount_code($invoice_id = 0) {
608
+    $invoice = new WPInv_Invoice($invoice_id);
609 609
 
610 610
     return $invoice->get_discount_code();
611 611
 }
612 612
 
613
-function wpinv_payment_total( $invoice_id = 0, $currency = false ) {
614
-    $invoice = new WPInv_Invoice( $invoice_id );
613
+function wpinv_payment_total($invoice_id = 0, $currency = false) {
614
+    $invoice = new WPInv_Invoice($invoice_id);
615 615
 
616
-    return $invoice->get_total( $currency );
616
+    return $invoice->get_total($currency);
617 617
 }
618 618
 
619
-function wpinv_get_date_created( $invoice_id = 0, $format = '' ) {
620
-    $invoice = new WPInv_Invoice( $invoice_id );
619
+function wpinv_get_date_created($invoice_id = 0, $format = '') {
620
+    $invoice = new WPInv_Invoice($invoice_id);
621 621
 
622
-    $format         = !empty( $format ) ? $format : get_option( 'date_format' );
622
+    $format         = !empty($format) ? $format : get_option('date_format');
623 623
     $date_created   = $invoice->get_created_date();
624
-    $date_created   = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n( $format, strtotime( $date_created ) ) : '';
624
+    $date_created   = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n($format, strtotime($date_created)) : '';
625 625
 
626 626
     return $date_created;
627 627
 }
628 628
 
629
-function wpinv_get_invoice_date( $invoice_id = 0, $format = '', $default = true ) {
630
-    $invoice = new WPInv_Invoice( $invoice_id );
629
+function wpinv_get_invoice_date($invoice_id = 0, $format = '', $default = true) {
630
+    $invoice = new WPInv_Invoice($invoice_id);
631 631
     
632
-    $format         = !empty( $format ) ? $format : get_option( 'date_format' );
632
+    $format         = !empty($format) ? $format : get_option('date_format');
633 633
     $date_completed = $invoice->get_completed_date();
634
-    $invoice_date   = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? date_i18n( $format, strtotime( $date_completed ) ) : '';
635
-    if ( $invoice_date == '' && $default ) {
636
-        $invoice_date   = wpinv_get_date_created( $invoice_id, $format );
634
+    $invoice_date   = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? date_i18n($format, strtotime($date_completed)) : '';
635
+    if ($invoice_date == '' && $default) {
636
+        $invoice_date = wpinv_get_date_created($invoice_id, $format);
637 637
     }
638 638
 
639 639
     return $invoice_date;
640 640
 }
641 641
 
642
-function wpinv_get_invoice_vat_number( $invoice_id = 0 ) {
643
-    $invoice = new WPInv_Invoice( $invoice_id );
642
+function wpinv_get_invoice_vat_number($invoice_id = 0) {
643
+    $invoice = new WPInv_Invoice($invoice_id);
644 644
     
645 645
     return $invoice->vat_number;
646 646
 }
647 647
 
648
-function wpinv_insert_payment_note( $invoice_id = 0, $note = '', $user_type = false, $added_by_user = false, $system = false ) {
649
-    $invoice = new WPInv_Invoice( $invoice_id );
648
+function wpinv_insert_payment_note($invoice_id = 0, $note = '', $user_type = false, $added_by_user = false, $system = false) {
649
+    $invoice = new WPInv_Invoice($invoice_id);
650 650
 
651
-    return $invoice->add_note( $note, $user_type, $added_by_user, $system );
651
+    return $invoice->add_note($note, $user_type, $added_by_user, $system);
652 652
 }
653 653
 
654
-function wpinv_get_invoice_notes( $invoice_id = 0, $type = '' ) {
654
+function wpinv_get_invoice_notes($invoice_id = 0, $type = '') {
655 655
     global $invoicing;
656 656
     
657
-    if ( empty( $invoice_id ) ) {
657
+    if (empty($invoice_id)) {
658 658
         return NULL;
659 659
     }
660 660
     
661
-    $notes = $invoicing->notes->get_invoice_notes( $invoice_id, $type );
661
+    $notes = $invoicing->notes->get_invoice_notes($invoice_id, $type);
662 662
     
663
-    return apply_filters( 'wpinv_invoice_notes', $notes, $invoice_id, $type );
663
+    return apply_filters('wpinv_invoice_notes', $notes, $invoice_id, $type);
664 664
 }
665 665
 
666
-function wpinv_get_payment_key( $invoice_id = 0 ) {
667
-	$invoice = new WPInv_Invoice( $invoice_id );
666
+function wpinv_get_payment_key($invoice_id = 0) {
667
+	$invoice = new WPInv_Invoice($invoice_id);
668 668
     return $invoice->get_key();
669 669
 }
670 670
 
671
-function wpinv_get_invoice_number( $invoice_id = 0 ) {
672
-    $invoice = new WPInv_Invoice( $invoice_id );
671
+function wpinv_get_invoice_number($invoice_id = 0) {
672
+    $invoice = new WPInv_Invoice($invoice_id);
673 673
     return $invoice->get_number();
674 674
 }
675 675
 
676
-function wpinv_get_cart_discountable_subtotal( $code_id ) {
676
+function wpinv_get_cart_discountable_subtotal($code_id) {
677 677
     $cart_items = wpinv_get_cart_content_details();
678 678
     $items      = array();
679 679
 
680
-    $excluded_items = wpinv_get_discount_excluded_items( $code_id );
680
+    $excluded_items = wpinv_get_discount_excluded_items($code_id);
681 681
 
682
-    if( $cart_items ) {
682
+    if ($cart_items) {
683 683
 
684
-        foreach( $cart_items as $item ) {
684
+        foreach ($cart_items as $item) {
685 685
 
686
-            if( ! in_array( $item['id'], $excluded_items ) ) {
687
-                $items[] =  $item;
686
+            if (!in_array($item['id'], $excluded_items)) {
687
+                $items[] = $item;
688 688
             }
689 689
         }
690 690
     }
691 691
 
692
-    $subtotal = wpinv_get_cart_items_subtotal( $items );
692
+    $subtotal = wpinv_get_cart_items_subtotal($items);
693 693
 
694
-    return apply_filters( 'wpinv_get_cart_discountable_subtotal', $subtotal );
694
+    return apply_filters('wpinv_get_cart_discountable_subtotal', $subtotal);
695 695
 }
696 696
 
697
-function wpinv_get_cart_items_subtotal( $items ) {
697
+function wpinv_get_cart_items_subtotal($items) {
698 698
     $subtotal = 0.00;
699 699
 
700
-    if ( is_array( $items ) && ! empty( $items ) ) {
701
-        $prices = wp_list_pluck( $items, 'subtotal' );
700
+    if (is_array($items) && !empty($items)) {
701
+        $prices = wp_list_pluck($items, 'subtotal');
702 702
 
703
-        if( is_array( $prices ) ) {
704
-            $subtotal = array_sum( $prices );
703
+        if (is_array($prices)) {
704
+            $subtotal = array_sum($prices);
705 705
         } else {
706 706
             $subtotal = 0.00;
707 707
         }
708 708
 
709
-        if( $subtotal < 0 ) {
709
+        if ($subtotal < 0) {
710 710
             $subtotal = 0.00;
711 711
         }
712 712
     }
713 713
 
714
-    return apply_filters( 'wpinv_get_cart_items_subtotal', $subtotal );
714
+    return apply_filters('wpinv_get_cart_items_subtotal', $subtotal);
715 715
 }
716 716
 
717
-function wpinv_get_cart_subtotal( $items = array() ) {
718
-    $items    = !empty( $items ) ? $items : wpinv_get_cart_content_details();
719
-    $subtotal = wpinv_get_cart_items_subtotal( $items );
717
+function wpinv_get_cart_subtotal($items = array()) {
718
+    $items    = !empty($items) ? $items : wpinv_get_cart_content_details();
719
+    $subtotal = wpinv_get_cart_items_subtotal($items);
720 720
 
721
-    return apply_filters( 'wpinv_get_cart_subtotal', $subtotal );
721
+    return apply_filters('wpinv_get_cart_subtotal', $subtotal);
722 722
 }
723 723
 
724
-function wpinv_cart_subtotal( $items = array() ) {
725
-    $price = wpinv_price( wpinv_format_amount( wpinv_get_cart_subtotal( $items ) ) );
724
+function wpinv_cart_subtotal($items = array()) {
725
+    $price = wpinv_price(wpinv_format_amount(wpinv_get_cart_subtotal($items)));
726 726
 
727 727
     return $price;
728 728
 }
729 729
 
730
-function wpinv_get_cart_total( $items = array(), $discounts = false, $invoice = array() ) {
731
-    $subtotal  = (float)wpinv_get_cart_subtotal( $items );
732
-    $discounts = (float)wpinv_get_cart_discounted_amount( $items );
733
-    $cart_tax  = (float)wpinv_get_cart_tax( $items );
730
+function wpinv_get_cart_total($items = array(), $discounts = false, $invoice = array()) {
731
+    $subtotal  = (float)wpinv_get_cart_subtotal($items);
732
+    $discounts = (float)wpinv_get_cart_discounted_amount($items);
733
+    $cart_tax  = (float)wpinv_get_cart_tax($items);
734 734
     $fees      = (float)wpinv_get_cart_fee_total();
735
-    if ( !empty( $invoice ) && $invoice->is_free_trial() ) {
735
+    if (!empty($invoice) && $invoice->is_free_trial()) {
736 736
         $total = 0;
737 737
     } else {
738
-        $total     = $subtotal - $discounts + $cart_tax + $fees;
738
+        $total = $subtotal - $discounts + $cart_tax + $fees;
739 739
     }
740 740
 
741
-    if ( $total < 0 ) {
741
+    if ($total < 0) {
742 742
         $total = 0.00;
743 743
     }
744 744
     
745
-    $total = (float)apply_filters( 'wpinv_get_cart_total', $total, $items );
745
+    $total = (float)apply_filters('wpinv_get_cart_total', $total, $items);
746 746
 
747
-    return wpinv_sanitize_amount( $total );
747
+    return wpinv_sanitize_amount($total);
748 748
 }
749 749
 
750
-function wpinv_cart_total( $cart_items = array(), $echo = true, $invoice = array() ) {
750
+function wpinv_cart_total($cart_items = array(), $echo = true, $invoice = array()) {
751 751
     global $cart_total;
752
-    $total = wpinv_price( wpinv_format_amount( wpinv_get_cart_total( $cart_items, NULL, $invoice ) ) );
753
-    $total = apply_filters( 'wpinv_cart_total', $total, $cart_items, $invoice );
752
+    $total = wpinv_price(wpinv_format_amount(wpinv_get_cart_total($cart_items, NULL, $invoice)));
753
+    $total = apply_filters('wpinv_cart_total', $total, $cart_items, $invoice);
754 754
     
755 755
     $cart_total = $total;
756 756
 
757
-    if ( !$echo ) {
757
+    if (!$echo) {
758 758
         return $total;
759 759
     }
760 760
 
761 761
     echo $total;
762 762
 }
763 763
 
764
-function wpinv_get_cart_tax( $items = array() ) {
764
+function wpinv_get_cart_tax($items = array()) {
765 765
     $cart_tax = 0;
766
-    $items    = !empty( $items ) ? $items : wpinv_get_cart_content_details();
766
+    $items    = !empty($items) ? $items : wpinv_get_cart_content_details();
767 767
 
768
-    if ( $items ) {
769
-        $taxes = wp_list_pluck( $items, 'tax' );
768
+    if ($items) {
769
+        $taxes = wp_list_pluck($items, 'tax');
770 770
 
771
-        if( is_array( $taxes ) ) {
772
-            $cart_tax = array_sum( $taxes );
771
+        if (is_array($taxes)) {
772
+            $cart_tax = array_sum($taxes);
773 773
         }
774 774
     }
775 775
 
776 776
     $cart_tax += wpinv_get_cart_fee_tax();
777 777
 
778
-    return apply_filters( 'wpinv_get_cart_tax', wpinv_sanitize_amount( $cart_tax ) );
778
+    return apply_filters('wpinv_get_cart_tax', wpinv_sanitize_amount($cart_tax));
779 779
 }
780 780
 
781
-function wpinv_cart_tax( $items = array(), $echo = false ) {
782
-    $cart_tax = wpinv_get_cart_tax( $items );
783
-    $cart_tax = wpinv_price( wpinv_format_amount( $cart_tax ) );
781
+function wpinv_cart_tax($items = array(), $echo = false) {
782
+    $cart_tax = wpinv_get_cart_tax($items);
783
+    $cart_tax = wpinv_price(wpinv_format_amount($cart_tax));
784 784
 
785
-    $tax = apply_filters( 'wpinv_cart_tax', $cart_tax, $items );
785
+    $tax = apply_filters('wpinv_cart_tax', $cart_tax, $items);
786 786
 
787
-    if ( !$echo ) {
787
+    if (!$echo) {
788 788
         return $tax;
789 789
     }
790 790
 
791 791
     echo $tax;
792 792
 }
793 793
 
794
-function wpinv_get_cart_discount_code( $items = array() ) {
794
+function wpinv_get_cart_discount_code($items = array()) {
795 795
     $invoice = wpinv_get_invoice_cart();
796
-    $cart_discount_code = !empty( $invoice ) ? $invoice->get_discount_code() : '';
796
+    $cart_discount_code = !empty($invoice) ? $invoice->get_discount_code() : '';
797 797
     
798
-    return apply_filters( 'wpinv_get_cart_discount_code', $cart_discount_code );
798
+    return apply_filters('wpinv_get_cart_discount_code', $cart_discount_code);
799 799
 }
800 800
 
801
-function wpinv_cart_discount_code( $items = array(), $echo = false ) {
802
-    $cart_discount_code = wpinv_get_cart_discount_code( $items );
801
+function wpinv_cart_discount_code($items = array(), $echo = false) {
802
+    $cart_discount_code = wpinv_get_cart_discount_code($items);
803 803
 
804
-    if ( $cart_discount_code != '' ) {
804
+    if ($cart_discount_code != '') {
805 805
         $cart_discount_code = ' (' . $cart_discount_code . ')';
806 806
     }
807 807
     
808
-    $discount_code = apply_filters( 'wpinv_cart_discount_code', $cart_discount_code, $items );
808
+    $discount_code = apply_filters('wpinv_cart_discount_code', $cart_discount_code, $items);
809 809
 
810
-    if ( !$echo ) {
810
+    if (!$echo) {
811 811
         return $discount_code;
812 812
     }
813 813
 
814 814
     echo $discount_code;
815 815
 }
816 816
 
817
-function wpinv_get_cart_discount( $items = array() ) {
817
+function wpinv_get_cart_discount($items = array()) {
818 818
     $invoice = wpinv_get_invoice_cart();
819
-    $cart_discount = !empty( $invoice ) ? $invoice->get_discount() : 0;
819
+    $cart_discount = !empty($invoice) ? $invoice->get_discount() : 0;
820 820
     
821
-    return apply_filters( 'wpinv_get_cart_discount', wpinv_sanitize_amount( $cart_discount ), $items );
821
+    return apply_filters('wpinv_get_cart_discount', wpinv_sanitize_amount($cart_discount), $items);
822 822
 }
823 823
 
824
-function wpinv_cart_discount( $items = array(), $echo = false ) {
825
-    $cart_discount = wpinv_get_cart_discount( $items );
826
-    $cart_discount = wpinv_price( wpinv_format_amount( $cart_discount ) );
824
+function wpinv_cart_discount($items = array(), $echo = false) {
825
+    $cart_discount = wpinv_get_cart_discount($items);
826
+    $cart_discount = wpinv_price(wpinv_format_amount($cart_discount));
827 827
 
828
-    $discount = apply_filters( 'wpinv_cart_discount', $cart_discount, $items );
828
+    $discount = apply_filters('wpinv_cart_discount', $cart_discount, $items);
829 829
 
830
-    if ( !$echo ) {
830
+    if (!$echo) {
831 831
         return $discount;
832 832
     }
833 833
 
834 834
     echo $discount;
835 835
 }
836 836
 
837
-function wpinv_get_cart_fees( $type = 'all', $item_id = 0 ) {
838
-    $item = new WPInv_Item( $item_id );
837
+function wpinv_get_cart_fees($type = 'all', $item_id = 0) {
838
+    $item = new WPInv_Item($item_id);
839 839
     
840
-    return $item->get_fees( $type, $item_id );
840
+    return $item->get_fees($type, $item_id);
841 841
 }
842 842
 
843 843
 function wpinv_get_cart_fee_total() {
844
-    $total  = 0;
844
+    $total = 0;
845 845
     $fees = wpinv_get_cart_fees();
846 846
     
847
-    if ( $fees ) {
848
-        foreach ( $fees as $fee_id => $fee ) {
847
+    if ($fees) {
848
+        foreach ($fees as $fee_id => $fee) {
849 849
             $total += $fee['amount'];
850 850
         }
851 851
     }
852 852
 
853
-    return apply_filters( 'wpinv_get_cart_fee_total', $total );
853
+    return apply_filters('wpinv_get_cart_fee_total', $total);
854 854
 }
855 855
 
856 856
 function wpinv_get_cart_fee_tax() {
857 857
     $tax  = 0;
858 858
     $fees = wpinv_get_cart_fees();
859 859
 
860
-    if ( $fees ) {
861
-        foreach ( $fees as $fee_id => $fee ) {
862
-            if( ! empty( $fee['no_tax'] ) ) {
860
+    if ($fees) {
861
+        foreach ($fees as $fee_id => $fee) {
862
+            if (!empty($fee['no_tax'])) {
863 863
                 continue;
864 864
             }
865 865
 
866
-            $tax += wpinv_calculate_tax( $fee['amount'] );
866
+            $tax += wpinv_calculate_tax($fee['amount']);
867 867
         }
868 868
     }
869 869
 
870
-    return apply_filters( 'wpinv_get_cart_fee_tax', $tax );
870
+    return apply_filters('wpinv_get_cart_fee_tax', $tax);
871 871
 }
872 872
 
873 873
 function wpinv_cart_has_recurring_item() {
874 874
     $cart_items = wpinv_get_cart_contents();
875 875
     
876
-    if ( empty( $cart_items ) ) {
876
+    if (empty($cart_items)) {
877 877
         return false;
878 878
     }
879 879
     
880 880
     $has_subscription = false;
881
-    foreach( $cart_items as $cart_item ) {
882
-        if ( !empty( $cart_item['id'] ) && wpinv_is_recurring_item( $cart_item['id'] )  ) {
881
+    foreach ($cart_items as $cart_item) {
882
+        if (!empty($cart_item['id']) && wpinv_is_recurring_item($cart_item['id'])) {
883 883
             $has_subscription = true;
884 884
             break;
885 885
         }
886 886
     }
887 887
     
888
-    return apply_filters( 'wpinv_cart_has_recurring_item', $has_subscription, $cart_items );
888
+    return apply_filters('wpinv_cart_has_recurring_item', $has_subscription, $cart_items);
889 889
 }
890 890
 
891 891
 function wpinv_cart_has_free_trial() {
@@ -893,94 +893,94 @@  discard block
 block discarded – undo
893 893
     
894 894
     $free_trial = false;
895 895
     
896
-    if ( !empty( $invoice ) && $invoice->is_free_trial() ) {
896
+    if (!empty($invoice) && $invoice->is_free_trial()) {
897 897
         $free_trial = true;
898 898
     }
899 899
     
900
-    return apply_filters( 'wpinv_cart_has_free_trial', $free_trial, $invoice );
900
+    return apply_filters('wpinv_cart_has_free_trial', $free_trial, $invoice);
901 901
 }
902 902
 
903 903
 function wpinv_get_cart_contents() {
904 904
     $cart_details = wpinv_get_cart_details();
905 905
     
906
-    return apply_filters( 'wpinv_get_cart_contents', $cart_details );
906
+    return apply_filters('wpinv_get_cart_contents', $cart_details);
907 907
 }
908 908
 
909 909
 function wpinv_get_cart_content_details() {
910 910
     global $wpinv_euvat, $wpi_current_id, $wpi_item_id, $wpinv_is_last_cart_item, $wpinv_flat_discount_total;
911 911
     $cart_items = wpinv_get_cart_contents();
912 912
     
913
-    if ( empty( $cart_items ) ) {
913
+    if (empty($cart_items)) {
914 914
         return false;
915 915
     }
916 916
     $invoice = wpinv_get_invoice_cart();
917 917
 
918 918
     $details = array();
919
-    $length  = count( $cart_items ) - 1;
919
+    $length  = count($cart_items) - 1;
920 920
     
921
-    if ( empty( $_POST['country'] ) ) {
921
+    if (empty($_POST['country'])) {
922 922
         $_POST['country'] = $invoice->country;
923 923
     }
924
-    if ( !isset( $_POST['state'] ) ) {
924
+    if (!isset($_POST['state'])) {
925 925
         $_POST['state'] = $invoice->state;
926 926
     }
927 927
 
928
-    foreach( $cart_items as $key => $item ) {
929
-        $item_id            = isset( $item['id'] ) ? sanitize_text_field( $item['id'] ) : '';
930
-        if ( empty( $item_id ) ) {
928
+    foreach ($cart_items as $key => $item) {
929
+        $item_id = isset($item['id']) ? sanitize_text_field($item['id']) : '';
930
+        if (empty($item_id)) {
931 931
             continue;
932 932
         }
933 933
         
934 934
         $wpi_current_id         = $invoice->ID;
935 935
         $wpi_item_id            = $item_id;
936 936
         
937
-        if ( isset( $item['custom_price'] ) && $item['custom_price'] !== '' ) {
937
+        if (isset($item['custom_price']) && $item['custom_price'] !== '') {
938 938
             $item_price = $item['custom_price'];
939 939
         } else {
940
-            if ( isset( $item['item_price'] ) && $item['item_price'] !== '' && $item['item_price'] !== false ) {
940
+            if (isset($item['item_price']) && $item['item_price'] !== '' && $item['item_price'] !== false) {
941 941
                 $item_price = $item['item_price'];
942 942
             } else {
943
-                $item_price = wpinv_get_item_price( $item_id );
943
+                $item_price = wpinv_get_item_price($item_id);
944 944
             }
945 945
         }
946
-        $discount           = wpinv_get_cart_item_discount_amount( $item );
947
-        $discount           = apply_filters( 'wpinv_get_cart_content_details_item_discount_amount', $discount, $item );
948
-        $quantity           = wpinv_get_cart_item_quantity( $item );
949
-        $fees               = wpinv_get_cart_fees( 'fee', $item_id );
946
+        $discount           = wpinv_get_cart_item_discount_amount($item);
947
+        $discount           = apply_filters('wpinv_get_cart_content_details_item_discount_amount', $discount, $item);
948
+        $quantity           = wpinv_get_cart_item_quantity($item);
949
+        $fees               = wpinv_get_cart_fees('fee', $item_id);
950 950
         
951 951
         $subtotal           = $item_price * $quantity;
952
-        $tax_rate           = wpinv_get_tax_rate( $_POST['country'], $_POST['state'], $wpi_item_id );
953
-        $tax_class          = $wpinv_euvat->get_item_class( $item_id );
954
-        $tax                = wpinv_get_cart_item_tax( $item_id, $subtotal - $discount );
952
+        $tax_rate           = wpinv_get_tax_rate($_POST['country'], $_POST['state'], $wpi_item_id);
953
+        $tax_class          = $wpinv_euvat->get_item_class($item_id);
954
+        $tax                = wpinv_get_cart_item_tax($item_id, $subtotal - $discount);
955 955
         
956
-        if ( wpinv_prices_include_tax() ) {
957
-            $subtotal -= wpinv_round_amount( $tax );
956
+        if (wpinv_prices_include_tax()) {
957
+            $subtotal -= wpinv_round_amount($tax);
958 958
         }
959 959
         
960
-        $total              = $subtotal - $discount + $tax;
960
+        $total = $subtotal - $discount + $tax;
961 961
         
962 962
         // Do not allow totals to go negatve
963
-        if( $total < 0 ) {
963
+        if ($total < 0) {
964 964
             $total = 0;
965 965
         }
966 966
         
967
-        $details[ $key ]  = array(
967
+        $details[$key] = array(
968 968
             'id'                => $item_id,
969
-            'name'              => !empty($item['name']) ? $item['name'] : get_the_title( $item_id ),
970
-            'item_price'        => wpinv_round_amount( $item_price ),
971
-            'custom_price'      => isset( $item['custom_price'] ) ? $item['custom_price'] : '',
969
+            'name'              => !empty($item['name']) ? $item['name'] : get_the_title($item_id),
970
+            'item_price'        => wpinv_round_amount($item_price),
971
+            'custom_price'      => isset($item['custom_price']) ? $item['custom_price'] : '',
972 972
             'quantity'          => $quantity,
973
-            'discount'          => wpinv_round_amount( $discount ),
974
-            'subtotal'          => wpinv_round_amount( $subtotal ),
975
-            'tax'               => wpinv_round_amount( $tax ),
976
-            'price'             => wpinv_round_amount( $total ),
973
+            'discount'          => wpinv_round_amount($discount),
974
+            'subtotal'          => wpinv_round_amount($subtotal),
975
+            'tax'               => wpinv_round_amount($tax),
976
+            'price'             => wpinv_round_amount($total),
977 977
             'vat_rates_class'   => $tax_class,
978 978
             'vat_rate'          => $tax_rate,
979
-            'meta'              => isset( $item['meta'] ) ? $item['meta'] : array(),
979
+            'meta'              => isset($item['meta']) ? $item['meta'] : array(),
980 980
             'fees'              => $fees,
981 981
         );
982 982
         
983
-        if ( $wpinv_is_last_cart_item ) {
983
+        if ($wpinv_is_last_cart_item) {
984 984
             $wpinv_is_last_cart_item   = false;
985 985
             $wpinv_flat_discount_total = 0.00;
986 986
         }
@@ -989,60 +989,60 @@  discard block
 block discarded – undo
989 989
     return $details;
990 990
 }
991 991
 
992
-function wpinv_get_cart_details( $invoice_id = 0 ) {
992
+function wpinv_get_cart_details($invoice_id = 0) {
993 993
     global $ajax_cart_details;
994 994
 
995
-    $invoice      = wpinv_get_invoice_cart( $invoice_id );
996
-    $cart_details = !empty( $ajax_cart_details ) ? $ajax_cart_details : $invoice->cart_details;
995
+    $invoice      = wpinv_get_invoice_cart($invoice_id);
996
+    $cart_details = !empty($ajax_cart_details) ? $ajax_cart_details : $invoice->cart_details;
997 997
 
998 998
     $invoice_currency = $invoice->currency;
999 999
 
1000
-    if ( ! empty( $cart_details ) && is_array( $cart_details ) ) {
1001
-        foreach ( $cart_details as $key => $cart_item ) {
1002
-            $cart_details[ $key ]['currency'] = $invoice_currency;
1000
+    if (!empty($cart_details) && is_array($cart_details)) {
1001
+        foreach ($cart_details as $key => $cart_item) {
1002
+            $cart_details[$key]['currency'] = $invoice_currency;
1003 1003
 
1004
-            if ( ! isset( $cart_item['subtotal'] ) ) {
1005
-                $cart_details[ $key ]['subtotal'] = $cart_item['price'];
1004
+            if (!isset($cart_item['subtotal'])) {
1005
+                $cart_details[$key]['subtotal'] = $cart_item['price'];
1006 1006
             }
1007 1007
         }
1008 1008
     }
1009 1009
 
1010
-    return apply_filters( 'wpinv_get_cart_details', $cart_details, $invoice_id );
1010
+    return apply_filters('wpinv_get_cart_details', $cart_details, $invoice_id);
1011 1011
 }
1012 1012
 
1013
-function wpinv_record_status_change( $invoice_id, $new_status, $old_status ) {
1014
-    if ( 'wpi_invoice' != get_post_type( $invoice_id ) ) {
1013
+function wpinv_record_status_change($invoice_id, $new_status, $old_status) {
1014
+    if ('wpi_invoice' != get_post_type($invoice_id)) {
1015 1015
         return;
1016 1016
     }
1017 1017
 
1018
-    $invoice    = wpinv_get_invoice( $invoice_id );
1018
+    $invoice    = wpinv_get_invoice($invoice_id);
1019 1019
     
1020
-    $old_status = wpinv_status_nicename( $old_status );
1021
-    $new_status = wpinv_status_nicename( $new_status );
1020
+    $old_status = wpinv_status_nicename($old_status);
1021
+    $new_status = wpinv_status_nicename($new_status);
1022 1022
 
1023
-    $status_change = sprintf( __( 'Invoice status changed from %s to %s', 'invoicing' ), $old_status, $new_status );
1023
+    $status_change = sprintf(__('Invoice status changed from %s to %s', 'invoicing'), $old_status, $new_status);
1024 1024
     
1025 1025
     // Add note
1026
-    return $invoice->add_note( $status_change, false, false, true );
1026
+    return $invoice->add_note($status_change, false, false, true);
1027 1027
 }
1028
-add_action( 'wpinv_update_status', 'wpinv_record_status_change', 100, 3 );
1028
+add_action('wpinv_update_status', 'wpinv_record_status_change', 100, 3);
1029 1029
 
1030
-function wpinv_complete_payment( $invoice_id, $new_status, $old_status ) {
1030
+function wpinv_complete_payment($invoice_id, $new_status, $old_status) {
1031 1031
     global $wpi_has_free_trial;
1032 1032
     
1033 1033
     $wpi_has_free_trial = false;
1034 1034
     
1035
-    if ( $old_status == 'publish' ) {
1035
+    if ($old_status == 'publish') {
1036 1036
         return; // Make sure that payments are only paid once
1037 1037
     }
1038 1038
 
1039 1039
     // Make sure the payment completion is only processed when new status is paid
1040
-    if ( $new_status != 'publish' ) {
1040
+    if ($new_status != 'publish') {
1041 1041
         return;
1042 1042
     }
1043 1043
 
1044
-    $invoice = new WPInv_Invoice( $invoice_id );
1045
-    if ( empty( $invoice ) ) {
1044
+    $invoice = new WPInv_Invoice($invoice_id);
1045
+    if (empty($invoice)) {
1046 1046
         return;
1047 1047
     }
1048 1048
 
@@ -1050,58 +1050,58 @@  discard block
 block discarded – undo
1050 1050
     $completed_date = $invoice->completed_date;
1051 1051
     $cart_details   = $invoice->cart_details;
1052 1052
 
1053
-    do_action( 'wpinv_pre_complete_payment', $invoice_id );
1053
+    do_action('wpinv_pre_complete_payment', $invoice_id);
1054 1054
 
1055
-    if ( is_array( $cart_details ) ) {
1055
+    if (is_array($cart_details)) {
1056 1056
         // Increase purchase count and earnings
1057
-        foreach ( $cart_details as $cart_index => $item ) {
1057
+        foreach ($cart_details as $cart_index => $item) {
1058 1058
             // Ensure these actions only run once, ever
1059
-            if ( empty( $completed_date ) ) {
1060
-                do_action( 'wpinv_complete_item_payment', $item['id'], $invoice_id, $item, $cart_index );
1059
+            if (empty($completed_date)) {
1060
+                do_action('wpinv_complete_item_payment', $item['id'], $invoice_id, $item, $cart_index);
1061 1061
             }
1062 1062
         }
1063 1063
     }
1064 1064
     
1065 1065
     // Check for discount codes and increment their use counts
1066
-    if ( $discounts = $invoice->get_discounts( true ) ) {
1067
-        if( ! empty( $discounts ) ) {
1068
-            foreach( $discounts as $code ) {
1069
-                wpinv_increase_discount_usage( $code );
1066
+    if ($discounts = $invoice->get_discounts(true)) {
1067
+        if (!empty($discounts)) {
1068
+            foreach ($discounts as $code) {
1069
+                wpinv_increase_discount_usage($code);
1070 1070
             }
1071 1071
         }
1072 1072
     }
1073 1073
     
1074 1074
     // Ensure this action only runs once ever
1075
-    if( empty( $completed_date ) ) {
1075
+    if (empty($completed_date)) {
1076 1076
         // Save the completed date
1077
-        $invoice->set( 'completed_date', current_time( 'mysql', 0 ) );
1077
+        $invoice->set('completed_date', current_time('mysql', 0));
1078 1078
         $invoice->save();
1079 1079
 
1080
-        do_action( 'wpinv_complete_payment', $invoice_id );
1080
+        do_action('wpinv_complete_payment', $invoice_id);
1081 1081
     }
1082 1082
 
1083 1083
     // Empty the shopping cart
1084 1084
     wpinv_empty_cart();
1085 1085
 }
1086
-add_action( 'wpinv_update_status', 'wpinv_complete_payment', 100, 3 );
1086
+add_action('wpinv_update_status', 'wpinv_complete_payment', 100, 3);
1087 1087
 
1088
-function wpinv_update_payment_status( $invoice_id, $new_status = 'publish' ) {    
1089
-    $invoice = !empty( $invoice_id ) && is_object( $invoice_id ) ? $invoice_id : wpinv_get_invoice( (int)$invoice_id );
1088
+function wpinv_update_payment_status($invoice_id, $new_status = 'publish') {    
1089
+    $invoice = !empty($invoice_id) && is_object($invoice_id) ? $invoice_id : wpinv_get_invoice((int)$invoice_id);
1090 1090
     
1091
-    if ( empty( $invoice ) ) {
1091
+    if (empty($invoice)) {
1092 1092
         return false;
1093 1093
     }
1094 1094
     
1095
-    return $invoice->update_status( $new_status );
1095
+    return $invoice->update_status($new_status);
1096 1096
 }
1097 1097
 
1098
-function wpinv_cart_has_fees( $type = 'all' ) {
1098
+function wpinv_cart_has_fees($type = 'all') {
1099 1099
     return false;
1100 1100
 }
1101 1101
 
1102 1102
 function wpinv_validate_checkout_fields() {    
1103 1103
     // Check if there is $_POST
1104
-    if ( empty( $_POST ) ) {
1104
+    if (empty($_POST)) {
1105 1105
         return false;
1106 1106
     }
1107 1107
     
@@ -1113,7 +1113,7 @@  discard block
 block discarded – undo
1113 1113
     );
1114 1114
     
1115 1115
     // Validate agree to terms
1116
-    if ( wpinv_get_option( 'show_agree_to_terms', false ) ) {
1116
+    if (wpinv_get_option('show_agree_to_terms', false)) {
1117 1117
         wpinv_checkout_validate_agree_to_terms();
1118 1118
     }
1119 1119
     
@@ -1129,26 +1129,26 @@  discard block
 block discarded – undo
1129 1129
     
1130 1130
     $invoice = wpinv_get_invoice_cart();
1131 1131
     $has_subscription = $invoice->is_recurring();
1132
-    if ( empty( $invoice ) ) {
1133
-        wpinv_set_error( 'invalid_invoice', __( 'Your cart is empty.', 'invoicing' ) );
1132
+    if (empty($invoice)) {
1133
+        wpinv_set_error('invalid_invoice', __('Your cart is empty.', 'invoicing'));
1134 1134
         return $gateway;
1135 1135
     }
1136 1136
 
1137 1137
     // Check if a gateway value is present
1138
-    if ( !empty( $_REQUEST['wpi-gateway'] ) ) {
1139
-        $gateway = sanitize_text_field( $_REQUEST['wpi-gateway'] );
1138
+    if (!empty($_REQUEST['wpi-gateway'])) {
1139
+        $gateway = sanitize_text_field($_REQUEST['wpi-gateway']);
1140 1140
 
1141
-        if ( $invoice->is_free() ) {
1141
+        if ($invoice->is_free()) {
1142 1142
             $gateway = 'manual';
1143
-        } elseif ( !wpinv_is_gateway_active( $gateway ) ) {
1144
-            wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway is not enabled', 'invoicing' ) );
1145
-        } elseif ( $has_subscription && !wpinv_gateway_support_subscription( $gateway ) ) {
1146
-            wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway doesnot support subscription payment', 'invoicing' ) );
1143
+        } elseif (!wpinv_is_gateway_active($gateway)) {
1144
+            wpinv_set_error('invalid_gateway', __('The selected payment gateway is not enabled', 'invoicing'));
1145
+        } elseif ($has_subscription && !wpinv_gateway_support_subscription($gateway)) {
1146
+            wpinv_set_error('invalid_gateway', __('The selected payment gateway doesnot support subscription payment', 'invoicing'));
1147 1147
         }
1148 1148
     }
1149 1149
 
1150
-    if ( $has_subscription && count( wpinv_get_cart_contents() ) > 1 ) {
1151
-        wpinv_set_error( 'subscription_invalid', __( 'Only one subscription may be purchased through payment per checkout.', 'invoicing' ) );
1150
+    if ($has_subscription && count(wpinv_get_cart_contents()) > 1) {
1151
+        wpinv_set_error('subscription_invalid', __('Only one subscription may be purchased through payment per checkout.', 'invoicing'));
1152 1152
     }
1153 1153
 
1154 1154
     return $gateway;
@@ -1162,10 +1162,10 @@  discard block
 block discarded – undo
1162 1162
     
1163 1163
     $error = false;
1164 1164
     // If we have discounts, loop through them
1165
-    if ( ! empty( $discounts ) ) {
1166
-        foreach ( $discounts as $discount ) {
1165
+    if (!empty($discounts)) {
1166
+        foreach ($discounts as $discount) {
1167 1167
             // Check if valid
1168
-            if (  !wpinv_is_discount_valid( $discount, (int)$wpi_cart->get_user_id() ) ) {
1168
+            if (!wpinv_is_discount_valid($discount, (int)$wpi_cart->get_user_id())) {
1169 1169
                 // Discount is not valid
1170 1170
                 $error = true;
1171 1171
             }
@@ -1175,20 +1175,20 @@  discard block
 block discarded – undo
1175 1175
         return NULL;
1176 1176
     }
1177 1177
 
1178
-    if ( $error && !wpinv_get_errors() ) {
1179
-        wpinv_set_error( 'invalid_discount', __( 'Discount code you entered is invalid', 'invoicing' ) );
1178
+    if ($error && !wpinv_get_errors()) {
1179
+        wpinv_set_error('invalid_discount', __('Discount code you entered is invalid', 'invoicing'));
1180 1180
     }
1181 1181
 
1182
-    return implode( ',', $discounts );
1182
+    return implode(',', $discounts);
1183 1183
 }
1184 1184
 
1185 1185
 function wpinv_checkout_validate_cc() {
1186 1186
     $card_data = wpinv_checkout_get_cc_info();
1187 1187
 
1188 1188
     // Validate the card zip
1189
-    if ( !empty( $card_data['wpinv_zip'] ) ) {
1190
-        if ( !wpinv_checkout_validate_cc_zip( $card_data['wpinv_zip'], $card_data['wpinv_country'] ) ) {
1191
-            wpinv_set_error( 'invalid_cc_zip', __( 'The zip / postcode you entered for your billing address is invalid', 'invoicing' ) );
1189
+    if (!empty($card_data['wpinv_zip'])) {
1190
+        if (!wpinv_checkout_validate_cc_zip($card_data['wpinv_zip'], $card_data['wpinv_country'])) {
1191
+            wpinv_set_error('invalid_cc_zip', __('The zip / postcode you entered for your billing address is invalid', 'invoicing'));
1192 1192
         }
1193 1193
     }
1194 1194
 
@@ -1198,28 +1198,28 @@  discard block
 block discarded – undo
1198 1198
 
1199 1199
 function wpinv_checkout_get_cc_info() {
1200 1200
 	$cc_info = array();
1201
-	$cc_info['card_name']      = isset( $_POST['card_name'] )       ? sanitize_text_field( $_POST['card_name'] )       : '';
1202
-	$cc_info['card_number']    = isset( $_POST['card_number'] )     ? sanitize_text_field( $_POST['card_number'] )     : '';
1203
-	$cc_info['card_cvc']       = isset( $_POST['card_cvc'] )        ? sanitize_text_field( $_POST['card_cvc'] )        : '';
1204
-	$cc_info['card_exp_month'] = isset( $_POST['card_exp_month'] )  ? sanitize_text_field( $_POST['card_exp_month'] )  : '';
1205
-	$cc_info['card_exp_year']  = isset( $_POST['card_exp_year'] )   ? sanitize_text_field( $_POST['card_exp_year'] )   : '';
1206
-	$cc_info['card_address']   = isset( $_POST['wpinv_address'] )  ? sanitize_text_field( $_POST['wpinv_address'] ) : '';
1207
-	$cc_info['card_city']      = isset( $_POST['wpinv_city'] )     ? sanitize_text_field( $_POST['wpinv_city'] )    : '';
1208
-	$cc_info['card_state']     = isset( $_POST['wpinv_state'] )    ? sanitize_text_field( $_POST['wpinv_state'] )   : '';
1209
-	$cc_info['card_country']   = isset( $_POST['wpinv_country'] )  ? sanitize_text_field( $_POST['wpinv_country'] ) : '';
1210
-	$cc_info['card_zip']       = isset( $_POST['wpinv_zip'] )      ? sanitize_text_field( $_POST['wpinv_zip'] )     : '';
1201
+	$cc_info['card_name']      = isset($_POST['card_name']) ? sanitize_text_field($_POST['card_name']) : '';
1202
+	$cc_info['card_number']    = isset($_POST['card_number']) ? sanitize_text_field($_POST['card_number']) : '';
1203
+	$cc_info['card_cvc']       = isset($_POST['card_cvc']) ? sanitize_text_field($_POST['card_cvc']) : '';
1204
+	$cc_info['card_exp_month'] = isset($_POST['card_exp_month']) ? sanitize_text_field($_POST['card_exp_month']) : '';
1205
+	$cc_info['card_exp_year']  = isset($_POST['card_exp_year']) ? sanitize_text_field($_POST['card_exp_year']) : '';
1206
+	$cc_info['card_address']   = isset($_POST['wpinv_address']) ? sanitize_text_field($_POST['wpinv_address']) : '';
1207
+	$cc_info['card_city']      = isset($_POST['wpinv_city']) ? sanitize_text_field($_POST['wpinv_city']) : '';
1208
+	$cc_info['card_state']     = isset($_POST['wpinv_state']) ? sanitize_text_field($_POST['wpinv_state']) : '';
1209
+	$cc_info['card_country']   = isset($_POST['wpinv_country']) ? sanitize_text_field($_POST['wpinv_country']) : '';
1210
+	$cc_info['card_zip']       = isset($_POST['wpinv_zip']) ? sanitize_text_field($_POST['wpinv_zip']) : '';
1211 1211
 
1212 1212
 	// Return cc info
1213 1213
 	return $cc_info;
1214 1214
 }
1215 1215
 
1216
-function wpinv_checkout_validate_cc_zip( $zip = 0, $country_code = '' ) {
1216
+function wpinv_checkout_validate_cc_zip($zip = 0, $country_code = '') {
1217 1217
     $ret = false;
1218 1218
 
1219
-    if ( empty( $zip ) || empty( $country_code ) )
1219
+    if (empty($zip) || empty($country_code))
1220 1220
         return $ret;
1221 1221
 
1222
-    $country_code = strtoupper( $country_code );
1222
+    $country_code = strtoupper($country_code);
1223 1223
 
1224 1224
     $zip_regex = array(
1225 1225
         "AD" => "AD\d{3}",
@@ -1379,17 +1379,17 @@  discard block
 block discarded – undo
1379 1379
         "ZM" => "\d{5}"
1380 1380
     );
1381 1381
 
1382
-    if ( ! isset ( $zip_regex[ $country_code ] ) || preg_match( "/" . $zip_regex[ $country_code ] . "/i", $zip ) )
1382
+    if (!isset ($zip_regex[$country_code]) || preg_match("/" . $zip_regex[$country_code] . "/i", $zip))
1383 1383
         $ret = true;
1384 1384
 
1385
-    return apply_filters( 'wpinv_is_zip_valid', $ret, $zip, $country_code );
1385
+    return apply_filters('wpinv_is_zip_valid', $ret, $zip, $country_code);
1386 1386
 }
1387 1387
 
1388 1388
 function wpinv_checkout_validate_agree_to_terms() {
1389 1389
     // Validate agree to terms
1390
-    if ( ! isset( $_POST['wpi_agree_to_terms'] ) || $_POST['wpi_agree_to_terms'] != 1 ) {
1390
+    if (!isset($_POST['wpi_agree_to_terms']) || $_POST['wpi_agree_to_terms'] != 1) {
1391 1391
         // User did not agree
1392
-        wpinv_set_error( 'agree_to_terms', apply_filters( 'wpinv_agree_to_terms_text', __( 'You must agree to the terms of use', 'invoicing' ) ) );
1392
+        wpinv_set_error('agree_to_terms', apply_filters('wpinv_agree_to_terms_text', __('You must agree to the terms of use', 'invoicing')));
1393 1393
     }
1394 1394
 }
1395 1395
 
@@ -1401,40 +1401,40 @@  discard block
 block discarded – undo
1401 1401
     );
1402 1402
     
1403 1403
     // Verify there is a user_ID
1404
-    if ( $user_ID = (int)$wpi_cart->get_user_id() ) {
1404
+    if ($user_ID = (int)$wpi_cart->get_user_id()) {
1405 1405
         // Get the logged in user data
1406
-        $user_data = get_userdata( $user_ID );
1407
-        $required_fields  = wpinv_checkout_required_fields();
1406
+        $user_data = get_userdata($user_ID);
1407
+        $required_fields = wpinv_checkout_required_fields();
1408 1408
 
1409 1409
         // Loop through required fields and show error messages
1410
-         if ( !empty( $required_fields ) ) {
1411
-            foreach ( $required_fields as $field_name => $value ) {
1412
-                if ( in_array( $value, $required_fields ) && empty( $_POST[ 'wpinv_' . $field_name ] ) ) {
1413
-                    wpinv_set_error( $value['error_id'], $value['error_message'] );
1410
+         if (!empty($required_fields)) {
1411
+            foreach ($required_fields as $field_name => $value) {
1412
+                if (in_array($value, $required_fields) && empty($_POST['wpinv_' . $field_name])) {
1413
+                    wpinv_set_error($value['error_id'], $value['error_message']);
1414 1414
                 }
1415 1415
             }
1416 1416
         }
1417 1417
 
1418 1418
         // Verify data
1419
-        if ( $user_data ) {
1419
+        if ($user_data) {
1420 1420
             // Collected logged in user data
1421 1421
             $valid_user_data = array(
1422 1422
                 'user_id'     => $user_ID,
1423
-                'email'       => isset( $_POST['wpinv_email'] ) ? sanitize_email( $_POST['wpinv_email'] ) : $user_data->user_email,
1424
-                'first_name'  => isset( $_POST['wpinv_first_name'] ) && ! empty( $_POST['wpinv_first_name'] ) ? sanitize_text_field( $_POST['wpinv_first_name'] ) : $user_data->first_name,
1425
-                'last_name'   => isset( $_POST['wpinv_last_name'] ) && ! empty( $_POST['wpinv_last_name']  ) ? sanitize_text_field( $_POST['wpinv_last_name']  ) : $user_data->last_name,
1423
+                'email'       => isset($_POST['wpinv_email']) ? sanitize_email($_POST['wpinv_email']) : $user_data->user_email,
1424
+                'first_name'  => isset($_POST['wpinv_first_name']) && !empty($_POST['wpinv_first_name']) ? sanitize_text_field($_POST['wpinv_first_name']) : $user_data->first_name,
1425
+                'last_name'   => isset($_POST['wpinv_last_name']) && !empty($_POST['wpinv_last_name']) ? sanitize_text_field($_POST['wpinv_last_name']) : $user_data->last_name,
1426 1426
             );
1427 1427
 
1428
-            if ( !empty( $_POST[ 'wpinv_email' ] ) && !is_email( $_POST[ 'wpinv_email' ] ) ) {
1429
-                wpinv_set_error( 'invalid_email', __( 'Please enter a valid email address', 'invoicing' ) );
1428
+            if (!empty($_POST['wpinv_email']) && !is_email($_POST['wpinv_email'])) {
1429
+                wpinv_set_error('invalid_email', __('Please enter a valid email address', 'invoicing'));
1430 1430
             }
1431 1431
         } else {
1432 1432
             // Set invalid user error
1433
-            wpinv_set_error( 'invalid_user', __( 'The user billing information is invalid', 'invoicing' ) );
1433
+            wpinv_set_error('invalid_user', __('The user billing information is invalid', 'invoicing'));
1434 1434
         }
1435 1435
     } else {
1436 1436
         // Set invalid user error
1437
-        wpinv_set_error( 'invalid_user_id', __( 'The invalid invoice user id', 'invoicing' ) );
1437
+        wpinv_set_error('invalid_user_id', __('The invalid invoice user id', 'invoicing'));
1438 1438
     }
1439 1439
 
1440 1440
     // Return user data
@@ -1446,30 +1446,30 @@  discard block
 block discarded – undo
1446 1446
 
1447 1447
     $data = array();
1448 1448
     
1449
-    if ( is_user_logged_in() ) {
1450
-        if ( !wpinv_require_login_to_checkout() || ( wpinv_require_login_to_checkout() && (int)$wpi_cart->get_user_id() === (int)get_current_user_id() ) ) {
1449
+    if (is_user_logged_in()) {
1450
+        if (!wpinv_require_login_to_checkout() || (wpinv_require_login_to_checkout() && (int)$wpi_cart->get_user_id() === (int)get_current_user_id())) {
1451 1451
             $data['user_id'] = (int)get_current_user_id();
1452 1452
         } else {
1453
-            wpinv_set_error( 'logged_in_only', __( 'You are not allowed to pay for this invoice', 'invoicing' ) );
1453
+            wpinv_set_error('logged_in_only', __('You are not allowed to pay for this invoice', 'invoicing'));
1454 1454
         }
1455 1455
     } else {
1456 1456
         // If guest checkout allowed
1457
-        if ( !wpinv_require_login_to_checkout() ) {
1457
+        if (!wpinv_require_login_to_checkout()) {
1458 1458
             $data['user_id'] = 0;
1459 1459
         } else {
1460
-            wpinv_set_error( 'logged_in_only', __( 'You must be logged in to pay for this invoice', 'invoicing' ) );
1460
+            wpinv_set_error('logged_in_only', __('You must be logged in to pay for this invoice', 'invoicing'));
1461 1461
         }
1462 1462
     }
1463 1463
 
1464 1464
     return $data;
1465 1465
 }
1466 1466
 
1467
-function wpinv_checkout_form_get_user( $valid_data = array() ) {
1467
+function wpinv_checkout_form_get_user($valid_data = array()) {
1468 1468
     // Initialize user
1469 1469
     $user    = false;
1470
-    $is_ajax = defined( 'DOING_AJAX' ) && DOING_AJAX;
1470
+    $is_ajax = defined('DOING_AJAX') && DOING_AJAX;
1471 1471
 
1472
-    if ( empty( $valid_data['current_user'] ) ) {
1472
+    if (empty($valid_data['current_user'])) {
1473 1473
         $user = false;
1474 1474
     } else {
1475 1475
         // Set the valid invoice user
@@ -1477,7 +1477,7 @@  discard block
 block discarded – undo
1477 1477
     }
1478 1478
 
1479 1479
     // Verify invoice have an user
1480
-    if ( false === $user || empty( $user ) ) {
1480
+    if (false === $user || empty($user)) {
1481 1481
         return false;
1482 1482
     }
1483 1483
 
@@ -1494,11 +1494,11 @@  discard block
 block discarded – undo
1494 1494
         'zip',
1495 1495
     );
1496 1496
     
1497
-    foreach ( $address_fields as $field ) {
1498
-        $user[$field]  = !empty( $_POST['wpinv_' . $field] ) ? sanitize_text_field( $_POST['wpinv_' . $field] ) : false;
1497
+    foreach ($address_fields as $field) {
1498
+        $user[$field] = !empty($_POST['wpinv_' . $field]) ? sanitize_text_field($_POST['wpinv_' . $field]) : false;
1499 1499
         
1500
-        if ( !empty( $user['user_id'] ) && !empty( $valid_data['current_user']['user_id'] ) && $valid_data['current_user']['user_id'] == $user['user_id'] ) {
1501
-            update_user_meta( $user['user_id'], '_wpinv_' . $field, $user[$field] );
1500
+        if (!empty($user['user_id']) && !empty($valid_data['current_user']['user_id']) && $valid_data['current_user']['user_id'] == $user['user_id']) {
1501
+            update_user_meta($user['user_id'], '_wpinv_' . $field, $user[$field]);
1502 1502
         }
1503 1503
     }
1504 1504
 
@@ -1506,28 +1506,28 @@  discard block
 block discarded – undo
1506 1506
     return $user;
1507 1507
 }
1508 1508
 
1509
-function wpinv_set_checkout_session( $invoice_data = array() ) {
1509
+function wpinv_set_checkout_session($invoice_data = array()) {
1510 1510
     global $wpi_session;
1511 1511
     
1512
-    return $wpi_session->set( 'wpinv_checkout', $invoice_data );
1512
+    return $wpi_session->set('wpinv_checkout', $invoice_data);
1513 1513
 }
1514 1514
 
1515 1515
 function wpinv_get_checkout_session() {
1516 1516
 	global $wpi_session;
1517 1517
     
1518
-    return $wpi_session->get( 'wpinv_checkout' );
1518
+    return $wpi_session->get('wpinv_checkout');
1519 1519
 }
1520 1520
 
1521 1521
 function wpinv_empty_cart() {
1522 1522
     global $wpi_session;
1523 1523
 
1524 1524
     // Remove cart contents
1525
-    $wpi_session->set( 'wpinv_checkout', NULL );
1525
+    $wpi_session->set('wpinv_checkout', NULL);
1526 1526
 
1527 1527
     // Remove all cart fees
1528
-    $wpi_session->set( 'wpi_cart_fees', NULL );
1528
+    $wpi_session->set('wpi_cart_fees', NULL);
1529 1529
 
1530
-    do_action( 'wpinv_empty_cart' );
1530
+    do_action('wpinv_empty_cart');
1531 1531
 }
1532 1532
 
1533 1533
 function wpinv_process_checkout() {
@@ -1540,42 +1540,42 @@  discard block
 block discarded – undo
1540 1540
     
1541 1541
     $wpi_checkout_id = $invoice->ID;
1542 1542
     
1543
-    do_action( 'wpinv_pre_process_checkout' );
1543
+    do_action('wpinv_pre_process_checkout');
1544 1544
     
1545
-    if ( !wpinv_get_cart_contents() ) { // Make sure the cart isn't empty
1545
+    if (!wpinv_get_cart_contents()) { // Make sure the cart isn't empty
1546 1546
         $valid_data = false;
1547
-        wpinv_set_error( 'empty_cart', __( 'Your cart is empty', 'invoicing' ) );
1547
+        wpinv_set_error('empty_cart', __('Your cart is empty', 'invoicing'));
1548 1548
     } else {
1549 1549
         // Validate the form $_POST data
1550 1550
         $valid_data = wpinv_validate_checkout_fields();
1551 1551
         
1552 1552
         // Allow themes and plugins to hook to errors
1553
-        do_action( 'wpinv_checkout_error_checks', $valid_data, $_POST );
1553
+        do_action('wpinv_checkout_error_checks', $valid_data, $_POST);
1554 1554
     }
1555 1555
     
1556
-    $is_ajax    = defined( 'DOING_AJAX' ) && DOING_AJAX;
1556
+    $is_ajax = defined('DOING_AJAX') && DOING_AJAX;
1557 1557
     
1558 1558
     // Validate the user
1559
-    $user = wpinv_checkout_form_get_user( $valid_data );
1559
+    $user = wpinv_checkout_form_get_user($valid_data);
1560 1560
 
1561 1561
     // Let extensions validate fields after user is logged in if user has used login/registration form
1562
-    do_action( 'wpinv_checkout_user_error_checks', $user, $valid_data, $_POST );
1562
+    do_action('wpinv_checkout_user_error_checks', $user, $valid_data, $_POST);
1563 1563
     
1564
-    if ( false === $valid_data || wpinv_get_errors() || ! $user ) {
1565
-        if ( $is_ajax ) {
1566
-            do_action( 'wpinv_ajax_checkout_errors' );
1564
+    if (false === $valid_data || wpinv_get_errors() || !$user) {
1565
+        if ($is_ajax) {
1566
+            do_action('wpinv_ajax_checkout_errors');
1567 1567
             die();
1568 1568
         } else {
1569 1569
             return false;
1570 1570
         }
1571 1571
     }
1572 1572
 
1573
-    if ( $is_ajax ) {
1573
+    if ($is_ajax) {
1574 1574
         // Save address fields.
1575
-        $address_fields = array( 'first_name', 'last_name', 'phone', 'address', 'city', 'country', 'state', 'zip', 'company' );
1576
-        foreach ( $address_fields as $field ) {
1577
-            if ( isset( $user[$field] ) ) {
1578
-                $invoice->set( $field, $user[$field] );
1575
+        $address_fields = array('first_name', 'last_name', 'phone', 'address', 'city', 'country', 'state', 'zip', 'company');
1576
+        foreach ($address_fields as $field) {
1577
+            if (isset($user[$field])) {
1578
+                $invoice->set($field, $user[$field]);
1579 1579
             }
1580 1580
             
1581 1581
             $invoice->save();
@@ -1583,15 +1583,15 @@  discard block
 block discarded – undo
1583 1583
 
1584 1584
         $response['success']            = true;
1585 1585
         $response['data']['subtotal']   = $invoice->get_subtotal();
1586
-        $response['data']['subtotalf']  = $invoice->get_subtotal( true );
1586
+        $response['data']['subtotalf']  = $invoice->get_subtotal(true);
1587 1587
         $response['data']['discount']   = $invoice->get_discount();
1588
-        $response['data']['discountf']  = $invoice->get_discount( true );
1588
+        $response['data']['discountf']  = $invoice->get_discount(true);
1589 1589
         $response['data']['tax']        = $invoice->get_tax();
1590
-        $response['data']['taxf']       = $invoice->get_tax( true );
1590
+        $response['data']['taxf']       = $invoice->get_tax(true);
1591 1591
         $response['data']['total']      = $invoice->get_total();
1592
-        $response['data']['totalf']     = $invoice->get_total( true );
1592
+        $response['data']['totalf']     = $invoice->get_total(true);
1593 1593
         
1594
-        wp_send_json( $response );
1594
+        wp_send_json($response);
1595 1595
     }
1596 1596
     
1597 1597
     $user_info = array(
@@ -1613,42 +1613,42 @@  discard block
 block discarded – undo
1613 1613
     
1614 1614
     // Setup invoice information
1615 1615
     $invoice_data = array(
1616
-        'invoice_id'        => !empty( $invoice ) ? $invoice->ID : 0,
1616
+        'invoice_id'        => !empty($invoice) ? $invoice->ID : 0,
1617 1617
         'items'             => $cart_items,
1618 1618
         'cart_discounts'    => $discounts,
1619
-        'fees'              => wpinv_get_cart_fees(),        // Any arbitrary fees that have been added to the cart
1620
-        'subtotal'          => wpinv_get_cart_subtotal( $cart_items ),    // Amount before taxes and discounts
1621
-        'discount'          => wpinv_get_cart_items_discount_amount( $cart_items, $discounts ), // Discounted amount
1622
-        'tax'               => wpinv_get_cart_tax( $cart_items ),               // Taxed amount
1623
-        'price'             => wpinv_get_cart_total( $cart_items, $discounts ),    // Amount after taxes
1619
+        'fees'              => wpinv_get_cart_fees(), // Any arbitrary fees that have been added to the cart
1620
+        'subtotal'          => wpinv_get_cart_subtotal($cart_items), // Amount before taxes and discounts
1621
+        'discount'          => wpinv_get_cart_items_discount_amount($cart_items, $discounts), // Discounted amount
1622
+        'tax'               => wpinv_get_cart_tax($cart_items), // Taxed amount
1623
+        'price'             => wpinv_get_cart_total($cart_items, $discounts), // Amount after taxes
1624 1624
         'invoice_key'       => $invoice->get_key() ? $invoice->get_key() : $invoice->generate_key(),
1625 1625
         'user_email'        => $user['email'],
1626
-        'date'              => date( 'Y-m-d H:i:s', current_time( 'timestamp' ) ),
1627
-        'user_info'         => stripslashes_deep( $user_info ),
1626
+        'date'              => date('Y-m-d H:i:s', current_time('timestamp')),
1627
+        'user_info'         => stripslashes_deep($user_info),
1628 1628
         'post_data'         => $_POST,
1629 1629
         'cart_details'      => $cart_items,
1630 1630
         'gateway'           => $valid_data['gateway'],
1631 1631
         'card_info'         => $valid_data['cc_info']
1632 1632
     );
1633 1633
     
1634
-    $vat_info   = $wpinv_euvat->current_vat_data();
1635
-    if ( is_array( $vat_info ) ) {
1634
+    $vat_info = $wpinv_euvat->current_vat_data();
1635
+    if (is_array($vat_info)) {
1636 1636
         $invoice_data['user_info']['vat_number']        = $vat_info['number'];
1637 1637
         $invoice_data['user_info']['vat_rate']          = wpinv_get_tax_rate($invoice_data['user_info']['country'], $invoice_data['user_info']['state']);
1638
-        $invoice_data['user_info']['adddress_confirmed']    = isset($vat_info['adddress_confirmed']) ? $vat_info['adddress_confirmed'] : false;
1638
+        $invoice_data['user_info']['adddress_confirmed'] = isset($vat_info['adddress_confirmed']) ? $vat_info['adddress_confirmed'] : false;
1639 1639
 
1640 1640
         // Add the VAT rate to each item in the cart
1641
-        foreach( $invoice_data['cart_details'] as $key => $item_data) {
1641
+        foreach ($invoice_data['cart_details'] as $key => $item_data) {
1642 1642
             $rate = wpinv_get_tax_rate($invoice_data['user_info']['country'], $invoice_data['user_info']['state'], $item_data['id']);
1643
-            $invoice_data['cart_details'][$key]['vat_rate'] = wpinv_round_amount( $rate, 4 );
1643
+            $invoice_data['cart_details'][$key]['vat_rate'] = wpinv_round_amount($rate, 4);
1644 1644
         }
1645 1645
     }
1646 1646
     
1647 1647
     // Save vat fields.
1648
-    $address_fields = array( 'vat_number', 'vat_rate', 'adddress_confirmed' );
1649
-    foreach ( $address_fields as $field ) {
1650
-        if ( isset( $invoice_data['user_info'][$field] ) ) {
1651
-            $invoice->set( $field, $invoice_data['user_info'][$field] );
1648
+    $address_fields = array('vat_number', 'vat_rate', 'adddress_confirmed');
1649
+    foreach ($address_fields as $field) {
1650
+        if (isset($invoice_data['user_info'][$field])) {
1651
+            $invoice->set($field, $invoice_data['user_info'][$field]);
1652 1652
         }
1653 1653
         
1654 1654
         $invoice->save();
@@ -1658,49 +1658,49 @@  discard block
 block discarded – undo
1658 1658
     $valid_data['user'] = $user;
1659 1659
     
1660 1660
     // Allow themes and plugins to hook before the gateway
1661
-    do_action( 'wpinv_checkout_before_gateway', $_POST, $user_info, $valid_data );
1661
+    do_action('wpinv_checkout_before_gateway', $_POST, $user_info, $valid_data);
1662 1662
     
1663 1663
     // If the total amount in the cart is 0, send to the manual gateway. This emulates a free invoice
1664
-    if ( !$invoice_data['price'] ) {
1664
+    if (!$invoice_data['price']) {
1665 1665
         // Revert to manual
1666 1666
         $invoice_data['gateway'] = 'manual';
1667 1667
         $_POST['wpi-gateway'] = 'manual';
1668 1668
     }
1669 1669
     
1670 1670
     // Allow the invoice data to be modified before it is sent to the gateway
1671
-    $invoice_data = apply_filters( 'wpinv_data_before_gateway', $invoice_data, $valid_data );
1671
+    $invoice_data = apply_filters('wpinv_data_before_gateway', $invoice_data, $valid_data);
1672 1672
     
1673 1673
     // Setup the data we're storing in the purchase session
1674 1674
     $session_data = $invoice_data;
1675 1675
     // Make sure credit card numbers are never stored in sessions
1676
-    if ( !empty( $session_data['card_info']['card_number'] ) ) {
1677
-        unset( $session_data['card_info']['card_number'] );
1676
+    if (!empty($session_data['card_info']['card_number'])) {
1677
+        unset($session_data['card_info']['card_number']);
1678 1678
     }
1679 1679
     
1680 1680
     // Used for showing item links to non logged-in users after purchase, and for other plugins needing purchase data.
1681
-    wpinv_set_checkout_session( $invoice_data );
1681
+    wpinv_set_checkout_session($invoice_data);
1682 1682
     
1683 1683
     // Set gateway
1684
-    $invoice->update_meta( '_wpinv_gateway', $invoice_data['gateway'] );
1685
-    $invoice->update_meta( '_wpinv_mode', ( wpinv_is_test_mode( $invoice_data['gateway'] ) ? 'test' : 'live' ) );
1686
-    $invoice->update_meta( '_wpinv_checkout', true );
1684
+    $invoice->update_meta('_wpinv_gateway', $invoice_data['gateway']);
1685
+    $invoice->update_meta('_wpinv_mode', (wpinv_is_test_mode($invoice_data['gateway']) ? 'test' : 'live'));
1686
+    $invoice->update_meta('_wpinv_checkout', true);
1687 1687
     
1688
-    do_action( 'wpinv_checkout_before_send_to_gateway', $invoice, $invoice_data );
1688
+    do_action('wpinv_checkout_before_send_to_gateway', $invoice, $invoice_data);
1689 1689
 
1690 1690
     // Send info to the gateway for payment processing
1691
-    wpinv_send_to_gateway( $invoice_data['gateway'], $invoice_data );
1691
+    wpinv_send_to_gateway($invoice_data['gateway'], $invoice_data);
1692 1692
     die();
1693 1693
 }
1694
-add_action( 'wpinv_payment', 'wpinv_process_checkout' );
1694
+add_action('wpinv_payment', 'wpinv_process_checkout');
1695 1695
 
1696
-function wpinv_get_invoices( $args ) {
1697
-    $args = wp_parse_args( $args, array(
1698
-        'status'   => array_keys( wpinv_get_invoice_statuses() ),
1696
+function wpinv_get_invoices($args) {
1697
+    $args = wp_parse_args($args, array(
1698
+        'status'   => array_keys(wpinv_get_invoice_statuses()),
1699 1699
         'type'     => 'wpi_invoice',
1700 1700
         'parent'   => null,
1701 1701
         'user'     => null,
1702 1702
         'email'    => '',
1703
-        'limit'    => get_option( 'posts_per_page' ),
1703
+        'limit'    => get_option('posts_per_page'),
1704 1704
         'offset'   => null,
1705 1705
         'page'     => 1,
1706 1706
         'exclude'  => array(),
@@ -1708,7 +1708,7 @@  discard block
 block discarded – undo
1708 1708
         'order'    => 'DESC',
1709 1709
         'return'   => 'objects',
1710 1710
         'paginate' => false,
1711
-    ) );
1711
+    ));
1712 1712
     
1713 1713
     // Handle some BW compatibility arg names where wp_query args differ in naming.
1714 1714
     $map_legacy = array(
@@ -1721,18 +1721,18 @@  discard block
 block discarded – undo
1721 1721
         'paged'          => 'page',
1722 1722
     );
1723 1723
 
1724
-    foreach ( $map_legacy as $from => $to ) {
1725
-        if ( isset( $args[ $from ] ) ) {
1726
-            $args[ $to ] = $args[ $from ];
1724
+    foreach ($map_legacy as $from => $to) {
1725
+        if (isset($args[$from])) {
1726
+            $args[$to] = $args[$from];
1727 1727
         }
1728 1728
     }
1729 1729
 
1730
-    if ( get_query_var( 'paged' ) )
1730
+    if (get_query_var('paged'))
1731 1731
         $args['page'] = get_query_var('paged');
1732
-    else if ( get_query_var( 'page' ) )
1733
-        $args['page'] = get_query_var( 'page' );
1734
-    else if ( !empty( $args[ 'page' ] ) )
1735
-        $args['page'] = $args[ 'page' ];
1732
+    else if (get_query_var('page'))
1733
+        $args['page'] = get_query_var('page');
1734
+    else if (!empty($args['page']))
1735
+        $args['page'] = $args['page'];
1736 1736
     else
1737 1737
         $args['page'] = 1;
1738 1738
 
@@ -1745,47 +1745,47 @@  discard block
 block discarded – undo
1745 1745
         'post_status'    => $args['status'],
1746 1746
         'posts_per_page' => $args['limit'],
1747 1747
         'meta_query'     => array(),
1748
-        'date_query'     => !empty( $args['date_query'] ) ? $args['date_query'] : array(),
1748
+        'date_query'     => !empty($args['date_query']) ? $args['date_query'] : array(),
1749 1749
         'fields'         => 'ids',
1750 1750
         'orderby'        => $args['orderby'],
1751 1751
         'order'          => $args['order'],
1752 1752
     );
1753 1753
     
1754
-    if ( !empty( $args['user'] ) ) {
1755
-        $wp_query_args['author'] = absint( $args['user'] );
1754
+    if (!empty($args['user'])) {
1755
+        $wp_query_args['author'] = absint($args['user']);
1756 1756
     }
1757 1757
 
1758
-    if ( ! is_null( $args['parent'] ) ) {
1759
-        $wp_query_args['post_parent'] = absint( $args['parent'] );
1758
+    if (!is_null($args['parent'])) {
1759
+        $wp_query_args['post_parent'] = absint($args['parent']);
1760 1760
     }
1761 1761
 
1762
-    if ( ! is_null( $args['offset'] ) ) {
1763
-        $wp_query_args['offset'] = absint( $args['offset'] );
1762
+    if (!is_null($args['offset'])) {
1763
+        $wp_query_args['offset'] = absint($args['offset']);
1764 1764
     } else {
1765
-        $wp_query_args['paged'] = absint( $args['page'] );
1765
+        $wp_query_args['paged'] = absint($args['page']);
1766 1766
     }
1767 1767
 
1768
-    if ( ! empty( $args['exclude'] ) ) {
1769
-        $wp_query_args['post__not_in'] = array_map( 'absint', $args['exclude'] );
1768
+    if (!empty($args['exclude'])) {
1769
+        $wp_query_args['post__not_in'] = array_map('absint', $args['exclude']);
1770 1770
     }
1771 1771
 
1772
-    if ( ! $args['paginate' ] ) {
1772
+    if (!$args['paginate']) {
1773 1773
         $wp_query_args['no_found_rows'] = true;
1774 1774
     }
1775 1775
 
1776 1776
     // Get results.
1777
-    $invoices = new WP_Query( $wp_query_args );
1777
+    $invoices = new WP_Query($wp_query_args);
1778 1778
 
1779
-    if ( 'objects' === $args['return'] ) {
1780
-        $return = array_map( 'wpinv_get_invoice', $invoices->posts );
1781
-    } elseif ( 'self' === $args['return'] ) {
1779
+    if ('objects' === $args['return']) {
1780
+        $return = array_map('wpinv_get_invoice', $invoices->posts);
1781
+    } elseif ('self' === $args['return']) {
1782 1782
         return $invoices;
1783 1783
     } else {
1784 1784
         $return = $invoices->posts;
1785 1785
     }
1786 1786
 
1787
-    if ( $args['paginate' ] ) {
1788
-        return (object) array(
1787
+    if ($args['paginate']) {
1788
+        return (object)array(
1789 1789
             'invoices'      => $return,
1790 1790
             'total'         => $invoices->found_posts,
1791 1791
             'max_num_pages' => $invoices->max_num_pages,
@@ -1797,22 +1797,22 @@  discard block
 block discarded – undo
1797 1797
 
1798 1798
 function wpinv_get_user_invoices_columns() {
1799 1799
     $columns = array(
1800
-            'invoice-number'  => array( 'title' => __( 'ID', 'invoicing' ), 'class' => 'text-left' ),
1801
-            'created-date'    => array( 'title' => __( 'Created Date', 'invoicing' ), 'class' => 'text-left' ),
1802
-            'payment-date'    => array( 'title' => __( 'Payment Date', 'invoicing' ), 'class' => 'text-left' ),
1803
-            'invoice-status'  => array( 'title' => __( 'Status', 'invoicing' ), 'class' => 'text-center' ),
1804
-            'invoice-total'   => array( 'title' => __( 'Total', 'invoicing' ), 'class' => 'text-right' ),
1805
-            'invoice-actions' => array( 'title' => '&nbsp;', 'class' => 'text-center' ),
1800
+            'invoice-number'  => array('title' => __('ID', 'invoicing'), 'class' => 'text-left'),
1801
+            'created-date'    => array('title' => __('Created Date', 'invoicing'), 'class' => 'text-left'),
1802
+            'payment-date'    => array('title' => __('Payment Date', 'invoicing'), 'class' => 'text-left'),
1803
+            'invoice-status'  => array('title' => __('Status', 'invoicing'), 'class' => 'text-center'),
1804
+            'invoice-total'   => array('title' => __('Total', 'invoicing'), 'class' => 'text-right'),
1805
+            'invoice-actions' => array('title' => '&nbsp;', 'class' => 'text-center'),
1806 1806
         );
1807 1807
 
1808
-    return apply_filters( 'wpinv_user_invoices_columns', $columns );
1808
+    return apply_filters('wpinv_user_invoices_columns', $columns);
1809 1809
 }
1810 1810
 
1811
-function wpinv_payment_receipt( $atts, $content = null ) {
1811
+function wpinv_payment_receipt($atts, $content = null) {
1812 1812
     global $wpinv_receipt_args;
1813 1813
 
1814
-    $wpinv_receipt_args = shortcode_atts( array(
1815
-        'error'           => __( 'Sorry, trouble retrieving payment receipt.', 'invoicing' ),
1814
+    $wpinv_receipt_args = shortcode_atts(array(
1815
+        'error'           => __('Sorry, trouble retrieving payment receipt.', 'invoicing'),
1816 1816
         'price'           => true,
1817 1817
         'discount'        => true,
1818 1818
         'items'           => true,
@@ -1821,195 +1821,195 @@  discard block
 block discarded – undo
1821 1821
         'invoice_key'     => false,
1822 1822
         'payment_method'  => true,
1823 1823
         'invoice_id'      => true
1824
-    ), $atts, 'wpinv_receipt' );
1824
+    ), $atts, 'wpinv_receipt');
1825 1825
 
1826 1826
     $session = wpinv_get_checkout_session();
1827
-    if ( isset( $_GET['invoice_key'] ) ) {
1828
-        $invoice_key = urldecode( $_GET['invoice_key'] );
1829
-    } else if ( $session && isset( $session['invoice_key'] ) ) {
1827
+    if (isset($_GET['invoice_key'])) {
1828
+        $invoice_key = urldecode($_GET['invoice_key']);
1829
+    } else if ($session && isset($session['invoice_key'])) {
1830 1830
         $invoice_key = $session['invoice_key'];
1831
-    } elseif ( isset( $wpinv_receipt_args['invoice_key'] ) && $wpinv_receipt_args['invoice_key'] ) {
1831
+    } elseif (isset($wpinv_receipt_args['invoice_key']) && $wpinv_receipt_args['invoice_key']) {
1832 1832
         $invoice_key = $wpinv_receipt_args['invoice_key'];
1833
-    } else if ( isset( $_GET['invoice-id'] ) ) {
1834
-        $invoice_key = wpinv_get_payment_key( (int)$_GET['invoice-id'] );
1833
+    } else if (isset($_GET['invoice-id'])) {
1834
+        $invoice_key = wpinv_get_payment_key((int)$_GET['invoice-id']);
1835 1835
     }
1836 1836
 
1837 1837
     // No key found
1838
-    if ( ! isset( $invoice_key ) ) {
1838
+    if (!isset($invoice_key)) {
1839 1839
         return '<p class="alert alert-error">' . $wpinv_receipt_args['error'] . '</p>';
1840 1840
     }
1841 1841
 
1842
-    $invoice_id    = wpinv_get_invoice_id_by_key( $invoice_key );
1843
-    $user_can_view = wpinv_can_view_receipt( $invoice_key );
1844
-    if ( $user_can_view && isset( $_GET['invoice-id'] ) ) {
1842
+    $invoice_id    = wpinv_get_invoice_id_by_key($invoice_key);
1843
+    $user_can_view = wpinv_can_view_receipt($invoice_key);
1844
+    if ($user_can_view && isset($_GET['invoice-id'])) {
1845 1845
         $invoice_id     = (int)$_GET['invoice-id'];
1846
-        $user_can_view  = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? true : false;
1846
+        $user_can_view  = $invoice_key == wpinv_get_payment_key((int)$_GET['invoice-id']) ? true : false;
1847 1847
     }
1848 1848
 
1849 1849
     // Key was provided, but user is logged out. Offer them the ability to login and view the receipt
1850
-    if ( ! $user_can_view && ! empty( $invoice_key ) && ! is_user_logged_in() ) {
1850
+    if (!$user_can_view && !empty($invoice_key) && !is_user_logged_in()) {
1851 1851
         // login redirect
1852
-        return '<p class="alert alert-error">' . __( 'You are not allowed to access this section', 'invoicing' ) . '</p>';
1852
+        return '<p class="alert alert-error">' . __('You are not allowed to access this section', 'invoicing') . '</p>';
1853 1853
     }
1854 1854
 
1855
-    if ( ! apply_filters( 'wpinv_user_can_view_receipt', $user_can_view, $wpinv_receipt_args ) ) {
1855
+    if (!apply_filters('wpinv_user_can_view_receipt', $user_can_view, $wpinv_receipt_args)) {
1856 1856
         return '<p class="alert alert-error">' . $wpinv_receipt_args['error'] . '</p>';
1857 1857
     }
1858 1858
 
1859 1859
     ob_start();
1860 1860
 
1861
-    wpinv_get_template_part( 'wpinv-invoice-receipt' );
1861
+    wpinv_get_template_part('wpinv-invoice-receipt');
1862 1862
 
1863 1863
     $display = ob_get_clean();
1864 1864
 
1865 1865
     return $display;
1866 1866
 }
1867 1867
 
1868
-function wpinv_get_invoice_id_by_key( $key ) {
1868
+function wpinv_get_invoice_id_by_key($key) {
1869 1869
 	global $wpdb;
1870 1870
 
1871
-	$invoice_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_key' AND meta_value = %s LIMIT 1", $key ) );
1871
+	$invoice_id = $wpdb->get_var($wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_key' AND meta_value = %s LIMIT 1", $key));
1872 1872
 
1873
-	if ( $invoice_id != NULL )
1873
+	if ($invoice_id != NULL)
1874 1874
 		return $invoice_id;
1875 1875
 
1876 1876
 	return 0;
1877 1877
 }
1878 1878
 
1879
-function wpinv_can_view_receipt( $invoice_key = '' ) {
1879
+function wpinv_can_view_receipt($invoice_key = '') {
1880 1880
 	$return = false;
1881 1881
 
1882
-	if ( empty( $invoice_key ) ) {
1882
+	if (empty($invoice_key)) {
1883 1883
 		return $return;
1884 1884
 	}
1885 1885
 
1886 1886
 	global $wpinv_receipt_args;
1887 1887
 
1888
-	$wpinv_receipt_args['id'] = wpinv_get_invoice_id_by_key( $invoice_key );
1889
-	if ( isset( $_GET['invoice-id'] ) ) {
1890
-		$wpinv_receipt_args['id'] = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? (int)$_GET['invoice-id'] : 0;
1888
+	$wpinv_receipt_args['id'] = wpinv_get_invoice_id_by_key($invoice_key);
1889
+	if (isset($_GET['invoice-id'])) {
1890
+		$wpinv_receipt_args['id'] = $invoice_key == wpinv_get_payment_key((int)$_GET['invoice-id']) ? (int)$_GET['invoice-id'] : 0;
1891 1891
 	}
1892 1892
 
1893
-	if ( empty( $wpinv_receipt_args['id'] ) ) {
1893
+	if (empty($wpinv_receipt_args['id'])) {
1894 1894
 		return $return;
1895 1895
 	}
1896 1896
 
1897
-	$invoice = wpinv_get_invoice( $wpinv_receipt_args['id'] );
1898
-	if ( !( !empty( $invoice->ID ) && $invoice->get_key() === $invoice_key ) ) {
1897
+	$invoice = wpinv_get_invoice($wpinv_receipt_args['id']);
1898
+	if (!(!empty($invoice->ID) && $invoice->get_key() === $invoice_key)) {
1899 1899
 		return $return;
1900 1900
 	}
1901 1901
 
1902
-	if ( is_user_logged_in() ) {
1903
-		if ( (int)$invoice->get_user_id() === (int) get_current_user_id() ) {
1902
+	if (is_user_logged_in()) {
1903
+		if ((int)$invoice->get_user_id() === (int)get_current_user_id()) {
1904 1904
 			$return = true;
1905 1905
 		}
1906 1906
 	}
1907 1907
 
1908 1908
 	$session = wpinv_get_checkout_session();
1909
-	if ( isset( $_GET['invoice_key'] ) || ( $session && isset( $session['invoice_key'] ) ) ) {
1910
-		$check_key = isset( $_GET['invoice_key'] ) ? $_GET['invoice_key'] : $session['invoice_key'];
1909
+	if (isset($_GET['invoice_key']) || ($session && isset($session['invoice_key']))) {
1910
+		$check_key = isset($_GET['invoice_key']) ? $_GET['invoice_key'] : $session['invoice_key'];
1911 1911
 
1912
-		if ( wpinv_require_login_to_checkout() ) {
1912
+		if (wpinv_require_login_to_checkout()) {
1913 1913
 			$return = $return && $check_key === $invoice_key;
1914 1914
 		} else {
1915 1915
 			$return = $check_key === $invoice_key;
1916 1916
 		}
1917 1917
 	}
1918 1918
 
1919
-	return (bool) apply_filters( 'wpinv_can_view_receipt', $return, $invoice_key );
1919
+	return (bool)apply_filters('wpinv_can_view_receipt', $return, $invoice_key);
1920 1920
 }
1921 1921
 
1922 1922
 function wpinv_pay_for_invoice() {
1923 1923
     global $wpinv_euvat;
1924 1924
     
1925
-    if ( isset( $_GET['invoice_key'] ) ) {
1925
+    if (isset($_GET['invoice_key'])) {
1926 1926
         $checkout_uri   = wpinv_get_checkout_uri();
1927
-        $invoice_key    = sanitize_text_field( $_GET['invoice_key'] );
1927
+        $invoice_key    = sanitize_text_field($_GET['invoice_key']);
1928 1928
         
1929
-        if ( empty( $invoice_key ) ) {
1930
-            wpinv_set_error( 'invalid_invoice', __( 'Invoice not found', 'invoicing' ) );
1931
-            wp_redirect( $checkout_uri );
1929
+        if (empty($invoice_key)) {
1930
+            wpinv_set_error('invalid_invoice', __('Invoice not found', 'invoicing'));
1931
+            wp_redirect($checkout_uri);
1932 1932
             wpinv_die();
1933 1933
         }
1934 1934
         
1935
-        do_action( 'wpinv_check_pay_for_invoice', $invoice_key );
1935
+        do_action('wpinv_check_pay_for_invoice', $invoice_key);
1936 1936
 
1937
-        $invoice_id    = wpinv_get_invoice_id_by_key( $invoice_key );
1938
-        $user_can_view = wpinv_can_view_receipt( $invoice_key );
1939
-        if ( $user_can_view && isset( $_GET['invoice-id'] ) ) {
1937
+        $invoice_id    = wpinv_get_invoice_id_by_key($invoice_key);
1938
+        $user_can_view = wpinv_can_view_receipt($invoice_key);
1939
+        if ($user_can_view && isset($_GET['invoice-id'])) {
1940 1940
             $invoice_id     = (int)$_GET['invoice-id'];
1941
-            $user_can_view  = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? true : false;
1941
+            $user_can_view  = $invoice_key == wpinv_get_payment_key((int)$_GET['invoice-id']) ? true : false;
1942 1942
         }
1943 1943
         
1944
-        if ( $invoice_id && $user_can_view && ( $invoice = wpinv_get_invoice( $invoice_id ) ) ) {
1945
-            if ( $invoice->needs_payment() ) {
1944
+        if ($invoice_id && $user_can_view && ($invoice = wpinv_get_invoice($invoice_id))) {
1945
+            if ($invoice->needs_payment()) {
1946 1946
                 $data                   = array();
1947 1947
                 $data['invoice_id']     = $invoice_id;
1948
-                $data['cart_discounts'] = $invoice->get_discounts( true );
1948
+                $data['cart_discounts'] = $invoice->get_discounts(true);
1949 1949
                 
1950
-                wpinv_set_checkout_session( $data );
1950
+                wpinv_set_checkout_session($data);
1951 1951
                 
1952
-                if ( wpinv_get_option( 'vat_ip_country_default' ) ) {
1952
+                if (wpinv_get_option('vat_ip_country_default')) {
1953 1953
                     $_POST['country']   = $wpinv_euvat->get_country_by_ip();
1954 1954
                     $_POST['state']     = $_POST['country'] == $invoice->country ? $invoice->state : '';
1955 1955
                     
1956
-                    wpinv_recalculate_tax( true );
1956
+                    wpinv_recalculate_tax(true);
1957 1957
                 }
1958 1958
                 
1959 1959
             } else {
1960 1960
                 $checkout_uri = $invoice->get_view_url();
1961 1961
             }
1962 1962
         } else {
1963
-            wpinv_set_error( 'invalid_invoice', __( 'You are not allowed to view this invoice', 'invoicing' ) );
1963
+            wpinv_set_error('invalid_invoice', __('You are not allowed to view this invoice', 'invoicing'));
1964 1964
             
1965
-            $checkout_uri = is_user_logged_in() ? wpinv_get_history_page_uri() : wp_login_url( get_permalink() );
1965
+            $checkout_uri = is_user_logged_in() ? wpinv_get_history_page_uri() : wp_login_url(get_permalink());
1966 1966
         }
1967 1967
         
1968
-        wp_redirect( $checkout_uri );
1968
+        wp_redirect($checkout_uri);
1969 1969
         wpinv_die();
1970 1970
     }
1971 1971
 }
1972
-add_action( 'wpinv_pay_for_invoice', 'wpinv_pay_for_invoice' );
1972
+add_action('wpinv_pay_for_invoice', 'wpinv_pay_for_invoice');
1973 1973
 
1974
-function wpinv_handle_pay_via_invoice_link( $invoice_key ) {
1975
-    if ( !empty( $invoice_key ) && !empty( $_REQUEST['_wpipay'] ) && !is_user_logged_in() && $invoice_id = wpinv_get_invoice_id_by_key( $invoice_key ) ) {
1976
-        if ( $invoice = wpinv_get_invoice( $invoice_id ) ) {
1974
+function wpinv_handle_pay_via_invoice_link($invoice_key) {
1975
+    if (!empty($invoice_key) && !empty($_REQUEST['_wpipay']) && !is_user_logged_in() && $invoice_id = wpinv_get_invoice_id_by_key($invoice_key)) {
1976
+        if ($invoice = wpinv_get_invoice($invoice_id)) {
1977 1977
             $user_id = $invoice->get_user_id();
1978
-            $secret = sanitize_text_field( $_GET['_wpipay'] );
1978
+            $secret = sanitize_text_field($_GET['_wpipay']);
1979 1979
             
1980
-            if ( $secret === md5( $user_id . '::' . $invoice->get_email() . '::' . $invoice_key ) ) { // valid invoice link
1981
-                $redirect_to = remove_query_arg( '_wpipay', get_permalink() );
1980
+            if ($secret === md5($user_id . '::' . $invoice->get_email() . '::' . $invoice_key)) { // valid invoice link
1981
+                $redirect_to = remove_query_arg('_wpipay', get_permalink());
1982 1982
                 
1983
-                wpinv_guest_redirect( $redirect_to, $user_id );
1983
+                wpinv_guest_redirect($redirect_to, $user_id);
1984 1984
                 wpinv_die();
1985 1985
             }
1986 1986
         }
1987 1987
     }
1988 1988
 }
1989
-add_action( 'wpinv_check_pay_for_invoice', 'wpinv_handle_pay_via_invoice_link' );
1989
+add_action('wpinv_check_pay_for_invoice', 'wpinv_handle_pay_via_invoice_link');
1990 1990
 
1991
-function wpinv_set_payment_transaction_id( $invoice_id = 0, $transaction_id = '' ) {
1992
-    $invoice_id = is_object( $invoice_id ) && !empty( $invoice_id->ID ) ? $invoice_id : $invoice_id;
1991
+function wpinv_set_payment_transaction_id($invoice_id = 0, $transaction_id = '') {
1992
+    $invoice_id = is_object($invoice_id) && !empty($invoice_id->ID) ? $invoice_id : $invoice_id;
1993 1993
     
1994
-    if ( empty( $invoice_id ) && $invoice_id > 0 ) {
1994
+    if (empty($invoice_id) && $invoice_id > 0) {
1995 1995
         return false;
1996 1996
     }
1997 1997
     
1998
-    if ( empty( $transaction_id ) ) {
1998
+    if (empty($transaction_id)) {
1999 1999
         $transaction_id = $invoice_id;
2000 2000
     }
2001 2001
 
2002
-    $transaction_id = apply_filters( 'wpinv_set_payment_transaction_id', $transaction_id, $invoice_id );
2002
+    $transaction_id = apply_filters('wpinv_set_payment_transaction_id', $transaction_id, $invoice_id);
2003 2003
     
2004
-    return wpinv_update_invoice_meta( $invoice_id, '_wpinv_transaction_id', $transaction_id );
2004
+    return wpinv_update_invoice_meta($invoice_id, '_wpinv_transaction_id', $transaction_id);
2005 2005
 }
2006 2006
 
2007
-function wpinv_invoice_status_label( $status, $status_display = '' ) {
2008
-    if ( empty( $status_display ) ) {
2009
-        $status_display = wpinv_status_nicename( $status );
2007
+function wpinv_invoice_status_label($status, $status_display = '') {
2008
+    if (empty($status_display)) {
2009
+        $status_display = wpinv_status_nicename($status);
2010 2010
     }
2011 2011
     
2012
-    switch ( $status ) {
2012
+    switch ($status) {
2013 2013
         case 'publish' :
2014 2014
         case 'wpi-renewal' :
2015 2015
             $class = 'label-success';
@@ -2034,243 +2034,243 @@  discard block
 block discarded – undo
2034 2034
     
2035 2035
     $label = '<span class="label label-inv-' . $status . ' ' . $class . '">' . $status_display . '</span>';
2036 2036
     
2037
-    return apply_filters( 'wpinv_invoice_status_label', $label, $status, $status_display );
2037
+    return apply_filters('wpinv_invoice_status_label', $label, $status, $status_display);
2038 2038
 }
2039 2039
 
2040
-function wpinv_format_invoice_number( $number, $type = '' ) {
2041
-    $check = apply_filters( 'wpinv_pre_format_invoice_number', null, $number, $type );
2042
-    if ( null !== $check ) {
2040
+function wpinv_format_invoice_number($number, $type = '') {
2041
+    $check = apply_filters('wpinv_pre_format_invoice_number', null, $number, $type);
2042
+    if (null !== $check) {
2043 2043
         return $check;
2044 2044
     }
2045 2045
 
2046
-    if ( !empty( $number ) && !is_numeric( $number ) ) {
2046
+    if (!empty($number) && !is_numeric($number)) {
2047 2047
         return $number;
2048 2048
     }
2049 2049
 
2050
-    $padd  = wpinv_get_option( 'invoice_number_padd' );
2051
-    $prefix  = wpinv_get_option( 'invoice_number_prefix' );
2052
-    $postfix = wpinv_get_option( 'invoice_number_postfix' );
2050
+    $padd = wpinv_get_option('invoice_number_padd');
2051
+    $prefix  = wpinv_get_option('invoice_number_prefix');
2052
+    $postfix = wpinv_get_option('invoice_number_postfix');
2053 2053
     
2054
-    $padd = absint( $padd );
2055
-    $formatted_number = absint( $number );
2054
+    $padd = absint($padd);
2055
+    $formatted_number = absint($number);
2056 2056
     
2057
-    if ( $padd > 0 ) {
2058
-        $formatted_number = zeroise( $formatted_number, $padd );
2057
+    if ($padd > 0) {
2058
+        $formatted_number = zeroise($formatted_number, $padd);
2059 2059
     }    
2060 2060
 
2061 2061
     $formatted_number = $prefix . $formatted_number . $postfix;
2062 2062
 
2063
-    return apply_filters( 'wpinv_format_invoice_number', $formatted_number, $number, $prefix, $postfix, $padd );
2063
+    return apply_filters('wpinv_format_invoice_number', $formatted_number, $number, $prefix, $postfix, $padd);
2064 2064
 }
2065 2065
 
2066
-function wpinv_get_next_invoice_number( $type = '' ) {
2067
-    $check = apply_filters( 'wpinv_get_pre_next_invoice_number', null, $type );
2068
-    if ( null !== $check ) {
2066
+function wpinv_get_next_invoice_number($type = '') {
2067
+    $check = apply_filters('wpinv_get_pre_next_invoice_number', null, $type);
2068
+    if (null !== $check) {
2069 2069
         return $check;
2070 2070
     }
2071 2071
     
2072
-    if ( !wpinv_sequential_number_active() ) {
2072
+    if (!wpinv_sequential_number_active()) {
2073 2073
         return false;
2074 2074
     }
2075 2075
 
2076
-    $number = $last_number = get_option( 'wpinv_last_invoice_number' );
2077
-    $start  = wpinv_get_option( 'invoice_sequence_start' );
2078
-    if ( !absint( $start ) > 0 ) {
2076
+    $number = $last_number = get_option('wpinv_last_invoice_number');
2077
+    $start  = wpinv_get_option('invoice_sequence_start');
2078
+    if (!absint($start) > 0) {
2079 2079
         $start = 1;
2080 2080
     }
2081 2081
     $increment_number = true;
2082 2082
     $save_number = false;
2083 2083
 
2084
-    if ( !empty( $number ) && !is_numeric( $number ) && $number == wpinv_format_invoice_number( $number ) ) {
2085
-        $number = wpinv_clean_invoice_number( $number );
2084
+    if (!empty($number) && !is_numeric($number) && $number == wpinv_format_invoice_number($number)) {
2085
+        $number = wpinv_clean_invoice_number($number);
2086 2086
     }
2087 2087
 
2088
-    if ( empty( $number ) ) {
2089
-        if ( !( $last_number === 0 || $last_number === '0' ) ) {
2090
-            $last_invoice = wpinv_get_invoices( array( 'limit' => 1, 'order' => 'DESC', 'orderby' => 'ID', 'return' => 'posts', 'fields' => 'ids', 'status' => array_keys( wpinv_get_invoice_statuses( true ) ) ) );
2088
+    if (empty($number)) {
2089
+        if (!($last_number === 0 || $last_number === '0')) {
2090
+            $last_invoice = wpinv_get_invoices(array('limit' => 1, 'order' => 'DESC', 'orderby' => 'ID', 'return' => 'posts', 'fields' => 'ids', 'status' => array_keys(wpinv_get_invoice_statuses(true))));
2091 2091
 
2092
-            if ( !empty( $last_invoice[0] ) && $invoice_number = wpinv_get_invoice_number( $last_invoice[0] ) ) {
2093
-                if ( is_numeric( $invoice_number ) ) {
2092
+            if (!empty($last_invoice[0]) && $invoice_number = wpinv_get_invoice_number($last_invoice[0])) {
2093
+                if (is_numeric($invoice_number)) {
2094 2094
                     $number = $invoice_number;
2095 2095
                 } else {
2096
-                    $number = wpinv_clean_invoice_number( $invoice_number );
2096
+                    $number = wpinv_clean_invoice_number($invoice_number);
2097 2097
                 }
2098 2098
             }
2099 2099
 
2100
-            if ( empty( $number ) ) {
2100
+            if (empty($number)) {
2101 2101
                 $increment_number = false;
2102 2102
                 $number = $start;
2103
-                $save_number = ( $number - 1 );
2103
+                $save_number = ($number - 1);
2104 2104
             } else {
2105 2105
                 $save_number = $number;
2106 2106
             }
2107 2107
         }
2108 2108
     }
2109 2109
 
2110
-    if ( $start > $number ) {
2110
+    if ($start > $number) {
2111 2111
         $increment_number = false;
2112 2112
         $number = $start;
2113
-        $save_number = ( $number - 1 );
2113
+        $save_number = ($number - 1);
2114 2114
     }
2115 2115
 
2116
-    if ( $save_number !== false ) {
2117
-        update_option( 'wpinv_last_invoice_number', $save_number );
2116
+    if ($save_number !== false) {
2117
+        update_option('wpinv_last_invoice_number', $save_number);
2118 2118
     }
2119 2119
     
2120
-    $increment_number = apply_filters( 'wpinv_increment_payment_number', $increment_number, $number );
2120
+    $increment_number = apply_filters('wpinv_increment_payment_number', $increment_number, $number);
2121 2121
 
2122
-    if ( $increment_number ) {
2122
+    if ($increment_number) {
2123 2123
         $number++;
2124 2124
     }
2125 2125
 
2126
-    return apply_filters( 'wpinv_get_next_invoice_number', $number );
2126
+    return apply_filters('wpinv_get_next_invoice_number', $number);
2127 2127
 }
2128 2128
 
2129
-function wpinv_clean_invoice_number( $number, $type = '' ) {
2130
-    $check = apply_filters( 'wpinv_pre_clean_invoice_number', null, $number, $type );
2131
-    if ( null !== $check ) {
2129
+function wpinv_clean_invoice_number($number, $type = '') {
2130
+    $check = apply_filters('wpinv_pre_clean_invoice_number', null, $number, $type);
2131
+    if (null !== $check) {
2132 2132
         return $check;
2133 2133
     }
2134 2134
     
2135
-    $prefix  = wpinv_get_option( 'invoice_number_prefix' );
2136
-    $postfix = wpinv_get_option( 'invoice_number_postfix' );
2135
+    $prefix  = wpinv_get_option('invoice_number_prefix');
2136
+    $postfix = wpinv_get_option('invoice_number_postfix');
2137 2137
 
2138
-    $number = preg_replace( '/' . $prefix . '/', '', $number, 1 );
2138
+    $number = preg_replace('/' . $prefix . '/', '', $number, 1);
2139 2139
 
2140
-    $length      = strlen( $number );
2141
-    $postfix_pos = strrpos( $number, $postfix );
2140
+    $length      = strlen($number);
2141
+    $postfix_pos = strrpos($number, $postfix);
2142 2142
     
2143
-    if ( false !== $postfix_pos ) {
2144
-        $number      = substr_replace( $number, '', $postfix_pos, $length );
2143
+    if (false !== $postfix_pos) {
2144
+        $number = substr_replace($number, '', $postfix_pos, $length);
2145 2145
     }
2146 2146
 
2147
-    $number = intval( $number );
2147
+    $number = intval($number);
2148 2148
 
2149
-    return apply_filters( 'wpinv_clean_invoice_number', $number, $prefix, $postfix );
2149
+    return apply_filters('wpinv_clean_invoice_number', $number, $prefix, $postfix);
2150 2150
 }
2151 2151
 
2152
-function wpinv_save_number_post_saved( $post_ID, $post, $update ) {
2152
+function wpinv_save_number_post_saved($post_ID, $post, $update) {
2153 2153
     global $wpdb;
2154 2154
 
2155
-    if ( !$update && !get_post_meta( $post_ID, '_wpinv_number', true ) ) {
2156
-        wpinv_update_invoice_number( $post_ID, $post->post_status != 'auto-draft', $post->post_type );
2155
+    if (!$update && !get_post_meta($post_ID, '_wpinv_number', true)) {
2156
+        wpinv_update_invoice_number($post_ID, $post->post_status != 'auto-draft', $post->post_type);
2157 2157
     }
2158 2158
 
2159
-    if ( !$update ) {
2160
-        $wpdb->update( $wpdb->posts, array( 'post_name' => wpinv_generate_post_name( $post_ID ) ), array( 'ID' => $post_ID ) );
2161
-        clean_post_cache( $post_ID );
2159
+    if (!$update) {
2160
+        $wpdb->update($wpdb->posts, array('post_name' => wpinv_generate_post_name($post_ID)), array('ID' => $post_ID));
2161
+        clean_post_cache($post_ID);
2162 2162
     }
2163 2163
 }
2164
-add_action( 'save_post_wpi_invoice', 'wpinv_save_number_post_saved', 1, 3 );
2164
+add_action('save_post_wpi_invoice', 'wpinv_save_number_post_saved', 1, 3);
2165 2165
 
2166
-function wpinv_save_number_post_updated( $post_ID, $post_after, $post_before ) {
2167
-    if ( !empty( $post_after->post_type ) && $post_after->post_type == 'wpi_invoice' && $post_before->post_status == 'auto-draft' && $post_after->post_status != $post_before->post_status ) {
2168
-        wpinv_update_invoice_number( $post_ID, true, $post_after->post_type );
2166
+function wpinv_save_number_post_updated($post_ID, $post_after, $post_before) {
2167
+    if (!empty($post_after->post_type) && $post_after->post_type == 'wpi_invoice' && $post_before->post_status == 'auto-draft' && $post_after->post_status != $post_before->post_status) {
2168
+        wpinv_update_invoice_number($post_ID, true, $post_after->post_type);
2169 2169
     }
2170 2170
 }
2171
-add_action( 'post_updated', 'wpinv_save_number_post_updated', 1, 3 );
2171
+add_action('post_updated', 'wpinv_save_number_post_updated', 1, 3);
2172 2172
 
2173
-function wpinv_update_invoice_number( $post_ID, $save_sequential = false, $type = '' ) {
2173
+function wpinv_update_invoice_number($post_ID, $save_sequential = false, $type = '') {
2174 2174
     global $wpdb;
2175 2175
     
2176
-    $check = apply_filters( 'wpinv_pre_update_invoice_number', null, $post_ID, $save_sequential, $type );
2177
-    if ( null !== $check ) {
2176
+    $check = apply_filters('wpinv_pre_update_invoice_number', null, $post_ID, $save_sequential, $type);
2177
+    if (null !== $check) {
2178 2178
         return $check;
2179 2179
     }
2180 2180
 
2181
-    if ( wpinv_sequential_number_active() ) {
2181
+    if (wpinv_sequential_number_active()) {
2182 2182
         $number = wpinv_get_next_invoice_number();
2183 2183
 
2184
-        if ( $save_sequential ) {
2185
-            update_option( 'wpinv_last_invoice_number', $number );
2184
+        if ($save_sequential) {
2185
+            update_option('wpinv_last_invoice_number', $number);
2186 2186
         }
2187 2187
     } else {
2188 2188
         $number = $post_ID;
2189 2189
     }
2190 2190
 
2191
-    $number = wpinv_format_invoice_number( $number );
2191
+    $number = wpinv_format_invoice_number($number);
2192 2192
 
2193
-    update_post_meta( $post_ID, '_wpinv_number', $number );
2193
+    update_post_meta($post_ID, '_wpinv_number', $number);
2194 2194
 
2195
-    $wpdb->update( $wpdb->posts, array( 'post_title' => $number ), array( 'ID' => $post_ID ) );
2195
+    $wpdb->update($wpdb->posts, array('post_title' => $number), array('ID' => $post_ID));
2196 2196
 
2197
-    clean_post_cache( $post_ID );
2197
+    clean_post_cache($post_ID);
2198 2198
 
2199 2199
     return $number;
2200 2200
 }
2201 2201
 
2202
-function wpinv_post_name_prefix( $post_type = 'wpi_invoice' ) {
2203
-    return apply_filters( 'wpinv_post_name_prefix', 'inv-', $post_type );
2202
+function wpinv_post_name_prefix($post_type = 'wpi_invoice') {
2203
+    return apply_filters('wpinv_post_name_prefix', 'inv-', $post_type);
2204 2204
 }
2205 2205
 
2206
-function wpinv_generate_post_name( $post_ID ) {
2207
-    $prefix = wpinv_post_name_prefix( get_post_type( $post_ID ) );
2208
-    $post_name = sanitize_title( $prefix . $post_ID );
2206
+function wpinv_generate_post_name($post_ID) {
2207
+    $prefix = wpinv_post_name_prefix(get_post_type($post_ID));
2208
+    $post_name = sanitize_title($prefix . $post_ID);
2209 2209
 
2210
-    return apply_filters( 'wpinv_generate_post_name', $post_name, $post_ID, $prefix );
2210
+    return apply_filters('wpinv_generate_post_name', $post_name, $post_ID, $prefix);
2211 2211
 }
2212 2212
 
2213
-function wpinv_is_invoice_viewed( $invoice_id ) {
2214
-    if ( empty( $invoice_id ) ) {
2213
+function wpinv_is_invoice_viewed($invoice_id) {
2214
+    if (empty($invoice_id)) {
2215 2215
         return false;
2216 2216
     }
2217 2217
 
2218
-    $viewed_meta = get_post_meta( $invoice_id, '_wpinv_is_viewed', true );
2218
+    $viewed_meta = get_post_meta($invoice_id, '_wpinv_is_viewed', true);
2219 2219
 
2220
-    if ( isset($viewed_meta) && 1 == $viewed_meta ) {
2220
+    if (isset($viewed_meta) && 1 == $viewed_meta) {
2221 2221
         $is_viewed = true;
2222 2222
     } else {
2223 2223
         $is_viewed = false;
2224 2224
     }
2225 2225
 
2226
-    return apply_filters( 'wpinv_is_invoice_viewed', $is_viewed, $invoice_id );
2226
+    return apply_filters('wpinv_is_invoice_viewed', $is_viewed, $invoice_id);
2227 2227
 }
2228 2228
 
2229 2229
 function wpinv_mark_invoice_viewed() {
2230 2230
 
2231
-    if ( isset( $_GET['invoice_key'] ) ) {
2231
+    if (isset($_GET['invoice_key'])) {
2232 2232
         $invoice_key = urldecode($_GET['invoice_key']);
2233 2233
 
2234 2234
         $invoice_id = wpinv_get_invoice_id_by_key($invoice_key);
2235 2235
         $invoice = new WPInv_Invoice($invoice_id);
2236 2236
 
2237
-        if(!$invoice_id){
2237
+        if (!$invoice_id) {
2238 2238
             return;
2239 2239
         }
2240 2240
 
2241
-        if( is_user_logged_in()){
2241
+        if (is_user_logged_in()) {
2242 2242
             $current_user = wp_get_current_user();
2243
-            if(!current_user_can('administrator') && $current_user->user_email == $invoice->get_email()){
2244
-                update_post_meta($invoice_id,'_wpinv_is_viewed', 1);
2243
+            if (!current_user_can('administrator') && $current_user->user_email == $invoice->get_email()) {
2244
+                update_post_meta($invoice_id, '_wpinv_is_viewed', 1);
2245 2245
             }
2246 2246
         } else {
2247
-            update_post_meta($invoice_id,'_wpinv_is_viewed', 1);
2247
+            update_post_meta($invoice_id, '_wpinv_is_viewed', 1);
2248 2248
         }
2249 2249
     }
2250 2250
 
2251 2251
 }
2252
-add_action( 'init', 'wpinv_mark_invoice_viewed' );
2252
+add_action('init', 'wpinv_mark_invoice_viewed');
2253 2253
 
2254
-function wpinv_get_subscription( $invoice ) {
2255
-    if ( empty( $invoice ) ) {
2254
+function wpinv_get_subscription($invoice) {
2255
+    if (empty($invoice)) {
2256 2256
         return false;
2257 2257
     }
2258 2258
     
2259
-    if ( ! is_object( $invoice ) && is_scalar( $invoice ) ) {
2260
-        $invoice = wpinv_get_invoice( $invoice );
2259
+    if (!is_object($invoice) && is_scalar($invoice)) {
2260
+        $invoice = wpinv_get_invoice($invoice);
2261 2261
     }
2262 2262
     
2263
-    if ( !( is_object( $invoice ) && ! empty( $invoice->ID ) && $invoice->is_recurring() ) ) {
2263
+    if (!(is_object($invoice) && !empty($invoice->ID) && $invoice->is_recurring())) {
2264 2264
         return false;
2265 2265
     }
2266 2266
     
2267
-    $invoice_id = ! empty( $invoice->parent_invoice ) ? $invoice->parent_invoice : $invoice->ID;
2267
+    $invoice_id = !empty($invoice->parent_invoice) ? $invoice->parent_invoice : $invoice->ID;
2268 2268
     
2269 2269
     $subs_db    = new WPInv_Subscriptions_DB;
2270
-    $subs       = $subs_db->get_subscriptions( array( 'parent_payment_id' => $invoice_id, 'number' => 1 ) );
2270
+    $subs       = $subs_db->get_subscriptions(array('parent_payment_id' => $invoice_id, 'number' => 1));
2271 2271
     
2272
-    if ( ! empty( $subs ) ) {
2273
-        return reset( $subs );
2272
+    if (!empty($subs)) {
2273
+        return reset($subs);
2274 2274
     }
2275 2275
     
2276 2276
     return false;
Please login to merge, or discard this patch.
includes/wpinv-template-functions.php 1 patch
Spacing   +682 added lines, -682 removed lines patch added patch discarded remove patch
@@ -7,91 +7,91 @@  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', wpinv_get_theme_template_dir_name() );
22
+    return apply_filters('wpinv_template_path', wpinv_get_theme_template_dir_name());
23 23
 }
24 24
 
25
-function wpinv_display_invoice_top_bar( $invoice ) {
26
-    if ( empty( $invoice ) ) {
25
+function wpinv_display_invoice_top_bar($invoice) {
26
+    if (empty($invoice)) {
27 27
         return;
28 28
     }
29 29
     ?>
30 30
     <div class="row wpinv-top-bar no-print">
31 31
         <div class="container">
32 32
             <div class="col-xs-6">
33
-                <?php do_action( 'wpinv_invoice_top_bar_left', $invoice );?>
33
+                <?php do_action('wpinv_invoice_top_bar_left', $invoice); ?>
34 34
             </div>
35 35
             <div class="col-xs-6 text-right">
36
-                <?php do_action( 'wpinv_invoice_top_bar_right', $invoice );?>
36
+                <?php do_action('wpinv_invoice_top_bar_right', $invoice); ?>
37 37
             </div>
38 38
         </div>
39 39
     </div>
40 40
     <?php
41 41
 }
42 42
 
43
-function wpinv_invoice_display_left_actions( $invoice ) {
44
-    if ( empty( $invoice ) ) {
43
+function wpinv_invoice_display_left_actions($invoice) {
44
+    if (empty($invoice)) {
45 45
         return; // Exit if invoice is not set.
46 46
     }
47 47
     
48
-    if ( $invoice->post_type == 'wpi_invoice' ) {
49
-        if ( $invoice->needs_payment() ) {
50
-            ?> <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
48
+    if ($invoice->post_type == 'wpi_invoice') {
49
+        if ($invoice->needs_payment()) {
50
+            ?> <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
51 51
         }
52 52
     }
53 53
     do_action('wpinv_invoice_display_left_actions', $invoice);
54 54
 }
55 55
 
56
-function wpinv_invoice_display_right_actions( $invoice ) {
57
-    if ( empty( $invoice ) ) {
56
+function wpinv_invoice_display_right_actions($invoice) {
57
+    if (empty($invoice)) {
58 58
         return; // Exit if invoice is not set.
59 59
     }
60 60
 
61
-    if ( $invoice->post_type == 'wpi_invoice' ) { ?>
62
-        <a class="btn btn-primary btn-sm" onclick="window.print();" href="javascript:void(0)"><?php _e( 'Print Invoice', 'invoicing' ); ?></a>
63
-        <?php if ( is_user_logged_in() ) { ?>
64
-        &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>
61
+    if ($invoice->post_type == 'wpi_invoice') { ?>
62
+        <a class="btn btn-primary btn-sm" onclick="window.print();" href="javascript:void(0)"><?php _e('Print Invoice', 'invoicing'); ?></a>
63
+        <?php if (is_user_logged_in()) { ?>
64
+        &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>
65 65
         <?php }
66 66
     }
67 67
     do_action('wpinv_invoice_display_right_actions', $invoice);
68 68
 }
69 69
 
70
-function wpinv_before_invoice_content( $content ) {
70
+function wpinv_before_invoice_content($content) {
71 71
     global $post;
72 72
 
73
-    if ( !empty( $post ) && $post->post_type == 'wpi_invoice' && is_singular( 'wpi_invoice' ) && is_main_query() ) {
73
+    if (!empty($post) && $post->post_type == 'wpi_invoice' && is_singular('wpi_invoice') && is_main_query()) {
74 74
         ob_start();
75
-        do_action( 'wpinv_before_invoice_content', $post->ID );
75
+        do_action('wpinv_before_invoice_content', $post->ID);
76 76
         $content = ob_get_clean() . $content;
77 77
     }
78 78
 
79 79
     return $content;
80 80
 }
81
-add_filter( 'the_content', 'wpinv_before_invoice_content' );
81
+add_filter('the_content', 'wpinv_before_invoice_content');
82 82
 
83
-function wpinv_after_invoice_content( $content ) {
83
+function wpinv_after_invoice_content($content) {
84 84
     global $post;
85 85
 
86
-    if ( !empty( $post ) && $post->post_type == 'wpi_invoice' && is_singular( 'wpi_invoice' ) && is_main_query() ) {
86
+    if (!empty($post) && $post->post_type == 'wpi_invoice' && is_singular('wpi_invoice') && is_main_query()) {
87 87
         ob_start();
88
-        do_action( 'wpinv_after_invoice_content', $post->ID );
88
+        do_action('wpinv_after_invoice_content', $post->ID);
89 89
         $content .= ob_get_clean();
90 90
     }
91 91
 
92 92
     return $content;
93 93
 }
94
-add_filter( 'the_content', 'wpinv_after_invoice_content' );
94
+add_filter('the_content', 'wpinv_after_invoice_content');
95 95
 
96 96
 function wpinv_get_templates_dir() {
97 97
     return WPINV_PLUGIN_DIR . 'templates';
@@ -101,105 +101,105 @@  discard block
 block discarded – undo
101 101
     return WPINV_PLUGIN_URL . 'templates';
102 102
 }
103 103
 
104
-function wpinv_get_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) {
105
-    if ( ! empty( $args ) && is_array( $args ) ) {
106
-		extract( $args );
104
+function wpinv_get_template($template_name, $args = array(), $template_path = '', $default_path = '') {
105
+    if (!empty($args) && is_array($args)) {
106
+		extract($args);
107 107
 	}
108 108
 
109
-	$located = wpinv_locate_template( $template_name, $template_path, $default_path );
109
+	$located = wpinv_locate_template($template_name, $template_path, $default_path);
110 110
 	// Allow 3rd party plugin filter template file from their plugin.
111
-	$located = apply_filters( 'wpinv_get_template', $located, $template_name, $args, $template_path, $default_path );
111
+	$located = apply_filters('wpinv_get_template', $located, $template_name, $args, $template_path, $default_path);
112 112
 
113
-	if ( ! file_exists( $located ) ) {
114
-        _doing_it_wrong( __FUNCTION__, sprintf( '<code>%s</code> does not exist.', $located ), '2.1' );
113
+	if (!file_exists($located)) {
114
+        _doing_it_wrong(__FUNCTION__, sprintf('<code>%s</code> does not exist.', $located), '2.1');
115 115
 		return;
116 116
 	}
117 117
 
118
-	do_action( 'wpinv_before_template_part', $template_name, $template_path, $located, $args );
118
+	do_action('wpinv_before_template_part', $template_name, $template_path, $located, $args);
119 119
 
120
-	include( $located );
120
+	include($located);
121 121
 
122
-	do_action( 'wpinv_after_template_part', $template_name, $template_path, $located, $args );
122
+	do_action('wpinv_after_template_part', $template_name, $template_path, $located, $args);
123 123
 }
124 124
 
125
-function wpinv_get_template_html( $template_name, $args = array(), $template_path = '', $default_path = '' ) {
125
+function wpinv_get_template_html($template_name, $args = array(), $template_path = '', $default_path = '') {
126 126
 	ob_start();
127
-	wpinv_get_template( $template_name, $args, $template_path, $default_path );
127
+	wpinv_get_template($template_name, $args, $template_path, $default_path);
128 128
 	return ob_get_clean();
129 129
 }
130 130
 
131
-function wpinv_locate_template( $template_name, $template_path = '', $default_path = '' ) {
132
-    if ( ! $template_path ) {
131
+function wpinv_locate_template($template_name, $template_path = '', $default_path = '') {
132
+    if (!$template_path) {
133 133
         $template_path = wpinv_template_path();
134 134
     }
135 135
 
136
-    if ( ! $default_path ) {
136
+    if (!$default_path) {
137 137
         $default_path = WPINV_PLUGIN_DIR . 'templates/';
138 138
     }
139 139
 
140 140
     // Look within passed path within the theme - this is priority.
141 141
     $template = locate_template(
142 142
         array(
143
-            trailingslashit( $template_path ) . $template_name,
143
+            trailingslashit($template_path) . $template_name,
144 144
             $template_name
145 145
         )
146 146
     );
147 147
 
148 148
     // Get default templates/
149
-    if ( !$template && $default_path ) {
150
-        $template = trailingslashit( $default_path ) . $template_name;
149
+    if (!$template && $default_path) {
150
+        $template = trailingslashit($default_path) . $template_name;
151 151
     }
152 152
 
153 153
     // Return what we found.
154
-    return apply_filters( 'wpinv_locate_template', $template, $template_name, $template_path );
154
+    return apply_filters('wpinv_locate_template', $template, $template_name, $template_path);
155 155
 }
156 156
 
157
-function wpinv_get_template_part( $slug, $name = null, $load = true ) {
158
-	do_action( 'get_template_part_' . $slug, $slug, $name );
157
+function wpinv_get_template_part($slug, $name = null, $load = true) {
158
+	do_action('get_template_part_' . $slug, $slug, $name);
159 159
 
160 160
 	// Setup possible parts
161 161
 	$templates = array();
162
-	if ( isset( $name ) )
162
+	if (isset($name))
163 163
 		$templates[] = $slug . '-' . $name . '.php';
164 164
 	$templates[] = $slug . '.php';
165 165
 
166 166
 	// Allow template parts to be filtered
167
-	$templates = apply_filters( 'wpinv_get_template_part', $templates, $slug, $name );
167
+	$templates = apply_filters('wpinv_get_template_part', $templates, $slug, $name);
168 168
 
169 169
 	// Return the part that is found
170
-	return wpinv_locate_tmpl( $templates, $load, false );
170
+	return wpinv_locate_tmpl($templates, $load, false);
171 171
 }
172 172
 
173
-function wpinv_locate_tmpl( $template_names, $load = false, $require_once = true ) {
173
+function wpinv_locate_tmpl($template_names, $load = false, $require_once = true) {
174 174
 	// No file found yet
175 175
 	$located = false;
176 176
 
177 177
 	// Try to find a template file
178
-	foreach ( (array)$template_names as $template_name ) {
178
+	foreach ((array)$template_names as $template_name) {
179 179
 
180 180
 		// Continue if template is empty
181
-		if ( empty( $template_name ) )
181
+		if (empty($template_name))
182 182
 			continue;
183 183
 
184 184
 		// Trim off any slashes from the template name
185
-		$template_name = ltrim( $template_name, '/' );
185
+		$template_name = ltrim($template_name, '/');
186 186
 
187 187
 		// try locating this template file by looping through the template paths
188
-		foreach( wpinv_get_theme_template_paths() as $template_path ) {
188
+		foreach (wpinv_get_theme_template_paths() as $template_path) {
189 189
 
190
-			if( file_exists( $template_path . $template_name ) ) {
190
+			if (file_exists($template_path . $template_name)) {
191 191
 				$located = $template_path . $template_name;
192 192
 				break;
193 193
 			}
194 194
 		}
195 195
 
196
-		if( !empty( $located ) ) {
196
+		if (!empty($located)) {
197 197
 			break;
198 198
 		}
199 199
 	}
200 200
 
201
-	if ( ( true == $load ) && ! empty( $located ) )
202
-		load_template( $located, $require_once );
201
+	if ((true == $load) && !empty($located))
202
+		load_template($located, $require_once);
203 203
 
204 204
 	return $located;
205 205
 }
@@ -208,149 +208,149 @@  discard block
 block discarded – undo
208 208
 	$template_dir = wpinv_get_theme_template_dir_name();
209 209
 
210 210
 	$file_paths = array(
211
-		1 => trailingslashit( get_stylesheet_directory() ) . $template_dir,
212
-		10 => trailingslashit( get_template_directory() ) . $template_dir,
211
+		1 => trailingslashit(get_stylesheet_directory()) . $template_dir,
212
+		10 => trailingslashit(get_template_directory()) . $template_dir,
213 213
 		100 => wpinv_get_templates_dir()
214 214
 	);
215 215
 
216
-	$file_paths = apply_filters( 'wpinv_template_paths', $file_paths );
216
+	$file_paths = apply_filters('wpinv_template_paths', $file_paths);
217 217
 
218 218
 	// sort the file paths based on priority
219
-	ksort( $file_paths, SORT_NUMERIC );
219
+	ksort($file_paths, SORT_NUMERIC);
220 220
 
221
-	return array_map( 'trailingslashit', $file_paths );
221
+	return array_map('trailingslashit', $file_paths);
222 222
 }
223 223
 
224 224
 function wpinv_get_theme_template_dir_name() {
225
-	return trailingslashit( apply_filters( 'wpinv_templates_dir', 'invoicing' ) );
225
+	return trailingslashit(apply_filters('wpinv_templates_dir', 'invoicing'));
226 226
 }
227 227
 
228 228
 function wpinv_checkout_meta_tags() {
229 229
 
230 230
 	$pages   = array();
231
-	$pages[] = wpinv_get_option( 'success_page' );
232
-	$pages[] = wpinv_get_option( 'failure_page' );
233
-	$pages[] = wpinv_get_option( 'invoice_history_page' );
234
-	$pages[] = wpinv_get_option( 'invoice_subscription_page' );
231
+	$pages[] = wpinv_get_option('success_page');
232
+	$pages[] = wpinv_get_option('failure_page');
233
+	$pages[] = wpinv_get_option('invoice_history_page');
234
+	$pages[] = wpinv_get_option('invoice_subscription_page');
235 235
 
236
-	if( !wpinv_is_checkout() && !is_page( $pages ) ) {
236
+	if (!wpinv_is_checkout() && !is_page($pages)) {
237 237
 		return;
238 238
 	}
239 239
 
240 240
 	echo '<meta name="robots" content="noindex,nofollow" />' . "\n";
241 241
 }
242
-add_action( 'wp_head', 'wpinv_checkout_meta_tags' );
242
+add_action('wp_head', 'wpinv_checkout_meta_tags');
243 243
 
244
-function wpinv_add_body_classes( $class ) {
244
+function wpinv_add_body_classes($class) {
245 245
 	$classes = (array)$class;
246 246
 
247
-	if( wpinv_is_checkout() ) {
247
+	if (wpinv_is_checkout()) {
248 248
 		$classes[] = 'wpinv-checkout';
249 249
 		$classes[] = 'wpinv-page';
250 250
 	}
251 251
 
252
-	if( wpinv_is_success_page() ) {
252
+	if (wpinv_is_success_page()) {
253 253
 		$classes[] = 'wpinv-success';
254 254
 		$classes[] = 'wpinv-page';
255 255
 	}
256 256
 
257
-	if( wpinv_is_failed_transaction_page() ) {
257
+	if (wpinv_is_failed_transaction_page()) {
258 258
 		$classes[] = 'wpinv-failed-transaction';
259 259
 		$classes[] = 'wpinv-page';
260 260
 	}
261 261
 
262
-	if( wpinv_is_invoice_history_page() ) {
262
+	if (wpinv_is_invoice_history_page()) {
263 263
 		$classes[] = 'wpinv-history';
264 264
 		$classes[] = 'wpinv-page';
265 265
 	}
266 266
 
267
-	if( wpinv_is_subscriptions_history_page() ) {
267
+	if (wpinv_is_subscriptions_history_page()) {
268 268
 		$classes[] = 'wpinv-subscription';
269 269
 		$classes[] = 'wpinv-page';
270 270
 	}
271 271
 
272
-	if( wpinv_is_test_mode() ) {
272
+	if (wpinv_is_test_mode()) {
273 273
 		$classes[] = 'wpinv-test-mode';
274 274
 		$classes[] = 'wpinv-page';
275 275
 	}
276 276
 
277
-	return array_unique( $classes );
277
+	return array_unique($classes);
278 278
 }
279
-add_filter( 'body_class', 'wpinv_add_body_classes' );
279
+add_filter('body_class', 'wpinv_add_body_classes');
280 280
 
281
-function wpinv_html_dropdown( $name = 'wpinv_discounts', $selected = 0, $status = '' ) {
282
-    $args = array( 'nopaging' => true );
281
+function wpinv_html_dropdown($name = 'wpinv_discounts', $selected = 0, $status = '') {
282
+    $args = array('nopaging' => true);
283 283
 
284
-    if ( ! empty( $status ) )
284
+    if (!empty($status))
285 285
         $args['post_status'] = $status;
286 286
 
287
-    $discounts = wpinv_get_discounts( $args );
287
+    $discounts = wpinv_get_discounts($args);
288 288
     $options   = array();
289 289
 
290
-    if ( $discounts ) {
291
-        foreach ( $discounts as $discount ) {
292
-            $options[ absint( $discount->ID ) ] = esc_html( get_the_title( $discount->ID ) );
290
+    if ($discounts) {
291
+        foreach ($discounts as $discount) {
292
+            $options[absint($discount->ID)] = esc_html(get_the_title($discount->ID));
293 293
         }
294 294
     } else {
295
-        $options[0] = __( 'No discounts found', 'invoicing' );
295
+        $options[0] = __('No discounts found', 'invoicing');
296 296
     }
297 297
 
298
-    $output = wpinv_html_select( array(
298
+    $output = wpinv_html_select(array(
299 299
         'name'             => $name,
300 300
         'selected'         => $selected,
301 301
         'options'          => $options,
302 302
         'show_option_all'  => false,
303 303
         'show_option_none' => false,
304
-    ) );
304
+    ));
305 305
 
306 306
     return $output;
307 307
 }
308 308
 
309
-function wpinv_html_year_dropdown( $name = 'year', $selected = 0, $years_before = 5, $years_after = 0 ) {
310
-    $current     = date( 'Y' );
311
-    $start_year  = $current - absint( $years_before );
312
-    $end_year    = $current + absint( $years_after );
313
-    $selected    = empty( $selected ) ? date( 'Y' ) : $selected;
309
+function wpinv_html_year_dropdown($name = 'year', $selected = 0, $years_before = 5, $years_after = 0) {
310
+    $current     = date('Y');
311
+    $start_year  = $current - absint($years_before);
312
+    $end_year    = $current + absint($years_after);
313
+    $selected    = empty($selected) ? date('Y') : $selected;
314 314
     $options     = array();
315 315
 
316
-    while ( $start_year <= $end_year ) {
317
-        $options[ absint( $start_year ) ] = $start_year;
316
+    while ($start_year <= $end_year) {
317
+        $options[absint($start_year)] = $start_year;
318 318
         $start_year++;
319 319
     }
320 320
 
321
-    $output = wpinv_html_select( array(
321
+    $output = wpinv_html_select(array(
322 322
         'name'             => $name,
323 323
         'selected'         => $selected,
324 324
         'options'          => $options,
325 325
         'show_option_all'  => false,
326 326
         'show_option_none' => false
327
-    ) );
327
+    ));
328 328
 
329 329
     return $output;
330 330
 }
331 331
 
332
-function wpinv_html_month_dropdown( $name = 'month', $selected = 0 ) {
332
+function wpinv_html_month_dropdown($name = 'month', $selected = 0) {
333 333
     $month   = 1;
334 334
     $options = array();
335
-    $selected = empty( $selected ) ? date( 'n' ) : $selected;
335
+    $selected = empty($selected) ? date('n') : $selected;
336 336
 
337
-    while ( $month <= 12 ) {
338
-        $options[ absint( $month ) ] = wpinv_month_num_to_name( $month );
337
+    while ($month <= 12) {
338
+        $options[absint($month)] = wpinv_month_num_to_name($month);
339 339
         $month++;
340 340
     }
341 341
 
342
-    $output = wpinv_html_select( array(
342
+    $output = wpinv_html_select(array(
343 343
         'name'             => $name,
344 344
         'selected'         => $selected,
345 345
         'options'          => $options,
346 346
         'show_option_all'  => false,
347 347
         'show_option_none' => false
348
-    ) );
348
+    ));
349 349
 
350 350
     return $output;
351 351
 }
352 352
 
353
-function wpinv_html_select( $args = array() ) {
353
+function wpinv_html_select($args = array()) {
354 354
     $defaults = array(
355 355
         'options'          => array(),
356 356
         'name'             => null,
@@ -359,8 +359,8 @@  discard block
 block discarded – undo
359 359
         'selected'         => 0,
360 360
         'placeholder'      => null,
361 361
         'multiple'         => false,
362
-        'show_option_all'  => _x( 'All', 'all dropdown items', 'invoicing' ),
363
-        'show_option_none' => _x( 'None', 'no dropdown items', 'invoicing' ),
362
+        'show_option_all'  => _x('All', 'all dropdown items', 'invoicing'),
363
+        'show_option_none' => _x('None', 'no dropdown items', 'invoicing'),
364 364
         'data'             => array(),
365 365
         'onchange'         => null,
366 366
         'required'         => false,
@@ -368,74 +368,74 @@  discard block
 block discarded – undo
368 368
         'readonly'         => false,
369 369
     );
370 370
 
371
-    $args = wp_parse_args( $args, $defaults );
371
+    $args = wp_parse_args($args, $defaults);
372 372
 
373 373
     $data_elements = '';
374
-    foreach ( $args['data'] as $key => $value ) {
375
-        $data_elements .= ' data-' . esc_attr( $key ) . '="' . esc_attr( $value ) . '"';
374
+    foreach ($args['data'] as $key => $value) {
375
+        $data_elements .= ' data-' . esc_attr($key) . '="' . esc_attr($value) . '"';
376 376
     }
377 377
 
378
-    if( $args['multiple'] ) {
378
+    if ($args['multiple']) {
379 379
         $multiple = ' MULTIPLE';
380 380
     } else {
381 381
         $multiple = '';
382 382
     }
383 383
 
384
-    if( $args['placeholder'] ) {
384
+    if ($args['placeholder']) {
385 385
         $placeholder = $args['placeholder'];
386 386
     } else {
387 387
         $placeholder = '';
388 388
     }
389 389
     
390 390
     $options = '';
391
-    if( !empty( $args['onchange'] ) ) {
392
-        $options .= ' onchange="' . esc_attr( $args['onchange'] ) . '"';
391
+    if (!empty($args['onchange'])) {
392
+        $options .= ' onchange="' . esc_attr($args['onchange']) . '"';
393 393
     }
394 394
     
395
-    if( !empty( $args['required'] ) ) {
395
+    if (!empty($args['required'])) {
396 396
         $options .= ' required="required"';
397 397
     }
398 398
     
399
-    if( !empty( $args['disabled'] ) ) {
399
+    if (!empty($args['disabled'])) {
400 400
         $options .= ' disabled';
401 401
     }
402 402
     
403
-    if( !empty( $args['readonly'] ) ) {
403
+    if (!empty($args['readonly'])) {
404 404
         $options .= ' readonly';
405 405
     }
406 406
 
407
-    $class  = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) );
408
-    $output = '<select name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['id'] ) . '" class="wpinv-select ' . $class . '"' . $multiple . ' data-placeholder="' . $placeholder . '" ' . trim( $options ) . $data_elements . '>';
407
+    $class  = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class'])));
408
+    $output = '<select name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['id']) . '" class="wpinv-select ' . $class . '"' . $multiple . ' data-placeholder="' . $placeholder . '" ' . trim($options) . $data_elements . '>';
409 409
 
410
-    if ( $args['show_option_all'] ) {
411
-        if( $args['multiple'] ) {
412
-            $selected = selected( true, in_array( 0, $args['selected'] ), false );
410
+    if ($args['show_option_all']) {
411
+        if ($args['multiple']) {
412
+            $selected = selected(true, in_array(0, $args['selected']), false);
413 413
         } else {
414
-            $selected = selected( $args['selected'], 0, false );
414
+            $selected = selected($args['selected'], 0, false);
415 415
         }
416
-        $output .= '<option value="all"' . $selected . '>' . esc_html( $args['show_option_all'] ) . '</option>';
416
+        $output .= '<option value="all"' . $selected . '>' . esc_html($args['show_option_all']) . '</option>';
417 417
     }
418 418
 
419
-    if ( !empty( $args['options'] ) ) {
419
+    if (!empty($args['options'])) {
420 420
 
421
-        if ( $args['show_option_none'] ) {
422
-            if( $args['multiple'] ) {
423
-                $selected = selected( true, in_array( "", $args['selected'] ), false );
421
+        if ($args['show_option_none']) {
422
+            if ($args['multiple']) {
423
+                $selected = selected(true, in_array("", $args['selected']), false);
424 424
             } else {
425
-                $selected = selected( $args['selected'] === "", true, false );
425
+                $selected = selected($args['selected'] === "", true, false);
426 426
             }
427
-            $output .= '<option value=""' . $selected . '>' . esc_html( $args['show_option_none'] ) . '</option>';
427
+            $output .= '<option value=""' . $selected . '>' . esc_html($args['show_option_none']) . '</option>';
428 428
         }
429 429
 
430
-        foreach( $args['options'] as $key => $option ) {
430
+        foreach ($args['options'] as $key => $option) {
431 431
 
432
-            if( $args['multiple'] && is_array( $args['selected'] ) ) {
433
-                $selected = selected( true, (bool)in_array( $key, $args['selected'] ), false );
432
+            if ($args['multiple'] && is_array($args['selected'])) {
433
+                $selected = selected(true, (bool)in_array($key, $args['selected']), false);
434 434
             } else {
435
-                $selected = selected( $args['selected'], $key, false );
435
+                $selected = selected($args['selected'], $key, false);
436 436
             }
437 437
 
438
-            $output .= '<option value="' . esc_attr( $key ) . '"' . $selected . '>' . esc_html( $option ) . '</option>';
438
+            $output .= '<option value="' . esc_attr($key) . '"' . $selected . '>' . esc_html($option) . '</option>';
439 439
         }
440 440
     }
441 441
 
@@ -444,7 +444,7 @@  discard block
 block discarded – undo
444 444
     return $output;
445 445
 }
446 446
 
447
-function wpinv_item_dropdown( $args = array() ) {
447
+function wpinv_item_dropdown($args = array()) {
448 448
     $defaults = array(
449 449
         'name'              => 'wpi_item',
450 450
         'id'                => 'wpi_item',
@@ -452,14 +452,14 @@  discard block
 block discarded – undo
452 452
         'multiple'          => false,
453 453
         'selected'          => 0,
454 454
         'number'            => 100,
455
-        'placeholder'       => __( 'Choose a item', 'invoicing' ),
456
-        'data'              => array( 'search-type' => 'item' ),
455
+        'placeholder'       => __('Choose a item', 'invoicing'),
456
+        'data'              => array('search-type' => 'item'),
457 457
         'show_option_all'   => false,
458 458
         'show_option_none'  => false,
459 459
         'show_recurring'    => false,
460 460
     );
461 461
 
462
-    $args = wp_parse_args( $args, $defaults );
462
+    $args = wp_parse_args($args, $defaults);
463 463
 
464 464
     $item_args = array(
465 465
         'post_type'      => 'wpi_item',
@@ -468,44 +468,44 @@  discard block
 block discarded – undo
468 468
         'posts_per_page' => $args['number']
469 469
     );
470 470
     
471
-    $item_args  = apply_filters( 'wpinv_item_dropdown_query_args', $item_args, $args, $defaults );
471
+    $item_args  = apply_filters('wpinv_item_dropdown_query_args', $item_args, $args, $defaults);
472 472
 
473
-    $items      = get_posts( $item_args );
473
+    $items      = get_posts($item_args);
474 474
     $options    = array();
475
-    if ( $items ) {
476
-        foreach ( $items as $item ) {
477
-            $title = esc_html( $item->post_title );
475
+    if ($items) {
476
+        foreach ($items as $item) {
477
+            $title = esc_html($item->post_title);
478 478
             
479
-            if ( !empty( $args['show_recurring'] ) ) {
480
-                $title .= wpinv_get_item_suffix( $item->ID, false );
479
+            if (!empty($args['show_recurring'])) {
480
+                $title .= wpinv_get_item_suffix($item->ID, false);
481 481
             }
482 482
             
483
-            $options[ absint( $item->ID ) ] = $title;
483
+            $options[absint($item->ID)] = $title;
484 484
         }
485 485
     }
486 486
 
487 487
     // This ensures that any selected items are included in the drop down
488
-    if( is_array( $args['selected'] ) ) {
489
-        foreach( $args['selected'] as $item ) {
490
-            if( ! in_array( $item, $options ) ) {
491
-                $title = get_the_title( $item );
492
-                if ( !empty( $args['show_recurring'] ) ) {
493
-                    $title .= wpinv_get_item_suffix( $item, false );
488
+    if (is_array($args['selected'])) {
489
+        foreach ($args['selected'] as $item) {
490
+            if (!in_array($item, $options)) {
491
+                $title = get_the_title($item);
492
+                if (!empty($args['show_recurring'])) {
493
+                    $title .= wpinv_get_item_suffix($item, false);
494 494
                 }
495 495
                 $options[$item] = $title;
496 496
             }
497 497
         }
498
-    } elseif ( is_numeric( $args['selected'] ) && $args['selected'] !== 0 ) {
499
-        if ( ! in_array( $args['selected'], $options ) ) {
500
-            $title = get_the_title( $args['selected'] );
501
-            if ( !empty( $args['show_recurring'] ) ) {
502
-                $title .= wpinv_get_item_suffix( $args['selected'], false );
498
+    } elseif (is_numeric($args['selected']) && $args['selected'] !== 0) {
499
+        if (!in_array($args['selected'], $options)) {
500
+            $title = get_the_title($args['selected']);
501
+            if (!empty($args['show_recurring'])) {
502
+                $title .= wpinv_get_item_suffix($args['selected'], false);
503 503
             }
504
-            $options[$args['selected']] = get_the_title( $args['selected'] );
504
+            $options[$args['selected']] = get_the_title($args['selected']);
505 505
         }
506 506
     }
507 507
 
508
-    $output = wpinv_html_select( array(
508
+    $output = wpinv_html_select(array(
509 509
         'name'             => $args['name'],
510 510
         'selected'         => $args['selected'],
511 511
         'id'               => $args['id'],
@@ -516,12 +516,12 @@  discard block
 block discarded – undo
516 516
         'show_option_all'  => $args['show_option_all'],
517 517
         'show_option_none' => $args['show_option_none'],
518 518
         'data'             => $args['data'],
519
-    ) );
519
+    ));
520 520
 
521 521
     return $output;
522 522
 }
523 523
 
524
-function wpinv_html_checkbox( $args = array() ) {
524
+function wpinv_html_checkbox($args = array()) {
525 525
     $defaults = array(
526 526
         'name'     => null,
527 527
         'current'  => null,
@@ -532,38 +532,38 @@  discard block
 block discarded – undo
532 532
         )
533 533
     );
534 534
 
535
-    $args = wp_parse_args( $args, $defaults );
535
+    $args = wp_parse_args($args, $defaults);
536 536
 
537
-    $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) );
537
+    $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class'])));
538 538
     $options = '';
539
-    if ( ! empty( $args['options']['disabled'] ) ) {
539
+    if (!empty($args['options']['disabled'])) {
540 540
         $options .= ' disabled="disabled"';
541
-    } elseif ( ! empty( $args['options']['readonly'] ) ) {
541
+    } elseif (!empty($args['options']['readonly'])) {
542 542
         $options .= ' readonly';
543 543
     }
544 544
 
545
-    $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 ) . ' />';
545
+    $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) . ' />';
546 546
 
547 547
     return $output;
548 548
 }
549 549
 
550
-function wpinv_html_text( $args = array() ) {
550
+function wpinv_html_text($args = array()) {
551 551
     // Backwards compatibility
552
-    if ( func_num_args() > 1 ) {
552
+    if (func_num_args() > 1) {
553 553
         $args = func_get_args();
554 554
 
555 555
         $name  = $args[0];
556
-        $value = isset( $args[1] ) ? $args[1] : '';
557
-        $label = isset( $args[2] ) ? $args[2] : '';
558
-        $desc  = isset( $args[3] ) ? $args[3] : '';
556
+        $value = isset($args[1]) ? $args[1] : '';
557
+        $label = isset($args[2]) ? $args[2] : '';
558
+        $desc  = isset($args[3]) ? $args[3] : '';
559 559
     }
560 560
 
561 561
     $defaults = array(
562 562
         'id'           => '',
563
-        'name'         => isset( $name )  ? $name  : 'text',
564
-        'value'        => isset( $value ) ? $value : null,
565
-        'label'        => isset( $label ) ? $label : null,
566
-        'desc'         => isset( $desc )  ? $desc  : null,
563
+        'name'         => isset($name) ? $name : 'text',
564
+        'value'        => isset($value) ? $value : null,
565
+        'label'        => isset($label) ? $label : null,
566
+        'desc'         => isset($desc) ? $desc : null,
567 567
         'placeholder'  => '',
568 568
         'class'        => 'regular-text',
569 569
         'disabled'     => false,
@@ -573,51 +573,51 @@  discard block
 block discarded – undo
573 573
         'data'         => false
574 574
     );
575 575
 
576
-    $args = wp_parse_args( $args, $defaults );
576
+    $args = wp_parse_args($args, $defaults);
577 577
 
578
-    $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) );
578
+    $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class'])));
579 579
     $options = '';
580
-    if( $args['required'] ) {
580
+    if ($args['required']) {
581 581
         $options .= ' required="required"';
582 582
     }
583
-    if( $args['readonly'] ) {
583
+    if ($args['readonly']) {
584 584
         $options .= ' readonly';
585 585
     }
586
-    if( $args['readonly'] ) {
586
+    if ($args['readonly']) {
587 587
         $options .= ' readonly';
588 588
     }
589 589
 
590 590
     $data = '';
591
-    if ( !empty( $args['data'] ) ) {
592
-        foreach ( $args['data'] as $key => $value ) {
593
-            $data .= 'data-' . wpinv_sanitize_key( $key ) . '="' . esc_attr( $value ) . '" ';
591
+    if (!empty($args['data'])) {
592
+        foreach ($args['data'] as $key => $value) {
593
+            $data .= 'data-' . wpinv_sanitize_key($key) . '="' . esc_attr($value) . '" ';
594 594
         }
595 595
     }
596 596
 
597
-    $output = '<span id="wpinv-' . wpinv_sanitize_key( $args['name'] ) . '-wrap">';
598
-    $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key( $args['id'] ) . '">' . esc_html( $args['label'] ) . '</label>';
599
-    if ( ! empty( $args['desc'] ) ) {
600
-        $output .= '<span class="wpinv-description">' . esc_html( $args['desc'] ) . '</span>';
597
+    $output = '<span id="wpinv-' . wpinv_sanitize_key($args['name']) . '-wrap">';
598
+    $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key($args['id']) . '">' . esc_html($args['label']) . '</label>';
599
+    if (!empty($args['desc'])) {
600
+        $output .= '<span class="wpinv-description">' . esc_html($args['desc']) . '</span>';
601 601
     }
602 602
 
603
-    $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 ) . '/>';
603
+    $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) . '/>';
604 604
 
605 605
     $output .= '</span>';
606 606
 
607 607
     return $output;
608 608
 }
609 609
 
610
-function wpinv_html_date_field( $args = array() ) {
611
-    if( empty( $args['class'] ) ) {
610
+function wpinv_html_date_field($args = array()) {
611
+    if (empty($args['class'])) {
612 612
         $args['class'] = 'wpiDatepicker';
613
-    } elseif( ! strpos( $args['class'], 'wpiDatepicker' ) ) {
613
+    } elseif (!strpos($args['class'], 'wpiDatepicker')) {
614 614
         $args['class'] .= ' wpiDatepicker';
615 615
     }
616 616
 
617
-    return wpinv_html_text( $args );
617
+    return wpinv_html_text($args);
618 618
 }
619 619
 
620
-function wpinv_html_textarea( $args = array() ) {
620
+function wpinv_html_textarea($args = array()) {
621 621
     $defaults = array(
622 622
         'name'        => 'textarea',
623 623
         'value'       => null,
@@ -627,31 +627,31 @@  discard block
 block discarded – undo
627 627
         'disabled'    => false
628 628
     );
629 629
 
630
-    $args = wp_parse_args( $args, $defaults );
630
+    $args = wp_parse_args($args, $defaults);
631 631
 
632
-    $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) );
632
+    $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class'])));
633 633
     $disabled = '';
634
-    if( $args['disabled'] ) {
634
+    if ($args['disabled']) {
635 635
         $disabled = ' disabled="disabled"';
636 636
     }
637 637
 
638
-    $output = '<span id="wpinv-' . wpinv_sanitize_key( $args['name'] ) . '-wrap">';
639
-    $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key( $args['name'] ) . '">' . esc_html( $args['label'] ) . '</label>';
640
-    $output .= '<textarea name="' . esc_attr( $args['name'] ) . '" id="' . wpinv_sanitize_key( $args['name'] ) . '" class="' . $class . '"' . $disabled . '>' . esc_attr( $args['value'] ) . '</textarea>';
638
+    $output = '<span id="wpinv-' . wpinv_sanitize_key($args['name']) . '-wrap">';
639
+    $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key($args['name']) . '">' . esc_html($args['label']) . '</label>';
640
+    $output .= '<textarea name="' . esc_attr($args['name']) . '" id="' . wpinv_sanitize_key($args['name']) . '" class="' . $class . '"' . $disabled . '>' . esc_attr($args['value']) . '</textarea>';
641 641
 
642
-    if ( ! empty( $args['desc'] ) ) {
643
-        $output .= '<span class="wpinv-description">' . esc_html( $args['desc'] ) . '</span>';
642
+    if (!empty($args['desc'])) {
643
+        $output .= '<span class="wpinv-description">' . esc_html($args['desc']) . '</span>';
644 644
     }
645 645
     $output .= '</span>';
646 646
 
647 647
     return $output;
648 648
 }
649 649
 
650
-function wpinv_html_ajax_user_search( $args = array() ) {
650
+function wpinv_html_ajax_user_search($args = array()) {
651 651
     $defaults = array(
652 652
         'name'        => 'user_id',
653 653
         'value'       => null,
654
-        'placeholder' => __( 'Enter username', 'invoicing' ),
654
+        'placeholder' => __('Enter username', 'invoicing'),
655 655
         'label'       => null,
656 656
         'desc'        => null,
657 657
         'class'       => '',
@@ -660,13 +660,13 @@  discard block
 block discarded – undo
660 660
         'data'        => false
661 661
     );
662 662
 
663
-    $args = wp_parse_args( $args, $defaults );
663
+    $args = wp_parse_args($args, $defaults);
664 664
 
665 665
     $args['class'] = 'wpinv-ajax-user-search ' . $args['class'];
666 666
 
667 667
     $output  = '<span class="wpinv_user_search_wrap">';
668
-        $output .= wpinv_html_text( $args );
669
-        $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>';
668
+        $output .= wpinv_html_text($args);
669
+        $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>';
670 670
     $output .= '</span>';
671 671
 
672 672
     return $output;
@@ -675,7 +675,7 @@  discard block
 block discarded – undo
675 675
 function wpinv_ip_geolocation() {
676 676
     global $wpinv_euvat;
677 677
     
678
-    $ip         = !empty( $_GET['ip'] ) ? sanitize_text_field( $_GET['ip'] ) : '';    
678
+    $ip         = !empty($_GET['ip']) ? sanitize_text_field($_GET['ip']) : '';    
679 679
     $content    = '';
680 680
     $iso        = '';
681 681
     $country    = '';
@@ -686,69 +686,69 @@  discard block
 block discarded – undo
686 686
     $credit     = '';
687 687
     $address    = '';
688 688
     
689
-    if ( wpinv_get_option( 'vat_ip_lookup' ) == 'geoip2' && $geoip2_city = $wpinv_euvat->geoip2_city_record( $ip ) ) {
689
+    if (wpinv_get_option('vat_ip_lookup') == 'geoip2' && $geoip2_city = $wpinv_euvat->geoip2_city_record($ip)) {
690 690
         try {
691 691
             $iso        = $geoip2_city->country->isoCode;
692 692
             $country    = $geoip2_city->country->name;
693
-            $region     = !empty( $geoip2_city->subdivisions ) && !empty( $geoip2_city->subdivisions[0]->name ) ? $geoip2_city->subdivisions[0]->name : '';
693
+            $region     = !empty($geoip2_city->subdivisions) && !empty($geoip2_city->subdivisions[0]->name) ? $geoip2_city->subdivisions[0]->name : '';
694 694
             $city       = $geoip2_city->city->name;
695 695
             $longitude  = $geoip2_city->location->longitude;
696 696
             $latitude   = $geoip2_city->location->latitude;
697
-            $credit     = __( 'Geolocated using the information by MaxMind, available from <a href="http://www.maxmind.com" target="_blank">www.maxmind.com</a>', 'invoicing' );
698
-        } catch( Exception $e ) { }
697
+            $credit     = __('Geolocated using the information by MaxMind, available from <a href="http://www.maxmind.com" target="_blank">www.maxmind.com</a>', 'invoicing');
698
+        } catch (Exception $e) { }
699 699
     }
700 700
     
701
-    if ( !( $iso && $longitude && $latitude ) && function_exists( 'simplexml_load_file' ) ) {
701
+    if (!($iso && $longitude && $latitude) && function_exists('simplexml_load_file')) {
702 702
         try {
703
-            $load_xml = simplexml_load_file( 'http://www.geoplugin.net/xml.gp?ip=' . $ip );
703
+            $load_xml = simplexml_load_file('http://www.geoplugin.net/xml.gp?ip=' . $ip);
704 704
             
705
-            if ( !empty( $load_xml ) && isset( $load_xml->geoplugin_countryCode ) && !empty( $load_xml->geoplugin_latitude ) && !empty( $load_xml->geoplugin_longitude ) ) {
705
+            if (!empty($load_xml) && isset($load_xml->geoplugin_countryCode) && !empty($load_xml->geoplugin_latitude) && !empty($load_xml->geoplugin_longitude)) {
706 706
                 $iso        = $load_xml->geoplugin_countryCode;
707 707
                 $country    = $load_xml->geoplugin_countryName;
708
-                $region     = !empty( $load_xml->geoplugin_regionName ) ? $load_xml->geoplugin_regionName : '';
709
-                $city       = !empty( $load_xml->geoplugin_city ) ? $load_xml->geoplugin_city : '';
708
+                $region     = !empty($load_xml->geoplugin_regionName) ? $load_xml->geoplugin_regionName : '';
709
+                $city       = !empty($load_xml->geoplugin_city) ? $load_xml->geoplugin_city : '';
710 710
                 $longitude  = $load_xml->geoplugin_longitude;
711 711
                 $latitude   = $load_xml->geoplugin_latitude;
712 712
                 $credit     = $load_xml->geoplugin_credit;
713
-                $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;
713
+                $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;
714 714
             }
715
-        } catch( Exception $e ) { }
715
+        } catch (Exception $e) { }
716 716
     }
717 717
     
718
-    if ( $iso && $longitude && $latitude ) {
719
-        if ( $city ) {
718
+    if ($iso && $longitude && $latitude) {
719
+        if ($city) {
720 720
             $address .= $city . ', ';
721 721
         }
722 722
         
723
-        if ( $region ) {
723
+        if ($region) {
724 724
             $address .= $region . ', ';
725 725
         }
726 726
         
727 727
         $address .= $country . ' (' . $iso . ')';
728
-        $content = '<p>'. sprintf( __( '<b>Address:</b> %s', 'invoicing' ), $address ) . '</p>';
729
-        $content .= '<p>'. $credit . '</p>';
728
+        $content = '<p>' . sprintf(__('<b>Address:</b> %s', 'invoicing'), $address) . '</p>';
729
+        $content .= '<p>' . $credit . '</p>';
730 730
     } else {
731
-        $content = '<p>'. sprintf( __( 'Unable to find geolocation for the IP address: %s', 'invoicing' ), $ip ) . '</p>';
731
+        $content = '<p>' . sprintf(__('Unable to find geolocation for the IP address: %s', 'invoicing'), $ip) . '</p>';
732 732
     }
733 733
     ?>
734 734
 <!DOCTYPE html>
735
-<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>
735
+<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>
736 736
 <body>
737
-    <?php if ( $latitude && $latitude ) { ?>
737
+    <?php if ($latitude && $latitude) { ?>
738 738
     <div id="map"></div>
739 739
         <script src="//cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.0-rc.1/leaflet.js"></script>
740 740
         <script type="text/javascript">
741 741
         var osmUrl = 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
742 742
             osmAttrib = '&copy; <a href="http://openstreetmap.org/copyright">OpenStreetMap</a> contributors',
743 743
             osm = L.tileLayer(osmUrl, {maxZoom: 18, attribution: osmAttrib}),
744
-            latlng = new L.LatLng(<?php echo $latitude;?>, <?php echo $longitude;?>);
744
+            latlng = new L.LatLng(<?php echo $latitude; ?>, <?php echo $longitude; ?>);
745 745
 
746 746
         var map = new L.Map('map', {center: latlng, zoom: 12, layers: [osm]});
747 747
 
748 748
         var marker = new L.Marker(latlng);
749 749
         map.addLayer(marker);
750 750
 
751
-        marker.bindPopup("<p><?php esc_attr_e( $address );?></p>");
751
+        marker.bindPopup("<p><?php esc_attr_e($address); ?></p>");
752 752
     </script>
753 753
     <?php } ?>
754 754
     <div style="height:100px"><?php echo $content; ?></div>
@@ -756,18 +756,18 @@  discard block
 block discarded – undo
756 756
 <?php
757 757
     exit;
758 758
 }
759
-add_action( 'wp_ajax_wpinv_ip_geolocation', 'wpinv_ip_geolocation' );
760
-add_action( 'wp_ajax_nopriv_wpinv_ip_geolocation', 'wpinv_ip_geolocation' );
759
+add_action('wp_ajax_wpinv_ip_geolocation', 'wpinv_ip_geolocation');
760
+add_action('wp_ajax_nopriv_wpinv_ip_geolocation', 'wpinv_ip_geolocation');
761 761
 
762 762
 // Set up the template for the invoice.
763
-function wpinv_template( $template ) {
763
+function wpinv_template($template) {
764 764
     global $post, $wp_query;
765 765
     
766
-    if ( ( is_single() || is_404() ) && !empty( $post->ID ) && (get_post_type( $post->ID ) == 'wpi_invoice' or get_post_type( $post->ID ) == 'wpi_quote')) {
767
-        if ( wpinv_user_can_view_invoice( $post->ID ) ) {
768
-            $template = wpinv_get_template_part( 'wpinv-invoice-print', false, false );
766
+    if ((is_single() || is_404()) && !empty($post->ID) && (get_post_type($post->ID) == 'wpi_invoice' or get_post_type($post->ID) == 'wpi_quote')) {
767
+        if (wpinv_user_can_view_invoice($post->ID)) {
768
+            $template = wpinv_get_template_part('wpinv-invoice-print', false, false);
769 769
         } else {
770
-            $template = wpinv_get_template_part( 'wpinv-invalid-access', false, false );
770
+            $template = wpinv_get_template_part('wpinv-invalid-access', false, false);
771 771
         }
772 772
     }
773 773
 
@@ -776,7 +776,7 @@  discard block
 block discarded – undo
776 776
 
777 777
 function wpinv_get_business_address() {
778 778
     $business_address   = wpinv_store_address();
779
-    $business_address   = !empty( $business_address ) ? wpautop( wp_kses_post( $business_address ) ) : '';
779
+    $business_address   = !empty($business_address) ? wpautop(wp_kses_post($business_address)) : '';
780 780
     
781 781
     /*
782 782
     $default_country    = wpinv_get_default_country();
@@ -800,7 +800,7 @@  discard block
 block discarded – undo
800 800
     
801 801
     $business_address = $business_address ? '<div class="address">' . $business_address . '</div>' : '';
802 802
     
803
-    return apply_filters( 'wpinv_get_business_address', $business_address );
803
+    return apply_filters('wpinv_get_business_address', $business_address);
804 804
 }
805 805
 
806 806
 function wpinv_display_from_address() {
@@ -810,192 +810,192 @@  discard block
 block discarded – undo
810 810
     if (empty($from_name)) {
811 811
         $from_name = wpinv_get_business_name();
812 812
     }
813
-    ?><div class="from col-xs-2"><strong><?php _e( 'From:', 'invoicing' ) ?></strong></div>
813
+    ?><div class="from col-xs-2"><strong><?php _e('From:', 'invoicing') ?></strong></div>
814 814
     <div class="wrapper col-xs-10">
815
-        <div class="name"><?php echo esc_html( $from_name ); ?></div>
816
-        <?php if ( $address = wpinv_get_business_address() ) { ?>
817
-        <div class="address"><?php echo wpautop( wp_kses_post( $address ) );?></div>
815
+        <div class="name"><?php echo esc_html($from_name); ?></div>
816
+        <?php if ($address = wpinv_get_business_address()) { ?>
817
+        <div class="address"><?php echo wpautop(wp_kses_post($address)); ?></div>
818 818
         <?php } ?>
819
-        <?php if ( $email_from = wpinv_mail_get_from_address() ) { ?>
820
-        <div class="email_from"><?php echo wp_sprintf( __( 'Email: %s', 'invoicing' ), $email_from );?></div>
819
+        <?php if ($email_from = wpinv_mail_get_from_address()) { ?>
820
+        <div class="email_from"><?php echo wp_sprintf(__('Email: %s', 'invoicing'), $email_from); ?></div>
821 821
         <?php } ?>
822 822
     </div>
823 823
     <?php
824 824
 }
825 825
 
826
-function wpinv_watermark( $id = 0 ) {
827
-    $output = wpinv_get_watermark( $id );
826
+function wpinv_watermark($id = 0) {
827
+    $output = wpinv_get_watermark($id);
828 828
     
829
-    return apply_filters( 'wpinv_get_watermark', $output, $id );
829
+    return apply_filters('wpinv_get_watermark', $output, $id);
830 830
 }
831 831
 
832
-function wpinv_get_watermark( $id ) {
833
-    if ( !$id > 0 ) {
832
+function wpinv_get_watermark($id) {
833
+    if (!$id > 0) {
834 834
         return NULL;
835 835
     }
836
-    $invoice = wpinv_get_invoice( $id );
836
+    $invoice = wpinv_get_invoice($id);
837 837
     
838
-    if ( !empty( $invoice ) && "wpi_invoice" === $invoice->post_type ) {
839
-        if ( $invoice->is_paid() ) {
840
-            return __( 'Paid', 'invoicing' );
838
+    if (!empty($invoice) && "wpi_invoice" === $invoice->post_type) {
839
+        if ($invoice->is_paid()) {
840
+            return __('Paid', 'invoicing');
841 841
         }
842
-        if ( $invoice->is_refunded() ) {
843
-            return __( 'Refunded', 'invoicing' );
842
+        if ($invoice->is_refunded()) {
843
+            return __('Refunded', 'invoicing');
844 844
         }
845
-        if ( $invoice->has_status( array( 'wpi-cancelled' ) ) ) {
846
-            return __( 'Cancelled', 'invoicing' );
845
+        if ($invoice->has_status(array('wpi-cancelled'))) {
846
+            return __('Cancelled', 'invoicing');
847 847
         }
848 848
     }
849 849
     
850 850
     return NULL;
851 851
 }
852 852
 
853
-function wpinv_display_invoice_details( $invoice ) {
853
+function wpinv_display_invoice_details($invoice) {
854 854
     global $wpinv_euvat;
855 855
     
856 856
     $invoice_id = $invoice->ID;
857 857
     $vat_name   = $wpinv_euvat->get_vat_name();
858 858
     $use_taxes  = wpinv_use_taxes();
859 859
     
860
-    $invoice_status = wpinv_get_invoice_status( $invoice_id );
860
+    $invoice_status = wpinv_get_invoice_status($invoice_id);
861 861
     ?>
862 862
     <table class="table table-bordered table-sm">
863
-        <?php if ( $invoice_number = wpinv_get_invoice_number( $invoice_id ) ) { ?>
863
+        <?php if ($invoice_number = wpinv_get_invoice_number($invoice_id)) { ?>
864 864
             <tr class="wpi-row-number">
865
-                <th><?php echo apply_filters( 'wpinv_invoice_number_label', __( 'Invoice Number', 'invoicing' ), $invoice ); ?></th>
866
-                <td><?php echo esc_html( $invoice_number ); ?></td>
865
+                <th><?php echo apply_filters('wpinv_invoice_number_label', __('Invoice Number', 'invoicing'), $invoice); ?></th>
866
+                <td><?php echo esc_html($invoice_number); ?></td>
867 867
             </tr>
868 868
         <?php } ?>
869 869
         <tr class="wpi-row-status">
870
-            <th><?php echo apply_filters( 'wpinv_invoice_status_label', __( 'Invoice Status', 'invoicing' ), $invoice ); ?></th>
871
-            <td><?php echo wpinv_invoice_status_label( $invoice_status, wpinv_get_invoice_status( $invoice_id, true ) ); ?></td>
870
+            <th><?php echo apply_filters('wpinv_invoice_status_label', __('Invoice Status', 'invoicing'), $invoice); ?></th>
871
+            <td><?php echo wpinv_invoice_status_label($invoice_status, wpinv_get_invoice_status($invoice_id, true)); ?></td>
872 872
         </tr>
873
-        <?php if ( $invoice->is_renewal() ) { ?>
873
+        <?php if ($invoice->is_renewal()) { ?>
874 874
         <tr class="wpi-row-parent">
875
-            <th><?php echo apply_filters( 'wpinv_invoice_parent_invoice_label', __( 'Parent Invoice', 'invoicing' ), $invoice ); ?></th>
876
-            <td><?php echo wpinv_invoice_link( $invoice->parent_invoice ); ?></td>
875
+            <th><?php echo apply_filters('wpinv_invoice_parent_invoice_label', __('Parent Invoice', 'invoicing'), $invoice); ?></th>
876
+            <td><?php echo wpinv_invoice_link($invoice->parent_invoice); ?></td>
877 877
         </tr>
878 878
         <?php } ?>
879
-        <?php if ( ( $gateway_name = wpinv_get_payment_gateway_name( $invoice_id ) ) && ( $invoice->is_paid() || $invoice->is_refunded() ) ) { ?>
879
+        <?php if (($gateway_name = wpinv_get_payment_gateway_name($invoice_id)) && ($invoice->is_paid() || $invoice->is_refunded())) { ?>
880 880
             <tr class="wpi-row-gateway">
881
-                <th><?php echo apply_filters( 'wpinv_invoice_payment_method_label', __( 'Payment Method', 'invoicing' ), $invoice ); ?></th>
881
+                <th><?php echo apply_filters('wpinv_invoice_payment_method_label', __('Payment Method', 'invoicing'), $invoice); ?></th>
882 882
                 <td><?php echo $gateway_name; ?></td>
883 883
             </tr>
884 884
         <?php } ?>
885
-        <?php if ( $invoice_date = wpinv_get_invoice_date( $invoice_id ) ) { ?>
885
+        <?php if ($invoice_date = wpinv_get_invoice_date($invoice_id)) { ?>
886 886
             <tr class="wpi-row-date">
887
-                <th><?php echo apply_filters( 'wpinv_invoice_date_label', __( 'Invoice Date', 'invoicing' ), $invoice ); ?></th>
887
+                <th><?php echo apply_filters('wpinv_invoice_date_label', __('Invoice Date', 'invoicing'), $invoice); ?></th>
888 888
                 <td><?php echo $invoice_date; ?></td>
889 889
             </tr>
890 890
         <?php } ?>
891
-        <?php if ( wpinv_get_option( 'overdue_active' ) && $invoice->needs_payment() && ( $due_date = $invoice->get_due_date( true ) ) ) { ?>
891
+        <?php if (wpinv_get_option('overdue_active') && $invoice->needs_payment() && ($due_date = $invoice->get_due_date(true))) { ?>
892 892
             <tr class="wpi-row-date">
893
-                <th><?php echo apply_filters( 'wpinv_invoice_due_date_label', __( 'Due Date', 'invoicing' ), $invoice ); ?></th>
893
+                <th><?php echo apply_filters('wpinv_invoice_due_date_label', __('Due Date', 'invoicing'), $invoice); ?></th>
894 894
                 <td><?php echo $due_date; ?></td>
895 895
             </tr>
896 896
         <?php } ?>
897
-        <?php do_action( 'wpinv_display_details_after_due_date', $invoice_id ); ?>
898
-        <?php if ( $owner_vat_number = $wpinv_euvat->get_vat_number() ) { ?>
897
+        <?php do_action('wpinv_display_details_after_due_date', $invoice_id); ?>
898
+        <?php if ($owner_vat_number = $wpinv_euvat->get_vat_number()) { ?>
899 899
             <tr class="wpi-row-ovatno">
900
-                <th><?php echo apply_filters( 'wpinv_invoice_owner_vat_number_label', wp_sprintf( __( 'Owner %s Number', 'invoicing' ), $vat_name ), $invoice, $vat_name ); ?></th>
900
+                <th><?php echo apply_filters('wpinv_invoice_owner_vat_number_label', wp_sprintf(__('Owner %s Number', 'invoicing'), $vat_name), $invoice, $vat_name); ?></th>
901 901
                 <td><?php echo $owner_vat_number; ?></td>
902 902
             </tr>
903 903
         <?php } ?>
904
-        <?php do_action( 'wpinv_display_details_after_due_date', $invoice_id ); ?>
905
-        <?php if ( $use_taxes && ( $user_vat_number = wpinv_get_invoice_vat_number( $invoice_id ) ) ) { ?>
904
+        <?php do_action('wpinv_display_details_after_due_date', $invoice_id); ?>
905
+        <?php if ($use_taxes && ($user_vat_number = wpinv_get_invoice_vat_number($invoice_id))) { ?>
906 906
             <tr class="wpi-row-uvatno">
907
-                <th><?php echo apply_filters( 'wpinv_invoice_user_vat_number_label', wp_sprintf( __( 'Invoice %s Number', 'invoicing' ), $vat_name ), $invoice, $vat_name ); ?></th>
907
+                <th><?php echo apply_filters('wpinv_invoice_user_vat_number_label', wp_sprintf(__('Invoice %s Number', 'invoicing'), $vat_name), $invoice, $vat_name); ?></th>
908 908
                 <td><?php echo $user_vat_number; ?></td>
909 909
             </tr>
910 910
         <?php } ?>
911 911
         <tr class="table-active tr-total wpi-row-total">
912
-            <th><strong><?php _e( 'Total Amount', 'invoicing' ) ?></strong></th>
913
-            <td><strong><?php echo wpinv_payment_total( $invoice_id, true ); ?></strong></td>
912
+            <th><strong><?php _e('Total Amount', 'invoicing') ?></strong></th>
913
+            <td><strong><?php echo wpinv_payment_total($invoice_id, true); ?></strong></td>
914 914
         </tr>
915 915
     </table>
916 916
 <?php
917 917
 }
918 918
 
919
-function wpinv_display_to_address( $invoice_id = 0 ) {
920
-    $invoice = wpinv_get_invoice( $invoice_id );
919
+function wpinv_display_to_address($invoice_id = 0) {
920
+    $invoice = wpinv_get_invoice($invoice_id);
921 921
     
922
-    if ( empty( $invoice ) ) {
922
+    if (empty($invoice)) {
923 923
         return NULL;
924 924
     }
925 925
     
926 926
     $billing_details = $invoice->get_user_info();
927
-    $output = '<div class="to col-xs-2"><strong>' . __( 'To:', 'invoicing' ) . '</strong></div>';
927
+    $output = '<div class="to col-xs-2"><strong>' . __('To:', 'invoicing') . '</strong></div>';
928 928
     $output .= '<div class="wrapper col-xs-10">';
929 929
     
930 930
     ob_start();
931
-    do_action( 'wpinv_display_to_address_top', $invoice );
931
+    do_action('wpinv_display_to_address_top', $invoice);
932 932
     $output .= ob_get_clean();
933 933
     
934
-    $output .= '<div class="name">' . esc_html( trim( $billing_details['first_name'] . ' ' . $billing_details['last_name'] ) ) . '</div>';
935
-    if ( $company = $billing_details['company'] ) {
936
-        $output .= '<div class="company">' . wpautop( wp_kses_post( $company ) ) . '</div>';
934
+    $output .= '<div class="name">' . esc_html(trim($billing_details['first_name'] . ' ' . $billing_details['last_name'])) . '</div>';
935
+    if ($company = $billing_details['company']) {
936
+        $output .= '<div class="company">' . wpautop(wp_kses_post($company)) . '</div>';
937 937
     }
938 938
     $address_row = '';
939
-    if ( $address = $billing_details['address'] ) {
940
-        $address_row .= wpautop( wp_kses_post( $address ) );
939
+    if ($address = $billing_details['address']) {
940
+        $address_row .= wpautop(wp_kses_post($address));
941 941
     }
942 942
     
943 943
     $address_fields = array();
944
-    if ( !empty( $billing_details['city'] ) ) {
944
+    if (!empty($billing_details['city'])) {
945 945
         $address_fields[] = $billing_details['city'];
946 946
     }
947 947
     
948
-    $billing_country = !empty( $billing_details['country'] ) ? $billing_details['country'] : '';
949
-    if ( !empty( $billing_details['state'] ) ) {
950
-        $address_fields[] = wpinv_state_name( $billing_details['state'], $billing_country );
948
+    $billing_country = !empty($billing_details['country']) ? $billing_details['country'] : '';
949
+    if (!empty($billing_details['state'])) {
950
+        $address_fields[] = wpinv_state_name($billing_details['state'], $billing_country);
951 951
     }
952 952
 
953
-    if ( !empty( $billing_country ) ) {
954
-        $address_fields[] = wpinv_country_name( $billing_country );
953
+    if (!empty($billing_country)) {
954
+        $address_fields[] = wpinv_country_name($billing_country);
955 955
     }
956 956
 
957
-    if ( !empty( $address_fields ) ) {
958
-        $address_fields = implode( ", ", $address_fields );
957
+    if (!empty($address_fields)) {
958
+        $address_fields = implode(", ", $address_fields);
959 959
         
960
-        if ( !empty( $billing_details['zip'] ) ) {
960
+        if (!empty($billing_details['zip'])) {
961 961
             $address_fields .= ' ' . $billing_details['zip'];
962 962
         }
963 963
 
964
-        $address_row .= wpautop( wp_kses_post( $address_fields ) );
964
+        $address_row .= wpautop(wp_kses_post($address_fields));
965 965
     }
966 966
     
967
-    if ( $address_row ) {
967
+    if ($address_row) {
968 968
         $output .= '<div class="address">' . $address_row . '</div>';
969 969
     }
970 970
 
971
-    if ( $phone = $invoice->get_phone() ) {
972
-        $output .= '<div class="phone">' . wp_sprintf( __( 'Phone: %s', 'invoicing' ), esc_html( $phone ) ) . '</div>';
971
+    if ($phone = $invoice->get_phone()) {
972
+        $output .= '<div class="phone">' . wp_sprintf(__('Phone: %s', 'invoicing'), esc_html($phone)) . '</div>';
973 973
     }
974
-    if ( $email = $invoice->get_email() ) {
975
-        $output .= '<div class="email">' . wp_sprintf( __( 'Email: %s' , 'invoicing'), esc_html( $email ) ) . '</div>';
974
+    if ($email = $invoice->get_email()) {
975
+        $output .= '<div class="email">' . wp_sprintf(__('Email: %s', 'invoicing'), esc_html($email)) . '</div>';
976 976
     }
977 977
 
978 978
     ob_start();
979
-    do_action( 'wpinv_display_to_address_bottom', $invoice );
979
+    do_action('wpinv_display_to_address_bottom', $invoice);
980 980
     $output .= ob_get_clean();
981 981
     
982 982
     $output .= '</div>';
983
-    $output = apply_filters( 'wpinv_display_to_address', $output, $invoice );
983
+    $output = apply_filters('wpinv_display_to_address', $output, $invoice);
984 984
 
985 985
     echo $output;
986 986
 }
987 987
 
988
-function wpinv_display_line_items( $invoice_id = 0 ) {
988
+function wpinv_display_line_items($invoice_id = 0) {
989 989
     global $wpinv_euvat, $ajax_cart_details;
990
-    $invoice            = wpinv_get_invoice( $invoice_id );
990
+    $invoice            = wpinv_get_invoice($invoice_id);
991 991
     $quantities_enabled = wpinv_item_quantities_enabled();
992 992
     $use_taxes          = wpinv_use_taxes();
993
-    if ( !$use_taxes && (float)$invoice->get_tax() > 0 ) {
993
+    if (!$use_taxes && (float)$invoice->get_tax() > 0) {
994 994
         $use_taxes = true;
995 995
     }
996 996
     $zero_tax           = !(float)$invoice->get_tax() > 0 ? true : false;
997
-    $tax_label           = $use_taxes && $invoice->has_vat() ? $wpinv_euvat->get_vat_name() : __( 'Tax', 'invoicing' );
998
-    $tax_title          = !$zero_tax && $use_taxes ? ( wpinv_prices_include_tax() ? wp_sprintf( __( '(%s Incl.)', 'invoicing' ), $tax_label ) : wp_sprintf( __( '(%s Excl.)', 'invoicing' ), $tax_label ) ) : '';
997
+    $tax_label = $use_taxes && $invoice->has_vat() ? $wpinv_euvat->get_vat_name() : __('Tax', 'invoicing');
998
+    $tax_title          = !$zero_tax && $use_taxes ? (wpinv_prices_include_tax() ? wp_sprintf(__('(%s Incl.)', 'invoicing'), $tax_label) : wp_sprintf(__('(%s Excl.)', 'invoicing'), $tax_label)) : '';
999 999
 
1000 1000
     $cart_details       = $invoice->get_cart_details();
1001 1001
     $ajax_cart_details  = $cart_details;
@@ -1004,64 +1004,64 @@  discard block
 block discarded – undo
1004 1004
     <table class="table table-sm table-bordered table-responsive">
1005 1005
         <thead>
1006 1006
             <tr>
1007
-                <th class="name"><strong><?php _e( "Item Name", "invoicing" );?></strong></th>
1008
-                <th class="rate"><strong><?php _e( "Price", "invoicing" );?></strong></th>
1007
+                <th class="name"><strong><?php _e("Item Name", "invoicing"); ?></strong></th>
1008
+                <th class="rate"><strong><?php _e("Price", "invoicing"); ?></strong></th>
1009 1009
                 <?php if ($quantities_enabled) { ?>
1010
-                    <th class="qty"><strong><?php _e( "Qty", "invoicing" );?></strong></th>
1010
+                    <th class="qty"><strong><?php _e("Qty", "invoicing"); ?></strong></th>
1011 1011
                 <?php } ?>
1012 1012
                 <?php if ($use_taxes && !$zero_tax) { ?>
1013 1013
                     <th class="tax"><strong><?php echo $tax_label . ' <span class="normal small">(%)</span>'; ?></strong></th>
1014 1014
                 <?php } ?>
1015
-                <th class="total"><strong><?php echo __( "Item Total", "invoicing" ) . ' <span class="normal small">' . $tax_title . '<span>';?></strong></th>
1015
+                <th class="total"><strong><?php echo __("Item Total", "invoicing") . ' <span class="normal small">' . $tax_title . '<span>'; ?></strong></th>
1016 1016
             </tr>
1017 1017
         </thead>
1018 1018
         <tbody>
1019 1019
         <?php 
1020
-            if ( !empty( $cart_details ) ) {
1021
-                do_action( 'wpinv_display_line_items_start', $invoice );
1020
+            if (!empty($cart_details)) {
1021
+                do_action('wpinv_display_line_items_start', $invoice);
1022 1022
 
1023 1023
                 $count = 0;
1024 1024
                 $cols  = 3;
1025
-                foreach ( $cart_details as $key => $cart_item ) {
1026
-                    $item_id    = !empty($cart_item['id']) ? absint( $cart_item['id'] ) : '';
1027
-                    $item_price = isset($cart_item["item_price"]) ? wpinv_round_amount( $cart_item["item_price"] ) : 0;
1028
-                    $line_total = isset($cart_item["subtotal"]) ? wpinv_round_amount( $cart_item["subtotal"] ) : 0;
1029
-                    $quantity   = !empty($cart_item['quantity']) && (int)$cart_item['quantity'] > 0 ? absint( $cart_item['quantity'] ) : 1;
1025
+                foreach ($cart_details as $key => $cart_item) {
1026
+                    $item_id    = !empty($cart_item['id']) ? absint($cart_item['id']) : '';
1027
+                    $item_price = isset($cart_item["item_price"]) ? wpinv_round_amount($cart_item["item_price"]) : 0;
1028
+                    $line_total = isset($cart_item["subtotal"]) ? wpinv_round_amount($cart_item["subtotal"]) : 0;
1029
+                    $quantity   = !empty($cart_item['quantity']) && (int)$cart_item['quantity'] > 0 ? absint($cart_item['quantity']) : 1;
1030 1030
 
1031
-                    $item       = $item_id ? new WPInv_Item( $item_id ) : NULL;
1031
+                    $item       = $item_id ? new WPInv_Item($item_id) : NULL;
1032 1032
                     $summary    = '';
1033 1033
                     $cols       = 3;
1034
-                    if ( !empty($item) ) {
1034
+                    if (!empty($item)) {
1035 1035
                         $item_name  = $item->get_name();
1036 1036
                         $summary    = $item->get_summary();
1037 1037
                     }
1038
-                    $item_name  = !empty($cart_item['name']) ? $cart_item['name'] : $item_name;
1038
+                    $item_name = !empty($cart_item['name']) ? $cart_item['name'] : $item_name;
1039 1039
 
1040
-                    $summary = apply_filters( 'wpinv_print_invoice_line_item_summary', $summary, $cart_item, $item, $invoice );
1040
+                    $summary = apply_filters('wpinv_print_invoice_line_item_summary', $summary, $cart_item, $item, $invoice);
1041 1041
 
1042 1042
                     $item_tax       = '';
1043 1043
                     $tax_rate       = '';
1044
-                    if ( $use_taxes && $cart_item['tax'] > 0 && $cart_item['subtotal'] > 0 ) {
1045
-                        $item_tax = wpinv_price( wpinv_format_amount( $cart_item['tax'] ), $invoice->get_currency() );
1046
-                        $tax_rate = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : ( $cart_item['tax'] / $cart_item['subtotal'] ) * 100;
1047
-                        $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount( $tax_rate, 4 ) : '';
1044
+                    if ($use_taxes && $cart_item['tax'] > 0 && $cart_item['subtotal'] > 0) {
1045
+                        $item_tax = wpinv_price(wpinv_format_amount($cart_item['tax']), $invoice->get_currency());
1046
+                        $tax_rate = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : ($cart_item['tax'] / $cart_item['subtotal']) * 100;
1047
+                        $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount($tax_rate, 4) : '';
1048 1048
                         $tax_rate = $tax_rate != '' ? ' <small class="tax-rate">(' . $tax_rate . '%)</small>' : '';
1049 1049
                     }
1050 1050
 
1051 1051
                     $line_item_tax = $item_tax . $tax_rate;
1052 1052
 
1053
-                    if ( $line_item_tax === '' ) {
1053
+                    if ($line_item_tax === '') {
1054 1054
                         $line_item_tax = 0; // Zero tax
1055 1055
                     }
1056 1056
 
1057
-                    $line_item = '<tr class="row-' . ( ($count % 2 == 0) ? 'even' : 'odd' ) . ' wpinv-item">';
1058
-                        $line_item .= '<td class="name">' . esc_html__( $item_name, 'invoicing' ) . wpinv_get_item_suffix( $item );
1059
-                        if ( $summary !== '' ) {
1060
-                            $line_item .= '<br/><small class="meta">' . wpautop( wp_kses_post( $summary ) ) . '</small>';
1057
+                    $line_item = '<tr class="row-' . (($count % 2 == 0) ? 'even' : 'odd') . ' wpinv-item">';
1058
+                        $line_item .= '<td class="name">' . esc_html__($item_name, 'invoicing') . wpinv_get_item_suffix($item);
1059
+                        if ($summary !== '') {
1060
+                            $line_item .= '<br/><small class="meta">' . wpautop(wp_kses_post($summary)) . '</small>';
1061 1061
                         }
1062 1062
                         $line_item .= '</td>';
1063 1063
 
1064
-                        $line_item .= '<td class="rate">' . esc_html__( wpinv_price( wpinv_format_amount( $item_price ), $invoice->get_currency() ) ) . '</td>';
1064
+                        $line_item .= '<td class="rate">' . esc_html__(wpinv_price(wpinv_format_amount($item_price), $invoice->get_currency())) . '</td>';
1065 1065
                         if ($quantities_enabled) {
1066 1066
                             $cols++;
1067 1067
                             $line_item .= '<td class="qty">' . $quantity . '</td>';
@@ -1070,55 +1070,55 @@  discard block
 block discarded – undo
1070 1070
                             $cols++;
1071 1071
                             $line_item .= '<td class="tax">' . $line_item_tax . '</td>';
1072 1072
                         }
1073
-                        $line_item .= '<td class="total">' . esc_html__( wpinv_price( wpinv_format_amount( $line_total ), $invoice->get_currency() ) ) . '</td>';
1073
+                        $line_item .= '<td class="total">' . esc_html__(wpinv_price(wpinv_format_amount($line_total), $invoice->get_currency())) . '</td>';
1074 1074
                     $line_item .= '</tr>';
1075 1075
 
1076
-                    echo apply_filters( 'wpinv_display_line_item', $line_item, $cart_item, $invoice, $cols );
1076
+                    echo apply_filters('wpinv_display_line_item', $line_item, $cart_item, $invoice, $cols);
1077 1077
 
1078 1078
                     $count++;
1079 1079
                 }
1080 1080
 
1081
-                do_action( 'wpinv_display_before_subtotal', $invoice, $cols );
1081
+                do_action('wpinv_display_before_subtotal', $invoice, $cols);
1082 1082
                 ?>
1083 1083
                 <tr class="row-sub-total row_odd">
1084
-                    <td class="rate" colspan="<?php echo ( $cols - 1 ); ?>"><?php echo apply_filters( 'wpinv_print_cart_subtotal_label', '<strong>' . __( 'Sub Total', 'invoicing' ) . ':</strong>', $invoice ); ?></td>
1085
-                    <td class="total"><strong><?php _e( wpinv_subtotal( $invoice_id, true ) ) ?></strong></td>
1084
+                    <td class="rate" colspan="<?php echo ($cols - 1); ?>"><?php echo apply_filters('wpinv_print_cart_subtotal_label', '<strong>' . __('Sub Total', 'invoicing') . ':</strong>', $invoice); ?></td>
1085
+                    <td class="total"><strong><?php _e(wpinv_subtotal($invoice_id, true)) ?></strong></td>
1086 1086
                 </tr>
1087 1087
                 <?php
1088
-                do_action( 'wpinv_display_after_subtotal', $invoice, $cols );
1088
+                do_action('wpinv_display_after_subtotal', $invoice, $cols);
1089 1089
                 
1090
-                if ( wpinv_discount( $invoice_id, false ) > 0 ) {
1091
-                    do_action( 'wpinv_display_before_discount', $invoice, $cols );
1090
+                if (wpinv_discount($invoice_id, false) > 0) {
1091
+                    do_action('wpinv_display_before_discount', $invoice, $cols);
1092 1092
                     ?>
1093 1093
                         <tr class="row-discount">
1094
-                            <td class="rate" colspan="<?php echo ( $cols - 1 ); ?>"><?php wpinv_get_discount_label( wpinv_discount_code( $invoice_id ) ); ?>:</td>
1095
-                            <td class="total"><?php echo wpinv_discount( $invoice_id, true, true ); ?></td>
1094
+                            <td class="rate" colspan="<?php echo ($cols - 1); ?>"><?php wpinv_get_discount_label(wpinv_discount_code($invoice_id)); ?>:</td>
1095
+                            <td class="total"><?php echo wpinv_discount($invoice_id, true, true); ?></td>
1096 1096
                         </tr>
1097 1097
                     <?php
1098
-                    do_action( 'wpinv_display_after_discount', $invoice, $cols );
1098
+                    do_action('wpinv_display_after_discount', $invoice, $cols);
1099 1099
                 }
1100 1100
 
1101
-                if ( $use_taxes ) {
1102
-                    do_action( 'wpinv_display_before_tax', $invoice, $cols );
1101
+                if ($use_taxes) {
1102
+                    do_action('wpinv_display_before_tax', $invoice, $cols);
1103 1103
                     ?>
1104 1104
                     <tr class="row-tax">
1105
-                        <td class="rate" colspan="<?php echo ( $cols - 1 ); ?>"><?php echo apply_filters( 'wpinv_print_cart_tax_label', '<strong>' . $tax_label . ':</strong>', $invoice ); ?></td>
1106
-                        <td class="total"><?php _e( wpinv_tax( $invoice_id, true ) ) ?></td>
1105
+                        <td class="rate" colspan="<?php echo ($cols - 1); ?>"><?php echo apply_filters('wpinv_print_cart_tax_label', '<strong>' . $tax_label . ':</strong>', $invoice); ?></td>
1106
+                        <td class="total"><?php _e(wpinv_tax($invoice_id, true)) ?></td>
1107 1107
                     </tr>
1108 1108
                     <?php
1109
-                    do_action( 'wpinv_display_after_tax', $invoice, $cols );
1109
+                    do_action('wpinv_display_after_tax', $invoice, $cols);
1110 1110
                 }
1111 1111
 
1112
-                do_action( 'wpinv_display_before_total', $invoice, $cols );
1112
+                do_action('wpinv_display_before_total', $invoice, $cols);
1113 1113
                 ?>
1114 1114
                 <tr class="table-active row-total">
1115
-                    <td class="rate" colspan="<?php echo ( $cols - 1 ); ?>"><?php echo apply_filters( 'wpinv_print_cart_total_label', '<strong>' . __( 'Total', 'invoicing' ) . ':</strong>', $invoice ); ?></td>
1116
-                    <td class="total"><strong><?php _e( wpinv_payment_total( $invoice_id, true ) ) ?></strong></td>
1115
+                    <td class="rate" colspan="<?php echo ($cols - 1); ?>"><?php echo apply_filters('wpinv_print_cart_total_label', '<strong>' . __('Total', 'invoicing') . ':</strong>', $invoice); ?></td>
1116
+                    <td class="total"><strong><?php _e(wpinv_payment_total($invoice_id, true)) ?></strong></td>
1117 1117
                 </tr>
1118 1118
                 <?php
1119
-                do_action( 'wpinv_display_after_total', $invoice, $cols );
1119
+                do_action('wpinv_display_after_total', $invoice, $cols);
1120 1120
 
1121
-                do_action( 'wpinv_display_line_end', $invoice, $cols );
1121
+                do_action('wpinv_display_line_end', $invoice, $cols);
1122 1122
             }
1123 1123
         ?>
1124 1124
         </tbody>
@@ -1127,35 +1127,35 @@  discard block
 block discarded – undo
1127 1127
     echo ob_get_clean();
1128 1128
 }
1129 1129
 
1130
-function wpinv_display_invoice_totals( $invoice_id = 0 ) {
1130
+function wpinv_display_invoice_totals($invoice_id = 0) {
1131 1131
     $use_taxes = wpinv_use_taxes();
1132 1132
 
1133
-    do_action( 'wpinv_before_display_totals_table', $invoice_id ); 
1133
+    do_action('wpinv_before_display_totals_table', $invoice_id); 
1134 1134
     ?>
1135 1135
     <table class="table table-sm table-bordered table-responsive">
1136 1136
         <tbody>
1137
-            <?php do_action( 'wpinv_before_display_totals' ); ?>
1137
+            <?php do_action('wpinv_before_display_totals'); ?>
1138 1138
             <tr class="row-sub-total">
1139
-                <td class="rate"><strong><?php _e( 'Sub Total', 'invoicing' ); ?></strong></td>
1140
-                <td class="total"><strong><?php _e( wpinv_subtotal( $invoice_id, true ) ) ?></strong></td>
1139
+                <td class="rate"><strong><?php _e('Sub Total', 'invoicing'); ?></strong></td>
1140
+                <td class="total"><strong><?php _e(wpinv_subtotal($invoice_id, true)) ?></strong></td>
1141 1141
             </tr>
1142
-            <?php do_action( 'wpinv_after_display_totals' ); ?>
1143
-            <?php if ( wpinv_discount( $invoice_id, false ) > 0 ) { ?>
1142
+            <?php do_action('wpinv_after_display_totals'); ?>
1143
+            <?php if (wpinv_discount($invoice_id, false) > 0) { ?>
1144 1144
                 <tr class="row-discount">
1145
-                    <td class="rate"><?php wpinv_get_discount_label( wpinv_discount_code( $invoice_id ) ); ?></td>
1146
-                    <td class="total"><?php echo wpinv_discount( $invoice_id, true, true ); ?></td>
1145
+                    <td class="rate"><?php wpinv_get_discount_label(wpinv_discount_code($invoice_id)); ?></td>
1146
+                    <td class="total"><?php echo wpinv_discount($invoice_id, true, true); ?></td>
1147 1147
                 </tr>
1148
-            <?php do_action( 'wpinv_after_display_discount' ); ?>
1148
+            <?php do_action('wpinv_after_display_discount'); ?>
1149 1149
             <?php } ?>
1150
-            <?php if ( $use_taxes ) { ?>
1150
+            <?php if ($use_taxes) { ?>
1151 1151
             <tr class="row-tax">
1152
-                <td class="rate"><?php _e( 'Tax', 'invoicing' ); ?></td>
1153
-                <td class="total"><?php _e( wpinv_tax( $invoice_id, true ) ) ?></td>
1152
+                <td class="rate"><?php _e('Tax', 'invoicing'); ?></td>
1153
+                <td class="total"><?php _e(wpinv_tax($invoice_id, true)) ?></td>
1154 1154
             </tr>
1155
-            <?php do_action( 'wpinv_after_display_tax' ); ?>
1155
+            <?php do_action('wpinv_after_display_tax'); ?>
1156 1156
             <?php } ?>
1157
-            <?php if ( $fees = wpinv_get_fees( $invoice_id ) ) { ?>
1158
-                <?php foreach ( $fees as $fee ) { ?>
1157
+            <?php if ($fees = wpinv_get_fees($invoice_id)) { ?>
1158
+                <?php foreach ($fees as $fee) { ?>
1159 1159
                     <tr class="row-fee">
1160 1160
                         <td class="rate"><?php echo $fee['label']; ?></td>
1161 1161
                         <td class="total"><?php echo $fee['amount_display']; ?></td>
@@ -1163,73 +1163,73 @@  discard block
 block discarded – undo
1163 1163
                 <?php } ?>
1164 1164
             <?php } ?>
1165 1165
             <tr class="table-active row-total">
1166
-                <td class="rate"><strong><?php _e( 'Total', 'invoicing' ) ?></strong></td>
1167
-                <td class="total"><strong><?php _e( wpinv_payment_total( $invoice_id, true ) ) ?></strong></td>
1166
+                <td class="rate"><strong><?php _e('Total', 'invoicing') ?></strong></td>
1167
+                <td class="total"><strong><?php _e(wpinv_payment_total($invoice_id, true)) ?></strong></td>
1168 1168
             </tr>
1169
-            <?php do_action( 'wpinv_after_totals' ); ?>
1169
+            <?php do_action('wpinv_after_totals'); ?>
1170 1170
         </tbody>
1171 1171
 
1172 1172
     </table>
1173 1173
 
1174
-    <?php do_action( 'wpinv_after_totals_table' );
1174
+    <?php do_action('wpinv_after_totals_table');
1175 1175
 }
1176 1176
 
1177
-function wpinv_display_payments_info( $invoice_id = 0, $echo = true ) {
1178
-    $invoice = wpinv_get_invoice( $invoice_id );
1177
+function wpinv_display_payments_info($invoice_id = 0, $echo = true) {
1178
+    $invoice = wpinv_get_invoice($invoice_id);
1179 1179
 
1180 1180
     ob_start();
1181
-    do_action( 'wpinv_before_display_payments_info', $invoice_id );
1182
-    if ( ( $gateway_title = $invoice->get_gateway_title() ) || $invoice->is_paid() || $invoice->is_refunded() ) {
1181
+    do_action('wpinv_before_display_payments_info', $invoice_id);
1182
+    if (($gateway_title = $invoice->get_gateway_title()) || $invoice->is_paid() || $invoice->is_refunded()) {
1183 1183
         ?>
1184 1184
         <div class="wpi-payment-info">
1185
-            <p class="wpi-payment-gateway"><?php echo wp_sprintf( __( 'Payment via %s', 'invoicing' ), $gateway_title ? $gateway_title : __( 'Manually', 'invoicing' ) ); ?></p>
1186
-            <?php if ( $gateway_title ) { ?>
1187
-            <p class="wpi-payment-transid"><?php echo wp_sprintf( __( 'Transaction ID: %s', 'invoicing' ), $invoice->get_transaction_id() ); ?></p>
1185
+            <p class="wpi-payment-gateway"><?php echo wp_sprintf(__('Payment via %s', 'invoicing'), $gateway_title ? $gateway_title : __('Manually', 'invoicing')); ?></p>
1186
+            <?php if ($gateway_title) { ?>
1187
+            <p class="wpi-payment-transid"><?php echo wp_sprintf(__('Transaction ID: %s', 'invoicing'), $invoice->get_transaction_id()); ?></p>
1188 1188
             <?php } ?>
1189 1189
         </div>
1190 1190
         <?php
1191 1191
     }
1192
-    do_action( 'wpinv_after_display_payments_info', $invoice_id );
1192
+    do_action('wpinv_after_display_payments_info', $invoice_id);
1193 1193
     $outout = ob_get_clean();
1194 1194
 
1195
-    if ( $echo ) {
1195
+    if ($echo) {
1196 1196
         echo $outout;
1197 1197
     } else {
1198 1198
         return $outout;
1199 1199
     }
1200 1200
 }
1201 1201
 
1202
-function wpinv_display_style( $invoice ) {
1203
-    wp_register_style( 'wpinv-single-style', WPINV_PLUGIN_URL . 'assets/css/invoice.css', array(), WPINV_VERSION );
1202
+function wpinv_display_style($invoice) {
1203
+    wp_register_style('wpinv-single-style', WPINV_PLUGIN_URL . 'assets/css/invoice.css', array(), WPINV_VERSION);
1204 1204
 
1205
-    wp_print_styles( 'open-sans' );
1206
-    wp_print_styles( 'wpinv-single-style' );
1205
+    wp_print_styles('open-sans');
1206
+    wp_print_styles('wpinv-single-style');
1207 1207
 }
1208
-add_action( 'wpinv_invoice_print_head', 'wpinv_display_style' );
1209
-add_action( 'wpinv_invalid_invoice_head', 'wpinv_display_style' );
1208
+add_action('wpinv_invoice_print_head', 'wpinv_display_style');
1209
+add_action('wpinv_invalid_invoice_head', 'wpinv_display_style');
1210 1210
 
1211 1211
 function wpinv_checkout_billing_details() {
1212 1212
     $invoice_id = (int)wpinv_get_invoice_cart_id();
1213 1213
     if (empty($invoice_id)) {
1214
-        wpinv_error_log( 'Invoice id not found', 'ERROR', __FILE__, __LINE__ );
1214
+        wpinv_error_log('Invoice id not found', 'ERROR', __FILE__, __LINE__);
1215 1215
         return null;
1216 1216
     }
1217 1217
 
1218
-    $invoice = wpinv_get_invoice_cart( $invoice_id );
1218
+    $invoice = wpinv_get_invoice_cart($invoice_id);
1219 1219
     if (empty($invoice)) {
1220
-        wpinv_error_log( 'Invoice not found', 'ERROR', __FILE__, __LINE__ );
1220
+        wpinv_error_log('Invoice not found', 'ERROR', __FILE__, __LINE__);
1221 1221
         return null;
1222 1222
     }
1223 1223
     $user_id        = $invoice->get_user_id();
1224 1224
     $user_info      = $invoice->get_user_info();
1225
-    $address_info   = wpinv_get_user_address( $user_id );
1225
+    $address_info   = wpinv_get_user_address($user_id);
1226 1226
 
1227
-    if ( empty( $user_info['first_name'] ) && !empty( $user_info['first_name'] ) ) {
1227
+    if (empty($user_info['first_name']) && !empty($user_info['first_name'])) {
1228 1228
         $user_info['first_name'] = $user_info['first_name'];
1229 1229
         $user_info['last_name'] = $user_info['last_name'];
1230 1230
     }
1231 1231
 
1232
-    if ( ( ( empty( $user_info['country'] ) && !empty( $address_info['country'] ) ) || ( empty( $user_info['state'] ) && !empty( $address_info['state'] ) && $user_info['country'] == $address_info['country'] ) ) ) {
1232
+    if (((empty($user_info['country']) && !empty($address_info['country'])) || (empty($user_info['state']) && !empty($address_info['state']) && $user_info['country'] == $address_info['country']))) {
1233 1233
         $user_info['country']   = $address_info['country'];
1234 1234
         $user_info['state']     = $address_info['state'];
1235 1235
         $user_info['city']      = $address_info['city'];
@@ -1245,98 +1245,98 @@  discard block
 block discarded – undo
1245 1245
         'address'
1246 1246
     );
1247 1247
 
1248
-    foreach ( $address_fields as $field ) {
1249
-        if ( empty( $user_info[$field] ) ) {
1248
+    foreach ($address_fields as $field) {
1249
+        if (empty($user_info[$field])) {
1250 1250
             $user_info[$field] = $address_info[$field];
1251 1251
         }
1252 1252
     }
1253 1253
 
1254
-    return apply_filters( 'wpinv_checkout_billing_details', $user_info, $invoice );
1254
+    return apply_filters('wpinv_checkout_billing_details', $user_info, $invoice);
1255 1255
 }
1256 1256
 
1257 1257
 function wpinv_admin_get_line_items($invoice = array()) {
1258 1258
     $item_quantities    = wpinv_item_quantities_enabled();
1259 1259
     $use_taxes          = wpinv_use_taxes();
1260 1260
 
1261
-    if ( empty( $invoice ) ) {
1261
+    if (empty($invoice)) {
1262 1262
         return NULL;
1263 1263
     }
1264 1264
 
1265 1265
     $cart_items = $invoice->get_cart_details();
1266
-    if ( empty( $cart_items ) ) {
1266
+    if (empty($cart_items)) {
1267 1267
         return NULL;
1268 1268
     }
1269 1269
     ob_start();
1270 1270
 
1271
-    do_action( 'wpinv_admin_before_line_items', $cart_items, $invoice );
1271
+    do_action('wpinv_admin_before_line_items', $cart_items, $invoice);
1272 1272
 
1273 1273
     $count = 0;
1274
-    foreach ( $cart_items as $key => $cart_item ) {
1274
+    foreach ($cart_items as $key => $cart_item) {
1275 1275
         $item_id    = $cart_item['id'];
1276
-        $wpi_item   = $item_id > 0 ? new WPInv_Item( $item_id ) : NULL;
1276
+        $wpi_item   = $item_id > 0 ? new WPInv_Item($item_id) : NULL;
1277 1277
 
1278 1278
         if (empty($wpi_item)) {
1279 1279
             continue;
1280 1280
         }
1281 1281
 
1282
-        $item_price     = wpinv_price( wpinv_format_amount( $cart_item['item_price'] ), $invoice->get_currency() );
1283
-        $quantity       = !empty( $cart_item['quantity'] ) && $cart_item['quantity'] > 0 ? $cart_item['quantity'] : 1;
1284
-        $item_subtotal  = wpinv_price( wpinv_format_amount( $cart_item['subtotal'] ), $invoice->get_currency() );
1282
+        $item_price     = wpinv_price(wpinv_format_amount($cart_item['item_price']), $invoice->get_currency());
1283
+        $quantity       = !empty($cart_item['quantity']) && $cart_item['quantity'] > 0 ? $cart_item['quantity'] : 1;
1284
+        $item_subtotal  = wpinv_price(wpinv_format_amount($cart_item['subtotal']), $invoice->get_currency());
1285 1285
         $can_remove     = true;
1286 1286
 
1287
-        $summary = apply_filters( 'wpinv_admin_invoice_line_item_summary', '', $cart_item, $wpi_item, $invoice );
1287
+        $summary = apply_filters('wpinv_admin_invoice_line_item_summary', '', $cart_item, $wpi_item, $invoice);
1288 1288
 
1289 1289
         $item_tax       = '';
1290 1290
         $tax_rate       = '';
1291
-        if ( $cart_item['tax'] > 0 && $cart_item['subtotal'] > 0 ) {
1292
-            $item_tax = wpinv_price( wpinv_format_amount( $cart_item['tax'] ), $invoice->get_currency() );
1293
-            $tax_rate = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : ( $cart_item['tax'] / $cart_item['subtotal'] ) * 100;
1294
-            $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount( $tax_rate, 4 ) : '';
1291
+        if ($cart_item['tax'] > 0 && $cart_item['subtotal'] > 0) {
1292
+            $item_tax = wpinv_price(wpinv_format_amount($cart_item['tax']), $invoice->get_currency());
1293
+            $tax_rate = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : ($cart_item['tax'] / $cart_item['subtotal']) * 100;
1294
+            $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount($tax_rate, 4) : '';
1295 1295
             $tax_rate = $tax_rate != '' ? ' <span class="tax-rate">(' . $tax_rate . '%)</span>' : '';
1296 1296
         }
1297 1297
         $line_item_tax = $item_tax . $tax_rate;
1298 1298
 
1299
-        if ( $line_item_tax === '' ) {
1299
+        if ($line_item_tax === '') {
1300 1300
             $line_item_tax = 0; // Zero tax
1301 1301
         }
1302 1302
 
1303
-        $line_item = '<tr class="item item-' . ( ($count % 2 == 0) ? 'even' : 'odd' ) . '" data-item-id="' . $item_id . '">';
1303
+        $line_item = '<tr class="item item-' . (($count % 2 == 0) ? 'even' : 'odd') . '" data-item-id="' . $item_id . '">';
1304 1304
             $line_item .= '<td class="id">' . $item_id . '</td>';
1305
-            $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 );
1306
-            if ( $summary !== '' ) {
1307
-                $line_item .= '<span class="meta">' . wpautop( wp_kses_post( $summary ) ) . '</span>';
1305
+            $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);
1306
+            if ($summary !== '') {
1307
+                $line_item .= '<span class="meta">' . wpautop(wp_kses_post($summary)) . '</span>';
1308 1308
             }
1309 1309
             $line_item .= '</td>';
1310 1310
             $line_item .= '<td class="price">' . $item_price . '</td>';
1311 1311
             
1312
-            if ( $item_quantities ) {
1313
-                if ( count( $cart_items ) == 1 && $quantity <= 1 ) {
1312
+            if ($item_quantities) {
1313
+                if (count($cart_items) == 1 && $quantity <= 1) {
1314 1314
                     $can_remove = false;
1315 1315
                 }
1316 1316
                 $line_item .= '<td class="qty" data-quantity="' . $quantity . '">&nbsp;&times;&nbsp;' . $quantity . '</td>';
1317 1317
             } else {
1318
-                if ( count( $cart_items ) == 1 ) {
1318
+                if (count($cart_items) == 1) {
1319 1319
                     $can_remove = false;
1320 1320
                 }
1321 1321
             }
1322 1322
             $line_item .= '<td class="total">' . $item_subtotal . '</td>';
1323 1323
             
1324
-            if ( $use_taxes ) {
1324
+            if ($use_taxes) {
1325 1325
                 $line_item .= '<td class="tax">' . $line_item_tax . '</td>';
1326 1326
             }
1327 1327
             $line_item .= '<td class="action">';
1328
-            if ( !$invoice->is_paid() && !$invoice->is_refunded() && $can_remove ) {
1328
+            if (!$invoice->is_paid() && !$invoice->is_refunded() && $can_remove) {
1329 1329
                 $line_item .= '<i class="fa fa-remove wpinv-item-remove"></i>';
1330 1330
             }
1331 1331
             $line_item .= '</td>';
1332 1332
         $line_item .= '</tr>';
1333 1333
 
1334
-        echo apply_filters( 'wpinv_admin_line_item', $line_item, $cart_item, $invoice );
1334
+        echo apply_filters('wpinv_admin_line_item', $line_item, $cart_item, $invoice);
1335 1335
 
1336 1336
         $count++;
1337 1337
     } 
1338 1338
 
1339
-    do_action( 'wpinv_admin_after_line_items', $cart_items, $invoice );
1339
+    do_action('wpinv_admin_after_line_items', $cart_items, $invoice);
1340 1340
 
1341 1341
     return ob_get_clean();
1342 1342
 }
@@ -1347,35 +1347,35 @@  discard block
 block discarded – undo
1347 1347
     // Set current invoice id.
1348 1348
     $wpi_checkout_id = wpinv_get_invoice_cart_id();
1349 1349
 
1350
-    $form_action  = esc_url( wpinv_get_checkout_uri() );
1350
+    $form_action = esc_url(wpinv_get_checkout_uri());
1351 1351
 
1352 1352
     ob_start();
1353 1353
         echo '<div id="wpinv_checkout_wrap">';
1354 1354
 
1355
-        if ( wpinv_get_cart_contents() || wpinv_cart_has_fees() ) {
1355
+        if (wpinv_get_cart_contents() || wpinv_cart_has_fees()) {
1356 1356
             ?>
1357 1357
             <div id="wpinv_checkout_form_wrap" class="wpinv_clearfix table-responsive">
1358
-                <?php do_action( 'wpinv_before_checkout_form' ); ?>
1358
+                <?php do_action('wpinv_before_checkout_form'); ?>
1359 1359
                 <form id="wpinv_checkout_form" class="wpi-form" action="<?php echo $form_action; ?>" method="POST">
1360 1360
                     <?php
1361
-                    do_action( 'wpinv_checkout_form_top' );
1362
-                    do_action( 'wpinv_checkout_billing_info' );
1363
-                    do_action( 'wpinv_checkout_cart' );
1364
-                    do_action( 'wpinv_payment_mode_select'  );
1365
-                    do_action( 'wpinv_checkout_form_bottom' )
1361
+                    do_action('wpinv_checkout_form_top');
1362
+                    do_action('wpinv_checkout_billing_info');
1363
+                    do_action('wpinv_checkout_cart');
1364
+                    do_action('wpinv_payment_mode_select');
1365
+                    do_action('wpinv_checkout_form_bottom')
1366 1366
                     ?>
1367 1367
                 </form>
1368
-                <?php do_action( 'wpinv_after_purchase_form' ); ?>
1368
+                <?php do_action('wpinv_after_purchase_form'); ?>
1369 1369
             </div><!--end #wpinv_checkout_form_wrap-->
1370 1370
         <?php
1371 1371
         } else {
1372
-            do_action( 'wpinv_cart_empty' );
1372
+            do_action('wpinv_cart_empty');
1373 1373
         }
1374 1374
         echo '</div><!--end #wpinv_checkout_wrap-->';
1375 1375
     return ob_get_clean();
1376 1376
 }
1377 1377
 
1378
-function wpinv_checkout_cart( $cart_details = array(), $echo = true ) {
1378
+function wpinv_checkout_cart($cart_details = array(), $echo = true) {
1379 1379
     global $ajax_cart_details;
1380 1380
     $ajax_cart_details = $cart_details;
1381 1381
     /*
@@ -1390,25 +1390,25 @@  discard block
 block discarded – undo
1390 1390
     }
1391 1391
     */
1392 1392
     ob_start();
1393
-    do_action( 'wpinv_before_checkout_cart' );
1393
+    do_action('wpinv_before_checkout_cart');
1394 1394
     echo '<div id="wpinv_checkout_cart_form" method="post">';
1395 1395
         echo '<div id="wpinv_checkout_cart_wrap">';
1396
-            wpinv_get_template_part( 'wpinv-checkout-cart' );
1396
+            wpinv_get_template_part('wpinv-checkout-cart');
1397 1397
         echo '</div>';
1398 1398
     echo '</div>';
1399
-    do_action( 'wpinv_after_checkout_cart' );
1399
+    do_action('wpinv_after_checkout_cart');
1400 1400
     $content = ob_get_clean();
1401 1401
     
1402
-    if ( $echo ) {
1402
+    if ($echo) {
1403 1403
         echo $content;
1404 1404
     } else {
1405 1405
         return $content;
1406 1406
     }
1407 1407
 }
1408
-add_action( 'wpinv_checkout_cart', 'wpinv_checkout_cart', 10 );
1408
+add_action('wpinv_checkout_cart', 'wpinv_checkout_cart', 10);
1409 1409
 
1410 1410
 function wpinv_empty_cart_message() {
1411
-	return apply_filters( 'wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __( 'Your cart is empty.', 'invoicing' ) . '</span>' );
1411
+	return apply_filters('wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __('Your cart is empty.', 'invoicing') . '</span>');
1412 1412
 }
1413 1413
 
1414 1414
 /**
@@ -1420,91 +1420,91 @@  discard block
 block discarded – undo
1420 1420
 function wpinv_empty_checkout_cart() {
1421 1421
 	echo wpinv_empty_cart_message();
1422 1422
 }
1423
-add_action( 'wpinv_cart_empty', 'wpinv_empty_checkout_cart' );
1423
+add_action('wpinv_cart_empty', 'wpinv_empty_checkout_cart');
1424 1424
 
1425 1425
 function wpinv_save_cart_button() {
1426
-    if ( wpinv_is_cart_saving_disabled() )
1426
+    if (wpinv_is_cart_saving_disabled())
1427 1427
         return;
1428 1428
 ?>
1429
-    <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>
1429
+    <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>
1430 1430
 <?php
1431 1431
 }
1432 1432
 
1433 1433
 function wpinv_update_cart_button() {
1434
-    if ( !wpinv_item_quantities_enabled() )
1434
+    if (!wpinv_item_quantities_enabled())
1435 1435
         return;
1436 1436
 ?>
1437
-    <input type="submit" name="wpinv_update_cart_submit" class="wpinv-submit wpinv-no-js button" value="<?php _e( 'Update Cart', 'invoicing' ); ?>"/>
1437
+    <input type="submit" name="wpinv_update_cart_submit" class="wpinv-submit wpinv-no-js button" value="<?php _e('Update Cart', 'invoicing'); ?>"/>
1438 1438
     <input type="hidden" name="wpi_action" value="update_cart"/>
1439 1439
 <?php
1440 1440
 }
1441 1441
 
1442 1442
 function wpinv_checkout_cart_columns() {
1443 1443
     $default = 3;
1444
-    if ( wpinv_item_quantities_enabled() ) {
1444
+    if (wpinv_item_quantities_enabled()) {
1445 1445
         $default++;
1446 1446
     }
1447 1447
     
1448
-    if ( wpinv_use_taxes() ) {
1448
+    if (wpinv_use_taxes()) {
1449 1449
         $default++;
1450 1450
     }
1451 1451
 
1452
-    return apply_filters( 'wpinv_checkout_cart_columns', $default );
1452
+    return apply_filters('wpinv_checkout_cart_columns', $default);
1453 1453
 }
1454 1454
 
1455 1455
 function wpinv_display_cart_messages() {
1456 1456
     global $wpi_session;
1457 1457
 
1458
-    $messages = $wpi_session->get( 'wpinv_cart_messages' );
1458
+    $messages = $wpi_session->get('wpinv_cart_messages');
1459 1459
 
1460
-    if ( $messages ) {
1461
-        foreach ( $messages as $message_id => $message ) {
1460
+    if ($messages) {
1461
+        foreach ($messages as $message_id => $message) {
1462 1462
             // Try and detect what type of message this is
1463
-            if ( strpos( strtolower( $message ), 'error' ) ) {
1463
+            if (strpos(strtolower($message), 'error')) {
1464 1464
                 $type = 'error';
1465
-            } elseif ( strpos( strtolower( $message ), 'success' ) ) {
1465
+            } elseif (strpos(strtolower($message), 'success')) {
1466 1466
                 $type = 'success';
1467 1467
             } else {
1468 1468
                 $type = 'info';
1469 1469
             }
1470 1470
 
1471
-            $classes = apply_filters( 'wpinv_' . $type . '_class', array( 'wpinv_errors', 'wpinv-alert', 'wpinv-alert-' . $type ) );
1471
+            $classes = apply_filters('wpinv_' . $type . '_class', array('wpinv_errors', 'wpinv-alert', 'wpinv-alert-' . $type));
1472 1472
 
1473
-            echo '<div class="' . implode( ' ', $classes ) . '">';
1473
+            echo '<div class="' . implode(' ', $classes) . '">';
1474 1474
                 // Loop message codes and display messages
1475 1475
                     echo '<p class="wpinv_error" id="wpinv_msg_' . $message_id . '">' . $message . '</p>';
1476 1476
             echo '</div>';
1477 1477
         }
1478 1478
 
1479 1479
         // Remove all of the cart saving messages
1480
-        $wpi_session->set( 'wpinv_cart_messages', null );
1480
+        $wpi_session->set('wpinv_cart_messages', null);
1481 1481
     }
1482 1482
 }
1483
-add_action( 'wpinv_before_checkout_cart', 'wpinv_display_cart_messages' );
1483
+add_action('wpinv_before_checkout_cart', 'wpinv_display_cart_messages');
1484 1484
 
1485 1485
 function wpinv_discount_field() {
1486
-    if ( isset( $_GET['wpi-gateway'] ) && wpinv_is_ajax_disabled() ) {
1486
+    if (isset($_GET['wpi-gateway']) && wpinv_is_ajax_disabled()) {
1487 1487
         return; // Only show before a payment method has been selected if ajax is disabled
1488 1488
     }
1489 1489
 
1490
-    if ( !wpinv_is_checkout() ) {
1490
+    if (!wpinv_is_checkout()) {
1491 1491
         return;
1492 1492
     }
1493 1493
 
1494
-    if ( wpinv_has_active_discounts() && wpinv_get_cart_total() ) {
1494
+    if (wpinv_has_active_discounts() && wpinv_get_cart_total()) {
1495 1495
     ?>
1496 1496
     <div id="wpinv-discount-field" class="panel panel-default">
1497 1497
         <div class="panel-body">
1498 1498
             <p>
1499
-                <label class="wpinv-label" for="wpinv_discount_code"><strong><?php _e( 'Discount', 'invoicing' ); ?></strong></label>
1500
-                <span class="wpinv-description"><?php _e( 'Enter a discount code if you have one.', 'invoicing' ); ?></span>
1499
+                <label class="wpinv-label" for="wpinv_discount_code"><strong><?php _e('Discount', 'invoicing'); ?></strong></label>
1500
+                <span class="wpinv-description"><?php _e('Enter a discount code if you have one.', 'invoicing'); ?></span>
1501 1501
             </p>
1502 1502
             <div class="form-group row">
1503 1503
                 <div class="col-sm-4">
1504
-                    <input class="wpinv-input form-control" type="text" id="wpinv_discount_code" name="wpinv_discount_code" placeholder="<?php _e( 'Enter discount code', 'invoicing' ); ?>"/>
1504
+                    <input class="wpinv-input form-control" type="text" id="wpinv_discount_code" name="wpinv_discount_code" placeholder="<?php _e('Enter discount code', 'invoicing'); ?>"/>
1505 1505
                 </div>
1506 1506
                 <div class="col-sm-3">
1507
-                    <button id="wpi-apply-discount" type="button" class="btn btn-success btn-sm"><?php _e( 'Apply Discount', 'invoicing' ); ?></button>
1507
+                    <button id="wpi-apply-discount" type="button" class="btn btn-success btn-sm"><?php _e('Apply Discount', 'invoicing'); ?></button>
1508 1508
                 </div>
1509 1509
                 <div style="clear:both"></div>
1510 1510
                 <div class="col-sm-12 wpinv-discount-msg">
@@ -1517,10 +1517,10 @@  discard block
 block discarded – undo
1517 1517
 <?php
1518 1518
     }
1519 1519
 }
1520
-add_action( 'wpinv_after_checkout_cart', 'wpinv_discount_field', -10 );
1520
+add_action('wpinv_after_checkout_cart', 'wpinv_discount_field', -10);
1521 1521
 
1522 1522
 function wpinv_agree_to_terms_js() {
1523
-    if ( wpinv_get_option( 'show_agree_to_terms', false ) ) {
1523
+    if (wpinv_get_option('show_agree_to_terms', false)) {
1524 1524
 ?>
1525 1525
 <script type="text/javascript">
1526 1526
     jQuery(document).ready(function($){
@@ -1535,126 +1535,126 @@  discard block
 block discarded – undo
1535 1535
 <?php
1536 1536
     }
1537 1537
 }
1538
-add_action( 'wpinv_checkout_form_top', 'wpinv_agree_to_terms_js' );
1538
+add_action('wpinv_checkout_form_top', 'wpinv_agree_to_terms_js');
1539 1539
 
1540 1540
 function wpinv_payment_mode_select() {
1541
-    $gateways = wpinv_get_enabled_payment_gateways( true );
1542
-    $gateways = apply_filters( 'wpinv_payment_gateways_on_cart', $gateways );
1541
+    $gateways = wpinv_get_enabled_payment_gateways(true);
1542
+    $gateways = apply_filters('wpinv_payment_gateways_on_cart', $gateways);
1543 1543
     $page_URL = wpinv_get_current_page_url();
1544
-    $invoice = wpinv_get_invoice( 0, true );
1544
+    $invoice = wpinv_get_invoice(0, true);
1545 1545
 
1546 1546
     do_action('wpinv_payment_mode_top');
1547 1547
     $invoice_id = (int)$invoice->ID;
1548
-    $chosen_gateway = wpinv_get_chosen_gateway( $invoice_id );
1548
+    $chosen_gateway = wpinv_get_chosen_gateway($invoice_id);
1549 1549
     ?>
1550
-    <div id="wpinv_payment_mode_select" data-gateway="<?php echo $chosen_gateway; ?>" <?php echo ( $invoice->is_free() ? 'style="display:none;" data-free="1"' : '' ); ?>>
1551
-            <?php do_action( 'wpinv_payment_mode_before_gateways_wrap' ); ?>
1550
+    <div id="wpinv_payment_mode_select" data-gateway="<?php echo $chosen_gateway; ?>" <?php echo ($invoice->is_free() ? 'style="display:none;" data-free="1"' : ''); ?>>
1551
+            <?php do_action('wpinv_payment_mode_before_gateways_wrap'); ?>
1552 1552
             <div id="wpinv-payment-mode-wrap" class="panel panel-default">
1553
-                <div class="panel-heading"><h3 class="panel-title"><?php _e( 'Select Payment Method', 'invoicing' ); ?></h3></div>
1553
+                <div class="panel-heading"><h3 class="panel-title"><?php _e('Select Payment Method', 'invoicing'); ?></h3></div>
1554 1554
                 <div class="panel-body list-group wpi-payment_methods">
1555 1555
                     <?php
1556
-                    do_action( 'wpinv_payment_mode_before_gateways' );
1556
+                    do_action('wpinv_payment_mode_before_gateways');
1557 1557
 
1558
-                    if ( !empty( $gateways ) ) {
1559
-                        foreach ( $gateways as $gateway_id => $gateway ) {
1560
-                            $checked = checked( $gateway_id, $chosen_gateway, false );
1561
-                            $button_label = wpinv_get_gateway_button_label( $gateway_id );
1562
-                            $description = wpinv_get_gateway_description( $gateway_id );
1558
+                    if (!empty($gateways)) {
1559
+                        foreach ($gateways as $gateway_id => $gateway) {
1560
+                            $checked = checked($gateway_id, $chosen_gateway, false);
1561
+                            $button_label = wpinv_get_gateway_button_label($gateway_id);
1562
+                            $description = wpinv_get_gateway_description($gateway_id);
1563 1563
                             ?>
1564 1564
                             <div class="list-group-item">
1565 1565
                                 <div class="radio">
1566
-                                    <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>
1566
+                                    <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>
1567 1567
                                 </div>
1568
-                                <div style="display:none;" class="payment_box wpi_gateway_<?php echo esc_attr( $gateway_id );?>" role="alert">
1569
-                                    <?php if ( !empty( $description ) ) { ?>
1570
-                                        <div class="wpi-gateway-desc alert alert-info"><?php echo $description;?></div>
1568
+                                <div style="display:none;" class="payment_box wpi_gateway_<?php echo esc_attr($gateway_id); ?>" role="alert">
1569
+                                    <?php if (!empty($description)) { ?>
1570
+                                        <div class="wpi-gateway-desc alert alert-info"><?php echo $description; ?></div>
1571 1571
                                     <?php } ?>
1572
-                                    <?php do_action( 'wpinv_' . $gateway_id . '_cc_form', $invoice_id ) ;?>
1572
+                                    <?php do_action('wpinv_' . $gateway_id . '_cc_form', $invoice_id); ?>
1573 1573
                                 </div>
1574 1574
                             </div>
1575 1575
                             <?php
1576 1576
                         }
1577 1577
                     } else {
1578
-                        echo '<div class="alert alert-warning">'. __( 'No payment gateway active', 'invoicing' ) .'</div>';
1578
+                        echo '<div class="alert alert-warning">' . __('No payment gateway active', 'invoicing') . '</div>';
1579 1579
                     }
1580 1580
 
1581
-                    do_action( 'wpinv_payment_mode_after_gateways' );
1581
+                    do_action('wpinv_payment_mode_after_gateways');
1582 1582
                     ?>
1583 1583
                 </div>
1584 1584
             </div>
1585
-            <?php do_action( 'wpinv_payment_mode_after_gateways_wrap' ); ?>
1585
+            <?php do_action('wpinv_payment_mode_after_gateways_wrap'); ?>
1586 1586
     </div>
1587 1587
     <?php
1588 1588
     do_action('wpinv_payment_mode_bottom');
1589 1589
 }
1590
-add_action( 'wpinv_payment_mode_select', 'wpinv_payment_mode_select' );
1590
+add_action('wpinv_payment_mode_select', 'wpinv_payment_mode_select');
1591 1591
 
1592 1592
 function wpinv_checkout_billing_info() {
1593
-    if ( wpinv_is_checkout() ) {
1593
+    if (wpinv_is_checkout()) {
1594 1594
         $logged_in          = is_user_logged_in();
1595 1595
         $billing_details    = wpinv_checkout_billing_details();
1596
-        $selected_country   = !empty( $billing_details['country'] ) ? $billing_details['country'] : wpinv_default_billing_country();
1596
+        $selected_country   = !empty($billing_details['country']) ? $billing_details['country'] : wpinv_default_billing_country();
1597 1597
         ?>
1598 1598
         <div id="wpinv-fields" class="clearfix">
1599 1599
             <div id="wpi-billing" class="wpi-billing clearfix panel panel-default">
1600
-                <div class="panel-heading"><h3 class="panel-title"><?php _e( 'Billing Details', 'invoicing' );?></h3></div>
1600
+                <div class="panel-heading"><h3 class="panel-title"><?php _e('Billing Details', 'invoicing'); ?></h3></div>
1601 1601
                 <div id="wpinv-fields-box" class="panel-body">
1602
-                    <?php do_action( 'wpinv_checkout_billing_fields_first', $billing_details ); ?>
1602
+                    <?php do_action('wpinv_checkout_billing_fields_first', $billing_details); ?>
1603 1603
                     <p class="wpi-cart-field wpi-col2 wpi-colf">
1604
-                        <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>
1604
+                        <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>
1605 1605
                         <?php
1606
-                        echo wpinv_html_text( array(
1606
+                        echo wpinv_html_text(array(
1607 1607
                                 'id'            => 'wpinv_first_name',
1608 1608
                                 'name'          => 'wpinv_first_name',
1609 1609
                                 'value'         => $billing_details['first_name'],
1610 1610
                                 'class'         => 'wpi-input form-control',
1611
-                                'placeholder'   => __( 'First name', 'invoicing' ),
1612
-                                'required'      => (bool)wpinv_get_option( 'fname_mandatory' ),
1613
-                            ) );
1611
+                                'placeholder'   => __('First name', 'invoicing'),
1612
+                                'required'      => (bool)wpinv_get_option('fname_mandatory'),
1613
+                            ));
1614 1614
                         ?>
1615 1615
                     </p>
1616 1616
                     <p class="wpi-cart-field wpi-col2 wpi-coll">
1617
-                        <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>
1617
+                        <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>
1618 1618
                         <?php
1619
-                        echo wpinv_html_text( array(
1619
+                        echo wpinv_html_text(array(
1620 1620
                                 'id'            => 'wpinv_last_name',
1621 1621
                                 'name'          => 'wpinv_last_name',
1622 1622
                                 'value'         => $billing_details['last_name'],
1623 1623
                                 'class'         => 'wpi-input form-control',
1624
-                                'placeholder'   => __( 'Last name', 'invoicing' ),
1625
-                                'required'      => (bool)wpinv_get_option( 'lname_mandatory' ),
1626
-                            ) );
1624
+                                'placeholder'   => __('Last name', 'invoicing'),
1625
+                                'required'      => (bool)wpinv_get_option('lname_mandatory'),
1626
+                            ));
1627 1627
                         ?>
1628 1628
                     </p>
1629 1629
                     <p class="wpi-cart-field wpi-col2 wpi-colf">
1630
-                        <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>
1630
+                        <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>
1631 1631
                         <?php
1632
-                        echo wpinv_html_text( array(
1632
+                        echo wpinv_html_text(array(
1633 1633
                                 'id'            => 'wpinv_address',
1634 1634
                                 'name'          => 'wpinv_address',
1635 1635
                                 'value'         => $billing_details['address'],
1636 1636
                                 'class'         => 'wpi-input form-control',
1637
-                                'placeholder'   => __( 'Address', 'invoicing' ),
1638
-                                'required'      => (bool)wpinv_get_option( 'address_mandatory' ),
1639
-                            ) );
1637
+                                'placeholder'   => __('Address', 'invoicing'),
1638
+                                'required'      => (bool)wpinv_get_option('address_mandatory'),
1639
+                            ));
1640 1640
                         ?>
1641 1641
                     </p>
1642 1642
                     <p class="wpi-cart-field wpi-col2 wpi-coll">
1643
-                        <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>
1643
+                        <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>
1644 1644
                         <?php
1645
-                        echo wpinv_html_text( array(
1645
+                        echo wpinv_html_text(array(
1646 1646
                                 'id'            => 'wpinv_city',
1647 1647
                                 'name'          => 'wpinv_city',
1648 1648
                                 'value'         => $billing_details['city'],
1649 1649
                                 'class'         => 'wpi-input form-control',
1650
-                                'placeholder'   => __( 'City', 'invoicing' ),
1651
-                                'required'      => (bool)wpinv_get_option( 'city_mandatory' ),
1652
-                            ) );
1650
+                                'placeholder'   => __('City', 'invoicing'),
1651
+                                'required'      => (bool)wpinv_get_option('city_mandatory'),
1652
+                            ));
1653 1653
                         ?>
1654 1654
                     </p>
1655 1655
                     <p id="wpinv_country_box" class="wpi-cart-field wpi-col2 wpi-colf">
1656
-                        <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>
1657
-                        <?php echo wpinv_html_select( array(
1656
+                        <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>
1657
+                        <?php echo wpinv_html_select(array(
1658 1658
                             'options'          => wpinv_get_country_list(),
1659 1659
                             'name'             => 'wpinv_country',
1660 1660
                             'id'               => 'wpinv_country',
@@ -1662,16 +1662,16 @@  discard block
 block discarded – undo
1662 1662
                             'show_option_all'  => false,
1663 1663
                             'show_option_none' => false,
1664 1664
                             'class'            => 'wpi-input form-control',
1665
-                            'placeholder'      => __( 'Choose a country', 'invoicing' ),
1666
-                            'required'         => (bool)wpinv_get_option( 'country_mandatory' ),
1667
-                        ) ); ?>
1665
+                            'placeholder'      => __('Choose a country', 'invoicing'),
1666
+                            'required'         => (bool)wpinv_get_option('country_mandatory'),
1667
+                        )); ?>
1668 1668
                     </p>
1669 1669
                     <p id="wpinv_state_box" class="wpi-cart-field wpi-col2 wpi-coll">
1670
-                        <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>
1670
+                        <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>
1671 1671
                         <?php
1672
-                        $states = wpinv_get_country_states( $selected_country );
1673
-                        if( !empty( $states ) ) {
1674
-                            echo wpinv_html_select( array(
1672
+                        $states = wpinv_get_country_states($selected_country);
1673
+                        if (!empty($states)) {
1674
+                            echo wpinv_html_select(array(
1675 1675
                                 'options'          => $states,
1676 1676
                                 'name'             => 'wpinv_state',
1677 1677
                                 'id'               => 'wpinv_state',
@@ -1679,61 +1679,61 @@  discard block
 block discarded – undo
1679 1679
                                 'show_option_all'  => false,
1680 1680
                                 'show_option_none' => false,
1681 1681
                                 'class'            => 'wpi-input form-control',
1682
-                                'placeholder'      => __( 'Choose a state', 'invoicing' ),
1683
-                                'required'         => (bool)wpinv_get_option( 'state_mandatory' ),
1684
-                            ) );
1682
+                                'placeholder'      => __('Choose a state', 'invoicing'),
1683
+                                'required'         => (bool)wpinv_get_option('state_mandatory'),
1684
+                            ));
1685 1685
                         } else {
1686
-                            echo wpinv_html_text( array(
1686
+                            echo wpinv_html_text(array(
1687 1687
                                 'name'          => 'wpinv_state',
1688 1688
                                 'value'         => $billing_details['state'],
1689 1689
                                 'id'            => 'wpinv_state',
1690 1690
                                 'class'         => 'wpi-input form-control',
1691
-                                'placeholder'   => __( 'State / Province', 'invoicing' ),
1692
-                                'required'      => (bool)wpinv_get_option( 'state_mandatory' ),
1693
-                            ) );
1691
+                                'placeholder'   => __('State / Province', 'invoicing'),
1692
+                                'required'      => (bool)wpinv_get_option('state_mandatory'),
1693
+                            ));
1694 1694
                         }
1695 1695
                         ?>
1696 1696
                     </p>
1697 1697
                     <p class="wpi-cart-field wpi-col2 wpi-colf">
1698
-                        <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>
1698
+                        <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>
1699 1699
                         <?php
1700
-                        echo wpinv_html_text( array(
1700
+                        echo wpinv_html_text(array(
1701 1701
                                 'name'          => 'wpinv_zip',
1702 1702
                                 'value'         => $billing_details['zip'],
1703 1703
                                 'id'            => 'wpinv_zip',
1704 1704
                                 'class'         => 'wpi-input form-control',
1705
-                                'placeholder'   => __( 'ZIP / Postcode', 'invoicing' ),
1706
-                                'required'      => (bool)wpinv_get_option( 'zip_mandatory' ),
1707
-                            ) );
1705
+                                'placeholder'   => __('ZIP / Postcode', 'invoicing'),
1706
+                                'required'      => (bool)wpinv_get_option('zip_mandatory'),
1707
+                            ));
1708 1708
                         ?>
1709 1709
                     </p>
1710 1710
                     <p class="wpi-cart-field wpi-col2 wpi-coll">
1711
-                        <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>
1711
+                        <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>
1712 1712
                         <?php
1713
-                        echo wpinv_html_text( array(
1713
+                        echo wpinv_html_text(array(
1714 1714
                                 'id'            => 'wpinv_phone',
1715 1715
                                 'name'          => 'wpinv_phone',
1716 1716
                                 'value'         => $billing_details['phone'],
1717 1717
                                 'class'         => 'wpi-input form-control',
1718
-                                'placeholder'   => __( 'Phone', 'invoicing' ),
1719
-                                'required'      => (bool)wpinv_get_option( 'phone_mandatory' ),
1720
-                            ) );
1718
+                                'placeholder'   => __('Phone', 'invoicing'),
1719
+                                'required'      => (bool)wpinv_get_option('phone_mandatory'),
1720
+                            ));
1721 1721
                         ?>
1722 1722
                     </p>
1723
-                    <?php do_action( 'wpinv_checkout_billing_fields_last', $billing_details ); ?>
1723
+                    <?php do_action('wpinv_checkout_billing_fields_last', $billing_details); ?>
1724 1724
                     <div class="clearfix"></div>
1725 1725
                 </div>
1726 1726
             </div>
1727
-            <?php do_action( 'wpinv_after_billing_fields', $billing_details ); ?>
1727
+            <?php do_action('wpinv_after_billing_fields', $billing_details); ?>
1728 1728
         </div>
1729 1729
         <?php
1730 1730
     }
1731 1731
 }
1732
-add_action( 'wpinv_checkout_billing_info', 'wpinv_checkout_billing_info' );
1732
+add_action('wpinv_checkout_billing_info', 'wpinv_checkout_billing_info');
1733 1733
 
1734 1734
 function wpinv_checkout_hidden_fields() {
1735 1735
 ?>
1736
-    <?php if ( is_user_logged_in() ) { ?>
1736
+    <?php if (is_user_logged_in()) { ?>
1737 1737
     <input type="hidden" name="wpinv_user_id" value="<?php echo get_current_user_id(); ?>"/>
1738 1738
     <?php } ?>
1739 1739
     <input type="hidden" name="wpi_action" value="payment" />
@@ -1743,9 +1743,9 @@  discard block
 block discarded – undo
1743 1743
 function wpinv_checkout_button_purchase() {
1744 1744
     ob_start();
1745 1745
 ?>
1746
-    <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' ) ?>"/>
1746
+    <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') ?>"/>
1747 1747
 <?php
1748
-    return apply_filters( 'wpinv_checkout_button_purchase', ob_get_clean() );
1748
+    return apply_filters('wpinv_checkout_button_purchase', ob_get_clean());
1749 1749
 }
1750 1750
 
1751 1751
 function wpinv_checkout_total() {
@@ -1754,96 +1754,96 @@  discard block
 block discarded – undo
1754 1754
 <div id="wpinv_checkout_total" class="panel panel-info">
1755 1755
     <div class="panel-body">
1756 1756
     <?php
1757
-    do_action( 'wpinv_purchase_form_before_checkout_total' );
1757
+    do_action('wpinv_purchase_form_before_checkout_total');
1758 1758
     ?>
1759
-    <strong><?php _e( 'Invoice Total:', 'invoicing' ) ?></strong> <span class="wpinv-chdeckout-total"><?php echo $cart_total;?></span>
1759
+    <strong><?php _e('Invoice Total:', 'invoicing') ?></strong> <span class="wpinv-chdeckout-total"><?php echo $cart_total; ?></span>
1760 1760
     <?php
1761
-    do_action( 'wpinv_purchase_form_after_checkout_total' );
1761
+    do_action('wpinv_purchase_form_after_checkout_total');
1762 1762
     ?>
1763 1763
     </div>
1764 1764
 </div>
1765 1765
 <?php
1766 1766
 }
1767
-add_action( 'wpinv_checkout_form_bottom', 'wpinv_checkout_total', 9998 );
1767
+add_action('wpinv_checkout_form_bottom', 'wpinv_checkout_total', 9998);
1768 1768
 
1769 1769
 function wpinv_checkout_submit() {
1770 1770
 ?>
1771 1771
 <div id="wpinv_purchase_submit" class="panel panel-success">
1772 1772
     <div class="panel-body text-center">
1773 1773
     <?php
1774
-    do_action( 'wpinv_purchase_form_before_submit' );
1774
+    do_action('wpinv_purchase_form_before_submit');
1775 1775
     wpinv_checkout_hidden_fields();
1776 1776
     echo wpinv_checkout_button_purchase();
1777
-    do_action( 'wpinv_purchase_form_after_submit' );
1777
+    do_action('wpinv_purchase_form_after_submit');
1778 1778
     ?>
1779 1779
     </div>
1780 1780
 </div>
1781 1781
 <?php
1782 1782
 }
1783
-add_action( 'wpinv_checkout_form_bottom', 'wpinv_checkout_submit', 9999 );
1783
+add_action('wpinv_checkout_form_bottom', 'wpinv_checkout_submit', 9999);
1784 1784
 
1785
-function wpinv_receipt_billing_address( $invoice_id = 0 ) {
1786
-    $invoice = wpinv_get_invoice( $invoice_id );
1785
+function wpinv_receipt_billing_address($invoice_id = 0) {
1786
+    $invoice = wpinv_get_invoice($invoice_id);
1787 1787
 
1788
-    if ( empty( $invoice ) ) {
1788
+    if (empty($invoice)) {
1789 1789
         return NULL;
1790 1790
     }
1791 1791
 
1792 1792
     $billing_details = $invoice->get_user_info();
1793 1793
     $address_row = '';
1794
-    if ( $address = $billing_details['address'] ) {
1795
-        $address_row .= wpautop( wp_kses_post( $address ) );
1794
+    if ($address = $billing_details['address']) {
1795
+        $address_row .= wpautop(wp_kses_post($address));
1796 1796
     }
1797 1797
 
1798 1798
     $address_fields = array();
1799
-    if ( !empty( $billing_details['city'] ) ) {
1799
+    if (!empty($billing_details['city'])) {
1800 1800
         $address_fields[] = $billing_details['city'];
1801 1801
     }
1802 1802
 
1803
-    $billing_country = !empty( $billing_details['country'] ) ? $billing_details['country'] : '';
1804
-    if ( !empty( $billing_details['state'] ) ) {
1805
-        $address_fields[] = wpinv_state_name( $billing_details['state'], $billing_country );
1803
+    $billing_country = !empty($billing_details['country']) ? $billing_details['country'] : '';
1804
+    if (!empty($billing_details['state'])) {
1805
+        $address_fields[] = wpinv_state_name($billing_details['state'], $billing_country);
1806 1806
     }
1807 1807
 
1808
-    if ( !empty( $billing_country ) ) {
1809
-        $address_fields[] = wpinv_country_name( $billing_country );
1808
+    if (!empty($billing_country)) {
1809
+        $address_fields[] = wpinv_country_name($billing_country);
1810 1810
     }
1811 1811
 
1812
-    if ( !empty( $address_fields ) ) {
1813
-        $address_fields = implode( ", ", $address_fields );
1812
+    if (!empty($address_fields)) {
1813
+        $address_fields = implode(", ", $address_fields);
1814 1814
 
1815
-        if ( !empty( $billing_details['zip'] ) ) {
1815
+        if (!empty($billing_details['zip'])) {
1816 1816
             $address_fields .= ' ' . $billing_details['zip'];
1817 1817
         }
1818 1818
 
1819
-        $address_row .= wpautop( wp_kses_post( $address_fields ) );
1819
+        $address_row .= wpautop(wp_kses_post($address_fields));
1820 1820
     }
1821 1821
     ob_start();
1822 1822
     ?>
1823 1823
     <table class="table table-bordered table-sm wpi-billing-details">
1824 1824
         <tbody>
1825 1825
             <tr class="wpi-receipt-name">
1826
-                <th class="text-left"><?php _e( 'Name', 'invoicing' ); ?></th>
1827
-                <td><?php echo esc_html( trim( $billing_details['first_name'] . ' ' . $billing_details['last_name'] ) ) ;?></td>
1826
+                <th class="text-left"><?php _e('Name', 'invoicing'); ?></th>
1827
+                <td><?php echo esc_html(trim($billing_details['first_name'] . ' ' . $billing_details['last_name'])); ?></td>
1828 1828
             </tr>
1829 1829
             <tr class="wpi-receipt-email">
1830
-                <th class="text-left"><?php _e( 'Email', 'invoicing' ); ?></th>
1831
-                <td><?php echo $billing_details['email'] ;?></td>
1830
+                <th class="text-left"><?php _e('Email', 'invoicing'); ?></th>
1831
+                <td><?php echo $billing_details['email']; ?></td>
1832 1832
             </tr>
1833
-            <?php if ( $billing_details['company'] ) { ?>
1833
+            <?php if ($billing_details['company']) { ?>
1834 1834
             <tr class="wpi-receipt-company">
1835
-                <th class="text-left"><?php _e( 'Company', 'invoicing' ); ?></th>
1836
-                <td><?php echo esc_html( $billing_details['company'] ) ;?></td>
1835
+                <th class="text-left"><?php _e('Company', 'invoicing'); ?></th>
1836
+                <td><?php echo esc_html($billing_details['company']); ?></td>
1837 1837
             </tr>
1838 1838
             <?php } ?>
1839 1839
             <tr class="wpi-receipt-address">
1840
-                <th class="text-left"><?php _e( 'Address', 'invoicing' ); ?></th>
1841
-                <td><?php echo $address_row ;?></td>
1840
+                <th class="text-left"><?php _e('Address', 'invoicing'); ?></th>
1841
+                <td><?php echo $address_row; ?></td>
1842 1842
             </tr>
1843
-            <?php if ( $billing_details['phone'] ) { ?>
1843
+            <?php if ($billing_details['phone']) { ?>
1844 1844
             <tr class="wpi-receipt-phone">
1845
-                <th class="text-left"><?php _e( 'Phone', 'invoicing' ); ?></th>
1846
-                <td><?php echo esc_html( $billing_details['phone'] ) ;?></td>
1845
+                <th class="text-left"><?php _e('Phone', 'invoicing'); ?></th>
1846
+                <td><?php echo esc_html($billing_details['phone']); ?></td>
1847 1847
             </tr>
1848 1848
             <?php } ?>
1849 1849
         </tbody>
@@ -1851,76 +1851,76 @@  discard block
 block discarded – undo
1851 1851
     <?php
1852 1852
     $output = ob_get_clean();
1853 1853
     
1854
-    $output = apply_filters( 'wpinv_receipt_billing_address', $output, $invoice_id );
1854
+    $output = apply_filters('wpinv_receipt_billing_address', $output, $invoice_id);
1855 1855
 
1856 1856
     echo $output;
1857 1857
 }
1858 1858
 
1859
-function wpinv_filter_success_page_content( $content ) {
1860
-    if ( isset( $_GET['payment-confirm'] ) && wpinv_is_success_page() ) {
1861
-        if ( has_filter( 'wpinv_payment_confirm_' . sanitize_text_field( $_GET['payment-confirm'] ) ) ) {
1862
-            $content = apply_filters( 'wpinv_payment_confirm_' . sanitize_text_field( $_GET['payment-confirm'] ), $content );
1859
+function wpinv_filter_success_page_content($content) {
1860
+    if (isset($_GET['payment-confirm']) && wpinv_is_success_page()) {
1861
+        if (has_filter('wpinv_payment_confirm_' . sanitize_text_field($_GET['payment-confirm']))) {
1862
+            $content = apply_filters('wpinv_payment_confirm_' . sanitize_text_field($_GET['payment-confirm']), $content);
1863 1863
         }
1864 1864
     }
1865 1865
 
1866 1866
     return $content;
1867 1867
 }
1868
-add_filter( 'the_content', 'wpinv_filter_success_page_content', 99999 );
1868
+add_filter('the_content', 'wpinv_filter_success_page_content', 99999);
1869 1869
 
1870
-function wpinv_receipt_actions( $invoice ) {
1871
-    if ( !empty( $invoice ) ) {
1870
+function wpinv_receipt_actions($invoice) {
1871
+    if (!empty($invoice)) {
1872 1872
         $actions = array();
1873 1873
 
1874
-        if ( wpinv_user_can_view_invoice( $invoice->ID ) ) {
1875
-            $actions['print']   = array(
1876
-                'url'  => $invoice->get_view_url( true ),
1877
-                'name' => __( 'Print Invoice', 'invoicing' ),
1874
+        if (wpinv_user_can_view_invoice($invoice->ID)) {
1875
+            $actions['print'] = array(
1876
+                'url'  => $invoice->get_view_url(true),
1877
+                'name' => __('Print Invoice', 'invoicing'),
1878 1878
                 'class' => 'btn-primary',
1879 1879
             );
1880 1880
         }
1881 1881
 
1882
-        if ( is_user_logged_in() ) {
1882
+        if (is_user_logged_in()) {
1883 1883
             $actions['history'] = array(
1884 1884
                 'url'  => wpinv_get_history_page_uri(),
1885
-                'name' => __( 'Invoice History', 'invoicing' ),
1885
+                'name' => __('Invoice History', 'invoicing'),
1886 1886
                 'class' => 'btn-warning',
1887 1887
             );
1888 1888
         }
1889 1889
 
1890
-        $actions = apply_filters( 'wpinv_invoice_receipt_actions', $actions, $invoice );
1890
+        $actions = apply_filters('wpinv_invoice_receipt_actions', $actions, $invoice);
1891 1891
 
1892
-        if ( !empty( $actions ) ) {
1892
+        if (!empty($actions)) {
1893 1893
         ?>
1894 1894
         <div class="wpinv-receipt-actions text-right">
1895
-            <?php foreach ( $actions as $key => $action ) { $class = !empty($action['class']) ? sanitize_html_class( $action['class'] ) : ''; ?>
1896
-            <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>
1895
+            <?php foreach ($actions as $key => $action) { $class = !empty($action['class']) ? sanitize_html_class($action['class']) : ''; ?>
1896
+            <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>
1897 1897
             <?php } ?>
1898 1898
         </div>
1899 1899
         <?php
1900 1900
         }
1901 1901
     }
1902 1902
 }
1903
-add_action( 'wpinv_receipt_start', 'wpinv_receipt_actions', -10, 1 );
1903
+add_action('wpinv_receipt_start', 'wpinv_receipt_actions', -10, 1);
1904 1904
 
1905
-function wpinv_invoice_link( $invoice_id ) {
1906
-    $invoice = wpinv_get_invoice( $invoice_id );
1905
+function wpinv_invoice_link($invoice_id) {
1906
+    $invoice = wpinv_get_invoice($invoice_id);
1907 1907
 
1908
-    if ( empty( $invoice ) ) {
1908
+    if (empty($invoice)) {
1909 1909
         return NULL;
1910 1910
     }
1911 1911
 
1912
-    $invoice_link = '<a href="' . esc_url( $invoice->get_view_url() ) . '">' . $invoice->get_number() . '</a>';
1912
+    $invoice_link = '<a href="' . esc_url($invoice->get_view_url()) . '">' . $invoice->get_number() . '</a>';
1913 1913
 
1914
-    return apply_filters( 'wpinv_get_invoice_link', $invoice_link, $invoice );
1914
+    return apply_filters('wpinv_get_invoice_link', $invoice_link, $invoice);
1915 1915
 }
1916 1916
 
1917
-function wpinv_invoice_subscription_details( $invoice ) {
1918
-    if ( !empty( $invoice ) && $invoice->is_recurring() && !wpinv_is_subscription_payment( $invoice ) ) {
1917
+function wpinv_invoice_subscription_details($invoice) {
1918
+    if (!empty($invoice) && $invoice->is_recurring() && !wpinv_is_subscription_payment($invoice)) {
1919 1919
         $subs_db = new WPInv_Subscriptions_DB;
1920 1920
         $subs = $subs_db->get_subscriptions(array('parent_payment_id' => $invoice->ID, 'number' => 1));
1921 1921
         $sub = reset($subs);
1922 1922
 
1923
-        if ( empty( $sub ) ) {
1923
+        if (empty($sub)) {
1924 1924
             return;
1925 1925
         }
1926 1926
 
@@ -1931,15 +1931,15 @@  discard block
 block discarded – undo
1931 1931
         $payments = $sub->get_child_payments();
1932 1932
         ?>
1933 1933
         <div class="wpinv-subscriptions-details">
1934
-            <h3 class="wpinv-subscriptions-t"><?php echo apply_filters( 'wpinv_subscription_details_title', __( 'Subscription Details', 'invoicing' ) ); ?></h3>
1934
+            <h3 class="wpinv-subscriptions-t"><?php echo apply_filters('wpinv_subscription_details_title', __('Subscription Details', 'invoicing')); ?></h3>
1935 1935
             <table class="table">
1936 1936
                 <thead>
1937 1937
                     <tr>
1938
-                        <th><?php _e( 'Billing Cycle', 'invoicing' ) ;?></th>
1939
-                        <th><?php _e( 'Start Date', 'invoicing' ) ;?></th>
1940
-                        <th><?php _e( 'Expiration Date', 'invoicing' ) ;?></th>
1941
-                        <th class="text-center"><?php _e( 'Times Billed', 'invoicing' ) ;?></th>
1942
-                        <th class="text-center"><?php _e( 'Status', 'invoicing' ) ;?></th>
1938
+                        <th><?php _e('Billing Cycle', 'invoicing'); ?></th>
1939
+                        <th><?php _e('Start Date', 'invoicing'); ?></th>
1940
+                        <th><?php _e('Expiration Date', 'invoicing'); ?></th>
1941
+                        <th class="text-center"><?php _e('Times Billed', 'invoicing'); ?></th>
1942
+                        <th class="text-center"><?php _e('Status', 'invoicing'); ?></th>
1943 1943
                     </tr>
1944 1944
                 </thead>
1945 1945
                 <tbody>
@@ -1954,29 +1954,29 @@  discard block
 block discarded – undo
1954 1954
                 </tbody>
1955 1955
             </table>
1956 1956
         </div>
1957
-        <?php if ( !empty( $payments ) ) { ?>
1957
+        <?php if (!empty($payments)) { ?>
1958 1958
         <div class="wpinv-renewal-payments">
1959
-            <h3 class="wpinv-renewals-t"><?php echo apply_filters( 'wpinv_renewal_payments_title', __( 'Renewal Payments', 'invoicing' ) ); ?></h3>
1959
+            <h3 class="wpinv-renewals-t"><?php echo apply_filters('wpinv_renewal_payments_title', __('Renewal Payments', 'invoicing')); ?></h3>
1960 1960
             <table class="table">
1961 1961
                 <thead>
1962 1962
                     <tr>
1963 1963
                         <th>#</th>
1964
-                        <th><?php _e( 'Invoice', 'invoicing' ) ;?></th>
1965
-                        <th><?php _e( 'Date', 'invoicing' ) ;?></th>
1966
-                        <th class="text-right"><?php _e( 'Amount', 'invoicing' ) ;?></th>
1964
+                        <th><?php _e('Invoice', 'invoicing'); ?></th>
1965
+                        <th><?php _e('Date', 'invoicing'); ?></th>
1966
+                        <th class="text-right"><?php _e('Amount', 'invoicing'); ?></th>
1967 1967
                     </tr>
1968 1968
                 </thead>
1969 1969
                 <tbody>
1970 1970
                     <?php
1971 1971
                         $i = 1;
1972
-                        foreach ( $payments as $payment ) {
1972
+                        foreach ($payments as $payment) {
1973 1973
                             $invoice_id = $payment->ID;
1974 1974
                     ?>
1975 1975
                     <tr>
1976
-                        <th scope="row"><?php echo $i;?></th>
1977
-                        <td><?php echo wpinv_invoice_link( $invoice_id ) ;?></td>
1978
-                        <td><?php echo wpinv_get_invoice_date( $invoice_id ); ?></td>
1979
-                        <td class="text-right"><?php echo wpinv_payment_total( $invoice_id, true ); ?></td>
1976
+                        <th scope="row"><?php echo $i; ?></th>
1977
+                        <td><?php echo wpinv_invoice_link($invoice_id); ?></td>
1978
+                        <td><?php echo wpinv_get_invoice_date($invoice_id); ?></td>
1979
+                        <td class="text-right"><?php echo wpinv_payment_total($invoice_id, true); ?></td>
1980 1980
                     </tr>
1981 1981
                     <?php $i++; } ?>
1982 1982
                     <tr><td colspan="4" style="padding:0"></td></tr>
@@ -1988,52 +1988,52 @@  discard block
 block discarded – undo
1988 1988
     }
1989 1989
 }
1990 1990
 
1991
-function wpinv_cart_total_label( $label, $invoice ) {
1992
-    if ( empty( $invoice ) ) {
1991
+function wpinv_cart_total_label($label, $invoice) {
1992
+    if (empty($invoice)) {
1993 1993
         return $label;
1994 1994
     }
1995 1995
 
1996 1996
     $prefix_label = '';
1997
-    if ( $invoice->is_parent() && $item_id = $invoice->get_recurring() ) {
1998
-        $prefix_label   = '<span class="label label-primary label-recurring">' . __( 'Recurring Payment', 'invoicing' ) . '</span> ' . wpinv_subscription_payment_desc( $invoice );
1999
-    } else if ( $invoice->is_renewal() ) {
2000
-        $prefix_label   = '<span class="label label-primary label-renewal">' . __( 'Renewal Payment', 'invoicing' ) . '</span> ';        
1997
+    if ($invoice->is_parent() && $item_id = $invoice->get_recurring()) {
1998
+        $prefix_label   = '<span class="label label-primary label-recurring">' . __('Recurring Payment', 'invoicing') . '</span> ' . wpinv_subscription_payment_desc($invoice);
1999
+    } else if ($invoice->is_renewal()) {
2000
+        $prefix_label   = '<span class="label label-primary label-renewal">' . __('Renewal Payment', 'invoicing') . '</span> ';        
2001 2001
     }
2002 2002
 
2003
-    if ( $prefix_label != '' ) {
2004
-        $label  = '<span class="wpinv-cart-sub-desc">' . $prefix_label . '</span> ' . $label;
2003
+    if ($prefix_label != '') {
2004
+        $label = '<span class="wpinv-cart-sub-desc">' . $prefix_label . '</span> ' . $label;
2005 2005
     }
2006 2006
 
2007 2007
     return $label;
2008 2008
 }
2009
-add_filter( 'wpinv_cart_total_label', 'wpinv_cart_total_label', 10, 2 );
2010
-add_filter( 'wpinv_email_cart_total_label', 'wpinv_cart_total_label', 10, 2 );
2011
-add_filter( 'wpinv_print_cart_total_label', 'wpinv_cart_total_label', 10, 2 );
2009
+add_filter('wpinv_cart_total_label', 'wpinv_cart_total_label', 10, 2);
2010
+add_filter('wpinv_email_cart_total_label', 'wpinv_cart_total_label', 10, 2);
2011
+add_filter('wpinv_print_cart_total_label', 'wpinv_cart_total_label', 10, 2);
2012 2012
 
2013
-add_action( 'wpinv_invoice_print_middle', 'wpinv_invoice_subscription_details', 10, 1 );
2013
+add_action('wpinv_invoice_print_middle', 'wpinv_invoice_subscription_details', 10, 1);
2014 2014
 
2015
-function wpinv_invoice_print_description( $invoice ) {
2016
-    if ( empty( $invoice ) ) {
2015
+function wpinv_invoice_print_description($invoice) {
2016
+    if (empty($invoice)) {
2017 2017
         return NULL;
2018 2018
     }
2019
-    if ( $description = wpinv_get_invoice_description( $invoice->ID ) ) {
2019
+    if ($description = wpinv_get_invoice_description($invoice->ID)) {
2020 2020
         ?>
2021 2021
         <div class="row wpinv-lower">
2022 2022
             <div class="col-sm-12 wpinv-description">
2023
-                <?php echo wpautop( $description ); ?>
2023
+                <?php echo wpautop($description); ?>
2024 2024
             </div>
2025 2025
         </div>
2026 2026
         <?php
2027 2027
     }
2028 2028
 }
2029
-add_action( 'wpinv_invoice_print_middle', 'wpinv_invoice_print_description', 10.1, 1 );
2029
+add_action('wpinv_invoice_print_middle', 'wpinv_invoice_print_description', 10.1, 1);
2030 2030
 
2031
-function wpinv_invoice_print_payment_info( $invoice ) {
2032
-    if ( empty( $invoice ) ) {
2031
+function wpinv_invoice_print_payment_info($invoice) {
2032
+    if (empty($invoice)) {
2033 2033
         return NULL;
2034 2034
     }
2035 2035
 
2036
-    if ( $payments_info = wpinv_display_payments_info( $invoice->ID, false ) ) {
2036
+    if ($payments_info = wpinv_display_payments_info($invoice->ID, false)) {
2037 2037
         ?>
2038 2038
         <div class="row wpinv-payments">
2039 2039
             <div class="col-sm-12">
@@ -2045,43 +2045,43 @@  discard block
 block discarded – undo
2045 2045
 }
2046 2046
 // add_action( 'wpinv_invoice_print_after_line_items', 'wpinv_invoice_print_payment_info', 10, 1 );
2047 2047
 
2048
-function wpinv_get_invoice_note_line_item( $note, $echo = true ) {
2049
-    if ( empty( $note ) ) {
2048
+function wpinv_get_invoice_note_line_item($note, $echo = true) {
2049
+    if (empty($note)) {
2050 2050
         return NULL;
2051 2051
     }
2052 2052
 
2053
-    if ( is_int( $note ) ) {
2054
-        $note = get_comment( $note );
2053
+    if (is_int($note)) {
2054
+        $note = get_comment($note);
2055 2055
     }
2056 2056
 
2057
-    if ( !( is_object( $note ) && is_a( $note, 'WP_Comment' ) ) ) {
2057
+    if (!(is_object($note) && is_a($note, 'WP_Comment'))) {
2058 2058
         return NULL;
2059 2059
     }
2060 2060
 
2061
-    $note_classes   = array( 'note' );
2062
-    $note_classes[] = get_comment_meta( $note->comment_ID, '_wpi_customer_note', true ) ? 'customer-note' : '';
2061
+    $note_classes   = array('note');
2062
+    $note_classes[] = get_comment_meta($note->comment_ID, '_wpi_customer_note', true) ? 'customer-note' : '';
2063 2063
     $note_classes[] = $note->comment_author === 'System' ? 'system-note' : '';
2064
-    $note_classes   = apply_filters( 'wpinv_invoice_note_class', array_filter( $note_classes ), $note );
2065
-    $note_classes   = !empty( $note_classes ) ? implode( ' ', $note_classes ) : '';
2064
+    $note_classes   = apply_filters('wpinv_invoice_note_class', array_filter($note_classes), $note);
2065
+    $note_classes   = !empty($note_classes) ? implode(' ', $note_classes) : '';
2066 2066
 
2067 2067
     ob_start();
2068 2068
     ?>
2069
-    <li rel="<?php echo absint( $note->comment_ID ) ; ?>" class="<?php echo esc_attr( $note_classes ); ?>">
2069
+    <li rel="<?php echo absint($note->comment_ID); ?>" class="<?php echo esc_attr($note_classes); ?>">
2070 2070
         <div class="note_content">
2071
-            <?php echo wpautop( wptexturize( wp_kses_post( $note->comment_content ) ) ); ?>
2071
+            <?php echo wpautop(wptexturize(wp_kses_post($note->comment_content))); ?>
2072 2072
         </div>
2073 2073
         <p class="meta">
2074
-            <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;
2075
-            <?php if ( $note->comment_author !== 'System' || current_user_can( 'manage_options' ) ) { ?>
2076
-                <a href="#" class="delete_note"><?php _e( 'Delete note', 'invoicing' ); ?></a>
2074
+            <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;
2075
+            <?php if ($note->comment_author !== 'System' || current_user_can('manage_options')) { ?>
2076
+                <a href="#" class="delete_note"><?php _e('Delete note', 'invoicing'); ?></a>
2077 2077
             <?php } ?>
2078 2078
         </p>
2079 2079
     </li>
2080 2080
     <?php
2081 2081
     $note_content = ob_get_clean();
2082
-    $note_content = apply_filters( 'wpinv_get_invoice_note_line_item', $note_content, $note, $echo );
2082
+    $note_content = apply_filters('wpinv_get_invoice_note_line_item', $note_content, $note, $echo);
2083 2083
 
2084
-    if ( $echo ) {
2084
+    if ($echo) {
2085 2085
         echo $note_content;
2086 2086
     } else {
2087 2087
         return $note_content;
@@ -2091,33 +2091,33 @@  discard block
 block discarded – undo
2091 2091
 function wpinv_invalid_invoice_content() {
2092 2092
     global $post;
2093 2093
 
2094
-    $invoice = wpinv_get_invoice( $post->ID );
2094
+    $invoice = wpinv_get_invoice($post->ID);
2095 2095
 
2096
-    $error = __( 'This invoice is only viewable by clicking on the invoice link that sent to you via email.', 'invoicing' );
2097
-    if ( !empty( $invoice->ID ) && $invoice->has_status( array_keys( wpinv_get_invoice_statuses() ) ) ) {
2098
-        if ( is_user_logged_in() ) {
2099
-            if ( wpinv_require_login_to_checkout() ) {
2100
-                if ( isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) {
2101
-                    $error = __( 'You are not allowed to view this invoice.', 'invoicing' );
2096
+    $error = __('This invoice is only viewable by clicking on the invoice link that sent to you via email.', 'invoicing');
2097
+    if (!empty($invoice->ID) && $invoice->has_status(array_keys(wpinv_get_invoice_statuses()))) {
2098
+        if (is_user_logged_in()) {
2099
+            if (wpinv_require_login_to_checkout()) {
2100
+                if (isset($_GET['invoice_key']) && $_GET['invoice_key'] === $invoice->get_key()) {
2101
+                    $error = __('You are not allowed to view this invoice.', 'invoicing');
2102 2102
                 }
2103 2103
             }
2104 2104
         } else {
2105
-            if ( wpinv_require_login_to_checkout() ) {
2106
-                if ( isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) {
2107
-                    $error = __( 'You must be logged in to view this invoice.', 'invoicing' );
2105
+            if (wpinv_require_login_to_checkout()) {
2106
+                if (isset($_GET['invoice_key']) && $_GET['invoice_key'] === $invoice->get_key()) {
2107
+                    $error = __('You must be logged in to view this invoice.', 'invoicing');
2108 2108
                 }
2109 2109
             }
2110 2110
         }
2111 2111
     } else {
2112
-        $error = __( 'This invoice is deleted or does not exist.', 'invoicing' );
2112
+        $error = __('This invoice is deleted or does not exist.', 'invoicing');
2113 2113
     }
2114 2114
     ?>
2115 2115
     <div class="row wpinv-row-invalid">
2116 2116
         <div class="col-md-6 col-md-offset-3 wpinv-message error">
2117
-            <h3><?php _e( 'Access Denied', 'invoicing' ); ?></h3>
2117
+            <h3><?php _e('Access Denied', 'invoicing'); ?></h3>
2118 2118
             <p class="wpinv-msg-text"><?php echo $error; ?></p>
2119 2119
         </div>
2120 2120
     </div>
2121 2121
     <?php
2122 2122
 }
2123
-add_action( 'wpinv_invalid_invoice_content', 'wpinv_invalid_invoice_content' );
2124 2123
\ No newline at end of file
2124
+add_action('wpinv_invalid_invoice_content', 'wpinv_invalid_invoice_content');
2125 2125
\ No newline at end of file
Please login to merge, or discard this patch.
includes/wpinv-subscription.php 1 patch
Spacing   +167 added lines, -167 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 // Exit if accessed directly
4
-if ( ! defined( 'ABSPATH' ) ) {
4
+if (!defined('ABSPATH')) {
5 5
 	exit;
6 6
 }
7 7
 
@@ -38,15 +38,15 @@  discard block
 block discarded – undo
38 38
 	 * @since  1.0.0
39 39
 	 * @return void
40 40
 	 */
41
-	function __construct( $_id_or_object = 0, $_by_profile_id = false ) {
41
+	function __construct($_id_or_object = 0, $_by_profile_id = false) {
42 42
 
43 43
 		$this->subs_db = new WPInv_Subscriptions_DB;
44 44
 
45
-		if( $_by_profile_id ) {
45
+		if ($_by_profile_id) {
46 46
 
47
-			$_sub = $this->subs_db->get_by( 'profile_id', $_id_or_object );
47
+			$_sub = $this->subs_db->get_by('profile_id', $_id_or_object);
48 48
 
49
-			if( empty( $_sub ) ) {
49
+			if (empty($_sub)) {
50 50
 				return false;
51 51
 			}
52 52
 
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
 
55 55
 		}
56 56
 
57
-		return $this->setup_subscription( $_id_or_object );
57
+		return $this->setup_subscription($_id_or_object);
58 58
 	}
59 59
 
60 60
 	/**
@@ -63,34 +63,34 @@  discard block
 block discarded – undo
63 63
 	 * @since  1.0.0
64 64
 	 * @return void
65 65
 	 */
66
-	private function setup_subscription( $id_or_object = 0 ) {
66
+	private function setup_subscription($id_or_object = 0) {
67 67
 
68
-		if( empty( $id_or_object ) ) {
68
+		if (empty($id_or_object)) {
69 69
 			return false;
70 70
 		}
71 71
 
72
-		if( is_numeric( $id_or_object ) ) {
72
+		if (is_numeric($id_or_object)) {
73 73
 
74
-			$sub = $this->subs_db->get( $id_or_object );
74
+			$sub = $this->subs_db->get($id_or_object);
75 75
 
76
-		} elseif( is_object( $id_or_object ) ) {
76
+		} elseif (is_object($id_or_object)) {
77 77
 
78 78
 			$sub = $id_or_object;
79 79
 
80 80
 		}
81 81
 
82
-		if( empty( $sub ) ) {
82
+		if (empty($sub)) {
83 83
 			return false;
84 84
 		}
85 85
 
86
-		foreach( $sub as $key => $value ) {
86
+		foreach ($sub as $key => $value) {
87 87
 			$this->$key = $value;
88 88
 		}
89 89
 
90
-		$this->customer = get_userdata( $this->customer_id );
91
-		$this->gateway  = wpinv_get_payment_gateway( $this->parent_payment_id );
90
+		$this->customer = get_userdata($this->customer_id);
91
+		$this->gateway  = wpinv_get_payment_gateway($this->parent_payment_id);
92 92
 
93
-		do_action( 'wpinv_recurring_setup_subscription', $this );
93
+		do_action('wpinv_recurring_setup_subscription', $this);
94 94
 
95 95
 		return $this;
96 96
 	}
@@ -100,15 +100,15 @@  discard block
 block discarded – undo
100 100
 	 *
101 101
 	 * @since 1.0.0
102 102
 	 */
103
-	public function __get( $key ) {
103
+	public function __get($key) {
104 104
 
105
-		if( method_exists( $this, 'get_' . $key ) ) {
105
+		if (method_exists($this, 'get_' . $key)) {
106 106
 
107
-			return call_user_func( array( $this, 'get_' . $key ) );
107
+			return call_user_func(array($this, 'get_' . $key));
108 108
 
109 109
 		} else {
110 110
 
111
-			return new WP_Error( 'wpinv-subscription-invalid-property', sprintf( __( 'Can\'t get property %s', 'invoicing' ), $key ) );
111
+			return new WP_Error('wpinv-subscription-invalid-property', sprintf(__('Can\'t get property %s', 'invoicing'), $key));
112 112
 
113 113
 		}
114 114
 
@@ -121,9 +121,9 @@  discard block
 block discarded – undo
121 121
 	 * @param  array  $data Array of attributes for a subscription
122 122
 	 * @return mixed  false if data isn't passed and class not instantiated for creation
123 123
 	 */
124
-	public function create( $data = array() ) {
124
+	public function create($data = array()) {
125 125
 
126
-		if ( $this->id != 0 ) {
126
+		if ($this->id != 0) {
127 127
 			return false;
128 128
 		}
129 129
 
@@ -142,11 +142,11 @@  discard block
 block discarded – undo
142 142
 			'profile_id'        => '',
143 143
 		);
144 144
 
145
-		$args = wp_parse_args( $data, $defaults );
145
+		$args = wp_parse_args($data, $defaults);
146 146
 
147
-		if( $args['expiration'] && strtotime( 'NOW', current_time( 'timestamp' ) ) > strtotime( $args['expiration'], current_time( 'timestamp' ) ) ) {
147
+		if ($args['expiration'] && strtotime('NOW', current_time('timestamp')) > strtotime($args['expiration'], current_time('timestamp'))) {
148 148
 
149
-			if( 'active' == $args['status'] || 'trialling' == $args['status'] ) {
149
+			if ('active' == $args['status'] || 'trialling' == $args['status']) {
150 150
 
151 151
 				// Force an active subscription to expired if expiration date is in the past
152 152
 				$args['status'] = 'expired';
@@ -154,13 +154,13 @@  discard block
 block discarded – undo
154 154
 			}
155 155
 		}
156 156
 
157
-		do_action( 'wpinv_subscription_pre_create', $args );
157
+		do_action('wpinv_subscription_pre_create', $args);
158 158
 
159
-		$id = $this->subs_db->insert( $args, 'subscription' );
159
+		$id = $this->subs_db->insert($args, 'subscription');
160 160
 
161
-		do_action( 'wpinv_subscription_post_create', $id, $args );
161
+		do_action('wpinv_subscription_post_create', $id, $args);
162 162
 
163
-		return $this->setup_subscription( $id );
163
+		return $this->setup_subscription($id);
164 164
 
165 165
 	}
166 166
 
@@ -171,11 +171,11 @@  discard block
 block discarded – undo
171 171
 	 * @param  array $args Array of fields to update
172 172
 	 * @return bool
173 173
 	 */
174
-	public function update( $args = array() ) {
174
+	public function update($args = array()) {
175 175
 
176
-		$ret = $this->subs_db->update( $this->id, $args );
176
+		$ret = $this->subs_db->update($this->id, $args);
177 177
 
178
-		do_action( 'wpinv_recurring_update_subscription', $this->id, $args, $this );
178
+		do_action('wpinv_recurring_update_subscription', $this->id, $args, $this);
179 179
 
180 180
 		return $ret;
181 181
 
@@ -188,7 +188,7 @@  discard block
 block discarded – undo
188 188
 	 * @return bool
189 189
 	 */
190 190
 	public function delete() {
191
-		return $this->subs_db->delete( $this->id );
191
+		return $this->subs_db->delete($this->id);
192 192
 	}
193 193
 
194 194
     /**
@@ -208,14 +208,14 @@  discard block
 block discarded – undo
208 208
      * @return array
209 209
      */
210 210
     public function get_child_payments() {
211
-        $payments = get_posts( array(
212
-            'post_parent'    => (int) $this->parent_payment_id,
211
+        $payments = get_posts(array(
212
+            'post_parent'    => (int)$this->parent_payment_id,
213 213
             'posts_per_page' => '999',
214
-            'post_status'    => array( 'publish', 'wpi-processing', 'wpi-renewal' ),
214
+            'post_status'    => array('publish', 'wpi-processing', 'wpi-renewal'),
215 215
             'orderby'           => 'ID',
216 216
             'order'             => 'DESC',
217 217
             'post_type'      => 'wpi_invoice'
218
-        ) );
218
+        ));
219 219
 
220 220
         return $payments;
221 221
     }
@@ -228,9 +228,9 @@  discard block
 block discarded – undo
228 228
      */
229 229
     public function get_total_payments() {
230 230
         $child_payments = $this->get_child_payments();
231
-        $total_payments = !empty( $child_payments ) ? count( $child_payments ) : 0;
231
+        $total_payments = !empty($child_payments) ? count($child_payments) : 0;
232 232
 
233
-        if ( 'pending' != $this->status ) {
233
+        if ('pending' != $this->status) {
234 234
                 $total_payments++;
235 235
         }
236 236
 
@@ -246,7 +246,7 @@  discard block
 block discarded – undo
246 246
     public function get_times_billed() {
247 247
         $times_billed = (int)$this->get_total_payments();
248 248
 
249
-        if ( ! empty( $this->trial_period ) && $times_billed > 0 ) {
249
+        if (!empty($this->trial_period) && $times_billed > 0) {
250 250
             $times_billed--;
251 251
         }
252 252
 
@@ -260,51 +260,51 @@  discard block
 block discarded – undo
260 260
      * @param  array $args Array of values for the payment, including amount and transaction ID
261 261
      * @return bool
262 262
      */
263
-    public function add_payment( $args = array() ) {
264
-        if ( ! $this->parent_payment_id ) {
263
+    public function add_payment($args = array()) {
264
+        if (!$this->parent_payment_id) {
265 265
             return false;
266 266
         }
267 267
 
268
-        $args = wp_parse_args( $args, array(
268
+        $args = wp_parse_args($args, array(
269 269
             'amount'         => '',
270 270
             'transaction_id' => '',
271 271
             'gateway'        => ''
272
-        ) );
272
+        ));
273 273
         
274
-        if ( empty( $args['transaction_id'] ) || $this->payment_exists( $args['transaction_id'] ) ) {
274
+        if (empty($args['transaction_id']) || $this->payment_exists($args['transaction_id'])) {
275 275
             return false;
276 276
         }
277 277
         
278
-        $parent_invoice = wpinv_get_invoice( $this->parent_payment_id );
279
-        if ( empty( $parent_invoice->ID ) ) {
278
+        $parent_invoice = wpinv_get_invoice($this->parent_payment_id);
279
+        if (empty($parent_invoice->ID)) {
280 280
             return false;
281 281
         }
282 282
 
283 283
         $invoice = new WPInv_Invoice();
284
-        $invoice->set( 'post_type', 'wpi_invoice' );
285
-        $invoice->set( 'parent_invoice', $this->parent_payment_id );
286
-        $invoice->set( 'currency', $parent_invoice->get_currency() );
287
-        $invoice->set( 'transaction_id', $args['transaction_id'] );
288
-        $invoice->set( 'key', $parent_invoice->generate_key() );
289
-        $invoice->set( 'ip', $parent_invoice->ip );
290
-        $invoice->set( 'user_id', $parent_invoice->get_user_id() );
291
-        $invoice->set( 'first_name', $parent_invoice->get_first_name() );
292
-        $invoice->set( 'last_name', $parent_invoice->get_last_name() );
293
-        $invoice->set( 'phone', $parent_invoice->phone );
294
-        $invoice->set( 'address', $parent_invoice->address );
295
-        $invoice->set( 'city', $parent_invoice->city );
296
-        $invoice->set( 'country', $parent_invoice->country );
297
-        $invoice->set( 'state', $parent_invoice->state );
298
-        $invoice->set( 'zip', $parent_invoice->zip );
299
-        $invoice->set( 'company', $parent_invoice->company );
300
-        $invoice->set( 'vat_number', $parent_invoice->vat_number );
301
-        $invoice->set( 'vat_rate', $parent_invoice->vat_rate );
302
-        $invoice->set( 'adddress_confirmed', $parent_invoice->adddress_confirmed );
303
-
304
-        if ( empty( $args['gateway'] ) ) {
305
-            $invoice->set( 'gateway', $parent_invoice->get_gateway() );
284
+        $invoice->set('post_type', 'wpi_invoice');
285
+        $invoice->set('parent_invoice', $this->parent_payment_id);
286
+        $invoice->set('currency', $parent_invoice->get_currency());
287
+        $invoice->set('transaction_id', $args['transaction_id']);
288
+        $invoice->set('key', $parent_invoice->generate_key());
289
+        $invoice->set('ip', $parent_invoice->ip);
290
+        $invoice->set('user_id', $parent_invoice->get_user_id());
291
+        $invoice->set('first_name', $parent_invoice->get_first_name());
292
+        $invoice->set('last_name', $parent_invoice->get_last_name());
293
+        $invoice->set('phone', $parent_invoice->phone);
294
+        $invoice->set('address', $parent_invoice->address);
295
+        $invoice->set('city', $parent_invoice->city);
296
+        $invoice->set('country', $parent_invoice->country);
297
+        $invoice->set('state', $parent_invoice->state);
298
+        $invoice->set('zip', $parent_invoice->zip);
299
+        $invoice->set('company', $parent_invoice->company);
300
+        $invoice->set('vat_number', $parent_invoice->vat_number);
301
+        $invoice->set('vat_rate', $parent_invoice->vat_rate);
302
+        $invoice->set('adddress_confirmed', $parent_invoice->adddress_confirmed);
303
+
304
+        if (empty($args['gateway'])) {
305
+            $invoice->set('gateway', $parent_invoice->get_gateway());
306 306
         } else {
307
-            $invoice->set( 'gateway', $args['gateway'] );
307
+            $invoice->set('gateway', $args['gateway']);
308 308
         }
309 309
         
310 310
         $recurring_details = $parent_invoice->get_recurring_details();
@@ -312,11 +312,11 @@  discard block
 block discarded – undo
312 312
         // increase the earnings for each item in the subscription
313 313
         $items = $recurring_details['cart_details'];
314 314
         
315
-        if ( $items ) {        
315
+        if ($items) {        
316 316
             $add_items      = array();
317 317
             $cart_details   = array();
318 318
             
319
-            foreach ( $items as $item ) {
319
+            foreach ($items as $item) {
320 320
                 $add_item             = array();
321 321
                 $add_item['id']       = $item['id'];
322 322
                 $add_item['quantity'] = $item['quantity'];
@@ -326,7 +326,7 @@  discard block
 block discarded – undo
326 326
                 break;
327 327
             }
328 328
             
329
-            $invoice->set( 'items', $add_items );
329
+            $invoice->set('items', $add_items);
330 330
             $invoice->cart_details = $cart_details;
331 331
         }
332 332
         
@@ -336,29 +336,29 @@  discard block
 block discarded – undo
336 336
         $tax                = $recurring_details['tax'];
337 337
         $discount           = $recurring_details['discount'];
338 338
         
339
-        if ( $discount > 0 ) {
340
-            $invoice->set( 'discount_code', $parent_invoice->discount_code );
339
+        if ($discount > 0) {
340
+            $invoice->set('discount_code', $parent_invoice->discount_code);
341 341
         }
342 342
         
343
-        $invoice->subtotal = wpinv_round_amount( $subtotal );
344
-        $invoice->tax      = wpinv_round_amount( $tax );
345
-        $invoice->discount = wpinv_round_amount( $discount );
346
-        $invoice->total    = wpinv_round_amount( $total );
343
+        $invoice->subtotal = wpinv_round_amount($subtotal);
344
+        $invoice->tax      = wpinv_round_amount($tax);
345
+        $invoice->discount = wpinv_round_amount($discount);
346
+        $invoice->total    = wpinv_round_amount($total);
347 347
 
348
-        $invoice  = apply_filters( 'wpinv_subscription_add_payment_save', $invoice, $this, $args );
348
+        $invoice = apply_filters('wpinv_subscription_add_payment_save', $invoice, $this, $args);
349 349
 
350 350
         $invoice->save();
351
-        $invoice->update_meta( '_wpinv_subscription_id', $this->id );
351
+        $invoice->update_meta('_wpinv_subscription_id', $this->id);
352 352
         
353
-        if ( !empty( $invoice->ID ) ) {
354
-            wpinv_update_payment_status( $invoice->ID, 'publish' );
353
+        if (!empty($invoice->ID)) {
354
+            wpinv_update_payment_status($invoice->ID, 'publish');
355 355
             sleep(1);
356
-            wpinv_update_payment_status( $invoice->ID, 'wpi-renewal' );
356
+            wpinv_update_payment_status($invoice->ID, 'wpi-renewal');
357 357
             
358
-            $invoice = wpinv_get_invoice( $invoice->ID );
358
+            $invoice = wpinv_get_invoice($invoice->ID);
359 359
 
360
-            do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $this );
361
-            do_action( 'wpinv_recurring_record_payment', $invoice->ID, $this->parent_payment_id, $args['amount'], $args['transaction_id'] );
360
+            do_action('wpinv_recurring_add_subscription_payment', $invoice, $this);
361
+            do_action('wpinv_recurring_record_payment', $invoice->ID, $this->parent_payment_id, $args['amount'], $args['transaction_id']);
362 362
             
363 363
             return $invoice->ID;
364 364
         }
@@ -374,12 +374,12 @@  discard block
 block discarded – undo
374 374
 	 */
375 375
 	public function get_transaction_id() {
376 376
 
377
-		if( empty( $this->transaction_id ) ) {
377
+		if (empty($this->transaction_id)) {
378 378
 
379
-			$txn_id = wpinv_get_payment_transaction_id( $this->parent_payment_id );
379
+			$txn_id = wpinv_get_payment_transaction_id($this->parent_payment_id);
380 380
 
381
-			if( ! empty( $txn_id ) && (int) $this->parent_payment_id !== (int) $txn_id ) {
382
-				$this->set_transaction_id( $txn_id );
381
+			if (!empty($txn_id) && (int)$this->parent_payment_id !== (int)$txn_id) {
382
+				$this->set_transaction_id($txn_id);
383 383
 			}
384 384
 
385 385
 		}
@@ -394,8 +394,8 @@  discard block
 block discarded – undo
394 394
 	 * @since  1.0.0.4
395 395
 	 * @return bool
396 396
 	 */
397
-	public function set_transaction_id( $txn_id = '' ) {
398
-		$this->update( array( 'transaction_id' => $txn_id ) );
397
+	public function set_transaction_id($txn_id = '') {
398
+		$this->update(array('transaction_id' => $txn_id));
399 399
 		$this->transaction_id = $txn_id;
400 400
 	}
401 401
 
@@ -411,35 +411,35 @@  discard block
 block discarded – undo
411 411
 
412 412
 
413 413
 		// Determine what date to use as the start for the new expiration calculation
414
-		if( $expires > current_time( 'timestamp' ) && $this->is_active() ) {
414
+		if ($expires > current_time('timestamp') && $this->is_active()) {
415 415
 
416
-			$base_date  = $expires;
416
+			$base_date = $expires;
417 417
 
418 418
 		} else {
419 419
 
420
-			$base_date  = current_time( 'timestamp' );
420
+			$base_date = current_time('timestamp');
421 421
 
422 422
 		}
423 423
 
424
-		$last_day = wpinv_cal_days_in_month( CAL_GREGORIAN, date( 'n', $base_date ), date( 'Y', $base_date ) );
424
+		$last_day = wpinv_cal_days_in_month(CAL_GREGORIAN, date('n', $base_date), date('Y', $base_date));
425 425
 
426 426
 
427 427
 		$frequency = isset($this->frequency) ? $this->frequency : 1;
428
-		$expiration = date( 'Y-m-d H:i:s', strtotime( '+' . $frequency . ' ' . $this->period  . ' 23:59:59', $base_date ) );
428
+		$expiration = date('Y-m-d H:i:s', strtotime('+' . $frequency . ' ' . $this->period . ' 23:59:59', $base_date));
429 429
 
430
-		if( date( 'j', $base_date ) == $last_day && 'day' != $this->period ) {
431
-			$expiration = date( 'Y-m-d H:i:s', strtotime( $expiration . ' +2 days' ) );
430
+		if (date('j', $base_date) == $last_day && 'day' != $this->period) {
431
+			$expiration = date('Y-m-d H:i:s', strtotime($expiration . ' +2 days'));
432 432
 		}
433 433
 
434
-		$expiration  = apply_filters( 'wpinv_subscription_renewal_expiration', $expiration, $this->id, $this );
434
+		$expiration  = apply_filters('wpinv_subscription_renewal_expiration', $expiration, $this->id, $this);
435 435
 
436
-		do_action( 'wpinv_subscription_pre_renew', $this->id, $expiration, $this );
436
+		do_action('wpinv_subscription_pre_renew', $this->id, $expiration, $this);
437 437
 
438 438
 		$this->status = 'active';
439 439
 		$times_billed = $this->get_times_billed();
440 440
 
441 441
 		// Complete subscription if applicable
442
-		if ( $this->bill_times > 0 && $times_billed >= $this->bill_times ) {
442
+		if ($this->bill_times > 0 && $times_billed >= $this->bill_times) {
443 443
 			$this->complete();
444 444
 			$this->status = 'completed';
445 445
 		}
@@ -449,10 +449,10 @@  discard block
 block discarded – undo
449 449
 			'status'     => $this->status,
450 450
 		);
451 451
 
452
-        $this->subs_db->update( $this->id, $args );
452
+        $this->subs_db->update($this->id, $args);
453 453
 
454
-		do_action( 'wpinv_subscription_post_renew', $this->id, $expiration, $this );
455
-		do_action( 'wpinv_recurring_set_subscription_status', $this->id, $this->status, $this );
454
+		do_action('wpinv_subscription_post_renew', $this->id, $expiration, $this);
455
+		do_action('wpinv_recurring_set_subscription_status', $this->id, $this->status, $this);
456 456
 
457 457
 	}
458 458
 
@@ -467,7 +467,7 @@  discard block
 block discarded – undo
467 467
 	public function complete() {
468 468
 
469 469
 		// Only mark a subscription as complete if it's not already cancelled.
470
-		if ( 'cancelled' === $this->status ) {
470
+		if ('cancelled' === $this->status) {
471 471
 			return;
472 472
 		}
473 473
 
@@ -475,11 +475,11 @@  discard block
 block discarded – undo
475 475
 			'status' => 'completed'
476 476
 		);
477 477
 
478
-		if( $this->subs_db->update( $this->id, $args ) ) {
478
+		if ($this->subs_db->update($this->id, $args)) {
479 479
 
480 480
 			$this->status = 'completed';
481 481
 
482
-			do_action( 'wpinv_subscription_completed', $this->id, $this );
482
+			do_action('wpinv_subscription_completed', $this->id, $this);
483 483
 
484 484
 		}
485 485
 
@@ -494,15 +494,15 @@  discard block
 block discarded – undo
494 494
 	 * @param  $check_expiration bool True if expiration date should be checked with merchant processor before expiring
495 495
 	 * @return void
496 496
 	 */
497
-	public function expire( $check_expiration = false ) {
497
+	public function expire($check_expiration = false) {
498 498
 
499 499
 		$expiration = $this->expiration;
500 500
 
501
-		if( $check_expiration ) {
501
+		if ($check_expiration) {
502 502
 
503 503
 			// check_expiration() updates $this->expiration so compare to $expiration above
504 504
 
505
-			if( $expiration < $this->get_expiration() && current_time( 'timestamp' ) < $this->get_expiration_time() ) {
505
+			if ($expiration < $this->get_expiration() && current_time('timestamp') < $this->get_expiration_time()) {
506 506
 
507 507
 				return false; // Do not mark as expired since real expiration date is in the future
508 508
 			}
@@ -513,11 +513,11 @@  discard block
 block discarded – undo
513 513
 			'status' => 'expired'
514 514
 		);
515 515
 
516
-		if( $this->subs_db->update( $this->id, $args ) ) {
516
+		if ($this->subs_db->update($this->id, $args)) {
517 517
 
518 518
 			$this->status = 'expired';
519 519
 
520
-			do_action( 'wpinv_subscription_expired', $this->id, $this );
520
+			do_action('wpinv_subscription_expired', $this->id, $this);
521 521
 
522 522
 		}
523 523
 
@@ -535,11 +535,11 @@  discard block
 block discarded – undo
535 535
 			'status' => 'failing'
536 536
 		);
537 537
 
538
-		if( $this->subs_db->update( $this->id, $args ) ) {
538
+		if ($this->subs_db->update($this->id, $args)) {
539 539
 
540 540
 			$this->status = 'failing';
541 541
 
542
-			do_action( 'wpinv_subscription_failing', $this->id, $this );
542
+			do_action('wpinv_subscription_failing', $this->id, $this);
543 543
 
544 544
 
545 545
 		}
@@ -553,7 +553,7 @@  discard block
 block discarded – undo
553 553
      * @return void
554 554
      */
555 555
     public function cancel() {
556
-        if ( 'cancelled' === $this->status ) {
556
+        if ('cancelled' === $this->status) {
557 557
             return; // Already cancelled
558 558
         }
559 559
 
@@ -561,20 +561,20 @@  discard block
 block discarded – undo
561 561
             'status' => 'cancelled'
562 562
         );
563 563
 
564
-        if ( $this->subs_db->update( $this->id, $args ) ) {
565
-            if ( is_user_logged_in() ) {
566
-                $userdata = get_userdata( get_current_user_id() );
564
+        if ($this->subs_db->update($this->id, $args)) {
565
+            if (is_user_logged_in()) {
566
+                $userdata = get_userdata(get_current_user_id());
567 567
                 $user     = $userdata->display_name;
568 568
             } else {
569
-                $user = __( 'gateway', 'invoicing' );
569
+                $user = __('gateway', 'invoicing');
570 570
             }
571 571
 
572
-            $note = sprintf( __( 'Subscription has been cancelled by %s', 'invoicing' ), $this->parent_payment_id, $user );
573
-            wpinv_insert_payment_note( $this->parent_payment_id, $note, '', '', true );
572
+            $note = sprintf(__('Subscription has been cancelled by %s', 'invoicing'), $this->parent_payment_id, $user);
573
+            wpinv_insert_payment_note($this->parent_payment_id, $note, '', '', true);
574 574
 
575 575
             $this->status = 'cancelled';
576 576
 
577
-            do_action( 'wpinv_subscription_cancelled', $this->id, $this );
577
+            do_action('wpinv_subscription_cancelled', $this->id, $this);
578 578
         }
579 579
     }
580 580
 
@@ -589,10 +589,10 @@  discard block
 block discarded – undo
589 589
 	 */
590 590
 	public function can_cancel() {
591 591
         $ret = false;
592
-	    if( $this->gateway === 'manual' || in_array( $this->status, $this->get_cancellable_statuses() ) ) {
592
+	    if ($this->gateway === 'manual' || in_array($this->status, $this->get_cancellable_statuses())) {
593 593
             $ret = true;
594 594
         }
595
-		return apply_filters( 'wpinv_subscription_can_cancel', $ret, $this );
595
+		return apply_filters('wpinv_subscription_can_cancel', $ret, $this);
596 596
 	}
597 597
 
598 598
     /**
@@ -603,7 +603,7 @@  discard block
 block discarded – undo
603 603
      * @return      array
604 604
      */
605 605
     public function get_cancellable_statuses() {
606
-        return apply_filters( 'wpinv_recurring_cancellable_statuses', array( 'active', 'trialling', 'failing' ) );
606
+        return apply_filters('wpinv_recurring_cancellable_statuses', array('active', 'trialling', 'failing'));
607 607
     }
608 608
 
609 609
 	/**
@@ -614,9 +614,9 @@  discard block
 block discarded – undo
614 614
 	 */
615 615
 	public function get_cancel_url() {
616 616
 
617
-		$url = wp_nonce_url( add_query_arg( array( 'wpinv_action' => 'cancel_subscription', 'sub_id' => $this->id ) ), 'wpinv-recurring-cancel' );
617
+		$url = wp_nonce_url(add_query_arg(array('wpinv_action' => 'cancel_subscription', 'sub_id' => $this->id)), 'wpinv-recurring-cancel');
618 618
 
619
-		return apply_filters( 'wpinv_subscription_cancel_url', $url, $this );
619
+		return apply_filters('wpinv_subscription_cancel_url', $url, $this);
620 620
 	}
621 621
 
622 622
 	/**
@@ -630,7 +630,7 @@  discard block
 block discarded – undo
630 630
 	 */
631 631
 	public function can_renew() {
632 632
 
633
-		return apply_filters( 'wpinv_subscription_can_renew', true, $this );
633
+		return apply_filters('wpinv_subscription_can_renew', true, $this);
634 634
 	}
635 635
 
636 636
 	/**
@@ -641,9 +641,9 @@  discard block
 block discarded – undo
641 641
 	 */
642 642
 	public function get_renew_url() {
643 643
 
644
-		$url = wp_nonce_url( add_query_arg( array( 'wpinv_action' => 'renew_subscription', 'sub_id' => $this->id ) ), 'wpinv-recurring-renew' );
644
+		$url = wp_nonce_url(add_query_arg(array('wpinv_action' => 'renew_subscription', 'sub_id' => $this->id)), 'wpinv-recurring-renew');
645 645
 
646
-		return apply_filters( 'wpinv_subscription_renew_url', $url, $this );
646
+		return apply_filters('wpinv_subscription_renew_url', $url, $this);
647 647
 	}
648 648
 
649 649
 	/**
@@ -653,7 +653,7 @@  discard block
 block discarded – undo
653 653
 	 * @return bool
654 654
 	 */
655 655
 	public function can_update() {
656
-		return apply_filters( 'wpinv_subscription_can_update', false, $this );
656
+		return apply_filters('wpinv_subscription_can_update', false, $this);
657 657
 	}
658 658
 
659 659
 	/**
@@ -664,9 +664,9 @@  discard block
 block discarded – undo
664 664
 	 */
665 665
 	public function get_update_url() {
666 666
 
667
-		$url = add_query_arg( array( 'action' => 'update', 'subscription_id' => $this->id ) );
667
+		$url = add_query_arg(array('action' => 'update', 'subscription_id' => $this->id));
668 668
 
669
-		return apply_filters( 'wpinv_subscription_update_url', $url, $this );
669
+		return apply_filters('wpinv_subscription_update_url', $url, $this);
670 670
 	}
671 671
 
672 672
 	/**
@@ -679,11 +679,11 @@  discard block
 block discarded – undo
679 679
 
680 680
 		$ret = false;
681 681
 
682
-		if( ! $this->is_expired() && ( $this->status == 'active' || $this->status == 'cancelled' || $this->status == 'trialling' ) ) {
682
+		if (!$this->is_expired() && ($this->status == 'active' || $this->status == 'cancelled' || $this->status == 'trialling')) {
683 683
 			$ret = true;
684 684
 		}
685 685
 
686
-		return apply_filters( 'wpinv_subscription_is_active', $ret, $this->id, $this );
686
+		return apply_filters('wpinv_subscription_is_active', $ret, $this->id, $this);
687 687
 
688 688
 	}
689 689
 
@@ -697,26 +697,26 @@  discard block
 block discarded – undo
697 697
 
698 698
 		$ret = false;
699 699
 
700
-		if ( $this->status == 'expired' ) {
700
+		if ($this->status == 'expired') {
701 701
 
702 702
 			$ret = true;
703 703
 
704
-		} elseif( 'active' === $this->status || 'cancelled' === $this->status || $this->status == 'trialling'  ) {
704
+		} elseif ('active' === $this->status || 'cancelled' === $this->status || $this->status == 'trialling') {
705 705
 
706 706
 			$ret        = false;
707 707
 			$expiration = $this->get_expiration_time();
708 708
 
709
-			if( $expiration && strtotime( 'NOW', current_time( 'timestamp' ) ) > $expiration ) {
709
+			if ($expiration && strtotime('NOW', current_time('timestamp')) > $expiration) {
710 710
 				$ret = true;
711 711
 
712
-				if ( 'active' === $this->status || $this->status == 'trialling'  ) {
712
+				if ('active' === $this->status || $this->status == 'trialling') {
713 713
 					$this->expire();
714 714
 				}
715 715
 			}
716 716
 
717 717
 		}
718 718
 
719
-		return apply_filters( 'wpinv_subscription_is_expired', $ret, $this->id, $this );
719
+		return apply_filters('wpinv_subscription_is_expired', $ret, $this->id, $this);
720 720
 
721 721
 	}
722 722
 
@@ -737,7 +737,7 @@  discard block
 block discarded – undo
737 737
 	 * @return int
738 738
 	 */
739 739
 	public function get_expiration_time() {
740
-		return strtotime( $this->expiration, current_time( 'timestamp' ) );
740
+		return strtotime($this->expiration, current_time('timestamp'));
741 741
 	}
742 742
 
743 743
 	/**
@@ -761,37 +761,37 @@  discard block
 block discarded – undo
761 761
 	 */
762 762
 	public function get_status_label() {
763 763
 
764
-		switch( $this->get_status() ) {
764
+		switch ($this->get_status()) {
765 765
 			case 'active' :
766
-				$status = __( 'Active', 'invoicing' );
766
+				$status = __('Active', 'invoicing');
767 767
 				break;
768 768
 
769 769
 			case 'cancelled' :
770
-				$status = __( 'Cancelled', 'invoicing' );
770
+				$status = __('Cancelled', 'invoicing');
771 771
 				break;
772 772
 
773 773
 			case 'expired' :
774
-				$status = __( 'Expired', 'invoicing' );
774
+				$status = __('Expired', 'invoicing');
775 775
 				break;
776 776
 
777 777
 			case 'pending' :
778
-				$status = __( 'Pending', 'invoicing' );
778
+				$status = __('Pending', 'invoicing');
779 779
 				break;
780 780
 
781 781
 			case 'failing' :
782
-				$status = __( 'Failing', 'invoicing' );
782
+				$status = __('Failing', 'invoicing');
783 783
 				break;
784 784
 
785 785
 			case 'trialling' :
786
-				$status = __( 'Trialling', 'invoicing' );
786
+				$status = __('Trialling', 'invoicing');
787 787
 				break;
788 788
 
789 789
 			case 'completed' :
790
-				$status = __( 'Completed', 'invoicing' );
790
+				$status = __('Completed', 'invoicing');
791 791
 				break;
792 792
 
793 793
 			default:
794
-				$status = ucfirst( $this->get_status() );
794
+				$status = ucfirst($this->get_status());
795 795
 				break;
796 796
 		}
797 797
 
@@ -806,51 +806,51 @@  discard block
 block discarded – undo
806 806
      */
807 807
     public function get_status_label_html() {
808 808
 
809
-        switch( $get_status = $this->get_status() ) {
809
+        switch ($get_status = $this->get_status()) {
810 810
             case 'active' :
811
-                $status = __( 'Active', 'invoicing' );
811
+                $status = __('Active', 'invoicing');
812 812
                 $class = 'label-info';
813 813
                 break;
814 814
 
815 815
             case 'cancelled' :
816
-                $status = __( 'Cancelled', 'invoicing' );
816
+                $status = __('Cancelled', 'invoicing');
817 817
                 $class = 'label-danger';
818 818
                 break;
819 819
 
820 820
             case 'expired' :
821
-                $status = __( 'Expired', 'invoicing' );
821
+                $status = __('Expired', 'invoicing');
822 822
                 $class = 'label-default';
823 823
                 break;
824 824
 
825 825
             case 'pending' :
826
-                $status = __( 'Pending', 'invoicing' );
826
+                $status = __('Pending', 'invoicing');
827 827
                 $class = 'label-primary';
828 828
                 break;
829 829
 
830 830
             case 'failing' :
831
-                $status = __( 'Failing', 'invoicing' );
831
+                $status = __('Failing', 'invoicing');
832 832
                 $class = 'label-danger';
833 833
                 break;
834 834
 
835 835
             case 'trialling' :
836
-                $status = __( 'Trialling', 'invoicing' );
836
+                $status = __('Trialling', 'invoicing');
837 837
                 $class = 'label-info';
838 838
                 break;
839 839
 
840 840
             case 'completed' :
841
-                $status = __( 'Completed', 'invoicing' );
841
+                $status = __('Completed', 'invoicing');
842 842
                 $class = 'label-success';
843 843
                 break;
844 844
 
845 845
             default:
846
-                $status = ucfirst( $this->get_status() );
846
+                $status = ucfirst($this->get_status());
847 847
                 $class = 'label-default';
848 848
                 break;
849 849
         }
850 850
 
851 851
         $label = '<span class="sub-status label label-sub-' . $get_status . ' ' . $class . '">' . $status . '</span>';
852 852
 
853
-        return apply_filters( 'wpinv_subscription_status_label_html', $label, $get_status, $status );
853
+        return apply_filters('wpinv_subscription_status_label_html', $label, $get_status, $status);
854 854
     }
855 855
 
856 856
     /**
@@ -860,18 +860,18 @@  discard block
 block discarded – undo
860 860
      * @param  string $txn_id The transaction ID from the merchant processor
861 861
      * @return bool
862 862
      */
863
-    public function payment_exists( $txn_id = '' ) {
863
+    public function payment_exists($txn_id = '') {
864 864
         global $wpdb;
865 865
 
866
-        if ( empty( $txn_id ) ) {
866
+        if (empty($txn_id)) {
867 867
             return false;
868 868
         }
869 869
 
870
-        $txn_id = esc_sql( $txn_id );
870
+        $txn_id = esc_sql($txn_id);
871 871
 
872
-        $purchase = $wpdb->get_var( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = '{$txn_id}' LIMIT 1" );
872
+        $purchase = $wpdb->get_var("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = '{$txn_id}' LIMIT 1");
873 873
 
874
-        if ( $purchase != null ) {
874
+        if ($purchase != null) {
875 875
             return true;
876 876
         }
877 877
 
Please login to merge, or discard this patch.
includes/wpinv-email-functions.php 1 patch
Spacing   +542 added lines, -542 removed lines patch added patch discarded remove patch
@@ -7,12 +7,12 @@  discard block
 block discarded – undo
7 7
  */
8 8
 
9 9
 // MUST have WordPress.
10
-if ( !defined( 'WPINC' ) ) {
11
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
10
+if (!defined('WPINC')) {
11
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
12 12
 }
13 13
 
14 14
 function wpinv_init_transactional_emails() {
15
-    $email_actions = apply_filters( 'wpinv_email_actions', array(
15
+    $email_actions = apply_filters('wpinv_email_actions', array(
16 16
         'wpinv_status_wpi-pending_to_wpi-processing',
17 17
         'wpinv_status_wpi-pending_to_publish',
18 18
         'wpinv_status_wpi-pending_to_wpi-cancelled',
@@ -30,238 +30,238 @@  discard block
 block discarded – undo
30 30
         'wpinv_fully_refunded',
31 31
         'wpinv_partially_refunded',
32 32
         'wpinv_new_invoice_note'
33
-    ) );
33
+    ));
34 34
 
35
-    foreach ( $email_actions as $action ) {
36
-        add_action( $action, 'wpinv_send_transactional_email', 10, 10 );
35
+    foreach ($email_actions as $action) {
36
+        add_action($action, 'wpinv_send_transactional_email', 10, 10);
37 37
     }
38 38
 }
39
-add_action( 'init', 'wpinv_init_transactional_emails' );
39
+add_action('init', 'wpinv_init_transactional_emails');
40 40
 
41 41
 // New invoice email
42
-add_action( 'wpinv_status_wpi-pending_to_wpi-processing_notification', 'wpinv_new_invoice_notification' );
43
-add_action( 'wpinv_status_wpi-pending_to_publish_notification', 'wpinv_new_invoice_notification' );
44
-add_action( 'wpinv_status_wpi-pending_to_wpi-onhold_notification', 'wpinv_new_invoice_notification' );
45
-add_action( 'wpinv_status_wpi-failed_to_wpi-processing_notification', 'wpinv_new_invoice_notification' );
46
-add_action( 'wpinv_status_wpi-failed_to_publish_notification', 'wpinv_new_invoice_notification' );
47
-add_action( 'wpinv_status_wpi-failed_to_wpi-onhold_notification', 'wpinv_new_invoice_notification' );
42
+add_action('wpinv_status_wpi-pending_to_wpi-processing_notification', 'wpinv_new_invoice_notification');
43
+add_action('wpinv_status_wpi-pending_to_publish_notification', 'wpinv_new_invoice_notification');
44
+add_action('wpinv_status_wpi-pending_to_wpi-onhold_notification', 'wpinv_new_invoice_notification');
45
+add_action('wpinv_status_wpi-failed_to_wpi-processing_notification', 'wpinv_new_invoice_notification');
46
+add_action('wpinv_status_wpi-failed_to_publish_notification', 'wpinv_new_invoice_notification');
47
+add_action('wpinv_status_wpi-failed_to_wpi-onhold_notification', 'wpinv_new_invoice_notification');
48 48
 
49 49
 // Cancelled invoice email
50
-add_action( 'wpinv_status_wpi-pending_to_wpi-cancelled_notification', 'wpinv_cancelled_invoice_notification' );
51
-add_action( 'wpinv_status_wpi-onhold_to_wpi-cancelled_notification', 'wpinv_cancelled_invoice_notification' );
50
+add_action('wpinv_status_wpi-pending_to_wpi-cancelled_notification', 'wpinv_cancelled_invoice_notification');
51
+add_action('wpinv_status_wpi-onhold_to_wpi-cancelled_notification', 'wpinv_cancelled_invoice_notification');
52 52
 
53 53
 // Failed invoice email
54
-add_action( 'wpinv_status_wpi-pending_to_wpi-failed_notification', 'wpinv_failed_invoice_notification' );
55
-add_action( 'wpinv_status_wpi-onhold_to_wpi-failed_notification', 'wpinv_failed_invoice_notification' );
54
+add_action('wpinv_status_wpi-pending_to_wpi-failed_notification', 'wpinv_failed_invoice_notification');
55
+add_action('wpinv_status_wpi-onhold_to_wpi-failed_notification', 'wpinv_failed_invoice_notification');
56 56
 
57 57
 // On hold invoice email
58
-add_action( 'wpinv_status_wpi-pending_to_wpi-onhold_notification', 'wpinv_onhold_invoice_notification' );
59
-add_action( 'wpinv_status_wpi-failed_to_wpi-onhold_notification', 'wpinv_onhold_invoice_notification' );
58
+add_action('wpinv_status_wpi-pending_to_wpi-onhold_notification', 'wpinv_onhold_invoice_notification');
59
+add_action('wpinv_status_wpi-failed_to_wpi-onhold_notification', 'wpinv_onhold_invoice_notification');
60 60
 
61 61
 // Processing invoice email
62
-add_action( 'wpinv_status_wpi-pending_to_wpi-processing_notification', 'wpinv_processing_invoice_notification' );
62
+add_action('wpinv_status_wpi-pending_to_wpi-processing_notification', 'wpinv_processing_invoice_notification');
63 63
 
64 64
 // Paid invoice email
65
-add_action( 'wpinv_status_publish_notification', 'wpinv_completed_invoice_notification' );
65
+add_action('wpinv_status_publish_notification', 'wpinv_completed_invoice_notification');
66 66
 
67 67
 // Refunded invoice email
68
-add_action( 'wpinv_fully_refunded_notification', 'wpinv_fully_refunded_notification' );
69
-add_action( 'wpinv_partially_refunded_notification', 'wpinv_partially_refunded_notification' );
70
-add_action( 'wpinv_status_publish_to_wpi-refunded_notification', 'wpinv_fully_refunded_notification' );
71
-add_action( 'wpinv_status_wpi-processing_to_wpi-refunded_notification', 'wpinv_fully_refunded_notification' );
68
+add_action('wpinv_fully_refunded_notification', 'wpinv_fully_refunded_notification');
69
+add_action('wpinv_partially_refunded_notification', 'wpinv_partially_refunded_notification');
70
+add_action('wpinv_status_publish_to_wpi-refunded_notification', 'wpinv_fully_refunded_notification');
71
+add_action('wpinv_status_wpi-processing_to_wpi-refunded_notification', 'wpinv_fully_refunded_notification');
72 72
 
73 73
 // Invoice note
74
-add_action( 'wpinv_new_invoice_note_notification', 'wpinv_new_invoice_note_notification' );
74
+add_action('wpinv_new_invoice_note_notification', 'wpinv_new_invoice_note_notification');
75 75
 
76
-add_action( 'wpinv_email_header', 'wpinv_email_header' );
77
-add_action( 'wpinv_email_footer', 'wpinv_email_footer' );
78
-add_action( 'wpinv_email_invoice_details', 'wpinv_email_invoice_details', 10, 3 );
79
-add_action( 'wpinv_email_invoice_items', 'wpinv_email_invoice_items', 10, 3 );
80
-add_action( 'wpinv_email_billing_details', 'wpinv_email_billing_details', 10, 3 );
76
+add_action('wpinv_email_header', 'wpinv_email_header');
77
+add_action('wpinv_email_footer', 'wpinv_email_footer');
78
+add_action('wpinv_email_invoice_details', 'wpinv_email_invoice_details', 10, 3);
79
+add_action('wpinv_email_invoice_items', 'wpinv_email_invoice_items', 10, 3);
80
+add_action('wpinv_email_billing_details', 'wpinv_email_billing_details', 10, 3);
81 81
 
82 82
 function wpinv_send_transactional_email() {
83 83
     $args       = func_get_args();
84 84
     $function   = current_filter() . '_notification';
85
-    do_action_ref_array( $function, $args );
85
+    do_action_ref_array($function, $args);
86 86
 }
87 87
 
88
-function wpinv_new_invoice_notification( $invoice_id, $new_status = '' ) {
88
+function wpinv_new_invoice_notification($invoice_id, $new_status = '') {
89 89
     $email_type = 'new_invoice';
90
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
90
+    if (!wpinv_email_is_enabled($email_type)) {
91 91
         return false;
92 92
     }
93 93
 
94
-    $invoice = wpinv_get_invoice( $invoice_id );
95
-    if ( empty( $invoice ) ) {
94
+    $invoice = wpinv_get_invoice($invoice_id);
95
+    if (empty($invoice)) {
96 96
         return false;
97 97
     }
98 98
 
99
-    if ( !("wpi_invoice" === $invoice->post_type) ) {
99
+    if (!("wpi_invoice" === $invoice->post_type)) {
100 100
         return false;
101 101
     }
102 102
 
103
-    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
104
-    if ( !is_email( $recipient ) ) {
103
+    $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
104
+    if (!is_email($recipient)) {
105 105
         return false;
106 106
     }
107 107
 
108
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
109
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
110
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
111
-    $message_body   = wpinv_email_get_content( $email_type, $invoice_id, $invoice );
112
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
108
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
109
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
110
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
111
+    $message_body   = wpinv_email_get_content($email_type, $invoice_id, $invoice);
112
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
113 113
 
114
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
114
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
115 115
             'invoice'       => $invoice,
116 116
             'email_type'    => $email_type,
117 117
             'email_heading' => $email_heading,
118 118
             'sent_to_admin' => true,
119 119
             'plain_text'    => false,
120 120
             'message_body'  => $message_body,
121
-        ) );
121
+        ));
122 122
 
123
-    return wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
123
+    return wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
124 124
 }
125 125
 
126
-function wpinv_cancelled_invoice_notification( $invoice_id, $new_status = '' ) {
126
+function wpinv_cancelled_invoice_notification($invoice_id, $new_status = '') {
127 127
     $email_type = 'cancelled_invoice';
128
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
128
+    if (!wpinv_email_is_enabled($email_type)) {
129 129
         return false;
130 130
     }
131 131
 
132
-    $invoice = wpinv_get_invoice( $invoice_id );
133
-    if ( empty( $invoice ) ) {
132
+    $invoice = wpinv_get_invoice($invoice_id);
133
+    if (empty($invoice)) {
134 134
         return false;
135 135
     }
136 136
 
137
-    if ( !("wpi_invoice" === $invoice->post_type) ) {
137
+    if (!("wpi_invoice" === $invoice->post_type)) {
138 138
         return false;
139 139
     }
140 140
 
141
-    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
142
-    if ( !is_email( $recipient ) ) {
141
+    $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
142
+    if (!is_email($recipient)) {
143 143
         return false;
144 144
     }
145 145
 
146
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
147
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
148
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
149
-    $message_body   = wpinv_email_get_content( $email_type, $invoice_id, $invoice );
150
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
146
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
147
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
148
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
149
+    $message_body   = wpinv_email_get_content($email_type, $invoice_id, $invoice);
150
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
151 151
 
152
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
152
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
153 153
             'invoice'       => $invoice,
154 154
             'email_type'    => $email_type,
155 155
             'email_heading' => $email_heading,
156 156
             'sent_to_admin' => true,
157 157
             'plain_text'    => false,
158 158
             'message_body'  => $message_body,
159
-        ) );
159
+        ));
160 160
 
161
-    return wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
161
+    return wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
162 162
 }
163 163
 
164
-function wpinv_failed_invoice_notification( $invoice_id, $new_status = '' ) {
164
+function wpinv_failed_invoice_notification($invoice_id, $new_status = '') {
165 165
     $email_type = 'failed_invoice';
166
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
166
+    if (!wpinv_email_is_enabled($email_type)) {
167 167
         return false;
168 168
     }
169 169
     
170
-    $invoice = wpinv_get_invoice( $invoice_id );
171
-    if ( empty( $invoice ) ) {
170
+    $invoice = wpinv_get_invoice($invoice_id);
171
+    if (empty($invoice)) {
172 172
         return false;
173 173
     }
174 174
 
175
-    if ( !("wpi_invoice" === $invoice->post_type) ) {
175
+    if (!("wpi_invoice" === $invoice->post_type)) {
176 176
         return false;
177 177
     }
178 178
 
179
-    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
180
-    if ( !is_email( $recipient ) ) {
179
+    $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
180
+    if (!is_email($recipient)) {
181 181
         return false;
182 182
     }
183 183
 
184
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
185
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
186
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
187
-    $message_body   = wpinv_email_get_content( $email_type, $invoice_id, $invoice );
188
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
184
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
185
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
186
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
187
+    $message_body   = wpinv_email_get_content($email_type, $invoice_id, $invoice);
188
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
189 189
     
190
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
190
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
191 191
             'invoice'       => $invoice,
192 192
             'email_type'    => $email_type,
193 193
             'email_heading' => $email_heading,
194 194
             'sent_to_admin' => true,
195 195
             'plain_text'    => false,
196 196
             'message_body'  => $message_body,
197
-        ) );
197
+        ));
198 198
     
199
-    return wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
199
+    return wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
200 200
 }
201 201
 
202
-function wpinv_onhold_invoice_notification( $invoice_id, $new_status = '' ) {
202
+function wpinv_onhold_invoice_notification($invoice_id, $new_status = '') {
203 203
     $email_type = 'onhold_invoice';
204
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
204
+    if (!wpinv_email_is_enabled($email_type)) {
205 205
         return false;
206 206
     }
207 207
 
208
-    $invoice = wpinv_get_invoice( $invoice_id );
209
-    if ( empty( $invoice ) ) {
208
+    $invoice = wpinv_get_invoice($invoice_id);
209
+    if (empty($invoice)) {
210 210
         return false;
211 211
     }
212 212
 
213
-    if ( !("wpi_invoice" === $invoice->post_type) ) {
213
+    if (!("wpi_invoice" === $invoice->post_type)) {
214 214
         return false;
215 215
     }
216 216
 
217
-    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
218
-    if ( !is_email( $recipient ) ) {
217
+    $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
218
+    if (!is_email($recipient)) {
219 219
         return false;
220 220
     }
221 221
 
222
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
223
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
224
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
225
-    $message_body   = wpinv_email_get_content( $email_type, $invoice_id, $invoice );
226
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
222
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
223
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
224
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
225
+    $message_body   = wpinv_email_get_content($email_type, $invoice_id, $invoice);
226
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
227 227
     
228
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
228
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
229 229
             'invoice'       => $invoice,
230 230
             'email_type'    => $email_type,
231 231
             'email_heading' => $email_heading,
232 232
             'sent_to_admin' => false,
233 233
             'plain_text'    => false,
234 234
             'message_body'  => $message_body,
235
-        ) );
235
+        ));
236 236
     
237
-    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
237
+    $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
238 238
     
239
-    if ( wpinv_mail_admin_bcc_active( $email_type ) ) {
240
-        $recipient  = wpinv_get_admin_email();
241
-        $subject    .= ' - ADMIN BCC COPY';
242
-        wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
239
+    if (wpinv_mail_admin_bcc_active($email_type)) {
240
+        $recipient = wpinv_get_admin_email();
241
+        $subject .= ' - ADMIN BCC COPY';
242
+        wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
243 243
     }
244 244
     
245 245
     return $sent;
246 246
 }
247 247
 
248
-function wpinv_processing_invoice_notification( $invoice_id, $new_status = '' ) {
248
+function wpinv_processing_invoice_notification($invoice_id, $new_status = '') {
249 249
     $email_type = 'processing_invoice';
250
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
250
+    if (!wpinv_email_is_enabled($email_type)) {
251 251
         return false;
252 252
     }
253 253
 
254
-    $invoice = wpinv_get_invoice( $invoice_id );
255
-    if ( empty( $invoice ) ) {
254
+    $invoice = wpinv_get_invoice($invoice_id);
255
+    if (empty($invoice)) {
256 256
         return false;
257 257
     }
258 258
 
259
-    if ( !("wpi_invoice" === $invoice->post_type) ) {
259
+    if (!("wpi_invoice" === $invoice->post_type)) {
260 260
         return false;
261 261
     }
262 262
 
263
-    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
264
-    if ( !is_email( $recipient ) ) {
263
+    $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
264
+    if (!is_email($recipient)) {
265 265
         return false;
266 266
     }
267 267
 
@@ -270,105 +270,105 @@  discard block
 block discarded – undo
270 270
     $search['invoice_date']     = '{invoice_date}';
271 271
     $search['name']             = '{name}';
272 272
 
273
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
274
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
275
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
276
-    $message_body   = wpinv_email_get_content( $email_type, $invoice_id, $invoice );
277
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
273
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
274
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
275
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
276
+    $message_body   = wpinv_email_get_content($email_type, $invoice_id, $invoice);
277
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
278 278
     
279
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
279
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
280 280
             'invoice'       => $invoice,
281 281
             'email_type'    => $email_type,
282 282
             'email_heading' => $email_heading,
283 283
             'sent_to_admin' => false,
284 284
             'plain_text'    => false,
285 285
             'message_body'  => $message_body,
286
-        ) );
286
+        ));
287 287
 
288
-    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
288
+    $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
289 289
 
290
-    if ( wpinv_mail_admin_bcc_active( $email_type ) ) {
291
-        $recipient  = wpinv_get_admin_email();
292
-        $subject    .= ' - ADMIN BCC COPY';
293
-        wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
290
+    if (wpinv_mail_admin_bcc_active($email_type)) {
291
+        $recipient = wpinv_get_admin_email();
292
+        $subject .= ' - ADMIN BCC COPY';
293
+        wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
294 294
     }
295 295
 
296 296
     return $sent;
297 297
 }
298 298
 
299
-function wpinv_completed_invoice_notification( $invoice_id, $new_status = '' ) {
299
+function wpinv_completed_invoice_notification($invoice_id, $new_status = '') {
300 300
     $email_type = 'completed_invoice';
301
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
301
+    if (!wpinv_email_is_enabled($email_type)) {
302 302
         return false;
303 303
     }
304 304
 
305
-    $invoice = wpinv_get_invoice( $invoice_id );
306
-    if ( empty( $invoice ) ) {
305
+    $invoice = wpinv_get_invoice($invoice_id);
306
+    if (empty($invoice)) {
307 307
         return false;
308 308
     }
309 309
 
310
-    if ( !("wpi_invoice" === $invoice->post_type) ) {
310
+    if (!("wpi_invoice" === $invoice->post_type)) {
311 311
         return false;
312 312
     }
313 313
 
314
-    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
315
-    if ( !is_email( $recipient ) ) {
314
+    $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
315
+    if (!is_email($recipient)) {
316 316
         return false;
317 317
     }
318 318
 
319
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
320
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
321
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
322
-    $message_body   = wpinv_email_get_content( $email_type, $invoice_id, $invoice );
323
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
319
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
320
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
321
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
322
+    $message_body   = wpinv_email_get_content($email_type, $invoice_id, $invoice);
323
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
324 324
 
325
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
325
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
326 326
             'invoice'       => $invoice,
327 327
             'email_type'    => $email_type,
328 328
             'email_heading' => $email_heading,
329 329
             'sent_to_admin' => false,
330 330
             'plain_text'    => false,
331 331
             'message_body'  => $message_body,
332
-        ) );
332
+        ));
333 333
 
334
-    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
334
+    $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
335 335
 
336
-    if ( wpinv_mail_admin_bcc_active( $email_type ) ) {
337
-        $recipient  = wpinv_get_admin_email();
338
-        $subject    .= ' - ADMIN BCC COPY';
339
-        wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
336
+    if (wpinv_mail_admin_bcc_active($email_type)) {
337
+        $recipient = wpinv_get_admin_email();
338
+        $subject .= ' - ADMIN BCC COPY';
339
+        wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
340 340
     }
341 341
 
342 342
     return $sent;
343 343
 }
344 344
 
345
-function wpinv_fully_refunded_notification( $invoice_id, $new_status = '' ) {
345
+function wpinv_fully_refunded_notification($invoice_id, $new_status = '') {
346 346
     $email_type = 'refunded_invoice';
347
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
347
+    if (!wpinv_email_is_enabled($email_type)) {
348 348
         return false;
349 349
     }
350 350
 
351
-    $invoice = wpinv_get_invoice( $invoice_id );
352
-    if ( empty( $invoice ) ) {
351
+    $invoice = wpinv_get_invoice($invoice_id);
352
+    if (empty($invoice)) {
353 353
         return false;
354 354
     }
355 355
 
356
-    if ( !("wpi_invoice" === $invoice->post_type) ) {
356
+    if (!("wpi_invoice" === $invoice->post_type)) {
357 357
         return false;
358 358
     }
359 359
 
360
-    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
361
-    if ( !is_email( $recipient ) ) {
360
+    $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
361
+    if (!is_email($recipient)) {
362 362
         return false;
363 363
     }
364 364
 
365
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
366
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
367
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
368
-    $message_body   = wpinv_email_get_content( $email_type, $invoice_id, $invoice );
369
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
365
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
366
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
367
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
368
+    $message_body   = wpinv_email_get_content($email_type, $invoice_id, $invoice);
369
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
370 370
 
371
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
371
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
372 372
             'invoice'           => $invoice,
373 373
             'email_type'        => $email_type,
374 374
             'email_heading'     => $email_heading,
@@ -376,46 +376,46 @@  discard block
 block discarded – undo
376 376
             'plain_text'        => false,
377 377
             'partial_refund'    => false,
378 378
             'message_body'      => $message_body,
379
-        ) );
379
+        ));
380 380
 
381
-    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
381
+    $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
382 382
 
383
-    if ( wpinv_mail_admin_bcc_active( $email_type ) ) {
384
-        $recipient  = wpinv_get_admin_email();
385
-        $subject    .= ' - ADMIN BCC COPY';
386
-        wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
383
+    if (wpinv_mail_admin_bcc_active($email_type)) {
384
+        $recipient = wpinv_get_admin_email();
385
+        $subject .= ' - ADMIN BCC COPY';
386
+        wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
387 387
     }
388 388
 
389 389
     return $sent;
390 390
 }
391 391
 
392
-function wpinv_partially_refunded_notification( $invoice_id, $new_status = '' ) {
392
+function wpinv_partially_refunded_notification($invoice_id, $new_status = '') {
393 393
     $email_type = 'refunded_invoice';
394
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
394
+    if (!wpinv_email_is_enabled($email_type)) {
395 395
         return false;
396 396
     }
397 397
 
398
-    $invoice = wpinv_get_invoice( $invoice_id );
399
-    if ( empty( $invoice ) ) {
398
+    $invoice = wpinv_get_invoice($invoice_id);
399
+    if (empty($invoice)) {
400 400
         return false;
401 401
     }
402 402
 
403
-    if ( !("wpi_invoice" === $invoice->post_type) ) {
403
+    if (!("wpi_invoice" === $invoice->post_type)) {
404 404
         return false;
405 405
     }
406 406
 
407
-    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
408
-    if ( !is_email( $recipient ) ) {
407
+    $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
408
+    if (!is_email($recipient)) {
409 409
         return false;
410 410
     }
411 411
 
412
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
413
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
414
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
415
-    $message_body   = wpinv_email_get_content( $email_type, $invoice_id, $invoice );
416
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
412
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
413
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
414
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
415
+    $message_body   = wpinv_email_get_content($email_type, $invoice_id, $invoice);
416
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
417 417
 
418
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
418
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
419 419
             'invoice'           => $invoice,
420 420
             'email_type'        => $email_type,
421 421
             'email_heading'     => $email_heading,
@@ -423,89 +423,89 @@  discard block
 block discarded – undo
423 423
             'plain_text'        => false,
424 424
             'partial_refund'    => true,
425 425
             'message_body'      => $message_body,
426
-        ) );
426
+        ));
427 427
 
428
-    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
428
+    $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
429 429
 
430
-    if ( wpinv_mail_admin_bcc_active( $email_type ) ) {
431
-        $recipient  = wpinv_get_admin_email();
432
-        $subject    .= ' - ADMIN BCC COPY';
433
-        wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
430
+    if (wpinv_mail_admin_bcc_active($email_type)) {
431
+        $recipient = wpinv_get_admin_email();
432
+        $subject .= ' - ADMIN BCC COPY';
433
+        wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
434 434
     }
435 435
 
436 436
     return $sent;
437 437
 }
438 438
 
439
-function wpinv_new_invoice_note_notification( $invoice_id, $new_status = '' ) {
439
+function wpinv_new_invoice_note_notification($invoice_id, $new_status = '') {
440 440
 }
441 441
 
442
-function wpinv_user_invoice_notification( $invoice_id ) {
442
+function wpinv_user_invoice_notification($invoice_id) {
443 443
     $email_type = 'user_invoice';
444
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
444
+    if (!wpinv_email_is_enabled($email_type)) {
445 445
         return -1;
446 446
     }
447 447
 
448
-    $invoice = wpinv_get_invoice( $invoice_id );
449
-    if ( empty( $invoice ) ) {
448
+    $invoice = wpinv_get_invoice($invoice_id);
449
+    if (empty($invoice)) {
450 450
         return false;
451 451
     }
452 452
 
453
-    if ( !("wpi_invoice" === $invoice->post_type) ) {
453
+    if (!("wpi_invoice" === $invoice->post_type)) {
454 454
         return false;
455 455
     }
456 456
 
457
-    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
458
-    if ( !is_email( $recipient ) ) {
457
+    $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
458
+    if (!is_email($recipient)) {
459 459
         return false;
460 460
     }
461 461
 
462
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
463
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
464
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
465
-    $message_body   = wpinv_email_get_content( $email_type, $invoice_id, $invoice );
466
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
462
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
463
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
464
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
465
+    $message_body   = wpinv_email_get_content($email_type, $invoice_id, $invoice);
466
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
467 467
     
468
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
468
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
469 469
             'invoice'       => $invoice,
470 470
             'email_type'    => $email_type,
471 471
             'email_heading' => $email_heading,
472 472
             'sent_to_admin' => false,
473 473
             'plain_text'    => false,
474 474
             'message_body'  => $message_body,
475
-        ) );
475
+        ));
476 476
 
477
-    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
477
+    $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
478 478
 
479
-    if ( $sent ) {
480
-        $note = __( 'Invoice has been emailed to the user.', 'invoicing' );
479
+    if ($sent) {
480
+        $note = __('Invoice has been emailed to the user.', 'invoicing');
481 481
     } else {
482
-        $note = __( 'Fail to send invoice to the user!', 'invoicing' );
482
+        $note = __('Fail to send invoice to the user!', 'invoicing');
483 483
     }
484 484
 
485
-    $invoice->add_note( $note, '', '', true ); // Add system note.
485
+    $invoice->add_note($note, '', '', true); // Add system note.
486 486
 
487
-    if ( wpinv_mail_admin_bcc_active( $email_type ) ) {
488
-        $recipient  = wpinv_get_admin_email();
489
-        $subject    .= ' - ADMIN BCC COPY';
490
-        wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
487
+    if (wpinv_mail_admin_bcc_active($email_type)) {
488
+        $recipient = wpinv_get_admin_email();
489
+        $subject .= ' - ADMIN BCC COPY';
490
+        wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
491 491
     }
492 492
 
493 493
     return $sent;
494 494
 }
495 495
 
496
-function wpinv_user_note_notification( $invoice_id, $args = array() ) {
496
+function wpinv_user_note_notification($invoice_id, $args = array()) {
497 497
     $email_type = 'user_note';
498
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
498
+    if (!wpinv_email_is_enabled($email_type)) {
499 499
         return false;
500 500
     }
501 501
 
502
-    $invoice = wpinv_get_invoice( $invoice_id );
503
-    if ( empty( $invoice ) ) {
502
+    $invoice = wpinv_get_invoice($invoice_id);
503
+    if (empty($invoice)) {
504 504
         return false;
505 505
     }
506 506
 
507
-    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
508
-    if ( !is_email( $recipient ) ) {
507
+    $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
508
+    if (!is_email($recipient)) {
509 509
         return false;
510 510
     }
511 511
 
@@ -513,17 +513,17 @@  discard block
 block discarded – undo
513 513
         'user_note' => ''
514 514
     );
515 515
 
516
-    $args = wp_parse_args( $args, $defaults );
516
+    $args = wp_parse_args($args, $defaults);
517 517
 
518
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
519
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
520
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
521
-    $message_body   = wpinv_email_get_content( $email_type, $invoice_id, $invoice );
522
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
518
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
519
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
520
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
521
+    $message_body   = wpinv_email_get_content($email_type, $invoice_id, $invoice);
522
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
523 523
 
524
-    $message_body   = str_replace( '{customer_note}', $args['user_note'], $message_body );
524
+    $message_body   = str_replace('{customer_note}', $args['user_note'], $message_body);
525 525
 
526
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
526
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
527 527
             'invoice'       => $invoice,
528 528
             'email_type'    => $email_type,
529 529
             'email_heading' => $email_heading,
@@ -531,34 +531,34 @@  discard block
 block discarded – undo
531 531
             'plain_text'    => false,
532 532
             'message_body'  => $message_body,
533 533
             'customer_note' => $args['user_note']
534
-        ) );
534
+        ));
535 535
 
536
-    $content        = wpinv_email_format_text( $content, $invoice );
536
+    $content = wpinv_email_format_text($content, $invoice);
537 537
 
538
-    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
538
+    $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
539 539
 
540 540
     return $sent;
541 541
 }
542 542
 
543 543
 function wpinv_mail_get_from_address() {
544
-    $from_address = apply_filters( 'wpinv_mail_from_address', wpinv_get_option( 'email_from' ) );
545
-    return sanitize_email( $from_address );
544
+    $from_address = apply_filters('wpinv_mail_from_address', wpinv_get_option('email_from'));
545
+    return sanitize_email($from_address);
546 546
 }
547 547
 
548 548
 function wpinv_mail_get_from_name() {
549
-    $from_name = apply_filters( 'wpinv_mail_from_name', wpinv_get_option( 'email_from_name' ) );
550
-    return wp_specialchars_decode( esc_html( $from_name ), ENT_QUOTES );
549
+    $from_name = apply_filters('wpinv_mail_from_name', wpinv_get_option('email_from_name'));
550
+    return wp_specialchars_decode(esc_html($from_name), ENT_QUOTES);
551 551
 }
552 552
 
553
-function wpinv_mail_admin_bcc_active( $mail_type = '' ) {
554
-    $active = apply_filters( 'wpinv_mail_admin_bcc_active', wpinv_get_option( 'email_' . $mail_type . '_admin_bcc' ) );
555
-    return ( $active ? true : false );
553
+function wpinv_mail_admin_bcc_active($mail_type = '') {
554
+    $active = apply_filters('wpinv_mail_admin_bcc_active', wpinv_get_option('email_' . $mail_type . '_admin_bcc'));
555
+    return ($active ? true : false);
556 556
 }
557 557
     
558
-function wpinv_mail_get_content_type(  $content_type = 'text/html', $email_type = 'html' ) {
559
-    $email_type = apply_filters( 'wpinv_mail_content_type', $email_type );
558
+function wpinv_mail_get_content_type($content_type = 'text/html', $email_type = 'html') {
559
+    $email_type = apply_filters('wpinv_mail_content_type', $email_type);
560 560
 
561
-    switch ( $email_type ) {
561
+    switch ($email_type) {
562 562
         case 'html' :
563 563
             $content_type = 'text/html';
564 564
             break;
@@ -573,35 +573,35 @@  discard block
 block discarded – undo
573 573
     return $content_type;
574 574
 }
575 575
     
576
-function wpinv_mail_send( $to, $subject, $message, $headers, $attachments ) {
577
-    add_filter( 'wp_mail_from', 'wpinv_mail_get_from_address' );
578
-    add_filter( 'wp_mail_from_name', 'wpinv_mail_get_from_name' );
579
-    add_filter( 'wp_mail_content_type', 'wpinv_mail_get_content_type' );
576
+function wpinv_mail_send($to, $subject, $message, $headers, $attachments) {
577
+    add_filter('wp_mail_from', 'wpinv_mail_get_from_address');
578
+    add_filter('wp_mail_from_name', 'wpinv_mail_get_from_name');
579
+    add_filter('wp_mail_content_type', 'wpinv_mail_get_content_type');
580 580
 
581
-    $message = wpinv_email_style_body( $message );
582
-    $message = apply_filters( 'wpinv_mail_content', $message );
581
+    $message = wpinv_email_style_body($message);
582
+    $message = apply_filters('wpinv_mail_content', $message);
583 583
 
584
-    $sent  = wp_mail( $to, $subject, $message, $headers, $attachments );
584
+    $sent = wp_mail($to, $subject, $message, $headers, $attachments);
585 585
 
586
-    if ( !$sent ) {
587
-        $log_message = wp_sprintf( __( "\nTime: %s\nTo: %s\nSubject: %s\n", 'invoicing' ), date_i18n( 'F j Y H:i:s', current_time( 'timestamp' ) ), ( is_array( $to ) ? implode( ', ', $to ) : $to ), $subject );
588
-        wpinv_error_log( $log_message, __( "Email from Invoicing plugin failed to send", 'invoicing' ), __FILE__, __LINE__ );
586
+    if (!$sent) {
587
+        $log_message = wp_sprintf(__("\nTime: %s\nTo: %s\nSubject: %s\n", 'invoicing'), date_i18n('F j Y H:i:s', current_time('timestamp')), (is_array($to) ? implode(', ', $to) : $to), $subject);
588
+        wpinv_error_log($log_message, __("Email from Invoicing plugin failed to send", 'invoicing'), __FILE__, __LINE__);
589 589
     }
590 590
 
591
-    remove_filter( 'wp_mail_from', 'wpinv_mail_get_from_address' );
592
-    remove_filter( 'wp_mail_from_name', 'wpinv_mail_get_from_name' );
593
-    remove_filter( 'wp_mail_content_type', 'wpinv_mail_get_content_type' );
591
+    remove_filter('wp_mail_from', 'wpinv_mail_get_from_address');
592
+    remove_filter('wp_mail_from_name', 'wpinv_mail_get_from_name');
593
+    remove_filter('wp_mail_content_type', 'wpinv_mail_get_content_type');
594 594
 
595 595
     return $sent;
596 596
 }
597 597
     
598 598
 function wpinv_get_emails() {
599 599
     $overdue_days_options       = array();
600
-    $overdue_days_options[0]    = __( 'On the Due Date', 'invoicing' );
601
-    $overdue_days_options[1]    = __( '1 day after Due Date', 'invoicing' );
600
+    $overdue_days_options[0]    = __('On the Due Date', 'invoicing');
601
+    $overdue_days_options[1]    = __('1 day after Due Date', 'invoicing');
602 602
 
603
-    for ( $i = 2; $i <= 10; $i++ ) {
604
-        $overdue_days_options[$i]   = wp_sprintf( __( '%d days after Due Date', 'invoicing' ), $i );
603
+    for ($i = 2; $i <= 10; $i++) {
604
+        $overdue_days_options[$i] = wp_sprintf(__('%d days after Due Date', 'invoicing'), $i);
605 605
     }
606 606
 
607 607
     // Default, built-in gateways
@@ -609,39 +609,39 @@  discard block
 block discarded – undo
609 609
             'new_invoice' => array(
610 610
             'email_new_invoice_header' => array(
611 611
                 'id'   => 'email_new_invoice_header',
612
-                'name' => '<h3>' . __( 'New Invoice', 'invoicing' ) . '</h3>',
613
-                'desc' => __( 'New invoice emails are sent to admin when a new invoice is received.', 'invoicing' ),
612
+                'name' => '<h3>' . __('New Invoice', 'invoicing') . '</h3>',
613
+                'desc' => __('New invoice emails are sent to admin when a new invoice is received.', 'invoicing'),
614 614
                 'type' => 'header',
615 615
             ),
616 616
             'email_new_invoice_active' => array(
617 617
                 'id'   => 'email_new_invoice_active',
618
-                'name' => __( 'Enable/Disable', 'invoicing' ),
619
-                'desc' => __( 'Enable this email notification', 'invoicing' ),
618
+                'name' => __('Enable/Disable', 'invoicing'),
619
+                'desc' => __('Enable this email notification', 'invoicing'),
620 620
                 'type' => 'checkbox',
621 621
                 'std'  => 1
622 622
             ),
623 623
             'email_new_invoice_subject' => array(
624 624
                 'id'   => 'email_new_invoice_subject',
625
-                'name' => __( 'Subject', 'invoicing' ),
626
-                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
625
+                'name' => __('Subject', 'invoicing'),
626
+                'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
627 627
                 'type' => 'text',
628
-                'std'  => __( '[{site_title}] New payment invoice ({invoice_number}) - {invoice_date}', 'invoicing' ),
628
+                'std'  => __('[{site_title}] New payment invoice ({invoice_number}) - {invoice_date}', 'invoicing'),
629 629
                 'size' => 'large'
630 630
             ),
631 631
             'email_new_invoice_heading' => array(
632 632
                 'id'   => 'email_new_invoice_heading',
633
-                'name' => __( 'Email Heading', 'invoicing' ),
634
-                'desc' => __( 'Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing' ),
633
+                'name' => __('Email Heading', 'invoicing'),
634
+                'desc' => __('Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing'),
635 635
                 'type' => 'text',
636
-                'std'  => __( 'New payment invoice', 'invoicing' ),
636
+                'std'  => __('New payment invoice', 'invoicing'),
637 637
                 'size' => 'large'
638 638
             ),
639 639
             'email_new_invoice_body' => array(
640 640
                 'id'   => 'email_new_invoice_body',
641
-                'name' => __( 'Email Content', 'invoicing' ),
642
-                'desc' => __( 'The content of the email (wildcards and HTML are allowed).', 'invoicing' ),
641
+                'name' => __('Email Content', 'invoicing'),
642
+                'desc' => __('The content of the email (wildcards and HTML are allowed).', 'invoicing'),
643 643
                 'type' => 'rich_editor',
644
-                'std'  => __( '<p>Hi Admin,</p><p>You have received payment invoice from {name}.</p>', 'invoicing' ),
644
+                'std'  => __('<p>Hi Admin,</p><p>You have received payment invoice from {name}.</p>', 'invoicing'),
645 645
                 'class' => 'large',
646 646
                 'size' => '10'
647 647
             ),
@@ -649,39 +649,39 @@  discard block
 block discarded – undo
649 649
         'cancelled_invoice' => array(
650 650
             'email_cancelled_invoice_header' => array(
651 651
                 'id'   => 'email_cancelled_invoice_header',
652
-                'name' => '<h3>' . __( 'Cancelled Invoice', 'invoicing' ) . '</h3>',
653
-                'desc' => __( 'Cancelled invoice emails are sent to admin when invoices have been marked cancelled.', 'invoicing' ),
652
+                'name' => '<h3>' . __('Cancelled Invoice', 'invoicing') . '</h3>',
653
+                'desc' => __('Cancelled invoice emails are sent to admin when invoices have been marked cancelled.', 'invoicing'),
654 654
                 'type' => 'header',
655 655
             ),
656 656
             'email_cancelled_invoice_active' => array(
657 657
                 'id'   => 'email_cancelled_invoice_active',
658
-                'name' => __( 'Enable/Disable', 'invoicing' ),
659
-                'desc' => __( 'Enable this email notification', 'invoicing' ),
658
+                'name' => __('Enable/Disable', 'invoicing'),
659
+                'desc' => __('Enable this email notification', 'invoicing'),
660 660
                 'type' => 'checkbox',
661 661
                 'std'  => 1
662 662
             ),
663 663
             'email_cancelled_invoice_subject' => array(
664 664
                 'id'   => 'email_cancelled_invoice_subject',
665
-                'name' => __( 'Subject', 'invoicing' ),
666
-                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
665
+                'name' => __('Subject', 'invoicing'),
666
+                'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
667 667
                 'type' => 'text',
668
-                'std'  => __( '[{site_title}] Cancelled invoice ({invoice_number})', 'invoicing' ),
668
+                'std'  => __('[{site_title}] Cancelled invoice ({invoice_number})', 'invoicing'),
669 669
                 'size' => 'large'
670 670
             ),
671 671
             'email_cancelled_invoice_heading' => array(
672 672
                 'id'   => 'email_cancelled_invoice_heading',
673
-                'name' => __( 'Email Heading', 'invoicing' ),
674
-                'desc' => __( 'Enter the main heading contained within the email notification.', 'invoicing' ),
673
+                'name' => __('Email Heading', 'invoicing'),
674
+                'desc' => __('Enter the main heading contained within the email notification.', 'invoicing'),
675 675
                 'type' => 'text',
676
-                'std'  => __( 'Cancelled invoice', 'invoicing' ),
676
+                'std'  => __('Cancelled invoice', 'invoicing'),
677 677
                 'size' => 'large'
678 678
             ),
679 679
             'email_cancelled_invoice_body' => array(
680 680
                 'id'   => 'email_cancelled_invoice_body',
681
-                'name' => __( 'Email Content', 'invoicing' ),
682
-                'desc' => __( 'The content of the email (wildcards and HTML are allowed).', 'invoicing' ),
681
+                'name' => __('Email Content', 'invoicing'),
682
+                'desc' => __('The content of the email (wildcards and HTML are allowed).', 'invoicing'),
683 683
                 'type' => 'rich_editor',
684
-                'std'  => __( '<p>Hi Admin,</p><p>The invoice #{invoice_number} from {site_title} has been cancelled.</p>', 'invoicing' ),
684
+                'std'  => __('<p>Hi Admin,</p><p>The invoice #{invoice_number} from {site_title} has been cancelled.</p>', 'invoicing'),
685 685
                 'class' => 'large',
686 686
                 'size' => '10'
687 687
             ),
@@ -689,39 +689,39 @@  discard block
 block discarded – undo
689 689
         'failed_invoice' => array(
690 690
             'email_failed_invoice_header' => array(
691 691
                 'id'   => 'email_failed_invoice_header',
692
-                'name' => '<h3>' . __( 'Failed Invoice', 'invoicing' ) . '</h3>',
693
-                'desc' => __( 'Failed invoice emails are sent to admin when invoices have been marked failed (if they were previously processing or on-hold).', 'invoicing' ),
692
+                'name' => '<h3>' . __('Failed Invoice', 'invoicing') . '</h3>',
693
+                'desc' => __('Failed invoice emails are sent to admin when invoices have been marked failed (if they were previously processing or on-hold).', 'invoicing'),
694 694
                 'type' => 'header',
695 695
             ),
696 696
             'email_failed_invoice_active' => array(
697 697
                 'id'   => 'email_failed_invoice_active',
698
-                'name' => __( 'Enable/Disable', 'invoicing' ),
699
-                'desc' => __( 'Enable this email notification', 'invoicing' ),
698
+                'name' => __('Enable/Disable', 'invoicing'),
699
+                'desc' => __('Enable this email notification', 'invoicing'),
700 700
                 'type' => 'checkbox',
701 701
                 'std'  => 1
702 702
             ),
703 703
             'email_failed_invoice_subject' => array(
704 704
                 'id'   => 'email_failed_invoice_subject',
705
-                'name' => __( 'Subject', 'invoicing' ),
706
-                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
705
+                'name' => __('Subject', 'invoicing'),
706
+                'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
707 707
                 'type' => 'text',
708
-                'std'  => __( '[{site_title}] Failed invoice ({invoice_number})', 'invoicing' ),
708
+                'std'  => __('[{site_title}] Failed invoice ({invoice_number})', 'invoicing'),
709 709
                 'size' => 'large'
710 710
             ),
711 711
             'email_failed_invoice_heading' => array(
712 712
                 'id'   => 'email_failed_invoice_heading',
713
-                'name' => __( 'Email Heading', 'invoicing' ),
714
-                'desc' => __( 'Enter the main heading contained within the email notification.', 'invoicing' ),
713
+                'name' => __('Email Heading', 'invoicing'),
714
+                'desc' => __('Enter the main heading contained within the email notification.', 'invoicing'),
715 715
                 'type' => 'text',
716
-                'std'  => __( 'Failed invoice', 'invoicing' ),
716
+                'std'  => __('Failed invoice', 'invoicing'),
717 717
                 'size' => 'large'
718 718
             ),
719 719
             'email_failed_invoice_body' => array(
720 720
                 'id'   => 'email_failed_invoice_body',
721
-                'name' => __( 'Email Content', 'invoicing' ),
722
-                'desc' => __( 'The content of the email (wildcards and HTML are allowed).', 'invoicing' ),
721
+                'name' => __('Email Content', 'invoicing'),
722
+                'desc' => __('The content of the email (wildcards and HTML are allowed).', 'invoicing'),
723 723
                 'type' => 'rich_editor',
724
-                'std'  => __( '<p>Hi Admin,</p><p>Payment for invoice #{invoice_number} from {site_title} has been failed.</p>', 'invoicing' ),
724
+                'std'  => __('<p>Hi Admin,</p><p>Payment for invoice #{invoice_number} from {site_title} has been failed.</p>', 'invoicing'),
725 725
                 'class' => 'large',
726 726
                 'size' => '10'
727 727
             ),
@@ -729,46 +729,46 @@  discard block
 block discarded – undo
729 729
         'onhold_invoice' => array(
730 730
             'email_onhold_invoice_header' => array(
731 731
                 'id'   => 'email_onhold_invoice_header',
732
-                'name' => '<h3>' . __( 'On Hold Invoice', 'invoicing' ) . '</h3>',
733
-                'desc' => __( 'This is an invoice notification sent to users containing invoice details after an invoice is placed on-hold.', 'invoicing' ),
732
+                'name' => '<h3>' . __('On Hold Invoice', 'invoicing') . '</h3>',
733
+                'desc' => __('This is an invoice notification sent to users containing invoice details after an invoice is placed on-hold.', 'invoicing'),
734 734
                 'type' => 'header',
735 735
             ),
736 736
             'email_onhold_invoice_active' => array(
737 737
                 'id'   => 'email_onhold_invoice_active',
738
-                'name' => __( 'Enable/Disable', 'invoicing' ),
739
-                'desc' => __( 'Enable this email notification', 'invoicing' ),
738
+                'name' => __('Enable/Disable', 'invoicing'),
739
+                'desc' => __('Enable this email notification', 'invoicing'),
740 740
                 'type' => 'checkbox',
741 741
                 'std'  => 1
742 742
             ),
743 743
             'email_onhold_invoice_subject' => array(
744 744
                 'id'   => 'email_onhold_invoice_subject',
745
-                'name' => __( 'Subject', 'invoicing' ),
746
-                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
745
+                'name' => __('Subject', 'invoicing'),
746
+                'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
747 747
                 'type' => 'text',
748
-                'std'  => __( '[{site_title}] Your invoice receipt from {invoice_date}', 'invoicing' ),
748
+                'std'  => __('[{site_title}] Your invoice receipt from {invoice_date}', 'invoicing'),
749 749
                 'size' => 'large'
750 750
             ),
751 751
             'email_onhold_invoice_heading' => array(
752 752
                 'id'   => 'email_onhold_invoice_heading',
753
-                'name' => __( 'Email Heading', 'invoicing' ),
754
-                'desc' => __( 'Enter the main heading contained within the email notification.', 'invoicing' ),
753
+                'name' => __('Email Heading', 'invoicing'),
754
+                'desc' => __('Enter the main heading contained within the email notification.', 'invoicing'),
755 755
                 'type' => 'text',
756
-                'std'  => __( 'Thank you for your invoice', 'invoicing' ),
756
+                'std'  => __('Thank you for your invoice', 'invoicing'),
757 757
                 'size' => 'large'
758 758
             ),
759 759
             'email_onhold_invoice_admin_bcc' => array(
760 760
                 'id'   => 'email_onhold_invoice_admin_bcc',
761
-                'name' => __( 'Enable Admin BCC', 'invoicing' ),
762
-                'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ),
761
+                'name' => __('Enable Admin BCC', 'invoicing'),
762
+                'desc' => __('Check if you want to send this notification email to site Admin.', 'invoicing'),
763 763
                 'type' => 'checkbox',
764 764
                 'std'  => 1
765 765
             ),
766 766
             'email_onhold_invoice_body' => array(
767 767
                 'id'   => 'email_onhold_invoice_body',
768
-                'name' => __( 'Email Content', 'invoicing' ),
769
-                'desc' => __( 'The content of the email (wildcards and HTML are allowed).', 'invoicing' ),
768
+                'name' => __('Email Content', 'invoicing'),
769
+                'desc' => __('The content of the email (wildcards and HTML are allowed).', 'invoicing'),
770 770
                 'type' => 'rich_editor',
771
-                'std'  => __( '<p>Hi {name},</p><p>Your invoice is on-hold until we confirm your payment has been received.</p>', 'invoicing' ),
771
+                'std'  => __('<p>Hi {name},</p><p>Your invoice is on-hold until we confirm your payment has been received.</p>', 'invoicing'),
772 772
                 'class' => 'large',
773 773
                 'size' => '10'
774 774
             ),
@@ -776,46 +776,46 @@  discard block
 block discarded – undo
776 776
         'processing_invoice' => array(
777 777
             'email_processing_invoice_header' => array(
778 778
                 'id'   => 'email_processing_invoice_header',
779
-                'name' => '<h3>' . __( 'Processing Invoice', 'invoicing' ) . '</h3>',
780
-                'desc' => __( 'This is an invoice notification sent to users containing invoice details after payment.', 'invoicing' ),
779
+                'name' => '<h3>' . __('Processing Invoice', 'invoicing') . '</h3>',
780
+                'desc' => __('This is an invoice notification sent to users containing invoice details after payment.', 'invoicing'),
781 781
                 'type' => 'header',
782 782
             ),
783 783
             'email_processing_invoice_active' => array(
784 784
                 'id'   => 'email_processing_invoice_active',
785
-                'name' => __( 'Enable/Disable', 'invoicing' ),
786
-                'desc' => __( 'Enable this email notification', 'invoicing' ),
785
+                'name' => __('Enable/Disable', 'invoicing'),
786
+                'desc' => __('Enable this email notification', 'invoicing'),
787 787
                 'type' => 'checkbox',
788 788
                 'std'  => 1
789 789
             ),
790 790
             'email_processing_invoice_subject' => array(
791 791
                 'id'   => 'email_processing_invoice_subject',
792
-                'name' => __( 'Subject', 'invoicing' ),
793
-                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
792
+                'name' => __('Subject', 'invoicing'),
793
+                'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
794 794
                 'type' => 'text',
795
-                'std'  => __( '[{site_title}] Your invoice receipt from {invoice_date}', 'invoicing' ),
795
+                'std'  => __('[{site_title}] Your invoice receipt from {invoice_date}', 'invoicing'),
796 796
                 'size' => 'large'
797 797
             ),
798 798
             'email_processing_invoice_heading' => array(
799 799
                 'id'   => 'email_processing_invoice_heading',
800
-                'name' => __( 'Email Heading', 'invoicing' ),
801
-                'desc' => __( 'Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing' ),
800
+                'name' => __('Email Heading', 'invoicing'),
801
+                'desc' => __('Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing'),
802 802
                 'type' => 'text',
803
-                'std'  => __( 'Thank you for your invoice', 'invoicing' ),
803
+                'std'  => __('Thank you for your invoice', 'invoicing'),
804 804
                 'size' => 'large'
805 805
             ),
806 806
             'email_processing_invoice_admin_bcc' => array(
807 807
                 'id'   => 'email_processing_invoice_admin_bcc',
808
-                'name' => __( 'Enable Admin BCC', 'invoicing' ),
809
-                'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ),
808
+                'name' => __('Enable Admin BCC', 'invoicing'),
809
+                'desc' => __('Check if you want to send this notification email to site Admin.', 'invoicing'),
810 810
                 'type' => 'checkbox',
811 811
                 'std'  => 1
812 812
             ),
813 813
             'email_processing_invoice_body' => array(
814 814
                 'id'   => 'email_processing_invoice_body',
815
-                'name' => __( 'Email Content', 'invoicing' ),
816
-                'desc' => __( 'The content of the email (wildcards and HTML are allowed).', 'invoicing' ),
815
+                'name' => __('Email Content', 'invoicing'),
816
+                'desc' => __('The content of the email (wildcards and HTML are allowed).', 'invoicing'),
817 817
                 'type' => 'rich_editor',
818
-                'std'  => __( '<p>Hi {name},</p><p>Your invoice has been received at {site_title} and is now being processed.</p>', 'invoicing' ),
818
+                'std'  => __('<p>Hi {name},</p><p>Your invoice has been received at {site_title} and is now being processed.</p>', 'invoicing'),
819 819
                 'class' => 'large',
820 820
                 'size' => '10'
821 821
             ),
@@ -823,45 +823,45 @@  discard block
 block discarded – undo
823 823
         'completed_invoice' => array(
824 824
             'email_completed_invoice_header' => array(
825 825
                 'id'   => 'email_completed_invoice_header',
826
-                'name' => '<h3>' . __( 'Paid Invoice', 'invoicing' ) . '</h3>',
827
-                'desc' => __( 'Invoice paid emails are sent to users when their invoices are marked paid and usually indicate that their payment has been done.', 'invoicing' ),
826
+                'name' => '<h3>' . __('Paid Invoice', 'invoicing') . '</h3>',
827
+                'desc' => __('Invoice paid emails are sent to users when their invoices are marked paid and usually indicate that their payment has been done.', 'invoicing'),
828 828
                 'type' => 'header',
829 829
             ),
830 830
             'email_completed_invoice_active' => array(
831 831
                 'id'   => 'email_completed_invoice_active',
832
-                'name' => __( 'Enable/Disable', 'invoicing' ),
833
-                'desc' => __( 'Enable this email notification', 'invoicing' ),
832
+                'name' => __('Enable/Disable', 'invoicing'),
833
+                'desc' => __('Enable this email notification', 'invoicing'),
834 834
                 'type' => 'checkbox',
835 835
                 'std'  => 1
836 836
             ),
837 837
             'email_completed_invoice_subject' => array(
838 838
                 'id'   => 'email_completed_invoice_subject',
839
-                'name' => __( 'Subject', 'invoicing' ),
840
-                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
839
+                'name' => __('Subject', 'invoicing'),
840
+                'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
841 841
                 'type' => 'text',
842
-                'std'  => __( '[{site_title}] Your invoice from {invoice_date} has been paid', 'invoicing' ),
842
+                'std'  => __('[{site_title}] Your invoice from {invoice_date} has been paid', 'invoicing'),
843 843
                 'size' => 'large'
844 844
             ),
845 845
             'email_completed_invoice_heading' => array(
846 846
                 'id'   => 'email_completed_invoice_heading',
847
-                'name' => __( 'Email Heading', 'invoicing' ),
848
-                'desc' => __( 'Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing' ),
847
+                'name' => __('Email Heading', 'invoicing'),
848
+                'desc' => __('Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing'),
849 849
                 'type' => 'text',
850
-                'std'  => __( 'Your invoice has been paid', 'invoicing' ),
850
+                'std'  => __('Your invoice has been paid', 'invoicing'),
851 851
                 'size' => 'large'
852 852
             ),
853 853
             'email_completed_invoice_admin_bcc' => array(
854 854
                 'id'   => 'email_completed_invoice_admin_bcc',
855
-                'name' => __( 'Enable Admin BCC', 'invoicing' ),
856
-                'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ),
855
+                'name' => __('Enable Admin BCC', 'invoicing'),
856
+                'desc' => __('Check if you want to send this notification email to site Admin.', 'invoicing'),
857 857
                 'type' => 'checkbox',
858 858
             ),
859 859
             'email_completed_invoice_body' => array(
860 860
                 'id'   => 'email_completed_invoice_body',
861
-                'name' => __( 'Email Content', 'invoicing' ),
862
-                'desc' => __( 'The content of the email (wildcards and HTML are allowed).', 'invoicing' ),
861
+                'name' => __('Email Content', 'invoicing'),
862
+                'desc' => __('The content of the email (wildcards and HTML are allowed).', 'invoicing'),
863 863
                 'type' => 'rich_editor',
864
-                'std'  => __( '<p>Hi {name},</p><p>Your recent invoice on {site_title} has been paid.</p>', 'invoicing' ),
864
+                'std'  => __('<p>Hi {name},</p><p>Your recent invoice on {site_title} has been paid.</p>', 'invoicing'),
865 865
                 'class' => 'large',
866 866
                 'size' => '10'
867 867
             ),
@@ -870,46 +870,46 @@  discard block
 block discarded – undo
870 870
         'refunded_invoice' => array(
871 871
             'email_refunded_invoice_header' => array(
872 872
                 'id'   => 'email_refunded_invoice_header',
873
-                'name' => '<h3>' . __( 'Refunded Invoice', 'invoicing' ) . '</h3>',
874
-                'desc' => __( 'Invoice refunded emails are sent to users when their invoices are marked refunded.', 'invoicing' ),
873
+                'name' => '<h3>' . __('Refunded Invoice', 'invoicing') . '</h3>',
874
+                'desc' => __('Invoice refunded emails are sent to users when their invoices are marked refunded.', 'invoicing'),
875 875
                 'type' => 'header',
876 876
             ),
877 877
             'email_refunded_invoice_active' => array(
878 878
                 'id'   => 'email_refunded_invoice_active',
879
-                'name' => __( 'Enable/Disable', 'invoicing' ),
880
-                'desc' => __( 'Enable this email notification', 'invoicing' ),
879
+                'name' => __('Enable/Disable', 'invoicing'),
880
+                'desc' => __('Enable this email notification', 'invoicing'),
881 881
                 'type' => 'checkbox',
882 882
                 'std'  => 1
883 883
             ),
884 884
             'email_refunded_invoice_subject' => array(
885 885
                 'id'   => 'email_refunded_invoice_subject',
886
-                'name' => __( 'Subject', 'invoicing' ),
887
-                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
886
+                'name' => __('Subject', 'invoicing'),
887
+                'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
888 888
                 'type' => 'text',
889
-                'std'  => __( '[{site_title}] Your invoice from {invoice_date} has been refunded', 'invoicing' ),
889
+                'std'  => __('[{site_title}] Your invoice from {invoice_date} has been refunded', 'invoicing'),
890 890
                 'size' => 'large'
891 891
             ),
892 892
             'email_refunded_invoice_heading' => array(
893 893
                 'id'   => 'email_refunded_invoice_heading',
894
-                'name' => __( 'Email Heading', 'invoicing' ),
895
-                'desc' => __( 'Enter the main heading contained within the email notification.', 'invoicing' ),
894
+                'name' => __('Email Heading', 'invoicing'),
895
+                'desc' => __('Enter the main heading contained within the email notification.', 'invoicing'),
896 896
                 'type' => 'text',
897
-                'std'  => __( 'Your invoice has been refunded', 'invoicing' ),
897
+                'std'  => __('Your invoice has been refunded', 'invoicing'),
898 898
                 'size' => 'large'
899 899
             ),
900 900
             'email_refunded_invoice_admin_bcc' => array(
901 901
                 'id'   => 'email_refunded_invoice_admin_bcc',
902
-                'name' => __( 'Enable Admin BCC', 'invoicing' ),
903
-                'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ),
902
+                'name' => __('Enable Admin BCC', 'invoicing'),
903
+                'desc' => __('Check if you want to send this notification email to site Admin.', 'invoicing'),
904 904
                 'type' => 'checkbox',
905 905
                 'std'  => 1
906 906
             ),
907 907
             'email_refunded_invoice_body' => array(
908 908
                 'id'   => 'email_refunded_invoice_body',
909
-                'name' => __( 'Email Content', 'invoicing' ),
910
-                'desc' => __( 'The content of the email (wildcards and HTML are allowed).', 'invoicing' ),
909
+                'name' => __('Email Content', 'invoicing'),
910
+                'desc' => __('The content of the email (wildcards and HTML are allowed).', 'invoicing'),
911 911
                 'type' => 'rich_editor',
912
-                'std'  => __( '<p>Hi {name},</p><p>Your invoice on {site_title} has been refunded.</p>', 'invoicing' ),
912
+                'std'  => __('<p>Hi {name},</p><p>Your invoice on {site_title} has been refunded.</p>', 'invoicing'),
913 913
                 'class' => 'large',
914 914
                 'size' => '10'
915 915
             ),
@@ -917,46 +917,46 @@  discard block
 block discarded – undo
917 917
         'user_invoice' => array(
918 918
             'email_user_invoice_header' => array(
919 919
                 'id'   => 'email_user_invoice_header',
920
-                'name' => '<h3>' . __( 'Customer Invoice', 'invoicing' ) . '</h3>',
921
-                'desc' => __( 'Customer invoice emails can be sent to customers containing their invoice information and payment links.', 'invoicing' ),
920
+                'name' => '<h3>' . __('Customer Invoice', 'invoicing') . '</h3>',
921
+                'desc' => __('Customer invoice emails can be sent to customers containing their invoice information and payment links.', 'invoicing'),
922 922
                 'type' => 'header',
923 923
             ),
924 924
             'email_user_invoice_active' => array(
925 925
                 'id'   => 'email_user_invoice_active',
926
-                'name' => __( 'Enable/Disable', 'invoicing' ),
927
-                'desc' => __( 'Enable this email notification', 'invoicing' ),
926
+                'name' => __('Enable/Disable', 'invoicing'),
927
+                'desc' => __('Enable this email notification', 'invoicing'),
928 928
                 'type' => 'checkbox',
929 929
                 'std'  => 1
930 930
             ),
931 931
             'email_user_invoice_subject' => array(
932 932
                 'id'   => 'email_user_invoice_subject',
933
-                'name' => __( 'Subject', 'invoicing' ),
934
-                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
933
+                'name' => __('Subject', 'invoicing'),
934
+                'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
935 935
                 'type' => 'text',
936
-                'std'  => __( '[{site_title}] Your invoice from {invoice_date}', 'invoicing' ),
936
+                'std'  => __('[{site_title}] Your invoice from {invoice_date}', 'invoicing'),
937 937
                 'size' => 'large'
938 938
             ),
939 939
             'email_user_invoice_heading' => array(
940 940
                 'id'   => 'email_user_invoice_heading',
941
-                'name' => __( 'Email Heading', 'invoicing' ),
942
-                'desc' => __( 'Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing' ),
941
+                'name' => __('Email Heading', 'invoicing'),
942
+                'desc' => __('Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing'),
943 943
                 'type' => 'text',
944
-                'std'  => __( 'Your invoice {invoice_number} details', 'invoicing' ),
944
+                'std'  => __('Your invoice {invoice_number} details', 'invoicing'),
945 945
                 'size' => 'large'
946 946
             ),
947 947
             'email_user_invoice_admin_bcc' => array(
948 948
                 'id'   => 'email_user_invoice_admin_bcc',
949
-                'name' => __( 'Enable Admin BCC', 'invoicing' ),
950
-                'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ),
949
+                'name' => __('Enable Admin BCC', 'invoicing'),
950
+                'desc' => __('Check if you want to send this notification email to site Admin.', 'invoicing'),
951 951
                 'type' => 'checkbox',
952 952
                 'std'  => 1
953 953
             ),
954 954
             'email_user_invoice_body' => array(
955 955
                 'id'   => 'email_user_invoice_body',
956
-                'name' => __( 'Email Content', 'invoicing' ),
957
-                'desc' => __( 'The content of the email (wildcards and HTML are allowed).', 'invoicing' ),
956
+                'name' => __('Email Content', 'invoicing'),
957
+                'desc' => __('The content of the email (wildcards and HTML are allowed).', 'invoicing'),
958 958
                 'type' => 'rich_editor',
959
-                'std'  => __( '<p>Hi {name},</p><p>An invoice has been created for you on {site_title}. To view / pay for this invoice please use the following link: <a class="btn btn-success" href="{invoice_link}">View / Pay</a></p>', 'invoicing' ),
959
+                'std'  => __('<p>Hi {name},</p><p>An invoice has been created for you on {site_title}. To view / pay for this invoice please use the following link: <a class="btn btn-success" href="{invoice_link}">View / Pay</a></p>', 'invoicing'),
960 960
                 'class' => 'large',
961 961
                 'size' => '10'
962 962
             ),
@@ -964,39 +964,39 @@  discard block
 block discarded – undo
964 964
         'user_note' => array(
965 965
             'email_user_note_header' => array(
966 966
                 'id'   => 'email_user_note_header',
967
-                'name' => '<h3>' . __( 'Customer Note', 'invoicing' ) . '</h3>',
968
-                'desc' => __( 'Customer note emails are sent when you add a note to an invoice/quote.', 'invoicing' ),
967
+                'name' => '<h3>' . __('Customer Note', 'invoicing') . '</h3>',
968
+                'desc' => __('Customer note emails are sent when you add a note to an invoice/quote.', 'invoicing'),
969 969
                 'type' => 'header',
970 970
             ),
971 971
             'email_user_note_active' => array(
972 972
                 'id'   => 'email_user_note_active',
973
-                'name' => __( 'Enable/Disable', 'invoicing' ),
974
-                'desc' => __( 'Enable this email notification', 'invoicing' ),
973
+                'name' => __('Enable/Disable', 'invoicing'),
974
+                'desc' => __('Enable this email notification', 'invoicing'),
975 975
                 'type' => 'checkbox',
976 976
                 'std'  => 1
977 977
             ),
978 978
             'email_user_note_subject' => array(
979 979
                 'id'   => 'email_user_note_subject',
980
-                'name' => __( 'Subject', 'invoicing' ),
981
-                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
980
+                'name' => __('Subject', 'invoicing'),
981
+                'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
982 982
                 'type' => 'text',
983
-                'std'  => __( '[{site_title}] Note added to your {invoice_label} #{invoice_number} from {invoice_date}', 'invoicing' ),
983
+                'std'  => __('[{site_title}] Note added to your {invoice_label} #{invoice_number} from {invoice_date}', 'invoicing'),
984 984
                 'size' => 'large'
985 985
             ),
986 986
             'email_user_note_heading' => array(
987 987
                 'id'   => 'email_user_note_heading',
988
-                'name' => __( 'Email Heading', 'invoicing' ),
989
-                'desc' => __( 'Enter the main heading contained within the email notification.', 'invoicing' ),
988
+                'name' => __('Email Heading', 'invoicing'),
989
+                'desc' => __('Enter the main heading contained within the email notification.', 'invoicing'),
990 990
                 'type' => 'text',
991
-                'std'  => __( 'A note has been added to your {invoice_label}', 'invoicing' ),
991
+                'std'  => __('A note has been added to your {invoice_label}', 'invoicing'),
992 992
                 'size' => 'large'
993 993
             ),
994 994
             'email_user_note_body' => array(
995 995
                 'id'   => 'email_user_note_body',
996
-                'name' => __( 'Email Content', 'invoicing' ),
997
-                'desc' => __( 'The content of the email (wildcards and HTML are allowed).', 'invoicing' ),
996
+                'name' => __('Email Content', 'invoicing'),
997
+                'desc' => __('The content of the email (wildcards and HTML are allowed).', 'invoicing'),
998 998
                 'type' => 'rich_editor',
999
-                'std'  => __( '<p>Hi {name},</p><p>Following note has been added to your {invoice_label}:</p><blockquote class="wpinv-note">{customer_note}</blockquote>', 'invoicing' ),
999
+                'std'  => __('<p>Hi {name},</p><p>Following note has been added to your {invoice_label}:</p><blockquote class="wpinv-note">{customer_note}</blockquote>', 'invoicing'),
1000 1000
                 'class' => 'large',
1001 1001
                 'size' => '10'
1002 1002
             ),
@@ -1004,155 +1004,155 @@  discard block
 block discarded – undo
1004 1004
         'overdue' => array(
1005 1005
             'email_overdue_header' => array(
1006 1006
                 'id'   => 'email_overdue_header',
1007
-                'name' => '<h3>' . __( 'Payment Reminder', 'invoicing' ) . '</h3>',
1008
-                'desc' => __( 'Payment reminder emails are sent to user automatically.', 'invoicing' ),
1007
+                'name' => '<h3>' . __('Payment Reminder', 'invoicing') . '</h3>',
1008
+                'desc' => __('Payment reminder emails are sent to user automatically.', 'invoicing'),
1009 1009
                 'type' => 'header',
1010 1010
             ),
1011 1011
             'email_overdue_active' => array(
1012 1012
                 'id'   => 'email_overdue_active',
1013
-                'name' => __( 'Enable/Disable', 'invoicing' ),
1014
-                'desc' => __( 'Enable this email notification', 'invoicing' ),
1013
+                'name' => __('Enable/Disable', 'invoicing'),
1014
+                'desc' => __('Enable this email notification', 'invoicing'),
1015 1015
                 'type' => 'checkbox',
1016 1016
                 'std'  => 1
1017 1017
             ),
1018 1018
             'email_due_reminder_days' => array(
1019 1019
                 'id'        => 'email_due_reminder_days',
1020
-                'name'      => __( 'When to Send', 'invoicing' ),
1021
-                'desc'      => __( 'Check when you would like payment reminders sent out.', 'invoicing' ),
1020
+                'name'      => __('When to Send', 'invoicing'),
1021
+                'desc'      => __('Check when you would like payment reminders sent out.', 'invoicing'),
1022 1022
                 'default'   => '',
1023 1023
                 'type'      => 'multicheck',
1024 1024
                 'options'   => $overdue_days_options,
1025 1025
             ),
1026 1026
             'email_overdue_subject' => array(
1027 1027
                 'id'   => 'email_overdue_subject',
1028
-                'name' => __( 'Subject', 'invoicing' ),
1029
-                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
1028
+                'name' => __('Subject', 'invoicing'),
1029
+                'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
1030 1030
                 'type' => 'text',
1031
-                'std'  => __( '[{site_title}] Payment Reminder', 'invoicing' ),
1031
+                'std'  => __('[{site_title}] Payment Reminder', 'invoicing'),
1032 1032
                 'size' => 'large'
1033 1033
             ),
1034 1034
             'email_overdue_heading' => array(
1035 1035
                 'id'   => 'email_overdue_heading',
1036
-                'name' => __( 'Email Heading', 'invoicing' ),
1037
-                'desc' => __( 'Enter the main heading contained within the email notification.', 'invoicing' ),
1036
+                'name' => __('Email Heading', 'invoicing'),
1037
+                'desc' => __('Enter the main heading contained within the email notification.', 'invoicing'),
1038 1038
                 'type' => 'text',
1039
-                'std'  => __( 'Payment reminder for your invoice', 'invoicing' ),
1039
+                'std'  => __('Payment reminder for your invoice', 'invoicing'),
1040 1040
                 'size' => 'large'
1041 1041
             ),
1042 1042
             'email_overdue_body' => array(
1043 1043
                 'id'   => 'email_overdue_body',
1044
-                'name' => __( 'Email Content', 'invoicing' ),
1045
-                'desc' => __( 'The content of the email.', 'invoicing' ),
1044
+                'name' => __('Email Content', 'invoicing'),
1045
+                'desc' => __('The content of the email.', 'invoicing'),
1046 1046
                 'type' => 'rich_editor',
1047
-                'std'  => __( '<p>Hi {full_name},</p><p>This is just a friendly reminder that your invoice <a href="{invoice_link}">#{invoice_number}</a> {is_was} due on {invoice_due_date}.</p><p>The total of this invoice is {invoice_total}</p><p>To view / pay now for this invoice please use the following link: <a class="btn btn-success" href="{invoice_link}">View / Pay</a></p>', 'invoicing' ),
1047
+                'std'  => __('<p>Hi {full_name},</p><p>This is just a friendly reminder that your invoice <a href="{invoice_link}">#{invoice_number}</a> {is_was} due on {invoice_due_date}.</p><p>The total of this invoice is {invoice_total}</p><p>To view / pay now for this invoice please use the following link: <a class="btn btn-success" href="{invoice_link}">View / Pay</a></p>', 'invoicing'),
1048 1048
                 'class' => 'large',
1049 1049
                 'size'  => 10,
1050 1050
             ),
1051 1051
         ),
1052 1052
     );
1053 1053
 
1054
-    return apply_filters( 'wpinv_get_emails', $emails );
1054
+    return apply_filters('wpinv_get_emails', $emails);
1055 1055
 }
1056 1056
 
1057
-function wpinv_settings_emails( $settings = array() ) {
1057
+function wpinv_settings_emails($settings = array()) {
1058 1058
     $emails = wpinv_get_emails();
1059 1059
 
1060
-    if ( !empty( $emails ) ) {
1061
-        foreach ( $emails as $key => $email ) {
1060
+    if (!empty($emails)) {
1061
+        foreach ($emails as $key => $email) {
1062 1062
             $settings[$key] = $email;
1063 1063
         }
1064 1064
     }
1065 1065
 
1066
-    return apply_filters( 'wpinv_settings_get_emails', $settings );
1066
+    return apply_filters('wpinv_settings_get_emails', $settings);
1067 1067
 }
1068
-add_filter( 'wpinv_settings_emails', 'wpinv_settings_emails', 10, 1 );
1068
+add_filter('wpinv_settings_emails', 'wpinv_settings_emails', 10, 1);
1069 1069
 
1070
-function wpinv_settings_sections_emails( $settings ) {
1070
+function wpinv_settings_sections_emails($settings) {
1071 1071
     $emails = wpinv_get_emails();
1072 1072
 
1073 1073
     if (!empty($emails)) {
1074
-        foreach  ($emails as $key => $email) {
1075
-            $settings[$key] = !empty( $email['email_' . $key . '_header']['name'] ) ? strip_tags( $email['email_' . $key . '_header']['name'] ) : $key;
1074
+        foreach ($emails as $key => $email) {
1075
+            $settings[$key] = !empty($email['email_' . $key . '_header']['name']) ? strip_tags($email['email_' . $key . '_header']['name']) : $key;
1076 1076
         }
1077 1077
     }
1078 1078
 
1079 1079
     return $settings;    
1080 1080
 }
1081
-add_filter( 'wpinv_settings_sections_emails', 'wpinv_settings_sections_emails', 10, 1 );
1081
+add_filter('wpinv_settings_sections_emails', 'wpinv_settings_sections_emails', 10, 1);
1082 1082
 
1083
-function wpinv_email_is_enabled( $email_type ) {
1083
+function wpinv_email_is_enabled($email_type) {
1084 1084
     $emails = wpinv_get_emails();
1085
-    $enabled = isset( $emails[$email_type] ) && wpinv_get_option( 'email_'. $email_type . '_active', 0 ) ? true : false;
1085
+    $enabled = isset($emails[$email_type]) && wpinv_get_option('email_' . $email_type . '_active', 0) ? true : false;
1086 1086
 
1087
-    return apply_filters( 'wpinv_email_is_enabled', $enabled, $email_type );
1087
+    return apply_filters('wpinv_email_is_enabled', $enabled, $email_type);
1088 1088
 }
1089 1089
 
1090
-function wpinv_email_get_recipient( $email_type = '', $invoice_id = 0, $invoice = array() ) {
1091
-    switch ( $email_type ) {
1090
+function wpinv_email_get_recipient($email_type = '', $invoice_id = 0, $invoice = array()) {
1091
+    switch ($email_type) {
1092 1092
         case 'new_invoice':
1093 1093
         case 'cancelled_invoice':
1094 1094
         case 'failed_invoice':
1095 1095
             $recipient  = wpinv_get_admin_email();
1096 1096
         break;
1097 1097
         default:
1098
-            $invoice    = !empty( $invoice ) && is_object( $invoice ) ? $invoice : ( $invoice_id > 0 ? wpinv_get_invoice( $invoice_id ) : NULL );
1099
-            $recipient  = !empty( $invoice ) ? $invoice->get_email() : '';
1098
+            $invoice    = !empty($invoice) && is_object($invoice) ? $invoice : ($invoice_id > 0 ? wpinv_get_invoice($invoice_id) : NULL);
1099
+            $recipient  = !empty($invoice) ? $invoice->get_email() : '';
1100 1100
         break;
1101 1101
     }
1102 1102
 
1103
-    return apply_filters( 'wpinv_email_recipient', $recipient, $email_type, $invoice_id, $invoice );
1103
+    return apply_filters('wpinv_email_recipient', $recipient, $email_type, $invoice_id, $invoice);
1104 1104
 }
1105 1105
 
1106
-function wpinv_email_get_subject( $email_type = '', $invoice_id = 0, $invoice = array() ) {
1107
-    $subject    = wpinv_get_option( 'email_' . $email_type . '_subject' );
1106
+function wpinv_email_get_subject($email_type = '', $invoice_id = 0, $invoice = array()) {
1107
+    $subject    = wpinv_get_option('email_' . $email_type . '_subject');
1108 1108
 
1109
-    $subject    = wpinv_email_format_text( $subject, $invoice );
1109
+    $subject    = wpinv_email_format_text($subject, $invoice);
1110 1110
 
1111
-    return apply_filters( 'wpinv_email_subject', $subject, $email_type, $invoice_id, $invoice );
1111
+    return apply_filters('wpinv_email_subject', $subject, $email_type, $invoice_id, $invoice);
1112 1112
 }
1113 1113
 
1114
-function wpinv_email_get_heading( $email_type = '', $invoice_id = 0, $invoice = array() ) {
1115
-    $email_heading = wpinv_get_option( 'email_' . $email_type . '_heading' );
1114
+function wpinv_email_get_heading($email_type = '', $invoice_id = 0, $invoice = array()) {
1115
+    $email_heading = wpinv_get_option('email_' . $email_type . '_heading');
1116 1116
 
1117
-    $email_heading = wpinv_email_format_text( $email_heading, $invoice );
1117
+    $email_heading = wpinv_email_format_text($email_heading, $invoice);
1118 1118
 
1119
-    return apply_filters( 'wpinv_email_heading', $email_heading, $email_type, $invoice_id, $invoice );
1119
+    return apply_filters('wpinv_email_heading', $email_heading, $email_type, $invoice_id, $invoice);
1120 1120
 }
1121 1121
 
1122
-function wpinv_email_get_content( $email_type = '', $invoice_id = 0, $invoice = array() ) {
1123
-    $content    = wpinv_get_option( 'email_' . $email_type . '_body' );
1122
+function wpinv_email_get_content($email_type = '', $invoice_id = 0, $invoice = array()) {
1123
+    $content    = wpinv_get_option('email_' . $email_type . '_body');
1124 1124
 
1125
-    $content    = wpinv_email_format_text( $content, $invoice );
1125
+    $content    = wpinv_email_format_text($content, $invoice);
1126 1126
 
1127
-    return apply_filters( 'wpinv_email_content', $content, $email_type, $invoice_id, $invoice );
1127
+    return apply_filters('wpinv_email_content', $content, $email_type, $invoice_id, $invoice);
1128 1128
 }
1129 1129
 
1130
-function wpinv_email_get_headers( $email_type = '', $invoice_id = 0, $invoice = array() ) {
1130
+function wpinv_email_get_headers($email_type = '', $invoice_id = 0, $invoice = array()) {
1131 1131
     $from_name = wpinv_mail_get_from_address();
1132 1132
     $from_email = wpinv_mail_get_from_address();
1133 1133
     
1134
-    $invoice    = !empty( $invoice ) && is_object( $invoice ) ? $invoice : ( $invoice_id > 0 ? wpinv_get_invoice( $invoice_id ) : NULL );
1134
+    $invoice    = !empty($invoice) && is_object($invoice) ? $invoice : ($invoice_id > 0 ? wpinv_get_invoice($invoice_id) : NULL);
1135 1135
     
1136
-    $headers    = "From: " . stripslashes_deep( html_entity_decode( $from_name, ENT_COMPAT, 'UTF-8' ) ) . " <$from_email>\r\n";
1137
-    $headers    .= "Reply-To: ". $from_email . "\r\n";
1136
+    $headers    = "From: " . stripslashes_deep(html_entity_decode($from_name, ENT_COMPAT, 'UTF-8')) . " <$from_email>\r\n";
1137
+    $headers    .= "Reply-To: " . $from_email . "\r\n";
1138 1138
     $headers    .= "Content-Type: " . wpinv_mail_get_content_type() . "\r\n";
1139 1139
     
1140
-    return apply_filters( 'wpinv_email_headers', $headers, $email_type, $invoice_id, $invoice );
1140
+    return apply_filters('wpinv_email_headers', $headers, $email_type, $invoice_id, $invoice);
1141 1141
 }
1142 1142
 
1143
-function wpinv_email_get_attachments( $email_type = '', $invoice_id = 0, $invoice = array() ) {
1143
+function wpinv_email_get_attachments($email_type = '', $invoice_id = 0, $invoice = array()) {
1144 1144
     $attachments = array();
1145 1145
     
1146
-    return apply_filters( 'wpinv_email_attachments', $attachments, $email_type, $invoice_id, $invoice );
1146
+    return apply_filters('wpinv_email_attachments', $attachments, $email_type, $invoice_id, $invoice);
1147 1147
 }
1148 1148
 
1149
-function wpinv_email_format_text( $content, $invoice ) {
1149
+function wpinv_email_format_text($content, $invoice) {
1150 1150
     $replace_array = array(
1151 1151
         '{site_title}'      => wpinv_get_blogname(),
1152
-        '{date}'            => date_i18n( get_option( 'date_format' ), (int) current_time( 'timestamp' ) ),
1152
+        '{date}'            => date_i18n(get_option('date_format'), (int)current_time('timestamp')),
1153 1153
     );
1154 1154
     
1155
-    if ( !empty( $invoice->ID ) ) {
1155
+    if (!empty($invoice->ID)) {
1156 1156
         $replace_array = array_merge(
1157 1157
             $replace_array, 
1158 1158
             array(
@@ -1162,65 +1162,65 @@  discard block
 block discarded – undo
1162 1162
                 '{last_name}'       => $invoice->get_last_name(),
1163 1163
                 '{email}'           => $invoice->get_email(),
1164 1164
                 '{invoice_number}'  => $invoice->get_number(),
1165
-                '{invoice_total}'   => $invoice->get_total( true ),
1166
-                '{invoice_link}'    => $invoice->get_view_url( true ),
1167
-                '{invoice_pay_link}'=> $invoice->get_view_url( true ),
1168
-                '{invoice_date}'    => $invoice->get_invoice_date( true ),
1169
-                '{invoice_due_date}'=> $invoice->get_due_date( true ),
1170
-                '{invoice_quote}'   => $invoice->get_invoice_quote_type( $invoice->ID ),
1171
-                '{invoice_label}'   => $invoice->get_invoice_quote_type( $invoice->ID ),
1172
-                '{is_was}'          => strtotime( $invoice->get_due_date() ) < strtotime( date_i18n( 'Y-m-d' ) ) ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ),
1165
+                '{invoice_total}'   => $invoice->get_total(true),
1166
+                '{invoice_link}'    => $invoice->get_view_url(true),
1167
+                '{invoice_pay_link}'=> $invoice->get_view_url(true),
1168
+                '{invoice_date}'    => $invoice->get_invoice_date(true),
1169
+                '{invoice_due_date}'=> $invoice->get_due_date(true),
1170
+                '{invoice_quote}'   => $invoice->get_invoice_quote_type($invoice->ID),
1171
+                '{invoice_label}'   => $invoice->get_invoice_quote_type($invoice->ID),
1172
+                '{is_was}'          => strtotime($invoice->get_due_date()) < strtotime(date_i18n('Y-m-d')) ? __('was', 'invoicing') : __('is', 'invoicing'),
1173 1173
             )
1174 1174
         );
1175 1175
     }
1176 1176
 
1177
-    $replace_array = apply_filters( 'wpinv_email_format_text', $replace_array, $content, $invoice );
1177
+    $replace_array = apply_filters('wpinv_email_format_text', $replace_array, $content, $invoice);
1178 1178
 
1179
-    foreach ( $replace_array as $key => $value ) {
1180
-        $content = str_replace( $key, $value, $content );
1179
+    foreach ($replace_array as $key => $value) {
1180
+        $content = str_replace($key, $value, $content);
1181 1181
     }
1182 1182
 
1183
-    return apply_filters( 'wpinv_email_content_replace', $content );
1183
+    return apply_filters('wpinv_email_content_replace', $content);
1184 1184
 }
1185 1185
 
1186
-function wpinv_email_style_body( $content ) {
1186
+function wpinv_email_style_body($content) {
1187 1187
     // make sure we only inline CSS for html emails
1188
-    if ( in_array( wpinv_mail_get_content_type(), array( 'text/html', 'multipart/alternative' ) ) && class_exists( 'DOMDocument' ) ) {
1188
+    if (in_array(wpinv_mail_get_content_type(), array('text/html', 'multipart/alternative')) && class_exists('DOMDocument')) {
1189 1189
         ob_start();
1190
-        wpinv_get_template( 'emails/wpinv-email-styles.php' );
1191
-        $css = apply_filters( 'wpinv_email_styles', ob_get_clean() );
1190
+        wpinv_get_template('emails/wpinv-email-styles.php');
1191
+        $css = apply_filters('wpinv_email_styles', ob_get_clean());
1192 1192
 
1193 1193
         // apply CSS styles inline for picky email clients
1194 1194
         try {
1195
-            $emogrifier = new Emogrifier( $content, $css );
1195
+            $emogrifier = new Emogrifier($content, $css);
1196 1196
             $content    = $emogrifier->emogrify();
1197
-        } catch ( Exception $e ) {
1198
-            wpinv_error_log( $e->getMessage(), 'emogrifier' );
1197
+        } catch (Exception $e) {
1198
+            wpinv_error_log($e->getMessage(), 'emogrifier');
1199 1199
         }
1200 1200
     }
1201 1201
     return $content;
1202 1202
 }
1203 1203
 
1204
-function wpinv_email_header( $email_heading = '', $invoice = array(), $email_type = '', $sent_to_admin = false ) {
1205
-    wpinv_get_template( 'emails/wpinv-email-header.php', array( 'email_heading' => $email_heading, 'invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin ) );
1204
+function wpinv_email_header($email_heading = '', $invoice = array(), $email_type = '', $sent_to_admin = false) {
1205
+    wpinv_get_template('emails/wpinv-email-header.php', array('email_heading' => $email_heading, 'invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin));
1206 1206
 }
1207 1207
 
1208 1208
 /**
1209 1209
  * Get the email footer.
1210 1210
  */
1211
-function wpinv_email_footer( $invoice = array(), $email_type = '', $sent_to_admin = false ) {
1212
-    wpinv_get_template( 'emails/wpinv-email-footer.php', array( 'invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin ) );
1211
+function wpinv_email_footer($invoice = array(), $email_type = '', $sent_to_admin = false) {
1212
+    wpinv_get_template('emails/wpinv-email-footer.php', array('invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin));
1213 1213
 }
1214 1214
 
1215
-function wpinv_email_wrap_message( $message ) {
1215
+function wpinv_email_wrap_message($message) {
1216 1216
     // Buffer
1217 1217
     ob_start();
1218 1218
 
1219
-    do_action( 'wpinv_email_header' );
1219
+    do_action('wpinv_email_header');
1220 1220
 
1221
-    echo wpautop( wptexturize( $message ) );
1221
+    echo wpautop(wptexturize($message));
1222 1222
 
1223
-    do_action( 'wpinv_email_footer' );
1223
+    do_action('wpinv_email_footer');
1224 1224
 
1225 1225
     // Get contents
1226 1226
     $message = ob_get_clean();
@@ -1228,92 +1228,92 @@  discard block
 block discarded – undo
1228 1228
     return $message;
1229 1229
 }
1230 1230
 
1231
-function wpinv_email_invoice_details( $invoice, $email_type = '', $sent_to_admin = false ) {
1232
-    wpinv_get_template( 'emails/wpinv-email-invoice-details.php', array( 'invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin ) );
1231
+function wpinv_email_invoice_details($invoice, $email_type = '', $sent_to_admin = false) {
1232
+    wpinv_get_template('emails/wpinv-email-invoice-details.php', array('invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin));
1233 1233
 }
1234 1234
 
1235
-function wpinv_email_invoice_items( $invoice, $email_type = '', $sent_to_admin = false ) {
1236
-    wpinv_get_template( 'emails/wpinv-email-invoice-items.php', array( 'invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin ) );
1235
+function wpinv_email_invoice_items($invoice, $email_type = '', $sent_to_admin = false) {
1236
+    wpinv_get_template('emails/wpinv-email-invoice-items.php', array('invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin));
1237 1237
 }
1238 1238
 
1239
-function wpinv_email_billing_details( $invoice, $email_type = '', $sent_to_admin = false ) {
1240
-    wpinv_get_template( 'emails/wpinv-email-billing-details.php', array( 'invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin ) );
1239
+function wpinv_email_billing_details($invoice, $email_type = '', $sent_to_admin = false) {
1240
+    wpinv_get_template('emails/wpinv-email-billing-details.php', array('invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin));
1241 1241
 }
1242 1242
 
1243
-function wpinv_send_customer_invoice( $data = array() ) {
1244
-    $invoice_id = !empty( $data['invoice_id'] ) ? absint( $data['invoice_id'] ) : NULL;
1243
+function wpinv_send_customer_invoice($data = array()) {
1244
+    $invoice_id = !empty($data['invoice_id']) ? absint($data['invoice_id']) : NULL;
1245 1245
 
1246
-    if ( empty( $invoice_id ) ) {
1246
+    if (empty($invoice_id)) {
1247 1247
         return;
1248 1248
     }
1249 1249
 
1250
-    if ( !current_user_can( 'manage_options' ) ) {
1251
-        wp_die( __( 'You do not have permission to send invoice notification', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
1250
+    if (!current_user_can('manage_options')) {
1251
+        wp_die(__('You do not have permission to send invoice notification', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
1252 1252
     }
1253 1253
     
1254
-    $sent = wpinv_user_invoice_notification( $invoice_id );
1254
+    $sent = wpinv_user_invoice_notification($invoice_id);
1255 1255
 
1256 1256
     if ( -1 == $sent ) {
1257 1257
         $status = 'email_disabled';
1258
-    } elseif ( $sent ) {
1258
+    } elseif ($sent) {
1259 1259
         $status = 'email_sent';
1260 1260
     } else {
1261 1261
         $status = 'email_fail';
1262 1262
     }
1263 1263
 
1264
-    $redirect = add_query_arg( array( 'wpinv-message' => $status, 'wpi_action' => false, 'invoice_id' => false ) );
1265
-    wp_redirect( $redirect );
1264
+    $redirect = add_query_arg(array('wpinv-message' => $status, 'wpi_action' => false, 'invoice_id' => false));
1265
+    wp_redirect($redirect);
1266 1266
     exit;
1267 1267
 }
1268
-add_action( 'wpinv_send_invoice', 'wpinv_send_customer_invoice' );
1268
+add_action('wpinv_send_invoice', 'wpinv_send_customer_invoice');
1269 1269
 
1270
-function wpinv_send_overdue_reminder( $data = array() ) {
1271
-    $invoice_id = !empty( $data['invoice_id'] ) ? absint( $data['invoice_id'] ) : NULL;
1270
+function wpinv_send_overdue_reminder($data = array()) {
1271
+    $invoice_id = !empty($data['invoice_id']) ? absint($data['invoice_id']) : NULL;
1272 1272
 
1273
-    if ( empty( $invoice_id ) ) {
1273
+    if (empty($invoice_id)) {
1274 1274
         return;
1275 1275
     }
1276 1276
 
1277
-    if ( !current_user_can( 'manage_options' ) ) {
1278
-        wp_die( __( 'You do not have permission to send reminder notification', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
1277
+    if (!current_user_can('manage_options')) {
1278
+        wp_die(__('You do not have permission to send reminder notification', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
1279 1279
     }
1280 1280
 
1281
-    $sent = wpinv_send_payment_reminder_notification( $invoice_id );
1281
+    $sent = wpinv_send_payment_reminder_notification($invoice_id);
1282 1282
     
1283 1283
     $status = $sent ? 'email_sent' : 'email_fail';
1284 1284
 
1285
-    $redirect = add_query_arg( array( 'wpinv-message' => $status, 'wpi_action' => false, 'invoice_id' => false ) );
1286
-    wp_redirect( $redirect );
1285
+    $redirect = add_query_arg(array('wpinv-message' => $status, 'wpi_action' => false, 'invoice_id' => false));
1286
+    wp_redirect($redirect);
1287 1287
     exit;
1288 1288
 }
1289
-add_action( 'wpinv_send_reminder', 'wpinv_send_overdue_reminder' );
1289
+add_action('wpinv_send_reminder', 'wpinv_send_overdue_reminder');
1290 1290
 
1291
-function wpinv_send_customer_note_email( $data ) {
1292
-    $invoice_id = !empty( $data['invoice_id'] ) ? absint( $data['invoice_id'] ) : NULL;
1291
+function wpinv_send_customer_note_email($data) {
1292
+    $invoice_id = !empty($data['invoice_id']) ? absint($data['invoice_id']) : NULL;
1293 1293
 
1294
-    if ( empty( $invoice_id ) ) {
1294
+    if (empty($invoice_id)) {
1295 1295
         return;
1296 1296
     }
1297 1297
 
1298
-    $sent = wpinv_user_note_notification( $invoice_id, $data );
1298
+    $sent = wpinv_user_note_notification($invoice_id, $data);
1299 1299
 }
1300
-add_action( 'wpinv_new_customer_note', 'wpinv_send_customer_note_email', 10, 1 );
1300
+add_action('wpinv_new_customer_note', 'wpinv_send_customer_note_email', 10, 1);
1301 1301
 
1302
-function wpinv_add_notes_to_invoice_email( $invoice, $email_type, $sent_to_admin ) {
1303
-    if ( !empty( $invoice ) && $email_type == 'user_invoice' && $invoice_notes = wpinv_get_invoice_notes( $invoice->ID, true ) ) {
1304
-        $date_format = get_option( 'date_format' );
1305
-        $time_format = get_option( 'time_format' );
1302
+function wpinv_add_notes_to_invoice_email($invoice, $email_type, $sent_to_admin) {
1303
+    if (!empty($invoice) && $email_type == 'user_invoice' && $invoice_notes = wpinv_get_invoice_notes($invoice->ID, true)) {
1304
+        $date_format = get_option('date_format');
1305
+        $time_format = get_option('time_format');
1306 1306
         ?>
1307 1307
         <div id="wpinv-email-notes">
1308
-            <h3 class="wpinv-notes-t"><?php echo apply_filters( 'wpinv_email_invoice_notes_title', __( 'Invoice Notes', 'invoicing' ) ); ?></h3>
1308
+            <h3 class="wpinv-notes-t"><?php echo apply_filters('wpinv_email_invoice_notes_title', __('Invoice Notes', 'invoicing')); ?></h3>
1309 1309
             <ol class="wpinv-notes-lists">
1310 1310
         <?php
1311
-        foreach ( $invoice_notes as $note ) {
1312
-            $note_time = strtotime( $note->comment_date );
1311
+        foreach ($invoice_notes as $note) {
1312
+            $note_time = strtotime($note->comment_date);
1313 1313
             ?>
1314 1314
             <li class="comment wpinv-note">
1315
-            <p class="wpinv-note-date meta"><?php printf( __( '%2$s at %3$s', 'invoicing' ), $note->comment_author, date_i18n( $date_format, $note_time ), date_i18n( $time_format, $note_time ), $note_time ); ?></p>
1316
-            <div class="wpinv-note-desc description"><?php echo wpautop( wptexturize( $note->comment_content ) ); ?></div>
1315
+            <p class="wpinv-note-date meta"><?php printf(__('%2$s at %3$s', 'invoicing'), $note->comment_author, date_i18n($date_format, $note_time), date_i18n($time_format, $note_time), $note_time); ?></p>
1316
+            <div class="wpinv-note-desc description"><?php echo wpautop(wptexturize($note->comment_content)); ?></div>
1317 1317
             </li>
1318 1318
             <?php
1319 1319
         }
@@ -1322,21 +1322,21 @@  discard block
 block discarded – undo
1322 1322
         <?php
1323 1323
     }
1324 1324
 }
1325
-add_action( 'wpinv_email_billing_details', 'wpinv_add_notes_to_invoice_email', 10, 3 );
1325
+add_action('wpinv_email_billing_details', 'wpinv_add_notes_to_invoice_email', 10, 3);
1326 1326
 
1327 1327
 function wpinv_email_payment_reminders() {
1328 1328
     global $wpi_auto_reminder;
1329
-    if ( !wpinv_get_option( 'email_overdue_active' ) ) {
1329
+    if (!wpinv_get_option('email_overdue_active')) {
1330 1330
         return;
1331 1331
     }
1332 1332
 
1333
-    if ( $reminder_days = wpinv_get_option( 'email_due_reminder_days' ) ) {
1334
-        $reminder_days  = is_array( $reminder_days ) ? array_values( $reminder_days ) : '';
1333
+    if ($reminder_days = wpinv_get_option('email_due_reminder_days')) {
1334
+        $reminder_days  = is_array($reminder_days) ? array_values($reminder_days) : '';
1335 1335
 
1336
-        if ( empty( $reminder_days ) ) {
1336
+        if (empty($reminder_days)) {
1337 1337
             return;
1338 1338
         }
1339
-        $reminder_days  = array_unique( array_map( 'absint', $reminder_days ) );
1339
+        $reminder_days = array_unique(array_map('absint', $reminder_days));
1340 1340
 
1341 1341
         $args = array(
1342 1342
             'post_type'     => 'wpi_invoice',
@@ -1346,7 +1346,7 @@  discard block
 block discarded – undo
1346 1346
             'meta_query'    => array(
1347 1347
                 array(
1348 1348
                     'key'       =>  '_wpinv_due_date',
1349
-                    'value'     =>  array( '', 'none' ),
1349
+                    'value'     =>  array('', 'none'),
1350 1350
                     'compare'   =>  'NOT IN',
1351 1351
                 )
1352 1352
             ),
@@ -1355,109 +1355,109 @@  discard block
 block discarded – undo
1355 1355
             'order'         => 'ASC',
1356 1356
         );
1357 1357
 
1358
-        $invoices = get_posts( $args );
1358
+        $invoices = get_posts($args);
1359 1359
 
1360
-        if ( empty( $invoices ) ) {
1360
+        if (empty($invoices)) {
1361 1361
             return;
1362 1362
         }
1363 1363
 
1364
-        $date_to_send   = array();
1364
+        $date_to_send = array();
1365 1365
 
1366
-        foreach ( $invoices as $id ) {
1367
-            $due_date = get_post_meta( $id, '_wpinv_due_date', true );
1366
+        foreach ($invoices as $id) {
1367
+            $due_date = get_post_meta($id, '_wpinv_due_date', true);
1368 1368
 
1369
-            foreach ( $reminder_days as $key => $days ) {
1370
-                if ( $days !== '' ) {
1371
-                    $date_to_send[$id][] = date_i18n( 'Y-m-d', strtotime( $due_date ) + ( $days * DAY_IN_SECONDS ) );
1369
+            foreach ($reminder_days as $key => $days) {
1370
+                if ($days !== '') {
1371
+                    $date_to_send[$id][] = date_i18n('Y-m-d', strtotime($due_date) + ($days * DAY_IN_SECONDS));
1372 1372
                 }
1373 1373
             }
1374 1374
         }
1375 1375
 
1376
-        $today              = date_i18n( 'Y-m-d' );
1376
+        $today              = date_i18n('Y-m-d');
1377 1377
         $wpi_auto_reminder  = true;
1378 1378
 
1379
-        foreach ( $date_to_send as $id => $values ) {
1380
-            if ( in_array( $today, $values ) ) {
1381
-                $sent = get_post_meta( $id, '_wpinv_reminder_sent', true );
1379
+        foreach ($date_to_send as $id => $values) {
1380
+            if (in_array($today, $values)) {
1381
+                $sent = get_post_meta($id, '_wpinv_reminder_sent', true);
1382 1382
 
1383
-                if ( isset( $sent ) && !empty( $sent ) ) {
1384
-                    if ( !in_array( $today, $sent ) ) {
1385
-                        do_action( 'wpinv_send_payment_reminder_notification', $id );
1383
+                if (isset($sent) && !empty($sent)) {
1384
+                    if (!in_array($today, $sent)) {
1385
+                        do_action('wpinv_send_payment_reminder_notification', $id);
1386 1386
                     }
1387 1387
                 } else {
1388
-                    do_action( 'wpinv_send_payment_reminder_notification', $id );
1388
+                    do_action('wpinv_send_payment_reminder_notification', $id);
1389 1389
                 }
1390 1390
             }
1391 1391
         }
1392 1392
 
1393
-        $wpi_auto_reminder  = false;
1393
+        $wpi_auto_reminder = false;
1394 1394
     }
1395 1395
 }
1396 1396
 
1397
-function wpinv_send_payment_reminder_notification( $invoice_id ) {
1397
+function wpinv_send_payment_reminder_notification($invoice_id) {
1398 1398
     $email_type = 'overdue';
1399
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
1399
+    if (!wpinv_email_is_enabled($email_type)) {
1400 1400
         return false;
1401 1401
     }
1402 1402
 
1403
-    $invoice    = wpinv_get_invoice( $invoice_id );
1404
-    if ( empty( $invoice ) ) {
1403
+    $invoice = wpinv_get_invoice($invoice_id);
1404
+    if (empty($invoice)) {
1405 1405
         return false;
1406 1406
     }
1407 1407
 
1408
-    if ( !$invoice->needs_payment() ) {
1408
+    if (!$invoice->needs_payment()) {
1409 1409
         return false;
1410 1410
     }
1411 1411
 
1412
-    $recipient  = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
1413
-    if ( !is_email( $recipient ) ) {
1412
+    $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
1413
+    if (!is_email($recipient)) {
1414 1414
         return false;
1415 1415
     }
1416 1416
 
1417
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
1418
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
1419
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
1420
-    $message_body   = wpinv_email_get_content( $email_type, $invoice_id, $invoice );
1421
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
1417
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
1418
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
1419
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
1420
+    $message_body   = wpinv_email_get_content($email_type, $invoice_id, $invoice);
1421
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
1422 1422
 
1423
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
1423
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
1424 1424
             'invoice'       => $invoice,
1425 1425
             'email_type'    => $email_type,
1426 1426
             'email_heading' => $email_heading,
1427 1427
             'sent_to_admin' => false,
1428 1428
             'plain_text'    => false,
1429 1429
             'message_body'  => $message_body
1430
-        ) );
1430
+        ));
1431 1431
 
1432
-    $content        = wpinv_email_format_text( $content, $invoice );
1432
+    $content = wpinv_email_format_text($content, $invoice);
1433 1433
 
1434
-    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
1435
-    if ( $sent ) {
1436
-        do_action( 'wpinv_payment_reminder_sent', $invoice_id, $invoice );
1434
+    $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
1435
+    if ($sent) {
1436
+        do_action('wpinv_payment_reminder_sent', $invoice_id, $invoice);
1437 1437
     }
1438 1438
 
1439 1439
     return $sent;
1440 1440
 }
1441
-add_action( 'wpinv_send_payment_reminder_notification', 'wpinv_send_payment_reminder_notification', 10, 1 );
1441
+add_action('wpinv_send_payment_reminder_notification', 'wpinv_send_payment_reminder_notification', 10, 1);
1442 1442
 
1443
-function wpinv_payment_reminder_sent( $invoice_id, $invoice ) {
1443
+function wpinv_payment_reminder_sent($invoice_id, $invoice) {
1444 1444
     global $wpi_auto_reminder;
1445 1445
 
1446
-    $sent = get_post_meta( $invoice_id, '_wpinv_reminder_sent', true );
1446
+    $sent = get_post_meta($invoice_id, '_wpinv_reminder_sent', true);
1447 1447
 
1448
-    if ( empty( $sent ) ) {
1448
+    if (empty($sent)) {
1449 1449
         $sent = array();
1450 1450
     }
1451
-    $sent[] = date_i18n( 'Y-m-d' );
1451
+    $sent[] = date_i18n('Y-m-d');
1452 1452
 
1453
-    update_post_meta( $invoice_id, '_wpinv_reminder_sent', $sent );
1453
+    update_post_meta($invoice_id, '_wpinv_reminder_sent', $sent);
1454 1454
 
1455
-    if ( $wpi_auto_reminder ) { // Auto reminder note.
1456
-        $note = __( 'Manual reminder sent to the user.', 'invoicing' );
1457
-        $invoice->add_note( $note, false, false, true );
1455
+    if ($wpi_auto_reminder) { // Auto reminder note.
1456
+        $note = __('Manual reminder sent to the user.', 'invoicing');
1457
+        $invoice->add_note($note, false, false, true);
1458 1458
     } else { // Menual reminder note.
1459
-        $note = __( 'Manual reminder sent to the user.', 'invoicing' );
1460
-        $invoice->add_note( $note );
1459
+        $note = __('Manual reminder sent to the user.', 'invoicing');
1460
+        $invoice->add_note($note);
1461 1461
     }
1462 1462
 }
1463
-add_action( 'wpinv_payment_reminder_sent', 'wpinv_payment_reminder_sent', 10, 2 );
1463
+add_action('wpinv_payment_reminder_sent', 'wpinv_payment_reminder_sent', 10, 2);
Please login to merge, or discard this patch.
includes/admin/admin-pages.php 1 patch
Spacing   +189 added lines, -189 removed lines patch added patch discarded remove patch
@@ -1,73 +1,73 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // MUST have WordPress.
3
-if ( !defined( 'WPINC' ) ) {
4
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
3
+if (!defined('WPINC')) {
4
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
5 5
 }
6 6
 
7
-add_action( 'admin_menu', 'wpinv_add_options_link', 10 );
7
+add_action('admin_menu', 'wpinv_add_options_link', 10);
8 8
 function wpinv_add_options_link() {
9 9
     global $menu;
10 10
 
11
-    if ( !(current_user_can( 'manage_invoicing' ) || current_user_can( 'manage_options' )) ) {
11
+    if (!(current_user_can('manage_invoicing') || current_user_can('manage_options'))) {
12 12
         return;
13 13
     }
14 14
 
15
-    $capability = apply_filters( 'invoicing_capability', 'manage_invoicing' );
15
+    $capability = apply_filters('invoicing_capability', 'manage_invoicing');
16 16
 
17
-    if ( current_user_can( 'manage_options' ) ) {
18
-        $menu[] = array( '', 'read', 'separator-wpinv', '', 'wp-menu-separator wpinv' );
17
+    if (current_user_can('manage_options')) {
18
+        $menu[] = array('', 'read', 'separator-wpinv', '', 'wp-menu-separator wpinv');
19 19
     }
20 20
 
21
-    $wpi_invoice = get_post_type_object( 'wpi_invoice' );
21
+    $wpi_invoice = get_post_type_object('wpi_invoice');
22 22
 
23
-    add_menu_page( __( 'Invoicing', 'invoicing' ), __( 'Invoicing', 'invoicing' ), $capability, 'wpinv', null, $wpi_invoice->menu_icon, '54.123460' );
23
+    add_menu_page(__('Invoicing', 'invoicing'), __('Invoicing', 'invoicing'), $capability, 'wpinv', null, $wpi_invoice->menu_icon, '54.123460');
24 24
 
25
-    $wpi_settings_page   = add_submenu_page( 'wpinv', __( 'Invoice Settings', 'invoicing' ), __( 'Settings', 'invoicing' ), $capability, 'wpinv-settings', 'wpinv_options_page' );
25
+    $wpi_settings_page = add_submenu_page('wpinv', __('Invoice Settings', 'invoicing'), __('Settings', 'invoicing'), $capability, 'wpinv-settings', 'wpinv_options_page');
26 26
 }
27 27
 
28
-add_action( 'admin_menu', 'wpinv_remove_admin_submenus', 999 );
28
+add_action('admin_menu', 'wpinv_remove_admin_submenus', 999);
29 29
 function wpinv_remove_admin_submenus() {
30
-    remove_submenu_page( 'edit.php?post_type=wpi_invoice', 'post-new.php?post_type=wpi_invoice' );
30
+    remove_submenu_page('edit.php?post_type=wpi_invoice', 'post-new.php?post_type=wpi_invoice');
31 31
 }
32 32
 
33
-add_filter( 'manage_wpi_discount_posts_columns', 'wpinv_discount_columns' );
34
-function wpinv_discount_columns( $existing_columns ) {
33
+add_filter('manage_wpi_discount_posts_columns', 'wpinv_discount_columns');
34
+function wpinv_discount_columns($existing_columns) {
35 35
     $columns                = array();
36 36
     $columns['cb']          = $existing_columns['cb'];
37
-    $columns['name']        = __( 'Name', 'invoicing' );
38
-    $columns['code']        = __( 'Code', 'invoicing' );
39
-    $columns['amount']      = __( 'Amount', 'invoicing' );
40
-    $columns['usage']       = __( 'Usage / Limit', 'invoicing' );
41
-    $columns['start_date']  = __( 'Start Date', 'invoicing' );
42
-    $columns['expiry_date'] = __( 'Expiry Date', 'invoicing' );
43
-    $columns['status']      = __( 'Status', 'invoicing' );
37
+    $columns['name']        = __('Name', 'invoicing');
38
+    $columns['code']        = __('Code', 'invoicing');
39
+    $columns['amount']      = __('Amount', 'invoicing');
40
+    $columns['usage']       = __('Usage / Limit', 'invoicing');
41
+    $columns['start_date']  = __('Start Date', 'invoicing');
42
+    $columns['expiry_date'] = __('Expiry Date', 'invoicing');
43
+    $columns['status']      = __('Status', 'invoicing');
44 44
 
45 45
     return $columns;
46 46
 }
47 47
 
48
-add_action( 'manage_wpi_discount_posts_custom_column', 'wpinv_discount_custom_column' );
49
-function wpinv_discount_custom_column( $column ) {
48
+add_action('manage_wpi_discount_posts_custom_column', 'wpinv_discount_custom_column');
49
+function wpinv_discount_custom_column($column) {
50 50
     global $post;
51 51
     
52 52
     $discount = $post;
53 53
 
54
-    switch ( $column ) {
54
+    switch ($column) {
55 55
         case 'name' :
56
-            echo get_the_title( $discount->ID );
56
+            echo get_the_title($discount->ID);
57 57
         break;
58 58
         case 'code' :
59
-            echo wpinv_get_discount_code( $discount->ID );
59
+            echo wpinv_get_discount_code($discount->ID);
60 60
         break;
61 61
         case 'amount' :
62
-            echo wpinv_format_discount_rate( wpinv_get_discount_type( $discount->ID ), wpinv_get_discount_amount( $discount->ID ) );
62
+            echo wpinv_format_discount_rate(wpinv_get_discount_type($discount->ID), wpinv_get_discount_amount($discount->ID));
63 63
         break;
64 64
         case 'usage_limit' :
65
-            echo wpinv_get_discount_uses( $discount->ID );
65
+            echo wpinv_get_discount_uses($discount->ID);
66 66
         break;
67 67
         case 'usage' :
68
-            $usage = wpinv_get_discount_uses( $discount->ID ) . ' / ';
69
-            if ( wpinv_get_discount_max_uses( $discount->ID ) ) {
70
-                $usage .= wpinv_get_discount_max_uses( $discount->ID );
68
+            $usage = wpinv_get_discount_uses($discount->ID) . ' / ';
69
+            if (wpinv_get_discount_max_uses($discount->ID)) {
70
+                $usage .= wpinv_get_discount_max_uses($discount->ID);
71 71
             } else {
72 72
                 $usage .= ' &infin;';
73 73
             }
@@ -75,8 +75,8 @@  discard block
 block discarded – undo
75 75
             echo $usage;
76 76
         break;
77 77
         case 'start_date' :
78
-            if ( $start_date = wpinv_get_discount_start_date( $discount->ID ) ) {
79
-                $value = date_i18n( get_option( 'date_format' ) . ' @ ' . get_option( 'time_format' ), strtotime( $start_date ) );
78
+            if ($start_date = wpinv_get_discount_start_date($discount->ID)) {
79
+                $value = date_i18n(get_option('date_format') . ' @ ' . get_option('time_format'), strtotime($start_date));
80 80
             } else {
81 81
                 $value = '-';
82 82
             }
@@ -84,163 +84,163 @@  discard block
 block discarded – undo
84 84
             echo $value;
85 85
         break;
86 86
         case 'expiry_date' :
87
-            if ( $expiration = wpinv_get_discount_expiration( $discount->ID ) ) {
88
-                $value = date_i18n( get_option( 'date_format' ) . ' @ ' . get_option( 'time_format' ), strtotime( $expiration ) );
87
+            if ($expiration = wpinv_get_discount_expiration($discount->ID)) {
88
+                $value = date_i18n(get_option('date_format') . ' @ ' . get_option('time_format'), strtotime($expiration));
89 89
             } else {
90
-                $value = __( 'Never', 'invoicing' );
90
+                $value = __('Never', 'invoicing');
91 91
             }
92 92
                 
93 93
             echo $value;
94 94
         break;
95 95
         break;
96 96
         case 'description' :
97
-            echo wp_kses_post( $post->post_excerpt );
97
+            echo wp_kses_post($post->post_excerpt);
98 98
         break;
99 99
         case 'status' :
100
-            $status = wpinv_is_discount_expired( $discount->ID ) ? 'expired' : $discount->post_status;
100
+            $status = wpinv_is_discount_expired($discount->ID) ? 'expired' : $discount->post_status;
101 101
             
102
-            echo wpinv_discount_status( $status );
102
+            echo wpinv_discount_status($status);
103 103
         break;
104 104
     }
105 105
 }
106 106
 
107
-add_filter( 'post_row_actions', 'wpinv_post_row_actions', 9999, 2 );
108
-function wpinv_post_row_actions( $actions, $post ) {
109
-    $post_type = !empty( $post->post_type ) ? $post->post_type : '';
107
+add_filter('post_row_actions', 'wpinv_post_row_actions', 9999, 2);
108
+function wpinv_post_row_actions($actions, $post) {
109
+    $post_type = !empty($post->post_type) ? $post->post_type : '';
110 110
     
111
-    if ( $post_type == 'wpi_invoice' ) {
111
+    if ($post_type == 'wpi_invoice') {
112 112
         $actions = array();
113 113
     }
114 114
     
115
-    if ( $post_type == 'wpi_discount' ) {
116
-        $actions = wpinv_discount_row_actions( $post, $actions );
115
+    if ($post_type == 'wpi_discount') {
116
+        $actions = wpinv_discount_row_actions($post, $actions);
117 117
     }
118 118
     
119 119
     return $actions;
120 120
 }
121 121
 
122
-function wpinv_discount_row_actions( $discount, $row_actions ) {
123
-    $row_actions  = array();
124
-    $edit_link = get_edit_post_link( $discount->ID );
125
-    $row_actions['edit'] = '<a href="' . esc_url( $edit_link ) . '">' . __( 'Edit', 'invoicing' ) . '</a>';
122
+function wpinv_discount_row_actions($discount, $row_actions) {
123
+    $row_actions = array();
124
+    $edit_link = get_edit_post_link($discount->ID);
125
+    $row_actions['edit'] = '<a href="' . esc_url($edit_link) . '">' . __('Edit', 'invoicing') . '</a>';
126 126
 
127
-    if( in_array( strtolower( $discount->post_status ),  array(  'publish' ) ) ) {
128
-        $row_actions['deactivate'] = '<a href="' . esc_url( wp_nonce_url( add_query_arg( array( 'wpi_action' => 'deactivate_discount', 'discount' => $discount->ID ) ), 'wpinv_discount_nonce' ) ) . '">' . __( 'Deactivate', 'invoicing' ) . '</a>';
129
-    } elseif( in_array( strtolower( $discount->post_status ),  array( 'pending', 'draft' ) ) ) {
130
-        $row_actions['activate'] = '<a href="' . esc_url( wp_nonce_url( add_query_arg( array( 'wpi_action' => 'activate_discount', 'discount' => $discount->ID ) ), 'wpinv_discount_nonce' ) ) . '">' . __( 'Activate', 'invoicing' ) . '</a>';
127
+    if (in_array(strtolower($discount->post_status), array('publish'))) {
128
+        $row_actions['deactivate'] = '<a href="' . esc_url(wp_nonce_url(add_query_arg(array('wpi_action' => 'deactivate_discount', 'discount' => $discount->ID)), 'wpinv_discount_nonce')) . '">' . __('Deactivate', 'invoicing') . '</a>';
129
+    } elseif (in_array(strtolower($discount->post_status), array('pending', 'draft'))) {
130
+        $row_actions['activate'] = '<a href="' . esc_url(wp_nonce_url(add_query_arg(array('wpi_action' => 'activate_discount', 'discount' => $discount->ID)), 'wpinv_discount_nonce')) . '">' . __('Activate', 'invoicing') . '</a>';
131 131
     }
132 132
 
133
-    if ( wpinv_get_discount_uses( $discount->ID ) > 0 ) {
134
-        if ( isset( $row_actions['delete'] ) ) {
135
-            unset( $row_actions['delete'] ); // Don't delete used discounts.
133
+    if (wpinv_get_discount_uses($discount->ID) > 0) {
134
+        if (isset($row_actions['delete'])) {
135
+            unset($row_actions['delete']); // Don't delete used discounts.
136 136
         }
137 137
     } else {
138
-        $row_actions['delete'] = '<a href="' . esc_url( wp_nonce_url( add_query_arg( array( 'wpi_action' => 'delete_discount', 'discount' => $discount->ID ) ), 'wpinv_discount_nonce' ) ) . '">' . __( 'Delete', 'invoicing' ) . '</a>';
138
+        $row_actions['delete'] = '<a href="' . esc_url(wp_nonce_url(add_query_arg(array('wpi_action' => 'delete_discount', 'discount' => $discount->ID)), 'wpinv_discount_nonce')) . '">' . __('Delete', 'invoicing') . '</a>';
139 139
     }
140 140
     
141 141
 
142
-    $row_actions = apply_filters( 'wpinv_discount_row_actions', $row_actions, $discount );
142
+    $row_actions = apply_filters('wpinv_discount_row_actions', $row_actions, $discount);
143 143
 
144 144
     return $row_actions;
145 145
 }
146 146
 
147
-add_filter( 'list_table_primary_column', 'wpinv_table_primary_column', 10, 2 );
148
-function wpinv_table_primary_column( $default, $screen_id ) {
149
-    if ( 'edit-wpi_invoice' === $screen_id ) {
147
+add_filter('list_table_primary_column', 'wpinv_table_primary_column', 10, 2);
148
+function wpinv_table_primary_column($default, $screen_id) {
149
+    if ('edit-wpi_invoice' === $screen_id) {
150 150
         return 'name';
151 151
     }
152 152
     
153 153
     return $default;
154 154
 }
155 155
 
156
-function wpinv_discount_bulk_actions( $actions, $display = false ) {    
157
-    if ( !$display ) {
156
+function wpinv_discount_bulk_actions($actions, $display = false) {    
157
+    if (!$display) {
158 158
         return array();
159 159
     }
160 160
     
161 161
     $actions = array(
162
-        'activate'   => __( 'Activate', 'invoicing' ),
163
-        'deactivate' => __( 'Deactivate', 'invoicing' ),
164
-        'delete'     => __( 'Delete', 'invoicing' ),
162
+        'activate'   => __('Activate', 'invoicing'),
163
+        'deactivate' => __('Deactivate', 'invoicing'),
164
+        'delete'     => __('Delete', 'invoicing'),
165 165
     );
166 166
     $two = '';
167 167
     $which = 'top';
168 168
     echo '</div><div class="alignleft actions bulkactions">';
169
-    echo '<label for="bulk-action-selector-' . esc_attr( $which ) . '" class="screen-reader-text">' . __( 'Select bulk action' ) . '</label>';
170
-    echo '<select name="action' . $two . '" id="bulk-action-selector-' . esc_attr( $which ) . "\">";
171
-    echo '<option value="-1">' . __( 'Bulk Actions' ) . "</option>";
169
+    echo '<label for="bulk-action-selector-' . esc_attr($which) . '" class="screen-reader-text">' . __('Select bulk action') . '</label>';
170
+    echo '<select name="action' . $two . '" id="bulk-action-selector-' . esc_attr($which) . "\">";
171
+    echo '<option value="-1">' . __('Bulk Actions') . "</option>";
172 172
 
173
-    foreach ( $actions as $name => $title ) {
173
+    foreach ($actions as $name => $title) {
174 174
         $class = 'edit' === $name ? ' class="hide-if-no-js"' : '';
175 175
 
176 176
         echo "" . '<option value="' . $name . '"' . $class . '>' . $title . "</option>";
177 177
     }
178 178
     echo "</select>";
179 179
 
180
-    submit_button( __( 'Apply' ), 'action', '', false, array( 'id' => "doaction$two" ) );
180
+    submit_button(__('Apply'), 'action', '', false, array('id' => "doaction$two"));
181 181
     
182 182
     echo '</div><div class="alignleft actions">';
183 183
 }
184
-add_filter( 'bulk_actions-edit-wpi_discount', 'wpinv_discount_bulk_actions', 10 );
184
+add_filter('bulk_actions-edit-wpi_discount', 'wpinv_discount_bulk_actions', 10);
185 185
 
186
-function wpinv_disable_months_dropdown( $disable, $post_type ) {
187
-    if ( $post_type == 'wpi_discount' ) {
186
+function wpinv_disable_months_dropdown($disable, $post_type) {
187
+    if ($post_type == 'wpi_discount') {
188 188
         $disable = true;
189 189
     }
190 190
     
191 191
     return $disable;
192 192
 }
193
-add_filter( 'disable_months_dropdown', 'wpinv_disable_months_dropdown', 10, 2 );
193
+add_filter('disable_months_dropdown', 'wpinv_disable_months_dropdown', 10, 2);
194 194
 
195 195
 function wpinv_restrict_manage_posts() {
196 196
     global $typenow;
197 197
 
198
-    if( 'wpi_discount' == $typenow ) {
198
+    if ('wpi_discount' == $typenow) {
199 199
         wpinv_discount_filters();
200 200
     }
201 201
 }
202
-add_action( 'restrict_manage_posts', 'wpinv_restrict_manage_posts', 10 );
202
+add_action('restrict_manage_posts', 'wpinv_restrict_manage_posts', 10);
203 203
 
204 204
 function wpinv_discount_filters() {
205
-    echo wpinv_discount_bulk_actions( array(), true );
205
+    echo wpinv_discount_bulk_actions(array(), true);
206 206
     
207 207
     ?>
208 208
     <select name="discount_type" id="dropdown_wpinv_discount_type">
209
-        <option value=""><?php _e( 'Show all types', 'invoicing' ); ?></option>
209
+        <option value=""><?php _e('Show all types', 'invoicing'); ?></option>
210 210
         <?php
211 211
             $types = wpinv_get_discount_types();
212 212
 
213
-            foreach ( $types as $name => $type ) {
214
-                echo '<option value="' . esc_attr( $name ) . '"';
213
+            foreach ($types as $name => $type) {
214
+                echo '<option value="' . esc_attr($name) . '"';
215 215
 
216
-                if ( isset( $_GET['discount_type'] ) )
217
-                    selected( $name, $_GET['discount_type'] );
216
+                if (isset($_GET['discount_type']))
217
+                    selected($name, $_GET['discount_type']);
218 218
 
219
-                echo '>' . esc_html__( $type, 'invoicing' ) . '</option>';
219
+                echo '>' . esc_html__($type, 'invoicing') . '</option>';
220 220
             }
221 221
         ?>
222 222
     </select>
223 223
     <?php
224 224
 }
225 225
 
226
-function wpinv_request( $vars ) {
226
+function wpinv_request($vars) {
227 227
     global $typenow, $wp_query, $wp_post_statuses;
228 228
 
229
-    if ( 'wpi_invoice' === $typenow ) {
230
-        if ( !isset( $vars['post_status'] ) ) {
229
+    if ('wpi_invoice' === $typenow) {
230
+        if (!isset($vars['post_status'])) {
231 231
             $post_statuses = wpinv_get_invoice_statuses();
232 232
 
233
-            foreach ( $post_statuses as $status => $value ) {
234
-                if ( isset( $wp_post_statuses[ $status ] ) && false === $wp_post_statuses[ $status ]->show_in_admin_all_list ) {
235
-                    unset( $post_statuses[ $status ] );
233
+            foreach ($post_statuses as $status => $value) {
234
+                if (isset($wp_post_statuses[$status]) && false === $wp_post_statuses[$status]->show_in_admin_all_list) {
235
+                    unset($post_statuses[$status]);
236 236
                 }
237 237
             }
238 238
 
239
-            $vars['post_status'] = array_keys( $post_statuses );
239
+            $vars['post_status'] = array_keys($post_statuses);
240 240
         }
241 241
         
242
-        if ( isset( $vars['orderby'] ) ) {
243
-            if ( 'amount' == $vars['orderby'] ) {
242
+        if (isset($vars['orderby'])) {
243
+            if ('amount' == $vars['orderby']) {
244 244
                 $vars = array_merge(
245 245
                     $vars,
246 246
                     array(
@@ -248,7 +248,7 @@  discard block
 block discarded – undo
248 248
                         'orderby'  => 'meta_value_num'
249 249
                     )
250 250
                 );
251
-            } else if ( 'customer' == $vars['orderby'] ) {
251
+            } else if ('customer' == $vars['orderby']) {
252 252
                 $vars = array_merge(
253 253
                     $vars,
254 254
                     array(
@@ -256,7 +256,7 @@  discard block
 block discarded – undo
256 256
                         'orderby'  => 'meta_value'
257 257
                     )
258 258
                 );
259
-            } else if ( 'number' == $vars['orderby'] ) {
259
+            } else if ('number' == $vars['orderby']) {
260 260
                 $vars = array_merge(
261 261
                     $vars,
262 262
                     array(
@@ -264,7 +264,7 @@  discard block
 block discarded – undo
264 264
                         'orderby'  => 'meta_value'
265 265
                     )
266 266
                 );
267
-            } else if ( 'payment_date' == $vars['orderby'] ) {
267
+            } else if ('payment_date' == $vars['orderby']) {
268 268
                 $vars = array_merge(
269 269
                     $vars,
270 270
                     array(
@@ -274,9 +274,9 @@  discard block
 block discarded – undo
274 274
                 );
275 275
             }
276 276
         }
277
-    } else if ( 'wpi_item' == $typenow ) {
277
+    } else if ('wpi_item' == $typenow) {
278 278
         // Check if 'orderby' is set to "price"
279
-        if ( isset( $vars['orderby'] ) && 'price' == $vars['orderby'] ) {
279
+        if (isset($vars['orderby']) && 'price' == $vars['orderby']) {
280 280
             $vars = array_merge(
281 281
                 $vars,
282 282
                 array(
@@ -287,7 +287,7 @@  discard block
 block discarded – undo
287 287
         }
288 288
 
289 289
         // Check if "orderby" is set to "vat_rule"
290
-        if ( isset( $vars['orderby'] ) && 'vat_rule' == $vars['orderby'] ) {
290
+        if (isset($vars['orderby']) && 'vat_rule' == $vars['orderby']) {
291 291
             $vars = array_merge(
292 292
                 $vars,
293 293
                 array(
@@ -298,7 +298,7 @@  discard block
 block discarded – undo
298 298
         }
299 299
 
300 300
         // Check if "orderby" is set to "vat_class"
301
-        if ( isset( $vars['orderby'] ) && 'vat_class' == $vars['orderby'] ) {
301
+        if (isset($vars['orderby']) && 'vat_class' == $vars['orderby']) {
302 302
             $vars = array_merge(
303 303
                 $vars,
304 304
                 array(
@@ -309,7 +309,7 @@  discard block
 block discarded – undo
309 309
         }
310 310
         
311 311
         // Check if "orderby" is set to "type"
312
-        if ( isset( $vars['orderby'] ) && 'type' == $vars['orderby'] ) {
312
+        if (isset($vars['orderby']) && 'type' == $vars['orderby']) {
313 313
             $vars = array_merge(
314 314
                 $vars,
315 315
                 array(
@@ -320,7 +320,7 @@  discard block
 block discarded – undo
320 320
         }
321 321
         
322 322
         // Check if "orderby" is set to "recurring"
323
-        if ( isset( $vars['orderby'] ) && 'recurring' == $vars['orderby'] ) {
323
+        if (isset($vars['orderby']) && 'recurring' == $vars['orderby']) {
324 324
             $vars = array_merge(
325 325
                 $vars,
326 326
                 array(
@@ -330,120 +330,120 @@  discard block
 block discarded – undo
330 330
             );
331 331
         }
332 332
 
333
-        $meta_query = !empty( $vars['meta_query'] ) ? $vars['meta_query'] : array();
333
+        $meta_query = !empty($vars['meta_query']) ? $vars['meta_query'] : array();
334 334
         // Filter vat rule type
335
-        if ( isset( $_GET['vat_rule'] ) && $_GET['vat_rule'] !== '' ) {
335
+        if (isset($_GET['vat_rule']) && $_GET['vat_rule'] !== '') {
336 336
             $meta_query[] = array(
337 337
                     'key'   => '_wpinv_vat_rule',
338
-                    'value' => sanitize_text_field( $_GET['vat_rule'] ),
338
+                    'value' => sanitize_text_field($_GET['vat_rule']),
339 339
                     'compare' => '='
340 340
                 );
341 341
         }
342 342
         
343 343
         // Filter vat class
344
-        if ( isset( $_GET['vat_class'] ) && $_GET['vat_class'] !== '' ) {
344
+        if (isset($_GET['vat_class']) && $_GET['vat_class'] !== '') {
345 345
             $meta_query[] = array(
346 346
                     'key'   => '_wpinv_vat_class',
347
-                    'value' => sanitize_text_field( $_GET['vat_class'] ),
347
+                    'value' => sanitize_text_field($_GET['vat_class']),
348 348
                     'compare' => '='
349 349
                 );
350 350
         }
351 351
         
352 352
         // Filter item type
353
-        if ( isset( $_GET['type'] ) && $_GET['type'] !== '' ) {
353
+        if (isset($_GET['type']) && $_GET['type'] !== '') {
354 354
             $meta_query[] = array(
355 355
                     'key'   => '_wpinv_type',
356
-                    'value' => sanitize_text_field( $_GET['type'] ),
356
+                    'value' => sanitize_text_field($_GET['type']),
357 357
                     'compare' => '='
358 358
                 );
359 359
         }
360 360
         
361
-        if ( !empty( $meta_query ) ) {
361
+        if (!empty($meta_query)) {
362 362
             $vars['meta_query'] = $meta_query;
363 363
         }
364
-    } else if ( 'wpi_discount' == $typenow ) {
365
-        $meta_query = !empty( $vars['meta_query'] ) ? $vars['meta_query'] : array();
364
+    } else if ('wpi_discount' == $typenow) {
365
+        $meta_query = !empty($vars['meta_query']) ? $vars['meta_query'] : array();
366 366
         // Filter vat rule type
367
-        if ( isset( $_GET['discount_type'] ) && $_GET['discount_type'] !== '' ) {
367
+        if (isset($_GET['discount_type']) && $_GET['discount_type'] !== '') {
368 368
             $meta_query[] = array(
369 369
                     'key'   => '_wpi_discount_type',
370
-                    'value' => sanitize_text_field( $_GET['discount_type'] ),
370
+                    'value' => sanitize_text_field($_GET['discount_type']),
371 371
                     'compare' => '='
372 372
                 );
373 373
         }
374 374
         
375
-        if ( !empty( $meta_query ) ) {
375
+        if (!empty($meta_query)) {
376 376
             $vars['meta_query'] = $meta_query;
377 377
         }
378 378
     }
379 379
 
380 380
     return $vars;
381 381
 }
382
-add_filter( 'request', 'wpinv_request' );
382
+add_filter('request', 'wpinv_request');
383 383
 
384 384
 function wpinv_options_page() {
385
-    $page       = isset( $_GET['page'] )                ? strtolower( $_GET['page'] )               : false;
385
+    $page = isset($_GET['page']) ? strtolower($_GET['page']) : false;
386 386
     
387
-    if ( $page !== 'wpinv-settings' ) {
387
+    if ($page !== 'wpinv-settings') {
388 388
         return;
389 389
     }
390 390
     
391 391
     $settings_tabs = wpinv_get_settings_tabs();
392 392
     $settings_tabs = empty($settings_tabs) ? array() : $settings_tabs;
393
-    $active_tab    = isset( $_GET['tab'] ) && array_key_exists( $_GET['tab'], $settings_tabs ) ? sanitize_text_field( $_GET['tab'] ) : 'general';
394
-    $sections      = wpinv_get_settings_tab_sections( $active_tab );
393
+    $active_tab    = isset($_GET['tab']) && array_key_exists($_GET['tab'], $settings_tabs) ? sanitize_text_field($_GET['tab']) : 'general';
394
+    $sections      = wpinv_get_settings_tab_sections($active_tab);
395 395
     $key           = 'main';
396 396
 
397
-    if ( is_array( $sections ) ) {
398
-        $key = key( $sections );
397
+    if (is_array($sections)) {
398
+        $key = key($sections);
399 399
     }
400 400
 
401
-    $registered_sections = wpinv_get_settings_tab_sections( $active_tab );
402
-    $section             = isset( $_GET['section'] ) && ! empty( $registered_sections ) && array_key_exists( $_GET['section'], $registered_sections ) ? $_GET['section'] : $key;
401
+    $registered_sections = wpinv_get_settings_tab_sections($active_tab);
402
+    $section             = isset($_GET['section']) && !empty($registered_sections) && array_key_exists($_GET['section'], $registered_sections) ? $_GET['section'] : $key;
403 403
     ob_start();
404 404
     ?>
405 405
     <div class="wrap">
406 406
         <h1 class="nav-tab-wrapper">
407 407
             <?php
408
-            foreach( wpinv_get_settings_tabs() as $tab_id => $tab_name ) {
409
-                $tab_url = add_query_arg( array(
408
+            foreach (wpinv_get_settings_tabs() as $tab_id => $tab_name) {
409
+                $tab_url = add_query_arg(array(
410 410
                     'settings-updated' => false,
411 411
                     'tab' => $tab_id,
412
-                ) );
412
+                ));
413 413
 
414 414
                 // Remove the section from the tabs so we always end up at the main section
415
-                $tab_url = remove_query_arg( 'section', $tab_url );
416
-                $tab_url = remove_query_arg( 'wpi_sub', $tab_url );
415
+                $tab_url = remove_query_arg('section', $tab_url);
416
+                $tab_url = remove_query_arg('wpi_sub', $tab_url);
417 417
 
418 418
                 $active = $active_tab == $tab_id ? ' nav-tab-active' : '';
419 419
 
420
-                echo '<a href="' . esc_url( $tab_url ) . '" title="' . esc_attr( $tab_name ) . '" class="nav-tab' . $active . '">';
421
-                    echo esc_html( $tab_name );
420
+                echo '<a href="' . esc_url($tab_url) . '" title="' . esc_attr($tab_name) . '" class="nav-tab' . $active . '">';
421
+                    echo esc_html($tab_name);
422 422
                 echo '</a>';
423 423
             }
424 424
             ?>
425 425
         </h1>
426 426
         <?php
427
-        $number_of_sections = count( $sections );
427
+        $number_of_sections = count($sections);
428 428
         $number = 0;
429
-        if ( $number_of_sections > 1 ) {
429
+        if ($number_of_sections > 1) {
430 430
             echo '<div><ul class="subsubsub">';
431
-            foreach( $sections as $section_id => $section_name ) {
431
+            foreach ($sections as $section_id => $section_name) {
432 432
                 echo '<li>';
433 433
                 $number++;
434
-                $tab_url = add_query_arg( array(
434
+                $tab_url = add_query_arg(array(
435 435
                     'settings-updated' => false,
436 436
                     'tab' => $active_tab,
437 437
                     'section' => $section_id
438
-                ) );
439
-                $tab_url = remove_query_arg( 'wpi_sub', $tab_url );
438
+                ));
439
+                $tab_url = remove_query_arg('wpi_sub', $tab_url);
440 440
                 $class = '';
441
-                if ( $section == $section_id ) {
441
+                if ($section == $section_id) {
442 442
                     $class = 'current';
443 443
                 }
444
-                echo '<a class="' . $class . '" href="' . esc_url( $tab_url ) . '">' . $section_name . '</a>';
444
+                echo '<a class="' . $class . '" href="' . esc_url($tab_url) . '">' . $section_name . '</a>';
445 445
 
446
-                if ( $number != $number_of_sections ) {
446
+                if ($number != $number_of_sections) {
447 447
                     echo ' | ';
448 448
                 }
449 449
                 echo '</li>';
@@ -455,19 +455,19 @@  discard block
 block discarded – undo
455 455
             <form method="post" action="options.php">
456 456
                 <table class="form-table">
457 457
                 <?php
458
-                settings_fields( 'wpinv_settings' );
458
+                settings_fields('wpinv_settings');
459 459
 
460
-                if ( 'main' === $section ) {
461
-                    do_action( 'wpinv_settings_tab_top', $active_tab );
460
+                if ('main' === $section) {
461
+                    do_action('wpinv_settings_tab_top', $active_tab);
462 462
                 }
463 463
 
464
-                do_action( 'wpinv_settings_tab_top_' . $active_tab . '_' . $section, $active_tab, $section );
465
-                do_settings_sections( 'wpinv_settings_' . $active_tab . '_' . $section, $active_tab, $section );
466
-                do_action( 'wpinv_settings_tab_bottom_' . $active_tab . '_' . $section, $active_tab, $section );
464
+                do_action('wpinv_settings_tab_top_' . $active_tab . '_' . $section, $active_tab, $section);
465
+                do_settings_sections('wpinv_settings_' . $active_tab . '_' . $section, $active_tab, $section);
466
+                do_action('wpinv_settings_tab_bottom_' . $active_tab . '_' . $section, $active_tab, $section);
467 467
 
468 468
                 // For backwards compatibility
469
-                if ( 'main' === $section ) {
470
-                    do_action( 'wpinv_settings_tab_bottom', $active_tab );
469
+                if ('main' === $section) {
470
+                    do_action('wpinv_settings_tab_bottom', $active_tab);
471 471
                 }
472 472
                 ?>
473 473
                 </table>
@@ -480,53 +480,53 @@  discard block
 block discarded – undo
480 480
     echo $content;
481 481
 }
482 482
 
483
-function wpinv_item_type_class( $classes, $class, $post_id ) {
483
+function wpinv_item_type_class($classes, $class, $post_id) {
484 484
     global $pagenow, $typenow;
485 485
 
486
-    if ( $pagenow == 'edit.php' && $typenow == 'wpi_item' && get_post_type( $post_id ) == $typenow ) {
487
-        if ( $type = get_post_meta( $post_id, '_wpinv_type', true ) ) {
488
-            $classes[] = 'wpi-type-' . sanitize_html_class( $type );
486
+    if ($pagenow == 'edit.php' && $typenow == 'wpi_item' && get_post_type($post_id) == $typenow) {
487
+        if ($type = get_post_meta($post_id, '_wpinv_type', true)) {
488
+            $classes[] = 'wpi-type-' . sanitize_html_class($type);
489 489
         }
490 490
         
491
-        if ( !wpinv_item_is_editable( $post_id ) ) {
491
+        if (!wpinv_item_is_editable($post_id)) {
492 492
             $classes[] = 'wpi-editable-n';
493 493
         }
494 494
     }
495 495
     return $classes;
496 496
 }
497
-add_filter( 'post_class', 'wpinv_item_type_class', 10, 3 );
497
+add_filter('post_class', 'wpinv_item_type_class', 10, 3);
498 498
 
499 499
 function wpinv_check_quick_edit() {
500 500
     global $pagenow, $current_screen, $wpinv_item_screen;
501 501
 
502
-    if ( $pagenow == 'edit.php' && !empty( $current_screen->post_type ) ) {
503
-        if ( empty( $wpinv_item_screen ) ) {
504
-            if ( $current_screen->post_type == 'wpi_item' ) {
502
+    if ($pagenow == 'edit.php' && !empty($current_screen->post_type)) {
503
+        if (empty($wpinv_item_screen)) {
504
+            if ($current_screen->post_type == 'wpi_item') {
505 505
                 $wpinv_item_screen = 'y';
506 506
             } else {
507 507
                 $wpinv_item_screen = 'n';
508 508
             }
509 509
         }
510 510
 
511
-        if ( $wpinv_item_screen == 'y' && $pagenow == 'edit.php' ) {
512
-            add_filter( 'post_row_actions', 'wpinv_item_disable_quick_edit', 10, 2 );
513
-            add_filter( 'page_row_actions', 'wpinv_item_disable_quick_edit', 10, 2 );
511
+        if ($wpinv_item_screen == 'y' && $pagenow == 'edit.php') {
512
+            add_filter('post_row_actions', 'wpinv_item_disable_quick_edit', 10, 2);
513
+            add_filter('page_row_actions', 'wpinv_item_disable_quick_edit', 10, 2);
514 514
         }
515 515
     }
516 516
 }
517
-add_action( 'admin_head', 'wpinv_check_quick_edit', 10 );
517
+add_action('admin_head', 'wpinv_check_quick_edit', 10);
518 518
 
519
-function wpinv_item_disable_quick_edit( $actions = array(), $row = null ) {
520
-    if ( isset( $actions['inline hide-if-no-js'] ) ) {
521
-        unset( $actions['inline hide-if-no-js'] );
519
+function wpinv_item_disable_quick_edit($actions = array(), $row = null) {
520
+    if (isset($actions['inline hide-if-no-js'])) {
521
+        unset($actions['inline hide-if-no-js']);
522 522
     }
523 523
     
524
-    if ( !empty( $row->post_type ) && $row->post_type == 'wpi_item' && !wpinv_item_is_editable( $row ) ) {
525
-        if ( isset( $actions['trash'] ) ) {
526
-            unset( $actions['trash'] );
524
+    if (!empty($row->post_type) && $row->post_type == 'wpi_item' && !wpinv_item_is_editable($row)) {
525
+        if (isset($actions['trash'])) {
526
+            unset($actions['trash']);
527 527
         }
528
-        if ( isset( $actions['delete'] ) ) {
529
-            unset( $actions['delete'] );
528
+        if (isset($actions['delete'])) {
529
+            unset($actions['delete']);
530 530
         }
531 531
     }
532 532
 
@@ -543,19 +543,19 @@  discard block
 block discarded – undo
543 543
  * @param int $post_parent (default: 0) Parent for the new page
544 544
  * @return int page ID
545 545
  */
546
-function wpinv_create_page( $slug, $option = '', $page_title = '', $page_content = '', $post_parent = 0 ) {
546
+function wpinv_create_page($slug, $option = '', $page_title = '', $page_content = '', $post_parent = 0) {
547 547
     global $wpdb;
548 548
 
549
-    $option_value = wpinv_get_option( $option );
549
+    $option_value = wpinv_get_option($option);
550 550
 
551
-    if ( $option_value > 0 && ( $page_object = get_post( $option_value ) ) ) {
552
-        if ( 'page' === $page_object->post_type && ! in_array( $page_object->post_status, array( 'pending', 'trash', 'future', 'auto-draft' ) ) ) {
551
+    if ($option_value > 0 && ($page_object = get_post($option_value))) {
552
+        if ('page' === $page_object->post_type && !in_array($page_object->post_status, array('pending', 'trash', 'future', 'auto-draft'))) {
553 553
             // Valid page is already in place
554 554
             return $page_object->ID;
555 555
         }
556 556
     }
557 557
 
558
-    if(!empty($post_parent)){
558
+    if (!empty($post_parent)) {
559 559
         $page = get_page_by_path($post_parent);
560 560
         if ($page) {
561 561
             $post_parent = $page->ID;
@@ -564,40 +564,40 @@  discard block
 block discarded – undo
564 564
         }
565 565
     }
566 566
 
567
-    if ( strlen( $page_content ) > 0 ) {
567
+    if (strlen($page_content) > 0) {
568 568
         // Search for an existing page with the specified page content (typically a shortcode)
569
-        $valid_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' ) AND post_content LIKE %s LIMIT 1;", "%{$page_content}%" ) );
569
+        $valid_page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' ) AND post_content LIKE %s LIMIT 1;", "%{$page_content}%"));
570 570
     } else {
571 571
         // Search for an existing page with the specified page slug
572
-        $valid_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' )  AND post_name = %s LIMIT 1;", $slug ) );
572
+        $valid_page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' )  AND post_name = %s LIMIT 1;", $slug));
573 573
     }
574 574
 
575
-    $valid_page_found = apply_filters( 'wpinv_create_page_id', $valid_page_found, $slug, $page_content );
575
+    $valid_page_found = apply_filters('wpinv_create_page_id', $valid_page_found, $slug, $page_content);
576 576
 
577
-    if ( $valid_page_found ) {
578
-        if ( $option ) {
579
-            wpinv_update_option( $option, $valid_page_found );
577
+    if ($valid_page_found) {
578
+        if ($option) {
579
+            wpinv_update_option($option, $valid_page_found);
580 580
         }
581 581
         return $valid_page_found;
582 582
     }
583 583
 
584 584
     // Search for a matching valid trashed page
585
-    if ( strlen( $page_content ) > 0 ) {
585
+    if (strlen($page_content) > 0) {
586 586
         // Search for an existing page with the specified page content (typically a shortcode)
587
-        $trashed_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_content LIKE %s LIMIT 1;", "%{$page_content}%" ) );
587
+        $trashed_page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_content LIKE %s LIMIT 1;", "%{$page_content}%"));
588 588
     } else {
589 589
         // Search for an existing page with the specified page slug
590
-        $trashed_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_name = %s LIMIT 1;", $slug ) );
590
+        $trashed_page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_name = %s LIMIT 1;", $slug));
591 591
     }
592 592
 
593
-    if ( $trashed_page_found ) {
593
+    if ($trashed_page_found) {
594 594
         $page_id   = $trashed_page_found;
595 595
         $page_data = array(
596 596
             'ID'             => $page_id,
597 597
             'post_status'    => 'publish',
598 598
             'post_parent'    => $post_parent,
599 599
         );
600
-        wp_update_post( $page_data );
600
+        wp_update_post($page_data);
601 601
     } else {
602 602
         $page_data = array(
603 603
             'post_status'    => 'publish',
@@ -609,11 +609,11 @@  discard block
 block discarded – undo
609 609
             'post_parent'    => $post_parent,
610 610
             'comment_status' => 'closed',
611 611
         );
612
-        $page_id = wp_insert_post( $page_data );
612
+        $page_id = wp_insert_post($page_data);
613 613
     }
614 614
 
615
-    if ( $option ) {
616
-        wpinv_update_option( $option, (int)$page_id );
615
+    if ($option) {
616
+        wpinv_update_option($option, (int)$page_id);
617 617
     }
618 618
 
619 619
     return $page_id;
Please login to merge, or discard this patch.