Passed
Pull Request — master (#47)
by Kiran
04:17
created
includes/gateways/authorizenet.php 1 patch
Spacing   +211 added lines, -211 removed lines patch added patch discarded remove patch
@@ -1,60 +1,60 @@  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_filter( 'wpinv_authorizenet_support_subscription', '__return_true' );
5
+add_filter('wpinv_authorizenet_support_subscription', '__return_true');
6 6
 
7
-function wpinv_authorizenet_cc_form( $invoice_id ) {
8
-    $invoice = wpinv_get_invoice( $invoice_id );
9
-    $cc_owner = !empty( $invoice ) ? esc_attr( $invoice->get_user_full_name() ) : '';
7
+function wpinv_authorizenet_cc_form($invoice_id) {
8
+    $invoice = wpinv_get_invoice($invoice_id);
9
+    $cc_owner = !empty($invoice) ? esc_attr($invoice->get_user_full_name()) : '';
10 10
     ?>
11 11
     <div id="authorizenet_cc_form" class="form-horizontal wpi-cc-form panel panel-default">
12
-        <div class="panel-heading"><h3 class="panel-title"><?php _e( 'Card Details', 'invoicing' ) ;?></h3></div>
12
+        <div class="panel-heading"><h3 class="panel-title"><?php _e('Card Details', 'invoicing'); ?></h3></div>
13 13
         <div class="panel-body">
14 14
             <div class="form-group required">
15
-              <label for="auth-input-cc-owner" class="col-sm-4 control-label"><?php _e( 'Card Owner', 'invoicing' ) ;?></label>
15
+              <label for="auth-input-cc-owner" class="col-sm-4 control-label"><?php _e('Card Owner', 'invoicing'); ?></label>
16 16
               <div class="col-sm-8">
17
-                <input type="text" class="form-control" id="auth-input-cc-owner" placeholder="<?php esc_attr_e( 'Card Owner', 'invoicing' ) ;?>" value="<?php echo $cc_owner;?>" name="authorizenet[cc_owner]">
17
+                <input type="text" class="form-control" id="auth-input-cc-owner" placeholder="<?php esc_attr_e('Card Owner', 'invoicing'); ?>" value="<?php echo $cc_owner; ?>" name="authorizenet[cc_owner]">
18 18
               </div>
19 19
             </div>
20 20
             <div class="form-group required">
21
-              <label for="auth-input-cc-number" class="col-sm-4 control-label"><?php _e( 'Card Number', 'invoicing' ) ;?></label>
21
+              <label for="auth-input-cc-number" class="col-sm-4 control-label"><?php _e('Card Number', 'invoicing'); ?></label>
22 22
               <div class="col-sm-8">
23
-                <input type="text" class="form-control" id="auth-input-cc-number" placeholder="<?php esc_attr_e( 'Card Number', 'invoicing' ) ;?>" value="" name="authorizenet[cc_number]">
23
+                <input type="text" class="form-control" id="auth-input-cc-number" placeholder="<?php esc_attr_e('Card Number', 'invoicing'); ?>" value="" name="authorizenet[cc_number]">
24 24
               </div>
25 25
             </div>
26 26
             <div class="form-group required">
27
-              <label for="auth-input-cc-expire-date" class="col-sm-4 control-label"><?php _e( 'Card Expiry Date', 'invoicing' ) ;?></label>
27
+              <label for="auth-input-cc-expire-date" class="col-sm-4 control-label"><?php _e('Card Expiry Date', 'invoicing'); ?></label>
28 28
               <div class="col-sm-2">
29 29
                 <select class="form-control" id="auth-input-cc-expire-date" name="authorizenet[cc_expire_month]">
30
-                    <?php for ( $i = 1; $i <= 12; $i++ ) { $value = str_pad( $i, 2, '0', STR_PAD_LEFT ); ?>
31
-                    <option value="<?php echo $value;?>"><?php echo $value;?></option>
30
+                    <?php for ($i = 1; $i <= 12; $i++) { $value = str_pad($i, 2, '0', STR_PAD_LEFT); ?>
31
+                    <option value="<?php echo $value; ?>"><?php echo $value; ?></option>
32 32
                     <?php } ?>
33 33
                 </select>
34 34
                </div>
35 35
                <div class="col-sm-2">
36 36
                 <select class="form-control" name="authorizenet[cc_expire_year]">
37
-                    <?php $year = date( 'Y' ); for ( $i = $year; $i <= ( $year + 10 ); $i++ ) { ?>
38
-                    <option value="<?php echo $i;?>"><?php echo $i;?></option>
37
+                    <?php $year = date('Y'); for ($i = $year; $i <= ($year + 10); $i++) { ?>
38
+                    <option value="<?php echo $i; ?>"><?php echo $i; ?></option>
39 39
                     <?php } ?>
40 40
                 </select>
41 41
               </div>
42 42
             </div>
43 43
             <div class="form-group required">
44
-              <label for="auth-input-cc-cvv2" class="col-sm-4 control-label"><?php _e( 'Card Security Code (CVV2)', 'invoicing' ) ;?></label>
44
+              <label for="auth-input-cc-cvv2" class="col-sm-4 control-label"><?php _e('Card Security Code (CVV2)', 'invoicing'); ?></label>
45 45
               <div class="col-sm-8">
46
-                <input type="text" class="form-control" id="auth-input-cc-cvv2" placeholder="<?php esc_attr_e( 'Card Security Code (CVV2)', 'invoicing' ) ;?>" value="" name="authorizenet[cc_cvv2]"">
46
+                <input type="text" class="form-control" id="auth-input-cc-cvv2" placeholder="<?php esc_attr_e('Card Security Code (CVV2)', 'invoicing'); ?>" value="" name="authorizenet[cc_cvv2]"">
47 47
               </div>
48 48
             </div>
49 49
       </div>
50 50
     </div>
51 51
     <?php
52 52
 }
53
-add_action( 'wpinv_authorizenet_cc_form', 'wpinv_authorizenet_cc_form', 10, 1 );
53
+add_action('wpinv_authorizenet_cc_form', 'wpinv_authorizenet_cc_form', 10, 1);
54 54
 
55
-function wpinv_process_authorizenet_payment( $purchase_data ) {
56
-    if( ! wp_verify_nonce( $purchase_data['gateway_nonce'], 'wpi-gateway' ) ) {
57
-        wp_die( __( 'Nonce verification has failed', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
55
+function wpinv_process_authorizenet_payment($purchase_data) {
56
+    if (!wp_verify_nonce($purchase_data['gateway_nonce'], 'wpi-gateway')) {
57
+        wp_die(__('Nonce verification has failed', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
58 58
     }
59 59
     
60 60
     // Collect payment data
@@ -72,10 +72,10 @@  discard block
 block discarded – undo
72 72
     );
73 73
 
74 74
     // Record the pending payment
75
-    $invoice = wpinv_get_invoice( $purchase_data['invoice_id'] );
75
+    $invoice = wpinv_get_invoice($purchase_data['invoice_id']);
76 76
 
77
-    if ( !empty( $invoice ) ) {
78
-        $authorizenet_card  = !empty( $_POST['authorizenet'] ) ? $_POST['authorizenet'] : array();
77
+    if (!empty($invoice)) {
78
+        $authorizenet_card  = !empty($_POST['authorizenet']) ? $_POST['authorizenet'] : array();
79 79
         $card_defaults      = array(
80 80
             'cc_owner'          => $invoice->get_user_full_name(),
81 81
             'cc_number'         => false,
@@ -83,174 +83,174 @@  discard block
 block discarded – undo
83 83
             'cc_expire_year'    => false,
84 84
             'cc_cvv2'           => false,
85 85
         );
86
-        $authorizenet_card = wp_parse_args( $authorizenet_card, $card_defaults );
86
+        $authorizenet_card = wp_parse_args($authorizenet_card, $card_defaults);
87 87
         
88
-        if ( empty( $authorizenet_card['cc_owner'] ) ) {
89
-            wpinv_set_error( 'empty_card_name', __( 'You must enter the name on your card!', 'invoicing'));
88
+        if (empty($authorizenet_card['cc_owner'])) {
89
+            wpinv_set_error('empty_card_name', __('You must enter the name on your card!', 'invoicing'));
90 90
         }
91
-        if ( empty( $authorizenet_card['cc_number'] ) ) {
92
-            wpinv_set_error( 'empty_card', __( 'You must enter a card number!', 'invoicing'));
91
+        if (empty($authorizenet_card['cc_number'])) {
92
+            wpinv_set_error('empty_card', __('You must enter a card number!', 'invoicing'));
93 93
         }
94
-        if ( empty( $authorizenet_card['cc_expire_month'] ) ) {
95
-            wpinv_set_error( 'empty_month', __( 'You must enter an card expiration month!', 'invoicing'));
94
+        if (empty($authorizenet_card['cc_expire_month'])) {
95
+            wpinv_set_error('empty_month', __('You must enter an card expiration month!', 'invoicing'));
96 96
         }
97
-        if ( empty( $authorizenet_card['cc_expire_year'] ) ) {
98
-            wpinv_set_error( 'empty_year', __( 'You must enter an card expiration year!', 'invoicing'));
97
+        if (empty($authorizenet_card['cc_expire_year'])) {
98
+            wpinv_set_error('empty_year', __('You must enter an card expiration year!', 'invoicing'));
99 99
         }
100
-        if ( empty( $authorizenet_card['cc_cvv2'] ) ) {
101
-            wpinv_set_error( 'empty_cvv2', __( 'You must enter a valid CVV2!', 'invoicing' ) );
100
+        if (empty($authorizenet_card['cc_cvv2'])) {
101
+            wpinv_set_error('empty_cvv2', __('You must enter a valid CVV2!', 'invoicing'));
102 102
         }
103 103
         
104 104
         $errors = wpinv_get_errors();
105 105
     
106
-        if ( empty( $errors ) ) {
106
+        if (empty($errors)) {
107 107
             $invoice_id = $invoice->ID;
108 108
             $quantities_enabled = wpinv_item_quantities_enabled();
109 109
             $use_taxes          = wpinv_use_taxes();
110 110
             
111 111
             $authorizeAIM = wpinv_authorizenet_AIM();
112
-            $authorizeAIM->first_name       = wpinv_utf8_substr( $invoice->get_first_name(), 0, 50 );
113
-            $authorizeAIM->last_name        = wpinv_utf8_substr( $invoice->get_last_name(), 0, 50 );
114
-            $authorizeAIM->company          = wpinv_utf8_substr( $invoice->company, 0, 50 );
115
-            $authorizeAIM->address          = wpinv_utf8_substr( wp_strip_all_tags( $invoice->get_address(), true ), 0, 60 );
116
-            $authorizeAIM->city             = wpinv_utf8_substr( $invoice->city, 0, 40 );
117
-            $authorizeAIM->state            = wpinv_utf8_substr( $invoice->state, 0, 40 );
118
-            $authorizeAIM->zip              = wpinv_utf8_substr( $invoice->zip, 0, 40 );
119
-            $authorizeAIM->country          = wpinv_utf8_substr( $invoice->country, 0, 60 );
120
-            $authorizeAIM->phone            = wpinv_utf8_substr( $invoice->phone, 0, 25 );
121
-            $authorizeAIM->email            = wpinv_utf8_substr( $invoice->get_email(), 0, 255 );
122
-            $authorizeAIM->amount           = wpinv_sanitize_amount( $invoice->get_total() );
123
-            $authorizeAIM->card_num         = str_replace( ' ', '', sanitize_text_field( $authorizenet_card['cc_number'] ) );
124
-            $authorizeAIM->exp_date         = sanitize_text_field( $authorizenet_card['cc_expire_month'] ) . sanitize_text_field( $authorizenet_card['cc_expire_year'] );
125
-            $authorizeAIM->card_code        = sanitize_text_field( $authorizenet_card['cc_cvv2'] );
112
+            $authorizeAIM->first_name       = wpinv_utf8_substr($invoice->get_first_name(), 0, 50);
113
+            $authorizeAIM->last_name        = wpinv_utf8_substr($invoice->get_last_name(), 0, 50);
114
+            $authorizeAIM->company          = wpinv_utf8_substr($invoice->company, 0, 50);
115
+            $authorizeAIM->address          = wpinv_utf8_substr(wp_strip_all_tags($invoice->get_address(), true), 0, 60);
116
+            $authorizeAIM->city             = wpinv_utf8_substr($invoice->city, 0, 40);
117
+            $authorizeAIM->state            = wpinv_utf8_substr($invoice->state, 0, 40);
118
+            $authorizeAIM->zip              = wpinv_utf8_substr($invoice->zip, 0, 40);
119
+            $authorizeAIM->country          = wpinv_utf8_substr($invoice->country, 0, 60);
120
+            $authorizeAIM->phone            = wpinv_utf8_substr($invoice->phone, 0, 25);
121
+            $authorizeAIM->email            = wpinv_utf8_substr($invoice->get_email(), 0, 255);
122
+            $authorizeAIM->amount           = wpinv_sanitize_amount($invoice->get_total());
123
+            $authorizeAIM->card_num         = str_replace(' ', '', sanitize_text_field($authorizenet_card['cc_number']));
124
+            $authorizeAIM->exp_date         = sanitize_text_field($authorizenet_card['cc_expire_month']) . sanitize_text_field($authorizenet_card['cc_expire_year']);
125
+            $authorizeAIM->card_code        = sanitize_text_field($authorizenet_card['cc_cvv2']);
126 126
             $authorizeAIM->invoice_num      = $invoice->ID;
127 127
             
128 128
             $item_desc = array();
129
-            foreach ( $invoice->get_cart_details() as $item ) {            
130
-                $quantity       = $quantities_enabled && !empty( $item['quantity'] ) && $item['quantity'] > 0 ? $item['quantity'] : 1;
131
-                $item_name      = wpinv_utf8_substr( $item['name'], 0, 31 );
132
-                $item_desc[]    = $item_name . ' (' . $quantity . 'x ' . wpinv_price( wpinv_format_amount( $item['item_price'] ) ) . ')';
129
+            foreach ($invoice->get_cart_details() as $item) {            
130
+                $quantity       = $quantities_enabled && !empty($item['quantity']) && $item['quantity'] > 0 ? $item['quantity'] : 1;
131
+                $item_name      = wpinv_utf8_substr($item['name'], 0, 31);
132
+                $item_desc[]    = $item_name . ' (' . $quantity . 'x ' . wpinv_price(wpinv_format_amount($item['item_price'])) . ')';
133 133
                 
134
-                $authorizeAIM->addLineItem( $item['id'], $item_name, '', $quantity, $item['item_price'], ( $use_taxes && !empty( $item['tax'] ) && $item['tax'] > 0 ? 'Y' : 'N' ) );
134
+                $authorizeAIM->addLineItem($item['id'], $item_name, '', $quantity, $item['item_price'], ($use_taxes && !empty($item['tax']) && $item['tax'] > 0 ? 'Y' : 'N'));
135 135
             }
136 136
             
137
-            $item_desc = '#' . $invoice->get_number() . ': ' . implode( ', ', $item_desc );
137
+            $item_desc = '#' . $invoice->get_number() . ': ' . implode(', ', $item_desc);
138 138
             
139
-            if ( $use_taxes && $invoice->get_tax() > 0 ) {
140
-                $authorizeAIM->tax  = $invoice->get_tax();
139
+            if ($use_taxes && $invoice->get_tax() > 0) {
140
+                $authorizeAIM->tax = $invoice->get_tax();
141 141
                 
142
-                $item_desc .= ', ' . wp_sprintf( __( 'Tax: %s', 'invoicing' ), $invoice->get_tax( true ) );
142
+                $item_desc .= ', ' . wp_sprintf(__('Tax: %s', 'invoicing'), $invoice->get_tax(true));
143 143
             }
144 144
             
145
-            if ( $invoice->get_discount() > 0 ) {
146
-                $item_desc .= ', ' . wp_sprintf( __( 'Discount: %s', 'invoicing' ), $invoice->get_discount( true ) );
145
+            if ($invoice->get_discount() > 0) {
146
+                $item_desc .= ', ' . wp_sprintf(__('Discount: %s', 'invoicing'), $invoice->get_discount(true));
147 147
             }
148 148
             
149
-            $item_description = wpinv_utf8_substr( $item_desc, 0, 255 );
150
-            $item_description = html_entity_decode( $item_desc , ENT_QUOTES, 'UTF-8' );
149
+            $item_description = wpinv_utf8_substr($item_desc, 0, 255);
150
+            $item_description = html_entity_decode($item_desc, ENT_QUOTES, 'UTF-8');
151 151
             
152
-            $authorizeAIM->description  = wpinv_utf8_substr( $item_description, 0, 255 );
152
+            $authorizeAIM->description = wpinv_utf8_substr($item_description, 0, 255);
153 153
             
154 154
             $is_recurring = $invoice->is_recurring(); // Recurring payment.
155 155
             
156
-            if ( $is_recurring ) {
156
+            if ($is_recurring) {
157 157
                 $authorizeAIM->recurring_billing = true;
158 158
             }
159 159
             
160 160
             try {
161
-                if ( $is_recurring ) {
161
+                if ($is_recurring) {
162 162
                     $response = $authorizeAIM->authorizeOnly();
163 163
                 } else {
164 164
                     $response = $authorizeAIM->authorizeAndCapture();
165 165
                 }
166 166
                 
167
-                if ( $response->approved || $response->held ) {
168
-                    if ( $response->approved ) {
169
-                        wpinv_update_payment_status( $invoice_id, 'publish' );
167
+                if ($response->approved || $response->held) {
168
+                    if ($response->approved) {
169
+                        wpinv_update_payment_status($invoice_id, 'publish');
170 170
                     }
171
-                    wpinv_set_payment_transaction_id( $invoice_id, $response->transaction_id );
171
+                    wpinv_set_payment_transaction_id($invoice_id, $response->transaction_id);
172 172
                     
173
-                    $message = wp_sprintf( __( 'Authorize.Net Payment: %s with transaction id %s using %s and authorization code %s', 'invoicing' ), $response->response_reason_text, $response->transaction_id, strtoupper( $response->transaction_type ), $response->authorization_code );
173
+                    $message = wp_sprintf(__('Authorize.Net Payment: %s with transaction id %s using %s and authorization code %s', 'invoicing'), $response->response_reason_text, $response->transaction_id, strtoupper($response->transaction_type), $response->authorization_code);
174 174
                     
175
-                    wpinv_insert_payment_note( $invoice_id, $message );
175
+                    wpinv_insert_payment_note($invoice_id, $message);
176 176
                     
177
-                    do_action( 'wpinv_authorizenet_handle_response', $response, $invoice, $authorizenet_card );
177
+                    do_action('wpinv_authorizenet_handle_response', $response, $invoice, $authorizenet_card);
178 178
                     
179 179
                     wpinv_clear_errors();
180 180
                     wpinv_empty_cart();
181 181
                     
182
-                    wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
182
+                    wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key()));
183 183
                 } else {
184
-                    if ( !empty( $response->response_reason_text ) ) {
185
-                        $error = __( $response->response_reason_text, 'invoicing' );
186
-                    } else if ( !empty( $response->error_message ) ) {
187
-                        $error = __( $response->error_message, 'invoicing' );
184
+                    if (!empty($response->response_reason_text)) {
185
+                        $error = __($response->response_reason_text, 'invoicing');
186
+                    } else if (!empty($response->error_message)) {
187
+                        $error = __($response->error_message, 'invoicing');
188 188
                     } else {
189
-                        $error = wp_sprintf( __( 'Error data: %s', 'invoicing' ), print_r( $response, true ) );
189
+                        $error = wp_sprintf(__('Error data: %s', 'invoicing'), print_r($response, true));
190 190
                     } 
191 191
                     
192
-                    $error = wp_sprintf( __( 'Authorize.Net payment error occurred. %s', 'invoicing' ), $error );
192
+                    $error = wp_sprintf(__('Authorize.Net payment error occurred. %s', 'invoicing'), $error);
193 193
                     
194
-                    wpinv_set_error( 'payment_error', $error );
195
-                    wpinv_record_gateway_error( $error, $response );
196
-                    wpinv_insert_payment_note( $invoice_id, $error );
194
+                    wpinv_set_error('payment_error', $error);
195
+                    wpinv_record_gateway_error($error, $response);
196
+                    wpinv_insert_payment_note($invoice_id, $error);
197 197
                     
198
-                    wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] );
198
+                    wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']);
199 199
                 }
200
-            } catch ( AuthorizeNetException $e ) {
201
-                wpinv_set_error( 'request_error', $e->getMessage() );
202
-                wpinv_record_gateway_error( wp_sprintf( __( 'Authorize.Net payment error occurred. %s', 'invoicing' ), $e->getMessage() ) );
203
-                wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] );
200
+            } catch (AuthorizeNetException $e) {
201
+                wpinv_set_error('request_error', $e->getMessage());
202
+                wpinv_record_gateway_error(wp_sprintf(__('Authorize.Net payment error occurred. %s', 'invoicing'), $e->getMessage()));
203
+                wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']);
204 204
             }
205 205
         } else {
206
-            wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] );
206
+            wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']);
207 207
         }
208 208
     } else {
209
-        wpinv_record_gateway_error( wp_sprintf( __( 'Authorize.Net payment error occurred. Payment creation failed while processing a Authorize.net payment. Payment data: %s', 'invoicing' ), print_r( $payment_data, true ) ), $invoice );
210
-        wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] );
209
+        wpinv_record_gateway_error(wp_sprintf(__('Authorize.Net payment error occurred. Payment creation failed while processing a Authorize.net payment. Payment data: %s', 'invoicing'), print_r($payment_data, true)), $invoice);
210
+        wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']);
211 211
     }
212 212
 }
213
-add_action( 'wpinv_gateway_authorizenet', 'wpinv_process_authorizenet_payment' );
213
+add_action('wpinv_gateway_authorizenet', 'wpinv_process_authorizenet_payment');
214 214
 
215
-function wpinv_authorizenet_cancel_subscription( $subscription_id = '' ) {
216
-    if ( empty( $subscription_id ) ) {
215
+function wpinv_authorizenet_cancel_subscription($subscription_id = '') {
216
+    if (empty($subscription_id)) {
217 217
         return false;
218 218
     }
219 219
     
220 220
     try {
221 221
         $authnetXML = wpinv_authorizenet_XML();
222
-        $authnetXML->ARBCancelSubscriptionRequest( array( 'subscriptionId' => $subscription_id ) );
222
+        $authnetXML->ARBCancelSubscriptionRequest(array('subscriptionId' => $subscription_id));
223 223
 
224 224
         return $authnetXML->isSuccessful();
225
-    } catch( Exception $e ) {
226
-        wpinv_error_log( $e->getMessage(), __( 'Authorize.Net cancel subscription', 'invoicing' ) );
225
+    } catch (Exception $e) {
226
+        wpinv_error_log($e->getMessage(), __('Authorize.Net cancel subscription', 'invoicing'));
227 227
     }
228 228
     
229 229
     return false;
230 230
 }
231 231
 
232
-function wpinv_authorizenet_valid_ipn( $md5_hash, $transaction_id, $amount ) {
233
-    $authorizenet_md5_hash = wpinv_get_option( 'authorizenet_md5_hash' );
234
-    if ( empty( $authorizenet_md5_hash ) ) {
232
+function wpinv_authorizenet_valid_ipn($md5_hash, $transaction_id, $amount) {
233
+    $authorizenet_md5_hash = wpinv_get_option('authorizenet_md5_hash');
234
+    if (empty($authorizenet_md5_hash)) {
235 235
         return true;
236 236
     }
237 237
     
238
-    $compare_md5 = strtoupper( md5( $authorizenet_md5_hash . $transaction_id . $amount ) );
238
+    $compare_md5 = strtoupper(md5($authorizenet_md5_hash . $transaction_id . $amount));
239 239
     
240
-    return hash_equals( $compare_md5, $md5_hash );
240
+    return hash_equals($compare_md5, $md5_hash);
241 241
 }
242 242
 
243 243
 function wpinv_authorizenet_AIM() {
244
-    if ( !class_exists( 'AuthorizeNetException' ) ) {
245
-        require_once plugin_dir_path( WPINV_PLUGIN_FILE ) . 'includes/gateways/authorizenet/anet_php_sdk/AuthorizeNet.php';
244
+    if (!class_exists('AuthorizeNetException')) {
245
+        require_once plugin_dir_path(WPINV_PLUGIN_FILE) . 'includes/gateways/authorizenet/anet_php_sdk/AuthorizeNet.php';
246 246
     }
247 247
     
248
-    $authorizeAIM = new AuthorizeNetAIM( wpinv_get_option( 'authorizenet_login_id' ), wpinv_get_option( 'authorizenet_transaction_key' ) );
248
+    $authorizeAIM = new AuthorizeNetAIM(wpinv_get_option('authorizenet_login_id'), wpinv_get_option('authorizenet_transaction_key'));
249 249
     
250
-    if ( wpinv_is_test_mode( 'authorizenet' ) ) {
251
-        $authorizeAIM->setSandbox( true );
250
+    if (wpinv_is_test_mode('authorizenet')) {
251
+        $authorizeAIM->setSandbox(true);
252 252
     } else {
253
-        $authorizeAIM->setSandbox( false );
253
+        $authorizeAIM->setSandbox(false);
254 254
     }
255 255
     
256 256
     $authorizeAIM->customer_ip = wpinv_get_ip();
@@ -259,164 +259,164 @@  discard block
 block discarded – undo
259 259
 }
260 260
 
261 261
 function wpinv_authorizenet_XML() {
262
-    if ( !class_exists( 'AuthnetXML' ) ) {
263
-        require_once plugin_dir_path( WPINV_PLUGIN_FILE ) . 'includes/gateways/authorizenet/Authorize.Net-XML/AuthnetXML.class.php';
262
+    if (!class_exists('AuthnetXML')) {
263
+        require_once plugin_dir_path(WPINV_PLUGIN_FILE) . 'includes/gateways/authorizenet/Authorize.Net-XML/AuthnetXML.class.php';
264 264
     }
265 265
     
266
-    $authnetXML = new AuthnetXML( wpinv_get_option( 'authorizenet_login_id' ), wpinv_get_option( 'authorizenet_transaction_key' ), (bool)wpinv_is_test_mode( 'authorizenet' ) );
266
+    $authnetXML = new AuthnetXML(wpinv_get_option('authorizenet_login_id'), wpinv_get_option('authorizenet_transaction_key'), (bool)wpinv_is_test_mode('authorizenet'));
267 267
     
268 268
     return $authnetXML;
269 269
 }
270 270
 
271
-function wpinv_authorizenet_handle_response( $response, $invoice, $card_info = array() ) {
272
-    if ( empty( $response ) || empty( $invoice ) ) {
271
+function wpinv_authorizenet_handle_response($response, $invoice, $card_info = array()) {
272
+    if (empty($response) || empty($invoice)) {
273 273
         return false;
274 274
     }
275 275
     
276
-    if ( $invoice->is_recurring() && !empty( $response->approved ) ) {
277
-        $subscription = wpinv_authorizenet_create_new_subscription( $invoice, $response, $card_info );
276
+    if ($invoice->is_recurring() && !empty($response->approved)) {
277
+        $subscription = wpinv_authorizenet_create_new_subscription($invoice, $response, $card_info);
278 278
 
279
-        if ( !empty( $subscription ) && $subscription->isSuccessful() ) {
280
-            do_action( 'wpinv_recurring_post_create_subscription', $subscription, $invoice, 'authorizenet' );
279
+        if (!empty($subscription) && $subscription->isSuccessful()) {
280
+            do_action('wpinv_recurring_post_create_subscription', $subscription, $invoice, 'authorizenet');
281 281
             
282
-            wpinv_authorizenet_subscription_record_signup( $subscription, $invoice );
282
+            wpinv_authorizenet_subscription_record_signup($subscription, $invoice);
283 283
             
284
-            do_action( 'wpinv_recurring_post_record_signup', $subscription, $invoice, 'authorizenet' );
284
+            do_action('wpinv_recurring_post_record_signup', $subscription, $invoice, 'authorizenet');
285 285
         } else {
286
-            if ( isset( $subscription->messages->message ) ) {
286
+            if (isset($subscription->messages->message)) {
287 287
                 $error = $subscription->messages->message->code . ': ' . $subscription->messages->message->text;
288
-                wpinv_set_error( 'wpinv_authorize_recurring_error', $error, 'invoicing' );
288
+                wpinv_set_error('wpinv_authorize_recurring_error', $error, 'invoicing');
289 289
             } else {
290
-                $error = __( 'Your subscription cannot be created due to an error.', 'invoicing' );
291
-                wpinv_set_error( 'wpinv_authorize_recurring_error', $error );
290
+                $error = __('Your subscription cannot be created due to an error.', 'invoicing');
291
+                wpinv_set_error('wpinv_authorize_recurring_error', $error);
292 292
             }
293 293
             
294
-            wpinv_record_gateway_error( $error, $subscription );
294
+            wpinv_record_gateway_error($error, $subscription);
295 295
             
296
-            wpinv_insert_payment_note( $invoice->ID, wp_sprintf( __( 'Authorize.Net subscription error occurred. %s', 'invoicing' ), $error ) );
296
+            wpinv_insert_payment_note($invoice->ID, wp_sprintf(__('Authorize.Net subscription error occurred. %s', 'invoicing'), $error));
297 297
         }
298 298
     }
299 299
 }
300
-add_action( 'wpinv_authorizenet_handle_response', 'wpinv_authorizenet_handle_response', 10, 3 );
300
+add_action('wpinv_authorizenet_handle_response', 'wpinv_authorizenet_handle_response', 10, 3);
301 301
 
302
-function wpinv_authorizenet_create_new_subscription( $invoice, $response = array(), $card_info = array() ) {
303
-    if ( empty( $invoice ) ) {
302
+function wpinv_authorizenet_create_new_subscription($invoice, $response = array(), $card_info = array()) {
303
+    if (empty($invoice)) {
304 304
         return false;
305 305
     }
306 306
     
307
-    $params = wpinv_authorizenet_generate_subscription_params( $invoice, $card_info, $response );
307
+    $params = wpinv_authorizenet_generate_subscription_params($invoice, $card_info, $response);
308 308
     
309 309
     try {
310 310
         $authnetXML = wpinv_authorizenet_XML();
311
-        $authnetXML->ARBCreateSubscriptionRequest( $params );
312
-    } catch( Exception $e ) {
311
+        $authnetXML->ARBCreateSubscriptionRequest($params);
312
+    } catch (Exception $e) {
313 313
         $authnetXML = array();
314
-        wpinv_error_log( $e->getMessage(), __( 'Authorize.Net cancel subscription', 'invoicing' ) );
314
+        wpinv_error_log($e->getMessage(), __('Authorize.Net cancel subscription', 'invoicing'));
315 315
     }
316 316
     
317 317
     return $authnetXML;
318 318
 }
319 319
 
320
-function wpinv_authorizenet_generate_subscription_params( $invoice, $card_info = array(), $response = array() ) {
321
-    if ( empty( $invoice ) ) {
320
+function wpinv_authorizenet_generate_subscription_params($invoice, $card_info = array(), $response = array()) {
321
+    if (empty($invoice)) {
322 322
         return false;
323 323
     }
324 324
     
325
-    $subscription_item = $invoice->get_recurring( true );
326
-    if ( empty( $subscription_item ) ) {
325
+    $subscription_item = $invoice->get_recurring(true);
326
+    if (empty($subscription_item)) {
327 327
         return false;
328 328
     }
329 329
     
330
-    $card_details       = wpinv_authorizenet_generate_card_info( $card_info );
330
+    $card_details       = wpinv_authorizenet_generate_card_info($card_info);
331 331
     $subscription_name  = $invoice->get_subscription_name();
332
-    $initial_amount     = wpinv_round_amount( $invoice->get_total() );
333
-    $recurring_amount   = wpinv_round_amount( $invoice->get_recurring_details( 'total' ) );
332
+    $initial_amount     = wpinv_round_amount($invoice->get_total());
333
+    $recurring_amount   = wpinv_round_amount($invoice->get_recurring_details('total'));
334 334
     $interval           = $subscription_item->get_recurring_interval();
335 335
     $period             = $subscription_item->get_recurring_period();
336 336
     $bill_times         = (int)$subscription_item->get_recurring_limit();
337 337
     $bill_times         = $bill_times > 0 ? $bill_times : 9999;
338 338
     
339
-    $time_period        = wpinv_authorizenet_get_time_period( $interval, $period );
339
+    $time_period        = wpinv_authorizenet_get_time_period($interval, $period);
340 340
     $interval           = $time_period['interval'];
341 341
     $period             = $time_period['period'];
342 342
     
343 343
     $current_tz = date_default_timezone_get();
344
-    date_default_timezone_set( 'America/Denver' ); // Set same timezone as Authorize's server (Mountain Time) to prevent conflicts.
345
-    $today = date( 'Y-m-d' );
346
-    date_default_timezone_set( $current_tz );
344
+    date_default_timezone_set('America/Denver'); // Set same timezone as Authorize's server (Mountain Time) to prevent conflicts.
345
+    $today = date('Y-m-d');
346
+    date_default_timezone_set($current_tz);
347 347
     
348 348
     $free_trial = $invoice->is_free_trial();
349
-    if ( $free_trial && $subscription_item->has_free_trial() ) {
349
+    if ($free_trial && $subscription_item->has_free_trial()) {
350 350
         $trial_interval    = $subscription_item->get_trial_interval();
351
-        $trial_period      = $subscription_item->get_trial_period( true );
351
+        $trial_period      = $subscription_item->get_trial_period(true);
352 352
     }
353 353
     
354 354
     $subscription = array();
355 355
     $subscription['name'] = $subscription_name;
356 356
     
357 357
     $subscription['paymentSchedule'] = array(
358
-        'interval'         => array( 'length' => $interval, 'unit' => $period ),
358
+        'interval'         => array('length' => $interval, 'unit' => $period),
359 359
         'startDate'        => $today,
360 360
         'totalOccurrences' => $bill_times,
361
-        'trialOccurrences' => $free_trial || ( $initial_amount != $recurring_amount ) ? 1 : 0,
361
+        'trialOccurrences' => $free_trial || ($initial_amount != $recurring_amount) ? 1 : 0,
362 362
     );
363 363
     
364 364
     $subscription['amount'] = $recurring_amount;
365 365
     $subscription['trialAmount'] = $initial_amount;
366
-    $subscription['payment'] = array( 'creditCard' => $card_details );
367
-    $subscription['order'] = array( 'invoiceNumber' => $invoice->ID, 'description' => '#' . $invoice->get_number() );
368
-    $subscription['customer'] = array( 'id' => $invoice->get_user_id(), 'email' => $invoice->get_email(), 'phoneNumber' => $invoice->phone );
366
+    $subscription['payment'] = array('creditCard' => $card_details);
367
+    $subscription['order'] = array('invoiceNumber' => $invoice->ID, 'description' => '#' . $invoice->get_number());
368
+    $subscription['customer'] = array('id' => $invoice->get_user_id(), 'email' => $invoice->get_email(), 'phoneNumber' => $invoice->phone);
369 369
     
370 370
     $subscription['billTo'] = array(
371 371
         'firstName' => $invoice->get_first_name(),
372 372
         'lastName'  => $invoice->get_last_name(),
373 373
         'company'   => $invoice->company,
374
-        'address'   => wp_strip_all_tags( $invoice->get_address(), true ),
374
+        'address'   => wp_strip_all_tags($invoice->get_address(), true),
375 375
         'city'      => $invoice->city,
376 376
         'state'     => $invoice->state,
377 377
         'zip'       => $invoice->zip,
378 378
         'country'   => $invoice->country,
379 379
     );
380 380
     
381
-    $params = array( 'subscription' => $subscription );
381
+    $params = array('subscription' => $subscription);
382 382
     
383
-    return apply_filters( 'wpinv_authorizenet_generate_subscription_params', $params, $invoice, $card_info, $response );
383
+    return apply_filters('wpinv_authorizenet_generate_subscription_params', $params, $invoice, $card_info, $response);
384 384
 }
385 385
 
386
-function wpinv_authorizenet_generate_card_info( $card_info = array() ) {
387
-    $card_defaults      = array(
386
+function wpinv_authorizenet_generate_card_info($card_info = array()) {
387
+    $card_defaults = array(
388 388
         'cc_owner'          => null,
389 389
         'cc_number'         => null,
390 390
         'cc_expire_month'   => null,
391 391
         'cc_expire_year'    => null,
392 392
         'cc_cvv2'           => null,
393 393
     );
394
-    $card_info = wp_parse_args( $card_info, $card_defaults );
394
+    $card_info = wp_parse_args($card_info, $card_defaults);
395 395
         
396 396
     $card_details = array(
397
-        'cardNumber'     => str_replace( ' ', '', sanitize_text_field( $card_info['cc_number'] ) ),
398
-        'expirationDate' => sanitize_text_field( $card_info['cc_expire_month'] ) . sanitize_text_field( $card_info['cc_expire_year'] ),
399
-        'cardCode'       => sanitize_text_field( $card_info['cc_cvv2'] ),
397
+        'cardNumber'     => str_replace(' ', '', sanitize_text_field($card_info['cc_number'])),
398
+        'expirationDate' => sanitize_text_field($card_info['cc_expire_month']) . sanitize_text_field($card_info['cc_expire_year']),
399
+        'cardCode'       => sanitize_text_field($card_info['cc_cvv2']),
400 400
     );
401 401
 
402 402
     return $card_details;
403 403
 }
404 404
 
405
-function wpinv_authorizenet_subscription_record_signup( $subscription, $invoice ) {
406
-    if ( empty( $invoice ) || empty( $subscription ) ) {
405
+function wpinv_authorizenet_subscription_record_signup($subscription, $invoice) {
406
+    if (empty($invoice) || empty($subscription)) {
407 407
         return false;
408 408
     }
409 409
     
410
-    $subscription_item = $invoice->get_recurring( true );
411
-    if ( empty( $subscription_item ) ) {
410
+    $subscription_item = $invoice->get_recurring(true);
411
+    if (empty($subscription_item)) {
412 412
         return false;
413 413
     }
414 414
     
415 415
     $invoice_id         = $invoice->ID;
416 416
     $subscriptionId     = (array)$subscription->subscriptionId;
417
-    $subscription_id    = !empty( $subscriptionId[0] ) ? $subscriptionId[0] : $invoice_id;
417
+    $subscription_id    = !empty($subscriptionId[0]) ? $subscriptionId[0] : $invoice_id;
418 418
 
419
-    wpinv_insert_payment_note( $invoice_id, sprintf( __( 'Authorize.Net Subscription ID: %s', 'invoicing' ) , $subscription_id ) );
419
+    wpinv_insert_payment_note($invoice_id, sprintf(__('Authorize.Net Subscription ID: %s', 'invoicing'), $subscription_id));
420 420
     
421 421
     $status = $invoice->is_free_trial() && $subscription_item->has_free_trial() ? 'trialing' : 'active';
422 422
     
@@ -424,16 +424,16 @@  discard block
 block discarded – undo
424 424
         'profile_id'        => $subscription_id,
425 425
         'item_id'           => $subscription_item->ID,
426 426
         'initial_amount'    => $invoice->get_total(),
427
-        'recurring_amount'  => $invoice->get_recurring_details( 'total' ),
427
+        'recurring_amount'  => $invoice->get_recurring_details('total'),
428 428
         'period'            => $subscription_item->get_recurring_period(),
429 429
         'interval'          => $subscription_item->get_recurring_interval(),
430 430
         'bill_times'        => $subscription_item->get_recurring_limit(),
431
-        'expiration'        => $invoice->get_new_expiration( $subscription_item->ID ),
431
+        'expiration'        => $invoice->get_new_expiration($subscription_item->ID),
432 432
         'status'            => $status,
433
-        'created'           => current_time( 'mysql', 0 )
433
+        'created'           => current_time('mysql', 0)
434 434
     );
435 435
     
436
-    if ( $invoice->is_free_trial() && $subscription_item->has_free_trial() ) {
436
+    if ($invoice->is_free_trial() && $subscription_item->has_free_trial()) {
437 437
         $args['trial_period']      = $subscription_item->get_trial_period();
438 438
         $args['trial_interval']    = $subscription_item->get_trial_interval();
439 439
     } else {
@@ -441,58 +441,58 @@  discard block
 block discarded – undo
441 441
         $args['trial_interval']    = 0;
442 442
     }
443 443
     
444
-    return $invoice->update_subscription( $args );
444
+    return $invoice->update_subscription($args);
445 445
 }
446 446
 
447
-function wpinv_authorizenet_validate_checkout( $valid_data, $post ) {
448
-    if ( !empty( $post['wpi-gateway'] ) && $post['wpi-gateway'] == 'authorizenet' ) {
447
+function wpinv_authorizenet_validate_checkout($valid_data, $post) {
448
+    if (!empty($post['wpi-gateway']) && $post['wpi-gateway'] == 'authorizenet') {
449 449
         $error = false;
450 450
         
451
-        if ( empty( $post['authorizenet']['cc_owner'] ) ) {
451
+        if (empty($post['authorizenet']['cc_owner'])) {
452 452
             $error = true;
453
-            wpinv_set_error( 'empty_card_name', __( 'You must enter the name on your card!', 'invoicing'));
453
+            wpinv_set_error('empty_card_name', __('You must enter the name on your card!', 'invoicing'));
454 454
         }
455
-        if ( empty( $post['authorizenet']['cc_number'] ) ) {
455
+        if (empty($post['authorizenet']['cc_number'])) {
456 456
             $error = true;
457
-            wpinv_set_error( 'empty_card', __( 'You must enter a card number!', 'invoicing'));
457
+            wpinv_set_error('empty_card', __('You must enter a card number!', 'invoicing'));
458 458
         }
459
-        if ( empty( $post['authorizenet']['cc_expire_month'] ) ) {
459
+        if (empty($post['authorizenet']['cc_expire_month'])) {
460 460
             $error = true;
461
-            wpinv_set_error( 'empty_month', __( 'You must enter an card expiration month!', 'invoicing'));
461
+            wpinv_set_error('empty_month', __('You must enter an card expiration month!', 'invoicing'));
462 462
         }
463
-        if ( empty( $post['authorizenet']['cc_expire_year'] ) ) {
463
+        if (empty($post['authorizenet']['cc_expire_year'])) {
464 464
             $error = true;
465
-            wpinv_set_error( 'empty_year', __( 'You must enter an card expiration year!', 'invoicing'));
465
+            wpinv_set_error('empty_year', __('You must enter an card expiration year!', 'invoicing'));
466 466
         }
467
-        if ( empty( $post['authorizenet']['cc_cvv2'] ) ) {
467
+        if (empty($post['authorizenet']['cc_cvv2'])) {
468 468
             $error = true;
469
-            wpinv_set_error( 'empty_cvv2', __( 'You must enter a valid CVV2!', 'invoicing' ) );
469
+            wpinv_set_error('empty_cvv2', __('You must enter a valid CVV2!', 'invoicing'));
470 470
         }
471 471
         
472
-        if ( $error ) {
472
+        if ($error) {
473 473
             return;
474 474
         }
475 475
         
476 476
         $invoice = wpinv_get_invoice_cart();
477 477
         
478
-        if ( !empty( $invoice ) && $subscription_item = $invoice->get_recurring( true ) ) {
479
-            $subscription_item = $invoice->get_recurring( true );
478
+        if (!empty($invoice) && $subscription_item = $invoice->get_recurring(true)) {
479
+            $subscription_item = $invoice->get_recurring(true);
480 480
             
481 481
             $interval   = $subscription_item->get_recurring_interval();
482 482
             $period     = $subscription_item->get_recurring_period();
483 483
             
484
-            if ( $period == 'D' && ( $interval < 7 || $interval > 365 ) ) {
485
-                wpinv_set_error( 'authorizenet_subscription_error', __( 'Interval Length must be a value from 7 through 365 for day based subscriptions.', 'invoicing' ) );
484
+            if ($period == 'D' && ($interval < 7 || $interval > 365)) {
485
+                wpinv_set_error('authorizenet_subscription_error', __('Interval Length must be a value from 7 through 365 for day based subscriptions.', 'invoicing'));
486 486
             }
487 487
         }
488 488
     }
489 489
 }
490
-add_action( 'wpinv_checkout_error_checks', 'wpinv_authorizenet_validate_checkout', 11, 2 );
490
+add_action('wpinv_checkout_error_checks', 'wpinv_authorizenet_validate_checkout', 11, 2);
491 491
 
492
-function wpinv_authorizenet_get_time_period( $subscription_interval, $subscription_period ) {
493
-    $subscription_interval = absint( $subscription_interval );
492
+function wpinv_authorizenet_get_time_period($subscription_interval, $subscription_period) {
493
+    $subscription_interval = absint($subscription_interval);
494 494
 
495
-    switch( $subscription_period ) {
495
+    switch ($subscription_period) {
496 496
         case 'W':
497 497
         case 'week':
498 498
         case 'weeks':
@@ -502,14 +502,14 @@  discard block
 block discarded – undo
502 502
         case 'M':
503 503
         case 'month':
504 504
         case 'months':
505
-            if ( $subscription_interval > 12 ) {
505
+            if ($subscription_interval > 12) {
506 506
                 $subscription_interval = 12;
507 507
             }
508 508
             
509 509
             $interval = $subscription_interval;
510 510
             $period   = 'months';
511 511
             
512
-            if ( !( $subscription_interval === 1 || $subscription_interval === 2 || $subscription_interval === 3 || $subscription_interval === 6 || $subscription_interval === 12 ) ) {
512
+            if (!($subscription_interval === 1 || $subscription_interval === 2 || $subscription_interval === 3 || $subscription_interval === 6 || $subscription_interval === 12)) {
513 513
                 $interval = $subscription_interval * 30;
514 514
                 $period   = 'days';
515 515
             }
@@ -526,40 +526,40 @@  discard block
 block discarded – undo
526 526
             break;
527 527
     }
528 528
 
529
-    return compact( 'interval', 'period' );
529
+    return compact('interval', 'period');
530 530
 }
531 531
 
532 532
 function wpinv_authorizenet_process_ipn() {
533
-    if ( !( !empty( $_REQUEST['wpi-gateway'] ) && $_REQUEST['wpi-gateway'] == 'authorizenet' ) ) {
533
+    if (!(!empty($_REQUEST['wpi-gateway']) && $_REQUEST['wpi-gateway'] == 'authorizenet')) {
534 534
         return;
535 535
     }
536 536
     
537
-    $subscription_id = intval( $_POST['x_subscription_id'] );
537
+    $subscription_id = intval($_POST['x_subscription_id']);
538 538
     
539
-    if ( $subscription_id ) {
540
-        $transaction_id = sanitize_text_field( $_POST['x_trans_id'] );
541
-        $renewal_amount = sanitize_text_field( $_POST['x_amount'] );
542
-        $response_code  = intval( $_POST['x_response_code'] );
543
-        $reason_code    = intval( $_POST['x_response_reason_code'] );
539
+    if ($subscription_id) {
540
+        $transaction_id = sanitize_text_field($_POST['x_trans_id']);
541
+        $renewal_amount = sanitize_text_field($_POST['x_amount']);
542
+        $response_code  = intval($_POST['x_response_code']);
543
+        $reason_code    = intval($_POST['x_response_reason_code']);
544 544
 
545
-        if ( 1 == $response_code ) {
545
+        if (1 == $response_code) {
546 546
             // Approved
547
-            do_action( 'wpinv_authorizenet_renewal_payment', $transaction_id );
548
-        } else if ( 2 == $response_code ) {
547
+            do_action('wpinv_authorizenet_renewal_payment', $transaction_id);
548
+        } else if (2 == $response_code) {
549 549
             // Declined
550
-            do_action( 'wpinv_authorizenet_renewal_payment_failed', $transaction_id );
551
-            do_action( 'wpinv_authorizenet_renewal_error', $transaction_id );
552
-        } else if ( 3 == $response_code || 8 == $reason_code ) {
550
+            do_action('wpinv_authorizenet_renewal_payment_failed', $transaction_id);
551
+            do_action('wpinv_authorizenet_renewal_error', $transaction_id);
552
+        } else if (3 == $response_code || 8 == $reason_code) {
553 553
             // An expired card
554
-            do_action( 'wpinv_authorizenet_renewal_payment_failed', $transaction_id );
555
-            do_action( 'wpinv_authorizenet_renewal_payment_error', $transaction_id );
554
+            do_action('wpinv_authorizenet_renewal_payment_failed', $transaction_id);
555
+            do_action('wpinv_authorizenet_renewal_payment_error', $transaction_id);
556 556
 
557 557
         } else {
558 558
             // Other Error
559
-            do_action( 'wpinv_authorizenet_renewal_payment_error', $subscription );
559
+            do_action('wpinv_authorizenet_renewal_payment_error', $subscription);
560 560
         }
561 561
         
562 562
         exit;
563 563
     }
564 564
 }
565
-add_action( 'wpinv_verify_authorizenet_ipn', 'wpinv_authorizenet_process_ipn' );
566 565
\ No newline at end of file
566
+add_action('wpinv_verify_authorizenet_ipn', 'wpinv_authorizenet_process_ipn');
567 567
\ No newline at end of file
Please login to merge, or discard this patch.
templates/emails/wpinv-email-invoice-items.php 1 patch
Spacing   +70 added lines, -70 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // don't load directly
3
-if ( !defined('ABSPATH') )
3
+if (!defined('ABSPATH'))
4 4
     die('-1');
5 5
 
6 6
 global $wpinv_euvat, $ajax_cart_details;
@@ -11,158 +11,158 @@  discard block
 block discarded – undo
11 11
 $quantities_enabled = wpinv_item_quantities_enabled();
12 12
 $use_taxes          = wpinv_use_taxes();
13 13
 $zero_tax           = !(float)$invoice->get_tax() > 0 ? true : false;
14
-$tax_label          = $use_taxes && $invoice->has_vat() ? $wpinv_euvat->get_vat_name() : __( 'Tax', 'invoicing' );
15
-$tax_title          = !$zero_tax && $use_taxes ? ( wpinv_prices_include_tax() ? wp_sprintf( __( '(%s Incl.)', 'invoicing' ), $tax_label ) : wp_sprintf( __( '(%s Excl.)', 'invoicing' ), $tax_label ) ) : '';
14
+$tax_label          = $use_taxes && $invoice->has_vat() ? $wpinv_euvat->get_vat_name() : __('Tax', 'invoicing');
15
+$tax_title          = !$zero_tax && $use_taxes ? (wpinv_prices_include_tax() ? wp_sprintf(__('(%s Incl.)', 'invoicing'), $tax_label) : wp_sprintf(__('(%s Excl.)', 'invoicing'), $tax_label)) : '';
16 16
 
17
-do_action( 'wpinv_before_email_items', $invoice ); ?>
17
+do_action('wpinv_before_email_items', $invoice); ?>
18 18
 <div id="wpinv-email-items">
19
-    <h3 class="wpinv-items-t"><?php echo apply_filters( 'wpinv_email_items_title', __( 'Items', 'invoicing' ) ); ?></h3>
19
+    <h3 class="wpinv-items-t"><?php echo apply_filters('wpinv_email_items_title', __('Items', 'invoicing')); ?></h3>
20 20
     <table id="wpinv_checkout_cart" class="table table-bordered table-hover">
21 21
         <thead>
22 22
             <tr class="wpinv_cart_header_row">
23
-                <?php do_action( 'wpinv_email_items_table_header_first' ); ?>
24
-                <th class="wpinv_cart_item_name text-left"><?php _e( 'Item Name', 'invoicing' ); ?></th>
25
-                <th class="wpinv_cart_item_price text-right"><?php _e( 'Item Price', 'invoicing' ); ?></th>
26
-                <?php if ( $quantities_enabled ) { ?>
27
-                <th class="wpinv_cart_item_qty text-right"><?php _e( 'Qty', 'invoicing' ); ?></th>
23
+                <?php do_action('wpinv_email_items_table_header_first'); ?>
24
+                <th class="wpinv_cart_item_name text-left"><?php _e('Item Name', 'invoicing'); ?></th>
25
+                <th class="wpinv_cart_item_price text-right"><?php _e('Item Price', 'invoicing'); ?></th>
26
+                <?php if ($quantities_enabled) { ?>
27
+                <th class="wpinv_cart_item_qty text-right"><?php _e('Qty', 'invoicing'); ?></th>
28 28
                 <?php } ?>
29
-                <?php if ( !$zero_tax && $use_taxes ) { ?>
29
+                <?php if (!$zero_tax && $use_taxes) { ?>
30 30
                 <th class="wpinv_cart_item_tax text-right"><?php echo $tax_label . ' <span class="normal small">(%)</span>'; ?></th>
31 31
                 <?php } ?>
32
-                <th class="wpinv_cart_item_subtotal text-right"><?php echo __( 'Item Total', 'invoicing' ) . ' <span class="normal small">' . $tax_title . '<span>'; ?></th>
33
-                <?php do_action( 'wpinv_email_items_table_header_last' ); ?>
32
+                <th class="wpinv_cart_item_subtotal text-right"><?php echo __('Item Total', 'invoicing') . ' <span class="normal small">' . $tax_title . '<span>'; ?></th>
33
+                <?php do_action('wpinv_email_items_table_header_last'); ?>
34 34
             </tr>
35 35
         </thead>
36 36
         <tbody>
37 37
             <?php
38
-                do_action( 'wpinv_email_items_before' );
39
-                if ( $cart_items ) {
40
-                    foreach ( $cart_items as $key => $item ) {
41
-                        $wpi_item = $item['id'] ? new WPInv_Item( $item['id'] ) : NULL;
38
+                do_action('wpinv_email_items_before');
39
+                if ($cart_items) {
40
+                    foreach ($cart_items as $key => $item) {
41
+                        $wpi_item = $item['id'] ? new WPInv_Item($item['id']) : NULL;
42 42
                     ?>
43
-                    <tr class="wpinv_cart_item" id="wpinv_cart_item_<?php echo esc_attr( $key ) . '_' . esc_attr( $item['id'] ); ?>" data-item-id="<?php echo esc_attr( $item['id'] ); ?>">
44
-                        <?php do_action( 'wpinv_email_items_table_body_first', $item ); ?>
43
+                    <tr class="wpinv_cart_item" id="wpinv_cart_item_<?php echo esc_attr($key) . '_' . esc_attr($item['id']); ?>" data-item-id="<?php echo esc_attr($item['id']); ?>">
44
+                        <?php do_action('wpinv_email_items_table_body_first', $item); ?>
45 45
                         <td class="wpinv_cart_item_name text-left">
46 46
                             <?php
47
-                                if ( current_theme_supports( 'post-thumbnails' ) && has_post_thumbnail( $item['id'] ) ) {
47
+                                if (current_theme_supports('post-thumbnails') && has_post_thumbnail($item['id'])) {
48 48
                                     echo '<div class="wpinv_cart_item_image">';
49
-                                        echo get_the_post_thumbnail( $item['id'], apply_filters( 'wpinv_checkout_image_size', array( 25,25 ) ) );
49
+                                        echo get_the_post_thumbnail($item['id'], apply_filters('wpinv_checkout_image_size', array(25, 25)));
50 50
                                     echo '</div>';
51 51
                                 }
52
-                                $item_title = esc_html( wpinv_get_cart_item_name( $item ) ) . wpinv_get_item_suffix( $wpi_item );
52
+                                $item_title = esc_html(wpinv_get_cart_item_name($item)) . wpinv_get_item_suffix($wpi_item);
53 53
                                 echo '<span class="wpinv_email_cart_item_title">' . $item_title . '</span>';
54 54
                                 
55 55
                                 $summary = '';
56
-                                if ( !empty( $wpi_item ) && $wpi_item->is_package() && !empty( $item['meta']['post_id'] ) ) {
57
-                                    $post_link = '<a href="' . get_permalink( $item['meta']['post_id'] ) .'" target="_blank">' . (!empty($item['meta']['invoice_title']) ? $item['meta']['invoice_title'] : get_the_title( $item['meta']['post_id']) ) . '</a>';
58
-                                    $summary = wp_sprintf( __( '%s: %s', 'invoicing' ), $wpi_item->get_custom_singular_name(), $post_link );
56
+                                if (!empty($wpi_item) && $wpi_item->is_package() && !empty($item['meta']['post_id'])) {
57
+                                    $post_link = '<a href="' . get_permalink($item['meta']['post_id']) . '" target="_blank">' . (!empty($item['meta']['invoice_title']) ? $item['meta']['invoice_title'] : get_the_title($item['meta']['post_id'])) . '</a>';
58
+                                    $summary = wp_sprintf(__('%s: %s', 'invoicing'), $wpi_item->get_custom_singular_name(), $post_link);
59 59
                                 }
60 60
                                 
61
-                                $summary = apply_filters( 'wpinv_email_invoice_line_item_summary', $summary, $item, $wpi_item, $invoice );
62
-                                if ( !empty( $summary ) ) {
61
+                                $summary = apply_filters('wpinv_email_invoice_line_item_summary', $summary, $item, $wpi_item, $invoice);
62
+                                if (!empty($summary)) {
63 63
                                     echo '<p class="small">' . $summary . '</p>';
64 64
                                 }
65 65
     
66
-                                do_action( 'wpinv_email_cart_item_title_after', $item, $key );
66
+                                do_action('wpinv_email_cart_item_title_after', $item, $key);
67 67
                             ?>
68 68
                         </td>
69 69
                         <td class="wpinv_cart_item_price text-right">
70 70
                             <?php 
71
-                            echo wpinv_cart_item_price( $item );
72
-                            do_action( 'wpinv_email_cart_item_price_after', $item, $key );
71
+                            echo wpinv_cart_item_price($item);
72
+                            do_action('wpinv_email_cart_item_price_after', $item, $key);
73 73
                             ?>
74 74
                         </td>
75
-                        <?php if ( $quantities_enabled ) { ?>
75
+                        <?php if ($quantities_enabled) { ?>
76 76
                         <td class="wpinv_cart_item_qty text-right">
77 77
                             <?php
78
-                            echo wpinv_get_cart_item_quantity( $item );
79
-                            do_action( 'wpinv_email_item_quantitiy', $item, $key );
78
+                            echo wpinv_get_cart_item_quantity($item);
79
+                            do_action('wpinv_email_item_quantitiy', $item, $key);
80 80
                             ?>
81 81
                         </td>
82 82
                         <?php } ?>
83
-                        <?php if ( !$zero_tax && $use_taxes ) { ?>
83
+                        <?php if (!$zero_tax && $use_taxes) { ?>
84 84
                         <td class="wpinv_cart_item_tax text-right">
85 85
                             <?php
86
-                            echo wpinv_cart_item_tax( $item );
87
-                            do_action( 'wpinv_email_item_tax', $item, $key );
86
+                            echo wpinv_cart_item_tax($item);
87
+                            do_action('wpinv_email_item_tax', $item, $key);
88 88
                             ?>
89 89
                         </td>
90 90
                         <?php } ?>
91 91
                         <td class="wpinv_cart_item_subtotal text-right">
92 92
                             <?php
93
-                            echo wpinv_cart_item_subtotal( $item );
94
-                            do_action( 'wpinv_email_item_subtotal', $item, $key );
93
+                            echo wpinv_cart_item_subtotal($item);
94
+                            do_action('wpinv_email_item_subtotal', $item, $key);
95 95
                             ?>
96 96
                         </td>
97
-                        <?php do_action( 'wpinv_email_items_table_body_last', $item, $key ); ?>
97
+                        <?php do_action('wpinv_email_items_table_body_last', $item, $key); ?>
98 98
                     </tr>
99 99
                 <?php } ?>
100 100
             <?php } ?>
101
-            <?php do_action( 'wpinv_email_items_middle' ); ?>
102
-            <?php do_action( 'wpinv_email_items_after' ); ?>
101
+            <?php do_action('wpinv_email_items_middle'); ?>
102
+            <?php do_action('wpinv_email_items_after'); ?>
103 103
         </tbody>
104 104
         <tfoot>
105
-            <?php $cart_columns = wpinv_checkout_cart_columns(); if ( $zero_tax && $use_taxes ) { $cart_columns--; } ?>
106
-            <?php if ( has_action( 'wpinv_email_footer_buttons' ) ) { ?>
105
+            <?php $cart_columns = wpinv_checkout_cart_columns(); if ($zero_tax && $use_taxes) { $cart_columns--; } ?>
106
+            <?php if (has_action('wpinv_email_footer_buttons')) { ?>
107 107
                 <tr class="wpinv_cart_footer_row">
108
-                    <?php do_action( 'wpinv_email_items_table_buttons_first', $cart_items ); ?>
109
-                    <td colspan="<?php echo ( $cart_columns ); ?>">
110
-                        <?php do_action( 'wpinv_email_footer_buttons' ); ?>
108
+                    <?php do_action('wpinv_email_items_table_buttons_first', $cart_items); ?>
109
+                    <td colspan="<?php echo ($cart_columns); ?>">
110
+                        <?php do_action('wpinv_email_footer_buttons'); ?>
111 111
                     </td>
112
-                    <?php do_action( 'wpinv_email_items_table_buttons_first', $cart_items ); ?>
112
+                    <?php do_action('wpinv_email_items_table_buttons_first', $cart_items); ?>
113 113
                 </tr>
114 114
             <?php } ?>
115 115
 
116
-            <?php if ( !$zero_tax && $use_taxes && !wpinv_prices_include_tax() && wpinv_is_cart_taxed() ) { ?>
116
+            <?php if (!$zero_tax && $use_taxes && !wpinv_prices_include_tax() && wpinv_is_cart_taxed()) { ?>
117 117
                 <tr class="wpinv_cart_footer_row wpinv_cart_subtotal_row">
118
-                    <?php do_action( 'wpinv_email_items_table_subtotal_first', $cart_items ); ?>
119
-                    <td colspan="<?php echo ( $cart_columns - 1 ); ?>" class="wpinv_cart_subtotal_label text-right">
120
-                        <strong><?php _e( 'Sub-Total', 'invoicing' ); ?>:</strong>
118
+                    <?php do_action('wpinv_email_items_table_subtotal_first', $cart_items); ?>
119
+                    <td colspan="<?php echo ($cart_columns - 1); ?>" class="wpinv_cart_subtotal_label text-right">
120
+                        <strong><?php _e('Sub-Total', 'invoicing'); ?>:</strong>
121 121
                     </td>
122 122
                     <td class="wpinv_cart_subtotal text-right">
123
-                        <span class="wpinv_cart_subtotal_amount bold"><?php echo $invoice->get_subtotal( true ); ?></span>
123
+                        <span class="wpinv_cart_subtotal_amount bold"><?php echo $invoice->get_subtotal(true); ?></span>
124 124
                     </td>
125
-                    <?php do_action( 'wpinv_email_items_table_subtotal_last', $cart_items, $invoice ); ?>
125
+                    <?php do_action('wpinv_email_items_table_subtotal_last', $cart_items, $invoice); ?>
126 126
                 </tr>
127 127
             <?php } ?>
128 128
             
129
-            <?php if ( wpinv_discount( $invoice_id, false ) > 0 ) { ?>
129
+            <?php if (wpinv_discount($invoice_id, false) > 0) { ?>
130 130
                 <tr class="wpinv_cart_footer_row wpinv_cart_discount_row">
131
-                    <?php do_action( 'wpinv_receipt_items_table_discount_first', $cart_items, $invoice ); ?>
132
-                    <td colspan="<?php echo ( $cart_columns - 1 ); ?>" class="wpinv_cart_discount_label text-right">
133
-                        <strong><?php wpinv_get_discount_label( wpinv_discount_code( $invoice_id ) ); ?>:</strong>
131
+                    <?php do_action('wpinv_receipt_items_table_discount_first', $cart_items, $invoice); ?>
132
+                    <td colspan="<?php echo ($cart_columns - 1); ?>" class="wpinv_cart_discount_label text-right">
133
+                        <strong><?php wpinv_get_discount_label(wpinv_discount_code($invoice_id)); ?>:</strong>
134 134
                     </td>
135 135
                     <td class="wpinv_cart_discount text-right">
136
-                        <span class="wpinv_cart_discount_amount"><?php echo wpinv_discount( $invoice_id, true, true ); ?></span>
136
+                        <span class="wpinv_cart_discount_amount"><?php echo wpinv_discount($invoice_id, true, true); ?></span>
137 137
                     </td>
138
-                    <?php do_action( 'wpinv_receipt_items_table_discount_last', $cart_items, $invoice ); ?>
138
+                    <?php do_action('wpinv_receipt_items_table_discount_last', $cart_items, $invoice); ?>
139 139
                 </tr>
140 140
             <?php } ?>
141 141
 
142
-            <?php if ( !$zero_tax && $use_taxes && wpinv_is_cart_taxed() ) { ?>
142
+            <?php if (!$zero_tax && $use_taxes && wpinv_is_cart_taxed()) { ?>
143 143
                 <tr class="wpinv_cart_footer_row wpinv_cart_tax_row">
144
-                    <?php do_action( 'wpinv_email_items_table_tax_first', $cart_items, $invoice ); ?>
145
-                    <td colspan="<?php echo ( $cart_columns - 1 ); ?>" class="wpinv_cart_tax_label text-right">
144
+                    <?php do_action('wpinv_email_items_table_tax_first', $cart_items, $invoice); ?>
145
+                    <td colspan="<?php echo ($cart_columns - 1); ?>" class="wpinv_cart_tax_label text-right">
146 146
                         <strong><?php echo $tax_label; ?>:</strong>
147 147
                     </td>
148 148
                     <td class="wpinv_cart_tax text-right">
149
-                        <span class="wpinv_cart_tax_amount"><?php echo $invoice->get_tax( true ); ?></span>
149
+                        <span class="wpinv_cart_tax_amount"><?php echo $invoice->get_tax(true); ?></span>
150 150
                     </td>
151
-                    <?php do_action( 'wpinv_email_items_table_tax_last', $cart_items, $invoice ); ?>
151
+                    <?php do_action('wpinv_email_items_table_tax_last', $cart_items, $invoice); ?>
152 152
                 </tr>
153 153
             <?php } ?>
154 154
 
155 155
             <tr class="wpinv_cart_footer_row">
156
-                <?php do_action( 'wpinv_email_items_table_footer_first', $cart_items, $invoice ); ?>
157
-                <td colspan="<?php echo ( $cart_columns - 1 ); ?>" class="wpinv_cart_total_label text-right">
158
-                    <?php echo apply_filters( 'wpinv_email_cart_total_label', '<strong>' . __( 'Total', 'invoicing' ) . ':</strong>', $invoice ); ?>
156
+                <?php do_action('wpinv_email_items_table_footer_first', $cart_items, $invoice); ?>
157
+                <td colspan="<?php echo ($cart_columns - 1); ?>" class="wpinv_cart_total_label text-right">
158
+                    <?php echo apply_filters('wpinv_email_cart_total_label', '<strong>' . __('Total', 'invoicing') . ':</strong>', $invoice); ?>
159 159
                 </td>
160 160
                 <td class="wpinv_cart_total text-right">
161
-                    <span class="wpinv_cart_amount bold"><?php echo $invoice->get_total( true ); ?></span>
161
+                    <span class="wpinv_cart_amount bold"><?php echo $invoice->get_total(true); ?></span>
162 162
                 </td>
163
-                <?php do_action( 'wpinv_email_items_table_footer_last', $cart_items, $invoice ); ?>
163
+                <?php do_action('wpinv_email_items_table_footer_last', $cart_items, $invoice); ?>
164 164
             </tr>
165 165
         </tfoot>
166 166
     </table>
167 167
 </div>
168
-<?php do_action( 'wpinv_after_email_items', $invoice ); ?>
169 168
\ No newline at end of file
169
+<?php do_action('wpinv_after_email_items', $invoice); ?>
170 170
\ No newline at end of file
Please login to merge, or discard this patch.
templates/wpinv-checkout-cart.php 1 patch
Spacing   +61 added lines, -61 removed lines patch added patch discarded remove patch
@@ -5,140 +5,140 @@
 block discarded – undo
5 5
 
6 6
 global $wpinv_euvat, $post, $ajax_cart_details, $wpi_cart_columns, $wpi_session;
7 7
 $invoice            = wpinv_get_invoice_cart();
8
-$cart_items         = !empty( $ajax_cart_details ) ? $ajax_cart_details : wpinv_get_cart_content_details();
8
+$cart_items         = !empty($ajax_cart_details) ? $ajax_cart_details : wpinv_get_cart_content_details();
9 9
 $quantities_enabled = wpinv_item_quantities_enabled();
10 10
 $use_taxes          = wpinv_use_taxes();
11 11
 $tax_label          = $wpinv_euvat->tax_label();
12
-$tax_title          = $use_taxes ? ( wpinv_prices_include_tax() ? wp_sprintf( __( '(%s Incl.)', 'invoicing' ), $tax_label ) : wp_sprintf( __( '(%s Excl.)', 'invoicing' ), $tax_label ) ) : '';
12
+$tax_title          = $use_taxes ? (wpinv_prices_include_tax() ? wp_sprintf(__('(%s Incl.)', 'invoicing'), $tax_label) : wp_sprintf(__('(%s Excl.)', 'invoicing'), $tax_label)) : '';
13 13
 ?>
14 14
 <table id="wpinv_checkout_cart" class="table table-bordered table-hover">
15 15
     <thead>
16 16
         <tr class="wpinv_cart_header_row">
17
-            <?php do_action( 'wpinv_checkout_table_header_first' ); ?>
18
-            <th class="wpinv_cart_item_name text-left"><?php _e( 'Item Name', 'invoicing' ); ?></th>
19
-            <th class="wpinv_cart_item_price text-right"><?php _e( 'Item Price', 'invoicing' ); ?></th>
20
-            <?php if ( $quantities_enabled ) { ?>
21
-            <th class="wpinv_cart_item_qty text-right"><?php _e( 'Qty', 'invoicing' ); ?></th>
17
+            <?php do_action('wpinv_checkout_table_header_first'); ?>
18
+            <th class="wpinv_cart_item_name text-left"><?php _e('Item Name', 'invoicing'); ?></th>
19
+            <th class="wpinv_cart_item_price text-right"><?php _e('Item Price', 'invoicing'); ?></th>
20
+            <?php if ($quantities_enabled) { ?>
21
+            <th class="wpinv_cart_item_qty text-right"><?php _e('Qty', 'invoicing'); ?></th>
22 22
             <?php } ?>
23
-            <?php if ( $use_taxes ) { ?>
23
+            <?php if ($use_taxes) { ?>
24 24
             <th class="wpinv_cart_item_tax text-right"><?php echo $tax_label . ' <span class="normal small">(%)</span>'; ?></th>
25 25
             <?php } ?>
26
-            <th class="wpinv_cart_item_subtotal text-right"><?php echo __( 'Item Total', 'invoicing' ) . ' <span class="normal small">' . $tax_title . '<span>'; ?></th>
27
-            <?php do_action( 'wpinv_checkout_table_header_last' ); ?>
26
+            <th class="wpinv_cart_item_subtotal text-right"><?php echo __('Item Total', 'invoicing') . ' <span class="normal small">' . $tax_title . '<span>'; ?></th>
27
+            <?php do_action('wpinv_checkout_table_header_last'); ?>
28 28
         </tr>
29 29
     </thead>
30 30
     <tbody>
31 31
         <?php
32
-            do_action( 'wpinv_cart_items_before' );
32
+            do_action('wpinv_cart_items_before');
33 33
             
34
-            if ( $cart_items ) {
35
-                foreach ( $cart_items as $key => $item ) {
36
-                    $wpi_item = !empty( $item['id'] ) ? new WPInv_Item( $item['id'] ) : NULL;
34
+            if ($cart_items) {
35
+                foreach ($cart_items as $key => $item) {
36
+                    $wpi_item = !empty($item['id']) ? new WPInv_Item($item['id']) : NULL;
37 37
                 ?>
38
-                <tr class="wpinv_cart_item" id="wpinv_cart_item_<?php echo esc_attr( $key ) . '_' . esc_attr( $item['id'] ); ?>" data-item-id="<?php echo esc_attr( $item['id'] ); ?>">
39
-                    <?php do_action( 'wpinv_checkout_table_body_first', $item ); ?>
38
+                <tr class="wpinv_cart_item" id="wpinv_cart_item_<?php echo esc_attr($key) . '_' . esc_attr($item['id']); ?>" data-item-id="<?php echo esc_attr($item['id']); ?>">
39
+                    <?php do_action('wpinv_checkout_table_body_first', $item); ?>
40 40
                     <td class="wpinv_cart_item_name text-left">
41 41
                         <?php
42
-                            if ( current_theme_supports( 'post-thumbnails' ) && has_post_thumbnail( $item['id'] ) ) {
42
+                            if (current_theme_supports('post-thumbnails') && has_post_thumbnail($item['id'])) {
43 43
                                 echo '<div class="wpinv_cart_item_image">';
44
-                                    echo get_the_post_thumbnail( $item['id'], apply_filters( 'wpinv_checkout_image_size', array( 25,25 ) ) );
44
+                                    echo get_the_post_thumbnail($item['id'], apply_filters('wpinv_checkout_image_size', array(25, 25)));
45 45
                                 echo '</div>';
46 46
                             }
47
-                            $item_title = esc_html( wpinv_get_cart_item_name( $item ) ) . wpinv_get_item_suffix( $wpi_item );
47
+                            $item_title = esc_html(wpinv_get_cart_item_name($item)) . wpinv_get_item_suffix($wpi_item);
48 48
                             echo '<span class="wpinv_checkout_cart_item_title">' . $item_title . '</span>';
49
-                            if ( !empty( $wpi_item ) && $wpi_item->is_package() && !empty( $item['meta']['post_id'] ) ) {
50
-                                $post_link = !empty( $item['meta']['invoice_title'] ) ? $item['meta']['invoice_title'] : get_the_title( $item['meta']['post_id'] );
51
-                                $summary = wp_sprintf( __( '%s: %s', 'invoicing' ), $wpi_item->get_custom_singular_name(), $post_link );
52
-                                echo '<small class="meta">' . wpautop( wp_kses_post( $summary ) ) . '</small>';
49
+                            if (!empty($wpi_item) && $wpi_item->is_package() && !empty($item['meta']['post_id'])) {
50
+                                $post_link = !empty($item['meta']['invoice_title']) ? $item['meta']['invoice_title'] : get_the_title($item['meta']['post_id']);
51
+                                $summary = wp_sprintf(__('%s: %s', 'invoicing'), $wpi_item->get_custom_singular_name(), $post_link);
52
+                                echo '<small class="meta">' . wpautop(wp_kses_post($summary)) . '</small>';
53 53
                             }
54
-                            do_action( 'wpinv_checkout_cart_item_title_after', $item, $key );
54
+                            do_action('wpinv_checkout_cart_item_title_after', $item, $key);
55 55
                         ?>
56 56
                     </td>
57 57
                     <td class="wpinv_cart_item_price text-right">
58 58
                         <?php 
59
-                        echo wpinv_cart_item_price( $item );
60
-                        do_action( 'wpinv_checkout_cart_item_price_after', $item, $key );
59
+                        echo wpinv_cart_item_price($item);
60
+                        do_action('wpinv_checkout_cart_item_price_after', $item, $key);
61 61
                         ?>
62 62
                     </td>
63
-                    <?php if ( $quantities_enabled ) { ?>
63
+                    <?php if ($quantities_enabled) { ?>
64 64
                     <td class="wpinv_cart_item_qty text-right">
65 65
                         <?php
66
-                        echo wpinv_get_cart_item_quantity( $item );
67
-                        do_action( 'wpinv_cart_item_quantitiy', $item, $key );
66
+                        echo wpinv_get_cart_item_quantity($item);
67
+                        do_action('wpinv_cart_item_quantitiy', $item, $key);
68 68
                         ?>
69 69
                     </td>
70 70
                     <?php } ?>
71
-                    <?php if ( $use_taxes ) { ?>
71
+                    <?php if ($use_taxes) { ?>
72 72
                     <td class="wpinv_cart_item_tax text-right">
73 73
                         <?php
74
-                        echo wpinv_cart_item_tax( $item );
74
+                        echo wpinv_cart_item_tax($item);
75 75
                         //echo wpinv_get_cart_item_tax( $wpi_item->ID, $subtotal = '', $options = array() );
76
-                        do_action( 'wpinv_cart_item_tax', $item, $key );
76
+                        do_action('wpinv_cart_item_tax', $item, $key);
77 77
                         ?>
78 78
                     </td>
79 79
                     <?php } ?>
80 80
                     <td class="wpinv_cart_item_subtotal text-right">
81 81
                         <?php
82
-                        echo wpinv_cart_item_subtotal( $item );
83
-                        do_action( 'wpinv_cart_item_subtotal', $item, $key );
82
+                        echo wpinv_cart_item_subtotal($item);
83
+                        do_action('wpinv_cart_item_subtotal', $item, $key);
84 84
                         ?>
85 85
                     </td>
86
-                    <?php do_action( 'wpinv_checkout_table_body_last', $item, $key ); ?>
86
+                    <?php do_action('wpinv_checkout_table_body_last', $item, $key); ?>
87 87
                 </tr>
88 88
             <?php } ?>
89 89
         <?php } ?>
90
-        <?php do_action( 'wpinv_cart_items_middle' ); ?>
91
-        <?php do_action( 'wpinv_cart_items_after' ); ?>
90
+        <?php do_action('wpinv_cart_items_middle'); ?>
91
+        <?php do_action('wpinv_cart_items_after'); ?>
92 92
     </tbody>
93 93
     <tfoot>
94 94
         <?php $cart_columns = wpinv_checkout_cart_columns(); ?>
95
-        <?php if ( has_action( 'wpinv_cart_footer_buttons' ) ) { ?>
95
+        <?php if (has_action('wpinv_cart_footer_buttons')) { ?>
96 96
             <tr class="wpinv_cart_footer_row">
97
-                <?php do_action( 'wpinv_checkout_table_buttons_first', $cart_items ); ?>
98
-                <td colspan="<?php echo ( $cart_columns ); ?>">
99
-                    <?php do_action( 'wpinv_cart_footer_buttons' ); ?>
97
+                <?php do_action('wpinv_checkout_table_buttons_first', $cart_items); ?>
98
+                <td colspan="<?php echo ($cart_columns); ?>">
99
+                    <?php do_action('wpinv_cart_footer_buttons'); ?>
100 100
                 </td>
101
-                <?php do_action( 'wpinv_checkout_table_buttons_first', $cart_items ); ?>
101
+                <?php do_action('wpinv_checkout_table_buttons_first', $cart_items); ?>
102 102
             </tr>
103 103
         <?php } ?>
104 104
 
105
-        <?php if ( $use_taxes && !wpinv_prices_include_tax() ) { ?>
106
-            <tr class="wpinv_cart_footer_row wpinv_cart_subtotal_row"<?php if ( !wpinv_is_cart_taxed() ) echo ' style="display:none;"'; ?>>
107
-                <?php do_action( 'wpinv_checkout_table_subtotal_first', $cart_items ); ?>
108
-                <td colspan="<?php echo ( $cart_columns - 1 ); ?>" class="wpinv_cart_subtotal_label text-right">
109
-                    <strong><?php _e( 'Sub-Total', 'invoicing' ); ?>:</strong>
105
+        <?php if ($use_taxes && !wpinv_prices_include_tax()) { ?>
106
+            <tr class="wpinv_cart_footer_row wpinv_cart_subtotal_row"<?php if (!wpinv_is_cart_taxed()) echo ' style="display:none;"'; ?>>
107
+                <?php do_action('wpinv_checkout_table_subtotal_first', $cart_items); ?>
108
+                <td colspan="<?php echo ($cart_columns - 1); ?>" class="wpinv_cart_subtotal_label text-right">
109
+                    <strong><?php _e('Sub-Total', 'invoicing'); ?>:</strong>
110 110
                 </td>
111 111
                 <td class="wpinv_cart_subtotal text-right">
112
-                    <span class="wpinv_cart_subtotal_amount bold"><?php echo wpinv_cart_subtotal( $cart_items ); ?></span>
112
+                    <span class="wpinv_cart_subtotal_amount bold"><?php echo wpinv_cart_subtotal($cart_items); ?></span>
113 113
                 </td>
114
-                <?php do_action( 'wpinv_checkout_table_subtotal_last', $cart_items ); ?>
114
+                <?php do_action('wpinv_checkout_table_subtotal_last', $cart_items); ?>
115 115
             </tr>
116 116
         <?php } ?>
117 117
         
118
-        <?php $wpi_cart_columns = $cart_columns - 1; wpinv_cart_discounts_html( $cart_items ); ?>
118
+        <?php $wpi_cart_columns = $cart_columns - 1; wpinv_cart_discounts_html($cart_items); ?>
119 119
 
120
-        <?php if ( $use_taxes ) { ?>
121
-            <tr class="wpinv_cart_footer_row wpinv_cart_tax_row"<?php if( !wpinv_is_cart_taxed() ) echo ' style="display:none;"'; ?>>
122
-                <?php do_action( 'wpinv_checkout_table_tax_first' ); ?>
123
-                <td colspan="<?php echo ( $cart_columns - 1 ); ?>" class="wpinv_cart_tax_label text-right">
120
+        <?php if ($use_taxes) { ?>
121
+            <tr class="wpinv_cart_footer_row wpinv_cart_tax_row"<?php if (!wpinv_is_cart_taxed()) echo ' style="display:none;"'; ?>>
122
+                <?php do_action('wpinv_checkout_table_tax_first'); ?>
123
+                <td colspan="<?php echo ($cart_columns - 1); ?>" class="wpinv_cart_tax_label text-right">
124 124
                     <strong><?php echo $tax_label; ?>:</strong>
125 125
                 </td>
126 126
                 <td class="wpinv_cart_tax text-right">
127
-                    <span class="wpinv_cart_tax_amount" data-tax="<?php echo wpinv_get_cart_tax( $cart_items ); ?>"><?php echo esc_html( wpinv_cart_tax( $cart_items ) ); ?></span>
127
+                    <span class="wpinv_cart_tax_amount" data-tax="<?php echo wpinv_get_cart_tax($cart_items); ?>"><?php echo esc_html(wpinv_cart_tax($cart_items)); ?></span>
128 128
                 </td>
129
-                <?php do_action( 'wpinv_checkout_table_tax_last' ); ?>
129
+                <?php do_action('wpinv_checkout_table_tax_last'); ?>
130 130
             </tr>
131 131
         <?php } ?>
132 132
 
133 133
         <tr class="wpinv_cart_footer_row wpinv_cart_total_row">
134
-            <?php do_action( 'wpinv_checkout_table_footer_first' ); ?>
135
-            <td colspan="<?php echo ( $cart_columns - 1 ); ?>" class="wpinv_cart_total_label text-right">
136
-                <?php echo apply_filters( 'wpinv_cart_total_label', '<strong>' . __( 'Total', 'invoicing' ) . ':</strong>', $invoice ); ?>
134
+            <?php do_action('wpinv_checkout_table_footer_first'); ?>
135
+            <td colspan="<?php echo ($cart_columns - 1); ?>" class="wpinv_cart_total_label text-right">
136
+                <?php echo apply_filters('wpinv_cart_total_label', '<strong>' . __('Total', 'invoicing') . ':</strong>', $invoice); ?>
137 137
             </td>
138 138
             <td class="wpinv_cart_total text-right">
139
-                <span class="wpinv_cart_amount bold" data-subtotal="<?php echo wpinv_get_cart_total( $cart_items ); ?>" data-total="<?php echo wpinv_get_cart_total( NULL, NULL, $invoice ); ?>"><?php wpinv_cart_total( $cart_items, true, $invoice ); ?></span>
139
+                <span class="wpinv_cart_amount bold" data-subtotal="<?php echo wpinv_get_cart_total($cart_items); ?>" data-total="<?php echo wpinv_get_cart_total(NULL, NULL, $invoice); ?>"><?php wpinv_cart_total($cart_items, true, $invoice); ?></span>
140 140
             </td>
141
-            <?php do_action( 'wpinv_checkout_table_footer_last' ); ?>
141
+            <?php do_action('wpinv_checkout_table_footer_last'); ?>
142 142
         </tr>
143 143
     </tfoot>
144 144
 </table>
Please login to merge, or discard this patch.
includes/wpinv-helper-functions.php 2 patches
Doc Comments   +28 added lines, -1 removed lines patch added patch discarded remove patch
@@ -31,6 +31,9 @@  discard block
 block discarded – undo
31 31
     return apply_filters( 'wpinv_get_ip', $ip );
32 32
 }
33 33
 
34
+/**
35
+ * @return string
36
+ */
34 37
 function wpinv_get_user_agent() {
35 38
     if ( ! empty( $_SERVER['HTTP_USER_AGENT'] ) ) {
36 39
         $user_agent = sanitize_text_field( $_SERVER['HTTP_USER_AGENT'] );
@@ -41,6 +44,9 @@  discard block
 block discarded – undo
41 44
     return apply_filters( 'wpinv_get_user_agent', $user_agent );
42 45
 }
43 46
 
47
+/**
48
+ * @param integer $decimals
49
+ */
44 50
 function wpinv_sanitize_amount( $amount, $decimals = NULL ) {
45 51
     $is_negative   = false;
46 52
     $thousands_sep = wpinv_thousands_separator();
@@ -79,6 +85,9 @@  discard block
 block discarded – undo
79 85
 }
80 86
 add_filter( 'wpinv_sanitize_amount_decimals', 'wpinv_currency_decimal_filter', 10, 1 );
81 87
 
88
+/**
89
+ * @param integer $decimals
90
+ */
82 91
 function wpinv_round_amount( $amount, $decimals = NULL ) {
83 92
     if ( $decimals === NULL ) {
84 93
         $decimals = wpinv_decimals();
@@ -117,6 +126,9 @@  discard block
 block discarded – undo
117 126
     return $status;
118 127
 }
119 128
 
129
+/**
130
+ * @return string
131
+ */
120 132
 function wpinv_get_currency() {
121 133
     $currency = wpinv_get_option( 'currency', 'USD' );
122 134
     
@@ -187,6 +199,9 @@  discard block
 block discarded – undo
187 199
     return apply_filters( 'wpinv_currency_symbol', $currency_symbol, $currency );
188 200
 }
189 201
 
202
+/**
203
+ * @return string
204
+ */
190 205
 function wpinv_currency_position() {
191 206
     $position = wpinv_get_option( 'currency_position', 'left' );
192 207
     
@@ -315,6 +330,9 @@  discard block
 block discarded – undo
315 330
     return $price;
316 331
 }
317 332
 
333
+/**
334
+ * @return string
335
+ */
318 336
 function wpinv_format_amount( $amount, $decimals = NULL, $calculate = false ) {
319 337
     $thousands_sep = wpinv_thousands_separator();
320 338
     $decimal_sep   = wpinv_decimal_separator();
@@ -365,6 +383,9 @@  discard block
 block discarded – undo
365 383
     return apply_filters( 'wpinv_sanitize_key', $key, $raw_key );
366 384
 }
367 385
 
386
+/**
387
+ * @return string
388
+ */
368 389
 function wpinv_get_file_extension( $str ) {
369 390
     $parts = explode( '.', $str );
370 391
     return end( $parts );
@@ -569,6 +590,9 @@  discard block
 block discarded – undo
569 590
     return strlen( $str );
570 591
 }
571 592
 
593
+/**
594
+ * @param string $str
595
+ */
572 596
 function wpinv_utf8_strtolower( $str, $encoding = 'UTF-8' ) {
573 597
     if ( function_exists( 'mb_strtolower' ) ) {
574 598
         return mb_strtolower( $str, $encoding );
@@ -577,6 +601,9 @@  discard block
 block discarded – undo
577 601
     return strtolower( $str );
578 602
 }
579 603
 
604
+/**
605
+ * @param string $str
606
+ */
580 607
 function wpinv_utf8_strtoupper( $str, $encoding = 'UTF-8' ) {
581 608
     if ( function_exists( 'mb_strtoupper' ) ) {
582 609
         return mb_strtoupper( $str, $encoding );
@@ -654,7 +681,7 @@  discard block
 block discarded – undo
654 681
  *
655 682
  * @param string $str The string being decoded.
656 683
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
657
- * @return string The width of string.
684
+ * @return integer The width of string.
658 685
  */
659 686
 function wpinv_utf8_strwidth( $str, $encoding = 'UTF-8' ) {
660 687
     if ( function_exists( 'mb_strwidth' ) ) {
Please login to merge, or discard this patch.
Spacing   +235 added lines, -235 removed lines patch added patch discarded remove patch
@@ -7,89 +7,89 @@  discard block
 block discarded – undo
7 7
  */
8 8
  
9 9
 // MUST have WordPress.
10
-if ( !defined( 'WPINC' ) ) {
11
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
10
+if (!defined('WPINC')) {
11
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
12 12
 }
13 13
 
14 14
 function wpinv_item_quantities_enabled() {
15
-    $ret = wpinv_get_option( 'item_quantities', true );
15
+    $ret = wpinv_get_option('item_quantities', true);
16 16
     
17
-    return (bool) apply_filters( 'wpinv_item_quantities_enabled', $ret );
17
+    return (bool)apply_filters('wpinv_item_quantities_enabled', $ret);
18 18
 }
19 19
 
20 20
 function wpinv_get_ip() {
21 21
     $ip = '127.0.0.1';
22 22
 
23
-    if ( !empty( $_SERVER['HTTP_CLIENT_IP'] ) ) {
24
-        $ip = sanitize_text_field( $_SERVER['HTTP_CLIENT_IP'] );
25
-    } elseif ( !empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
26
-        $ip = sanitize_text_field( $_SERVER['HTTP_X_FORWARDED_FOR'] );
27
-    } elseif( !empty( $_SERVER['REMOTE_ADDR'] ) ) {
28
-        $ip = sanitize_text_field( $_SERVER['REMOTE_ADDR'] );
23
+    if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
24
+        $ip = sanitize_text_field($_SERVER['HTTP_CLIENT_IP']);
25
+    } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
26
+        $ip = sanitize_text_field($_SERVER['HTTP_X_FORWARDED_FOR']);
27
+    } elseif (!empty($_SERVER['REMOTE_ADDR'])) {
28
+        $ip = sanitize_text_field($_SERVER['REMOTE_ADDR']);
29 29
     }
30 30
     
31
-    return apply_filters( 'wpinv_get_ip', $ip );
31
+    return apply_filters('wpinv_get_ip', $ip);
32 32
 }
33 33
 
34 34
 function wpinv_get_user_agent() {
35
-    if ( ! empty( $_SERVER['HTTP_USER_AGENT'] ) ) {
36
-        $user_agent = sanitize_text_field( $_SERVER['HTTP_USER_AGENT'] );
35
+    if (!empty($_SERVER['HTTP_USER_AGENT'])) {
36
+        $user_agent = sanitize_text_field($_SERVER['HTTP_USER_AGENT']);
37 37
     } else {
38 38
         $user_agent = '';
39 39
     }
40 40
     
41
-    return apply_filters( 'wpinv_get_user_agent', $user_agent );
41
+    return apply_filters('wpinv_get_user_agent', $user_agent);
42 42
 }
43 43
 
44
-function wpinv_sanitize_amount( $amount, $decimals = NULL ) {
44
+function wpinv_sanitize_amount($amount, $decimals = NULL) {
45 45
     $is_negative   = false;
46 46
     $thousands_sep = wpinv_thousands_separator();
47 47
     $decimal_sep   = wpinv_decimal_separator();
48
-    if ( $decimals === NULL ) {
48
+    if ($decimals === NULL) {
49 49
         $decimals = wpinv_decimals();
50 50
     }
51 51
 
52 52
     // Sanitize the amount
53
-    if ( $decimal_sep == ',' && false !== ( $found = strpos( $amount, $decimal_sep ) ) ) {
54
-        if ( ( $thousands_sep == '.' || $thousands_sep == ' ' ) && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) {
55
-            $amount = str_replace( $thousands_sep, '', $amount );
56
-        } elseif( empty( $thousands_sep ) && false !== ( $found = strpos( $amount, '.' ) ) ) {
57
-            $amount = str_replace( '.', '', $amount );
53
+    if ($decimal_sep == ',' && false !== ($found = strpos($amount, $decimal_sep))) {
54
+        if (($thousands_sep == '.' || $thousands_sep == ' ') && false !== ($found = strpos($amount, $thousands_sep))) {
55
+            $amount = str_replace($thousands_sep, '', $amount);
56
+        } elseif (empty($thousands_sep) && false !== ($found = strpos($amount, '.'))) {
57
+            $amount = str_replace('.', '', $amount);
58 58
         }
59 59
 
60
-        $amount = str_replace( $decimal_sep, '.', $amount );
61
-    } elseif( $thousands_sep == ',' && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) {
62
-        $amount = str_replace( $thousands_sep, '', $amount );
60
+        $amount = str_replace($decimal_sep, '.', $amount);
61
+    } elseif ($thousands_sep == ',' && false !== ($found = strpos($amount, $thousands_sep))) {
62
+        $amount = str_replace($thousands_sep, '', $amount);
63 63
     }
64 64
 
65
-    if( $amount < 0 ) {
65
+    if ($amount < 0) {
66 66
         $is_negative = true;
67 67
     }
68 68
 
69
-    $amount   = preg_replace( '/[^0-9\.]/', '', $amount );
69
+    $amount   = preg_replace('/[^0-9\.]/', '', $amount);
70 70
 
71
-    $decimals = apply_filters( 'wpinv_sanitize_amount_decimals', absint( $decimals ), $amount );
72
-    $amount   = number_format( (double) $amount, absint( $decimals ), '.', '' );
71
+    $decimals = apply_filters('wpinv_sanitize_amount_decimals', absint($decimals), $amount);
72
+    $amount   = number_format((double)$amount, absint($decimals), '.', '');
73 73
 
74
-    if( $is_negative ) {
74
+    if ($is_negative) {
75 75
         $amount *= -1;
76 76
     }
77 77
 
78
-    return apply_filters( 'wpinv_sanitize_amount', $amount, $decimals );
78
+    return apply_filters('wpinv_sanitize_amount', $amount, $decimals);
79 79
 }
80
-add_filter( 'wpinv_sanitize_amount_decimals', 'wpinv_currency_decimal_filter', 10, 1 );
80
+add_filter('wpinv_sanitize_amount_decimals', 'wpinv_currency_decimal_filter', 10, 1);
81 81
 
82
-function wpinv_round_amount( $amount, $decimals = NULL ) {
83
-    if ( $decimals === NULL ) {
82
+function wpinv_round_amount($amount, $decimals = NULL) {
83
+    if ($decimals === NULL) {
84 84
         $decimals = wpinv_decimals();
85 85
     }
86 86
     
87
-    $amount = round( (double)$amount, wpinv_currency_decimal_filter( absint( $decimals ) ) );
87
+    $amount = round((double)$amount, wpinv_currency_decimal_filter(absint($decimals)));
88 88
 
89
-    return apply_filters( 'wpinv_round_amount', $amount, $decimals );
89
+    return apply_filters('wpinv_round_amount', $amount, $decimals);
90 90
 }
91 91
 
92
-function wpinv_get_invoice_statuses( $trashed = false ) {
92
+function wpinv_get_invoice_statuses($trashed = false) {
93 93
     global $post;
94 94
     $invoice_statuses = array();
95 95
     $invoice_statuses = array(
@@ -103,32 +103,32 @@  discard block
 block discarded – undo
103 103
         'wpi-renewal' => __('Renewal Payment', 'invoicing')
104 104
     );
105 105
     
106
-    if ( $trashed ) {
107
-        $invoice_statuses['trash'] = __( 'Trash', 'invoicing' );
106
+    if ($trashed) {
107
+        $invoice_statuses['trash'] = __('Trash', 'invoicing');
108 108
     }
109 109
 
110
-    return apply_filters( 'wpinv_statuses', $invoice_statuses );
110
+    return apply_filters('wpinv_statuses', $invoice_statuses);
111 111
 }
112 112
 
113
-function wpinv_status_nicename( $status ) {
113
+function wpinv_status_nicename($status) {
114 114
     $statuses = wpinv_get_invoice_statuses();
115
-    $status   = isset( $statuses[$status] ) ? $statuses[$status] : __( $status, 'invoicing' );
115
+    $status   = isset($statuses[$status]) ? $statuses[$status] : __($status, 'invoicing');
116 116
 
117 117
     return $status;
118 118
 }
119 119
 
120 120
 function wpinv_get_currency() {
121
-    $currency = wpinv_get_option( 'currency', 'USD' );
121
+    $currency = wpinv_get_option('currency', 'USD');
122 122
     
123
-    return apply_filters( 'wpinv_currency', $currency );
123
+    return apply_filters('wpinv_currency', $currency);
124 124
 }
125 125
 
126
-function wpinv_currency_symbol( $currency = '' ) {
127
-    if ( empty( $currency ) ) {
126
+function wpinv_currency_symbol($currency = '') {
127
+    if (empty($currency)) {
128 128
         $currency = wpinv_get_currency();
129 129
     }
130 130
     
131
-    $symbols = apply_filters( 'wpinv_currency_symbols', array(
131
+    $symbols = apply_filters('wpinv_currency_symbols', array(
132 132
         'AED' => 'د.إ',
133 133
         'ARS' => '&#36;',
134 134
         'AUD' => '&#36;',
@@ -180,78 +180,78 @@  discard block
 block discarded – undo
180 180
         'USD' => '&#36;',
181 181
         'VND' => '&#8363;',
182 182
         'ZAR' => '&#82;',
183
-    ) );
183
+    ));
184 184
 
185
-    $currency_symbol = isset( $symbols[$currency] ) ? $symbols[$currency] : '&#36;';
185
+    $currency_symbol = isset($symbols[$currency]) ? $symbols[$currency] : '&#36;';
186 186
 
187
-    return apply_filters( 'wpinv_currency_symbol', $currency_symbol, $currency );
187
+    return apply_filters('wpinv_currency_symbol', $currency_symbol, $currency);
188 188
 }
189 189
 
190 190
 function wpinv_currency_position() {
191
-    $position = wpinv_get_option( 'currency_position', 'left' );
191
+    $position = wpinv_get_option('currency_position', 'left');
192 192
     
193
-    return apply_filters( 'wpinv_currency_position', $position );
193
+    return apply_filters('wpinv_currency_position', $position);
194 194
 }
195 195
 
196 196
 function wpinv_thousands_separator() {
197
-    $thousand_sep = wpinv_get_option( 'thousands_separator', ',' );
197
+    $thousand_sep = wpinv_get_option('thousands_separator', ',');
198 198
     
199
-    return apply_filters( 'wpinv_thousands_separator', $thousand_sep );
199
+    return apply_filters('wpinv_thousands_separator', $thousand_sep);
200 200
 }
201 201
 
202 202
 function wpinv_decimal_separator() {
203
-    $decimal_sep = wpinv_get_option( 'decimal_separator', '.' );
203
+    $decimal_sep = wpinv_get_option('decimal_separator', '.');
204 204
     
205
-    return apply_filters( 'wpinv_decimal_separator', $decimal_sep );
205
+    return apply_filters('wpinv_decimal_separator', $decimal_sep);
206 206
 }
207 207
 
208 208
 function wpinv_decimals() {
209
-    $decimals = apply_filters( 'wpinv_decimals', wpinv_get_option( 'decimals', 2 ) );
209
+    $decimals = apply_filters('wpinv_decimals', wpinv_get_option('decimals', 2));
210 210
     
211
-    return absint( $decimals );
211
+    return absint($decimals);
212 212
 }
213 213
 
214 214
 function wpinv_get_currencies() {
215 215
     $currencies = array(
216
-        'USD'  => __( 'US Dollars (&#36;)', 'invoicing' ),
217
-        'EUR'  => __( 'Euros (&euro;)', 'invoicing' ),
218
-        'GBP'  => __( 'Pounds Sterling (&pound;)', 'invoicing' ),
219
-        'AUD'  => __( 'Australian Dollars (&#36;)', 'invoicing' ),
220
-        'BRL'  => __( 'Brazilian Real (R&#36;)', 'invoicing' ),
221
-        'CAD'  => __( 'Canadian Dollars (&#36;)', 'invoicing' ),
222
-        'CLP'  => __( 'Chilean Peso (&#36;)', 'invoicing' ),
223
-        'CNY'  => __( 'Chinese Yuan (&yen;)', 'invoicing' ),
224
-        'CZK'  => __( 'Czech Koruna (&#75;&#269;)', 'invoicing' ),
225
-        'DKK'  => __( 'Danish Krone (DKK)', 'invoicing' ),
226
-        'HKD'  => __( 'Hong Kong Dollar (&#36;)', 'invoicing' ),
227
-        'HUF'  => __( 'Hungarian Forint (&#70;&#116;)', 'invoicing' ),
228
-        'INR'  => __( 'Indian Rupee (&#8377;)', 'invoicing' ),
229
-        'ILS'  => __( 'Israeli Shekel (&#8362;)', 'invoicing' ),
230
-        'JPY'  => __( 'Japanese Yen (&yen;)', 'invoicing' ),
231
-        'MYR'  => __( 'Malaysian Ringgit (&#82;&#77;)', 'invoicing' ),
232
-        'MXN'  => __( 'Mexican Peso (&#36;)', 'invoicing' ),
233
-        'NZD'  => __( 'New Zealand Dollar (&#36;)', 'invoicing' ),
234
-        'NOK'  => __( 'Norwegian Krone (&#107;&#114;)', 'invoicing' ),
235
-        'PHP'  => __( 'Philippine Peso (&#8369;)', 'invoicing' ),
236
-        'PLN'  => __( 'Polish Zloty (&#122;&#322;)', 'invoicing' ),
237
-        'SGD'  => __( 'Singapore Dollar (&#36;)', 'invoicing' ),
238
-        'SEK'  => __( 'Swedish Krona (&#107;&#114;)', 'invoicing' ),
239
-        'CHF'  => __( 'Swiss Franc (&#67;&#72;&#70;)', 'invoicing' ),
240
-        'TWD'  => __( 'Taiwan New Dollar (&#78;&#84;&#36;)', 'invoicing' ),
241
-        'THB'  => __( 'Thai Baht (&#3647;)', 'invoicing' ),
242
-        'TRY'  => __( 'Turkish Lira (&#8378;)', 'invoicing' ),
243
-        'RIAL' => __( 'Iranian Rial (&#65020;)', 'invoicing' ),
244
-        'RUB'  => __( 'Russian Ruble (&#8381;)', 'invoicing' ),
245
-        'ZAR'  => __( 'South African Rand (&#82;)', 'invoicing' )
216
+        'USD'  => __('US Dollars (&#36;)', 'invoicing'),
217
+        'EUR'  => __('Euros (&euro;)', 'invoicing'),
218
+        'GBP'  => __('Pounds Sterling (&pound;)', 'invoicing'),
219
+        'AUD'  => __('Australian Dollars (&#36;)', 'invoicing'),
220
+        'BRL'  => __('Brazilian Real (R&#36;)', 'invoicing'),
221
+        'CAD'  => __('Canadian Dollars (&#36;)', 'invoicing'),
222
+        'CLP'  => __('Chilean Peso (&#36;)', 'invoicing'),
223
+        'CNY'  => __('Chinese Yuan (&yen;)', 'invoicing'),
224
+        'CZK'  => __('Czech Koruna (&#75;&#269;)', 'invoicing'),
225
+        'DKK'  => __('Danish Krone (DKK)', 'invoicing'),
226
+        'HKD'  => __('Hong Kong Dollar (&#36;)', 'invoicing'),
227
+        'HUF'  => __('Hungarian Forint (&#70;&#116;)', 'invoicing'),
228
+        'INR'  => __('Indian Rupee (&#8377;)', 'invoicing'),
229
+        'ILS'  => __('Israeli Shekel (&#8362;)', 'invoicing'),
230
+        'JPY'  => __('Japanese Yen (&yen;)', 'invoicing'),
231
+        'MYR'  => __('Malaysian Ringgit (&#82;&#77;)', 'invoicing'),
232
+        'MXN'  => __('Mexican Peso (&#36;)', 'invoicing'),
233
+        'NZD'  => __('New Zealand Dollar (&#36;)', 'invoicing'),
234
+        'NOK'  => __('Norwegian Krone (&#107;&#114;)', 'invoicing'),
235
+        'PHP'  => __('Philippine Peso (&#8369;)', 'invoicing'),
236
+        'PLN'  => __('Polish Zloty (&#122;&#322;)', 'invoicing'),
237
+        'SGD'  => __('Singapore Dollar (&#36;)', 'invoicing'),
238
+        'SEK'  => __('Swedish Krona (&#107;&#114;)', 'invoicing'),
239
+        'CHF'  => __('Swiss Franc (&#67;&#72;&#70;)', 'invoicing'),
240
+        'TWD'  => __('Taiwan New Dollar (&#78;&#84;&#36;)', 'invoicing'),
241
+        'THB'  => __('Thai Baht (&#3647;)', 'invoicing'),
242
+        'TRY'  => __('Turkish Lira (&#8378;)', 'invoicing'),
243
+        'RIAL' => __('Iranian Rial (&#65020;)', 'invoicing'),
244
+        'RUB'  => __('Russian Ruble (&#8381;)', 'invoicing'),
245
+        'ZAR'  => __('South African Rand (&#82;)', 'invoicing')
246 246
     );
247 247
     
248
-    asort( $currencies );
248
+    asort($currencies);
249 249
 
250
-    return apply_filters( 'wpinv_currencies', $currencies );
250
+    return apply_filters('wpinv_currencies', $currencies);
251 251
 }
252 252
 
253
-function wpinv_price( $amount = '', $currency = '' ) {
254
-    if( empty( $currency ) ) {
253
+function wpinv_price($amount = '', $currency = '') {
254
+    if (empty($currency)) {
255 255
         $currency = wpinv_get_currency();
256 256
     }
257 257
 
@@ -259,14 +259,14 @@  discard block
 block discarded – undo
259 259
 
260 260
     $negative = $amount < 0;
261 261
 
262
-    if ( $negative ) {
263
-        $amount = substr( $amount, 1 );
262
+    if ($negative) {
263
+        $amount = substr($amount, 1);
264 264
     }
265 265
 
266
-    $symbol = wpinv_currency_symbol( $currency );
266
+    $symbol = wpinv_currency_symbol($currency);
267 267
 
268
-    if ( $position == 'left' || $position == 'left_space' ) {
269
-        switch ( $currency ) {
268
+    if ($position == 'left' || $position == 'left_space') {
269
+        switch ($currency) {
270 270
             case "GBP" :
271 271
             case "BRL" :
272 272
             case "EUR" :
@@ -278,15 +278,15 @@  discard block
 block discarded – undo
278 278
             case "NZD" :
279 279
             case "SGD" :
280 280
             case "JPY" :
281
-                $price = $position == 'left_space' ? $symbol . ' ' .  $amount : $symbol . $amount;
281
+                $price = $position == 'left_space' ? $symbol . ' ' . $amount : $symbol . $amount;
282 282
                 break;
283 283
             default :
284 284
                 //$price = $currency . ' ' . $amount;
285
-                $price = $position == 'left_space' ? $symbol . ' ' .  $amount : $symbol . $amount;
285
+                $price = $position == 'left_space' ? $symbol . ' ' . $amount : $symbol . $amount;
286 286
                 break;
287 287
         }
288 288
     } else {
289
-        switch ( $currency ) {
289
+        switch ($currency) {
290 290
             case "GBP" :
291 291
             case "BRL" :
292 292
             case "EUR" :
@@ -297,83 +297,83 @@  discard block
 block discarded – undo
297 297
             case "MXN" :
298 298
             case "SGD" :
299 299
             case "JPY" :
300
-                $price = $position == 'right_space' ? $amount . ' ' .  $symbol : $amount . $symbol;
300
+                $price = $position == 'right_space' ? $amount . ' ' . $symbol : $amount . $symbol;
301 301
                 break;
302 302
             default :
303 303
                 //$price = $amount . ' ' . $currency;
304
-                $price = $position == 'right_space' ? $amount . ' ' .  $symbol : $amount . $symbol;
304
+                $price = $position == 'right_space' ? $amount . ' ' . $symbol : $amount . $symbol;
305 305
                 break;
306 306
         }
307 307
     }
308 308
     
309
-    if ( $negative ) {
309
+    if ($negative) {
310 310
         $price = '-' . $price;
311 311
     }
312 312
     
313
-    $price = apply_filters( 'wpinv_' . strtolower( $currency ) . '_currency_filter_' . $position, $price, $currency, $amount );
313
+    $price = apply_filters('wpinv_' . strtolower($currency) . '_currency_filter_' . $position, $price, $currency, $amount);
314 314
 
315 315
     return $price;
316 316
 }
317 317
 
318
-function wpinv_format_amount( $amount, $decimals = NULL, $calculate = false ) {
318
+function wpinv_format_amount($amount, $decimals = NULL, $calculate = false) {
319 319
     $thousands_sep = wpinv_thousands_separator();
320 320
     $decimal_sep   = wpinv_decimal_separator();
321 321
 
322
-    if ( $decimals === NULL ) {
322
+    if ($decimals === NULL) {
323 323
         $decimals = wpinv_decimals();
324 324
     }
325 325
 
326
-    if ( $decimal_sep == ',' && false !== ( $sep_found = strpos( $amount, $decimal_sep ) ) ) {
327
-        $whole = substr( $amount, 0, $sep_found );
328
-        $part = substr( $amount, $sep_found + 1, ( strlen( $amount ) - 1 ) );
326
+    if ($decimal_sep == ',' && false !== ($sep_found = strpos($amount, $decimal_sep))) {
327
+        $whole = substr($amount, 0, $sep_found);
328
+        $part = substr($amount, $sep_found + 1, (strlen($amount) - 1));
329 329
         $amount = $whole . '.' . $part;
330 330
     }
331 331
 
332
-    if ( $thousands_sep == ',' && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) {
333
-        $amount = str_replace( ',', '', $amount );
332
+    if ($thousands_sep == ',' && false !== ($found = strpos($amount, $thousands_sep))) {
333
+        $amount = str_replace(',', '', $amount);
334 334
     }
335 335
 
336
-    if ( $thousands_sep == ' ' && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) {
337
-        $amount = str_replace( ' ', '', $amount );
336
+    if ($thousands_sep == ' ' && false !== ($found = strpos($amount, $thousands_sep))) {
337
+        $amount = str_replace(' ', '', $amount);
338 338
     }
339 339
 
340
-    if ( empty( $amount ) ) {
340
+    if (empty($amount)) {
341 341
         $amount = 0;
342 342
     }
343 343
     
344
-    $decimals  = apply_filters( 'wpinv_amount_format_decimals', $decimals ? $decimals : 0, $amount, $calculate );
345
-    $formatted = number_format( (float)$amount, $decimals, $decimal_sep, $thousands_sep );
344
+    $decimals  = apply_filters('wpinv_amount_format_decimals', $decimals ? $decimals : 0, $amount, $calculate);
345
+    $formatted = number_format((float)$amount, $decimals, $decimal_sep, $thousands_sep);
346 346
     
347
-    if ( $calculate ) {
348
-        if ( $thousands_sep === "," ) {
349
-            $formatted = str_replace( ",", "", $formatted );
347
+    if ($calculate) {
348
+        if ($thousands_sep === ",") {
349
+            $formatted = str_replace(",", "", $formatted);
350 350
         }
351 351
         
352
-        if ( $decimal_sep === "," ) {
353
-            $formatted = str_replace( ",", ".", $formatted );
352
+        if ($decimal_sep === ",") {
353
+            $formatted = str_replace(",", ".", $formatted);
354 354
         }
355 355
     }
356 356
 
357
-    return apply_filters( 'wpinv_amount_format', $formatted, $amount, $decimals, $decimal_sep, $thousands_sep, $calculate );
357
+    return apply_filters('wpinv_amount_format', $formatted, $amount, $decimals, $decimal_sep, $thousands_sep, $calculate);
358 358
 }
359
-add_filter( 'wpinv_amount_format_decimals', 'wpinv_currency_decimal_filter', 10, 1 );
359
+add_filter('wpinv_amount_format_decimals', 'wpinv_currency_decimal_filter', 10, 1);
360 360
 
361
-function wpinv_sanitize_key( $key ) {
361
+function wpinv_sanitize_key($key) {
362 362
     $raw_key = $key;
363
-    $key = preg_replace( '/[^a-zA-Z0-9_\-\.\:\/]/', '', $key );
363
+    $key = preg_replace('/[^a-zA-Z0-9_\-\.\:\/]/', '', $key);
364 364
 
365
-    return apply_filters( 'wpinv_sanitize_key', $key, $raw_key );
365
+    return apply_filters('wpinv_sanitize_key', $key, $raw_key);
366 366
 }
367 367
 
368
-function wpinv_get_file_extension( $str ) {
369
-    $parts = explode( '.', $str );
370
-    return end( $parts );
368
+function wpinv_get_file_extension($str) {
369
+    $parts = explode('.', $str);
370
+    return end($parts);
371 371
 }
372 372
 
373
-function wpinv_string_is_image_url( $str ) {
374
-    $ext = wpinv_get_file_extension( $str );
373
+function wpinv_string_is_image_url($str) {
374
+    $ext = wpinv_get_file_extension($str);
375 375
 
376
-    switch ( strtolower( $ext ) ) {
376
+    switch (strtolower($ext)) {
377 377
         case 'jpeg';
378 378
         case 'jpg';
379 379
             $return = true;
@@ -389,32 +389,32 @@  discard block
 block discarded – undo
389 389
             break;
390 390
     }
391 391
 
392
-    return (bool)apply_filters( 'wpinv_string_is_image', $return, $str );
392
+    return (bool)apply_filters('wpinv_string_is_image', $return, $str);
393 393
 }
394 394
 
395
-function wpinv_error_log( $log, $title = '', $file = '', $line = '', $exit = false ) {
396
-    $should_log = apply_filters( 'wpinv_log_errors', WP_DEBUG );
395
+function wpinv_error_log($log, $title = '', $file = '', $line = '', $exit = false) {
396
+    $should_log = apply_filters('wpinv_log_errors', WP_DEBUG);
397 397
     
398
-    if ( true === $should_log ) {
398
+    if (true === $should_log) {
399 399
         $label = '';
400
-        if ( $file && $file !== '' ) {
401
-            $label .= basename( $file ) . ( $line ? '(' . $line . ')' : '' );
400
+        if ($file && $file !== '') {
401
+            $label .= basename($file) . ($line ? '(' . $line . ')' : '');
402 402
         }
403 403
         
404
-        if ( $title && $title !== '' ) {
404
+        if ($title && $title !== '') {
405 405
             $label = $label !== '' ? $label . ' ' : '';
406 406
             $label .= $title . ' ';
407 407
         }
408 408
         
409
-        $label = $label !== '' ? trim( $label ) . ' : ' : '';
409
+        $label = $label !== '' ? trim($label) . ' : ' : '';
410 410
         
411
-        if ( is_array( $log ) || is_object( $log ) ) {
412
-            error_log( $label . print_r( $log, true ) );
411
+        if (is_array($log) || is_object($log)) {
412
+            error_log($label . print_r($log, true));
413 413
         } else {
414
-            error_log( $label . $log );
414
+            error_log($label . $log);
415 415
         }
416 416
         
417
-        if ( $exit ) {
417
+        if ($exit) {
418 418
             exit;
419 419
         }
420 420
     }
@@ -422,65 +422,65 @@  discard block
 block discarded – undo
422 422
 
423 423
 function wpinv_is_ajax_disabled() {
424 424
     $retval = false;
425
-    return apply_filters( 'wpinv_is_ajax_disabled', $retval );
425
+    return apply_filters('wpinv_is_ajax_disabled', $retval);
426 426
 }
427 427
 
428
-function wpinv_get_current_page_url( $nocache = false ) {
428
+function wpinv_get_current_page_url($nocache = false) {
429 429
     global $wp;
430 430
 
431
-    if ( get_option( 'permalink_structure' ) ) {
432
-        $base = trailingslashit( home_url( $wp->request ) );
431
+    if (get_option('permalink_structure')) {
432
+        $base = trailingslashit(home_url($wp->request));
433 433
     } else {
434
-        $base = add_query_arg( $wp->query_string, '', trailingslashit( home_url( $wp->request ) ) );
435
-        $base = remove_query_arg( array( 'post_type', 'name' ), $base );
434
+        $base = add_query_arg($wp->query_string, '', trailingslashit(home_url($wp->request)));
435
+        $base = remove_query_arg(array('post_type', 'name'), $base);
436 436
     }
437 437
 
438 438
     $scheme = is_ssl() ? 'https' : 'http';
439
-    $uri    = set_url_scheme( $base, $scheme );
439
+    $uri    = set_url_scheme($base, $scheme);
440 440
 
441
-    if ( is_front_page() ) {
442
-        $uri = home_url( '/' );
443
-    } elseif ( wpinv_is_checkout( array(), false ) ) {
441
+    if (is_front_page()) {
442
+        $uri = home_url('/');
443
+    } elseif (wpinv_is_checkout(array(), false)) {
444 444
         $uri = wpinv_get_checkout_uri();
445 445
     }
446 446
 
447
-    $uri = apply_filters( 'wpinv_get_current_page_url', $uri );
447
+    $uri = apply_filters('wpinv_get_current_page_url', $uri);
448 448
 
449
-    if ( $nocache ) {
450
-        $uri = wpinv_add_cache_busting( $uri );
449
+    if ($nocache) {
450
+        $uri = wpinv_add_cache_busting($uri);
451 451
     }
452 452
 
453 453
     return $uri;
454 454
 }
455 455
 
456 456
 function wpinv_get_php_arg_separator_output() {
457
-	return ini_get( 'arg_separator.output' );
457
+	return ini_get('arg_separator.output');
458 458
 }
459 459
 
460
-function wpinv_rgb_from_hex( $color ) {
461
-    $color = str_replace( '#', '', $color );
460
+function wpinv_rgb_from_hex($color) {
461
+    $color = str_replace('#', '', $color);
462 462
     // Convert shorthand colors to full format, e.g. "FFF" -> "FFFFFF"
463
-    $color = preg_replace( '~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color );
463
+    $color = preg_replace('~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color);
464 464
 
465 465
     $rgb      = array();
466
-    $rgb['R'] = hexdec( $color{0}.$color{1} );
467
-    $rgb['G'] = hexdec( $color{2}.$color{3} );
468
-    $rgb['B'] = hexdec( $color{4}.$color{5} );
466
+    $rgb['R'] = hexdec($color{0} . $color{1} );
467
+    $rgb['G'] = hexdec($color{2} . $color{3} );
468
+    $rgb['B'] = hexdec($color{4} . $color{5} );
469 469
 
470 470
     return $rgb;
471 471
 }
472 472
 
473
-function wpinv_hex_darker( $color, $factor = 30 ) {
474
-    $base  = wpinv_rgb_from_hex( $color );
473
+function wpinv_hex_darker($color, $factor = 30) {
474
+    $base  = wpinv_rgb_from_hex($color);
475 475
     $color = '#';
476 476
 
477
-    foreach ( $base as $k => $v ) {
477
+    foreach ($base as $k => $v) {
478 478
         $amount      = $v / 100;
479
-        $amount      = round( $amount * $factor );
479
+        $amount      = round($amount * $factor);
480 480
         $new_decimal = $v - $amount;
481 481
 
482
-        $new_hex_component = dechex( $new_decimal );
483
-        if ( strlen( $new_hex_component ) < 2 ) {
482
+        $new_hex_component = dechex($new_decimal);
483
+        if (strlen($new_hex_component) < 2) {
484 484
             $new_hex_component = "0" . $new_hex_component;
485 485
         }
486 486
         $color .= $new_hex_component;
@@ -489,18 +489,18 @@  discard block
 block discarded – undo
489 489
     return $color;
490 490
 }
491 491
 
492
-function wpinv_hex_lighter( $color, $factor = 30 ) {
493
-    $base  = wpinv_rgb_from_hex( $color );
492
+function wpinv_hex_lighter($color, $factor = 30) {
493
+    $base  = wpinv_rgb_from_hex($color);
494 494
     $color = '#';
495 495
 
496
-    foreach ( $base as $k => $v ) {
496
+    foreach ($base as $k => $v) {
497 497
         $amount      = 255 - $v;
498 498
         $amount      = $amount / 100;
499
-        $amount      = round( $amount * $factor );
499
+        $amount      = round($amount * $factor);
500 500
         $new_decimal = $v + $amount;
501 501
 
502
-        $new_hex_component = dechex( $new_decimal );
503
-        if ( strlen( $new_hex_component ) < 2 ) {
502
+        $new_hex_component = dechex($new_decimal);
503
+        if (strlen($new_hex_component) < 2) {
504 504
             $new_hex_component = "0" . $new_hex_component;
505 505
         }
506 506
         $color .= $new_hex_component;
@@ -509,22 +509,22 @@  discard block
 block discarded – undo
509 509
     return $color;
510 510
 }
511 511
 
512
-function wpinv_light_or_dark( $color, $dark = '#000000', $light = '#FFFFFF' ) {
513
-    $hex = str_replace( '#', '', $color );
512
+function wpinv_light_or_dark($color, $dark = '#000000', $light = '#FFFFFF') {
513
+    $hex = str_replace('#', '', $color);
514 514
 
515
-    $c_r = hexdec( substr( $hex, 0, 2 ) );
516
-    $c_g = hexdec( substr( $hex, 2, 2 ) );
517
-    $c_b = hexdec( substr( $hex, 4, 2 ) );
515
+    $c_r = hexdec(substr($hex, 0, 2));
516
+    $c_g = hexdec(substr($hex, 2, 2));
517
+    $c_b = hexdec(substr($hex, 4, 2));
518 518
 
519
-    $brightness = ( ( $c_r * 299 ) + ( $c_g * 587 ) + ( $c_b * 114 ) ) / 1000;
519
+    $brightness = (($c_r * 299) + ($c_g * 587) + ($c_b * 114)) / 1000;
520 520
 
521 521
     return $brightness > 155 ? $dark : $light;
522 522
 }
523 523
 
524
-function wpinv_format_hex( $hex ) {
525
-    $hex = trim( str_replace( '#', '', $hex ) );
524
+function wpinv_format_hex($hex) {
525
+    $hex = trim(str_replace('#', '', $hex));
526 526
 
527
-    if ( strlen( $hex ) == 3 ) {
527
+    if (strlen($hex) == 3) {
528 528
         $hex = $hex[0] . $hex[0] . $hex[1] . $hex[1] . $hex[2] . $hex[2];
529 529
     }
530 530
 
@@ -544,12 +544,12 @@  discard block
 block discarded – undo
544 544
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
545 545
  * @return string
546 546
  */
547
-function wpinv_utf8_strimwidth( $str, $start, $width, $trimmaker = '', $encoding = 'UTF-8' ) {
548
-    if ( function_exists( 'mb_strimwidth' ) ) {
549
-        return mb_strimwidth( $str, $start, $width, $trimmaker, $encoding );
547
+function wpinv_utf8_strimwidth($str, $start, $width, $trimmaker = '', $encoding = 'UTF-8') {
548
+    if (function_exists('mb_strimwidth')) {
549
+        return mb_strimwidth($str, $start, $width, $trimmaker, $encoding);
550 550
     }
551 551
     
552
-    return wpinv_utf8_substr( $str, $start, $width, $encoding ) . $trimmaker;
552
+    return wpinv_utf8_substr($str, $start, $width, $encoding) . $trimmaker;
553 553
 }
554 554
 
555 555
 /**
@@ -561,28 +561,28 @@  discard block
 block discarded – undo
561 561
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
562 562
  * @return int Returns the number of characters in string.
563 563
  */
564
-function wpinv_utf8_strlen( $str, $encoding = 'UTF-8' ) {
565
-    if ( function_exists( 'mb_strlen' ) ) {
566
-        return mb_strlen( $str, $encoding );
564
+function wpinv_utf8_strlen($str, $encoding = 'UTF-8') {
565
+    if (function_exists('mb_strlen')) {
566
+        return mb_strlen($str, $encoding);
567 567
     }
568 568
         
569
-    return strlen( $str );
569
+    return strlen($str);
570 570
 }
571 571
 
572
-function wpinv_utf8_strtolower( $str, $encoding = 'UTF-8' ) {
573
-    if ( function_exists( 'mb_strtolower' ) ) {
574
-        return mb_strtolower( $str, $encoding );
572
+function wpinv_utf8_strtolower($str, $encoding = 'UTF-8') {
573
+    if (function_exists('mb_strtolower')) {
574
+        return mb_strtolower($str, $encoding);
575 575
     }
576 576
     
577
-    return strtolower( $str );
577
+    return strtolower($str);
578 578
 }
579 579
 
580
-function wpinv_utf8_strtoupper( $str, $encoding = 'UTF-8' ) {
581
-    if ( function_exists( 'mb_strtoupper' ) ) {
582
-        return mb_strtoupper( $str, $encoding );
580
+function wpinv_utf8_strtoupper($str, $encoding = 'UTF-8') {
581
+    if (function_exists('mb_strtoupper')) {
582
+        return mb_strtoupper($str, $encoding);
583 583
     }
584 584
     
585
-    return strtoupper( $str );
585
+    return strtoupper($str);
586 586
 }
587 587
 
588 588
 /**
@@ -596,12 +596,12 @@  discard block
 block discarded – undo
596 596
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
597 597
  * @return int Returns the position of the first occurrence of search in the string.
598 598
  */
599
-function wpinv_utf8_strpos( $str, $find, $offset = 0, $encoding = 'UTF-8' ) {
600
-    if ( function_exists( 'mb_strpos' ) ) {
601
-        return mb_strpos( $str, $find, $offset, $encoding );
599
+function wpinv_utf8_strpos($str, $find, $offset = 0, $encoding = 'UTF-8') {
600
+    if (function_exists('mb_strpos')) {
601
+        return mb_strpos($str, $find, $offset, $encoding);
602 602
     }
603 603
         
604
-    return strpos( $str, $find, $offset );
604
+    return strpos($str, $find, $offset);
605 605
 }
606 606
 
607 607
 /**
@@ -615,12 +615,12 @@  discard block
 block discarded – undo
615 615
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
616 616
  * @return int Returns the position of the last occurrence of search.
617 617
  */
618
-function wpinv_utf8_strrpos( $str, $find, $offset = 0, $encoding = 'UTF-8' ) {
619
-    if ( function_exists( 'mb_strrpos' ) ) {
620
-        return mb_strrpos( $str, $find, $offset, $encoding );
618
+function wpinv_utf8_strrpos($str, $find, $offset = 0, $encoding = 'UTF-8') {
619
+    if (function_exists('mb_strrpos')) {
620
+        return mb_strrpos($str, $find, $offset, $encoding);
621 621
     }
622 622
         
623
-    return strrpos( $str, $find, $offset );
623
+    return strrpos($str, $find, $offset);
624 624
 }
625 625
 
626 626
 /**
@@ -635,16 +635,16 @@  discard block
 block discarded – undo
635 635
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
636 636
  * @return string
637 637
  */
638
-function wpinv_utf8_substr( $str, $start, $length = null, $encoding = 'UTF-8' ) {
639
-    if ( function_exists( 'mb_substr' ) ) {
640
-        if ( $length === null ) {
641
-            return mb_substr( $str, $start, wpinv_utf8_strlen( $str, $encoding ), $encoding );
638
+function wpinv_utf8_substr($str, $start, $length = null, $encoding = 'UTF-8') {
639
+    if (function_exists('mb_substr')) {
640
+        if ($length === null) {
641
+            return mb_substr($str, $start, wpinv_utf8_strlen($str, $encoding), $encoding);
642 642
         } else {
643
-            return mb_substr( $str, $start, $length, $encoding );
643
+            return mb_substr($str, $start, $length, $encoding);
644 644
         }
645 645
     }
646 646
         
647
-    return substr( $str, $start, $length );
647
+    return substr($str, $start, $length);
648 648
 }
649 649
 
650 650
 /**
@@ -656,48 +656,48 @@  discard block
 block discarded – undo
656 656
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
657 657
  * @return string The width of string.
658 658
  */
659
-function wpinv_utf8_strwidth( $str, $encoding = 'UTF-8' ) {
660
-    if ( function_exists( 'mb_strwidth' ) ) {
661
-        return mb_strwidth( $str, $encoding );
659
+function wpinv_utf8_strwidth($str, $encoding = 'UTF-8') {
660
+    if (function_exists('mb_strwidth')) {
661
+        return mb_strwidth($str, $encoding);
662 662
     }
663 663
     
664
-    return wpinv_utf8_strlen( $str, $encoding );
664
+    return wpinv_utf8_strlen($str, $encoding);
665 665
 }
666 666
 
667
-function wpinv_utf8_ucfirst( $str, $lower_str_end = false, $encoding = 'UTF-8' ) {
668
-    if ( function_exists( 'mb_strlen' ) ) {
669
-        $first_letter = wpinv_utf8_strtoupper( wpinv_utf8_substr( $str, 0, 1, $encoding ), $encoding );
667
+function wpinv_utf8_ucfirst($str, $lower_str_end = false, $encoding = 'UTF-8') {
668
+    if (function_exists('mb_strlen')) {
669
+        $first_letter = wpinv_utf8_strtoupper(wpinv_utf8_substr($str, 0, 1, $encoding), $encoding);
670 670
         $str_end = "";
671 671
         
672
-        if ( $lower_str_end ) {
673
-            $str_end = wpinv_utf8_strtolower( wpinv_utf8_substr( $str, 1, wpinv_utf8_strlen( $str, $encoding ), $encoding ), $encoding );
672
+        if ($lower_str_end) {
673
+            $str_end = wpinv_utf8_strtolower(wpinv_utf8_substr($str, 1, wpinv_utf8_strlen($str, $encoding), $encoding), $encoding);
674 674
         } else {
675
-            $str_end = wpinv_utf8_substr( $str, 1, wpinv_utf8_strlen( $str, $encoding ), $encoding );
675
+            $str_end = wpinv_utf8_substr($str, 1, wpinv_utf8_strlen($str, $encoding), $encoding);
676 676
         }
677 677
 
678 678
         return $first_letter . $str_end;
679 679
     }
680 680
     
681
-    return ucfirst( $str );
681
+    return ucfirst($str);
682 682
 }
683 683
 
684
-function wpinv_utf8_ucwords( $str, $encoding = 'UTF-8' ) {
685
-    if ( function_exists( 'mb_convert_case' ) ) {
686
-        return mb_convert_case( $str, MB_CASE_TITLE, $encoding );
684
+function wpinv_utf8_ucwords($str, $encoding = 'UTF-8') {
685
+    if (function_exists('mb_convert_case')) {
686
+        return mb_convert_case($str, MB_CASE_TITLE, $encoding);
687 687
     }
688 688
     
689
-    return ucwords( $str );
689
+    return ucwords($str);
690 690
 }
691 691
 
692
-function wpinv_period_in_days( $period, $unit ) {
693
-    $period = absint( $period );
692
+function wpinv_period_in_days($period, $unit) {
693
+    $period = absint($period);
694 694
     
695
-    if ( $period > 0 ) {
696
-        if ( in_array( strtolower( $unit ), array( 'w', 'week', 'weeks' ) ) ) {
695
+    if ($period > 0) {
696
+        if (in_array(strtolower($unit), array('w', 'week', 'weeks'))) {
697 697
             $period = $period * 7;
698
-        } else if ( in_array( strtolower( $unit ), array( 'm', 'month', 'months' ) ) ) {
698
+        } else if (in_array(strtolower($unit), array('m', 'month', 'months'))) {
699 699
             $period = $period * 30;
700
-        } else if ( in_array( strtolower( $unit ), array( 'y', 'year', 'years' ) ) ) {
700
+        } else if (in_array(strtolower($unit), array('y', 'year', 'years'))) {
701 701
             $period = $period * 365;
702 702
         }
703 703
     }
Please login to merge, or discard this patch.
includes/wpinv-discount-functions.php 1 patch
Spacing   +469 added lines, -469 removed lines patch added patch discarded remove patch
@@ -7,90 +7,90 @@  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_discount_types() {
15 15
     $discount_types = array(
16
-                        'percent'   => __( 'Percentage', 'invoicing' ),
17
-                        'flat'     => __( 'Flat Amount', 'invoicing' ),
16
+                        'percent'   => __('Percentage', 'invoicing'),
17
+                        'flat'     => __('Flat Amount', 'invoicing'),
18 18
                     );
19
-    return (array)apply_filters( 'wpinv_discount_types', $discount_types );
19
+    return (array)apply_filters('wpinv_discount_types', $discount_types);
20 20
 }
21 21
 
22
-function wpinv_get_discount_type_name( $type = '' ) {
22
+function wpinv_get_discount_type_name($type = '') {
23 23
     $types = wpinv_get_discount_types();
24
-    return isset( $types[ $type ] ) ? $types[ $type ] : '';
24
+    return isset($types[$type]) ? $types[$type] : '';
25 25
 }
26 26
 
27
-function wpinv_delete_discount( $data ) {
28
-    if ( ! isset( $data['_wpnonce'] ) || ! wp_verify_nonce( $data['_wpnonce'], 'wpinv_discount_nonce' ) ) {
29
-        wp_die( __( 'Trying to cheat or something?', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
27
+function wpinv_delete_discount($data) {
28
+    if (!isset($data['_wpnonce']) || !wp_verify_nonce($data['_wpnonce'], 'wpinv_discount_nonce')) {
29
+        wp_die(__('Trying to cheat or something?', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
30 30
     }
31 31
 
32
-    if( ! current_user_can( 'manage_options' ) ) {
33
-        wp_die( __( 'You do not have permission to delete discount codes', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
32
+    if (!current_user_can('manage_options')) {
33
+        wp_die(__('You do not have permission to delete discount codes', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
34 34
     }
35 35
 
36 36
     $discount_id = $data['discount'];
37
-    wpinv_remove_discount( $discount_id );
37
+    wpinv_remove_discount($discount_id);
38 38
 }
39
-add_action( 'wpinv_delete_discount', 'wpinv_delete_discount' );
39
+add_action('wpinv_delete_discount', 'wpinv_delete_discount');
40 40
 
41
-function wpinv_activate_discount( $data ) {
42
-    if ( ! isset( $data['_wpnonce'] ) || ! wp_verify_nonce( $data['_wpnonce'], 'wpinv_discount_nonce' ) ) {
43
-        wp_die( __( 'Trying to cheat or something?', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
41
+function wpinv_activate_discount($data) {
42
+    if (!isset($data['_wpnonce']) || !wp_verify_nonce($data['_wpnonce'], 'wpinv_discount_nonce')) {
43
+        wp_die(__('Trying to cheat or something?', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
44 44
     }
45 45
 
46
-    if( ! current_user_can( 'manage_options' ) ) {
47
-        wp_die( __( 'You do not have permission to edit discount codes', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
46
+    if (!current_user_can('manage_options')) {
47
+        wp_die(__('You do not have permission to edit discount codes', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
48 48
     }
49 49
 
50
-    $id = absint( $data['discount'] );
51
-    wpinv_update_discount_status( $id, 'publish' );
50
+    $id = absint($data['discount']);
51
+    wpinv_update_discount_status($id, 'publish');
52 52
 }
53
-add_action( 'wpinv_activate_discount', 'wpinv_activate_discount' );
53
+add_action('wpinv_activate_discount', 'wpinv_activate_discount');
54 54
 
55
-function wpinv_deactivate_discount( $data ) {
56
-    if ( ! isset( $data['_wpnonce'] ) || ! wp_verify_nonce( $data['_wpnonce'], 'wpinv_discount_nonce' ) ) {
57
-        wp_die( __( 'Trying to cheat or something?', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
55
+function wpinv_deactivate_discount($data) {
56
+    if (!isset($data['_wpnonce']) || !wp_verify_nonce($data['_wpnonce'], 'wpinv_discount_nonce')) {
57
+        wp_die(__('Trying to cheat or something?', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
58 58
     }
59 59
 
60
-    if( ! current_user_can( 'manage_options' ) ) {
61
-        wp_die( __( 'You do not have permission to create discount codes', 'invoicing' ), array( 'response' => 403 ) );
60
+    if (!current_user_can('manage_options')) {
61
+        wp_die(__('You do not have permission to create discount codes', 'invoicing'), array('response' => 403));
62 62
     }
63 63
 
64
-    $id = absint( $data['discount'] );
65
-    wpinv_update_discount_status( $id, 'pending' );
64
+    $id = absint($data['discount']);
65
+    wpinv_update_discount_status($id, 'pending');
66 66
 }
67
-add_action( 'wpinv_deactivate_discount', 'wpinv_deactivate_discount' );
67
+add_action('wpinv_deactivate_discount', 'wpinv_deactivate_discount');
68 68
 
69
-function wpinv_get_discounts( $args = array() ) {
69
+function wpinv_get_discounts($args = array()) {
70 70
     $defaults = array(
71 71
         'post_type'      => 'wpi_discount',
72 72
         'posts_per_page' => 20,
73 73
         'paged'          => null,
74
-        'post_status'    => array( 'publish', 'pending', 'draft', 'expired' )
74
+        'post_status'    => array('publish', 'pending', 'draft', 'expired')
75 75
     );
76 76
 
77
-    $args = wp_parse_args( $args, $defaults );
77
+    $args = wp_parse_args($args, $defaults);
78 78
 
79
-    $discounts = get_posts( $args );
79
+    $discounts = get_posts($args);
80 80
 
81
-    if ( $discounts ) {
81
+    if ($discounts) {
82 82
         return $discounts;
83 83
     }
84 84
 
85
-    if( ! $discounts && ! empty( $args['s'] ) ) {
85
+    if (!$discounts && !empty($args['s'])) {
86 86
         $args['meta_key']     = 'gd_discount_code';
87 87
         $args['meta_value']   = $args['s'];
88 88
         $args['meta_compare'] = 'LIKE';
89
-        unset( $args['s'] );
90
-        $discounts = get_posts( $args );
89
+        unset($args['s']);
90
+        $discounts = get_posts($args);
91 91
     }
92 92
 
93
-    if( $discounts ) {
93
+    if ($discounts) {
94 94
         return $discounts;
95 95
     }
96 96
 
@@ -102,9 +102,9 @@  discard block
 block discarded – undo
102 102
 
103 103
     $discounts  = wpinv_get_discounts();
104 104
 
105
-    if ( $discounts) {
106
-        foreach ( $discounts as $discount ) {
107
-            if ( wpinv_is_discount_active( $discount->ID ) ) {
105
+    if ($discounts) {
106
+        foreach ($discounts as $discount) {
107
+            if (wpinv_is_discount_active($discount->ID)) {
108 108
                 $has_active = true;
109 109
                 break;
110 110
             }
@@ -113,38 +113,38 @@  discard block
 block discarded – undo
113 113
     return $has_active;
114 114
 }
115 115
 
116
-function wpinv_get_discount( $discount_id = 0 ) {
117
-    if( empty( $discount_id ) ) {
116
+function wpinv_get_discount($discount_id = 0) {
117
+    if (empty($discount_id)) {
118 118
         return false;
119 119
     }
120 120
     
121
-    if ( get_post_type( $discount_id ) != 'wpi_discount' ) {
121
+    if (get_post_type($discount_id) != 'wpi_discount') {
122 122
         return false;
123 123
     }
124 124
 
125
-    $discount = get_post( $discount_id );
125
+    $discount = get_post($discount_id);
126 126
 
127 127
     return $discount;
128 128
 }
129 129
 
130
-function wpinv_get_discount_by_code( $code = '' ) {
131
-    if( empty( $code ) || ! is_string( $code ) ) {
130
+function wpinv_get_discount_by_code($code = '') {
131
+    if (empty($code) || !is_string($code)) {
132 132
         return false;
133 133
     }
134 134
 
135
-    return wpinv_get_discount_by( 'code', $code );
135
+    return wpinv_get_discount_by('code', $code);
136 136
 }
137 137
 
138
-function wpinv_get_discount_by( $field = '', $value = '' ) {
139
-    if( empty( $field ) || empty( $value ) ) {
138
+function wpinv_get_discount_by($field = '', $value = '') {
139
+    if (empty($field) || empty($value)) {
140 140
         return false;
141 141
     }
142 142
 
143
-    if( ! is_string( $field ) ) {
143
+    if (!is_string($field)) {
144 144
         return false;
145 145
     }
146 146
 
147
-    switch( strtolower( $field ) ) {
147
+    switch (strtolower($field)) {
148 148
 
149 149
         case 'code':
150 150
             $meta_query     = array();
@@ -154,32 +154,32 @@  discard block
 block discarded – undo
154 154
                 'compare' => '='
155 155
             );
156 156
             
157
-            $discount = wpinv_get_discounts( array(
157
+            $discount = wpinv_get_discounts(array(
158 158
                 'posts_per_page' => 1,
159 159
                 'post_status'    => 'any',
160 160
                 'meta_query'     => $meta_query,
161
-            ) );
161
+            ));
162 162
             
163
-            if( $discount ) {
163
+            if ($discount) {
164 164
                 $discount = $discount[0];
165 165
             }
166 166
 
167 167
             break;
168 168
 
169 169
         case 'id':
170
-            $discount = wpinv_get_discount( $value );
170
+            $discount = wpinv_get_discount($value);
171 171
 
172 172
             break;
173 173
 
174 174
         case 'name':
175
-            $discount = get_posts( array(
175
+            $discount = get_posts(array(
176 176
                 'post_type'      => 'wpi_discount',
177 177
                 'name'           => $value,
178 178
                 'posts_per_page' => 1,
179 179
                 'post_status'    => 'any'
180
-            ) );
180
+            ));
181 181
 
182
-            if( $discount ) {
182
+            if ($discount) {
183 183
                 $discount = $discount[0];
184 184
             }
185 185
 
@@ -189,99 +189,99 @@  discard block
 block discarded – undo
189 189
             return false;
190 190
     }
191 191
 
192
-    if( ! empty( $discount ) ) {
192
+    if (!empty($discount)) {
193 193
         return $discount;
194 194
     }
195 195
 
196 196
     return false;
197 197
 }
198 198
 
199
-function wpinv_store_discount( $post_id, $data, $post, $update = false ) {
199
+function wpinv_store_discount($post_id, $data, $post, $update = false) {
200 200
     $meta = array(
201
-        'code'              => isset( $data['code'] )             ? sanitize_text_field( $data['code'] )              : '',
202
-        'type'              => isset( $data['type'] )             ? sanitize_text_field( $data['type'] )              : 'percent',
203
-        'amount'            => isset( $data['amount'] )           ? wpinv_sanitize_amount( $data['amount'] )          : '',
204
-        'start'             => isset( $data['start'] )            ? sanitize_text_field( $data['start'] )             : '',
205
-        'expiration'        => isset( $data['expiration'] )       ? sanitize_text_field( $data['expiration'] )        : '',
206
-        'min_total'         => isset( $data['min_total'] )        ? wpinv_sanitize_amount( $data['min_total'] )       : '',
207
-        'max_total'         => isset( $data['max_total'] )        ? wpinv_sanitize_amount( $data['max_total'] )       : '',
208
-        'max_uses'          => isset( $data['max_uses'] )         ? absint( $data['max_uses'] )                       : '',
209
-        'items'             => isset( $data['items'] )            ? $data['items']                                    : array(),
210
-        'excluded_items'    => isset( $data['excluded_items'] )   ? $data['excluded_items']                           : array(),
211
-        'is_recurring'      => isset( $data['recurring'] )        ? (bool)$data['recurring']                          : false,
212
-        'is_single_use'     => isset( $data['single_use'] )       ? (bool)$data['single_use']                         : false,
213
-        'uses'              => isset( $data['uses'] )             ? (int)$data['uses']                                : false,
201
+        'code'              => isset($data['code']) ? sanitize_text_field($data['code']) : '',
202
+        'type'              => isset($data['type']) ? sanitize_text_field($data['type']) : 'percent',
203
+        'amount'            => isset($data['amount']) ? wpinv_sanitize_amount($data['amount']) : '',
204
+        'start'             => isset($data['start']) ? sanitize_text_field($data['start']) : '',
205
+        'expiration'        => isset($data['expiration']) ? sanitize_text_field($data['expiration']) : '',
206
+        'min_total'         => isset($data['min_total']) ? wpinv_sanitize_amount($data['min_total']) : '',
207
+        'max_total'         => isset($data['max_total']) ? wpinv_sanitize_amount($data['max_total']) : '',
208
+        'max_uses'          => isset($data['max_uses']) ? absint($data['max_uses']) : '',
209
+        'items'             => isset($data['items']) ? $data['items'] : array(),
210
+        'excluded_items'    => isset($data['excluded_items']) ? $data['excluded_items'] : array(),
211
+        'is_recurring'      => isset($data['recurring']) ? (bool)$data['recurring'] : false,
212
+        'is_single_use'     => isset($data['single_use']) ? (bool)$data['single_use'] : false,
213
+        'uses'              => isset($data['uses']) ? (int)$data['uses'] : false,
214 214
     );
215 215
     
216
-    $start_timestamp        = strtotime( $meta['start'] );
216
+    $start_timestamp        = strtotime($meta['start']);
217 217
 
218
-    if ( !empty( $meta['start'] ) ) {
219
-        $meta['start']      = date( 'Y-m-d H:i:s', $start_timestamp );
218
+    if (!empty($meta['start'])) {
219
+        $meta['start']      = date('Y-m-d H:i:s', $start_timestamp);
220 220
     }
221 221
         
222
-    if ( $meta['type'] == 'percent' && (float)$meta['amount'] > 100 ) {
222
+    if ($meta['type'] == 'percent' && (float)$meta['amount'] > 100) {
223 223
         $meta['amount'] = 100;
224 224
     }
225 225
 
226
-    if ( !empty( $meta['expiration'] ) ) {
227
-        $meta['expiration'] = date( 'Y-m-d H:i:s', strtotime( date( 'Y-m-d', strtotime( $meta['expiration'] ) ) . ' 23:59:59' ) );
228
-        $end_timestamp      = strtotime( $meta['expiration'] );
226
+    if (!empty($meta['expiration'])) {
227
+        $meta['expiration'] = date('Y-m-d H:i:s', strtotime(date('Y-m-d', strtotime($meta['expiration'])) . ' 23:59:59'));
228
+        $end_timestamp      = strtotime($meta['expiration']);
229 229
 
230
-        if ( !empty( $meta['start'] ) && $start_timestamp > $end_timestamp ) {
230
+        if (!empty($meta['start']) && $start_timestamp > $end_timestamp) {
231 231
             $meta['expiration'] = $meta['start']; // Set the expiration date to the start date if start is later than expiration date.
232 232
         }
233 233
     }
234 234
     
235
-    if ( $meta['uses'] === false ) {
236
-        unset( $meta['uses'] );
235
+    if ($meta['uses'] === false) {
236
+        unset($meta['uses']);
237 237
     }
238 238
     
239
-    if ( ! empty( $meta['items'] ) ) {
240
-        foreach ( $meta['items'] as $key => $item ) {
241
-            if ( 0 === intval( $item ) ) {
242
-                unset( $meta['items'][ $key ] );
239
+    if (!empty($meta['items'])) {
240
+        foreach ($meta['items'] as $key => $item) {
241
+            if (0 === intval($item)) {
242
+                unset($meta['items'][$key]);
243 243
             }
244 244
         }
245 245
     }
246 246
     
247
-    if ( ! empty( $meta['excluded_items'] ) ) {
248
-        foreach ( $meta['excluded_items'] as $key => $item ) {
249
-            if ( 0 === intval( $item ) ) {
250
-                unset( $meta['excluded_items'][ $key ] );
247
+    if (!empty($meta['excluded_items'])) {
248
+        foreach ($meta['excluded_items'] as $key => $item) {
249
+            if (0 === intval($item)) {
250
+                unset($meta['excluded_items'][$key]);
251 251
             }
252 252
         }
253 253
     }
254 254
     
255
-    $meta = apply_filters( 'wpinv_update_discount', $meta, $post_id, $post );
255
+    $meta = apply_filters('wpinv_update_discount', $meta, $post_id, $post);
256 256
     
257
-    do_action( 'wpinv_pre_update_discount', $meta, $post_id, $post );
257
+    do_action('wpinv_pre_update_discount', $meta, $post_id, $post);
258 258
     
259
-    foreach( $meta as $key => $value ) {
260
-        update_post_meta( $post_id, '_wpi_discount_' . $key, $value );
259
+    foreach ($meta as $key => $value) {
260
+        update_post_meta($post_id, '_wpi_discount_' . $key, $value);
261 261
     }
262 262
     
263
-    do_action( 'wpinv_post_update_discount', $meta, $post_id, $post );
263
+    do_action('wpinv_post_update_discount', $meta, $post_id, $post);
264 264
     
265 265
     return $post_id;
266 266
 }
267 267
 
268
-function wpinv_remove_discount( $discount_id = 0 ) {
269
-    do_action( 'wpinv_pre_delete_discount', $discount_id );
268
+function wpinv_remove_discount($discount_id = 0) {
269
+    do_action('wpinv_pre_delete_discount', $discount_id);
270 270
 
271
-    wp_delete_post( $discount_id, true );
271
+    wp_delete_post($discount_id, true);
272 272
 
273
-    do_action( 'wpinv_post_delete_discount', $discount_id );
273
+    do_action('wpinv_post_delete_discount', $discount_id);
274 274
 }
275 275
 
276
-function wpinv_update_discount_status( $code_id = 0, $new_status = 'publish' ) {
277
-    $discount = wpinv_get_discount(  $code_id );
276
+function wpinv_update_discount_status($code_id = 0, $new_status = 'publish') {
277
+    $discount = wpinv_get_discount($code_id);
278 278
 
279
-    if ( $discount ) {
280
-        do_action( 'wpinv_pre_update_discount_status', $code_id, $new_status, $discount->post_status );
279
+    if ($discount) {
280
+        do_action('wpinv_pre_update_discount_status', $code_id, $new_status, $discount->post_status);
281 281
 
282
-        wp_update_post( array( 'ID' => $code_id, 'post_status' => $new_status ) );
282
+        wp_update_post(array('ID' => $code_id, 'post_status' => $new_status));
283 283
 
284
-        do_action( 'wpinv_post_update_discount_status', $code_id, $new_status, $discount->post_status );
284
+        do_action('wpinv_post_update_discount_status', $code_id, $new_status, $discount->post_status);
285 285
 
286 286
         return true;
287 287
     }
@@ -289,173 +289,173 @@  discard block
 block discarded – undo
289 289
     return false;
290 290
 }
291 291
 
292
-function wpinv_discount_exists( $code_id ) {
293
-    if ( wpinv_get_discount(  $code_id ) ) {
292
+function wpinv_discount_exists($code_id) {
293
+    if (wpinv_get_discount($code_id)) {
294 294
         return true;
295 295
     }
296 296
 
297 297
     return false;
298 298
 }
299 299
 
300
-function wpinv_is_discount_active( $code_id = null ) {
301
-    $discount = wpinv_get_discount(  $code_id );
300
+function wpinv_is_discount_active($code_id = null) {
301
+    $discount = wpinv_get_discount($code_id);
302 302
     $return   = false;
303 303
 
304
-    if ( $discount ) {
305
-        if ( wpinv_is_discount_expired( $code_id ) ) {
306
-            if( defined( 'DOING_AJAX' ) ) {
307
-                wpinv_set_error( 'wpinv-discount-error', __( 'This discount is expired.', 'invoicing' ) );
304
+    if ($discount) {
305
+        if (wpinv_is_discount_expired($code_id)) {
306
+            if (defined('DOING_AJAX')) {
307
+                wpinv_set_error('wpinv-discount-error', __('This discount is expired.', 'invoicing'));
308 308
             }
309
-        } elseif ( $discount->post_status == 'publish' ) {
309
+        } elseif ($discount->post_status == 'publish') {
310 310
             $return = true;
311 311
         } else {
312
-            if( defined( 'DOING_AJAX' ) ) {
313
-                wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not active.', 'invoicing' ) );
312
+            if (defined('DOING_AJAX')) {
313
+                wpinv_set_error('wpinv-discount-error', __('This discount is not active.', 'invoicing'));
314 314
             }
315 315
         }
316 316
     }
317 317
 
318
-    return apply_filters( 'wpinv_is_discount_active', $return, $code_id );
318
+    return apply_filters('wpinv_is_discount_active', $return, $code_id);
319 319
 }
320 320
 
321
-function wpinv_get_discount_code( $code_id = null ) {
322
-    $code = get_post_meta( $code_id, '_wpi_discount_code', true );
321
+function wpinv_get_discount_code($code_id = null) {
322
+    $code = get_post_meta($code_id, '_wpi_discount_code', true);
323 323
 
324
-    return apply_filters( 'wpinv_get_discount_code', $code, $code_id );
324
+    return apply_filters('wpinv_get_discount_code', $code, $code_id);
325 325
 }
326 326
 
327
-function wpinv_get_discount_start_date( $code_id = null ) {
328
-    $start_date = get_post_meta( $code_id, '_wpi_discount_start', true );
327
+function wpinv_get_discount_start_date($code_id = null) {
328
+    $start_date = get_post_meta($code_id, '_wpi_discount_start', true);
329 329
 
330
-    return apply_filters( 'wpinv_get_discount_start_date', $start_date, $code_id );
330
+    return apply_filters('wpinv_get_discount_start_date', $start_date, $code_id);
331 331
 }
332 332
 
333
-function wpinv_get_discount_expiration( $code_id = null ) {
334
-    $expiration = get_post_meta( $code_id, '_wpi_discount_expiration', true );
333
+function wpinv_get_discount_expiration($code_id = null) {
334
+    $expiration = get_post_meta($code_id, '_wpi_discount_expiration', true);
335 335
 
336
-    return apply_filters( 'wpinv_get_discount_expiration', $expiration, $code_id );
336
+    return apply_filters('wpinv_get_discount_expiration', $expiration, $code_id);
337 337
 }
338 338
 
339
-function wpinv_get_discount_max_uses( $code_id = null ) {
340
-    $max_uses = get_post_meta( $code_id, '_wpi_discount_max_uses', true );
339
+function wpinv_get_discount_max_uses($code_id = null) {
340
+    $max_uses = get_post_meta($code_id, '_wpi_discount_max_uses', true);
341 341
 
342
-    return (int) apply_filters( 'wpinv_get_discount_max_uses', $max_uses, $code_id );
342
+    return (int)apply_filters('wpinv_get_discount_max_uses', $max_uses, $code_id);
343 343
 }
344 344
 
345
-function wpinv_get_discount_uses( $code_id = null ) {
346
-    $uses = get_post_meta( $code_id, '_wpi_discount_uses', true );
345
+function wpinv_get_discount_uses($code_id = null) {
346
+    $uses = get_post_meta($code_id, '_wpi_discount_uses', true);
347 347
 
348
-    return (int) apply_filters( 'wpinv_get_discount_uses', $uses, $code_id );
348
+    return (int)apply_filters('wpinv_get_discount_uses', $uses, $code_id);
349 349
 }
350 350
 
351
-function wpinv_get_discount_min_total( $code_id = null ) {
352
-    $min_total = get_post_meta( $code_id, '_wpi_discount_min_total', true );
351
+function wpinv_get_discount_min_total($code_id = null) {
352
+    $min_total = get_post_meta($code_id, '_wpi_discount_min_total', true);
353 353
 
354
-    return (float) apply_filters( 'wpinv_get_discount_min_total', $min_total, $code_id );
354
+    return (float)apply_filters('wpinv_get_discount_min_total', $min_total, $code_id);
355 355
 }
356 356
 
357
-function wpinv_get_discount_max_total( $code_id = null ) {
358
-    $max_total = get_post_meta( $code_id, '_wpi_discount_max_total', true );
357
+function wpinv_get_discount_max_total($code_id = null) {
358
+    $max_total = get_post_meta($code_id, '_wpi_discount_max_total', true);
359 359
 
360
-    return (float) apply_filters( 'wpinv_get_discount_max_total', $max_total, $code_id );
360
+    return (float)apply_filters('wpinv_get_discount_max_total', $max_total, $code_id);
361 361
 }
362 362
 
363
-function wpinv_get_discount_amount( $code_id = null ) {
364
-    $amount = get_post_meta( $code_id, '_wpi_discount_amount', true );
363
+function wpinv_get_discount_amount($code_id = null) {
364
+    $amount = get_post_meta($code_id, '_wpi_discount_amount', true);
365 365
 
366
-    return (float) apply_filters( 'wpinv_get_discount_amount', $amount, $code_id );
366
+    return (float)apply_filters('wpinv_get_discount_amount', $amount, $code_id);
367 367
 }
368 368
 
369
-function wpinv_get_discount_type( $code_id = null, $name = false ) {
370
-    $type = strtolower( get_post_meta( $code_id, '_wpi_discount_type', true ) );
369
+function wpinv_get_discount_type($code_id = null, $name = false) {
370
+    $type = strtolower(get_post_meta($code_id, '_wpi_discount_type', true));
371 371
     
372
-    if ( $name ) {
373
-        $name = wpinv_get_discount_type_name( $type );
372
+    if ($name) {
373
+        $name = wpinv_get_discount_type_name($type);
374 374
         
375
-        return apply_filters( 'wpinv_get_discount_type_name', $name, $code_id );
375
+        return apply_filters('wpinv_get_discount_type_name', $name, $code_id);
376 376
     }
377 377
 
378
-    return apply_filters( 'wpinv_get_discount_type', $type, $code_id );
378
+    return apply_filters('wpinv_get_discount_type', $type, $code_id);
379 379
 }
380 380
 
381
-function wpinv_discount_status( $status ) {
382
-    switch( $status ){
381
+function wpinv_discount_status($status) {
382
+    switch ($status) {
383 383
         case 'expired' :
384
-            $name = __( 'Expired', 'invoicing' );
384
+            $name = __('Expired', 'invoicing');
385 385
             break;
386 386
         case 'publish' :
387 387
         case 'active' :
388
-            $name = __( 'Active', 'invoicing' );
388
+            $name = __('Active', 'invoicing');
389 389
             break;
390 390
         default :
391
-            $name = __( 'Inactive', 'invoicing' );
391
+            $name = __('Inactive', 'invoicing');
392 392
             break;
393 393
     }
394 394
     return $name;
395 395
 }
396 396
 
397
-function wpinv_get_discount_excluded_items( $code_id = null ) {
398
-    $excluded_items = get_post_meta( $code_id, '_wpi_discount_excluded_items', true );
397
+function wpinv_get_discount_excluded_items($code_id = null) {
398
+    $excluded_items = get_post_meta($code_id, '_wpi_discount_excluded_items', true);
399 399
 
400
-    if ( empty( $excluded_items ) || ! is_array( $excluded_items ) ) {
400
+    if (empty($excluded_items) || !is_array($excluded_items)) {
401 401
         $excluded_items = array();
402 402
     }
403 403
 
404
-    return (array) apply_filters( 'wpinv_get_discount_excluded_items', $excluded_items, $code_id );
404
+    return (array)apply_filters('wpinv_get_discount_excluded_items', $excluded_items, $code_id);
405 405
 }
406 406
 
407
-function wpinv_get_discount_item_reqs( $code_id = null ) {
408
-    $item_reqs = get_post_meta( $code_id, '_wpi_discount_items', true );
407
+function wpinv_get_discount_item_reqs($code_id = null) {
408
+    $item_reqs = get_post_meta($code_id, '_wpi_discount_items', true);
409 409
 
410
-    if ( empty( $item_reqs ) || ! is_array( $item_reqs ) ) {
410
+    if (empty($item_reqs) || !is_array($item_reqs)) {
411 411
         $item_reqs = array();
412 412
     }
413 413
 
414
-    return (array) apply_filters( 'wpinv_get_discount_item_reqs', $item_reqs, $code_id );
414
+    return (array)apply_filters('wpinv_get_discount_item_reqs', $item_reqs, $code_id);
415 415
 }
416 416
 
417
-function wpinv_get_discount_item_condition( $code_id = 0 ) {
418
-    return get_post_meta( $code_id, '_wpi_discount_item_condition', true );
417
+function wpinv_get_discount_item_condition($code_id = 0) {
418
+    return get_post_meta($code_id, '_wpi_discount_item_condition', true);
419 419
 }
420 420
 
421
-function wpinv_is_discount_not_global( $code_id = 0 ) {
422
-    return (bool) get_post_meta( $code_id, '_wpi_discount_is_not_global', true );
421
+function wpinv_is_discount_not_global($code_id = 0) {
422
+    return (bool)get_post_meta($code_id, '_wpi_discount_is_not_global', true);
423 423
 }
424 424
 
425
-function wpinv_is_discount_expired( $code_id = null ) {
426
-    $discount = wpinv_get_discount(  $code_id );
425
+function wpinv_is_discount_expired($code_id = null) {
426
+    $discount = wpinv_get_discount($code_id);
427 427
     $return   = false;
428 428
 
429
-    if ( $discount ) {
430
-        $expiration = wpinv_get_discount_expiration( $code_id );
431
-        if ( $expiration ) {
432
-            $expiration = strtotime( $expiration );
433
-            if ( $expiration < current_time( 'timestamp' ) ) {
429
+    if ($discount) {
430
+        $expiration = wpinv_get_discount_expiration($code_id);
431
+        if ($expiration) {
432
+            $expiration = strtotime($expiration);
433
+            if ($expiration < current_time('timestamp')) {
434 434
                 // Discount is expired
435
-                wpinv_update_discount_status( $code_id, 'pending' );
435
+                wpinv_update_discount_status($code_id, 'pending');
436 436
                 $return = true;
437 437
             }
438 438
         }
439 439
     }
440 440
 
441
-    return apply_filters( 'wpinv_is_discount_expired', $return, $code_id );
441
+    return apply_filters('wpinv_is_discount_expired', $return, $code_id);
442 442
 }
443 443
 
444
-function wpinv_is_discount_started( $code_id = null ) {
445
-    $discount = wpinv_get_discount(  $code_id );
444
+function wpinv_is_discount_started($code_id = null) {
445
+    $discount = wpinv_get_discount($code_id);
446 446
     $return   = false;
447 447
 
448
-    if ( $discount ) {
449
-        $start_date = wpinv_get_discount_start_date( $code_id );
448
+    if ($discount) {
449
+        $start_date = wpinv_get_discount_start_date($code_id);
450 450
 
451
-        if ( $start_date ) {
452
-            $start_date = strtotime( $start_date );
451
+        if ($start_date) {
452
+            $start_date = strtotime($start_date);
453 453
 
454
-            if ( $start_date < current_time( 'timestamp' ) ) {
454
+            if ($start_date < current_time('timestamp')) {
455 455
                 // Discount has past the start date
456 456
                 $return = true;
457 457
             } else {
458
-                wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not active yet.', 'invoicing' ) );
458
+                wpinv_set_error('wpinv-discount-error', __('This discount is not active yet.', 'invoicing'));
459 459
             }
460 460
         } else {
461 461
             // No start date for this discount, so has to be true
@@ -463,159 +463,159 @@  discard block
 block discarded – undo
463 463
         }
464 464
     }
465 465
 
466
-    return apply_filters( 'wpinv_is_discount_started', $return, $code_id );
466
+    return apply_filters('wpinv_is_discount_started', $return, $code_id);
467 467
 }
468 468
 
469
-function wpinv_check_discount_dates( $code_id = null ) {
470
-    $discount = wpinv_get_discount(  $code_id );
469
+function wpinv_check_discount_dates($code_id = null) {
470
+    $discount = wpinv_get_discount($code_id);
471 471
     $return   = false;
472 472
 
473
-    if ( $discount ) {
474
-        $start_date = wpinv_get_discount_start_date( $code_id );
473
+    if ($discount) {
474
+        $start_date = wpinv_get_discount_start_date($code_id);
475 475
 
476
-        if ( $start_date ) {
477
-            $start_date = strtotime( $start_date );
476
+        if ($start_date) {
477
+            $start_date = strtotime($start_date);
478 478
 
479
-            if ( $start_date < current_time( 'timestamp' ) ) {
479
+            if ($start_date < current_time('timestamp')) {
480 480
                 // Discount has past the start date
481 481
                 $return = true;
482 482
             } else {
483
-                wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not active yet.', 'invoicing' ) );
483
+                wpinv_set_error('wpinv-discount-error', __('This discount is not active yet.', 'invoicing'));
484 484
             }
485 485
         } else {
486 486
             // No start date for this discount, so has to be true
487 487
             $return = true;
488 488
         }
489 489
         
490
-        if ( $return ) {
491
-            $expiration = wpinv_get_discount_expiration( $code_id );
490
+        if ($return) {
491
+            $expiration = wpinv_get_discount_expiration($code_id);
492 492
             
493
-            if ( $expiration ) {
494
-                $expiration = strtotime( $expiration );
495
-                if ( $expiration < current_time( 'timestamp' ) ) {
493
+            if ($expiration) {
494
+                $expiration = strtotime($expiration);
495
+                if ($expiration < current_time('timestamp')) {
496 496
                     // Discount is expired
497
-                    wpinv_update_discount_status( $code_id, 'pending' );
497
+                    wpinv_update_discount_status($code_id, 'pending');
498 498
                     $return = true;
499 499
                 }
500 500
             }
501 501
         }
502 502
     }
503 503
     
504
-    return apply_filters( 'wpinv_check_discount_dates', $return, $code_id );
504
+    return apply_filters('wpinv_check_discount_dates', $return, $code_id);
505 505
 }
506 506
 
507
-function wpinv_is_discount_maxed_out( $code_id = null ) {
508
-    $discount = wpinv_get_discount(  $code_id );
507
+function wpinv_is_discount_maxed_out($code_id = null) {
508
+    $discount = wpinv_get_discount($code_id);
509 509
     $return   = false;
510 510
 
511
-    if ( $discount ) {
512
-        $uses = wpinv_get_discount_uses( $code_id );
511
+    if ($discount) {
512
+        $uses = wpinv_get_discount_uses($code_id);
513 513
         // Large number that will never be reached
514
-        $max_uses = wpinv_get_discount_max_uses( $code_id );
514
+        $max_uses = wpinv_get_discount_max_uses($code_id);
515 515
         // Should never be greater than, but just in case
516
-        if ( $uses >= $max_uses && ! empty( $max_uses ) ) {
516
+        if ($uses >= $max_uses && !empty($max_uses)) {
517 517
             // Discount is maxed out
518
-            wpinv_set_error( 'wpinv-discount-error', __( 'This discount has reached its maximum usage.', 'invoicing' ) );
518
+            wpinv_set_error('wpinv-discount-error', __('This discount has reached its maximum usage.', 'invoicing'));
519 519
             $return = true;
520 520
         }
521 521
     }
522 522
 
523
-    return apply_filters( 'wpinv_is_discount_maxed_out', $return, $code_id );
523
+    return apply_filters('wpinv_is_discount_maxed_out', $return, $code_id);
524 524
 }
525 525
 
526
-function wpinv_discount_is_min_met( $code_id = null ) {
527
-    $discount = wpinv_get_discount( $code_id );
526
+function wpinv_discount_is_min_met($code_id = null) {
527
+    $discount = wpinv_get_discount($code_id);
528 528
     $return   = false;
529 529
 
530
-    if ( $discount ) {
531
-        $min         = (float)wpinv_get_discount_min_total( $code_id );
532
-        $cart_amount = (float)wpinv_get_cart_discountable_subtotal( $code_id );
530
+    if ($discount) {
531
+        $min         = (float)wpinv_get_discount_min_total($code_id);
532
+        $cart_amount = (float)wpinv_get_cart_discountable_subtotal($code_id);
533 533
 
534
-        if ( !$min > 0 || $cart_amount >= $min ) {
534
+        if (!$min > 0 || $cart_amount >= $min) {
535 535
             // Minimum has been met
536 536
             $return = true;
537 537
         } else {
538
-            wpinv_set_error( 'wpinv-discount-error', sprintf( __( 'Minimum invoice of %s not met.', 'invoicing' ), wpinv_price( wpinv_format_amount( $min ) ) ) );
538
+            wpinv_set_error('wpinv-discount-error', sprintf(__('Minimum invoice of %s not met.', 'invoicing'), wpinv_price(wpinv_format_amount($min))));
539 539
         }
540 540
     }
541 541
 
542
-    return apply_filters( 'wpinv_is_discount_min_met', $return, $code_id );
542
+    return apply_filters('wpinv_is_discount_min_met', $return, $code_id);
543 543
 }
544 544
 
545
-function wpinv_discount_is_max_met( $code_id = null ) {
546
-    $discount = wpinv_get_discount( $code_id );
545
+function wpinv_discount_is_max_met($code_id = null) {
546
+    $discount = wpinv_get_discount($code_id);
547 547
     $return   = false;
548 548
 
549
-    if ( $discount ) {
550
-        $max         = (float)wpinv_get_discount_max_total( $code_id );
551
-        $cart_amount = (float)wpinv_get_cart_discountable_subtotal( $code_id );
549
+    if ($discount) {
550
+        $max         = (float)wpinv_get_discount_max_total($code_id);
551
+        $cart_amount = (float)wpinv_get_cart_discountable_subtotal($code_id);
552 552
 
553
-        if ( !$max > 0 || $cart_amount <= $max ) {
553
+        if (!$max > 0 || $cart_amount <= $max) {
554 554
             // Minimum has been met
555 555
             $return = true;
556 556
         } else {
557
-            wpinv_set_error( 'wpinv-discount-error', sprintf( __( 'Maximum invoice of %s not met.', 'invoicing' ), wpinv_price( wpinv_format_amount( $max ) ) ) );
557
+            wpinv_set_error('wpinv-discount-error', sprintf(__('Maximum invoice of %s not met.', 'invoicing'), wpinv_price(wpinv_format_amount($max))));
558 558
         }
559 559
     }
560 560
 
561
-    return apply_filters( 'wpinv_is_discount_max_met', $return, $code_id );
561
+    return apply_filters('wpinv_is_discount_max_met', $return, $code_id);
562 562
 }
563 563
 
564
-function wpinv_discount_is_single_use( $code_id = 0 ) {
565
-    $single_use = get_post_meta( $code_id, '_wpi_discount_is_single_use', true );
566
-    return (bool) apply_filters( 'wpinv_is_discount_single_use', $single_use, $code_id );
564
+function wpinv_discount_is_single_use($code_id = 0) {
565
+    $single_use = get_post_meta($code_id, '_wpi_discount_is_single_use', true);
566
+    return (bool)apply_filters('wpinv_is_discount_single_use', $single_use, $code_id);
567 567
 }
568 568
 
569
-function wpinv_discount_is_recurring( $code_id = 0, $code = false ) {
570
-    if ( $code ) {
571
-        $discount = wpinv_get_discount_by_code( $code_id );
569
+function wpinv_discount_is_recurring($code_id = 0, $code = false) {
570
+    if ($code) {
571
+        $discount = wpinv_get_discount_by_code($code_id);
572 572
         
573
-        if ( !empty( $discount ) ) {
573
+        if (!empty($discount)) {
574 574
             $code_id = $discount->ID;
575 575
         }
576 576
     }
577 577
     
578
-    $recurring = get_post_meta( $code_id, '_wpi_discount_is_recurring', true );
578
+    $recurring = get_post_meta($code_id, '_wpi_discount_is_recurring', true);
579 579
     
580
-    return (bool) apply_filters( 'wpinv_is_discount_recurring', $recurring, $code_id, $code );
580
+    return (bool)apply_filters('wpinv_is_discount_recurring', $recurring, $code_id, $code);
581 581
 }
582 582
 
583
-function wpinv_discount_item_reqs_met( $code_id = null ) {
584
-    $item_reqs    = wpinv_get_discount_item_reqs( $code_id );
585
-    $condition    = wpinv_get_discount_item_condition( $code_id );
586
-    $excluded_ps  = wpinv_get_discount_excluded_items( $code_id );
583
+function wpinv_discount_item_reqs_met($code_id = null) {
584
+    $item_reqs    = wpinv_get_discount_item_reqs($code_id);
585
+    $condition    = wpinv_get_discount_item_condition($code_id);
586
+    $excluded_ps  = wpinv_get_discount_excluded_items($code_id);
587 587
     $cart_items   = wpinv_get_cart_contents();
588
-    $cart_ids     = $cart_items ? wp_list_pluck( $cart_items, 'id' ) : null;
588
+    $cart_ids     = $cart_items ? wp_list_pluck($cart_items, 'id') : null;
589 589
     $ret          = false;
590 590
 
591
-    if ( empty( $item_reqs ) && empty( $excluded_ps ) ) {
591
+    if (empty($item_reqs) && empty($excluded_ps)) {
592 592
         $ret = true;
593 593
     }
594 594
 
595 595
     // Normalize our data for item requirements, exclusions and cart data
596 596
     // First absint the items, then sort, and reset the array keys
597
-    $item_reqs = array_map( 'absint', $item_reqs );
598
-    asort( $item_reqs );
599
-    $item_reqs = array_values( $item_reqs );
597
+    $item_reqs = array_map('absint', $item_reqs);
598
+    asort($item_reqs);
599
+    $item_reqs = array_values($item_reqs);
600 600
 
601
-    $excluded_ps  = array_map( 'absint', $excluded_ps );
602
-    asort( $excluded_ps );
603
-    $excluded_ps  = array_values( $excluded_ps );
601
+    $excluded_ps  = array_map('absint', $excluded_ps);
602
+    asort($excluded_ps);
603
+    $excluded_ps  = array_values($excluded_ps);
604 604
 
605
-    $cart_ids     = array_map( 'absint', $cart_ids );
606
-    asort( $cart_ids );
607
-    $cart_ids     = array_values( $cart_ids );
605
+    $cart_ids     = array_map('absint', $cart_ids);
606
+    asort($cart_ids);
607
+    $cart_ids     = array_values($cart_ids);
608 608
 
609 609
     // Ensure we have requirements before proceeding
610
-    if ( !$ret && ! empty( $item_reqs ) ) {
611
-        switch( $condition ) {
610
+    if (!$ret && !empty($item_reqs)) {
611
+        switch ($condition) {
612 612
             case 'all' :
613 613
                 // Default back to true
614 614
                 $ret = true;
615 615
 
616
-                foreach ( $item_reqs as $item_id ) {
617
-                    if ( !wpinv_item_in_cart( $item_id ) ) {
618
-                        wpinv_set_error( 'wpinv-discount-error', __( 'The item requirements for this discount are not met.', 'invoicing' ) );
616
+                foreach ($item_reqs as $item_id) {
617
+                    if (!wpinv_item_in_cart($item_id)) {
618
+                        wpinv_set_error('wpinv-discount-error', __('The item requirements for this discount are not met.', 'invoicing'));
619 619
                         $ret = false;
620 620
                         break;
621 621
                     }
@@ -624,15 +624,15 @@  discard block
 block discarded – undo
624 624
                 break;
625 625
 
626 626
             default : // Any
627
-                foreach ( $item_reqs as $item_id ) {
628
-                    if ( wpinv_item_in_cart( $item_id ) ) {
627
+                foreach ($item_reqs as $item_id) {
628
+                    if (wpinv_item_in_cart($item_id)) {
629 629
                         $ret = true;
630 630
                         break;
631 631
                     }
632 632
                 }
633 633
 
634
-                if( ! $ret ) {
635
-                    wpinv_set_error( 'wpinv-discount-error', __( 'The item requirements for this discount are not met.', 'invoicing' ) );
634
+                if (!$ret) {
635
+                    wpinv_set_error('wpinv-discount-error', __('The item requirements for this discount are not met.', 'invoicing'));
636 636
                 }
637 637
 
638 638
                 break;
@@ -641,68 +641,68 @@  discard block
 block discarded – undo
641 641
         $ret = true;
642 642
     }
643 643
 
644
-    if( ! empty( $excluded_ps ) ) {
644
+    if (!empty($excluded_ps)) {
645 645
         // Check that there are items other than excluded ones in the cart
646
-        if( $cart_ids == $excluded_ps ) {
647
-            wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not valid for the cart contents.', 'invoicing' ) );
646
+        if ($cart_ids == $excluded_ps) {
647
+            wpinv_set_error('wpinv-discount-error', __('This discount is not valid for the cart contents.', 'invoicing'));
648 648
             $ret = false;
649 649
         }
650 650
     }
651 651
 
652
-    return (bool) apply_filters( 'wpinv_is_discount_item_req_met', $ret, $code_id, $condition );
652
+    return (bool)apply_filters('wpinv_is_discount_item_req_met', $ret, $code_id, $condition);
653 653
 }
654 654
 
655
-function wpinv_is_discount_used( $code = null, $user = '', $code_id = 0 ) {
655
+function wpinv_is_discount_used($code = null, $user = '', $code_id = 0) {
656 656
     global $wpi_checkout_id;
657 657
     
658 658
     $return = false;
659 659
 
660
-    if ( empty( $code_id ) ) {
661
-        $code_id = wpinv_get_discount_id_by_code( $code );
660
+    if (empty($code_id)) {
661
+        $code_id = wpinv_get_discount_id_by_code($code);
662 662
         
663
-        if( empty( $code_id ) ) {
663
+        if (empty($code_id)) {
664 664
             return false; // No discount was found
665 665
         }
666 666
     }
667 667
 
668
-    if ( wpinv_discount_is_single_use( $code_id ) ) {
668
+    if (wpinv_discount_is_single_use($code_id)) {
669 669
         $payments = array();
670 670
 
671 671
         $user_id = 0;
672
-        if ( is_int( $user ) ) {
672
+        if (is_int($user)) {
673 673
             $user_id = $user;
674
-        } else if ( is_email( $user ) && $user_data = get_user_by( 'email', $user ) ) {
674
+        } else if (is_email($user) && $user_data = get_user_by('email', $user)) {
675 675
             $user_id = $user_data->ID;
676
-        } else if ( $user_data = get_user_by( 'login', $user ) ) {
676
+        } else if ($user_data = get_user_by('login', $user)) {
677 677
             $user_id = $user_data->ID;
678 678
         }
679 679
 
680
-        if ( !$user_id ) {
681
-            $query    = array( 'user' => $user_id, 'limit' => false );
682
-            $payments = wpinv_get_invoices( $query ); // Get all payments with matching email
680
+        if (!$user_id) {
681
+            $query    = array('user' => $user_id, 'limit' => false);
682
+            $payments = wpinv_get_invoices($query); // Get all payments with matching email
683 683
         }
684 684
 
685
-        if ( $payments ) {
686
-            foreach ( $payments as $payment ) {
687
-                if ( $payment->has_status( array( 'wpi-cancelled', 'wpi-failed' ) ) ) {
685
+        if ($payments) {
686
+            foreach ($payments as $payment) {
687
+                if ($payment->has_status(array('wpi-cancelled', 'wpi-failed'))) {
688 688
                     continue;
689 689
                 }
690 690
 
691 691
                 // Don't count discount used for current invoice chekcout.
692
-                if ( !empty( $wpi_checkout_id ) && $wpi_checkout_id == $payment->ID ) {
692
+                if (!empty($wpi_checkout_id) && $wpi_checkout_id == $payment->ID) {
693 693
                     continue;
694 694
                 }
695 695
 
696
-                $discounts = $payment->get_discounts( true );
697
-                if ( empty( $discounts ) ) {
696
+                $discounts = $payment->get_discounts(true);
697
+                if (empty($discounts)) {
698 698
                     continue;
699 699
                 }
700 700
 
701
-                $discounts = $discounts && !is_array( $discounts ) ? explode( ',', $discounts ) : $discounts;
701
+                $discounts = $discounts && !is_array($discounts) ? explode(',', $discounts) : $discounts;
702 702
 
703
-                if ( !empty( $discounts ) && is_array( $discounts ) ) {
704
-                    if ( in_array( strtolower( $code ), array_map( 'strtolower', $discounts ) ) ) {
705
-                        wpinv_set_error( 'wpinv-discount-error', __( 'This discount has already been redeemed.', 'invoicing' ) );
703
+                if (!empty($discounts) && is_array($discounts)) {
704
+                    if (in_array(strtolower($code), array_map('strtolower', $discounts))) {
705
+                        wpinv_set_error('wpinv-discount-error', __('This discount has already been redeemed.', 'invoicing'));
706 706
                         $return = true;
707 707
                         break;
708 708
                     }
@@ -711,61 +711,61 @@  discard block
 block discarded – undo
711 711
         }
712 712
     }
713 713
 
714
-    return apply_filters( 'wpinv_is_discount_used', $return, $code, $user );
714
+    return apply_filters('wpinv_is_discount_used', $return, $code, $user);
715 715
 }
716 716
 
717
-function wpinv_is_discount_valid( $code = '', $user = '', $set_error = true ) {
717
+function wpinv_is_discount_valid($code = '', $user = '', $set_error = true) {
718 718
     $return      = false;
719
-    $discount_id = wpinv_get_discount_id_by_code( $code );
720
-    $user        = trim( $user );
719
+    $discount_id = wpinv_get_discount_id_by_code($code);
720
+    $user        = trim($user);
721 721
 
722
-    if ( wpinv_get_cart_contents() ) {
723
-        if ( $discount_id ) {
722
+    if (wpinv_get_cart_contents()) {
723
+        if ($discount_id) {
724 724
             if (
725
-                wpinv_is_discount_active( $discount_id ) &&
726
-                wpinv_check_discount_dates( $discount_id ) &&
727
-                !wpinv_is_discount_maxed_out( $discount_id ) &&
728
-                !wpinv_is_discount_used( $code, $user, $discount_id ) &&
729
-                wpinv_discount_is_min_met( $discount_id ) &&
730
-                wpinv_discount_is_max_met( $discount_id ) &&
731
-                wpinv_discount_item_reqs_met( $discount_id )
725
+                wpinv_is_discount_active($discount_id) &&
726
+                wpinv_check_discount_dates($discount_id) &&
727
+                !wpinv_is_discount_maxed_out($discount_id) &&
728
+                !wpinv_is_discount_used($code, $user, $discount_id) &&
729
+                wpinv_discount_is_min_met($discount_id) &&
730
+                wpinv_discount_is_max_met($discount_id) &&
731
+                wpinv_discount_item_reqs_met($discount_id)
732 732
             ) {
733 733
                 $return = true;
734 734
             }
735
-        } elseif( $set_error ) {
736
-            wpinv_set_error( 'wpinv-discount-error', __( 'This discount is invalid.', 'invoicing' ) );
735
+        } elseif ($set_error) {
736
+            wpinv_set_error('wpinv-discount-error', __('This discount is invalid.', 'invoicing'));
737 737
         }
738 738
     }
739 739
 
740
-    return apply_filters( 'wpinv_is_discount_valid', $return, $discount_id, $code, $user );
740
+    return apply_filters('wpinv_is_discount_valid', $return, $discount_id, $code, $user);
741 741
 }
742 742
 
743
-function wpinv_get_discount_id_by_code( $code ) {
744
-    $discount = wpinv_get_discount_by_code( $code );
745
-    if( $discount ) {
743
+function wpinv_get_discount_id_by_code($code) {
744
+    $discount = wpinv_get_discount_by_code($code);
745
+    if ($discount) {
746 746
         return $discount->ID;
747 747
     }
748 748
     return false;
749 749
 }
750 750
 
751
-function wpinv_get_discounted_amount( $code, $base_price ) {
751
+function wpinv_get_discounted_amount($code, $base_price) {
752 752
     $amount      = $base_price;
753
-    $discount_id = wpinv_get_discount_id_by_code( $code );
753
+    $discount_id = wpinv_get_discount_id_by_code($code);
754 754
 
755
-    if( $discount_id ) {
756
-        $type        = wpinv_get_discount_type( $discount_id );
757
-        $rate        = wpinv_get_discount_amount( $discount_id );
755
+    if ($discount_id) {
756
+        $type        = wpinv_get_discount_type($discount_id);
757
+        $rate        = wpinv_get_discount_amount($discount_id);
758 758
 
759
-        if ( $type == 'flat' ) {
759
+        if ($type == 'flat') {
760 760
             // Set amount
761 761
             $amount = $base_price - $rate;
762
-            if ( $amount < 0 ) {
762
+            if ($amount < 0) {
763 763
                 $amount = 0;
764 764
             }
765 765
 
766 766
         } else {
767 767
             // Percentage discount
768
-            $amount = $base_price - ( $base_price * ( $rate / 100 ) );
768
+            $amount = $base_price - ($base_price * ($rate / 100));
769 769
         }
770 770
 
771 771
     } else {
@@ -774,108 +774,108 @@  discard block
 block discarded – undo
774 774
 
775 775
     }
776 776
 
777
-    return apply_filters( 'wpinv_discounted_amount', $amount );
777
+    return apply_filters('wpinv_discounted_amount', $amount);
778 778
 }
779 779
 
780
-function wpinv_increase_discount_usage( $code ) {
780
+function wpinv_increase_discount_usage($code) {
781 781
 
782
-    $id   = wpinv_get_discount_id_by_code( $code );
783
-    $uses = wpinv_get_discount_uses( $id );
782
+    $id   = wpinv_get_discount_id_by_code($code);
783
+    $uses = wpinv_get_discount_uses($id);
784 784
 
785
-    if ( $uses ) {
785
+    if ($uses) {
786 786
         $uses++;
787 787
     } else {
788 788
         $uses = 1;
789 789
     }
790 790
 
791
-    update_post_meta( $id, '_wpi_discount_uses', $uses );
791
+    update_post_meta($id, '_wpi_discount_uses', $uses);
792 792
 
793
-    do_action( 'wpinv_discount_increase_use_count', $uses, $id, $code );
793
+    do_action('wpinv_discount_increase_use_count', $uses, $id, $code);
794 794
 
795 795
     return $uses;
796 796
 
797 797
 }
798 798
 
799
-function wpinv_decrease_discount_usage( $code ) {
799
+function wpinv_decrease_discount_usage($code) {
800 800
 
801
-    $id   = wpinv_get_discount_id_by_code( $code );
802
-    $uses = wpinv_get_discount_uses( $id );
801
+    $id   = wpinv_get_discount_id_by_code($code);
802
+    $uses = wpinv_get_discount_uses($id);
803 803
 
804
-    if ( $uses ) {
804
+    if ($uses) {
805 805
         $uses--;
806 806
     }
807 807
 
808
-    if ( $uses < 0 ) {
808
+    if ($uses < 0) {
809 809
         $uses = 0;
810 810
     }
811 811
 
812
-    update_post_meta( $id, '_wpi_discount_uses', $uses );
812
+    update_post_meta($id, '_wpi_discount_uses', $uses);
813 813
 
814
-    do_action( 'wpinv_discount_decrease_use_count', $uses, $id, $code );
814
+    do_action('wpinv_discount_decrease_use_count', $uses, $id, $code);
815 815
 
816 816
     return $uses;
817 817
 
818 818
 }
819 819
 
820
-function wpinv_format_discount_rate( $type, $amount ) {
821
-    if ( $type == 'flat' ) {
822
-        return wpinv_price( wpinv_format_amount( $amount ) );
820
+function wpinv_format_discount_rate($type, $amount) {
821
+    if ($type == 'flat') {
822
+        return wpinv_price(wpinv_format_amount($amount));
823 823
     } else {
824 824
         return $amount . '%';
825 825
     }
826 826
 }
827 827
 
828
-function wpinv_set_cart_discount( $code = '' ) {    
829
-    if ( wpinv_multiple_discounts_allowed() ) {
828
+function wpinv_set_cart_discount($code = '') {    
829
+    if (wpinv_multiple_discounts_allowed()) {
830 830
         // Get all active cart discounts
831 831
         $discounts = wpinv_get_cart_discounts();
832 832
     } else {
833 833
         $discounts = false; // Only one discount allowed per purchase, so override any existing
834 834
     }
835 835
 
836
-    if ( $discounts ) {
837
-        $key = array_search( strtolower( $code ), array_map( 'strtolower', $discounts ) );
838
-        if( false !== $key ) {
839
-            unset( $discounts[ $key ] ); // Can't set the same discount more than once
836
+    if ($discounts) {
837
+        $key = array_search(strtolower($code), array_map('strtolower', $discounts));
838
+        if (false !== $key) {
839
+            unset($discounts[$key]); // Can't set the same discount more than once
840 840
         }
841 841
         $discounts[] = $code;
842 842
     } else {
843 843
         $discounts = array();
844 844
         $discounts[] = $code;
845 845
     }
846
-    $discounts = array_values( $discounts );
846
+    $discounts = array_values($discounts);
847 847
     
848 848
     $data = wpinv_get_checkout_session();
849
-    if ( empty( $data ) ) {
849
+    if (empty($data)) {
850 850
         $data = array();
851 851
     } else {
852
-        if ( !empty( $data['invoice_id'] ) && $payment_meta = wpinv_get_invoice_meta( $data['invoice_id'] ) ) {
853
-            $payment_meta['user_info']['discount']  = implode( ',', $discounts );
854
-            update_post_meta( $data['invoice_id'], '_wpinv_payment_meta', $payment_meta );
852
+        if (!empty($data['invoice_id']) && $payment_meta = wpinv_get_invoice_meta($data['invoice_id'])) {
853
+            $payment_meta['user_info']['discount'] = implode(',', $discounts);
854
+            update_post_meta($data['invoice_id'], '_wpinv_payment_meta', $payment_meta);
855 855
         }
856 856
     }
857 857
     $data['cart_discounts'] = $discounts;
858 858
     
859
-    wpinv_set_checkout_session( $data );
859
+    wpinv_set_checkout_session($data);
860 860
     
861 861
     return $discounts;
862 862
 }
863 863
 
864
-function wpinv_unset_cart_discount( $code = '' ) {    
864
+function wpinv_unset_cart_discount($code = '') {    
865 865
     $discounts = wpinv_get_cart_discounts();
866 866
 
867
-    if ( $code && !empty( $discounts ) && in_array( $code, $discounts ) ) {
868
-        $key = array_search( $code, $discounts );
869
-        unset( $discounts[ $key ] );
867
+    if ($code && !empty($discounts) && in_array($code, $discounts)) {
868
+        $key = array_search($code, $discounts);
869
+        unset($discounts[$key]);
870 870
             
871 871
         $data = wpinv_get_checkout_session();
872 872
         $data['cart_discounts'] = $discounts;
873
-        if ( !empty( $data['invoice_id'] ) && $payment_meta = wpinv_get_invoice_meta( $data['invoice_id'] ) ) {
874
-            $payment_meta['user_info']['discount']  = !empty( $discounts ) ? implode( ',', $discounts ) : '';
875
-            update_post_meta( $data['invoice_id'], '_wpinv_payment_meta', $payment_meta );
873
+        if (!empty($data['invoice_id']) && $payment_meta = wpinv_get_invoice_meta($data['invoice_id'])) {
874
+            $payment_meta['user_info']['discount'] = !empty($discounts) ? implode(',', $discounts) : '';
875
+            update_post_meta($data['invoice_id'], '_wpinv_payment_meta', $payment_meta);
876 876
         }
877 877
         
878
-        wpinv_set_checkout_session( $data );
878
+        wpinv_set_checkout_session($data);
879 879
     }
880 880
 
881 881
     return $discounts;
@@ -884,27 +884,27 @@  discard block
 block discarded – undo
884 884
 function wpinv_unset_all_cart_discounts() {
885 885
     $data = wpinv_get_checkout_session();
886 886
     
887
-    if ( !empty( $data ) && isset( $data['cart_discounts'] ) ) {
888
-        unset( $data['cart_discounts'] );
887
+    if (!empty($data) && isset($data['cart_discounts'])) {
888
+        unset($data['cart_discounts']);
889 889
         
890
-         wpinv_set_checkout_session( $data );
890
+         wpinv_set_checkout_session($data);
891 891
          return true;
892 892
     }
893 893
     
894 894
     return false;
895 895
 }
896 896
 
897
-function wpinv_get_cart_discounts( $items = array() ) {
897
+function wpinv_get_cart_discounts($items = array()) {
898 898
     $session = wpinv_get_checkout_session();
899 899
     
900
-    $discounts = !empty( $session['cart_discounts'] ) ? $session['cart_discounts'] : false;
900
+    $discounts = !empty($session['cart_discounts']) ? $session['cart_discounts'] : false;
901 901
     return $discounts;
902 902
 }
903 903
 
904
-function wpinv_cart_has_discounts( $items = array() ) {
904
+function wpinv_cart_has_discounts($items = array()) {
905 905
     $ret = false;
906 906
 
907
-    if ( wpinv_get_cart_discounts( $items ) ) {
907
+    if (wpinv_get_cart_discounts($items)) {
908 908
         $ret = true;
909 909
     }
910 910
     
@@ -915,131 +915,131 @@  discard block
 block discarded – undo
915 915
     }
916 916
     */
917 917
 
918
-    return apply_filters( 'wpinv_cart_has_discounts', $ret );
918
+    return apply_filters('wpinv_cart_has_discounts', $ret);
919 919
 }
920 920
 
921
-function wpinv_get_cart_discounted_amount( $items = array(), $discounts = false ) {
921
+function wpinv_get_cart_discounted_amount($items = array(), $discounts = false) {
922 922
     $amount = 0.00;
923
-    $items  = !empty( $items ) ? $items : wpinv_get_cart_content_details();
923
+    $items  = !empty($items) ? $items : wpinv_get_cart_content_details();
924 924
 
925
-    if ( $items ) {
926
-        $discounts = wp_list_pluck( $items, 'discount' );
925
+    if ($items) {
926
+        $discounts = wp_list_pluck($items, 'discount');
927 927
 
928
-        if ( is_array( $discounts ) ) {
929
-            $discounts = array_map( 'floatval', $discounts );
930
-            $amount    = array_sum( $discounts );
928
+        if (is_array($discounts)) {
929
+            $discounts = array_map('floatval', $discounts);
930
+            $amount    = array_sum($discounts);
931 931
         }
932 932
     }
933 933
 
934
-    return apply_filters( 'wpinv_get_cart_discounted_amount', $amount );
934
+    return apply_filters('wpinv_get_cart_discounted_amount', $amount);
935 935
 }
936 936
 
937
-function wpinv_get_cart_items_discount_amount( $items = array(), $discount = false ) {
938
-    $items  = !empty( $items ) ? $items : wpinv_get_cart_content_details();
937
+function wpinv_get_cart_items_discount_amount($items = array(), $discount = false) {
938
+    $items = !empty($items) ? $items : wpinv_get_cart_content_details();
939 939
     
940
-    if ( empty( $discount ) || empty( $items ) ) {
940
+    if (empty($discount) || empty($items)) {
941 941
         return 0;
942 942
     }
943 943
 
944 944
     $amount = 0;
945 945
     
946
-    foreach ( $items as $item ) {
947
-        $amount += wpinv_get_cart_item_discount_amount( $item, $discount );
946
+    foreach ($items as $item) {
947
+        $amount += wpinv_get_cart_item_discount_amount($item, $discount);
948 948
     }
949 949
     
950
-    $amount = wpinv_round_amount( $amount );
950
+    $amount = wpinv_round_amount($amount);
951 951
 
952 952
     return $amount;
953 953
 }
954 954
 
955
-function wpinv_get_cart_item_discount_amount( $item = array(), $discount = false ) {
955
+function wpinv_get_cart_item_discount_amount($item = array(), $discount = false) {
956 956
     global $wpinv_is_last_cart_item, $wpinv_flat_discount_total;
957 957
     
958 958
     $amount = 0;
959 959
 
960
-    if ( empty( $item ) || empty( $item['id'] ) ) {
960
+    if (empty($item) || empty($item['id'])) {
961 961
         return $amount;
962 962
     }
963 963
 
964
-    if ( empty( $item['quantity'] ) ) {
964
+    if (empty($item['quantity'])) {
965 965
         return $amount;
966 966
     }
967 967
 
968
-    if ( empty( $item['options'] ) ) {
968
+    if (empty($item['options'])) {
969 969
         $item['options'] = array();
970 970
     }
971 971
 
972
-    $price            = wpinv_get_cart_item_price( $item['id'], $item, $item['options'] );
972
+    $price            = wpinv_get_cart_item_price($item['id'], $item, $item['options']);
973 973
     $discounted_price = $price;
974 974
 
975 975
     $discounts = false === $discount ? wpinv_get_cart_discounts() : $discount;
976
-    if ( empty( $discounts ) ) {
976
+    if (empty($discounts)) {
977 977
         return $amount;
978 978
     }
979 979
 
980
-    if ( $discounts ) {
981
-        if ( is_array( $discounts ) ) {
982
-            $discounts = array_values( $discounts );
980
+    if ($discounts) {
981
+        if (is_array($discounts)) {
982
+            $discounts = array_values($discounts);
983 983
         } else {
984
-            $discounts = explode( ',', $discounts );
984
+            $discounts = explode(',', $discounts);
985 985
         }
986 986
     }
987 987
 
988
-    if( $discounts ) {
989
-        foreach ( $discounts as $discount ) {
990
-            $code_id = wpinv_get_discount_id_by_code( $discount );
988
+    if ($discounts) {
989
+        foreach ($discounts as $discount) {
990
+            $code_id = wpinv_get_discount_id_by_code($discount);
991 991
 
992 992
             // Check discount exists
993
-            if( ! $code_id ) {
993
+            if (!$code_id) {
994 994
                 continue;
995 995
             }
996 996
 
997
-            $reqs           = wpinv_get_discount_item_reqs( $code_id );
998
-            $excluded_items = wpinv_get_discount_excluded_items( $code_id );
997
+            $reqs           = wpinv_get_discount_item_reqs($code_id);
998
+            $excluded_items = wpinv_get_discount_excluded_items($code_id);
999 999
 
1000 1000
             // Make sure requirements are set and that this discount shouldn't apply to the whole cart
1001
-            if ( !empty( $reqs ) && wpinv_is_discount_not_global( $code_id ) ) {
1002
-                foreach ( $reqs as $item_id ) {
1003
-                    if ( $item_id == $item['id'] && ! in_array( $item['id'], $excluded_items ) ) {
1004
-                        $discounted_price -= $price - wpinv_get_discounted_amount( $discount, $price );
1001
+            if (!empty($reqs) && wpinv_is_discount_not_global($code_id)) {
1002
+                foreach ($reqs as $item_id) {
1003
+                    if ($item_id == $item['id'] && !in_array($item['id'], $excluded_items)) {
1004
+                        $discounted_price -= $price - wpinv_get_discounted_amount($discount, $price);
1005 1005
                     }
1006 1006
                 }
1007 1007
             } else {
1008 1008
                 // This is a global cart discount
1009
-                if ( !in_array( $item['id'], $excluded_items ) ) {
1010
-                    if ( 'flat' === wpinv_get_discount_type( $code_id ) ) {
1009
+                if (!in_array($item['id'], $excluded_items)) {
1010
+                    if ('flat' === wpinv_get_discount_type($code_id)) {
1011 1011
                         $items_subtotal    = 0.00;
1012 1012
                         $cart_items        = wpinv_get_cart_contents();
1013 1013
                         
1014
-                        foreach ( $cart_items as $cart_item ) {
1015
-                            if ( ! in_array( $cart_item['id'], $excluded_items ) ) {
1016
-                                $options = !empty( $cart_item['options'] ) ? $cart_item['options'] : array();
1017
-                                $item_price      = wpinv_get_cart_item_price( $cart_item['id'], $cart_item, $options );
1014
+                        foreach ($cart_items as $cart_item) {
1015
+                            if (!in_array($cart_item['id'], $excluded_items)) {
1016
+                                $options = !empty($cart_item['options']) ? $cart_item['options'] : array();
1017
+                                $item_price      = wpinv_get_cart_item_price($cart_item['id'], $cart_item, $options);
1018 1018
                                 $items_subtotal += $item_price * $cart_item['quantity'];
1019 1019
                             }
1020 1020
                         }
1021 1021
 
1022
-                        $subtotal_percent  = ( ( $price * $item['quantity'] ) / $items_subtotal );
1023
-                        $code_amount       = wpinv_get_discount_amount( $code_id );
1022
+                        $subtotal_percent  = (($price * $item['quantity']) / $items_subtotal);
1023
+                        $code_amount       = wpinv_get_discount_amount($code_id);
1024 1024
                         $discounted_amount = $code_amount * $subtotal_percent;
1025 1025
                         $discounted_price -= $discounted_amount;
1026 1026
 
1027
-                        $wpinv_flat_discount_total += round( $discounted_amount, wpinv_currency_decimal_filter() );
1027
+                        $wpinv_flat_discount_total += round($discounted_amount, wpinv_currency_decimal_filter());
1028 1028
 
1029
-                        if ( $wpinv_is_last_cart_item && $wpinv_flat_discount_total < $code_amount ) {
1029
+                        if ($wpinv_is_last_cart_item && $wpinv_flat_discount_total < $code_amount) {
1030 1030
                             $adjustment = $code_amount - $wpinv_flat_discount_total;
1031 1031
                             $discounted_price -= $adjustment;
1032 1032
                         }
1033 1033
                     } else {
1034
-                        $discounted_price -= $price - wpinv_get_discounted_amount( $discount, $price );
1034
+                        $discounted_price -= $price - wpinv_get_discounted_amount($discount, $price);
1035 1035
                     }
1036 1036
                 }
1037 1037
             }
1038 1038
         }
1039 1039
 
1040
-        $amount = ( $price - apply_filters( 'wpinv_get_cart_item_discounted_amount', $discounted_price, $discounts, $item, $price ) );
1040
+        $amount = ($price - apply_filters('wpinv_get_cart_item_discounted_amount', $discounted_price, $discounts, $item, $price));
1041 1041
 
1042
-        if ( 'flat' !== wpinv_get_discount_type( $code_id ) ) {
1042
+        if ('flat' !== wpinv_get_discount_type($code_id)) {
1043 1043
             $amount = $amount * $item['quantity'];
1044 1044
         }
1045 1045
     }
@@ -1047,59 +1047,59 @@  discard block
 block discarded – undo
1047 1047
     return $amount;
1048 1048
 }
1049 1049
 
1050
-function wpinv_cart_discounts_html( $items = array() ) {
1051
-    echo wpinv_get_cart_discounts_html( $items );
1050
+function wpinv_cart_discounts_html($items = array()) {
1051
+    echo wpinv_get_cart_discounts_html($items);
1052 1052
 }
1053 1053
 
1054
-function wpinv_get_cart_discounts_html( $items = array(), $discounts = false ) {
1054
+function wpinv_get_cart_discounts_html($items = array(), $discounts = false) {
1055 1055
     global $wpi_cart_columns;
1056 1056
     
1057
-    $items  = !empty( $items ) ? $items : wpinv_get_cart_content_details();
1057
+    $items = !empty($items) ? $items : wpinv_get_cart_content_details();
1058 1058
     
1059
-    if ( !$discounts ) {
1060
-        $discounts = wpinv_get_cart_discounts( $items );
1059
+    if (!$discounts) {
1060
+        $discounts = wpinv_get_cart_discounts($items);
1061 1061
     }
1062 1062
 
1063
-    if ( !$discounts ) {
1063
+    if (!$discounts) {
1064 1064
         return;
1065 1065
     }
1066 1066
     
1067
-    $discounts = is_array( $discounts ) ? $discounts : array( $discounts );
1067
+    $discounts = is_array($discounts) ? $discounts : array($discounts);
1068 1068
     
1069 1069
     $html = '';
1070 1070
 
1071
-    foreach ( $discounts as $discount ) {
1072
-        $discount_id    = wpinv_get_discount_id_by_code( $discount );
1073
-        $discount_value = wpinv_get_discount_amount( $discount_id );
1074
-        $rate           = wpinv_format_discount_rate( wpinv_get_discount_type( $discount_id ), $discount_value );
1075
-        $amount         = wpinv_get_cart_items_discount_amount( $items, $discount );
1076
-        $remove_btn     = '<a title="' . esc_attr__( 'Remove discount', 'invoicing' ) . '" data-code="' . $discount . '" data-value="' . $discount_value . '" class="wpi-discount-remove" href="javascript:void(0);">[<i class="fa fa-times" aria-hidden="true"></i>]</a> ';
1071
+    foreach ($discounts as $discount) {
1072
+        $discount_id    = wpinv_get_discount_id_by_code($discount);
1073
+        $discount_value = wpinv_get_discount_amount($discount_id);
1074
+        $rate           = wpinv_format_discount_rate(wpinv_get_discount_type($discount_id), $discount_value);
1075
+        $amount         = wpinv_get_cart_items_discount_amount($items, $discount);
1076
+        $remove_btn     = '<a title="' . esc_attr__('Remove discount', 'invoicing') . '" data-code="' . $discount . '" data-value="' . $discount_value . '" class="wpi-discount-remove" href="javascript:void(0);">[<i class="fa fa-times" aria-hidden="true"></i>]</a> ';
1077 1077
         
1078 1078
         $html .= '<tr class="wpinv_cart_footer_row wpinv_cart_discount_row">';
1079 1079
         ob_start();
1080
-        do_action( 'wpinv_checkout_table_discount_first', $items );
1080
+        do_action('wpinv_checkout_table_discount_first', $items);
1081 1081
         $html .= ob_get_clean();
1082
-        $html .= '<td class="wpinv_cart_discount_label text-right" colspan="' . $wpi_cart_columns . '">' . $remove_btn . '<strong>' . wpinv_cart_discount_label( $discount, $rate, false ) . '</strong></td><td class="wpinv_cart_discount text-right"><span data-discount="' . $amount . '" class="wpinv_cart_discount_amount">&ndash;' . wpinv_price( wpinv_format_amount( $amount ) ) . '</span></td>';
1082
+        $html .= '<td class="wpinv_cart_discount_label text-right" colspan="' . $wpi_cart_columns . '">' . $remove_btn . '<strong>' . wpinv_cart_discount_label($discount, $rate, false) . '</strong></td><td class="wpinv_cart_discount text-right"><span data-discount="' . $amount . '" class="wpinv_cart_discount_amount">&ndash;' . wpinv_price(wpinv_format_amount($amount)) . '</span></td>';
1083 1083
         ob_start();
1084
-        do_action( 'wpinv_checkout_table_discount_last', $items );
1084
+        do_action('wpinv_checkout_table_discount_last', $items);
1085 1085
         $html .= ob_get_clean();
1086 1086
         $html .= '</tr>';
1087 1087
     }
1088 1088
 
1089
-    return apply_filters( 'wpinv_get_cart_discounts_html', $html, $discounts, $rate );
1089
+    return apply_filters('wpinv_get_cart_discounts_html', $html, $discounts, $rate);
1090 1090
 }
1091 1091
 
1092
-function wpinv_display_cart_discount( $formatted = false, $echo = false ) {
1092
+function wpinv_display_cart_discount($formatted = false, $echo = false) {
1093 1093
     $discounts = wpinv_get_cart_discounts();
1094 1094
 
1095
-    if ( empty( $discounts ) ) {
1095
+    if (empty($discounts)) {
1096 1096
         return false;
1097 1097
     }
1098 1098
 
1099
-    $discount_id  = wpinv_get_discount_id_by_code( $discounts[0] );
1100
-    $amount       = wpinv_format_discount_rate( wpinv_get_discount_type( $discount_id ), wpinv_get_discount_amount( $discount_id ) );
1099
+    $discount_id  = wpinv_get_discount_id_by_code($discounts[0]);
1100
+    $amount       = wpinv_format_discount_rate(wpinv_get_discount_type($discount_id), wpinv_get_discount_amount($discount_id));
1101 1101
 
1102
-    if ( $echo ) {
1102
+    if ($echo) {
1103 1103
         echo $amount;
1104 1104
     }
1105 1105
 
@@ -1107,133 +1107,133 @@  discard block
 block discarded – undo
1107 1107
 }
1108 1108
 
1109 1109
 function wpinv_remove_cart_discount() {
1110
-    if ( !isset( $_GET['discount_id'] ) || ! isset( $_GET['discount_code'] ) ) {
1110
+    if (!isset($_GET['discount_id']) || !isset($_GET['discount_code'])) {
1111 1111
         return;
1112 1112
     }
1113 1113
 
1114
-    do_action( 'wpinv_pre_remove_cart_discount', absint( $_GET['discount_id'] ) );
1114
+    do_action('wpinv_pre_remove_cart_discount', absint($_GET['discount_id']));
1115 1115
 
1116
-    wpinv_unset_cart_discount( urldecode( $_GET['discount_code'] ) );
1116
+    wpinv_unset_cart_discount(urldecode($_GET['discount_code']));
1117 1117
 
1118
-    do_action( 'wpinv_post_remove_cart_discount', absint( $_GET['discount_id'] ) );
1118
+    do_action('wpinv_post_remove_cart_discount', absint($_GET['discount_id']));
1119 1119
 
1120
-    wp_redirect( wpinv_get_checkout_uri() ); wpinv_die();
1120
+    wp_redirect(wpinv_get_checkout_uri()); wpinv_die();
1121 1121
 }
1122
-add_action( 'wpinv_remove_cart_discount', 'wpinv_remove_cart_discount' );
1122
+add_action('wpinv_remove_cart_discount', 'wpinv_remove_cart_discount');
1123 1123
 
1124
-function wpinv_maybe_remove_cart_discount( $cart_key = 0 ) {
1124
+function wpinv_maybe_remove_cart_discount($cart_key = 0) {
1125 1125
     $discounts = wpinv_get_cart_discounts();
1126 1126
 
1127
-    if ( !$discounts ) {
1127
+    if (!$discounts) {
1128 1128
         return;
1129 1129
     }
1130 1130
 
1131
-    foreach ( $discounts as $discount ) {
1132
-        if ( !wpinv_is_discount_valid( $discount ) ) {
1133
-            wpinv_unset_cart_discount( $discount );
1131
+    foreach ($discounts as $discount) {
1132
+        if (!wpinv_is_discount_valid($discount)) {
1133
+            wpinv_unset_cart_discount($discount);
1134 1134
         }
1135 1135
     }
1136 1136
 }
1137
-add_action( 'wpinv_post_remove_from_cart', 'wpinv_maybe_remove_cart_discount' );
1137
+add_action('wpinv_post_remove_from_cart', 'wpinv_maybe_remove_cart_discount');
1138 1138
 
1139 1139
 function wpinv_multiple_discounts_allowed() {
1140
-    $ret = wpinv_get_option( 'allow_multiple_discounts', false );
1141
-    return (bool) apply_filters( 'wpinv_multiple_discounts_allowed', $ret );
1140
+    $ret = wpinv_get_option('allow_multiple_discounts', false);
1141
+    return (bool)apply_filters('wpinv_multiple_discounts_allowed', $ret);
1142 1142
 }
1143 1143
 
1144 1144
 function wpinv_listen_for_cart_discount() {
1145 1145
     global $wpi_session;
1146 1146
     
1147
-    if ( empty( $_REQUEST['discount'] ) || is_array( $_REQUEST['discount'] ) ) {
1147
+    if (empty($_REQUEST['discount']) || is_array($_REQUEST['discount'])) {
1148 1148
         return;
1149 1149
     }
1150 1150
 
1151
-    $code = preg_replace('/[^a-zA-Z0-9-_]+/', '', $_REQUEST['discount'] );
1151
+    $code = preg_replace('/[^a-zA-Z0-9-_]+/', '', $_REQUEST['discount']);
1152 1152
 
1153
-    $wpi_session->set( 'preset_discount', $code );
1153
+    $wpi_session->set('preset_discount', $code);
1154 1154
 }
1155 1155
 //add_action( 'init', 'wpinv_listen_for_cart_discount', 0 );
1156 1156
 
1157 1157
 function wpinv_apply_preset_discount() {
1158 1158
     global $wpi_session;
1159 1159
     
1160
-    $code = $wpi_session->get( 'preset_discount' );
1160
+    $code = $wpi_session->get('preset_discount');
1161 1161
 
1162
-    if ( !$code ) {
1162
+    if (!$code) {
1163 1163
         return;
1164 1164
     }
1165 1165
 
1166
-    if ( !wpinv_is_discount_valid( $code, '', false ) ) {
1166
+    if (!wpinv_is_discount_valid($code, '', false)) {
1167 1167
         return;
1168 1168
     }
1169 1169
     
1170
-    $code = apply_filters( 'wpinv_apply_preset_discount', $code );
1170
+    $code = apply_filters('wpinv_apply_preset_discount', $code);
1171 1171
 
1172
-    wpinv_set_cart_discount( $code );
1172
+    wpinv_set_cart_discount($code);
1173 1173
 
1174
-    $wpi_session->set( 'preset_discount', null );
1174
+    $wpi_session->set('preset_discount', null);
1175 1175
 }
1176 1176
 //add_action( 'init', 'wpinv_apply_preset_discount', 999 );
1177 1177
 
1178
-function wpinv_get_discount_label( $code, $echo = true ) {
1179
-    $label = wp_sprintf( __( 'Discount%1$s', 'invoicing' ), ( $code != '' && $code != 'none' ? ' (<code>' . $code . '</code>)': '' ) );
1180
-    $label = apply_filters( 'wpinv_get_discount_label', $label, $code );
1178
+function wpinv_get_discount_label($code, $echo = true) {
1179
+    $label = wp_sprintf(__('Discount%1$s', 'invoicing'), ($code != '' && $code != 'none' ? ' (<code>' . $code . '</code>)' : ''));
1180
+    $label = apply_filters('wpinv_get_discount_label', $label, $code);
1181 1181
 
1182
-    if ( $echo ) {
1182
+    if ($echo) {
1183 1183
         echo $label;
1184 1184
     } else {
1185 1185
         return $label;
1186 1186
     }
1187 1187
 }
1188 1188
 
1189
-function wpinv_cart_discount_label( $code, $rate, $echo = true ) {
1190
-    $label = wp_sprintf( __( '%1$s Discount: %2$s', 'invoicing' ), $rate, $code );
1191
-    $label = apply_filters( 'wpinv_cart_discount_label', $label, $code, $rate );
1189
+function wpinv_cart_discount_label($code, $rate, $echo = true) {
1190
+    $label = wp_sprintf(__('%1$s Discount: %2$s', 'invoicing'), $rate, $code);
1191
+    $label = apply_filters('wpinv_cart_discount_label', $label, $code, $rate);
1192 1192
 
1193
-    if ( $echo ) {
1193
+    if ($echo) {
1194 1194
         echo $label;
1195 1195
     } else {
1196 1196
         return $label;
1197 1197
     }
1198 1198
 }
1199 1199
 
1200
-function wpinv_check_delete_discount( $check, $post, $force_delete ) {
1201
-    if ( $post->post_type == 'wpi_discount' && wpinv_get_discount_uses( $post->ID ) > 0 ) {
1200
+function wpinv_check_delete_discount($check, $post, $force_delete) {
1201
+    if ($post->post_type == 'wpi_discount' && wpinv_get_discount_uses($post->ID) > 0) {
1202 1202
         return true;
1203 1203
     }
1204 1204
     
1205 1205
     return $check;
1206 1206
 }
1207
-add_filter( 'pre_delete_post', 'wpinv_check_delete_discount', 10, 3 );
1207
+add_filter('pre_delete_post', 'wpinv_check_delete_discount', 10, 3);
1208 1208
 
1209 1209
 function wpinv_checkout_form_validate_discounts() {
1210 1210
     $discounts = wpinv_get_cart_discounts();
1211 1211
     
1212
-    if ( !empty( $discounts ) ) {
1212
+    if (!empty($discounts)) {
1213 1213
         $invalid = false;
1214 1214
         
1215
-        foreach ( $discounts as $key => $code ) {
1216
-            if ( !wpinv_is_discount_valid( $code, get_current_user_id() ) ) {
1215
+        foreach ($discounts as $key => $code) {
1216
+            if (!wpinv_is_discount_valid($code, get_current_user_id())) {
1217 1217
                 $invalid = true;
1218 1218
                 
1219
-                wpinv_unset_cart_discount( $code );
1219
+                wpinv_unset_cart_discount($code);
1220 1220
             }
1221 1221
         }
1222 1222
         
1223
-        if ( $invalid ) {
1223
+        if ($invalid) {
1224 1224
             $errors = wpinv_get_errors();
1225
-            $error  = !empty( $errors['wpinv-discount-error'] ) ? $errors['wpinv-discount-error'] . ' ' : '';
1226
-            $error  .= __( 'The discount has been removed from cart.', 'invoicing' );
1227
-            wpinv_set_error( 'wpinv-discount-error', $error );
1225
+            $error  = !empty($errors['wpinv-discount-error']) ? $errors['wpinv-discount-error'] . ' ' : '';
1226
+            $error .= __('The discount has been removed from cart.', 'invoicing');
1227
+            wpinv_set_error('wpinv-discount-error', $error);
1228 1228
             
1229
-            wpinv_recalculate_tax( true );
1229
+            wpinv_recalculate_tax(true);
1230 1230
         }
1231 1231
     }
1232 1232
 }
1233
-add_action( 'wpinv_before_checkout_form', 'wpinv_checkout_form_validate_discounts', -10 );
1233
+add_action('wpinv_before_checkout_form', 'wpinv_checkout_form_validate_discounts', -10);
1234 1234
 
1235 1235
 function wpinv_discount_amount() {
1236 1236
     $output = 0.00;
1237 1237
     
1238
-    return apply_filters( 'wpinv_discount_amount', $output );
1238
+    return apply_filters('wpinv_discount_amount', $output);
1239 1239
 }
1240 1240
\ No newline at end of file
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,109 +7,109 @@  discard block
 block discarded – undo
7 7
  */
8 8
  
9 9
 // MUST have WordPress.
10
-if ( !defined( 'WPINC' ) ) {
11
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
10
+if (!defined('WPINC')) {
11
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
12 12
 }
13 13
 
14
-if ( !is_admin() ) {
15
-    add_filter( 'template_include', 'wpinv_template', 10, 1 );
16
-    add_action( 'wpinv_invoice_print_body_start', 'wpinv_display_invoice_top_bar' );
17
-    add_action( 'wpinv_invoice_top_bar_left', 'wpinv_invoice_display_left_actions' );
18
-    add_action( 'wpinv_invoice_top_bar_right', 'wpinv_invoice_display_right_actions' );
14
+if (!is_admin()) {
15
+    add_filter('template_include', 'wpinv_template', 10, 1);
16
+    add_action('wpinv_invoice_print_body_start', 'wpinv_display_invoice_top_bar');
17
+    add_action('wpinv_invoice_top_bar_left', 'wpinv_invoice_display_left_actions');
18
+    add_action('wpinv_invoice_top_bar_right', 'wpinv_invoice_display_right_actions');
19 19
 }
20 20
 
21 21
 function wpinv_template_path() {
22
-    return apply_filters( 'wpinv_template_path', 'invoicing/' );
22
+    return apply_filters('wpinv_template_path', 'invoicing/');
23 23
 }
24 24
 
25
-function wpinv_post_class( $classes, $class, $post_id ) {
25
+function wpinv_post_class($classes, $class, $post_id) {
26 26
     global $pagenow, $typenow;
27 27
 
28
-    if ( $pagenow == 'edit.php' && $typenow == 'wpi_item' && get_post_type( $post_id ) == $typenow && get_post_meta( $post_id, '_wpinv_type', true ) == 'package' ) {
28
+    if ($pagenow == 'edit.php' && $typenow == 'wpi_item' && get_post_type($post_id) == $typenow && get_post_meta($post_id, '_wpinv_type', true) == 'package') {
29 29
         $classes[] = 'wpi-gd-package';
30 30
     }
31 31
     return $classes;
32 32
 }
33
-add_filter( 'post_class', 'wpinv_post_class', 10, 3 );
33
+add_filter('post_class', 'wpinv_post_class', 10, 3);
34 34
 
35
-function wpinv_display_invoice_top_bar( $invoice ) {
36
-    if ( empty( $invoice ) ) {
35
+function wpinv_display_invoice_top_bar($invoice) {
36
+    if (empty($invoice)) {
37 37
         return;
38 38
     }
39 39
     ?>
40 40
     <div class="row wpinv-top-bar no-print">
41 41
         <div class="container">
42 42
             <div class="col-xs-6">
43
-                <?php do_action( 'wpinv_invoice_top_bar_left', $invoice );?>
43
+                <?php do_action('wpinv_invoice_top_bar_left', $invoice); ?>
44 44
             </div>
45 45
             <div class="col-xs-6 text-right">
46
-                <?php do_action( 'wpinv_invoice_top_bar_right', $invoice );?>
46
+                <?php do_action('wpinv_invoice_top_bar_right', $invoice); ?>
47 47
             </div>
48 48
         </div>
49 49
     </div>
50 50
     <?php
51 51
 }
52 52
 
53
-function wpinv_invoice_display_left_actions( $invoice ) {
54
-    if ( empty( $invoice ) ) {
53
+function wpinv_invoice_display_left_actions($invoice) {
54
+    if (empty($invoice)) {
55 55
         return;
56 56
     }
57 57
     
58
-    if($invoice->post_type == 'wpi_invoice'){
58
+    if ($invoice->post_type == 'wpi_invoice') {
59 59
     
60 60
         $user_id = (int)$invoice->get_user_id();
61 61
         $current_user_id = (int)get_current_user_id();
62 62
 
63
-        if ( $user_id > 0 && $user_id == $current_user_id && $invoice->needs_payment() ) {
63
+        if ($user_id > 0 && $user_id == $current_user_id && $invoice->needs_payment()) {
64 64
             ?> 
65
-            <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>
65
+            <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>
66 66
             <?php
67 67
         }
68 68
     }
69 69
     do_action('wpinv_invoice_display_left_actions', $invoice);
70 70
 }
71 71
 
72
-function wpinv_invoice_display_right_actions( $invoice ) {
73
-    if ( empty( $invoice ) ) return; //Exit if invoice is not set.
72
+function wpinv_invoice_display_right_actions($invoice) {
73
+    if (empty($invoice)) return; //Exit if invoice is not set.
74 74
     
75
-    if($invoice->post_type == 'wpi_invoice'){
75
+    if ($invoice->post_type == 'wpi_invoice') {
76 76
         $user_id = (int)$invoice->get_user_id();
77 77
         $current_user_id = (int)get_current_user_id();
78 78
 
79
-        if ( $user_id > 0 && $user_id == $current_user_id ) {
79
+        if ($user_id > 0 && $user_id == $current_user_id) {
80 80
         ?>
81
-            <a class="btn btn-primary btn-sm" onclick="window.print();" href="javascript:void(0)"><?php _e( 'Print Invoice', 'invoicing' ); ?></a> &nbsp;
82
-            <a class="btn btn-warning btn-sm" href="<?php echo esc_url( wpinv_get_history_page_uri() ); ?>"><?php _e( 'Invoice History', 'invoicing' ); ?></a>
81
+            <a class="btn btn-primary btn-sm" onclick="window.print();" href="javascript:void(0)"><?php _e('Print Invoice', 'invoicing'); ?></a> &nbsp;
82
+            <a class="btn btn-warning btn-sm" href="<?php echo esc_url(wpinv_get_history_page_uri()); ?>"><?php _e('Invoice History', 'invoicing'); ?></a>
83 83
         <?php } 
84 84
     }
85 85
     do_action('wpinv_invoice_display_right_actions', $invoice);
86 86
 }
87 87
 
88
-function wpinv_before_invoice_content( $content ) {
88
+function wpinv_before_invoice_content($content) {
89 89
     global $post;
90 90
 
91
-    if ( $post && $post->post_type == 'wpi_invoice' && is_singular( 'wpi_invoice' ) && is_main_query() ) {
91
+    if ($post && $post->post_type == 'wpi_invoice' && is_singular('wpi_invoice') && is_main_query()) {
92 92
         ob_start();
93
-        do_action( 'wpinv_before_invoice_content', $post->ID );
93
+        do_action('wpinv_before_invoice_content', $post->ID);
94 94
         $content = ob_get_clean() . $content;
95 95
     }
96 96
 
97 97
     return $content;
98 98
 }
99
-add_filter( 'the_content', 'wpinv_before_invoice_content' );
99
+add_filter('the_content', 'wpinv_before_invoice_content');
100 100
 
101
-function wpinv_after_invoice_content( $content ) {
101
+function wpinv_after_invoice_content($content) {
102 102
     global $post;
103 103
 
104
-    if ( $post && $post->post_type == 'wpi_invoice' && is_singular( 'wpi_invoice' ) && is_main_query() ) {
104
+    if ($post && $post->post_type == 'wpi_invoice' && is_singular('wpi_invoice') && is_main_query()) {
105 105
         ob_start();
106
-        do_action( 'wpinv_after_invoice_content', $post->ID );
106
+        do_action('wpinv_after_invoice_content', $post->ID);
107 107
         $content .= ob_get_clean();
108 108
     }
109 109
 
110 110
     return $content;
111 111
 }
112
-add_filter( 'the_content', 'wpinv_after_invoice_content' );
112
+add_filter('the_content', 'wpinv_after_invoice_content');
113 113
 
114 114
 function wpinv_get_templates_dir() {
115 115
     return WPINV_PLUGIN_DIR . 'templates';
@@ -119,105 +119,105 @@  discard block
 block discarded – undo
119 119
     return WPINV_PLUGIN_URL . 'templates';
120 120
 }
121 121
 
122
-function wpinv_get_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) {
123
-    if ( ! empty( $args ) && is_array( $args ) ) {
124
-		extract( $args );
122
+function wpinv_get_template($template_name, $args = array(), $template_path = '', $default_path = '') {
123
+    if (!empty($args) && is_array($args)) {
124
+		extract($args);
125 125
 	}
126 126
 
127
-	$located = wpinv_locate_template( $template_name, $template_path, $default_path );
127
+	$located = wpinv_locate_template($template_name, $template_path, $default_path);
128 128
 	// Allow 3rd party plugin filter template file from their plugin.
129
-	$located = apply_filters( 'wpinv_get_template', $located, $template_name, $args, $template_path, $default_path );
129
+	$located = apply_filters('wpinv_get_template', $located, $template_name, $args, $template_path, $default_path);
130 130
 
131
-	if ( ! file_exists( $located ) ) {
132
-        _doing_it_wrong( __FUNCTION__, sprintf( '<code>%s</code> does not exist.', $located ), '2.1' );
131
+	if (!file_exists($located)) {
132
+        _doing_it_wrong(__FUNCTION__, sprintf('<code>%s</code> does not exist.', $located), '2.1');
133 133
 		return;
134 134
 	}
135 135
 
136
-	do_action( 'wpinv_before_template_part', $template_name, $template_path, $located, $args );
136
+	do_action('wpinv_before_template_part', $template_name, $template_path, $located, $args);
137 137
 
138
-	include( $located );
138
+	include($located);
139 139
 
140
-	do_action( 'wpinv_after_template_part', $template_name, $template_path, $located, $args );
140
+	do_action('wpinv_after_template_part', $template_name, $template_path, $located, $args);
141 141
 }
142 142
 
143
-function wpinv_get_template_html( $template_name, $args = array(), $template_path = '', $default_path = '' ) {
143
+function wpinv_get_template_html($template_name, $args = array(), $template_path = '', $default_path = '') {
144 144
 	ob_start();
145
-	wpinv_get_template( $template_name, $args, $template_path, $default_path );
145
+	wpinv_get_template($template_name, $args, $template_path, $default_path);
146 146
 	return ob_get_clean();
147 147
 }
148 148
 
149
-function wpinv_locate_template( $template_name, $template_path = '', $default_path = '' ) {
150
-    if ( ! $template_path ) {
149
+function wpinv_locate_template($template_name, $template_path = '', $default_path = '') {
150
+    if (!$template_path) {
151 151
         $template_path = wpinv_template_path();
152 152
     }
153 153
 
154
-    if ( ! $default_path ) {
154
+    if (!$default_path) {
155 155
         $default_path = WPINV_PLUGIN_DIR . 'templates/';
156 156
     }
157 157
 
158 158
     // Look within passed path within the theme - this is priority.
159 159
     $template = locate_template(
160 160
         array(
161
-            trailingslashit( $template_path ) . $template_name,
161
+            trailingslashit($template_path) . $template_name,
162 162
             $template_name
163 163
         )
164 164
     );
165 165
 
166 166
     // Get default templates/
167
-    if ( !$template && $default_path ) {
168
-        $template = trailingslashit( $default_path ) . $template_name;
167
+    if (!$template && $default_path) {
168
+        $template = trailingslashit($default_path) . $template_name;
169 169
     }
170 170
 
171 171
     // Return what we found.
172
-    return apply_filters( 'wpinv_locate_template', $template, $template_name, $template_path );
172
+    return apply_filters('wpinv_locate_template', $template, $template_name, $template_path);
173 173
 }
174 174
 
175
-function wpinv_get_template_part( $slug, $name = null, $load = true ) {
176
-	do_action( 'get_template_part_' . $slug, $slug, $name );
175
+function wpinv_get_template_part($slug, $name = null, $load = true) {
176
+	do_action('get_template_part_' . $slug, $slug, $name);
177 177
 
178 178
 	// Setup possible parts
179 179
 	$templates = array();
180
-	if ( isset( $name ) )
180
+	if (isset($name))
181 181
 		$templates[] = $slug . '-' . $name . '.php';
182 182
 	$templates[] = $slug . '.php';
183 183
 
184 184
 	// Allow template parts to be filtered
185
-	$templates = apply_filters( 'wpinv_get_template_part', $templates, $slug, $name );
185
+	$templates = apply_filters('wpinv_get_template_part', $templates, $slug, $name);
186 186
 
187 187
 	// Return the part that is found
188
-	return wpinv_locate_tmpl( $templates, $load, false );
188
+	return wpinv_locate_tmpl($templates, $load, false);
189 189
 }
190 190
 
191
-function wpinv_locate_tmpl( $template_names, $load = false, $require_once = true ) {
191
+function wpinv_locate_tmpl($template_names, $load = false, $require_once = true) {
192 192
 	// No file found yet
193 193
 	$located = false;
194 194
 
195 195
 	// Try to find a template file
196
-	foreach ( (array)$template_names as $template_name ) {
196
+	foreach ((array)$template_names as $template_name) {
197 197
 
198 198
 		// Continue if template is empty
199
-		if ( empty( $template_name ) )
199
+		if (empty($template_name))
200 200
 			continue;
201 201
 
202 202
 		// Trim off any slashes from the template name
203
-		$template_name = ltrim( $template_name, '/' );
203
+		$template_name = ltrim($template_name, '/');
204 204
 
205 205
 		// try locating this template file by looping through the template paths
206
-		foreach( wpinv_get_theme_template_paths() as $template_path ) {
206
+		foreach (wpinv_get_theme_template_paths() as $template_path) {
207 207
 
208
-			if( file_exists( $template_path . $template_name ) ) {
208
+			if (file_exists($template_path . $template_name)) {
209 209
 				$located = $template_path . $template_name;
210 210
 				break;
211 211
 			}
212 212
 		}
213 213
 
214
-		if( !empty( $located ) ) {
214
+		if (!empty($located)) {
215 215
 			break;
216 216
 		}
217 217
 	}
218 218
 
219
-	if ( ( true == $load ) && ! empty( $located ) )
220
-		load_template( $located, $require_once );
219
+	if ((true == $load) && !empty($located))
220
+		load_template($located, $require_once);
221 221
 
222 222
 	return $located;
223 223
 }
@@ -226,143 +226,143 @@  discard block
 block discarded – undo
226 226
 	$template_dir = wpinv_get_theme_template_dir_name();
227 227
 
228 228
 	$file_paths = array(
229
-		1 => trailingslashit( get_stylesheet_directory() ) . $template_dir,
230
-		10 => trailingslashit( get_template_directory() ) . $template_dir,
229
+		1 => trailingslashit(get_stylesheet_directory()) . $template_dir,
230
+		10 => trailingslashit(get_template_directory()) . $template_dir,
231 231
 		100 => wpinv_get_templates_dir()
232 232
 	);
233 233
 
234
-	$file_paths = apply_filters( 'wpinv_template_paths', $file_paths );
234
+	$file_paths = apply_filters('wpinv_template_paths', $file_paths);
235 235
 
236 236
 	// sort the file paths based on priority
237
-	ksort( $file_paths, SORT_NUMERIC );
237
+	ksort($file_paths, SORT_NUMERIC);
238 238
 
239
-	return array_map( 'trailingslashit', $file_paths );
239
+	return array_map('trailingslashit', $file_paths);
240 240
 }
241 241
 
242 242
 function wpinv_get_theme_template_dir_name() {
243
-	return trailingslashit( apply_filters( 'wpinv_templates_dir', 'wpinv_templates' ) );
243
+	return trailingslashit(apply_filters('wpinv_templates_dir', 'wpinv_templates'));
244 244
 }
245 245
 
246 246
 function wpinv_checkout_meta_tags() {
247 247
 
248 248
 	$pages   = array();
249
-	$pages[] = wpinv_get_option( 'success_page' );
250
-	$pages[] = wpinv_get_option( 'failure_page' );
251
-	$pages[] = wpinv_get_option( 'invoice_history_page' );
249
+	$pages[] = wpinv_get_option('success_page');
250
+	$pages[] = wpinv_get_option('failure_page');
251
+	$pages[] = wpinv_get_option('invoice_history_page');
252 252
 
253
-	if( !wpinv_is_checkout() && !is_page( $pages ) ) {
253
+	if (!wpinv_is_checkout() && !is_page($pages)) {
254 254
 		return;
255 255
 	}
256 256
 
257 257
 	echo '<meta name="robots" content="noindex,nofollow" />' . "\n";
258 258
 }
259
-add_action( 'wp_head', 'wpinv_checkout_meta_tags' );
259
+add_action('wp_head', 'wpinv_checkout_meta_tags');
260 260
 
261
-function wpinv_add_body_classes( $class ) {
261
+function wpinv_add_body_classes($class) {
262 262
 	$classes = (array)$class;
263 263
 
264
-	if( wpinv_is_checkout() ) {
264
+	if (wpinv_is_checkout()) {
265 265
 		$classes[] = 'wpinv-checkout';
266 266
 		$classes[] = 'wpinv-page';
267 267
 	}
268 268
 
269
-	if( wpinv_is_success_page() ) {
269
+	if (wpinv_is_success_page()) {
270 270
 		$classes[] = 'wpinv-success';
271 271
 		$classes[] = 'wpinv-page';
272 272
 	}
273 273
 
274
-	if( wpinv_is_failed_transaction_page() ) {
274
+	if (wpinv_is_failed_transaction_page()) {
275 275
 		$classes[] = 'wpinv-failed-transaction';
276 276
 		$classes[] = 'wpinv-page';
277 277
 	}
278 278
 
279
-	if( wpinv_is_invoice_history_page() ) {
279
+	if (wpinv_is_invoice_history_page()) {
280 280
 		$classes[] = 'wpinv-history';
281 281
 		$classes[] = 'wpinv-page';
282 282
 	}
283 283
 
284
-	if( wpinv_is_test_mode() ) {
284
+	if (wpinv_is_test_mode()) {
285 285
 		$classes[] = 'wpinv-test-mode';
286 286
 		$classes[] = 'wpinv-page';
287 287
 	}
288 288
 
289
-	return array_unique( $classes );
289
+	return array_unique($classes);
290 290
 }
291
-add_filter( 'body_class', 'wpinv_add_body_classes' );
291
+add_filter('body_class', 'wpinv_add_body_classes');
292 292
 
293
-function wpinv_html_dropdown( $name = 'wpinv_discounts', $selected = 0, $status = '' ) {
294
-    $args = array( 'nopaging' => true );
293
+function wpinv_html_dropdown($name = 'wpinv_discounts', $selected = 0, $status = '') {
294
+    $args = array('nopaging' => true);
295 295
 
296
-    if ( ! empty( $status ) )
296
+    if (!empty($status))
297 297
         $args['post_status'] = $status;
298 298
 
299
-    $discounts = wpinv_get_discounts( $args );
299
+    $discounts = wpinv_get_discounts($args);
300 300
     $options   = array();
301 301
 
302
-    if ( $discounts ) {
303
-        foreach ( $discounts as $discount ) {
304
-            $options[ absint( $discount->ID ) ] = esc_html( get_the_title( $discount->ID ) );
302
+    if ($discounts) {
303
+        foreach ($discounts as $discount) {
304
+            $options[absint($discount->ID)] = esc_html(get_the_title($discount->ID));
305 305
         }
306 306
     } else {
307
-        $options[0] = __( 'No discounts found', 'invoicing' );
307
+        $options[0] = __('No discounts found', 'invoicing');
308 308
     }
309 309
 
310
-    $output = wpinv_html_select( array(
310
+    $output = wpinv_html_select(array(
311 311
         'name'             => $name,
312 312
         'selected'         => $selected,
313 313
         'options'          => $options,
314 314
         'show_option_all'  => false,
315 315
         'show_option_none' => false,
316
-    ) );
316
+    ));
317 317
 
318 318
     return $output;
319 319
 }
320 320
 
321
-function wpinv_html_year_dropdown( $name = 'year', $selected = 0, $years_before = 5, $years_after = 0 ) {
322
-    $current     = date( 'Y' );
323
-    $start_year  = $current - absint( $years_before );
324
-    $end_year    = $current + absint( $years_after );
325
-    $selected    = empty( $selected ) ? date( 'Y' ) : $selected;
321
+function wpinv_html_year_dropdown($name = 'year', $selected = 0, $years_before = 5, $years_after = 0) {
322
+    $current     = date('Y');
323
+    $start_year  = $current - absint($years_before);
324
+    $end_year    = $current + absint($years_after);
325
+    $selected    = empty($selected) ? date('Y') : $selected;
326 326
     $options     = array();
327 327
 
328
-    while ( $start_year <= $end_year ) {
329
-        $options[ absint( $start_year ) ] = $start_year;
328
+    while ($start_year <= $end_year) {
329
+        $options[absint($start_year)] = $start_year;
330 330
         $start_year++;
331 331
     }
332 332
 
333
-    $output = wpinv_html_select( array(
333
+    $output = wpinv_html_select(array(
334 334
         'name'             => $name,
335 335
         'selected'         => $selected,
336 336
         'options'          => $options,
337 337
         'show_option_all'  => false,
338 338
         'show_option_none' => false
339
-    ) );
339
+    ));
340 340
 
341 341
     return $output;
342 342
 }
343 343
 
344
-function wpinv_html_month_dropdown( $name = 'month', $selected = 0 ) {
344
+function wpinv_html_month_dropdown($name = 'month', $selected = 0) {
345 345
     $month   = 1;
346 346
     $options = array();
347
-    $selected = empty( $selected ) ? date( 'n' ) : $selected;
347
+    $selected = empty($selected) ? date('n') : $selected;
348 348
 
349
-    while ( $month <= 12 ) {
350
-        $options[ absint( $month ) ] = wpinv_month_num_to_name( $month );
349
+    while ($month <= 12) {
350
+        $options[absint($month)] = wpinv_month_num_to_name($month);
351 351
         $month++;
352 352
     }
353 353
 
354
-    $output = wpinv_html_select( array(
354
+    $output = wpinv_html_select(array(
355 355
         'name'             => $name,
356 356
         'selected'         => $selected,
357 357
         'options'          => $options,
358 358
         'show_option_all'  => false,
359 359
         'show_option_none' => false
360
-    ) );
360
+    ));
361 361
 
362 362
     return $output;
363 363
 }
364 364
 
365
-function wpinv_html_select( $args = array() ) {
365
+function wpinv_html_select($args = array()) {
366 366
     $defaults = array(
367 367
         'options'          => array(),
368 368
         'name'             => null,
@@ -372,8 +372,8 @@  discard block
 block discarded – undo
372 372
         'chosen'           => false,
373 373
         'placeholder'      => null,
374 374
         'multiple'         => false,
375
-        'show_option_all'  => _x( 'All', 'all dropdown items', 'invoicing' ),
376
-        'show_option_none' => _x( 'None', 'no dropdown items', 'invoicing' ),
375
+        'show_option_all'  => _x('All', 'all dropdown items', 'invoicing'),
376
+        'show_option_none' => _x('None', 'no dropdown items', 'invoicing'),
377 377
         'data'             => array(),
378 378
         'onchange'         => null,
379 379
         'required'         => false,
@@ -381,78 +381,78 @@  discard block
 block discarded – undo
381 381
         'readonly'         => false,
382 382
     );
383 383
 
384
-    $args = wp_parse_args( $args, $defaults );
384
+    $args = wp_parse_args($args, $defaults);
385 385
 
386 386
     $data_elements = '';
387
-    foreach ( $args['data'] as $key => $value ) {
388
-        $data_elements .= ' data-' . esc_attr( $key ) . '="' . esc_attr( $value ) . '"';
387
+    foreach ($args['data'] as $key => $value) {
388
+        $data_elements .= ' data-' . esc_attr($key) . '="' . esc_attr($value) . '"';
389 389
     }
390 390
 
391
-    if( $args['multiple'] ) {
391
+    if ($args['multiple']) {
392 392
         $multiple = ' MULTIPLE';
393 393
     } else {
394 394
         $multiple = '';
395 395
     }
396 396
 
397
-    if( $args['chosen'] ) {
397
+    if ($args['chosen']) {
398 398
         $args['class'] .= ' wpinv-select-chosen';
399 399
     }
400 400
 
401
-    if( $args['placeholder'] ) {
401
+    if ($args['placeholder']) {
402 402
         $placeholder = $args['placeholder'];
403 403
     } else {
404 404
         $placeholder = '';
405 405
     }
406 406
     
407 407
     $options = '';
408
-    if( !empty( $args['onchange'] ) ) {
409
-        $options .= ' onchange="' . esc_attr( $args['onchange'] ) . '"';
408
+    if (!empty($args['onchange'])) {
409
+        $options .= ' onchange="' . esc_attr($args['onchange']) . '"';
410 410
     }
411 411
     
412
-    if( !empty( $args['required'] ) ) {
412
+    if (!empty($args['required'])) {
413 413
         $options .= ' required="required"';
414 414
     }
415 415
     
416
-    if( !empty( $args['disabled'] ) ) {
416
+    if (!empty($args['disabled'])) {
417 417
         $options .= ' disabled';
418 418
     }
419 419
     
420
-    if( !empty( $args['readonly'] ) ) {
420
+    if (!empty($args['readonly'])) {
421 421
         $options .= ' readonly';
422 422
     }
423 423
 
424
-    $class  = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) );
425
-    $output = '<select name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['id'] ) . '" class="wpinv-select ' . $class . '"' . $multiple . ' data-placeholder="' . $placeholder . '" ' . trim( $options ) . $data_elements . '>';
424
+    $class  = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class'])));
425
+    $output = '<select name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['id']) . '" class="wpinv-select ' . $class . '"' . $multiple . ' data-placeholder="' . $placeholder . '" ' . trim($options) . $data_elements . '>';
426 426
 
427
-    if ( $args['show_option_all'] ) {
428
-        if( $args['multiple'] ) {
429
-            $selected = selected( true, in_array( 0, $args['selected'] ), false );
427
+    if ($args['show_option_all']) {
428
+        if ($args['multiple']) {
429
+            $selected = selected(true, in_array(0, $args['selected']), false);
430 430
         } else {
431
-            $selected = selected( $args['selected'], 0, false );
431
+            $selected = selected($args['selected'], 0, false);
432 432
         }
433
-        $output .= '<option value="all"' . $selected . '>' . esc_html( $args['show_option_all'] ) . '</option>';
433
+        $output .= '<option value="all"' . $selected . '>' . esc_html($args['show_option_all']) . '</option>';
434 434
     }
435 435
 
436
-    if ( !empty( $args['options'] ) ) {
436
+    if (!empty($args['options'])) {
437 437
 
438
-        if ( $args['show_option_none'] ) {
439
-            if( $args['multiple'] ) {
440
-                $selected = selected( true, in_array( "", $args['selected'] ), false );
438
+        if ($args['show_option_none']) {
439
+            if ($args['multiple']) {
440
+                $selected = selected(true, in_array("", $args['selected']), false);
441 441
             } else {
442
-                $selected = selected( $args['selected'] === "", true, false );
442
+                $selected = selected($args['selected'] === "", true, false);
443 443
             }
444
-            $output .= '<option value=""' . $selected . '>' . esc_html( $args['show_option_none'] ) . '</option>';
444
+            $output .= '<option value=""' . $selected . '>' . esc_html($args['show_option_none']) . '</option>';
445 445
         }
446 446
 
447
-        foreach( $args['options'] as $key => $option ) {
447
+        foreach ($args['options'] as $key => $option) {
448 448
 
449
-            if( $args['multiple'] && is_array( $args['selected'] ) ) {
450
-                $selected = selected( true, (bool)in_array( $key, $args['selected'] ), false );
449
+            if ($args['multiple'] && is_array($args['selected'])) {
450
+                $selected = selected(true, (bool)in_array($key, $args['selected']), false);
451 451
             } else {
452
-                $selected = selected( $args['selected'], $key, false );
452
+                $selected = selected($args['selected'], $key, false);
453 453
             }
454 454
 
455
-            $output .= '<option value="' . esc_attr( $key ) . '"' . $selected . '>' . esc_html( $option ) . '</option>';
455
+            $output .= '<option value="' . esc_attr($key) . '"' . $selected . '>' . esc_html($option) . '</option>';
456 456
         }
457 457
     }
458 458
 
@@ -461,7 +461,7 @@  discard block
 block discarded – undo
461 461
     return $output;
462 462
 }
463 463
 
464
-function wpinv_item_dropdown( $args = array() ) {
464
+function wpinv_item_dropdown($args = array()) {
465 465
     $defaults = array(
466 466
         'name'              => 'wpi_item',
467 467
         'id'                => 'wpi_item',
@@ -470,15 +470,15 @@  discard block
 block discarded – undo
470 470
         'selected'          => 0,
471 471
         'chosen'            => false,
472 472
         'number'            => 100,
473
-        'placeholder'       => __( 'Choose a item', 'invoicing' ),
474
-        'data'              => array( 'search-type' => 'item' ),
473
+        'placeholder'       => __('Choose a item', 'invoicing'),
474
+        'data'              => array('search-type' => 'item'),
475 475
         'show_option_all'   => false,
476 476
         'show_option_none'  => false,
477 477
         'with_packages'     => true,
478 478
         'show_recurring'    => false,
479 479
     );
480 480
 
481
-    $args = wp_parse_args( $args, $defaults );
481
+    $args = wp_parse_args($args, $defaults);
482 482
 
483 483
     $item_args = array(
484 484
         'post_type'      => 'wpi_item',
@@ -487,7 +487,7 @@  discard block
 block discarded – undo
487 487
         'posts_per_page' => $args['number']
488 488
     );
489 489
     
490
-    if ( !$args['with_packages'] ) {
490
+    if (!$args['with_packages']) {
491 491
         $item_args['meta_query'] = array(
492 492
             array(
493 493
                 'key'       => '_wpinv_type',
@@ -497,42 +497,42 @@  discard block
 block discarded – undo
497 497
         );
498 498
     }
499 499
 
500
-    $items      = get_posts( $item_args );
500
+    $items      = get_posts($item_args);
501 501
     $options    = array();
502
-    if ( $items ) {
503
-        foreach ( $items as $item ) {
504
-            $title = esc_html( $item->post_title );
502
+    if ($items) {
503
+        foreach ($items as $item) {
504
+            $title = esc_html($item->post_title);
505 505
             
506
-            if ( !empty( $args['show_recurring'] ) ) {
507
-                $title .= wpinv_get_item_suffix( $item->ID, false );
506
+            if (!empty($args['show_recurring'])) {
507
+                $title .= wpinv_get_item_suffix($item->ID, false);
508 508
             }
509 509
             
510
-            $options[ absint( $item->ID ) ] = $title;
510
+            $options[absint($item->ID)] = $title;
511 511
         }
512 512
     }
513 513
 
514 514
     // This ensures that any selected items are included in the drop down
515
-    if( is_array( $args['selected'] ) ) {
516
-        foreach( $args['selected'] as $item ) {
517
-            if( ! in_array( $item, $options ) ) {
518
-                $title = get_the_title( $item );
519
-                if ( !empty( $args['show_recurring'] ) ) {
520
-                    $title .= wpinv_get_item_suffix( $item, false );
515
+    if (is_array($args['selected'])) {
516
+        foreach ($args['selected'] as $item) {
517
+            if (!in_array($item, $options)) {
518
+                $title = get_the_title($item);
519
+                if (!empty($args['show_recurring'])) {
520
+                    $title .= wpinv_get_item_suffix($item, false);
521 521
                 }
522 522
                 $options[$item] = $title;
523 523
             }
524 524
         }
525
-    } elseif ( is_numeric( $args['selected'] ) && $args['selected'] !== 0 ) {
526
-        if ( ! in_array( $args['selected'], $options ) ) {
527
-            $title = get_the_title( $args['selected'] );
528
-            if ( !empty( $args['show_recurring'] ) ) {
529
-                $title .= wpinv_get_item_suffix( $args['selected'], false );
525
+    } elseif (is_numeric($args['selected']) && $args['selected'] !== 0) {
526
+        if (!in_array($args['selected'], $options)) {
527
+            $title = get_the_title($args['selected']);
528
+            if (!empty($args['show_recurring'])) {
529
+                $title .= wpinv_get_item_suffix($args['selected'], false);
530 530
             }
531
-            $options[$args['selected']] = get_the_title( $args['selected'] );
531
+            $options[$args['selected']] = get_the_title($args['selected']);
532 532
         }
533 533
     }
534 534
 
535
-    $output = wpinv_html_select( array(
535
+    $output = wpinv_html_select(array(
536 536
         'name'             => $args['name'],
537 537
         'selected'         => $args['selected'],
538 538
         'id'               => $args['id'],
@@ -544,12 +544,12 @@  discard block
 block discarded – undo
544 544
         'show_option_all'  => $args['show_option_all'],
545 545
         'show_option_none' => $args['show_option_none'],
546 546
         'data'             => $args['data'],
547
-    ) );
547
+    ));
548 548
 
549 549
     return $output;
550 550
 }
551 551
 
552
-function wpinv_html_checkbox( $args = array() ) {
552
+function wpinv_html_checkbox($args = array()) {
553 553
     $defaults = array(
554 554
         'name'     => null,
555 555
         'current'  => null,
@@ -560,38 +560,38 @@  discard block
 block discarded – undo
560 560
         )
561 561
     );
562 562
 
563
-    $args = wp_parse_args( $args, $defaults );
563
+    $args = wp_parse_args($args, $defaults);
564 564
 
565
-    $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) );
565
+    $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class'])));
566 566
     $options = '';
567
-    if ( ! empty( $args['options']['disabled'] ) ) {
567
+    if (!empty($args['options']['disabled'])) {
568 568
         $options .= ' disabled="disabled"';
569
-    } elseif ( ! empty( $args['options']['readonly'] ) ) {
569
+    } elseif (!empty($args['options']['readonly'])) {
570 570
         $options .= ' readonly';
571 571
     }
572 572
 
573
-    $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 ) . ' />';
573
+    $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) . ' />';
574 574
 
575 575
     return $output;
576 576
 }
577 577
 
578
-function wpinv_html_text( $args = array() ) {
578
+function wpinv_html_text($args = array()) {
579 579
     // Backwards compatibility
580
-    if ( func_num_args() > 1 ) {
580
+    if (func_num_args() > 1) {
581 581
         $args = func_get_args();
582 582
 
583 583
         $name  = $args[0];
584
-        $value = isset( $args[1] ) ? $args[1] : '';
585
-        $label = isset( $args[2] ) ? $args[2] : '';
586
-        $desc  = isset( $args[3] ) ? $args[3] : '';
584
+        $value = isset($args[1]) ? $args[1] : '';
585
+        $label = isset($args[2]) ? $args[2] : '';
586
+        $desc  = isset($args[3]) ? $args[3] : '';
587 587
     }
588 588
 
589 589
     $defaults = array(
590 590
         'id'           => '',
591
-        'name'         => isset( $name )  ? $name  : 'text',
592
-        'value'        => isset( $value ) ? $value : null,
593
-        'label'        => isset( $label ) ? $label : null,
594
-        'desc'         => isset( $desc )  ? $desc  : null,
591
+        'name'         => isset($name) ? $name : 'text',
592
+        'value'        => isset($value) ? $value : null,
593
+        'label'        => isset($label) ? $label : null,
594
+        'desc'         => isset($desc) ? $desc : null,
595 595
         'placeholder'  => '',
596 596
         'class'        => 'regular-text',
597 597
         'disabled'     => false,
@@ -601,51 +601,51 @@  discard block
 block discarded – undo
601 601
         'data'         => false
602 602
     );
603 603
 
604
-    $args = wp_parse_args( $args, $defaults );
604
+    $args = wp_parse_args($args, $defaults);
605 605
 
606
-    $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) );
606
+    $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class'])));
607 607
     $options = '';
608
-    if( $args['required'] ) {
608
+    if ($args['required']) {
609 609
         $options .= ' required="required"';
610 610
     }
611
-    if( $args['readonly'] ) {
611
+    if ($args['readonly']) {
612 612
         $options .= ' readonly';
613 613
     }
614
-    if( $args['readonly'] ) {
614
+    if ($args['readonly']) {
615 615
         $options .= ' readonly';
616 616
     }
617 617
 
618 618
     $data = '';
619
-    if ( !empty( $args['data'] ) ) {
620
-        foreach ( $args['data'] as $key => $value ) {
621
-            $data .= 'data-' . wpinv_sanitize_key( $key ) . '="' . esc_attr( $value ) . '" ';
619
+    if (!empty($args['data'])) {
620
+        foreach ($args['data'] as $key => $value) {
621
+            $data .= 'data-' . wpinv_sanitize_key($key) . '="' . esc_attr($value) . '" ';
622 622
         }
623 623
     }
624 624
 
625
-    $output = '<span id="wpinv-' . wpinv_sanitize_key( $args['name'] ) . '-wrap">';
626
-    $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key( $args['id'] ) . '">' . esc_html( $args['label'] ) . '</label>';
627
-    if ( ! empty( $args['desc'] ) ) {
628
-        $output .= '<span class="wpinv-description">' . esc_html( $args['desc'] ) . '</span>';
625
+    $output = '<span id="wpinv-' . wpinv_sanitize_key($args['name']) . '-wrap">';
626
+    $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key($args['id']) . '">' . esc_html($args['label']) . '</label>';
627
+    if (!empty($args['desc'])) {
628
+        $output .= '<span class="wpinv-description">' . esc_html($args['desc']) . '</span>';
629 629
     }
630 630
 
631
-    $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 ) . '/>';
631
+    $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) . '/>';
632 632
 
633 633
     $output .= '</span>';
634 634
 
635 635
     return $output;
636 636
 }
637 637
 
638
-function wpinv_html_date_field( $args = array() ) {
639
-    if( empty( $args['class'] ) ) {
638
+function wpinv_html_date_field($args = array()) {
639
+    if (empty($args['class'])) {
640 640
         $args['class'] = 'wpiDatepicker';
641
-    } elseif( ! strpos( $args['class'], 'wpiDatepicker' ) ) {
641
+    } elseif (!strpos($args['class'], 'wpiDatepicker')) {
642 642
         $args['class'] .= ' wpiDatepicker';
643 643
     }
644 644
 
645
-    return wpinv_html_text( $args );
645
+    return wpinv_html_text($args);
646 646
 }
647 647
 
648
-function wpinv_html_textarea( $args = array() ) {
648
+function wpinv_html_textarea($args = array()) {
649 649
     $defaults = array(
650 650
         'name'        => 'textarea',
651 651
         'value'       => null,
@@ -655,31 +655,31 @@  discard block
 block discarded – undo
655 655
         'disabled'    => false
656 656
     );
657 657
 
658
-    $args = wp_parse_args( $args, $defaults );
658
+    $args = wp_parse_args($args, $defaults);
659 659
 
660
-    $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) );
660
+    $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class'])));
661 661
     $disabled = '';
662
-    if( $args['disabled'] ) {
662
+    if ($args['disabled']) {
663 663
         $disabled = ' disabled="disabled"';
664 664
     }
665 665
 
666
-    $output = '<span id="wpinv-' . wpinv_sanitize_key( $args['name'] ) . '-wrap">';
667
-    $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key( $args['name'] ) . '">' . esc_html( $args['label'] ) . '</label>';
668
-    $output .= '<textarea name="' . esc_attr( $args['name'] ) . '" id="' . wpinv_sanitize_key( $args['name'] ) . '" class="' . $class . '"' . $disabled . '>' . esc_attr( $args['value'] ) . '</textarea>';
666
+    $output = '<span id="wpinv-' . wpinv_sanitize_key($args['name']) . '-wrap">';
667
+    $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key($args['name']) . '">' . esc_html($args['label']) . '</label>';
668
+    $output .= '<textarea name="' . esc_attr($args['name']) . '" id="' . wpinv_sanitize_key($args['name']) . '" class="' . $class . '"' . $disabled . '>' . esc_attr($args['value']) . '</textarea>';
669 669
 
670
-    if ( ! empty( $args['desc'] ) ) {
671
-        $output .= '<span class="wpinv-description">' . esc_html( $args['desc'] ) . '</span>';
670
+    if (!empty($args['desc'])) {
671
+        $output .= '<span class="wpinv-description">' . esc_html($args['desc']) . '</span>';
672 672
     }
673 673
     $output .= '</span>';
674 674
 
675 675
     return $output;
676 676
 }
677 677
 
678
-function wpinv_html_ajax_user_search( $args = array() ) {
678
+function wpinv_html_ajax_user_search($args = array()) {
679 679
     $defaults = array(
680 680
         'name'        => 'user_id',
681 681
         'value'       => null,
682
-        'placeholder' => __( 'Enter username', 'invoicing' ),
682
+        'placeholder' => __('Enter username', 'invoicing'),
683 683
         'label'       => null,
684 684
         'desc'        => null,
685 685
         'class'       => '',
@@ -688,13 +688,13 @@  discard block
 block discarded – undo
688 688
         'data'        => false
689 689
     );
690 690
 
691
-    $args = wp_parse_args( $args, $defaults );
691
+    $args = wp_parse_args($args, $defaults);
692 692
 
693 693
     $args['class'] = 'wpinv-ajax-user-search ' . $args['class'];
694 694
 
695 695
     $output  = '<span class="wpinv_user_search_wrap">';
696
-        $output .= wpinv_html_text( $args );
697
-        $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>';
696
+        $output .= wpinv_html_text($args);
697
+        $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>';
698 698
     $output .= '</span>';
699 699
 
700 700
     return $output;
@@ -703,7 +703,7 @@  discard block
 block discarded – undo
703 703
 function wpinv_ip_geolocation() {
704 704
     global $wpinv_euvat;
705 705
     
706
-    $ip         = !empty( $_GET['ip'] ) ? sanitize_text_field( $_GET['ip'] ) : '';    
706
+    $ip         = !empty($_GET['ip']) ? sanitize_text_field($_GET['ip']) : '';    
707 707
     $content    = '';
708 708
     $iso        = '';
709 709
     $country    = '';
@@ -714,69 +714,69 @@  discard block
 block discarded – undo
714 714
     $credit     = '';
715 715
     $address    = '';
716 716
     
717
-    if ( wpinv_get_option( 'vat_ip_lookup' ) == 'geoip2' && $geoip2_city = $wpinv_euvat->geoip2_city_record( $ip ) ) {
717
+    if (wpinv_get_option('vat_ip_lookup') == 'geoip2' && $geoip2_city = $wpinv_euvat->geoip2_city_record($ip)) {
718 718
         try {
719 719
             $iso        = $geoip2_city->country->isoCode;
720 720
             $country    = $geoip2_city->country->name;
721
-            $region     = !empty( $geoip2_city->subdivisions ) && !empty( $geoip2_city->subdivisions[0]->name ) ? $geoip2_city->subdivisions[0]->name : '';
721
+            $region     = !empty($geoip2_city->subdivisions) && !empty($geoip2_city->subdivisions[0]->name) ? $geoip2_city->subdivisions[0]->name : '';
722 722
             $city       = $geoip2_city->city->name;
723 723
             $longitude  = $geoip2_city->location->longitude;
724 724
             $latitude   = $geoip2_city->location->latitude;
725
-            $credit     = __( 'Geolocated using the information by MaxMind, available from <a href="http://www.maxmind.com" target="_blank">www.maxmind.com</a>', 'invoicing' );
726
-        } catch( Exception $e ) { }
725
+            $credit     = __('Geolocated using the information by MaxMind, available from <a href="http://www.maxmind.com" target="_blank">www.maxmind.com</a>', 'invoicing');
726
+        } catch (Exception $e) { }
727 727
     }
728 728
     
729
-    if ( !( $iso && $longitude && $latitude ) && function_exists( 'simplexml_load_file' ) ) {
729
+    if (!($iso && $longitude && $latitude) && function_exists('simplexml_load_file')) {
730 730
         try {
731
-            $load_xml = simplexml_load_file( 'http://www.geoplugin.net/xml.gp?ip=' . $ip );
731
+            $load_xml = simplexml_load_file('http://www.geoplugin.net/xml.gp?ip=' . $ip);
732 732
             
733
-            if ( !empty( $load_xml ) && isset( $load_xml->geoplugin_countryCode ) && !empty( $load_xml->geoplugin_latitude ) && !empty( $load_xml->geoplugin_longitude ) ) {
733
+            if (!empty($load_xml) && isset($load_xml->geoplugin_countryCode) && !empty($load_xml->geoplugin_latitude) && !empty($load_xml->geoplugin_longitude)) {
734 734
                 $iso        = $load_xml->geoplugin_countryCode;
735 735
                 $country    = $load_xml->geoplugin_countryName;
736
-                $region     = !empty( $load_xml->geoplugin_regionName ) ? $load_xml->geoplugin_regionName : '';
737
-                $city       = !empty( $load_xml->geoplugin_city ) ? $load_xml->geoplugin_city : '';
736
+                $region     = !empty($load_xml->geoplugin_regionName) ? $load_xml->geoplugin_regionName : '';
737
+                $city       = !empty($load_xml->geoplugin_city) ? $load_xml->geoplugin_city : '';
738 738
                 $longitude  = $load_xml->geoplugin_longitude;
739 739
                 $latitude   = $load_xml->geoplugin_latitude;
740 740
                 $credit     = $load_xml->geoplugin_credit;
741
-                $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;
741
+                $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;
742 742
             }
743
-        } catch( Exception $e ) { }
743
+        } catch (Exception $e) { }
744 744
     }
745 745
     
746
-    if ( $iso && $longitude && $latitude ) {
747
-        if ( $city ) {
746
+    if ($iso && $longitude && $latitude) {
747
+        if ($city) {
748 748
             $address .= $city . ', ';
749 749
         }
750 750
         
751
-        if ( $region ) {
751
+        if ($region) {
752 752
             $address .= $region . ', ';
753 753
         }
754 754
         
755 755
         $address .= $country . ' (' . $iso . ')';
756
-        $content = '<p>'. sprintf( __( '<b>Address:</b> %s', 'invoicing' ), $address ) . '</p>';
757
-        $content .= '<p>'. $credit . '</p>';
756
+        $content = '<p>' . sprintf(__('<b>Address:</b> %s', 'invoicing'), $address) . '</p>';
757
+        $content .= '<p>' . $credit . '</p>';
758 758
     } else {
759
-        $content = '<p>'. sprintf( __( 'Unable to find geolocation for the IP address: %s', 'invoicing' ), $ip ) . '</p>';
759
+        $content = '<p>' . sprintf(__('Unable to find geolocation for the IP address: %s', 'invoicing'), $ip) . '</p>';
760 760
     }
761 761
     ?>
762 762
 <!DOCTYPE html>
763
-<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>
763
+<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>
764 764
 <body>
765
-    <?php if ( $latitude && $latitude ) { ?>
765
+    <?php if ($latitude && $latitude) { ?>
766 766
     <div id="map"></div>
767 767
         <script src="//cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.0-rc.1/leaflet.js"></script>
768 768
         <script type="text/javascript">
769 769
         var osmUrl = 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
770 770
             osmAttrib = '&copy; <a href="http://openstreetmap.org/copyright">OpenStreetMap</a> contributors',
771 771
             osm = L.tileLayer(osmUrl, {maxZoom: 18, attribution: osmAttrib}),
772
-            latlng = new L.LatLng(<?php echo $latitude;?>, <?php echo $longitude;?>);
772
+            latlng = new L.LatLng(<?php echo $latitude; ?>, <?php echo $longitude; ?>);
773 773
 
774 774
         var map = new L.Map('map', {center: latlng, zoom: 12, layers: [osm]});
775 775
 
776 776
         var marker = new L.Marker(latlng);
777 777
         map.addLayer(marker);
778 778
 
779
-        marker.bindPopup("<p><?php esc_attr_e( $address );?></p>");
779
+        marker.bindPopup("<p><?php esc_attr_e($address); ?></p>");
780 780
     </script>
781 781
     <?php } ?>
782 782
     <div style="height:100px"><?php echo $content; ?></div>
@@ -784,31 +784,31 @@  discard block
 block discarded – undo
784 784
 <?php
785 785
     exit;
786 786
 }
787
-add_action( 'wp_ajax_wpinv_ip_geolocation', 'wpinv_ip_geolocation' );
788
-add_action( 'wp_ajax_nopriv_wpinv_ip_geolocation', 'wpinv_ip_geolocation' );
787
+add_action('wp_ajax_wpinv_ip_geolocation', 'wpinv_ip_geolocation');
788
+add_action('wp_ajax_nopriv_wpinv_ip_geolocation', 'wpinv_ip_geolocation');
789 789
 
790 790
 // Set up the template for the invoice.
791
-function wpinv_template( $template ) {
791
+function wpinv_template($template) {
792 792
     global $post, $wp_query;
793 793
     
794
-    if ( ( is_single() || is_404() ) && !empty( $post->ID ) && (get_post_type( $post->ID ) == 'wpi_invoice' or get_post_type( $post->ID ) == 'wpi_quote')) {
795
-        if ( wpinv_user_can_print_invoice( $post->ID ) ) {
796
-            $template = wpinv_get_template_part( 'wpinv-invoice-print', false, false );
794
+    if ((is_single() || is_404()) && !empty($post->ID) && (get_post_type($post->ID) == 'wpi_invoice' or get_post_type($post->ID) == 'wpi_quote')) {
795
+        if (wpinv_user_can_print_invoice($post->ID)) {
796
+            $template = wpinv_get_template_part('wpinv-invoice-print', false, false);
797 797
         } else {
798
-            if ( !is_user_logged_in() && !empty( $_REQUEST['_wpipay'] ) && $invoice = wpinv_get_invoice( $post->ID ) ) {
798
+            if (!is_user_logged_in() && !empty($_REQUEST['_wpipay']) && $invoice = wpinv_get_invoice($post->ID)) {
799 799
                 $user_id = $invoice->get_user_id();
800
-                $secret = sanitize_text_field( $_GET['_wpipay'] );
800
+                $secret = sanitize_text_field($_GET['_wpipay']);
801 801
 
802
-                if ( $secret === md5( $user_id . '::' . $invoice->get_email() . '::' . $invoice->get_key() ) ) { // valid invoice link
803
-                    $redirect_to = remove_query_arg( '_wpipay', get_permalink() );
802
+                if ($secret === md5($user_id . '::' . $invoice->get_email() . '::' . $invoice->get_key())) { // valid invoice link
803
+                    $redirect_to = remove_query_arg('_wpipay', get_permalink());
804 804
 
805
-                    wpinv_guest_redirect( $redirect_to, $user_id );
805
+                    wpinv_guest_redirect($redirect_to, $user_id);
806 806
                     wpinv_die();
807 807
                 }
808 808
             }
809
-            $redirect_to = is_user_logged_in() ? wpinv_get_history_page_uri() : wp_login_url( get_permalink() );
809
+            $redirect_to = is_user_logged_in() ? wpinv_get_history_page_uri() : wp_login_url(get_permalink());
810 810
 
811
-            wp_redirect( $redirect_to );
811
+            wp_redirect($redirect_to);
812 812
             wpinv_die();
813 813
         }
814 814
     }
@@ -818,7 +818,7 @@  discard block
 block discarded – undo
818 818
 
819 819
 function wpinv_get_business_address() {
820 820
     $business_address   = wpinv_store_address();
821
-    $business_address   = !empty( $business_address ) ? wpautop( wp_kses_post( $business_address ) ) : '';
821
+    $business_address   = !empty($business_address) ? wpautop(wp_kses_post($business_address)) : '';
822 822
     
823 823
     /*
824 824
     $default_country    = wpinv_get_default_country();
@@ -842,7 +842,7 @@  discard block
 block discarded – undo
842 842
     
843 843
     $business_address = $business_address ? '<div class="address">' . $business_address . '</div>' : '';
844 844
     
845
-    return apply_filters( 'wpinv_get_business_address', $business_address );
845
+    return apply_filters('wpinv_get_business_address', $business_address);
846 846
 }
847 847
 
848 848
 function wpinv_display_from_address() {
@@ -852,185 +852,185 @@  discard block
 block discarded – undo
852 852
     if (empty($from_name)) {
853 853
         $from_name = wpinv_get_business_name();
854 854
     }
855
-    ?><div class="from col-xs-2"><strong><?php _e( 'From:', 'invoicing' ) ?></strong></div>
855
+    ?><div class="from col-xs-2"><strong><?php _e('From:', 'invoicing') ?></strong></div>
856 856
     <div class="wrapper col-xs-10">
857
-        <div class="name"><?php echo esc_html( $from_name ); ?></div>
858
-        <?php if ( $address = wpinv_get_business_address() ) { ?>
859
-        <div class="address"><?php echo wpautop( wp_kses_post( $address ) );?></div>
857
+        <div class="name"><?php echo esc_html($from_name); ?></div>
858
+        <?php if ($address = wpinv_get_business_address()) { ?>
859
+        <div class="address"><?php echo wpautop(wp_kses_post($address)); ?></div>
860 860
         <?php } ?>
861
-        <?php if ( $email_from = wpinv_mail_get_from_address() ) { ?>
862
-        <div class="email_from"><?php echo wp_sprintf( __( 'Email: %s' ), $email_from );?></div>
861
+        <?php if ($email_from = wpinv_mail_get_from_address()) { ?>
862
+        <div class="email_from"><?php echo wp_sprintf(__('Email: %s'), $email_from); ?></div>
863 863
         <?php } ?>
864 864
     </div>
865 865
     <?php
866 866
 }
867 867
 
868
-function wpinv_watermark( $id = 0 ) {
869
-    $output = wpinv_get_watermark( $id );
868
+function wpinv_watermark($id = 0) {
869
+    $output = wpinv_get_watermark($id);
870 870
     
871
-    return apply_filters( 'wpinv_get_watermark', $output, $id );
871
+    return apply_filters('wpinv_get_watermark', $output, $id);
872 872
 }
873 873
 
874
-function wpinv_get_watermark( $id ) {
875
-    if ( !$id > 0 ) {
874
+function wpinv_get_watermark($id) {
875
+    if (!$id > 0) {
876 876
         return NULL;
877 877
     }
878
-    $invoice = wpinv_get_invoice( $id );
878
+    $invoice = wpinv_get_invoice($id);
879 879
     
880
-    if ( !empty( $invoice ) && "wpi_invoice" === $invoice->post_type ) {
881
-        if ( $invoice->is_paid() ) {
882
-            return __( 'Paid', 'invoicing' );
880
+    if (!empty($invoice) && "wpi_invoice" === $invoice->post_type) {
881
+        if ($invoice->is_paid()) {
882
+            return __('Paid', 'invoicing');
883 883
         }
884
-        if ( $invoice->has_status( array( 'wpi-cancelled' ) ) ) {
885
-            return __( 'Cancelled', 'invoicing' );
884
+        if ($invoice->has_status(array('wpi-cancelled'))) {
885
+            return __('Cancelled', 'invoicing');
886 886
         }
887 887
     }
888 888
     
889 889
     return NULL;
890 890
 }
891 891
 
892
-function wpinv_display_invoice_details( $invoice ) {
892
+function wpinv_display_invoice_details($invoice) {
893 893
     global $wpinv_euvat;
894 894
     
895 895
     $invoice_id = $invoice->ID;
896 896
     $vat_name   = $wpinv_euvat->get_vat_name();
897 897
     $use_taxes  = wpinv_use_taxes();
898 898
     
899
-    $invoice_status = wpinv_get_invoice_status( $invoice_id );
899
+    $invoice_status = wpinv_get_invoice_status($invoice_id);
900 900
     
901
-    if($invoice->post_type == 'wpi_invoice') $type = 'Invoice';
902
-    elseif($invoice->post_type == 'wpi_quote') $type = 'Quote';
901
+    if ($invoice->post_type == 'wpi_invoice') $type = 'Invoice';
902
+    elseif ($invoice->post_type == 'wpi_quote') $type = 'Quote';
903 903
     ?>
904 904
     <table class="table table-bordered table-sm">
905
-        <?php if ( $invoice_number = wpinv_get_invoice_number( $invoice_id ) ) { ?>
905
+        <?php if ($invoice_number = wpinv_get_invoice_number($invoice_id)) { ?>
906 906
             <tr class="wpi-row-number">
907
-                <th><?php echo sprintf(__( '%s Number', 'invoicing' ), $type); ?></th>
908
-                <td><?php echo esc_html( $invoice_number ); ?></td>
907
+                <th><?php echo sprintf(__('%s Number', 'invoicing'), $type); ?></th>
908
+                <td><?php echo esc_html($invoice_number); ?></td>
909 909
             </tr>
910 910
         <?php } ?>
911 911
         <tr class="wpi-row-status">
912
-            <th><?php echo wp_sprintf(__( '%s Status', 'invoicing' ), $type); ?></th>
913
-            <td><?php echo wpinv_invoice_status_label( $invoice_status, wpinv_get_invoice_status( $invoice_id, true ) ); ?></td>
912
+            <th><?php echo wp_sprintf(__('%s Status', 'invoicing'), $type); ?></th>
913
+            <td><?php echo wpinv_invoice_status_label($invoice_status, wpinv_get_invoice_status($invoice_id, true)); ?></td>
914 914
         </tr>
915
-        <?php if ( $invoice->is_renewal() ) { ?>
915
+        <?php if ($invoice->is_renewal()) { ?>
916 916
         <tr class="wpi-row-parent">
917
-            <th><?php echo wp_sprintf(__( 'Parent %s', 'invoicing' ), $type); ?></th>
918
-            <td><?php echo wpinv_invoice_link( $invoice->parent_invoice ); ?></td>
917
+            <th><?php echo wp_sprintf(__('Parent %s', 'invoicing'), $type); ?></th>
918
+            <td><?php echo wpinv_invoice_link($invoice->parent_invoice); ?></td>
919 919
         </tr>
920 920
         <?php } ?>
921 921
         <tr class="wpi-row-gateway">
922
-            <th><?php _e( 'Payment Method', 'invoicing' ); ?></th>
923
-            <td><?php echo wpinv_get_payment_gateway_name( $invoice_id ); ?></td>
922
+            <th><?php _e('Payment Method', 'invoicing'); ?></th>
923
+            <td><?php echo wpinv_get_payment_gateway_name($invoice_id); ?></td>
924 924
         </tr>
925
-        <?php if ( $invoice_date = wpinv_get_invoice_date( $invoice_id ) ) { ?>
925
+        <?php if ($invoice_date = wpinv_get_invoice_date($invoice_id)) { ?>
926 926
             <tr class="wpi-row-date">
927
-                <th><?php echo wp_sprintf(__( '%s Date', 'invoicing' ), $type); ?></th>
927
+                <th><?php echo wp_sprintf(__('%s Date', 'invoicing'), $type); ?></th>
928 928
                 <td><?php echo $invoice_date; ?></td>
929 929
             </tr>
930 930
         <?php } ?>
931
-        <?php if ( wpinv_get_option( 'overdue_active' ) && $invoice->needs_payment() && ( $due_date = $invoice->get_due_date( true ) ) ) { ?>
931
+        <?php if (wpinv_get_option('overdue_active') && $invoice->needs_payment() && ($due_date = $invoice->get_due_date(true))) { ?>
932 932
             <tr class="wpi-row-date">
933
-                <th><?php _e( 'Due Date', 'invoicing' ); ?></th>
933
+                <th><?php _e('Due Date', 'invoicing'); ?></th>
934 934
                 <td><?php echo $due_date; ?></td>
935 935
             </tr>
936 936
         <?php } ?>
937
-        <?php if ( $owner_vat_number = $wpinv_euvat->get_vat_number() ) { ?>
937
+        <?php if ($owner_vat_number = $wpinv_euvat->get_vat_number()) { ?>
938 938
             <tr class="wpi-row-ovatno">
939
-                <th><?php echo wp_sprintf( __( 'Owner %s Number', 'invoicing' ), $vat_name ); ?></th>
939
+                <th><?php echo wp_sprintf(__('Owner %s Number', 'invoicing'), $vat_name); ?></th>
940 940
                 <td><?php echo $owner_vat_number; ?></td>
941 941
             </tr>
942 942
         <?php } ?>
943
-        <?php if ( $use_taxes && $user_vat_number = wpinv_get_invoice_vat_number( $invoice_id ) ) { ?>
943
+        <?php if ($use_taxes && $user_vat_number = wpinv_get_invoice_vat_number($invoice_id)) { ?>
944 944
             <tr class="wpi-row-uvatno">
945
-                <th><?php echo wp_sprintf( __( 'Your %s Number', 'invoicing' ), $vat_name ); ?></th>
945
+                <th><?php echo wp_sprintf(__('Your %s Number', 'invoicing'), $vat_name); ?></th>
946 946
                 <td><?php echo $user_vat_number; ?></td>
947 947
             </tr>
948 948
         <?php } ?>
949 949
         <tr class="table-active tr-total wpi-row-total">
950
-            <th><strong><?php _e( 'Total Amount', 'invoicing' ) ?></strong></th>
951
-            <td><strong><?php echo wpinv_payment_total( $invoice_id, true ); ?></strong></td>
950
+            <th><strong><?php _e('Total Amount', 'invoicing') ?></strong></th>
951
+            <td><strong><?php echo wpinv_payment_total($invoice_id, true); ?></strong></td>
952 952
         </tr>
953 953
     </table>
954 954
 <?php
955 955
 }
956 956
 
957
-function wpinv_display_to_address( $invoice_id = 0 ) {
958
-    $invoice = wpinv_get_invoice( $invoice_id );
957
+function wpinv_display_to_address($invoice_id = 0) {
958
+    $invoice = wpinv_get_invoice($invoice_id);
959 959
     
960
-    if ( empty( $invoice ) ) {
960
+    if (empty($invoice)) {
961 961
         return NULL;
962 962
     }
963 963
     
964 964
     $billing_details = $invoice->get_user_info();
965
-    $output = '<div class="to col-xs-2"><strong>' . __( 'To:', 'invoicing' ) . '</strong></div>';
965
+    $output = '<div class="to col-xs-2"><strong>' . __('To:', 'invoicing') . '</strong></div>';
966 966
     $output .= '<div class="wrapper col-xs-10">';
967 967
     
968 968
     ob_start();
969
-    do_action( 'wpinv_display_to_address_top', $invoice );
969
+    do_action('wpinv_display_to_address_top', $invoice);
970 970
     $output .= ob_get_clean();
971 971
     
972
-    $output .= '<div class="name">' . esc_html( trim( $billing_details['first_name'] . ' ' . $billing_details['last_name'] ) ) . '</div>';
973
-    if ( $company = $billing_details['company'] ) {
974
-        $output .= '<div class="company">' . wpautop( wp_kses_post( $company ) ) . '</div>';
972
+    $output .= '<div class="name">' . esc_html(trim($billing_details['first_name'] . ' ' . $billing_details['last_name'])) . '</div>';
973
+    if ($company = $billing_details['company']) {
974
+        $output .= '<div class="company">' . wpautop(wp_kses_post($company)) . '</div>';
975 975
     }
976 976
     $address_row = '';
977
-    if ( $address = $billing_details['address'] ) {
978
-        $address_row .= wpautop( wp_kses_post( $address ) );
977
+    if ($address = $billing_details['address']) {
978
+        $address_row .= wpautop(wp_kses_post($address));
979 979
     }
980 980
     
981 981
     $address_fields = array();
982
-    if ( !empty( $billing_details['city'] ) ) {
982
+    if (!empty($billing_details['city'])) {
983 983
         $address_fields[] = $billing_details['city'];
984 984
     }
985 985
     
986
-    $billing_country = !empty( $billing_details['country'] ) ? $billing_details['country'] : '';
987
-    if ( !empty( $billing_details['state'] ) ) {
988
-        $address_fields[] = wpinv_state_name( $billing_details['state'], $billing_country );
986
+    $billing_country = !empty($billing_details['country']) ? $billing_details['country'] : '';
987
+    if (!empty($billing_details['state'])) {
988
+        $address_fields[] = wpinv_state_name($billing_details['state'], $billing_country);
989 989
     }
990 990
     
991
-    if ( !empty( $billing_country ) ) {
992
-        $address_fields[] = wpinv_country_name( $billing_country );
991
+    if (!empty($billing_country)) {
992
+        $address_fields[] = wpinv_country_name($billing_country);
993 993
     }
994 994
     
995
-    if ( !empty( $address_fields ) ) {
996
-        $address_fields = implode( ", ", $address_fields );
995
+    if (!empty($address_fields)) {
996
+        $address_fields = implode(", ", $address_fields);
997 997
         
998
-        if ( !empty( $billing_details['zip'] ) ) {
998
+        if (!empty($billing_details['zip'])) {
999 999
             $address_fields .= ' ' . $billing_details['zip'];
1000 1000
         }
1001 1001
         
1002
-        $address_row .= wpautop( wp_kses_post( $address_fields ) );
1002
+        $address_row .= wpautop(wp_kses_post($address_fields));
1003 1003
     }
1004 1004
     
1005
-    if ( $address_row ) {
1005
+    if ($address_row) {
1006 1006
         $output .= '<div class="address">' . $address_row . '</div>';
1007 1007
     }
1008 1008
     
1009
-    if ( $phone = $invoice->get_phone() ) {
1010
-        $output .= '<div class="phone">' . wp_sprintf( __( 'Phone: %s' ), esc_html( $phone ) ) . '</div>';
1009
+    if ($phone = $invoice->get_phone()) {
1010
+        $output .= '<div class="phone">' . wp_sprintf(__('Phone: %s'), esc_html($phone)) . '</div>';
1011 1011
     }
1012
-    if ( $email = $invoice->get_email() ) {
1013
-        $output .= '<div class="email">' . wp_sprintf( __( 'Email: %s' ), esc_html( $email ) ) . '</div>';
1012
+    if ($email = $invoice->get_email()) {
1013
+        $output .= '<div class="email">' . wp_sprintf(__('Email: %s'), esc_html($email)) . '</div>';
1014 1014
     }
1015 1015
     
1016 1016
     ob_start();
1017
-    do_action( 'wpinv_display_to_address_bottom', $invoice );
1017
+    do_action('wpinv_display_to_address_bottom', $invoice);
1018 1018
     $output .= ob_get_clean();
1019 1019
     
1020 1020
     $output .= '</div>';
1021
-    $output = apply_filters( 'wpinv_display_to_address', $output, $invoice );
1021
+    $output = apply_filters('wpinv_display_to_address', $output, $invoice);
1022 1022
 
1023 1023
     echo $output;
1024 1024
 }
1025 1025
 
1026
-function wpinv_display_line_items( $invoice_id = 0 ) {
1026
+function wpinv_display_line_items($invoice_id = 0) {
1027 1027
     global $wpinv_euvat, $ajax_cart_details;
1028
-    $invoice            = wpinv_get_invoice( $invoice_id );
1028
+    $invoice            = wpinv_get_invoice($invoice_id);
1029 1029
     $quantities_enabled = wpinv_item_quantities_enabled();
1030 1030
     $use_taxes          = wpinv_use_taxes();
1031 1031
     $zero_tax           = !(float)$invoice->get_tax() > 0 ? true : false;
1032
-    $tax_label           = $use_taxes && $invoice->has_vat() ? $wpinv_euvat->get_vat_name() : __( 'Tax', 'invoicing' );
1033
-    $tax_title          = !$zero_tax && $use_taxes ? ( wpinv_prices_include_tax() ? wp_sprintf( __( '(%s Incl.)', 'invoicing' ), $tax_label ) : wp_sprintf( __( '(%s Excl.)', 'invoicing' ), $tax_label ) ) : '';
1032
+    $tax_label = $use_taxes && $invoice->has_vat() ? $wpinv_euvat->get_vat_name() : __('Tax', 'invoicing');
1033
+    $tax_title          = !$zero_tax && $use_taxes ? (wpinv_prices_include_tax() ? wp_sprintf(__('(%s Incl.)', 'invoicing'), $tax_label) : wp_sprintf(__('(%s Excl.)', 'invoicing'), $tax_label)) : '';
1034 1034
     
1035 1035
     $cart_details       = $invoice->get_cart_details();
1036 1036
     $ajax_cart_details  = $cart_details;
@@ -1039,68 +1039,68 @@  discard block
 block discarded – undo
1039 1039
     <table class="table table-sm table-bordered table-responsive">
1040 1040
         <thead>
1041 1041
             <tr>
1042
-                <th class="name"><strong><?php _e( "Item Name", "invoicing" );?></strong></th>
1043
-                <th class="rate"><strong><?php _e( "Price", "invoicing" );?></strong></th>
1042
+                <th class="name"><strong><?php _e("Item Name", "invoicing"); ?></strong></th>
1043
+                <th class="rate"><strong><?php _e("Price", "invoicing"); ?></strong></th>
1044 1044
                 <?php if ($quantities_enabled) { ?>
1045
-                    <th class="qty"><strong><?php _e( "Qty", "invoicing" );?></strong></th>
1045
+                    <th class="qty"><strong><?php _e("Qty", "invoicing"); ?></strong></th>
1046 1046
                 <?php } ?>
1047 1047
                 <?php if ($use_taxes && !$zero_tax) { ?>
1048 1048
                     <th class="tax"><strong><?php echo $tax_label . ' <span class="normal small">(%)</span>'; ?></strong></th>
1049 1049
                 <?php } ?>
1050
-                <th class="total"><strong><?php echo __( "Item Total", "invoicing" ) . ' <span class="normal small">' . $tax_title . '<span>';?></strong></th>
1050
+                <th class="total"><strong><?php echo __("Item Total", "invoicing") . ' <span class="normal small">' . $tax_title . '<span>'; ?></strong></th>
1051 1051
             </tr>
1052 1052
         </thead>
1053 1053
         <tbody>
1054 1054
         <?php 
1055
-            if ( !empty( $cart_details ) ) {
1056
-                do_action( 'wpinv_display_line_items_start', $invoice );
1055
+            if (!empty($cart_details)) {
1056
+                do_action('wpinv_display_line_items_start', $invoice);
1057 1057
                 
1058 1058
                 $count = 0;
1059 1059
                 $cols  = 3;
1060
-                foreach ( $cart_details as $key => $cart_item ) {
1061
-                    $item_id    = !empty($cart_item['id']) ? absint( $cart_item['id'] ) : '';
1062
-                    $item_price = isset($cart_item["item_price"]) ? wpinv_round_amount( $cart_item["item_price"] ) : 0;
1063
-                    $line_total = isset($cart_item["subtotal"]) ? wpinv_round_amount( $cart_item["subtotal"] ) : 0;
1064
-                    $quantity   = !empty($cart_item['quantity']) && (int)$cart_item['quantity'] > 0 ? absint( $cart_item['quantity'] ) : 1;
1060
+                foreach ($cart_details as $key => $cart_item) {
1061
+                    $item_id    = !empty($cart_item['id']) ? absint($cart_item['id']) : '';
1062
+                    $item_price = isset($cart_item["item_price"]) ? wpinv_round_amount($cart_item["item_price"]) : 0;
1063
+                    $line_total = isset($cart_item["subtotal"]) ? wpinv_round_amount($cart_item["subtotal"]) : 0;
1064
+                    $quantity   = !empty($cart_item['quantity']) && (int)$cart_item['quantity'] > 0 ? absint($cart_item['quantity']) : 1;
1065 1065
                     
1066
-                    $item       = $item_id ? new WPInv_Item( $item_id ) : NULL;
1066
+                    $item       = $item_id ? new WPInv_Item($item_id) : NULL;
1067 1067
                     $summary    = '';
1068 1068
                     $cols       = 3;
1069
-                    if ( !empty($item) ) {
1069
+                    if (!empty($item)) {
1070 1070
                         $item_name  = $item->get_name();
1071 1071
                         $summary    = $item->get_summary();
1072 1072
                     }
1073
-                    $item_name  = !empty($cart_item['name']) ? $cart_item['name'] : $item_name;
1073
+                    $item_name = !empty($cart_item['name']) ? $cart_item['name'] : $item_name;
1074 1074
                     
1075 1075
                     if (!empty($item) && $item->is_package() && !empty($cart_item['meta']['post_id'])) {
1076
-                        $post_link = '<a href="' . get_edit_post_link( $cart_item['meta']['post_id'] ) .'" target="_blank">' . (!empty($cart_item['meta']['invoice_title']) ? $cart_item['meta']['invoice_title'] : get_the_title( $cart_item['meta']['post_id']) ) . '</a>';
1077
-                        $summary = wp_sprintf( __( '%s: %s', 'invoicing' ), $item->get_custom_singular_name(), $post_link );
1076
+                        $post_link = '<a href="' . get_edit_post_link($cart_item['meta']['post_id']) . '" target="_blank">' . (!empty($cart_item['meta']['invoice_title']) ? $cart_item['meta']['invoice_title'] : get_the_title($cart_item['meta']['post_id'])) . '</a>';
1077
+                        $summary = wp_sprintf(__('%s: %s', 'invoicing'), $item->get_custom_singular_name(), $post_link);
1078 1078
                     }
1079
-                    $summary = apply_filters( 'wpinv_print_invoice_line_item_summary', $summary, $cart_item, $item, $invoice );
1079
+                    $summary = apply_filters('wpinv_print_invoice_line_item_summary', $summary, $cart_item, $item, $invoice);
1080 1080
                     
1081 1081
                     $item_tax       = '';
1082 1082
                     $tax_rate       = '';
1083
-                    if ( $use_taxes && $cart_item['tax'] > 0 && $cart_item['subtotal'] > 0 ) {
1084
-                        $item_tax = wpinv_price( wpinv_format_amount( $cart_item['tax'] ) );
1085
-                        $tax_rate = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : ( $cart_item['tax'] / $cart_item['subtotal'] ) * 100;
1086
-                        $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount( $tax_rate, 4 ) : '';
1083
+                    if ($use_taxes && $cart_item['tax'] > 0 && $cart_item['subtotal'] > 0) {
1084
+                        $item_tax = wpinv_price(wpinv_format_amount($cart_item['tax']));
1085
+                        $tax_rate = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : ($cart_item['tax'] / $cart_item['subtotal']) * 100;
1086
+                        $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount($tax_rate, 4) : '';
1087 1087
                         $tax_rate = $tax_rate != '' ? ' <small class="tax-rate">(' . $tax_rate . '%)</small>' : '';
1088 1088
                     }
1089 1089
                     
1090 1090
                     $line_item_tax = $item_tax . $tax_rate;
1091 1091
                     
1092
-                    if ( $line_item_tax === '' ) {
1092
+                    if ($line_item_tax === '') {
1093 1093
                         $line_item_tax = 0; // Zero tax
1094 1094
                     }
1095 1095
                     
1096
-                    $line_item = '<tr class="row-' . ( ($count % 2 == 0) ? 'even' : 'odd' ) . ' wpinv-item">';
1097
-                        $line_item .= '<td class="name">' . esc_html__( $item_name, 'invoicing' ) . wpinv_get_item_suffix( $item );
1098
-                        if ( $summary !== '' ) {
1099
-                            $line_item .= '<br/><small class="meta">' . wpautop( wp_kses_post( $summary ) ) . '</small>';
1096
+                    $line_item = '<tr class="row-' . (($count % 2 == 0) ? 'even' : 'odd') . ' wpinv-item">';
1097
+                        $line_item .= '<td class="name">' . esc_html__($item_name, 'invoicing') . wpinv_get_item_suffix($item);
1098
+                        if ($summary !== '') {
1099
+                            $line_item .= '<br/><small class="meta">' . wpautop(wp_kses_post($summary)) . '</small>';
1100 1100
                         }
1101 1101
                         $line_item .= '</td>';
1102 1102
                         
1103
-                        $line_item .= '<td class="rate">' . esc_html__( wpinv_price( wpinv_format_amount( $item_price ), $invoice->get_currency() ) ) . '</td>';
1103
+                        $line_item .= '<td class="rate">' . esc_html__(wpinv_price(wpinv_format_amount($item_price), $invoice->get_currency())) . '</td>';
1104 1104
                         if ($quantities_enabled) {
1105 1105
                             $cols++;
1106 1106
                             $line_item .= '<td class="qty">' . $quantity . '</td>';
@@ -1109,55 +1109,55 @@  discard block
 block discarded – undo
1109 1109
                             $cols++;
1110 1110
                             $line_item .= '<td class="tax">' . $line_item_tax . '</td>';
1111 1111
                         }
1112
-                        $line_item .= '<td class="total">' . esc_html__( wpinv_price( wpinv_format_amount( $line_total ), $invoice->get_currency() ) ) . '</td>';
1112
+                        $line_item .= '<td class="total">' . esc_html__(wpinv_price(wpinv_format_amount($line_total), $invoice->get_currency())) . '</td>';
1113 1113
                     $line_item .= '</tr>';
1114 1114
                     
1115
-                    echo apply_filters( 'wpinv_display_line_item', $line_item, $cart_item, $invoice, $cols );
1115
+                    echo apply_filters('wpinv_display_line_item', $line_item, $cart_item, $invoice, $cols);
1116 1116
 
1117 1117
                     $count++;
1118 1118
                 }
1119 1119
                 
1120
-                do_action( 'wpinv_display_before_subtotal', $invoice, $cols );
1120
+                do_action('wpinv_display_before_subtotal', $invoice, $cols);
1121 1121
                 ?>
1122 1122
                 <tr class="row-sub-total row_odd">
1123
-                    <td class="rate" colspan="<?php echo ( $cols - 1 ); ?>"><?php echo apply_filters( 'wpinv_print_cart_subtotal_label', '<strong>' . __( 'Sub Total', 'invoicing' ) . ':</strong>', $invoice ); ?></td>
1124
-                    <td class="total"><strong><?php _e( wpinv_subtotal( $invoice_id, true ) ) ?></strong></td>
1123
+                    <td class="rate" colspan="<?php echo ($cols - 1); ?>"><?php echo apply_filters('wpinv_print_cart_subtotal_label', '<strong>' . __('Sub Total', 'invoicing') . ':</strong>', $invoice); ?></td>
1124
+                    <td class="total"><strong><?php _e(wpinv_subtotal($invoice_id, true)) ?></strong></td>
1125 1125
                 </tr>
1126 1126
                 <?php
1127
-                do_action( 'wpinv_display_after_subtotal', $invoice, $cols );
1127
+                do_action('wpinv_display_after_subtotal', $invoice, $cols);
1128 1128
                 
1129
-                if ( wpinv_discount( $invoice_id, false ) > 0 ) {
1130
-                    do_action( 'wpinv_display_before_discount', $invoice, $cols );
1129
+                if (wpinv_discount($invoice_id, false) > 0) {
1130
+                    do_action('wpinv_display_before_discount', $invoice, $cols);
1131 1131
                     ?>
1132 1132
                         <tr class="row-discount">
1133
-                            <td class="rate" colspan="<?php echo ( $cols - 1 ); ?>"><?php wpinv_get_discount_label( wpinv_discount_code( $invoice_id ) ); ?>:</td>
1134
-                            <td class="total"><?php echo wpinv_discount( $invoice_id, true, true ); ?></td>
1133
+                            <td class="rate" colspan="<?php echo ($cols - 1); ?>"><?php wpinv_get_discount_label(wpinv_discount_code($invoice_id)); ?>:</td>
1134
+                            <td class="total"><?php echo wpinv_discount($invoice_id, true, true); ?></td>
1135 1135
                         </tr>
1136 1136
                     <?php
1137
-                    do_action( 'wpinv_display_after_discount', $invoice, $cols );
1137
+                    do_action('wpinv_display_after_discount', $invoice, $cols);
1138 1138
                 }
1139 1139
                 
1140
-                if ( $use_taxes ) {
1141
-                    do_action( 'wpinv_display_before_tax', $invoice, $cols );
1140
+                if ($use_taxes) {
1141
+                    do_action('wpinv_display_before_tax', $invoice, $cols);
1142 1142
                     ?>
1143 1143
                     <tr class="row-tax">
1144
-                        <td class="rate" colspan="<?php echo ( $cols - 1 ); ?>"><?php echo apply_filters( 'wpinv_print_cart_tax_label', '<strong>' . $tax_label . ':</strong>', $invoice ); ?></td>
1145
-                        <td class="total"><?php _e( wpinv_tax( $invoice_id, true ) ) ?></td>
1144
+                        <td class="rate" colspan="<?php echo ($cols - 1); ?>"><?php echo apply_filters('wpinv_print_cart_tax_label', '<strong>' . $tax_label . ':</strong>', $invoice); ?></td>
1145
+                        <td class="total"><?php _e(wpinv_tax($invoice_id, true)) ?></td>
1146 1146
                     </tr>
1147 1147
                     <?php
1148
-                    do_action( 'wpinv_display_after_tax', $invoice, $cols );
1148
+                    do_action('wpinv_display_after_tax', $invoice, $cols);
1149 1149
                 }
1150 1150
                 
1151
-                do_action( 'wpinv_display_before_total', $invoice, $cols );
1151
+                do_action('wpinv_display_before_total', $invoice, $cols);
1152 1152
                 ?>
1153 1153
                 <tr class="table-active row-total">
1154
-                    <td class="rate" colspan="<?php echo ( $cols - 1 ); ?>"><?php echo apply_filters( 'wpinv_print_cart_total_label', '<strong>' . __( 'Total', 'invoicing' ) . ':</strong>', $invoice ); ?></td>
1155
-                    <td class="total"><strong><?php _e( wpinv_payment_total( $invoice_id, true ) ) ?></strong></td>
1154
+                    <td class="rate" colspan="<?php echo ($cols - 1); ?>"><?php echo apply_filters('wpinv_print_cart_total_label', '<strong>' . __('Total', 'invoicing') . ':</strong>', $invoice); ?></td>
1155
+                    <td class="total"><strong><?php _e(wpinv_payment_total($invoice_id, true)) ?></strong></td>
1156 1156
                 </tr>
1157 1157
                 <?php
1158
-                do_action( 'wpinv_display_after_total', $invoice, $cols );
1158
+                do_action('wpinv_display_after_total', $invoice, $cols);
1159 1159
                 
1160
-                do_action( 'wpinv_display_line_end', $invoice, $cols );
1160
+                do_action('wpinv_display_line_end', $invoice, $cols);
1161 1161
             }
1162 1162
         ?>
1163 1163
         </tbody>
@@ -1166,35 +1166,35 @@  discard block
 block discarded – undo
1166 1166
     echo ob_get_clean();
1167 1167
 }
1168 1168
 
1169
-function wpinv_display_invoice_totals( $invoice_id = 0 ) {    
1169
+function wpinv_display_invoice_totals($invoice_id = 0) {    
1170 1170
     $use_taxes = wpinv_use_taxes();
1171 1171
     
1172
-    do_action( 'wpinv_before_display_totals_table', $invoice_id ); 
1172
+    do_action('wpinv_before_display_totals_table', $invoice_id); 
1173 1173
     ?>
1174 1174
     <table class="table table-sm table-bordered table-responsive">
1175 1175
         <tbody>
1176
-            <?php do_action( 'wpinv_before_display_totals' ); ?>
1176
+            <?php do_action('wpinv_before_display_totals'); ?>
1177 1177
             <tr class="row-sub-total">
1178
-                <td class="rate"><strong><?php _e( 'Sub Total', 'invoicing' ); ?></strong></td>
1179
-                <td class="total"><strong><?php _e( wpinv_subtotal( $invoice_id, true ) ) ?></strong></td>
1178
+                <td class="rate"><strong><?php _e('Sub Total', 'invoicing'); ?></strong></td>
1179
+                <td class="total"><strong><?php _e(wpinv_subtotal($invoice_id, true)) ?></strong></td>
1180 1180
             </tr>
1181
-            <?php do_action( 'wpinv_after_display_totals' ); ?>
1182
-            <?php if ( wpinv_discount( $invoice_id, false ) > 0 ) { ?>
1181
+            <?php do_action('wpinv_after_display_totals'); ?>
1182
+            <?php if (wpinv_discount($invoice_id, false) > 0) { ?>
1183 1183
                 <tr class="row-discount">
1184
-                    <td class="rate"><?php wpinv_get_discount_label( wpinv_discount_code( $invoice_id ) ); ?></td>
1185
-                    <td class="total"><?php echo wpinv_discount( $invoice_id, true, true ); ?></td>
1184
+                    <td class="rate"><?php wpinv_get_discount_label(wpinv_discount_code($invoice_id)); ?></td>
1185
+                    <td class="total"><?php echo wpinv_discount($invoice_id, true, true); ?></td>
1186 1186
                 </tr>
1187
-            <?php do_action( 'wpinv_after_display_discount' ); ?>
1187
+            <?php do_action('wpinv_after_display_discount'); ?>
1188 1188
             <?php } ?>
1189
-            <?php if ( $use_taxes ) { ?>
1189
+            <?php if ($use_taxes) { ?>
1190 1190
             <tr class="row-tax">
1191
-                <td class="rate"><?php _e( 'Tax', 'invoicing' ); ?></td>
1192
-                <td class="total"><?php _e( wpinv_tax( $invoice_id, true ) ) ?></td>
1191
+                <td class="rate"><?php _e('Tax', 'invoicing'); ?></td>
1192
+                <td class="total"><?php _e(wpinv_tax($invoice_id, true)) ?></td>
1193 1193
             </tr>
1194
-            <?php do_action( 'wpinv_after_display_tax' ); ?>
1194
+            <?php do_action('wpinv_after_display_tax'); ?>
1195 1195
             <?php } ?>
1196
-            <?php if ( $fees = wpinv_get_fees( $invoice_id ) ) { ?>
1197
-                <?php foreach ( $fees as $fee ) { ?>
1196
+            <?php if ($fees = wpinv_get_fees($invoice_id)) { ?>
1197
+                <?php foreach ($fees as $fee) { ?>
1198 1198
                     <tr class="row-fee">
1199 1199
                         <td class="rate"><?php echo $fee['label']; ?></td>
1200 1200
                         <td class="total"><?php echo $fee['amount_display']; ?></td>
@@ -1202,72 +1202,72 @@  discard block
 block discarded – undo
1202 1202
                 <?php } ?>
1203 1203
             <?php } ?>
1204 1204
             <tr class="table-active row-total">
1205
-                <td class="rate"><strong><?php _e( 'Total', 'invoicing' ) ?></strong></td>
1206
-                <td class="total"><strong><?php _e( wpinv_payment_total( $invoice_id, true ) ) ?></strong></td>
1205
+                <td class="rate"><strong><?php _e('Total', 'invoicing') ?></strong></td>
1206
+                <td class="total"><strong><?php _e(wpinv_payment_total($invoice_id, true)) ?></strong></td>
1207 1207
             </tr>
1208
-            <?php do_action( 'wpinv_after_totals' ); ?>
1208
+            <?php do_action('wpinv_after_totals'); ?>
1209 1209
         </tbody>
1210 1210
 
1211 1211
     </table>
1212 1212
 
1213
-    <?php do_action( 'wpinv_after_totals_table' );
1213
+    <?php do_action('wpinv_after_totals_table');
1214 1214
 }
1215 1215
 
1216
-function wpinv_display_payments_info( $invoice_id = 0, $echo = true ) {
1217
-    $invoice = wpinv_get_invoice( $invoice_id );
1216
+function wpinv_display_payments_info($invoice_id = 0, $echo = true) {
1217
+    $invoice = wpinv_get_invoice($invoice_id);
1218 1218
     
1219 1219
     ob_start();
1220
-    do_action( 'wpinv_before_display_payments_info', $invoice_id );
1221
-    if ( ( $gateway_title = $invoice->get_gateway_title() ) || $invoice->is_paid() ) {
1220
+    do_action('wpinv_before_display_payments_info', $invoice_id);
1221
+    if (($gateway_title = $invoice->get_gateway_title()) || $invoice->is_paid()) {
1222 1222
         ?>
1223 1223
         <div class="wpi-payment-info">
1224
-            <p class="wpi-payment-gateway"><?php echo wp_sprintf( __( 'Payment via %s', 'invoicing' ), $gateway_title ? $gateway_title : __( 'Manually', 'invoicing' ) ); ?></p>
1225
-            <?php if ( $gateway_title ) { ?>
1226
-            <p class="wpi-payment-transid"><?php echo wp_sprintf( __( 'Transaction ID: %s', 'invoicing' ), $invoice->get_transaction_id() ); ?></p>
1224
+            <p class="wpi-payment-gateway"><?php echo wp_sprintf(__('Payment via %s', 'invoicing'), $gateway_title ? $gateway_title : __('Manually', 'invoicing')); ?></p>
1225
+            <?php if ($gateway_title) { ?>
1226
+            <p class="wpi-payment-transid"><?php echo wp_sprintf(__('Transaction ID: %s', 'invoicing'), $invoice->get_transaction_id()); ?></p>
1227 1227
             <?php } ?>
1228 1228
         </div>
1229 1229
         <?php
1230 1230
     }
1231
-    do_action( 'wpinv_after_display_payments_info', $invoice_id );
1231
+    do_action('wpinv_after_display_payments_info', $invoice_id);
1232 1232
     $outout = ob_get_clean();
1233 1233
     
1234
-    if ( $echo ) {
1234
+    if ($echo) {
1235 1235
         echo $outout;
1236 1236
     } else {
1237 1237
         return $outout;
1238 1238
     }
1239 1239
 }
1240 1240
 
1241
-function wpinv_display_style( $invoice ) {
1242
-    wp_register_style( 'wpinv-single-style', WPINV_PLUGIN_URL . 'assets/css/invoice.css', array(), WPINV_VERSION );
1241
+function wpinv_display_style($invoice) {
1242
+    wp_register_style('wpinv-single-style', WPINV_PLUGIN_URL . 'assets/css/invoice.css', array(), WPINV_VERSION);
1243 1243
     
1244
-    wp_print_styles( 'open-sans' );
1245
-    wp_print_styles( 'wpinv-single-style' );
1244
+    wp_print_styles('open-sans');
1245
+    wp_print_styles('wpinv-single-style');
1246 1246
 }
1247
-add_action( 'wpinv_invoice_print_head', 'wpinv_display_style' );
1247
+add_action('wpinv_invoice_print_head', 'wpinv_display_style');
1248 1248
 
1249 1249
 function wpinv_checkout_billing_details() {  
1250 1250
     $invoice_id = (int)wpinv_get_invoice_cart_id();
1251 1251
     if (empty($invoice_id)) {
1252
-        wpinv_error_log( 'Invoice id not found', 'ERROR', __FILE__, __LINE__ );
1252
+        wpinv_error_log('Invoice id not found', 'ERROR', __FILE__, __LINE__);
1253 1253
         return null;
1254 1254
     }
1255 1255
     
1256
-    $invoice = wpinv_get_invoice_cart( $invoice_id );
1256
+    $invoice = wpinv_get_invoice_cart($invoice_id);
1257 1257
     if (empty($invoice)) {
1258
-        wpinv_error_log( 'Invoice not found', 'ERROR', __FILE__, __LINE__ );
1258
+        wpinv_error_log('Invoice not found', 'ERROR', __FILE__, __LINE__);
1259 1259
         return null;
1260 1260
     }
1261 1261
     $user_id        = $invoice->get_user_id();
1262 1262
     $user_info      = $invoice->get_user_info();
1263
-    $address_info   = wpinv_get_user_address( $user_id );
1263
+    $address_info   = wpinv_get_user_address($user_id);
1264 1264
     
1265
-    if ( empty( $user_info['first_name'] ) && !empty( $user_info['first_name'] ) ) {
1265
+    if (empty($user_info['first_name']) && !empty($user_info['first_name'])) {
1266 1266
         $user_info['first_name'] = $user_info['first_name'];
1267 1267
         $user_info['last_name'] = $user_info['last_name'];
1268 1268
     }
1269 1269
     
1270
-    if ( ( ( empty( $user_info['country'] ) && !empty( $address_info['country'] ) ) || ( empty( $user_info['state'] ) && !empty( $address_info['state'] ) && $user_info['country'] == $address_info['country'] ) ) ) {
1270
+    if (((empty($user_info['country']) && !empty($address_info['country'])) || (empty($user_info['state']) && !empty($address_info['state']) && $user_info['country'] == $address_info['country']))) {
1271 1271
         $user_info['country']   = $address_info['country'];
1272 1272
         $user_info['state']     = $address_info['state'];
1273 1273
         $user_info['city']      = $address_info['city'];
@@ -1283,103 +1283,103 @@  discard block
 block discarded – undo
1283 1283
         'address'
1284 1284
     );
1285 1285
     
1286
-    foreach ( $address_fields as $field ) {
1287
-        if ( empty( $user_info[$field] ) ) {
1286
+    foreach ($address_fields as $field) {
1287
+        if (empty($user_info[$field])) {
1288 1288
             $user_info[$field] = $address_info[$field];
1289 1289
         }
1290 1290
     }
1291 1291
     
1292
-    return apply_filters( 'wpinv_checkout_billing_details', $user_info, $invoice );
1292
+    return apply_filters('wpinv_checkout_billing_details', $user_info, $invoice);
1293 1293
 }
1294 1294
 
1295 1295
 function wpinv_admin_get_line_items($invoice = array()) {
1296 1296
     $item_quantities    = wpinv_item_quantities_enabled();
1297 1297
     $use_taxes          = wpinv_use_taxes();
1298 1298
     
1299
-    if ( empty( $invoice ) ) {
1299
+    if (empty($invoice)) {
1300 1300
         return NULL;
1301 1301
     }
1302 1302
     
1303 1303
     $cart_items = $invoice->get_cart_details();
1304
-    if ( empty( $cart_items ) ) {
1304
+    if (empty($cart_items)) {
1305 1305
         return NULL;
1306 1306
     }
1307 1307
     ob_start();
1308 1308
     
1309
-    do_action( 'wpinv_admin_before_line_items', $cart_items, $invoice );
1309
+    do_action('wpinv_admin_before_line_items', $cart_items, $invoice);
1310 1310
     
1311 1311
     $count = 0;
1312
-    foreach ( $cart_items as $key => $cart_item ) {
1312
+    foreach ($cart_items as $key => $cart_item) {
1313 1313
         $item_id    = $cart_item['id'];
1314
-        $wpi_item   = $item_id > 0 ? new WPInv_Item( $item_id ) : NULL;
1314
+        $wpi_item   = $item_id > 0 ? new WPInv_Item($item_id) : NULL;
1315 1315
         
1316 1316
         if (empty($wpi_item)) {
1317 1317
             continue;
1318 1318
         }
1319 1319
         
1320
-        $item_price     = wpinv_price( wpinv_format_amount( $cart_item['item_price'] ) );
1321
-        $quantity       = !empty( $cart_item['quantity'] ) && $cart_item['quantity'] > 0 ? $cart_item['quantity'] : 1;
1322
-        $item_subtotal  = wpinv_price( wpinv_format_amount( $cart_item['subtotal'] ) );
1320
+        $item_price     = wpinv_price(wpinv_format_amount($cart_item['item_price']));
1321
+        $quantity       = !empty($cart_item['quantity']) && $cart_item['quantity'] > 0 ? $cart_item['quantity'] : 1;
1322
+        $item_subtotal  = wpinv_price(wpinv_format_amount($cart_item['subtotal']));
1323 1323
         $can_remove     = true;
1324 1324
         
1325 1325
         $summary = '';
1326 1326
         if ($wpi_item->is_package() && !empty($cart_item['meta']['post_id'])) {
1327
-            $post_link = '<a href="' . get_edit_post_link( $cart_item['meta']['post_id'] ) .'" target="_blank">' . (!empty($cart_item['meta']['invoice_title']) ? $cart_item['meta']['invoice_title'] : get_the_title( $cart_item['meta']['post_id']) ) . '</a>';
1328
-            $summary = wp_sprintf( __( '%s: %s', 'invoicing' ), $wpi_item->get_custom_singular_name(), $post_link );
1327
+            $post_link = '<a href="' . get_edit_post_link($cart_item['meta']['post_id']) . '" target="_blank">' . (!empty($cart_item['meta']['invoice_title']) ? $cart_item['meta']['invoice_title'] : get_the_title($cart_item['meta']['post_id'])) . '</a>';
1328
+            $summary = wp_sprintf(__('%s: %s', 'invoicing'), $wpi_item->get_custom_singular_name(), $post_link);
1329 1329
         }
1330
-        $summary = apply_filters( 'wpinv_admin_invoice_line_item_summary', $summary, $cart_item, $wpi_item, $invoice );
1330
+        $summary = apply_filters('wpinv_admin_invoice_line_item_summary', $summary, $cart_item, $wpi_item, $invoice);
1331 1331
         
1332 1332
         $item_tax       = '';
1333 1333
         $tax_rate       = '';
1334
-        if ( $cart_item['tax'] > 0 && $cart_item['subtotal'] > 0 ) {
1335
-            $item_tax = wpinv_price( wpinv_format_amount( $cart_item['tax'] ) );
1336
-            $tax_rate = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : ( $cart_item['tax'] / $cart_item['subtotal'] ) * 100;
1337
-            $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount( $tax_rate, 4 ) : '';
1334
+        if ($cart_item['tax'] > 0 && $cart_item['subtotal'] > 0) {
1335
+            $item_tax = wpinv_price(wpinv_format_amount($cart_item['tax']));
1336
+            $tax_rate = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : ($cart_item['tax'] / $cart_item['subtotal']) * 100;
1337
+            $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount($tax_rate, 4) : '';
1338 1338
             $tax_rate = $tax_rate != '' ? ' <span class="tax-rate">(' . $tax_rate . '%)</span>' : '';
1339 1339
         }
1340 1340
         $line_item_tax = $item_tax . $tax_rate;
1341 1341
         
1342
-        if ( $line_item_tax === '' ) {
1342
+        if ($line_item_tax === '') {
1343 1343
             $line_item_tax = 0; // Zero tax
1344 1344
         }
1345 1345
 
1346
-        $line_item = '<tr class="item item-' . ( ($count % 2 == 0) ? 'even' : 'odd' ) . '" data-item-id="' . $item_id . '">';
1346
+        $line_item = '<tr class="item item-' . (($count % 2 == 0) ? 'even' : 'odd') . '" data-item-id="' . $item_id . '">';
1347 1347
             $line_item .= '<td class="id">' . $item_id . '</td>';
1348
-            $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 );
1349
-            if ( $summary !== '' ) {
1350
-                $line_item .= '<span class="meta">' . wpautop( wp_kses_post( $summary ) ) . '</span>';
1348
+            $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);
1349
+            if ($summary !== '') {
1350
+                $line_item .= '<span class="meta">' . wpautop(wp_kses_post($summary)) . '</span>';
1351 1351
             }
1352 1352
             $line_item .= '</td>';
1353 1353
             $line_item .= '<td class="price">' . $item_price . '</td>';
1354 1354
             
1355
-            if ( $item_quantities ) {
1356
-                if ( count( $cart_items ) == 1 && $quantity <= 1 ) {
1355
+            if ($item_quantities) {
1356
+                if (count($cart_items) == 1 && $quantity <= 1) {
1357 1357
                     $can_remove = false;
1358 1358
                 }
1359 1359
                 $line_item .= '<td class="qty" data-quantity="' . $quantity . '">&nbsp;&times;&nbsp;' . $quantity . '</td>';
1360 1360
             } else {
1361
-                if ( count( $cart_items ) == 1 ) {
1361
+                if (count($cart_items) == 1) {
1362 1362
                     $can_remove = false;
1363 1363
                 }
1364 1364
             }
1365 1365
             $line_item .= '<td class="total">' . $item_subtotal . '</td>';
1366 1366
             
1367
-            if ( $use_taxes ) {
1367
+            if ($use_taxes) {
1368 1368
                 $line_item .= '<td class="tax">' . $line_item_tax . '</td>';
1369 1369
             }
1370 1370
             $line_item .= '<td class="action">';
1371
-            if ( !$invoice->is_paid() && $can_remove ) {
1371
+            if (!$invoice->is_paid() && $can_remove) {
1372 1372
                 $line_item .= '<i class="fa fa-remove wpinv-item-remove"></i>';
1373 1373
             }
1374 1374
             $line_item .= '</td>';
1375 1375
         $line_item .= '</tr>';
1376 1376
         
1377
-        echo apply_filters( 'wpinv_admin_line_item', $line_item, $cart_item, $invoice );
1377
+        echo apply_filters('wpinv_admin_line_item', $line_item, $cart_item, $invoice);
1378 1378
         
1379 1379
         $count++;
1380 1380
     } 
1381 1381
     
1382
-    do_action( 'wpinv_admin_after_line_items', $cart_items, $invoice );
1382
+    do_action('wpinv_admin_after_line_items', $cart_items, $invoice);
1383 1383
     
1384 1384
     return ob_get_clean();
1385 1385
 }
@@ -1390,35 +1390,35 @@  discard block
 block discarded – undo
1390 1390
     // Set current invoice id.
1391 1391
     $wpi_checkout_id = wpinv_get_invoice_cart_id();
1392 1392
     
1393
-    $form_action  = esc_url( wpinv_get_checkout_uri() );
1393
+    $form_action = esc_url(wpinv_get_checkout_uri());
1394 1394
 
1395 1395
     ob_start();
1396 1396
         echo '<div id="wpinv_checkout_wrap">';
1397 1397
         
1398
-        if ( wpinv_get_cart_contents() || wpinv_cart_has_fees() ) {
1398
+        if (wpinv_get_cart_contents() || wpinv_cart_has_fees()) {
1399 1399
             ?>
1400 1400
             <div id="wpinv_checkout_form_wrap" class="wpinv_clearfix table-responsive">
1401
-                <?php do_action( 'wpinv_before_checkout_form' ); ?>
1401
+                <?php do_action('wpinv_before_checkout_form'); ?>
1402 1402
                 <form id="wpinv_checkout_form" class="wpi-form" action="<?php echo $form_action; ?>" method="POST">
1403 1403
                     <?php
1404
-                    do_action( 'wpinv_checkout_form_top' );
1405
-                    do_action( 'wpinv_checkout_billing_info' );
1406
-                    do_action( 'wpinv_checkout_cart' );
1407
-                    do_action( 'wpinv_payment_mode_select'  );
1408
-                    do_action( 'wpinv_checkout_form_bottom' )
1404
+                    do_action('wpinv_checkout_form_top');
1405
+                    do_action('wpinv_checkout_billing_info');
1406
+                    do_action('wpinv_checkout_cart');
1407
+                    do_action('wpinv_payment_mode_select');
1408
+                    do_action('wpinv_checkout_form_bottom')
1409 1409
                     ?>
1410 1410
                 </form>
1411
-                <?php do_action( 'wpinv_after_purchase_form' ); ?>
1411
+                <?php do_action('wpinv_after_purchase_form'); ?>
1412 1412
             </div><!--end #wpinv_checkout_form_wrap-->
1413 1413
         <?php
1414 1414
         } else {
1415
-            do_action( 'wpinv_cart_empty' );
1415
+            do_action('wpinv_cart_empty');
1416 1416
         }
1417 1417
         echo '</div><!--end #wpinv_checkout_wrap-->';
1418 1418
     return ob_get_clean();
1419 1419
 }
1420 1420
 
1421
-function wpinv_checkout_cart( $cart_details = array(), $echo = true ) {
1421
+function wpinv_checkout_cart($cart_details = array(), $echo = true) {
1422 1422
     global $ajax_cart_details;
1423 1423
     $ajax_cart_details = $cart_details;
1424 1424
     /*
@@ -1433,25 +1433,25 @@  discard block
 block discarded – undo
1433 1433
     }
1434 1434
     */
1435 1435
     ob_start();
1436
-    do_action( 'wpinv_before_checkout_cart' );
1436
+    do_action('wpinv_before_checkout_cart');
1437 1437
     echo '<div id="wpinv_checkout_cart_form" method="post">';
1438 1438
         echo '<div id="wpinv_checkout_cart_wrap">';
1439
-            wpinv_get_template_part( 'wpinv-checkout-cart' );
1439
+            wpinv_get_template_part('wpinv-checkout-cart');
1440 1440
         echo '</div>';
1441 1441
     echo '</div>';
1442
-    do_action( 'wpinv_after_checkout_cart' );
1442
+    do_action('wpinv_after_checkout_cart');
1443 1443
     $content = ob_get_clean();
1444 1444
     
1445
-    if ( $echo ) {
1445
+    if ($echo) {
1446 1446
         echo $content;
1447 1447
     } else {
1448 1448
         return $content;
1449 1449
     }
1450 1450
 }
1451
-add_action( 'wpinv_checkout_cart', 'wpinv_checkout_cart', 10 );
1451
+add_action('wpinv_checkout_cart', 'wpinv_checkout_cart', 10);
1452 1452
 
1453 1453
 function wpinv_empty_cart_message() {
1454
-	return apply_filters( 'wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __( 'Your cart is empty.', 'invoicing' ) . '</span>' );
1454
+	return apply_filters('wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __('Your cart is empty.', 'invoicing') . '</span>');
1455 1455
 }
1456 1456
 
1457 1457
 /**
@@ -1463,91 +1463,91 @@  discard block
 block discarded – undo
1463 1463
 function wpinv_empty_checkout_cart() {
1464 1464
 	echo wpinv_empty_cart_message();
1465 1465
 }
1466
-add_action( 'wpinv_cart_empty', 'wpinv_empty_checkout_cart' );
1466
+add_action('wpinv_cart_empty', 'wpinv_empty_checkout_cart');
1467 1467
 
1468 1468
 function wpinv_save_cart_button() {
1469
-    if ( wpinv_is_cart_saving_disabled() )
1469
+    if (wpinv_is_cart_saving_disabled())
1470 1470
         return;
1471 1471
 ?>
1472
-    <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>
1472
+    <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>
1473 1473
 <?php
1474 1474
 }
1475 1475
 
1476 1476
 function wpinv_update_cart_button() {
1477
-    if ( !wpinv_item_quantities_enabled() )
1477
+    if (!wpinv_item_quantities_enabled())
1478 1478
         return;
1479 1479
 ?>
1480
-    <input type="submit" name="wpinv_update_cart_submit" class="wpinv-submit wpinv-no-js button" value="<?php _e( 'Update Cart', 'invoicing' ); ?>"/>
1480
+    <input type="submit" name="wpinv_update_cart_submit" class="wpinv-submit wpinv-no-js button" value="<?php _e('Update Cart', 'invoicing'); ?>"/>
1481 1481
     <input type="hidden" name="wpi_action" value="update_cart"/>
1482 1482
 <?php
1483 1483
 }
1484 1484
 
1485 1485
 function wpinv_checkout_cart_columns() {
1486 1486
     $default = 3;
1487
-    if ( wpinv_item_quantities_enabled() ) {
1487
+    if (wpinv_item_quantities_enabled()) {
1488 1488
         $default++;
1489 1489
     }
1490 1490
     
1491
-    if ( wpinv_use_taxes() ) {
1491
+    if (wpinv_use_taxes()) {
1492 1492
         $default++;
1493 1493
     }
1494 1494
 
1495
-    return apply_filters( 'wpinv_checkout_cart_columns', $default );
1495
+    return apply_filters('wpinv_checkout_cart_columns', $default);
1496 1496
 }
1497 1497
 
1498 1498
 function wpinv_display_cart_messages() {
1499 1499
     global $wpi_session;
1500 1500
 
1501
-    $messages = $wpi_session->get( 'wpinv_cart_messages' );
1501
+    $messages = $wpi_session->get('wpinv_cart_messages');
1502 1502
 
1503
-    if ( $messages ) {
1504
-        foreach ( $messages as $message_id => $message ) {
1503
+    if ($messages) {
1504
+        foreach ($messages as $message_id => $message) {
1505 1505
             // Try and detect what type of message this is
1506
-            if ( strpos( strtolower( $message ), 'error' ) ) {
1506
+            if (strpos(strtolower($message), 'error')) {
1507 1507
                 $type = 'error';
1508
-            } elseif ( strpos( strtolower( $message ), 'success' ) ) {
1508
+            } elseif (strpos(strtolower($message), 'success')) {
1509 1509
                 $type = 'success';
1510 1510
             } else {
1511 1511
                 $type = 'info';
1512 1512
             }
1513 1513
 
1514
-            $classes = apply_filters( 'wpinv_' . $type . '_class', array( 'wpinv_errors', 'wpinv-alert', 'wpinv-alert-' . $type ) );
1514
+            $classes = apply_filters('wpinv_' . $type . '_class', array('wpinv_errors', 'wpinv-alert', 'wpinv-alert-' . $type));
1515 1515
 
1516
-            echo '<div class="' . implode( ' ', $classes ) . '">';
1516
+            echo '<div class="' . implode(' ', $classes) . '">';
1517 1517
                 // Loop message codes and display messages
1518 1518
                     echo '<p class="wpinv_error" id="wpinv_msg_' . $message_id . '">' . $message . '</p>';
1519 1519
             echo '</div>';
1520 1520
         }
1521 1521
 
1522 1522
         // Remove all of the cart saving messages
1523
-        $wpi_session->set( 'wpinv_cart_messages', null );
1523
+        $wpi_session->set('wpinv_cart_messages', null);
1524 1524
     }
1525 1525
 }
1526
-add_action( 'wpinv_before_checkout_cart', 'wpinv_display_cart_messages' );
1526
+add_action('wpinv_before_checkout_cart', 'wpinv_display_cart_messages');
1527 1527
 
1528 1528
 function wpinv_discount_field() {
1529
-    if ( isset( $_GET['wpi-gateway'] ) && wpinv_is_ajax_disabled() ) {
1529
+    if (isset($_GET['wpi-gateway']) && wpinv_is_ajax_disabled()) {
1530 1530
         return; // Only show before a payment method has been selected if ajax is disabled
1531 1531
     }
1532 1532
 
1533
-    if ( !wpinv_is_checkout() ) {
1533
+    if (!wpinv_is_checkout()) {
1534 1534
         return;
1535 1535
     }
1536 1536
 
1537
-    if ( wpinv_has_active_discounts() && wpinv_get_cart_total() ) {
1537
+    if (wpinv_has_active_discounts() && wpinv_get_cart_total()) {
1538 1538
     ?>
1539 1539
     <div id="wpinv-discount-field" class="panel panel-default">
1540 1540
         <div class="panel-body">
1541 1541
             <p>
1542
-                <label class="wpinv-label" for="wpinv_discount_code"><strong><?php _e( 'Discount', 'invoicing' ); ?></strong></label>
1543
-                <span class="wpinv-description"><?php _e( 'Enter a discount code if you have one.', 'invoicing' ); ?></span>
1542
+                <label class="wpinv-label" for="wpinv_discount_code"><strong><?php _e('Discount', 'invoicing'); ?></strong></label>
1543
+                <span class="wpinv-description"><?php _e('Enter a discount code if you have one.', 'invoicing'); ?></span>
1544 1544
             </p>
1545 1545
             <div class="form-group row">
1546 1546
                 <div class="col-sm-4">
1547
-                    <input class="wpinv-input form-control" type="text" id="wpinv_discount_code" name="wpinv_discount_code" placeholder="<?php _e( 'Enter discount code', 'invoicing' ); ?>"/>
1547
+                    <input class="wpinv-input form-control" type="text" id="wpinv_discount_code" name="wpinv_discount_code" placeholder="<?php _e('Enter discount code', 'invoicing'); ?>"/>
1548 1548
                 </div>
1549 1549
                 <div class="col-sm-3">
1550
-                    <button id="wpi-apply-discount" type="button" class="btn btn-success btn-sm"><?php _e( 'Apply Discount', 'invoicing' ); ?></button>
1550
+                    <button id="wpi-apply-discount" type="button" class="btn btn-success btn-sm"><?php _e('Apply Discount', 'invoicing'); ?></button>
1551 1551
                 </div>
1552 1552
                 <div class="col-sm-12 wpinv-discount-msg">
1553 1553
                     <div class="alert alert-success"><i class="fa fa-check-circle"></i><span class="wpi-msg"></span></div>
@@ -1559,10 +1559,10 @@  discard block
 block discarded – undo
1559 1559
 <?php
1560 1560
     }
1561 1561
 }
1562
-add_action( 'wpinv_after_checkout_cart', 'wpinv_discount_field', -10 );
1562
+add_action('wpinv_after_checkout_cart', 'wpinv_discount_field', -10);
1563 1563
 
1564 1564
 function wpinv_agree_to_terms_js() {
1565
-    if ( wpinv_get_option( 'show_agree_to_terms', false ) ) {
1565
+    if (wpinv_get_option('show_agree_to_terms', false)) {
1566 1566
 ?>
1567 1567
 <script type="text/javascript">
1568 1568
     jQuery(document).ready(function($){
@@ -1577,126 +1577,126 @@  discard block
 block discarded – undo
1577 1577
 <?php
1578 1578
     }
1579 1579
 }
1580
-add_action( 'wpinv_checkout_form_top', 'wpinv_agree_to_terms_js' );
1580
+add_action('wpinv_checkout_form_top', 'wpinv_agree_to_terms_js');
1581 1581
 
1582 1582
 function wpinv_payment_mode_select() {
1583
-    $gateways = wpinv_get_enabled_payment_gateways( true );
1584
-    $gateways = apply_filters( 'wpinv_payment_gateways_on_cart', $gateways );
1583
+    $gateways = wpinv_get_enabled_payment_gateways(true);
1584
+    $gateways = apply_filters('wpinv_payment_gateways_on_cart', $gateways);
1585 1585
     $page_URL = wpinv_get_current_page_url();
1586
-    $invoice = wpinv_get_invoice( 0, true );
1586
+    $invoice = wpinv_get_invoice(0, true);
1587 1587
     
1588 1588
     do_action('wpinv_payment_mode_top');
1589 1589
     $invoice_id = (int)$invoice->ID;
1590
-    $chosen_gateway = wpinv_get_chosen_gateway( $invoice_id );
1590
+    $chosen_gateway = wpinv_get_chosen_gateway($invoice_id);
1591 1591
     ?>
1592
-    <div id="wpinv_payment_mode_select" data-gateway="<?php echo $chosen_gateway; ?>" <?php echo ( $invoice->is_free() ? 'style="display:none;"' : '' ); ?>>
1593
-            <?php do_action( 'wpinv_payment_mode_before_gateways_wrap' ); ?>
1592
+    <div id="wpinv_payment_mode_select" data-gateway="<?php echo $chosen_gateway; ?>" <?php echo ($invoice->is_free() ? 'style="display:none;"' : ''); ?>>
1593
+            <?php do_action('wpinv_payment_mode_before_gateways_wrap'); ?>
1594 1594
             <div id="wpinv-payment-mode-wrap" class="panel panel-default">
1595
-                <div class="panel-heading"><h3 class="panel-title"><?php _e( 'Select Payment Method', 'invoicing' ); ?></h3></div>
1595
+                <div class="panel-heading"><h3 class="panel-title"><?php _e('Select Payment Method', 'invoicing'); ?></h3></div>
1596 1596
                 <div class="panel-body list-group wpi-payment_methods">
1597 1597
                     <?php
1598
-                    do_action( 'wpinv_payment_mode_before_gateways' );
1598
+                    do_action('wpinv_payment_mode_before_gateways');
1599 1599
                     
1600
-                    if(!empty($gateways)){
1601
-	                    foreach ( $gateways as $gateway_id => $gateway ) {
1602
-		                    $checked = checked( $gateway_id, $chosen_gateway, false );
1603
-		                    $button_label = wpinv_get_gateway_button_label( $gateway_id );
1604
-		                    $description = wpinv_get_gateway_description( $gateway_id );
1600
+                    if (!empty($gateways)) {
1601
+	                    foreach ($gateways as $gateway_id => $gateway) {
1602
+		                    $checked = checked($gateway_id, $chosen_gateway, false);
1603
+		                    $button_label = wpinv_get_gateway_button_label($gateway_id);
1604
+		                    $description = wpinv_get_gateway_description($gateway_id);
1605 1605
 		                    ?>
1606 1606
 		                    <div class="list-group-item">
1607 1607
 			                    <div class="radio">
1608
-				                    <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>
1608
+				                    <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>
1609 1609
 			                    </div>
1610
-			                    <div style="display:none;" class="payment_box wpi_gateway_<?php echo esc_attr( $gateway_id );?>" role="alert">
1611
-				                    <?php if ( !empty( $description ) ) { ?>
1612
-					                    <div class="wpi-gateway-desc alert alert-info"><?php echo $description;?></div>
1610
+			                    <div style="display:none;" class="payment_box wpi_gateway_<?php echo esc_attr($gateway_id); ?>" role="alert">
1611
+				                    <?php if (!empty($description)) { ?>
1612
+					                    <div class="wpi-gateway-desc alert alert-info"><?php echo $description; ?></div>
1613 1613
 				                    <?php } ?>
1614
-				                    <?php do_action( 'wpinv_' . $gateway_id . '_cc_form', $invoice_id ) ;?>
1614
+				                    <?php do_action('wpinv_' . $gateway_id . '_cc_form', $invoice_id); ?>
1615 1615
 			                    </div>
1616 1616
 		                    </div>
1617 1617
 		                    <?php
1618 1618
 	                    }
1619
-                    }else{
1620
-	                    echo '<div class="alert alert-warning">'. __('No payment gateway active','invoicing') .'</div>';
1619
+                    } else {
1620
+	                    echo '<div class="alert alert-warning">' . __('No payment gateway active', 'invoicing') . '</div>';
1621 1621
                     }
1622 1622
 
1623
-                    do_action( 'wpinv_payment_mode_after_gateways' );
1623
+                    do_action('wpinv_payment_mode_after_gateways');
1624 1624
                     ?>
1625 1625
                 </div>
1626 1626
             </div>
1627
-            <?php do_action( 'wpinv_payment_mode_after_gateways_wrap' ); ?>
1627
+            <?php do_action('wpinv_payment_mode_after_gateways_wrap'); ?>
1628 1628
     </div>
1629 1629
     <?php
1630 1630
     do_action('wpinv_payment_mode_bottom');
1631 1631
 }
1632
-add_action( 'wpinv_payment_mode_select', 'wpinv_payment_mode_select' );
1632
+add_action('wpinv_payment_mode_select', 'wpinv_payment_mode_select');
1633 1633
 
1634 1634
 function wpinv_checkout_billing_info() {    
1635
-    if ( wpinv_is_checkout() ) {
1635
+    if (wpinv_is_checkout()) {
1636 1636
         $logged_in          = is_user_logged_in();
1637 1637
         $billing_details    = wpinv_checkout_billing_details();
1638
-        $selected_country   = !empty( $billing_details['country'] ) ? $billing_details['country'] : wpinv_default_billing_country();
1638
+        $selected_country   = !empty($billing_details['country']) ? $billing_details['country'] : wpinv_default_billing_country();
1639 1639
         ?>
1640 1640
         <div id="wpinv-fields" class="clearfix">
1641 1641
             <div id="wpi-billing" class="wpi-billing clearfix panel panel-default">
1642
-                <div class="panel-heading"><h3 class="panel-title"><?php _e( 'Billing Details', 'invoicing' );?></h3></div>
1642
+                <div class="panel-heading"><h3 class="panel-title"><?php _e('Billing Details', 'invoicing'); ?></h3></div>
1643 1643
                 <div id="wpinv-fields-box" class="panel-body">
1644
-                    <?php do_action( 'wpinv_checkout_billing_fields_first', $billing_details ); ?>
1644
+                    <?php do_action('wpinv_checkout_billing_fields_first', $billing_details); ?>
1645 1645
                     <p class="wpi-cart-field wpi-col2 wpi-colf">
1646
-                        <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>
1646
+                        <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>
1647 1647
                         <?php
1648
-                        echo wpinv_html_text( array(
1648
+                        echo wpinv_html_text(array(
1649 1649
                                 'id'            => 'wpinv_first_name',
1650 1650
                                 'name'          => 'wpinv_first_name',
1651 1651
                                 'value'         => $billing_details['first_name'],
1652 1652
                                 'class'         => 'wpi-input form-control required',
1653
-                                'placeholder'   => __( 'First name', 'invoicing' ),
1654
-                                'required'      => (bool)wpinv_get_option( 'fname_mandatory' ),
1655
-                            ) );
1653
+                                'placeholder'   => __('First name', 'invoicing'),
1654
+                                'required'      => (bool)wpinv_get_option('fname_mandatory'),
1655
+                            ));
1656 1656
                         ?>
1657 1657
                     </p>
1658 1658
                     <p class="wpi-cart-field wpi-col2 wpi-coll">
1659
-                        <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>
1659
+                        <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>
1660 1660
                         <?php
1661
-                        echo wpinv_html_text( array(
1661
+                        echo wpinv_html_text(array(
1662 1662
                                 'id'            => 'wpinv_last_name',
1663 1663
                                 'name'          => 'wpinv_last_name',
1664 1664
                                 'value'         => $billing_details['last_name'],
1665 1665
                                 'class'         => 'wpi-input form-control',
1666
-                                'placeholder'   => __( 'Last name', 'invoicing' ),
1667
-                                'required'      => (bool)wpinv_get_option( 'lname_mandatory' ),
1668
-                            ) );
1666
+                                'placeholder'   => __('Last name', 'invoicing'),
1667
+                                'required'      => (bool)wpinv_get_option('lname_mandatory'),
1668
+                            ));
1669 1669
                         ?>
1670 1670
                     </p>
1671 1671
                     <p class="wpi-cart-field wpi-col2 wpi-colf">
1672
-                        <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>
1672
+                        <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>
1673 1673
                         <?php
1674
-                        echo wpinv_html_text( array(
1674
+                        echo wpinv_html_text(array(
1675 1675
                                 'id'            => 'wpinv_address',
1676 1676
                                 'name'          => 'wpinv_address',
1677 1677
                                 'value'         => $billing_details['address'],
1678 1678
                                 'class'         => 'wpi-input form-control required',
1679
-                                'placeholder'   => __( 'Address', 'invoicing' ),
1680
-                                'required'      => (bool)wpinv_get_option( 'address_mandatory' ),
1681
-                            ) );
1679
+                                'placeholder'   => __('Address', 'invoicing'),
1680
+                                'required'      => (bool)wpinv_get_option('address_mandatory'),
1681
+                            ));
1682 1682
                         ?>
1683 1683
                     </p>
1684 1684
                     <p class="wpi-cart-field wpi-col2 wpi-coll">
1685
-                        <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>
1685
+                        <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>
1686 1686
                         <?php
1687
-                        echo wpinv_html_text( array(
1687
+                        echo wpinv_html_text(array(
1688 1688
                                 'id'            => 'wpinv_city',
1689 1689
                                 'name'          => 'wpinv_city',
1690 1690
                                 'value'         => $billing_details['city'],
1691 1691
                                 'class'         => 'wpi-input form-control required',
1692
-                                'placeholder'   => __( 'City', 'invoicing' ),
1693
-                                'required'      => (bool)wpinv_get_option( 'city_mandatory' ),
1694
-                            ) );
1692
+                                'placeholder'   => __('City', 'invoicing'),
1693
+                                'required'      => (bool)wpinv_get_option('city_mandatory'),
1694
+                            ));
1695 1695
                         ?>
1696 1696
                     </p>
1697 1697
                     <p id="wpinv_country_box" class="wpi-cart-field wpi-col2 wpi-colf">
1698
-                        <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>
1699
-                        <?php echo wpinv_html_select( array(
1698
+                        <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>
1699
+                        <?php echo wpinv_html_select(array(
1700 1700
                             'options'          => wpinv_get_country_list(),
1701 1701
                             'name'             => 'wpinv_country',
1702 1702
                             'id'               => 'wpinv_country',
@@ -1704,16 +1704,16 @@  discard block
 block discarded – undo
1704 1704
                             'show_option_all'  => false,
1705 1705
                             'show_option_none' => false,
1706 1706
                             'class'            => 'wpi-input form-control required',
1707
-                            'placeholder'      => __( 'Choose a country', 'invoicing' ),
1708
-                            'required'          => (bool)wpinv_get_option( 'country_mandatory' ),
1709
-                        ) ); ?>
1707
+                            'placeholder'      => __('Choose a country', 'invoicing'),
1708
+                            'required'          => (bool)wpinv_get_option('country_mandatory'),
1709
+                        )); ?>
1710 1710
                     </p>
1711 1711
                     <p id="wpinv_state_box" class="wpi-cart-field wpi-col2 wpi-coll">
1712
-                        <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>
1712
+                        <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>
1713 1713
                         <?php
1714
-                        $states = wpinv_get_country_states( $selected_country );
1715
-                        if( !empty( $states ) ) {
1716
-                            echo wpinv_html_select( array(
1714
+                        $states = wpinv_get_country_states($selected_country);
1715
+                        if (!empty($states)) {
1716
+                            echo wpinv_html_select(array(
1717 1717
                                 'options'          => $states,
1718 1718
                                 'name'             => 'wpinv_state',
1719 1719
                                 'id'               => 'wpinv_state',
@@ -1721,61 +1721,61 @@  discard block
 block discarded – undo
1721 1721
                                 'show_option_all'  => false,
1722 1722
                                 'show_option_none' => false,
1723 1723
                                 'class'            => 'wpi-input form-control required',
1724
-                                'placeholder'      => __( 'Choose a state', 'invoicing' ),
1725
-                                'required'         => (bool)wpinv_get_option( 'state_mandatory' ),
1726
-                            ) );
1724
+                                'placeholder'      => __('Choose a state', 'invoicing'),
1725
+                                'required'         => (bool)wpinv_get_option('state_mandatory'),
1726
+                            ));
1727 1727
                         } else {
1728
-                            echo wpinv_html_text( array(
1728
+                            echo wpinv_html_text(array(
1729 1729
                                 'name'          => 'wpinv_state',
1730 1730
                                 'value'         => $billing_details['state'],
1731 1731
                                 'id'            => 'wpinv_state',
1732 1732
                                 'class'         => 'wpi-input form-control required',
1733
-                                'placeholder'   => __( 'State / Province', 'invoicing' ),
1734
-                                'required'      => (bool)wpinv_get_option( 'state_mandatory' ),
1735
-                            ) );
1733
+                                'placeholder'   => __('State / Province', 'invoicing'),
1734
+                                'required'      => (bool)wpinv_get_option('state_mandatory'),
1735
+                            ));
1736 1736
                         }
1737 1737
                         ?>
1738 1738
                     </p>
1739 1739
                     <p class="wpi-cart-field wpi-col2 wpi-colf">
1740
-                        <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>
1740
+                        <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>
1741 1741
                         <?php
1742
-                        echo wpinv_html_text( array(
1742
+                        echo wpinv_html_text(array(
1743 1743
                                 'name'          => 'wpinv_zip',
1744 1744
                                 'value'         => $billing_details['zip'],
1745 1745
                                 'id'            => 'wpinv_zip',
1746 1746
                                 'class'         => 'wpi-input form-control',
1747
-                                'placeholder'   => __( 'ZIP / Postcode', 'invoicing' ),
1748
-                                'required'      => (bool)wpinv_get_option( 'zip_mandatory' ),
1749
-                            ) );
1747
+                                'placeholder'   => __('ZIP / Postcode', 'invoicing'),
1748
+                                'required'      => (bool)wpinv_get_option('zip_mandatory'),
1749
+                            ));
1750 1750
                         ?>
1751 1751
                     </p>
1752 1752
                     <p class="wpi-cart-field wpi-col2 wpi-coll">
1753
-                        <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>
1753
+                        <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>
1754 1754
                         <?php
1755
-                        echo wpinv_html_text( array(
1755
+                        echo wpinv_html_text(array(
1756 1756
                                 'id'            => 'wpinv_phone',
1757 1757
                                 'name'          => 'wpinv_phone',
1758 1758
                                 'value'         => $billing_details['phone'],
1759 1759
                                 'class'         => 'wpi-input form-control',
1760
-                                'placeholder'   => __( 'Phone', 'invoicing' ),
1761
-                                'required'      => (bool)wpinv_get_option( 'phone_mandatory' ),
1762
-                            ) );
1760
+                                'placeholder'   => __('Phone', 'invoicing'),
1761
+                                'required'      => (bool)wpinv_get_option('phone_mandatory'),
1762
+                            ));
1763 1763
                         ?>
1764 1764
                     </p>
1765
-                    <?php do_action( 'wpinv_checkout_billing_fields_last', $billing_details ); ?>
1765
+                    <?php do_action('wpinv_checkout_billing_fields_last', $billing_details); ?>
1766 1766
                     <div class="clearfix"></div>
1767 1767
                 </div>
1768 1768
             </div>
1769
-            <?php do_action( 'wpinv_after_billing_fields', $billing_details ); ?>
1769
+            <?php do_action('wpinv_after_billing_fields', $billing_details); ?>
1770 1770
         </div>
1771 1771
         <?php
1772 1772
     }
1773 1773
 }
1774
-add_action( 'wpinv_checkout_billing_info', 'wpinv_checkout_billing_info' );
1774
+add_action('wpinv_checkout_billing_info', 'wpinv_checkout_billing_info');
1775 1775
 
1776 1776
 function wpinv_checkout_hidden_fields() {
1777 1777
 ?>
1778
-    <?php if ( is_user_logged_in() ) { ?>
1778
+    <?php if (is_user_logged_in()) { ?>
1779 1779
     <input type="hidden" name="wpinv_user_id" value="<?php echo get_current_user_id(); ?>"/>
1780 1780
     <?php } ?>
1781 1781
     <input type="hidden" name="wpi_action" value="payment" />
@@ -1785,9 +1785,9 @@  discard block
 block discarded – undo
1785 1785
 function wpinv_checkout_button_purchase() {
1786 1786
     ob_start();
1787 1787
 ?>
1788
-    <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' ) ?>"/>
1788
+    <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') ?>"/>
1789 1789
 <?php
1790
-    return apply_filters( 'wpinv_checkout_button_purchase', ob_get_clean() );
1790
+    return apply_filters('wpinv_checkout_button_purchase', ob_get_clean());
1791 1791
 }
1792 1792
 
1793 1793
 function wpinv_checkout_total() {
@@ -1796,96 +1796,96 @@  discard block
 block discarded – undo
1796 1796
 <div id="wpinv_checkout_total" class="panel panel-info">
1797 1797
     <div class="panel-body">
1798 1798
     <?php
1799
-    do_action( 'wpinv_purchase_form_before_checkout_total' );
1799
+    do_action('wpinv_purchase_form_before_checkout_total');
1800 1800
     ?>
1801
-    <strong><?php _e( 'Invoice Total:', 'invoicing' ) ?></strong> <span class="wpinv-chdeckout-total"><?php echo $cart_total;?></span>
1801
+    <strong><?php _e('Invoice Total:', 'invoicing') ?></strong> <span class="wpinv-chdeckout-total"><?php echo $cart_total; ?></span>
1802 1802
     <?php
1803
-    do_action( 'wpinv_purchase_form_after_checkout_total' );
1803
+    do_action('wpinv_purchase_form_after_checkout_total');
1804 1804
     ?>
1805 1805
     </div>
1806 1806
 </div>
1807 1807
 <?php
1808 1808
 }
1809
-add_action( 'wpinv_checkout_form_bottom', 'wpinv_checkout_total', 9998 );
1809
+add_action('wpinv_checkout_form_bottom', 'wpinv_checkout_total', 9998);
1810 1810
 
1811 1811
 function wpinv_checkout_submit() {
1812 1812
 ?>
1813 1813
 <div id="wpinv_purchase_submit" class="panel panel-success">
1814 1814
     <div class="panel-body text-center">
1815 1815
     <?php
1816
-    do_action( 'wpinv_purchase_form_before_submit' );
1816
+    do_action('wpinv_purchase_form_before_submit');
1817 1817
     wpinv_checkout_hidden_fields();
1818 1818
     echo wpinv_checkout_button_purchase();
1819
-    do_action( 'wpinv_purchase_form_after_submit' );
1819
+    do_action('wpinv_purchase_form_after_submit');
1820 1820
     ?>
1821 1821
     </div>
1822 1822
 </div>
1823 1823
 <?php
1824 1824
 }
1825
-add_action( 'wpinv_checkout_form_bottom', 'wpinv_checkout_submit', 9999 );
1825
+add_action('wpinv_checkout_form_bottom', 'wpinv_checkout_submit', 9999);
1826 1826
 
1827
-function wpinv_receipt_billing_address( $invoice_id = 0 ) {
1828
-    $invoice = wpinv_get_invoice( $invoice_id );
1827
+function wpinv_receipt_billing_address($invoice_id = 0) {
1828
+    $invoice = wpinv_get_invoice($invoice_id);
1829 1829
     
1830
-    if ( empty( $invoice ) ) {
1830
+    if (empty($invoice)) {
1831 1831
         return NULL;
1832 1832
     }
1833 1833
     
1834 1834
     $billing_details = $invoice->get_user_info();
1835 1835
     $address_row = '';
1836
-    if ( $address = $billing_details['address'] ) {
1837
-        $address_row .= wpautop( wp_kses_post( $address ) );
1836
+    if ($address = $billing_details['address']) {
1837
+        $address_row .= wpautop(wp_kses_post($address));
1838 1838
     }
1839 1839
     
1840 1840
     $address_fields = array();
1841
-    if ( !empty( $billing_details['city'] ) ) {
1841
+    if (!empty($billing_details['city'])) {
1842 1842
         $address_fields[] = $billing_details['city'];
1843 1843
     }
1844 1844
     
1845
-    $billing_country = !empty( $billing_details['country'] ) ? $billing_details['country'] : '';
1846
-    if ( !empty( $billing_details['state'] ) ) {
1847
-        $address_fields[] = wpinv_state_name( $billing_details['state'], $billing_country );
1845
+    $billing_country = !empty($billing_details['country']) ? $billing_details['country'] : '';
1846
+    if (!empty($billing_details['state'])) {
1847
+        $address_fields[] = wpinv_state_name($billing_details['state'], $billing_country);
1848 1848
     }
1849 1849
     
1850
-    if ( !empty( $billing_country ) ) {
1851
-        $address_fields[] = wpinv_country_name( $billing_country );
1850
+    if (!empty($billing_country)) {
1851
+        $address_fields[] = wpinv_country_name($billing_country);
1852 1852
     }
1853 1853
     
1854
-    if ( !empty( $address_fields ) ) {
1855
-        $address_fields = implode( ", ", $address_fields );
1854
+    if (!empty($address_fields)) {
1855
+        $address_fields = implode(", ", $address_fields);
1856 1856
         
1857
-        if ( !empty( $billing_details['zip'] ) ) {
1857
+        if (!empty($billing_details['zip'])) {
1858 1858
             $address_fields .= ' ' . $billing_details['zip'];
1859 1859
         }
1860 1860
         
1861
-        $address_row .= wpautop( wp_kses_post( $address_fields ) );
1861
+        $address_row .= wpautop(wp_kses_post($address_fields));
1862 1862
     }
1863 1863
     ob_start();
1864 1864
     ?>
1865 1865
     <table class="table table-bordered table-sm wpi-billing-details">
1866 1866
         <tbody>
1867 1867
             <tr class="wpi-receipt-name">
1868
-                <th class="text-left"><?php _e( 'Name', 'invoicing' ); ?></th>
1869
-                <td><?php echo esc_html( trim( $billing_details['first_name'] . ' ' . $billing_details['last_name'] ) ) ;?></td>
1868
+                <th class="text-left"><?php _e('Name', 'invoicing'); ?></th>
1869
+                <td><?php echo esc_html(trim($billing_details['first_name'] . ' ' . $billing_details['last_name'])); ?></td>
1870 1870
             </tr>
1871 1871
             <tr class="wpi-receipt-email">
1872
-                <th class="text-left"><?php _e( 'Email', 'invoicing' ); ?></th>
1873
-                <td><?php echo $billing_details['email'] ;?></td>
1872
+                <th class="text-left"><?php _e('Email', 'invoicing'); ?></th>
1873
+                <td><?php echo $billing_details['email']; ?></td>
1874 1874
             </tr>
1875
-            <?php if ( $billing_details['company'] ) { ?>
1875
+            <?php if ($billing_details['company']) { ?>
1876 1876
             <tr class="wpi-receipt-company">
1877
-                <th class="text-left"><?php _e( 'Company', 'invoicing' ); ?></th>
1878
-                <td><?php echo esc_html( $billing_details['company'] ) ;?></td>
1877
+                <th class="text-left"><?php _e('Company', 'invoicing'); ?></th>
1878
+                <td><?php echo esc_html($billing_details['company']); ?></td>
1879 1879
             </tr>
1880 1880
             <?php } ?>
1881 1881
             <tr class="wpi-receipt-address">
1882
-                <th class="text-left"><?php _e( 'Address', 'invoicing' ); ?></th>
1883
-                <td><?php echo $address_row ;?></td>
1882
+                <th class="text-left"><?php _e('Address', 'invoicing'); ?></th>
1883
+                <td><?php echo $address_row; ?></td>
1884 1884
             </tr>
1885
-            <?php if ( $billing_details['phone'] ) { ?>
1885
+            <?php if ($billing_details['phone']) { ?>
1886 1886
             <tr class="wpi-receipt-phone">
1887
-                <th class="text-left"><?php _e( 'Phone', 'invoicing' ); ?></th>
1888
-                <td><?php echo esc_html( $billing_details['phone'] ) ;?></td>
1887
+                <th class="text-left"><?php _e('Phone', 'invoicing'); ?></th>
1888
+                <td><?php echo esc_html($billing_details['phone']); ?></td>
1889 1889
             </tr>
1890 1890
             <?php } ?>
1891 1891
         </tbody>
@@ -1893,98 +1893,98 @@  discard block
 block discarded – undo
1893 1893
     <?php
1894 1894
     $output = ob_get_clean();
1895 1895
     
1896
-    $output = apply_filters( 'wpinv_receipt_billing_address', $output, $invoice_id );
1896
+    $output = apply_filters('wpinv_receipt_billing_address', $output, $invoice_id);
1897 1897
 
1898 1898
     echo $output;
1899 1899
 }
1900 1900
 
1901
-function wpinv_filter_success_page_content( $content ) {
1902
-    if ( isset( $_GET['payment-confirm'] ) && wpinv_is_success_page() ) {
1903
-        if ( has_filter( 'wpinv_payment_confirm_' . sanitize_text_field( $_GET['payment-confirm'] ) ) ) {
1904
-            $content = apply_filters( 'wpinv_payment_confirm_' . sanitize_text_field( $_GET['payment-confirm'] ), $content );
1901
+function wpinv_filter_success_page_content($content) {
1902
+    if (isset($_GET['payment-confirm']) && wpinv_is_success_page()) {
1903
+        if (has_filter('wpinv_payment_confirm_' . sanitize_text_field($_GET['payment-confirm']))) {
1904
+            $content = apply_filters('wpinv_payment_confirm_' . sanitize_text_field($_GET['payment-confirm']), $content);
1905 1905
         }
1906 1906
     }
1907 1907
 
1908 1908
     return $content;
1909 1909
 }
1910
-add_filter( 'the_content', 'wpinv_filter_success_page_content', 99999 );
1910
+add_filter('the_content', 'wpinv_filter_success_page_content', 99999);
1911 1911
 
1912
-function wpinv_receipt_actions( $invoice ) {
1913
-    if ( !empty( $invoice ) ) {
1912
+function wpinv_receipt_actions($invoice) {
1913
+    if (!empty($invoice)) {
1914 1914
         $actions = array(
1915 1915
             'print'   => array(
1916 1916
                 'url'  => $invoice->get_view_url(),
1917
-                'name' => __( 'Print Invoice', 'invoicing' ),
1917
+                'name' => __('Print Invoice', 'invoicing'),
1918 1918
                 'class' => 'btn-primary',
1919 1919
             ),
1920 1920
             'history'   => array(
1921 1921
                 'url'  => wpinv_get_history_page_uri(),
1922
-                'name' => __( 'Invoice History', 'invoicing' ),
1922
+                'name' => __('Invoice History', 'invoicing'),
1923 1923
                 'class' => 'btn-warning',
1924 1924
             )
1925 1925
         );
1926 1926
 
1927
-        $actions = apply_filters( 'wpinv_invoice_receipt_actions', $actions, $invoice );
1927
+        $actions = apply_filters('wpinv_invoice_receipt_actions', $actions, $invoice);
1928 1928
         
1929
-        if ( !empty( $actions ) ) {
1929
+        if (!empty($actions)) {
1930 1930
         ?>
1931 1931
         <div class="wpinv-receipt-actions text-right">
1932
-            <?php foreach ( $actions as $key => $action ) { $class = !empty($action['class']) ? sanitize_html_class( $action['class'] ) : ''; ?>
1933
-            <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>
1932
+            <?php foreach ($actions as $key => $action) { $class = !empty($action['class']) ? sanitize_html_class($action['class']) : ''; ?>
1933
+            <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>
1934 1934
             <?php } ?>
1935 1935
         </div>
1936 1936
         <?php
1937 1937
         }
1938 1938
     }
1939 1939
 }
1940
-add_action( 'wpinv_receipt_start', 'wpinv_receipt_actions', -10, 1 );
1940
+add_action('wpinv_receipt_start', 'wpinv_receipt_actions', -10, 1);
1941 1941
 
1942
-function wpinv_invoice_link( $invoice_id ) {
1943
-    $invoice = wpinv_get_invoice( $invoice_id );
1942
+function wpinv_invoice_link($invoice_id) {
1943
+    $invoice = wpinv_get_invoice($invoice_id);
1944 1944
     
1945
-    if ( empty( $invoice ) ) {
1945
+    if (empty($invoice)) {
1946 1946
         return NULL;
1947 1947
     }
1948 1948
     
1949
-    $invoice_link = '<a href="' . esc_url( $invoice->get_view_url() ) . '">' . $invoice->get_number() . '</a>';
1949
+    $invoice_link = '<a href="' . esc_url($invoice->get_view_url()) . '">' . $invoice->get_number() . '</a>';
1950 1950
     
1951
-    return apply_filters( 'wpinv_get_invoice_link', $invoice_link, $invoice );
1951
+    return apply_filters('wpinv_get_invoice_link', $invoice_link, $invoice);
1952 1952
 }
1953 1953
 
1954
-function wpinv_invoice_subscription_details( $invoice ) {
1955
-    if ( !empty( $invoice ) && $invoice->is_recurring() && !wpinv_is_subscription_payment( $invoice ) ) {
1954
+function wpinv_invoice_subscription_details($invoice) {
1955
+    if (!empty($invoice) && $invoice->is_recurring() && !wpinv_is_subscription_payment($invoice)) {
1956 1956
         $total_payments = (int)$invoice->get_total_payments();
1957 1957
         $payments       = $invoice->get_child_payments();
1958 1958
         
1959 1959
         $subscription   = $invoice->get_subscription_data();
1960 1960
         
1961
-        if ( !( !empty( $subscription ) && !empty( $subscription['item_id'] ) ) ) {
1961
+        if (!(!empty($subscription) && !empty($subscription['item_id']))) {
1962 1962
             return;
1963 1963
         }
1964 1964
         
1965
-        $billing_cycle  = wpinv_get_billing_cycle( $subscription['initial_amount'], $subscription['recurring_amount'], $subscription['period'], $subscription['interval'], $subscription['bill_times'], $subscription['trial_period'], $subscription['trial_interval'], $invoice->get_currency() );
1966
-        $times_billed   = $total_payments . ' / ' . ( ( (int)$subscription['bill_times'] == 0 ) ? __( 'Until cancelled', 'invoicing' ) : $subscription['bill_times'] );
1965
+        $billing_cycle  = wpinv_get_billing_cycle($subscription['initial_amount'], $subscription['recurring_amount'], $subscription['period'], $subscription['interval'], $subscription['bill_times'], $subscription['trial_period'], $subscription['trial_interval'], $invoice->get_currency());
1966
+        $times_billed   = $total_payments . ' / ' . (((int)$subscription['bill_times'] == 0) ? __('Until cancelled', 'invoicing') : $subscription['bill_times']);
1967 1967
         
1968 1968
         $subscription_status = $invoice->get_subscription_status();
1969 1969
         
1970 1970
         $status_desc = '';
1971
-        if ( $subscription_status == 'trialing' && $trial_end_date = $invoice->get_trial_end_date() ) {
1972
-            $status_desc = wp_sprintf( __( 'Until: %s', 'invoicing' ), $trial_end_date );
1973
-        } else if ( $subscription_status == 'cancelled' && $cancelled_date = $invoice->get_cancelled_date() ) {
1974
-            $status_desc = wp_sprintf( __( 'On: %s', 'invoicing' ), $cancelled_date );
1971
+        if ($subscription_status == 'trialing' && $trial_end_date = $invoice->get_trial_end_date()) {
1972
+            $status_desc = wp_sprintf(__('Until: %s', 'invoicing'), $trial_end_date);
1973
+        } else if ($subscription_status == 'cancelled' && $cancelled_date = $invoice->get_cancelled_date()) {
1974
+            $status_desc = wp_sprintf(__('On: %s', 'invoicing'), $cancelled_date);
1975 1975
         }
1976 1976
         $status_desc = $status_desc != '' ? '<span class="meta">' . $status_desc . '</span>' : '';
1977 1977
         ?>
1978 1978
         <div class="wpinv-subscriptions-details">
1979
-            <h3 class="wpinv-subscriptions-t"><?php echo apply_filters( 'wpinv_subscription_details_title', __( 'Subscription Details', 'invoicing' ) ); ?></h3>
1979
+            <h3 class="wpinv-subscriptions-t"><?php echo apply_filters('wpinv_subscription_details_title', __('Subscription Details', 'invoicing')); ?></h3>
1980 1980
             <table class="table">
1981 1981
                 <thead>
1982 1982
                     <tr>
1983
-                        <th><?php _e( 'Billing Cycle', 'invoicing' ) ;?></th>
1984
-                        <th><?php _e( 'Start Date', 'invoicing' ) ;?></th>
1985
-                        <th><?php _e( 'Expiration Date', 'invoicing' ) ;?></th>
1986
-                        <th class="text-center"><?php _e( 'Times Billed', 'invoicing' ) ;?></th>
1987
-                        <th class="text-center"><?php _e( 'Status', 'invoicing' ) ;?></th>
1983
+                        <th><?php _e('Billing Cycle', 'invoicing'); ?></th>
1984
+                        <th><?php _e('Start Date', 'invoicing'); ?></th>
1985
+                        <th><?php _e('Expiration Date', 'invoicing'); ?></th>
1986
+                        <th class="text-center"><?php _e('Times Billed', 'invoicing'); ?></th>
1987
+                        <th class="text-center"><?php _e('Status', 'invoicing'); ?></th>
1988 1988
                     </tr>
1989 1989
                 </thead>
1990 1990
                 <tbody>
@@ -1993,32 +1993,32 @@  discard block
 block discarded – undo
1993 1993
                         <td><?php echo $invoice->get_subscription_start(); ?></td>
1994 1994
                         <td><?php echo $invoice->get_subscription_end(); ?></td>
1995 1995
                         <td class="text-center"><?php echo $times_billed; ?></td>
1996
-                        <td class="text-center wpi-sub-status"><?php echo $invoice->get_subscription_status_label() ;?>
1996
+                        <td class="text-center wpi-sub-status"><?php echo $invoice->get_subscription_status_label(); ?>
1997 1997
                         <?php echo $status_desc; ?>
1998 1998
                         </td>
1999 1999
                     </tr>
2000 2000
                 </tbody>
2001 2001
             </table>
2002 2002
         </div>
2003
-        <?php if ( !empty( $payments ) ) { ?>
2003
+        <?php if (!empty($payments)) { ?>
2004 2004
         <div class="wpinv-renewal-payments">
2005
-            <h3 class="wpinv-renewals-t"><?php echo apply_filters( 'wpinv_renewal_payments_title', __( 'Renewal Payments', 'invoicing' ) ); ?></h3>
2005
+            <h3 class="wpinv-renewals-t"><?php echo apply_filters('wpinv_renewal_payments_title', __('Renewal Payments', 'invoicing')); ?></h3>
2006 2006
             <table class="table">
2007 2007
                 <thead>
2008 2008
                     <tr>
2009 2009
                         <th>#</th>
2010
-                        <th><?php _e( 'Invoice', 'invoicing' ) ;?></th>
2011
-                        <th><?php _e( 'Date', 'invoicing' ) ;?></th>
2012
-                        <th class="text-right"><?php _e( 'Amount', 'invoicing' ) ;?></th>
2010
+                        <th><?php _e('Invoice', 'invoicing'); ?></th>
2011
+                        <th><?php _e('Date', 'invoicing'); ?></th>
2012
+                        <th class="text-right"><?php _e('Amount', 'invoicing'); ?></th>
2013 2013
                     </tr>
2014 2014
                 </thead>
2015 2015
                 <tbody>
2016
-                    <?php foreach ( $payments as $key => $invoice_id ) { ?>
2016
+                    <?php foreach ($payments as $key => $invoice_id) { ?>
2017 2017
                     <tr>
2018
-                        <th scope="row"><?php echo ( $key + 1 );?></th>
2019
-                        <td><?php echo wpinv_invoice_link( $invoice_id ) ;?></td>
2020
-                        <td><?php echo wpinv_get_invoice_date( $invoice_id ); ?></td>
2021
-                        <td class="text-right"><?php echo wpinv_payment_total( $invoice_id, true ); ?></td>
2018
+                        <th scope="row"><?php echo ($key + 1); ?></th>
2019
+                        <td><?php echo wpinv_invoice_link($invoice_id); ?></td>
2020
+                        <td><?php echo wpinv_get_invoice_date($invoice_id); ?></td>
2021
+                        <td class="text-right"><?php echo wpinv_payment_total($invoice_id, true); ?></td>
2022 2022
                     </tr>
2023 2023
                     <?php } ?>
2024 2024
                     <tr><td colspan="4" style="padding:0"></td></tr>
@@ -2030,52 +2030,52 @@  discard block
 block discarded – undo
2030 2030
     }
2031 2031
 }
2032 2032
 
2033
-function wpinv_cart_total_label( $label, $invoice ) {
2034
-    if ( empty( $invoice ) ) {
2033
+function wpinv_cart_total_label($label, $invoice) {
2034
+    if (empty($invoice)) {
2035 2035
         return $label;
2036 2036
     }
2037 2037
     
2038 2038
     $prefix_label = '';
2039
-    if ( $invoice->is_parent() && $item_id = $invoice->get_recurring() ) {        
2040
-        $prefix_label   = '<span class="label label-primary label-recurring">' . __( 'Recurring Payment', 'invoicing' ) . '</span> ' . wpinv_subscription_payment_desc( $invoice );
2041
-    } else if ( $invoice->is_renewal() ) {
2042
-        $prefix_label   = '<span class="label label-primary label-renewal">' . __( 'Renewal Payment', 'invoicing' ) . '</span> ';        
2039
+    if ($invoice->is_parent() && $item_id = $invoice->get_recurring()) {        
2040
+        $prefix_label   = '<span class="label label-primary label-recurring">' . __('Recurring Payment', 'invoicing') . '</span> ' . wpinv_subscription_payment_desc($invoice);
2041
+    } else if ($invoice->is_renewal()) {
2042
+        $prefix_label   = '<span class="label label-primary label-renewal">' . __('Renewal Payment', 'invoicing') . '</span> ';        
2043 2043
     }
2044 2044
     
2045
-    if ( $prefix_label != '' ) {
2046
-        $label  = '<span class="wpinv-cart-sub-desc">' . $prefix_label . '</span> ' . $label;
2045
+    if ($prefix_label != '') {
2046
+        $label = '<span class="wpinv-cart-sub-desc">' . $prefix_label . '</span> ' . $label;
2047 2047
     }
2048 2048
     
2049 2049
     return $label;
2050 2050
 }
2051
-add_filter( 'wpinv_cart_total_label', 'wpinv_cart_total_label', 10, 2 );
2052
-add_filter( 'wpinv_email_cart_total_label', 'wpinv_cart_total_label', 10, 2 );
2053
-add_filter( 'wpinv_print_cart_total_label', 'wpinv_cart_total_label', 10, 2 );
2051
+add_filter('wpinv_cart_total_label', 'wpinv_cart_total_label', 10, 2);
2052
+add_filter('wpinv_email_cart_total_label', 'wpinv_cart_total_label', 10, 2);
2053
+add_filter('wpinv_print_cart_total_label', 'wpinv_cart_total_label', 10, 2);
2054 2054
 
2055
-add_action( 'wpinv_invoice_print_middle', 'wpinv_invoice_subscription_details', 10, 1 );
2055
+add_action('wpinv_invoice_print_middle', 'wpinv_invoice_subscription_details', 10, 1);
2056 2056
 
2057
-function wpinv_invoice_print_description( $invoice ) {
2058
-    if ( empty( $invoice ) ) {
2057
+function wpinv_invoice_print_description($invoice) {
2058
+    if (empty($invoice)) {
2059 2059
         return NULL;
2060 2060
     }
2061
-    if ( $description = wpinv_get_invoice_description( $invoice->ID ) ) {
2061
+    if ($description = wpinv_get_invoice_description($invoice->ID)) {
2062 2062
         ?>
2063 2063
         <div class="row wpinv-lower">
2064 2064
             <div class="col-sm-12 wpinv-description">
2065
-                <?php echo wpautop( $description ); ?>
2065
+                <?php echo wpautop($description); ?>
2066 2066
             </div>
2067 2067
         </div>
2068 2068
         <?php
2069 2069
     }
2070 2070
 }
2071
-add_action( 'wpinv_invoice_print_middle', 'wpinv_invoice_print_description', 10.1, 1 );
2071
+add_action('wpinv_invoice_print_middle', 'wpinv_invoice_print_description', 10.1, 1);
2072 2072
 
2073
-function wpinv_invoice_print_payment_info( $invoice ) {
2074
-    if ( empty( $invoice ) ) {
2073
+function wpinv_invoice_print_payment_info($invoice) {
2074
+    if (empty($invoice)) {
2075 2075
         return NULL;
2076 2076
     }
2077 2077
     
2078
-    if ( $payments_info = wpinv_display_payments_info( $invoice->ID, false ) ) {
2078
+    if ($payments_info = wpinv_display_payments_info($invoice->ID, false)) {
2079 2079
         ?>
2080 2080
         <div class="row wpinv-payments">
2081 2081
             <div class="col-sm-12">
@@ -2087,43 +2087,43 @@  discard block
 block discarded – undo
2087 2087
 }
2088 2088
 // add_action( 'wpinv_invoice_print_after_line_items', 'wpinv_invoice_print_payment_info', 10, 1 );
2089 2089
 
2090
-function wpinv_get_invoice_note_line_item( $note, $echo = true ) {
2091
-    if ( empty( $note ) ) {
2090
+function wpinv_get_invoice_note_line_item($note, $echo = true) {
2091
+    if (empty($note)) {
2092 2092
         return NULL;
2093 2093
     }
2094 2094
     
2095
-    if ( is_int( $note ) ) {
2096
-        $note = get_comment( $note );
2095
+    if (is_int($note)) {
2096
+        $note = get_comment($note);
2097 2097
     }
2098 2098
     
2099
-    if ( !( is_object( $note ) && is_a( $note, 'WP_Comment' ) ) ) {
2099
+    if (!(is_object($note) && is_a($note, 'WP_Comment'))) {
2100 2100
         return NULL;
2101 2101
     }
2102 2102
     
2103
-    $note_classes   = array( 'note' );
2104
-    $note_classes[] = get_comment_meta( $note->comment_ID, '_wpi_customer_note', true ) ? 'customer-note' : '';
2105
-    $note_classes[] = $note->comment_author === __( 'System', 'invoicing' ) ? 'system-note' : '';
2106
-    $note_classes   = apply_filters( 'wpinv_invoice_note_class', array_filter( $note_classes ), $note );
2107
-    $note_classes   = !empty( $note_classes ) ? implode( ' ', $note_classes ) : '';
2103
+    $note_classes   = array('note');
2104
+    $note_classes[] = get_comment_meta($note->comment_ID, '_wpi_customer_note', true) ? 'customer-note' : '';
2105
+    $note_classes[] = $note->comment_author === __('System', 'invoicing') ? 'system-note' : '';
2106
+    $note_classes   = apply_filters('wpinv_invoice_note_class', array_filter($note_classes), $note);
2107
+    $note_classes   = !empty($note_classes) ? implode(' ', $note_classes) : '';
2108 2108
     
2109 2109
     ob_start();
2110 2110
     ?>
2111
-    <li rel="<?php echo absint( $note->comment_ID ) ; ?>" class="<?php echo esc_attr( $note_classes ); ?>">
2111
+    <li rel="<?php echo absint($note->comment_ID); ?>" class="<?php echo esc_attr($note_classes); ?>">
2112 2112
         <div class="note_content">
2113
-            <?php echo wpautop( wptexturize( wp_kses_post( $note->comment_content ) ) ); ?>
2113
+            <?php echo wpautop(wptexturize(wp_kses_post($note->comment_content))); ?>
2114 2114
         </div>
2115 2115
         <p class="meta">
2116
-            <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;
2117
-            <?php if($note->comment_author !== 'System') {?>
2118
-                <a href="#" class="delete_note"><?php _e( 'Delete note', 'invoicing' ); ?></a>
2116
+            <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;
2117
+            <?php if ($note->comment_author !== 'System') {?>
2118
+                <a href="#" class="delete_note"><?php _e('Delete note', 'invoicing'); ?></a>
2119 2119
             <?php } ?>
2120 2120
         </p>
2121 2121
     </li>
2122 2122
     <?php
2123 2123
     $note_content = ob_get_clean();
2124
-    $note_content = apply_filters( 'wpinv_get_invoice_note_line_item', $note_content, $note, $echo );
2124
+    $note_content = apply_filters('wpinv_get_invoice_note_line_item', $note_content, $note, $echo);
2125 2125
     
2126
-    if ( $echo ) {
2126
+    if ($echo) {
2127 2127
         echo $note_content;
2128 2128
     } else {
2129 2129
         return $note_content;
Please login to merge, or discard this patch.
includes/wpinv-item-functions.php 1 patch
Spacing   +245 added lines, -245 removed lines patch added patch discarded remove patch
@@ -1,19 +1,19 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // Exit if accessed directly
3
-if ( ! defined( 'ABSPATH' ) ) exit;
3
+if (!defined('ABSPATH')) exit;
4 4
 
5
-function wpinv_get_item_by( $field = '', $value = '', $type = '' ) {
6
-    if( empty( $field ) || empty( $value ) ) {
5
+function wpinv_get_item_by($field = '', $value = '', $type = '') {
6
+    if (empty($field) || empty($value)) {
7 7
         return false;
8 8
     }
9 9
     
10 10
     $posts = array();
11 11
 
12
-    switch( strtolower( $field ) ) {
12
+    switch (strtolower($field)) {
13 13
         case 'id':
14
-            $item = get_post( $value );
14
+            $item = get_post($value);
15 15
 
16
-            if( get_post_type( $item ) != 'wpi_item' ) {
16
+            if (get_post_type($item) != 'wpi_item') {
17 17
                 return false;
18 18
             }
19 19
 
@@ -21,16 +21,16 @@  discard block
 block discarded – undo
21 21
 
22 22
         case 'slug':
23 23
         case 'name':
24
-            $posts = get_posts( array(
24
+            $posts = get_posts(array(
25 25
                 'post_type'      => 'wpi_item',
26 26
                 'name'           => $value,
27 27
                 'posts_per_page' => 1,
28 28
                 'post_status'    => 'any'
29
-            ) );
29
+            ));
30 30
 
31 31
             break;
32 32
         case 'custom_id':
33
-            if ( empty( $value ) || empty( $type ) ) {
33
+            if (empty($value) || empty($type)) {
34 34
                 return false;
35 35
             }
36 36
             
@@ -50,10 +50,10 @@  discard block
 block discarded – undo
50 50
                 'post_status'    => 'any',
51 51
                 'orderby'        => 'ID',
52 52
                 'order'          => 'ASC',
53
-                'meta_query'     => array( $meta_query )
53
+                'meta_query'     => array($meta_query)
54 54
             );
55 55
             
56
-            $posts = get_posts( $args );
56
+            $posts = get_posts($args);
57 57
 
58 58
             break;
59 59
 
@@ -61,17 +61,17 @@  discard block
 block discarded – undo
61 61
             return false;
62 62
     }
63 63
     
64
-    if ( !empty( $posts[0] ) ) {
65
-        return new WPInv_Item( $posts[0]->ID );
64
+    if (!empty($posts[0])) {
65
+        return new WPInv_Item($posts[0]->ID);
66 66
     }
67 67
 
68 68
     return false;
69 69
 }
70 70
 
71
-function wpinv_get_item( $item = 0 ) {
72
-    if ( is_numeric( $item ) ) {
73
-        $item = get_post( $item );
74
-        if ( ! $item || 'wpi_item' !== $item->post_type )
71
+function wpinv_get_item($item = 0) {
72
+    if (is_numeric($item)) {
73
+        $item = get_post($item);
74
+        if (!$item || 'wpi_item' !== $item->post_type)
75 75
             return null;
76 76
         return $item;
77 77
     }
@@ -84,136 +84,136 @@  discard block
 block discarded – undo
84 84
 
85 85
     $item = get_posts($args);
86 86
 
87
-    if ( $item ) {
87
+    if ($item) {
88 88
         return $item[0];
89 89
     }
90 90
 
91 91
     return null;
92 92
 }
93 93
 
94
-function wpinv_is_free_item( $item_id = 0 ) {
95
-    if( empty( $item_id ) ) {
94
+function wpinv_is_free_item($item_id = 0) {
95
+    if (empty($item_id)) {
96 96
         return false;
97 97
     }
98 98
 
99
-    $item = new WPInv_Item( $item_id );
99
+    $item = new WPInv_Item($item_id);
100 100
     
101 101
     return $item->is_free();
102 102
 }
103 103
 
104
-function wpinv_get_item_price( $item_id = 0 ) {
105
-    if( empty( $item_id ) ) {
104
+function wpinv_get_item_price($item_id = 0) {
105
+    if (empty($item_id)) {
106 106
         return false;
107 107
     }
108 108
 
109
-    $item = new WPInv_Item( $item_id );
109
+    $item = new WPInv_Item($item_id);
110 110
     
111 111
     return $item->get_price();
112 112
 }
113 113
 
114
-function wpinv_is_recurring_item( $item_id = 0 ) {
115
-    if( empty( $item_id ) ) {
114
+function wpinv_is_recurring_item($item_id = 0) {
115
+    if (empty($item_id)) {
116 116
         return false;
117 117
     }
118 118
 
119
-    $item = new WPInv_Item( $item_id );
119
+    $item = new WPInv_Item($item_id);
120 120
     
121 121
     return $item->is_recurring();
122 122
 }
123 123
 
124
-function wpinv_item_price( $item_id = 0 ) {
125
-    if( empty( $item_id ) ) {
124
+function wpinv_item_price($item_id = 0) {
125
+    if (empty($item_id)) {
126 126
         return false;
127 127
     }
128 128
 
129
-    $price = wpinv_get_item_price( $item_id );
130
-    $price = wpinv_price( wpinv_format_amount( $price ) );
129
+    $price = wpinv_get_item_price($item_id);
130
+    $price = wpinv_price(wpinv_format_amount($price));
131 131
     
132
-    return apply_filters( 'wpinv_item_price', $price, $item_id );
132
+    return apply_filters('wpinv_item_price', $price, $item_id);
133 133
 }
134 134
 
135
-function wpinv_item_show_price( $item_id = 0, $echo = true ) {
136
-    if ( empty( $item_id ) ) {
135
+function wpinv_item_show_price($item_id = 0, $echo = true) {
136
+    if (empty($item_id)) {
137 137
         $item_id = get_the_ID();
138 138
     }
139 139
 
140
-    $price = wpinv_item_price( $item_id );
140
+    $price = wpinv_item_price($item_id);
141 141
 
142
-    $price           = apply_filters( 'wpinv_item_price', wpinv_sanitize_amount( $price ), $item_id );
142
+    $price           = apply_filters('wpinv_item_price', wpinv_sanitize_amount($price), $item_id);
143 143
     $formatted_price = '<span class="wpinv_price" id="wpinv_item_' . $item_id . '">' . $price . '</span>';
144
-    $formatted_price = apply_filters( 'wpinv_item_price_after_html', $formatted_price, $item_id, $price );
144
+    $formatted_price = apply_filters('wpinv_item_price_after_html', $formatted_price, $item_id, $price);
145 145
 
146
-    if ( $echo ) {
146
+    if ($echo) {
147 147
         echo $formatted_price;
148 148
     } else {
149 149
         return $formatted_price;
150 150
     }
151 151
 }
152 152
 
153
-function wpinv_get_item_final_price( $item_id = 0, $amount_override = null ) {
154
-    if ( is_null( $amount_override ) ) {
155
-        $original_price = get_post_meta( $item_id, '_wpinv_price', true );
153
+function wpinv_get_item_final_price($item_id = 0, $amount_override = null) {
154
+    if (is_null($amount_override)) {
155
+        $original_price = get_post_meta($item_id, '_wpinv_price', true);
156 156
     } else {
157 157
         $original_price = $amount_override;
158 158
     }
159 159
     
160 160
     $price = $original_price;
161 161
 
162
-    return apply_filters( 'wpinv_get_item_final_price', $price, $item_id );
162
+    return apply_filters('wpinv_get_item_final_price', $price, $item_id);
163 163
 }
164 164
 
165
-function wpinv_item_custom_singular_name( $item_id ) {
166
-    if( empty( $item_id ) ) {
165
+function wpinv_item_custom_singular_name($item_id) {
166
+    if (empty($item_id)) {
167 167
         return false;
168 168
     }
169 169
 
170
-    $item = new WPInv_Item( $item_id );
170
+    $item = new WPInv_Item($item_id);
171 171
     
172 172
     return $item->get_custom_singular_name();
173 173
 }
174 174
 
175 175
 function wpinv_get_item_types() {
176 176
     $item_types = array(
177
-            'custom'    => __( 'Standard', 'invoicing' ),
178
-            'fee'       => __( 'Fee', 'invoicing' ),
177
+            'custom'    => __('Standard', 'invoicing'),
178
+            'fee'       => __('Fee', 'invoicing'),
179 179
         );
180
-    return apply_filters( 'wpinv_get_item_types', $item_types );
180
+    return apply_filters('wpinv_get_item_types', $item_types);
181 181
 }
182 182
 
183 183
 function wpinv_item_types() {
184 184
     $item_types = wpinv_get_item_types();
185 185
     
186
-    return ( !empty( $item_types ) ? array_keys( $item_types ) : array() );
186
+    return (!empty($item_types) ? array_keys($item_types) : array());
187 187
 }
188 188
 
189
-function wpinv_get_item_type( $item_id ) {
190
-    if( empty( $item_id ) ) {
189
+function wpinv_get_item_type($item_id) {
190
+    if (empty($item_id)) {
191 191
         return false;
192 192
     }
193 193
 
194
-    $item = new WPInv_Item( $item_id );
194
+    $item = new WPInv_Item($item_id);
195 195
     
196 196
     return $item->get_type();
197 197
 }
198 198
 
199
-function wpinv_item_type( $item_id ) {
199
+function wpinv_item_type($item_id) {
200 200
     $item_types = wpinv_get_item_types();
201 201
     
202
-    $item_type = wpinv_get_item_type( $item_id );
202
+    $item_type = wpinv_get_item_type($item_id);
203 203
     
204
-    if ( empty( $item_type ) ) {
204
+    if (empty($item_type)) {
205 205
         $item_type = '-';
206 206
     }
207 207
     
208
-    $item_type = isset( $item_types[$item_type] ) ? $item_types[$item_type] : __( $item_type, 'invoicing' );
208
+    $item_type = isset($item_types[$item_type]) ? $item_types[$item_type] : __($item_type, 'invoicing');
209 209
 
210
-    return apply_filters( 'wpinv_item_type', $item_type, $item_id );
210
+    return apply_filters('wpinv_item_type', $item_type, $item_id);
211 211
 }
212 212
 
213
-function wpinv_record_item_in_log( $item_id = 0, $file_id, $user_info, $ip, $invoice_id ) {
213
+function wpinv_record_item_in_log($item_id = 0, $file_id, $user_info, $ip, $invoice_id) {
214 214
     global $wpinv_logs;
215 215
     
216
-    if ( empty( $wpinv_logs ) ) {
216
+    if (empty($wpinv_logs)) {
217 217
         return false;
218 218
     }
219 219
 
@@ -222,7 +222,7 @@  discard block
 block discarded – undo
222 222
         'log_type'		=> 'wpi_item'
223 223
     );
224 224
 
225
-    $user_id = isset( $user_info['user_id'] ) ? $user_info['user_id'] : (int) -1;
225
+    $user_id = isset($user_info['user_id']) ? $user_info['user_id'] : (int) -1;
226 226
 
227 227
     $log_meta = array(
228 228
         'user_info'	=> $user_info,
@@ -232,253 +232,253 @@  discard block
 block discarded – undo
232 232
         'invoice_id'=> $invoice_id,
233 233
     );
234 234
 
235
-    $wpinv_logs->insert_log( $log_data, $log_meta );
235
+    $wpinv_logs->insert_log($log_data, $log_meta);
236 236
 }
237 237
 
238
-function wpinv_remove_item_logs_on_delete( $item_id = 0 ) {
239
-    if ( 'wpi_item' !== get_post_type( $item_id ) )
238
+function wpinv_remove_item_logs_on_delete($item_id = 0) {
239
+    if ('wpi_item' !== get_post_type($item_id))
240 240
         return;
241 241
 
242 242
     global $wpinv_logs;
243 243
     
244
-    if ( empty( $wpinv_logs ) ) {
244
+    if (empty($wpinv_logs)) {
245 245
         return false;
246 246
     }
247 247
 
248 248
     // Remove all log entries related to this item
249
-    $wpinv_logs->delete_logs( $item_id );
249
+    $wpinv_logs->delete_logs($item_id);
250 250
 }
251
-add_action( 'delete_post', 'wpinv_remove_item_logs_on_delete' );
251
+add_action('delete_post', 'wpinv_remove_item_logs_on_delete');
252 252
 
253
-function wpinv_get_random_item( $post_ids = true ) {
254
-    wpinv_get_random_items( 1, $post_ids );
253
+function wpinv_get_random_item($post_ids = true) {
254
+    wpinv_get_random_items(1, $post_ids);
255 255
 }
256 256
 
257
-function wpinv_get_random_items( $num = 3, $post_ids = true ) {
258
-    if ( $post_ids ) {
259
-        $args = array( 'post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num, 'fields' => 'ids' );
257
+function wpinv_get_random_items($num = 3, $post_ids = true) {
258
+    if ($post_ids) {
259
+        $args = array('post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num, 'fields' => 'ids');
260 260
     } else {
261
-        $args = array( 'post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num );
261
+        $args = array('post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num);
262 262
     }
263 263
     
264
-    $args  = apply_filters( 'wpinv_get_random_items', $args );
264
+    $args = apply_filters('wpinv_get_random_items', $args);
265 265
     
266
-    return get_posts( $args );
266
+    return get_posts($args);
267 267
 }
268 268
 
269
-function wpinv_get_item_token( $url = '' ) {
269
+function wpinv_get_item_token($url = '') {
270 270
     $args    = array();
271
-    $hash    = apply_filters( 'wpinv_get_url_token_algorithm', 'sha256' );
272
-    $secret  = apply_filters( 'wpinv_get_url_token_secret', hash( $hash, wp_salt() ) );
271
+    $hash    = apply_filters('wpinv_get_url_token_algorithm', 'sha256');
272
+    $secret  = apply_filters('wpinv_get_url_token_secret', hash($hash, wp_salt()));
273 273
 
274
-    $parts   = parse_url( $url );
274
+    $parts   = parse_url($url);
275 275
     $options = array();
276 276
 
277
-    if ( isset( $parts['query'] ) ) {
278
-        wp_parse_str( $parts['query'], $query_args );
277
+    if (isset($parts['query'])) {
278
+        wp_parse_str($parts['query'], $query_args);
279 279
 
280
-        if ( ! empty( $query_args['o'] ) ) {
281
-            $options = explode( ':', rawurldecode( $query_args['o'] ) );
280
+        if (!empty($query_args['o'])) {
281
+            $options = explode(':', rawurldecode($query_args['o']));
282 282
 
283
-            if ( in_array( 'ip', $options ) ) {
283
+            if (in_array('ip', $options)) {
284 284
                 $args['ip'] = wpinv_get_ip();
285 285
             }
286 286
 
287
-            if ( in_array( 'ua', $options ) ) {
287
+            if (in_array('ua', $options)) {
288 288
                 $ua = wpinv_get_user_agent();
289
-                $args['user_agent'] = rawurlencode( $ua );
289
+                $args['user_agent'] = rawurlencode($ua);
290 290
             }
291 291
         }
292 292
     }
293 293
 
294
-    $args = apply_filters( 'wpinv_get_url_token_args', $args, $url, $options );
294
+    $args = apply_filters('wpinv_get_url_token_args', $args, $url, $options);
295 295
 
296 296
     $args['secret'] = $secret;
297 297
     $args['token']  = false;
298 298
 
299
-    $url   = add_query_arg( $args, $url );
300
-    $parts = parse_url( $url );
299
+    $url   = add_query_arg($args, $url);
300
+    $parts = parse_url($url);
301 301
 
302
-    if ( ! isset( $parts['path'] ) ) {
302
+    if (!isset($parts['path'])) {
303 303
         $parts['path'] = '';
304 304
     }
305 305
 
306
-    $token = md5( $parts['path'] . '?' . $parts['query'] );
306
+    $token = md5($parts['path'] . '?' . $parts['query']);
307 307
 
308 308
     return $token;
309 309
 }
310 310
 
311
-function wpinv_validate_url_token( $url = '' ) {
311
+function wpinv_validate_url_token($url = '') {
312 312
     $ret   = false;
313
-    $parts = parse_url( $url );
313
+    $parts = parse_url($url);
314 314
 
315
-    if ( isset( $parts['query'] ) ) {
316
-        wp_parse_str( $parts['query'], $query_args );
315
+    if (isset($parts['query'])) {
316
+        wp_parse_str($parts['query'], $query_args);
317 317
 
318
-        $allowed = apply_filters( 'wpinv_url_token_allowed_params', array(
318
+        $allowed = apply_filters('wpinv_url_token_allowed_params', array(
319 319
             'item',
320 320
             'ttl',
321 321
             'token'
322
-        ) );
322
+        ));
323 323
 
324 324
         $remove = array();
325 325
 
326
-        foreach( $query_args as $key => $value ) {
327
-            if( false === in_array( $key, $allowed ) ) {
326
+        foreach ($query_args as $key => $value) {
327
+            if (false === in_array($key, $allowed)) {
328 328
                 $remove[] = $key;
329 329
             }
330 330
         }
331 331
 
332
-        if( ! empty( $remove ) ) {
333
-            $url = remove_query_arg( $remove, $url );
332
+        if (!empty($remove)) {
333
+            $url = remove_query_arg($remove, $url);
334 334
         }
335 335
 
336
-        if ( isset( $query_args['ttl'] ) && current_time( 'timestamp' ) > $query_args['ttl'] ) {
337
-            wp_die( apply_filters( 'wpinv_item_link_expired_text', __( 'Sorry but your item link has expired.', 'invoicing' ) ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
336
+        if (isset($query_args['ttl']) && current_time('timestamp') > $query_args['ttl']) {
337
+            wp_die(apply_filters('wpinv_item_link_expired_text', __('Sorry but your item link has expired.', 'invoicing')), __('Error', 'invoicing'), array('response' => 403));
338 338
         }
339 339
 
340
-        if ( isset( $query_args['token'] ) && $query_args['token'] == wpinv_get_item_token( $url ) ) {
340
+        if (isset($query_args['token']) && $query_args['token'] == wpinv_get_item_token($url)) {
341 341
             $ret = true;
342 342
         }
343 343
 
344 344
     }
345 345
 
346
-    return apply_filters( 'wpinv_validate_url_token', $ret, $url, $query_args );
346
+    return apply_filters('wpinv_validate_url_token', $ret, $url, $query_args);
347 347
 }
348 348
 
349
-function wpinv_item_in_cart( $item_id = 0, $options = array() ) {
349
+function wpinv_item_in_cart($item_id = 0, $options = array()) {
350 350
     $cart_items = wpinv_get_cart_contents();
351 351
 
352 352
     $ret = false;
353 353
 
354
-    if ( is_array( $cart_items ) ) {
355
-        foreach ( $cart_items as $item ) {
356
-            if ( $item['id'] == $item_id ) {
354
+    if (is_array($cart_items)) {
355
+        foreach ($cart_items as $item) {
356
+            if ($item['id'] == $item_id) {
357 357
                 $ret = true;
358 358
                 break;
359 359
             }
360 360
         }
361 361
     }
362 362
 
363
-    return (bool) apply_filters( 'wpinv_item_in_cart', $ret, $item_id, $options );
363
+    return (bool)apply_filters('wpinv_item_in_cart', $ret, $item_id, $options);
364 364
 }
365 365
 
366
-function wpinv_get_cart_item_tax( $item_id = 0, $subtotal = '', $options = array() ) {
366
+function wpinv_get_cart_item_tax($item_id = 0, $subtotal = '', $options = array()) {
367 367
     $tax = 0;
368
-    if ( ! wpinv_item_is_tax_exclusive( $item_id ) ) {
369
-        $country = !empty( $_POST['country'] ) ? $_POST['country'] : false;
370
-        $state   = isset( $_POST['state'] ) ? $_POST['state'] : '';
368
+    if (!wpinv_item_is_tax_exclusive($item_id)) {
369
+        $country = !empty($_POST['country']) ? $_POST['country'] : false;
370
+        $state   = isset($_POST['state']) ? $_POST['state'] : '';
371 371
 
372
-        $tax = wpinv_calculate_tax( $subtotal, $country, $state, $item_id );
372
+        $tax = wpinv_calculate_tax($subtotal, $country, $state, $item_id);
373 373
     }
374 374
 
375
-    return apply_filters( 'wpinv_get_cart_item_tax', $tax, $item_id, $subtotal, $options );
375
+    return apply_filters('wpinv_get_cart_item_tax', $tax, $item_id, $subtotal, $options);
376 376
 }
377 377
 
378
-function wpinv_cart_item_price( $item ) {
378
+function wpinv_cart_item_price($item) {
379 379
     $use_taxes  = wpinv_use_taxes();
380
-    $item_id    = isset( $item['id'] ) ? $item['id'] : 0;
381
-    $price      = isset( $item['item_price'] ) ? wpinv_round_amount( $item['item_price'] ) : 0;
382
-    $options    = isset( $item['options'] ) ? $item['options'] : array();
383
-    $price_id   = isset( $options['price_id'] ) ? $options['price_id'] : false;
384
-    $tax        = wpinv_price( wpinv_format_amount( $item['tax'] ) );
385
-    
386
-    if ( !wpinv_is_free_item( $item_id, $price_id ) && !wpinv_item_is_tax_exclusive( $item_id ) ) {
387
-        if ( wpinv_prices_show_tax_on_checkout() && !wpinv_prices_include_tax() ) {
380
+    $item_id    = isset($item['id']) ? $item['id'] : 0;
381
+    $price      = isset($item['item_price']) ? wpinv_round_amount($item['item_price']) : 0;
382
+    $options    = isset($item['options']) ? $item['options'] : array();
383
+    $price_id   = isset($options['price_id']) ? $options['price_id'] : false;
384
+    $tax        = wpinv_price(wpinv_format_amount($item['tax']));
385
+    
386
+    if (!wpinv_is_free_item($item_id, $price_id) && !wpinv_item_is_tax_exclusive($item_id)) {
387
+        if (wpinv_prices_show_tax_on_checkout() && !wpinv_prices_include_tax()) {
388 388
             $price += $tax;
389 389
         }
390 390
         
391
-        if( !wpinv_prices_show_tax_on_checkout() && wpinv_prices_include_tax() ) {
391
+        if (!wpinv_prices_show_tax_on_checkout() && wpinv_prices_include_tax()) {
392 392
             $price -= $tax;
393 393
         }        
394 394
     }
395 395
 
396
-    $price = wpinv_price( wpinv_format_amount( $price ) );
396
+    $price = wpinv_price(wpinv_format_amount($price));
397 397
 
398
-    return apply_filters( 'wpinv_cart_item_price_label', $price, $item );
398
+    return apply_filters('wpinv_cart_item_price_label', $price, $item);
399 399
 }
400 400
 
401
-function wpinv_cart_item_subtotal( $item ) {
402
-    $subtotal   = isset( $item['subtotal'] ) ? $item['subtotal'] : 0;
403
-    $subtotal   = wpinv_price( wpinv_format_amount( $subtotal ) );
401
+function wpinv_cart_item_subtotal($item) {
402
+    $subtotal   = isset($item['subtotal']) ? $item['subtotal'] : 0;
403
+    $subtotal   = wpinv_price(wpinv_format_amount($subtotal));
404 404
 
405
-    return apply_filters( 'wpinv_cart_item_subtotal_label', $subtotal, $item );
405
+    return apply_filters('wpinv_cart_item_subtotal_label', $subtotal, $item);
406 406
 }
407 407
 
408
-function wpinv_cart_item_tax( $item ) {
408
+function wpinv_cart_item_tax($item) {
409 409
     $tax        = '';
410 410
     $tax_rate   = '';
411 411
     
412
-    if ( isset( $item['tax'] ) && $item['tax'] > 0 && $item['subtotal'] > 0 ) {
413
-        $tax      = wpinv_price( wpinv_format_amount( $item['tax'] ) );
414
-        $tax_rate = !empty( $item['vat_rate'] ) ? $item['vat_rate'] : ( $item['tax'] / $item['subtotal'] ) * 100;
415
-        $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount( $tax_rate, 4 ) : '';
412
+    if (isset($item['tax']) && $item['tax'] > 0 && $item['subtotal'] > 0) {
413
+        $tax      = wpinv_price(wpinv_format_amount($item['tax']));
414
+        $tax_rate = !empty($item['vat_rate']) ? $item['vat_rate'] : ($item['tax'] / $item['subtotal']) * 100;
415
+        $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount($tax_rate, 4) : '';
416 416
         $tax_rate = $tax_rate != '' ? ' <small class="tax-rate normal small">(' . $tax_rate . '%)</small>' : '';
417 417
     }
418 418
     
419
-    $tax        = $tax . $tax_rate;
419
+    $tax = $tax . $tax_rate;
420 420
     
421
-    if ( $tax === '' ) {
421
+    if ($tax === '') {
422 422
         $tax = 0; // Zero tax
423 423
     }
424 424
 
425
-    return apply_filters( 'wpinv_cart_item_tax_label', $tax, $item );
425
+    return apply_filters('wpinv_cart_item_tax_label', $tax, $item);
426 426
 }
427 427
 
428
-function wpinv_get_cart_item_price( $item_id = 0, $cart_item = array(), $options = array(), $remove_tax_from_inclusive = false ) {
428
+function wpinv_get_cart_item_price($item_id = 0, $cart_item = array(), $options = array(), $remove_tax_from_inclusive = false) {
429 429
     $price = 0;
430 430
     
431 431
     // Set custom price
432
-    if ( isset( $cart_item['custom_price'] ) && $cart_item['custom_price'] !== '' ) {
432
+    if (isset($cart_item['custom_price']) && $cart_item['custom_price'] !== '') {
433 433
         $price = $cart_item['custom_price'];
434 434
     } else {
435
-        $variable_prices = wpinv_has_variable_prices( $item_id );
435
+        $variable_prices = wpinv_has_variable_prices($item_id);
436 436
 
437
-        if ( $variable_prices ) {
438
-            $prices = wpinv_get_variable_prices( $item_id );
437
+        if ($variable_prices) {
438
+            $prices = wpinv_get_variable_prices($item_id);
439 439
 
440
-            if ( $prices ) {
441
-                if( ! empty( $options ) ) {
442
-                    $price = isset( $prices[ $options['price_id'] ] ) ? $prices[ $options['price_id'] ]['amount'] : false;
440
+            if ($prices) {
441
+                if (!empty($options)) {
442
+                    $price = isset($prices[$options['price_id']]) ? $prices[$options['price_id']]['amount'] : false;
443 443
                 } else {
444 444
                     $price = false;
445 445
                 }
446 446
             }
447 447
         }
448 448
 
449
-        if( ! $variable_prices || false === $price ) {
449
+        if (!$variable_prices || false === $price) {
450 450
             // Get the standard Item price if not using variable prices
451
-            $price = wpinv_get_item_price( $item_id );
451
+            $price = wpinv_get_item_price($item_id);
452 452
         }
453 453
     }
454 454
 
455
-    if ( $remove_tax_from_inclusive && wpinv_prices_include_tax() ) {
456
-        $price -= wpinv_get_cart_item_tax( $item_id, $price, $options );
455
+    if ($remove_tax_from_inclusive && wpinv_prices_include_tax()) {
456
+        $price -= wpinv_get_cart_item_tax($item_id, $price, $options);
457 457
     }
458 458
 
459
-    return apply_filters( 'wpinv_cart_item_price', $price, $item_id, $cart_item, $options, $remove_tax_from_inclusive );
459
+    return apply_filters('wpinv_cart_item_price', $price, $item_id, $cart_item, $options, $remove_tax_from_inclusive);
460 460
 }
461 461
 
462
-function wpinv_get_cart_item_price_id( $item = array() ) {
463
-    if( isset( $item['item_number'] ) ) {
464
-        $price_id = isset( $item['item_number']['options']['price_id'] ) ? $item['item_number']['options']['price_id'] : null;
462
+function wpinv_get_cart_item_price_id($item = array()) {
463
+    if (isset($item['item_number'])) {
464
+        $price_id = isset($item['item_number']['options']['price_id']) ? $item['item_number']['options']['price_id'] : null;
465 465
     } else {
466
-        $price_id = isset( $item['options']['price_id'] ) ? $item['options']['price_id'] : null;
466
+        $price_id = isset($item['options']['price_id']) ? $item['options']['price_id'] : null;
467 467
     }
468 468
     return $price_id;
469 469
 }
470 470
 
471
-function wpinv_get_cart_item_price_name( $item = array() ) {
472
-    $price_id = (int)wpinv_get_cart_item_price_id( $item );
473
-    $prices   = wpinv_get_variable_prices( $item['id'] );
474
-    $name     = ! empty( $prices[ $price_id ] ) ? $prices[ $price_id ]['name'] : '';
475
-    return apply_filters( 'wpinv_get_cart_item_price_name', $name, $item['id'], $price_id, $item );
471
+function wpinv_get_cart_item_price_name($item = array()) {
472
+    $price_id = (int)wpinv_get_cart_item_price_id($item);
473
+    $prices   = wpinv_get_variable_prices($item['id']);
474
+    $name     = !empty($prices[$price_id]) ? $prices[$price_id]['name'] : '';
475
+    return apply_filters('wpinv_get_cart_item_price_name', $name, $item['id'], $price_id, $item);
476 476
 }
477 477
 
478
-function wpinv_get_cart_item_name( $item = array() ) {
479
-    $item_title = !empty( $item['name'] ) ? $item['name'] : get_the_title( $item['id'] );
478
+function wpinv_get_cart_item_name($item = array()) {
479
+    $item_title = !empty($item['name']) ? $item['name'] : get_the_title($item['id']);
480 480
 
481
-    if ( empty( $item_title ) ) {
481
+    if (empty($item_title)) {
482 482
         $item_title = $item['id'];
483 483
     }
484 484
 
@@ -488,23 +488,23 @@  discard block
 block discarded – undo
488 488
     }
489 489
     */
490 490
 
491
-    return apply_filters( 'wpinv_get_cart_item_name', $item_title, $item['id'], $item );
491
+    return apply_filters('wpinv_get_cart_item_name', $item_title, $item['id'], $item);
492 492
 }
493 493
 
494
-function wpinv_has_variable_prices( $item_id = 0 ) {
494
+function wpinv_has_variable_prices($item_id = 0) {
495 495
     return false;
496 496
 }
497 497
 
498
-function wpinv_get_item_position_in_cart( $item_id = 0, $options = array() ) {
498
+function wpinv_get_item_position_in_cart($item_id = 0, $options = array()) {
499 499
     $cart_items = wpinv_get_cart_contents();
500 500
 
501
-    if ( !is_array( $cart_items ) ) {
501
+    if (!is_array($cart_items)) {
502 502
         return false; // Empty cart
503 503
     } else {
504
-        foreach ( $cart_items as $position => $item ) {
505
-            if ( $item['id'] == $item_id ) {
506
-                if ( isset( $options['price_id'] ) && isset( $item['options']['price_id'] ) ) {
507
-                    if ( (int) $options['price_id'] == (int) $item['options']['price_id'] ) {
504
+        foreach ($cart_items as $position => $item) {
505
+            if ($item['id'] == $item_id) {
506
+                if (isset($options['price_id']) && isset($item['options']['price_id'])) {
507
+                    if ((int)$options['price_id'] == (int)$item['options']['price_id']) {
508 508
                         return $position;
509 509
                     }
510 510
                 } else {
@@ -517,80 +517,80 @@  discard block
 block discarded – undo
517 517
     return false; // Not found
518 518
 }
519 519
 
520
-function wpinv_get_cart_item_quantity( $item ) {
521
-    if ( wpinv_item_quantities_enabled() ) {
522
-        $quantity = !empty( $item['quantity'] ) && (int)$item['quantity'] > 0 ? absint( $item['quantity'] ) : 1;
520
+function wpinv_get_cart_item_quantity($item) {
521
+    if (wpinv_item_quantities_enabled()) {
522
+        $quantity = !empty($item['quantity']) && (int)$item['quantity'] > 0 ? absint($item['quantity']) : 1;
523 523
     } else {
524 524
         $quantity = 1;
525 525
     }
526 526
     
527
-    if ( $quantity < 1 ) {
527
+    if ($quantity < 1) {
528 528
         $quantity = 1;
529 529
     }
530 530
     
531
-    return apply_filters( 'wpinv_get_cart_item_quantity', $quantity, $item );
531
+    return apply_filters('wpinv_get_cart_item_quantity', $quantity, $item);
532 532
 }
533 533
 
534
-function wpinv_get_item_suffix( $item, $html = true ) {
535
-    if ( empty( $item ) ) {
534
+function wpinv_get_item_suffix($item, $html = true) {
535
+    if (empty($item)) {
536 536
         return NULL;
537 537
     }
538 538
     
539
-    if ( is_int( $item ) ) {
540
-        $item = new WPInv_Item( $item );
539
+    if (is_int($item)) {
540
+        $item = new WPInv_Item($item);
541 541
     }
542 542
     
543
-    if ( !( is_object( $item ) && is_a( $item, 'WPInv_Item' ) ) ) {
543
+    if (!(is_object($item) && is_a($item, 'WPInv_Item'))) {
544 544
         return NULL;
545 545
     }
546 546
     
547
-    $suffix = $item->is_recurring() ? ' <span class="wpi-suffix">' . __( '(r)', 'invoicing' ) . '</span>' : '';
547
+    $suffix = $item->is_recurring() ? ' <span class="wpi-suffix">' . __('(r)', 'invoicing') . '</span>' : '';
548 548
     
549
-    if ( !$html && $suffix ) {
550
-        $suffix = strip_tags( $suffix );
549
+    if (!$html && $suffix) {
550
+        $suffix = strip_tags($suffix);
551 551
     }
552 552
     
553
-    return apply_filters( 'wpinv_get_item_suffix', $suffix, $item, $html );
553
+    return apply_filters('wpinv_get_item_suffix', $suffix, $item, $html);
554 554
 }
555 555
 
556
-function wpinv_remove_item( $item = 0, $force_delete = false ) {
557
-    if ( empty( $item ) ) {
556
+function wpinv_remove_item($item = 0, $force_delete = false) {
557
+    if (empty($item)) {
558 558
         return NULL;
559 559
     }
560 560
     
561
-    if ( is_int( $item ) ) {
562
-        $item = new WPInv_Item( $item );
561
+    if (is_int($item)) {
562
+        $item = new WPInv_Item($item);
563 563
     }
564 564
     
565
-    if ( !( is_object( $item ) && is_a( $item, 'WPInv_Item' ) ) ) {
565
+    if (!(is_object($item) && is_a($item, 'WPInv_Item'))) {
566 566
         return NULL;
567 567
     }
568 568
     
569
-    do_action( 'wpinv_pre_delete_item', $item );
569
+    do_action('wpinv_pre_delete_item', $item);
570 570
 
571
-    wp_delete_post( $item->ID, $force_delete );
571
+    wp_delete_post($item->ID, $force_delete);
572 572
 
573
-    do_action( 'wpinv_post_delete_item', $item );
573
+    do_action('wpinv_post_delete_item', $item);
574 574
 }
575 575
 
576
-function wpinv_can_delete_item( $post_id ) {
577
-    $return = current_user_can( 'manage_options' ) ? true : false;
576
+function wpinv_can_delete_item($post_id) {
577
+    $return = current_user_can('manage_options') ? true : false;
578 578
     
579
-    if ( $return && wpinv_item_in_use( $post_id ) ) {
579
+    if ($return && wpinv_item_in_use($post_id)) {
580 580
         $return = false; // Don't delete item already use in invoices.
581 581
     }
582 582
     
583
-    return apply_filters( 'wpinv_can_delete_item', $return, $post_id );
583
+    return apply_filters('wpinv_can_delete_item', $return, $post_id);
584 584
 }
585 585
 
586 586
 function wpinv_admin_action_delete() {
587 587
     $screen = get_current_screen();
588 588
     
589
-    if ( !empty( $screen->post_type ) && $screen->post_type == 'wpi_item' && !empty( $_REQUEST['post'] ) && is_array( $_REQUEST['post'] ) ) {
589
+    if (!empty($screen->post_type) && $screen->post_type == 'wpi_item' && !empty($_REQUEST['post']) && is_array($_REQUEST['post'])) {
590 590
         $post_ids = array();
591 591
         
592
-        foreach ( $_REQUEST['post'] as $post_id ) {
593
-            if ( !wpinv_can_delete_item( $post_id ) ) {
592
+        foreach ($_REQUEST['post'] as $post_id) {
593
+            if (!wpinv_can_delete_item($post_id)) {
594 594
                 continue;
595 595
             }
596 596
             
@@ -600,80 +600,80 @@  discard block
 block discarded – undo
600 600
         $_REQUEST['post'] = $post_ids;
601 601
     }
602 602
 }
603
-add_action( 'admin_action_trash', 'wpinv_admin_action_delete', -10 );
604
-add_action( 'admin_action_delete', 'wpinv_admin_action_delete', -10 );
603
+add_action('admin_action_trash', 'wpinv_admin_action_delete', -10);
604
+add_action('admin_action_delete', 'wpinv_admin_action_delete', -10);
605 605
 
606
-function wpinv_check_delete_item( $check, $post, $force_delete ) {
607
-    if ( $post->post_type == 'wpi_item' ) {
608
-        if ( $force_delete && !wpinv_can_delete_item( $post->ID ) ) {
606
+function wpinv_check_delete_item($check, $post, $force_delete) {
607
+    if ($post->post_type == 'wpi_item') {
608
+        if ($force_delete && !wpinv_can_delete_item($post->ID)) {
609 609
             return true;
610 610
         }
611 611
     }
612 612
     
613 613
     return $check;
614 614
 }
615
-add_filter( 'pre_delete_post', 'wpinv_check_delete_item', 10, 3 );
615
+add_filter('pre_delete_post', 'wpinv_check_delete_item', 10, 3);
616 616
 
617
-function wpinv_item_in_use( $item_id ) {
617
+function wpinv_item_in_use($item_id) {
618 618
     global $wpdb, $wpi_items_in_use;
619 619
     
620
-    if ( !$item_id > 0 ) {
620
+    if (!$item_id > 0) {
621 621
         return false;
622 622
     }
623 623
     
624
-    if ( !empty( $wpi_items_in_use ) ) {
625
-        if ( isset( $wpi_items_in_use[$item_id] ) ) {
624
+    if (!empty($wpi_items_in_use)) {
625
+        if (isset($wpi_items_in_use[$item_id])) {
626 626
             return $wpi_items_in_use[$item_id];
627 627
         }
628 628
     } else {
629 629
         $wpi_items_in_use = array();
630 630
     }
631 631
     
632
-    $statuses   = array_keys( wpinv_get_invoice_statuses( true ) );
632
+    $statuses = array_keys(wpinv_get_invoice_statuses(true));
633 633
     
634
-    $query  = "SELECT p.ID FROM " . $wpdb->posts . " AS p INNER JOIN " . $wpdb->postmeta . " AS pm ON p.ID = pm.post_id WHERE p.post_type = 'wpi_invoice' AND p.post_status IN( '" . implode( "','", $statuses ) . "' ) AND pm.meta_key = '_wpinv_item_ids' AND FIND_IN_SET( '" . (int)$item_id . "', pm.meta_value )";
635
-    $in_use = $wpdb->get_var( $query ) > 0 ? true : false;
634
+    $query  = "SELECT p.ID FROM " . $wpdb->posts . " AS p INNER JOIN " . $wpdb->postmeta . " AS pm ON p.ID = pm.post_id WHERE p.post_type = 'wpi_invoice' AND p.post_status IN( '" . implode("','", $statuses) . "' ) AND pm.meta_key = '_wpinv_item_ids' AND FIND_IN_SET( '" . (int)$item_id . "', pm.meta_value )";
635
+    $in_use = $wpdb->get_var($query) > 0 ? true : false;
636 636
     
637 637
     $wpi_items_in_use[$item_id] = $in_use;
638 638
     
639 639
     return $in_use;
640 640
 }
641 641
 
642
-function wpinv_create_item( $args = array(), $wp_error = false, $force_update = false ) {
642
+function wpinv_create_item($args = array(), $wp_error = false, $force_update = false) {
643 643
     // Set some defaults
644 644
     $defaults = array(
645
-        'type'                 => 'custom',                                                // Optional. Item type. Default 'custom'.
646
-        'title'                => '',                                                      // Required. Item title.
647
-        'custom_id'            => 0,                                                       // Optional. Any integer or non numeric id. Must be unique within item type.
648
-        'price'                => '0.00',                                                  // Optional. Item price. Default '0.00'.
649
-        'status'               => 'pending',                                               // Optional. pending, publish
650
-        'custom_name'          => '',                                                      // Optional. Plural sub title for item.
651
-        'custom_singular_name' => '',                                                      // Optional. Singular sub title for item.
652
-        'vat_rule'             => 'digital',                                               // Optional. digital => Digital item, physical => Physical item
653
-        'excerpt'              => '',                                                      // Optional. Item short description
645
+        'type'                 => 'custom', // Optional. Item type. Default 'custom'.
646
+        'title'                => '', // Required. Item title.
647
+        'custom_id'            => 0, // Optional. Any integer or non numeric id. Must be unique within item type.
648
+        'price'                => '0.00', // Optional. Item price. Default '0.00'.
649
+        'status'               => 'pending', // Optional. pending, publish
650
+        'custom_name'          => '', // Optional. Plural sub title for item.
651
+        'custom_singular_name' => '', // Optional. Singular sub title for item.
652
+        'vat_rule'             => 'digital', // Optional. digital => Digital item, physical => Physical item
653
+        'excerpt'              => '', // Optional. Item short description
654 654
         /* Recurring item fields */
655
-        'is_recurring'         => 0,                                                       // Optional. 1 => Allow recurring or 0 => Don't allow recurring
656
-        'recurring_period'     => 'M',                                                     // Optional. D => Daily, W => Weekly, M => Monthly, Y => Yearly
657
-        'recurring_interval'   => 0,                                                       // Optional. Integer value between 1 - 90.
658
-        'recurring_limit'      => 0,                                                       // Optional. Any integer number. 0 for recurring forever until cancelled.
659
-        'free_trial'           => 0,                                                       // Optional. 1 => Allow free trial or 0 => Don't free trial
660
-        'trial_period'         => 'M',                                                     // Optional. D => Daily, W => Weekly, M => Monthly, Y => Yearly
661
-        'trial_interval'       => 0,                                                       // Optional. Any integer number.
655
+        'is_recurring'         => 0, // Optional. 1 => Allow recurring or 0 => Don't allow recurring
656
+        'recurring_period'     => 'M', // Optional. D => Daily, W => Weekly, M => Monthly, Y => Yearly
657
+        'recurring_interval'   => 0, // Optional. Integer value between 1 - 90.
658
+        'recurring_limit'      => 0, // Optional. Any integer number. 0 for recurring forever until cancelled.
659
+        'free_trial'           => 0, // Optional. 1 => Allow free trial or 0 => Don't free trial
660
+        'trial_period'         => 'M', // Optional. D => Daily, W => Weekly, M => Monthly, Y => Yearly
661
+        'trial_interval'       => 0, // Optional. Any integer number.
662 662
     );
663 663
     
664
-    $data = wp_parse_args( $args, $defaults );
664
+    $data = wp_parse_args($args, $defaults);
665 665
     
666
-    if ( empty( $data['type'] ) ) {
666
+    if (empty($data['type'])) {
667 667
         $data['type'] = 'custom';
668 668
     }
669 669
     
670
-    if ( !empty( $data['custom_id'] ) ) {
671
-        $item = wpinv_get_item_by( 'custom_id', $data['custom_id'], $data['type'] );
670
+    if (!empty($data['custom_id'])) {
671
+        $item = wpinv_get_item_by('custom_id', $data['custom_id'], $data['type']);
672 672
     } else {
673 673
         $item = NULL;
674 674
     }
675 675
     
676
-    if ( !$force_update && !empty( $item ) ) {
676
+    if (!$force_update && !empty($item)) {
677 677
         return $item;
678 678
     }
679 679
         
@@ -682,18 +682,18 @@  discard block
 block discarded – undo
682 682
     $meta['custom_id']              = $data['custom_id'];
683 683
     $meta['custom_singular_name']   = $data['custom_singular_name'];
684 684
     $meta['custom_name']            = $data['custom_name'];
685
-    $meta['price']                  = wpinv_round_amount( $data['price'] );
685
+    $meta['price']                  = wpinv_round_amount($data['price']);
686 686
     $meta['vat_rule']               = $data['vat_rule'];
687 687
     $meta['vat_class']              = '_standard';
688 688
     
689
-    if ( !empty( $data['is_recurring'] ) ) {
689
+    if (!empty($data['is_recurring'])) {
690 690
         $meta['is_recurring']       = $data['is_recurring'];
691 691
         $meta['recurring_period']   = $data['recurring_period'];
692
-        $meta['recurring_interval'] = absint( $data['recurring_interval'] );
693
-        $meta['recurring_limit']    = absint( $data['recurring_limit'] );
692
+        $meta['recurring_interval'] = absint($data['recurring_interval']);
693
+        $meta['recurring_limit']    = absint($data['recurring_limit']);
694 694
         $meta['free_trial']         = $data['free_trial'];
695 695
         $meta['trial_period']       = $data['trial_period'];
696
-        $meta['trial_interval']     = absint( $data['trial_interval'] );
696
+        $meta['trial_interval']     = absint($data['trial_interval']);
697 697
     } else {
698 698
         $meta['is_recurring']       = 0;
699 699
         $meta['recurring_period']   = '';
@@ -704,18 +704,18 @@  discard block
 block discarded – undo
704 704
         $meta['trial_interval']     = '';
705 705
     }
706 706
     
707
-    $post_data  = array( 
707
+    $post_data = array( 
708 708
         'post_title'    => $data['title'],
709 709
         'post_excerpt'  => $data['excerpt'],
710 710
         'post_status'   => $data['status'],
711 711
         'meta'          => $meta
712 712
     );
713 713
 
714
-    if ( !empty( $item ) ) {
715
-        $item->update( $post_data, $wp_error );
714
+    if (!empty($item)) {
715
+        $item->update($post_data, $wp_error);
716 716
     } else {
717 717
         $item = new WPInv_Item();
718
-        $item->create( $post_data, $wp_error );
718
+        $item->create($post_data, $wp_error);
719 719
     }
720 720
     
721 721
     return $item;
Please login to merge, or discard this patch.
includes/class-wpinv.php 1 patch
Spacing   +153 added lines, -153 removed lines patch added patch discarded remove patch
@@ -7,15 +7,15 @@  discard block
 block discarded – undo
7 7
  */
8 8
  
9 9
 // MUST have WordPress.
10
-if ( !defined( 'WPINC' ) ) {
11
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
10
+if (!defined('WPINC')) {
11
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
12 12
 }
13 13
 
14 14
 class WPInv_Plugin {
15 15
     private static $instance;
16 16
     
17 17
     public static function run() {
18
-        if ( !isset( self::$instance ) && !( self::$instance instanceof WPInv_Plugin ) ) {
18
+        if (!isset(self::$instance) && !(self::$instance instanceof WPInv_Plugin)) {
19 19
             self::$instance = new WPInv_Plugin;
20 20
             self::$instance->includes();
21 21
             self::$instance->actions();
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
             self::$instance->reports    = new WPInv_Reports();
24 24
         }
25 25
         
26
-        do_action( 'wpinv_loaded' );
26
+        do_action('wpinv_loaded');
27 27
         
28 28
         return self::$instance;
29 29
     }
@@ -33,31 +33,31 @@  discard block
 block discarded – undo
33 33
     }
34 34
     
35 35
     public function define_constants() {
36
-        define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) );
37
-        define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) );
36
+        define('WPINV_PLUGIN_DIR', plugin_dir_path(WPINV_PLUGIN_FILE));
37
+        define('WPINV_PLUGIN_URL', plugin_dir_url(WPINV_PLUGIN_FILE));
38 38
     }
39 39
     
40 40
     private function actions() {
41 41
         /* Internationalize the text strings used. */
42
-        add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) );
42
+        add_action('plugins_loaded', array(&$this, 'plugins_loaded'));
43 43
         
44 44
         /* Perform actions on admin initialization. */
45
-        add_action( 'admin_init', array( &$this, 'admin_init') );
46
-        add_action( 'init', array( &$this, 'init' ), 3 );
47
-        add_action( 'init', array( 'WPInv_Shortcodes', 'init' ) );
48
-        add_action( 'init', array( &$this, 'wpinv_actions' ) );
45
+        add_action('admin_init', array(&$this, 'admin_init'));
46
+        add_action('init', array(&$this, 'init'), 3);
47
+        add_action('init', array('WPInv_Shortcodes', 'init'));
48
+        add_action('init', array(&$this, 'wpinv_actions'));
49 49
         
50
-        if ( class_exists( 'BuddyPress' ) ) {
51
-            add_action( 'bp_include', array( &$this, 'bp_invoicing_init' ) );
50
+        if (class_exists('BuddyPress')) {
51
+            add_action('bp_include', array(&$this, 'bp_invoicing_init'));
52 52
         }
53 53
 
54
-        add_action( 'wp_enqueue_scripts', array( &$this, 'enqueue_scripts' ) );
54
+        add_action('wp_enqueue_scripts', array(&$this, 'enqueue_scripts'));
55 55
         
56
-        if ( is_admin() ) {
57
-            add_action( 'admin_enqueue_scripts', array( &$this, 'admin_enqueue_scripts' ) );
58
-            add_action( 'admin_body_class', array( &$this, 'admin_body_class' ) );
56
+        if (is_admin()) {
57
+            add_action('admin_enqueue_scripts', array(&$this, 'admin_enqueue_scripts'));
58
+            add_action('admin_body_class', array(&$this, 'admin_body_class'));
59 59
         } else {
60
-            add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) );
60
+            add_filter('pre_get_posts', array(&$this, 'pre_get_posts'));
61 61
         }
62 62
         
63 63
         /**
@@ -67,9 +67,9 @@  discard block
 block discarded – undo
67 67
          *
68 68
          * @param WPInv_Plugin $this. Current WPInv_Plugin instance. Passed by reference.
69 69
          */
70
-        do_action_ref_array( 'wpinv_actions', array( &$this ) );
70
+        do_action_ref_array('wpinv_actions', array(&$this));
71 71
 
72
-        add_action( 'admin_init', array( &$this, 'activation_redirect') );
72
+        add_action('admin_init', array(&$this, 'activation_redirect'));
73 73
     }
74 74
     
75 75
     public function plugins_loaded() {
@@ -83,193 +83,193 @@  discard block
 block discarded – undo
83 83
      * @since 1.0
84 84
      */
85 85
     public function load_textdomain() {
86
-        $locale = apply_filters( 'plugin_locale', get_locale(), 'invoicing' );
86
+        $locale = apply_filters('plugin_locale', get_locale(), 'invoicing');
87 87
         
88
-        load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' );
89
-        load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' );
88
+        load_textdomain('invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo');
89
+        load_plugin_textdomain('invoicing', false, WPINV_PLUGIN_DIR . 'languages');
90 90
         
91 91
         /**
92 92
          * Define language constants.
93 93
          */
94
-        require_once( WPINV_PLUGIN_DIR . 'language.php' );
94
+        require_once(WPINV_PLUGIN_DIR . 'language.php');
95 95
     }
96 96
         
97 97
     public function includes() {
98 98
         global $wpinv_options;
99 99
         
100
-        require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' );
100
+        require_once(WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php');
101 101
         $wpinv_options = wpinv_get_settings();
102 102
         
103
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-post-types.php' );
104
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' );
105
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' );
106
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' );
107
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' );
108
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' );
109
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' );
110
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-invoice-functions.php' );
111
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' );
112
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' );
113
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' );
114
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' );
115
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php' );
116
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gd-functions.php' );
117
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-error-functions.php' );
103
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-post-types.php');
104
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php');
105
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php');
106
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php');
107
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php');
108
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php');
109
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php');
110
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-invoice-functions.php');
111
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php');
112
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php');
113
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php');
114
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php');
115
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php');
116
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-gd-functions.php');
117
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-error-functions.php');
118 118
         //require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' );
119 119
         //require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' );
120
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-invoice.php' );
120
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-invoice.php');
121 121
         //require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscription.php' );
122
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-item.php' );
123
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-notes.php' );
124
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session.php' );
125
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' );
126
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' );
127
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php' );
128
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-shortcodes.php' );
129
-        if ( !class_exists( 'Geodir_EUVat' ) ) {
130
-            require_once( WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php' );
122
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-item.php');
123
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-notes.php');
124
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-session.php');
125
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php');
126
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php');
127
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php');
128
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-shortcodes.php');
129
+        if (!class_exists('Geodir_EUVat')) {
130
+            require_once(WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php');
131 131
         }
132 132
         
133
-        $gateways = array_keys( wpinv_get_enabled_payment_gateways() );
134
-        if ( !empty( $gateways ) ) {
135
-            foreach ( $gateways as $gateway ) {
136
-                if ( $gateway == 'manual' ) {
133
+        $gateways = array_keys(wpinv_get_enabled_payment_gateways());
134
+        if (!empty($gateways)) {
135
+            foreach ($gateways as $gateway) {
136
+                if ($gateway == 'manual') {
137 137
                     continue;
138 138
                 }
139 139
                 
140 140
                 $gateway_file = WPINV_PLUGIN_DIR . 'includes/gateways/' . $gateway . '.php';
141 141
                 
142
-                if ( file_exists( $gateway_file ) ) {
143
-                    require_once( $gateway_file );
142
+                if (file_exists($gateway_file)) {
143
+                    require_once($gateway_file);
144 144
                 }
145 145
             }
146 146
         }
147
-        require_once( WPINV_PLUGIN_DIR . 'includes/gateways/manual.php' );
147
+        require_once(WPINV_PLUGIN_DIR . 'includes/gateways/manual.php');
148 148
         
149
-        if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) {
150
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php' );
151
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' );
152
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-meta-boxes.php' );
149
+        if (is_admin() || (defined('WP_CLI') && WP_CLI)) {
150
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php');
151
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php');
152
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/admin-meta-boxes.php');
153 153
             //require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-recurring-admin.php' );
154
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-details.php' );
155
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-items.php' );
156
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' );
157
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-address.php' );
158
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' );
154
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-details.php');
155
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-items.php');
156
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php');
157
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-address.php');
158
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php');
159 159
             //require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' );
160 160
         }
161 161
         
162 162
         // include css inliner
163
-        if ( ! class_exists( 'Emogrifier' ) && class_exists( 'DOMDocument' ) ) {
164
-            include_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php' );
163
+        if (!class_exists('Emogrifier') && class_exists('DOMDocument')) {
164
+            include_once(WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php');
165 165
         }
166 166
         
167
-        require_once( WPINV_PLUGIN_DIR . 'includes/admin/install.php' );
167
+        require_once(WPINV_PLUGIN_DIR . 'includes/admin/install.php');
168 168
     }
169 169
     
170 170
     public function init() {
171 171
     }
172 172
     
173 173
     public function admin_init() {
174
-        if (!(defined( 'DOING_AJAX' ) && DOING_AJAX)) {
174
+        if (!(defined('DOING_AJAX') && DOING_AJAX)) {
175 175
         }
176 176
         
177
-        add_action( 'admin_print_scripts-edit.php', array( &$this, 'admin_print_scripts_edit_php' ) );
177
+        add_action('admin_print_scripts-edit.php', array(&$this, 'admin_print_scripts_edit_php'));
178 178
     }
179 179
 
180 180
     public function activation_redirect() {
181 181
         // Bail if no activation redirect
182
-        if ( !get_transient( '_wpinv_activation_redirect' ) ) {
182
+        if (!get_transient('_wpinv_activation_redirect')) {
183 183
             return;
184 184
         }
185 185
 
186 186
         // Delete the redirect transient
187
-        delete_transient( '_wpinv_activation_redirect' );
187
+        delete_transient('_wpinv_activation_redirect');
188 188
 
189 189
         // Bail if activating from network, or bulk
190
-        if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) {
190
+        if (is_network_admin() || isset($_GET['activate-multi'])) {
191 191
             return;
192 192
         }
193 193
 
194
-        wp_safe_redirect( admin_url( 'admin.php?page=wpinv-settings&tab=general' ) );
194
+        wp_safe_redirect(admin_url('admin.php?page=wpinv-settings&tab=general'));
195 195
         exit;
196 196
     }
197 197
     
198 198
     public function enqueue_scripts() {
199
-        $suffix       = '';//defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
199
+        $suffix = ''; //defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
200 200
         
201
-        wp_deregister_style( 'font-awesome' );
202
-        wp_register_style( 'font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome' . $suffix . '.css', array(), '4.7.0' );
203
-        wp_enqueue_style( 'font-awesome' );
201
+        wp_deregister_style('font-awesome');
202
+        wp_register_style('font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome' . $suffix . '.css', array(), '4.7.0');
203
+        wp_enqueue_style('font-awesome');
204 204
         
205
-        wp_register_style( 'wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), WPINV_VERSION );
206
-        wp_enqueue_style( 'wpinv_front_style' );
205
+        wp_register_style('wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), WPINV_VERSION);
206
+        wp_enqueue_style('wpinv_front_style');
207 207
                
208 208
         // Register scripts
209
-        wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true );
210
-        wp_register_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front' . $suffix . '.js', array( 'jquery', 'wpinv-vat-script' ),  WPINV_VERSION );
209
+        wp_register_script('jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array('jquery'), '2.70', true);
210
+        wp_register_script('wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front' . $suffix . '.js', array('jquery', 'wpinv-vat-script'), WPINV_VERSION);
211 211
         
212 212
         $localize                         = array();
213
-        $localize['ajax_url']             = admin_url( 'admin-ajax.php' );
214
-        $localize['nonce']                = wp_create_nonce( 'wpinv-nonce' );
213
+        $localize['ajax_url']             = admin_url('admin-ajax.php');
214
+        $localize['nonce']                = wp_create_nonce('wpinv-nonce');
215 215
         $localize['currency_symbol']      = wpinv_currency_symbol();
216 216
         $localize['currency_pos']         = wpinv_currency_position();
217 217
         $localize['thousand_sep']         = wpinv_thousands_separator();
218 218
         $localize['decimal_sep']          = wpinv_decimal_separator();
219 219
         $localize['decimals']             = wpinv_decimals();
220 220
         
221
-        $localize = apply_filters( 'wpinv_front_js_localize', $localize );
221
+        $localize = apply_filters('wpinv_front_js_localize', $localize);
222 222
         
223
-        wp_enqueue_script( 'jquery-blockui' );
224
-        wp_enqueue_script( 'wpinv-front-script' );
225
-        wp_localize_script( 'wpinv-front-script', 'WPInv', $localize );
223
+        wp_enqueue_script('jquery-blockui');
224
+        wp_enqueue_script('wpinv-front-script');
225
+        wp_localize_script('wpinv-front-script', 'WPInv', $localize);
226 226
     }
227 227
     
228 228
     public function admin_enqueue_scripts() {
229 229
         global $post, $pagenow;
230 230
         
231 231
         $post_type  = wpinv_admin_post_type();
232
-        $suffix     = '';//defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
232
+        $suffix     = ''; //defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
233 233
         
234
-        wp_deregister_style( 'font-awesome' );
235
-        wp_register_style( 'font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome' . $suffix . '.css', array(), '4.7.0' );
236
-        wp_enqueue_style( 'font-awesome' );
234
+        wp_deregister_style('font-awesome');
235
+        wp_register_style('font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome' . $suffix . '.css', array(), '4.7.0');
236
+        wp_enqueue_style('font-awesome');
237 237
         
238
-        wp_register_style( 'jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui' . $suffix . '.css', array(), '1.8.16' );
239
-        wp_enqueue_style( 'jquery-ui-css' );
238
+        wp_register_style('jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui' . $suffix . '.css', array(), '1.8.16');
239
+        wp_enqueue_style('jquery-ui-css');
240 240
         
241
-        wp_register_style( 'jquery-chosen', WPINV_PLUGIN_URL . 'assets/css/chosen' . $suffix . '.css', array(), '1.6.2' );
242
-        wp_enqueue_style( 'jquery-chosen' );
241
+        wp_register_style('jquery-chosen', WPINV_PLUGIN_URL . 'assets/css/chosen' . $suffix . '.css', array(), '1.6.2');
242
+        wp_enqueue_style('jquery-chosen');
243 243
 
244
-        wp_register_script( 'jquery-chosen', WPINV_PLUGIN_URL . 'assets/js/chosen.jquery' . $suffix . '.js', array( 'jquery' ), '1.6.2' );
245
-        wp_enqueue_script( 'jquery-chosen' );
244
+        wp_register_script('jquery-chosen', WPINV_PLUGIN_URL . 'assets/js/chosen.jquery' . $suffix . '.js', array('jquery'), '1.6.2');
245
+        wp_enqueue_script('jquery-chosen');
246 246
         
247
-        wp_register_style( 'wpinv_meta_box_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION );
248
-        wp_enqueue_style( 'wpinv_meta_box_style' );
247
+        wp_register_style('wpinv_meta_box_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION);
248
+        wp_enqueue_style('wpinv_meta_box_style');
249 249
         
250
-        wp_register_style( 'wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array(), WPINV_VERSION );
251
-        wp_enqueue_style( 'wpinv_admin_style' );
250
+        wp_register_style('wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array(), WPINV_VERSION);
251
+        wp_enqueue_style('wpinv_admin_style');
252 252
         
253
-        if ( $post_type == 'wpi_discount' || $post_type == 'wpi_invoice' && ( $pagenow == 'post-new.php' || $pagenow == 'post.php' ) ) {
254
-            wp_enqueue_script( 'jquery-ui-datepicker' );
253
+        if ($post_type == 'wpi_discount' || $post_type == 'wpi_invoice' && ($pagenow == 'post-new.php' || $pagenow == 'post.php')) {
254
+            wp_enqueue_script('jquery-ui-datepicker');
255 255
         }
256 256
 
257
-        wp_enqueue_style( 'wp-color-picker' );
258
-        wp_enqueue_script( 'wp-color-picker' );
257
+        wp_enqueue_style('wp-color-picker');
258
+        wp_enqueue_script('wp-color-picker');
259 259
         
260
-        wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true );
260
+        wp_register_script('jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array('jquery'), '2.70', true);
261 261
         
262
-        wp_register_script( 'wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin' . $suffix . '.js', array( 'jquery', 'jquery-blockui' ),  WPINV_VERSION );
263
-        wp_enqueue_script( 'wpinv-admin-script' );
262
+        wp_register_script('wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin' . $suffix . '.js', array('jquery', 'jquery-blockui'), WPINV_VERSION);
263
+        wp_enqueue_script('wpinv-admin-script');
264 264
         
265 265
         $localize                               = array();
266
-        $localize['ajax_url']                   = admin_url( 'admin-ajax.php' );
267
-        $localize['post_ID']                    = isset( $post->ID ) ? $post->ID : '';
268
-        $localize['wpinv_nonce']                = wp_create_nonce( 'wpinv-nonce' );
269
-        $localize['add_invoice_note_nonce']     = wp_create_nonce( 'add-invoice-note' );
270
-        $localize['delete_invoice_note_nonce']  = wp_create_nonce( 'delete-invoice-note' );
271
-        $localize['invoice_item_nonce']         = wp_create_nonce( 'invoice-item' );
272
-        $localize['billing_details_nonce']      = wp_create_nonce( 'get-billing-details' );
266
+        $localize['ajax_url']                   = admin_url('admin-ajax.php');
267
+        $localize['post_ID']                    = isset($post->ID) ? $post->ID : '';
268
+        $localize['wpinv_nonce']                = wp_create_nonce('wpinv-nonce');
269
+        $localize['add_invoice_note_nonce']     = wp_create_nonce('add-invoice-note');
270
+        $localize['delete_invoice_note_nonce']  = wp_create_nonce('delete-invoice-note');
271
+        $localize['invoice_item_nonce']         = wp_create_nonce('invoice-item');
272
+        $localize['billing_details_nonce']      = wp_create_nonce('get-billing-details');
273 273
         $localize['tax']                        = wpinv_tax_amount();
274 274
         $localize['discount']                   = wpinv_discount_amount();
275 275
         $localize['currency_symbol']            = wpinv_currency_symbol();
@@ -277,55 +277,55 @@  discard block
 block discarded – undo
277 277
         $localize['thousand_sep']               = wpinv_thousands_separator();
278 278
         $localize['decimal_sep']                = wpinv_decimal_separator();
279 279
         $localize['decimals']                   = wpinv_decimals();
280
-        $localize['save_invoice']               = __( 'Save Invoice', 'invoicing' );
281
-        $localize['status_publish']             = wpinv_status_nicename( 'publish' );
282
-        $localize['status_pending']             = wpinv_status_nicename( 'pending' );
283
-        $localize['delete_tax_rate']            = __( 'Are you sure you wish to delete this tax rate?', 'invoicing' );
284
-        $localize['OneItemMin']                 = __( 'Invoice must contain at least one item', 'invoicing' );
285
-        $localize['DeleteInvoiceItem']          = __( 'Are you sure you wish to delete this item?', 'invoicing' );
286
-        $localize['FillBillingDetails']         = __( 'Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing' );
287
-        $localize['confirmCalcTotals']          = __( 'Recalculate totals? This will recalculate totals based on the user billing country. If no billing country is set it will use the base country.', 'invoicing' );
288
-        $localize['AreYouSure']                 = __( 'Are you sure?', 'invoicing' );
289
-        $localize['hasGD']                      = wpinv_gd_active();;
280
+        $localize['save_invoice']               = __('Save Invoice', 'invoicing');
281
+        $localize['status_publish']             = wpinv_status_nicename('publish');
282
+        $localize['status_pending']             = wpinv_status_nicename('pending');
283
+        $localize['delete_tax_rate']            = __('Are you sure you wish to delete this tax rate?', 'invoicing');
284
+        $localize['OneItemMin']                 = __('Invoice must contain at least one item', 'invoicing');
285
+        $localize['DeleteInvoiceItem']          = __('Are you sure you wish to delete this item?', 'invoicing');
286
+        $localize['FillBillingDetails']         = __('Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing');
287
+        $localize['confirmCalcTotals']          = __('Recalculate totals? This will recalculate totals based on the user billing country. If no billing country is set it will use the base country.', 'invoicing');
288
+        $localize['AreYouSure']                 = __('Are you sure?', 'invoicing');
289
+        $localize['hasGD']                      = wpinv_gd_active(); ;
290 290
         $localize['hasPM']                      = wpinv_pm_active();
291
-        $localize['emptyInvoice']               = __( 'Add atleast one item to save invoice!', 'invoicing' );
292
-        $localize['deletePackage']              = __( 'GD package items should be deleted from GD payment manager only, otherwise it will break invoices that created with this package!', 'invoicing' );
293
-        $localize['deletePackages']             = __( 'GD package items should be deleted from GD payment manager only', 'invoicing' );
294
-        $localize['deleteInvoiceFirst']         = __( 'This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing' );
291
+        $localize['emptyInvoice']               = __('Add atleast one item to save invoice!', 'invoicing');
292
+        $localize['deletePackage']              = __('GD package items should be deleted from GD payment manager only, otherwise it will break invoices that created with this package!', 'invoicing');
293
+        $localize['deletePackages']             = __('GD package items should be deleted from GD payment manager only', 'invoicing');
294
+        $localize['deleteInvoiceFirst']         = __('This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing');
295 295
         
296
-        wp_localize_script( 'wpinv-admin-script', 'WPInv_Admin', $localize );
296
+        wp_localize_script('wpinv-admin-script', 'WPInv_Admin', $localize);
297 297
     }
298 298
     
299
-    public function admin_body_class( $classes ) {
299
+    public function admin_body_class($classes) {
300 300
         global $pagenow;
301 301
         
302
-        $page = isset( $_GET['page'] ) ? strtolower( $_GET['page'] ) : false;
302
+        $page = isset($_GET['page']) ? strtolower($_GET['page']) : false;
303 303
 
304 304
         $add_class = false;
305
-        if ( $pagenow == 'admin.php' && $page ) {
306
-            $add_class = strpos( $page, 'wpinv-' );
305
+        if ($pagenow == 'admin.php' && $page) {
306
+            $add_class = strpos($page, 'wpinv-');
307 307
         }
308 308
         
309 309
         $settings_class = array();
310
-        if ( $page == 'wpinv-settings' ) {
311
-            if ( !empty( $_REQUEST['tab'] ) ) {
312
-                $settings_class[] = sanitize_text_field( $_REQUEST['tab'] );
310
+        if ($page == 'wpinv-settings') {
311
+            if (!empty($_REQUEST['tab'])) {
312
+                $settings_class[] = sanitize_text_field($_REQUEST['tab']);
313 313
             }
314 314
             
315
-            if ( !empty( $_REQUEST['section'] ) ) {
316
-                $settings_class[] = sanitize_text_field( $_REQUEST['section'] );
315
+            if (!empty($_REQUEST['section'])) {
316
+                $settings_class[] = sanitize_text_field($_REQUEST['section']);
317 317
             }
318 318
             
319
-            $settings_class[] = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' ? sanitize_text_field( $_REQUEST['wpi_sub'] ) : 'main';
319
+            $settings_class[] = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' ? sanitize_text_field($_REQUEST['wpi_sub']) : 'main';
320 320
         }
321 321
         
322
-        if ( !empty( $settings_class ) ) {
323
-            $classes .= ' wpi-' . wpinv_sanitize_key( implode( $settings_class, '-' ) );
322
+        if (!empty($settings_class)) {
323
+            $classes .= ' wpi-' . wpinv_sanitize_key(implode($settings_class, '-'));
324 324
         }
325 325
         
326 326
         $post_type = wpinv_admin_post_type();
327 327
         
328
-        if ( $post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $add_class !== false ) {
328
+        if ($post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $add_class !== false) {
329 329
             return $classes .= ' wpinv';
330 330
         } else {
331 331
             return $classes;
@@ -337,26 +337,26 @@  discard block
 block discarded – undo
337 337
     public function admin_print_scripts_edit_php() {
338 338
         $post_type = wpinv_admin_post_type();
339 339
         
340
-        if ( $post_type == 'wpi_item' ) {
341
-            wp_enqueue_script( 'wpinv-inline-edit-post', WPINV_PLUGIN_URL . 'assets/js/quick-edit.js', array( 'jquery', 'inline-edit-post' ), '', true );
340
+        if ($post_type == 'wpi_item') {
341
+            wp_enqueue_script('wpinv-inline-edit-post', WPINV_PLUGIN_URL . 'assets/js/quick-edit.js', array('jquery', 'inline-edit-post'), '', true);
342 342
         }
343 343
     }
344 344
     
345 345
     public function wpinv_actions() {
346
-        if ( isset( $_REQUEST['wpi_action'] ) ) {
347
-            do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST );
346
+        if (isset($_REQUEST['wpi_action'])) {
347
+            do_action('wpinv_' . wpinv_sanitize_key($_REQUEST['wpi_action']), $_REQUEST);
348 348
         }
349 349
     }
350 350
     
351
-    public function pre_get_posts( $wp_query ) {
352
-        if ( !empty( $wp_query->query_vars['post_type'] ) && $wp_query->query_vars['post_type'] == 'wpi_invoice' && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) {
353
-            $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses() );
351
+    public function pre_get_posts($wp_query) {
352
+        if (!empty($wp_query->query_vars['post_type']) && $wp_query->query_vars['post_type'] == 'wpi_invoice' && is_user_logged_in() && is_single() && $wp_query->is_main_query()) {
353
+            $wp_query->query_vars['post_status'] = array_keys(wpinv_get_invoice_statuses());
354 354
         }
355 355
         
356 356
         return $wp_query;
357 357
     }
358 358
     
359 359
     public function bp_invoicing_init() {
360
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' );
360
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php');
361 361
     }
362 362
 }
363 363
\ No newline at end of file
Please login to merge, or discard this patch.
includes/wpinv-invoice-functions.php 1 patch
Spacing   +563 added lines, -563 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'] = '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,20 +79,20 @@  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
-    $user_info = wp_parse_args( $invoice_data['user_info'], $default_user_info );
88
+    $user_info = wp_parse_args($invoice_data['user_info'], $default_user_info);
89 89
     
90
-    if ( empty( $user_info['first_name'] ) ) {
90
+    if (empty($user_info['first_name'])) {
91 91
         $user_info['first_name'] = $default_user_info['first_name'];
92 92
         $user_info['last_name'] = $default_user_info['last_name'];
93 93
     }
94 94
     
95
-    if ( empty( $user_info['country'] ) ) {
95
+    if (empty($user_info['country'])) {
96 96
         $user_info['country'] = $default_user_info['country'];
97 97
         $user_info['state'] = $default_user_info['state'];
98 98
         $user_info['city'] = $default_user_info['city'];
@@ -101,13 +101,13 @@  discard block
 block discarded – undo
101 101
         $user_info['phone'] = $default_user_info['phone'];
102 102
     }
103 103
     
104
-    if ( !empty( $user_info['discount'] ) && !is_array( $user_info['discount'] ) ) {
104
+    if (!empty($user_info['discount']) && !is_array($user_info['discount'])) {
105 105
         $user_info['discount'] = (array)$user_info['discount'];
106 106
     }
107 107
 
108 108
     // Payment details
109 109
     $payment_details = array();
110
-    if ( !empty( $invoice_data['payment_details'] ) ) {
110
+    if (!empty($invoice_data['payment_details'])) {
111 111
         $default_payment_details = array(
112 112
             'gateway'           => 'manual',
113 113
             'gateway_title'     => '',
@@ -115,59 +115,59 @@  discard block
 block discarded – undo
115 115
             'transaction_id'    => '',
116 116
         );
117 117
         
118
-        $payment_details = wp_parse_args( $invoice_data['payment_details'], $default_payment_details );
118
+        $payment_details = wp_parse_args($invoice_data['payment_details'], $default_payment_details);
119 119
         
120
-        if ( empty( $payment_details['gateway'] ) ) {
120
+        if (empty($payment_details['gateway'])) {
121 121
             $payment_details['gateway'] = 'manual';
122 122
         }
123 123
         
124
-        if ( empty( $payment_details['currency'] ) ) {
124
+        if (empty($payment_details['currency'])) {
125 125
             $payment_details['currency'] = geodir_get_currency_type();
126 126
         }
127 127
         
128
-        if ( empty( $payment_details['gateway_title'] ) ) {
129
-            $payment_details['gateway_title'] = wpinv_get_gateway_checkout_label( $payment_details['gateway'] );
128
+        if (empty($payment_details['gateway_title'])) {
129
+            $payment_details['gateway_title'] = wpinv_get_gateway_checkout_label($payment_details['gateway']);
130 130
         }
131 131
     }
132 132
     
133
-    $invoice->set( 'status', ( !empty( $invoice_data['status'] ) ? $invoice_data['status'] : 'pending' ) );
134
-    
135
-    if ( !empty( $payment_details ) ) {
136
-        $invoice->set( 'currency', $payment_details['currency'] );
137
-        $invoice->set( 'gateway', $payment_details['gateway'] );
138
-        $invoice->set( 'gateway_title', $payment_details['gateway_title'] );
139
-        $invoice->set( 'transaction_id', $payment_details['transaction_id'] );
140
-    }
141
-    
142
-    $invoice->set( 'user_info', $user_info );
143
-    $invoice->set( 'first_name', $user_info['first_name'] );
144
-    $invoice->set( 'last_name', $user_info['last_name'] );
145
-    $invoice->set( 'address', $user_info['address'] );
146
-    $invoice->set( 'company', $user_info['company'] );
147
-    $invoice->set( 'vat_number', $user_info['vat_number'] );
148
-    $invoice->set( 'phone', $user_info['phone'] );
149
-    $invoice->set( 'city', $user_info['city'] );
150
-    $invoice->set( 'country', $user_info['country'] );
151
-    $invoice->set( 'state', $user_info['state'] );
152
-    $invoice->set( 'zip', $user_info['zip'] );
153
-    $invoice->set( 'discounts', $user_info['discount'] );
154
-    $invoice->set( 'ip', ( !empty( $invoice_data['ip'] ) ? $invoice_data['ip'] : wpinv_get_ip() ) );
155
-    if ( !empty( $invoice_data['invoice_key'] ) ) {
156
-        $invoice->set( 'key', $invoice_data['invoice_key'] );
157
-    }
158
-    $invoice->set( 'mode', ( wpinv_is_test_mode() ? 'test' : 'live' ) );
159
-    $invoice->set( 'parent_invoice', ( !empty( $invoice_data['parent'] ) ? absint( $invoice_data['parent'] ) : '' ) );
160
-    
161
-    if ( !empty( $invoice_data['cart_details'] ) && is_array( $invoice_data['cart_details'] ) ) {
162
-        foreach ( $invoice_data['cart_details'] as $key => $item ) {
163
-            $item_id        = !empty( $item['id'] ) ? $item['id'] : 0;
164
-            $quantity       = !empty( $item['quantity'] ) ? $item['quantity'] : 1;
165
-            $name           = !empty( $item['name'] ) ? $item['name'] : '';
166
-            $item_price     = isset( $item['item_price'] ) ? $item['item_price'] : '';
133
+    $invoice->set('status', (!empty($invoice_data['status']) ? $invoice_data['status'] : 'pending'));
134
+    
135
+    if (!empty($payment_details)) {
136
+        $invoice->set('currency', $payment_details['currency']);
137
+        $invoice->set('gateway', $payment_details['gateway']);
138
+        $invoice->set('gateway_title', $payment_details['gateway_title']);
139
+        $invoice->set('transaction_id', $payment_details['transaction_id']);
140
+    }
141
+    
142
+    $invoice->set('user_info', $user_info);
143
+    $invoice->set('first_name', $user_info['first_name']);
144
+    $invoice->set('last_name', $user_info['last_name']);
145
+    $invoice->set('address', $user_info['address']);
146
+    $invoice->set('company', $user_info['company']);
147
+    $invoice->set('vat_number', $user_info['vat_number']);
148
+    $invoice->set('phone', $user_info['phone']);
149
+    $invoice->set('city', $user_info['city']);
150
+    $invoice->set('country', $user_info['country']);
151
+    $invoice->set('state', $user_info['state']);
152
+    $invoice->set('zip', $user_info['zip']);
153
+    $invoice->set('discounts', $user_info['discount']);
154
+    $invoice->set('ip', (!empty($invoice_data['ip']) ? $invoice_data['ip'] : wpinv_get_ip()));
155
+    if (!empty($invoice_data['invoice_key'])) {
156
+        $invoice->set('key', $invoice_data['invoice_key']);
157
+    }
158
+    $invoice->set('mode', (wpinv_is_test_mode() ? 'test' : 'live'));
159
+    $invoice->set('parent_invoice', (!empty($invoice_data['parent']) ? absint($invoice_data['parent']) : ''));
160
+    
161
+    if (!empty($invoice_data['cart_details']) && is_array($invoice_data['cart_details'])) {
162
+        foreach ($invoice_data['cart_details'] as $key => $item) {
163
+            $item_id        = !empty($item['id']) ? $item['id'] : 0;
164
+            $quantity       = !empty($item['quantity']) ? $item['quantity'] : 1;
165
+            $name           = !empty($item['name']) ? $item['name'] : '';
166
+            $item_price     = isset($item['item_price']) ? $item['item_price'] : '';
167 167
             
168
-            $post_item  = new WPInv_Item( $item_id );
169
-            if ( !empty( $post_item ) ) {
170
-                $name       = !empty( $name ) ? $name : $post_item->get_name();
168
+            $post_item = new WPInv_Item($item_id);
169
+            if (!empty($post_item)) {
170
+                $name       = !empty($name) ? $name : $post_item->get_name();
171 171
                 $item_price = $item_price !== '' ? $item_price : $post_item->get_price();
172 172
             } else {
173 173
                 continue;
@@ -177,494 +177,494 @@  discard block
 block discarded – undo
177 177
                 'name'          => $name,
178 178
                 'quantity'      => $quantity,
179 179
                 'item_price'    => $item_price,
180
-                'custom_price'  => isset( $item['custom_price'] ) ? $item['custom_price'] : '',
181
-                'tax'           => !empty( $item['tax'] ) ? $item['tax'] : 0.00,
182
-                'discount'      => isset( $item['discount'] ) ? $item['discount'] : 0,
183
-                'meta'          => isset( $item['meta'] ) ? $item['meta'] : array(),
184
-                'fees'          => isset( $item['fees'] ) ? $item['fees'] : array(),
180
+                'custom_price'  => isset($item['custom_price']) ? $item['custom_price'] : '',
181
+                'tax'           => !empty($item['tax']) ? $item['tax'] : 0.00,
182
+                'discount'      => isset($item['discount']) ? $item['discount'] : 0,
183
+                'meta'          => isset($item['meta']) ? $item['meta'] : array(),
184
+                'fees'          => isset($item['fees']) ? $item['fees'] : array(),
185 185
             );
186 186
 
187
-            $invoice->add_item( $item_id, $args );
187
+            $invoice->add_item($item_id, $args);
188 188
         }
189 189
     }
190 190
 
191
-    $invoice->increase_tax( wpinv_get_cart_fee_tax() );
191
+    $invoice->increase_tax(wpinv_get_cart_fee_tax());
192 192
 
193
-    if ( isset( $invoice_data['post_date'] ) ) {
194
-        $invoice->set( 'date', $invoice_data['post_date'] );
193
+    if (isset($invoice_data['post_date'])) {
194
+        $invoice->set('date', $invoice_data['post_date']);
195 195
     }
196 196
 
197
-    $number = wpinv_format_invoice_number( $invoice->ID );
198
-    $invoice->set( 'number', $number );
199
-    update_option( 'wpinv_last_invoice_number', $number );
197
+    $number = wpinv_format_invoice_number($invoice->ID);
198
+    $invoice->set('number', $number);
199
+    update_option('wpinv_last_invoice_number', $number);
200 200
     
201 201
     $invoice->save();
202 202
     
203 203
     // Add notes
204
-    if ( !empty( $invoice_data['private_note'] ) ) {
205
-        $invoice->add_note( $invoice_data['private_note'] );
204
+    if (!empty($invoice_data['private_note'])) {
205
+        $invoice->add_note($invoice_data['private_note']);
206 206
     }
207
-    if ( !empty( $invoice_data['user_note'] ) ) {
208
-        $invoice->add_note( $invoice_data['user_note'], true );
207
+    if (!empty($invoice_data['user_note'])) {
208
+        $invoice->add_note($invoice_data['user_note'], true);
209 209
     }
210 210
     
211
-    do_action( 'wpinv_insert_invoice', $invoice->ID, $invoice_data );
211
+    do_action('wpinv_insert_invoice', $invoice->ID, $invoice_data);
212 212
 
213
-    if ( ! empty( $invoice->ID ) ) {
213
+    if (!empty($invoice->ID)) {
214 214
         global $wpi_userID, $wpinv_ip_address_country;
215 215
         
216 216
         $checkout_session = wpinv_get_checkout_session();
217 217
         
218 218
         $data_session                   = array();
219 219
         $data_session['invoice_id']     = $invoice->ID;
220
-        $data_session['cart_discounts'] = $invoice->get_discounts( true );
220
+        $data_session['cart_discounts'] = $invoice->get_discounts(true);
221 221
         
222
-        wpinv_set_checkout_session( $data_session );
222
+        wpinv_set_checkout_session($data_session);
223 223
         
224 224
         $wpi_userID         = (int)$invoice->get_user_id();
225 225
         
226
-        $_POST['country']   = !empty( $invoice->country ) ? $invoice->country : wpinv_get_default_country();
226
+        $_POST['country']   = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country();
227 227
         $_POST['state']     = $invoice->state;
228 228
 
229
-        $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) );
230
-        $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) );
229
+        $invoice->set('country', sanitize_text_field($_POST['country']));
230
+        $invoice->set('state', sanitize_text_field($_POST['state']));
231 231
         
232 232
         $wpinv_ip_address_country = $invoice->country;
233 233
         
234
-        $invoice = $invoice->recalculate_totals( true );
234
+        $invoice = $invoice->recalculate_totals(true);
235 235
         
236
-        wpinv_set_checkout_session( $checkout_session );
236
+        wpinv_set_checkout_session($checkout_session);
237 237
                     
238 238
         return $invoice;
239 239
     }
240 240
     
241
-    if ( $wp_error ) {
242
-        if ( is_wp_error( $invoice ) ) {
241
+    if ($wp_error) {
242
+        if (is_wp_error($invoice)) {
243 243
             return $invoice;
244 244
         } else {
245
-            return new WP_Error( 'wpinv_insert_invoice_error', __( 'Error in insert invoice.', 'invoicing' ) );
245
+            return new WP_Error('wpinv_insert_invoice_error', __('Error in insert invoice.', 'invoicing'));
246 246
         }
247 247
     } else {
248 248
         return 0;
249 249
     }
250 250
 }
251 251
 
252
-function wpinv_get_invoice( $invoice_id = 0, $cart = false ) {
253
-    if ( $cart && empty( $invoice_id ) ) {
252
+function wpinv_get_invoice($invoice_id = 0, $cart = false) {
253
+    if ($cart && empty($invoice_id)) {
254 254
         $invoice_id = (int)wpinv_get_invoice_cart_id();
255 255
     }
256 256
 
257
-    $invoice = new WPInv_Invoice( $invoice_id );
257
+    $invoice = new WPInv_Invoice($invoice_id);
258 258
     return $invoice;
259 259
 }
260 260
 
261
-function wpinv_get_invoice_cart( $invoice_id = 0 ) {
262
-    return wpinv_get_invoice( $invoice_id, true );
261
+function wpinv_get_invoice_cart($invoice_id = 0) {
262
+    return wpinv_get_invoice($invoice_id, true);
263 263
 }
264 264
 
265
-function wpinv_get_invoice_description( $invoice_id = 0 ) {
266
-    $invoice = new WPInv_Invoice( $invoice_id );
265
+function wpinv_get_invoice_description($invoice_id = 0) {
266
+    $invoice = new WPInv_Invoice($invoice_id);
267 267
     return $invoice->get_description();
268 268
 }
269 269
 
270
-function wpinv_get_invoice_currency_code( $invoice_id = 0 ) {
271
-    $invoice = new WPInv_Invoice( $invoice_id );
270
+function wpinv_get_invoice_currency_code($invoice_id = 0) {
271
+    $invoice = new WPInv_Invoice($invoice_id);
272 272
     return $invoice->get_currency();
273 273
 }
274 274
 
275
-function wpinv_get_payment_user_email( $invoice_id ) {
276
-    $invoice = new WPInv_Invoice( $invoice_id );
275
+function wpinv_get_payment_user_email($invoice_id) {
276
+    $invoice = new WPInv_Invoice($invoice_id);
277 277
     return $invoice->get_email();
278 278
 }
279 279
 
280
-function wpinv_get_user_id( $invoice_id ) {
281
-    $invoice = new WPInv_Invoice( $invoice_id );
280
+function wpinv_get_user_id($invoice_id) {
281
+    $invoice = new WPInv_Invoice($invoice_id);
282 282
     return $invoice->get_user_id();
283 283
 }
284 284
 
285
-function wpinv_get_invoice_status( $invoice_id, $return_label = false ) {
286
-    $invoice = new WPInv_Invoice( $invoice_id );
285
+function wpinv_get_invoice_status($invoice_id, $return_label = false) {
286
+    $invoice = new WPInv_Invoice($invoice_id);
287 287
     
288
-    return $invoice->get_status( $return_label );
288
+    return $invoice->get_status($return_label);
289 289
 }
290 290
 
291
-function wpinv_get_payment_gateway( $invoice_id, $return_label = false ) {
292
-    $invoice = new WPInv_Invoice( $invoice_id );
291
+function wpinv_get_payment_gateway($invoice_id, $return_label = false) {
292
+    $invoice = new WPInv_Invoice($invoice_id);
293 293
     
294
-    return $invoice->get_gateway( $return_label );
294
+    return $invoice->get_gateway($return_label);
295 295
 }
296 296
 
297
-function wpinv_get_payment_gateway_name( $invoice_id ) {
298
-    $invoice = new WPInv_Invoice( $invoice_id );
297
+function wpinv_get_payment_gateway_name($invoice_id) {
298
+    $invoice = new WPInv_Invoice($invoice_id);
299 299
     
300 300
     return $invoice->get_gateway_title();
301 301
 }
302 302
 
303
-function wpinv_get_payment_transaction_id( $invoice_id ) {
304
-    $invoice = new WPInv_Invoice( $invoice_id );
303
+function wpinv_get_payment_transaction_id($invoice_id) {
304
+    $invoice = new WPInv_Invoice($invoice_id);
305 305
     
306 306
     return $invoice->get_transaction_id();
307 307
 }
308 308
 
309
-function wpinv_get_id_by_transaction_id( $key ) {
309
+function wpinv_get_id_by_transaction_id($key) {
310 310
     global $wpdb;
311 311
 
312
-    $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 ) );
312
+    $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));
313 313
 
314
-    if ( $invoice_id != NULL )
314
+    if ($invoice_id != NULL)
315 315
         return $invoice_id;
316 316
 
317 317
     return 0;
318 318
 }
319 319
 
320
-function wpinv_get_invoice_meta( $invoice_id = 0, $meta_key = '_wpinv_payment_meta', $single = true ) {
321
-    $invoice = new WPInv_Invoice( $invoice_id );
320
+function wpinv_get_invoice_meta($invoice_id = 0, $meta_key = '_wpinv_payment_meta', $single = true) {
321
+    $invoice = new WPInv_Invoice($invoice_id);
322 322
 
323
-    return $invoice->get_meta( $meta_key, $single );
323
+    return $invoice->get_meta($meta_key, $single);
324 324
 }
325 325
 
326
-function wpinv_update_invoice_meta( $invoice_id = 0, $meta_key = '', $meta_value = '', $prev_value = '' ) {
327
-    $invoice = new WPInv_Invoice( $invoice_id );
326
+function wpinv_update_invoice_meta($invoice_id = 0, $meta_key = '', $meta_value = '', $prev_value = '') {
327
+    $invoice = new WPInv_Invoice($invoice_id);
328 328
     
329
-    return $invoice->update_meta( $meta_key, $meta_value, $prev_value );
329
+    return $invoice->update_meta($meta_key, $meta_value, $prev_value);
330 330
 }
331 331
 
332
-function wpinv_get_items( $invoice_id = 0 ) {
333
-    $invoice            = wpinv_get_invoice( $invoice_id );
332
+function wpinv_get_items($invoice_id = 0) {
333
+    $invoice            = wpinv_get_invoice($invoice_id);
334 334
     
335 335
     $items              = $invoice->get_items();
336 336
     $invoice_currency   = $invoice->get_currency();
337 337
 
338
-    if ( !empty( $items ) && is_array( $items ) ) {
339
-        foreach ( $items as $key => $item ) {
338
+    if (!empty($items) && is_array($items)) {
339
+        foreach ($items as $key => $item) {
340 340
             $items[$key]['currency'] = $invoice_currency;
341 341
 
342
-            if ( !isset( $cart_item['subtotal'] ) ) {
342
+            if (!isset($cart_item['subtotal'])) {
343 343
                 $items[$key]['subtotal'] = $items[$key]['amount'] * 1;
344 344
             }
345 345
         }
346 346
     }
347 347
 
348
-    return apply_filters( 'wpinv_get_items', $items, $invoice_id );
348
+    return apply_filters('wpinv_get_items', $items, $invoice_id);
349 349
 }
350 350
 
351
-function wpinv_get_fees( $invoice_id = 0 ) {
352
-    $invoice           = wpinv_get_invoice( $invoice_id );
351
+function wpinv_get_fees($invoice_id = 0) {
352
+    $invoice           = wpinv_get_invoice($invoice_id);
353 353
     $fees              = $invoice->get_fees();
354 354
 
355
-    return apply_filters( 'wpinv_get_fees', $fees, $invoice_id );
355
+    return apply_filters('wpinv_get_fees', $fees, $invoice_id);
356 356
 }
357 357
 
358
-function wpinv_get_invoice_ip( $invoice_id ) {
359
-    $invoice = new WPInv_Invoice( $invoice_id );
358
+function wpinv_get_invoice_ip($invoice_id) {
359
+    $invoice = new WPInv_Invoice($invoice_id);
360 360
     return $invoice->get_ip();
361 361
 }
362 362
 
363
-function wpinv_get_invoice_user_info( $invoice_id ) {
364
-    $invoice = new WPInv_Invoice( $invoice_id );
363
+function wpinv_get_invoice_user_info($invoice_id) {
364
+    $invoice = new WPInv_Invoice($invoice_id);
365 365
     return $invoice->get_user_info();
366 366
 }
367 367
 
368
-function wpinv_subtotal( $invoice_id = 0, $currency = false ) {
369
-    $invoice = new WPInv_Invoice( $invoice_id );
368
+function wpinv_subtotal($invoice_id = 0, $currency = false) {
369
+    $invoice = new WPInv_Invoice($invoice_id);
370 370
 
371
-    return $invoice->get_subtotal( $currency );
371
+    return $invoice->get_subtotal($currency);
372 372
 }
373 373
 
374
-function wpinv_tax( $invoice_id = 0, $currency = false ) {
375
-    $invoice = new WPInv_Invoice( $invoice_id );
374
+function wpinv_tax($invoice_id = 0, $currency = false) {
375
+    $invoice = new WPInv_Invoice($invoice_id);
376 376
 
377
-    return $invoice->get_tax( $currency );
377
+    return $invoice->get_tax($currency);
378 378
 }
379 379
 
380
-function wpinv_discount( $invoice_id = 0, $currency = false, $dash = false ) {
381
-    $invoice = wpinv_get_invoice( $invoice_id );
380
+function wpinv_discount($invoice_id = 0, $currency = false, $dash = false) {
381
+    $invoice = wpinv_get_invoice($invoice_id);
382 382
 
383
-    return $invoice->get_discount( $currency, $dash );
383
+    return $invoice->get_discount($currency, $dash);
384 384
 }
385 385
 
386
-function wpinv_discount_code( $invoice_id = 0 ) {
387
-    $invoice = new WPInv_Invoice( $invoice_id );
386
+function wpinv_discount_code($invoice_id = 0) {
387
+    $invoice = new WPInv_Invoice($invoice_id);
388 388
 
389 389
     return $invoice->get_discount_code();
390 390
 }
391 391
 
392
-function wpinv_payment_total( $invoice_id = 0, $currency = false ) {
393
-    $invoice = new WPInv_Invoice( $invoice_id );
392
+function wpinv_payment_total($invoice_id = 0, $currency = false) {
393
+    $invoice = new WPInv_Invoice($invoice_id);
394 394
 
395
-    return $invoice->get_total( $currency );
395
+    return $invoice->get_total($currency);
396 396
 }
397 397
 
398
-function wpinv_get_date_created( $invoice_id = 0 ) {
399
-    $invoice = new WPInv_Invoice( $invoice_id );
398
+function wpinv_get_date_created($invoice_id = 0) {
399
+    $invoice = new WPInv_Invoice($invoice_id);
400 400
     
401 401
     $date_created   = $invoice->get_created_date();
402
-    $date_created   = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n( get_option( 'date_format' ), strtotime( $date_created ) ) : '';
402
+    $date_created   = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n(get_option('date_format'), strtotime($date_created)) : '';
403 403
 
404 404
     return $date_created;
405 405
 }
406 406
 
407
-function wpinv_get_invoice_date( $invoice_id = 0, $format = '' ) {
408
-    $invoice = new WPInv_Invoice( $invoice_id );
407
+function wpinv_get_invoice_date($invoice_id = 0, $format = '') {
408
+    $invoice = new WPInv_Invoice($invoice_id);
409 409
     
410
-    $format         = !empty( $format ) ? $format : get_option( 'date_format' );
410
+    $format         = !empty($format) ? $format : get_option('date_format');
411 411
     $date_completed = $invoice->get_completed_date();
412
-    $invoice_date   = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? date_i18n( $format, strtotime( $date_completed ) ) : '';
413
-    if ( $invoice_date == '' ) {
412
+    $invoice_date   = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? date_i18n($format, strtotime($date_completed)) : '';
413
+    if ($invoice_date == '') {
414 414
         $date_created   = $invoice->get_created_date();
415
-        $invoice_date   = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n( $format, strtotime( $date_created ) ) : '';
415
+        $invoice_date   = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n($format, strtotime($date_created)) : '';
416 416
     }
417 417
 
418 418
     return $invoice_date;
419 419
 }
420 420
 
421
-function wpinv_get_invoice_vat_number( $invoice_id = 0 ) {
422
-    $invoice = new WPInv_Invoice( $invoice_id );
421
+function wpinv_get_invoice_vat_number($invoice_id = 0) {
422
+    $invoice = new WPInv_Invoice($invoice_id);
423 423
     
424 424
     return $invoice->vat_number;
425 425
 }
426 426
 
427
-function wpinv_insert_payment_note( $invoice_id = 0, $note = '', $user_type = false, $added_by_user = false ) {
428
-    $invoice = new WPInv_Invoice( $invoice_id );
427
+function wpinv_insert_payment_note($invoice_id = 0, $note = '', $user_type = false, $added_by_user = false) {
428
+    $invoice = new WPInv_Invoice($invoice_id);
429 429
 
430
-    return $invoice->add_note( $note, $user_type, $added_by_user );
430
+    return $invoice->add_note($note, $user_type, $added_by_user);
431 431
 }
432 432
 
433
-function wpinv_get_invoice_notes( $invoice_id = 0, $type = '' ) {
433
+function wpinv_get_invoice_notes($invoice_id = 0, $type = '') {
434 434
     global $invoicing;
435 435
     
436
-    if ( empty( $invoice_id ) ) {
436
+    if (empty($invoice_id)) {
437 437
         return NULL;
438 438
     }
439 439
     
440
-    $notes = $invoicing->notes->get_invoice_notes( $invoice_id, $type );
440
+    $notes = $invoicing->notes->get_invoice_notes($invoice_id, $type);
441 441
     
442
-    return apply_filters( 'wpinv_invoice_notes', $notes, $invoice_id, $type );
442
+    return apply_filters('wpinv_invoice_notes', $notes, $invoice_id, $type);
443 443
 }
444 444
 
445
-function wpinv_get_payment_key( $invoice_id = 0 ) {
446
-	$invoice = new WPInv_Invoice( $invoice_id );
445
+function wpinv_get_payment_key($invoice_id = 0) {
446
+	$invoice = new WPInv_Invoice($invoice_id);
447 447
     return $invoice->get_key();
448 448
 }
449 449
 
450
-function wpinv_get_invoice_number( $invoice_id = 0 ) {
451
-    $invoice = new WPInv_Invoice( $invoice_id );
450
+function wpinv_get_invoice_number($invoice_id = 0) {
451
+    $invoice = new WPInv_Invoice($invoice_id);
452 452
     return $invoice->get_number();
453 453
 }
454 454
 
455
-function wpinv_get_cart_discountable_subtotal( $code_id ) {
455
+function wpinv_get_cart_discountable_subtotal($code_id) {
456 456
     $cart_items = wpinv_get_cart_content_details();
457 457
     $items      = array();
458 458
 
459
-    $excluded_items = wpinv_get_discount_excluded_items( $code_id );
459
+    $excluded_items = wpinv_get_discount_excluded_items($code_id);
460 460
 
461
-    if( $cart_items ) {
461
+    if ($cart_items) {
462 462
 
463
-        foreach( $cart_items as $item ) {
463
+        foreach ($cart_items as $item) {
464 464
 
465
-            if( ! in_array( $item['id'], $excluded_items ) ) {
466
-                $items[] =  $item;
465
+            if (!in_array($item['id'], $excluded_items)) {
466
+                $items[] = $item;
467 467
             }
468 468
         }
469 469
     }
470 470
 
471
-    $subtotal = wpinv_get_cart_items_subtotal( $items );
471
+    $subtotal = wpinv_get_cart_items_subtotal($items);
472 472
 
473
-    return apply_filters( 'wpinv_get_cart_discountable_subtotal', $subtotal );
473
+    return apply_filters('wpinv_get_cart_discountable_subtotal', $subtotal);
474 474
 }
475 475
 
476
-function wpinv_get_cart_items_subtotal( $items ) {
476
+function wpinv_get_cart_items_subtotal($items) {
477 477
     $subtotal = 0.00;
478 478
 
479
-    if ( is_array( $items ) && ! empty( $items ) ) {
480
-        $prices = wp_list_pluck( $items, 'subtotal' );
479
+    if (is_array($items) && !empty($items)) {
480
+        $prices = wp_list_pluck($items, 'subtotal');
481 481
 
482
-        if( is_array( $prices ) ) {
483
-            $subtotal = array_sum( $prices );
482
+        if (is_array($prices)) {
483
+            $subtotal = array_sum($prices);
484 484
         } else {
485 485
             $subtotal = 0.00;
486 486
         }
487 487
 
488
-        if( $subtotal < 0 ) {
488
+        if ($subtotal < 0) {
489 489
             $subtotal = 0.00;
490 490
         }
491 491
     }
492 492
 
493
-    return apply_filters( 'wpinv_get_cart_items_subtotal', $subtotal );
493
+    return apply_filters('wpinv_get_cart_items_subtotal', $subtotal);
494 494
 }
495 495
 
496
-function wpinv_get_cart_subtotal( $items = array() ) {
497
-    $items    = !empty( $items ) ? $items : wpinv_get_cart_content_details();
498
-    $subtotal = wpinv_get_cart_items_subtotal( $items );
496
+function wpinv_get_cart_subtotal($items = array()) {
497
+    $items    = !empty($items) ? $items : wpinv_get_cart_content_details();
498
+    $subtotal = wpinv_get_cart_items_subtotal($items);
499 499
 
500
-    return apply_filters( 'wpinv_get_cart_subtotal', $subtotal );
500
+    return apply_filters('wpinv_get_cart_subtotal', $subtotal);
501 501
 }
502 502
 
503
-function wpinv_cart_subtotal( $items = array() ) {
504
-    $price = wpinv_price( wpinv_format_amount( wpinv_get_cart_subtotal( $items ) ) );
503
+function wpinv_cart_subtotal($items = array()) {
504
+    $price = wpinv_price(wpinv_format_amount(wpinv_get_cart_subtotal($items)));
505 505
 
506 506
     return $price;
507 507
 }
508 508
 
509
-function wpinv_get_cart_total( $items = array(), $discounts = false, $invoice = array() ) {
510
-    $subtotal  = (float)wpinv_get_cart_subtotal( $items );
511
-    $discounts = (float)wpinv_get_cart_discounted_amount( $items );
512
-    $cart_tax  = (float)wpinv_get_cart_tax( $items );
509
+function wpinv_get_cart_total($items = array(), $discounts = false, $invoice = array()) {
510
+    $subtotal  = (float)wpinv_get_cart_subtotal($items);
511
+    $discounts = (float)wpinv_get_cart_discounted_amount($items);
512
+    $cart_tax  = (float)wpinv_get_cart_tax($items);
513 513
     $fees      = (float)wpinv_get_cart_fee_total();
514
-    if ( !empty( $invoice ) && $invoice->is_free_trial() ) {
514
+    if (!empty($invoice) && $invoice->is_free_trial()) {
515 515
         $total = 0;
516 516
     } else {
517
-        $total     = $subtotal - $discounts + $cart_tax + $fees;
517
+        $total = $subtotal - $discounts + $cart_tax + $fees;
518 518
     }
519 519
 
520
-    if ( $total < 0 ) {
520
+    if ($total < 0) {
521 521
         $total = 0.00;
522 522
     }
523 523
     
524
-    $total = (float)apply_filters( 'wpinv_get_cart_total', $total, $items );
524
+    $total = (float)apply_filters('wpinv_get_cart_total', $total, $items);
525 525
 
526
-    return wpinv_sanitize_amount( $total );
526
+    return wpinv_sanitize_amount($total);
527 527
 }
528 528
 
529
-function wpinv_cart_total( $cart_items = array(), $echo = true, $invoice = array() ) {
529
+function wpinv_cart_total($cart_items = array(), $echo = true, $invoice = array()) {
530 530
     global $cart_total;
531
-    $total = wpinv_price( wpinv_format_amount( wpinv_get_cart_total( $cart_items, NULL, $invoice ) ) );
532
-    $total = apply_filters( 'wpinv_cart_total', $total, $cart_items, $invoice );
531
+    $total = wpinv_price(wpinv_format_amount(wpinv_get_cart_total($cart_items, NULL, $invoice)));
532
+    $total = apply_filters('wpinv_cart_total', $total, $cart_items, $invoice);
533 533
     
534 534
     $cart_total = $total;
535 535
 
536
-    if ( !$echo ) {
536
+    if (!$echo) {
537 537
         return $total;
538 538
     }
539 539
 
540 540
     echo $total;
541 541
 }
542 542
 
543
-function wpinv_get_cart_tax( $items = array() ) {
543
+function wpinv_get_cart_tax($items = array()) {
544 544
     $cart_tax = 0;
545
-    $items    = !empty( $items ) ? $items : wpinv_get_cart_content_details();
545
+    $items    = !empty($items) ? $items : wpinv_get_cart_content_details();
546 546
 
547
-    if ( $items ) {
548
-        $taxes = wp_list_pluck( $items, 'tax' );
547
+    if ($items) {
548
+        $taxes = wp_list_pluck($items, 'tax');
549 549
 
550
-        if( is_array( $taxes ) ) {
551
-            $cart_tax = array_sum( $taxes );
550
+        if (is_array($taxes)) {
551
+            $cart_tax = array_sum($taxes);
552 552
         }
553 553
     }
554 554
 
555 555
     $cart_tax += wpinv_get_cart_fee_tax();
556 556
 
557
-    return apply_filters( 'wpinv_get_cart_tax', wpinv_sanitize_amount( $cart_tax ) );
557
+    return apply_filters('wpinv_get_cart_tax', wpinv_sanitize_amount($cart_tax));
558 558
 }
559 559
 
560
-function wpinv_cart_tax( $items = array(), $echo = false ) {
561
-    $cart_tax = wpinv_get_cart_tax( $items );
562
-    $cart_tax = wpinv_price( wpinv_format_amount( $cart_tax ) );
560
+function wpinv_cart_tax($items = array(), $echo = false) {
561
+    $cart_tax = wpinv_get_cart_tax($items);
562
+    $cart_tax = wpinv_price(wpinv_format_amount($cart_tax));
563 563
 
564
-    $tax = apply_filters( 'wpinv_cart_tax', $cart_tax, $items );
564
+    $tax = apply_filters('wpinv_cart_tax', $cart_tax, $items);
565 565
 
566
-    if ( !$echo ) {
566
+    if (!$echo) {
567 567
         return $tax;
568 568
     }
569 569
 
570 570
     echo $tax;
571 571
 }
572 572
 
573
-function wpinv_get_cart_discount_code( $items = array() ) {
573
+function wpinv_get_cart_discount_code($items = array()) {
574 574
     $invoice = wpinv_get_invoice_cart();
575
-    $cart_discount_code = !empty( $invoice ) ? $invoice->get_discount_code() : '';
575
+    $cart_discount_code = !empty($invoice) ? $invoice->get_discount_code() : '';
576 576
     
577
-    return apply_filters( 'wpinv_get_cart_discount_code', $cart_discount_code );
577
+    return apply_filters('wpinv_get_cart_discount_code', $cart_discount_code);
578 578
 }
579 579
 
580
-function wpinv_cart_discount_code( $items = array(), $echo = false ) {
581
-    $cart_discount_code = wpinv_get_cart_discount_code( $items );
580
+function wpinv_cart_discount_code($items = array(), $echo = false) {
581
+    $cart_discount_code = wpinv_get_cart_discount_code($items);
582 582
 
583
-    if ( $cart_discount_code != '' ) {
583
+    if ($cart_discount_code != '') {
584 584
         $cart_discount_code = ' (' . $cart_discount_code . ')';
585 585
     }
586 586
     
587
-    $discount_code = apply_filters( 'wpinv_cart_discount_code', $cart_discount_code, $items );
587
+    $discount_code = apply_filters('wpinv_cart_discount_code', $cart_discount_code, $items);
588 588
 
589
-    if ( !$echo ) {
589
+    if (!$echo) {
590 590
         return $discount_code;
591 591
     }
592 592
 
593 593
     echo $discount_code;
594 594
 }
595 595
 
596
-function wpinv_get_cart_discount( $items = array() ) {
596
+function wpinv_get_cart_discount($items = array()) {
597 597
     $invoice = wpinv_get_invoice_cart();
598
-    $cart_discount = !empty( $invoice ) ? $invoice->get_discount() : 0;
598
+    $cart_discount = !empty($invoice) ? $invoice->get_discount() : 0;
599 599
     
600
-    return apply_filters( 'wpinv_get_cart_discount', wpinv_sanitize_amount( $cart_discount ), $items );
600
+    return apply_filters('wpinv_get_cart_discount', wpinv_sanitize_amount($cart_discount), $items);
601 601
 }
602 602
 
603
-function wpinv_cart_discount( $items = array(), $echo = false ) {
604
-    $cart_discount = wpinv_get_cart_discount( $items );
605
-    $cart_discount = wpinv_price( wpinv_format_amount( $cart_discount ) );
603
+function wpinv_cart_discount($items = array(), $echo = false) {
604
+    $cart_discount = wpinv_get_cart_discount($items);
605
+    $cart_discount = wpinv_price(wpinv_format_amount($cart_discount));
606 606
 
607
-    $discount = apply_filters( 'wpinv_cart_discount', $cart_discount, $items );
607
+    $discount = apply_filters('wpinv_cart_discount', $cart_discount, $items);
608 608
 
609
-    if ( !$echo ) {
609
+    if (!$echo) {
610 610
         return $discount;
611 611
     }
612 612
 
613 613
     echo $discount;
614 614
 }
615 615
 
616
-function wpinv_get_cart_fees( $type = 'all', $item_id = 0 ) {
617
-    $item = new WPInv_Item( $item_id );
616
+function wpinv_get_cart_fees($type = 'all', $item_id = 0) {
617
+    $item = new WPInv_Item($item_id);
618 618
     
619
-    return $item->get_fees( $type, $item_id );
619
+    return $item->get_fees($type, $item_id);
620 620
 }
621 621
 
622 622
 function wpinv_get_cart_fee_total() {
623
-    $total  = 0;
623
+    $total = 0;
624 624
     $fees = wpinv_get_cart_fees();
625 625
     
626
-    if ( $fees ) {
627
-        foreach ( $fees as $fee_id => $fee ) {
626
+    if ($fees) {
627
+        foreach ($fees as $fee_id => $fee) {
628 628
             $total += $fee['amount'];
629 629
         }
630 630
     }
631 631
 
632
-    return apply_filters( 'wpinv_get_cart_fee_total', $total );
632
+    return apply_filters('wpinv_get_cart_fee_total', $total);
633 633
 }
634 634
 
635 635
 function wpinv_get_cart_fee_tax() {
636 636
     $tax  = 0;
637 637
     $fees = wpinv_get_cart_fees();
638 638
 
639
-    if ( $fees ) {
640
-        foreach ( $fees as $fee_id => $fee ) {
641
-            if( ! empty( $fee['no_tax'] ) ) {
639
+    if ($fees) {
640
+        foreach ($fees as $fee_id => $fee) {
641
+            if (!empty($fee['no_tax'])) {
642 642
                 continue;
643 643
             }
644 644
 
645
-            $tax += wpinv_calculate_tax( $fee['amount'] );
645
+            $tax += wpinv_calculate_tax($fee['amount']);
646 646
         }
647 647
     }
648 648
 
649
-    return apply_filters( 'wpinv_get_cart_fee_tax', $tax );
649
+    return apply_filters('wpinv_get_cart_fee_tax', $tax);
650 650
 }
651 651
 
652 652
 function wpinv_cart_has_recurring_item() {
653 653
     $cart_items = wpinv_get_cart_contents();
654 654
     
655
-    if ( empty( $cart_items ) ) {
655
+    if (empty($cart_items)) {
656 656
         return false;
657 657
     }
658 658
     
659 659
     $has_subscription = false;
660
-    foreach( $cart_items as $cart_item ) {
661
-        if ( !empty( $cart_item['id'] ) && wpinv_is_recurring_item( $cart_item['id'] )  ) {
660
+    foreach ($cart_items as $cart_item) {
661
+        if (!empty($cart_item['id']) && wpinv_is_recurring_item($cart_item['id'])) {
662 662
             $has_subscription = true;
663 663
             break;
664 664
         }
665 665
     }
666 666
     
667
-    return apply_filters( 'wpinv_cart_has_recurring_item', $has_subscription, $cart_items );
667
+    return apply_filters('wpinv_cart_has_recurring_item', $has_subscription, $cart_items);
668 668
 }
669 669
 
670 670
 function wpinv_cart_has_free_trial() {
@@ -672,94 +672,94 @@  discard block
 block discarded – undo
672 672
     
673 673
     $free_trial = false;
674 674
     
675
-    if ( !empty( $invoice ) && $invoice->is_free_trial() ) {
675
+    if (!empty($invoice) && $invoice->is_free_trial()) {
676 676
         $free_trial = true;
677 677
     }
678 678
     
679
-    return apply_filters( 'wpinv_cart_has_free_trial', $free_trial, $invoice );
679
+    return apply_filters('wpinv_cart_has_free_trial', $free_trial, $invoice);
680 680
 }
681 681
 
682 682
 function wpinv_get_cart_contents() {
683 683
     $cart_details = wpinv_get_cart_details();
684 684
     
685
-    return apply_filters( 'wpinv_get_cart_contents', $cart_details );
685
+    return apply_filters('wpinv_get_cart_contents', $cart_details);
686 686
 }
687 687
 
688 688
 function wpinv_get_cart_content_details() {
689 689
     global $wpinv_euvat, $wpi_current_id, $wpi_item_id, $wpinv_is_last_cart_item, $wpinv_flat_discount_total;
690 690
     $cart_items = wpinv_get_cart_contents();
691 691
     
692
-    if ( empty( $cart_items ) ) {
692
+    if (empty($cart_items)) {
693 693
         return false;
694 694
     }
695 695
     $invoice = wpinv_get_invoice_cart();
696 696
 
697 697
     $details = array();
698
-    $length  = count( $cart_items ) - 1;
698
+    $length  = count($cart_items) - 1;
699 699
     
700
-    if ( empty( $_POST['country'] ) ) {
700
+    if (empty($_POST['country'])) {
701 701
         $_POST['country'] = $invoice->country;
702 702
     }
703
-    if ( !isset( $_POST['state'] ) ) {
703
+    if (!isset($_POST['state'])) {
704 704
         $_POST['state'] = $invoice->state;
705 705
     }
706 706
 
707
-    foreach( $cart_items as $key => $item ) {
708
-        $item_id            = isset( $item['id'] ) ? sanitize_text_field( $item['id'] ) : '';
709
-        if ( empty( $item_id ) ) {
707
+    foreach ($cart_items as $key => $item) {
708
+        $item_id = isset($item['id']) ? sanitize_text_field($item['id']) : '';
709
+        if (empty($item_id)) {
710 710
             continue;
711 711
         }
712 712
         
713 713
         $wpi_current_id         = $invoice->ID;
714 714
         $wpi_item_id            = $item_id;
715 715
         
716
-        if ( isset( $item['custom_price'] ) && $item['custom_price'] !== '' ) {
716
+        if (isset($item['custom_price']) && $item['custom_price'] !== '') {
717 717
             $item_price = $item['custom_price'];
718 718
         } else {
719
-            if ( isset( $item['item_price'] ) && $item['item_price'] !== '' && $item['item_price'] !== false ) {
719
+            if (isset($item['item_price']) && $item['item_price'] !== '' && $item['item_price'] !== false) {
720 720
                 $item_price = $item['item_price'];
721 721
             } else {
722
-                $item_price = wpinv_get_item_price( $item_id );
722
+                $item_price = wpinv_get_item_price($item_id);
723 723
             }
724 724
         }
725
-        $discount           = wpinv_get_cart_item_discount_amount( $item );
726
-        $discount           = apply_filters( 'wpinv_get_cart_content_details_item_discount_amount', $discount, $item );
727
-        $quantity           = wpinv_get_cart_item_quantity( $item );
728
-        $fees               = wpinv_get_cart_fees( 'fee', $item_id );
725
+        $discount           = wpinv_get_cart_item_discount_amount($item);
726
+        $discount           = apply_filters('wpinv_get_cart_content_details_item_discount_amount', $discount, $item);
727
+        $quantity           = wpinv_get_cart_item_quantity($item);
728
+        $fees               = wpinv_get_cart_fees('fee', $item_id);
729 729
         
730 730
         $subtotal           = $item_price * $quantity;
731
-        $tax_rate           = wpinv_get_tax_rate( $_POST['country'], $_POST['state'], $wpi_item_id );
732
-        $tax_class          = $wpinv_euvat->get_item_class( $item_id );
733
-        $tax                = wpinv_get_cart_item_tax( $item_id, $subtotal - $discount );
731
+        $tax_rate           = wpinv_get_tax_rate($_POST['country'], $_POST['state'], $wpi_item_id);
732
+        $tax_class          = $wpinv_euvat->get_item_class($item_id);
733
+        $tax                = wpinv_get_cart_item_tax($item_id, $subtotal - $discount);
734 734
         
735
-        if ( wpinv_prices_include_tax() ) {
736
-            $subtotal -= wpinv_round_amount( $tax );
735
+        if (wpinv_prices_include_tax()) {
736
+            $subtotal -= wpinv_round_amount($tax);
737 737
         }
738 738
         
739
-        $total              = $subtotal - $discount + $tax;
739
+        $total = $subtotal - $discount + $tax;
740 740
         
741 741
         // Do not allow totals to go negatve
742
-        if( $total < 0 ) {
742
+        if ($total < 0) {
743 743
             $total = 0;
744 744
         }
745 745
         
746
-        $details[ $key ]  = array(
746
+        $details[$key] = array(
747 747
             'id'                => $item_id,
748
-            'name'              => !empty($item['name']) ? $item['name'] : get_the_title( $item_id ),
749
-            'item_price'        => wpinv_round_amount( $item_price ),
750
-            'custom_price'      => isset( $item['custom_price'] ) ? $item['custom_price'] : '',
748
+            'name'              => !empty($item['name']) ? $item['name'] : get_the_title($item_id),
749
+            'item_price'        => wpinv_round_amount($item_price),
750
+            'custom_price'      => isset($item['custom_price']) ? $item['custom_price'] : '',
751 751
             'quantity'          => $quantity,
752
-            'discount'          => wpinv_round_amount( $discount ),
753
-            'subtotal'          => wpinv_round_amount( $subtotal ),
754
-            'tax'               => wpinv_round_amount( $tax ),
755
-            'price'             => wpinv_round_amount( $total ),
752
+            'discount'          => wpinv_round_amount($discount),
753
+            'subtotal'          => wpinv_round_amount($subtotal),
754
+            'tax'               => wpinv_round_amount($tax),
755
+            'price'             => wpinv_round_amount($total),
756 756
             'vat_rates_class'   => $tax_class,
757 757
             'vat_rate'          => $tax_rate,
758
-            'meta'              => isset( $item['meta'] ) ? $item['meta'] : array(),
758
+            'meta'              => isset($item['meta']) ? $item['meta'] : array(),
759 759
             'fees'              => $fees,
760 760
         );
761 761
         
762
-        if ( $wpinv_is_last_cart_item ) {
762
+        if ($wpinv_is_last_cart_item) {
763 763
             $wpinv_is_last_cart_item   = false;
764 764
             $wpinv_flat_discount_total = 0.00;
765 765
         }
@@ -768,60 +768,60 @@  discard block
 block discarded – undo
768 768
     return $details;
769 769
 }
770 770
 
771
-function wpinv_get_cart_details( $invoice_id = 0 ) {
771
+function wpinv_get_cart_details($invoice_id = 0) {
772 772
     global $ajax_cart_details;
773 773
 
774
-    $invoice      = wpinv_get_invoice_cart( $invoice_id );
775
-    $cart_details = !empty( $ajax_cart_details ) ? $ajax_cart_details : $invoice->cart_details;
774
+    $invoice      = wpinv_get_invoice_cart($invoice_id);
775
+    $cart_details = !empty($ajax_cart_details) ? $ajax_cart_details : $invoice->cart_details;
776 776
 
777 777
     $invoice_currency = $invoice->currency;
778 778
 
779
-    if ( ! empty( $cart_details ) && is_array( $cart_details ) ) {
780
-        foreach ( $cart_details as $key => $cart_item ) {
781
-            $cart_details[ $key ]['currency'] = $invoice_currency;
779
+    if (!empty($cart_details) && is_array($cart_details)) {
780
+        foreach ($cart_details as $key => $cart_item) {
781
+            $cart_details[$key]['currency'] = $invoice_currency;
782 782
 
783
-            if ( ! isset( $cart_item['subtotal'] ) ) {
784
-                $cart_details[ $key ]['subtotal'] = $cart_item['price'];
783
+            if (!isset($cart_item['subtotal'])) {
784
+                $cart_details[$key]['subtotal'] = $cart_item['price'];
785 785
             }
786 786
         }
787 787
     }
788 788
 
789
-    return apply_filters( 'wpinv_get_cart_details', $cart_details, $invoice_id );
789
+    return apply_filters('wpinv_get_cart_details', $cart_details, $invoice_id);
790 790
 }
791 791
 
792
-function wpinv_record_status_change( $invoice_id, $new_status, $old_status ) {
793
-    if('wpi_invoice' != get_post_type($invoice_id)){
792
+function wpinv_record_status_change($invoice_id, $new_status, $old_status) {
793
+    if ('wpi_invoice' != get_post_type($invoice_id)) {
794 794
         return;
795 795
     }
796 796
 
797
-    $invoice    = wpinv_get_invoice( $invoice_id );
797
+    $invoice    = wpinv_get_invoice($invoice_id);
798 798
     
799
-    $old_status = wpinv_status_nicename( $old_status );
800
-    $new_status = wpinv_status_nicename( $new_status );
799
+    $old_status = wpinv_status_nicename($old_status);
800
+    $new_status = wpinv_status_nicename($new_status);
801 801
 
802
-    $status_change = sprintf( __( 'Invoice status changed from %s to %s', 'invoicing' ), $old_status, $new_status );
802
+    $status_change = sprintf(__('Invoice status changed from %s to %s', 'invoicing'), $old_status, $new_status);
803 803
     
804 804
     // Add note
805
-    return $invoice->add_note( $status_change, false, false, true );
805
+    return $invoice->add_note($status_change, false, false, true);
806 806
 }
807
-add_action( 'wpinv_update_status', 'wpinv_record_status_change', 100, 3 );
807
+add_action('wpinv_update_status', 'wpinv_record_status_change', 100, 3);
808 808
 
809
-function wpinv_complete_payment( $invoice_id, $new_status, $old_status ) {
809
+function wpinv_complete_payment($invoice_id, $new_status, $old_status) {
810 810
     global $wpi_has_free_trial;
811 811
     
812 812
     $wpi_has_free_trial = false;
813 813
     
814
-    if ( $old_status == 'publish' ) {
814
+    if ($old_status == 'publish') {
815 815
         return; // Make sure that payments are only paid once
816 816
     }
817 817
 
818 818
     // Make sure the payment completion is only processed when new status is paid
819
-    if ( $new_status != 'publish' ) {
819
+    if ($new_status != 'publish') {
820 820
         return;
821 821
     }
822 822
 
823
-    $invoice = new WPInv_Invoice( $invoice_id );
824
-    if ( empty( $invoice ) ) {
823
+    $invoice = new WPInv_Invoice($invoice_id);
824
+    if (empty($invoice)) {
825 825
         return;
826 826
     }
827 827
 
@@ -829,58 +829,58 @@  discard block
 block discarded – undo
829 829
     $completed_date = $invoice->completed_date;
830 830
     $cart_details   = $invoice->cart_details;
831 831
 
832
-    do_action( 'wpinv_pre_complete_payment', $invoice_id );
832
+    do_action('wpinv_pre_complete_payment', $invoice_id);
833 833
 
834
-    if ( is_array( $cart_details ) ) {
834
+    if (is_array($cart_details)) {
835 835
         // Increase purchase count and earnings
836
-        foreach ( $cart_details as $cart_index => $item ) {
836
+        foreach ($cart_details as $cart_index => $item) {
837 837
             // Ensure these actions only run once, ever
838
-            if ( empty( $completed_date ) ) {
839
-                do_action( 'wpinv_complete_item_payment', $item['id'], $invoice_id, $item, $cart_index );
838
+            if (empty($completed_date)) {
839
+                do_action('wpinv_complete_item_payment', $item['id'], $invoice_id, $item, $cart_index);
840 840
             }
841 841
         }
842 842
     }
843 843
     
844 844
     // Check for discount codes and increment their use counts
845
-    if ( $discounts = $invoice->get_discounts( true ) ) {
846
-        if( ! empty( $discounts ) ) {
847
-            foreach( $discounts as $code ) {
848
-                wpinv_increase_discount_usage( $code );
845
+    if ($discounts = $invoice->get_discounts(true)) {
846
+        if (!empty($discounts)) {
847
+            foreach ($discounts as $code) {
848
+                wpinv_increase_discount_usage($code);
849 849
             }
850 850
         }
851 851
     }
852 852
     
853 853
     // Ensure this action only runs once ever
854
-    if( empty( $completed_date ) ) {
854
+    if (empty($completed_date)) {
855 855
         // Save the completed date
856
-        $invoice->set( 'completed_date', current_time( 'mysql', 0 ) );
856
+        $invoice->set('completed_date', current_time('mysql', 0));
857 857
         $invoice->save();
858 858
 
859
-        do_action( 'wpinv_complete_payment', $invoice_id );
859
+        do_action('wpinv_complete_payment', $invoice_id);
860 860
     }
861 861
 
862 862
     // Empty the shopping cart
863 863
     wpinv_empty_cart();
864 864
 }
865
-add_action( 'wpinv_update_status', 'wpinv_complete_payment', 100, 3 );
865
+add_action('wpinv_update_status', 'wpinv_complete_payment', 100, 3);
866 866
 
867
-function wpinv_update_payment_status( $invoice_id, $new_status = 'publish' ) {    
868
-    $invoice = !empty( $invoice_id ) && is_object( $invoice_id ) ? $invoice_id : wpinv_get_invoice( (int)$invoice_id );
867
+function wpinv_update_payment_status($invoice_id, $new_status = 'publish') {    
868
+    $invoice = !empty($invoice_id) && is_object($invoice_id) ? $invoice_id : wpinv_get_invoice((int)$invoice_id);
869 869
     
870
-    if ( empty( $invoice ) ) {
870
+    if (empty($invoice)) {
871 871
         return false;
872 872
     }
873 873
     
874
-    return $invoice->update_status( $new_status );
874
+    return $invoice->update_status($new_status);
875 875
 }
876 876
 
877
-function wpinv_cart_has_fees( $type = 'all' ) {
877
+function wpinv_cart_has_fees($type = 'all') {
878 878
     return false;
879 879
 }
880 880
 
881 881
 function wpinv_validate_checkout_fields() {    
882 882
     // Check if there is $_POST
883
-    if ( empty( $_POST ) ) {
883
+    if (empty($_POST)) {
884 884
         return false;
885 885
     }
886 886
     
@@ -892,11 +892,11 @@  discard block
 block discarded – undo
892 892
     );
893 893
     
894 894
     // Validate agree to terms
895
-    if ( wpinv_get_option( 'show_agree_to_terms', false ) ) {
895
+    if (wpinv_get_option('show_agree_to_terms', false)) {
896 896
         wpinv_checkout_validate_agree_to_terms();
897 897
     }
898 898
     
899
-    $valid_data['logged_in_user']   = wpinv_checkout_validate_logged_in_user();
899
+    $valid_data['logged_in_user'] = wpinv_checkout_validate_logged_in_user();
900 900
     
901 901
     // Return collected data
902 902
     return $valid_data;
@@ -907,26 +907,26 @@  discard block
 block discarded – undo
907 907
     
908 908
     $invoice = wpinv_get_invoice_cart();
909 909
     $has_subscription = $invoice->is_recurring();
910
-    if ( empty( $invoice ) ) {
911
-        wpinv_set_error( 'invalid_invoice', __( 'Your cart is empty.', 'invoicing' ) );
910
+    if (empty($invoice)) {
911
+        wpinv_set_error('invalid_invoice', __('Your cart is empty.', 'invoicing'));
912 912
         return $gateway;
913 913
     }
914 914
 
915 915
     // Check if a gateway value is present
916
-    if ( !empty( $_REQUEST['wpi-gateway'] ) ) {
917
-        $gateway = sanitize_text_field( $_REQUEST['wpi-gateway'] );
916
+    if (!empty($_REQUEST['wpi-gateway'])) {
917
+        $gateway = sanitize_text_field($_REQUEST['wpi-gateway']);
918 918
 
919
-        if ( $invoice->is_free() ) {
919
+        if ($invoice->is_free()) {
920 920
             $gateway = 'manual';
921
-        } elseif ( !wpinv_is_gateway_active( $gateway ) ) {
922
-            wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway is not enabled', 'invoicing' ) );
923
-        } elseif ( $has_subscription && !wpinv_gateway_support_subscription( $gateway ) ) {
924
-            wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway doesnot support subscription payment', 'invoicing' ) );
921
+        } elseif (!wpinv_is_gateway_active($gateway)) {
922
+            wpinv_set_error('invalid_gateway', __('The selected payment gateway is not enabled', 'invoicing'));
923
+        } elseif ($has_subscription && !wpinv_gateway_support_subscription($gateway)) {
924
+            wpinv_set_error('invalid_gateway', __('The selected payment gateway doesnot support subscription payment', 'invoicing'));
925 925
         }
926 926
     }
927 927
 
928
-    if ( $has_subscription && count( wpinv_get_cart_contents() ) > 1 ) {
929
-        wpinv_set_error( 'subscription_invalid', __( 'Only one subscription may be purchased through payment per checkout.', 'invoicing' ) );
928
+    if ($has_subscription && count(wpinv_get_cart_contents()) > 1) {
929
+        wpinv_set_error('subscription_invalid', __('Only one subscription may be purchased through payment per checkout.', 'invoicing'));
930 930
     }
931 931
 
932 932
     return $gateway;
@@ -938,10 +938,10 @@  discard block
 block discarded – undo
938 938
     
939 939
     $error = false;
940 940
     // If we have discounts, loop through them
941
-    if ( ! empty( $discounts ) ) {
942
-        foreach ( $discounts as $discount ) {
941
+    if (!empty($discounts)) {
942
+        foreach ($discounts as $discount) {
943 943
             // Check if valid
944
-            if (  !wpinv_is_discount_valid( $discount, get_current_user_id() ) ) {
944
+            if (!wpinv_is_discount_valid($discount, get_current_user_id())) {
945 945
                 // Discount is not valid
946 946
                 $error = true;
947 947
             }
@@ -951,20 +951,20 @@  discard block
 block discarded – undo
951 951
         return NULL;
952 952
     }
953 953
 
954
-    if ( $error && !wpinv_get_errors() ) {
955
-        wpinv_set_error( 'invalid_discount', __( 'Discount code you entered is invalid', 'invoicing' ) );
954
+    if ($error && !wpinv_get_errors()) {
955
+        wpinv_set_error('invalid_discount', __('Discount code you entered is invalid', 'invoicing'));
956 956
     }
957 957
 
958
-    return implode( ',', $discounts );
958
+    return implode(',', $discounts);
959 959
 }
960 960
 
961 961
 function wpinv_checkout_validate_cc() {
962 962
     $card_data = wpinv_checkout_get_cc_info();
963 963
 
964 964
     // Validate the card zip
965
-    if ( !empty( $card_data['wpinv_zip'] ) ) {
966
-        if ( !wpinv_checkout_validate_cc_zip( $card_data['wpinv_zip'], $card_data['wpinv_country'] ) ) {
967
-            wpinv_set_error( 'invalid_cc_zip', __( 'The zip / postcode you entered for your billing address is invalid', 'invoicing' ) );
965
+    if (!empty($card_data['wpinv_zip'])) {
966
+        if (!wpinv_checkout_validate_cc_zip($card_data['wpinv_zip'], $card_data['wpinv_country'])) {
967
+            wpinv_set_error('invalid_cc_zip', __('The zip / postcode you entered for your billing address is invalid', 'invoicing'));
968 968
         }
969 969
     }
970 970
 
@@ -974,28 +974,28 @@  discard block
 block discarded – undo
974 974
 
975 975
 function wpinv_checkout_get_cc_info() {
976 976
 	$cc_info = array();
977
-	$cc_info['card_name']      = isset( $_POST['card_name'] )       ? sanitize_text_field( $_POST['card_name'] )       : '';
978
-	$cc_info['card_number']    = isset( $_POST['card_number'] )     ? sanitize_text_field( $_POST['card_number'] )     : '';
979
-	$cc_info['card_cvc']       = isset( $_POST['card_cvc'] )        ? sanitize_text_field( $_POST['card_cvc'] )        : '';
980
-	$cc_info['card_exp_month'] = isset( $_POST['card_exp_month'] )  ? sanitize_text_field( $_POST['card_exp_month'] )  : '';
981
-	$cc_info['card_exp_year']  = isset( $_POST['card_exp_year'] )   ? sanitize_text_field( $_POST['card_exp_year'] )   : '';
982
-	$cc_info['card_address']   = isset( $_POST['wpinv_address'] )  ? sanitize_text_field( $_POST['wpinv_address'] ) : '';
983
-	$cc_info['card_city']      = isset( $_POST['wpinv_city'] )     ? sanitize_text_field( $_POST['wpinv_city'] )    : '';
984
-	$cc_info['card_state']     = isset( $_POST['wpinv_state'] )    ? sanitize_text_field( $_POST['wpinv_state'] )   : '';
985
-	$cc_info['card_country']   = isset( $_POST['wpinv_country'] )  ? sanitize_text_field( $_POST['wpinv_country'] ) : '';
986
-	$cc_info['card_zip']       = isset( $_POST['wpinv_zip'] )      ? sanitize_text_field( $_POST['wpinv_zip'] )     : '';
977
+	$cc_info['card_name']      = isset($_POST['card_name']) ? sanitize_text_field($_POST['card_name']) : '';
978
+	$cc_info['card_number']    = isset($_POST['card_number']) ? sanitize_text_field($_POST['card_number']) : '';
979
+	$cc_info['card_cvc']       = isset($_POST['card_cvc']) ? sanitize_text_field($_POST['card_cvc']) : '';
980
+	$cc_info['card_exp_month'] = isset($_POST['card_exp_month']) ? sanitize_text_field($_POST['card_exp_month']) : '';
981
+	$cc_info['card_exp_year']  = isset($_POST['card_exp_year']) ? sanitize_text_field($_POST['card_exp_year']) : '';
982
+	$cc_info['card_address']   = isset($_POST['wpinv_address']) ? sanitize_text_field($_POST['wpinv_address']) : '';
983
+	$cc_info['card_city']      = isset($_POST['wpinv_city']) ? sanitize_text_field($_POST['wpinv_city']) : '';
984
+	$cc_info['card_state']     = isset($_POST['wpinv_state']) ? sanitize_text_field($_POST['wpinv_state']) : '';
985
+	$cc_info['card_country']   = isset($_POST['wpinv_country']) ? sanitize_text_field($_POST['wpinv_country']) : '';
986
+	$cc_info['card_zip']       = isset($_POST['wpinv_zip']) ? sanitize_text_field($_POST['wpinv_zip']) : '';
987 987
 
988 988
 	// Return cc info
989 989
 	return $cc_info;
990 990
 }
991 991
 
992
-function wpinv_checkout_validate_cc_zip( $zip = 0, $country_code = '' ) {
992
+function wpinv_checkout_validate_cc_zip($zip = 0, $country_code = '') {
993 993
     $ret = false;
994 994
 
995
-    if ( empty( $zip ) || empty( $country_code ) )
995
+    if (empty($zip) || empty($country_code))
996 996
         return $ret;
997 997
 
998
-    $country_code = strtoupper( $country_code );
998
+    $country_code = strtoupper($country_code);
999 999
 
1000 1000
     $zip_regex = array(
1001 1001
         "AD" => "AD\d{3}",
@@ -1155,17 +1155,17 @@  discard block
 block discarded – undo
1155 1155
         "ZM" => "\d{5}"
1156 1156
     );
1157 1157
 
1158
-    if ( ! isset ( $zip_regex[ $country_code ] ) || preg_match( "/" . $zip_regex[ $country_code ] . "/i", $zip ) )
1158
+    if (!isset ($zip_regex[$country_code]) || preg_match("/" . $zip_regex[$country_code] . "/i", $zip))
1159 1159
         $ret = true;
1160 1160
 
1161
-    return apply_filters( 'wpinv_is_zip_valid', $ret, $zip, $country_code );
1161
+    return apply_filters('wpinv_is_zip_valid', $ret, $zip, $country_code);
1162 1162
 }
1163 1163
 
1164 1164
 function wpinv_checkout_validate_agree_to_terms() {
1165 1165
     // Validate agree to terms
1166
-    if ( ! isset( $_POST['wpi_agree_to_terms'] ) || $_POST['wpi_agree_to_terms'] != 1 ) {
1166
+    if (!isset($_POST['wpi_agree_to_terms']) || $_POST['wpi_agree_to_terms'] != 1) {
1167 1167
         // User did not agree
1168
-        wpinv_set_error( 'agree_to_terms', apply_filters( 'wpinv_agree_to_terms_text', __( 'You must agree to the terms of use', 'invoicing' ) ) );
1168
+        wpinv_set_error('agree_to_terms', apply_filters('wpinv_agree_to_terms_text', __('You must agree to the terms of use', 'invoicing')));
1169 1169
     }
1170 1170
 }
1171 1171
 
@@ -1178,36 +1178,36 @@  discard block
 block discarded – undo
1178 1178
     );
1179 1179
     
1180 1180
     // Verify there is a user_ID
1181
-    if ( $user_ID > 0 ) {
1181
+    if ($user_ID > 0) {
1182 1182
         // Get the logged in user data
1183
-        $user_data = get_userdata( $user_ID );
1184
-        $required_fields  = wpinv_checkout_required_fields();
1183
+        $user_data = get_userdata($user_ID);
1184
+        $required_fields = wpinv_checkout_required_fields();
1185 1185
 
1186 1186
         // Loop through required fields and show error messages
1187
-         if ( !empty( $required_fields ) ) {
1188
-            foreach ( $required_fields as $field_name => $value ) {
1189
-                if ( in_array( $value, $required_fields ) && empty( $_POST[ 'wpinv_' . $field_name ] ) ) {
1190
-                    wpinv_set_error( $value['error_id'], $value['error_message'] );
1187
+         if (!empty($required_fields)) {
1188
+            foreach ($required_fields as $field_name => $value) {
1189
+                if (in_array($value, $required_fields) && empty($_POST['wpinv_' . $field_name])) {
1190
+                    wpinv_set_error($value['error_id'], $value['error_message']);
1191 1191
                 }
1192 1192
             }
1193 1193
         }
1194 1194
 
1195 1195
         // Verify data
1196
-        if ( $user_data ) {
1196
+        if ($user_data) {
1197 1197
             // Collected logged in user data
1198 1198
             $valid_user_data = array(
1199 1199
                 'user_id'     => $user_ID,
1200
-                'email'       => isset( $_POST['wpinv_email'] ) ? sanitize_email( $_POST['wpinv_email'] ) : $user_data->user_email,
1201
-                'first_name'  => isset( $_POST['wpinv_first_name'] ) && ! empty( $_POST['wpinv_first_name'] ) ? sanitize_text_field( $_POST['wpinv_first_name'] ) : $user_data->first_name,
1202
-                'last_name'   => isset( $_POST['wpinv_last_name'] ) && ! empty( $_POST['wpinv_last_name']  ) ? sanitize_text_field( $_POST['wpinv_last_name']  ) : $user_data->last_name,
1200
+                'email'       => isset($_POST['wpinv_email']) ? sanitize_email($_POST['wpinv_email']) : $user_data->user_email,
1201
+                'first_name'  => isset($_POST['wpinv_first_name']) && !empty($_POST['wpinv_first_name']) ? sanitize_text_field($_POST['wpinv_first_name']) : $user_data->first_name,
1202
+                'last_name'   => isset($_POST['wpinv_last_name']) && !empty($_POST['wpinv_last_name']) ? sanitize_text_field($_POST['wpinv_last_name']) : $user_data->last_name,
1203 1203
             );
1204 1204
 
1205
-            if ( !empty( $_POST[ 'wpinv_email' ] ) && !is_email( $_POST[ 'wpinv_email' ] ) ) {
1206
-                wpinv_set_error( 'invalid_email', __( 'Please enter a valid email address', 'invoicing' ) );
1205
+            if (!empty($_POST['wpinv_email']) && !is_email($_POST['wpinv_email'])) {
1206
+                wpinv_set_error('invalid_email', __('Please enter a valid email address', 'invoicing'));
1207 1207
             }
1208 1208
         } else {
1209 1209
             // Set invalid user error
1210
-            wpinv_set_error( 'invalid_user', __( 'The user billing information is invalid', 'invoicing' ) );
1210
+            wpinv_set_error('invalid_user', __('The user billing information is invalid', 'invoicing'));
1211 1211
         }
1212 1212
     }
1213 1213
 
@@ -1215,21 +1215,21 @@  discard block
 block discarded – undo
1215 1215
     return $valid_user_data;
1216 1216
 }
1217 1217
 
1218
-function wpinv_checkout_form_get_user( $valid_data = array() ) {
1218
+function wpinv_checkout_form_get_user($valid_data = array()) {
1219 1219
     // Initialize user
1220 1220
     $user    = false;
1221
-    $is_ajax = defined( 'DOING_AJAX' ) && DOING_AJAX;
1221
+    $is_ajax = defined('DOING_AJAX') && DOING_AJAX;
1222 1222
 
1223 1223
     /*if ( $is_ajax ) {
1224 1224
         // Do not create or login the user during the ajax submission (check for errors only)
1225 1225
         return true;
1226
-    } else */if ( is_user_logged_in() ) {
1226
+    } else */if (is_user_logged_in()) {
1227 1227
         // Set the valid user as the logged in collected data
1228 1228
         $user = $valid_data['logged_in_user'];
1229 1229
     }
1230 1230
 
1231 1231
     // Verify we have an user
1232
-    if ( false === $user || empty( $user ) ) {
1232
+    if (false === $user || empty($user)) {
1233 1233
         // Return false
1234 1234
         return false;
1235 1235
     }
@@ -1248,11 +1248,11 @@  discard block
 block discarded – undo
1248 1248
         'zip',
1249 1249
     );
1250 1250
     
1251
-    foreach ( $address_fields as $field ) {
1252
-        $user[$field]  = !empty( $_POST['wpinv_' . $field] ) ? sanitize_text_field( $_POST['wpinv_' . $field] ) : false;
1251
+    foreach ($address_fields as $field) {
1252
+        $user[$field] = !empty($_POST['wpinv_' . $field]) ? sanitize_text_field($_POST['wpinv_' . $field]) : false;
1253 1253
         
1254
-        if ( !empty( $user['user_id'] ) ) {
1255
-            update_user_meta( $user['user_id'], '_wpinv_' . $field, $user[$field] );
1254
+        if (!empty($user['user_id'])) {
1255
+            update_user_meta($user['user_id'], '_wpinv_' . $field, $user[$field]);
1256 1256
         }
1257 1257
     }
1258 1258
 
@@ -1260,28 +1260,28 @@  discard block
 block discarded – undo
1260 1260
     return $user;
1261 1261
 }
1262 1262
 
1263
-function wpinv_set_checkout_session( $invoice_data = array() ) {
1263
+function wpinv_set_checkout_session($invoice_data = array()) {
1264 1264
     global $wpi_session;
1265 1265
     
1266
-    return $wpi_session->set( 'wpinv_checkout', $invoice_data );
1266
+    return $wpi_session->set('wpinv_checkout', $invoice_data);
1267 1267
 }
1268 1268
 
1269 1269
 function wpinv_get_checkout_session() {
1270 1270
 	global $wpi_session;
1271 1271
     
1272
-    return $wpi_session->get( 'wpinv_checkout' );
1272
+    return $wpi_session->get('wpinv_checkout');
1273 1273
 }
1274 1274
 
1275 1275
 function wpinv_empty_cart() {
1276 1276
     global $wpi_session;
1277 1277
 
1278 1278
     // Remove cart contents
1279
-    $wpi_session->set( 'wpinv_checkout', NULL );
1279
+    $wpi_session->set('wpinv_checkout', NULL);
1280 1280
 
1281 1281
     // Remove all cart fees
1282
-    $wpi_session->set( 'wpi_cart_fees', NULL );
1282
+    $wpi_session->set('wpi_cart_fees', NULL);
1283 1283
 
1284
-    do_action( 'wpinv_empty_cart' );
1284
+    do_action('wpinv_empty_cart');
1285 1285
 }
1286 1286
 
1287 1287
 function wpinv_process_checkout() {
@@ -1293,42 +1293,42 @@  discard block
 block discarded – undo
1293 1293
     
1294 1294
     $wpi_checkout_id = $invoice->ID;
1295 1295
     
1296
-    do_action( 'wpinv_pre_process_checkout' );
1296
+    do_action('wpinv_pre_process_checkout');
1297 1297
     
1298
-    if ( !wpinv_get_cart_contents() ) { // Make sure the cart isn't empty
1298
+    if (!wpinv_get_cart_contents()) { // Make sure the cart isn't empty
1299 1299
         $valid_data = false;
1300
-        wpinv_set_error( 'empty_cart', __( 'Your cart is empty', 'invoicing' ) );
1300
+        wpinv_set_error('empty_cart', __('Your cart is empty', 'invoicing'));
1301 1301
     } else {
1302 1302
         // Validate the form $_POST data
1303 1303
         $valid_data = wpinv_validate_checkout_fields();
1304 1304
         
1305 1305
         // Allow themes and plugins to hook to errors
1306
-        do_action( 'wpinv_checkout_error_checks', $valid_data, $_POST );
1306
+        do_action('wpinv_checkout_error_checks', $valid_data, $_POST);
1307 1307
     }
1308 1308
     
1309
-    $is_ajax    = defined( 'DOING_AJAX' ) && DOING_AJAX;
1309
+    $is_ajax = defined('DOING_AJAX') && DOING_AJAX;
1310 1310
     
1311 1311
     // Validate the user
1312
-    $user = wpinv_checkout_form_get_user( $valid_data );
1312
+    $user = wpinv_checkout_form_get_user($valid_data);
1313 1313
 
1314 1314
     // Let extensions validate fields after user is logged in if user has used login/registration form
1315
-    do_action( 'wpinv_checkout_user_error_checks', $user, $valid_data, $_POST );
1315
+    do_action('wpinv_checkout_user_error_checks', $user, $valid_data, $_POST);
1316 1316
     
1317
-    if ( false === $valid_data || wpinv_get_errors() || ! $user ) {
1318
-        if ( $is_ajax ) {
1319
-            do_action( 'wpinv_ajax_checkout_errors' );
1317
+    if (false === $valid_data || wpinv_get_errors() || !$user) {
1318
+        if ($is_ajax) {
1319
+            do_action('wpinv_ajax_checkout_errors');
1320 1320
             die();
1321 1321
         } else {
1322 1322
             return false;
1323 1323
         }
1324 1324
     }
1325 1325
 
1326
-    if ( $is_ajax ) {
1326
+    if ($is_ajax) {
1327 1327
         // Save address fields.
1328
-        $address_fields = array( 'first_name', 'last_name', 'phone', 'address', 'city', 'country', 'state', 'zip', 'company' );
1329
-        foreach ( $address_fields as $field ) {
1330
-            if ( isset( $user[$field] ) ) {
1331
-                $invoice->set( $field, $user[$field] );
1328
+        $address_fields = array('first_name', 'last_name', 'phone', 'address', 'city', 'country', 'state', 'zip', 'company');
1329
+        foreach ($address_fields as $field) {
1330
+            if (isset($user[$field])) {
1331
+                $invoice->set($field, $user[$field]);
1332 1332
             }
1333 1333
             
1334 1334
             $invoice->save();
@@ -1336,15 +1336,15 @@  discard block
 block discarded – undo
1336 1336
 
1337 1337
         $response['success']            = true;
1338 1338
         $response['data']['subtotal']   = $invoice->get_subtotal();
1339
-        $response['data']['subtotalf']  = $invoice->get_subtotal( true );
1339
+        $response['data']['subtotalf']  = $invoice->get_subtotal(true);
1340 1340
         $response['data']['discount']   = $invoice->get_discount();
1341
-        $response['data']['discountf']  = $invoice->get_discount( true );
1341
+        $response['data']['discountf']  = $invoice->get_discount(true);
1342 1342
         $response['data']['tax']        = $invoice->get_tax();
1343
-        $response['data']['taxf']       = $invoice->get_tax( true );
1343
+        $response['data']['taxf']       = $invoice->get_tax(true);
1344 1344
         $response['data']['total']      = $invoice->get_total();
1345
-        $response['data']['totalf']     = $invoice->get_total( true );
1345
+        $response['data']['totalf']     = $invoice->get_total(true);
1346 1346
         
1347
-        wp_send_json( $response );
1347
+        wp_send_json($response);
1348 1348
     }
1349 1349
     
1350 1350
     $user_info = array(
@@ -1366,42 +1366,42 @@  discard block
 block discarded – undo
1366 1366
     
1367 1367
     // Setup invoice information
1368 1368
     $invoice_data = array(
1369
-        'invoice_id'        => !empty( $invoice ) ? $invoice->ID : 0,
1369
+        'invoice_id'        => !empty($invoice) ? $invoice->ID : 0,
1370 1370
         'items'             => $cart_items,
1371 1371
         'cart_discounts'    => $discounts,
1372
-        'fees'              => wpinv_get_cart_fees(),        // Any arbitrary fees that have been added to the cart
1373
-        'subtotal'          => wpinv_get_cart_subtotal( $cart_items ),    // Amount before taxes and discounts
1374
-        'discount'          => wpinv_get_cart_items_discount_amount( $cart_items, $discounts ), // Discounted amount
1375
-        'tax'               => wpinv_get_cart_tax( $cart_items ),               // Taxed amount
1376
-        'price'             => wpinv_get_cart_total( $cart_items, $discounts ),    // Amount after taxes
1372
+        'fees'              => wpinv_get_cart_fees(), // Any arbitrary fees that have been added to the cart
1373
+        'subtotal'          => wpinv_get_cart_subtotal($cart_items), // Amount before taxes and discounts
1374
+        'discount'          => wpinv_get_cart_items_discount_amount($cart_items, $discounts), // Discounted amount
1375
+        'tax'               => wpinv_get_cart_tax($cart_items), // Taxed amount
1376
+        'price'             => wpinv_get_cart_total($cart_items, $discounts), // Amount after taxes
1377 1377
         'invoice_key'       => $invoice->get_key() ? $invoice->get_key() : $invoice->generate_key(),
1378 1378
         'user_email'        => $user['email'],
1379
-        'date'              => date( 'Y-m-d H:i:s', current_time( 'timestamp' ) ),
1380
-        'user_info'         => stripslashes_deep( $user_info ),
1379
+        'date'              => date('Y-m-d H:i:s', current_time('timestamp')),
1380
+        'user_info'         => stripslashes_deep($user_info),
1381 1381
         'post_data'         => $_POST,
1382 1382
         'cart_details'      => $cart_items,
1383 1383
         'gateway'           => $valid_data['gateway'],
1384 1384
         'card_info'         => $valid_data['cc_info']
1385 1385
     );
1386 1386
     
1387
-    $vat_info   = $wpinv_euvat->current_vat_data();
1388
-    if ( is_array( $vat_info ) ) {
1387
+    $vat_info = $wpinv_euvat->current_vat_data();
1388
+    if (is_array($vat_info)) {
1389 1389
         $invoice_data['user_info']['vat_number']        = $vat_info['number'];
1390 1390
         $invoice_data['user_info']['vat_rate']          = wpinv_get_tax_rate($invoice_data['user_info']['country'], $invoice_data['user_info']['state']);
1391
-        $invoice_data['user_info']['adddress_confirmed']    = isset($vat_info['adddress_confirmed']) ? $vat_info['adddress_confirmed'] : false;
1391
+        $invoice_data['user_info']['adddress_confirmed'] = isset($vat_info['adddress_confirmed']) ? $vat_info['adddress_confirmed'] : false;
1392 1392
 
1393 1393
         // Add the VAT rate to each item in the cart
1394
-        foreach( $invoice_data['cart_details'] as $key => $item_data) {
1394
+        foreach ($invoice_data['cart_details'] as $key => $item_data) {
1395 1395
             $rate = wpinv_get_tax_rate($invoice_data['user_info']['country'], $invoice_data['user_info']['state'], $item_data['id']);
1396
-            $invoice_data['cart_details'][$key]['vat_rate'] = wpinv_round_amount( $rate, 4 );
1396
+            $invoice_data['cart_details'][$key]['vat_rate'] = wpinv_round_amount($rate, 4);
1397 1397
         }
1398 1398
     }
1399 1399
     
1400 1400
     // Save vat fields.
1401
-    $address_fields = array( 'vat_number', 'vat_rate', 'adddress_confirmed' );
1402
-    foreach ( $address_fields as $field ) {
1403
-        if ( isset( $invoice_data['user_info'][$field] ) ) {
1404
-            $invoice->set( $field, $invoice_data['user_info'][$field] );
1401
+    $address_fields = array('vat_number', 'vat_rate', 'adddress_confirmed');
1402
+    foreach ($address_fields as $field) {
1403
+        if (isset($invoice_data['user_info'][$field])) {
1404
+            $invoice->set($field, $invoice_data['user_info'][$field]);
1405 1405
         }
1406 1406
         
1407 1407
         $invoice->save();
@@ -1411,49 +1411,49 @@  discard block
 block discarded – undo
1411 1411
     $valid_data['user'] = $user;
1412 1412
     
1413 1413
     // Allow themes and plugins to hook before the gateway
1414
-    do_action( 'wpinv_checkout_before_gateway', $_POST, $user_info, $valid_data );
1414
+    do_action('wpinv_checkout_before_gateway', $_POST, $user_info, $valid_data);
1415 1415
     
1416 1416
     // If the total amount in the cart is 0, send to the manual gateway. This emulates a free invoice
1417
-    if ( !$invoice_data['price'] ) {
1417
+    if (!$invoice_data['price']) {
1418 1418
         // Revert to manual
1419 1419
         $invoice_data['gateway'] = 'manual';
1420 1420
         $_POST['wpi-gateway'] = 'manual';
1421 1421
     }
1422 1422
     
1423 1423
     // Allow the invoice data to be modified before it is sent to the gateway
1424
-    $invoice_data = apply_filters( 'wpinv_data_before_gateway', $invoice_data, $valid_data );
1424
+    $invoice_data = apply_filters('wpinv_data_before_gateway', $invoice_data, $valid_data);
1425 1425
     
1426 1426
     // Setup the data we're storing in the purchase session
1427 1427
     $session_data = $invoice_data;
1428 1428
     // Make sure credit card numbers are never stored in sessions
1429
-    if ( !empty( $session_data['card_info']['card_number'] ) ) {
1430
-        unset( $session_data['card_info']['card_number'] );
1429
+    if (!empty($session_data['card_info']['card_number'])) {
1430
+        unset($session_data['card_info']['card_number']);
1431 1431
     }
1432 1432
     
1433 1433
     // Used for showing item links to non logged-in users after purchase, and for other plugins needing purchase data.
1434
-    wpinv_set_checkout_session( $invoice_data );
1434
+    wpinv_set_checkout_session($invoice_data);
1435 1435
     
1436 1436
     // Set gateway
1437
-    $invoice->update_meta( '_wpinv_gateway', $invoice_data['gateway'] );
1438
-    $invoice->update_meta( '_wpinv_mode', ( wpinv_is_test_mode( $invoice_data['gateway'] ) ? 'test' : 'live' ) );
1439
-    $invoice->update_meta( '_wpinv_checkout', true );
1437
+    $invoice->update_meta('_wpinv_gateway', $invoice_data['gateway']);
1438
+    $invoice->update_meta('_wpinv_mode', (wpinv_is_test_mode($invoice_data['gateway']) ? 'test' : 'live'));
1439
+    $invoice->update_meta('_wpinv_checkout', true);
1440 1440
     
1441
-    do_action( 'wpinv_checkout_before_send_to_gateway', $invoice, $invoice_data );
1441
+    do_action('wpinv_checkout_before_send_to_gateway', $invoice, $invoice_data);
1442 1442
 
1443 1443
     // Send info to the gateway for payment processing
1444
-    wpinv_send_to_gateway( $invoice_data['gateway'], $invoice_data );
1444
+    wpinv_send_to_gateway($invoice_data['gateway'], $invoice_data);
1445 1445
     die();
1446 1446
 }
1447
-add_action( 'wpinv_payment', 'wpinv_process_checkout' );
1447
+add_action('wpinv_payment', 'wpinv_process_checkout');
1448 1448
 
1449
-function wpinv_get_invoices( $args ) {
1450
-    $args = wp_parse_args( $args, array(
1451
-        'status'   => array_keys( wpinv_get_invoice_statuses() ),
1449
+function wpinv_get_invoices($args) {
1450
+    $args = wp_parse_args($args, array(
1451
+        'status'   => array_keys(wpinv_get_invoice_statuses()),
1452 1452
         'type'     => 'wpi_invoice',
1453 1453
         'parent'   => null,
1454 1454
         'user'     => null,
1455 1455
         'email'    => '',
1456
-        'limit'    => get_option( 'posts_per_page' ),
1456
+        'limit'    => get_option('posts_per_page'),
1457 1457
         'offset'   => null,
1458 1458
         'page'     => 1,
1459 1459
         'exclude'  => array(),
@@ -1461,7 +1461,7 @@  discard block
 block discarded – undo
1461 1461
         'order'    => 'DESC',
1462 1462
         'return'   => 'objects',
1463 1463
         'paginate' => false,
1464
-    ) );
1464
+    ));
1465 1465
     
1466 1466
     // Handle some BW compatibility arg names where wp_query args differ in naming.
1467 1467
     $map_legacy = array(
@@ -1474,20 +1474,20 @@  discard block
 block discarded – undo
1474 1474
         'paged'          => 'page',
1475 1475
     );
1476 1476
 
1477
-    foreach ( $map_legacy as $from => $to ) {
1478
-        if ( isset( $args[ $from ] ) ) {
1479
-            $args[ $to ] = $args[ $from ];
1477
+    foreach ($map_legacy as $from => $to) {
1478
+        if (isset($args[$from])) {
1479
+            $args[$to] = $args[$from];
1480 1480
         }
1481 1481
     }
1482 1482
 
1483
-    $wpinv_cpt = $_REQUEST[ 'wpinv-cpt' ];
1483
+    $wpinv_cpt = $_REQUEST['wpinv-cpt'];
1484 1484
 
1485
-    if ( get_query_var( 'paged' ) && 'wpi_invoice' == $wpinv_cpt )
1485
+    if (get_query_var('paged') && 'wpi_invoice' == $wpinv_cpt)
1486 1486
         $args['page'] = get_query_var('paged');
1487
-    else if ( get_query_var( 'page' )  && 'wpi_invoice' == $wpinv_cpt )
1488
-        $args['page'] = get_query_var( 'page' );
1489
-    else if ( !empty( $args[ 'page' ] ) )
1490
-        $args['page'] = $args[ 'page' ];
1487
+    else if (get_query_var('page') && 'wpi_invoice' == $wpinv_cpt)
1488
+        $args['page'] = get_query_var('page');
1489
+    else if (!empty($args['page']))
1490
+        $args['page'] = $args['page'];
1491 1491
     else
1492 1492
         $args['page'] = 1;
1493 1493
 
@@ -1500,47 +1500,47 @@  discard block
 block discarded – undo
1500 1500
         'post_status'    => $args['status'],
1501 1501
         'posts_per_page' => $args['limit'],
1502 1502
         'meta_query'     => array(),
1503
-        'date_query'     => !empty( $args['date_query'] ) ? $args['date_query'] : array(),
1503
+        'date_query'     => !empty($args['date_query']) ? $args['date_query'] : array(),
1504 1504
         'fields'         => 'ids',
1505 1505
         'orderby'        => $args['orderby'],
1506 1506
         'order'          => $args['order'],
1507 1507
     );
1508 1508
     
1509
-    if ( !empty( $args['user'] ) ) {
1510
-        $wp_query_args['author'] = absint( $args['user'] );
1509
+    if (!empty($args['user'])) {
1510
+        $wp_query_args['author'] = absint($args['user']);
1511 1511
     }
1512 1512
 
1513
-    if ( ! is_null( $args['parent'] ) ) {
1514
-        $wp_query_args['post_parent'] = absint( $args['parent'] );
1513
+    if (!is_null($args['parent'])) {
1514
+        $wp_query_args['post_parent'] = absint($args['parent']);
1515 1515
     }
1516 1516
 
1517
-    if ( ! is_null( $args['offset'] ) ) {
1518
-        $wp_query_args['offset'] = absint( $args['offset'] );
1517
+    if (!is_null($args['offset'])) {
1518
+        $wp_query_args['offset'] = absint($args['offset']);
1519 1519
     } else {
1520
-        $wp_query_args['paged'] = absint( $args['page'] );
1520
+        $wp_query_args['paged'] = absint($args['page']);
1521 1521
     }
1522 1522
 
1523
-    if ( ! empty( $args['exclude'] ) ) {
1524
-        $wp_query_args['post__not_in'] = array_map( 'absint', $args['exclude'] );
1523
+    if (!empty($args['exclude'])) {
1524
+        $wp_query_args['post__not_in'] = array_map('absint', $args['exclude']);
1525 1525
     }
1526 1526
 
1527
-    if ( ! $args['paginate' ] ) {
1527
+    if (!$args['paginate']) {
1528 1528
         $wp_query_args['no_found_rows'] = true;
1529 1529
     }
1530 1530
 
1531 1531
     // Get results.
1532
-    $invoices = new WP_Query( $wp_query_args );
1532
+    $invoices = new WP_Query($wp_query_args);
1533 1533
 
1534
-    if ( 'objects' === $args['return'] ) {
1535
-        $return = array_map( 'wpinv_get_invoice', $invoices->posts );
1536
-    } elseif ( 'self' === $args['return'] ) {
1534
+    if ('objects' === $args['return']) {
1535
+        $return = array_map('wpinv_get_invoice', $invoices->posts);
1536
+    } elseif ('self' === $args['return']) {
1537 1537
         return $invoices;
1538 1538
     } else {
1539 1539
         $return = $invoices->posts;
1540 1540
     }
1541 1541
 
1542
-    if ( $args['paginate' ] ) {
1543
-        return (object) array(
1542
+    if ($args['paginate']) {
1543
+        return (object)array(
1544 1544
             'invoices'      => $return,
1545 1545
             'total'         => $invoices->found_posts,
1546 1546
             'max_num_pages' => $invoices->max_num_pages,
@@ -1552,21 +1552,21 @@  discard block
 block discarded – undo
1552 1552
 
1553 1553
 function wpinv_get_user_invoices_columns() {
1554 1554
     $columns = array(
1555
-            'invoice-number'  => array( 'title' => __( 'ID', 'invoicing' ), 'class' => 'text-left' ),
1556
-            'invoice-date'    => array( 'title' => __( 'Date', 'invoicing' ), 'class' => 'text-left' ),
1557
-            'invoice-status'  => array( 'title' => __( 'Status', 'invoicing' ), 'class' => 'text-center' ),
1558
-            'invoice-total'   => array( 'title' => __( 'Total', 'invoicing' ), 'class' => 'text-right' ),
1559
-            'invoice-actions' => array( 'title' => '&nbsp;', 'class' => 'text-center' ),
1555
+            'invoice-number'  => array('title' => __('ID', 'invoicing'), 'class' => 'text-left'),
1556
+            'invoice-date'    => array('title' => __('Date', 'invoicing'), 'class' => 'text-left'),
1557
+            'invoice-status'  => array('title' => __('Status', 'invoicing'), 'class' => 'text-center'),
1558
+            'invoice-total'   => array('title' => __('Total', 'invoicing'), 'class' => 'text-right'),
1559
+            'invoice-actions' => array('title' => '&nbsp;', 'class' => 'text-center'),
1560 1560
         );
1561 1561
 
1562
-    return apply_filters( 'wpinv_user_invoices_columns', $columns );
1562
+    return apply_filters('wpinv_user_invoices_columns', $columns);
1563 1563
 }
1564 1564
 
1565
-function wpinv_payment_receipt( $atts, $content = null ) {
1565
+function wpinv_payment_receipt($atts, $content = null) {
1566 1566
     global $wpinv_receipt_args;
1567 1567
 
1568
-    $wpinv_receipt_args = shortcode_atts( array(
1569
-        'error'           => __( 'Sorry, trouble retrieving payment receipt.', 'invoicing' ),
1568
+    $wpinv_receipt_args = shortcode_atts(array(
1569
+        'error'           => __('Sorry, trouble retrieving payment receipt.', 'invoicing'),
1570 1570
         'price'           => true,
1571 1571
         'discount'        => true,
1572 1572
         'items'           => true,
@@ -1575,185 +1575,185 @@  discard block
 block discarded – undo
1575 1575
         'invoice_key'     => false,
1576 1576
         'payment_method'  => true,
1577 1577
         'invoice_id'      => true
1578
-    ), $atts, 'wpinv_receipt' );
1578
+    ), $atts, 'wpinv_receipt');
1579 1579
 
1580 1580
     $session = wpinv_get_checkout_session();
1581
-    if ( isset( $_GET['invoice_key'] ) ) {
1582
-        $invoice_key = urldecode( $_GET['invoice_key'] );
1583
-    } else if ( $session && isset( $session['invoice_key'] ) ) {
1581
+    if (isset($_GET['invoice_key'])) {
1582
+        $invoice_key = urldecode($_GET['invoice_key']);
1583
+    } else if ($session && isset($session['invoice_key'])) {
1584 1584
         $invoice_key = $session['invoice_key'];
1585
-    } elseif ( isset( $wpinv_receipt_args['invoice_key'] ) && $wpinv_receipt_args['invoice_key'] ) {
1585
+    } elseif (isset($wpinv_receipt_args['invoice_key']) && $wpinv_receipt_args['invoice_key']) {
1586 1586
         $invoice_key = $wpinv_receipt_args['invoice_key'];
1587
-    } else if ( isset( $_GET['invoice-id'] ) ) {
1588
-        $invoice_key = wpinv_get_payment_key( (int)$_GET['invoice-id'] );
1587
+    } else if (isset($_GET['invoice-id'])) {
1588
+        $invoice_key = wpinv_get_payment_key((int)$_GET['invoice-id']);
1589 1589
     }
1590 1590
 
1591 1591
     // No key found
1592
-    if ( ! isset( $invoice_key ) ) {
1592
+    if (!isset($invoice_key)) {
1593 1593
         return '<p class="alert alert-error">' . $wpinv_receipt_args['error'] . '</p>';
1594 1594
     }
1595 1595
 
1596
-    $invoice_id    = wpinv_get_invoice_id_by_key( $invoice_key );
1597
-    $user_can_view = wpinv_can_view_receipt( $invoice_key );
1598
-    if ( $user_can_view && isset( $_GET['invoice-id'] ) ) {
1596
+    $invoice_id    = wpinv_get_invoice_id_by_key($invoice_key);
1597
+    $user_can_view = wpinv_can_view_receipt($invoice_key);
1598
+    if ($user_can_view && isset($_GET['invoice-id'])) {
1599 1599
         $invoice_id     = (int)$_GET['invoice-id'];
1600
-        $user_can_view  = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? true : false;
1600
+        $user_can_view  = $invoice_key == wpinv_get_payment_key((int)$_GET['invoice-id']) ? true : false;
1601 1601
     }
1602 1602
 
1603 1603
     // Key was provided, but user is logged out. Offer them the ability to login and view the receipt
1604
-    if ( ! $user_can_view && ! empty( $invoice_key ) && ! is_user_logged_in() ) {
1604
+    if (!$user_can_view && !empty($invoice_key) && !is_user_logged_in()) {
1605 1605
         // login redirect
1606
-        return '<p class="alert alert-error">' . __( 'You are not allowed to access this section', 'invoicing' ) . '</p>';
1606
+        return '<p class="alert alert-error">' . __('You are not allowed to access this section', 'invoicing') . '</p>';
1607 1607
     }
1608 1608
 
1609
-    if ( ! apply_filters( 'wpinv_user_can_view_receipt', $user_can_view, $wpinv_receipt_args ) ) {
1609
+    if (!apply_filters('wpinv_user_can_view_receipt', $user_can_view, $wpinv_receipt_args)) {
1610 1610
         return '<p class="alert alert-error">' . $wpinv_receipt_args['error'] . '</p>';
1611 1611
     }
1612 1612
 
1613 1613
     ob_start();
1614 1614
 
1615
-    wpinv_get_template_part( 'wpinv-invoice-receipt' );
1615
+    wpinv_get_template_part('wpinv-invoice-receipt');
1616 1616
 
1617 1617
     $display = ob_get_clean();
1618 1618
 
1619 1619
     return $display;
1620 1620
 }
1621 1621
 
1622
-function wpinv_get_invoice_id_by_key( $key ) {
1622
+function wpinv_get_invoice_id_by_key($key) {
1623 1623
 	global $wpdb;
1624 1624
 
1625
-	$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 ) );
1625
+	$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));
1626 1626
 
1627
-	if ( $invoice_id != NULL )
1627
+	if ($invoice_id != NULL)
1628 1628
 		return $invoice_id;
1629 1629
 
1630 1630
 	return 0;
1631 1631
 }
1632 1632
 
1633
-function wpinv_can_view_receipt( $invoice_key = '' ) {
1633
+function wpinv_can_view_receipt($invoice_key = '') {
1634 1634
 	$return = false;
1635 1635
 
1636
-	if ( empty( $invoice_key ) ) {
1636
+	if (empty($invoice_key)) {
1637 1637
 		return $return;
1638 1638
 	}
1639 1639
 
1640 1640
 	global $wpinv_receipt_args;
1641 1641
 
1642
-	$wpinv_receipt_args['id'] = wpinv_get_invoice_id_by_key( $invoice_key );
1643
-	if ( isset( $_GET['invoice-id'] ) ) {
1644
-		$wpinv_receipt_args['id'] = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? (int)$_GET['invoice-id'] : 0;
1642
+	$wpinv_receipt_args['id'] = wpinv_get_invoice_id_by_key($invoice_key);
1643
+	if (isset($_GET['invoice-id'])) {
1644
+		$wpinv_receipt_args['id'] = $invoice_key == wpinv_get_payment_key((int)$_GET['invoice-id']) ? (int)$_GET['invoice-id'] : 0;
1645 1645
 	}
1646 1646
 
1647
-	$user_id = (int) wpinv_get_user_id( $wpinv_receipt_args['id'] );
1648
-    $invoice_meta = wpinv_get_invoice_meta( $wpinv_receipt_args['id'] );
1647
+	$user_id = (int)wpinv_get_user_id($wpinv_receipt_args['id']);
1648
+    $invoice_meta = wpinv_get_invoice_meta($wpinv_receipt_args['id']);
1649 1649
 
1650
-	if ( is_user_logged_in() ) {
1651
-		if ( $user_id === (int) get_current_user_id() ) {
1650
+	if (is_user_logged_in()) {
1651
+		if ($user_id === (int)get_current_user_id()) {
1652 1652
 			$return = true;
1653 1653
 		}
1654 1654
 	}
1655 1655
 
1656 1656
 	$session = wpinv_get_checkout_session();
1657
-	if ( ! empty( $session ) && ! is_user_logged_in() ) {
1658
-		if ( $session['invoice_key'] === $invoice_meta['key'] ) {
1657
+	if (!empty($session) && !is_user_logged_in()) {
1658
+		if ($session['invoice_key'] === $invoice_meta['key']) {
1659 1659
 			$return = true;
1660 1660
 		}
1661 1661
 	}
1662 1662
 
1663
-	return (bool) apply_filters( 'wpinv_can_view_receipt', $return, $invoice_key );
1663
+	return (bool)apply_filters('wpinv_can_view_receipt', $return, $invoice_key);
1664 1664
 }
1665 1665
 
1666 1666
 function wpinv_pay_for_invoice() {
1667 1667
     global $wpinv_euvat;
1668 1668
     
1669
-    if ( isset( $_GET['invoice_key'] ) ) {
1669
+    if (isset($_GET['invoice_key'])) {
1670 1670
         $checkout_uri   = wpinv_get_checkout_uri();
1671
-        $invoice_key    = sanitize_text_field( $_GET['invoice_key'] );
1671
+        $invoice_key    = sanitize_text_field($_GET['invoice_key']);
1672 1672
         
1673
-        if ( empty( $invoice_key ) ) {
1674
-            wpinv_set_error( 'invalid_invoice', __( 'Invoice not found', 'invoicing' ) );
1675
-            wp_redirect( $checkout_uri );
1673
+        if (empty($invoice_key)) {
1674
+            wpinv_set_error('invalid_invoice', __('Invoice not found', 'invoicing'));
1675
+            wp_redirect($checkout_uri);
1676 1676
             wpinv_die();
1677 1677
         }
1678 1678
         
1679
-        do_action( 'wpinv_check_pay_for_invoice', $invoice_key );
1679
+        do_action('wpinv_check_pay_for_invoice', $invoice_key);
1680 1680
 
1681
-        $invoice_id    = wpinv_get_invoice_id_by_key( $invoice_key );
1682
-        $user_can_view = wpinv_can_view_receipt( $invoice_key );
1683
-        if ( $user_can_view && isset( $_GET['invoice-id'] ) ) {
1681
+        $invoice_id    = wpinv_get_invoice_id_by_key($invoice_key);
1682
+        $user_can_view = wpinv_can_view_receipt($invoice_key);
1683
+        if ($user_can_view && isset($_GET['invoice-id'])) {
1684 1684
             $invoice_id     = (int)$_GET['invoice-id'];
1685
-            $user_can_view  = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? true : false;
1685
+            $user_can_view  = $invoice_key == wpinv_get_payment_key((int)$_GET['invoice-id']) ? true : false;
1686 1686
         }
1687 1687
         
1688
-        if ( $invoice_id && $user_can_view && ( $invoice = wpinv_get_invoice( $invoice_id ) ) ) {
1689
-            if ( $invoice->needs_payment() ) {
1688
+        if ($invoice_id && $user_can_view && ($invoice = wpinv_get_invoice($invoice_id))) {
1689
+            if ($invoice->needs_payment()) {
1690 1690
                 $data                   = array();
1691 1691
                 $data['invoice_id']     = $invoice_id;
1692
-                $data['cart_discounts'] = $invoice->get_discounts( true );
1692
+                $data['cart_discounts'] = $invoice->get_discounts(true);
1693 1693
                 
1694
-                wpinv_set_checkout_session( $data );
1694
+                wpinv_set_checkout_session($data);
1695 1695
                 
1696
-                if ( wpinv_get_option( 'vat_ip_country_default' ) ) {
1696
+                if (wpinv_get_option('vat_ip_country_default')) {
1697 1697
                     $_POST['country']   = $wpinv_euvat->get_country_by_ip();
1698 1698
                     $_POST['state']     = $_POST['country'] == $invoice->country ? $invoice->state : '';
1699 1699
                     
1700
-                    wpinv_recalculate_tax( true );
1700
+                    wpinv_recalculate_tax(true);
1701 1701
                 }
1702 1702
                 
1703 1703
             } else {
1704 1704
                 $checkout_uri = $invoice->get_view_url();
1705 1705
             }
1706 1706
         } else {
1707
-            wpinv_set_error( 'invalid_invoice', __( 'You are not allowed to view this invoice', 'invoicing' ) );
1707
+            wpinv_set_error('invalid_invoice', __('You are not allowed to view this invoice', 'invoicing'));
1708 1708
             
1709
-            $checkout_uri = is_user_logged_in() ? wpinv_get_history_page_uri() : wp_login_url( get_permalink() );
1709
+            $checkout_uri = is_user_logged_in() ? wpinv_get_history_page_uri() : wp_login_url(get_permalink());
1710 1710
         }
1711 1711
         
1712
-        wp_redirect( $checkout_uri );
1712
+        wp_redirect($checkout_uri);
1713 1713
         wpinv_die();
1714 1714
     }
1715 1715
 }
1716
-add_action( 'wpinv_pay_for_invoice', 'wpinv_pay_for_invoice' );
1716
+add_action('wpinv_pay_for_invoice', 'wpinv_pay_for_invoice');
1717 1717
 
1718
-function wpinv_handle_pay_via_invoice_link( $invoice_key ) {
1719
-    if ( !empty( $invoice_key ) && !empty( $_REQUEST['_wpipay'] ) && !is_user_logged_in() && $invoice_id = wpinv_get_invoice_id_by_key( $invoice_key ) ) {
1720
-        if ( $invoice = wpinv_get_invoice( $invoice_id ) ) {
1718
+function wpinv_handle_pay_via_invoice_link($invoice_key) {
1719
+    if (!empty($invoice_key) && !empty($_REQUEST['_wpipay']) && !is_user_logged_in() && $invoice_id = wpinv_get_invoice_id_by_key($invoice_key)) {
1720
+        if ($invoice = wpinv_get_invoice($invoice_id)) {
1721 1721
             $user_id = $invoice->get_user_id();
1722
-            $secret = sanitize_text_field( $_GET['_wpipay'] );
1722
+            $secret = sanitize_text_field($_GET['_wpipay']);
1723 1723
             
1724
-            if ( $secret === md5( $user_id . '::' . $invoice->get_email() . '::' . $invoice_key ) ) { // valid invoice link
1725
-                $redirect_to = remove_query_arg( '_wpipay', get_permalink() );
1724
+            if ($secret === md5($user_id . '::' . $invoice->get_email() . '::' . $invoice_key)) { // valid invoice link
1725
+                $redirect_to = remove_query_arg('_wpipay', get_permalink());
1726 1726
                 
1727
-                wpinv_guest_redirect( $redirect_to, $user_id );
1727
+                wpinv_guest_redirect($redirect_to, $user_id);
1728 1728
                 wpinv_die();
1729 1729
             }
1730 1730
         }
1731 1731
     }
1732 1732
 }
1733
-add_action( 'wpinv_check_pay_for_invoice', 'wpinv_handle_pay_via_invoice_link' );
1733
+add_action('wpinv_check_pay_for_invoice', 'wpinv_handle_pay_via_invoice_link');
1734 1734
 
1735
-function wpinv_set_payment_transaction_id( $invoice_id = 0, $transaction_id = '' ) {
1736
-    $invoice_id = is_object( $invoice_id ) && !empty( $invoice_id->ID ) ? $invoice_id : $invoice_id;
1735
+function wpinv_set_payment_transaction_id($invoice_id = 0, $transaction_id = '') {
1736
+    $invoice_id = is_object($invoice_id) && !empty($invoice_id->ID) ? $invoice_id : $invoice_id;
1737 1737
     
1738
-    if ( empty( $invoice_id ) && $invoice_id > 0 ) {
1738
+    if (empty($invoice_id) && $invoice_id > 0) {
1739 1739
         return false;
1740 1740
     }
1741 1741
     
1742
-    if ( empty( $transaction_id ) ) {
1742
+    if (empty($transaction_id)) {
1743 1743
         $transaction_id = $invoice_id;
1744 1744
     }
1745 1745
 
1746
-    $transaction_id = apply_filters( 'wpinv_set_payment_transaction_id', $transaction_id, $invoice_id );
1746
+    $transaction_id = apply_filters('wpinv_set_payment_transaction_id', $transaction_id, $invoice_id);
1747 1747
     
1748
-    return wpinv_update_invoice_meta( $invoice_id, '_wpinv_transaction_id', $transaction_id );
1748
+    return wpinv_update_invoice_meta($invoice_id, '_wpinv_transaction_id', $transaction_id);
1749 1749
 }
1750 1750
 
1751
-function wpinv_invoice_status_label( $status, $status_display = '' ) {
1752
-    if ( empty( $status_display ) ) {
1753
-        $status_display = wpinv_status_nicename( $status );
1751
+function wpinv_invoice_status_label($status, $status_display = '') {
1752
+    if (empty($status_display)) {
1753
+        $status_display = wpinv_status_nicename($status);
1754 1754
     }
1755 1755
     
1756
-    switch ( $status ) {
1756
+    switch ($status) {
1757 1757
         case 'publish' :
1758 1758
         case 'wpi-renewal' :
1759 1759
             $class = 'label-success';
@@ -1778,28 +1778,28 @@  discard block
 block discarded – undo
1778 1778
     
1779 1779
     $label = '<span class="label label-inv-' . $status . ' ' . $class . '">' . $status_display . '</span>';
1780 1780
     
1781
-    return apply_filters( 'wpinv_invoice_status_label', $label, $status, $status_display );
1781
+    return apply_filters('wpinv_invoice_status_label', $label, $status, $status_display);
1782 1782
 }
1783 1783
 
1784
-function wpinv_format_invoice_number( $number ) {
1785
-    $padd  = wpinv_get_option( 'invoice_number_padd' );
1784
+function wpinv_format_invoice_number($number) {
1785
+    $padd = wpinv_get_option('invoice_number_padd');
1786 1786
     
1787 1787
     // TODO maintain old invoice numbers if invoice number settings not saved. Should be removed before stable release.
1788
-    if ( $padd === '' || $padd === false || $padd === NULL ) {
1789
-        return wp_sprintf( __( 'WPINV-%d', 'invoicing' ), $number );
1788
+    if ($padd === '' || $padd === false || $padd === NULL) {
1789
+        return wp_sprintf(__('WPINV-%d', 'invoicing'), $number);
1790 1790
     }
1791 1791
     
1792
-    $prefix  = wpinv_get_option( 'invoice_number_prefix' );
1793
-    $postfix = wpinv_get_option( 'invoice_number_postfix' );
1792
+    $prefix  = wpinv_get_option('invoice_number_prefix');
1793
+    $postfix = wpinv_get_option('invoice_number_postfix');
1794 1794
     
1795
-    $padd = absint( $padd );
1796
-    $formatted_number = absint( $number );
1795
+    $padd = absint($padd);
1796
+    $formatted_number = absint($number);
1797 1797
     
1798
-    if ( $padd > 0 ) {
1799
-        $formatted_number = zeroise( $formatted_number, $padd );
1798
+    if ($padd > 0) {
1799
+        $formatted_number = zeroise($formatted_number, $padd);
1800 1800
     }    
1801 1801
 
1802 1802
     $formatted_number = $prefix . $formatted_number . $postfix;
1803 1803
 
1804
-    return apply_filters( 'wpinv_format_invoice_number', $formatted_number, $number, $prefix, $postfix, $padd );
1804
+    return apply_filters('wpinv_format_invoice_number', $formatted_number, $number, $prefix, $postfix, $padd);
1805 1805
 }
1806 1806
\ No newline at end of file
Please login to merge, or discard this patch.