Passed
Push — master ( f76276...ca99e2 )
by Stiofan
03:29
created
includes/wpinv-discount-functions.php 1 patch
Spacing   +472 added lines, -472 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,70 +641,70 @@  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 ) ) {
673
-            $user_id = absint( $user );
674
-        } else if ( is_email( $user ) && $user_data = get_user_by( 'email', $user ) ) {
672
+        if (is_int($user)) {
673
+            $user_id = absint($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
-        } else if ( absint( $user ) > 0 ) {
679
-            $user_id = absint( $user );
678
+        } else if (absint($user) > 0) {
679
+            $user_id = absint($user);
680 680
         }
681 681
 
682
-        if ( !empty( $user_id ) ) {
683
-            $query    = array( 'user' => $user_id, 'limit' => false );
684
-            $payments = wpinv_get_invoices( $query ); // Get all payments with matching user id
682
+        if (!empty($user_id)) {
683
+            $query    = array('user' => $user_id, 'limit' => false);
684
+            $payments = wpinv_get_invoices($query); // Get all payments with matching user id
685 685
         }
686 686
 
687
-        if ( $payments ) {
688
-            foreach ( $payments as $payment ) {
687
+        if ($payments) {
688
+            foreach ($payments as $payment) {
689 689
                 // Don't count discount used for current invoice chekcout.
690
-                if ( !empty( $wpi_checkout_id ) && $wpi_checkout_id == $payment->ID ) {
690
+                if (!empty($wpi_checkout_id) && $wpi_checkout_id == $payment->ID) {
691 691
                     continue;
692 692
                 }
693 693
                 
694
-                if ( $payment->has_status( array( 'wpi-cancelled', 'wpi-failed' ) ) ) {
694
+                if ($payment->has_status(array('wpi-cancelled', 'wpi-failed'))) {
695 695
                     continue;
696 696
                 }
697 697
 
698
-                $discounts = $payment->get_discounts( true );
699
-                if ( empty( $discounts ) ) {
698
+                $discounts = $payment->get_discounts(true);
699
+                if (empty($discounts)) {
700 700
                     continue;
701 701
                 }
702 702
 
703
-                $discounts = $discounts && !is_array( $discounts ) ? explode( ',', $discounts ) : $discounts;
703
+                $discounts = $discounts && !is_array($discounts) ? explode(',', $discounts) : $discounts;
704 704
 
705
-                if ( !empty( $discounts ) && is_array( $discounts ) ) {
706
-                    if ( in_array( strtolower( $code ), array_map( 'strtolower', $discounts ) ) ) {
707
-                        wpinv_set_error( 'wpinv-discount-error', __( 'This discount has already been redeemed.', 'invoicing' ) );
705
+                if (!empty($discounts) && is_array($discounts)) {
706
+                    if (in_array(strtolower($code), array_map('strtolower', $discounts))) {
707
+                        wpinv_set_error('wpinv-discount-error', __('This discount has already been redeemed.', 'invoicing'));
708 708
                         $return = true;
709 709
                         break;
710 710
                     }
@@ -713,61 +713,61 @@  discard block
 block discarded – undo
713 713
         }
714 714
     }
715 715
 
716
-    return apply_filters( 'wpinv_is_discount_used', $return, $code, $user );
716
+    return apply_filters('wpinv_is_discount_used', $return, $code, $user);
717 717
 }
718 718
 
719
-function wpinv_is_discount_valid( $code = '', $user = '', $set_error = true ) {
719
+function wpinv_is_discount_valid($code = '', $user = '', $set_error = true) {
720 720
     $return      = false;
721
-    $discount_id = wpinv_get_discount_id_by_code( $code );
722
-    $user        = trim( $user );
721
+    $discount_id = wpinv_get_discount_id_by_code($code);
722
+    $user        = trim($user);
723 723
 
724
-    if ( wpinv_get_cart_contents() ) {
725
-        if ( $discount_id ) {
724
+    if (wpinv_get_cart_contents()) {
725
+        if ($discount_id) {
726 726
             if (
727
-                wpinv_is_discount_active( $discount_id ) &&
728
-                wpinv_check_discount_dates( $discount_id ) &&
729
-                !wpinv_is_discount_maxed_out( $discount_id ) &&
730
-                !wpinv_is_discount_used( $code, $user, $discount_id ) &&
731
-                wpinv_discount_is_min_met( $discount_id ) &&
732
-                wpinv_discount_is_max_met( $discount_id ) &&
733
-                wpinv_discount_item_reqs_met( $discount_id )
727
+                wpinv_is_discount_active($discount_id) &&
728
+                wpinv_check_discount_dates($discount_id) &&
729
+                !wpinv_is_discount_maxed_out($discount_id) &&
730
+                !wpinv_is_discount_used($code, $user, $discount_id) &&
731
+                wpinv_discount_is_min_met($discount_id) &&
732
+                wpinv_discount_is_max_met($discount_id) &&
733
+                wpinv_discount_item_reqs_met($discount_id)
734 734
             ) {
735 735
                 $return = true;
736 736
             }
737
-        } elseif( $set_error ) {
738
-            wpinv_set_error( 'wpinv-discount-error', __( 'This discount is invalid.', 'invoicing' ) );
737
+        } elseif ($set_error) {
738
+            wpinv_set_error('wpinv-discount-error', __('This discount is invalid.', 'invoicing'));
739 739
         }
740 740
     }
741 741
 
742
-    return apply_filters( 'wpinv_is_discount_valid', $return, $discount_id, $code, $user );
742
+    return apply_filters('wpinv_is_discount_valid', $return, $discount_id, $code, $user);
743 743
 }
744 744
 
745
-function wpinv_get_discount_id_by_code( $code ) {
746
-    $discount = wpinv_get_discount_by_code( $code );
747
-    if( $discount ) {
745
+function wpinv_get_discount_id_by_code($code) {
746
+    $discount = wpinv_get_discount_by_code($code);
747
+    if ($discount) {
748 748
         return $discount->ID;
749 749
     }
750 750
     return false;
751 751
 }
752 752
 
753
-function wpinv_get_discounted_amount( $code, $base_price ) {
753
+function wpinv_get_discounted_amount($code, $base_price) {
754 754
     $amount      = $base_price;
755
-    $discount_id = wpinv_get_discount_id_by_code( $code );
755
+    $discount_id = wpinv_get_discount_id_by_code($code);
756 756
 
757
-    if( $discount_id ) {
758
-        $type        = wpinv_get_discount_type( $discount_id );
759
-        $rate        = wpinv_get_discount_amount( $discount_id );
757
+    if ($discount_id) {
758
+        $type        = wpinv_get_discount_type($discount_id);
759
+        $rate        = wpinv_get_discount_amount($discount_id);
760 760
 
761
-        if ( $type == 'flat' ) {
761
+        if ($type == 'flat') {
762 762
             // Set amount
763 763
             $amount = $base_price - $rate;
764
-            if ( $amount < 0 ) {
764
+            if ($amount < 0) {
765 765
                 $amount = 0;
766 766
             }
767 767
 
768 768
         } else {
769 769
             // Percentage discount
770
-            $amount = $base_price - ( $base_price * ( $rate / 100 ) );
770
+            $amount = $base_price - ($base_price * ($rate / 100));
771 771
         }
772 772
 
773 773
     } else {
@@ -776,108 +776,108 @@  discard block
 block discarded – undo
776 776
 
777 777
     }
778 778
 
779
-    return apply_filters( 'wpinv_discounted_amount', $amount );
779
+    return apply_filters('wpinv_discounted_amount', $amount);
780 780
 }
781 781
 
782
-function wpinv_increase_discount_usage( $code ) {
782
+function wpinv_increase_discount_usage($code) {
783 783
 
784
-    $id   = wpinv_get_discount_id_by_code( $code );
785
-    $uses = wpinv_get_discount_uses( $id );
784
+    $id   = wpinv_get_discount_id_by_code($code);
785
+    $uses = wpinv_get_discount_uses($id);
786 786
 
787
-    if ( $uses ) {
787
+    if ($uses) {
788 788
         $uses++;
789 789
     } else {
790 790
         $uses = 1;
791 791
     }
792 792
 
793
-    update_post_meta( $id, '_wpi_discount_uses', $uses );
793
+    update_post_meta($id, '_wpi_discount_uses', $uses);
794 794
 
795
-    do_action( 'wpinv_discount_increase_use_count', $uses, $id, $code );
795
+    do_action('wpinv_discount_increase_use_count', $uses, $id, $code);
796 796
 
797 797
     return $uses;
798 798
 
799 799
 }
800 800
 
801
-function wpinv_decrease_discount_usage( $code ) {
801
+function wpinv_decrease_discount_usage($code) {
802 802
 
803
-    $id   = wpinv_get_discount_id_by_code( $code );
804
-    $uses = wpinv_get_discount_uses( $id );
803
+    $id   = wpinv_get_discount_id_by_code($code);
804
+    $uses = wpinv_get_discount_uses($id);
805 805
 
806
-    if ( $uses ) {
806
+    if ($uses) {
807 807
         $uses--;
808 808
     }
809 809
 
810
-    if ( $uses < 0 ) {
810
+    if ($uses < 0) {
811 811
         $uses = 0;
812 812
     }
813 813
 
814
-    update_post_meta( $id, '_wpi_discount_uses', $uses );
814
+    update_post_meta($id, '_wpi_discount_uses', $uses);
815 815
 
816
-    do_action( 'wpinv_discount_decrease_use_count', $uses, $id, $code );
816
+    do_action('wpinv_discount_decrease_use_count', $uses, $id, $code);
817 817
 
818 818
     return $uses;
819 819
 
820 820
 }
821 821
 
822
-function wpinv_format_discount_rate( $type, $amount ) {
823
-    if ( $type == 'flat' ) {
824
-        return wpinv_price( wpinv_format_amount( $amount ) );
822
+function wpinv_format_discount_rate($type, $amount) {
823
+    if ($type == 'flat') {
824
+        return wpinv_price(wpinv_format_amount($amount));
825 825
     } else {
826 826
         return $amount . '%';
827 827
     }
828 828
 }
829 829
 
830
-function wpinv_set_cart_discount( $code = '' ) {    
831
-    if ( wpinv_multiple_discounts_allowed() ) {
830
+function wpinv_set_cart_discount($code = '') {    
831
+    if (wpinv_multiple_discounts_allowed()) {
832 832
         // Get all active cart discounts
833 833
         $discounts = wpinv_get_cart_discounts();
834 834
     } else {
835 835
         $discounts = false; // Only one discount allowed per purchase, so override any existing
836 836
     }
837 837
 
838
-    if ( $discounts ) {
839
-        $key = array_search( strtolower( $code ), array_map( 'strtolower', $discounts ) );
840
-        if( false !== $key ) {
841
-            unset( $discounts[ $key ] ); // Can't set the same discount more than once
838
+    if ($discounts) {
839
+        $key = array_search(strtolower($code), array_map('strtolower', $discounts));
840
+        if (false !== $key) {
841
+            unset($discounts[$key]); // Can't set the same discount more than once
842 842
         }
843 843
         $discounts[] = $code;
844 844
     } else {
845 845
         $discounts = array();
846 846
         $discounts[] = $code;
847 847
     }
848
-    $discounts = array_values( $discounts );
848
+    $discounts = array_values($discounts);
849 849
     
850 850
     $data = wpinv_get_checkout_session();
851
-    if ( empty( $data ) ) {
851
+    if (empty($data)) {
852 852
         $data = array();
853 853
     } else {
854
-        if ( !empty( $data['invoice_id'] ) && $payment_meta = wpinv_get_invoice_meta( $data['invoice_id'] ) ) {
855
-            $payment_meta['user_info']['discount']  = implode( ',', $discounts );
856
-            update_post_meta( $data['invoice_id'], '_wpinv_payment_meta', $payment_meta );
854
+        if (!empty($data['invoice_id']) && $payment_meta = wpinv_get_invoice_meta($data['invoice_id'])) {
855
+            $payment_meta['user_info']['discount'] = implode(',', $discounts);
856
+            update_post_meta($data['invoice_id'], '_wpinv_payment_meta', $payment_meta);
857 857
         }
858 858
     }
859 859
     $data['cart_discounts'] = $discounts;
860 860
     
861
-    wpinv_set_checkout_session( $data );
861
+    wpinv_set_checkout_session($data);
862 862
     
863 863
     return $discounts;
864 864
 }
865 865
 
866
-function wpinv_unset_cart_discount( $code = '' ) {    
866
+function wpinv_unset_cart_discount($code = '') {    
867 867
     $discounts = wpinv_get_cart_discounts();
868 868
 
869
-    if ( $code && !empty( $discounts ) && in_array( $code, $discounts ) ) {
870
-        $key = array_search( $code, $discounts );
871
-        unset( $discounts[ $key ] );
869
+    if ($code && !empty($discounts) && in_array($code, $discounts)) {
870
+        $key = array_search($code, $discounts);
871
+        unset($discounts[$key]);
872 872
             
873 873
         $data = wpinv_get_checkout_session();
874 874
         $data['cart_discounts'] = $discounts;
875
-        if ( !empty( $data['invoice_id'] ) && $payment_meta = wpinv_get_invoice_meta( $data['invoice_id'] ) ) {
876
-            $payment_meta['user_info']['discount']  = !empty( $discounts ) ? implode( ',', $discounts ) : '';
877
-            update_post_meta( $data['invoice_id'], '_wpinv_payment_meta', $payment_meta );
875
+        if (!empty($data['invoice_id']) && $payment_meta = wpinv_get_invoice_meta($data['invoice_id'])) {
876
+            $payment_meta['user_info']['discount'] = !empty($discounts) ? implode(',', $discounts) : '';
877
+            update_post_meta($data['invoice_id'], '_wpinv_payment_meta', $payment_meta);
878 878
         }
879 879
         
880
-        wpinv_set_checkout_session( $data );
880
+        wpinv_set_checkout_session($data);
881 881
     }
882 882
 
883 883
     return $discounts;
@@ -886,27 +886,27 @@  discard block
 block discarded – undo
886 886
 function wpinv_unset_all_cart_discounts() {
887 887
     $data = wpinv_get_checkout_session();
888 888
     
889
-    if ( !empty( $data ) && isset( $data['cart_discounts'] ) ) {
890
-        unset( $data['cart_discounts'] );
889
+    if (!empty($data) && isset($data['cart_discounts'])) {
890
+        unset($data['cart_discounts']);
891 891
         
892
-         wpinv_set_checkout_session( $data );
892
+         wpinv_set_checkout_session($data);
893 893
          return true;
894 894
     }
895 895
     
896 896
     return false;
897 897
 }
898 898
 
899
-function wpinv_get_cart_discounts( $items = array() ) {
899
+function wpinv_get_cart_discounts($items = array()) {
900 900
     $session = wpinv_get_checkout_session();
901 901
     
902
-    $discounts = !empty( $session['cart_discounts'] ) ? $session['cart_discounts'] : false;
902
+    $discounts = !empty($session['cart_discounts']) ? $session['cart_discounts'] : false;
903 903
     return $discounts;
904 904
 }
905 905
 
906
-function wpinv_cart_has_discounts( $items = array() ) {
906
+function wpinv_cart_has_discounts($items = array()) {
907 907
     $ret = false;
908 908
 
909
-    if ( wpinv_get_cart_discounts( $items ) ) {
909
+    if (wpinv_get_cart_discounts($items)) {
910 910
         $ret = true;
911 911
     }
912 912
     
@@ -917,131 +917,131 @@  discard block
 block discarded – undo
917 917
     }
918 918
     */
919 919
 
920
-    return apply_filters( 'wpinv_cart_has_discounts', $ret );
920
+    return apply_filters('wpinv_cart_has_discounts', $ret);
921 921
 }
922 922
 
923
-function wpinv_get_cart_discounted_amount( $items = array(), $discounts = false ) {
923
+function wpinv_get_cart_discounted_amount($items = array(), $discounts = false) {
924 924
     $amount = 0.00;
925
-    $items  = !empty( $items ) ? $items : wpinv_get_cart_content_details();
925
+    $items  = !empty($items) ? $items : wpinv_get_cart_content_details();
926 926
 
927
-    if ( $items ) {
928
-        $discounts = wp_list_pluck( $items, 'discount' );
927
+    if ($items) {
928
+        $discounts = wp_list_pluck($items, 'discount');
929 929
 
930
-        if ( is_array( $discounts ) ) {
931
-            $discounts = array_map( 'floatval', $discounts );
932
-            $amount    = array_sum( $discounts );
930
+        if (is_array($discounts)) {
931
+            $discounts = array_map('floatval', $discounts);
932
+            $amount    = array_sum($discounts);
933 933
         }
934 934
     }
935 935
 
936
-    return apply_filters( 'wpinv_get_cart_discounted_amount', $amount );
936
+    return apply_filters('wpinv_get_cart_discounted_amount', $amount);
937 937
 }
938 938
 
939
-function wpinv_get_cart_items_discount_amount( $items = array(), $discount = false ) {
940
-    $items  = !empty( $items ) ? $items : wpinv_get_cart_content_details();
939
+function wpinv_get_cart_items_discount_amount($items = array(), $discount = false) {
940
+    $items = !empty($items) ? $items : wpinv_get_cart_content_details();
941 941
     
942
-    if ( empty( $discount ) || empty( $items ) ) {
942
+    if (empty($discount) || empty($items)) {
943 943
         return 0;
944 944
     }
945 945
 
946 946
     $amount = 0;
947 947
     
948
-    foreach ( $items as $item ) {
949
-        $amount += wpinv_get_cart_item_discount_amount( $item, $discount );
948
+    foreach ($items as $item) {
949
+        $amount += wpinv_get_cart_item_discount_amount($item, $discount);
950 950
     }
951 951
     
952
-    $amount = wpinv_round_amount( $amount );
952
+    $amount = wpinv_round_amount($amount);
953 953
 
954 954
     return $amount;
955 955
 }
956 956
 
957
-function wpinv_get_cart_item_discount_amount( $item = array(), $discount = false ) {
957
+function wpinv_get_cart_item_discount_amount($item = array(), $discount = false) {
958 958
     global $wpinv_is_last_cart_item, $wpinv_flat_discount_total;
959 959
     
960 960
     $amount = 0;
961 961
 
962
-    if ( empty( $item ) || empty( $item['id'] ) ) {
962
+    if (empty($item) || empty($item['id'])) {
963 963
         return $amount;
964 964
     }
965 965
 
966
-    if ( empty( $item['quantity'] ) ) {
966
+    if (empty($item['quantity'])) {
967 967
         return $amount;
968 968
     }
969 969
 
970
-    if ( empty( $item['options'] ) ) {
970
+    if (empty($item['options'])) {
971 971
         $item['options'] = array();
972 972
     }
973 973
 
974
-    $price            = wpinv_get_cart_item_price( $item['id'], $item, $item['options'] );
974
+    $price            = wpinv_get_cart_item_price($item['id'], $item, $item['options']);
975 975
     $discounted_price = $price;
976 976
 
977 977
     $discounts = false === $discount ? wpinv_get_cart_discounts() : $discount;
978
-    if ( empty( $discounts ) ) {
978
+    if (empty($discounts)) {
979 979
         return $amount;
980 980
     }
981 981
 
982
-    if ( $discounts ) {
983
-        if ( is_array( $discounts ) ) {
984
-            $discounts = array_values( $discounts );
982
+    if ($discounts) {
983
+        if (is_array($discounts)) {
984
+            $discounts = array_values($discounts);
985 985
         } else {
986
-            $discounts = explode( ',', $discounts );
986
+            $discounts = explode(',', $discounts);
987 987
         }
988 988
     }
989 989
 
990
-    if( $discounts ) {
991
-        foreach ( $discounts as $discount ) {
992
-            $code_id = wpinv_get_discount_id_by_code( $discount );
990
+    if ($discounts) {
991
+        foreach ($discounts as $discount) {
992
+            $code_id = wpinv_get_discount_id_by_code($discount);
993 993
 
994 994
             // Check discount exists
995
-            if( ! $code_id ) {
995
+            if (!$code_id) {
996 996
                 continue;
997 997
             }
998 998
 
999
-            $reqs           = wpinv_get_discount_item_reqs( $code_id );
1000
-            $excluded_items = wpinv_get_discount_excluded_items( $code_id );
999
+            $reqs           = wpinv_get_discount_item_reqs($code_id);
1000
+            $excluded_items = wpinv_get_discount_excluded_items($code_id);
1001 1001
 
1002 1002
             // Make sure requirements are set and that this discount shouldn't apply to the whole cart
1003
-            if ( !empty( $reqs ) && wpinv_is_discount_not_global( $code_id ) ) {
1004
-                foreach ( $reqs as $item_id ) {
1005
-                    if ( $item_id == $item['id'] && ! in_array( $item['id'], $excluded_items ) ) {
1006
-                        $discounted_price -= $price - wpinv_get_discounted_amount( $discount, $price );
1003
+            if (!empty($reqs) && wpinv_is_discount_not_global($code_id)) {
1004
+                foreach ($reqs as $item_id) {
1005
+                    if ($item_id == $item['id'] && !in_array($item['id'], $excluded_items)) {
1006
+                        $discounted_price -= $price - wpinv_get_discounted_amount($discount, $price);
1007 1007
                     }
1008 1008
                 }
1009 1009
             } else {
1010 1010
                 // This is a global cart discount
1011
-                if ( !in_array( $item['id'], $excluded_items ) ) {
1012
-                    if ( 'flat' === wpinv_get_discount_type( $code_id ) ) {
1011
+                if (!in_array($item['id'], $excluded_items)) {
1012
+                    if ('flat' === wpinv_get_discount_type($code_id)) {
1013 1013
                         $items_subtotal    = 0.00;
1014 1014
                         $cart_items        = wpinv_get_cart_contents();
1015 1015
                         
1016
-                        foreach ( $cart_items as $cart_item ) {
1017
-                            if ( ! in_array( $cart_item['id'], $excluded_items ) ) {
1018
-                                $options = !empty( $cart_item['options'] ) ? $cart_item['options'] : array();
1019
-                                $item_price      = wpinv_get_cart_item_price( $cart_item['id'], $cart_item, $options );
1016
+                        foreach ($cart_items as $cart_item) {
1017
+                            if (!in_array($cart_item['id'], $excluded_items)) {
1018
+                                $options = !empty($cart_item['options']) ? $cart_item['options'] : array();
1019
+                                $item_price      = wpinv_get_cart_item_price($cart_item['id'], $cart_item, $options);
1020 1020
                                 $items_subtotal += $item_price * $cart_item['quantity'];
1021 1021
                             }
1022 1022
                         }
1023 1023
 
1024
-                        $subtotal_percent  = ( ( $price * $item['quantity'] ) / $items_subtotal );
1025
-                        $code_amount       = wpinv_get_discount_amount( $code_id );
1024
+                        $subtotal_percent  = (($price * $item['quantity']) / $items_subtotal);
1025
+                        $code_amount       = wpinv_get_discount_amount($code_id);
1026 1026
                         $discounted_amount = $code_amount * $subtotal_percent;
1027 1027
                         $discounted_price -= $discounted_amount;
1028 1028
 
1029
-                        $wpinv_flat_discount_total += round( $discounted_amount, wpinv_currency_decimal_filter() );
1029
+                        $wpinv_flat_discount_total += round($discounted_amount, wpinv_currency_decimal_filter());
1030 1030
 
1031
-                        if ( $wpinv_is_last_cart_item && $wpinv_flat_discount_total < $code_amount ) {
1031
+                        if ($wpinv_is_last_cart_item && $wpinv_flat_discount_total < $code_amount) {
1032 1032
                             $adjustment = $code_amount - $wpinv_flat_discount_total;
1033 1033
                             $discounted_price -= $adjustment;
1034 1034
                         }
1035 1035
                     } else {
1036
-                        $discounted_price -= $price - wpinv_get_discounted_amount( $discount, $price );
1036
+                        $discounted_price -= $price - wpinv_get_discounted_amount($discount, $price);
1037 1037
                     }
1038 1038
                 }
1039 1039
             }
1040 1040
         }
1041 1041
 
1042
-        $amount = ( $price - apply_filters( 'wpinv_get_cart_item_discounted_amount', $discounted_price, $discounts, $item, $price ) );
1042
+        $amount = ($price - apply_filters('wpinv_get_cart_item_discounted_amount', $discounted_price, $discounts, $item, $price));
1043 1043
 
1044
-        if ( 'flat' !== wpinv_get_discount_type( $code_id ) ) {
1044
+        if ('flat' !== wpinv_get_discount_type($code_id)) {
1045 1045
             $amount = $amount * $item['quantity'];
1046 1046
         }
1047 1047
     }
@@ -1049,59 +1049,59 @@  discard block
 block discarded – undo
1049 1049
     return $amount;
1050 1050
 }
1051 1051
 
1052
-function wpinv_cart_discounts_html( $items = array() ) {
1053
-    echo wpinv_get_cart_discounts_html( $items );
1052
+function wpinv_cart_discounts_html($items = array()) {
1053
+    echo wpinv_get_cart_discounts_html($items);
1054 1054
 }
1055 1055
 
1056
-function wpinv_get_cart_discounts_html( $items = array(), $discounts = false ) {
1056
+function wpinv_get_cart_discounts_html($items = array(), $discounts = false) {
1057 1057
     global $wpi_cart_columns;
1058 1058
     
1059
-    $items  = !empty( $items ) ? $items : wpinv_get_cart_content_details();
1059
+    $items = !empty($items) ? $items : wpinv_get_cart_content_details();
1060 1060
     
1061
-    if ( !$discounts ) {
1062
-        $discounts = wpinv_get_cart_discounts( $items );
1061
+    if (!$discounts) {
1062
+        $discounts = wpinv_get_cart_discounts($items);
1063 1063
     }
1064 1064
 
1065
-    if ( !$discounts ) {
1065
+    if (!$discounts) {
1066 1066
         return;
1067 1067
     }
1068 1068
     
1069
-    $discounts = is_array( $discounts ) ? $discounts : array( $discounts );
1069
+    $discounts = is_array($discounts) ? $discounts : array($discounts);
1070 1070
     
1071 1071
     $html = '';
1072 1072
 
1073
-    foreach ( $discounts as $discount ) {
1074
-        $discount_id    = wpinv_get_discount_id_by_code( $discount );
1075
-        $discount_value = wpinv_get_discount_amount( $discount_id );
1076
-        $rate           = wpinv_format_discount_rate( wpinv_get_discount_type( $discount_id ), $discount_value );
1077
-        $amount         = wpinv_get_cart_items_discount_amount( $items, $discount );
1078
-        $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> ';
1073
+    foreach ($discounts as $discount) {
1074
+        $discount_id    = wpinv_get_discount_id_by_code($discount);
1075
+        $discount_value = wpinv_get_discount_amount($discount_id);
1076
+        $rate           = wpinv_format_discount_rate(wpinv_get_discount_type($discount_id), $discount_value);
1077
+        $amount         = wpinv_get_cart_items_discount_amount($items, $discount);
1078
+        $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> ';
1079 1079
         
1080 1080
         $html .= '<tr class="wpinv_cart_footer_row wpinv_cart_discount_row">';
1081 1081
         ob_start();
1082
-        do_action( 'wpinv_checkout_table_discount_first', $items );
1082
+        do_action('wpinv_checkout_table_discount_first', $items);
1083 1083
         $html .= ob_get_clean();
1084
-        $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>';
1084
+        $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>';
1085 1085
         ob_start();
1086
-        do_action( 'wpinv_checkout_table_discount_last', $items );
1086
+        do_action('wpinv_checkout_table_discount_last', $items);
1087 1087
         $html .= ob_get_clean();
1088 1088
         $html .= '</tr>';
1089 1089
     }
1090 1090
 
1091
-    return apply_filters( 'wpinv_get_cart_discounts_html', $html, $discounts, $rate );
1091
+    return apply_filters('wpinv_get_cart_discounts_html', $html, $discounts, $rate);
1092 1092
 }
1093 1093
 
1094
-function wpinv_display_cart_discount( $formatted = false, $echo = false ) {
1094
+function wpinv_display_cart_discount($formatted = false, $echo = false) {
1095 1095
     $discounts = wpinv_get_cart_discounts();
1096 1096
 
1097
-    if ( empty( $discounts ) ) {
1097
+    if (empty($discounts)) {
1098 1098
         return false;
1099 1099
     }
1100 1100
 
1101
-    $discount_id  = wpinv_get_discount_id_by_code( $discounts[0] );
1102
-    $amount       = wpinv_format_discount_rate( wpinv_get_discount_type( $discount_id ), wpinv_get_discount_amount( $discount_id ) );
1101
+    $discount_id  = wpinv_get_discount_id_by_code($discounts[0]);
1102
+    $amount       = wpinv_format_discount_rate(wpinv_get_discount_type($discount_id), wpinv_get_discount_amount($discount_id));
1103 1103
 
1104
-    if ( $echo ) {
1104
+    if ($echo) {
1105 1105
         echo $amount;
1106 1106
     }
1107 1107
 
@@ -1109,135 +1109,135 @@  discard block
 block discarded – undo
1109 1109
 }
1110 1110
 
1111 1111
 function wpinv_remove_cart_discount() {
1112
-    if ( !isset( $_GET['discount_id'] ) || ! isset( $_GET['discount_code'] ) ) {
1112
+    if (!isset($_GET['discount_id']) || !isset($_GET['discount_code'])) {
1113 1113
         return;
1114 1114
     }
1115 1115
 
1116
-    do_action( 'wpinv_pre_remove_cart_discount', absint( $_GET['discount_id'] ) );
1116
+    do_action('wpinv_pre_remove_cart_discount', absint($_GET['discount_id']));
1117 1117
 
1118
-    wpinv_unset_cart_discount( urldecode( $_GET['discount_code'] ) );
1118
+    wpinv_unset_cart_discount(urldecode($_GET['discount_code']));
1119 1119
 
1120
-    do_action( 'wpinv_post_remove_cart_discount', absint( $_GET['discount_id'] ) );
1120
+    do_action('wpinv_post_remove_cart_discount', absint($_GET['discount_id']));
1121 1121
 
1122
-    wp_redirect( wpinv_get_checkout_uri() ); wpinv_die();
1122
+    wp_redirect(wpinv_get_checkout_uri()); wpinv_die();
1123 1123
 }
1124
-add_action( 'wpinv_remove_cart_discount', 'wpinv_remove_cart_discount' );
1124
+add_action('wpinv_remove_cart_discount', 'wpinv_remove_cart_discount');
1125 1125
 
1126
-function wpinv_maybe_remove_cart_discount( $cart_key = 0 ) {
1126
+function wpinv_maybe_remove_cart_discount($cart_key = 0) {
1127 1127
     $discounts = wpinv_get_cart_discounts();
1128 1128
 
1129
-    if ( !$discounts ) {
1129
+    if (!$discounts) {
1130 1130
         return;
1131 1131
     }
1132 1132
 
1133
-    foreach ( $discounts as $discount ) {
1134
-        if ( !wpinv_is_discount_valid( $discount ) ) {
1135
-            wpinv_unset_cart_discount( $discount );
1133
+    foreach ($discounts as $discount) {
1134
+        if (!wpinv_is_discount_valid($discount)) {
1135
+            wpinv_unset_cart_discount($discount);
1136 1136
         }
1137 1137
     }
1138 1138
 }
1139
-add_action( 'wpinv_post_remove_from_cart', 'wpinv_maybe_remove_cart_discount' );
1139
+add_action('wpinv_post_remove_from_cart', 'wpinv_maybe_remove_cart_discount');
1140 1140
 
1141 1141
 function wpinv_multiple_discounts_allowed() {
1142
-    $ret = wpinv_get_option( 'allow_multiple_discounts', false );
1143
-    return (bool) apply_filters( 'wpinv_multiple_discounts_allowed', $ret );
1142
+    $ret = wpinv_get_option('allow_multiple_discounts', false);
1143
+    return (bool)apply_filters('wpinv_multiple_discounts_allowed', $ret);
1144 1144
 }
1145 1145
 
1146 1146
 function wpinv_listen_for_cart_discount() {
1147 1147
     global $wpi_session;
1148 1148
     
1149
-    if ( empty( $_REQUEST['discount'] ) || is_array( $_REQUEST['discount'] ) ) {
1149
+    if (empty($_REQUEST['discount']) || is_array($_REQUEST['discount'])) {
1150 1150
         return;
1151 1151
     }
1152 1152
 
1153
-    $code = preg_replace('/[^a-zA-Z0-9-_]+/', '', $_REQUEST['discount'] );
1153
+    $code = preg_replace('/[^a-zA-Z0-9-_]+/', '', $_REQUEST['discount']);
1154 1154
 
1155
-    $wpi_session->set( 'preset_discount', $code );
1155
+    $wpi_session->set('preset_discount', $code);
1156 1156
 }
1157 1157
 //add_action( 'init', 'wpinv_listen_for_cart_discount', 0 );
1158 1158
 
1159 1159
 function wpinv_apply_preset_discount() {
1160 1160
     global $wpi_session;
1161 1161
     
1162
-    $code = $wpi_session->get( 'preset_discount' );
1162
+    $code = $wpi_session->get('preset_discount');
1163 1163
 
1164
-    if ( !$code ) {
1164
+    if (!$code) {
1165 1165
         return;
1166 1166
     }
1167 1167
 
1168
-    if ( !wpinv_is_discount_valid( $code, '', false ) ) {
1168
+    if (!wpinv_is_discount_valid($code, '', false)) {
1169 1169
         return;
1170 1170
     }
1171 1171
     
1172
-    $code = apply_filters( 'wpinv_apply_preset_discount', $code );
1172
+    $code = apply_filters('wpinv_apply_preset_discount', $code);
1173 1173
 
1174
-    wpinv_set_cart_discount( $code );
1174
+    wpinv_set_cart_discount($code);
1175 1175
 
1176
-    $wpi_session->set( 'preset_discount', null );
1176
+    $wpi_session->set('preset_discount', null);
1177 1177
 }
1178 1178
 //add_action( 'init', 'wpinv_apply_preset_discount', 999 );
1179 1179
 
1180
-function wpinv_get_discount_label( $code, $echo = true ) {
1181
-    $label = wp_sprintf( __( 'Discount%1$s', 'invoicing' ), ( $code != '' && $code != 'none' ? ' (<code>' . $code . '</code>)': '' ) );
1182
-    $label = apply_filters( 'wpinv_get_discount_label', $label, $code );
1180
+function wpinv_get_discount_label($code, $echo = true) {
1181
+    $label = wp_sprintf(__('Discount%1$s', 'invoicing'), ($code != '' && $code != 'none' ? ' (<code>' . $code . '</code>)' : ''));
1182
+    $label = apply_filters('wpinv_get_discount_label', $label, $code);
1183 1183
 
1184
-    if ( $echo ) {
1184
+    if ($echo) {
1185 1185
         echo $label;
1186 1186
     } else {
1187 1187
         return $label;
1188 1188
     }
1189 1189
 }
1190 1190
 
1191
-function wpinv_cart_discount_label( $code, $rate, $echo = true ) {
1192
-    $label = wp_sprintf( __( '%1$s Discount: %2$s', 'invoicing' ), $rate, $code );
1193
-    $label = apply_filters( 'wpinv_cart_discount_label', $label, $code, $rate );
1191
+function wpinv_cart_discount_label($code, $rate, $echo = true) {
1192
+    $label = wp_sprintf(__('%1$s Discount: %2$s', 'invoicing'), $rate, $code);
1193
+    $label = apply_filters('wpinv_cart_discount_label', $label, $code, $rate);
1194 1194
 
1195
-    if ( $echo ) {
1195
+    if ($echo) {
1196 1196
         echo $label;
1197 1197
     } else {
1198 1198
         return $label;
1199 1199
     }
1200 1200
 }
1201 1201
 
1202
-function wpinv_check_delete_discount( $check, $post, $force_delete ) {
1203
-    if ( $post->post_type == 'wpi_discount' && wpinv_get_discount_uses( $post->ID ) > 0 ) {
1202
+function wpinv_check_delete_discount($check, $post, $force_delete) {
1203
+    if ($post->post_type == 'wpi_discount' && wpinv_get_discount_uses($post->ID) > 0) {
1204 1204
         return true;
1205 1205
     }
1206 1206
     
1207 1207
     return $check;
1208 1208
 }
1209
-add_filter( 'pre_delete_post', 'wpinv_check_delete_discount', 10, 3 );
1209
+add_filter('pre_delete_post', 'wpinv_check_delete_discount', 10, 3);
1210 1210
 
1211 1211
 function wpinv_checkout_form_validate_discounts() {
1212 1212
     global $wpi_checkout_id;
1213 1213
     
1214 1214
     $discounts = wpinv_get_cart_discounts();
1215 1215
     
1216
-    if ( !empty( $discounts ) ) {
1216
+    if (!empty($discounts)) {
1217 1217
         $invalid = false;
1218 1218
         
1219
-        foreach ( $discounts as $key => $code ) {
1220
-            if ( !wpinv_is_discount_valid( $code, (int)wpinv_get_user_id( $wpi_checkout_id ) ) ) {
1219
+        foreach ($discounts as $key => $code) {
1220
+            if (!wpinv_is_discount_valid($code, (int)wpinv_get_user_id($wpi_checkout_id))) {
1221 1221
                 $invalid = true;
1222 1222
                 
1223
-                wpinv_unset_cart_discount( $code );
1223
+                wpinv_unset_cart_discount($code);
1224 1224
             }
1225 1225
         }
1226 1226
         
1227
-        if ( $invalid ) {
1227
+        if ($invalid) {
1228 1228
             $errors = wpinv_get_errors();
1229
-            $error  = !empty( $errors['wpinv-discount-error'] ) ? $errors['wpinv-discount-error'] . ' ' : '';
1230
-            $error  .= __( 'The discount has been removed from cart.', 'invoicing' );
1231
-            wpinv_set_error( 'wpinv-discount-error', $error );
1229
+            $error  = !empty($errors['wpinv-discount-error']) ? $errors['wpinv-discount-error'] . ' ' : '';
1230
+            $error .= __('The discount has been removed from cart.', 'invoicing');
1231
+            wpinv_set_error('wpinv-discount-error', $error);
1232 1232
             
1233
-            wpinv_recalculate_tax( true );
1233
+            wpinv_recalculate_tax(true);
1234 1234
         }
1235 1235
     }
1236 1236
 }
1237
-add_action( 'wpinv_before_checkout_form', 'wpinv_checkout_form_validate_discounts', -10 );
1237
+add_action('wpinv_before_checkout_form', 'wpinv_checkout_form_validate_discounts', -10);
1238 1238
 
1239 1239
 function wpinv_discount_amount() {
1240 1240
     $output = 0.00;
1241 1241
     
1242
-    return apply_filters( 'wpinv_discount_amount', $output );
1242
+    return apply_filters('wpinv_discount_amount', $output);
1243 1243
 }
1244 1244
\ No newline at end of file
Please login to merge, or discard this patch.
includes/admin/meta-boxes/class-mb-invoice-details.php 1 patch
Spacing   +87 added lines, -87 removed lines patch added patch discarded remove patch
@@ -1,30 +1,30 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // MUST have WordPress.
3
-if ( !defined( 'WPINC' ) ) {
4
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
3
+if (!defined('WPINC')) {
4
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
5 5
 }
6 6
 
7 7
 class WPInv_Meta_Box_Details {
8
-    public static function output( $post ) {
8
+    public static function output($post) {
9 9
         $currency_symbol    = wpinv_currency_symbol();
10 10
         $statuses           = wpinv_get_invoice_statuses();
11 11
         
12
-        $post_id            = !empty( $post->ID ) ? $post->ID : 0;
13
-        $invoice            = new WPInv_Invoice( $post_id );
12
+        $post_id            = !empty($post->ID) ? $post->ID : 0;
13
+        $invoice            = new WPInv_Invoice($post_id);
14 14
         
15
-        $status             = $invoice->get_status( false ); // Current status    
15
+        $status             = $invoice->get_status(false); // Current status    
16 16
         $discount           = $invoice->get_discount();
17 17
         $discount_code      = $discount > 0 ? $invoice->get_discount_code() : '';
18 18
         $invoice_number     = $invoice->get_number();
19 19
         
20 20
         $date_created       = $invoice->get_created_date();
21
-        $datetime_created   = strtotime( $date_created );
22
-        $date_created       = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), $datetime_created ) : '';
21
+        $datetime_created   = strtotime($date_created);
22
+        $date_created       = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n(get_option('date_format') . ' ' . get_option('time_format'), $datetime_created) : '';
23 23
         $date_completed     = $invoice->get_completed_date();
24
-        $date_completed     = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), strtotime( $date_completed ) ) : 'n/a';
25
-        $title['status'] = __( 'Invoice Status:', 'invoicing' );
26
-        $title['number'] = __( 'Invoice Number:', 'invoicing' );
27
-        $mail_notice = esc_attr__( 'After saving invoice, this will send a copy of the invoice to the user&#8217;s email address.', 'invoicing' );
24
+        $date_completed     = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? date_i18n(get_option('date_format') . ' ' . get_option('time_format'), strtotime($date_completed)) : 'n/a';
25
+        $title['status'] = __('Invoice Status:', 'invoicing');
26
+        $title['number'] = __('Invoice Number:', 'invoicing');
27
+        $mail_notice = esc_attr__('After saving invoice, this will send a copy of the invoice to the user&#8217;s email address.', 'invoicing');
28 28
         
29 29
         $title = apply_filters('wpinv_details_metabox_titles', $title, $invoice);
30 30
         $statuses = apply_filters('wpinv_invoice_statuses', $statuses, $invoice);
@@ -34,29 +34,29 @@  discard block
 block discarded – undo
34 34
 <div class="gdmbx2-wrap form-table">
35 35
     <div class="gdmbx2-metabox gdmbx-field-list" id="gdmbx2-metabox-wpinv_details">
36 36
         <div class="gdmbx-row gdmbx-type-select gdmbx2-id-wpinv-date-created">
37
-            <div class="gdmbx-th"><label><?php _e( 'Date Created:', 'invoicing' );?></label></div>
38
-            <div class="gdmbx-td"><?php echo $date_created;?></div>
37
+            <div class="gdmbx-th"><label><?php _e('Date Created:', 'invoicing'); ?></label></div>
38
+            <div class="gdmbx-td"><?php echo $date_created; ?></div>
39 39
         </div>
40
-        <?php if ( wpinv_get_option( 'overdue_active' ) && ( $invoice->needs_payment() || $invoice->has_status( array( 'auto-draft' ) ) ) ) { ?>
40
+        <?php if (wpinv_get_option('overdue_active') && ($invoice->needs_payment() || $invoice->has_status(array('auto-draft')))) { ?>
41 41
         <div class="gdmbx-row gdmbx-type-select gdmbx2-id-wpinv-date-overdue">
42
-            <div class="gdmbx-th"><label for="wpinv_due_date"><?php _e( 'Due Date:', 'invoicing' );?></label></div>
42
+            <div class="gdmbx-th"><label for="wpinv_due_date"><?php _e('Due Date:', 'invoicing'); ?></label></div>
43 43
             <div class="gdmbx-td">
44
-                <input type="text" placeholder="<?php esc_attr_e( 'Y-m-d', 'invoicing' );?>" value="<?php echo esc_attr( $invoice->get_due_date() );?>" id="wpinv_due_date" name="wpinv_due_date" class="regular-text wpiDatepicker" data-minDate="<?php echo esc_attr( date_i18n( 'Y-m-d', $datetime_created ) );?>" data-dateFormat="yy-mm-dd">
44
+                <input type="text" placeholder="<?php esc_attr_e('Y-m-d', 'invoicing'); ?>" value="<?php echo esc_attr($invoice->get_due_date()); ?>" id="wpinv_due_date" name="wpinv_due_date" class="regular-text wpiDatepicker" data-minDate="<?php echo esc_attr(date_i18n('Y-m-d', $datetime_created)); ?>" data-dateFormat="yy-mm-dd">
45 45
             </div>
46 46
         </div>
47 47
         <?php } ?>
48
-        <?php if ( $date_completed && $date_completed != 'n/a' ) { ?>
48
+        <?php if ($date_completed && $date_completed != 'n/a') { ?>
49 49
         <div class="gdmbx-row gdmbx-type-select gdmbx2-id-wpinv-date-completed">
50
-            <div class="gdmbx-th"><label><?php _e( 'Payment Date:', 'invoicing' );?></label></div>
51
-            <div class="gdmbx-td"><?php echo $date_completed;?></div>
50
+            <div class="gdmbx-th"><label><?php _e('Payment Date:', 'invoicing'); ?></label></div>
51
+            <div class="gdmbx-td"><?php echo $date_completed; ?></div>
52 52
         </div>
53 53
         <?php } ?>
54 54
         <div class="gdmbx-row gdmbx-type-select gdmbx2-id-wpinv-status">
55 55
             <div class="gdmbx-th"><label for="wpinv_status"><?php echo $title['status']; ?></label></div>
56 56
             <div class="gdmbx-td">
57 57
                 <select required="required" id="wpinv_status" name="wpinv_status" class="gdmbx2_select">
58
-                    <?php foreach ( $statuses as $value => $label ) { ?>
59
-                    <option value="<?php echo $value;?>" <?php selected( $status, $value );?>><?php echo $label;?></option>
58
+                    <?php foreach ($statuses as $value => $label) { ?>
59
+                    <option value="<?php echo $value; ?>" <?php selected($status, $value); ?>><?php echo $label; ?></option>
60 60
                     <?php } ?>
61 61
                 </select>
62 62
             </div>
@@ -64,107 +64,107 @@  discard block
 block discarded – undo
64 64
         <div class="gdmbx-row gdmbx-type-text gdmbx2-id-wpinv-number table-layout">
65 65
             <div class="gdmbx-th"><label for="wpinv_number"><?php echo $title['number']; ?></label></div>
66 66
             <div class="gdmbx-td">
67
-                <input type="text" value="<?php echo esc_attr( $invoice_number );?>" id="wpinv_number" name="wpinv_number" class="regular-text" readonly>
67
+                <input type="text" value="<?php echo esc_attr($invoice_number); ?>" id="wpinv_number" name="wpinv_number" class="regular-text" readonly>
68 68
             </div>
69 69
         </div>
70
-        <?php do_action( 'wpinv_meta_box_details_inner', $post_id ); ?>
71
-        <?php if ( !( $is_paid = ( $invoice->is_paid() || $invoice->is_refunded() ) ) || $discount_code ) { ?>
70
+        <?php do_action('wpinv_meta_box_details_inner', $post_id); ?>
71
+        <?php if (!($is_paid = ($invoice->is_paid() || $invoice->is_refunded())) || $discount_code) { ?>
72 72
         <div class="gdmbx-row gdmbx-type-text gdmbx2-id-wpinv-discount-code table-layout">
73
-            <div class="gdmbx-th"><label for="wpinv_discount_code"><?php _e( 'Discount Code:', 'invoicing' );?></label></div>
73
+            <div class="gdmbx-th"><label for="wpinv_discount_code"><?php _e('Discount Code:', 'invoicing'); ?></label></div>
74 74
             <div class="gdmbx-td">
75
-                <input type="text" value="<?php echo esc_attr( $discount_code ); ?>" id="wpinv_discount" class="medium-text" <?php echo ( $discount_code ? 'readonly' : '' ); ?> /><?php if ( !$is_paid ) { ?><input value="<?php echo esc_attr_e( 'Apply', 'invoicing' ); ?>" class="button button-small button-primary <?php echo ( $discount_code ? 'wpi-hide' : 'wpi-inlineb' ); ?>" id="wpinv-apply-code" type="button" /><input value="<?php echo esc_attr_e( 'Remove', 'invoicing' ); ?>" class="button button-small button-primary <?php echo ( $discount_code ? 'wpi-inlineb' : 'wpi-hide' ); ?>" id="wpinv-remove-code" type="button" /><?php } ?>
75
+                <input type="text" value="<?php echo esc_attr($discount_code); ?>" id="wpinv_discount" class="medium-text" <?php echo ($discount_code ? 'readonly' : ''); ?> /><?php if (!$is_paid) { ?><input value="<?php echo esc_attr_e('Apply', 'invoicing'); ?>" class="button button-small button-primary <?php echo ($discount_code ? 'wpi-hide' : 'wpi-inlineb'); ?>" id="wpinv-apply-code" type="button" /><input value="<?php echo esc_attr_e('Remove', 'invoicing'); ?>" class="button button-small button-primary <?php echo ($discount_code ? 'wpi-inlineb' : 'wpi-hide'); ?>" id="wpinv-remove-code" type="button" /><?php } ?>
76 76
             </div>
77 77
         </div>
78 78
         <?php } ?>
79 79
     </div>
80 80
 </div>
81 81
 <div class="gdmbx-row gdmbx-type-text gdmbx-wpinv-save-send table-layout">
82
-    <p class="wpi-meta-row wpi-save-send"><label for="wpi_save_send"><?php echo sprintf(__( 'Send %s:', 'invoicing' ),$post_obj->labels->singular_name) ; ?></label>
82
+    <p class="wpi-meta-row wpi-save-send"><label for="wpi_save_send"><?php echo sprintf(__('Send %s:', 'invoicing'), $post_obj->labels->singular_name); ?></label>
83 83
         <select id="wpi_save_send" name="wpi_save_send">
84
-            <option value="1"><?php _e( 'Yes', 'invoicing' ); ?></option>
85
-            <option value="" selected="selected"><?php _e( 'No', 'invoicing' ); ?></option>
84
+            <option value="1"><?php _e('Yes', 'invoicing'); ?></option>
85
+            <option value="" selected="selected"><?php _e('No', 'invoicing'); ?></option>
86 86
         </select>
87 87
     </p>
88 88
     <p class="wpi-meta-row wpi-send-info"><?php echo $mail_notice; ?></p>
89 89
 </div>
90
-<?php wp_nonce_field( 'wpinv_details', 'wpinv_details_nonce' ) ;?>
90
+<?php wp_nonce_field('wpinv_details', 'wpinv_details_nonce'); ?>
91 91
         <?php
92 92
     }
93 93
     
94
-    public static function resend_invoice( $post ) {
94
+    public static function resend_invoice($post) {
95 95
         global $wpi_mb_invoice;
96 96
         
97
-        if ( empty( $wpi_mb_invoice ) ) {
97
+        if (empty($wpi_mb_invoice)) {
98 98
             return;
99 99
         }
100 100
         
101 101
         $text = array(
102
-            'message'       => esc_attr__( 'This will send a copy of the invoice to the customer&#8217;s email address.', 'invoicing' ),
103
-            'button_text'   =>  __( 'Resend Invoice', 'invoicing' ),
102
+            'message'       => esc_attr__('This will send a copy of the invoice to the customer&#8217;s email address.', 'invoicing'),
103
+            'button_text'   =>  __('Resend Invoice', 'invoicing'),
104 104
         );
105 105
             
106 106
         $text = apply_filters('wpinv_resend_invoice_metabox_text', $text);
107
-        do_action( 'wpinv_metabox_resend_invoice_before', $wpi_mb_invoice );
107
+        do_action('wpinv_metabox_resend_invoice_before', $wpi_mb_invoice);
108 108
         
109
-        if ( $email = $wpi_mb_invoice->get_email() ) {
109
+        if ($email = $wpi_mb_invoice->get_email()) {
110 110
             $email_actions = array();
111
-            $email_actions['email_url']      = add_query_arg( array( 'wpi_action' => 'send_invoice', 'invoice_id' => $post->ID ) );
112
-            $email_actions['reminder_url']   = add_query_arg( array( 'wpi_action' => 'send_reminder', 'invoice_id' => $post->ID ) );
111
+            $email_actions['email_url']      = add_query_arg(array('wpi_action' => 'send_invoice', 'invoice_id' => $post->ID));
112
+            $email_actions['reminder_url']   = add_query_arg(array('wpi_action' => 'send_reminder', 'invoice_id' => $post->ID));
113 113
             
114
-            $email_actions = apply_filters('wpinv_resend_invoice_email_actions', $email_actions );
114
+            $email_actions = apply_filters('wpinv_resend_invoice_email_actions', $email_actions);
115 115
         ?>
116 116
         <p class="wpi-meta-row wpi-resend-info"><?php echo $text['message']; ?></p>
117
-        <p class="wpi-meta-row wpi-resend-email"><a href="<?php echo esc_url( $email_actions['email_url'] ); ?>" class="button button-secondary"><?php echo $text['button_text']; ?></a></p>
118
-        <?php if ( wpinv_get_option( 'overdue_active' ) && "wpi_invoice" === $wpi_mb_invoice->post_type && $wpi_mb_invoice->needs_payment() && ( $due_date = $wpi_mb_invoice->get_due_date() ) ) { ?>
119
-        <p class="wpi-meta-row wpi-send-reminder"><a title="<?php esc_attr_e( 'Send overdue reminder notification to customer', 'invoicing' ); ?>" href="<?php echo esc_url( $email_actions['reminder_url'] ); ?>" class="button button-secondary"><?php esc_attr_e( 'Send Reminder', 'invoicing' ); ?></a></p>
117
+        <p class="wpi-meta-row wpi-resend-email"><a href="<?php echo esc_url($email_actions['email_url']); ?>" class="button button-secondary"><?php echo $text['button_text']; ?></a></p>
118
+        <?php if (wpinv_get_option('overdue_active') && "wpi_invoice" === $wpi_mb_invoice->post_type && $wpi_mb_invoice->needs_payment() && ($due_date = $wpi_mb_invoice->get_due_date())) { ?>
119
+        <p class="wpi-meta-row wpi-send-reminder"><a title="<?php esc_attr_e('Send overdue reminder notification to customer', 'invoicing'); ?>" href="<?php echo esc_url($email_actions['reminder_url']); ?>" class="button button-secondary"><?php esc_attr_e('Send Reminder', 'invoicing'); ?></a></p>
120 120
         <?php } ?>
121 121
         <?php
122 122
         }
123 123
         
124
-        do_action( 'wpinv_metabox_resend_invoice_after', $wpi_mb_invoice );
124
+        do_action('wpinv_metabox_resend_invoice_after', $wpi_mb_invoice);
125 125
     }
126 126
     
127
-    public static function subscriptions( $post ) {
127
+    public static function subscriptions($post) {
128 128
         global $wpi_mb_invoice;
129 129
         
130 130
         $invoice = $wpi_mb_invoice;
131 131
         
132
-        if ( !empty( $invoice ) && $invoice->is_recurring() && $invoice->is_parent() ) {
132
+        if (!empty($invoice) && $invoice->is_recurring() && $invoice->is_parent()) {
133 133
             $payments       = $invoice->get_child_payments();
134 134
             
135 135
             $total_payments = (int)$invoice->get_total_payments();
136 136
             $subscription   = $invoice->get_subscription_data();
137 137
 
138
-            $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() );
139
-            $times_billed   = $total_payments . ' / ' . ( ( (int)$subscription['bill_times'] == 0 ) ? __( 'Until cancelled', 'invoicing' ) : $subscription['bill_times'] );
138
+            $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());
139
+            $times_billed   = $total_payments . ' / ' . (((int)$subscription['bill_times'] == 0) ? __('Until cancelled', 'invoicing') : $subscription['bill_times']);
140 140
             $subscription_status = $invoice->get_subscription_status();
141 141
             ?>
142
-            <p class="wpi-meta-row wpi-sub-label"><?php _e( 'Recurring Payment', 'invoicing' );?></p>
143
-            <?php if ( $subscription_id = $invoice->get_subscription_id() ) { ?>
144
-            <p class="wpi-meta-row wpi-sub-id"><label><?php _e( 'Subscription ID:', 'invoicing' );?> </label><?php echo $subscription_id; ?></p>
142
+            <p class="wpi-meta-row wpi-sub-label"><?php _e('Recurring Payment', 'invoicing'); ?></p>
143
+            <?php if ($subscription_id = $invoice->get_subscription_id()) { ?>
144
+            <p class="wpi-meta-row wpi-sub-id"><label><?php _e('Subscription ID:', 'invoicing'); ?> </label><?php echo $subscription_id; ?></p>
145 145
             <?php } ?>
146
-            <p class="wpi-meta-row wpi-bill-cycle"><label><?php _e( 'Billing Cycle:', 'invoicing' );?> </label><?php echo $billing_cycle; ?></p>
147
-            <p class="wpi-meta-row wpi-billed-times"><label><?php _e( 'Times Billed:', 'invoicing' );?> </label><?php echo $times_billed; ?></p>
148
-            <?php if ( !empty( $payments ) || $invoice->is_paid() ) { ?>
149
-                <p class="wpi-meta-row wpi-start-date"><label><?php _e( 'Start Date:', 'invoicing' );?> </label><?php echo $invoice->get_subscription_start(); ?></p>
150
-                <p class="wpi-meta-row wpi-end-date"><label><?php _e( 'Expiration Date:', 'invoicing' );?> </label><?php echo $invoice->get_subscription_end(); ?></p>
151
-                <?php if ( $status_label = $invoice->get_subscription_status_label( $subscription_status ) ) { ?>
152
-                <p class="wpi-meta-row wpi-sub-status"><label><?php _e( 'Subscription Status:', 'invoicing' );?> </label><?php echo $status_label; ?></p>
146
+            <p class="wpi-meta-row wpi-bill-cycle"><label><?php _e('Billing Cycle:', 'invoicing'); ?> </label><?php echo $billing_cycle; ?></p>
147
+            <p class="wpi-meta-row wpi-billed-times"><label><?php _e('Times Billed:', 'invoicing'); ?> </label><?php echo $times_billed; ?></p>
148
+            <?php if (!empty($payments) || $invoice->is_paid()) { ?>
149
+                <p class="wpi-meta-row wpi-start-date"><label><?php _e('Start Date:', 'invoicing'); ?> </label><?php echo $invoice->get_subscription_start(); ?></p>
150
+                <p class="wpi-meta-row wpi-end-date"><label><?php _e('Expiration Date:', 'invoicing'); ?> </label><?php echo $invoice->get_subscription_end(); ?></p>
151
+                <?php if ($status_label = $invoice->get_subscription_status_label($subscription_status)) { ?>
152
+                <p class="wpi-meta-row wpi-sub-status"><label><?php _e('Subscription Status:', 'invoicing'); ?> </label><?php echo $status_label; ?></p>
153 153
                 <?php } ?>
154
-                <?php if ( $subscription_status == 'trialing' && $trial_end_date = $invoice->get_trial_end_date() ) { ?>
155
-                <p class="wpi-meta-row wpi-trial-date"><label><?php _e( 'Trial Until:', 'invoicing' );?> </label><?php echo $trial_end_date; ?></p>
154
+                <?php if ($subscription_status == 'trialing' && $trial_end_date = $invoice->get_trial_end_date()) { ?>
155
+                <p class="wpi-meta-row wpi-trial-date"><label><?php _e('Trial Until:', 'invoicing'); ?> </label><?php echo $trial_end_date; ?></p>
156 156
                 <?php } ?>
157
-                <?php if ( $cancelled_date = $invoice->get_cancelled_date() ) { ?>
158
-                <p class="wpi-meta-row wpi-cancel-date"><label><?php _e( 'Cancelled On:', 'invoicing' );?> </label><?php echo $cancelled_date; ?></p>
157
+                <?php if ($cancelled_date = $invoice->get_cancelled_date()) { ?>
158
+                <p class="wpi-meta-row wpi-cancel-date"><label><?php _e('Cancelled On:', 'invoicing'); ?> </label><?php echo $cancelled_date; ?></p>
159 159
                 <?php } ?>
160
-                <?php if ( !empty( $payments ) ) { ?>
161
-                <p><strong><?php _e( 'Renewal Payments:', 'invoicing' ); ?></strong></p>
160
+                <?php if (!empty($payments)) { ?>
161
+                <p><strong><?php _e('Renewal Payments:', 'invoicing'); ?></strong></p>
162 162
                 <ul id="wpi-sub-payments">
163
-                <?php foreach ( $payments as $invoice_id ) { ?>
163
+                <?php foreach ($payments as $invoice_id) { ?>
164 164
                     <li>
165
-                        <a href="<?php echo esc_url( get_edit_post_link( $invoice_id ) ); ?>"><?php echo wpinv_get_invoice_number( $invoice_id ); ?></a>&nbsp;&ndash;&nbsp;
166
-                        <span><?php echo wpinv_get_invoice_date( $invoice_id ); ?>&nbsp;&ndash;&nbsp;</span>
167
-                        <span><?php echo wpinv_payment_total( $invoice_id, true ); ?></span>
165
+                        <a href="<?php echo esc_url(get_edit_post_link($invoice_id)); ?>"><?php echo wpinv_get_invoice_number($invoice_id); ?></a>&nbsp;&ndash;&nbsp;
166
+                        <span><?php echo wpinv_get_invoice_date($invoice_id); ?>&nbsp;&ndash;&nbsp;</span>
167
+                        <span><?php echo wpinv_payment_total($invoice_id, true); ?></span>
168 168
                     </li>
169 169
                 <?php } ?>
170 170
                 </ul>
@@ -172,49 +172,49 @@  discard block
 block discarded – undo
172 172
         }
173 173
     }
174 174
     
175
-    public static function renewals( $post ) {
175
+    public static function renewals($post) {
176 176
         global $wpi_mb_invoice;
177 177
         
178
-        if ( wpinv_is_subscription_payment( $wpi_mb_invoice ) ) {
179
-            $parent_url = get_edit_post_link( $wpi_mb_invoice->parent_invoice );
180
-            $parent_id  = wpinv_get_invoice_number( $wpi_mb_invoice->parent_invoice );
178
+        if (wpinv_is_subscription_payment($wpi_mb_invoice)) {
179
+            $parent_url = get_edit_post_link($wpi_mb_invoice->parent_invoice);
180
+            $parent_id  = wpinv_get_invoice_number($wpi_mb_invoice->parent_invoice);
181 181
         ?>
182
-        <p class="wpi-meta-row wpi-sub-id"><label><?php _e( 'Subscription ID:', 'invoicing' );?> </label><?php echo $wpi_mb_invoice->get_subscription_id(); ?></p>
183
-        <p class="wpi-meta-row wpi-parent-id"><label><?php _e( 'Parent Invoice:', 'invoicing' );?> </label><a href="<?php echo esc_url( $parent_url ); ?>"><?php echo $parent_id; ?></a></p>
182
+        <p class="wpi-meta-row wpi-sub-id"><label><?php _e('Subscription ID:', 'invoicing'); ?> </label><?php echo $wpi_mb_invoice->get_subscription_id(); ?></p>
183
+        <p class="wpi-meta-row wpi-parent-id"><label><?php _e('Parent Invoice:', 'invoicing'); ?> </label><a href="<?php echo esc_url($parent_url); ?>"><?php echo $parent_id; ?></a></p>
184 184
         <?php
185 185
         }
186 186
     }
187 187
     
188
-    public static function payment_meta( $post ) {
188
+    public static function payment_meta($post) {
189 189
         global $wpi_mb_invoice;
190 190
 
191
-        $set_dateway = empty( $wpi_mb_invoice->gateway ) ? true : false;
192
-        if ( !$set_dateway && !$wpi_mb_invoice->get_meta( '_wpinv_checkout', true ) && !$wpi_mb_invoice->is_paid() && !$wpi_mb_invoice->is_refunded() ) {
191
+        $set_dateway = empty($wpi_mb_invoice->gateway) ? true : false;
192
+        if (!$set_dateway && !$wpi_mb_invoice->get_meta('_wpinv_checkout', true) && !$wpi_mb_invoice->is_paid() && !$wpi_mb_invoice->is_refunded()) {
193 193
             $set_dateway = true;
194 194
         }
195 195
         
196 196
         ?>
197 197
         <p class="wpi-meta-row">
198
-        <?php if ( $set_dateway ) { $gateways = wpinv_get_enabled_payment_gateways( true ); ?>
199
-            <label for="wpinv_gateway"><?php _e( 'Gateway:', 'invoicing' ) ; ?></label>
198
+        <?php if ($set_dateway) { $gateways = wpinv_get_enabled_payment_gateways(true); ?>
199
+            <label for="wpinv_gateway"><?php _e('Gateway:', 'invoicing'); ?></label>
200 200
             <select required="required" id="wpinv_gateway" name="wpinv_gateway">
201
-                <?php foreach ( $gateways as $name => $gateway ) {
202
-                    if ( $wpi_mb_invoice->is_recurring() && !wpinv_gateway_support_subscription( $name ) ) {
201
+                <?php foreach ($gateways as $name => $gateway) {
202
+                    if ($wpi_mb_invoice->is_recurring() && !wpinv_gateway_support_subscription($name)) {
203 203
                         continue;
204 204
                     }
205 205
                     ?>
206
-                <option value="<?php echo $name;?>" <?php selected( $wpi_mb_invoice->gateway, $name );?>><?php echo !empty( $gateway['admin_label'] ) ? $gateway['admin_label'] : $gateway['checkout_label']; ?></option>
206
+                <option value="<?php echo $name; ?>" <?php selected($wpi_mb_invoice->gateway, $name); ?>><?php echo !empty($gateway['admin_label']) ? $gateway['admin_label'] : $gateway['checkout_label']; ?></option>
207 207
                 <?php } ?>
208 208
             </select>
209 209
         <?php } else { 
210
-            echo wp_sprintf( __( '<label>Gateway:</label> %s', 'invoicing' ), wpinv_get_gateway_checkout_label( $wpi_mb_invoice->gateway ) );
210
+            echo wp_sprintf(__('<label>Gateway:</label> %s', 'invoicing'), wpinv_get_gateway_checkout_label($wpi_mb_invoice->gateway));
211 211
         } ?>
212 212
         </p>
213
-        <?php if ( $key = $wpi_mb_invoice->get_key() ) { ?>
214
-        <p class="wpi-meta-row"><?php echo wp_sprintf( __( '<label>Key:</label> %s', 'invoicing' ), $key ); ?></p>
213
+        <?php if ($key = $wpi_mb_invoice->get_key()) { ?>
214
+        <p class="wpi-meta-row"><?php echo wp_sprintf(__('<label>Key:</label> %s', 'invoicing'), $key); ?></p>
215 215
         <?php } ?>
216
-        <?php if ( $wpi_mb_invoice->is_paid() || $wpi_mb_invoice->is_refunded() ) { ?>
217
-        <p class="wpi-meta-row"><?php echo wp_sprintf( __( '<label>Transaction ID:</label> %s', 'invoicing' ), wpinv_payment_link_transaction_id( $wpi_mb_invoice ) ); ?></p>
216
+        <?php if ($wpi_mb_invoice->is_paid() || $wpi_mb_invoice->is_refunded()) { ?>
217
+        <p class="wpi-meta-row"><?php echo wp_sprintf(__('<label>Transaction ID:</label> %s', 'invoicing'), wpinv_payment_link_transaction_id($wpi_mb_invoice)); ?></p>
218 218
         <?php } ?>
219 219
         <?php
220 220
     }
Please login to merge, or discard this patch.
includes/admin/meta-boxes/class-mb-invoice-items.php 1 patch
Spacing   +150 added lines, -150 removed lines patch added patch discarded remove patch
@@ -1,22 +1,22 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // MUST have WordPress.
3
-if ( !defined( 'WPINC' ) ) {
4
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
3
+if (!defined('WPINC')) {
4
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
5 5
 }
6 6
 
7 7
 class WPInv_Meta_Box_Items {
8
-    public static function output( $post ) {        
8
+    public static function output($post) {        
9 9
         global $wpinv_euvat, $ajax_cart_details;
10 10
         
11
-        $post_id            = !empty( $post->ID ) ? $post->ID : 0;
12
-        $invoice            = new WPInv_Invoice( $post_id );
11
+        $post_id            = !empty($post->ID) ? $post->ID : 0;
12
+        $invoice            = new WPInv_Invoice($post_id);
13 13
         $ajax_cart_details  = $invoice->get_cart_details();
14
-        $subtotal           = $invoice->get_subtotal( true );
14
+        $subtotal           = $invoice->get_subtotal(true);
15 15
         $discount_raw       = $invoice->get_discount();
16
-        $discount           = wpinv_price( $discount_raw, $invoice->get_currency() );
16
+        $discount           = wpinv_price($discount_raw, $invoice->get_currency());
17 17
         $discounts          = $discount_raw > 0 ? $invoice->get_discounts() : '';
18
-        $tax                = $invoice->get_tax( true );
19
-        $total              = $invoice->get_total( true );
18
+        $tax                = $invoice->get_tax(true);
19
+        $total              = $invoice->get_total(true);
20 20
         $item_quantities    = wpinv_item_quantities_enabled();
21 21
         $use_taxes          = wpinv_use_taxes();
22 22
         $item_types         = wpinv_get_item_types();
@@ -29,20 +29,20 @@  discard block
 block discarded – undo
29 29
         }
30 30
         
31 31
         $cols = 5;
32
-        if ( $item_quantities ) {
32
+        if ($item_quantities) {
33 33
             $cols++;
34 34
         }
35
-        if ( $use_taxes ) {
35
+        if ($use_taxes) {
36 36
             $cols++;
37 37
         }
38 38
         $class = '';
39
-        if ( $invoice->is_paid() ) {
39
+        if ($invoice->is_paid()) {
40 40
             $class .= ' wpinv-paid';
41 41
         }
42
-        if ( $invoice->is_refunded() ) {
42
+        if ($invoice->is_refunded()) {
43 43
             $class .= ' wpinv-refunded';
44 44
         }
45
-        if ( $is_recurring ) {
45
+        if ($is_recurring) {
46 46
             $class .= ' wpi-recurring';
47 47
         }
48 48
         ?>
@@ -50,21 +50,21 @@  discard block
 block discarded – undo
50 50
             <table id="wpinv_items" class="wpinv-items" cellspacing="0" cellpadding="0">
51 51
                 <thead>
52 52
                     <tr>
53
-                        <th class="id"><?php _e( 'ID', 'invoicing' );?></th>
54
-                        <th class="title"><?php _e( 'Item', 'invoicing' );?></th>
55
-                        <th class="price"><?php _e( 'Price', 'invoicing' );?></th>
56
-                        <?php if ( $item_quantities ) { ?>
57
-                        <th class="qty"><?php _e( 'Qty', 'invoicing' );?></th>
53
+                        <th class="id"><?php _e('ID', 'invoicing'); ?></th>
54
+                        <th class="title"><?php _e('Item', 'invoicing'); ?></th>
55
+                        <th class="price"><?php _e('Price', 'invoicing'); ?></th>
56
+                        <?php if ($item_quantities) { ?>
57
+                        <th class="qty"><?php _e('Qty', 'invoicing'); ?></th>
58 58
                         <?php } ?>
59
-                        <th class="total"><?php _e( 'Total', 'invoicing' );?></th>
60
-                        <?php if ( $use_taxes ) { ?>
61
-                        <th class="tax"><?php _e( 'Tax (%)', 'invoicing' );?></th>
59
+                        <th class="total"><?php _e('Total', 'invoicing'); ?></th>
60
+                        <?php if ($use_taxes) { ?>
61
+                        <th class="tax"><?php _e('Tax (%)', 'invoicing'); ?></th>
62 62
                         <?php } ?>
63 63
                         <th class="action"></th>
64 64
                     </tr>
65 65
                 </thead>
66 66
                 <tbody class="wpinv-line-items">
67
-                    <?php echo wpinv_admin_get_line_items( $invoice ); ?>
67
+                    <?php echo wpinv_admin_get_line_items($invoice); ?>
68 68
                 </tbody>
69 69
                 <tfoot class="wpinv-totals">
70 70
                     <tr>
@@ -76,44 +76,44 @@  discard block
 block discarded – undo
76 76
                                         </td>
77 77
                                         <td class="title">
78 78
                                             <input type="text" class="regular-text" placeholder="Item name" value="" name="_wpinv_quick[name]">
79
-                                            <?php if ( $wpinv_euvat->allow_vat_rules() ) { ?>
79
+                                            <?php if ($wpinv_euvat->allow_vat_rules()) { ?>
80 80
                                             <div class="wp-clearfix">
81 81
                                                 <label class="wpi-vat-rule">
82
-                                                    <span class="title"><?php _e( 'VAT rule type', 'invoicing' );?></span>
82
+                                                    <span class="title"><?php _e('VAT rule type', 'invoicing'); ?></span>
83 83
                                                     <span class="input-text-wrap">
84
-                                                        <?php echo wpinv_html_select( array(
84
+                                                        <?php echo wpinv_html_select(array(
85 85
                                                             'options'          => $wpinv_euvat->get_rules(),
86 86
                                                             'name'             => '_wpinv_quick[vat_rule]',
87 87
                                                             'id'               => '_wpinv_quick_vat_rule',
88 88
                                                             'show_option_all'  => false,
89 89
                                                             'show_option_none' => false,
90 90
                                                             'class'            => 'gdmbx2-text-medium wpinv-quick-vat-rule',
91
-                                                        ) ); ?>
91
+                                                        )); ?>
92 92
                                                     </span>
93 93
                                                 </label>
94 94
                                             </div>
95
-                                            <?php } if ( $wpinv_euvat->allow_vat_classes() ) { ?>
95
+                                            <?php } if ($wpinv_euvat->allow_vat_classes()) { ?>
96 96
                                             <div class="wp-clearfix">
97 97
                                                 <label class="wpi-vat-class">
98
-                                                    <span class="title"><?php _e( 'VAT class', 'invoicing' );?></span>
98
+                                                    <span class="title"><?php _e('VAT class', 'invoicing'); ?></span>
99 99
                                                     <span class="input-text-wrap">
100
-                                                        <?php echo wpinv_html_select( array(
100
+                                                        <?php echo wpinv_html_select(array(
101 101
                                                             'options'          => $wpinv_euvat->get_all_classes(),
102 102
                                                             'name'             => '_wpinv_quick[vat_class]',
103 103
                                                             'id'               => '_wpinv_quick_vat_class',
104 104
                                                             'show_option_all'  => false,
105 105
                                                             'show_option_none' => false,
106 106
                                                             'class'            => 'gdmbx2-text-medium wpinv-quick-vat-class',
107
-                                                        ) ); ?>
107
+                                                        )); ?>
108 108
                                                     </span>
109 109
                                                 </label>
110 110
                                             </div>
111 111
                                             <?php } ?>
112 112
                                             <div class="wp-clearfix">
113 113
                                                 <label class="wpi-item-type">
114
-                                                    <span class="title"><?php _e( 'Item type', 'invoicing' );?></span>
114
+                                                    <span class="title"><?php _e('Item type', 'invoicing'); ?></span>
115 115
                                                     <span class="input-text-wrap">
116
-                                                        <?php echo wpinv_html_select( array(
116
+                                                        <?php echo wpinv_html_select(array(
117 117
                                                             'options'          => $item_types,
118 118
                                                             'name'             => '_wpinv_quick[type]',
119 119
                                                             'id'               => '_wpinv_quick_type',
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
                                                             'show_option_all'  => false,
122 122
                                                             'show_option_none' => false,
123 123
                                                             'class'            => 'gdmbx2-text-medium wpinv-quick-type',
124
-                                                        ) ); ?>
124
+                                                        )); ?>
125 125
                                                     </span>
126 126
                                                 </label>
127 127
                                             </div>
@@ -134,11 +134,11 @@  discard block
 block discarded – undo
134 134
                                             </div>
135 135
                                         </td>
136 136
                                         <td class="price"><input type="text" placeholder="0.00" class="wpi-field-price wpi-price" name="_wpinv_quick[price]" /></td>
137
-                                        <?php if ( $item_quantities ) { ?>
137
+                                        <?php if ($item_quantities) { ?>
138 138
                                         <td class="qty"><input type="number" class="small-text" step="1" min="1" value="1" name="_wpinv_quick[qty]" /></td>
139 139
                                         <?php } ?>
140 140
                                         <td class="total"></td>
141
-                                        <?php if ( $use_taxes ) { ?>
141
+                                        <?php if ($use_taxes) { ?>
142 142
                                         <td class="tax"></td>
143 143
                                         <?php } ?>
144 144
                                         <td class="action"></td>
@@ -151,29 +151,29 @@  discard block
 block discarded – undo
151 151
                         <td colspan="<?php echo $cols; ?>"></td>
152 152
                     </tr>
153 153
                     <tr class="totals">
154
-                        <td colspan="<?php echo ( $cols - 4 ); ?>"></td>
154
+                        <td colspan="<?php echo ($cols - 4); ?>"></td>
155 155
                         <td colspan="4">
156 156
                             <table cellspacing="0" cellpadding="0">
157 157
                                 <tr class="subtotal">
158
-                                    <td class="name"><?php _e( 'Sub Total:', 'invoicing' );?></td>
159
-                                    <td class="total"><?php echo $subtotal;?></td>
158
+                                    <td class="name"><?php _e('Sub Total:', 'invoicing'); ?></td>
159
+                                    <td class="total"><?php echo $subtotal; ?></td>
160 160
                                     <td class="action"></td>
161 161
                                 </tr>
162 162
                                 <tr class="discount">
163
-                                    <td class="name"><?php wpinv_get_discount_label( wpinv_discount_code( $invoice->ID ) ); ?>:</td>
164
-                                    <td class="total"><?php echo wpinv_discount( $invoice->ID, true, true ); ?></td>
163
+                                    <td class="name"><?php wpinv_get_discount_label(wpinv_discount_code($invoice->ID)); ?>:</td>
164
+                                    <td class="total"><?php echo wpinv_discount($invoice->ID, true, true); ?></td>
165 165
                                     <td class="action"></td>
166 166
                                 </tr>
167
-                                <?php if ( $use_taxes ) { ?>
167
+                                <?php if ($use_taxes) { ?>
168 168
                                 <tr class="tax">
169
-                                    <td class="name"><?php _e( 'Tax:', 'invoicing' );?></td>
170
-                                    <td class="total"><?php echo $tax;?></td>
169
+                                    <td class="name"><?php _e('Tax:', 'invoicing'); ?></td>
170
+                                    <td class="total"><?php echo $tax; ?></td>
171 171
                                     <td class="action"></td>
172 172
                                 </tr>
173 173
                                 <?php } ?>
174 174
                                 <tr class="total">
175
-                                    <td class="name"><?php echo apply_filters( 'wpinv_invoice_items_total_label', __( 'Invoice Total:', 'invoicing' ), $invoice );?></td>
176
-                                    <td class="total"><?php echo $total;?></td>
175
+                                    <td class="name"><?php echo apply_filters('wpinv_invoice_items_total_label', __('Invoice Total:', 'invoicing'), $invoice); ?></td>
176
+                                    <td class="total"><?php echo $total; ?></td>
177 177
                                     <td class="action"></td>
178 178
                                 </tr>
179 179
                             </table>
@@ -183,89 +183,89 @@  discard block
 block discarded – undo
183 183
             </table>
184 184
             <div class="wpinv-actions">
185 185
                 <?php
186
-                    if ( !$invoice->is_paid() && !$invoice->is_refunded() ) {
187
-                    if ( !$invoice->is_recurring() ) {
188
-                    echo wpinv_item_dropdown( array(
186
+                    if (!$invoice->is_paid() && !$invoice->is_refunded()) {
187
+                    if (!$invoice->is_recurring()) {
188
+                    echo wpinv_item_dropdown(array(
189 189
                         'name'             => 'wpinv_invoice_item',
190 190
                         'id'               => 'wpinv_invoice_item',
191 191
                         'with_packages'    => false,
192 192
                         'show_recurring'   => true,
193
-                    ) );
193
+                    ));
194 194
                     ?>
195
-                <input type="button" value="<?php echo sprintf(esc_attr__( 'Add item to %s', 'invoicing'), $type_title); ?>" class="button button-primary" id="wpinv-add-item"><input type="button" value="<?php esc_attr_e( 'Create new item', 'invoicing' );?>" class="button button-primary" id="wpinv-new-item"><?php } ?><input type="button" value="<?php esc_attr_e( 'Recalculate Totals', 'invoicing' );?>" class="button button-primary wpinv-flr" id="wpinv-recalc-totals">
195
+                <input type="button" value="<?php echo sprintf(esc_attr__('Add item to %s', 'invoicing'), $type_title); ?>" class="button button-primary" id="wpinv-add-item"><input type="button" value="<?php esc_attr_e('Create new item', 'invoicing'); ?>" class="button button-primary" id="wpinv-new-item"><?php } ?><input type="button" value="<?php esc_attr_e('Recalculate Totals', 'invoicing'); ?>" class="button button-primary wpinv-flr" id="wpinv-recalc-totals">
196 196
                     <?php } ?>
197
-                <?php do_action( 'wpinv_invoice_items_actions', $invoice ); ?>
197
+                <?php do_action('wpinv_invoice_items_actions', $invoice); ?>
198 198
             </div>
199 199
         </div>
200 200
         <?php
201 201
     }
202 202
     
203
-    public static function prices( $post ) {        
203
+    public static function prices($post) {        
204 204
         $symbol         = wpinv_currency_symbol();
205 205
         $position       = wpinv_currency_position();
206
-        $item           = new WPInv_Item( $post->ID );
206
+        $item           = new WPInv_Item($post->ID);
207 207
         
208 208
         $price          = $item->get_price();
209 209
         $is_recurring   = $item->is_recurring();
210 210
         $period         = $item->get_recurring_period();
211
-        $interval       = absint( $item->get_recurring_interval() );
212
-        $times          = absint( $item->get_recurring_limit() );
211
+        $interval       = absint($item->get_recurring_interval());
212
+        $times          = absint($item->get_recurring_limit());
213 213
         $free_trial     = $item->has_free_trial();
214 214
         $trial_interval = $item->get_trial_interval();
215 215
         $trial_period   = $item->get_trial_period();
216 216
         
217 217
         $intervals      = array();
218
-        for ( $i = 1; $i <= 90; $i++ ) {
218
+        for ($i = 1; $i <= 90; $i++) {
219 219
             $intervals[$i] = $i;
220 220
         }
221 221
         
222
-        $interval       = $interval > 0 ? $interval : 1;
222
+        $interval = $interval > 0 ? $interval : 1;
223 223
         
224 224
         $class = $is_recurring ? 'wpinv-recurring-y' : 'wpinv-recurring-n';
225 225
         ?>
226
-        <p class="wpinv-row-prices"><?php echo ( $position != 'right' ? $symbol . '&nbsp;' : '' );?><input type="text" maxlength="12" placeholder="<?php echo wpinv_sanitize_amount( 0 ); ?>" value="<?php echo $price;?>" id="wpinv_item_price" name="wpinv_item_price" class="medium-text wpi-field-price wpi-price" <?php disabled( $item->is_package(), true ); ?> /><?php echo ( $position == 'right' ? '&nbsp;' . $symbol : '' );?><input type="hidden" name="wpinv_vat_meta_box_nonce" value="<?php echo wp_create_nonce( 'wpinv_item_meta_box_save' ) ;?>" />
227
-        <?php if ( $item->is_package() ) { ?>
228
-        <span class="description"><?php _e( 'GD package item price can be edited only from GD payment manager.', 'invoicing' ); ?></span>
226
+        <p class="wpinv-row-prices"><?php echo ($position != 'right' ? $symbol . '&nbsp;' : ''); ?><input type="text" maxlength="12" placeholder="<?php echo wpinv_sanitize_amount(0); ?>" value="<?php echo $price; ?>" id="wpinv_item_price" name="wpinv_item_price" class="medium-text wpi-field-price wpi-price" <?php disabled($item->is_package(), true); ?> /><?php echo ($position == 'right' ? '&nbsp;' . $symbol : ''); ?><input type="hidden" name="wpinv_vat_meta_box_nonce" value="<?php echo wp_create_nonce('wpinv_item_meta_box_save'); ?>" />
227
+        <?php if ($item->is_package()) { ?>
228
+        <span class="description"><?php _e('GD package item price can be edited only from GD payment manager.', 'invoicing'); ?></span>
229 229
         <?php } ?>
230 230
         </p>
231 231
         <p class="wpinv-row-is-recurring">
232 232
             <label for="wpinv_is_recurring">
233
-                <input type="checkbox" name="wpinv_is_recurring" id="wpinv_is_recurring" value="1" <?php checked( 1, $is_recurring ); ?> />
234
-                <?php echo apply_filters( 'wpinv_is_recurring_toggle_text', __( 'Is Recurring Item?', 'invoicing' ) ); ?>
233
+                <input type="checkbox" name="wpinv_is_recurring" id="wpinv_is_recurring" value="1" <?php checked(1, $is_recurring); ?> />
234
+                <?php echo apply_filters('wpinv_is_recurring_toggle_text', __('Is Recurring Item?', 'invoicing')); ?>
235 235
             </label>
236 236
         </p>
237
-        <p class="wpinv-row-recurring-fields <?php echo $class;?>">
238
-                <label class="wpinv-period" for="wpinv_recurring_period"><?php _e( 'Recurring', 'invoicing' );?> <select class="wpinv-select " id="wpinv_recurring_period" name="wpinv_recurring_period"><option value="D" data-text="<?php esc_attr_e( 'day(s)', 'invoicing' ); ?>" <?php selected( 'D', $period );?>><?php _e( 'Daily', 'invoicing' ); ?></option><option value="W" data-text="<?php esc_attr_e( 'week(s)', 'invoicing' ); ?>" <?php selected( 'W', $period );?>><?php _e( 'Weekly', 'invoicing' ); ?></option><option value="M" data-text="<?php esc_attr_e( 'month(s)', 'invoicing' ); ?>" <?php selected( 'M', $period );?>><?php _e( 'Monthly', 'invoicing' ); ?></option><option value="Y" data-text="<?php esc_attr_e( 'year(s)', 'invoicing' ); ?>" <?php selected( 'Y', $period );?>><?php _e( 'Yearly', 'invoicing' ); ?></option></select></label>
239
-                <label class="wpinv-interval" for="wpinv_recurring_interval"> <?php _e( 'at every', 'invoicing' );?> <?php echo wpinv_html_select( array(
237
+        <p class="wpinv-row-recurring-fields <?php echo $class; ?>">
238
+                <label class="wpinv-period" for="wpinv_recurring_period"><?php _e('Recurring', 'invoicing'); ?> <select class="wpinv-select " id="wpinv_recurring_period" name="wpinv_recurring_period"><option value="D" data-text="<?php esc_attr_e('day(s)', 'invoicing'); ?>" <?php selected('D', $period); ?>><?php _e('Daily', 'invoicing'); ?></option><option value="W" data-text="<?php esc_attr_e('week(s)', 'invoicing'); ?>" <?php selected('W', $period); ?>><?php _e('Weekly', 'invoicing'); ?></option><option value="M" data-text="<?php esc_attr_e('month(s)', 'invoicing'); ?>" <?php selected('M', $period); ?>><?php _e('Monthly', 'invoicing'); ?></option><option value="Y" data-text="<?php esc_attr_e('year(s)', 'invoicing'); ?>" <?php selected('Y', $period); ?>><?php _e('Yearly', 'invoicing'); ?></option></select></label>
239
+                <label class="wpinv-interval" for="wpinv_recurring_interval"> <?php _e('at every', 'invoicing'); ?> <?php echo wpinv_html_select(array(
240 240
                     'options'          => $intervals,
241 241
                     'name'             => 'wpinv_recurring_interval',
242 242
                     'id'               => 'wpinv_recurring_interval',
243 243
                     'selected'         => $interval,
244 244
                     'show_option_all'  => false,
245 245
                     'show_option_none' => false
246
-                ) ); ?> <span id="wpinv_interval_text"><?php _e( 'day(s)', 'invoicing' );?></span></label>
247
-                <label class="wpinv-times" for="wpinv_recurring_limit"> <?php _e( 'for', 'invoicing' );?> <input class="small-text" type="number" value="<?php echo $times;?>" size="4" id="wpinv_recurring_limit" name="wpinv_recurring_limit" step="1" min="0"> <?php _e( 'time(s) <i>(select 0 for recurring forever until cancelled</i>)', 'invoicing' );?></label>
246
+                )); ?> <span id="wpinv_interval_text"><?php _e('day(s)', 'invoicing'); ?></span></label>
247
+                <label class="wpinv-times" for="wpinv_recurring_limit"> <?php _e('for', 'invoicing'); ?> <input class="small-text" type="number" value="<?php echo $times; ?>" size="4" id="wpinv_recurring_limit" name="wpinv_recurring_limit" step="1" min="0"> <?php _e('time(s) <i>(select 0 for recurring forever until cancelled</i>)', 'invoicing'); ?></label>
248 248
                 <span class="clear wpi-trial-clr"></span>
249 249
                 <label class="wpinv-free-trial" for="wpinv_free_trial">
250
-                    <input type="checkbox" name="wpinv_free_trial" id="wpinv_free_trial" value="1" <?php checked( true, (bool)$free_trial ); ?> /> 
251
-                    <?php echo __( 'Offer free trial for', 'invoicing' ); ?>
250
+                    <input type="checkbox" name="wpinv_free_trial" id="wpinv_free_trial" value="1" <?php checked(true, (bool)$free_trial); ?> /> 
251
+                    <?php echo __('Offer free trial for', 'invoicing'); ?>
252 252
                 </label>
253 253
                 <label class="wpinv-trial-interval" for="wpinv_trial_interval">
254
-                    <input class="small-text" type="number" value="<?php echo $trial_interval;?>" size="4" id="wpinv_trial_interval" name="wpinv_trial_interval" step="1" min="1"> <select class="wpinv-select" id="wpinv_trial_period" name="wpinv_trial_period"><option value="D" <?php selected( 'D', $trial_period );?>><?php _e( 'day(s)', 'invoicing' ); ?></option><option value="W" <?php selected( 'W', $trial_period );?>><?php _e( 'week(s)', 'invoicing' ); ?></option><option value="M" <?php selected( 'M', $trial_period );?>><?php _e( 'month(s)', 'invoicing' ); ?></option><option value="Y" <?php selected( 'Y', $trial_period );?>><?php _e( 'year(s)', 'invoicing' ); ?></option></select>
254
+                    <input class="small-text" type="number" value="<?php echo $trial_interval; ?>" size="4" id="wpinv_trial_interval" name="wpinv_trial_interval" step="1" min="1"> <select class="wpinv-select" id="wpinv_trial_period" name="wpinv_trial_period"><option value="D" <?php selected('D', $trial_period); ?>><?php _e('day(s)', 'invoicing'); ?></option><option value="W" <?php selected('W', $trial_period); ?>><?php _e('week(s)', 'invoicing'); ?></option><option value="M" <?php selected('M', $trial_period); ?>><?php _e('month(s)', 'invoicing'); ?></option><option value="Y" <?php selected('Y', $trial_period); ?>><?php _e('year(s)', 'invoicing'); ?></option></select>
255 255
                 </label>
256 256
         </p>
257
-        <input type="hidden" id="_wpi_current_type" value="<?php echo wpinv_get_item_type( $post->ID ); ?>" />
258
-        <?php do_action( 'wpinv_item_price_field', $post->ID ); ?>
257
+        <input type="hidden" id="_wpi_current_type" value="<?php echo wpinv_get_item_type($post->ID); ?>" />
258
+        <?php do_action('wpinv_item_price_field', $post->ID); ?>
259 259
         <?php
260 260
     }
261 261
     
262
-    public static function vat_rules( $post ) {
262
+    public static function vat_rules($post) {
263 263
         global $wpinv_euvat;
264 264
         
265
-        $rule_type = $wpinv_euvat->get_item_rule( $post->ID );
265
+        $rule_type = $wpinv_euvat->get_item_rule($post->ID);
266 266
         ?>
267
-        <p><label for="wpinv_vat_rules"><strong><?php _e( 'Select how VAT rules will be applied:', 'invoicing' );?></strong></label>&nbsp;&nbsp;&nbsp;
268
-        <?php echo wpinv_html_select( array(
267
+        <p><label for="wpinv_vat_rules"><strong><?php _e('Select how VAT rules will be applied:', 'invoicing'); ?></strong></label>&nbsp;&nbsp;&nbsp;
268
+        <?php echo wpinv_html_select(array(
269 269
                     'options'          => $wpinv_euvat->get_rules(),
270 270
                     'name'             => 'wpinv_vat_rules',
271 271
                     'id'               => 'wpinv_vat_rules',
@@ -273,19 +273,19 @@  discard block
 block discarded – undo
273 273
                     'show_option_all'  => false,
274 274
                     'show_option_none' => false,
275 275
                     'class'            => 'gdmbx2-text-medium wpinv-vat-rules',
276
-                ) ); ?>
276
+                )); ?>
277 277
         </p>
278
-        <p class="wpi-m0"><?php _e( 'When you select physical product rules, only consumers and businesses in your country will be charged VAT.  The VAT rate used will be the rate in your country.', 'invoicing' ); ?></p>
279
-        <p class="wpi-m0"><?php _e( 'If you select Digital product rules, VAT will be charged at the rate that applies in the country of the consumer.  Only businesses in your country will be charged VAT.', 'invoicing' ); ?></p>
278
+        <p class="wpi-m0"><?php _e('When you select physical product rules, only consumers and businesses in your country will be charged VAT.  The VAT rate used will be the rate in your country.', 'invoicing'); ?></p>
279
+        <p class="wpi-m0"><?php _e('If you select Digital product rules, VAT will be charged at the rate that applies in the country of the consumer.  Only businesses in your country will be charged VAT.', 'invoicing'); ?></p>
280 280
         <?php
281 281
     }
282 282
     
283
-    public static function vat_classes( $post ) {
283
+    public static function vat_classes($post) {
284 284
         global $wpinv_euvat;
285 285
         
286
-        $vat_class = $wpinv_euvat->get_item_class( $post->ID );
286
+        $vat_class = $wpinv_euvat->get_item_class($post->ID);
287 287
         ?>
288
-        <p><?php echo wpinv_html_select( array(
288
+        <p><?php echo wpinv_html_select(array(
289 289
                     'options'          => $wpinv_euvat->get_all_classes(),
290 290
                     'name'             => 'wpinv_vat_class',
291 291
                     'id'               => 'wpinv_vat_class',
@@ -293,18 +293,18 @@  discard block
 block discarded – undo
293 293
                     'show_option_all'  => false,
294 294
                     'show_option_none' => false,
295 295
                     'class'            => 'gdmbx2-text-medium wpinv-vat-class',
296
-                ) ); ?>
296
+                )); ?>
297 297
         </p>
298
-        <p class="wpi-m0"><?php _e( 'Select the VAT rate class to use for this invoice item.', 'invoicing' ); ?></p>
298
+        <p class="wpi-m0"><?php _e('Select the VAT rate class to use for this invoice item.', 'invoicing'); ?></p>
299 299
         <?php
300 300
     }
301 301
     
302
-    public static function item_info( $post ) {
303
-        $item_type = wpinv_get_item_type( $post->ID );
304
-        do_action( 'wpinv_item_info_metabox_before', $post );
302
+    public static function item_info($post) {
303
+        $item_type = wpinv_get_item_type($post->ID);
304
+        do_action('wpinv_item_info_metabox_before', $post);
305 305
         ?>
306
-        <p><label for="wpinv_item_type"><strong><?php _e( 'Type:', 'invoicing' );?></strong></label>&nbsp;&nbsp;&nbsp;
307
-        <?php echo wpinv_html_select( array(
306
+        <p><label for="wpinv_item_type"><strong><?php _e('Type:', 'invoicing'); ?></strong></label>&nbsp;&nbsp;&nbsp;
307
+        <?php echo wpinv_html_select(array(
308 308
                     'options'          => wpinv_get_item_types(),
309 309
                     'name'             => 'wpinv_item_type',
310 310
                     'id'               => 'wpinv_item_type',
@@ -313,114 +313,114 @@  discard block
 block discarded – undo
313 313
                     'show_option_none' => false,
314 314
                     'class'            => 'gdmbx2-text-medium wpinv-item-type',
315 315
                     //'disabled'         => $item_type == 'package' ? true : false,
316
-                ) ); ?>
316
+                )); ?>
317 317
         </p>
318
-        <p class="wpi-m0"><?php _e( 'Select item type.', 'invoicing' );?><br><?php _e( '<b>Standard:</b> Standard item type', 'invoicing' );?><br><?php _e( '<b>Fee:</b> Like Registration Fee, Sign up Fee etc.', 'invoicing' );?></p>
318
+        <p class="wpi-m0"><?php _e('Select item type.', 'invoicing'); ?><br><?php _e('<b>Standard:</b> Standard item type', 'invoicing'); ?><br><?php _e('<b>Fee:</b> Like Registration Fee, Sign up Fee etc.', 'invoicing'); ?></p>
319 319
         <?php
320
-        do_action( 'wpinv_item_info_metabox_after', $post );
320
+        do_action('wpinv_item_info_metabox_after', $post);
321 321
     }
322 322
     
323
-    public static function meta_values( $post ) {
324
-        $meta_keys = apply_filters( 'wpinv_show_meta_values_for_keys', array(
323
+    public static function meta_values($post) {
324
+        $meta_keys = apply_filters('wpinv_show_meta_values_for_keys', array(
325 325
             'type',
326 326
             'custom_id'
327
-        ) );
327
+        ));
328 328
         
329
-        if ( empty( $meta_keys ) ) {
329
+        if (empty($meta_keys)) {
330 330
             return;
331 331
         }
332 332
         
333
-        do_action( 'wpinv_meta_values_metabox_before', $post );
333
+        do_action('wpinv_meta_values_metabox_before', $post);
334 334
         
335
-        foreach ( $meta_keys as $meta_key ) {
335
+        foreach ($meta_keys as $meta_key) {
336 336
             ?>
337
-            <p class="wpi-mtb05"><label><strong><?php echo $meta_key; ?></strong>: <?php echo get_post_meta( $post->ID, '_wpinv_' . $meta_key, true ); ?></label></p>
337
+            <p class="wpi-mtb05"><label><strong><?php echo $meta_key; ?></strong>: <?php echo get_post_meta($post->ID, '_wpinv_' . $meta_key, true); ?></label></p>
338 338
             <?php 
339 339
         }
340 340
         
341
-        do_action( 'wpinv_meta_values_metabox_after', $post );
341
+        do_action('wpinv_meta_values_metabox_after', $post);
342 342
     }
343 343
     
344
-    public static function save( $post_id, $data, $post ) {
345
-        $invoice        = new WPInv_Invoice( $post_id );
344
+    public static function save($post_id, $data, $post) {
345
+        $invoice        = new WPInv_Invoice($post_id);
346 346
         
347 347
         // Billing
348
-        $first_name     = sanitize_text_field( $data['wpinv_first_name'] );
349
-        $last_name      = sanitize_text_field( $data['wpinv_last_name'] );
350
-        $company        = sanitize_text_field( $data['wpinv_company'] );
351
-        $vat_number     = sanitize_text_field( $data['wpinv_vat_number'] );
352
-        $phone          = sanitize_text_field( $data['wpinv_phone'] );
353
-        $address        = sanitize_text_field( $data['wpinv_address'] );
354
-        $city           = sanitize_text_field( $data['wpinv_city'] );
355
-        $zip            = sanitize_text_field( $data['wpinv_zip'] );
356
-        $country        = sanitize_text_field( $data['wpinv_country'] );
357
-        $state          = sanitize_text_field( $data['wpinv_state'] );
348
+        $first_name     = sanitize_text_field($data['wpinv_first_name']);
349
+        $last_name      = sanitize_text_field($data['wpinv_last_name']);
350
+        $company        = sanitize_text_field($data['wpinv_company']);
351
+        $vat_number     = sanitize_text_field($data['wpinv_vat_number']);
352
+        $phone          = sanitize_text_field($data['wpinv_phone']);
353
+        $address        = sanitize_text_field($data['wpinv_address']);
354
+        $city           = sanitize_text_field($data['wpinv_city']);
355
+        $zip            = sanitize_text_field($data['wpinv_zip']);
356
+        $country        = sanitize_text_field($data['wpinv_country']);
357
+        $state          = sanitize_text_field($data['wpinv_state']);
358 358
         
359 359
         // Details
360
-        $status         = sanitize_text_field( $data['wpinv_status'] );
361
-        $old_status     = !empty( $data['original_post_status'] ) ? sanitize_text_field( $data['original_post_status'] ) : $status;
362
-        $number         = sanitize_text_field( $data['wpinv_number'] );
363
-        $due_date       = isset( $data['wpinv_due_date'] ) ? sanitize_text_field( $data['wpinv_due_date'] ) : '';
360
+        $status         = sanitize_text_field($data['wpinv_status']);
361
+        $old_status     = !empty($data['original_post_status']) ? sanitize_text_field($data['original_post_status']) : $status;
362
+        $number         = sanitize_text_field($data['wpinv_number']);
363
+        $due_date       = isset($data['wpinv_due_date']) ? sanitize_text_field($data['wpinv_due_date']) : '';
364 364
         //$discounts      = sanitize_text_field( $data['wpinv_discounts'] );
365 365
         //$discount       = sanitize_text_field( $data['wpinv_discount'] );
366 366
         
367
-        $ip             = $invoice->get_ip() ? $invoice->get_ip() : wpinv_get_ip();
367
+        $ip = $invoice->get_ip() ? $invoice->get_ip() : wpinv_get_ip();
368 368
         
369
-        $invoice->set( 'due_date', $due_date );
370
-        $invoice->set( 'first_name', $first_name );
371
-        $invoice->set( 'last_name', $last_name );
372
-        $invoice->set( 'company', $company );
373
-        $invoice->set( 'vat_number', $vat_number );
374
-        $invoice->set( 'phone', $phone );
375
-        $invoice->set( 'address', $address );
376
-        $invoice->set( 'city', $city );
377
-        $invoice->set( 'zip', $zip );
378
-        $invoice->set( 'country', $country );
379
-        $invoice->set( 'state', $state );
380
-        $invoice->set( 'status', $status );
369
+        $invoice->set('due_date', $due_date);
370
+        $invoice->set('first_name', $first_name);
371
+        $invoice->set('last_name', $last_name);
372
+        $invoice->set('company', $company);
373
+        $invoice->set('vat_number', $vat_number);
374
+        $invoice->set('phone', $phone);
375
+        $invoice->set('address', $address);
376
+        $invoice->set('city', $city);
377
+        $invoice->set('zip', $zip);
378
+        $invoice->set('country', $country);
379
+        $invoice->set('state', $state);
380
+        $invoice->set('status', $status);
381 381
         //$invoice->set( 'number', $number );
382 382
         //$invoice->set( 'discounts', $discounts );
383 383
         //$invoice->set( 'discount', $discount );
384
-        $invoice->set( 'ip', $ip );
384
+        $invoice->set('ip', $ip);
385 385
         $invoice->old_status = $_POST['original_post_status'];
386 386
         $invoice->currency = wpinv_get_currency();
387
-        if ( !empty( $data['wpinv_gateway'] ) ) {
388
-            $invoice->set( 'gateway', sanitize_text_field( $data['wpinv_gateway'] ) );
387
+        if (!empty($data['wpinv_gateway'])) {
388
+            $invoice->set('gateway', sanitize_text_field($data['wpinv_gateway']));
389 389
         }
390 390
         $saved = $invoice->save();
391 391
         
392 392
         // Check for payment notes
393
-        if ( !empty( $data['invoice_note'] ) ) {
394
-            $note               = wp_kses( $data['invoice_note'], array() );
395
-            $note_type          = sanitize_text_field( $data['invoice_note_type'] );
393
+        if (!empty($data['invoice_note'])) {
394
+            $note               = wp_kses($data['invoice_note'], array());
395
+            $note_type          = sanitize_text_field($data['invoice_note_type']);
396 396
             $is_customer_note   = $note_type == 'customer' ? 1 : 0;
397 397
         
398
-            wpinv_insert_payment_note( $invoice->ID, $note, $is_customer_note );
398
+            wpinv_insert_payment_note($invoice->ID, $note, $is_customer_note);
399 399
         }
400 400
         
401 401
         // Update user address if empty.
402
-        if ( $saved && !empty( $invoice ) ) {
403
-            if ( $user_id = $invoice->get_user_id() ) {
404
-                $user_address = wpinv_get_user_address( $user_id, false );
402
+        if ($saved && !empty($invoice)) {
403
+            if ($user_id = $invoice->get_user_id()) {
404
+                $user_address = wpinv_get_user_address($user_id, false);
405 405
                 
406 406
                 if (empty($user_address['first_name'])) {
407
-                    update_user_meta( $user_id, '_wpinv_first_name', $first_name );
408
-                    update_user_meta( $user_id, '_wpinv_last_name', $last_name );
407
+                    update_user_meta($user_id, '_wpinv_first_name', $first_name);
408
+                    update_user_meta($user_id, '_wpinv_last_name', $last_name);
409 409
                 } else if (empty($user_address['last_name']) && $user_address['first_name'] == $first_name) {
410
-                    update_user_meta( $user_id, '_wpinv_last_name', $last_name );
410
+                    update_user_meta($user_id, '_wpinv_last_name', $last_name);
411 411
                 }
412 412
                 
413 413
                 if (empty($user_address['address']) || empty($user_address['city']) || empty($user_address['state']) || empty($user_address['country'])) {
414
-                    update_user_meta( $user_id, '_wpinv_address', $address );
415
-                    update_user_meta( $user_id, '_wpinv_city', $city );
416
-                    update_user_meta( $user_id, '_wpinv_state', $state );
417
-                    update_user_meta( $user_id, '_wpinv_country', $country );
418
-                    update_user_meta( $user_id, '_wpinv_zip', $zip );
419
-                    update_user_meta( $user_id, '_wpinv_phone', $phone );
414
+                    update_user_meta($user_id, '_wpinv_address', $address);
415
+                    update_user_meta($user_id, '_wpinv_city', $city);
416
+                    update_user_meta($user_id, '_wpinv_state', $state);
417
+                    update_user_meta($user_id, '_wpinv_country', $country);
418
+                    update_user_meta($user_id, '_wpinv_zip', $zip);
419
+                    update_user_meta($user_id, '_wpinv_phone', $phone);
420 420
                 }
421 421
             }
422 422
             
423
-            do_action( 'wpinv_invoice_metabox_saved', $invoice );
423
+            do_action('wpinv_invoice_metabox_saved', $invoice);
424 424
         }
425 425
         
426 426
         return $saved;
Please login to merge, or discard this patch.
includes/admin/wpinv-admin-functions.php 1 patch
Spacing   +189 added lines, -189 removed lines patch added patch discarded remove patch
@@ -7,239 +7,239 @@  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
-function wpinv_columns( $columns ) {
14
+function wpinv_columns($columns) {
15 15
     $columns = array(
16 16
         'cb'                => $columns['cb'],
17
-        'number'            => __( 'Number', 'invoicing' ),
18
-        'customer'          => __( 'Customer', 'invoicing' ),
19
-        'amount'            => __( 'Amount', 'invoicing' ),
20
-        'invoice_date'      => __( 'Date', 'invoicing' ),
21
-        'status'            => __( 'Status', 'invoicing' ),
22
-        'ID'                => __( 'ID', 'invoicing' ),
23
-        'wpi_actions'       => __( 'Actions', 'invoicing' ),
17
+        'number'            => __('Number', 'invoicing'),
18
+        'customer'          => __('Customer', 'invoicing'),
19
+        'amount'            => __('Amount', 'invoicing'),
20
+        'invoice_date'      => __('Date', 'invoicing'),
21
+        'status'            => __('Status', 'invoicing'),
22
+        'ID'                => __('ID', 'invoicing'),
23
+        'wpi_actions'       => __('Actions', 'invoicing'),
24 24
     );
25 25
 
26
-    return apply_filters( 'wpi_invoice_table_columns', $columns );
26
+    return apply_filters('wpi_invoice_table_columns', $columns);
27 27
 }
28
-add_filter( 'manage_wpi_invoice_posts_columns', 'wpinv_columns' );
28
+add_filter('manage_wpi_invoice_posts_columns', 'wpinv_columns');
29 29
 
30
-function wpinv_bulk_actions( $actions ) {
31
-    if ( isset( $actions['edit'] ) ) {
32
-        unset( $actions['edit'] );
30
+function wpinv_bulk_actions($actions) {
31
+    if (isset($actions['edit'])) {
32
+        unset($actions['edit']);
33 33
     }
34 34
 
35 35
     return $actions;
36 36
 }
37
-add_filter( 'bulk_actions-edit-wpi_invoice', 'wpinv_bulk_actions' );
38
-add_filter( 'bulk_actions-edit-wpi_item', 'wpinv_bulk_actions' );
37
+add_filter('bulk_actions-edit-wpi_invoice', 'wpinv_bulk_actions');
38
+add_filter('bulk_actions-edit-wpi_item', 'wpinv_bulk_actions');
39 39
 
40
-function wpinv_sortable_columns( $columns ) {
40
+function wpinv_sortable_columns($columns) {
41 41
     $columns = array(
42
-        'ID'            => array( 'ID', true ),
43
-        'number'        => array( 'number', false ),
44
-        'amount'        => array( 'amount', false ),
45
-        'invoice_date'  => array( 'date', false ),
46
-        'customer'      => array( 'customer', false ),
47
-        'status'        => array( 'status', false ),
42
+        'ID'            => array('ID', true),
43
+        'number'        => array('number', false),
44
+        'amount'        => array('amount', false),
45
+        'invoice_date'  => array('date', false),
46
+        'customer'      => array('customer', false),
47
+        'status'        => array('status', false),
48 48
     );
49 49
     
50
-    return apply_filters( 'wpi_invoice_table_sortable_columns', $columns );
50
+    return apply_filters('wpi_invoice_table_sortable_columns', $columns);
51 51
 }
52
-add_filter( 'manage_edit-wpi_invoice_sortable_columns', 'wpinv_sortable_columns' );
52
+add_filter('manage_edit-wpi_invoice_sortable_columns', 'wpinv_sortable_columns');
53 53
 
54
-add_action( 'manage_wpi_invoice_posts_custom_column', 'wpinv_posts_custom_column');
55
-function wpinv_posts_custom_column( $column_name, $post_id = 0 ) {
54
+add_action('manage_wpi_invoice_posts_custom_column', 'wpinv_posts_custom_column');
55
+function wpinv_posts_custom_column($column_name, $post_id = 0) {
56 56
     global $post, $wpi_invoice;
57 57
     
58
-    if ( empty( $wpi_invoice ) || ( !empty( $wpi_invoice ) && $post->ID != $wpi_invoice->ID ) ) {
59
-        $wpi_invoice = new WPInv_Invoice( $post->ID );
58
+    if (empty($wpi_invoice) || (!empty($wpi_invoice) && $post->ID != $wpi_invoice->ID)) {
59
+        $wpi_invoice = new WPInv_Invoice($post->ID);
60 60
     }
61 61
 
62 62
     $value = NULL;
63 63
     
64
-    switch ( $column_name ) {
64
+    switch ($column_name) {
65 65
         case 'email' :
66
-            $value   = $wpi_invoice->get_email();
66
+            $value = $wpi_invoice->get_email();
67 67
             break;
68 68
         case 'customer' :
69 69
             $customer_name = $wpi_invoice->get_user_full_name();
70
-            $customer_name = $customer_name != '' ? $customer_name : __( 'Customer', 'invoicing' );
71
-            $value = '<a href="' . esc_url( get_edit_user_link( $wpi_invoice->get_user_id() ) ) . '">' . $customer_name . '</a>';
72
-            if ( $email = $wpi_invoice->get_email() ) {
70
+            $customer_name = $customer_name != '' ? $customer_name : __('Customer', 'invoicing');
71
+            $value = '<a href="' . esc_url(get_edit_user_link($wpi_invoice->get_user_id())) . '">' . $customer_name . '</a>';
72
+            if ($email = $wpi_invoice->get_email()) {
73 73
                 $value .= '<br><a class="email" href="mailto:' . $email . '">' . $email . '</a>';
74 74
             }
75 75
             break;
76 76
         case 'amount' :
77
-            echo $wpi_invoice->get_total( true );
77
+            echo $wpi_invoice->get_total(true);
78 78
             break;
79 79
         case 'invoice_date' :
80
-            $date_format = get_option( 'date_format' );
81
-            $time_format = get_option( 'time_format' );
82
-            $date_time_format = $date_format . ' '. $time_format;
80
+            $date_format = get_option('date_format');
81
+            $time_format = get_option('time_format');
82
+            $date_time_format = $date_format . ' ' . $time_format;
83 83
             
84
-            $t_time = get_the_time( $date_time_format );
84
+            $t_time = get_the_time($date_time_format);
85 85
             $m_time = $post->post_date;
86
-            $h_time = mysql2date( $date_format, $m_time );
86
+            $h_time = mysql2date($date_format, $m_time);
87 87
             
88 88
             $value   = '<abbr title="' . $t_time . '">' . $h_time . '</abbr>';
89 89
             break;
90 90
         case 'status' :
91
-            $value   = $wpi_invoice->get_status( true ) . ( $wpi_invoice->is_recurring() && $wpi_invoice->is_parent() ? ' <span class="wpi-suffix">' . __( '(r)', 'invoicing' ) . '</span>' : '' );
92
-            if ( ( $wpi_invoice->is_paid() || $wpi_invoice->is_refunded() ) && $gateway_title = $wpi_invoice->get_gateway_title() ) {
93
-                $value .= '<br><small class="meta gateway">' . wp_sprintf( __( 'Via %s', 'invoicing' ), $gateway_title ) . '</small>';
91
+            $value   = $wpi_invoice->get_status(true) . ($wpi_invoice->is_recurring() && $wpi_invoice->is_parent() ? ' <span class="wpi-suffix">' . __('(r)', 'invoicing') . '</span>' : '');
92
+            if (($wpi_invoice->is_paid() || $wpi_invoice->is_refunded()) && $gateway_title = $wpi_invoice->get_gateway_title()) {
93
+                $value .= '<br><small class="meta gateway">' . wp_sprintf(__('Via %s', 'invoicing'), $gateway_title) . '</small>';
94 94
             }
95 95
             break;
96 96
         case 'number' :
97
-            $edit_link = get_edit_post_link( $post->ID );
98
-            $value = '<a title="' . esc_attr__( 'View Invoice Details', 'invoicing' ) . '" href="' . esc_url( $edit_link ) . '">' . $wpi_invoice->get_number() . '</a>';
97
+            $edit_link = get_edit_post_link($post->ID);
98
+            $value = '<a title="' . esc_attr__('View Invoice Details', 'invoicing') . '" href="' . esc_url($edit_link) . '">' . $wpi_invoice->get_number() . '</a>';
99 99
             break;
100 100
         case 'wpi_actions' :
101 101
             $value = '';
102
-            if ( !empty( $post->post_name ) ) {
103
-                $value .= '<a title="' . esc_attr__( 'Print invoice', 'invoicing' ) . '" href="' . esc_url( get_permalink( $post->ID ) ) . '" class="button ui-tip column-act-btn" title="" target="_blank"><span class="dashicons dashicons-print"><i style="" class="fa fa-print"></i></span></a>';
102
+            if (!empty($post->post_name)) {
103
+                $value .= '<a title="' . esc_attr__('Print invoice', 'invoicing') . '" href="' . esc_url(get_permalink($post->ID)) . '" class="button ui-tip column-act-btn" title="" target="_blank"><span class="dashicons dashicons-print"><i style="" class="fa fa-print"></i></span></a>';
104 104
             }
105 105
             
106
-            if ( $email = $wpi_invoice->get_email() ) {
107
-                $value .= '<a title="' . esc_attr__( 'Send invoice to customer', 'invoicing' ) . '" href="' . esc_url( add_query_arg( array( 'wpi_action' => 'send_invoice', 'invoice_id' => $post->ID ) ) ) . '" class="button ui-tip column-act-btn"><span class="dashicons dashicons-email-alt"></span></a>';
106
+            if ($email = $wpi_invoice->get_email()) {
107
+                $value .= '<a title="' . esc_attr__('Send invoice to customer', 'invoicing') . '" href="' . esc_url(add_query_arg(array('wpi_action' => 'send_invoice', 'invoice_id' => $post->ID))) . '" class="button ui-tip column-act-btn"><span class="dashicons dashicons-email-alt"></span></a>';
108 108
             }
109 109
             
110 110
             break;
111 111
         default:
112
-            $value = isset( $post->$column_name ) ? $post->$column_name : '';
112
+            $value = isset($post->$column_name) ? $post->$column_name : '';
113 113
             break;
114 114
 
115 115
     }
116
-    $value = apply_filters( 'wpinv_payments_table_column', $value, $post->ID, $column_name );
116
+    $value = apply_filters('wpinv_payments_table_column', $value, $post->ID, $column_name);
117 117
     
118
-    if ( $value !== NULL ) {
118
+    if ($value !== NULL) {
119 119
         echo $value;
120 120
     }
121 121
 }
122 122
 
123
-function wpinv_admin_post_id( $id = 0 ) {
123
+function wpinv_admin_post_id($id = 0) {
124 124
     global $post;
125 125
 
126
-    if ( isset( $id ) && ! empty( $id ) ) {
126
+    if (isset($id) && !empty($id)) {
127 127
         return (int)$id;
128
-    } else if ( get_the_ID() ) {
129
-        return (int) get_the_ID();
130
-    } else if ( isset( $post->ID ) && !empty( $post->ID ) ) {
131
-        return (int) $post->ID;
132
-    } else if ( isset( $_GET['post'] ) && !empty( $_GET['post'] ) ) {
133
-        return (int) $_GET['post'];
134
-    } else if ( isset( $_GET['id'] ) && !empty( $_GET['id'] ) ) {
135
-        return (int) $_GET['id'];
136
-    } else if ( isset( $_POST['id'] ) && !empty( $_POST['id'] ) ) {
137
-        return (int) $_POST['id'];
128
+    } else if (get_the_ID()) {
129
+        return (int)get_the_ID();
130
+    } else if (isset($post->ID) && !empty($post->ID)) {
131
+        return (int)$post->ID;
132
+    } else if (isset($_GET['post']) && !empty($_GET['post'])) {
133
+        return (int)$_GET['post'];
134
+    } else if (isset($_GET['id']) && !empty($_GET['id'])) {
135
+        return (int)$_GET['id'];
136
+    } else if (isset($_POST['id']) && !empty($_POST['id'])) {
137
+        return (int)$_POST['id'];
138 138
     } 
139 139
 
140 140
     return null;
141 141
 }
142 142
     
143
-function wpinv_admin_post_type( $id = 0 ) {
144
-    if ( !$id ) {
143
+function wpinv_admin_post_type($id = 0) {
144
+    if (!$id) {
145 145
         $id = wpinv_admin_post_id();
146 146
     }
147 147
     
148
-    $type = get_post_type( $id );
148
+    $type = get_post_type($id);
149 149
     
150
-    if ( !$type ) {
151
-        $type = isset( $_GET['post_type'] ) && !empty( $_GET['post_type'] ) ? $_GET['post_type'] : null;
150
+    if (!$type) {
151
+        $type = isset($_GET['post_type']) && !empty($_GET['post_type']) ? $_GET['post_type'] : null;
152 152
     }
153 153
     
154
-    return apply_filters( 'wpinv_admin_post_type', $type, $id );
154
+    return apply_filters('wpinv_admin_post_type', $type, $id);
155 155
 }
156 156
 
157 157
 function wpinv_admin_messages() {
158 158
 	global $wpinv_options, $pagenow, $post;
159 159
 
160
-	if ( isset( $_GET['wpinv-message'] ) && 'discount_added' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
161
-		 add_settings_error( 'wpinv-notices', 'wpinv-discount-added', __( 'Discount code added.', 'invoicing' ), 'updated' );
160
+	if (isset($_GET['wpinv-message']) && 'discount_added' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
161
+		 add_settings_error('wpinv-notices', 'wpinv-discount-added', __('Discount code added.', 'invoicing'), 'updated');
162 162
 	}
163 163
 
164
-	if ( isset( $_GET['wpinv-message'] ) && 'discount_add_failed' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
165
-		add_settings_error( 'wpinv-notices', 'wpinv-discount-add-fail', __( 'There was a problem adding your discount code, please try again.', 'invoicing' ), 'error' );
164
+	if (isset($_GET['wpinv-message']) && 'discount_add_failed' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
165
+		add_settings_error('wpinv-notices', 'wpinv-discount-add-fail', __('There was a problem adding your discount code, please try again.', 'invoicing'), 'error');
166 166
 	}
167 167
 
168
-	if ( isset( $_GET['wpinv-message'] ) && 'discount_exists' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
169
-		add_settings_error( 'wpinv-notices', 'wpinv-discount-exists', __( 'A discount with that code already exists, please use a different code.', 'invoicing' ), 'error' );
168
+	if (isset($_GET['wpinv-message']) && 'discount_exists' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
169
+		add_settings_error('wpinv-notices', 'wpinv-discount-exists', __('A discount with that code already exists, please use a different code.', 'invoicing'), 'error');
170 170
 	}
171 171
 
172
-	if ( isset( $_GET['wpinv-message'] ) && 'discount_updated' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
173
-		 add_settings_error( 'wpinv-notices', 'wpinv-discount-updated', __( 'Discount code updated.', 'invoicing' ), 'updated' );
172
+	if (isset($_GET['wpinv-message']) && 'discount_updated' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
173
+		 add_settings_error('wpinv-notices', 'wpinv-discount-updated', __('Discount code updated.', 'invoicing'), 'updated');
174 174
 	}
175 175
 
176
-	if ( isset( $_GET['wpinv-message'] ) && 'discount_update_failed' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
177
-		add_settings_error( 'wpinv-notices', 'wpinv-discount-updated-fail', __( 'There was a problem updating your discount code, please try again.', 'invoicing' ), 'error' );
176
+	if (isset($_GET['wpinv-message']) && 'discount_update_failed' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
177
+		add_settings_error('wpinv-notices', 'wpinv-discount-updated-fail', __('There was a problem updating your discount code, please try again.', 'invoicing'), 'error');
178 178
 	}
179 179
 
180
-	if ( isset( $_GET['wpinv-message'] ) && 'invoice_deleted' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
181
-		add_settings_error( 'wpinv-notices', 'wpinv-deleted', __( 'The invoice has been deleted.', 'invoicing' ), 'updated' );
180
+	if (isset($_GET['wpinv-message']) && 'invoice_deleted' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
181
+		add_settings_error('wpinv-notices', 'wpinv-deleted', __('The invoice has been deleted.', 'invoicing'), 'updated');
182 182
 	}
183 183
 
184
-	if ( isset( $_GET['wpinv-message'] ) && 'email_sent' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
185
-		add_settings_error( 'wpinv-notices', 'wpinv-sent', __( 'The email has been sent to customer.', 'invoicing' ), 'updated' );
184
+	if (isset($_GET['wpinv-message']) && 'email_sent' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
185
+		add_settings_error('wpinv-notices', 'wpinv-sent', __('The email has been sent to customer.', 'invoicing'), 'updated');
186 186
     }
187 187
     
188
-    if ( isset( $_GET['wpinv-message'] ) && 'email_fail' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
189
-		add_settings_error( 'wpinv-notices', 'wpinv-sent-fail', __( 'Fail to send email to the customer.', 'invoicing' ), 'error' );
188
+    if (isset($_GET['wpinv-message']) && 'email_fail' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
189
+		add_settings_error('wpinv-notices', 'wpinv-sent-fail', __('Fail to send email to the customer.', 'invoicing'), 'error');
190 190
     }
191 191
 
192
-    if ( isset( $_GET['wpinv-message'] ) && 'invoice-note-deleted' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
193
-        add_settings_error( 'wpinv-notices', 'wpinv-note-deleted', __( 'The invoice note has been deleted.', 'invoicing' ), 'updated' );
192
+    if (isset($_GET['wpinv-message']) && 'invoice-note-deleted' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
193
+        add_settings_error('wpinv-notices', 'wpinv-note-deleted', __('The invoice note has been deleted.', 'invoicing'), 'updated');
194 194
     }
195 195
 
196
-	if ( isset( $_GET['wpinv-message'] ) && 'settings-imported' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
197
-		add_settings_error( 'wpinv-notices', 'wpinv-settings-imported', __( 'The settings have been imported.', 'invoicing' ), 'updated' );
196
+	if (isset($_GET['wpinv-message']) && 'settings-imported' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
197
+		add_settings_error('wpinv-notices', 'wpinv-settings-imported', __('The settings have been imported.', 'invoicing'), 'updated');
198 198
 	}
199 199
 
200
-	if ( isset( $_GET['wpinv-message'] ) && 'note-added' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
201
-		add_settings_error( 'wpinv-notices', 'wpinv-note-added', __( 'The invoice note has been added successfully.', 'invoicing' ), 'updated' );
200
+	if (isset($_GET['wpinv-message']) && 'note-added' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
201
+		add_settings_error('wpinv-notices', 'wpinv-note-added', __('The invoice note has been added successfully.', 'invoicing'), 'updated');
202 202
 	}
203 203
 
204
-	if ( isset( $_GET['wpinv-message'] ) && 'invoice-updated' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
205
-		add_settings_error( 'wpinv-notices', 'wpinv-updated', __( 'The invoice has been successfully updated.', 'invoicing' ), 'updated' );
204
+	if (isset($_GET['wpinv-message']) && 'invoice-updated' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
205
+		add_settings_error('wpinv-notices', 'wpinv-updated', __('The invoice has been successfully updated.', 'invoicing'), 'updated');
206 206
 	}
207 207
     
208
-	if ( $pagenow == 'post.php' && !empty( $post->post_type ) && $post->post_type == 'wpi_item' && !wpinv_item_is_editable( $post ) ) {
209
-		$message = apply_filters( 'wpinv_item_non_editable_message', __( 'This item in not editable.', 'invoicing' ), $post->ID );
208
+	if ($pagenow == 'post.php' && !empty($post->post_type) && $post->post_type == 'wpi_item' && !wpinv_item_is_editable($post)) {
209
+		$message = apply_filters('wpinv_item_non_editable_message', __('This item in not editable.', 'invoicing'), $post->ID);
210 210
 
211
-		if ( !empty( $message ) ) {
212
-			add_settings_error( 'wpinv-notices', 'wpinv-edit-n', $message, 'updated' );
211
+		if (!empty($message)) {
212
+			add_settings_error('wpinv-notices', 'wpinv-edit-n', $message, 'updated');
213 213
 		}
214 214
 	}
215 215
 
216
-	settings_errors( 'wpinv-notices' );
216
+	settings_errors('wpinv-notices');
217 217
 }
218
-add_action( 'admin_notices', 'wpinv_admin_messages' );
218
+add_action('admin_notices', 'wpinv_admin_messages');
219 219
 
220
-function wpinv_items_columns( $existing_columns ) {
220
+function wpinv_items_columns($existing_columns) {
221 221
     global $wpinv_euvat;
222 222
     
223 223
     $columns                = array();
224 224
     $columns['cb']          = $existing_columns['cb'];
225
-    $columns['title']       = __( 'Title', 'invoicing' );
226
-    $columns['price']       = __( 'Price', 'invoicing' );
227
-    if ( $wpinv_euvat->allow_vat_rules() ) {
228
-        $columns['vat_rule']    = __( 'VAT rule type', 'invoicing' );
225
+    $columns['title']       = __('Title', 'invoicing');
226
+    $columns['price']       = __('Price', 'invoicing');
227
+    if ($wpinv_euvat->allow_vat_rules()) {
228
+        $columns['vat_rule']    = __('VAT rule type', 'invoicing');
229 229
     }
230
-    if ( $wpinv_euvat->allow_vat_classes() ) {
231
-        $columns['vat_class']   = __( 'VAT class', 'invoicing' );
230
+    if ($wpinv_euvat->allow_vat_classes()) {
231
+        $columns['vat_class']   = __('VAT class', 'invoicing');
232 232
     }
233
-    $columns['type']        = __( 'Type', 'invoicing' );
234
-    $columns['recurring']   = __( 'Recurring', 'invoicing' );
235
-    $columns['date']        = __( 'Date', 'invoicing' );
236
-    $columns['id']          = __( 'ID', 'invoicing' );
233
+    $columns['type']        = __('Type', 'invoicing');
234
+    $columns['recurring']   = __('Recurring', 'invoicing');
235
+    $columns['date']        = __('Date', 'invoicing');
236
+    $columns['id']          = __('ID', 'invoicing');
237 237
 
238
-    return apply_filters( 'wpinv_items_columns', $columns );
238
+    return apply_filters('wpinv_items_columns', $columns);
239 239
 }
240
-add_filter( 'manage_wpi_item_posts_columns', 'wpinv_items_columns' );
240
+add_filter('manage_wpi_item_posts_columns', 'wpinv_items_columns');
241 241
 
242
-function wpinv_items_sortable_columns( $columns ) {
242
+function wpinv_items_sortable_columns($columns) {
243 243
     $columns['price']       = 'price';
244 244
     $columns['vat_rule']    = 'vat_rule';
245 245
     $columns['vat_class']   = 'vat_class';
@@ -249,156 +249,156 @@  discard block
 block discarded – undo
249 249
 
250 250
     return $columns;
251 251
 }
252
-add_filter( 'manage_edit-wpi_item_sortable_columns', 'wpinv_items_sortable_columns' );
252
+add_filter('manage_edit-wpi_item_sortable_columns', 'wpinv_items_sortable_columns');
253 253
 
254
-function wpinv_items_table_custom_column( $column ) {
254
+function wpinv_items_table_custom_column($column) {
255 255
     global $wpinv_euvat, $post, $wpi_item;
256 256
     
257
-    if ( empty( $wpi_item ) || ( !empty( $wpi_item ) && $post->ID != $wpi_item->ID ) ) {
258
-        $wpi_item = new WPInv_Item( $post->ID );
257
+    if (empty($wpi_item) || (!empty($wpi_item) && $post->ID != $wpi_item->ID)) {
258
+        $wpi_item = new WPInv_Item($post->ID);
259 259
     }
260 260
 
261
-    switch ( $column ) {
261
+    switch ($column) {
262 262
         case 'price' :
263
-            echo wpinv_item_price( $post->ID );
263
+            echo wpinv_item_price($post->ID);
264 264
         break;
265 265
         case 'vat_rule' :
266
-            echo $wpinv_euvat->item_rule_label( $post->ID );
266
+            echo $wpinv_euvat->item_rule_label($post->ID);
267 267
         break;
268 268
         case 'vat_class' :
269
-            echo $wpinv_euvat->item_class_label( $post->ID );
269
+            echo $wpinv_euvat->item_class_label($post->ID);
270 270
         break;
271 271
         case 'type' :
272
-            echo wpinv_item_type( $post->ID ) . '<span class="meta">' . $wpi_item->get_custom_singular_name() . '</span>';
272
+            echo wpinv_item_type($post->ID) . '<span class="meta">' . $wpi_item->get_custom_singular_name() . '</span>';
273 273
         break;
274 274
         case 'recurring' :
275
-            echo ( wpinv_is_recurring_item( $post->ID ) ? '<i class="fa fa-check fa-recurring-y"></i>' : '<i class="fa fa-close fa-recurring-n"></i>' );
275
+            echo (wpinv_is_recurring_item($post->ID) ? '<i class="fa fa-check fa-recurring-y"></i>' : '<i class="fa fa-close fa-recurring-n"></i>');
276 276
         break;
277 277
         case 'id' :
278 278
            echo $post->ID;
279 279
            echo '<div class="hidden" id="wpinv_inline-' . $post->ID . '">
280
-                    <div class="price">' . wpinv_get_item_price( $post->ID ) . '</div>';
281
-                    if ( $wpinv_euvat->allow_vat_rules() ) {
282
-                        echo '<div class="vat_rule">' . $wpinv_euvat->get_item_rule( $post->ID ) . '</div>';
280
+                    <div class="price">' . wpinv_get_item_price($post->ID) . '</div>';
281
+                    if ($wpinv_euvat->allow_vat_rules()) {
282
+                        echo '<div class="vat_rule">' . $wpinv_euvat->get_item_rule($post->ID) . '</div>';
283 283
                     }
284
-                    if ( $wpinv_euvat->allow_vat_classes() ) {
285
-                        echo '<div class="vat_class">' . $wpinv_euvat->get_item_class( $post->ID ) . '</div>';
284
+                    if ($wpinv_euvat->allow_vat_classes()) {
285
+                        echo '<div class="vat_class">' . $wpinv_euvat->get_item_class($post->ID) . '</div>';
286 286
                     }
287
-                    echo '<div class="type">' . wpinv_get_item_type( $post->ID ) . '</div>
287
+                    echo '<div class="type">' . wpinv_get_item_type($post->ID) . '</div>
288 288
                 </div>';
289 289
         break;
290 290
     }
291 291
     
292
-    do_action( 'wpinv_items_table_column_item_' . $column, $wpi_item, $post );
292
+    do_action('wpinv_items_table_column_item_' . $column, $wpi_item, $post);
293 293
 }
294
-add_action( 'manage_wpi_item_posts_custom_column', 'wpinv_items_table_custom_column' );
294
+add_action('manage_wpi_item_posts_custom_column', 'wpinv_items_table_custom_column');
295 295
 
296 296
 function wpinv_add_items_filters() {
297 297
     global $wpinv_euvat, $typenow;
298 298
 
299 299
     // Checks if the current post type is 'item'
300
-    if ( $typenow == 'wpi_item') {
301
-        if ( $wpinv_euvat->allow_vat_rules() ) {
302
-            echo wpinv_html_select( array(
303
-                    'options'          => array_merge( array( '' => __( 'All VAT rules', 'invoicing' ) ), $wpinv_euvat->get_rules() ),
300
+    if ($typenow == 'wpi_item') {
301
+        if ($wpinv_euvat->allow_vat_rules()) {
302
+            echo wpinv_html_select(array(
303
+                    'options'          => array_merge(array('' => __('All VAT rules', 'invoicing')), $wpinv_euvat->get_rules()),
304 304
                     'name'             => 'vat_rule',
305 305
                     'id'               => 'vat_rule',
306
-                    'selected'         => ( isset( $_GET['vat_rule'] ) ? $_GET['vat_rule'] : '' ),
306
+                    'selected'         => (isset($_GET['vat_rule']) ? $_GET['vat_rule'] : ''),
307 307
                     'show_option_all'  => false,
308 308
                     'show_option_none' => false,
309 309
                     'class'            => 'gdmbx2-text-medium',
310
-                ) );
310
+                ));
311 311
         }
312 312
         
313
-        if ( $wpinv_euvat->allow_vat_classes() ) {
314
-            echo wpinv_html_select( array(
315
-                    'options'          => array_merge( array( '' => __( 'All VAT classes', 'invoicing' ) ), $wpinv_euvat->get_all_classes() ),
313
+        if ($wpinv_euvat->allow_vat_classes()) {
314
+            echo wpinv_html_select(array(
315
+                    'options'          => array_merge(array('' => __('All VAT classes', 'invoicing')), $wpinv_euvat->get_all_classes()),
316 316
                     'name'             => 'vat_class',
317 317
                     'id'               => 'vat_class',
318
-                    'selected'         => ( isset( $_GET['vat_class'] ) ? $_GET['vat_class'] : '' ),
318
+                    'selected'         => (isset($_GET['vat_class']) ? $_GET['vat_class'] : ''),
319 319
                     'show_option_all'  => false,
320 320
                     'show_option_none' => false,
321 321
                     'class'            => 'gdmbx2-text-medium',
322
-                ) );
322
+                ));
323 323
         }
324 324
             
325
-        echo wpinv_html_select( array(
326
-                'options'          => array_merge( array( '' => __( 'All item types', 'invoicing' ) ), wpinv_get_item_types() ),
325
+        echo wpinv_html_select(array(
326
+                'options'          => array_merge(array('' => __('All item types', 'invoicing')), wpinv_get_item_types()),
327 327
                 'name'             => 'type',
328 328
                 'id'               => 'type',
329
-                'selected'         => ( isset( $_GET['type'] ) ? $_GET['type'] : '' ),
329
+                'selected'         => (isset($_GET['type']) ? $_GET['type'] : ''),
330 330
                 'show_option_all'  => false,
331 331
                 'show_option_none' => false,
332 332
                 'class'            => 'gdmbx2-text-medium',
333
-            ) );
333
+            ));
334 334
 
335
-        if ( isset( $_REQUEST['all_posts'] ) && '1' === $_REQUEST['all_posts'] ) {
335
+        if (isset($_REQUEST['all_posts']) && '1' === $_REQUEST['all_posts']) {
336 336
             echo '<input type="hidden" name="all_posts" value="1" />';
337 337
         }
338 338
     }
339 339
 }
340
-add_action( 'restrict_manage_posts', 'wpinv_add_items_filters', 100 );
340
+add_action('restrict_manage_posts', 'wpinv_add_items_filters', 100);
341 341
 
342
-function wpinv_send_invoice_after_save( $post_id ) {
342
+function wpinv_send_invoice_after_save($post_id) {
343 343
     // If this is just a revision, don't send the email.
344
-    if ( wp_is_post_revision( $post_id ) ) {
344
+    if (wp_is_post_revision($post_id)) {
345 345
         return;
346 346
     }
347 347
     
348
-    if ( !current_user_can( 'manage_options' ) || !('wpi_invoice' == get_post_type( $post_id ))  ) {
348
+    if (!current_user_can('manage_options') || !('wpi_invoice' == get_post_type($post_id))) {
349 349
         return;
350 350
     }
351 351
     
352
-    if ( !empty( $_POST['wpi_save_send'] ) ) {
353
-        wpinv_user_invoice_notification( $post_id );
352
+    if (!empty($_POST['wpi_save_send'])) {
353
+        wpinv_user_invoice_notification($post_id);
354 354
     }
355 355
 }
356
-add_action( 'save_post_wpi_invoice', 'wpinv_send_invoice_after_save', 100, 1 );
356
+add_action('save_post_wpi_invoice', 'wpinv_send_invoice_after_save', 100, 1);
357 357
 
358
-function wpinv_send_register_new_user( $data, $postarr ) {
359
-    if ( current_user_can( 'manage_options' ) && !empty( $data['post_type'] ) && ( 'wpi_invoice' == $data['post_type'] || 'wpi_quote' == $data['post_type'] ) ) {
360
-        $is_new_user = !empty( $postarr['wpinv_new_user'] ) ? true : false;
361
-        $email = !empty( $postarr['wpinv_email'] ) && $postarr['wpinv_email'] && is_email( $postarr['wpinv_email'] ) ? $postarr['wpinv_email'] : NULL;
358
+function wpinv_send_register_new_user($data, $postarr) {
359
+    if (current_user_can('manage_options') && !empty($data['post_type']) && ('wpi_invoice' == $data['post_type'] || 'wpi_quote' == $data['post_type'])) {
360
+        $is_new_user = !empty($postarr['wpinv_new_user']) ? true : false;
361
+        $email = !empty($postarr['wpinv_email']) && $postarr['wpinv_email'] && is_email($postarr['wpinv_email']) ? $postarr['wpinv_email'] : NULL;
362 362
         
363
-        if ( $is_new_user && $email && !email_exists( $email ) ) {
364
-            $first_name = !empty( $postarr['wpinv_first_name'] ) ? sanitize_text_field( $postarr['wpinv_first_name'] ) : '';
365
-            $last_name = !empty( $postarr['wpinv_last_name'] ) ? sanitize_text_field( $postarr['wpinv_last_name'] ) : '';
366
-            $display_name = $first_name || $last_name ? trim( $first_name . ' ' . $last_name ) : '';
367
-            $user_nicename = $display_name ? trim( $display_name ) : $email;
368
-            $user_company = !empty( $postarr['wpinv_company'] ) ? sanitize_text_field( $postarr['wpinv_company'] ) : '';
363
+        if ($is_new_user && $email && !email_exists($email)) {
364
+            $first_name = !empty($postarr['wpinv_first_name']) ? sanitize_text_field($postarr['wpinv_first_name']) : '';
365
+            $last_name = !empty($postarr['wpinv_last_name']) ? sanitize_text_field($postarr['wpinv_last_name']) : '';
366
+            $display_name = $first_name || $last_name ? trim($first_name . ' ' . $last_name) : '';
367
+            $user_nicename = $display_name ? trim($display_name) : $email;
368
+            $user_company = !empty($postarr['wpinv_company']) ? sanitize_text_field($postarr['wpinv_company']) : '';
369 369
             
370
-            $user_login = sanitize_user( str_replace( ' ', '', $display_name ), true );
371
-            if ( !( validate_username( $user_login ) && !username_exists( $user_login ) ) ) {
370
+            $user_login = sanitize_user(str_replace(' ', '', $display_name), true);
371
+            if (!(validate_username($user_login) && !username_exists($user_login))) {
372 372
                 $new_user_login = strstr($email, '@', true);
373
-                if ( validate_username( $user_login ) && username_exists( $user_login ) ) {
374
-                    $user_login = sanitize_user($new_user_login, true );
373
+                if (validate_username($user_login) && username_exists($user_login)) {
374
+                    $user_login = sanitize_user($new_user_login, true);
375 375
                 }
376
-                if ( validate_username( $user_login ) && username_exists( $user_login ) ) {
377
-                    $user_append_text = rand(10,1000);
378
-                    $user_login = sanitize_user($new_user_login.$user_append_text, true );
376
+                if (validate_username($user_login) && username_exists($user_login)) {
377
+                    $user_append_text = rand(10, 1000);
378
+                    $user_login = sanitize_user($new_user_login . $user_append_text, true);
379 379
                 }
380 380
                 
381
-                if ( !( validate_username( $user_login ) && !username_exists( $user_login ) ) ) {
381
+                if (!(validate_username($user_login) && !username_exists($user_login))) {
382 382
                     $user_login = $email;
383 383
                 }
384 384
             }
385 385
             
386 386
             $userdata = array(
387 387
                 'user_login' => $user_login,
388
-                'user_pass' => wp_generate_password( 12, false ),
389
-                'user_email' => sanitize_text_field( $email ),
388
+                'user_pass' => wp_generate_password(12, false),
389
+                'user_email' => sanitize_text_field($email),
390 390
                 'first_name' => $first_name,
391 391
                 'last_name' => $last_name,
392
-                'user_nicename' => wpinv_utf8_substr( $user_nicename, 0, 50 ),
392
+                'user_nicename' => wpinv_utf8_substr($user_nicename, 0, 50),
393 393
                 'nickname' => $display_name,
394 394
                 'display_name' => $display_name,
395 395
             );
396 396
 
397
-            $userdata = apply_filters( 'wpinv_register_new_user_data', $userdata );
397
+            $userdata = apply_filters('wpinv_register_new_user_data', $userdata);
398 398
             
399
-            $new_user_id = wp_insert_user( $userdata );
399
+            $new_user_id = wp_insert_user($userdata);
400 400
             
401
-            if ( !is_wp_error( $new_user_id ) ) {
401
+            if (!is_wp_error($new_user_id)) {
402 402
                 $data['post_author'] = $new_user_id;
403 403
                 $_POST['post_author'] = $new_user_id;
404 404
                 $_POST['post_author_override'] = $new_user_id;
@@ -419,27 +419,27 @@  discard block
 block discarded – undo
419 419
                 
420 420
                 $meta = array();
421 421
                 ///$meta['_wpinv_user_id'] = $new_user_id;
422
-                foreach ( $meta_fields as $field ) {
423
-                    $meta['_wpinv_' . $field] = isset( $postarr['wpinv_' . $field] ) ? sanitize_text_field( $postarr['wpinv_' . $field] ) : '';
422
+                foreach ($meta_fields as $field) {
423
+                    $meta['_wpinv_' . $field] = isset($postarr['wpinv_' . $field]) ? sanitize_text_field($postarr['wpinv_' . $field]) : '';
424 424
                 }
425 425
                 
426
-                $meta = apply_filters( 'wpinv_register_new_user_meta', $meta, $new_user_id );
426
+                $meta = apply_filters('wpinv_register_new_user_meta', $meta, $new_user_id);
427 427
 
428 428
                 // Update user meta.
429
-                foreach ( $meta as $key => $value ) {
430
-                    update_user_meta( $new_user_id, $key, $value );
429
+                foreach ($meta as $key => $value) {
430
+                    update_user_meta($new_user_id, $key, $value);
431 431
                 }
432 432
                 
433
-                if ( function_exists( 'wp_send_new_user_notifications' ) ) {
433
+                if (function_exists('wp_send_new_user_notifications')) {
434 434
                     // Send email notifications related to the creation of new user.
435
-                    wp_send_new_user_notifications( $new_user_id, 'user' );
435
+                    wp_send_new_user_notifications($new_user_id, 'user');
436 436
                 }
437 437
             } else {
438
-                wpinv_error_log( $new_user_id->get_error_message(), 'Invoice add new user', __FILE__, __LINE__ );
438
+                wpinv_error_log($new_user_id->get_error_message(), 'Invoice add new user', __FILE__, __LINE__);
439 439
             }
440 440
         }
441 441
     }
442 442
     
443 443
     return $data;
444 444
 }
445
-add_filter( 'wp_insert_post_data', 'wpinv_send_register_new_user', 10, 2 );
446 445
\ No newline at end of file
446
+add_filter('wp_insert_post_data', 'wpinv_send_register_new_user', 10, 2);
447 447
\ No newline at end of file
Please login to merge, or discard this patch.
includes/libraries/wpinv-euvat/class-wpinv-euvat.php 1 patch
Spacing   +710 added lines, -710 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // Exit if accessed directly.
3
-if (!defined( 'ABSPATH' ) ) exit;
3
+if (!defined('ABSPATH')) exit;
4 4
 
5 5
 class WPInv_EUVat {
6 6
     private static $is_ajax = false;
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
     private static $instance = false;
9 9
     
10 10
     public static function get_instance() {
11
-        if ( !self::$instance ) {
11
+        if (!self::$instance) {
12 12
             self::$instance = new self();
13 13
             self::$instance->actions();
14 14
         }
@@ -17,132 +17,132 @@  discard block
 block discarded – undo
17 17
     }
18 18
     
19 19
     public function __construct() {
20
-        self::$is_ajax          = defined( 'DOING_AJAX' ) && DOING_AJAX;
20
+        self::$is_ajax          = defined('DOING_AJAX') && DOING_AJAX;
21 21
         self::$default_country  = wpinv_get_default_country();
22 22
     }
23 23
     
24 24
     public static function actions() {
25
-        if ( is_admin() ) {
26
-            add_action( 'admin_enqueue_scripts', array( self::$instance, 'enqueue_admin_scripts' ) );
27
-            add_action( 'wpinv_settings_sections_taxes', array( self::$instance, 'section_vat_settings' ) ); 
28
-            add_action( 'wpinv_settings_taxes', array( self::$instance, 'vat_settings' ) );
29
-            add_filter( 'wpinv_settings_taxes-vat_sanitize', array( self::$instance, 'sanitize_vat_settings' ) );
30
-            add_filter( 'wpinv_settings_taxes-vat_rates_sanitize', array( self::$instance, 'sanitize_vat_rates' ) );
31
-            add_action( 'wp_ajax_wpinv_add_vat_class', array( self::$instance, 'add_class' ) );
32
-            add_action( 'wp_ajax_nopriv_wpinv_add_vat_class', array( self::$instance, 'add_class' ) );
33
-            add_action( 'wp_ajax_wpinv_delete_vat_class', array( self::$instance, 'delete_class' ) );
34
-            add_action( 'wp_ajax_nopriv_wpinv_delete_vat_class', array( self::$instance, 'delete_class' ) );
35
-            add_action( 'wp_ajax_wpinv_update_vat_rates', array( self::$instance, 'update_eu_rates' ) );
36
-            add_action( 'wp_ajax_nopriv_wpinv_update_vat_rates', array( self::$instance, 'update_eu_rates' ) );
37
-            add_action( 'wp_ajax_wpinv_geoip2', array( self::$instance, 'geoip2_download_database' ) );
38
-            add_action( 'wp_ajax_nopriv_wpinv_geoip2', array( self::$instance, 'geoip2_download_database' ) );
39
-        }
40
-        
41
-        add_action( 'wp_enqueue_scripts', array( self::$instance, 'enqueue_vat_scripts' ) );
42
-        add_filter( 'wpinv_default_billing_country', array( self::$instance, 'get_user_country' ), 10 );
43
-        add_filter( 'wpinv_get_user_country', array( self::$instance, 'set_user_country' ), 10 );
44
-        add_action( 'wp_ajax_wpinv_vat_validate', array( self::$instance, 'ajax_vat_validate' ) );
45
-        add_action( 'wp_ajax_nopriv_wpinv_vat_validate', array( self::$instance, 'ajax_vat_validate' ) );
46
-        add_action( 'wp_ajax_wpinv_vat_reset', array( self::$instance, 'ajax_vat_reset' ) );
47
-        add_action( 'wp_ajax_nopriv_wpinv_vat_reset', array( self::$instance, 'ajax_vat_reset' ) );
48
-        add_action( 'wpinv_invoice_print_after_line_items', array( self::$instance, 'show_vat_notice' ), 999, 1 );
49
-        if ( wpinv_use_taxes() ) {
50
-            add_action( 'wpinv_after_billing_fields', array( self::$instance, 'checkout_vat_fields' ) );
51
-            if ( self::allow_vat_rules() ) {
52
-                add_action( 'wpinv_checkout_error_checks', array( self::$instance, 'checkout_vat_validate' ), 10, 2 );
53
-                add_filter( 'wpinv_tax_rate', array( self::$instance, 'get_rate' ), 10, 4 );
25
+        if (is_admin()) {
26
+            add_action('admin_enqueue_scripts', array(self::$instance, 'enqueue_admin_scripts'));
27
+            add_action('wpinv_settings_sections_taxes', array(self::$instance, 'section_vat_settings')); 
28
+            add_action('wpinv_settings_taxes', array(self::$instance, 'vat_settings'));
29
+            add_filter('wpinv_settings_taxes-vat_sanitize', array(self::$instance, 'sanitize_vat_settings'));
30
+            add_filter('wpinv_settings_taxes-vat_rates_sanitize', array(self::$instance, 'sanitize_vat_rates'));
31
+            add_action('wp_ajax_wpinv_add_vat_class', array(self::$instance, 'add_class'));
32
+            add_action('wp_ajax_nopriv_wpinv_add_vat_class', array(self::$instance, 'add_class'));
33
+            add_action('wp_ajax_wpinv_delete_vat_class', array(self::$instance, 'delete_class'));
34
+            add_action('wp_ajax_nopriv_wpinv_delete_vat_class', array(self::$instance, 'delete_class'));
35
+            add_action('wp_ajax_wpinv_update_vat_rates', array(self::$instance, 'update_eu_rates'));
36
+            add_action('wp_ajax_nopriv_wpinv_update_vat_rates', array(self::$instance, 'update_eu_rates'));
37
+            add_action('wp_ajax_wpinv_geoip2', array(self::$instance, 'geoip2_download_database'));
38
+            add_action('wp_ajax_nopriv_wpinv_geoip2', array(self::$instance, 'geoip2_download_database'));
39
+        }
40
+        
41
+        add_action('wp_enqueue_scripts', array(self::$instance, 'enqueue_vat_scripts'));
42
+        add_filter('wpinv_default_billing_country', array(self::$instance, 'get_user_country'), 10);
43
+        add_filter('wpinv_get_user_country', array(self::$instance, 'set_user_country'), 10);
44
+        add_action('wp_ajax_wpinv_vat_validate', array(self::$instance, 'ajax_vat_validate'));
45
+        add_action('wp_ajax_nopriv_wpinv_vat_validate', array(self::$instance, 'ajax_vat_validate'));
46
+        add_action('wp_ajax_wpinv_vat_reset', array(self::$instance, 'ajax_vat_reset'));
47
+        add_action('wp_ajax_nopriv_wpinv_vat_reset', array(self::$instance, 'ajax_vat_reset'));
48
+        add_action('wpinv_invoice_print_after_line_items', array(self::$instance, 'show_vat_notice'), 999, 1);
49
+        if (wpinv_use_taxes()) {
50
+            add_action('wpinv_after_billing_fields', array(self::$instance, 'checkout_vat_fields'));
51
+            if (self::allow_vat_rules()) {
52
+                add_action('wpinv_checkout_error_checks', array(self::$instance, 'checkout_vat_validate'), 10, 2);
53
+                add_filter('wpinv_tax_rate', array(self::$instance, 'get_rate'), 10, 4);
54 54
             }
55 55
         }
56 56
     }        
57 57
     
58
-    public static function get_eu_states( $sort = true ) {
59
-        $eu_states = array( 'AT', 'BE', 'BG', 'HR', 'CY', 'CZ', 'DK', 'EE', 'FI', 'FR', 'DE', 'GB', 'GR', 'HU', 'IE', 'IT', 'LV', 'LT', 'LU', 'MT', 'NL', 'PL', 'PT', 'RO', 'SK', 'SI', 'ES', 'SE' );
60
-        if ( $sort ) {
61
-            $sort = sort( $eu_states );
58
+    public static function get_eu_states($sort = true) {
59
+        $eu_states = array('AT', 'BE', 'BG', 'HR', 'CY', 'CZ', 'DK', 'EE', 'FI', 'FR', 'DE', 'GB', 'GR', 'HU', 'IE', 'IT', 'LV', 'LT', 'LU', 'MT', 'NL', 'PL', 'PT', 'RO', 'SK', 'SI', 'ES', 'SE');
60
+        if ($sort) {
61
+            $sort = sort($eu_states);
62 62
         }
63 63
         
64
-        return apply_filters( 'wpinv_get_eu_states', $eu_states, $sort );
64
+        return apply_filters('wpinv_get_eu_states', $eu_states, $sort);
65 65
     }
66 66
     
67
-    public static function get_gst_countries( $sort = true ) {
68
-        $gst_countries  = array( 'AU', 'NZ', 'CA', 'CN' );
67
+    public static function get_gst_countries($sort = true) {
68
+        $gst_countries = array('AU', 'NZ', 'CA', 'CN');
69 69
         
70
-        if ( $sort ) {
71
-            $sort = sort( $gst_countries );
70
+        if ($sort) {
71
+            $sort = sort($gst_countries);
72 72
         }
73 73
         
74
-        return apply_filters( 'wpinv_get_gst_countries', $gst_countries, $sort );
74
+        return apply_filters('wpinv_get_gst_countries', $gst_countries, $sort);
75 75
     }
76 76
     
77
-    public static function is_eu_state( $country_code ) {
78
-        $return = !empty( $country_code ) && in_array( strtoupper( $country_code ), self::get_eu_states() ) ? true : false;
77
+    public static function is_eu_state($country_code) {
78
+        $return = !empty($country_code) && in_array(strtoupper($country_code), self::get_eu_states()) ? true : false;
79 79
                 
80
-        return apply_filters( 'wpinv_is_eu_state', $return, $country_code );
80
+        return apply_filters('wpinv_is_eu_state', $return, $country_code);
81 81
     }
82 82
     
83
-    public static function is_gst_country( $country_code ) {
84
-        $return = !empty( $country_code ) && in_array( strtoupper( $country_code ), self::get_gst_countries() ) ? true : false;
83
+    public static function is_gst_country($country_code) {
84
+        $return = !empty($country_code) && in_array(strtoupper($country_code), self::get_gst_countries()) ? true : false;
85 85
                 
86
-        return apply_filters( 'wpinv_is_gst_country', $return, $country_code );
86
+        return apply_filters('wpinv_is_gst_country', $return, $country_code);
87 87
     }
88 88
     
89 89
     public static function enqueue_vat_scripts() {
90
-        $suffix     = '';//defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
90
+        $suffix = ''; //defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
91 91
         
92
-        wp_register_script( 'wpinv-vat-validation-script', WPINV_PLUGIN_URL . 'assets/js/jsvat' . $suffix . '.js', array( 'jquery' ),  WPINV_VERSION );
93
-        wp_register_script( 'wpinv-vat-script', WPINV_PLUGIN_URL . 'assets/js/euvat' . $suffix . '.js', array( 'jquery' ),  WPINV_VERSION );
92
+        wp_register_script('wpinv-vat-validation-script', WPINV_PLUGIN_URL . 'assets/js/jsvat' . $suffix . '.js', array('jquery'), WPINV_VERSION);
93
+        wp_register_script('wpinv-vat-script', WPINV_PLUGIN_URL . 'assets/js/euvat' . $suffix . '.js', array('jquery'), WPINV_VERSION);
94 94
         
95
-        $vat_name   = self::get_vat_name();
95
+        $vat_name = self::get_vat_name();
96 96
         
97 97
         $vars = array();
98 98
         $vars['UseTaxes'] = wpinv_use_taxes();
99 99
         $vars['EUStates'] = self::get_eu_states();
100
-        $vars['NoRateSet'] = __( 'You have not set a rate. Do you want to continue?', 'invoicing' );
101
-        $vars['EmptyCompany'] = __( 'Please enter your registered company name!', 'invoicing' );
102
-        $vars['EmptyVAT'] = wp_sprintf( __( 'Please enter your %s number!', 'invoicing' ), $vat_name );
103
-        $vars['TotalsRefreshed'] = wp_sprintf( __( 'The invoice totals will be refreshed to update the %s.', 'invoicing' ), $vat_name );
104
-        $vars['ErrValidateVAT'] = wp_sprintf( __( 'Fail to validate the %s number!', 'invoicing' ), $vat_name );
105
-        $vars['ErrResetVAT'] = wp_sprintf( __( 'Fail to reset the %s number!', 'invoicing' ), $vat_name );
106
-        $vars['ErrInvalidVat'] = wp_sprintf( __( 'The %s number supplied does not have a valid format!', 'invoicing' ), $vat_name );
107
-        $vars['ErrInvalidResponse'] = __( 'An invalid response has been received from the server!', 'invoicing' );
100
+        $vars['NoRateSet'] = __('You have not set a rate. Do you want to continue?', 'invoicing');
101
+        $vars['EmptyCompany'] = __('Please enter your registered company name!', 'invoicing');
102
+        $vars['EmptyVAT'] = wp_sprintf(__('Please enter your %s number!', 'invoicing'), $vat_name);
103
+        $vars['TotalsRefreshed'] = wp_sprintf(__('The invoice totals will be refreshed to update the %s.', 'invoicing'), $vat_name);
104
+        $vars['ErrValidateVAT'] = wp_sprintf(__('Fail to validate the %s number!', 'invoicing'), $vat_name);
105
+        $vars['ErrResetVAT'] = wp_sprintf(__('Fail to reset the %s number!', 'invoicing'), $vat_name);
106
+        $vars['ErrInvalidVat'] = wp_sprintf(__('The %s number supplied does not have a valid format!', 'invoicing'), $vat_name);
107
+        $vars['ErrInvalidResponse'] = __('An invalid response has been received from the server!', 'invoicing');
108 108
         $vars['ApplyVATRules'] = $vars['UseTaxes'] ? self::allow_vat_rules() : false;
109 109
         $vars['HideVatFields'] = $vars['ApplyVATRules'] ? self::hide_vat_fields() : true;
110
-        $vars['ErrResponse'] = __( 'The request response is invalid!', 'invoicing' );
111
-        $vars['ErrRateResponse'] = __( 'The get rate request response is invalid', 'invoicing' );
112
-        $vars['PageRefresh'] = __( 'The page will be refreshed in 10 seconds to show the new options.', 'invoicing' );
113
-        $vars['RequestResponseNotValidJSON'] = __( 'The get rate request response is not valid JSON', 'invoicing' );
114
-        $vars['GetRateRequestFailed'] = __( 'The get rate request failed: ', 'invoicing' );
115
-        $vars['NoRateInformationInResponse'] = __( 'The get rate request response does not contain any rate information', 'invoicing' );
116
-        $vars['RatesUpdated'] = __( 'The rates have been updated. Press the save button to record these new rates.', 'invoicing' );
117
-        $vars['IPAddressInformation'] = __( 'IP Address Information', 'invoicing' );
118
-        $vars['VatValidating'] = wp_sprintf( __( 'Validating %s number...', 'invoicing' ), $vat_name );
119
-        $vars['VatReseting'] = __( 'Reseting...', 'invoicing' );
120
-        $vars['VatValidated'] = wp_sprintf( __( '%s number validated', 'invoicing' ), $vat_name );
121
-        $vars['VatNotValidated'] = wp_sprintf( __( '%s number not validated', 'invoicing' ), $vat_name );
122
-        $vars['ConfirmDeleteClass'] = __( 'Are you sure you wish to delete this rates class?', 'invoicing' );
110
+        $vars['ErrResponse'] = __('The request response is invalid!', 'invoicing');
111
+        $vars['ErrRateResponse'] = __('The get rate request response is invalid', 'invoicing');
112
+        $vars['PageRefresh'] = __('The page will be refreshed in 10 seconds to show the new options.', 'invoicing');
113
+        $vars['RequestResponseNotValidJSON'] = __('The get rate request response is not valid JSON', 'invoicing');
114
+        $vars['GetRateRequestFailed'] = __('The get rate request failed: ', 'invoicing');
115
+        $vars['NoRateInformationInResponse'] = __('The get rate request response does not contain any rate information', 'invoicing');
116
+        $vars['RatesUpdated'] = __('The rates have been updated. Press the save button to record these new rates.', 'invoicing');
117
+        $vars['IPAddressInformation'] = __('IP Address Information', 'invoicing');
118
+        $vars['VatValidating'] = wp_sprintf(__('Validating %s number...', 'invoicing'), $vat_name);
119
+        $vars['VatReseting'] = __('Reseting...', 'invoicing');
120
+        $vars['VatValidated'] = wp_sprintf(__('%s number validated', 'invoicing'), $vat_name);
121
+        $vars['VatNotValidated'] = wp_sprintf(__('%s number not validated', 'invoicing'), $vat_name);
122
+        $vars['ConfirmDeleteClass'] = __('Are you sure you wish to delete this rates class?', 'invoicing');
123 123
         $vars['isFront'] = is_admin() ? false : true;
124
-        $vars['checkoutNonce'] = wp_create_nonce( 'wpinv_checkout_nonce' );
124
+        $vars['checkoutNonce'] = wp_create_nonce('wpinv_checkout_nonce');
125 125
         $vars['baseCountry'] = wpinv_get_default_country();
126
-        $vars['disableVATSameCountry'] = ( self::same_country_rule() == 'no' ? true : false );
127
-        $vars['disableVATSimpleCheck'] = wpinv_get_option( 'vat_offline_check' ) ? true : false;
126
+        $vars['disableVATSameCountry'] = (self::same_country_rule() == 'no' ? true : false);
127
+        $vars['disableVATSimpleCheck'] = wpinv_get_option('vat_offline_check') ? true : false;
128 128
         
129
-        wp_enqueue_script( 'wpinv-vat-validation-script' );
130
-        wp_enqueue_script( 'wpinv-vat-script' );
131
-        wp_localize_script( 'wpinv-vat-script', 'WPInv_VAT_Vars', $vars );
129
+        wp_enqueue_script('wpinv-vat-validation-script');
130
+        wp_enqueue_script('wpinv-vat-script');
131
+        wp_localize_script('wpinv-vat-script', 'WPInv_VAT_Vars', $vars);
132 132
     }
133 133
 
134 134
     public static function enqueue_admin_scripts() {
135
-        if( isset( $_GET['page'] ) && 'wpinv-settings' == $_GET['page'] ) {
135
+        if (isset($_GET['page']) && 'wpinv-settings' == $_GET['page']) {
136 136
             self::enqueue_vat_scripts();
137 137
         }
138 138
     }
139 139
     
140
-    public static function section_vat_settings( $sections ) {
141
-        if ( !empty( $sections ) ) {
142
-            $sections['vat'] = __( 'EU VAT Settings', 'invoicing' );
140
+    public static function section_vat_settings($sections) {
141
+        if (!empty($sections)) {
142
+            $sections['vat'] = __('EU VAT Settings', 'invoicing');
143 143
             
144
-            if ( self::allow_vat_classes() ) {
145
-                $sections['vat_rates'] = __( 'EU VAT Rates', 'invoicing' );
144
+            if (self::allow_vat_classes()) {
145
+                $sections['vat_rates'] = __('EU VAT Rates', 'invoicing');
146 146
             }
147 147
         }
148 148
         return $sections;
@@ -151,52 +151,52 @@  discard block
 block discarded – undo
151 151
     public static function vat_rates_settings() {
152 152
         $vat_classes = self::get_rate_classes();
153 153
         $vat_rates = array();
154
-        $vat_class = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' && isset( $vat_classes[$_REQUEST['wpi_sub']] )? sanitize_text_field( $_REQUEST['wpi_sub'] ) : '_new';
155
-        $current_url = remove_query_arg( 'wpi_sub' );
154
+        $vat_class = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' && isset($vat_classes[$_REQUEST['wpi_sub']]) ? sanitize_text_field($_REQUEST['wpi_sub']) : '_new';
155
+        $current_url = remove_query_arg('wpi_sub');
156 156
         
157 157
         $vat_rates['vat_rates_header'] = array(
158 158
             'id' => 'vat_rates_header',
159
-            'name' => '<h3>' . __( 'Manage VAT Rates', 'invoicing' ) . '</h3>',
159
+            'name' => '<h3>' . __('Manage VAT Rates', 'invoicing') . '</h3>',
160 160
             'desc' => '',
161 161
             'type' => 'header',
162 162
             'size' => 'regular'
163 163
         );
164 164
         $vat_rates['vat_rates_class'] = array(
165 165
             'id'          => 'vat_rates_class',
166
-            'name'        => __( 'Edit VAT Rates', 'invoicing' ),
167
-            'desc'        => __( 'The standard rate will apply where no explicit rate is provided.', 'invoicing' ),
166
+            'name'        => __('Edit VAT Rates', 'invoicing'),
167
+            'desc'        => __('The standard rate will apply where no explicit rate is provided.', 'invoicing'),
168 168
             'type'        => 'select',
169
-            'options'     => array_merge( $vat_classes, array( '_new' => __( 'Add New Rate Class', 'invoicing' ) ) ),
169
+            'options'     => array_merge($vat_classes, array('_new' => __('Add New Rate Class', 'invoicing'))),
170 170
             'chosen'      => true,
171
-            'placeholder' => __( 'Select a VAT Rate', 'invoicing' ),
171
+            'placeholder' => __('Select a VAT Rate', 'invoicing'),
172 172
             'selected'    => $vat_class,
173 173
             'onchange'    => 'document.location.href="' . $current_url . '&wpi_sub=" + this.value;',
174 174
         );
175 175
         
176
-        if ( $vat_class != '_standard' && $vat_class != '_new' ) {
176
+        if ($vat_class != '_standard' && $vat_class != '_new') {
177 177
             $vat_rates['vat_rate_delete'] = array(
178 178
                 'id'   => 'vat_rate_delete',
179 179
                 'type' => 'vat_rate_delete',
180 180
             );
181 181
         }
182 182
                     
183
-        if ( $vat_class == '_new' ) {
183
+        if ($vat_class == '_new') {
184 184
             $vat_rates['vat_rates_settings'] = array(
185 185
                 'id' => 'vat_rates_settings',
186
-                'name' => '<h3>' . __( 'Add New Rate Class', 'invoicing' ) . '</h3>',
186
+                'name' => '<h3>' . __('Add New Rate Class', 'invoicing') . '</h3>',
187 187
                 'type' => 'header',
188 188
             );
189 189
             $vat_rates['vat_rate_name'] = array(
190 190
                 'id'   => 'vat_rate_name',
191
-                'name' => __( 'Name', 'invoicing' ),
192
-                'desc' => __( 'A short name for the new VAT Rate class', 'invoicing' ),
191
+                'name' => __('Name', 'invoicing'),
192
+                'desc' => __('A short name for the new VAT Rate class', 'invoicing'),
193 193
                 'type' => 'text',
194 194
                 'size' => 'regular',
195 195
             );
196 196
             $vat_rates['vat_rate_desc'] = array(
197 197
                 'id'   => 'vat_rate_desc',
198
-                'name' => __( 'Description', 'invoicing' ),
199
-                'desc' => __( 'Manage VAT Rate class', 'invoicing' ),
198
+                'name' => __('Description', 'invoicing'),
199
+                'desc' => __('Manage VAT Rate class', 'invoicing'),
200 200
                 'type' => 'text',
201 201
                 'size' => 'regular',
202 202
             );
@@ -208,7 +208,7 @@  discard block
 block discarded – undo
208 208
             $vat_rates['vat_rates'] = array(
209 209
                 'id'   => 'vat_rates',
210 210
                 'name' => '<h3>' . $vat_classes[$vat_class] . '</h3>',
211
-                'desc' => self::get_class_desc( $vat_class ),
211
+                'desc' => self::get_class_desc($vat_class),
212 212
                 'type' => 'vat_rates',
213 213
             );
214 214
         }
@@ -216,12 +216,12 @@  discard block
 block discarded – undo
216 216
         return $vat_rates;
217 217
     }
218 218
     
219
-    public static function vat_settings( $settings ) {
220
-        if ( !empty( $settings ) ) {    
219
+    public static function vat_settings($settings) {
220
+        if (!empty($settings)) {    
221 221
             $vat_settings = array();
222 222
             $vat_settings['vat_company_title'] = array(
223 223
                 'id' => 'vat_company_title',
224
-                'name' => '<h3>' . __( 'Your Company Details', 'invoicing' ) . '</h3>',
224
+                'name' => '<h3>' . __('Your Company Details', 'invoicing') . '</h3>',
225 225
                 'desc' => '',
226 226
                 'type' => 'header',
227 227
                 'size' => 'regular'
@@ -229,22 +229,22 @@  discard block
 block discarded – undo
229 229
             
230 230
             $vat_settings['vat_company_name'] = array(
231 231
                 'id' => 'vat_company_name',
232
-                'name' => __( 'Your Company Name', 'invoicing' ),
233
-                'desc' => wp_sprintf(__( 'Your company name as it appears on your VAT return, you can verify it via your VAT ID on the %sEU VIES System.%s', 'invoicing' ), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>' ),
232
+                'name' => __('Your Company Name', 'invoicing'),
233
+                'desc' => wp_sprintf(__('Your company name as it appears on your VAT return, you can verify it via your VAT ID on the %sEU VIES System.%s', 'invoicing'), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>'),
234 234
                 'type' => 'text',
235 235
                 'size' => 'regular',
236 236
             );
237 237
             
238 238
             $vat_settings['vat_number'] = array(
239 239
                 'id'   => 'vat_number',
240
-                'name' => __( 'Your VAT Number', 'invoicing' ),
240
+                'name' => __('Your VAT Number', 'invoicing'),
241 241
                 'type' => 'vat_number',
242 242
                 'size' => 'regular',
243 243
             );
244 244
 
245 245
             $vat_settings['vat_settings_title'] = array(
246 246
                 'id' => 'vat_settings_title',
247
-                'name' => '<h3>' . __( 'Apply VAT Settings', 'invoicing' ) . '</h3>',
247
+                'name' => '<h3>' . __('Apply VAT Settings', 'invoicing') . '</h3>',
248 248
                 'desc' => '',
249 249
                 'type' => 'header',
250 250
                 'size' => 'regular'
@@ -252,8 +252,8 @@  discard block
 block discarded – undo
252 252
 
253 253
             $vat_settings['apply_vat_rules'] = array(
254 254
                 'id' => 'apply_vat_rules',
255
-                'name' => __( 'Enable VAT Rules', 'invoicing' ),
256
-                'desc' => __( 'Apply VAT to consumer sales from IP addresses within the EU, even if the billing address is outside the EU.', 'invoicing' ) . '<br><font style="color:red">' . __( 'Do not disable unless you know what you are doing.', 'invoicing' ) . '</font>',
255
+                'name' => __('Enable VAT Rules', 'invoicing'),
256
+                'desc' => __('Apply VAT to consumer sales from IP addresses within the EU, even if the billing address is outside the EU.', 'invoicing') . '<br><font style="color:red">' . __('Do not disable unless you know what you are doing.', 'invoicing') . '</font>',
257 257
                 'type' => 'checkbox',
258 258
                 'std' => '1'
259 259
             );
@@ -269,8 +269,8 @@  discard block
 block discarded – undo
269 269
 
270 270
             $vat_settings['vat_prevent_b2c_purchase'] = array(
271 271
                 'id' => 'vat_prevent_b2c_purchase',
272
-                'name' => __( 'Prevent EU B2C Sales', 'invoicing' ),
273
-                'desc' => __( 'Enable this option if you are not registered for VAT in the EU.', 'invoicing' ),
272
+                'name' => __('Prevent EU B2C Sales', 'invoicing'),
273
+                'desc' => __('Enable this option if you are not registered for VAT in the EU.', 'invoicing'),
274 274
                 'type' => 'checkbox'
275 275
             );
276 276
 
@@ -278,21 +278,21 @@  discard block
 block discarded – undo
278 278
 
279 279
             $vat_settings['vat_same_country_rule'] = array(
280 280
                 'id'          => 'vat_same_country_rule',
281
-                'name'        => __( 'Same Country Rule', 'invoicing' ),
282
-                'desc'        => __( 'Select how you want to handle VAT charge if sales are in the same country as the base country.', 'invoicing' ),
281
+                'name'        => __('Same Country Rule', 'invoicing'),
282
+                'desc'        => __('Select how you want to handle VAT charge if sales are in the same country as the base country.', 'invoicing'),
283 283
                 'type'        => 'select',
284 284
                 'options'     => array(
285
-                    ''          => __( 'Normal', 'invoicing' ),
286
-                    'no'        => __( 'No VAT', 'invoicing' ),
287
-                    'always'    => __( 'Always apply VAT', 'invoicing' ),
285
+                    ''          => __('Normal', 'invoicing'),
286
+                    'no'        => __('No VAT', 'invoicing'),
287
+                    'always'    => __('Always apply VAT', 'invoicing'),
288 288
                 ),
289
-                'placeholder' => __( 'Select an option', 'invoicing' ),
289
+                'placeholder' => __('Select an option', 'invoicing'),
290 290
                 'std'         => ''
291 291
             );
292 292
 
293 293
             $vat_settings['vat_checkout_title'] = array(
294 294
                 'id' => 'vat_checkout_title',
295
-                'name' => '<h3>' . __( 'Checkout Fields', 'invoicing' ) . '</h3>',
295
+                'name' => '<h3>' . __('Checkout Fields', 'invoicing') . '</h3>',
296 296
                 'desc' => '',
297 297
                 'type' => 'header',
298 298
                 'size' => 'regular'
@@ -300,14 +300,14 @@  discard block
 block discarded – undo
300 300
 
301 301
             $vat_settings['vat_disable_fields'] = array(
302 302
                 'id' => 'vat_disable_fields',
303
-                'name' => __( 'Disable VAT Fields', 'invoicing' ),
304
-                'desc' => __( 'Disable VAT fields if Invoicing is being used for GST.', 'invoicing' ) . '<br><font style="color:red">' . __( 'Do not disable if you have enabled Prevent EU B2C sales, otherwise Prevent EU B2C sales setting will not work.', 'invoicing' ) . '</font>',
303
+                'name' => __('Disable VAT Fields', 'invoicing'),
304
+                'desc' => __('Disable VAT fields if Invoicing is being used for GST.', 'invoicing') . '<br><font style="color:red">' . __('Do not disable if you have enabled Prevent EU B2C sales, otherwise Prevent EU B2C sales setting will not work.', 'invoicing') . '</font>',
305 305
                 'type' => 'checkbox'
306 306
             );
307 307
 
308 308
             $vat_settings['vat_ip_lookup'] = array(
309 309
                 'id'   => 'vat_ip_lookup',
310
-                'name' => __( 'IP Country Look-up', 'invoicing' ),
310
+                'name' => __('IP Country Look-up', 'invoicing'),
311 311
                 'type' => 'vat_ip_lookup',
312 312
                 'size' => 'regular',
313 313
                 'std' => 'default'
@@ -315,21 +315,21 @@  discard block
 block discarded – undo
315 315
 
316 316
             $vat_settings['hide_ip_address'] = array(
317 317
                 'id' => 'hide_ip_address',
318
-                'name' => __( 'Hide IP Info at Checkout', 'invoicing' ),
319
-                'desc' => __( 'Hide the user IP info at checkout.', 'invoicing' ),
318
+                'name' => __('Hide IP Info at Checkout', 'invoicing'),
319
+                'desc' => __('Hide the user IP info at checkout.', 'invoicing'),
320 320
                 'type' => 'checkbox'
321 321
             );
322 322
 
323 323
             $vat_settings['vat_ip_country_default'] = array(
324 324
                 'id' => 'vat_ip_country_default',
325
-                'name' => __( 'Enable IP Country as Default', 'invoicing' ),
326
-                'desc' => __( 'Show the country of the users IP as the default country, otherwise the site default country will be used.', 'invoicing' ),
325
+                'name' => __('Enable IP Country as Default', 'invoicing'),
326
+                'desc' => __('Show the country of the users IP as the default country, otherwise the site default country will be used.', 'invoicing'),
327 327
                 'type' => 'checkbox'
328 328
             );
329 329
 
330 330
             $vat_settings['vies_validation_title'] = array(
331 331
                 'id' => 'vies_validation_title',
332
-                'name' => '<h3>' . __( 'VIES Validation', 'invoicing' ) . '</h3>',
332
+                'name' => '<h3>' . __('VIES Validation', 'invoicing') . '</h3>',
333 333
                 'desc' => '',
334 334
                 'type' => 'header',
335 335
                 'size' => 'regular'
@@ -337,37 +337,37 @@  discard block
 block discarded – undo
337 337
 
338 338
             $vat_settings['vat_vies_check'] = array(
339 339
                 'id' => 'vat_vies_check',
340
-                'name' => __( 'Disable VIES VAT ID Check', 'invoicing' ),
341
-                'desc' => wp_sprintf( __( 'Prevent VAT numbers from being validated by the %sEU VIES System.%s', 'invoicing' ), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>' ),
340
+                'name' => __('Disable VIES VAT ID Check', 'invoicing'),
341
+                'desc' => wp_sprintf(__('Prevent VAT numbers from being validated by the %sEU VIES System.%s', 'invoicing'), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>'),
342 342
                 'type' => 'checkbox'
343 343
             );
344 344
 
345 345
             $vat_settings['vat_disable_company_name_check'] = array(
346 346
                 'id' => 'vat_disable_company_name_check',
347
-                'name' => __( 'Disable VIES Name Check', 'invoicing' ),
348
-                'desc' => wp_sprintf( __( 'Prevent company name from being validated by the %sEU VIES System.%s', 'invoicing' ), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>' ),
347
+                'name' => __('Disable VIES Name Check', 'invoicing'),
348
+                'desc' => wp_sprintf(__('Prevent company name from being validated by the %sEU VIES System.%s', 'invoicing'), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>'),
349 349
                 'type' => 'checkbox'
350 350
             );
351 351
 
352 352
             $vat_settings['vat_offline_check'] = array(
353 353
                 'id' => 'vat_offline_check',
354
-                'name' => __( 'Disable Basic Checks', 'invoicing' ),
355
-                'desc' => __( 'This will disable basic JS correct format validation attempts, it is very rare this should need to be disabled.', 'invoicing' ),
354
+                'name' => __('Disable Basic Checks', 'invoicing'),
355
+                'desc' => __('This will disable basic JS correct format validation attempts, it is very rare this should need to be disabled.', 'invoicing'),
356 356
                 'type' => 'checkbox'
357 357
             );
358 358
             
359 359
 
360 360
             $settings['vat'] = $vat_settings;
361 361
             
362
-            if ( self::allow_vat_classes() ) {
362
+            if (self::allow_vat_classes()) {
363 363
                 $settings['vat_rates'] = self::vat_rates_settings();
364 364
             }
365 365
             
366 366
             $eu_fallback_rate = array(
367 367
                 'id'   => 'eu_fallback_rate',
368
-                'name' => '<h3>' . __( 'VAT rate for EU member states', 'invoicing' ) . '</h3>',
368
+                'name' => '<h3>' . __('VAT rate for EU member states', 'invoicing') . '</h3>',
369 369
                 'type' => 'eu_fallback_rate',
370
-                'desc' => __( 'Enter the VAT rate to be charged for EU member states. You can edit the rates for each member state when a country rate has been set up by pressing this button.', 'invoicing' ),
370
+                'desc' => __('Enter the VAT rate to be charged for EU member states. You can edit the rates for each member state when a country rate has been set up by pressing this button.', 'invoicing'),
371 371
                 'std'  => '20',
372 372
                 'size' => 'small'
373 373
             );
@@ -383,11 +383,11 @@  discard block
 block discarded – undo
383 383
         $database_url       = 'http' . (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] === 'on' ? 's' : '') . '://geolite.maxmind.com/download/geoip/database/';
384 384
         $destination_dir    = $upload_dir['basedir'] . '/invoicing';
385 385
         
386
-        if ( !is_dir( $destination_dir ) ) { 
387
-            mkdir( $destination_dir );
386
+        if (!is_dir($destination_dir)) { 
387
+            mkdir($destination_dir);
388 388
         }
389 389
         
390
-        $database_files     = array(
390
+        $database_files = array(
391 391
             'country'   => array(
392 392
                 'source'        => $database_url . 'GeoLite2-Country.mmdb.gz',
393 393
                 'destination'   => $destination_dir . '/GeoLite2-Country.mmdb',
@@ -398,57 +398,57 @@  discard block
 block discarded – undo
398 398
             )
399 399
         );
400 400
 
401
-        foreach( $database_files as $database => $files ) {
402
-            $result = self::geoip2_download_file( $files['source'], $files['destination'] );
401
+        foreach ($database_files as $database => $files) {
402
+            $result = self::geoip2_download_file($files['source'], $files['destination']);
403 403
             
404
-            if ( empty( $result['success'] ) ) {
404
+            if (empty($result['success'])) {
405 405
                 echo $result['message'];
406 406
                 exit;
407 407
             }
408 408
             
409
-            wpinv_update_option( 'wpinv_geoip2_date_updated', current_time( 'timestamp' ) );
410
-            echo sprintf(__( 'GeoIp2 %s database updated successfully.', 'invoicing' ), $database ) . ' ';
409
+            wpinv_update_option('wpinv_geoip2_date_updated', current_time('timestamp'));
410
+            echo sprintf(__('GeoIp2 %s database updated successfully.', 'invoicing'), $database) . ' ';
411 411
         }
412 412
         
413 413
         exit;
414 414
     }
415 415
     
416
-    public static function geoip2_download_file( $source_url, $destination_file ) {
416
+    public static function geoip2_download_file($source_url, $destination_file) {
417 417
         $success    = false;
418 418
         $message    = '';
419 419
         
420
-        if ( !function_exists( 'download_url' ) ) {
421
-            require_once( ABSPATH . 'wp-admin/includes/file.php' );
420
+        if (!function_exists('download_url')) {
421
+            require_once(ABSPATH . 'wp-admin/includes/file.php');
422 422
         }
423 423
 
424
-        $temp_file  = download_url( $source_url );
424
+        $temp_file = download_url($source_url);
425 425
         
426
-        if ( is_wp_error( $temp_file ) ) {
427
-            $message = sprintf( __( 'Error while downloading GeoIp2 database( %s ): %s', 'invoicing' ), $source_url, $temp_file->get_error_message() );
426
+        if (is_wp_error($temp_file)) {
427
+            $message = sprintf(__('Error while downloading GeoIp2 database( %s ): %s', 'invoicing'), $source_url, $temp_file->get_error_message());
428 428
         } else {
429
-            $handle = gzopen( $temp_file, 'rb' );
429
+            $handle = gzopen($temp_file, 'rb');
430 430
             
431
-            if ( $handle ) {
432
-                $fopen  = fopen( $destination_file, 'wb' );
433
-                if ( $fopen ) {
434
-                    while ( ( $data = gzread( $handle, 4096 ) ) != false ) {
435
-                        fwrite( $fopen, $data );
431
+            if ($handle) {
432
+                $fopen = fopen($destination_file, 'wb');
433
+                if ($fopen) {
434
+                    while (($data = gzread($handle, 4096)) != false) {
435
+                        fwrite($fopen, $data);
436 436
                     }
437 437
 
438
-                    gzclose( $handle );
439
-                    fclose( $fopen );
438
+                    gzclose($handle);
439
+                    fclose($fopen);
440 440
                         
441 441
                     $success = true;
442 442
                 } else {
443
-                    gzclose( $handle );
444
-                    $message = sprintf( __( 'Error could not open destination GeoIp2 database file for writing: %s', 'invoicing' ), $destination_file );
443
+                    gzclose($handle);
444
+                    $message = sprintf(__('Error could not open destination GeoIp2 database file for writing: %s', 'invoicing'), $destination_file);
445 445
                 }
446 446
             } else {
447
-                $message = sprintf( __( 'Error could not open GeoIp2 database file for reading: %s', 'invoicing' ), $temp_file );
447
+                $message = sprintf(__('Error could not open GeoIp2 database file for reading: %s', 'invoicing'), $temp_file);
448 448
             }
449 449
             
450
-            if ( file_exists( $temp_file ) ) {
451
-                unlink( $temp_file );
450
+            if (file_exists($temp_file)) {
451
+                unlink($temp_file);
452 452
             }
453 453
         }
454 454
         
@@ -460,11 +460,11 @@  discard block
 block discarded – undo
460 460
     }
461 461
     
462 462
     public static function load_geoip2() {
463
-        if ( defined( 'WPINV_GEOIP2_LODDED' ) ) {
463
+        if (defined('WPINV_GEOIP2_LODDED')) {
464 464
             return;
465 465
         }
466 466
         
467
-        if ( !class_exists( '\MaxMind\Db\Reader' ) ) {
467
+        if (!class_exists('\MaxMind\Db\Reader')) {
468 468
             $maxmind_db_files = array(
469 469
                 'Reader/Decoder.php',
470 470
                 'Reader/InvalidDatabaseException.php',
@@ -473,12 +473,12 @@  discard block
 block discarded – undo
473 473
                 'Reader.php',
474 474
             );
475 475
             
476
-            foreach ( $maxmind_db_files as $key => $file ) {
477
-                require_once( WPINV_PLUGIN_DIR . 'includes/libraries/MaxMind/Db/' . $file );
476
+            foreach ($maxmind_db_files as $key => $file) {
477
+                require_once(WPINV_PLUGIN_DIR . 'includes/libraries/MaxMind/Db/' . $file);
478 478
             }
479 479
         }
480 480
         
481
-        if ( !class_exists( '\GeoIp2\Database\Reader' ) ) {        
481
+        if (!class_exists('\GeoIp2\Database\Reader')) {        
482 482
             $geoip2_files = array(
483 483
                 'ProviderInterface.php',
484 484
                 'Compat/JsonSerializable.php',
@@ -512,23 +512,23 @@  discard block
 block discarded – undo
512 512
                 'WebService/Client.php',
513 513
             );
514 514
             
515
-            foreach ( $geoip2_files as $key => $file ) {
516
-                require_once( WPINV_PLUGIN_DIR . 'includes/libraries/GeoIp2/' . $file );
515
+            foreach ($geoip2_files as $key => $file) {
516
+                require_once(WPINV_PLUGIN_DIR . 'includes/libraries/GeoIp2/' . $file);
517 517
             }
518 518
         }
519 519
 
520
-        define( 'WPINV_GEOIP2_LODDED', true );
520
+        define('WPINV_GEOIP2_LODDED', true);
521 521
     }
522 522
 
523 523
     public static function geoip2_country_dbfile() {
524 524
         $upload_dir = wp_upload_dir();
525 525
 
526
-        if ( !isset( $upload_dir['basedir'] ) ) {
526
+        if (!isset($upload_dir['basedir'])) {
527 527
             return false;
528 528
         }
529 529
 
530 530
         $filename = $upload_dir['basedir'] . '/invoicing/GeoLite2-Country.mmdb';
531
-        if ( !file_exists( $filename ) ) {
531
+        if (!file_exists($filename)) {
532 532
             return false;
533 533
         }
534 534
         
@@ -538,12 +538,12 @@  discard block
 block discarded – undo
538 538
     public static function geoip2_city_dbfile() {
539 539
         $upload_dir = wp_upload_dir();
540 540
 
541
-        if ( !isset( $upload_dir['basedir'] ) ) {
541
+        if (!isset($upload_dir['basedir'])) {
542 542
             return false;
543 543
         }
544 544
 
545 545
         $filename = $upload_dir['basedir'] . '/invoicing/GeoLite2-City.mmdb';
546
-        if ( !file_exists( $filename ) ) {
546
+        if (!file_exists($filename)) {
547 547
             return false;
548 548
         }
549 549
         
@@ -554,10 +554,10 @@  discard block
 block discarded – undo
554 554
         try {
555 555
             self::load_geoip2();
556 556
 
557
-            if ( $filename = self::geoip2_country_dbfile() ) {
558
-                return new \GeoIp2\Database\Reader( $filename );
557
+            if ($filename = self::geoip2_country_dbfile()) {
558
+                return new \GeoIp2\Database\Reader($filename);
559 559
             }
560
-        } catch( Exception $e ) {
560
+        } catch (Exception $e) {
561 561
             return false;
562 562
         }
563 563
         
@@ -568,173 +568,173 @@  discard block
 block discarded – undo
568 568
         try {
569 569
             self::load_geoip2();
570 570
 
571
-            if ( $filename = self::geoip2_city_dbfile() ) {
572
-                return new \GeoIp2\Database\Reader( $filename );
571
+            if ($filename = self::geoip2_city_dbfile()) {
572
+                return new \GeoIp2\Database\Reader($filename);
573 573
             }
574
-        } catch( Exception $e ) {
574
+        } catch (Exception $e) {
575 575
             return false;
576 576
         }
577 577
         
578 578
         return false;
579 579
     }
580 580
 
581
-    public static function geoip2_country_record( $ip_address ) {
581
+    public static function geoip2_country_record($ip_address) {
582 582
         try {
583 583
             $reader = self::geoip2_country_reader();
584 584
 
585
-            if ( $reader ) {
586
-                $record = $reader->country( $ip_address );
585
+            if ($reader) {
586
+                $record = $reader->country($ip_address);
587 587
                 
588
-                if ( !empty( $record->country->isoCode ) ) {
588
+                if (!empty($record->country->isoCode)) {
589 589
                     return $record;
590 590
                 }
591 591
             }
592
-        } catch(\InvalidArgumentException $e) {
593
-            wpinv_error_log( $e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )' );
592
+        } catch (\InvalidArgumentException $e) {
593
+            wpinv_error_log($e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )');
594 594
             
595 595
             return false;
596
-        } catch(\GeoIp2\Exception\AddressNotFoundException $e) {
597
-            wpinv_error_log( $e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )' );
596
+        } catch (\GeoIp2\Exception\AddressNotFoundException $e) {
597
+            wpinv_error_log($e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )');
598 598
             
599 599
             return false;
600
-        } catch( Exception $e ) {
600
+        } catch (Exception $e) {
601 601
             return false;
602 602
         }
603 603
         
604 604
         return false;
605 605
     }
606 606
 
607
-    public static function geoip2_city_record( $ip_address ) {
607
+    public static function geoip2_city_record($ip_address) {
608 608
         try {
609 609
             $reader = self::geoip2_city_reader();
610 610
 
611
-            if ( $reader ) {
612
-                $record = $reader->city( $ip_address );
611
+            if ($reader) {
612
+                $record = $reader->city($ip_address);
613 613
                 
614
-                if ( !empty( $record->country->isoCode ) ) {
614
+                if (!empty($record->country->isoCode)) {
615 615
                     return $record;
616 616
                 }
617 617
             }
618
-        } catch(\InvalidArgumentException $e) {
619
-            wpinv_error_log( $e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )' );
618
+        } catch (\InvalidArgumentException $e) {
619
+            wpinv_error_log($e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )');
620 620
             
621 621
             return false;
622
-        } catch(\GeoIp2\Exception\AddressNotFoundException $e) {
623
-            wpinv_error_log( $e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )' );
622
+        } catch (\GeoIp2\Exception\AddressNotFoundException $e) {
623
+            wpinv_error_log($e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )');
624 624
             
625 625
             return false;
626
-        } catch( Exception $e ) {
626
+        } catch (Exception $e) {
627 627
             return false;
628 628
         }
629 629
         
630 630
         return false;
631 631
     }
632 632
 
633
-    public static function geoip2_country_code( $ip_address ) {
634
-        $record = self::geoip2_country_record( $ip_address );
635
-        return !empty( $record->country->isoCode ) ? $record->country->isoCode : wpinv_get_default_country();
633
+    public static function geoip2_country_code($ip_address) {
634
+        $record = self::geoip2_country_record($ip_address);
635
+        return !empty($record->country->isoCode) ? $record->country->isoCode : wpinv_get_default_country();
636 636
     }
637 637
 
638 638
     // Find country by IP address.
639
-    public static function get_country_by_ip( $ip = '' ) {
639
+    public static function get_country_by_ip($ip = '') {
640 640
         global $wpinv_ip_address_country;
641 641
         
642
-        if ( !empty( $wpinv_ip_address_country ) ) {
642
+        if (!empty($wpinv_ip_address_country)) {
643 643
             return $wpinv_ip_address_country;
644 644
         }
645 645
         
646
-        if ( empty( $ip ) ) {
646
+        if (empty($ip)) {
647 647
             $ip = wpinv_get_ip();
648 648
         }
649 649
 
650
-        $ip_country_service = wpinv_get_option( 'vat_ip_lookup' );
651
-        $is_default         = empty( $ip_country_service ) || $ip_country_service === 'default' ? true : false;
650
+        $ip_country_service = wpinv_get_option('vat_ip_lookup');
651
+        $is_default         = empty($ip_country_service) || $ip_country_service === 'default' ? true : false;
652 652
 
653
-        if ( !empty( $ip ) && $ip !== '127.0.0.1' ) { // For 127.0.0.1(localhost) use default country.
654
-            if ( function_exists( 'geoip_country_code_by_name') && ( $ip_country_service === 'geoip' || $is_default ) ) {
653
+        if (!empty($ip) && $ip !== '127.0.0.1') { // For 127.0.0.1(localhost) use default country.
654
+            if (function_exists('geoip_country_code_by_name') && ($ip_country_service === 'geoip' || $is_default)) {
655 655
                 try {
656
-                    $wpinv_ip_address_country = geoip_country_code_by_name( $ip );
657
-                } catch( Exception $e ) {
658
-                    wpinv_error_log( $e->getMessage(), 'GeoIP Lookup( ' . $ip . ' )' );
656
+                    $wpinv_ip_address_country = geoip_country_code_by_name($ip);
657
+                } catch (Exception $e) {
658
+                    wpinv_error_log($e->getMessage(), 'GeoIP Lookup( ' . $ip . ' )');
659 659
                 }
660
-            } else if ( self::geoip2_country_dbfile() && ( $ip_country_service === 'geoip2' || $is_default ) ) {
661
-                $wpinv_ip_address_country = self::geoip2_country_code( $ip );
662
-            } else if ( function_exists( 'simplexml_load_file' ) && ( $ip_country_service === 'geoplugin' || $is_default ) ) {
663
-                $load_xml = simplexml_load_file( 'http://www.geoplugin.net/xml.gp?ip=' . $ip );
660
+            } else if (self::geoip2_country_dbfile() && ($ip_country_service === 'geoip2' || $is_default)) {
661
+                $wpinv_ip_address_country = self::geoip2_country_code($ip);
662
+            } else if (function_exists('simplexml_load_file') && ($ip_country_service === 'geoplugin' || $is_default)) {
663
+                $load_xml = simplexml_load_file('http://www.geoplugin.net/xml.gp?ip=' . $ip);
664 664
                 
665
-                if ( !empty( $load_xml ) && !empty( $load_xml->geoplugin_countryCode ) ) {
665
+                if (!empty($load_xml) && !empty($load_xml->geoplugin_countryCode)) {
666 666
                     $wpinv_ip_address_country = (string)$load_xml->geoplugin_countryCode;
667 667
                 }
668 668
             }
669 669
         }
670 670
 
671
-        if ( empty( $wpinv_ip_address_country ) ) {
671
+        if (empty($wpinv_ip_address_country)) {
672 672
             $wpinv_ip_address_country = wpinv_get_default_country();
673 673
         }
674 674
 
675 675
         return $wpinv_ip_address_country;
676 676
     }
677 677
     
678
-    public static function sanitize_vat_settings( $input ) {
678
+    public static function sanitize_vat_settings($input) {
679 679
         global $wpinv_options;
680 680
         
681 681
         $valid      = false;
682 682
         $message    = '';
683 683
         
684
-        if ( !empty( $wpinv_options['vat_vies_check'] ) ) {
685
-            if ( empty( $wpinv_options['vat_offline_check'] ) ) {
686
-                $valid = self::offline_check( $input['vat_number'] );
684
+        if (!empty($wpinv_options['vat_vies_check'])) {
685
+            if (empty($wpinv_options['vat_offline_check'])) {
686
+                $valid = self::offline_check($input['vat_number']);
687 687
             } else {
688 688
                 $valid = true;
689 689
             }
690 690
             
691
-            $message = $valid ? '' : __( 'VAT number not validated', 'invoicing' );
691
+            $message = $valid ? '' : __('VAT number not validated', 'invoicing');
692 692
         } else {
693
-            $result = self::check_vat( $input['vat_number'] );
693
+            $result = self::check_vat($input['vat_number']);
694 694
             
695
-            if ( empty( $result['valid'] ) ) {
695
+            if (empty($result['valid'])) {
696 696
                 $valid      = false;
697 697
                 $message    = $result['message'];
698 698
             } else {
699
-                $valid      = ( isset( $result['company'] ) && ( $result['company'] == '---' || ( strcasecmp( trim( $result['company'] ), trim( $input['vat_company_name'] ) ) == 0 ) ) ) || !empty( $wpinv_options['vat_disable_company_name_check'] );
700
-                $message    = $valid ? '' : __( 'The company name associated with the VAT number provided is not the same as the company name provided.', 'invoicing' );
699
+                $valid      = (isset($result['company']) && ($result['company'] == '---' || (strcasecmp(trim($result['company']), trim($input['vat_company_name'])) == 0))) || !empty($wpinv_options['vat_disable_company_name_check']);
700
+                $message    = $valid ? '' : __('The company name associated with the VAT number provided is not the same as the company name provided.', 'invoicing');
701 701
             }
702 702
         }
703 703
 
704
-        if ( $message && self::is_vat_validated() != $valid ) {
705
-            add_settings_error( 'wpinv-notices', '', $message, ( $valid ? 'updated' : 'error' ) );
704
+        if ($message && self::is_vat_validated() != $valid) {
705
+            add_settings_error('wpinv-notices', '', $message, ($valid ? 'updated' : 'error'));
706 706
         }
707 707
 
708 708
         $input['vat_valid'] = $valid;
709 709
         return $input;
710 710
     }
711 711
     
712
-    public static function sanitize_vat_rates( $input ) {
713
-        if( !current_user_can( 'manage_options' ) ) {
714
-            add_settings_error( 'wpinv-notices', '', __( 'Your account does not have permission to add rate classes.', 'invoicing' ), 'error' );
712
+    public static function sanitize_vat_rates($input) {
713
+        if (!current_user_can('manage_options')) {
714
+            add_settings_error('wpinv-notices', '', __('Your account does not have permission to add rate classes.', 'invoicing'), 'error');
715 715
             return $input;
716 716
         }
717 717
         
718 718
         $vat_classes = self::get_rate_classes();
719
-        $vat_class = !empty( $_REQUEST['wpi_vat_class'] ) && isset( $vat_classes[$_REQUEST['wpi_vat_class']] )? sanitize_text_field( $_REQUEST['wpi_vat_class'] ) : '';
719
+        $vat_class = !empty($_REQUEST['wpi_vat_class']) && isset($vat_classes[$_REQUEST['wpi_vat_class']]) ? sanitize_text_field($_REQUEST['wpi_vat_class']) : '';
720 720
         
721
-        if ( empty( $vat_class ) ) {
722
-            add_settings_error( 'wpinv-notices', '', __( 'No valid VAT rates class contained in the request to save rates.', 'invoicing' ), 'error' );
721
+        if (empty($vat_class)) {
722
+            add_settings_error('wpinv-notices', '', __('No valid VAT rates class contained in the request to save rates.', 'invoicing'), 'error');
723 723
             
724 724
             return $input;
725 725
         }
726 726
 
727
-        $new_rates = ! empty( $_POST['vat_rates'] ) ? array_values( $_POST['vat_rates'] ) : array();
727
+        $new_rates = !empty($_POST['vat_rates']) ? array_values($_POST['vat_rates']) : array();
728 728
 
729
-        if ( $vat_class === '_standard' ) {
729
+        if ($vat_class === '_standard') {
730 730
             // Save the active rates in the invoice settings
731
-            update_option( 'wpinv_tax_rates', $new_rates );
731
+            update_option('wpinv_tax_rates', $new_rates);
732 732
         } else {
733 733
             // Get the existing set of rates
734 734
             $rates = self::get_non_standard_rates();
735 735
             $rates[$vat_class] = $new_rates;
736 736
 
737
-            update_option( 'wpinv_vat_rates', $rates );
737
+            update_option('wpinv_vat_rates', $rates);
738 738
         }
739 739
         
740 740
         return $input;
@@ -744,71 +744,71 @@  discard block
 block discarded – undo
744 744
         $response = array();
745 745
         $response['success'] = false;
746 746
         
747
-        if ( !current_user_can( 'manage_options' ) ) {
748
-            $response['error'] = __( 'Invalid access!', 'invoicing' );
749
-            wp_send_json( $response );
747
+        if (!current_user_can('manage_options')) {
748
+            $response['error'] = __('Invalid access!', 'invoicing');
749
+            wp_send_json($response);
750 750
         }
751 751
         
752
-        $vat_class_name = !empty( $_POST['name'] ) ? sanitize_text_field( $_POST['name'] ) : false;
753
-        $vat_class_desc = !empty( $_POST['desc'] ) ? sanitize_text_field( $_POST['desc'] ) : false;
752
+        $vat_class_name = !empty($_POST['name']) ? sanitize_text_field($_POST['name']) : false;
753
+        $vat_class_desc = !empty($_POST['desc']) ? sanitize_text_field($_POST['desc']) : false;
754 754
         
755
-        if ( empty( $vat_class_name ) ) {
756
-            $response['error'] = __( 'Select the VAT rate name', 'invoicing' );
757
-            wp_send_json( $response );
755
+        if (empty($vat_class_name)) {
756
+            $response['error'] = __('Select the VAT rate name', 'invoicing');
757
+            wp_send_json($response);
758 758
         }
759 759
         
760 760
         $vat_classes = (array)self::get_rate_classes();
761 761
 
762
-        if ( !empty( $vat_classes ) && in_array( strtolower( $vat_class_name ), array_map( 'strtolower', array_values( $vat_classes ) ) ) ) {
763
-            $response['error'] = wp_sprintf( __( 'A VAT Rate name "%s" already exists', 'invoicing' ), $vat_class_name );
764
-            wp_send_json( $response );
762
+        if (!empty($vat_classes) && in_array(strtolower($vat_class_name), array_map('strtolower', array_values($vat_classes)))) {
763
+            $response['error'] = wp_sprintf(__('A VAT Rate name "%s" already exists', 'invoicing'), $vat_class_name);
764
+            wp_send_json($response);
765 765
         }
766 766
         
767
-        $rate_class_key = normalize_whitespace( 'wpi-' . $vat_class_name );
768
-        $rate_class_key = sanitize_key( str_replace( " ", "-", $rate_class_key ) );
767
+        $rate_class_key = normalize_whitespace('wpi-' . $vat_class_name);
768
+        $rate_class_key = sanitize_key(str_replace(" ", "-", $rate_class_key));
769 769
         
770
-        $vat_classes = (array)self::get_rate_classes( true );
771
-        $vat_classes[$rate_class_key] = array( 'name' => $vat_class_name, 'desc' => $vat_class_desc );
770
+        $vat_classes = (array)self::get_rate_classes(true);
771
+        $vat_classes[$rate_class_key] = array('name' => $vat_class_name, 'desc' => $vat_class_desc);
772 772
         
773
-        update_option( '_wpinv_vat_rate_classes', $vat_classes );
773
+        update_option('_wpinv_vat_rate_classes', $vat_classes);
774 774
         
775 775
         $response['success'] = true;
776
-        $response['redirect'] = admin_url( 'admin.php?page=wpinv-settings&tab=taxes&section=vat_rates&wpi_sub=' . $rate_class_key );
776
+        $response['redirect'] = admin_url('admin.php?page=wpinv-settings&tab=taxes&section=vat_rates&wpi_sub=' . $rate_class_key);
777 777
         
778
-        wp_send_json( $response );
778
+        wp_send_json($response);
779 779
     }
780 780
     
781 781
     public static function delete_class() {
782 782
         $response = array();
783 783
         $response['success'] = false;
784 784
         
785
-        if ( !current_user_can( 'manage_options' ) || !isset( $_POST['class'] ) ) {
786
-            $response['error'] = __( 'Invalid access!', 'invoicing' );
787
-            wp_send_json( $response );
785
+        if (!current_user_can('manage_options') || !isset($_POST['class'])) {
786
+            $response['error'] = __('Invalid access!', 'invoicing');
787
+            wp_send_json($response);
788 788
         }
789 789
         
790
-        $vat_class = isset( $_POST['class'] ) && $_POST['class'] !== '' ? sanitize_text_field( $_POST['class'] ) : false;
790
+        $vat_class = isset($_POST['class']) && $_POST['class'] !== '' ? sanitize_text_field($_POST['class']) : false;
791 791
         $vat_classes = (array)self::get_rate_classes();
792 792
 
793
-        if ( !isset( $vat_classes[$vat_class] ) ) {
794
-            $response['error'] = __( 'Requested class does not exists', 'invoicing' );
795
-            wp_send_json( $response );
793
+        if (!isset($vat_classes[$vat_class])) {
794
+            $response['error'] = __('Requested class does not exists', 'invoicing');
795
+            wp_send_json($response);
796 796
         }
797 797
         
798
-        if ( $vat_class == '_new' || $vat_class == '_standard' ) {
799
-            $response['error'] = __( 'You can not delete standard rates class', 'invoicing' );
800
-            wp_send_json( $response );
798
+        if ($vat_class == '_new' || $vat_class == '_standard') {
799
+            $response['error'] = __('You can not delete standard rates class', 'invoicing');
800
+            wp_send_json($response);
801 801
         }
802 802
             
803
-        $vat_classes = (array)self::get_rate_classes( true );
804
-        unset( $vat_classes[$vat_class] );
803
+        $vat_classes = (array)self::get_rate_classes(true);
804
+        unset($vat_classes[$vat_class]);
805 805
         
806
-        update_option( '_wpinv_vat_rate_classes', $vat_classes );
806
+        update_option('_wpinv_vat_rate_classes', $vat_classes);
807 807
         
808 808
         $response['success'] = true;
809
-        $response['redirect'] = admin_url( 'admin.php?page=wpinv-settings&tab=taxes&section=vat_rates&wpi_sub=_new' );
809
+        $response['redirect'] = admin_url('admin.php?page=wpinv-settings&tab=taxes&section=vat_rates&wpi_sub=_new');
810 810
         
811
-        wp_send_json( $response );
811
+        wp_send_json($response);
812 812
     }
813 813
     
814 814
     public static function update_eu_rates() {        
@@ -817,72 +817,72 @@  discard block
 block discarded – undo
817 817
         $response['error']      = null;
818 818
         $response['data']       = null;
819 819
         
820
-        if ( !current_user_can( 'manage_options' ) ) {
821
-            $response['error'] = __( 'Invalid access!', 'invoicing' );
822
-            wp_send_json( $response );
820
+        if (!current_user_can('manage_options')) {
821
+            $response['error'] = __('Invalid access!', 'invoicing');
822
+            wp_send_json($response);
823 823
         }
824 824
         
825
-        $group      = !empty( $_POST['group'] ) ? sanitize_text_field( $_POST['group'] ) : '';
826
-        $euvatrates = self::request_euvatrates( $group );
825
+        $group      = !empty($_POST['group']) ? sanitize_text_field($_POST['group']) : '';
826
+        $euvatrates = self::request_euvatrates($group);
827 827
         
828
-        if ( !empty( $euvatrates ) ) {
829
-            if ( !empty( $euvatrates['success'] ) && !empty( $euvatrates['rates'] ) ) {
828
+        if (!empty($euvatrates)) {
829
+            if (!empty($euvatrates['success']) && !empty($euvatrates['rates'])) {
830 830
                 $response['success']        = true;
831 831
                 $response['data']['rates']  = $euvatrates['rates'];
832
-            } else if ( !empty( $euvatrates['error'] ) ) {
832
+            } else if (!empty($euvatrates['error'])) {
833 833
                 $response['error']          = $euvatrates['error'];
834 834
             }
835 835
         }
836 836
             
837
-        wp_send_json( $response );
837
+        wp_send_json($response);
838 838
     }
839 839
     
840 840
     public static function hide_vat_fields() {
841
-        $hide = wpinv_get_option( 'vat_disable_fields' );
841
+        $hide = wpinv_get_option('vat_disable_fields');
842 842
         
843
-        return apply_filters( 'wpinv_hide_vat_fields', $hide );
843
+        return apply_filters('wpinv_hide_vat_fields', $hide);
844 844
     }
845 845
     
846 846
     public static function same_country_rule() {
847
-        $same_country_rule = wpinv_get_option( 'vat_same_country_rule' );
847
+        $same_country_rule = wpinv_get_option('vat_same_country_rule');
848 848
         
849
-        return apply_filters( 'wpinv_vat_same_country_rule', $same_country_rule );
849
+        return apply_filters('wpinv_vat_same_country_rule', $same_country_rule);
850 850
     }
851 851
     
852 852
     public static function get_vat_name() {
853
-        $vat_name   = wpinv_get_option( 'vat_name' );
854
-        $vat_name   = !empty( $vat_name ) ? $vat_name : 'VAT';
853
+        $vat_name   = wpinv_get_option('vat_name');
854
+        $vat_name   = !empty($vat_name) ? $vat_name : 'VAT';
855 855
         
856
-        return apply_filters( 'wpinv_get_owner_vat_name', $vat_name );
856
+        return apply_filters('wpinv_get_owner_vat_name', $vat_name);
857 857
     }
858 858
     
859 859
     public static function get_company_name() {
860
-        $company_name = wpinv_get_option( 'vat_company_name' );
860
+        $company_name = wpinv_get_option('vat_company_name');
861 861
         
862
-        return apply_filters( 'wpinv_get_owner_company_name', $company_name );
862
+        return apply_filters('wpinv_get_owner_company_name', $company_name);
863 863
     }
864 864
     
865 865
     public static function get_vat_number() {
866
-        $vat_number = wpinv_get_option( 'vat_number' );
866
+        $vat_number = wpinv_get_option('vat_number');
867 867
         
868
-        return apply_filters( 'wpinv_get_owner_vat_number', $vat_number );
868
+        return apply_filters('wpinv_get_owner_vat_number', $vat_number);
869 869
     }
870 870
     
871 871
     public static function is_vat_validated() {
872
-        $validated = self::get_vat_number() && wpinv_get_option( 'vat_valid' );
872
+        $validated = self::get_vat_number() && wpinv_get_option('vat_valid');
873 873
         
874
-        return apply_filters( 'wpinv_is_owner_vat_validated', $validated );
874
+        return apply_filters('wpinv_is_owner_vat_validated', $validated);
875 875
     }
876 876
     
877
-    public static function sanitize_vat( $vat_number, $country_code = '' ) {        
878
-        $vat_number = str_replace( array(' ', '.', '-', '_', ',' ), '', strtoupper( trim( $vat_number ) ) );
877
+    public static function sanitize_vat($vat_number, $country_code = '') {        
878
+        $vat_number = str_replace(array(' ', '.', '-', '_', ','), '', strtoupper(trim($vat_number)));
879 879
         
880
-        if ( empty( $country_code ) ) {
881
-            $country_code = substr( $vat_number, 0, 2 );
880
+        if (empty($country_code)) {
881
+            $country_code = substr($vat_number, 0, 2);
882 882
         }
883 883
         
884
-        if ( strpos( $vat_number , $country_code ) === 0 ) {
885
-            $vat = str_replace( $country_code, '', $vat_number );
884
+        if (strpos($vat_number, $country_code) === 0) {
885
+            $vat = str_replace($country_code, '', $vat_number);
886 886
         } else {
887 887
             $vat = $country_code . $vat_number;
888 888
         }
@@ -895,140 +895,140 @@  discard block
 block discarded – undo
895 895
         return $return;
896 896
     }
897 897
     
898
-    public static function offline_check( $vat_number, $country_code = '', $formatted = false ) {
899
-        $vat            = self::sanitize_vat( $vat_number, $country_code );
898
+    public static function offline_check($vat_number, $country_code = '', $formatted = false) {
899
+        $vat            = self::sanitize_vat($vat_number, $country_code);
900 900
         $vat_number     = $vat['vat_number'];
901 901
         $country_code   = $vat['iso'];
902 902
         $regex          = array();
903 903
         
904
-        switch ( $country_code ) {
904
+        switch ($country_code) {
905 905
             case 'AT':
906
-                $regex[] = '/^(AT)U(\d{8})$/';                           // Austria
906
+                $regex[] = '/^(AT)U(\d{8})$/'; // Austria
907 907
                 break;
908 908
             case 'BE':
909
-                $regex[] = '/^(BE)(0?\d{9})$/';                          // Belgium
909
+                $regex[] = '/^(BE)(0?\d{9})$/'; // Belgium
910 910
                 break;
911 911
             case 'BG':
912
-                $regex[] = '/^(BG)(\d{9,10})$/';                         // Bulgaria
912
+                $regex[] = '/^(BG)(\d{9,10})$/'; // Bulgaria
913 913
                 break;
914 914
             case 'CH':
915 915
             case 'CHE':
916
-                $regex[] = '/^(CHE)(\d{9})MWST$/';                       // Switzerland (Not EU)
916
+                $regex[] = '/^(CHE)(\d{9})MWST$/'; // Switzerland (Not EU)
917 917
                 break;
918 918
             case 'CY':
919
-                $regex[] = '/^(CY)([0-5|9]\d{7}[A-Z])$/';                // Cyprus
919
+                $regex[] = '/^(CY)([0-5|9]\d{7}[A-Z])$/'; // Cyprus
920 920
                 break;
921 921
             case 'CZ':
922
-                $regex[] = '/^(CZ)(\d{8,13})$/';                         // Czech Republic
922
+                $regex[] = '/^(CZ)(\d{8,13})$/'; // Czech Republic
923 923
                 break;
924 924
             case 'DE':
925
-                $regex[] = '/^(DE)([1-9]\d{8})$/';                       // Germany
925
+                $regex[] = '/^(DE)([1-9]\d{8})$/'; // Germany
926 926
                 break;
927 927
             case 'DK':
928
-                $regex[] = '/^(DK)(\d{8})$/';                            // Denmark
928
+                $regex[] = '/^(DK)(\d{8})$/'; // Denmark
929 929
                 break;
930 930
             case 'EE':
931
-                $regex[] = '/^(EE)(10\d{7})$/';                          // Estonia
931
+                $regex[] = '/^(EE)(10\d{7})$/'; // Estonia
932 932
                 break;
933 933
             case 'EL':
934
-                $regex[] = '/^(EL)(\d{9})$/';                            // Greece
934
+                $regex[] = '/^(EL)(\d{9})$/'; // Greece
935 935
                 break;
936 936
             case 'ES':
937
-                $regex[] = '/^(ES)([A-Z]\d{8})$/';                       // Spain (National juridical entities)
938
-                $regex[] = '/^(ES)([A-H|N-S|W]\d{7}[A-J])$/';            // Spain (Other juridical entities)
939
-                $regex[] = '/^(ES)([0-9|Y|Z]\d{7}[A-Z])$/';              // Spain (Personal entities type 1)
940
-                $regex[] = '/^(ES)([K|L|M|X]\d{7}[A-Z])$/';              // Spain (Personal entities type 2)
937
+                $regex[] = '/^(ES)([A-Z]\d{8})$/'; // Spain (National juridical entities)
938
+                $regex[] = '/^(ES)([A-H|N-S|W]\d{7}[A-J])$/'; // Spain (Other juridical entities)
939
+                $regex[] = '/^(ES)([0-9|Y|Z]\d{7}[A-Z])$/'; // Spain (Personal entities type 1)
940
+                $regex[] = '/^(ES)([K|L|M|X]\d{7}[A-Z])$/'; // Spain (Personal entities type 2)
941 941
                 break;
942 942
             case 'EU':
943
-                $regex[] = '/^(EU)(\d{9})$/';                            // EU-type
943
+                $regex[] = '/^(EU)(\d{9})$/'; // EU-type
944 944
                 break;
945 945
             case 'FI':
946
-                $regex[] = '/^(FI)(\d{8})$/';                            // Finland
946
+                $regex[] = '/^(FI)(\d{8})$/'; // Finland
947 947
                 break;
948 948
             case 'FR':
949
-                $regex[] = '/^(FR)(\d{11})$/';                           // France (1)
950
-                $regex[] = '/^(FR)[(A-H)|(J-N)|(P-Z)](\d{10})$/';        // France (2)
951
-                $regex[] = '/^(FR)\d[(A-H)|(J-N)|(P-Z)](\d{9})$/';       // France (3)
952
-                $regex[] = '/^(FR)[(A-H)|(J-N)|(P-Z)]{2}(\d{9})$/';      // France (4)
949
+                $regex[] = '/^(FR)(\d{11})$/'; // France (1)
950
+                $regex[] = '/^(FR)[(A-H)|(J-N)|(P-Z)](\d{10})$/'; // France (2)
951
+                $regex[] = '/^(FR)\d[(A-H)|(J-N)|(P-Z)](\d{9})$/'; // France (3)
952
+                $regex[] = '/^(FR)[(A-H)|(J-N)|(P-Z)]{2}(\d{9})$/'; // France (4)
953 953
                 break;
954 954
             case 'GB':
955
-                $regex[] = '/^(GB)?(\d{9})$/';                           // UK (Standard)
956
-                $regex[] = '/^(GB)?(\d{12})$/';                          // UK (Branches)
957
-                $regex[] = '/^(GB)?(GD\d{3})$/';                         // UK (Government)
958
-                $regex[] = '/^(GB)?(HA\d{3})$/';                         // UK (Health authority)
955
+                $regex[] = '/^(GB)?(\d{9})$/'; // UK (Standard)
956
+                $regex[] = '/^(GB)?(\d{12})$/'; // UK (Branches)
957
+                $regex[] = '/^(GB)?(GD\d{3})$/'; // UK (Government)
958
+                $regex[] = '/^(GB)?(HA\d{3})$/'; // UK (Health authority)
959 959
                 break;
960 960
             case 'GR':
961
-                $regex[] = '/^(GR)(\d{8,9})$/';                          // Greece
961
+                $regex[] = '/^(GR)(\d{8,9})$/'; // Greece
962 962
                 break;
963 963
             case 'HR':
964
-                $regex[] = '/^(HR)(\d{11})$/';                           // Croatia
964
+                $regex[] = '/^(HR)(\d{11})$/'; // Croatia
965 965
                 break;
966 966
             case 'HU':
967
-                $regex[] = '/^(HU)(\d{8})$/';                            // Hungary
967
+                $regex[] = '/^(HU)(\d{8})$/'; // Hungary
968 968
                 break;
969 969
             case 'IE':
970
-                $regex[] = '/^(IE)(\d{7}[A-W])$/';                       // Ireland (1)
971
-                $regex[] = '/^(IE)([7-9][A-Z\*\+)]\d{5}[A-W])$/';        // Ireland (2)
972
-                $regex[] = '/^(IE)(\d{7}[A-Z][AH])$/';                   // Ireland (3) (new format from 1 Jan 2013)
970
+                $regex[] = '/^(IE)(\d{7}[A-W])$/'; // Ireland (1)
971
+                $regex[] = '/^(IE)([7-9][A-Z\*\+)]\d{5}[A-W])$/'; // Ireland (2)
972
+                $regex[] = '/^(IE)(\d{7}[A-Z][AH])$/'; // Ireland (3) (new format from 1 Jan 2013)
973 973
                 break;
974 974
             case 'IT':
975
-                $regex[] = '/^(IT)(\d{11})$/';                           // Italy
975
+                $regex[] = '/^(IT)(\d{11})$/'; // Italy
976 976
                 break;
977 977
             case 'LV':
978
-                $regex[] = '/^(LV)(\d{11})$/';                           // Latvia
978
+                $regex[] = '/^(LV)(\d{11})$/'; // Latvia
979 979
                 break;
980 980
             case 'LT':
981
-                $regex[] = '/^(LT)(\d{9}|\d{12})$/';                     // Lithuania
981
+                $regex[] = '/^(LT)(\d{9}|\d{12})$/'; // Lithuania
982 982
                 break;
983 983
             case 'LU':
984
-                $regex[] = '/^(LU)(\d{8})$/';                            // Luxembourg
984
+                $regex[] = '/^(LU)(\d{8})$/'; // Luxembourg
985 985
                 break;
986 986
             case 'MT':
987
-                $regex[] = '/^(MT)([1-9]\d{7})$/';                       // Malta
987
+                $regex[] = '/^(MT)([1-9]\d{7})$/'; // Malta
988 988
                 break;
989 989
             case 'NL':
990
-                $regex[] = '/^(NL)(\d{9})B\d{2}$/';                      // Netherlands
990
+                $regex[] = '/^(NL)(\d{9})B\d{2}$/'; // Netherlands
991 991
                 break;
992 992
             case 'NO':
993
-                $regex[] = '/^(NO)(\d{9})$/';                            // Norway (Not EU)
993
+                $regex[] = '/^(NO)(\d{9})$/'; // Norway (Not EU)
994 994
                 break;
995 995
             case 'PL':
996
-                $regex[] = '/^(PL)(\d{10})$/';                           // Poland
996
+                $regex[] = '/^(PL)(\d{10})$/'; // Poland
997 997
                 break;
998 998
             case 'PT':
999
-                $regex[] = '/^(PT)(\d{9})$/';                            // Portugal
999
+                $regex[] = '/^(PT)(\d{9})$/'; // Portugal
1000 1000
                 break;
1001 1001
             case 'RO':
1002
-                $regex[] = '/^(RO)([1-9]\d{1,9})$/';                     // Romania
1002
+                $regex[] = '/^(RO)([1-9]\d{1,9})$/'; // Romania
1003 1003
                 break;
1004 1004
             case 'RS':
1005
-                $regex[] = '/^(RS)(\d{9})$/';                            // Serbia (Not EU)
1005
+                $regex[] = '/^(RS)(\d{9})$/'; // Serbia (Not EU)
1006 1006
                 break;
1007 1007
             case 'SI':
1008
-                $regex[] = '/^(SI)([1-9]\d{7})$/';                       // Slovenia
1008
+                $regex[] = '/^(SI)([1-9]\d{7})$/'; // Slovenia
1009 1009
                 break;
1010 1010
             case 'SK':
1011
-                $regex[] = '/^(SK)([1-9]\d[(2-4)|(6-9)]\d{7})$/';        // Slovakia Republic
1011
+                $regex[] = '/^(SK)([1-9]\d[(2-4)|(6-9)]\d{7})$/'; // Slovakia Republic
1012 1012
                 break;
1013 1013
             case 'SE':
1014
-                $regex[] = '/^(SE)(\d{10}01)$/';                         // Sweden
1014
+                $regex[] = '/^(SE)(\d{10}01)$/'; // Sweden
1015 1015
                 break;
1016 1016
             default:
1017 1017
                 $regex = array();
1018 1018
             break;
1019 1019
         }
1020 1020
         
1021
-        if ( empty( $regex ) ) {
1021
+        if (empty($regex)) {
1022 1022
             return false;
1023 1023
         }
1024 1024
         
1025
-        foreach ( $regex as $pattern ) {
1025
+        foreach ($regex as $pattern) {
1026 1026
             $matches = null;
1027
-            preg_match_all( $pattern, $vat_number, $matches );
1027
+            preg_match_all($pattern, $vat_number, $matches);
1028 1028
             
1029
-            if ( !empty( $matches[1][0] ) && !empty( $matches[2][0] ) ) {
1030
-                if ( $formatted ) {
1031
-                    return array( 'code' => $matches[1][0], 'number' => $matches[2][0] );
1029
+            if (!empty($matches[1][0]) && !empty($matches[2][0])) {
1030
+                if ($formatted) {
1031
+                    return array('code' => $matches[1][0], 'number' => $matches[2][0]);
1032 1032
                 } else {
1033 1033
                     return true;
1034 1034
                 }
@@ -1038,75 +1038,75 @@  discard block
 block discarded – undo
1038 1038
         return false;
1039 1039
     }
1040 1040
     
1041
-    public static function vies_check( $vat_number, $country_code = '', $result = false ) {
1042
-        $vat            = self::sanitize_vat( $vat_number, $country_code );
1041
+    public static function vies_check($vat_number, $country_code = '', $result = false) {
1042
+        $vat            = self::sanitize_vat($vat_number, $country_code);
1043 1043
         $vat_number     = $vat['vat'];
1044 1044
         $iso            = $vat['iso'];
1045 1045
         
1046
-        $url = 'http://ec.europa.eu/taxation_customs/vies/viesquer.do?ms=' . urlencode( $iso ) . '&iso=' . urlencode( $iso ) . '&vat=' . urlencode( $vat_number );
1046
+        $url = 'http://ec.europa.eu/taxation_customs/vies/viesquer.do?ms=' . urlencode($iso) . '&iso=' . urlencode($iso) . '&vat=' . urlencode($vat_number);
1047 1047
         
1048
-        if ( ini_get( 'allow_url_fopen' ) ) {
1049
-            $response = file_get_contents( $url );
1050
-        } else if ( function_exists( 'curl_init' ) ) {
1048
+        if (ini_get('allow_url_fopen')) {
1049
+            $response = file_get_contents($url);
1050
+        } else if (function_exists('curl_init')) {
1051 1051
             $ch = curl_init();
1052 1052
             
1053
-            curl_setopt( $ch, CURLOPT_URL, $url );
1054
-            curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, 30 );
1055
-            curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
1056
-            curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, 0 );
1057
-            curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, 0 );
1053
+            curl_setopt($ch, CURLOPT_URL, $url);
1054
+            curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
1055
+            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
1056
+            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
1057
+            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
1058 1058
             
1059
-            $response = curl_exec( $ch );
1059
+            $response = curl_exec($ch);
1060 1060
             
1061
-            if ( curl_errno( $ch ) ) {
1062
-                wpinv_error_log( curl_error( $ch ), 'VIES CHECK ERROR' );
1061
+            if (curl_errno($ch)) {
1062
+                wpinv_error_log(curl_error($ch), 'VIES CHECK ERROR');
1063 1063
                 $response = '';
1064 1064
             }
1065 1065
             
1066
-            curl_close( $ch );
1066
+            curl_close($ch);
1067 1067
         } else {
1068
-            wpinv_error_log( 'To use VIES CHECK you must have allow_url_fopen is ON or cURL installed & active on your server.', 'VIES CHECK ERROR' );
1068
+            wpinv_error_log('To use VIES CHECK you must have allow_url_fopen is ON or cURL installed & active on your server.', 'VIES CHECK ERROR');
1069 1069
         }
1070 1070
         
1071
-        if ( empty( $response ) ) {
1071
+        if (empty($response)) {
1072 1072
             return $result;
1073 1073
         }
1074 1074
 
1075
-        if ( preg_match( '/invalid VAT number/i', $response ) ) {
1075
+        if (preg_match('/invalid VAT number/i', $response)) {
1076 1076
             return false;
1077
-        } else if ( preg_match( '/valid VAT number/i', $response, $matches ) ) {
1078
-            $content = explode( "valid VAT number", htmlentities( $response ) );
1077
+        } else if (preg_match('/valid VAT number/i', $response, $matches)) {
1078
+            $content = explode("valid VAT number", htmlentities($response));
1079 1079
             
1080
-            if ( !empty( $content[1] ) ) {
1081
-                preg_match_all( '/<tr>(.*?)<td.*?>(.*?)<\/td>(.*?)<\/tr>/si', html_entity_decode( $content[1] ), $matches );
1080
+            if (!empty($content[1])) {
1081
+                preg_match_all('/<tr>(.*?)<td.*?>(.*?)<\/td>(.*?)<\/tr>/si', html_entity_decode($content[1]), $matches);
1082 1082
                 
1083
-                if ( !empty( $matches[2] ) && $matches[3] ) {
1083
+                if (!empty($matches[2]) && $matches[3]) {
1084 1084
                     $return = array();
1085 1085
                     
1086
-                    foreach ( $matches[2] as $key => $label ) {
1087
-                        $label = trim( $label );
1086
+                    foreach ($matches[2] as $key => $label) {
1087
+                        $label = trim($label);
1088 1088
                         
1089
-                        switch ( strtolower( $label ) ) {
1089
+                        switch (strtolower($label)) {
1090 1090
                             case 'member state':
1091
-                                $return['state'] = trim( strip_tags( $matches[3][$key] ) );
1091
+                                $return['state'] = trim(strip_tags($matches[3][$key]));
1092 1092
                             break;
1093 1093
                             case 'vat number':
1094
-                                $return['number'] = trim( strip_tags( $matches[3][$key] ) );
1094
+                                $return['number'] = trim(strip_tags($matches[3][$key]));
1095 1095
                             break;
1096 1096
                             case 'name':
1097
-                                $return['company'] = trim( strip_tags( $matches[3][$key] ) );
1097
+                                $return['company'] = trim(strip_tags($matches[3][$key]));
1098 1098
                             break;
1099 1099
                             case 'address':
1100
-                                $address           = str_replace( array( "<br><br>", "<br /><br />", "<br/><br/>" ), "<br>", html_entity_decode( trim( $matches[3][$key] ) ) );
1101
-                                $return['address'] = trim( strip_tags( $address, '<br>' ) );
1100
+                                $address           = str_replace(array("<br><br>", "<br /><br />", "<br/><br/>"), "<br>", html_entity_decode(trim($matches[3][$key])));
1101
+                                $return['address'] = trim(strip_tags($address, '<br>'));
1102 1102
                             break;
1103 1103
                             case 'consultation number':
1104
-                                $return['consultation'] = trim( strip_tags( $matches[3][$key] ) );
1104
+                                $return['consultation'] = trim(strip_tags($matches[3][$key]));
1105 1105
                             break;
1106 1106
                         }
1107 1107
                     }
1108 1108
                     
1109
-                    if ( !empty( $return ) ) {
1109
+                    if (!empty($return)) {
1110 1110
                         return $return;
1111 1111
                     }
1112 1112
                 }
@@ -1118,55 +1118,55 @@  discard block
 block discarded – undo
1118 1118
         }
1119 1119
     }
1120 1120
     
1121
-    public static function check_vat( $vat_number, $country_code = '' ) {        
1121
+    public static function check_vat($vat_number, $country_code = '') {        
1122 1122
         $vat_name           = self::get_vat_name();
1123 1123
         
1124 1124
         $return             = array();
1125 1125
         $return['valid']    = false;
1126
-        $return['message']  = wp_sprintf( __( '%s number not validated', 'invoicing' ), $vat_name );
1126
+        $return['message']  = wp_sprintf(__('%s number not validated', 'invoicing'), $vat_name);
1127 1127
                 
1128
-        if ( !wpinv_get_option( 'vat_offline_check' ) && !self::offline_check( $vat_number, $country_code ) ) {
1128
+        if (!wpinv_get_option('vat_offline_check') && !self::offline_check($vat_number, $country_code)) {
1129 1129
             return $return;
1130 1130
         }
1131 1131
             
1132
-        $response = self::vies_check( $vat_number, $country_code );
1132
+        $response = self::vies_check($vat_number, $country_code);
1133 1133
         
1134
-        if ( $response ) {
1135
-            $return['valid']    = true;
1134
+        if ($response) {
1135
+            $return['valid'] = true;
1136 1136
             
1137
-            if ( is_array( $response ) ) {
1138
-                $return['company'] = isset( $response['company'] ) ? $response['company'] : '';
1139
-                $return['address'] = isset( $response['address'] ) ? $response['address'] : '';
1137
+            if (is_array($response)) {
1138
+                $return['company'] = isset($response['company']) ? $response['company'] : '';
1139
+                $return['address'] = isset($response['address']) ? $response['address'] : '';
1140 1140
                 $return['message'] = $return['company'] . '<br/>' . $return['address'];
1141 1141
             }
1142 1142
         } else {
1143 1143
             $return['valid']    = false;
1144
-            $return['message']  = wp_sprintf( __( 'Fail to validate the %s number: EU Commission VAT server (VIES) check fails.', 'invoicing' ), $vat_name );
1144
+            $return['message']  = wp_sprintf(__('Fail to validate the %s number: EU Commission VAT server (VIES) check fails.', 'invoicing'), $vat_name);
1145 1145
         }
1146 1146
         
1147 1147
         return $return;
1148 1148
     }
1149 1149
     
1150
-    public static function request_euvatrates( $group ) {
1150
+    public static function request_euvatrates($group) {
1151 1151
         $response               = array();
1152 1152
         $response['success']    = false;
1153 1153
         $response['error']      = null;
1154 1154
         $response['eurates']    = null;
1155 1155
         
1156 1156
         $euvatrates_url = 'https://euvatrates.com/rates.json';
1157
-        $euvatrates_url = apply_filters( 'wpinv_euvatrates_url', $euvatrates_url );
1158
-        $api_response   = wp_remote_get( $euvatrates_url );
1157
+        $euvatrates_url = apply_filters('wpinv_euvatrates_url', $euvatrates_url);
1158
+        $api_response   = wp_remote_get($euvatrates_url);
1159 1159
     
1160 1160
         try {
1161
-            if ( is_wp_error( $api_response ) ) {
1162
-                $response['error']      = __( $api_response->get_error_message(), 'invoicing' );
1161
+            if (is_wp_error($api_response)) {
1162
+                $response['error'] = __($api_response->get_error_message(), 'invoicing');
1163 1163
             } else {
1164
-                $body = json_decode( $api_response['body'] );
1164
+                $body = json_decode($api_response['body']);
1165 1165
                 
1166
-                if ( isset( $body->rates ) ) {
1166
+                if (isset($body->rates)) {
1167 1167
                     $rates = array();
1168 1168
                     
1169
-                    foreach ( $body->rates as $country_code => $rate ) {
1169
+                    foreach ($body->rates as $country_code => $rate) {
1170 1170
                         $vat_rate = array();
1171 1171
                         $vat_rate['country']        = $rate->country;
1172 1172
                         $vat_rate['standard']       = (float)$rate->standard_rate;
@@ -1174,7 +1174,7 @@  discard block
 block discarded – undo
1174 1174
                         $vat_rate['superreduced']   = (float)$rate->super_reduced_rate;
1175 1175
                         $vat_rate['parking']        = (float)$rate->parking_rate;
1176 1176
                         
1177
-                        if ( $group !== '' && in_array( $group, array( 'standard', 'reduced', 'superreduced', 'parking' ) ) ) {
1177
+                        if ($group !== '' && in_array($group, array('standard', 'reduced', 'superreduced', 'parking'))) {
1178 1178
                             $vat_rate_group = array();
1179 1179
                             $vat_rate_group['country'] = $rate->country;
1180 1180
                             $vat_rate_group[$group]    = $vat_rate[$group];
@@ -1186,79 +1186,79 @@  discard block
 block discarded – undo
1186 1186
                     }
1187 1187
                     
1188 1188
                     $response['success']    = true;                                
1189
-                    $response['rates']      = apply_filters( 'wpinv_process_euvatrates', $rates, $api_response, $group );
1189
+                    $response['rates']      = apply_filters('wpinv_process_euvatrates', $rates, $api_response, $group);
1190 1190
                 } else {
1191
-                    $response['error']      = __( 'No EU rates found!', 'invoicing' );
1191
+                    $response['error']      = __('No EU rates found!', 'invoicing');
1192 1192
                 }
1193 1193
             }
1194
-        } catch ( Exception $e ) {
1195
-            $response['error'] = __( $e->getMessage(), 'invoicing' );
1194
+        } catch (Exception $e) {
1195
+            $response['error'] = __($e->getMessage(), 'invoicing');
1196 1196
         }
1197 1197
         
1198
-        return apply_filters( 'wpinv_response_euvatrates', $response, $group );
1198
+        return apply_filters('wpinv_response_euvatrates', $response, $group);
1199 1199
     }    
1200 1200
     
1201
-    public static function requires_vat( $requires_vat = false, $user_id = 0, $is_digital = null ) {
1201
+    public static function requires_vat($requires_vat = false, $user_id = 0, $is_digital = null) {
1202 1202
         global $wpi_item_id, $wpi_country;
1203 1203
         
1204
-        if ( !empty( $_POST['wpinv_country'] ) ) {
1205
-            $country_code = trim( $_POST['wpinv_country'] );
1206
-        } else if ( !empty( $_POST['country'] ) ) {
1207
-            $country_code = trim( $_POST['country'] );
1208
-        } else if ( !empty( $wpi_country ) ) {
1204
+        if (!empty($_POST['wpinv_country'])) {
1205
+            $country_code = trim($_POST['wpinv_country']);
1206
+        } else if (!empty($_POST['country'])) {
1207
+            $country_code = trim($_POST['country']);
1208
+        } else if (!empty($wpi_country)) {
1209 1209
             $country_code = $wpi_country;
1210 1210
         } else {
1211
-            $country_code = self::get_user_country( '', $user_id );
1211
+            $country_code = self::get_user_country('', $user_id);
1212 1212
         }
1213 1213
         
1214
-        if ( $is_digital === null && $wpi_item_id ) {
1215
-            $is_digital = $wpi_item_id ? self::item_has_digital_rule( $wpi_item_id ) : self::allow_vat_rules();
1214
+        if ($is_digital === null && $wpi_item_id) {
1215
+            $is_digital = $wpi_item_id ? self::item_has_digital_rule($wpi_item_id) : self::allow_vat_rules();
1216 1216
         }
1217 1217
         
1218
-        if ( !empty( $country_code ) ) {
1219
-            $requires_vat = ( self::is_eu_state( $country_code ) && ( self::is_eu_state( self::$default_country ) || $is_digital ) ) || ( self::is_gst_country( $country_code ) && self::is_gst_country( self::$default_country ) );
1218
+        if (!empty($country_code)) {
1219
+            $requires_vat = (self::is_eu_state($country_code) && (self::is_eu_state(self::$default_country) || $is_digital)) || (self::is_gst_country($country_code) && self::is_gst_country(self::$default_country));
1220 1220
         }
1221 1221
         
1222
-        return apply_filters( 'wpinv_requires_vat', $requires_vat, $user_id );
1222
+        return apply_filters('wpinv_requires_vat', $requires_vat, $user_id);
1223 1223
     }
1224 1224
     
1225
-    public static function tax_label( $label = '' ) {
1225
+    public static function tax_label($label = '') {
1226 1226
         global $wpi_requires_vat;
1227 1227
         
1228
-        if ( !( $wpi_requires_vat !== 0 && $wpi_requires_vat ) ) {
1229
-            $wpi_requires_vat = self::requires_vat( 0, false );
1228
+        if (!($wpi_requires_vat !== 0 && $wpi_requires_vat)) {
1229
+            $wpi_requires_vat = self::requires_vat(0, false);
1230 1230
         }
1231 1231
         
1232
-        return $wpi_requires_vat ? __( self::get_vat_name(), 'invoicing' ) : ( $label ? $label : __( 'Tax', 'invoicing' ) );
1232
+        return $wpi_requires_vat ? __(self::get_vat_name(), 'invoicing') : ($label ? $label : __('Tax', 'invoicing'));
1233 1233
     }
1234 1234
     
1235 1235
     public static function standard_rates_label() {
1236
-        return __( 'Standard Rates', 'invoicing' );
1236
+        return __('Standard Rates', 'invoicing');
1237 1237
     }
1238 1238
     
1239
-    public static function get_rate_classes( $with_desc = false ) {        
1240
-        $rate_classes_option = get_option( '_wpinv_vat_rate_classes', true );
1241
-        $classes = maybe_unserialize( $rate_classes_option );
1239
+    public static function get_rate_classes($with_desc = false) {        
1240
+        $rate_classes_option = get_option('_wpinv_vat_rate_classes', true);
1241
+        $classes = maybe_unserialize($rate_classes_option);
1242 1242
         
1243
-        if ( empty( $classes ) || !is_array( $classes ) ) {
1243
+        if (empty($classes) || !is_array($classes)) {
1244 1244
             $classes = array();
1245 1245
         }
1246 1246
 
1247 1247
         $rate_classes = array();
1248
-        if ( !array_key_exists( '_standard', $classes ) ) {
1249
-            if ( $with_desc ) {
1250
-                $rate_classes['_standard'] = array( 'name' => self::standard_rates_label(), 'desc' => __( 'EU member states standard VAT rates', 'invoicing' ) );
1248
+        if (!array_key_exists('_standard', $classes)) {
1249
+            if ($with_desc) {
1250
+                $rate_classes['_standard'] = array('name' => self::standard_rates_label(), 'desc' => __('EU member states standard VAT rates', 'invoicing'));
1251 1251
             } else {
1252 1252
                 $rate_classes['_standard'] = self::standard_rates_label();
1253 1253
             }
1254 1254
         }
1255 1255
         
1256
-        foreach ( $classes as $key => $class ) {
1257
-            $name = !empty( $class['name'] ) ? __( $class['name'], 'invoicing' ) : $key;
1258
-            $desc = !empty( $class['desc'] ) ? __( $class['desc'], 'invoicing' ) : '';
1256
+        foreach ($classes as $key => $class) {
1257
+            $name = !empty($class['name']) ? __($class['name'], 'invoicing') : $key;
1258
+            $desc = !empty($class['desc']) ? __($class['desc'], 'invoicing') : '';
1259 1259
             
1260
-            if ( $with_desc ) {
1261
-                $rate_classes[$key] = array( 'name' => $name, 'desc' => $desc );
1260
+            if ($with_desc) {
1261
+                $rate_classes[$key] = array('name' => $name, 'desc' => $desc);
1262 1262
             } else {
1263 1263
                 $rate_classes[$key] = $name;
1264 1264
             }
@@ -1269,15 +1269,15 @@  discard block
 block discarded – undo
1269 1269
     
1270 1270
     public static function get_all_classes() {        
1271 1271
         $classes            = self::get_rate_classes();
1272
-        $classes['_exempt'] = __( 'Exempt (0%)', 'invoicing' );
1272
+        $classes['_exempt'] = __('Exempt (0%)', 'invoicing');
1273 1273
         
1274
-        return apply_filters( 'wpinv_vat_get_all_classes', $classes );
1274
+        return apply_filters('wpinv_vat_get_all_classes', $classes);
1275 1275
     }
1276 1276
     
1277
-    public static function get_class_desc( $rate_class ) {        
1278
-        $rate_classes = self::get_rate_classes( true );
1277
+    public static function get_class_desc($rate_class) {        
1278
+        $rate_classes = self::get_rate_classes(true);
1279 1279
 
1280
-        if ( !empty( $rate_classes ) && isset( $rate_classes[$rate_class] ) && isset( $rate_classes[$rate_class]['desc'] ) ) {
1280
+        if (!empty($rate_classes) && isset($rate_classes[$rate_class]) && isset($rate_classes[$rate_class]['desc'])) {
1281 1281
             return $rate_classes[$rate_class]['desc'];
1282 1282
         }
1283 1283
         
@@ -1293,106 +1293,106 @@  discard block
 block discarded – undo
1293 1293
             'increased'     => 'Increased'
1294 1294
         );
1295 1295
         
1296
-        return apply_filters( 'wpinv_get_vat_groups', $vat_groups );
1296
+        return apply_filters('wpinv_get_vat_groups', $vat_groups);
1297 1297
     }
1298 1298
 
1299 1299
     public static function get_rules() {
1300 1300
         $vat_rules = array(
1301
-            'digital' => __( 'Digital Product', 'invoicing' ),
1302
-            'physical' => __( 'Physical Product', 'invoicing' )
1301
+            'digital' => __('Digital Product', 'invoicing'),
1302
+            'physical' => __('Physical Product', 'invoicing')
1303 1303
         );
1304
-        return apply_filters( 'wpinv_get_vat_rules', $vat_rules );
1304
+        return apply_filters('wpinv_get_vat_rules', $vat_rules);
1305 1305
     }
1306 1306
 
1307
-    public static function get_vat_rates( $class ) {
1308
-        if ( $class === '_standard' ) {
1307
+    public static function get_vat_rates($class) {
1308
+        if ($class === '_standard') {
1309 1309
             return wpinv_get_tax_rates();
1310 1310
         }
1311 1311
 
1312 1312
         $rates = self::get_non_standard_rates();
1313 1313
 
1314
-        return array_key_exists( $class, $rates ) ? $rates[$class] : array();
1314
+        return array_key_exists($class, $rates) ? $rates[$class] : array();
1315 1315
     }
1316 1316
 
1317 1317
     public static function get_non_standard_rates() {
1318
-        $option = get_option( 'wpinv_vat_rates', array());
1319
-        return is_array( $option ) ? $option : array();
1318
+        $option = get_option('wpinv_vat_rates', array());
1319
+        return is_array($option) ? $option : array();
1320 1320
     }
1321 1321
     
1322 1322
     public static function allow_vat_rules() {
1323
-        return ( wpinv_use_taxes() && wpinv_get_option( 'apply_vat_rules' ) ? true : false );
1323
+        return (wpinv_use_taxes() && wpinv_get_option('apply_vat_rules') ? true : false);
1324 1324
     }
1325 1325
     
1326 1326
     public static function allow_vat_classes() {
1327 1327
         return false; // TODO
1328
-        return ( wpinv_get_option( 'vat_allow_classes' ) ? true : false );
1328
+        return (wpinv_get_option('vat_allow_classes') ? true : false);
1329 1329
     }
1330 1330
     
1331
-    public static function get_item_class( $postID ) {
1332
-        $class = get_post_meta( $postID, '_wpinv_vat_class', true );
1331
+    public static function get_item_class($postID) {
1332
+        $class = get_post_meta($postID, '_wpinv_vat_class', true);
1333 1333
 
1334
-        if ( empty( $class ) ) {
1334
+        if (empty($class)) {
1335 1335
             $class = '_standard';
1336 1336
         }
1337 1337
         
1338
-        return apply_filters( 'wpinv_get_item_vat_class', $class, $postID );
1338
+        return apply_filters('wpinv_get_item_vat_class', $class, $postID);
1339 1339
     }
1340 1340
     
1341
-    public static function item_class_label( $postID ) {        
1341
+    public static function item_class_label($postID) {        
1342 1342
         $vat_classes = self::get_all_classes();
1343 1343
         
1344
-        $class = self::get_item_class( $postID );
1345
-        $class = isset( $vat_classes[$class] ) ? $vat_classes[$class] : __( $class, 'invoicing' );
1344
+        $class = self::get_item_class($postID);
1345
+        $class = isset($vat_classes[$class]) ? $vat_classes[$class] : __($class, 'invoicing');
1346 1346
         
1347
-        return apply_filters( 'wpinv_item_class_label', $class, $postID );
1347
+        return apply_filters('wpinv_item_class_label', $class, $postID);
1348 1348
     }
1349 1349
     
1350
-    public static function get_item_rule( $postID ) {        
1351
-        $rule_type = get_post_meta( $postID, '_wpinv_vat_rule', true );
1350
+    public static function get_item_rule($postID) {        
1351
+        $rule_type = get_post_meta($postID, '_wpinv_vat_rule', true);
1352 1352
         
1353
-        if ( empty( $rule_type ) ) {        
1353
+        if (empty($rule_type)) {        
1354 1354
             $rule_type = self::allow_vat_rules() ? 'digital' : 'physical';
1355 1355
         }
1356 1356
         
1357
-        return apply_filters( 'wpinv_item_get_vat_rule', $rule_type, $postID );
1357
+        return apply_filters('wpinv_item_get_vat_rule', $rule_type, $postID);
1358 1358
     }
1359 1359
     
1360
-    public static function item_rule_label( $postID ) {
1360
+    public static function item_rule_label($postID) {
1361 1361
         $vat_rules  = self::get_rules();
1362
-        $vat_rule   = self::get_item_rule( $postID );
1363
-        $vat_rule   = isset( $vat_rules[$vat_rule] ) ? $vat_rules[$vat_rule] : $vat_rule;
1362
+        $vat_rule   = self::get_item_rule($postID);
1363
+        $vat_rule   = isset($vat_rules[$vat_rule]) ? $vat_rules[$vat_rule] : $vat_rule;
1364 1364
         
1365
-        return apply_filters( 'wpinv_item_rule_label', $vat_rule, $postID );
1365
+        return apply_filters('wpinv_item_rule_label', $vat_rule, $postID);
1366 1366
     }
1367 1367
     
1368
-    public static function item_has_digital_rule( $item_id = 0 ) {        
1369
-        return self::get_item_rule( $item_id ) == 'digital' ? true : false;
1368
+    public static function item_has_digital_rule($item_id = 0) {        
1369
+        return self::get_item_rule($item_id) == 'digital' ? true : false;
1370 1370
     }
1371 1371
     
1372
-    public static function invoice_has_digital_rule( $invoice = 0 ) {        
1373
-        if ( !self::allow_vat_rules() ) {
1372
+    public static function invoice_has_digital_rule($invoice = 0) {        
1373
+        if (!self::allow_vat_rules()) {
1374 1374
             return false;
1375 1375
         }
1376 1376
         
1377
-        if ( empty( $invoice ) ) {
1377
+        if (empty($invoice)) {
1378 1378
             return true;
1379 1379
         }
1380 1380
         
1381
-        if ( is_int( $invoice ) ) {
1382
-            $invoice = new WPInv_Invoice( $invoice );
1381
+        if (is_int($invoice)) {
1382
+            $invoice = new WPInv_Invoice($invoice);
1383 1383
         }
1384 1384
         
1385
-        if ( !( is_object( $invoice ) && is_a( $invoice, 'WPInv_Invoice' ) ) ) {
1385
+        if (!(is_object($invoice) && is_a($invoice, 'WPInv_Invoice'))) {
1386 1386
             return true;
1387 1387
         }
1388 1388
         
1389
-        $cart_items  = $invoice->get_cart_details();
1389
+        $cart_items = $invoice->get_cart_details();
1390 1390
         
1391
-        if ( !empty( $cart_items ) ) {
1391
+        if (!empty($cart_items)) {
1392 1392
             $has_digital_rule = false;
1393 1393
             
1394
-            foreach ( $cart_items as $key => $item ) {
1395
-                if ( self::item_has_digital_rule( $item['id'] ) ) {
1394
+            foreach ($cart_items as $key => $item) {
1395
+                if (self::item_has_digital_rule($item['id'])) {
1396 1396
                     $has_digital_rule = true;
1397 1397
                     break;
1398 1398
                 }
@@ -1404,67 +1404,67 @@  discard block
 block discarded – undo
1404 1404
         return $has_digital_rule;
1405 1405
     }
1406 1406
     
1407
-    public static function item_is_taxable( $item_id = 0, $country = false, $state = false ) {        
1408
-        if ( !wpinv_use_taxes() ) {
1407
+    public static function item_is_taxable($item_id = 0, $country = false, $state = false) {        
1408
+        if (!wpinv_use_taxes()) {
1409 1409
             return false;
1410 1410
         }
1411 1411
         
1412 1412
         $is_taxable = true;
1413 1413
 
1414
-        if ( !empty( $item_id ) && self::get_item_class( $item_id ) == '_exempt' ) {
1414
+        if (!empty($item_id) && self::get_item_class($item_id) == '_exempt') {
1415 1415
             $is_taxable = false;
1416 1416
         }
1417 1417
         
1418
-        return apply_filters( 'wpinv_item_is_taxable', $is_taxable, $item_id, $country , $state );
1418
+        return apply_filters('wpinv_item_is_taxable', $is_taxable, $item_id, $country, $state);
1419 1419
     }
1420 1420
     
1421
-    public static function find_rate( $country, $state, $rate, $class ) {
1421
+    public static function find_rate($country, $state, $rate, $class) {
1422 1422
         global $wpi_zero_tax;
1423 1423
 
1424
-        if ( $class === '_exempt' || $wpi_zero_tax ) {
1424
+        if ($class === '_exempt' || $wpi_zero_tax) {
1425 1425
             return 0;
1426 1426
         }
1427 1427
 
1428
-        $tax_rates   = wpinv_get_tax_rates();
1428
+        $tax_rates = wpinv_get_tax_rates();
1429 1429
         
1430
-        if ( $class !== '_standard' ) {
1431
-            $class_rates = self::get_vat_rates( $class );
1430
+        if ($class !== '_standard') {
1431
+            $class_rates = self::get_vat_rates($class);
1432 1432
             
1433
-            if ( is_array( $class_rates ) ) {
1433
+            if (is_array($class_rates)) {
1434 1434
                 $indexed_class_rates = array();
1435 1435
                 
1436
-                foreach ( $class_rates as $key => $cr ) {
1436
+                foreach ($class_rates as $key => $cr) {
1437 1437
                     $indexed_class_rates[$cr['country']] = $cr;
1438 1438
                 }
1439 1439
 
1440
-                $tax_rates = array_map( function( $tr ) use( $indexed_class_rates ) {
1440
+                $tax_rates = array_map(function($tr) use($indexed_class_rates) {
1441 1441
                     $tr_country = $tr['country'];
1442
-                    if ( !isset( $indexed_class_rates[$tr_country] ) ) {
1442
+                    if (!isset($indexed_class_rates[$tr_country])) {
1443 1443
                         return $tr;
1444 1444
                     }
1445 1445
                     $icr = $indexed_class_rates[$tr_country];
1446
-                    return ( empty( $icr['rate'] ) && $icr['rate'] !== '0' ) ? $tr : $icr;
1446
+                    return (empty($icr['rate']) && $icr['rate'] !== '0') ? $tr : $icr;
1447 1447
 
1448
-                }, $tax_rates, $class_rates );
1448
+                }, $tax_rates, $class_rates);
1449 1449
             }
1450 1450
         }
1451 1451
 
1452
-        if ( !empty( $tax_rates ) ) {
1453
-            foreach ( $tax_rates as $key => $tax_rate ) {
1454
-                if ( $country != $tax_rate['country'] )
1452
+        if (!empty($tax_rates)) {
1453
+            foreach ($tax_rates as $key => $tax_rate) {
1454
+                if ($country != $tax_rate['country'])
1455 1455
                     continue;
1456 1456
 
1457
-                if ( !empty( $tax_rate['global'] ) ) {
1458
-                    if ( 0 !== $tax_rate['rate'] || !empty( $tax_rate['rate'] ) ) {
1459
-                        $rate = number_format( $tax_rate['rate'], 4 );
1457
+                if (!empty($tax_rate['global'])) {
1458
+                    if (0 !== $tax_rate['rate'] || !empty($tax_rate['rate'])) {
1459
+                        $rate = number_format($tax_rate['rate'], 4);
1460 1460
                     }
1461 1461
                 } else {
1462
-                    if ( empty( $tax_rate['state'] ) || strtolower( $state ) != strtolower( $tax_rate['state'] ) )
1462
+                    if (empty($tax_rate['state']) || strtolower($state) != strtolower($tax_rate['state']))
1463 1463
                         continue;
1464 1464
 
1465 1465
                     $state_rate = $tax_rate['rate'];
1466
-                    if ( 0 !== $state_rate || !empty( $state_rate ) ) {
1467
-                        $rate = number_format( $state_rate, 4 );
1466
+                    if (0 !== $state_rate || !empty($state_rate)) {
1467
+                        $rate = number_format($state_rate, 4);
1468 1468
                     }
1469 1469
                 }
1470 1470
             }
@@ -1473,84 +1473,84 @@  discard block
 block discarded – undo
1473 1473
         return $rate;
1474 1474
     }
1475 1475
     
1476
-    public static function get_rate( $rate = 1, $country = '', $state = '', $item_id = 0 ) {
1476
+    public static function get_rate($rate = 1, $country = '', $state = '', $item_id = 0) {
1477 1477
         global $wpinv_options, $wpi_session, $wpi_item_id, $wpi_zero_tax;
1478 1478
         
1479 1479
         $item_id = $item_id > 0 ? $item_id : $wpi_item_id;
1480 1480
         $allow_vat_classes = self::allow_vat_classes();
1481
-        $class = $item_id ? self::get_item_class( $item_id ) : '_standard';
1481
+        $class = $item_id ? self::get_item_class($item_id) : '_standard';
1482 1482
 
1483
-        if ( $class === '_exempt' || $wpi_zero_tax ) {
1483
+        if ($class === '_exempt' || $wpi_zero_tax) {
1484 1484
             return 0;
1485
-        } else if ( !$allow_vat_classes ) {
1485
+        } else if (!$allow_vat_classes) {
1486 1486
             $class = '_standard';
1487 1487
         }
1488 1488
 
1489
-        if( !empty( $_POST['wpinv_country'] ) ) {
1489
+        if (!empty($_POST['wpinv_country'])) {
1490 1490
             $post_country = $_POST['wpinv_country'];
1491
-        } elseif( !empty( $_POST['wpinv_country'] ) ) {
1491
+        } elseif (!empty($_POST['wpinv_country'])) {
1492 1492
             $post_country = $_POST['wpinv_country'];
1493
-        } elseif( !empty( $_POST['country'] ) ) {
1493
+        } elseif (!empty($_POST['country'])) {
1494 1494
             $post_country = $_POST['country'];
1495 1495
         } else {
1496 1496
             $post_country = '';
1497 1497
         }
1498 1498
 
1499
-        $country        = !empty( $post_country ) ? $post_country : wpinv_default_billing_country( $country );
1500
-        $base_country   = wpinv_is_base_country( $country );
1499
+        $country        = !empty($post_country) ? $post_country : wpinv_default_billing_country($country);
1500
+        $base_country   = wpinv_is_base_country($country);
1501 1501
         
1502
-        $requires_vat   = self::requires_vat( 0, false );
1503
-        $is_digital     = self::get_item_rule( $item_id ) == 'digital' ;
1504
-        $rate           = $requires_vat && isset( $wpinv_options['eu_fallback_rate'] ) ? $wpinv_options['eu_fallback_rate'] : $rate;
1502
+        $requires_vat   = self::requires_vat(0, false);
1503
+        $is_digital     = self::get_item_rule($item_id) == 'digital';
1504
+        $rate           = $requires_vat && isset($wpinv_options['eu_fallback_rate']) ? $wpinv_options['eu_fallback_rate'] : $rate;
1505 1505
           
1506
-        if ( self::same_country_rule() == 'no' && $base_country ) { // Disable VAT to same country
1506
+        if (self::same_country_rule() == 'no' && $base_country) { // Disable VAT to same country
1507 1507
             $rate = 0;
1508
-        } else if ( $requires_vat ) {
1509
-            $vat_number = self::get_user_vat_number( '', 0, true );
1508
+        } else if ($requires_vat) {
1509
+            $vat_number = self::get_user_vat_number('', 0, true);
1510 1510
             $vat_info   = self::current_vat_data();
1511 1511
             
1512
-            if ( is_array( $vat_info ) ) {
1513
-                $vat_number = isset( $vat_info['number'] ) && !empty( $vat_info['valid'] ) ? $vat_info['number'] : "";
1512
+            if (is_array($vat_info)) {
1513
+                $vat_number = isset($vat_info['number']) && !empty($vat_info['valid']) ? $vat_info['number'] : "";
1514 1514
             }
1515 1515
             
1516
-            if ( $country == 'UK' ) {
1516
+            if ($country == 'UK') {
1517 1517
                 $country = 'GB';
1518 1518
             }
1519 1519
 
1520
-            if ( !empty( $vat_number ) ) {
1520
+            if (!empty($vat_number)) {
1521 1521
                 $rate = 0;
1522 1522
             } else {
1523
-                $rate = self::find_rate( $country, $state, $rate, $class ); // Fix if there are no tax rated and you try to pay an invoice it does not add the fallback tax rate
1523
+                $rate = self::find_rate($country, $state, $rate, $class); // Fix if there are no tax rated and you try to pay an invoice it does not add the fallback tax rate
1524 1524
             }
1525 1525
 
1526
-            if ( empty( $vat_number ) && !$is_digital ) {
1527
-                if ( $base_country ) {
1528
-                    $rate = self::find_rate( $country, null, $rate, $class );
1526
+            if (empty($vat_number) && !$is_digital) {
1527
+                if ($base_country) {
1528
+                    $rate = self::find_rate($country, null, $rate, $class);
1529 1529
                 } else {
1530
-                    if ( empty( $country ) && isset( $wpinv_options['eu_fallback_rate'] ) ) {
1530
+                    if (empty($country) && isset($wpinv_options['eu_fallback_rate'])) {
1531 1531
                         $rate = $wpinv_options['eu_fallback_rate'];
1532
-                    } else if( !empty( $country ) ) {
1533
-                        $rate = self::find_rate( $country, $state, $rate, $class );
1532
+                    } else if (!empty($country)) {
1533
+                        $rate = self::find_rate($country, $state, $rate, $class);
1534 1534
                     }
1535 1535
                 }
1536
-            } else if ( empty( $vat_number ) || ( self::same_country_rule() == 'always' && $base_country ) ) {
1537
-                if ( empty( $country ) && isset( $wpinv_options['eu_fallback_rate'] ) ) {
1536
+            } else if (empty($vat_number) || (self::same_country_rule() == 'always' && $base_country)) {
1537
+                if (empty($country) && isset($wpinv_options['eu_fallback_rate'])) {
1538 1538
                     $rate = $wpinv_options['eu_fallback_rate'];
1539
-                } else if( !empty( $country ) ) {
1540
-                    $rate = self::find_rate( $country, $state, $rate, $class );
1539
+                } else if (!empty($country)) {
1540
+                    $rate = self::find_rate($country, $state, $rate, $class);
1541 1541
                 }
1542 1542
             }
1543 1543
         } else {
1544
-            if ( $is_digital ) {
1544
+            if ($is_digital) {
1545 1545
                 $ip_country_code = self::get_country_by_ip();
1546 1546
                 
1547
-                if ( $ip_country_code && self::is_eu_state( $ip_country_code ) ) {
1548
-                    $rate = self::find_rate( $ip_country_code, '', 0, $class );
1547
+                if ($ip_country_code && self::is_eu_state($ip_country_code)) {
1548
+                    $rate = self::find_rate($ip_country_code, '', 0, $class);
1549 1549
                 } else {
1550
-                    $rate = self::find_rate( $country, $state, $rate, $class );
1550
+                    $rate = self::find_rate($country, $state, $rate, $class);
1551 1551
                 }
1552 1552
             } else {
1553
-                $rate = self::find_rate( $country, $state, $rate, $class );
1553
+                $rate = self::find_rate($country, $state, $rate, $class);
1554 1554
             }
1555 1555
         }
1556 1556
 
@@ -1560,48 +1560,48 @@  discard block
 block discarded – undo
1560 1560
     public static function current_vat_data() {
1561 1561
         global $wpi_session;
1562 1562
         
1563
-        return $wpi_session->get( 'user_vat_data' );
1563
+        return $wpi_session->get('user_vat_data');
1564 1564
     }
1565 1565
     
1566
-    public static function get_user_country( $country = '', $user_id = 0 ) {
1567
-        $user_address = wpinv_get_user_address( $user_id, false );
1566
+    public static function get_user_country($country = '', $user_id = 0) {
1567
+        $user_address = wpinv_get_user_address($user_id, false);
1568 1568
         
1569
-        if ( wpinv_get_option( 'vat_ip_country_default' ) ) {
1569
+        if (wpinv_get_option('vat_ip_country_default')) {
1570 1570
             $country = '';
1571 1571
         }
1572 1572
         
1573
-        $country    = empty( $user_address ) || !isset( $user_address['country'] ) || empty( $user_address['country'] ) ? $country : $user_address['country'];
1574
-        $result     = apply_filters( 'wpinv_get_user_country', $country, $user_id );
1573
+        $country    = empty($user_address) || !isset($user_address['country']) || empty($user_address['country']) ? $country : $user_address['country'];
1574
+        $result     = apply_filters('wpinv_get_user_country', $country, $user_id);
1575 1575
 
1576
-        if ( empty( $result ) ) {
1576
+        if (empty($result)) {
1577 1577
             $result = self::get_country_by_ip();
1578 1578
         }
1579 1579
 
1580 1580
         return $result;
1581 1581
     }
1582 1582
     
1583
-    public static function set_user_country( $country = '', $user_id = 0 ) {
1583
+    public static function set_user_country($country = '', $user_id = 0) {
1584 1584
         global $wpi_userID;
1585 1585
         
1586
-        if ( empty($country) && !empty($wpi_userID) && get_current_user_id() != $wpi_userID ) {
1586
+        if (empty($country) && !empty($wpi_userID) && get_current_user_id() != $wpi_userID) {
1587 1587
             $country = wpinv_get_default_country();
1588 1588
         }
1589 1589
         
1590 1590
         return $country;
1591 1591
     }
1592 1592
     
1593
-    public static function get_user_vat_number( $vat_number = '', $user_id = 0, $is_valid = false ) {
1593
+    public static function get_user_vat_number($vat_number = '', $user_id = 0, $is_valid = false) {
1594 1594
         global $wpi_current_id, $wpi_userID;
1595 1595
         
1596
-        if ( !empty( $_POST['new_user'] ) ) {
1596
+        if (!empty($_POST['new_user'])) {
1597 1597
             return '';
1598 1598
         }
1599 1599
         
1600
-        if ( empty( $user_id ) ) {
1601
-            $user_id = !empty( $wpi_userID ) ? $wpi_userID : ( $wpi_current_id ? wpinv_get_user_id( $wpi_current_id ) : get_current_user_id() );
1600
+        if (empty($user_id)) {
1601
+            $user_id = !empty($wpi_userID) ? $wpi_userID : ($wpi_current_id ? wpinv_get_user_id($wpi_current_id) : get_current_user_id());
1602 1602
         }
1603 1603
 
1604
-        $vat_number = empty( $user_id ) ? '' : get_user_meta( $user_id, '_wpinv_vat_number', true );
1604
+        $vat_number = empty($user_id) ? '' : get_user_meta($user_id, '_wpinv_vat_number', true);
1605 1605
         
1606 1606
         /* TODO
1607 1607
         if ( $is_valid && $vat_number ) {
@@ -1612,38 +1612,38 @@  discard block
 block discarded – undo
1612 1612
         }
1613 1613
         */
1614 1614
 
1615
-        return apply_filters('wpinv_get_user_vat_number', $vat_number, $user_id, $is_valid );
1615
+        return apply_filters('wpinv_get_user_vat_number', $vat_number, $user_id, $is_valid);
1616 1616
     }
1617 1617
     
1618
-    public static function get_user_company( $company = '', $user_id = 0 ) {
1618
+    public static function get_user_company($company = '', $user_id = 0) {
1619 1619
         global $wpi_current_id, $wpi_userID;
1620 1620
         
1621
-        if ( empty( $user_id ) ) {
1622
-            $user_id = !empty( $wpi_userID ) ? $wpi_userID : ( $wpi_current_id ? wpinv_get_user_id( $wpi_current_id ) : get_current_user_id() );
1621
+        if (empty($user_id)) {
1622
+            $user_id = !empty($wpi_userID) ? $wpi_userID : ($wpi_current_id ? wpinv_get_user_id($wpi_current_id) : get_current_user_id());
1623 1623
         }
1624 1624
 
1625
-        $company = empty( $user_id ) ? "" : get_user_meta( $user_id, '_wpinv_company', true );
1625
+        $company = empty($user_id) ? "" : get_user_meta($user_id, '_wpinv_company', true);
1626 1626
 
1627
-        return apply_filters( 'wpinv_user_company', $company, $user_id );
1627
+        return apply_filters('wpinv_user_company', $company, $user_id);
1628 1628
     }
1629 1629
     
1630
-    public static function save_user_vat_details( $company = '', $vat_number = '' ) {
1631
-        $save = apply_filters( 'wpinv_allow_save_user_vat_details', true );
1630
+    public static function save_user_vat_details($company = '', $vat_number = '') {
1631
+        $save = apply_filters('wpinv_allow_save_user_vat_details', true);
1632 1632
 
1633
-        if ( is_user_logged_in() && $save ) {
1633
+        if (is_user_logged_in() && $save) {
1634 1634
             $user_id = get_current_user_id();
1635 1635
 
1636
-            if ( !empty( $vat_number ) ) {
1637
-                update_user_meta( $user_id, '_wpinv_vat_number', $vat_number );
1636
+            if (!empty($vat_number)) {
1637
+                update_user_meta($user_id, '_wpinv_vat_number', $vat_number);
1638 1638
             } else {
1639
-                delete_user_meta( $user_id, '_wpinv_vat_number');
1639
+                delete_user_meta($user_id, '_wpinv_vat_number');
1640 1640
             }
1641 1641
 
1642
-            if ( !empty( $company ) ) {
1643
-                update_user_meta( $user_id, '_wpinv_company', $company );
1642
+            if (!empty($company)) {
1643
+                update_user_meta($user_id, '_wpinv_company', $company);
1644 1644
             } else {
1645
-                delete_user_meta( $user_id, '_wpinv_company');
1646
-                delete_user_meta( $user_id, '_wpinv_vat_number');
1645
+                delete_user_meta($user_id, '_wpinv_company');
1646
+                delete_user_meta($user_id, '_wpinv_vat_number');
1647 1647
             }
1648 1648
         }
1649 1649
 
@@ -1653,113 +1653,113 @@  discard block
 block discarded – undo
1653 1653
     public static function ajax_vat_validate() {
1654 1654
         global $wpinv_options, $wpi_session;
1655 1655
         
1656
-        $is_checkout            = ( !empty( $_POST['source'] ) && $_POST['source'] == 'checkout' ) ? true : false;
1656
+        $is_checkout            = (!empty($_POST['source']) && $_POST['source'] == 'checkout') ? true : false;
1657 1657
         $response               = array();
1658 1658
         $response['success']    = false;
1659 1659
         
1660
-        if ( empty( $_REQUEST['_wpi_nonce'] ) || ( !empty( $_REQUEST['_wpi_nonce'] ) && !wp_verify_nonce( $_REQUEST['_wpi_nonce'], 'vat_validation' ) ) ) {
1661
-            $response['error'] = __( 'Invalid security nonce', 'invoicing' );
1662
-            wp_send_json( $response );
1660
+        if (empty($_REQUEST['_wpi_nonce']) || (!empty($_REQUEST['_wpi_nonce']) && !wp_verify_nonce($_REQUEST['_wpi_nonce'], 'vat_validation'))) {
1661
+            $response['error'] = __('Invalid security nonce', 'invoicing');
1662
+            wp_send_json($response);
1663 1663
         }
1664 1664
         
1665
-        $vat_name   = self::get_vat_name();
1665
+        $vat_name = self::get_vat_name();
1666 1666
         
1667
-        if ( $is_checkout ) {
1667
+        if ($is_checkout) {
1668 1668
             $invoice = wpinv_get_invoice_cart();
1669 1669
             
1670
-            if ( !self::requires_vat( false, 0, self::invoice_has_digital_rule( $invoice ) ) ) {
1670
+            if (!self::requires_vat(false, 0, self::invoice_has_digital_rule($invoice))) {
1671 1671
                 $vat_info = array();
1672
-                $wpi_session->set( 'user_vat_data', $vat_info );
1672
+                $wpi_session->set('user_vat_data', $vat_info);
1673 1673
 
1674 1674
                 self::save_user_vat_details();
1675 1675
                 
1676 1676
                 $response['success'] = true;
1677
-                $response['message'] = wp_sprintf( __( 'Ignore %s', 'invoicing' ), $vat_name );
1678
-                wp_send_json( $response );
1677
+                $response['message'] = wp_sprintf(__('Ignore %s', 'invoicing'), $vat_name);
1678
+                wp_send_json($response);
1679 1679
             }
1680 1680
         }
1681 1681
         
1682
-        $company    = !empty( $_POST['company'] ) ? sanitize_text_field( $_POST['company'] ) : '';
1683
-        $vat_number = !empty( $_POST['number'] ) ? sanitize_text_field( $_POST['number'] ) : '';
1682
+        $company    = !empty($_POST['company']) ? sanitize_text_field($_POST['company']) : '';
1683
+        $vat_number = !empty($_POST['number']) ? sanitize_text_field($_POST['number']) : '';
1684 1684
         
1685
-        $vat_info = $wpi_session->get( 'user_vat_data' );
1686
-        if ( !is_array( $vat_info ) || empty( $vat_info ) ) {
1687
-            $vat_info = array( 'company'=> $company, 'number' => '', 'valid' => true );
1685
+        $vat_info = $wpi_session->get('user_vat_data');
1686
+        if (!is_array($vat_info) || empty($vat_info)) {
1687
+            $vat_info = array('company'=> $company, 'number' => '', 'valid' => true);
1688 1688
         }
1689 1689
         
1690
-        if ( empty( $vat_number ) ) {
1691
-            if ( $is_checkout ) {
1690
+        if (empty($vat_number)) {
1691
+            if ($is_checkout) {
1692 1692
                 $response['success'] = true;
1693
-                $response['message'] = wp_sprintf( __( 'No %s number has been applied. %s will be added to invoice totals', 'invoicing' ), $vat_name, $vat_name );
1693
+                $response['message'] = wp_sprintf(__('No %s number has been applied. %s will be added to invoice totals', 'invoicing'), $vat_name, $vat_name);
1694 1694
                 
1695
-                $vat_info = $wpi_session->get( 'user_vat_data' );
1695
+                $vat_info = $wpi_session->get('user_vat_data');
1696 1696
                 $vat_info['number'] = "";
1697 1697
                 $vat_info['valid'] = true;
1698 1698
                 
1699
-                self::save_user_vat_details( $company );
1699
+                self::save_user_vat_details($company);
1700 1700
             } else {
1701
-                $response['error'] = wp_sprintf( __( 'Please enter your %s number!', 'invoicing' ), $vat_name );
1701
+                $response['error'] = wp_sprintf(__('Please enter your %s number!', 'invoicing'), $vat_name);
1702 1702
                 
1703 1703
                 $vat_info['valid'] = false;
1704 1704
             }
1705 1705
 
1706
-            $wpi_session->set( 'user_vat_data', $vat_info );
1707
-            wp_send_json( $response );
1706
+            $wpi_session->set('user_vat_data', $vat_info);
1707
+            wp_send_json($response);
1708 1708
         }
1709 1709
         
1710
-        if ( empty( $company ) ) {
1710
+        if (empty($company)) {
1711 1711
             $vat_info['valid'] = false;
1712
-            $wpi_session->set( 'user_vat_data', $vat_info );
1712
+            $wpi_session->set('user_vat_data', $vat_info);
1713 1713
             
1714
-            $response['error'] = __( 'Please enter your registered company name!', 'invoicing' );
1715
-            wp_send_json( $response );
1714
+            $response['error'] = __('Please enter your registered company name!', 'invoicing');
1715
+            wp_send_json($response);
1716 1716
         }
1717 1717
         
1718
-        if ( !empty( $wpinv_options['vat_vies_check'] ) ) {
1719
-            if ( empty( $wpinv_options['vat_offline_check'] ) && !self::offline_check( $vat_number ) ) {
1718
+        if (!empty($wpinv_options['vat_vies_check'])) {
1719
+            if (empty($wpinv_options['vat_offline_check']) && !self::offline_check($vat_number)) {
1720 1720
                 $vat_info['valid'] = false;
1721
-                $wpi_session->set( 'user_vat_data', $vat_info );
1721
+                $wpi_session->set('user_vat_data', $vat_info);
1722 1722
                 
1723
-                $response['error'] = wp_sprintf( __( '%s number not validated', 'invoicing' ), $vat_name );
1724
-                wp_send_json( $response );
1723
+                $response['error'] = wp_sprintf(__('%s number not validated', 'invoicing'), $vat_name);
1724
+                wp_send_json($response);
1725 1725
             }
1726 1726
             
1727 1727
             $response['success'] = true;
1728
-            $response['message'] = wp_sprintf( __( '%s number validated', 'invoicing' ), $vat_name );
1728
+            $response['message'] = wp_sprintf(__('%s number validated', 'invoicing'), $vat_name);
1729 1729
         } else {
1730
-            $result = self::check_vat( $vat_number );
1730
+            $result = self::check_vat($vat_number);
1731 1731
             
1732
-            if ( empty( $result['valid'] ) ) {
1732
+            if (empty($result['valid'])) {
1733 1733
                 $response['error'] = $result['message'];
1734
-                wp_send_json( $response );
1734
+                wp_send_json($response);
1735 1735
             }
1736 1736
             
1737
-            $vies_company = !empty( $result['company'] ) ? $result['company'] : '';
1738
-            $vies_company = apply_filters( 'wpinv_vies_company_name', $vies_company );
1737
+            $vies_company = !empty($result['company']) ? $result['company'] : '';
1738
+            $vies_company = apply_filters('wpinv_vies_company_name', $vies_company);
1739 1739
             
1740
-            $valid_company = $vies_company && $company && ( $vies_company == '---' || strcasecmp( trim( $vies_company ), trim( $company ) ) == 0 ) ? true : false;
1740
+            $valid_company = $vies_company && $company && ($vies_company == '---' || strcasecmp(trim($vies_company), trim($company)) == 0) ? true : false;
1741 1741
 
1742
-            if ( !empty( $wpinv_options['vat_disable_company_name_check'] ) || $valid_company ) {
1742
+            if (!empty($wpinv_options['vat_disable_company_name_check']) || $valid_company) {
1743 1743
                 $response['success'] = true;
1744
-                $response['message'] = wp_sprintf( __( '%s number validated', 'invoicing' ), $vat_name );
1744
+                $response['message'] = wp_sprintf(__('%s number validated', 'invoicing'), $vat_name);
1745 1745
             } else {           
1746 1746
                 $vat_info['valid'] = false;
1747
-                $wpi_session->set( 'user_vat_data', $vat_info );
1747
+                $wpi_session->set('user_vat_data', $vat_info);
1748 1748
                 
1749 1749
                 $response['success'] = false;
1750
-                $response['message'] = wp_sprintf( __( 'The company name associated with the %s number provided is not the same as the company name provided.', 'invoicing' ), $vat_name );
1751
-                wp_send_json( $response );
1750
+                $response['message'] = wp_sprintf(__('The company name associated with the %s number provided is not the same as the company name provided.', 'invoicing'), $vat_name);
1751
+                wp_send_json($response);
1752 1752
             }
1753 1753
         }
1754 1754
         
1755
-        if ( $is_checkout ) {
1756
-            self::save_user_vat_details( $company, $vat_number );
1755
+        if ($is_checkout) {
1756
+            self::save_user_vat_details($company, $vat_number);
1757 1757
 
1758
-            $vat_info = array('company' => $company, 'number' => $vat_number, 'valid' => true );
1759
-            $wpi_session->set( 'user_vat_data', $vat_info );
1758
+            $vat_info = array('company' => $company, 'number' => $vat_number, 'valid' => true);
1759
+            $wpi_session->set('user_vat_data', $vat_info);
1760 1760
         }
1761 1761
 
1762
-        wp_send_json( $response );
1762
+        wp_send_json($response);
1763 1763
     }
1764 1764
     
1765 1765
     public static function ajax_vat_reset() {
@@ -1768,161 +1768,161 @@  discard block
 block discarded – undo
1768 1768
         $company    = is_user_logged_in() ? self::get_user_company() : '';
1769 1769
         $vat_number = self::get_user_vat_number();
1770 1770
         
1771
-        $vat_info   = array('company' => $company, 'number' => $vat_number, 'valid' => false );
1772
-        $wpi_session->set( 'user_vat_data', $vat_info );
1771
+        $vat_info   = array('company' => $company, 'number' => $vat_number, 'valid' => false);
1772
+        $wpi_session->set('user_vat_data', $vat_info);
1773 1773
         
1774 1774
         $response                       = array();
1775 1775
         $response['success']            = true;
1776 1776
         $response['data']['company']    = $company;
1777 1777
         $response['data']['number']     = $vat_number;
1778 1778
         
1779
-        wp_send_json( $response );
1779
+        wp_send_json($response);
1780 1780
     }
1781 1781
     
1782
-    public static function checkout_vat_validate( $valid_data, $post ) {
1782
+    public static function checkout_vat_validate($valid_data, $post) {
1783 1783
         global $wpinv_options, $wpi_session;
1784 1784
         
1785
-        $vat_name  = __( self::get_vat_name(), 'invoicing' );
1785
+        $vat_name = __(self::get_vat_name(), 'invoicing');
1786 1786
         
1787
-        if ( !isset( $_POST['_wpi_nonce'] ) || !wp_verify_nonce( $_POST['_wpi_nonce'], 'vat_validation' ) ) {
1788
-            wpinv_set_error( 'vat_validation', wp_sprintf( __( "Invalid %s validation request.", 'invoicing' ), $vat_name ) );
1787
+        if (!isset($_POST['_wpi_nonce']) || !wp_verify_nonce($_POST['_wpi_nonce'], 'vat_validation')) {
1788
+            wpinv_set_error('vat_validation', wp_sprintf(__("Invalid %s validation request.", 'invoicing'), $vat_name));
1789 1789
             return;
1790 1790
         }
1791 1791
         
1792
-        $vat_saved = $wpi_session->get( 'user_vat_data' );
1793
-        $wpi_session->set( 'user_vat_data', null );
1792
+        $vat_saved = $wpi_session->get('user_vat_data');
1793
+        $wpi_session->set('user_vat_data', null);
1794 1794
         
1795 1795
         $invoice        = wpinv_get_invoice_cart();
1796 1796
         $amount         = $invoice->get_total();
1797
-        $is_digital     = self::invoice_has_digital_rule( $invoice );
1798
-        $no_vat         = !self::requires_vat( 0, false, $is_digital );
1797
+        $is_digital     = self::invoice_has_digital_rule($invoice);
1798
+        $no_vat         = !self::requires_vat(0, false, $is_digital);
1799 1799
         
1800
-        $company        = !empty( $_POST['wpinv_company'] ) ? $_POST['wpinv_company'] : null;
1801
-        $vat_number     = !empty( $_POST['wpinv_vat_number'] ) ? $_POST['wpinv_vat_number'] : null;
1802
-        $country        = !empty( $_POST['wpinv_country'] ) ? $_POST['wpinv_country'] : $invoice->country;
1803
-        if ( empty( $country ) ) {
1800
+        $company        = !empty($_POST['wpinv_company']) ? $_POST['wpinv_company'] : null;
1801
+        $vat_number     = !empty($_POST['wpinv_vat_number']) ? $_POST['wpinv_vat_number'] : null;
1802
+        $country        = !empty($_POST['wpinv_country']) ? $_POST['wpinv_country'] : $invoice->country;
1803
+        if (empty($country)) {
1804 1804
             $country = wpinv_default_billing_country();
1805 1805
         }
1806 1806
         
1807
-        if ( !$is_digital && $no_vat ) {
1807
+        if (!$is_digital && $no_vat) {
1808 1808
             return;
1809 1809
         }
1810 1810
             
1811
-        $vat_data           = array( 'company' => '', 'number' => '', 'valid' => false );
1811
+        $vat_data           = array('company' => '', 'number' => '', 'valid' => false);
1812 1812
         
1813 1813
         $ip_country_code    = self::get_country_by_ip();
1814
-        $is_eu_state        = self::is_eu_state( $country );
1815
-        $is_eu_state_ip     = self::is_eu_state( $ip_country_code );
1814
+        $is_eu_state        = self::is_eu_state($country);
1815
+        $is_eu_state_ip     = self::is_eu_state($ip_country_code);
1816 1816
         $is_non_eu_user     = !$is_eu_state && !$is_eu_state_ip;
1817 1817
         
1818
-        if ( $is_digital && !$is_non_eu_user && empty( $vat_number ) && apply_filters( 'wpinv_checkout_requires_country', true, $amount ) ) {
1818
+        if ($is_digital && !$is_non_eu_user && empty($vat_number) && apply_filters('wpinv_checkout_requires_country', true, $amount)) {
1819 1819
             $vat_data['adddress_confirmed'] = false;
1820 1820
             
1821
-            if ( !isset( $_POST['wpinv_adddress_confirmed'] ) ) {
1822
-                if ( $ip_country_code != $country ) {
1823
-                    wpinv_set_error( 'vat_validation', sprintf( __( 'The country of your current location must be the same as the country of your billing location or you must %s confirm %s the billing address is your home country.', 'invoicing' ), '<a href="#wpinv_adddress_confirm">', '</a>' ) );
1821
+            if (!isset($_POST['wpinv_adddress_confirmed'])) {
1822
+                if ($ip_country_code != $country) {
1823
+                    wpinv_set_error('vat_validation', sprintf(__('The country of your current location must be the same as the country of your billing location or you must %s confirm %s the billing address is your home country.', 'invoicing'), '<a href="#wpinv_adddress_confirm">', '</a>'));
1824 1824
                 }
1825 1825
             } else {
1826 1826
                 $vat_data['adddress_confirmed'] = true;
1827 1827
             }
1828 1828
         }
1829 1829
         
1830
-        if ( !empty( $wpinv_options['vat_prevent_b2c_purchase'] ) && !$is_non_eu_user && ( empty( $vat_number ) || $no_vat ) ) {
1831
-            if ( $is_eu_state ) {
1832
-                wpinv_set_error( 'vat_validation', wp_sprintf( __( 'Please enter and validate your %s number to verify your purchase is by an EU business.', 'invoicing' ), $vat_name ) );
1833
-            } else if ( $is_digital && $is_eu_state_ip ) {
1834
-                wpinv_set_error( 'vat_validation', wp_sprintf( __( 'Sales to non-EU countries cannot be completed because %s must be applied.', 'invoicing' ), $vat_name ) );
1830
+        if (!empty($wpinv_options['vat_prevent_b2c_purchase']) && !$is_non_eu_user && (empty($vat_number) || $no_vat)) {
1831
+            if ($is_eu_state) {
1832
+                wpinv_set_error('vat_validation', wp_sprintf(__('Please enter and validate your %s number to verify your purchase is by an EU business.', 'invoicing'), $vat_name));
1833
+            } else if ($is_digital && $is_eu_state_ip) {
1834
+                wpinv_set_error('vat_validation', wp_sprintf(__('Sales to non-EU countries cannot be completed because %s must be applied.', 'invoicing'), $vat_name));
1835 1835
             }
1836 1836
         }
1837 1837
         
1838
-        if ( !$is_eu_state || $no_vat || empty( $vat_number ) ) {
1838
+        if (!$is_eu_state || $no_vat || empty($vat_number)) {
1839 1839
             return;
1840 1840
         }
1841 1841
 
1842
-        if ( !empty( $vat_saved ) && isset( $vat_saved['valid'] ) ) {
1843
-            $vat_data['valid']  = $vat_saved['valid'];
1842
+        if (!empty($vat_saved) && isset($vat_saved['valid'])) {
1843
+            $vat_data['valid'] = $vat_saved['valid'];
1844 1844
         }
1845 1845
             
1846
-        if ( $company !== null ) {
1846
+        if ($company !== null) {
1847 1847
             $vat_data['company'] = $company;
1848 1848
         }
1849 1849
 
1850 1850
         $message = '';
1851
-        if ( $vat_number !== null ) {
1851
+        if ($vat_number !== null) {
1852 1852
             $vat_data['number'] = $vat_number;
1853 1853
             
1854
-            if ( !$vat_data['valid'] || ( $vat_saved['number'] !== $vat_data['number'] ) || ( $vat_saved['company'] !== $vat_data['company'] ) ) {
1855
-                if ( !empty( $wpinv_options['vat_vies_check'] ) ) {            
1856
-                    if ( empty( $wpinv_options['vat_offline_check'] ) && !self::offline_check( $vat_number ) ) {
1854
+            if (!$vat_data['valid'] || ($vat_saved['number'] !== $vat_data['number']) || ($vat_saved['company'] !== $vat_data['company'])) {
1855
+                if (!empty($wpinv_options['vat_vies_check'])) {            
1856
+                    if (empty($wpinv_options['vat_offline_check']) && !self::offline_check($vat_number)) {
1857 1857
                         $vat_data['valid'] = false;
1858 1858
                     }
1859 1859
                 } else {
1860
-                    $result = self::check_vat( $vat_number );
1860
+                    $result = self::check_vat($vat_number);
1861 1861
                     
1862
-                    if ( !empty( $result['valid'] ) ) {                
1862
+                    if (!empty($result['valid'])) {                
1863 1863
                         $vat_data['valid'] = true;
1864
-                        $vies_company = !empty( $result['company'] ) ? $result['company'] : '';
1865
-                        $vies_company = apply_filters( 'wpinv_vies_company_name', $vies_company );
1864
+                        $vies_company = !empty($result['company']) ? $result['company'] : '';
1865
+                        $vies_company = apply_filters('wpinv_vies_company_name', $vies_company);
1866 1866
                     
1867
-                        $valid_company = $vies_company && $company && ( $vies_company == '---' || strcasecmp( trim( $vies_company ), trim( $company ) ) == 0 ) ? true : false;
1867
+                        $valid_company = $vies_company && $company && ($vies_company == '---' || strcasecmp(trim($vies_company), trim($company)) == 0) ? true : false;
1868 1868
 
1869
-                        if ( !( !empty( $wpinv_options['vat_disable_company_name_check'] ) || $valid_company ) ) {         
1869
+                        if (!(!empty($wpinv_options['vat_disable_company_name_check']) || $valid_company)) {         
1870 1870
                             $vat_data['valid'] = false;
1871 1871
                             
1872
-                            $message = wp_sprintf( __( 'The company name associated with the %s number provided is not the same as the company name provided.', 'invoicing' ), $vat_name );
1872
+                            $message = wp_sprintf(__('The company name associated with the %s number provided is not the same as the company name provided.', 'invoicing'), $vat_name);
1873 1873
                         }
1874 1874
                     } else {
1875
-                        $message = wp_sprintf( __( 'Fail to validate the %s number: EU Commission VAT server (VIES) check fails.', 'invoicing' ), $vat_name );
1875
+                        $message = wp_sprintf(__('Fail to validate the %s number: EU Commission VAT server (VIES) check fails.', 'invoicing'), $vat_name);
1876 1876
                     }
1877 1877
                 }
1878 1878
                 
1879
-                if ( !$vat_data['valid'] ) {
1880
-                    $error = wp_sprintf( __( 'The %s %s number %s you have entered has not been validated', 'invoicing' ), '<a href="#wpi-vat-details">', $vat_name, '</a>' ) . ( $message ? ' ( ' . $message . ' )' : '' );
1881
-                    wpinv_set_error( 'vat_validation', $error );
1879
+                if (!$vat_data['valid']) {
1880
+                    $error = wp_sprintf(__('The %s %s number %s you have entered has not been validated', 'invoicing'), '<a href="#wpi-vat-details">', $vat_name, '</a>') . ($message ? ' ( ' . $message . ' )' : '');
1881
+                    wpinv_set_error('vat_validation', $error);
1882 1882
                 }
1883 1883
             }
1884 1884
         }
1885 1885
 
1886
-        $wpi_session->set( 'user_vat_data', $vat_data );
1886
+        $wpi_session->set('user_vat_data', $vat_data);
1887 1887
     }
1888 1888
     
1889
-    public static function checkout_vat_fields( $billing_details ) {
1889
+    public static function checkout_vat_fields($billing_details) {
1890 1890
         global $wpi_session, $wpinv_options, $wpi_country, $wpi_requires_vat;
1891 1891
         
1892 1892
         $ip_address         = wpinv_get_ip();
1893 1893
         $ip_country_code    = self::get_country_by_ip();
1894 1894
         
1895
-        $tax_label          = __( self::get_vat_name(), 'invoicing' );
1895
+        $tax_label          = __(self::get_vat_name(), 'invoicing');
1896 1896
         $invoice            = wpinv_get_invoice_cart();
1897
-        $is_digital         = self::invoice_has_digital_rule( $invoice );
1897
+        $is_digital         = self::invoice_has_digital_rule($invoice);
1898 1898
         $wpi_country        = $invoice->country;
1899 1899
         
1900
-        $requires_vat       = !self::hide_vat_fields() && $invoice->get_total() > 0 && self::requires_vat( 0, false, $is_digital );
1900
+        $requires_vat       = !self::hide_vat_fields() && $invoice->get_total() > 0 && self::requires_vat(0, false, $is_digital);
1901 1901
         $wpi_requires_vat   = $requires_vat;
1902 1902
         
1903 1903
         $company            = self::get_user_company();
1904 1904
         $vat_number         = self::get_user_vat_number();
1905 1905
         
1906
-        $validated          = $vat_number ? self::get_user_vat_number( '', 0, true ) : 1;
1907
-        $vat_info           = $wpi_session->get( 'user_vat_data' );
1906
+        $validated          = $vat_number ? self::get_user_vat_number('', 0, true) : 1;
1907
+        $vat_info           = $wpi_session->get('user_vat_data');
1908 1908
 
1909
-        if ( is_array( $vat_info ) ) {
1910
-            $company    = isset( $vat_info['company'] ) ? $vat_info['company'] : '';
1911
-            $vat_number = isset( $vat_info['number'] ) ? $vat_info['number'] : '';
1912
-            $validated  = isset( $vat_info['valid'] ) ? $vat_info['valid'] : false;
1909
+        if (is_array($vat_info)) {
1910
+            $company    = isset($vat_info['company']) ? $vat_info['company'] : '';
1911
+            $vat_number = isset($vat_info['number']) ? $vat_info['number'] : '';
1912
+            $validated  = isset($vat_info['valid']) ? $vat_info['valid'] : false;
1913 1913
         }
1914 1914
         
1915 1915
         $selected_country = $invoice->country ? $invoice->country : wpinv_default_billing_country();
1916 1916
 
1917
-        if ( $ip_country_code == 'UK' ) {
1917
+        if ($ip_country_code == 'UK') {
1918 1918
             $ip_country_code = 'GB';
1919 1919
         }
1920 1920
         
1921
-        if ( $selected_country == 'UK' ) {
1921
+        if ($selected_country == 'UK') {
1922 1922
             $selected_country = 'GB';
1923 1923
         }
1924 1924
         
1925
-        if ( $requires_vat && ( self::same_country_rule() == 'no' && wpinv_is_base_country( $selected_country ) || !self::allow_vat_rules() ) ) {
1925
+        if ($requires_vat && (self::same_country_rule() == 'no' && wpinv_is_base_country($selected_country) || !self::allow_vat_rules())) {
1926 1926
             $requires_vat = false;
1927 1927
         }
1928 1928
 
@@ -1930,52 +1930,52 @@  discard block
 block discarded – undo
1930 1930
         $display_validate_btn   = 'none';
1931 1931
         $display_reset_btn      = 'none';
1932 1932
         
1933
-        if ( !empty( $vat_number ) && $validated ) {
1934
-            $vat_vailidated_text    = wp_sprintf( __( '%s number validated', 'invoicing' ), $tax_label );
1933
+        if (!empty($vat_number) && $validated) {
1934
+            $vat_vailidated_text    = wp_sprintf(__('%s number validated', 'invoicing'), $tax_label);
1935 1935
             $vat_vailidated_class   = 'wpinv-vat-stat-1';
1936 1936
             $display_reset_btn      = 'block';
1937 1937
         } else {
1938
-            $vat_vailidated_text    = empty( $vat_number ) ? '' : wp_sprintf( __( '%s number not validated', 'invoicing' ), $tax_label );
1939
-            $vat_vailidated_class   = empty( $vat_number ) ? '' : 'wpinv-vat-stat-0';
1938
+            $vat_vailidated_text    = empty($vat_number) ? '' : wp_sprintf(__('%s number not validated', 'invoicing'), $tax_label);
1939
+            $vat_vailidated_class   = empty($vat_number) ? '' : 'wpinv-vat-stat-0';
1940 1940
             $display_validate_btn   = 'block';
1941 1941
         }
1942 1942
         
1943
-        $show_ip_country        = $is_digital && ( empty( $vat_number ) || !$requires_vat ) && $ip_country_code != $selected_country ? 'block' : 'none';
1943
+        $show_ip_country = $is_digital && (empty($vat_number) || !$requires_vat) && $ip_country_code != $selected_country ? 'block' : 'none';
1944 1944
         ?>
1945 1945
         <div id="wpi-vat-details" class="wpi-vat-details clearfix" style="display:<?php echo $display_vat_details; ?>">
1946 1946
             <div id="wpi_vat_info" class="clearfix panel panel-default">
1947
-                <div class="panel-heading"><h3 class="panel-title"><?php echo wp_sprintf( __( '%s Details', 'invoicing' ), $tax_label );?></h3></div>
1947
+                <div class="panel-heading"><h3 class="panel-title"><?php echo wp_sprintf(__('%s Details', 'invoicing'), $tax_label); ?></h3></div>
1948 1948
                 <div id="wpinv-fields-box" class="panel-body">
1949 1949
                     <p id="wpi_show_vat_note">
1950
-                        <?php echo wp_sprintf( __( 'Validate your registered %s number to exclude tax.', 'invoicing' ), $tax_label ); ?>
1950
+                        <?php echo wp_sprintf(__('Validate your registered %s number to exclude tax.', 'invoicing'), $tax_label); ?>
1951 1951
                     </p>
1952 1952
                     <div id="wpi_vat_fields" class="wpi_vat_info">
1953 1953
                         <p class="wpi-cart-field wpi-col2 wpi-colf">
1954
-                            <label for="wpinv_company" class="wpi-label"><?php _e( 'Company Name', 'invoicing' );?></label>
1954
+                            <label for="wpinv_company" class="wpi-label"><?php _e('Company Name', 'invoicing'); ?></label>
1955 1955
                             <?php
1956
-                            echo wpinv_html_text( array(
1956
+                            echo wpinv_html_text(array(
1957 1957
                                     'id'            => 'wpinv_company',
1958 1958
                                     'name'          => 'wpinv_company',
1959 1959
                                     'value'         => $company,
1960 1960
                                     'class'         => 'wpi-input form-control',
1961
-                                    'placeholder'   => __( 'Company name', 'invoicing' ),
1962
-                                ) );
1961
+                                    'placeholder'   => __('Company name', 'invoicing'),
1962
+                                ));
1963 1963
                             ?>
1964 1964
                         </p>
1965 1965
                         <p class="wpi-cart-field wpi-col2 wpi-coll wpi-cart-field-vat">
1966
-                            <label for="wpinv_vat_number" class="wpi-label"><?php echo wp_sprintf( __( '%s Number', 'invoicing' ), $tax_label );?></label>
1966
+                            <label for="wpinv_vat_number" class="wpi-label"><?php echo wp_sprintf(__('%s Number', 'invoicing'), $tax_label); ?></label>
1967 1967
                             <span id="wpinv_vat_number-wrap">
1968 1968
                                 <label for="wpinv_vat_number" class="wpinv-label"></label>
1969
-                                <input type="text" class="wpi-input form-control" placeholder="<?php echo esc_attr( wp_sprintf( __( '%s number', 'invoicing' ), $tax_label ) );?>" value="<?php esc_attr_e( $vat_number );?>" id="wpinv_vat_number" name="wpinv_vat_number">
1970
-                                <span class="wpinv-vat-stat <?php echo $vat_vailidated_class;?>"><i class="fa"></i>&nbsp;<font><?php echo $vat_vailidated_text;?></font></span>
1969
+                                <input type="text" class="wpi-input form-control" placeholder="<?php echo esc_attr(wp_sprintf(__('%s number', 'invoicing'), $tax_label)); ?>" value="<?php esc_attr_e($vat_number); ?>" id="wpinv_vat_number" name="wpinv_vat_number">
1970
+                                <span class="wpinv-vat-stat <?php echo $vat_vailidated_class; ?>"><i class="fa"></i>&nbsp;<font><?php echo $vat_vailidated_text; ?></font></span>
1971 1971
                             </span>
1972 1972
                         </p>
1973 1973
                         <p class="wpi-cart-field wpi-col wpi-colf wpi-cart-field-actions">
1974
-                            <button class="btn btn-success btn-sm wpinv-vat-validate" type="button" id="wpinv_vat_validate" style="display:<?php echo $display_validate_btn; ?>"><?php echo wp_sprintf( __("Validate %s Number", 'invoicing'), $tax_label ); ?></button>
1975
-                            <button class="btn btn-danger btn-sm wpinv-vat-reset" type="button" id="wpinv_vat_reset" style="display:<?php echo $display_reset_btn; ?>"><?php echo wp_sprintf( __("Reset %s", 'invoicing'), $tax_label ); ?></button>
1974
+                            <button class="btn btn-success btn-sm wpinv-vat-validate" type="button" id="wpinv_vat_validate" style="display:<?php echo $display_validate_btn; ?>"><?php echo wp_sprintf(__("Validate %s Number", 'invoicing'), $tax_label); ?></button>
1975
+                            <button class="btn btn-danger btn-sm wpinv-vat-reset" type="button" id="wpinv_vat_reset" style="display:<?php echo $display_reset_btn; ?>"><?php echo wp_sprintf(__("Reset %s", 'invoicing'), $tax_label); ?></button>
1976 1976
                             <span class="wpi-vat-box wpi-vat-box-info"><span id="text"></span></span>
1977 1977
                             <span class="wpi-vat-box wpi-vat-box-error"><span id="text"></span></span>
1978
-                            <input type="hidden" name="_wpi_nonce" value="<?php echo wp_create_nonce( 'vat_validation' ) ?>" />
1978
+                            <input type="hidden" name="_wpi_nonce" value="<?php echo wp_create_nonce('vat_validation') ?>" />
1979 1979
                         </p>
1980 1980
                     </div>
1981 1981
                 </div>
@@ -1989,32 +1989,32 @@  discard block
 block discarded – undo
1989 1989
                 </span>
1990 1990
             </div>
1991 1991
         </div>
1992
-        <?php if ( empty( $wpinv_options['hide_ip_address'] ) ) { 
1993
-            $ip_link = '<a title="' . esc_attr( __( 'View more details on map', 'invoicing' ) ) . '" target="_blank" href="' . esc_url( admin_url( 'admin-ajax.php?action=wpinv_ip_geolocation&ip=' . $ip_address ) ) . '" class="wpi-ip-address-link">' . $ip_address . '&nbsp;&nbsp;<i class="fa fa-external-link-square" aria-hidden="true"></i></a>';
1992
+        <?php if (empty($wpinv_options['hide_ip_address'])) { 
1993
+            $ip_link = '<a title="' . esc_attr(__('View more details on map', 'invoicing')) . '" target="_blank" href="' . esc_url(admin_url('admin-ajax.php?action=wpinv_ip_geolocation&ip=' . $ip_address)) . '" class="wpi-ip-address-link">' . $ip_address . '&nbsp;&nbsp;<i class="fa fa-external-link-square" aria-hidden="true"></i></a>';
1994 1994
         ?>
1995 1995
         <div class="wpi-ip-info clearfix panel panel-info">
1996 1996
             <div id="wpinv-fields-box" class="panel-body">
1997
-                <span><?php echo wp_sprintf( __( "Your IP address is: %s", 'invoicing' ), $ip_link ); ?></span>
1997
+                <span><?php echo wp_sprintf(__("Your IP address is: %s", 'invoicing'), $ip_link); ?></span>
1998 1998
             </div>
1999 1999
         </div>
2000 2000
         <?php }
2001 2001
     }
2002 2002
     
2003
-    public static function show_vat_notice( $invoice ) {
2004
-        if ( empty( $invoice ) ) {
2003
+    public static function show_vat_notice($invoice) {
2004
+        if (empty($invoice)) {
2005 2005
             return NULL;
2006 2006
         }
2007 2007
         
2008
-        $label      = wpinv_get_option( 'vat_invoice_notice_label' );
2009
-        $notice     = wpinv_get_option( 'vat_invoice_notice' );
2010
-        if ( $label || $notice ) {
2008
+        $label      = wpinv_get_option('vat_invoice_notice_label');
2009
+        $notice     = wpinv_get_option('vat_invoice_notice');
2010
+        if ($label || $notice) {
2011 2011
         ?>
2012 2012
         <div class="row wpinv-vat-notice">
2013 2013
             <div class="col-sm-12">
2014
-                <?php if ( $label ) { ?>
2015
-                <strong><?php _e( $label, 'invoicing' ); ?></strong>
2016
-                <?php } if ( $notice ) { ?>
2017
-                <?php echo wpautop( wptexturize( __( $notice, 'invoicing' ) ) ) ?>
2014
+                <?php if ($label) { ?>
2015
+                <strong><?php _e($label, 'invoicing'); ?></strong>
2016
+                <?php } if ($notice) { ?>
2017
+                <?php echo wpautop(wptexturize(__($notice, 'invoicing'))) ?>
2018 2018
                 <?php } ?>
2019 2019
             </div>
2020 2020
         </div>
Please login to merge, or discard this patch.
includes/wpinv-general-functions.php 1 patch
Spacing   +153 added lines, -153 removed lines patch added patch discarded remove patch
@@ -7,195 +7,195 @@  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_is_checkout() {
15 15
     global $wp_query;
16 16
 
17
-    $is_object_set    = isset( $wp_query->queried_object );
18
-    $is_object_id_set = isset( $wp_query->queried_object_id );
19
-    $is_checkout      = is_page( wpinv_get_option( 'checkout_page' ) );
17
+    $is_object_set    = isset($wp_query->queried_object);
18
+    $is_object_id_set = isset($wp_query->queried_object_id);
19
+    $is_checkout      = is_page(wpinv_get_option('checkout_page'));
20 20
 
21
-    if ( !$is_object_set ) {
22
-        unset( $wp_query->queried_object );
21
+    if (!$is_object_set) {
22
+        unset($wp_query->queried_object);
23 23
     }
24 24
 
25
-    if ( !$is_object_id_set ) {
26
-        unset( $wp_query->queried_object_id );
25
+    if (!$is_object_id_set) {
26
+        unset($wp_query->queried_object_id);
27 27
     }
28 28
 
29
-    return apply_filters( 'wpinv_is_checkout', $is_checkout );
29
+    return apply_filters('wpinv_is_checkout', $is_checkout);
30 30
 }
31 31
 
32 32
 function wpinv_can_checkout() {
33 33
 	$can_checkout = true; // Always true for now
34 34
 
35
-	return (bool) apply_filters( 'wpinv_can_checkout', $can_checkout );
35
+	return (bool)apply_filters('wpinv_can_checkout', $can_checkout);
36 36
 }
37 37
 
38 38
 function wpinv_get_success_page_uri() {
39
-	$page_id = wpinv_get_option( 'success_page', 0 );
40
-	$page_id = absint( $page_id );
39
+	$page_id = wpinv_get_option('success_page', 0);
40
+	$page_id = absint($page_id);
41 41
 
42
-	return apply_filters( 'wpinv_get_success_page_uri', get_permalink( $page_id ) );
42
+	return apply_filters('wpinv_get_success_page_uri', get_permalink($page_id));
43 43
 }
44 44
 
45 45
 function wpinv_get_history_page_uri() {
46
-	$page_id = wpinv_get_option( 'invoice_history_page', 0 );
47
-	$page_id = absint( $page_id );
46
+	$page_id = wpinv_get_option('invoice_history_page', 0);
47
+	$page_id = absint($page_id);
48 48
 
49
-	return apply_filters( 'wpinv_get_history_page_uri', get_permalink( $page_id ) );
49
+	return apply_filters('wpinv_get_history_page_uri', get_permalink($page_id));
50 50
 }
51 51
 
52 52
 function wpinv_is_success_page() {
53
-	$is_success_page = wpinv_get_option( 'success_page', false );
54
-	$is_success_page = isset( $is_success_page ) ? is_page( $is_success_page ) : false;
53
+	$is_success_page = wpinv_get_option('success_page', false);
54
+	$is_success_page = isset($is_success_page) ? is_page($is_success_page) : false;
55 55
 
56
-	return apply_filters( 'wpinv_is_success_page', $is_success_page );
56
+	return apply_filters('wpinv_is_success_page', $is_success_page);
57 57
 }
58 58
 
59 59
 function wpinv_is_invoice_history_page() {
60
-	$ret = wpinv_get_option( 'invoice_history_page', false );
61
-	$ret = $ret ? is_page( $ret ) : false;
62
-	return apply_filters( 'wpinv_is_invoice_history_page', $ret );
60
+	$ret = wpinv_get_option('invoice_history_page', false);
61
+	$ret = $ret ? is_page($ret) : false;
62
+	return apply_filters('wpinv_is_invoice_history_page', $ret);
63 63
 }
64 64
 
65
-function wpinv_send_to_success_page( $args = null ) {
65
+function wpinv_send_to_success_page($args = null) {
66 66
 	$redirect = wpinv_get_success_page_uri();
67 67
     
68
-    if ( !empty( $args ) ) {
68
+    if (!empty($args)) {
69 69
         // Check for backward compatibility
70
-        if ( is_string( $args ) )
71
-            $args = str_replace( '?', '', $args );
70
+        if (is_string($args))
71
+            $args = str_replace('?', '', $args);
72 72
 
73
-        $args = wp_parse_args( $args );
73
+        $args = wp_parse_args($args);
74 74
 
75
-        $redirect = add_query_arg( $args, $redirect );
75
+        $redirect = add_query_arg($args, $redirect);
76 76
     }
77 77
 
78
-    $gateway = isset( $_REQUEST['wpi-gateway'] ) ? $_REQUEST['wpi-gateway'] : '';
78
+    $gateway = isset($_REQUEST['wpi-gateway']) ? $_REQUEST['wpi-gateway'] : '';
79 79
     
80
-    $redirect = apply_filters( 'wpinv_success_page_redirect', $redirect, $gateway, $args );
81
-    wp_redirect( $redirect );
80
+    $redirect = apply_filters('wpinv_success_page_redirect', $redirect, $gateway, $args);
81
+    wp_redirect($redirect);
82 82
     exit;
83 83
 }
84 84
 
85
-function wpinv_send_to_failed_page( $args = null ) {
85
+function wpinv_send_to_failed_page($args = null) {
86 86
 	$redirect = wpinv_get_failed_transaction_uri();
87 87
     
88
-    if ( !empty( $args ) ) {
88
+    if (!empty($args)) {
89 89
         // Check for backward compatibility
90
-        if ( is_string( $args ) )
91
-            $args = str_replace( '?', '', $args );
90
+        if (is_string($args))
91
+            $args = str_replace('?', '', $args);
92 92
 
93
-        $args = wp_parse_args( $args );
93
+        $args = wp_parse_args($args);
94 94
 
95
-        $redirect = add_query_arg( $args, $redirect );
95
+        $redirect = add_query_arg($args, $redirect);
96 96
     }
97 97
 
98
-    $gateway = isset( $_REQUEST['wpi-gateway'] ) ? $_REQUEST['wpi-gateway'] : '';
98
+    $gateway = isset($_REQUEST['wpi-gateway']) ? $_REQUEST['wpi-gateway'] : '';
99 99
     
100
-    $redirect = apply_filters( 'wpinv_failed_page_redirect', $redirect, $gateway, $args );
101
-    wp_redirect( $redirect );
100
+    $redirect = apply_filters('wpinv_failed_page_redirect', $redirect, $gateway, $args);
101
+    wp_redirect($redirect);
102 102
     exit;
103 103
 }
104 104
 
105
-function wpinv_get_checkout_uri( $args = array() ) {
106
-	$uri = wpinv_get_option( 'checkout_page', false );
107
-	$uri = isset( $uri ) ? get_permalink( $uri ) : NULL;
105
+function wpinv_get_checkout_uri($args = array()) {
106
+	$uri = wpinv_get_option('checkout_page', false);
107
+	$uri = isset($uri) ? get_permalink($uri) : NULL;
108 108
 
109
-	if ( !empty( $args ) ) {
109
+	if (!empty($args)) {
110 110
 		// Check for backward compatibility
111
-		if ( is_string( $args ) )
112
-			$args = str_replace( '?', '', $args );
111
+		if (is_string($args))
112
+			$args = str_replace('?', '', $args);
113 113
 
114
-		$args = wp_parse_args( $args );
114
+		$args = wp_parse_args($args);
115 115
 
116
-		$uri = add_query_arg( $args, $uri );
116
+		$uri = add_query_arg($args, $uri);
117 117
 	}
118 118
 
119
-	$scheme = defined( 'FORCE_SSL_ADMIN' ) && FORCE_SSL_ADMIN ? 'https' : 'admin';
119
+	$scheme = defined('FORCE_SSL_ADMIN') && FORCE_SSL_ADMIN ? 'https' : 'admin';
120 120
 
121
-	$ajax_url = admin_url( 'admin-ajax.php', $scheme );
121
+	$ajax_url = admin_url('admin-ajax.php', $scheme);
122 122
 
123
-	if ( ( ! preg_match( '/^https/', $uri ) && preg_match( '/^https/', $ajax_url ) ) || wpinv_is_ssl_enforced() ) {
124
-		$uri = preg_replace( '/^http:/', 'https:', $uri );
123
+	if ((!preg_match('/^https/', $uri) && preg_match('/^https/', $ajax_url)) || wpinv_is_ssl_enforced()) {
124
+		$uri = preg_replace('/^http:/', 'https:', $uri);
125 125
 	}
126 126
 
127
-	return apply_filters( 'wpinv_get_checkout_uri', $uri );
127
+	return apply_filters('wpinv_get_checkout_uri', $uri);
128 128
 }
129 129
 
130
-function wpinv_send_back_to_checkout( $args = array() ) {
130
+function wpinv_send_back_to_checkout($args = array()) {
131 131
 	$redirect = wpinv_get_checkout_uri();
132 132
 
133
-	if ( ! empty( $args ) ) {
133
+	if (!empty($args)) {
134 134
 		// Check for backward compatibility
135
-		if ( is_string( $args ) )
136
-			$args = str_replace( '?', '', $args );
135
+		if (is_string($args))
136
+			$args = str_replace('?', '', $args);
137 137
 
138
-		$args = wp_parse_args( $args );
138
+		$args = wp_parse_args($args);
139 139
 
140
-		$redirect = add_query_arg( $args, $redirect );
140
+		$redirect = add_query_arg($args, $redirect);
141 141
 	}
142 142
 
143
-	wp_redirect( apply_filters( 'wpinv_send_back_to_checkout', $redirect, $args ) );
143
+	wp_redirect(apply_filters('wpinv_send_back_to_checkout', $redirect, $args));
144 144
 	exit;
145 145
 }
146 146
 
147
-function wpinv_get_success_page_url( $query_string = null ) {
148
-	$success_page = wpinv_get_option( 'success_page', 0 );
149
-	$success_page = get_permalink( $success_page );
147
+function wpinv_get_success_page_url($query_string = null) {
148
+	$success_page = wpinv_get_option('success_page', 0);
149
+	$success_page = get_permalink($success_page);
150 150
 
151
-	if ( $query_string )
151
+	if ($query_string)
152 152
 		$success_page .= $query_string;
153 153
 
154
-	return apply_filters( 'wpinv_success_page_url', $success_page );
154
+	return apply_filters('wpinv_success_page_url', $success_page);
155 155
 }
156 156
 
157
-function wpinv_get_failed_transaction_uri( $extras = false ) {
158
-	$uri = wpinv_get_option( 'failure_page', '' );
159
-	$uri = ! empty( $uri ) ? trailingslashit( get_permalink( $uri ) ) : home_url();
157
+function wpinv_get_failed_transaction_uri($extras = false) {
158
+	$uri = wpinv_get_option('failure_page', '');
159
+	$uri = !empty($uri) ? trailingslashit(get_permalink($uri)) : home_url();
160 160
 
161
-	if ( $extras )
161
+	if ($extras)
162 162
 		$uri .= $extras;
163 163
 
164
-	return apply_filters( 'wpinv_get_failed_transaction_uri', $uri );
164
+	return apply_filters('wpinv_get_failed_transaction_uri', $uri);
165 165
 }
166 166
 
167 167
 function wpinv_is_failed_transaction_page() {
168
-	$ret = wpinv_get_option( 'failure_page', false );
169
-	$ret = isset( $ret ) ? is_page( $ret ) : false;
168
+	$ret = wpinv_get_option('failure_page', false);
169
+	$ret = isset($ret) ? is_page($ret) : false;
170 170
 
171
-	return apply_filters( 'wpinv_is_failure_page', $ret );
171
+	return apply_filters('wpinv_is_failure_page', $ret);
172 172
 }
173 173
 
174
-function wpinv_transaction_query( $type = 'start' ) {
174
+function wpinv_transaction_query($type = 'start') {
175 175
     global $wpdb;
176 176
 
177 177
     $wpdb->hide_errors();
178 178
 
179
-    if ( ! defined( 'WPINV_USE_TRANSACTIONS' ) ) {
180
-        define( 'WPINV_USE_TRANSACTIONS', true );
179
+    if (!defined('WPINV_USE_TRANSACTIONS')) {
180
+        define('WPINV_USE_TRANSACTIONS', true);
181 181
     }
182 182
 
183
-    if ( WPINV_USE_TRANSACTIONS ) {
184
-        switch ( $type ) {
183
+    if (WPINV_USE_TRANSACTIONS) {
184
+        switch ($type) {
185 185
             case 'commit' :
186
-                $wpdb->query( 'COMMIT' );
186
+                $wpdb->query('COMMIT');
187 187
                 break;
188 188
             case 'rollback' :
189
-                $wpdb->query( 'ROLLBACK' );
189
+                $wpdb->query('ROLLBACK');
190 190
                 break;
191 191
             default :
192
-                $wpdb->query( 'START TRANSACTION' );
192
+                $wpdb->query('START TRANSACTION');
193 193
             break;
194 194
         }
195 195
     }
196 196
 }
197 197
 
198
-function wpinv_create_invoice( $args = array(), $data = array(), $wp_error = false ) {
198
+function wpinv_create_invoice($args = array(), $data = array(), $wp_error = false) {
199 199
     $default_args = array(
200 200
         'status'        => '',
201 201
         'user_id'       => null,
@@ -205,63 +205,63 @@  discard block
 block discarded – undo
205 205
         'parent'        => 0
206 206
     );
207 207
 
208
-    $args           = wp_parse_args( $args, $default_args );
208
+    $args           = wp_parse_args($args, $default_args);
209 209
     $invoice_data   = array();
210 210
 
211
-    if ( $args['invoice_id'] > 0 ) {
212
-        $updating           = true;
211
+    if ($args['invoice_id'] > 0) {
212
+        $updating = true;
213 213
         $invoice_data['post_type']  = 'wpi_invoice';
214 214
         $invoice_data['ID']         = $args['invoice_id'];
215 215
     } else {
216 216
         $updating                       = false;
217 217
         $invoice_data['post_type']      = 'wpi_invoice';
218
-        $invoice_data['post_status']    = apply_filters( 'wpinv_default_invoice_status', 'wpi-pending' );
218
+        $invoice_data['post_status']    = apply_filters('wpinv_default_invoice_status', 'wpi-pending');
219 219
         $invoice_data['ping_status']    = 'closed';
220
-        $invoice_data['post_author']    = !empty( $args['user_id'] ) ? $args['user_id'] : get_current_user_id();
221
-        $invoice_data['post_title']     = wpinv_format_invoice_number( '0' );
222
-        $invoice_data['post_parent']    = absint( $args['parent'] );
223
-        if ( !empty( $args['created_date'] ) ) {
220
+        $invoice_data['post_author']    = !empty($args['user_id']) ? $args['user_id'] : get_current_user_id();
221
+        $invoice_data['post_title']     = wpinv_format_invoice_number('0');
222
+        $invoice_data['post_parent']    = absint($args['parent']);
223
+        if (!empty($args['created_date'])) {
224 224
             $invoice_data['post_date']      = $args['created_date'];
225
-            $invoice_data['post_date_gmt']  = get_gmt_from_date( $args['created_date'] );
225
+            $invoice_data['post_date_gmt']  = get_gmt_from_date($args['created_date']);
226 226
         }
227 227
     }
228 228
 
229
-    if ( $args['status'] ) {
230
-        if ( ! in_array( $args['status'], array_keys( wpinv_get_invoice_statuses() ) ) ) {
231
-            return new WP_Error( 'wpinv_invalid_invoice_status', wp_sprintf( __( 'Invalid invoice status: %s', 'invoicing' ), $args['status'] ) );
229
+    if ($args['status']) {
230
+        if (!in_array($args['status'], array_keys(wpinv_get_invoice_statuses()))) {
231
+            return new WP_Error('wpinv_invalid_invoice_status', wp_sprintf(__('Invalid invoice status: %s', 'invoicing'), $args['status']));
232 232
         }
233
-        $invoice_data['post_status']    = $args['status'];
233
+        $invoice_data['post_status'] = $args['status'];
234 234
     }
235 235
 
236
-    if ( ! is_null( $args['user_note'] ) ) {
237
-        $invoice_data['post_excerpt']   = $args['user_note'];
236
+    if (!is_null($args['user_note'])) {
237
+        $invoice_data['post_excerpt'] = $args['user_note'];
238 238
     }
239 239
 
240
-    if ( $updating ) {
241
-        $invoice_id = wp_update_post( $invoice_data, true );
240
+    if ($updating) {
241
+        $invoice_id = wp_update_post($invoice_data, true);
242 242
     } else {
243
-        $invoice_id = wp_insert_post( apply_filters( 'wpinv_new_invoice_data', $invoice_data ), true );
243
+        $invoice_id = wp_insert_post(apply_filters('wpinv_new_invoice_data', $invoice_data), true);
244 244
     }
245 245
 
246
-    if ( is_wp_error( $invoice_id ) ) {
246
+    if (is_wp_error($invoice_id)) {
247 247
         return $wp_error ? $invoice_id : 0;
248 248
     }
249 249
     
250
-    $invoice = wpinv_get_invoice( $invoice_id );
251
-
252
-    if ( !$updating ) {
253
-        update_post_meta( $invoice_id, '_wpinv_key', apply_filters( 'wpinv_generate_invoice_key', uniqid( 'wpinv_' ) ) );
254
-        update_post_meta( $invoice_id, '_wpinv_currency', wpinv_get_currency() );
255
-        update_post_meta( $invoice_id, '_wpinv_include_tax', get_option( 'wpinv_prices_include_tax' ) );
256
-        update_post_meta( $invoice_id, '_wpinv_user_ip', wpinv_get_ip() );
257
-        update_post_meta( $invoice_id, '_wpinv_user_agent', wpinv_get_user_agent() );
258
-        update_post_meta( $invoice_id, '_wpinv_created_via', sanitize_text_field( $args['created_via'] ) );
250
+    $invoice = wpinv_get_invoice($invoice_id);
251
+
252
+    if (!$updating) {
253
+        update_post_meta($invoice_id, '_wpinv_key', apply_filters('wpinv_generate_invoice_key', uniqid('wpinv_')));
254
+        update_post_meta($invoice_id, '_wpinv_currency', wpinv_get_currency());
255
+        update_post_meta($invoice_id, '_wpinv_include_tax', get_option('wpinv_prices_include_tax'));
256
+        update_post_meta($invoice_id, '_wpinv_user_ip', wpinv_get_ip());
257
+        update_post_meta($invoice_id, '_wpinv_user_agent', wpinv_get_user_agent());
258
+        update_post_meta($invoice_id, '_wpinv_created_via', sanitize_text_field($args['created_via']));
259 259
         
260 260
         // Add invoice note
261
-        $invoice->add_note( wp_sprintf( __( 'Invoice is created with status %s.', 'invoicing' ), wpinv_status_nicename( $invoice->status ) ) );
261
+        $invoice->add_note(wp_sprintf(__('Invoice is created with status %s.', 'invoicing'), wpinv_status_nicename($invoice->status)));
262 262
     }
263 263
 
264
-    update_post_meta( $invoice_id, '_wpinv_version', WPINV_VERSION );
264
+    update_post_meta($invoice_id, '_wpinv_version', WPINV_VERSION);
265 265
 
266 266
     return $invoice;
267 267
 }
@@ -269,127 +269,127 @@  discard block
 block discarded – undo
269 269
 function wpinv_get_prefix() {
270 270
     $invoice_prefix = 'INV-';
271 271
     
272
-    return apply_filters( 'wpinv_get_prefix', $invoice_prefix );
272
+    return apply_filters('wpinv_get_prefix', $invoice_prefix);
273 273
 }
274 274
 
275 275
 function wpinv_get_business_logo() {
276
-    $business_logo = wpinv_get_option( 'logo' );
277
-    return apply_filters( 'wpinv_get_business_logo', $business_logo );
276
+    $business_logo = wpinv_get_option('logo');
277
+    return apply_filters('wpinv_get_business_logo', $business_logo);
278 278
 }
279 279
 
280 280
 function wpinv_get_business_name() {
281 281
     $business_name = wpinv_get_option('store_name');
282
-    return apply_filters( 'wpinv_get_business_name', $business_name );
282
+    return apply_filters('wpinv_get_business_name', $business_name);
283 283
 }
284 284
 
285 285
 function wpinv_get_blogname() {
286
-    return wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
286
+    return wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
287 287
 }
288 288
 
289 289
 function wpinv_get_admin_email() {
290
-    $admin_email = get_option( 'admin_email' );
291
-    return apply_filters( 'wpinv_admin_email', $admin_email );
290
+    $admin_email = get_option('admin_email');
291
+    return apply_filters('wpinv_admin_email', $admin_email);
292 292
 }
293 293
 
294 294
 function wpinv_get_business_website() {
295
-    $business_website = home_url( '/' );
296
-    return apply_filters( 'wpinv_get_business_website', $business_website );
295
+    $business_website = home_url('/');
296
+    return apply_filters('wpinv_get_business_website', $business_website);
297 297
 }
298 298
 
299
-function wpinv_get_terms_text( $invoice_id = 0 ) {
299
+function wpinv_get_terms_text($invoice_id = 0) {
300 300
     $terms_text = '';
301
-    return apply_filters( 'wpinv_get_terms_text', $terms_text, $invoice_id );
301
+    return apply_filters('wpinv_get_terms_text', $terms_text, $invoice_id);
302 302
 }
303 303
 
304 304
 function wpinv_get_business_footer() {
305
-    $site_link = '<a target="_blank" href="' . esc_url( wpinv_get_business_website() ) . '">' . esc_html( wpinv_get_business_name() ) . '</a>';
306
-    $business_footer = wp_sprintf( __( 'Thanks for using %s', 'invoicing' ), $site_link );
307
-    return apply_filters( 'wpinv_get_business_footer', $business_footer );
305
+    $site_link = '<a target="_blank" href="' . esc_url(wpinv_get_business_website()) . '">' . esc_html(wpinv_get_business_name()) . '</a>';
306
+    $business_footer = wp_sprintf(__('Thanks for using %s', 'invoicing'), $site_link);
307
+    return apply_filters('wpinv_get_business_footer', $business_footer);
308 308
 }
309 309
 
310 310
 function wpinv_checkout_required_fields() {
311 311
     $required_fields = array();
312 312
     
313 313
     // Let payment gateways and other extensions determine if address fields should be required
314
-    $require_billing_details = apply_filters( 'wpinv_checkout_required_billing_details', wpinv_use_taxes() );
314
+    $require_billing_details = apply_filters('wpinv_checkout_required_billing_details', wpinv_use_taxes());
315 315
     
316
-    if ( $require_billing_details ) {
316
+    if ($require_billing_details) {
317 317
         ///$required_fields['email'] = array(
318 318
                 ///'error_id' => 'invalid_email',
319 319
                 ///'error_message' => __( 'Please enter a valid email address', 'invoicing' )
320 320
             ///);
321 321
         $required_fields['first_name'] = array(
322 322
                 'error_id' => 'invalid_first_name',
323
-                'error_message' => __( 'Please enter your first name', 'invoicing' )
323
+                'error_message' => __('Please enter your first name', 'invoicing')
324 324
             );
325 325
         $required_fields['address'] = array(
326 326
                 'error_id' => 'invalid_address',
327
-                'error_message' => __( 'Please enter your address', 'invoicing' )
327
+                'error_message' => __('Please enter your address', 'invoicing')
328 328
             );
329 329
         $required_fields['city'] = array(
330 330
                 'error_id' => 'invalid_city',
331
-                'error_message' => __( 'Please enter your billing city', 'invoicing' )
331
+                'error_message' => __('Please enter your billing city', 'invoicing')
332 332
             );
333 333
         $required_fields['state'] = array(
334 334
                 'error_id' => 'invalid_state',
335
-                'error_message' => __( 'Please enter billing state / province', 'invoicing' )
335
+                'error_message' => __('Please enter billing state / province', 'invoicing')
336 336
             );
337 337
         $required_fields['country'] = array(
338 338
                 'error_id' => 'invalid_country',
339
-                'error_message' => __( 'Please select your billing country', 'invoicing' )
339
+                'error_message' => __('Please select your billing country', 'invoicing')
340 340
             );
341 341
     }
342 342
 
343
-    return apply_filters( 'wpinv_checkout_required_fields', $required_fields );
343
+    return apply_filters('wpinv_checkout_required_fields', $required_fields);
344 344
 }
345 345
 
346 346
 function wpinv_is_ssl_enforced() {
347
-    $ssl_enforced = wpinv_get_option( 'enforce_ssl', false );
348
-    return (bool) apply_filters( 'wpinv_is_ssl_enforced', $ssl_enforced );
347
+    $ssl_enforced = wpinv_get_option('enforce_ssl', false);
348
+    return (bool)apply_filters('wpinv_is_ssl_enforced', $ssl_enforced);
349 349
 }
350 350
 
351
-function wpinv_user_can_print_invoice( $post ) {
351
+function wpinv_user_can_print_invoice($post) {
352 352
     $allow = false;
353 353
 
354
-    $post = get_post( $post );
354
+    $post = get_post($post);
355 355
 
356
-    if ( empty( $post->ID ) ) {
356
+    if (empty($post->ID)) {
357 357
         return $allow;
358 358
     }
359 359
 
360
-    $invoice = wpinv_get_invoice( $post->ID );
361
-    if ( empty( $invoice->ID ) ) {
360
+    $invoice = wpinv_get_invoice($post->ID);
361
+    if (empty($invoice->ID)) {
362 362
         return $allow;
363 363
     }
364 364
 
365 365
     // Don't allow trash, draft status
366
-    if ( $invoice->has_status( array_keys( wpinv_get_invoice_statuses() ) ) ) {
367
-        if ( current_user_can( 'manage_options' ) ) { // Admin user
366
+    if ($invoice->has_status(array_keys(wpinv_get_invoice_statuses()))) {
367
+        if (current_user_can('manage_options')) { // Admin user
368 368
             $allow = true;
369
-        } else if ( is_user_logged_in() && (int)$invoice->get_user_id() === (int)get_current_user_id() ) { // Invoice owner
369
+        } else if (is_user_logged_in() && (int)$invoice->get_user_id() === (int)get_current_user_id()) { // Invoice owner
370 370
             $allow = true;
371
-        } else if ( isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) { // Invoice by key
371
+        } else if (isset($_GET['invoice_key']) && $_GET['invoice_key'] === $invoice->get_key()) { // Invoice by key
372 372
             $allow = true;
373 373
         }
374 374
     }
375 375
     
376
-    return apply_filters( 'wpinv_can_print_invoice', $allow, $post, $invoice );
376
+    return apply_filters('wpinv_can_print_invoice', $allow, $post, $invoice);
377 377
 }
378 378
 
379 379
 function wpinv_schedule_events() {
380 380
     // hourly, daily and twicedaily
381
-    if ( !wp_next_scheduled( 'wpinv_register_schedule_event_twicedaily' ) ) {
382
-        wp_schedule_event( current_time( 'timestamp' ), 'twicedaily', 'wpinv_register_schedule_event_twicedaily' );
381
+    if (!wp_next_scheduled('wpinv_register_schedule_event_twicedaily')) {
382
+        wp_schedule_event(current_time('timestamp'), 'twicedaily', 'wpinv_register_schedule_event_twicedaily');
383 383
     }
384 384
 }
385
-add_action( 'wp', 'wpinv_schedule_events' );
385
+add_action('wp', 'wpinv_schedule_events');
386 386
 
387 387
 function wpinv_schedule_event_twicedaily() {
388 388
     wpinv_email_payment_reminders();
389 389
 }
390
-add_action( 'wpinv_register_schedule_event_twicedaily', 'wpinv_schedule_event_twicedaily' );
390
+add_action('wpinv_register_schedule_event_twicedaily', 'wpinv_schedule_event_twicedaily');
391 391
 
392 392
 function wpinv_allow_guest_checkout() {
393
-    $return = wpinv_get_option( 'disable_guest_checkout', false );
394
-    return (bool) apply_filters( 'wpinv_allow_guest_checkout', !$return );
393
+    $return = wpinv_get_option('disable_guest_checkout', false);
394
+    return (bool)apply_filters('wpinv_allow_guest_checkout', !$return);
395 395
 }
396 396
\ No newline at end of file
Please login to merge, or discard this patch.
includes/class-wpinv-invoice.php 1 patch
Spacing   +796 added lines, -796 removed lines patch added patch discarded remove patch
@@ -7,12 +7,12 @@  discard block
 block discarded – undo
7 7
  */
8 8
  
9 9
 // MUST have WordPress.
10
-if ( !defined( 'WPINC' ) ) {
11
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
10
+if (!defined('WPINC')) {
11
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
12 12
 }
13 13
 
14 14
 final class WPInv_Invoice {
15
-    public $ID  = 0;
15
+    public $ID = 0;
16 16
     public $title;
17 17
     public $post_type;
18 18
     
@@ -65,17 +65,17 @@  discard block
 block discarded – undo
65 65
     public $full_name = '';
66 66
     public $parent_invoice = 0;
67 67
     
68
-    public function __construct( $invoice_id = false ) {
69
-        if( empty( $invoice_id ) ) {
68
+    public function __construct($invoice_id = false) {
69
+        if (empty($invoice_id)) {
70 70
             return false;
71 71
         }
72 72
 
73
-        $this->setup_invoice( $invoice_id );
73
+        $this->setup_invoice($invoice_id);
74 74
     }
75 75
 
76
-    public function get( $key ) {
77
-        if ( method_exists( $this, 'get_' . $key ) ) {
78
-            $value = call_user_func( array( $this, 'get_' . $key ) );
76
+    public function get($key) {
77
+        if (method_exists($this, 'get_' . $key)) {
78
+            $value = call_user_func(array($this, 'get_' . $key));
79 79
         } else {
80 80
             $value = $this->$key;
81 81
         }
@@ -83,51 +83,51 @@  discard block
 block discarded – undo
83 83
         return $value;
84 84
     }
85 85
 
86
-    public function set( $key, $value ) {
87
-        $ignore = array( 'items', 'cart_details', 'fees', '_ID' );
86
+    public function set($key, $value) {
87
+        $ignore = array('items', 'cart_details', 'fees', '_ID');
88 88
 
89
-        if ( $key === 'status' ) {
89
+        if ($key === 'status') {
90 90
             $this->old_status = $this->status;
91 91
         }
92 92
 
93
-        if ( ! in_array( $key, $ignore ) ) {
94
-            $this->pending[ $key ] = $value;
93
+        if (!in_array($key, $ignore)) {
94
+            $this->pending[$key] = $value;
95 95
         }
96 96
 
97
-        if( '_ID' !== $key ) {
97
+        if ('_ID' !== $key) {
98 98
             $this->$key = $value;
99 99
         }
100 100
     }
101 101
 
102
-    public function _isset( $name ) {
103
-        if ( property_exists( $this, $name) ) {
104
-            return false === empty( $this->$name );
102
+    public function _isset($name) {
103
+        if (property_exists($this, $name)) {
104
+            return false === empty($this->$name);
105 105
         } else {
106 106
             return null;
107 107
         }
108 108
     }
109 109
 
110
-    private function setup_invoice( $invoice_id ) {
110
+    private function setup_invoice($invoice_id) {
111 111
         $this->pending = array();
112 112
 
113
-        if ( empty( $invoice_id ) ) {
113
+        if (empty($invoice_id)) {
114 114
             return false;
115 115
         }
116 116
 
117
-        $invoice = get_post( $invoice_id );
117
+        $invoice = get_post($invoice_id);
118 118
 
119
-        if( !$invoice || is_wp_error( $invoice ) ) {
119
+        if (!$invoice || is_wp_error($invoice)) {
120 120
             return false;
121 121
         }
122 122
 
123
-        if( !('wpi_invoice' == $invoice->post_type OR 'wpi_quote' == $invoice->post_type) ) {
123
+        if (!('wpi_invoice' == $invoice->post_type OR 'wpi_quote' == $invoice->post_type)) {
124 124
             return false;
125 125
         }
126 126
 
127
-        do_action( 'wpinv_pre_setup_invoice', $this, $invoice_id );
127
+        do_action('wpinv_pre_setup_invoice', $this, $invoice_id);
128 128
         
129 129
         // Primary Identifier
130
-        $this->ID              = absint( $invoice_id );
130
+        $this->ID              = absint($invoice_id);
131 131
         $this->post_type       = $invoice->post_type;
132 132
         
133 133
         // We have a payment, get the generic payment_meta item to reduce calls to it
@@ -139,7 +139,7 @@  discard block
 block discarded – undo
139 139
         $this->post_status     = $this->status;
140 140
         $this->mode            = $this->setup_mode();
141 141
         $this->parent_invoice  = $invoice->post_parent;
142
-        $this->post_name       = $this->setup_post_name( $invoice );
142
+        $this->post_name       = $this->setup_post_name($invoice);
143 143
         $this->status_nicename = $this->setup_status_nicename($invoice->post_status);
144 144
 
145 145
         // Items
@@ -161,8 +161,8 @@  discard block
 block discarded – undo
161 161
         
162 162
         // User based
163 163
         $this->ip              = $this->setup_ip();
164
-        $this->user_id         = !empty( $invoice->post_author ) ? $invoice->post_author : get_current_user_id();///$this->setup_user_id();
165
-        $this->email           = get_the_author_meta( 'email', $this->user_id );
164
+        $this->user_id         = !empty($invoice->post_author) ? $invoice->post_author : get_current_user_id(); ///$this->setup_user_id();
165
+        $this->email           = get_the_author_meta('email', $this->user_id);
166 166
         
167 167
         $this->user_info       = $this->setup_user_info();
168 168
                 
@@ -171,7 +171,7 @@  discard block
 block discarded – undo
171 171
         $this->company         = $this->user_info['company'];
172 172
         $this->vat_number      = $this->user_info['vat_number'];
173 173
         $this->vat_rate        = $this->user_info['vat_rate'];
174
-        $this->adddress_confirmed  = $this->user_info['adddress_confirmed'];
174
+        $this->adddress_confirmed = $this->user_info['adddress_confirmed'];
175 175
         $this->address         = $this->user_info['address'];
176 176
         $this->city            = $this->user_info['city'];
177 177
         $this->country         = $this->user_info['country'];
@@ -186,35 +186,35 @@  discard block
 block discarded – undo
186 186
         // Other Identifiers
187 187
         $this->key             = $this->setup_invoice_key();
188 188
         $this->number          = $this->setup_invoice_number();
189
-        $this->title           = !empty( $invoice->post_title ) ? $invoice->post_title : $this->number;
189
+        $this->title           = !empty($invoice->post_title) ? $invoice->post_title : $this->number;
190 190
         
191
-        $this->full_name       = trim( $this->first_name . ' '. $this->last_name );
191
+        $this->full_name       = trim($this->first_name . ' ' . $this->last_name);
192 192
         
193 193
         // Allow extensions to add items to this object via hook
194
-        do_action( 'wpinv_setup_invoice', $this, $invoice_id );
194
+        do_action('wpinv_setup_invoice', $this, $invoice_id);
195 195
 
196 196
         return true;
197 197
     }
198 198
     
199 199
     private function setup_status_nicename($status) {
200
-        $all_invoice_statuses  = wpinv_get_invoice_statuses();
201
-        $status   = isset( $all_invoice_statuses[$status] ) ? $all_invoice_statuses[$status] : __( $status, 'invoicing' );
200
+        $all_invoice_statuses = wpinv_get_invoice_statuses();
201
+        $status = isset($all_invoice_statuses[$status]) ? $all_invoice_statuses[$status] : __($status, 'invoicing');
202 202
 
203
-        return apply_filters( 'setup_status_nicename', $status );
203
+        return apply_filters('setup_status_nicename', $status);
204 204
     }
205 205
     
206
-    private function setup_post_name( $post = NULL ) {
206
+    private function setup_post_name($post = NULL) {
207 207
         global $wpdb;
208 208
         
209 209
         $post_name = '';
210 210
         
211
-        if ( !empty( $post ) ) {
212
-            if( !empty( $post->post_name ) ) {
211
+        if (!empty($post)) {
212
+            if (!empty($post->post_name)) {
213 213
                 $post_name = $post->post_name;
214
-            } else if ( !empty( $post->ID ) ) {
214
+            } else if (!empty($post->ID)) {
215 215
                 $post_name = 'inv-' . $post->ID;
216 216
 
217
-                $wpdb->update( $wpdb->posts, array( 'post_name' => 'inv-' . $post->ID ), array( 'ID' => $post->ID ) );
217
+                $wpdb->update($wpdb->posts, array('post_name' => 'inv-' . $post->ID), array('ID' => $post->ID));
218 218
             }
219 219
         }
220 220
 
@@ -222,12 +222,12 @@  discard block
 block discarded – undo
222 222
     }
223 223
     
224 224
     private function setup_due_date() {
225
-        $due_date = $this->get_meta( '_wpinv_due_date' );
225
+        $due_date = $this->get_meta('_wpinv_due_date');
226 226
         
227
-        if ( empty( $due_date ) ) {
228
-            $overdue_time = strtotime( $this->date ) + ( DAY_IN_SECONDS * absint( wpinv_get_option( 'overdue_days' ) ) );
229
-            $due_date = date_i18n( 'Y-m-d', $overdue_time );
230
-        } else if ( $due_date == 'none' ) {
227
+        if (empty($due_date)) {
228
+            $overdue_time = strtotime($this->date) + (DAY_IN_SECONDS * absint(wpinv_get_option('overdue_days')));
229
+            $due_date = date_i18n('Y-m-d', $overdue_time);
230
+        } else if ($due_date == 'none') {
231 231
             $due_date = '';
232 232
         }
233 233
         
@@ -235,63 +235,63 @@  discard block
 block discarded – undo
235 235
     }
236 236
     
237 237
     private function setup_completed_date() {
238
-        $invoice = get_post( $this->ID );
238
+        $invoice = get_post($this->ID);
239 239
 
240
-        if ( 'wpi-pending' == $invoice->post_status || 'preapproved' == $invoice->post_status ) {
240
+        if ('wpi-pending' == $invoice->post_status || 'preapproved' == $invoice->post_status) {
241 241
             return false; // This invoice was never paid
242 242
         }
243 243
 
244
-        $date = ( $date = $this->get_meta( '_wpinv_completed_date', true ) ) ? $date : $invoice->modified_date;
244
+        $date = ($date = $this->get_meta('_wpinv_completed_date', true)) ? $date : $invoice->modified_date;
245 245
 
246 246
         return $date;
247 247
     }
248 248
     
249 249
     private function setup_cart_details() {
250
-        $cart_details = isset( $this->payment_meta['cart_details'] ) ? maybe_unserialize( $this->payment_meta['cart_details'] ) : array();
250
+        $cart_details = isset($this->payment_meta['cart_details']) ? maybe_unserialize($this->payment_meta['cart_details']) : array();
251 251
         return $cart_details;
252 252
     }
253 253
     
254 254
     public function array_convert() {
255
-        return get_object_vars( $this );
255
+        return get_object_vars($this);
256 256
     }
257 257
     
258 258
     private function setup_items() {
259
-        $items = isset( $this->payment_meta['items'] ) ? maybe_unserialize( $this->payment_meta['items'] ) : array();
259
+        $items = isset($this->payment_meta['items']) ? maybe_unserialize($this->payment_meta['items']) : array();
260 260
         return $items;
261 261
     }
262 262
     
263 263
     private function setup_fees() {
264
-        $payment_fees = isset( $this->payment_meta['fees'] ) ? $this->payment_meta['fees'] : array();
264
+        $payment_fees = isset($this->payment_meta['fees']) ? $this->payment_meta['fees'] : array();
265 265
         return $payment_fees;
266 266
     }
267 267
         
268 268
     private function setup_currency() {
269
-        $currency = isset( $this->payment_meta['currency'] ) ? $this->payment_meta['currency'] : apply_filters( 'wpinv_currency_default', wpinv_get_currency(), $this );
269
+        $currency = isset($this->payment_meta['currency']) ? $this->payment_meta['currency'] : apply_filters('wpinv_currency_default', wpinv_get_currency(), $this);
270 270
         return $currency;
271 271
     }
272 272
     
273 273
     private function setup_discount() {
274 274
         //$discount = $this->get_meta( '_wpinv_discount', true );
275
-        $discount = (float)$this->subtotal - ( (float)$this->total - (float)$this->tax - (float)$this->fees_total );
276
-        if ( $discount < 0 ) {
275
+        $discount = (float)$this->subtotal - ((float)$this->total - (float)$this->tax - (float)$this->fees_total);
276
+        if ($discount < 0) {
277 277
             $discount = 0;
278 278
         }
279
-        $discount = wpinv_round_amount( $discount );
279
+        $discount = wpinv_round_amount($discount);
280 280
         
281 281
         return $discount;
282 282
     }
283 283
     
284 284
     private function setup_discount_code() {
285
-        $discount_code = !empty( $this->discounts ) ? $this->discounts : $this->get_meta( '_wpinv_discount_code', true );
285
+        $discount_code = !empty($this->discounts) ? $this->discounts : $this->get_meta('_wpinv_discount_code', true);
286 286
         return $discount_code;
287 287
     }
288 288
     
289 289
     private function setup_tax() {
290
-        $tax = $this->get_meta( '_wpinv_tax', true );
290
+        $tax = $this->get_meta('_wpinv_tax', true);
291 291
 
292 292
         // We don't have tax as it's own meta and no meta was passed
293
-        if ( '' === $tax ) {            
294
-            $tax = isset( $this->payment_meta['tax'] ) ? $this->payment_meta['tax'] : 0;
293
+        if ('' === $tax) {            
294
+            $tax = isset($this->payment_meta['tax']) ? $this->payment_meta['tax'] : 0;
295 295
         }
296 296
 
297 297
         return $tax;
@@ -301,9 +301,9 @@  discard block
 block discarded – undo
301 301
         $subtotal     = 0;
302 302
         $cart_details = $this->cart_details;
303 303
 
304
-        if ( is_array( $cart_details ) ) {
305
-            foreach ( $cart_details as $item ) {
306
-                if ( isset( $item['subtotal'] ) ) {
304
+        if (is_array($cart_details)) {
305
+            foreach ($cart_details as $item) {
306
+                if (isset($item['subtotal'])) {
307 307
                     $subtotal += $item['subtotal'];
308 308
                 }
309 309
             }
@@ -317,23 +317,23 @@  discard block
 block discarded – undo
317 317
     }
318 318
     
319 319
     private function setup_discounts() {
320
-        $discounts = ! empty( $this->payment_meta['user_info']['discount'] ) ? $this->payment_meta['user_info']['discount'] : array();
320
+        $discounts = !empty($this->payment_meta['user_info']['discount']) ? $this->payment_meta['user_info']['discount'] : array();
321 321
         return $discounts;
322 322
     }
323 323
     
324 324
     private function setup_total() {
325
-        $amount = $this->get_meta( '_wpinv_total', true );
325
+        $amount = $this->get_meta('_wpinv_total', true);
326 326
 
327
-        if ( empty( $amount ) && '0.00' != $amount ) {
328
-            $meta   = $this->get_meta( '_wpinv_payment_meta', true );
329
-            $meta   = maybe_unserialize( $meta );
327
+        if (empty($amount) && '0.00' != $amount) {
328
+            $meta   = $this->get_meta('_wpinv_payment_meta', true);
329
+            $meta   = maybe_unserialize($meta);
330 330
 
331
-            if ( isset( $meta['amount'] ) ) {
331
+            if (isset($meta['amount'])) {
332 332
                 $amount = $meta['amount'];
333 333
             }
334 334
         }
335 335
 
336
-        if($amount < 0){
336
+        if ($amount < 0) {
337 337
             $amount = 0;
338 338
         }
339 339
 
@@ -341,13 +341,13 @@  discard block
 block discarded – undo
341 341
     }
342 342
     
343 343
     private function setup_mode() {
344
-        return $this->get_meta( '_wpinv_mode' );
344
+        return $this->get_meta('_wpinv_mode');
345 345
     }
346 346
 
347 347
     private function setup_gateway() {
348
-        $gateway = $this->get_meta( '_wpinv_gateway' );
348
+        $gateway = $this->get_meta('_wpinv_gateway');
349 349
         
350
-        if ( empty( $gateway ) && 'publish' === $this->status ) {
350
+        if (empty($gateway) && 'publish' === $this->status) {
351 351
             $gateway = 'manual';
352 352
         }
353 353
         
@@ -355,23 +355,23 @@  discard block
 block discarded – undo
355 355
     }
356 356
     
357 357
     private function setup_gateway_title() {
358
-        $gateway_title = wpinv_get_gateway_checkout_label( $this->gateway );
358
+        $gateway_title = wpinv_get_gateway_checkout_label($this->gateway);
359 359
         return $gateway_title;
360 360
     }
361 361
 
362 362
     private function setup_transaction_id() {
363
-        $transaction_id = $this->get_meta( '_wpinv_transaction_id' );
363
+        $transaction_id = $this->get_meta('_wpinv_transaction_id');
364 364
 
365
-        if ( empty( $transaction_id ) || (int) $transaction_id === (int) $this->ID ) {
365
+        if (empty($transaction_id) || (int)$transaction_id === (int)$this->ID) {
366 366
             $gateway        = $this->gateway;
367
-            $transaction_id = apply_filters( 'wpinv_get_invoice_transaction_id-' . $gateway, $this->ID );
367
+            $transaction_id = apply_filters('wpinv_get_invoice_transaction_id-' . $gateway, $this->ID);
368 368
         }
369 369
 
370 370
         return $transaction_id;
371 371
     }
372 372
 
373 373
     private function setup_ip() {
374
-        $ip = $this->get_meta( '_wpinv_user_ip' );
374
+        $ip = $this->get_meta('_wpinv_user_ip');
375 375
         return $ip;
376 376
     }
377 377
 
@@ -381,62 +381,62 @@  discard block
 block discarded – undo
381 381
     ///}
382 382
         
383 383
     private function setup_first_name() {
384
-        $first_name = $this->get_meta( '_wpinv_first_name' );
384
+        $first_name = $this->get_meta('_wpinv_first_name');
385 385
         return $first_name;
386 386
     }
387 387
     
388 388
     private function setup_last_name() {
389
-        $last_name = $this->get_meta( '_wpinv_last_name' );
389
+        $last_name = $this->get_meta('_wpinv_last_name');
390 390
         return $last_name;
391 391
     }
392 392
     
393 393
     private function setup_company() {
394
-        $company = $this->get_meta( '_wpinv_company' );
394
+        $company = $this->get_meta('_wpinv_company');
395 395
         return $company;
396 396
     }
397 397
     
398 398
     private function setup_vat_number() {
399
-        $vat_number = $this->get_meta( '_wpinv_vat_number' );
399
+        $vat_number = $this->get_meta('_wpinv_vat_number');
400 400
         return $vat_number;
401 401
     }
402 402
     
403 403
     private function setup_vat_rate() {
404
-        $vat_rate = $this->get_meta( '_wpinv_vat_rate' );
404
+        $vat_rate = $this->get_meta('_wpinv_vat_rate');
405 405
         return $vat_rate;
406 406
     }
407 407
     
408 408
     private function setup_adddress_confirmed() {
409
-        $adddress_confirmed = $this->get_meta( '_wpinv_adddress_confirmed' );
409
+        $adddress_confirmed = $this->get_meta('_wpinv_adddress_confirmed');
410 410
         return $adddress_confirmed;
411 411
     }
412 412
     
413 413
     private function setup_phone() {
414
-        $phone = $this->get_meta( '_wpinv_phone' );
414
+        $phone = $this->get_meta('_wpinv_phone');
415 415
         return $phone;
416 416
     }
417 417
     
418 418
     private function setup_address() {
419
-        $address = $this->get_meta( '_wpinv_address', true );
419
+        $address = $this->get_meta('_wpinv_address', true);
420 420
         return $address;
421 421
     }
422 422
     
423 423
     private function setup_city() {
424
-        $city = $this->get_meta( '_wpinv_city', true );
424
+        $city = $this->get_meta('_wpinv_city', true);
425 425
         return $city;
426 426
     }
427 427
     
428 428
     private function setup_country() {
429
-        $country = $this->get_meta( '_wpinv_country', true );
429
+        $country = $this->get_meta('_wpinv_country', true);
430 430
         return $country;
431 431
     }
432 432
     
433 433
     private function setup_state() {
434
-        $state = $this->get_meta( '_wpinv_state', true );
434
+        $state = $this->get_meta('_wpinv_state', true);
435 435
         return $state;
436 436
     }
437 437
     
438 438
     private function setup_zip() {
439
-        $zip = $this->get_meta( '_wpinv_zip', true );
439
+        $zip = $this->get_meta('_wpinv_zip', true);
440 440
         return $zip;
441 441
     }
442 442
 
@@ -445,7 +445,7 @@  discard block
 block discarded – undo
445 445
             'user_id'        => $this->user_id,
446 446
             'first_name'     => $this->first_name,
447 447
             'last_name'      => $this->last_name,
448
-            'email'          => get_the_author_meta( 'email', $this->user_id ),
448
+            'email'          => get_the_author_meta('email', $this->user_id),
449 449
             'phone'          => $this->phone,
450 450
             'address'        => $this->address,
451 451
             'city'           => $this->city,
@@ -460,12 +460,12 @@  discard block
 block discarded – undo
460 460
         );
461 461
         
462 462
         $user_info = array();
463
-        if ( isset( $this->payment_meta['user_info'] ) ) {
464
-            $user_info = maybe_unserialize( $this->payment_meta['user_info'] );
463
+        if (isset($this->payment_meta['user_info'])) {
464
+            $user_info = maybe_unserialize($this->payment_meta['user_info']);
465 465
             
466
-            if ( !empty( $user_info ) && isset( $user_info['user_id'] ) && $post = get_post( $this->ID ) ) {
466
+            if (!empty($user_info) && isset($user_info['user_id']) && $post = get_post($this->ID)) {
467 467
                 $this->user_id = $post->post_author;
468
-                $this->email = get_the_author_meta( 'email', $this->user_id );
468
+                $this->email = get_the_author_meta('email', $this->user_id);
469 469
                 
470 470
                 $user_info['user_id'] = $this->user_id;
471 471
                 $user_info['email'] = $this->email;
@@ -474,13 +474,13 @@  discard block
 block discarded – undo
474 474
             }
475 475
         }
476 476
         
477
-        $user_info    = wp_parse_args( $user_info, $defaults );
477
+        $user_info = wp_parse_args($user_info, $defaults);
478 478
         
479 479
         // Get the user, but only if it's been created
480
-        $user = get_userdata( $this->user_id );
480
+        $user = get_userdata($this->user_id);
481 481
         
482
-        if ( !empty( $user ) && $user->ID > 0 ) {
483
-            if ( empty( $user_info ) ) {
482
+        if (!empty($user) && $user->ID > 0) {
483
+            if (empty($user_info)) {
484 484
                 $user_info = array(
485 485
                     'user_id'    => $user->ID,
486 486
                     'first_name' => $user->first_name,
@@ -489,23 +489,23 @@  discard block
 block discarded – undo
489 489
                     'discount'   => '',
490 490
                 );
491 491
             } else {
492
-                foreach ( $user_info as $key => $value ) {
493
-                    if ( ! empty( $value ) ) {
492
+                foreach ($user_info as $key => $value) {
493
+                    if (!empty($value)) {
494 494
                         continue;
495 495
                     }
496 496
 
497
-                    switch( $key ) {
497
+                    switch ($key) {
498 498
                         case 'user_id':
499
-                            $user_info[ $key ] = $user->ID;
499
+                            $user_info[$key] = $user->ID;
500 500
                             break;
501 501
                         case 'first_name':
502
-                            $user_info[ $key ] = $user->first_name;
502
+                            $user_info[$key] = $user->first_name;
503 503
                             break;
504 504
                         case 'last_name':
505
-                            $user_info[ $key ] = $user->last_name;
505
+                            $user_info[$key] = $user->last_name;
506 506
                             break;
507 507
                         case 'email':
508
-                            $user_info[ $key ] = $user->user_email;
508
+                            $user_info[$key] = $user->user_email;
509 509
                             break;
510 510
                     }
511 511
                 }
@@ -516,25 +516,25 @@  discard block
 block discarded – undo
516 516
     }
517 517
 
518 518
     private function setup_invoice_key() {
519
-        $key = $this->get_meta( '_wpinv_key', true );
519
+        $key = $this->get_meta('_wpinv_key', true);
520 520
         
521 521
         return $key;
522 522
     }
523 523
 
524 524
     private function setup_invoice_number() {
525
-        $number = $this->get_meta( '_wpinv_number', true );
525
+        $number = $this->get_meta('_wpinv_number', true);
526 526
 
527
-        if ( !$number ) {
527
+        if (!$number) {
528 528
             $number = $this->ID;
529 529
 
530
-            if ( $this->status == 'auto-draft' ) {
531
-                if ( wpinv_get_option( 'sequential_invoice_number' ) ) {
530
+            if ($this->status == 'auto-draft') {
531
+                if (wpinv_get_option('sequential_invoice_number')) {
532 532
                     $next_number = wpinv_get_next_invoice_number();
533 533
                     $number      = $next_number;
534 534
                 }
535 535
             }
536 536
             
537
-            $number = wpinv_format_invoice_number( $number );
537
+            $number = wpinv_format_invoice_number($number);
538 538
         }
539 539
 
540 540
         return $number;
@@ -544,16 +544,16 @@  discard block
 block discarded – undo
544 544
         global $wpdb;
545 545
 
546 546
         $invoice_number = $this->ID;
547
-        if ( $number = $this->get_meta( '_wpinv_number', true ) ) {
547
+        if ($number = $this->get_meta('_wpinv_number', true)) {
548 548
             $invoice_number = $number;
549 549
         }
550 550
 
551
-        if ( empty( $this->key ) ) {
551
+        if (empty($this->key)) {
552 552
             $this->key = self::generate_key();
553 553
             $this->pending['key'] = $this->key;
554 554
         }
555 555
 
556
-        if ( empty( $this->ip ) ) {
556
+        if (empty($this->ip)) {
557 557
             $this->ip = wpinv_get_ip();
558 558
             $this->pending['ip'] = $this->ip;
559 559
         }
@@ -590,61 +590,61 @@  discard block
 block discarded – undo
590 590
                         'post_status'   => $this->status,
591 591
                         'post_author'   => $this->user_id,
592 592
                         'post_type'     => $this->post_type,
593
-                        'post_date'     => ! empty( $this->date ) && $this->date != '0000-00-00 00:00:00' ? $this->date : current_time( 'mysql' ),
594
-                        'post_date_gmt' => ! empty( $this->date ) && $this->date != '0000-00-00 00:00:00' ? get_gmt_from_date( $this->date ) : current_time( 'mysql', 1 ),
593
+                        'post_date'     => !empty($this->date) && $this->date != '0000-00-00 00:00:00' ? $this->date : current_time('mysql'),
594
+                        'post_date_gmt' => !empty($this->date) && $this->date != '0000-00-00 00:00:00' ? get_gmt_from_date($this->date) : current_time('mysql', 1),
595 595
                         'post_parent'   => $this->parent_invoice,
596 596
                     );
597
-        $args = apply_filters( 'wpinv_insert_invoice_args', $post_data, $this );
597
+        $args = apply_filters('wpinv_insert_invoice_args', $post_data, $this);
598 598
 
599 599
         // Create a blank invoice
600
-        if ( !empty( $this->ID ) ) {
601
-            $args['ID']         = $this->ID;
600
+        if (!empty($this->ID)) {
601
+            $args['ID'] = $this->ID;
602 602
 
603
-            $invoice_id = wp_update_post( $args, true );
603
+            $invoice_id = wp_update_post($args, true);
604 604
         } else {
605
-            $invoice_id = wp_insert_post( $args, true );
605
+            $invoice_id = wp_insert_post($args, true);
606 606
         }
607 607
 
608
-        if ( is_wp_error( $invoice_id ) ) {
608
+        if (is_wp_error($invoice_id)) {
609 609
             return false;
610 610
         }
611 611
 
612
-        if ( !empty( $invoice_id ) ) {
612
+        if (!empty($invoice_id)) {
613 613
             $this->ID  = $invoice_id;
614 614
             $this->_ID = $invoice_id;
615 615
 
616
-            $this->payment_meta = apply_filters( 'wpinv_payment_meta', $this->payment_meta, $payment_data );
617
-            if ( ! empty( $this->payment_meta['fees'] ) ) {
618
-                $this->fees = array_merge( $this->fees, $this->payment_meta['fees'] );
619
-                foreach( $this->fees as $fee ) {
620
-                    $this->increase_fees( $fee['amount'] );
616
+            $this->payment_meta = apply_filters('wpinv_payment_meta', $this->payment_meta, $payment_data);
617
+            if (!empty($this->payment_meta['fees'])) {
618
+                $this->fees = array_merge($this->fees, $this->payment_meta['fees']);
619
+                foreach ($this->fees as $fee) {
620
+                    $this->increase_fees($fee['amount']);
621 621
                 }
622 622
             }
623 623
 
624
-            $this->update_meta( '_wpinv_payment_meta', $this->payment_meta );            
624
+            $this->update_meta('_wpinv_payment_meta', $this->payment_meta);            
625 625
             $this->new = true;
626 626
         }
627 627
 
628 628
         return $this->ID;
629 629
     }
630 630
 
631
-    public function save( $setup = false ) {
631
+    public function save($setup = false) {
632 632
         global $wpi_session;
633 633
         
634 634
         $saved = false;
635
-        if ( empty( $this->items ) ) {
635
+        if (empty($this->items)) {
636 636
             return $saved; // Don't save empty invoice.
637 637
         }
638 638
         
639
-        if ( empty( $this->key ) ) {
639
+        if (empty($this->key)) {
640 640
             $this->key = self::generate_key();
641 641
             $this->pending['key'] = $this->key;
642 642
         }
643 643
         
644
-        if ( empty( $this->ID ) ) {
644
+        if (empty($this->ID)) {
645 645
             $invoice_id = $this->insert_invoice();
646 646
 
647
-            if ( false === $invoice_id ) {
647
+            if (false === $invoice_id) {
648 648
                 $saved = false;
649 649
             } else {
650 650
                 $this->ID = $invoice_id;
@@ -652,27 +652,27 @@  discard block
 block discarded – undo
652 652
         }
653 653
 
654 654
         // If we have something pending, let's save it
655
-        if ( !empty( $this->pending ) ) {
655
+        if (!empty($this->pending)) {
656 656
             $total_increase = 0;
657 657
             $total_decrease = 0;
658 658
 
659
-            foreach ( $this->pending as $key => $value ) {
660
-                switch( $key ) {
659
+            foreach ($this->pending as $key => $value) {
660
+                switch ($key) {
661 661
                     case 'items':
662 662
                         // Update totals for pending items
663
-                        foreach ( $this->pending[ $key ] as $item ) {
664
-                            switch( $item['action'] ) {
663
+                        foreach ($this->pending[$key] as $item) {
664
+                            switch ($item['action']) {
665 665
                                 case 'add':
666 666
                                     $price = $item['price'];
667 667
                                     $taxes = $item['tax'];
668 668
 
669
-                                    if ( 'publish' === $this->status ) {
669
+                                    if ('publish' === $this->status) {
670 670
                                         $total_increase += $price;
671 671
                                     }
672 672
                                     break;
673 673
 
674 674
                                 case 'remove':
675
-                                    if ( 'publish' === $this->status ) {
675
+                                    if ('publish' === $this->status) {
676 676
                                         $total_decrease += $item['price'];
677 677
                                     }
678 678
                                     break;
@@ -680,16 +680,16 @@  discard block
 block discarded – undo
680 680
                         }
681 681
                         break;
682 682
                     case 'fees':
683
-                        if ( 'publish' !== $this->status ) {
683
+                        if ('publish' !== $this->status) {
684 684
                             break;
685 685
                         }
686 686
 
687
-                        if ( empty( $this->pending[ $key ] ) ) {
687
+                        if (empty($this->pending[$key])) {
688 688
                             break;
689 689
                         }
690 690
 
691
-                        foreach ( $this->pending[ $key ] as $fee ) {
692
-                            switch( $fee['action'] ) {
691
+                        foreach ($this->pending[$key] as $fee) {
692
+                            switch ($fee['action']) {
693 693
                                 case 'add':
694 694
                                     $total_increase += $fee['amount'];
695 695
                                     break;
@@ -701,83 +701,83 @@  discard block
 block discarded – undo
701 701
                         }
702 702
                         break;
703 703
                     case 'status':
704
-                        $this->update_status( $this->status );
704
+                        $this->update_status($this->status);
705 705
                         break;
706 706
                     case 'gateway':
707
-                        $this->update_meta( '_wpinv_gateway', $this->gateway );
707
+                        $this->update_meta('_wpinv_gateway', $this->gateway);
708 708
                         break;
709 709
                     case 'mode':
710
-                        $this->update_meta( '_wpinv_mode', $this->mode );
710
+                        $this->update_meta('_wpinv_mode', $this->mode);
711 711
                         break;
712 712
                     case 'transaction_id':
713
-                        $this->update_meta( '_wpinv_transaction_id', $this->transaction_id );
713
+                        $this->update_meta('_wpinv_transaction_id', $this->transaction_id);
714 714
                         break;
715 715
                     case 'ip':
716
-                        $this->update_meta( '_wpinv_user_ip', $this->ip );
716
+                        $this->update_meta('_wpinv_user_ip', $this->ip);
717 717
                         break;
718 718
                     ///case 'user_id':
719 719
                         ///$this->update_meta( '_wpinv_user_id', $this->user_id );
720 720
                         ///$this->user_info['user_id'] = $this->user_id;
721 721
                         ///break;
722 722
                     case 'first_name':
723
-                        $this->update_meta( '_wpinv_first_name', $this->first_name );
723
+                        $this->update_meta('_wpinv_first_name', $this->first_name);
724 724
                         $this->user_info['first_name'] = $this->first_name;
725 725
                         break;
726 726
                     case 'last_name':
727
-                        $this->update_meta( '_wpinv_last_name', $this->last_name );
727
+                        $this->update_meta('_wpinv_last_name', $this->last_name);
728 728
                         $this->user_info['last_name'] = $this->last_name;
729 729
                         break;
730 730
                     case 'phone':
731
-                        $this->update_meta( '_wpinv_phone', $this->phone );
731
+                        $this->update_meta('_wpinv_phone', $this->phone);
732 732
                         $this->user_info['phone'] = $this->phone;
733 733
                         break;
734 734
                     case 'address':
735
-                        $this->update_meta( '_wpinv_address', $this->address );
735
+                        $this->update_meta('_wpinv_address', $this->address);
736 736
                         $this->user_info['address'] = $this->address;
737 737
                         break;
738 738
                     case 'city':
739
-                        $this->update_meta( '_wpinv_city', $this->city );
739
+                        $this->update_meta('_wpinv_city', $this->city);
740 740
                         $this->user_info['city'] = $this->city;
741 741
                         break;
742 742
                     case 'country':
743
-                        $this->update_meta( '_wpinv_country', $this->country );
743
+                        $this->update_meta('_wpinv_country', $this->country);
744 744
                         $this->user_info['country'] = $this->country;
745 745
                         break;
746 746
                     case 'state':
747
-                        $this->update_meta( '_wpinv_state', $this->state );
747
+                        $this->update_meta('_wpinv_state', $this->state);
748 748
                         $this->user_info['state'] = $this->state;
749 749
                         break;
750 750
                     case 'zip':
751
-                        $this->update_meta( '_wpinv_zip', $this->zip );
751
+                        $this->update_meta('_wpinv_zip', $this->zip);
752 752
                         $this->user_info['zip'] = $this->zip;
753 753
                         break;
754 754
                     case 'company':
755
-                        $this->update_meta( '_wpinv_company', $this->company );
755
+                        $this->update_meta('_wpinv_company', $this->company);
756 756
                         $this->user_info['company'] = $this->company;
757 757
                         break;
758 758
                     case 'vat_number':
759
-                        $this->update_meta( '_wpinv_vat_number', $this->vat_number );
759
+                        $this->update_meta('_wpinv_vat_number', $this->vat_number);
760 760
                         $this->user_info['vat_number'] = $this->vat_number;
761 761
                         
762
-                        $vat_info = $wpi_session->get( 'user_vat_data' );
763
-                        if ( $this->vat_number && !empty( $vat_info ) && isset( $vat_info['number'] ) && isset( $vat_info['valid'] ) && $vat_info['number'] == $this->vat_number ) {
764
-                            $adddress_confirmed = isset( $vat_info['adddress_confirmed'] ) ? $vat_info['adddress_confirmed'] : false;
765
-                            $this->update_meta( '_wpinv_adddress_confirmed', (bool)$adddress_confirmed );
762
+                        $vat_info = $wpi_session->get('user_vat_data');
763
+                        if ($this->vat_number && !empty($vat_info) && isset($vat_info['number']) && isset($vat_info['valid']) && $vat_info['number'] == $this->vat_number) {
764
+                            $adddress_confirmed = isset($vat_info['adddress_confirmed']) ? $vat_info['adddress_confirmed'] : false;
765
+                            $this->update_meta('_wpinv_adddress_confirmed', (bool)$adddress_confirmed);
766 766
                             $this->user_info['adddress_confirmed'] = (bool)$adddress_confirmed;
767 767
                         }
768 768
     
769 769
                         break;
770 770
                     case 'vat_rate':
771
-                        $this->update_meta( '_wpinv_vat_rate', $this->vat_rate );
771
+                        $this->update_meta('_wpinv_vat_rate', $this->vat_rate);
772 772
                         $this->user_info['vat_rate'] = $this->vat_rate;
773 773
                         break;
774 774
                     case 'adddress_confirmed':
775
-                        $this->update_meta( '_wpinv_adddress_confirmed', $this->adddress_confirmed );
775
+                        $this->update_meta('_wpinv_adddress_confirmed', $this->adddress_confirmed);
776 776
                         $this->user_info['adddress_confirmed'] = $this->adddress_confirmed;
777 777
                         break;
778 778
                     
779 779
                     case 'key':
780
-                        $this->update_meta( '_wpinv_key', $this->key );
780
+                        $this->update_meta('_wpinv_key', $this->key);
781 781
                         break;
782 782
                     case 'date':
783 783
                         $args = array(
@@ -786,49 +786,49 @@  discard block
 block discarded – undo
786 786
                             'edit_date' => true,
787 787
                         );
788 788
 
789
-                        wp_update_post( $args );
789
+                        wp_update_post($args);
790 790
                         break;
791 791
                     case 'due_date':
792
-                        if ( empty( $this->due_date ) ) {
792
+                        if (empty($this->due_date)) {
793 793
                             $this->due_date = 'none';
794 794
                         }
795 795
                         
796
-                        $this->update_meta( '_wpinv_due_date', $this->due_date );
796
+                        $this->update_meta('_wpinv_due_date', $this->due_date);
797 797
                         break;
798 798
                     case 'completed_date':
799
-                        $this->update_meta( '_wpinv_completed_date', $this->completed_date );
799
+                        $this->update_meta('_wpinv_completed_date', $this->completed_date);
800 800
                         break;
801 801
                     case 'discounts':
802
-                        if ( ! is_array( $this->discounts ) ) {
803
-                            $this->discounts = explode( ',', $this->discounts );
802
+                        if (!is_array($this->discounts)) {
803
+                            $this->discounts = explode(',', $this->discounts);
804 804
                         }
805 805
 
806
-                        $this->user_info['discount'] = implode( ',', $this->discounts );
806
+                        $this->user_info['discount'] = implode(',', $this->discounts);
807 807
                         break;
808 808
                     case 'discount':
809
-                        $this->update_meta( '_wpinv_discount', wpinv_round_amount( $this->discount ) );
809
+                        $this->update_meta('_wpinv_discount', wpinv_round_amount($this->discount));
810 810
                         break;
811 811
                     case 'discount_code':
812
-                        $this->update_meta( '_wpinv_discount_code', $this->discount_code );
812
+                        $this->update_meta('_wpinv_discount_code', $this->discount_code);
813 813
                         break;
814 814
                     case 'parent_invoice':
815 815
                         $args = array(
816 816
                             'ID'          => $this->ID,
817 817
                             'post_parent' => $this->parent_invoice,
818 818
                         );
819
-                        wp_update_post( $args );
819
+                        wp_update_post($args);
820 820
                         break;
821 821
                     default:
822
-                        do_action( 'wpinv_save', $this, $key );
822
+                        do_action('wpinv_save', $this, $key);
823 823
                         break;
824 824
                 }
825 825
             }
826 826
 
827
-            $this->update_meta( '_wpinv_subtotal', wpinv_round_amount( $this->subtotal ) );
828
-            $this->update_meta( '_wpinv_total', wpinv_round_amount( $this->total ) );
829
-            $this->update_meta( '_wpinv_tax', wpinv_round_amount( $this->tax ) );
827
+            $this->update_meta('_wpinv_subtotal', wpinv_round_amount($this->subtotal));
828
+            $this->update_meta('_wpinv_total', wpinv_round_amount($this->total));
829
+            $this->update_meta('_wpinv_tax', wpinv_round_amount($this->tax));
830 830
             
831
-            $this->items    = array_values( $this->items );
831
+            $this->items = array_values($this->items);
832 832
             
833 833
             $new_meta = array(
834 834
                 'items'         => $this->items,
@@ -839,12 +839,12 @@  discard block
 block discarded – undo
839 839
             );
840 840
             
841 841
             $meta        = $this->get_meta();
842
-            $merged_meta = array_merge( $meta, $new_meta );
842
+            $merged_meta = array_merge($meta, $new_meta);
843 843
 
844 844
             // Only save the payment meta if it's changed
845
-            if ( md5( serialize( $meta ) ) !== md5( serialize( $merged_meta) ) ) {
846
-                $updated     = $this->update_meta( '_wpinv_payment_meta', $merged_meta );
847
-                if ( false !== $updated ) {
845
+            if (md5(serialize($meta)) !== md5(serialize($merged_meta))) {
846
+                $updated = $this->update_meta('_wpinv_payment_meta', $merged_meta);
847
+                if (false !== $updated) {
848 848
                     $saved = true;
849 849
                 }
850 850
             }
@@ -852,15 +852,15 @@  discard block
 block discarded – undo
852 852
             $this->pending = array();
853 853
             $saved         = true;
854 854
         } else {
855
-            $this->update_meta( '_wpinv_subtotal', wpinv_round_amount( $this->subtotal ) );
856
-            $this->update_meta( '_wpinv_total', wpinv_round_amount( $this->total ) );
857
-            $this->update_meta( '_wpinv_tax', wpinv_round_amount( $this->tax ) );
855
+            $this->update_meta('_wpinv_subtotal', wpinv_round_amount($this->subtotal));
856
+            $this->update_meta('_wpinv_total', wpinv_round_amount($this->total));
857
+            $this->update_meta('_wpinv_tax', wpinv_round_amount($this->tax));
858 858
         }
859 859
         
860
-        do_action( 'wpinv_invoice_save', $this, $saved );
860
+        do_action('wpinv_invoice_save', $this, $saved);
861 861
 
862
-        if ( true === $saved || $setup ) {
863
-            $this->setup_invoice( $this->ID );
862
+        if (true === $saved || $setup) {
863
+            $this->setup_invoice($this->ID);
864 864
         }
865 865
         
866 866
         $this->refresh_item_ids();
@@ -868,7 +868,7 @@  discard block
 block discarded – undo
868 868
         return $saved;
869 869
     }
870 870
     
871
-    public function add_fee( $args, $global = true ) {
871
+    public function add_fee($args, $global = true) {
872 872
         $default_args = array(
873 873
             'label'       => '',
874 874
             'amount'      => 0,
@@ -878,75 +878,75 @@  discard block
 block discarded – undo
878 878
             'item_id'     => 0,
879 879
         );
880 880
 
881
-        $fee = wp_parse_args( $args, $default_args );
881
+        $fee = wp_parse_args($args, $default_args);
882 882
         
883
-        if ( !empty( $fee['label'] ) ) {
883
+        if (!empty($fee['label'])) {
884 884
             return false;
885 885
         }
886 886
         
887
-        $fee['id']  = sanitize_title( $fee['label'] );
887
+        $fee['id'] = sanitize_title($fee['label']);
888 888
         
889
-        $this->fees[]               = $fee;
889
+        $this->fees[] = $fee;
890 890
         
891 891
         $added_fee               = $fee;
892 892
         $added_fee['action']     = 'add';
893 893
         $this->pending['fees'][] = $added_fee;
894
-        reset( $this->fees );
894
+        reset($this->fees);
895 895
 
896
-        $this->increase_fees( $fee['amount'] );
896
+        $this->increase_fees($fee['amount']);
897 897
         return true;
898 898
     }
899 899
 
900
-    public function remove_fee( $key ) {
900
+    public function remove_fee($key) {
901 901
         $removed = false;
902 902
 
903
-        if ( is_numeric( $key ) ) {
904
-            $removed = $this->remove_fee_by( 'index', $key );
903
+        if (is_numeric($key)) {
904
+            $removed = $this->remove_fee_by('index', $key);
905 905
         }
906 906
 
907 907
         return $removed;
908 908
     }
909 909
 
910
-    public function remove_fee_by( $key, $value, $global = false ) {
911
-        $allowed_fee_keys = apply_filters( 'wpinv_fee_keys', array(
910
+    public function remove_fee_by($key, $value, $global = false) {
911
+        $allowed_fee_keys = apply_filters('wpinv_fee_keys', array(
912 912
             'index', 'label', 'amount', 'type',
913
-        ) );
913
+        ));
914 914
 
915
-        if ( ! in_array( $key, $allowed_fee_keys ) ) {
915
+        if (!in_array($key, $allowed_fee_keys)) {
916 916
             return false;
917 917
         }
918 918
 
919 919
         $removed = false;
920
-        if ( 'index' === $key && array_key_exists( $value, $this->fees ) ) {
921
-            $removed_fee             = $this->fees[ $value ];
920
+        if ('index' === $key && array_key_exists($value, $this->fees)) {
921
+            $removed_fee             = $this->fees[$value];
922 922
             $removed_fee['action']   = 'remove';
923 923
             $this->pending['fees'][] = $removed_fee;
924 924
 
925
-            $this->decrease_fees( $removed_fee['amount'] );
925
+            $this->decrease_fees($removed_fee['amount']);
926 926
 
927
-            unset( $this->fees[ $value ] );
927
+            unset($this->fees[$value]);
928 928
             $removed = true;
929
-        } else if ( 'index' !== $key ) {
930
-            foreach ( $this->fees as $index => $fee ) {
931
-                if ( isset( $fee[ $key ] ) && $fee[ $key ] == $value ) {
929
+        } else if ('index' !== $key) {
930
+            foreach ($this->fees as $index => $fee) {
931
+                if (isset($fee[$key]) && $fee[$key] == $value) {
932 932
                     $removed_fee             = $fee;
933 933
                     $removed_fee['action']   = 'remove';
934 934
                     $this->pending['fees'][] = $removed_fee;
935 935
 
936
-                    $this->decrease_fees( $removed_fee['amount'] );
936
+                    $this->decrease_fees($removed_fee['amount']);
937 937
 
938
-                    unset( $this->fees[ $index ] );
938
+                    unset($this->fees[$index]);
939 939
                     $removed = true;
940 940
 
941
-                    if ( false === $global ) {
941
+                    if (false === $global) {
942 942
                         break;
943 943
                     }
944 944
                 }
945 945
             }
946 946
         }
947 947
 
948
-        if ( true === $removed ) {
949
-            $this->fees = array_values( $this->fees );
948
+        if (true === $removed) {
949
+            $this->fees = array_values($this->fees);
950 950
         }
951 951
 
952 952
         return $removed;
@@ -954,35 +954,35 @@  discard block
 block discarded – undo
954 954
 
955 955
     
956 956
 
957
-    public function add_note( $note = '', $customer_type = false, $added_by_user = false, $system = false ) {
957
+    public function add_note($note = '', $customer_type = false, $added_by_user = false, $system = false) {
958 958
         // Bail if no note specified
959
-        if( !$note ) {
959
+        if (!$note) {
960 960
             return false;
961 961
         }
962 962
 
963
-        if ( empty( $this->ID ) )
963
+        if (empty($this->ID))
964 964
             return false;
965 965
         
966
-        if ( ( ( is_user_logged_in() && current_user_can( 'manage_options' ) ) || $added_by_user ) && !$system ) {
967
-            $user                 = get_user_by( 'id', get_current_user_id() );
966
+        if (((is_user_logged_in() && current_user_can('manage_options')) || $added_by_user) && !$system) {
967
+            $user                 = get_user_by('id', get_current_user_id());
968 968
             $comment_author       = $user->display_name;
969 969
             $comment_author_email = $user->user_email;
970 970
         } else {
971
-            $comment_author       = __( 'System', 'invoicing' );
972
-            $comment_author_email = strtolower( __( 'System', 'invoicing' ) ) . '@';
973
-            $comment_author_email .= isset( $_SERVER['HTTP_HOST'] ) ? str_replace( 'www.', '', $_SERVER['HTTP_HOST'] ) : 'noreply.com';
974
-            $comment_author_email = sanitize_email( $comment_author_email );
971
+            $comment_author       = __('System', 'invoicing');
972
+            $comment_author_email = strtolower(__('System', 'invoicing')) . '@';
973
+            $comment_author_email .= isset($_SERVER['HTTP_HOST']) ? str_replace('www.', '', $_SERVER['HTTP_HOST']) : 'noreply.com';
974
+            $comment_author_email = sanitize_email($comment_author_email);
975 975
         }
976 976
 
977
-        do_action( 'wpinv_pre_insert_invoice_note', $this->ID, $note, $customer_type );
977
+        do_action('wpinv_pre_insert_invoice_note', $this->ID, $note, $customer_type);
978 978
 
979
-        $note_id = wp_insert_comment( wp_filter_comment( array(
979
+        $note_id = wp_insert_comment(wp_filter_comment(array(
980 980
             'comment_post_ID'      => $this->ID,
981 981
             'comment_content'      => $note,
982 982
             'comment_agent'        => 'GeoDirectory',
983 983
             'user_id'              => is_admin() ? get_current_user_id() : 0,
984
-            'comment_date'         => current_time( 'mysql' ),
985
-            'comment_date_gmt'     => current_time( 'mysql', 1 ),
984
+            'comment_date'         => current_time('mysql'),
985
+            'comment_date_gmt'     => current_time('mysql', 1),
986 986
             'comment_approved'     => 1,
987 987
             'comment_parent'       => 0,
988 988
             'comment_author'       => $comment_author,
@@ -990,53 +990,53 @@  discard block
 block discarded – undo
990 990
             'comment_author_url'   => '',
991 991
             'comment_author_email' => $comment_author_email,
992 992
             'comment_type'         => 'wpinv_note'
993
-        ) ) );
993
+        )));
994 994
 
995
-        do_action( 'wpinv_insert_payment_note', $note_id, $this->ID, $note );
995
+        do_action('wpinv_insert_payment_note', $note_id, $this->ID, $note);
996 996
         
997
-        if ( $customer_type ) {
998
-            add_comment_meta( $note_id, '_wpi_customer_note', 1 );
997
+        if ($customer_type) {
998
+            add_comment_meta($note_id, '_wpi_customer_note', 1);
999 999
 
1000
-            do_action( 'wpinv_new_customer_note', array( 'invoice_id' => $this->ID, 'user_note' => $note ) );
1000
+            do_action('wpinv_new_customer_note', array('invoice_id' => $this->ID, 'user_note' => $note));
1001 1001
         }
1002 1002
 
1003 1003
         return $note_id;
1004 1004
     }
1005 1005
 
1006
-    private function increase_subtotal( $amount = 0.00 ) {
1007
-        $amount          = (float) $amount;
1006
+    private function increase_subtotal($amount = 0.00) {
1007
+        $amount          = (float)$amount;
1008 1008
         $this->subtotal += $amount;
1009
-        $this->subtotal  = wpinv_round_amount( $this->subtotal );
1009
+        $this->subtotal  = wpinv_round_amount($this->subtotal);
1010 1010
 
1011 1011
         $this->recalculate_total();
1012 1012
     }
1013 1013
 
1014
-    private function decrease_subtotal( $amount = 0.00 ) {
1015
-        $amount          = (float) $amount;
1014
+    private function decrease_subtotal($amount = 0.00) {
1015
+        $amount          = (float)$amount;
1016 1016
         $this->subtotal -= $amount;
1017
-        $this->subtotal  = wpinv_round_amount( $this->subtotal );
1017
+        $this->subtotal  = wpinv_round_amount($this->subtotal);
1018 1018
 
1019
-        if ( $this->subtotal < 0 ) {
1019
+        if ($this->subtotal < 0) {
1020 1020
             $this->subtotal = 0;
1021 1021
         }
1022 1022
 
1023 1023
         $this->recalculate_total();
1024 1024
     }
1025 1025
 
1026
-    private function increase_fees( $amount = 0.00 ) {
1026
+    private function increase_fees($amount = 0.00) {
1027 1027
         $amount            = (float)$amount;
1028 1028
         $this->fees_total += $amount;
1029
-        $this->fees_total  = wpinv_round_amount( $this->fees_total );
1029
+        $this->fees_total  = wpinv_round_amount($this->fees_total);
1030 1030
 
1031 1031
         $this->recalculate_total();
1032 1032
     }
1033 1033
 
1034
-    private function decrease_fees( $amount = 0.00 ) {
1035
-        $amount            = (float) $amount;
1034
+    private function decrease_fees($amount = 0.00) {
1035
+        $amount            = (float)$amount;
1036 1036
         $this->fees_total -= $amount;
1037
-        $this->fees_total  = wpinv_round_amount( $this->fees_total );
1037
+        $this->fees_total  = wpinv_round_amount($this->fees_total);
1038 1038
 
1039
-        if ( $this->fees_total < 0 ) {
1039
+        if ($this->fees_total < 0) {
1040 1040
             $this->fees_total = 0;
1041 1041
         }
1042 1042
 
@@ -1047,54 +1047,54 @@  discard block
 block discarded – undo
1047 1047
         global $wpi_nosave;
1048 1048
         
1049 1049
         $this->total = $this->subtotal + $this->tax + $this->fees_total;
1050
-        $this->total = wpinv_round_amount( $this->total );
1050
+        $this->total = wpinv_round_amount($this->total);
1051 1051
         
1052
-        do_action( 'wpinv_invoice_recalculate_total', $this, $wpi_nosave );
1052
+        do_action('wpinv_invoice_recalculate_total', $this, $wpi_nosave);
1053 1053
     }
1054 1054
     
1055
-    public function increase_tax( $amount = 0.00 ) {
1056
-        $amount       = (float) $amount;
1055
+    public function increase_tax($amount = 0.00) {
1056
+        $amount       = (float)$amount;
1057 1057
         $this->tax   += $amount;
1058 1058
 
1059 1059
         $this->recalculate_total();
1060 1060
     }
1061 1061
 
1062
-    public function decrease_tax( $amount = 0.00 ) {
1063
-        $amount     = (float) $amount;
1062
+    public function decrease_tax($amount = 0.00) {
1063
+        $amount     = (float)$amount;
1064 1064
         $this->tax -= $amount;
1065 1065
 
1066
-        if ( $this->tax < 0 ) {
1066
+        if ($this->tax < 0) {
1067 1067
             $this->tax = 0;
1068 1068
         }
1069 1069
 
1070 1070
         $this->recalculate_total();
1071 1071
     }
1072 1072
 
1073
-    public function update_status( $new_status = false, $note = '', $manual = false ) {
1074
-        $old_status = ! empty( $this->old_status ) ? $this->old_status : get_post_status( $this->ID );
1073
+    public function update_status($new_status = false, $note = '', $manual = false) {
1074
+        $old_status = !empty($this->old_status) ? $this->old_status : get_post_status($this->ID);
1075 1075
         
1076
-        if ( $old_status === $new_status && in_array( $new_status, array_keys( wpinv_get_invoice_statuses() ) ) ) {
1076
+        if ($old_status === $new_status && in_array($new_status, array_keys(wpinv_get_invoice_statuses()))) {
1077 1077
             return false; // Don't permit status changes that aren't changes
1078 1078
         }
1079 1079
 
1080
-        $do_change = apply_filters( 'wpinv_should_update_invoice_status', true, $this->ID, $new_status, $old_status );
1080
+        $do_change = apply_filters('wpinv_should_update_invoice_status', true, $this->ID, $new_status, $old_status);
1081 1081
         $updated = false;
1082 1082
 
1083
-        if ( $do_change ) {
1084
-            do_action( 'wpinv_before_invoice_status_change', $this->ID, $new_status, $old_status );
1083
+        if ($do_change) {
1084
+            do_action('wpinv_before_invoice_status_change', $this->ID, $new_status, $old_status);
1085 1085
 
1086 1086
             $update_post_data                   = array();
1087 1087
             $update_post_data['ID']             = $this->ID;
1088 1088
             $update_post_data['post_status']    = $new_status;
1089
-            $update_post_data['edit_date']      = current_time( 'mysql', 0 );
1090
-            $update_post_data['edit_date_gmt']  = current_time( 'mysql', 1 );
1089
+            $update_post_data['edit_date']      = current_time('mysql', 0);
1090
+            $update_post_data['edit_date_gmt']  = current_time('mysql', 1);
1091 1091
             
1092
-            $update_post_data = apply_filters( 'wpinv_update_invoice_status_fields', $update_post_data, $this->ID );
1092
+            $update_post_data = apply_filters('wpinv_update_invoice_status_fields', $update_post_data, $this->ID);
1093 1093
 
1094
-            $updated = wp_update_post( $update_post_data );     
1094
+            $updated = wp_update_post($update_post_data);     
1095 1095
            
1096 1096
             // Process any specific status functions
1097
-            switch( $new_status ) {
1097
+            switch ($new_status) {
1098 1098
                 case 'wpi-refunded':
1099 1099
                     $this->process_refund();
1100 1100
                     break;
@@ -1107,9 +1107,9 @@  discard block
 block discarded – undo
1107 1107
             }
1108 1108
             
1109 1109
             // Status was changed.
1110
-            do_action( 'wpinv_status_' . $new_status, $this->ID, $old_status );
1111
-            do_action( 'wpinv_status_' . $old_status . '_to_' . $new_status, $this->ID, $old_status );
1112
-            do_action( 'wpinv_update_status', $this->ID, $new_status, $old_status );
1110
+            do_action('wpinv_status_' . $new_status, $this->ID, $old_status);
1111
+            do_action('wpinv_status_' . $old_status . '_to_' . $new_status, $this->ID, $old_status);
1112
+            do_action('wpinv_update_status', $this->ID, $new_status, $old_status);
1113 1113
         }
1114 1114
 
1115 1115
         return $updated;
@@ -1123,72 +1123,72 @@  discard block
 block discarded – undo
1123 1123
         $this->save();
1124 1124
     }
1125 1125
 
1126
-    public function update_meta( $meta_key = '', $meta_value = '', $prev_value = '' ) {
1127
-        if ( empty( $meta_key ) ) {
1126
+    public function update_meta($meta_key = '', $meta_value = '', $prev_value = '') {
1127
+        if (empty($meta_key)) {
1128 1128
             return false;
1129 1129
         }
1130 1130
 
1131
-        if ( $meta_key == 'key' || $meta_key == 'date' ) {
1131
+        if ($meta_key == 'key' || $meta_key == 'date') {
1132 1132
             $current_meta = $this->get_meta();
1133
-            $current_meta[ $meta_key ] = $meta_value;
1133
+            $current_meta[$meta_key] = $meta_value;
1134 1134
 
1135 1135
             $meta_key     = '_wpinv_payment_meta';
1136 1136
             $meta_value   = $current_meta;
1137 1137
         }
1138 1138
 
1139
-        $meta_value = apply_filters( 'wpinv_update_payment_meta_' . $meta_key, $meta_value, $this->ID );
1139
+        $meta_value = apply_filters('wpinv_update_payment_meta_' . $meta_key, $meta_value, $this->ID);
1140 1140
         
1141
-        if ( $meta_key == '_wpinv_completed_date' && !empty( $meta_value ) ) {
1141
+        if ($meta_key == '_wpinv_completed_date' && !empty($meta_value)) {
1142 1142
             $args = array(
1143 1143
                 'ID'                => $this->ID,
1144 1144
                 'post_date'         => $meta_value,
1145 1145
                 'edit_date'         => true,
1146
-                'post_date_gmt'     => get_gmt_from_date( $meta_value ),
1146
+                'post_date_gmt'     => get_gmt_from_date($meta_value),
1147 1147
                 'post_modified'     => $meta_value,
1148
-                'post_modified_gmt' => get_gmt_from_date( $meta_value )
1148
+                'post_modified_gmt' => get_gmt_from_date($meta_value)
1149 1149
             );
1150
-            wp_update_post( $args );
1150
+            wp_update_post($args);
1151 1151
         }
1152 1152
         
1153
-        return update_post_meta( $this->ID, $meta_key, $meta_value, $prev_value );
1153
+        return update_post_meta($this->ID, $meta_key, $meta_value, $prev_value);
1154 1154
     }
1155 1155
 
1156 1156
     private function process_refund() {
1157 1157
         $process_refund = true;
1158 1158
 
1159 1159
         // If the payment was not in publish, don't decrement stats as they were never incremented
1160
-        if ( 'publish' != $this->old_status || 'wpi-refunded' != $this->status ) {
1160
+        if ('publish' != $this->old_status || 'wpi-refunded' != $this->status) {
1161 1161
             $process_refund = false;
1162 1162
         }
1163 1163
 
1164 1164
         // Allow extensions to filter for their own payment types, Example: Recurring Payments
1165
-        $process_refund = apply_filters( 'wpinv_should_process_refund', $process_refund, $this );
1165
+        $process_refund = apply_filters('wpinv_should_process_refund', $process_refund, $this);
1166 1166
 
1167
-        if ( false === $process_refund ) {
1167
+        if (false === $process_refund) {
1168 1168
             return;
1169 1169
         }
1170 1170
 
1171
-        do_action( 'wpinv_pre_refund_invoice', $this );
1171
+        do_action('wpinv_pre_refund_invoice', $this);
1172 1172
         
1173
-        $decrease_store_earnings = apply_filters( 'wpinv_decrease_store_earnings_on_refund', true, $this );
1174
-        $decrease_customer_value = apply_filters( 'wpinv_decrease_customer_value_on_refund', true, $this );
1175
-        $decrease_purchase_count = apply_filters( 'wpinv_decrease_customer_purchase_count_on_refund', true, $this );
1173
+        $decrease_store_earnings = apply_filters('wpinv_decrease_store_earnings_on_refund', true, $this);
1174
+        $decrease_customer_value = apply_filters('wpinv_decrease_customer_value_on_refund', true, $this);
1175
+        $decrease_purchase_count = apply_filters('wpinv_decrease_customer_purchase_count_on_refund', true, $this);
1176 1176
         
1177
-        do_action( 'wpinv_post_refund_invoice', $this );
1177
+        do_action('wpinv_post_refund_invoice', $this);
1178 1178
     }
1179 1179
 
1180 1180
     private function process_failure() {
1181 1181
         $discounts = $this->discounts;
1182
-        if ( empty( $discounts ) ) {
1182
+        if (empty($discounts)) {
1183 1183
             return;
1184 1184
         }
1185 1185
 
1186
-        if ( ! is_array( $discounts ) ) {
1187
-            $discounts = array_map( 'trim', explode( ',', $discounts ) );
1186
+        if (!is_array($discounts)) {
1187
+            $discounts = array_map('trim', explode(',', $discounts));
1188 1188
         }
1189 1189
 
1190
-        foreach ( $discounts as $discount ) {
1191
-            wpinv_decrease_discount_usage( $discount );
1190
+        foreach ($discounts as $discount) {
1191
+            wpinv_decrease_discount_usage($discount);
1192 1192
         }
1193 1193
     }
1194 1194
     
@@ -1196,92 +1196,92 @@  discard block
 block discarded – undo
1196 1196
         $process_pending = true;
1197 1197
 
1198 1198
         // If the payment was not in publish or revoked status, don't decrement stats as they were never incremented
1199
-        if ( ( 'publish' != $this->old_status && 'revoked' != $this->old_status ) || 'wpi-pending' != $this->status ) {
1199
+        if (('publish' != $this->old_status && 'revoked' != $this->old_status) || 'wpi-pending' != $this->status) {
1200 1200
             $process_pending = false;
1201 1201
         }
1202 1202
 
1203 1203
         // Allow extensions to filter for their own payment types, Example: Recurring Payments
1204
-        $process_pending = apply_filters( 'wpinv_should_process_pending', $process_pending, $this );
1204
+        $process_pending = apply_filters('wpinv_should_process_pending', $process_pending, $this);
1205 1205
 
1206
-        if ( false === $process_pending ) {
1206
+        if (false === $process_pending) {
1207 1207
             return;
1208 1208
         }
1209 1209
 
1210
-        $decrease_store_earnings = apply_filters( 'wpinv_decrease_store_earnings_on_pending', true, $this );
1211
-        $decrease_customer_value = apply_filters( 'wpinv_decrease_customer_value_on_pending', true, $this );
1212
-        $decrease_purchase_count = apply_filters( 'wpinv_decrease_customer_purchase_count_on_pending', true, $this );
1210
+        $decrease_store_earnings = apply_filters('wpinv_decrease_store_earnings_on_pending', true, $this);
1211
+        $decrease_customer_value = apply_filters('wpinv_decrease_customer_value_on_pending', true, $this);
1212
+        $decrease_purchase_count = apply_filters('wpinv_decrease_customer_purchase_count_on_pending', true, $this);
1213 1213
 
1214 1214
         $this->completed_date = '';
1215
-        $this->update_meta( '_wpinv_completed_date', '' );
1215
+        $this->update_meta('_wpinv_completed_date', '');
1216 1216
     }
1217 1217
     
1218 1218
     // get data
1219
-    public function get_meta( $meta_key = '_wpinv_payment_meta', $single = true ) {
1220
-        $meta = get_post_meta( $this->ID, $meta_key, $single );
1219
+    public function get_meta($meta_key = '_wpinv_payment_meta', $single = true) {
1220
+        $meta = get_post_meta($this->ID, $meta_key, $single);
1221 1221
 
1222
-        if ( $meta_key === '_wpinv_payment_meta' ) {
1222
+        if ($meta_key === '_wpinv_payment_meta') {
1223 1223
 
1224
-            if(!is_array($meta)){$meta = array();} // we need this to be an array so make sure it is.
1224
+            if (!is_array($meta)) {$meta = array(); } // we need this to be an array so make sure it is.
1225 1225
 
1226
-            if ( empty( $meta['key'] ) ) {
1226
+            if (empty($meta['key'])) {
1227 1227
                 $meta['key'] = $this->setup_invoice_key();
1228 1228
             }
1229 1229
 
1230
-            if ( empty( $meta['date'] ) ) {
1231
-                $meta['date'] = get_post_field( 'post_date', $this->ID );
1230
+            if (empty($meta['date'])) {
1231
+                $meta['date'] = get_post_field('post_date', $this->ID);
1232 1232
             }
1233 1233
         }
1234 1234
 
1235
-        $meta = apply_filters( 'wpinv_get_invoice_meta_' . $meta_key, $meta, $this->ID );
1235
+        $meta = apply_filters('wpinv_get_invoice_meta_' . $meta_key, $meta, $this->ID);
1236 1236
 
1237
-        return apply_filters( 'wpinv_get_invoice_meta', $meta, $this->ID, $meta_key );
1237
+        return apply_filters('wpinv_get_invoice_meta', $meta, $this->ID, $meta_key);
1238 1238
     }
1239 1239
     
1240 1240
     public function get_description() {
1241
-        $post = get_post( $this->ID );
1241
+        $post = get_post($this->ID);
1242 1242
         
1243
-        $description = !empty( $post ) ? $post->post_content : '';
1244
-        return apply_filters( 'wpinv_get_description', $description, $this->ID, $this );
1243
+        $description = !empty($post) ? $post->post_content : '';
1244
+        return apply_filters('wpinv_get_description', $description, $this->ID, $this);
1245 1245
     }
1246 1246
     
1247
-    public function get_status( $nicename = false ) {
1248
-        if ( !$nicename ) {
1247
+    public function get_status($nicename = false) {
1248
+        if (!$nicename) {
1249 1249
             $status = $this->status;
1250 1250
         } else {
1251 1251
             $status = $this->status_nicename;
1252 1252
         }
1253 1253
         
1254
-        return apply_filters( 'wpinv_get_status', $status, $nicename, $this->ID, $this );
1254
+        return apply_filters('wpinv_get_status', $status, $nicename, $this->ID, $this);
1255 1255
     }
1256 1256
     
1257 1257
     public function get_cart_details() {
1258
-        return apply_filters( 'wpinv_cart_details', $this->cart_details, $this->ID, $this );
1258
+        return apply_filters('wpinv_cart_details', $this->cart_details, $this->ID, $this);
1259 1259
     }
1260 1260
     
1261
-    public function get_subtotal( $currency = false ) {
1262
-        $subtotal = wpinv_round_amount( $this->subtotal );
1261
+    public function get_subtotal($currency = false) {
1262
+        $subtotal = wpinv_round_amount($this->subtotal);
1263 1263
         
1264
-        if ( $currency ) {
1265
-            $subtotal = wpinv_price( wpinv_format_amount( $subtotal, NULL, !$currency ), $this->get_currency() );
1264
+        if ($currency) {
1265
+            $subtotal = wpinv_price(wpinv_format_amount($subtotal, NULL, !$currency), $this->get_currency());
1266 1266
         }
1267 1267
         
1268
-        return apply_filters( 'wpinv_get_invoice_subtotal', $subtotal, $this->ID, $this, $currency );
1268
+        return apply_filters('wpinv_get_invoice_subtotal', $subtotal, $this->ID, $this, $currency);
1269 1269
     }
1270 1270
     
1271
-    public function get_total( $currency = false ) {        
1272
-        if ( $this->is_free_trial() ) {
1273
-            $total = wpinv_round_amount( 0 );
1271
+    public function get_total($currency = false) {        
1272
+        if ($this->is_free_trial()) {
1273
+            $total = wpinv_round_amount(0);
1274 1274
         } else {
1275
-            $total = wpinv_round_amount( $this->total );
1275
+            $total = wpinv_round_amount($this->total);
1276 1276
         }
1277
-        if ( $currency ) {
1278
-            $total = wpinv_price( wpinv_format_amount( $total, NULL, !$currency ), $this->get_currency() );
1277
+        if ($currency) {
1278
+            $total = wpinv_price(wpinv_format_amount($total, NULL, !$currency), $this->get_currency());
1279 1279
         }
1280 1280
         
1281
-        return apply_filters( 'wpinv_get_invoice_total', $total, $this->ID, $this, $currency );
1281
+        return apply_filters('wpinv_get_invoice_total', $total, $this->ID, $this, $currency);
1282 1282
     }
1283 1283
     
1284
-    public function get_recurring_details( $field = '', $currency = false ) {        
1284
+    public function get_recurring_details($field = '', $currency = false) {        
1285 1285
         $data                 = array();
1286 1286
         $data['cart_details'] = $this->cart_details;
1287 1287
         $data['subtotal']     = $this->get_subtotal();
@@ -1289,45 +1289,45 @@  discard block
 block discarded – undo
1289 1289
         $data['tax']          = $this->get_tax();
1290 1290
         $data['total']        = $this->get_total();
1291 1291
     
1292
-        if ( !empty( $this->cart_details ) && ( $this->is_parent() || $this->is_renewal() ) ) {
1292
+        if (!empty($this->cart_details) && ($this->is_parent() || $this->is_renewal())) {
1293 1293
             $is_free_trial = $this->is_free_trial();
1294
-            $discounts = $this->get_discounts( true );
1294
+            $discounts = $this->get_discounts(true);
1295 1295
             
1296
-            if ( $is_free_trial || !empty( $discounts ) ) {
1296
+            if ($is_free_trial || !empty($discounts)) {
1297 1297
                 $first_use_only = false;
1298 1298
                 
1299
-                if ( !empty( $discounts ) ) {
1300
-                    foreach ( $discounts as $key => $code ) {
1301
-                        if ( wpinv_discount_is_recurring( $code, true ) ) {
1299
+                if (!empty($discounts)) {
1300
+                    foreach ($discounts as $key => $code) {
1301
+                        if (wpinv_discount_is_recurring($code, true)) {
1302 1302
                             $first_use_only = true;
1303 1303
                             break;
1304 1304
                         }
1305 1305
                     }
1306 1306
                 }
1307 1307
                     
1308
-                if ( !$first_use_only ) {
1309
-                    $data['subtotal'] = wpinv_round_amount( $this->subtotal );
1310
-                    $data['discount'] = wpinv_round_amount( $this->discount );
1311
-                    $data['tax']      = wpinv_round_amount( $this->tax );
1312
-                    $data['total']    = wpinv_round_amount( $this->total );
1308
+                if (!$first_use_only) {
1309
+                    $data['subtotal'] = wpinv_round_amount($this->subtotal);
1310
+                    $data['discount'] = wpinv_round_amount($this->discount);
1311
+                    $data['tax']      = wpinv_round_amount($this->tax);
1312
+                    $data['total']    = wpinv_round_amount($this->total);
1313 1313
                 } else {
1314 1314
                     $cart_subtotal   = 0;
1315 1315
                     $cart_discount   = 0;
1316 1316
                     $cart_tax        = 0;
1317 1317
 
1318
-                    foreach ( $this->cart_details as $key => $item ) {
1319
-                        $item_quantity  = $item['quantity'] > 0 ? absint( $item['quantity'] ) : 1;
1320
-                        $item_subtotal  = !empty( $item['subtotal'] ) ? $item['subtotal'] : $item['item_price'] * $item_quantity;
1318
+                    foreach ($this->cart_details as $key => $item) {
1319
+                        $item_quantity  = $item['quantity'] > 0 ? absint($item['quantity']) : 1;
1320
+                        $item_subtotal  = !empty($item['subtotal']) ? $item['subtotal'] : $item['item_price'] * $item_quantity;
1321 1321
                         $item_discount  = 0;
1322
-                        $item_tax       = $item_subtotal > 0 && !empty( $item['vat_rate'] ) ? ( $item_subtotal * 0.01 * (float)$item['vat_rate'] ) : 0;
1322
+                        $item_tax       = $item_subtotal > 0 && !empty($item['vat_rate']) ? ($item_subtotal * 0.01 * (float)$item['vat_rate']) : 0;
1323 1323
                         
1324
-                        if ( wpinv_prices_include_tax() ) {
1325
-                            $item_subtotal -= wpinv_round_amount( $item_tax );
1324
+                        if (wpinv_prices_include_tax()) {
1325
+                            $item_subtotal -= wpinv_round_amount($item_tax);
1326 1326
                         }
1327 1327
                         
1328 1328
                         $item_total     = $item_subtotal - $item_discount + $item_tax;
1329 1329
                         // Do not allow totals to go negative
1330
-                        if ( $item_total < 0 ) {
1330
+                        if ($item_total < 0) {
1331 1331
                             $item_total = 0;
1332 1332
                         }
1333 1333
                         
@@ -1335,113 +1335,113 @@  discard block
 block discarded – undo
1335 1335
                         $cart_discount  += (float)($item_discount);
1336 1336
                         $cart_tax       += (float)($item_tax);
1337 1337
                         
1338
-                        $data['cart_details'][$key]['discount']   = wpinv_round_amount( $item_discount );
1339
-                        $data['cart_details'][$key]['tax']        = wpinv_round_amount( $item_tax );
1340
-                        $data['cart_details'][$key]['price']      = wpinv_round_amount( $item_total );
1338
+                        $data['cart_details'][$key]['discount']   = wpinv_round_amount($item_discount);
1339
+                        $data['cart_details'][$key]['tax']        = wpinv_round_amount($item_tax);
1340
+                        $data['cart_details'][$key]['price']      = wpinv_round_amount($item_total);
1341 1341
                     }
1342 1342
                     
1343
-                    $data['subtotal'] = wpinv_round_amount( $cart_subtotal );
1344
-                    $data['discount'] = wpinv_round_amount( $cart_discount );
1345
-                    $data['tax']      = wpinv_round_amount( $cart_tax );
1346
-                    $data['total']    = wpinv_round_amount( $data['subtotal'] + $data['tax'] );
1343
+                    $data['subtotal'] = wpinv_round_amount($cart_subtotal);
1344
+                    $data['discount'] = wpinv_round_amount($cart_discount);
1345
+                    $data['tax']      = wpinv_round_amount($cart_tax);
1346
+                    $data['total']    = wpinv_round_amount($data['subtotal'] + $data['tax']);
1347 1347
                 }
1348 1348
             }
1349 1349
         }
1350 1350
         
1351
-        $data = apply_filters( 'wpinv_get_invoice_recurring_details', $data, $this, $field, $currency );
1351
+        $data = apply_filters('wpinv_get_invoice_recurring_details', $data, $this, $field, $currency);
1352 1352
 
1353
-        if ( isset( $data[$field] ) ) {
1354
-            return ( $currency ? wpinv_price( $data[$field], $this->get_currency() ) : $data[$field] );
1353
+        if (isset($data[$field])) {
1354
+            return ($currency ? wpinv_price($data[$field], $this->get_currency()) : $data[$field]);
1355 1355
         }
1356 1356
         
1357 1357
         return $data;
1358 1358
     }
1359 1359
     
1360
-    public function get_final_tax( $currency = false ) {        
1361
-        $final_total = wpinv_round_amount( $this->tax );
1362
-        if ( $currency ) {
1363
-            $final_total = wpinv_price( wpinv_format_amount( $final_total, NULL, !$currency ), $this->get_currency() );
1360
+    public function get_final_tax($currency = false) {        
1361
+        $final_total = wpinv_round_amount($this->tax);
1362
+        if ($currency) {
1363
+            $final_total = wpinv_price(wpinv_format_amount($final_total, NULL, !$currency), $this->get_currency());
1364 1364
         }
1365 1365
         
1366
-        return apply_filters( 'wpinv_get_invoice_final_total', $final_total, $this, $currency );
1366
+        return apply_filters('wpinv_get_invoice_final_total', $final_total, $this, $currency);
1367 1367
     }
1368 1368
     
1369
-    public function get_discounts( $array = false ) {
1369
+    public function get_discounts($array = false) {
1370 1370
         $discounts = $this->discounts;
1371
-        if ( $array && $discounts ) {
1372
-            $discounts = explode( ',', $discounts );
1371
+        if ($array && $discounts) {
1372
+            $discounts = explode(',', $discounts);
1373 1373
         }
1374
-        return apply_filters( 'wpinv_payment_discounts', $discounts, $this->ID, $this, $array );
1374
+        return apply_filters('wpinv_payment_discounts', $discounts, $this->ID, $this, $array);
1375 1375
     }
1376 1376
     
1377
-    public function get_discount( $currency = false, $dash = false ) {
1378
-        if ( !empty( $this->discounts ) ) {
1377
+    public function get_discount($currency = false, $dash = false) {
1378
+        if (!empty($this->discounts)) {
1379 1379
             global $ajax_cart_details;
1380 1380
             $ajax_cart_details = $this->get_cart_details();
1381 1381
             
1382
-            if ( !empty( $ajax_cart_details ) && count( $ajax_cart_details ) == count( $this->items ) ) {
1382
+            if (!empty($ajax_cart_details) && count($ajax_cart_details) == count($this->items)) {
1383 1383
                 $cart_items = $ajax_cart_details;
1384 1384
             } else {
1385 1385
                 $cart_items = $this->items;
1386 1386
             }
1387 1387
 
1388
-            $this->discount = wpinv_get_cart_items_discount_amount( $cart_items , $this->discounts );
1388
+            $this->discount = wpinv_get_cart_items_discount_amount($cart_items, $this->discounts);
1389 1389
         }
1390
-        $discount   = wpinv_round_amount( $this->discount );
1390
+        $discount   = wpinv_round_amount($this->discount);
1391 1391
         $dash       = $dash && $discount > 0 ? '&ndash;' : '';
1392 1392
         
1393
-        if ( $currency ) {
1394
-            $discount = wpinv_price( wpinv_format_amount( $discount, NULL, !$currency ), $this->get_currency() );
1393
+        if ($currency) {
1394
+            $discount = wpinv_price(wpinv_format_amount($discount, NULL, !$currency), $this->get_currency());
1395 1395
         }
1396 1396
         
1397
-        $discount   = $dash . $discount;
1397
+        $discount = $dash . $discount;
1398 1398
         
1399
-        return apply_filters( 'wpinv_get_invoice_discount', $discount, $this->ID, $this, $currency, $dash );
1399
+        return apply_filters('wpinv_get_invoice_discount', $discount, $this->ID, $this, $currency, $dash);
1400 1400
     }
1401 1401
     
1402 1402
     public function get_discount_code() {
1403 1403
         return $this->discount_code;
1404 1404
     }
1405 1405
     
1406
-    public function get_tax( $currency = false ) {
1407
-        $tax = wpinv_round_amount( $this->tax );
1406
+    public function get_tax($currency = false) {
1407
+        $tax = wpinv_round_amount($this->tax);
1408 1408
         
1409
-        if ( $currency ) {
1410
-            $tax = wpinv_price( wpinv_format_amount( $tax, NULL, !$currency ), $this->get_currency() );
1409
+        if ($currency) {
1410
+            $tax = wpinv_price(wpinv_format_amount($tax, NULL, !$currency), $this->get_currency());
1411 1411
         }
1412 1412
         
1413
-        return apply_filters( 'wpinv_get_invoice_tax', $tax, $this->ID, $this, $currency );
1413
+        return apply_filters('wpinv_get_invoice_tax', $tax, $this->ID, $this, $currency);
1414 1414
     }
1415 1415
     
1416
-    public function get_fees( $type = 'all' ) {
1417
-        $fees    = array();
1416
+    public function get_fees($type = 'all') {
1417
+        $fees = array();
1418 1418
 
1419
-        if ( ! empty( $this->fees ) && is_array( $this->fees ) ) {
1420
-            foreach ( $this->fees as $fee ) {
1421
-                if( 'all' != $type && ! empty( $fee['type'] ) && $type != $fee['type'] ) {
1419
+        if (!empty($this->fees) && is_array($this->fees)) {
1420
+            foreach ($this->fees as $fee) {
1421
+                if ('all' != $type && !empty($fee['type']) && $type != $fee['type']) {
1422 1422
                     continue;
1423 1423
                 }
1424 1424
 
1425
-                $fee['label'] = stripslashes( $fee['label'] );
1426
-                $fee['amount_display'] = wpinv_price( $fee['amount'], $this->get_currency() );
1427
-                $fees[]    = $fee;
1425
+                $fee['label'] = stripslashes($fee['label']);
1426
+                $fee['amount_display'] = wpinv_price($fee['amount'], $this->get_currency());
1427
+                $fees[] = $fee;
1428 1428
             }
1429 1429
         }
1430 1430
 
1431
-        return apply_filters( 'wpinv_get_invoice_fees', $fees, $this->ID, $this );
1431
+        return apply_filters('wpinv_get_invoice_fees', $fees, $this->ID, $this);
1432 1432
     }
1433 1433
     
1434
-    public function get_fees_total( $type = 'all' ) {
1435
-        $fees_total = (float) 0.00;
1434
+    public function get_fees_total($type = 'all') {
1435
+        $fees_total = (float)0.00;
1436 1436
 
1437
-        $payment_fees = isset( $this->payment_meta['fees'] ) ? $this->payment_meta['fees'] : array();
1438
-        if ( ! empty( $payment_fees ) ) {
1439
-            foreach ( $payment_fees as $fee ) {
1440
-                $fees_total += (float) $fee['amount'];
1437
+        $payment_fees = isset($this->payment_meta['fees']) ? $this->payment_meta['fees'] : array();
1438
+        if (!empty($payment_fees)) {
1439
+            foreach ($payment_fees as $fee) {
1440
+                $fees_total += (float)$fee['amount'];
1441 1441
             }
1442 1442
         }
1443 1443
 
1444
-        return apply_filters( 'wpinv_get_invoice_fees_total', $fees_total, $this->ID, $this );
1444
+        return apply_filters('wpinv_get_invoice_fees_total', $fees_total, $this->ID, $this);
1445 1445
         /*
1446 1446
         $fees = $this->get_fees( $type );
1447 1447
 
@@ -1461,116 +1461,116 @@  discard block
 block discarded – undo
1461 1461
     }
1462 1462
 
1463 1463
     public function get_user_id() {
1464
-        return apply_filters( 'wpinv_user_id', $this->user_id, $this->ID, $this );
1464
+        return apply_filters('wpinv_user_id', $this->user_id, $this->ID, $this);
1465 1465
     }
1466 1466
     
1467 1467
     public function get_first_name() {
1468
-        return apply_filters( 'wpinv_first_name', $this->first_name, $this->ID, $this );
1468
+        return apply_filters('wpinv_first_name', $this->first_name, $this->ID, $this);
1469 1469
     }
1470 1470
     
1471 1471
     public function get_last_name() {
1472
-        return apply_filters( 'wpinv_last_name', $this->last_name, $this->ID, $this );
1472
+        return apply_filters('wpinv_last_name', $this->last_name, $this->ID, $this);
1473 1473
     }
1474 1474
     
1475 1475
     public function get_user_full_name() {
1476
-        return apply_filters( 'wpinv_user_full_name', $this->full_name, $this->ID, $this );
1476
+        return apply_filters('wpinv_user_full_name', $this->full_name, $this->ID, $this);
1477 1477
     }
1478 1478
     
1479 1479
     public function get_user_info() {
1480
-        return apply_filters( 'wpinv_user_info', $this->user_info, $this->ID, $this );
1480
+        return apply_filters('wpinv_user_info', $this->user_info, $this->ID, $this);
1481 1481
     }
1482 1482
     
1483 1483
     public function get_email() {
1484
-        return apply_filters( 'wpinv_user_email', $this->email, $this->ID, $this );
1484
+        return apply_filters('wpinv_user_email', $this->email, $this->ID, $this);
1485 1485
     }
1486 1486
     
1487 1487
     public function get_address() {
1488
-        return apply_filters( 'wpinv_address', $this->address, $this->ID, $this );
1488
+        return apply_filters('wpinv_address', $this->address, $this->ID, $this);
1489 1489
     }
1490 1490
     
1491 1491
     public function get_phone() {
1492
-        return apply_filters( 'wpinv_phone', $this->phone, $this->ID, $this );
1492
+        return apply_filters('wpinv_phone', $this->phone, $this->ID, $this);
1493 1493
     }
1494 1494
     
1495 1495
     public function get_number() {
1496
-        return apply_filters( 'wpinv_number', $this->number, $this->ID, $this );
1496
+        return apply_filters('wpinv_number', $this->number, $this->ID, $this);
1497 1497
     }
1498 1498
     
1499 1499
     public function get_items() {
1500
-        return apply_filters( 'wpinv_payment_meta_items', $this->items, $this->ID, $this );
1500
+        return apply_filters('wpinv_payment_meta_items', $this->items, $this->ID, $this);
1501 1501
     }
1502 1502
     
1503 1503
     public function get_key() {
1504
-        return apply_filters( 'wpinv_key', $this->key, $this->ID, $this );
1504
+        return apply_filters('wpinv_key', $this->key, $this->ID, $this);
1505 1505
     }
1506 1506
     
1507 1507
     public function get_transaction_id() {
1508
-        return apply_filters( 'wpinv_get_invoice_transaction_id', $this->transaction_id, $this->ID, $this );
1508
+        return apply_filters('wpinv_get_invoice_transaction_id', $this->transaction_id, $this->ID, $this);
1509 1509
     }
1510 1510
     
1511 1511
     public function get_gateway() {
1512
-        return apply_filters( 'wpinv_gateway', $this->gateway, $this->ID, $this );
1512
+        return apply_filters('wpinv_gateway', $this->gateway, $this->ID, $this);
1513 1513
     }
1514 1514
     
1515 1515
     public function get_gateway_title() {
1516
-        $this->gateway_title = !empty( $this->gateway_title ) ? $this->gateway_title : wpinv_get_gateway_checkout_label( $this->gateway );
1516
+        $this->gateway_title = !empty($this->gateway_title) ? $this->gateway_title : wpinv_get_gateway_checkout_label($this->gateway);
1517 1517
         
1518
-        return apply_filters( 'wpinv_gateway_title', $this->gateway_title, $this->ID, $this );
1518
+        return apply_filters('wpinv_gateway_title', $this->gateway_title, $this->ID, $this);
1519 1519
     }
1520 1520
     
1521 1521
     public function get_currency() {
1522
-        return apply_filters( 'wpinv_currency_code', $this->currency, $this->ID, $this );
1522
+        return apply_filters('wpinv_currency_code', $this->currency, $this->ID, $this);
1523 1523
     }
1524 1524
     
1525 1525
     public function get_created_date() {
1526
-        return apply_filters( 'wpinv_created_date', $this->date, $this->ID, $this );
1526
+        return apply_filters('wpinv_created_date', $this->date, $this->ID, $this);
1527 1527
     }
1528 1528
     
1529
-    public function get_due_date( $display = false ) {
1530
-        $due_date = apply_filters( 'wpinv_due_date', $this->due_date, $this->ID, $this );
1529
+    public function get_due_date($display = false) {
1530
+        $due_date = apply_filters('wpinv_due_date', $this->due_date, $this->ID, $this);
1531 1531
         
1532
-        if ( !$display || empty( $due_date ) ) {
1532
+        if (!$display || empty($due_date)) {
1533 1533
             return $due_date;
1534 1534
         }
1535 1535
         
1536
-        return date_i18n( get_option( 'date_format' ), strtotime( $due_date ) );
1536
+        return date_i18n(get_option('date_format'), strtotime($due_date));
1537 1537
     }
1538 1538
     
1539 1539
     public function get_completed_date() {
1540
-        return apply_filters( 'wpinv_completed_date', $this->completed_date, $this->ID, $this );
1540
+        return apply_filters('wpinv_completed_date', $this->completed_date, $this->ID, $this);
1541 1541
     }
1542 1542
     
1543
-    public function get_invoice_date( $formatted = true ) {
1543
+    public function get_invoice_date($formatted = true) {
1544 1544
         $date_completed = $this->completed_date;
1545 1545
         $invoice_date   = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? $date_completed : '';
1546 1546
         
1547
-        if ( $invoice_date == '' ) {
1547
+        if ($invoice_date == '') {
1548 1548
             $date_created   = $this->date;
1549 1549
             $invoice_date   = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? $date_created : '';
1550 1550
         }
1551 1551
         
1552
-        if ( $formatted && $invoice_date ) {
1553
-            $invoice_date   = date_i18n( get_option( 'date_format' ), strtotime( $invoice_date ) );
1552
+        if ($formatted && $invoice_date) {
1553
+            $invoice_date = date_i18n(get_option('date_format'), strtotime($invoice_date));
1554 1554
         }
1555 1555
 
1556
-        return apply_filters( 'wpinv_get_invoice_date', $invoice_date, $formatted, $this->ID, $this );
1556
+        return apply_filters('wpinv_get_invoice_date', $invoice_date, $formatted, $this->ID, $this);
1557 1557
     }
1558 1558
     
1559 1559
     public function get_ip() {
1560
-        return apply_filters( 'wpinv_user_ip', $this->ip, $this->ID, $this );
1560
+        return apply_filters('wpinv_user_ip', $this->ip, $this->ID, $this);
1561 1561
     }
1562 1562
         
1563
-    public function has_status( $status ) {
1564
-        return apply_filters( 'wpinv_has_status', ( is_array( $status ) && in_array( $this->get_status(), $status ) ) || $this->get_status() === $status ? true : false, $this, $status );
1563
+    public function has_status($status) {
1564
+        return apply_filters('wpinv_has_status', (is_array($status) && in_array($this->get_status(), $status)) || $this->get_status() === $status ? true : false, $this, $status);
1565 1565
     }
1566 1566
     
1567
-    public function add_item( $item_id = 0, $args = array() ) {
1567
+    public function add_item($item_id = 0, $args = array()) {
1568 1568
         global $wpi_current_id, $wpi_item_id;
1569 1569
         
1570
-        $item = new WPInv_Item( $item_id );
1570
+        $item = new WPInv_Item($item_id);
1571 1571
 
1572 1572
         // Bail if this post isn't a item
1573
-        if( !$item || $item->post_type !== 'wpi_item' ) {
1573
+        if (!$item || $item->post_type !== 'wpi_item') {
1574 1574
             return false;
1575 1575
         }
1576 1576
         
@@ -1589,8 +1589,8 @@  discard block
 block discarded – undo
1589 1589
             'fees'          => array()
1590 1590
         );
1591 1591
 
1592
-        $args = wp_parse_args( apply_filters( 'wpinv_add_item_args', $args, $item->ID ), $defaults );
1593
-        $args['quantity']   = $has_quantities && $args['quantity'] > 0 ? absint( $args['quantity'] ) : 1;
1592
+        $args = wp_parse_args(apply_filters('wpinv_add_item_args', $args, $item->ID), $defaults);
1593
+        $args['quantity'] = $has_quantities && $args['quantity'] > 0 ? absint($args['quantity']) : 1;
1594 1594
 
1595 1595
         $wpi_current_id         = $this->ID;
1596 1596
         $wpi_item_id            = $item->ID;
@@ -1602,19 +1602,19 @@  discard block
 block discarded – undo
1602 1602
         $found_cart_key         = false;
1603 1603
         
1604 1604
         if ($has_quantities) {
1605
-            $this->cart_details = !empty( $this->cart_details ) ? array_values( $this->cart_details ) : $this->cart_details;
1605
+            $this->cart_details = !empty($this->cart_details) ? array_values($this->cart_details) : $this->cart_details;
1606 1606
             
1607
-            foreach ( $this->items as $key => $cart_item ) {
1608
-                if ( (int)$item_id !== (int)$cart_item['id'] ) {
1607
+            foreach ($this->items as $key => $cart_item) {
1608
+                if ((int)$item_id !== (int)$cart_item['id']) {
1609 1609
                     continue;
1610 1610
                 }
1611 1611
 
1612
-                $this->items[ $key ]['quantity'] += $args['quantity'];
1612
+                $this->items[$key]['quantity'] += $args['quantity'];
1613 1613
                 break;
1614 1614
             }
1615 1615
             
1616
-            foreach ( $this->cart_details as $cart_key => $cart_item ) {
1617
-                if ( $item_id != $cart_item['id'] ) {
1616
+            foreach ($this->cart_details as $cart_key => $cart_item) {
1617
+                if ($item_id != $cart_item['id']) {
1618 1618
                     continue;
1619 1619
                 }
1620 1620
 
@@ -1626,29 +1626,29 @@  discard block
 block discarded – undo
1626 1626
         if ($has_quantities && $found_cart_key !== false) {
1627 1627
             $cart_item          = $this->cart_details[$found_cart_key];
1628 1628
             $item_price         = $cart_item['item_price'];
1629
-            $quantity           = !empty( $cart_item['quantity'] ) ? $cart_item['quantity'] : 1;
1630
-            $tax_rate           = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : 0;
1629
+            $quantity           = !empty($cart_item['quantity']) ? $cart_item['quantity'] : 1;
1630
+            $tax_rate           = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : 0;
1631 1631
             
1632 1632
             $new_quantity       = $quantity + $args['quantity'];
1633 1633
             $subtotal           = $item_price * $new_quantity;
1634 1634
             
1635 1635
             $args['quantity']   = $new_quantity;
1636
-            $discount           = !empty( $args['discount'] ) ? $args['discount'] : 0;
1637
-            $tax                = $subtotal > 0 && $tax_rate > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0;
1636
+            $discount           = !empty($args['discount']) ? $args['discount'] : 0;
1637
+            $tax                = $subtotal > 0 && $tax_rate > 0 ? (($subtotal - $discount) * 0.01 * (float)$tax_rate) : 0;
1638 1638
             
1639 1639
             $discount_increased = $discount > 0 && $subtotal > 0 && $discount > (float)$cart_item['discount'] ? $discount - (float)$cart_item['discount'] : 0;
1640 1640
             $tax_increased      = $tax > 0 && $subtotal > 0 && $tax > (float)$cart_item['tax'] ? $tax - (float)$cart_item['tax'] : 0;
1641 1641
             // The total increase equals the number removed * the item_price
1642
-            $total_increased    = wpinv_round_amount( $item_price );
1642
+            $total_increased    = wpinv_round_amount($item_price);
1643 1643
             
1644
-            if ( wpinv_prices_include_tax() ) {
1645
-                $subtotal -= wpinv_round_amount( $tax );
1644
+            if (wpinv_prices_include_tax()) {
1645
+                $subtotal -= wpinv_round_amount($tax);
1646 1646
             }
1647 1647
 
1648
-            $total              = $subtotal - $discount + $tax;
1648
+            $total = $subtotal - $discount + $tax;
1649 1649
 
1650 1650
             // Do not allow totals to go negative
1651
-            if( $total < 0 ) {
1651
+            if ($total < 0) {
1652 1652
                 $total = 0;
1653 1653
             }
1654 1654
             
@@ -1664,25 +1664,25 @@  discard block
 block discarded – undo
1664 1664
             $this->cart_details[$found_cart_key] = $cart_item;
1665 1665
         } else {
1666 1666
             // Set custom price.
1667
-            if ( $args['custom_price'] !== '' ) {
1667
+            if ($args['custom_price'] !== '') {
1668 1668
                 $item_price = $args['custom_price'];
1669 1669
             } else {
1670 1670
                 // Allow overriding the price
1671
-                if ( false !== $args['item_price'] ) {
1671
+                if (false !== $args['item_price']) {
1672 1672
                     $item_price = $args['item_price'];
1673 1673
                 } else {
1674
-                    $item_price = wpinv_get_item_price( $item->ID );
1674
+                    $item_price = wpinv_get_item_price($item->ID);
1675 1675
                 }
1676 1676
             }
1677 1677
 
1678 1678
             // Sanitizing the price here so we don't have a dozen calls later
1679
-            $item_price = wpinv_sanitize_amount( $item_price );
1680
-            $subtotal   = wpinv_round_amount( $item_price * $args['quantity'] );
1679
+            $item_price = wpinv_sanitize_amount($item_price);
1680
+            $subtotal   = wpinv_round_amount($item_price * $args['quantity']);
1681 1681
         
1682
-            $discount   = !empty( $args['discount'] ) ? $args['discount'] : 0;
1683
-            $tax_class  = !empty( $args['vat_class'] ) ? $args['vat_class'] : '';
1684
-            $tax_rate   = !empty( $args['vat_rate'] ) ? $args['vat_rate'] : 0;
1685
-            $tax        = $subtotal > 0 && $tax_rate > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0;
1682
+            $discount   = !empty($args['discount']) ? $args['discount'] : 0;
1683
+            $tax_class  = !empty($args['vat_class']) ? $args['vat_class'] : '';
1684
+            $tax_rate   = !empty($args['vat_rate']) ? $args['vat_rate'] : 0;
1685
+            $tax        = $subtotal > 0 && $tax_rate > 0 ? (($subtotal - $discount) * 0.01 * (float)$tax_rate) : 0;
1686 1686
 
1687 1687
             // Setup the items meta item
1688 1688
             $new_item = array(
@@ -1690,29 +1690,29 @@  discard block
 block discarded – undo
1690 1690
                 'quantity' => $args['quantity'],
1691 1691
             );
1692 1692
 
1693
-            $this->items[]  = $new_item;
1693
+            $this->items[] = $new_item;
1694 1694
 
1695
-            if ( wpinv_prices_include_tax() ) {
1696
-                $subtotal -= wpinv_round_amount( $tax );
1695
+            if (wpinv_prices_include_tax()) {
1696
+                $subtotal -= wpinv_round_amount($tax);
1697 1697
             }
1698 1698
 
1699
-            $total      = $subtotal - $discount + $tax;
1699
+            $total = $subtotal - $discount + $tax;
1700 1700
 
1701 1701
             // Do not allow totals to go negative
1702
-            if( $total < 0 ) {
1702
+            if ($total < 0) {
1703 1703
                 $total = 0;
1704 1704
             }
1705 1705
         
1706 1706
             $this->cart_details[] = array(
1707 1707
                 'name'          => !empty($args['name']) ? $args['name'] : $item->get_name(),
1708 1708
                 'id'            => $item->ID,
1709
-                'item_price'    => wpinv_round_amount( $item_price ),
1710
-                'custom_price'  => ( $args['custom_price'] !== '' ? wpinv_round_amount( $args['custom_price'] ) : '' ),
1709
+                'item_price'    => wpinv_round_amount($item_price),
1710
+                'custom_price'  => ($args['custom_price'] !== '' ? wpinv_round_amount($args['custom_price']) : ''),
1711 1711
                 'quantity'      => $args['quantity'],
1712 1712
                 'discount'      => $discount,
1713
-                'subtotal'      => wpinv_round_amount( $subtotal ),
1714
-                'tax'           => wpinv_round_amount( $tax ),
1715
-                'price'         => wpinv_round_amount( $total ),
1713
+                'subtotal'      => wpinv_round_amount($subtotal),
1714
+                'tax'           => wpinv_round_amount($tax),
1715
+                'price'         => wpinv_round_amount($total),
1716 1716
                 'vat_rate'      => $tax_rate,
1717 1717
                 'vat_class'     => $tax_class,
1718 1718
                 'meta'          => $args['meta'],
@@ -1722,18 +1722,18 @@  discard block
 block discarded – undo
1722 1722
             $subtotal = $subtotal - $discount;
1723 1723
         }
1724 1724
         
1725
-        $added_item = end( $this->cart_details );
1726
-        $added_item['action']  = 'add';
1725
+        $added_item = end($this->cart_details);
1726
+        $added_item['action'] = 'add';
1727 1727
         
1728 1728
         $this->pending['items'][] = $added_item;
1729 1729
         
1730
-        $this->increase_subtotal( $subtotal );
1731
-        $this->increase_tax( $tax );
1730
+        $this->increase_subtotal($subtotal);
1731
+        $this->increase_tax($tax);
1732 1732
 
1733 1733
         return true;
1734 1734
     }
1735 1735
     
1736
-    public function remove_item( $item_id, $args = array() ) {
1736
+    public function remove_item($item_id, $args = array()) {
1737 1737
         // Set some defaults
1738 1738
         $defaults = array(
1739 1739
             'quantity'      => 1,
@@ -1741,51 +1741,51 @@  discard block
 block discarded – undo
1741 1741
             'custom_price'  => '',
1742 1742
             'cart_index'    => false,
1743 1743
         );
1744
-        $args = wp_parse_args( $args, $defaults );
1744
+        $args = wp_parse_args($args, $defaults);
1745 1745
 
1746 1746
         // Bail if this post isn't a item
1747
-        if ( get_post_type( $item_id ) !== 'wpi_item' ) {
1747
+        if (get_post_type($item_id) !== 'wpi_item') {
1748 1748
             return false;
1749 1749
         }
1750 1750
         
1751
-        $this->cart_details = !empty( $this->cart_details ) ? array_values( $this->cart_details ) : $this->cart_details;
1751
+        $this->cart_details = !empty($this->cart_details) ? array_values($this->cart_details) : $this->cart_details;
1752 1752
 
1753
-        foreach ( $this->items as $key => $item ) {
1754
-            if ( !empty($item['id']) && (int)$item_id !== (int)$item['id'] ) {
1753
+        foreach ($this->items as $key => $item) {
1754
+            if (!empty($item['id']) && (int)$item_id !== (int)$item['id']) {
1755 1755
                 continue;
1756 1756
             }
1757 1757
 
1758
-            if ( false !== $args['cart_index'] ) {
1759
-                $cart_index = absint( $args['cart_index'] );
1760
-                $cart_item  = ! empty( $this->cart_details[ $cart_index ] ) ? $this->cart_details[ $cart_index ] : false;
1758
+            if (false !== $args['cart_index']) {
1759
+                $cart_index = absint($args['cart_index']);
1760
+                $cart_item  = !empty($this->cart_details[$cart_index]) ? $this->cart_details[$cart_index] : false;
1761 1761
 
1762
-                if ( ! empty( $cart_item ) ) {
1762
+                if (!empty($cart_item)) {
1763 1763
                     // If the cart index item isn't the same item ID, don't remove it
1764
-                    if ( !empty($cart_item['id']) && $cart_item['id'] != $item['id'] ) {
1764
+                    if (!empty($cart_item['id']) && $cart_item['id'] != $item['id']) {
1765 1765
                         continue;
1766 1766
                     }
1767 1767
                 }
1768 1768
             }
1769 1769
 
1770
-            $item_quantity = $this->items[ $key ]['quantity'];
1771
-            if ( $item_quantity > $args['quantity'] ) {
1772
-                $this->items[ $key ]['quantity'] -= $args['quantity'];
1770
+            $item_quantity = $this->items[$key]['quantity'];
1771
+            if ($item_quantity > $args['quantity']) {
1772
+                $this->items[$key]['quantity'] -= $args['quantity'];
1773 1773
                 break;
1774 1774
             } else {
1775
-                unset( $this->items[ $key ] );
1775
+                unset($this->items[$key]);
1776 1776
                 break;
1777 1777
             }
1778 1778
         }
1779 1779
 
1780 1780
         $found_cart_key = false;
1781
-        if ( false === $args['cart_index'] ) {
1782
-            foreach ( $this->cart_details as $cart_key => $item ) {
1783
-                if ( $item_id != $item['id'] ) {
1781
+        if (false === $args['cart_index']) {
1782
+            foreach ($this->cart_details as $cart_key => $item) {
1783
+                if ($item_id != $item['id']) {
1784 1784
                     continue;
1785 1785
                 }
1786 1786
 
1787
-                if ( false !== $args['item_price'] ) {
1788
-                    if ( isset( $item['item_price'] ) && (float) $args['item_price'] != (float) $item['item_price'] ) {
1787
+                if (false !== $args['item_price']) {
1788
+                    if (isset($item['item_price']) && (float)$args['item_price'] != (float)$item['item_price']) {
1789 1789
                         continue;
1790 1790
                     }
1791 1791
                 }
@@ -1794,13 +1794,13 @@  discard block
 block discarded – undo
1794 1794
                 break;
1795 1795
             }
1796 1796
         } else {
1797
-            $cart_index = absint( $args['cart_index'] );
1797
+            $cart_index = absint($args['cart_index']);
1798 1798
 
1799
-            if ( ! array_key_exists( $cart_index, $this->cart_details ) ) {
1799
+            if (!array_key_exists($cart_index, $this->cart_details)) {
1800 1800
                 return false; // Invalid cart index passed.
1801 1801
             }
1802 1802
 
1803
-            if ( (int) $this->cart_details[ $cart_index ]['id'] > 0 && (int) $this->cart_details[ $cart_index ]['id'] !== (int) $item_id ) {
1803
+            if ((int)$this->cart_details[$cart_index]['id'] > 0 && (int)$this->cart_details[$cart_index]['id'] !== (int)$item_id) {
1804 1804
                 return false; // We still need the proper Item ID to be sure.
1805 1805
             }
1806 1806
 
@@ -1808,41 +1808,41 @@  discard block
 block discarded – undo
1808 1808
         }
1809 1809
         
1810 1810
         $cart_item  = $this->cart_details[$found_cart_key];
1811
-        $quantity   = !empty( $cart_item['quantity'] ) ? $cart_item['quantity'] : 1;
1811
+        $quantity   = !empty($cart_item['quantity']) ? $cart_item['quantity'] : 1;
1812 1812
         
1813
-        if ( count( $this->cart_details ) == 1 && ( $quantity - $args['quantity'] ) < 1 ) {
1813
+        if (count($this->cart_details) == 1 && ($quantity - $args['quantity']) < 1) {
1814 1814
             return false; // Invoice must contain at least one item.
1815 1815
         }
1816 1816
         
1817
-        $discounts  = $this->get_discounts();
1817
+        $discounts = $this->get_discounts();
1818 1818
         
1819
-        if ( $quantity > $args['quantity'] ) {
1819
+        if ($quantity > $args['quantity']) {
1820 1820
             $item_price         = $cart_item['item_price'];
1821
-            $tax_rate           = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : 0;
1821
+            $tax_rate           = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : 0;
1822 1822
             
1823
-            $new_quantity       = max( $quantity - $args['quantity'], 1);
1823
+            $new_quantity       = max($quantity - $args['quantity'], 1);
1824 1824
             $subtotal           = $item_price * $new_quantity;
1825 1825
             
1826 1826
             $args['quantity']   = $new_quantity;
1827
-            $discount           = !empty( $cart_item['discount'] ) ? $cart_item['discount'] : 0;
1828
-            $tax                = $subtotal > 0 && $tax_rate > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0;
1827
+            $discount           = !empty($cart_item['discount']) ? $cart_item['discount'] : 0;
1828
+            $tax                = $subtotal > 0 && $tax_rate > 0 ? (($subtotal - $discount) * 0.01 * (float)$tax_rate) : 0;
1829 1829
             
1830
-            $discount_decrease  = (float)$cart_item['discount'] > 0 && $quantity > 0 ? wpinv_round_amount( ( (float)$cart_item['discount'] / $quantity ) ) : 0;
1830
+            $discount_decrease  = (float)$cart_item['discount'] > 0 && $quantity > 0 ? wpinv_round_amount(((float)$cart_item['discount'] / $quantity)) : 0;
1831 1831
             $discount_decrease  = $discount > 0 && $subtotal > 0 && (float)$cart_item['discount'] > $discount ? (float)$cart_item['discount'] - $discount : $discount_decrease; 
1832
-            $tax_decrease       = (float)$cart_item['tax'] > 0 && $quantity > 0 ? wpinv_round_amount( ( (float)$cart_item['tax'] / $quantity ) ) : 0;
1832
+            $tax_decrease       = (float)$cart_item['tax'] > 0 && $quantity > 0 ? wpinv_round_amount(((float)$cart_item['tax'] / $quantity)) : 0;
1833 1833
             $tax_decrease       = $tax > 0 && $subtotal > 0 && (float)$cart_item['tax'] > $tax ? (float)$cart_item['tax'] - $tax : $tax_decrease;
1834 1834
             
1835 1835
             // The total increase equals the number removed * the item_price
1836
-            $total_decrease     = wpinv_round_amount( $item_price );
1836
+            $total_decrease     = wpinv_round_amount($item_price);
1837 1837
             
1838
-            if ( wpinv_prices_include_tax() ) {
1839
-                $subtotal -= wpinv_round_amount( $tax );
1838
+            if (wpinv_prices_include_tax()) {
1839
+                $subtotal -= wpinv_round_amount($tax);
1840 1840
             }
1841 1841
 
1842
-            $total              = $subtotal - $discount + $tax;
1842
+            $total = $subtotal - $discount + $tax;
1843 1843
 
1844 1844
             // Do not allow totals to go negative
1845
-            if( $total < 0 ) {
1845
+            if ($total < 0) {
1846 1846
                 $total = 0;
1847 1847
             }
1848 1848
             
@@ -1861,16 +1861,16 @@  discard block
 block discarded – undo
1861 1861
             
1862 1862
             $this->cart_details[$found_cart_key] = $cart_item;
1863 1863
             
1864
-            $remove_item = end( $this->cart_details );
1864
+            $remove_item = end($this->cart_details);
1865 1865
         } else {
1866 1866
             $item_price     = $cart_item['item_price'];
1867
-            $discount       = !empty( $cart_item['discount'] ) ? $cart_item['discount'] : 0;
1868
-            $tax            = !empty( $cart_item['tax'] ) ? $cart_item['tax'] : 0;
1867
+            $discount       = !empty($cart_item['discount']) ? $cart_item['discount'] : 0;
1868
+            $tax            = !empty($cart_item['tax']) ? $cart_item['tax'] : 0;
1869 1869
         
1870
-            $subtotal_decrease  = ( $item_price * $quantity ) - $discount;
1870
+            $subtotal_decrease  = ($item_price * $quantity) - $discount;
1871 1871
             $tax_decrease       = $tax;
1872 1872
 
1873
-            unset( $this->cart_details[$found_cart_key] );
1873
+            unset($this->cart_details[$found_cart_key]);
1874 1874
             
1875 1875
             $remove_item             = $args;
1876 1876
             $remove_item['id']       = $item_id;
@@ -1881,8 +1881,8 @@  discard block
 block discarded – undo
1881 1881
         $remove_item['action']      = 'remove';
1882 1882
         $this->pending['items'][]   = $remove_item;
1883 1883
                
1884
-        $this->decrease_subtotal( $subtotal_decrease );
1885
-        $this->decrease_tax( $tax_decrease );
1884
+        $this->decrease_subtotal($subtotal_decrease);
1885
+        $this->decrease_tax($tax_decrease);
1886 1886
         
1887 1887
         return true;
1888 1888
     }
@@ -1890,7 +1890,7 @@  discard block
 block discarded – undo
1890 1890
     public function update_items($temp = false) {
1891 1891
         global $wpinv_euvat, $wpi_current_id, $wpi_item_id, $wpi_nosave;
1892 1892
         
1893
-        if ( !empty( $this->cart_details ) ) {
1893
+        if (!empty($this->cart_details)) {
1894 1894
             $wpi_nosave             = $temp;
1895 1895
             $cart_subtotal          = 0;
1896 1896
             $cart_discount          = 0;
@@ -1900,42 +1900,42 @@  discard block
 block discarded – undo
1900 1900
             $_POST['wpinv_country'] = $this->country;
1901 1901
             $_POST['wpinv_state']   = $this->state;
1902 1902
             
1903
-            foreach ( $this->cart_details as $key => $item ) {
1903
+            foreach ($this->cart_details as $key => $item) {
1904 1904
                 $item_price = $item['item_price'];
1905
-                $quantity   = wpinv_item_quantities_enabled() && $item['quantity'] > 0 ? absint( $item['quantity'] ) : 1;
1906
-                $amount     = wpinv_round_amount( $item_price * $quantity );
1905
+                $quantity   = wpinv_item_quantities_enabled() && $item['quantity'] > 0 ? absint($item['quantity']) : 1;
1906
+                $amount     = wpinv_round_amount($item_price * $quantity);
1907 1907
                 $subtotal   = $item_price * $quantity;
1908 1908
                 
1909 1909
                 $wpi_current_id         = $this->ID;
1910 1910
                 $wpi_item_id            = $item['id'];
1911 1911
                 
1912
-                $discount   = wpinv_get_cart_item_discount_amount( $item, $this->get_discounts() );
1912
+                $discount   = wpinv_get_cart_item_discount_amount($item, $this->get_discounts());
1913 1913
                 
1914
-                $tax_rate   = wpinv_get_tax_rate( $this->country, $this->state, $wpi_item_id );
1915
-                $tax_class  = $wpinv_euvat->get_item_class( $wpi_item_id );
1916
-                $tax        = $item_price > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0;
1914
+                $tax_rate   = wpinv_get_tax_rate($this->country, $this->state, $wpi_item_id);
1915
+                $tax_class  = $wpinv_euvat->get_item_class($wpi_item_id);
1916
+                $tax        = $item_price > 0 ? (($subtotal - $discount) * 0.01 * (float)$tax_rate) : 0;
1917 1917
 
1918
-                if ( wpinv_prices_include_tax() ) {
1919
-                    $subtotal -= wpinv_round_amount( $tax );
1918
+                if (wpinv_prices_include_tax()) {
1919
+                    $subtotal -= wpinv_round_amount($tax);
1920 1920
                 }
1921 1921
 
1922
-                $total      = $subtotal - $discount + $tax;
1922
+                $total = $subtotal - $discount + $tax;
1923 1923
 
1924 1924
                 // Do not allow totals to go negative
1925
-                if( $total < 0 ) {
1925
+                if ($total < 0) {
1926 1926
                     $total = 0;
1927 1927
                 }
1928 1928
 
1929 1929
                 $cart_details[] = array(
1930 1930
                     'id'          => $item['id'],
1931 1931
                     'name'        => $item['name'],
1932
-                    'item_price'  => wpinv_round_amount( $item_price ),
1933
-                    'custom_price'=> ( isset( $item['custom_price'] ) ? $item['custom_price'] : '' ),
1932
+                    'item_price'  => wpinv_round_amount($item_price),
1933
+                    'custom_price'=> (isset($item['custom_price']) ? $item['custom_price'] : ''),
1934 1934
                     'quantity'    => $quantity,
1935 1935
                     'discount'    => $discount,
1936
-                    'subtotal'    => wpinv_round_amount( $subtotal ),
1937
-                    'tax'         => wpinv_round_amount( $tax ),
1938
-                    'price'       => wpinv_round_amount( $total ),
1936
+                    'subtotal'    => wpinv_round_amount($subtotal),
1937
+                    'tax'         => wpinv_round_amount($tax),
1938
+                    'price'       => wpinv_round_amount($total),
1939 1939
                     'vat_rate'    => $tax_rate,
1940 1940
                     'vat_class'   => $tax_class,
1941 1941
                     'meta'        => isset($item['meta']) ? $item['meta'] : array(),
@@ -1946,9 +1946,9 @@  discard block
 block discarded – undo
1946 1946
                 $cart_discount  += (float)($discount);
1947 1947
                 $cart_tax       += (float)($tax);
1948 1948
             }
1949
-            $this->subtotal = wpinv_round_amount( $cart_subtotal );
1950
-            $this->tax      = wpinv_round_amount( $cart_tax );
1951
-            $this->discount = wpinv_round_amount( $cart_discount );
1949
+            $this->subtotal = wpinv_round_amount($cart_subtotal);
1950
+            $this->tax      = wpinv_round_amount($cart_tax);
1951
+            $this->discount = wpinv_round_amount($cart_discount);
1952 1952
             
1953 1953
             $this->recalculate_total();
1954 1954
             
@@ -1960,225 +1960,225 @@  discard block
 block discarded – undo
1960 1960
     
1961 1961
     public function recalculate_totals($temp = false) {        
1962 1962
         $this->update_items($temp);
1963
-        $this->save( true );
1963
+        $this->save(true);
1964 1964
         
1965 1965
         return $this;
1966 1966
     }
1967 1967
     
1968 1968
     public function needs_payment() {
1969
-        $valid_invoice_statuses = apply_filters( 'wpinv_valid_invoice_statuses_for_payment', array( 'wpi-pending' ), $this );
1969
+        $valid_invoice_statuses = apply_filters('wpinv_valid_invoice_statuses_for_payment', array('wpi-pending'), $this);
1970 1970
 
1971
-        if ( $this->has_status( $valid_invoice_statuses ) && ( $this->get_total() > 0 || $this->is_free_trial() || $this->is_free() ) ) {
1971
+        if ($this->has_status($valid_invoice_statuses) && ($this->get_total() > 0 || $this->is_free_trial() || $this->is_free())) {
1972 1972
             $needs_payment = true;
1973 1973
         } else {
1974 1974
             $needs_payment = false;
1975 1975
         }
1976 1976
 
1977
-        return apply_filters( 'wpinv_needs_payment', $needs_payment, $this, $valid_invoice_statuses );
1977
+        return apply_filters('wpinv_needs_payment', $needs_payment, $this, $valid_invoice_statuses);
1978 1978
     }
1979 1979
     
1980
-    public function get_checkout_payment_url( $with_key = false, $secret = false ) {
1980
+    public function get_checkout_payment_url($with_key = false, $secret = false) {
1981 1981
         $pay_url = wpinv_get_checkout_uri();
1982 1982
 
1983
-        if ( is_ssl() ) {
1984
-            $pay_url = str_replace( 'http:', 'https:', $pay_url );
1983
+        if (is_ssl()) {
1984
+            $pay_url = str_replace('http:', 'https:', $pay_url);
1985 1985
         }
1986 1986
         
1987 1987
         $key = $this->get_key();
1988 1988
 
1989
-        if ( $with_key ) {
1990
-            $pay_url = add_query_arg( 'invoice_key', $key, $pay_url );
1989
+        if ($with_key) {
1990
+            $pay_url = add_query_arg('invoice_key', $key, $pay_url);
1991 1991
         } else {
1992
-            $pay_url = add_query_arg( array( 'wpi_action' => 'pay_for_invoice', 'invoice_key' => $key ), $pay_url );
1992
+            $pay_url = add_query_arg(array('wpi_action' => 'pay_for_invoice', 'invoice_key' => $key), $pay_url);
1993 1993
         }
1994 1994
         
1995
-        if ( $secret ) {
1996
-            $pay_url = add_query_arg( array( '_wpipay' => md5( $this->get_user_id() . '::' . $this->get_email() . '::' . $key ) ), $pay_url );
1995
+        if ($secret) {
1996
+            $pay_url = add_query_arg(array('_wpipay' => md5($this->get_user_id() . '::' . $this->get_email() . '::' . $key)), $pay_url);
1997 1997
         }
1998 1998
 
1999
-        return apply_filters( 'wpinv_get_checkout_payment_url', $pay_url, $this, $with_key, $secret );
1999
+        return apply_filters('wpinv_get_checkout_payment_url', $pay_url, $this, $with_key, $secret);
2000 2000
     }
2001 2001
     
2002
-    public function get_view_url( $secret = false, $with_key = false ) {
2003
-        $print_url = get_permalink( $this->ID );
2002
+    public function get_view_url($secret = false, $with_key = false) {
2003
+        $print_url = get_permalink($this->ID);
2004 2004
         
2005
-        if ( $secret ) {
2006
-            $print_url = add_query_arg( array( '_wpipay' => md5( $this->get_user_id() . '::' . $this->get_email() . '::' . $this->get_key() ) ), $print_url );
2005
+        if ($secret) {
2006
+            $print_url = add_query_arg(array('_wpipay' => md5($this->get_user_id() . '::' . $this->get_email() . '::' . $this->get_key())), $print_url);
2007 2007
         }
2008 2008
         
2009
-        if ( $with_key ) {
2010
-            $print_url = add_query_arg( 'invoice_key', $this->get_key(), $print_url );
2009
+        if ($with_key) {
2010
+            $print_url = add_query_arg('invoice_key', $this->get_key(), $print_url);
2011 2011
         }
2012 2012
 
2013
-        return apply_filters( 'wpinv_get_view_url', $print_url, $this, $secret, $with_key );
2013
+        return apply_filters('wpinv_get_view_url', $print_url, $this, $secret, $with_key);
2014 2014
     }
2015 2015
     
2016
-    public function generate_key( $string = '' ) {
2017
-        $auth_key  = defined( 'AUTH_KEY' ) ? AUTH_KEY : '';
2018
-        return strtolower( md5( $string . date( 'Y-m-d H:i:s' ) . $auth_key . uniqid( 'wpinv', true ) ) );  // Unique key
2016
+    public function generate_key($string = '') {
2017
+        $auth_key = defined('AUTH_KEY') ? AUTH_KEY : '';
2018
+        return strtolower(md5($string . date('Y-m-d H:i:s') . $auth_key . uniqid('wpinv', true))); // Unique key
2019 2019
     }
2020 2020
     
2021 2021
     public function is_recurring() {
2022
-        if ( empty( $this->cart_details ) ) {
2022
+        if (empty($this->cart_details)) {
2023 2023
             return false;
2024 2024
         }
2025 2025
         
2026 2026
         $has_subscription = false;
2027
-        foreach( $this->cart_details as $cart_item ) {
2028
-            if ( !empty( $cart_item['id'] ) && wpinv_is_recurring_item( $cart_item['id'] )  ) {
2027
+        foreach ($this->cart_details as $cart_item) {
2028
+            if (!empty($cart_item['id']) && wpinv_is_recurring_item($cart_item['id'])) {
2029 2029
                 $has_subscription = true;
2030 2030
                 break;
2031 2031
             }
2032 2032
         }
2033 2033
         
2034
-        if ( count( $this->cart_details ) > 1 ) {
2034
+        if (count($this->cart_details) > 1) {
2035 2035
             $has_subscription = false;
2036 2036
         }
2037 2037
 
2038
-        return apply_filters( 'wpinv_invoice_has_recurring_item', $has_subscription, $this->cart_details );
2038
+        return apply_filters('wpinv_invoice_has_recurring_item', $has_subscription, $this->cart_details);
2039 2039
     }
2040 2040
     
2041 2041
     public function is_free_trial() {
2042 2042
         $is_free_trial = false;
2043 2043
         
2044
-        if ( $this->is_parent() && $item = $this->get_recurring( true ) ) {
2045
-            if ( !empty( $item ) && $item->has_free_trial() ) {
2044
+        if ($this->is_parent() && $item = $this->get_recurring(true)) {
2045
+            if (!empty($item) && $item->has_free_trial()) {
2046 2046
                 $is_free_trial = true;
2047 2047
             }
2048 2048
         }
2049 2049
 
2050
-        return apply_filters( 'wpinv_invoice_is_free_trial', $is_free_trial, $this->cart_details );
2050
+        return apply_filters('wpinv_invoice_is_free_trial', $is_free_trial, $this->cart_details);
2051 2051
     }
2052 2052
     
2053
-    public function get_recurring( $object = false ) {
2053
+    public function get_recurring($object = false) {
2054 2054
         $item = NULL;
2055 2055
         
2056
-        if ( empty( $this->cart_details ) ) {
2056
+        if (empty($this->cart_details)) {
2057 2057
             return $item;
2058 2058
         }
2059 2059
         
2060
-        foreach( $this->cart_details as $cart_item ) {
2061
-            if ( !empty( $cart_item['id'] ) && wpinv_is_recurring_item( $cart_item['id'] )  ) {
2060
+        foreach ($this->cart_details as $cart_item) {
2061
+            if (!empty($cart_item['id']) && wpinv_is_recurring_item($cart_item['id'])) {
2062 2062
                 $item = $cart_item['id'];
2063 2063
                 break;
2064 2064
             }
2065 2065
         }
2066 2066
         
2067
-        if ( $object ) {
2068
-            $item = $item ? new WPInv_Item( $item ) : NULL;
2067
+        if ($object) {
2068
+            $item = $item ? new WPInv_Item($item) : NULL;
2069 2069
             
2070
-            apply_filters( 'wpinv_invoice_get_recurring_item', $item, $this );
2070
+            apply_filters('wpinv_invoice_get_recurring_item', $item, $this);
2071 2071
         }
2072 2072
 
2073
-        return apply_filters( 'wpinv_invoice_get_recurring_item_id', $item, $this );
2073
+        return apply_filters('wpinv_invoice_get_recurring_item_id', $item, $this);
2074 2074
     }
2075 2075
     
2076 2076
     public function get_subscription_name() {
2077
-        $item = $this->get_recurring( true );
2077
+        $item = $this->get_recurring(true);
2078 2078
         
2079
-        if ( empty( $item ) ) {
2079
+        if (empty($item)) {
2080 2080
             return NULL;
2081 2081
         }
2082 2082
         
2083
-        if ( !($name = $item->get_name()) ) {
2083
+        if (!($name = $item->get_name())) {
2084 2084
             $name = $item->post_name;
2085 2085
         }
2086 2086
 
2087
-        return apply_filters( 'wpinv_invoice_get_subscription_name', $name, $this );
2087
+        return apply_filters('wpinv_invoice_get_subscription_name', $name, $this);
2088 2088
     }
2089 2089
         
2090 2090
     public function get_expiration() {
2091
-        $expiration = $this->get_meta( '_wpinv_subscr_expiration', true );
2091
+        $expiration = $this->get_meta('_wpinv_subscr_expiration', true);
2092 2092
         return $expiration;
2093 2093
     }
2094 2094
     
2095
-    public function get_cancelled_date( $formatted = true ) {
2096
-        $cancelled_date = $this->get_subscription_status() == 'cancelled' ? $this->get_meta( '_wpinv_subscr_cancelled_on', true ) : '';
2095
+    public function get_cancelled_date($formatted = true) {
2096
+        $cancelled_date = $this->get_subscription_status() == 'cancelled' ? $this->get_meta('_wpinv_subscr_cancelled_on', true) : '';
2097 2097
         
2098
-        if ( $formatted && $cancelled_date ) {
2099
-            $cancelled_date = date_i18n( get_option( 'date_format' ), strtotime( $cancelled_date ) );
2098
+        if ($formatted && $cancelled_date) {
2099
+            $cancelled_date = date_i18n(get_option('date_format'), strtotime($cancelled_date));
2100 2100
         }
2101 2101
         
2102 2102
         return $cancelled_date;
2103 2103
     }
2104 2104
     
2105
-    public function get_trial_end_date( $formatted = true ) {
2106
-        if ( !$this->is_free_trial() || !$this->is_paid() ) {
2105
+    public function get_trial_end_date($formatted = true) {
2106
+        if (!$this->is_free_trial() || !$this->is_paid()) {
2107 2107
             return NULL;
2108 2108
         }
2109 2109
         
2110
-        $trial_end_date = $this->get_subscription_status() == 'trialing' ? $this->get_meta( '_wpinv_subscr_trial_end', true ) : '';
2110
+        $trial_end_date = $this->get_subscription_status() == 'trialing' ? $this->get_meta('_wpinv_subscr_trial_end', true) : '';
2111 2111
         
2112
-        if ( empty( $trial_end_date ) ) {
2113
-            $trial_start_time = strtotime( $this->get_subscription_start() );
2114
-            $trial_start_time += ( wpinv_period_in_days( $this->get_subscription_trial_interval(), $this->get_subscription_trial_period() ) * DAY_IN_SECONDS ) ;
2112
+        if (empty($trial_end_date)) {
2113
+            $trial_start_time = strtotime($this->get_subscription_start());
2114
+            $trial_start_time += (wpinv_period_in_days($this->get_subscription_trial_interval(), $this->get_subscription_trial_period()) * DAY_IN_SECONDS);
2115 2115
             
2116
-            $trial_end_date = date_i18n( 'Y-m-d H:i:s', $trial_start_time );
2116
+            $trial_end_date = date_i18n('Y-m-d H:i:s', $trial_start_time);
2117 2117
         }
2118 2118
         
2119
-        if ( $formatted && $trial_end_date ) {
2120
-            $trial_end_date = date_i18n( get_option( 'date_format' ), strtotime( $trial_end_date ) );
2119
+        if ($formatted && $trial_end_date) {
2120
+            $trial_end_date = date_i18n(get_option('date_format'), strtotime($trial_end_date));
2121 2121
         }
2122 2122
         
2123 2123
         return $trial_end_date;
2124 2124
     }
2125 2125
     
2126
-    public function get_subscription_created( $default = true ) {
2127
-        $created = $this->get_meta( '_wpinv_subscr_created', true );
2126
+    public function get_subscription_created($default = true) {
2127
+        $created = $this->get_meta('_wpinv_subscr_created', true);
2128 2128
         
2129
-        if ( empty( $created ) && $default ) {
2129
+        if (empty($created) && $default) {
2130 2130
             $created = $this->date;
2131 2131
         }
2132 2132
         return $created;
2133 2133
     }
2134 2134
     
2135
-    public function get_subscription_start( $formatted = true ) {
2136
-        if ( !$this->is_paid() ) {
2135
+    public function get_subscription_start($formatted = true) {
2136
+        if (!$this->is_paid()) {
2137 2137
             return '-';
2138 2138
         }
2139
-        $start   = $this->get_subscription_created();
2139
+        $start = $this->get_subscription_created();
2140 2140
         
2141
-        if ( $formatted ) {
2142
-            $date = date_i18n( get_option( 'date_format' ), strtotime( $start ) );
2141
+        if ($formatted) {
2142
+            $date = date_i18n(get_option('date_format'), strtotime($start));
2143 2143
         } else {
2144
-            $date = date_i18n( 'Y-m-d H:i:s', strtotime( $start ) );
2144
+            $date = date_i18n('Y-m-d H:i:s', strtotime($start));
2145 2145
         }
2146 2146
 
2147 2147
         return $date;
2148 2148
     }
2149 2149
     
2150
-    public function get_subscription_end( $formatted = true ) {
2151
-        if ( !$this->is_paid() ) {
2150
+    public function get_subscription_end($formatted = true) {
2151
+        if (!$this->is_paid()) {
2152 2152
             return '-';
2153 2153
         }
2154 2154
         $start          = $this->get_subscription_created();
2155 2155
         $interval       = $this->get_subscription_interval();
2156
-        $period         = $this->get_subscription_period( true );
2156
+        $period         = $this->get_subscription_period(true);
2157 2157
         $bill_times     = (int)$this->get_bill_times();
2158 2158
         
2159
-        if ( $bill_times == 0 ) {
2160
-            return $formatted ? __( 'Until cancelled', 'invoicing' ) : $bill_times;
2159
+        if ($bill_times == 0) {
2160
+            return $formatted ? __('Until cancelled', 'invoicing') : $bill_times;
2161 2161
         }
2162 2162
         
2163
-        $total_period = $start . '+' . ( $interval * $bill_times ) . ' ' . $period;
2163
+        $total_period = $start . '+' . ($interval * $bill_times) . ' ' . $period;
2164 2164
         
2165
-        $end_time = strtotime( $start . '+' . ( $interval * $bill_times ) . ' ' . $period );
2165
+        $end_time = strtotime($start . '+' . ($interval * $bill_times) . ' ' . $period);
2166 2166
         
2167
-        if ( $this->is_free_trial() ) {
2168
-            $end_time += ( wpinv_period_in_days( $this->get_subscription_trial_interval(), $this->get_subscription_trial_period() ) * DAY_IN_SECONDS ) ;
2167
+        if ($this->is_free_trial()) {
2168
+            $end_time += (wpinv_period_in_days($this->get_subscription_trial_interval(), $this->get_subscription_trial_period()) * DAY_IN_SECONDS);
2169 2169
         }
2170 2170
         
2171
-        if ( $formatted ) {
2172
-            $date = date_i18n( get_option( 'date_format' ), $end_time );
2171
+        if ($formatted) {
2172
+            $date = date_i18n(get_option('date_format'), $end_time);
2173 2173
         } else {
2174
-            $date = date_i18n( 'Y-m-d H:i:s', $end_time );
2174
+            $date = date_i18n('Y-m-d H:i:s', $end_time);
2175 2175
         }
2176 2176
 
2177 2177
         return $date;
2178 2178
     }
2179 2179
     
2180 2180
     public function get_expiration_time() {
2181
-        return strtotime( $this->get_expiration(), current_time( 'timestamp' ) );
2181
+        return strtotime($this->get_expiration(), current_time('timestamp'));
2182 2182
     }
2183 2183
     
2184 2184
     public function get_original_invoice_id() {        
@@ -2190,125 +2190,125 @@  discard block
 block discarded – undo
2190 2190
         return $subscription_data['bill_times'];
2191 2191
     }
2192 2192
 
2193
-    public function get_child_payments( $self = false ) {
2194
-        $invoices = get_posts( array(
2193
+    public function get_child_payments($self = false) {
2194
+        $invoices = get_posts(array(
2195 2195
             'post_type'         => $this->post_type,
2196 2196
             'post_parent'       => (int)$this->ID,
2197 2197
             'posts_per_page'    => '999',
2198
-            'post_status'       => array( 'publish', 'wpi-processing', 'wpi-renewal' ),
2198
+            'post_status'       => array('publish', 'wpi-processing', 'wpi-renewal'),
2199 2199
             'orderby'           => 'ID',
2200 2200
             'order'             => 'DESC',
2201 2201
             'fields'            => 'ids'
2202
-        ) );
2202
+        ));
2203 2203
         
2204
-        if ( $this->is_free_trial() ) {
2204
+        if ($this->is_free_trial()) {
2205 2205
             $self = false;
2206 2206
         }
2207 2207
         
2208
-        if ( $self && $this->is_paid() ) {
2209
-            if ( !empty( $invoices ) ) {
2208
+        if ($self && $this->is_paid()) {
2209
+            if (!empty($invoices)) {
2210 2210
                 $invoices[] = (int)$this->ID;
2211 2211
             } else {
2212
-                $invoices = array( $this->ID );
2212
+                $invoices = array($this->ID);
2213 2213
             }
2214 2214
             
2215
-            $invoices = array_unique( $invoices );
2215
+            $invoices = array_unique($invoices);
2216 2216
         }
2217 2217
 
2218 2218
         return $invoices;
2219 2219
     }
2220 2220
 
2221
-    public function get_total_payments( $self = true ) {
2222
-        return count( $this->get_child_payments( $self ) );
2221
+    public function get_total_payments($self = true) {
2222
+        return count($this->get_child_payments($self));
2223 2223
     }
2224 2224
     
2225
-    public function get_subscriptions( $limit = -1 ) {
2226
-        $subscriptions = wpinv_get_subscriptions( array( 'parent_invoice_id' => $this->ID, 'numberposts' => $limit ) );
2225
+    public function get_subscriptions($limit = -1) {
2226
+        $subscriptions = wpinv_get_subscriptions(array('parent_invoice_id' => $this->ID, 'numberposts' => $limit));
2227 2227
 
2228 2228
         return $subscriptions;
2229 2229
     }
2230 2230
     
2231 2231
     public function get_subscription_id() {
2232
-        $subscription_id = $this->get_meta( '_wpinv_subscr_profile_id', true );
2232
+        $subscription_id = $this->get_meta('_wpinv_subscr_profile_id', true);
2233 2233
         
2234
-        if ( empty( $subscription_id ) && !empty( $this->parent_invoice ) ) {
2235
-            $parent_invoice = wpinv_get_invoice( $this->parent_invoice );
2234
+        if (empty($subscription_id) && !empty($this->parent_invoice)) {
2235
+            $parent_invoice = wpinv_get_invoice($this->parent_invoice);
2236 2236
             
2237
-            $subscription_id = $parent_invoice->get_meta( '_wpinv_subscr_profile_id', true );
2237
+            $subscription_id = $parent_invoice->get_meta('_wpinv_subscr_profile_id', true);
2238 2238
         }
2239 2239
         
2240 2240
         return $subscription_id;
2241 2241
     }
2242 2242
     
2243 2243
     public function get_subscription_status() {
2244
-        $subscription_status = $this->get_meta( '_wpinv_subscr_status', true );
2244
+        $subscription_status = $this->get_meta('_wpinv_subscr_status', true);
2245 2245
 
2246
-        if ( empty( $subscription_status ) ) {
2246
+        if (empty($subscription_status)) {
2247 2247
             $status = 'pending';
2248 2248
             
2249
-            if ( $this->is_paid() ) {        
2249
+            if ($this->is_paid()) {        
2250 2250
                 $bill_times   = (int)$this->get_bill_times();
2251 2251
                 $times_billed = (int)$this->get_total_payments();
2252
-                $expiration = $this->get_subscription_end( false );
2253
-                $expired = $bill_times != 0 && $expiration != '' && $expiration != '-' && strtotime( date_i18n( 'Y-m-d', strtotime( $expiration ) ) ) < strtotime( date_i18n( 'Y-m-d', current_time( 'timestamp' ) ) ) ? true : false;
2252
+                $expiration = $this->get_subscription_end(false);
2253
+                $expired = $bill_times != 0 && $expiration != '' && $expiration != '-' && strtotime(date_i18n('Y-m-d', strtotime($expiration))) < strtotime(date_i18n('Y-m-d', current_time('timestamp'))) ? true : false;
2254 2254
                 
2255
-                if ( (int)$bill_times == 0 ) {
2255
+                if ((int)$bill_times == 0) {
2256 2256
                     $status = $expired ? 'expired' : 'active';
2257
-                } else if ( $bill_times > 0 && $times_billed >= $bill_times ) {
2257
+                } else if ($bill_times > 0 && $times_billed >= $bill_times) {
2258 2258
                     $status = 'completed';
2259
-                } else if ( $expired ) {
2259
+                } else if ($expired) {
2260 2260
                     $status = 'expired';
2261
-                } else if ( $bill_times > 0 ) {
2261
+                } else if ($bill_times > 0) {
2262 2262
                     $status = 'active';
2263 2263
                 } else {
2264 2264
                     $status = 'pending';
2265 2265
                 }
2266 2266
             }
2267 2267
             
2268
-            if ( $status && $status != $subscription_status ) {
2268
+            if ($status && $status != $subscription_status) {
2269 2269
                 $subscription_status = $status;
2270 2270
                 
2271
-                $this->update_meta( '_wpinv_subscr_status', $status );
2271
+                $this->update_meta('_wpinv_subscr_status', $status);
2272 2272
             }
2273 2273
         }
2274 2274
         
2275 2275
         return $subscription_status;
2276 2276
     }
2277 2277
     
2278
-    public function get_subscription_status_label( $status = '' ) {
2279
-        $status = !empty( $status ) ? $status : $this->get_subscription_status();
2278
+    public function get_subscription_status_label($status = '') {
2279
+        $status = !empty($status) ? $status : $this->get_subscription_status();
2280 2280
 
2281
-        switch( $status ) {
2281
+        switch ($status) {
2282 2282
             case 'active' :
2283
-                $status_label = __( 'Active', 'invoicing' );
2283
+                $status_label = __('Active', 'invoicing');
2284 2284
                 break;
2285 2285
 
2286 2286
             case 'cancelled' :
2287
-                $status_label = __( 'Cancelled', 'invoicing' );
2287
+                $status_label = __('Cancelled', 'invoicing');
2288 2288
                 break;
2289 2289
                 
2290 2290
             case 'completed' :
2291
-                $status_label = __( 'Completed', 'invoicing' );
2291
+                $status_label = __('Completed', 'invoicing');
2292 2292
                 break;
2293 2293
 
2294 2294
             case 'expired' :
2295
-                $status_label = __( 'Expired', 'invoicing' );
2295
+                $status_label = __('Expired', 'invoicing');
2296 2296
                 break;
2297 2297
 
2298 2298
             case 'pending' :
2299
-                $status_label = __( 'Pending', 'invoicing' );
2299
+                $status_label = __('Pending', 'invoicing');
2300 2300
                 break;
2301 2301
 
2302 2302
             case 'failing' :
2303
-                $status_label = __( 'Failing', 'invoicing' );
2303
+                $status_label = __('Failing', 'invoicing');
2304 2304
                 break;
2305 2305
                 
2306 2306
             case 'stopped' :
2307
-                $status_label = __( 'Stopped', 'invoicing' );
2307
+                $status_label = __('Stopped', 'invoicing');
2308 2308
                 break;
2309 2309
                 
2310 2310
             case 'trialing' :
2311
-                $status_label = __( 'Trialing', 'invoicing' );
2311
+                $status_label = __('Trialing', 'invoicing');
2312 2312
                 break;
2313 2313
 
2314 2314
             default:
@@ -2319,26 +2319,26 @@  discard block
 block discarded – undo
2319 2319
         return $status_label;
2320 2320
     }
2321 2321
     
2322
-    public function get_subscription_period( $full = false ) {
2323
-        $period = $this->get_meta( '_wpinv_subscr_period', true );
2322
+    public function get_subscription_period($full = false) {
2323
+        $period = $this->get_meta('_wpinv_subscr_period', true);
2324 2324
         
2325 2325
         // Fix period for old invoices
2326
-        if ( $period == 'day' ) {
2326
+        if ($period == 'day') {
2327 2327
             $period = 'D';
2328
-        } else if ( $period == 'week' ) {
2328
+        } else if ($period == 'week') {
2329 2329
             $period = 'W';
2330
-        } else if ( $period == 'month' ) {
2330
+        } else if ($period == 'month') {
2331 2331
             $period = 'M';
2332
-        } else if ( $period == 'year' ) {
2332
+        } else if ($period == 'year') {
2333 2333
             $period = 'Y';
2334 2334
         }
2335 2335
         
2336
-        if ( !in_array( $period, array( 'D', 'W', 'M', 'Y' ) ) ) {
2336
+        if (!in_array($period, array('D', 'W', 'M', 'Y'))) {
2337 2337
             $period = 'D';
2338 2338
         }
2339 2339
         
2340
-        if ( $full ) {
2341
-            switch( $period ) {
2340
+        if ($full) {
2341
+            switch ($period) {
2342 2342
                 case 'D':
2343 2343
                     $period = 'day';
2344 2344
                 break;
@@ -2358,39 +2358,39 @@  discard block
 block discarded – undo
2358 2358
     }
2359 2359
     
2360 2360
     public function get_subscription_interval() {
2361
-        $interval = (int)$this->get_meta( '_wpinv_subscr_interval', true );
2361
+        $interval = (int)$this->get_meta('_wpinv_subscr_interval', true);
2362 2362
         
2363
-        if ( !$interval > 0 ) {
2363
+        if (!$interval > 0) {
2364 2364
             $interval = 1;
2365 2365
         }
2366 2366
         
2367 2367
         return $interval;
2368 2368
     }
2369 2369
     
2370
-    public function get_subscription_trial_period( $full = false ) {
2371
-        if ( !$this->is_free_trial() ) {
2370
+    public function get_subscription_trial_period($full = false) {
2371
+        if (!$this->is_free_trial()) {
2372 2372
             return '';
2373 2373
         }
2374 2374
         
2375
-        $period = $this->get_meta( '_wpinv_subscr_trial_period', true );
2375
+        $period = $this->get_meta('_wpinv_subscr_trial_period', true);
2376 2376
         
2377 2377
         // Fix period for old invoices
2378
-        if ( $period == 'day' ) {
2378
+        if ($period == 'day') {
2379 2379
             $period = 'D';
2380
-        } else if ( $period == 'week' ) {
2380
+        } else if ($period == 'week') {
2381 2381
             $period = 'W';
2382
-        } else if ( $period == 'month' ) {
2382
+        } else if ($period == 'month') {
2383 2383
             $period = 'M';
2384
-        } else if ( $period == 'year' ) {
2384
+        } else if ($period == 'year') {
2385 2385
             $period = 'Y';
2386 2386
         }
2387 2387
         
2388
-        if ( !in_array( $period, array( 'D', 'W', 'M', 'Y' ) ) ) {
2388
+        if (!in_array($period, array('D', 'W', 'M', 'Y'))) {
2389 2389
             $period = 'D';
2390 2390
         }
2391 2391
         
2392
-        if ( $full ) {
2393
-            switch( $period ) {
2392
+        if ($full) {
2393
+            switch ($period) {
2394 2394
                 case 'D':
2395 2395
                     $period = 'day';
2396 2396
                 break;
@@ -2410,13 +2410,13 @@  discard block
 block discarded – undo
2410 2410
     }
2411 2411
     
2412 2412
     public function get_subscription_trial_interval() {
2413
-        if ( !$this->is_free_trial() ) {
2413
+        if (!$this->is_free_trial()) {
2414 2414
             return 0;
2415 2415
         }
2416 2416
         
2417
-        $interval = (int)$this->get_meta( '_wpinv_subscr_trial_interval', true );
2417
+        $interval = (int)$this->get_meta('_wpinv_subscr_trial_interval', true);
2418 2418
         
2419
-        if ( !$interval > 0 ) {
2419
+        if (!$interval > 0) {
2420 2420
             $interval = 1;
2421 2421
         }
2422 2422
         
@@ -2428,8 +2428,8 @@  discard block
 block discarded – undo
2428 2428
             'status' => 'failing'
2429 2429
         );
2430 2430
 
2431
-        if ( $this->update_subscription( $args ) ) {
2432
-            do_action( 'wpinv_subscription_failing', $this->ID, $this );
2431
+        if ($this->update_subscription($args)) {
2432
+            do_action('wpinv_subscription_failing', $this->ID, $this);
2433 2433
             return true;
2434 2434
         }
2435 2435
 
@@ -2441,8 +2441,8 @@  discard block
 block discarded – undo
2441 2441
             'status' => 'stopped'
2442 2442
         );
2443 2443
 
2444
-        if ( $this->update_subscription( $args ) ) {
2445
-            do_action( 'wpinv_subscription_stopped', $this->ID, $this );
2444
+        if ($this->update_subscription($args)) {
2445
+            do_action('wpinv_subscription_stopped', $this->ID, $this);
2446 2446
             return true;
2447 2447
         }
2448 2448
 
@@ -2454,8 +2454,8 @@  discard block
 block discarded – undo
2454 2454
             'status' => 'active'
2455 2455
         );
2456 2456
 
2457
-        if ( $this->update_subscription( $args ) ) {
2458
-            do_action( 'wpinv_subscription_restarted', $this->ID, $this );
2457
+        if ($this->update_subscription($args)) {
2458
+            do_action('wpinv_subscription_restarted', $this->ID, $this);
2459 2459
             return true;
2460 2460
         }
2461 2461
 
@@ -2467,23 +2467,23 @@  discard block
 block discarded – undo
2467 2467
             'status' => 'cancelled'
2468 2468
         );
2469 2469
 
2470
-        if ( $this->update_subscription( $args ) ) {
2471
-            if ( is_user_logged_in() ) {
2472
-                $userdata = get_userdata( get_current_user_id() );
2470
+        if ($this->update_subscription($args)) {
2471
+            if (is_user_logged_in()) {
2472
+                $userdata = get_userdata(get_current_user_id());
2473 2473
                 $user     = $userdata->user_login;
2474 2474
             } else {
2475
-                $user = __( 'gateway', 'invoicing' );
2475
+                $user = __('gateway', 'invoicing');
2476 2476
             }
2477 2477
             
2478 2478
             $subscription_id = $this->get_subscription_id();
2479
-            if ( !$subscription_id ) {
2479
+            if (!$subscription_id) {
2480 2480
                 $subscription_id = $this->ID;
2481 2481
             }
2482 2482
 
2483
-            $note = sprintf( __( 'Subscription %s has been cancelled by %s', 'invoicing' ), $subscription_id, $user );
2484
-            $this->add_note( $note );
2483
+            $note = sprintf(__('Subscription %s has been cancelled by %s', 'invoicing'), $subscription_id, $user);
2484
+            $this->add_note($note);
2485 2485
 
2486
-            do_action( 'wpinv_subscription_cancelled', $this->ID, $this );
2486
+            do_action('wpinv_subscription_cancelled', $this->ID, $this);
2487 2487
             return true;
2488 2488
         }
2489 2489
 
@@ -2491,11 +2491,11 @@  discard block
 block discarded – undo
2491 2491
     }
2492 2492
 
2493 2493
     public function can_cancel() {
2494
-        return apply_filters( 'wpinv_subscription_can_cancel', false, $this );
2494
+        return apply_filters('wpinv_subscription_can_cancel', false, $this);
2495 2495
     }
2496 2496
     
2497
-    public function add_subscription( $data = array() ) {
2498
-        if ( empty( $this->ID ) ) {
2497
+    public function add_subscription($data = array()) {
2498
+        if (empty($this->ID)) {
2499 2499
             return false;
2500 2500
         }
2501 2501
 
@@ -2514,85 +2514,85 @@  discard block
 block discarded – undo
2514 2514
             'profile_id'        => '',
2515 2515
         );
2516 2516
 
2517
-        $args = wp_parse_args( $data, $defaults );
2517
+        $args = wp_parse_args($data, $defaults);
2518 2518
 
2519
-        if ( $args['expiration'] && strtotime( 'NOW', current_time( 'timestamp' ) ) > strtotime( $args['expiration'], current_time( 'timestamp' ) ) ) {
2520
-            if ( 'active' == $args['status'] || $args['status'] == 'trialing' ) {
2519
+        if ($args['expiration'] && strtotime('NOW', current_time('timestamp')) > strtotime($args['expiration'], current_time('timestamp'))) {
2520
+            if ('active' == $args['status'] || $args['status'] == 'trialing') {
2521 2521
                 $args['status'] = 'expired';
2522 2522
             }
2523 2523
         }
2524 2524
 
2525
-        do_action( 'wpinv_subscription_pre_create', $args, $data, $this );
2525
+        do_action('wpinv_subscription_pre_create', $args, $data, $this);
2526 2526
         
2527
-        if ( !empty( $args ) ) {
2528
-            foreach ( $args as $key => $value ) {
2529
-                $this->update_meta( '_wpinv_subscr_' . $key, $value );
2527
+        if (!empty($args)) {
2528
+            foreach ($args as $key => $value) {
2529
+                $this->update_meta('_wpinv_subscr_' . $key, $value);
2530 2530
             }
2531 2531
         }
2532 2532
 
2533
-        do_action( 'wpinv_subscription_post_create', $args, $data, $this );
2533
+        do_action('wpinv_subscription_post_create', $args, $data, $this);
2534 2534
 
2535 2535
         return true;
2536 2536
     }
2537 2537
     
2538
-    public function update_subscription( $args = array() ) {
2539
-        if ( empty( $this->ID ) ) {
2538
+    public function update_subscription($args = array()) {
2539
+        if (empty($this->ID)) {
2540 2540
             return false;
2541 2541
         }
2542 2542
 
2543
-        if ( !empty( $args['expiration'] ) && $args['expiration'] && strtotime( 'NOW', current_time( 'timestamp' ) ) > strtotime( $args['expiration'], current_time( 'timestamp' ) ) ) {
2544
-            if ( !isset( $args['status'] ) || ( isset( $args['status'] ) && ( 'active' == $args['status'] || $args['status'] == 'trialing' ) ) ) {
2543
+        if (!empty($args['expiration']) && $args['expiration'] && strtotime('NOW', current_time('timestamp')) > strtotime($args['expiration'], current_time('timestamp'))) {
2544
+            if (!isset($args['status']) || (isset($args['status']) && ('active' == $args['status'] || $args['status'] == 'trialing'))) {
2545 2545
                 $args['status'] = 'expired';
2546 2546
             }
2547 2547
         }
2548 2548
 
2549
-        if ( isset( $args['status'] ) && $args['status'] == 'cancelled' && empty( $args['cancelled_on'] ) ) {
2550
-            $args['cancelled_on'] = date_i18n( 'Y-m-d H:i:s', current_time( 'timestamp' ) );
2549
+        if (isset($args['status']) && $args['status'] == 'cancelled' && empty($args['cancelled_on'])) {
2550
+            $args['cancelled_on'] = date_i18n('Y-m-d H:i:s', current_time('timestamp'));
2551 2551
         }
2552 2552
 
2553
-        do_action( 'wpinv_subscription_pre_update', $args, $this );
2553
+        do_action('wpinv_subscription_pre_update', $args, $this);
2554 2554
         
2555
-        if ( !empty( $args ) ) {
2556
-            foreach ( $args as $key => $value ) {
2557
-                $this->update_meta( '_wpinv_subscr_' . $key, $value );
2555
+        if (!empty($args)) {
2556
+            foreach ($args as $key => $value) {
2557
+                $this->update_meta('_wpinv_subscr_' . $key, $value);
2558 2558
             }
2559 2559
         }
2560 2560
 
2561
-        do_action( 'wpinv_subscription_post_update', $args, $this );
2561
+        do_action('wpinv_subscription_post_update', $args, $this);
2562 2562
 
2563 2563
         return true;
2564 2564
     }
2565 2565
     
2566 2566
     public function renew_subscription() {
2567 2567
         $parent_invoice = $this->get_parent_payment();
2568
-        $parent_invoice = empty( $parent_invoice ) ? $this : $parent_invoice;
2568
+        $parent_invoice = empty($parent_invoice) ? $this : $parent_invoice;
2569 2569
         
2570
-        $current_time   = current_time( 'timestamp' );
2570
+        $current_time   = current_time('timestamp');
2571 2571
         $start          = $this->get_subscription_created();
2572
-        $start          = $start ? strtotime( $start ) : $current_time;
2572
+        $start          = $start ? strtotime($start) : $current_time;
2573 2573
         $expires        = $this->get_expiration_time();
2574 2574
         
2575
-        if ( !$expires ) {
2576
-            $expires    = strtotime( '+' . $parent_invoice->get_subscription_interval() . ' ' . $parent_invoice->get_subscription_period( true ), $start );
2575
+        if (!$expires) {
2576
+            $expires    = strtotime('+' . $parent_invoice->get_subscription_interval() . ' ' . $parent_invoice->get_subscription_period(true), $start);
2577 2577
         }
2578 2578
         
2579
-        $expiration     = date_i18n( 'Y-m-d 23:59:59', $expires );
2580
-        $expiration     = apply_filters( 'wpinv_subscription_renewal_expiration', $expiration, $this->ID, $this );
2579
+        $expiration     = date_i18n('Y-m-d 23:59:59', $expires);
2580
+        $expiration     = apply_filters('wpinv_subscription_renewal_expiration', $expiration, $this->ID, $this);
2581 2581
         $bill_times     = $parent_invoice->get_bill_times();
2582 2582
         $times_billed   = $parent_invoice->get_total_payments();
2583 2583
         
2584
-        if ( $parent_invoice->get_subscription_status() == 'trialing' && ( $times_billed > 0 || strtotime( date_i18n( 'Y-m-d' ) ) < strtotime( $parent_invoice->get_trial_end_date( false ) ) ) ) {
2584
+        if ($parent_invoice->get_subscription_status() == 'trialing' && ($times_billed > 0 || strtotime(date_i18n('Y-m-d')) < strtotime($parent_invoice->get_trial_end_date(false)))) {
2585 2585
             $args = array(
2586 2586
                 'status'     => 'active',
2587 2587
             );
2588 2588
 
2589
-            $parent_invoice->update_subscription( $args );
2589
+            $parent_invoice->update_subscription($args);
2590 2590
         }
2591 2591
         
2592
-        do_action( 'wpinv_subscription_pre_renew', $this->ID, $expiration, $this );
2592
+        do_action('wpinv_subscription_pre_renew', $this->ID, $expiration, $this);
2593 2593
 
2594
-        $status       = 'active';
2595
-        if ( $bill_times > 0 && $times_billed >= $bill_times ) {
2594
+        $status = 'active';
2595
+        if ($bill_times > 0 && $times_billed >= $bill_times) {
2596 2596
             $this->complete_subscription();
2597 2597
             $status = 'completed';
2598 2598
         }
@@ -2602,10 +2602,10 @@  discard block
 block discarded – undo
2602 2602
             'status'     => $status,
2603 2603
         );
2604 2604
 
2605
-        $this->update_subscription( $args );
2605
+        $this->update_subscription($args);
2606 2606
 
2607
-        do_action( 'wpinv_subscription_post_renew', $this->ID, $expiration, $this );
2608
-        do_action( 'wpinv_recurring_set_subscription_status', $this->ID, $status, $this );
2607
+        do_action('wpinv_subscription_post_renew', $this->ID, $expiration, $this);
2608
+        do_action('wpinv_recurring_set_subscription_status', $this->ID, $status, $this);
2609 2609
     }
2610 2610
     
2611 2611
     public function complete_subscription() {
@@ -2613,8 +2613,8 @@  discard block
 block discarded – undo
2613 2613
             'status' => 'completed'
2614 2614
         );
2615 2615
 
2616
-        if ( $this->update_subscription( $args ) ) {
2617
-            do_action( 'wpinv_subscription_completed', $this->ID, $this );
2616
+        if ($this->update_subscription($args)) {
2617
+            do_action('wpinv_subscription_completed', $this->ID, $this);
2618 2618
         }
2619 2619
     }
2620 2620
     
@@ -2623,44 +2623,44 @@  discard block
 block discarded – undo
2623 2623
             'status' => 'expired'
2624 2624
         );
2625 2625
 
2626
-        if ( $this->update_subscription( $args ) ) {
2627
-            do_action( 'wpinv_subscription_expired', $this->ID, $this );
2626
+        if ($this->update_subscription($args)) {
2627
+            do_action('wpinv_subscription_expired', $this->ID, $this);
2628 2628
         }
2629 2629
     }
2630 2630
 
2631 2631
     public function get_cancel_url() {
2632
-        $url = wp_nonce_url( add_query_arg( array( 'wpi_action' => 'cancel_subscription', 'sub_id' => $this->ID ) ), 'wpinv-recurring-cancel' );
2632
+        $url = wp_nonce_url(add_query_arg(array('wpi_action' => 'cancel_subscription', 'sub_id' => $this->ID)), 'wpinv-recurring-cancel');
2633 2633
 
2634
-        return apply_filters( 'wpinv_subscription_cancel_url', $url, $this );
2634
+        return apply_filters('wpinv_subscription_cancel_url', $url, $this);
2635 2635
     }
2636 2636
 
2637 2637
     public function can_update() {
2638
-        return apply_filters( 'wpinv_subscription_can_update', false, $this );
2638
+        return apply_filters('wpinv_subscription_can_update', false, $this);
2639 2639
     }
2640 2640
 
2641 2641
     public function get_update_url() {
2642
-        $url = add_query_arg( array( 'action' => 'update', 'sub_id' => $this->ID ) );
2642
+        $url = add_query_arg(array('action' => 'update', 'sub_id' => $this->ID));
2643 2643
 
2644
-        return apply_filters( 'wpinv_subscription_update_url', $url, $this );
2644
+        return apply_filters('wpinv_subscription_update_url', $url, $this);
2645 2645
     }
2646 2646
 
2647 2647
     public function is_parent() {
2648
-        $is_parent = empty( $this->parent_invoice ) ? true : false;
2648
+        $is_parent = empty($this->parent_invoice) ? true : false;
2649 2649
 
2650
-        return apply_filters( 'wpinv_invoice_is_parent', $is_parent, $this );
2650
+        return apply_filters('wpinv_invoice_is_parent', $is_parent, $this);
2651 2651
     }
2652 2652
     
2653 2653
     public function is_renewal() {
2654 2654
         $is_renewal = $this->parent_invoice && $this->parent_invoice != $this->ID ? true : false;
2655 2655
 
2656
-        return apply_filters( 'wpinv_invoice_is_renewal', $is_renewal, $this );
2656
+        return apply_filters('wpinv_invoice_is_renewal', $is_renewal, $this);
2657 2657
     }
2658 2658
     
2659 2659
     public function get_parent_payment() {
2660 2660
         $parent_payment = NULL;
2661 2661
         
2662
-        if ( $this->is_renewal() ) {
2663
-            $parent_payment = wpinv_get_invoice( $this->parent_invoice );
2662
+        if ($this->is_renewal()) {
2663
+            $parent_payment = wpinv_get_invoice($this->parent_invoice);
2664 2664
         }
2665 2665
         
2666 2666
         return $parent_payment;
@@ -2671,100 +2671,100 @@  discard block
 block discarded – undo
2671 2671
         
2672 2672
         $subscription_status = $this->get_subscription_status();
2673 2673
 
2674
-        if( ! $this->is_subscription_expired() && ( $subscription_status == 'active' || $subscription_status == 'cancelled' || $subscription_status == 'trialing' ) ) {
2674
+        if (!$this->is_subscription_expired() && ($subscription_status == 'active' || $subscription_status == 'cancelled' || $subscription_status == 'trialing')) {
2675 2675
             $ret = true;
2676 2676
         }
2677 2677
 
2678
-        return apply_filters( 'wpinv_subscription_is_active', $ret, $this->ID, $this );
2678
+        return apply_filters('wpinv_subscription_is_active', $ret, $this->ID, $this);
2679 2679
     }
2680 2680
 
2681 2681
     public function is_subscription_expired() {
2682 2682
         $ret = false;
2683 2683
         $subscription_status = $this->get_subscription_status();
2684 2684
 
2685
-        if ( $subscription_status == 'expired' ) {
2685
+        if ($subscription_status == 'expired') {
2686 2686
             $ret = true;
2687
-        } else if ( 'active' === $subscription_status || 'cancelled' === $subscription_status || 'trialing' == $subscription_status ) {
2687
+        } else if ('active' === $subscription_status || 'cancelled' === $subscription_status || 'trialing' == $subscription_status) {
2688 2688
             $ret        = false;
2689 2689
             $expiration = $this->get_expiration_time();
2690 2690
 
2691
-            if ( $expiration && strtotime( 'NOW', current_time( 'timestamp' ) ) > $expiration ) {
2691
+            if ($expiration && strtotime('NOW', current_time('timestamp')) > $expiration) {
2692 2692
                 $ret = true;
2693 2693
 
2694
-                if ( 'active' === $subscription_status || 'trialing' === $subscription_status ) {
2694
+                if ('active' === $subscription_status || 'trialing' === $subscription_status) {
2695 2695
                     $this->expire_subscription();
2696 2696
                 }
2697 2697
             }
2698 2698
         }
2699 2699
 
2700
-        return apply_filters( 'wpinv_subscription_is_expired', $ret, $this->ID, $this );
2700
+        return apply_filters('wpinv_subscription_is_expired', $ret, $this->ID, $this);
2701 2701
     }
2702 2702
     
2703
-    public function get_new_expiration( $item_id = 0, $trial = true ) {
2704
-        $item   = new WPInv_Item( $item_id );
2703
+    public function get_new_expiration($item_id = 0, $trial = true) {
2704
+        $item   = new WPInv_Item($item_id);
2705 2705
         $interval = $item->get_recurring_interval();
2706
-        $period = $item->get_recurring_period( true );
2706
+        $period = $item->get_recurring_period(true);
2707 2707
         
2708
-        $expiration_time = strtotime( '+' . $interval . ' ' . $period );
2708
+        $expiration_time = strtotime('+' . $interval . ' ' . $period);
2709 2709
         
2710
-        if ( $trial && $this->is_free_trial() && $item->has_free_trial() ) {
2711
-            $expiration_time += ( wpinv_period_in_days( $item->get_trial_interval(), $item->get_trial_period() ) * DAY_IN_SECONDS ) ;
2710
+        if ($trial && $this->is_free_trial() && $item->has_free_trial()) {
2711
+            $expiration_time += (wpinv_period_in_days($item->get_trial_interval(), $item->get_trial_period()) * DAY_IN_SECONDS);
2712 2712
         }
2713 2713
 
2714
-        return date_i18n( 'Y-m-d 23:59:59', $expiration_time );
2714
+        return date_i18n('Y-m-d 23:59:59', $expiration_time);
2715 2715
     }
2716 2716
     
2717
-    public function get_subscription_data( $filed = '' ) {
2718
-        $fields = array( 'item_id', 'status', 'period', 'initial_amount', 'recurring_amount', 'interval', 'bill_times', 'trial_period', 'trial_interval', 'expiration', 'profile_id', 'created', 'cancelled_on' );
2717
+    public function get_subscription_data($filed = '') {
2718
+        $fields = array('item_id', 'status', 'period', 'initial_amount', 'recurring_amount', 'interval', 'bill_times', 'trial_period', 'trial_interval', 'expiration', 'profile_id', 'created', 'cancelled_on');
2719 2719
         
2720 2720
         $subscription_meta = array();
2721
-        foreach ( $fields as $field ) {
2722
-            $subscription_meta[ $field ] = $this->get_meta( '_wpinv_subscr_' . $field );
2721
+        foreach ($fields as $field) {
2722
+            $subscription_meta[$field] = $this->get_meta('_wpinv_subscr_' . $field);
2723 2723
         }
2724 2724
         
2725
-        $item = $this->get_recurring( true );
2725
+        $item = $this->get_recurring(true);
2726 2726
         
2727
-        if ( !empty( $item ) ) {
2728
-            if ( empty( $subscription_meta['item_id'] ) ) {
2727
+        if (!empty($item)) {
2728
+            if (empty($subscription_meta['item_id'])) {
2729 2729
                 $subscription_meta['item_id'] = $item->ID;
2730 2730
             }
2731
-            if ( empty( $subscription_meta['period'] ) ) {
2731
+            if (empty($subscription_meta['period'])) {
2732 2732
                 $subscription_meta['period'] = $item->get_recurring_period();
2733 2733
             }
2734
-            if ( empty( $subscription_meta['interval'] ) ) {
2734
+            if (empty($subscription_meta['interval'])) {
2735 2735
                 $subscription_meta['interval'] = $item->get_recurring_interval();
2736 2736
             }
2737
-            if ( $item->has_free_trial() ) {
2738
-                if ( empty( $subscription_meta['trial_period'] ) ) {
2737
+            if ($item->has_free_trial()) {
2738
+                if (empty($subscription_meta['trial_period'])) {
2739 2739
                     $subscription_meta['trial_period'] = $item->get_trial_period();
2740 2740
                 }
2741
-                if ( empty( $subscription_meta['trial_interval'] ) ) {
2741
+                if (empty($subscription_meta['trial_interval'])) {
2742 2742
                     $subscription_meta['trial_interval'] = $item->get_trial_interval();
2743 2743
                 }
2744 2744
             } else {
2745 2745
                 $subscription_meta['trial_period']      = '';
2746 2746
                 $subscription_meta['trial_interval']    = 0;
2747 2747
             }
2748
-            if ( !$subscription_meta['bill_times'] && $subscription_meta['bill_times'] !== 0 ) {
2748
+            if (!$subscription_meta['bill_times'] && $subscription_meta['bill_times'] !== 0) {
2749 2749
                 $subscription_meta['bill_times'] = $item->get_recurring_limit();
2750 2750
             }
2751
-            if ( $subscription_meta['initial_amount'] === '' || $subscription_meta['recurring_amount'] === '' ) {
2752
-                $subscription_meta['initial_amount']    = wpinv_round_amount( $this->get_total() );
2753
-                $subscription_meta['recurring_amount']  = wpinv_round_amount( $this->get_recurring_details( 'total' ) );
2751
+            if ($subscription_meta['initial_amount'] === '' || $subscription_meta['recurring_amount'] === '') {
2752
+                $subscription_meta['initial_amount']    = wpinv_round_amount($this->get_total());
2753
+                $subscription_meta['recurring_amount']  = wpinv_round_amount($this->get_recurring_details('total'));
2754 2754
             }
2755 2755
         }
2756 2756
         
2757
-        if ( $filed === '' ) {
2758
-            return apply_filters( 'wpinv_get_invoice_subscription_data', $subscription_meta, $this );
2757
+        if ($filed === '') {
2758
+            return apply_filters('wpinv_get_invoice_subscription_data', $subscription_meta, $this);
2759 2759
         }
2760 2760
         
2761
-        $value = isset( $subscription_meta[$filed] ) ? $subscription_meta[$filed] : '';
2761
+        $value = isset($subscription_meta[$filed]) ? $subscription_meta[$filed] : '';
2762 2762
         
2763
-        return apply_filters( 'wpinv_invoice_subscription_data_value', $value, $subscription_meta, $this );
2763
+        return apply_filters('wpinv_invoice_subscription_data_value', $value, $subscription_meta, $this);
2764 2764
     }
2765 2765
     
2766 2766
     public function is_paid() {
2767
-        if ( $this->has_status( array( 'publish', 'wpi-processing', 'wpi-renewal' ) ) ) {
2767
+        if ($this->has_status(array('publish', 'wpi-processing', 'wpi-renewal'))) {
2768 2768
             return true;
2769 2769
         }
2770 2770
         
@@ -2772,23 +2772,23 @@  discard block
 block discarded – undo
2772 2772
     }
2773 2773
     
2774 2774
     public function is_refunded() {
2775
-        $is_refunded = $this->has_status( array( 'wpi-refunded' ) );
2775
+        $is_refunded = $this->has_status(array('wpi-refunded'));
2776 2776
 
2777
-        return apply_filters( 'wpinv_invoice_is_refunded', $is_refunded, $this );
2777
+        return apply_filters('wpinv_invoice_is_refunded', $is_refunded, $this);
2778 2778
     }
2779 2779
     
2780 2780
     public function is_free() {
2781 2781
         $is_free = false;
2782 2782
         
2783
-        if ( !( (float)wpinv_round_amount( $this->get_total() ) > 0 ) ) {
2784
-            if ( $this->is_parent() && $this->is_recurring() ) {
2785
-                $is_free = (float)wpinv_round_amount( $this->get_recurring_details( 'total' ) ) > 0 ? false : true;
2783
+        if (!((float)wpinv_round_amount($this->get_total()) > 0)) {
2784
+            if ($this->is_parent() && $this->is_recurring()) {
2785
+                $is_free = (float)wpinv_round_amount($this->get_recurring_details('total')) > 0 ? false : true;
2786 2786
             } else {
2787 2787
                 $is_free = true;
2788 2788
             }
2789 2789
         }
2790 2790
         
2791
-        return apply_filters( 'wpinv_invoice_is_free', $is_free, $this );
2791
+        return apply_filters('wpinv_invoice_is_free', $is_free, $this);
2792 2792
     }
2793 2793
     
2794 2794
     public function has_vat() {
@@ -2796,41 +2796,41 @@  discard block
 block discarded – undo
2796 2796
         
2797 2797
         $requires_vat = false;
2798 2798
         
2799
-        if ( $this->country ) {
2799
+        if ($this->country) {
2800 2800
             $wpi_country        = $this->country;
2801 2801
             
2802
-            $requires_vat       = $wpinv_euvat->requires_vat( $requires_vat, $this->get_user_id(), $wpinv_euvat->invoice_has_digital_rule( $this ) );
2802
+            $requires_vat       = $wpinv_euvat->requires_vat($requires_vat, $this->get_user_id(), $wpinv_euvat->invoice_has_digital_rule($this));
2803 2803
         }
2804 2804
         
2805
-        return apply_filters( 'wpinv_invoice_has_vat', $requires_vat, $this );
2805
+        return apply_filters('wpinv_invoice_has_vat', $requires_vat, $this);
2806 2806
     }
2807 2807
     
2808 2808
     public function refresh_item_ids() {
2809 2809
         $item_ids = array();
2810 2810
         
2811
-        if ( !empty( $this->cart_details ) ) {
2812
-            foreach ( $this->cart_details as $key => $item ) {
2813
-                if ( !empty( $item['id'] ) ) {
2811
+        if (!empty($this->cart_details)) {
2812
+            foreach ($this->cart_details as $key => $item) {
2813
+                if (!empty($item['id'])) {
2814 2814
                     $item_ids[] = $item['id'];
2815 2815
                 }
2816 2816
             }
2817 2817
         }
2818 2818
         
2819
-        $item_ids = !empty( $item_ids ) ? implode( ',', array_unique( $item_ids ) ) : '';
2819
+        $item_ids = !empty($item_ids) ? implode(',', array_unique($item_ids)) : '';
2820 2820
         
2821
-        update_post_meta( $this->ID, '_wpinv_item_ids', $item_ids );
2821
+        update_post_meta($this->ID, '_wpinv_item_ids', $item_ids);
2822 2822
     }
2823 2823
     
2824
-    public function get_invoice_quote_type( $post_id ) {
2825
-        if ( empty( $post_id ) ) {
2824
+    public function get_invoice_quote_type($post_id) {
2825
+        if (empty($post_id)) {
2826 2826
             return '';
2827 2827
         }
2828 2828
 
2829
-        $type = get_post_type( $post_id );
2829
+        $type = get_post_type($post_id);
2830 2830
 
2831
-        if ( 'wpi_invoice' === $type ) {
2831
+        if ('wpi_invoice' === $type) {
2832 2832
             $post_type = __('Invoice', 'invoicing');
2833
-        } else{
2833
+        } else {
2834 2834
             $post_type = __('Quote', 'invoicing');
2835 2835
         }
2836 2836
 
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,187 +83,187 @@  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' );
223
+        wp_enqueue_script('jquery-blockui');
224 224
         $autofill_api = wpinv_get_option('address_autofill_api');
225 225
         $autofill_active = wpinv_get_option('address_autofill_active');
226 226
         if (isset($autofill_active) && 1 == $autofill_active && !empty($autofill_api) && wpinv_is_checkout()) {
227 227
             wp_enqueue_script('google-maps-api', 'https://maps.googleapis.com/maps/api/js?key=' . $autofill_api . '&libraries=places', array('jquery'), '', false);
228 228
             wp_enqueue_script('google-maps-init', WPINV_PLUGIN_URL . 'assets/js/gaaf.js', array('jquery'), '', true);
229 229
         }
230
-        wp_enqueue_script( 'wpinv-front-script' );
231
-        wp_localize_script( 'wpinv-front-script', 'WPInv', $localize );
230
+        wp_enqueue_script('wpinv-front-script');
231
+        wp_localize_script('wpinv-front-script', 'WPInv', $localize);
232 232
     }
233 233
     
234 234
     public function admin_enqueue_scripts() {
235 235
         global $post, $pagenow;
236 236
         
237 237
         $post_type  = wpinv_admin_post_type();
238
-        $suffix     = '';//defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
238
+        $suffix     = ''; //defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
239 239
         
240
-        wp_deregister_style( 'font-awesome' );
241
-        wp_register_style( 'font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome' . $suffix . '.css', array(), '4.7.0' );
242
-        wp_enqueue_style( 'font-awesome' );
240
+        wp_deregister_style('font-awesome');
241
+        wp_register_style('font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome' . $suffix . '.css', array(), '4.7.0');
242
+        wp_enqueue_style('font-awesome');
243 243
         
244
-        wp_register_style( 'jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui' . $suffix . '.css', array(), '1.8.16' );
245
-        wp_enqueue_style( 'jquery-ui-css' );
244
+        wp_register_style('jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui' . $suffix . '.css', array(), '1.8.16');
245
+        wp_enqueue_style('jquery-ui-css');
246 246
         
247
-        wp_register_style( 'jquery-chosen', WPINV_PLUGIN_URL . 'assets/css/chosen' . $suffix . '.css', array(), '1.6.2' );
248
-        wp_enqueue_style( 'jquery-chosen' );
247
+        wp_register_style('jquery-chosen', WPINV_PLUGIN_URL . 'assets/css/chosen' . $suffix . '.css', array(), '1.6.2');
248
+        wp_enqueue_style('jquery-chosen');
249 249
 
250
-        wp_register_script( 'jquery-chosen', WPINV_PLUGIN_URL . 'assets/js/chosen.jquery' . $suffix . '.js', array( 'jquery' ), '1.6.2' );
251
-        wp_enqueue_script( 'jquery-chosen' );
250
+        wp_register_script('jquery-chosen', WPINV_PLUGIN_URL . 'assets/js/chosen.jquery' . $suffix . '.js', array('jquery'), '1.6.2');
251
+        wp_enqueue_script('jquery-chosen');
252 252
         
253
-        wp_register_style( 'wpinv_meta_box_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION );
254
-        wp_enqueue_style( 'wpinv_meta_box_style' );
253
+        wp_register_style('wpinv_meta_box_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION);
254
+        wp_enqueue_style('wpinv_meta_box_style');
255 255
         
256
-        wp_register_style( 'wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array(), WPINV_VERSION );
257
-        wp_enqueue_style( 'wpinv_admin_style' );
256
+        wp_register_style('wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array(), WPINV_VERSION);
257
+        wp_enqueue_style('wpinv_admin_style');
258 258
         
259
-        if ( $post_type == 'wpi_discount' || $post_type == 'wpi_invoice' && ( $pagenow == 'post-new.php' || $pagenow == 'post.php' ) ) {
260
-            wp_enqueue_script( 'jquery-ui-datepicker' );
259
+        if ($post_type == 'wpi_discount' || $post_type == 'wpi_invoice' && ($pagenow == 'post-new.php' || $pagenow == 'post.php')) {
260
+            wp_enqueue_script('jquery-ui-datepicker');
261 261
         }
262 262
 
263
-        wp_enqueue_style( 'wp-color-picker' );
264
-        wp_enqueue_script( 'wp-color-picker' );
263
+        wp_enqueue_style('wp-color-picker');
264
+        wp_enqueue_script('wp-color-picker');
265 265
         
266
-        wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true );
266
+        wp_register_script('jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array('jquery'), '2.70', true);
267 267
 
268 268
         if ($post_type == 'wpi_invoice' || $post_type == 'wpi_quote' && ($pagenow == 'post-new.php' || $pagenow == 'post.php')) {
269 269
             $autofill_api = wpinv_get_option('address_autofill_api');
@@ -274,17 +274,17 @@  discard block
 block discarded – undo
274 274
             }
275 275
         }
276 276
 
277
-        wp_register_script( 'wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin' . $suffix . '.js', array( 'jquery', 'jquery-blockui','jquery-ui-tooltip' ),  WPINV_VERSION );
278
-        wp_enqueue_script( 'wpinv-admin-script' );
277
+        wp_register_script('wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin' . $suffix . '.js', array('jquery', 'jquery-blockui', 'jquery-ui-tooltip'), WPINV_VERSION);
278
+        wp_enqueue_script('wpinv-admin-script');
279 279
         
280 280
         $localize                               = array();
281
-        $localize['ajax_url']                   = admin_url( 'admin-ajax.php' );
282
-        $localize['post_ID']                    = isset( $post->ID ) ? $post->ID : '';
283
-        $localize['wpinv_nonce']                = wp_create_nonce( 'wpinv-nonce' );
284
-        $localize['add_invoice_note_nonce']     = wp_create_nonce( 'add-invoice-note' );
285
-        $localize['delete_invoice_note_nonce']  = wp_create_nonce( 'delete-invoice-note' );
286
-        $localize['invoice_item_nonce']         = wp_create_nonce( 'invoice-item' );
287
-        $localize['billing_details_nonce']      = wp_create_nonce( 'get-billing-details' );
281
+        $localize['ajax_url']                   = admin_url('admin-ajax.php');
282
+        $localize['post_ID']                    = isset($post->ID) ? $post->ID : '';
283
+        $localize['wpinv_nonce']                = wp_create_nonce('wpinv-nonce');
284
+        $localize['add_invoice_note_nonce']     = wp_create_nonce('add-invoice-note');
285
+        $localize['delete_invoice_note_nonce']  = wp_create_nonce('delete-invoice-note');
286
+        $localize['invoice_item_nonce']         = wp_create_nonce('invoice-item');
287
+        $localize['billing_details_nonce']      = wp_create_nonce('get-billing-details');
288 288
         $localize['tax']                        = wpinv_tax_amount();
289 289
         $localize['discount']                   = wpinv_discount_amount();
290 290
         $localize['currency_symbol']            = wpinv_currency_symbol();
@@ -292,65 +292,65 @@  discard block
 block discarded – undo
292 292
         $localize['thousand_sep']               = wpinv_thousands_separator();
293 293
         $localize['decimal_sep']                = wpinv_decimal_separator();
294 294
         $localize['decimals']                   = wpinv_decimals();
295
-        $localize['save_invoice']               = __( 'Save Invoice', 'invoicing' );
296
-        $localize['status_publish']             = wpinv_status_nicename( 'publish' );
297
-        $localize['status_pending']             = wpinv_status_nicename( 'wpi-pending' );
298
-        $localize['delete_tax_rate']            = __( 'Are you sure you wish to delete this tax rate?', 'invoicing' );
299
-        $localize['OneItemMin']                 = __( 'Invoice must contain at least one item', 'invoicing' );
300
-        $localize['DeleteInvoiceItem']          = __( 'Are you sure you wish to delete this item?', 'invoicing' );
301
-        $localize['FillBillingDetails']         = __( 'Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing' );
302
-        $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' );
303
-        $localize['AreYouSure']                 = __( 'Are you sure?', 'invoicing' );
295
+        $localize['save_invoice']               = __('Save Invoice', 'invoicing');
296
+        $localize['status_publish']             = wpinv_status_nicename('publish');
297
+        $localize['status_pending']             = wpinv_status_nicename('wpi-pending');
298
+        $localize['delete_tax_rate']            = __('Are you sure you wish to delete this tax rate?', 'invoicing');
299
+        $localize['OneItemMin']                 = __('Invoice must contain at least one item', 'invoicing');
300
+        $localize['DeleteInvoiceItem']          = __('Are you sure you wish to delete this item?', 'invoicing');
301
+        $localize['FillBillingDetails']         = __('Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing');
302
+        $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');
303
+        $localize['AreYouSure']                 = __('Are you sure?', 'invoicing');
304 304
         $localize['hasGD']                      = wpinv_gd_active();
305 305
         $localize['hasPM']                      = wpinv_pm_active();
306
-        $localize['emptyInvoice']               = __( 'Add atleast one item to save invoice!', 'invoicing' );
307
-        $localize['deletePackage']              = __( 'GD package items should be deleted from GD payment manager only, otherwise it will break invoices that created with this package!', 'invoicing' );
308
-        $localize['deletePackages']             = __( 'GD package items should be deleted from GD payment manager only', 'invoicing' );
309
-        $localize['deleteInvoiceFirst']         = __( 'This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing' );
306
+        $localize['emptyInvoice']               = __('Add atleast one item to save invoice!', 'invoicing');
307
+        $localize['deletePackage']              = __('GD package items should be deleted from GD payment manager only, otherwise it will break invoices that created with this package!', 'invoicing');
308
+        $localize['deletePackages']             = __('GD package items should be deleted from GD payment manager only', 'invoicing');
309
+        $localize['deleteInvoiceFirst']         = __('This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing');
310 310
 
311
-        $localize = apply_filters( 'wpinv_admin_js_localize', $localize );
311
+        $localize = apply_filters('wpinv_admin_js_localize', $localize);
312 312
 
313
-        wp_localize_script( 'wpinv-admin-script', 'WPInv_Admin', $localize );
313
+        wp_localize_script('wpinv-admin-script', 'WPInv_Admin', $localize);
314 314
     }
315 315
     
316
-    public function admin_body_class( $classes ) {
316
+    public function admin_body_class($classes) {
317 317
         global $pagenow, $post, $current_screen;
318 318
         
319
-        if ( !empty( $current_screen->post_type ) && ( $current_screen->post_type == 'wpi_invoice' || $current_screen->post_type == 'wpi_quote' ) ) {
319
+        if (!empty($current_screen->post_type) && ($current_screen->post_type == 'wpi_invoice' || $current_screen->post_type == 'wpi_quote')) {
320 320
             $classes .= ' wpinv-cpt';
321 321
         }
322 322
         
323
-        $page = isset( $_GET['page'] ) ? strtolower( $_GET['page'] ) : false;
323
+        $page = isset($_GET['page']) ? strtolower($_GET['page']) : false;
324 324
 
325 325
         $add_class = false;
326
-        if ( $pagenow == 'admin.php' && $page ) {
327
-            $add_class = strpos( $page, 'wpinv-' );
326
+        if ($pagenow == 'admin.php' && $page) {
327
+            $add_class = strpos($page, 'wpinv-');
328 328
         }
329 329
         
330 330
         $settings_class = array();
331
-        if ( $page == 'wpinv-settings' ) {
332
-            if ( !empty( $_REQUEST['tab'] ) ) {
333
-                $settings_class[] = sanitize_text_field( $_REQUEST['tab'] );
331
+        if ($page == 'wpinv-settings') {
332
+            if (!empty($_REQUEST['tab'])) {
333
+                $settings_class[] = sanitize_text_field($_REQUEST['tab']);
334 334
             }
335 335
             
336
-            if ( !empty( $_REQUEST['section'] ) ) {
337
-                $settings_class[] = sanitize_text_field( $_REQUEST['section'] );
336
+            if (!empty($_REQUEST['section'])) {
337
+                $settings_class[] = sanitize_text_field($_REQUEST['section']);
338 338
             }
339 339
             
340
-            $settings_class[] = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' ? sanitize_text_field( $_REQUEST['wpi_sub'] ) : 'main';
340
+            $settings_class[] = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' ? sanitize_text_field($_REQUEST['wpi_sub']) : 'main';
341 341
         }
342 342
         
343
-        if ( !empty( $settings_class ) ) {
344
-            $classes .= ' wpi-' . wpinv_sanitize_key( implode( $settings_class, '-' ) );
343
+        if (!empty($settings_class)) {
344
+            $classes .= ' wpi-' . wpinv_sanitize_key(implode($settings_class, '-'));
345 345
         }
346 346
         
347 347
         $post_type = wpinv_admin_post_type();
348 348
 
349
-        if ( $post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $add_class !== false ) {
349
+        if ($post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $add_class !== false) {
350 350
             return $classes .= ' wpinv';
351 351
         }
352 352
         
353
-        if ( $pagenow == 'post.php' && $post_type == 'wpi_item' && !empty( $post ) && !wpinv_item_is_editable( $post ) ) {
353
+        if ($pagenow == 'post.php' && $post_type == 'wpi_item' && !empty($post) && !wpinv_item_is_editable($post)) {
354 354
             $classes .= ' wpi-editable-n';
355 355
         }
356 356
 
@@ -362,20 +362,20 @@  discard block
 block discarded – undo
362 362
     }
363 363
     
364 364
     public function wpinv_actions() {
365
-        if ( isset( $_REQUEST['wpi_action'] ) ) {
366
-            do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST );
365
+        if (isset($_REQUEST['wpi_action'])) {
366
+            do_action('wpinv_' . wpinv_sanitize_key($_REQUEST['wpi_action']), $_REQUEST);
367 367
         }
368 368
     }
369 369
     
370
-    public function pre_get_posts( $wp_query ) {
371
-        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() ) {
372
-            $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses() );
370
+    public function pre_get_posts($wp_query) {
371
+        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()) {
372
+            $wp_query->query_vars['post_status'] = array_keys(wpinv_get_invoice_statuses());
373 373
         }
374 374
         
375 375
         return $wp_query;
376 376
     }
377 377
     
378 378
     public function bp_invoicing_init() {
379
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' );
379
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php');
380 380
     }
381 381
 }
382 382
\ No newline at end of file
Please login to merge, or discard this patch.
includes/class-wpinv-ajax.php 1 patch
Spacing   +228 added lines, -228 removed lines patch added patch discarded remove patch
@@ -7,28 +7,28 @@  discard block
 block discarded – undo
7 7
  */
8 8
  
9 9
 // MUST have WordPress.
10
-if ( !defined( 'WPINC' ) ) {
11
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
10
+if (!defined('WPINC')) {
11
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
12 12
 }
13 13
 
14 14
 class WPInv_Ajax {
15 15
     public static function init() {
16
-        add_action( 'init', array( __CLASS__, 'define_ajax' ), 0 );
17
-        add_action( 'template_redirect', array( __CLASS__, 'do_wpinv_ajax' ), 0 );
16
+        add_action('init', array(__CLASS__, 'define_ajax'), 0);
17
+        add_action('template_redirect', array(__CLASS__, 'do_wpinv_ajax'), 0);
18 18
         self::add_ajax_events();
19 19
     }
20 20
 
21 21
     public static function define_ajax() {
22
-        if ( !empty( $_GET['wpinv-ajax'] ) ) {
23
-            if ( ! defined( 'DOING_AJAX' ) ) {
24
-                define( 'DOING_AJAX', true );
22
+        if (!empty($_GET['wpinv-ajax'])) {
23
+            if (!defined('DOING_AJAX')) {
24
+                define('DOING_AJAX', true);
25 25
             }
26
-            if ( ! defined( 'WC_DOING_AJAX' ) ) {
27
-                define( 'WC_DOING_AJAX', true );
26
+            if (!defined('WC_DOING_AJAX')) {
27
+                define('WC_DOING_AJAX', true);
28 28
             }
29 29
             // Turn off display_errors during AJAX events to prevent malformed JSON
30
-            if ( ! WP_DEBUG || ( WP_DEBUG && ! WP_DEBUG_DISPLAY ) ) {
31
-                @ini_set( 'display_errors', 0 );
30
+            if (!WP_DEBUG || (WP_DEBUG && !WP_DEBUG_DISPLAY)) {
31
+                @ini_set('display_errors', 0);
32 32
             }
33 33
             $GLOBALS['wpdb']->hide_errors();
34 34
         }
@@ -37,24 +37,24 @@  discard block
 block discarded – undo
37 37
     public static function do_wpinv_ajax() {
38 38
         global $wp_query;
39 39
 
40
-        if ( !empty( $_GET['wpinv-ajax'] ) ) {
41
-            $wp_query->set( 'wpinv-ajax', sanitize_text_field( $_GET['wpinv-ajax'] ) );
40
+        if (!empty($_GET['wpinv-ajax'])) {
41
+            $wp_query->set('wpinv-ajax', sanitize_text_field($_GET['wpinv-ajax']));
42 42
         }
43 43
 
44
-        if ( $action = $wp_query->get( 'wpinv-ajax' ) ) {
44
+        if ($action = $wp_query->get('wpinv-ajax')) {
45 45
             self::wpinv_ajax_headers();
46
-            do_action( 'wpinv_ajax_' . sanitize_text_field( $action ) );
46
+            do_action('wpinv_ajax_' . sanitize_text_field($action));
47 47
             die();
48 48
         }
49 49
     }
50 50
     
51 51
     private static function wpinv_ajax_headers() {
52 52
         send_origin_headers();
53
-        @header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) );
54
-        @header( 'X-Robots-Tag: noindex' );
53
+        @header('Content-Type: text/html; charset=' . get_option('blog_charset'));
54
+        @header('X-Robots-Tag: noindex');
55 55
         send_nosniff_header();
56 56
         nocache_headers();
57
-        status_header( 200 );
57
+        status_header(200);
58 58
     }
59 59
     
60 60
     public static function add_ajax_events() {
@@ -77,39 +77,39 @@  discard block
 block discarded – undo
77 77
             'buy_items' => true,
78 78
         );
79 79
 
80
-        foreach ( $ajax_events as $ajax_event => $nopriv ) {
81
-            add_action( 'wp_ajax_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) );
80
+        foreach ($ajax_events as $ajax_event => $nopriv) {
81
+            add_action('wp_ajax_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event));
82 82
             
83
-            if ( !defined( 'WPI_AJAX_' . strtoupper( $nopriv ) ) ) {
84
-                define( 'WPI_AJAX_' . strtoupper( $nopriv ), 1 );
83
+            if (!defined('WPI_AJAX_' . strtoupper($nopriv))) {
84
+                define('WPI_AJAX_' . strtoupper($nopriv), 1);
85 85
             }
86 86
 
87
-            if ( $nopriv ) {
88
-                add_action( 'wp_ajax_nopriv_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) );
87
+            if ($nopriv) {
88
+                add_action('wp_ajax_nopriv_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event));
89 89
 
90
-                add_action( 'wpinv_ajax_' . $ajax_event, array( __CLASS__, $ajax_event ) );
90
+                add_action('wpinv_ajax_' . $ajax_event, array(__CLASS__, $ajax_event));
91 91
             }
92 92
         }
93 93
     }
94 94
     
95 95
     public static function add_note() {
96
-        check_ajax_referer( 'add-invoice-note', '_nonce' );
96
+        check_ajax_referer('add-invoice-note', '_nonce');
97 97
 
98
-        if ( !current_user_can( 'manage_options' ) ) {
98
+        if (!current_user_can('manage_options')) {
99 99
             die(-1);
100 100
         }
101 101
 
102
-        $post_id   = absint( $_POST['post_id'] );
103
-        $note      = wp_kses_post( trim( stripslashes( $_POST['note'] ) ) );
104
-        $note_type = sanitize_text_field( $_POST['note_type'] );
102
+        $post_id   = absint($_POST['post_id']);
103
+        $note      = wp_kses_post(trim(stripslashes($_POST['note'])));
104
+        $note_type = sanitize_text_field($_POST['note_type']);
105 105
 
106 106
         $is_customer_note = $note_type == 'customer' ? 1 : 0;
107 107
 
108
-        if ( $post_id > 0 ) {
109
-            $note_id = wpinv_insert_payment_note( $post_id, $note, $is_customer_note );
108
+        if ($post_id > 0) {
109
+            $note_id = wpinv_insert_payment_note($post_id, $note, $is_customer_note);
110 110
 
111
-            if ( $note_id > 0 && !is_wp_error( $note_id ) ) {
112
-                wpinv_get_invoice_note_line_item( $note_id );
111
+            if ($note_id > 0 && !is_wp_error($note_id)) {
112
+                wpinv_get_invoice_note_line_item($note_id);
113 113
             }
114 114
         }
115 115
 
@@ -117,16 +117,16 @@  discard block
 block discarded – undo
117 117
     }
118 118
 
119 119
     public static function delete_note() {
120
-        check_ajax_referer( 'delete-invoice-note', '_nonce' );
120
+        check_ajax_referer('delete-invoice-note', '_nonce');
121 121
 
122
-        if ( !current_user_can( 'manage_options' ) ) {
122
+        if (!current_user_can('manage_options')) {
123 123
             die(-1);
124 124
         }
125 125
 
126 126
         $note_id = (int)$_POST['note_id'];
127 127
 
128
-        if ( $note_id > 0 ) {
129
-            wp_delete_comment( $note_id, true );
128
+        if ($note_id > 0) {
129
+            wp_delete_comment($note_id, true);
130 130
         }
131 131
 
132 132
         die();
@@ -139,8 +139,8 @@  discard block
 block discarded – undo
139 139
     }
140 140
     
141 141
     public static function checkout() {
142
-        if ( ! defined( 'WPINV_CHECKOUT' ) ) {
143
-            define( 'WPINV_CHECKOUT', true );
142
+        if (!defined('WPINV_CHECKOUT')) {
143
+            define('WPINV_CHECKOUT', true);
144 144
         }
145 145
 
146 146
         wpinv_process_checkout();
@@ -149,53 +149,53 @@  discard block
 block discarded – undo
149 149
     
150 150
     public static function add_invoice_item() {
151 151
         global $wpi_userID, $wpinv_ip_address_country;
152
-        check_ajax_referer( 'invoice-item', '_nonce' );
153
-        if ( !current_user_can( 'manage_options' ) ) {
152
+        check_ajax_referer('invoice-item', '_nonce');
153
+        if (!current_user_can('manage_options')) {
154 154
             die(-1);
155 155
         }
156 156
         
157
-        $item_id    = sanitize_text_field( $_POST['item_id'] );
158
-        $invoice_id = absint( $_POST['invoice_id'] );
157
+        $item_id    = sanitize_text_field($_POST['item_id']);
158
+        $invoice_id = absint($_POST['invoice_id']);
159 159
         
160
-        if ( !is_numeric( $invoice_id ) || !is_numeric( $item_id ) ) {
160
+        if (!is_numeric($invoice_id) || !is_numeric($item_id)) {
161 161
             die();
162 162
         }
163 163
         
164
-        $invoice    = wpinv_get_invoice( $invoice_id );
165
-        if ( empty( $invoice ) ) {
164
+        $invoice = wpinv_get_invoice($invoice_id);
165
+        if (empty($invoice)) {
166 166
             die();
167 167
         }
168 168
         
169
-        if ( $invoice->is_paid() || $invoice->is_refunded() ) {
169
+        if ($invoice->is_paid() || $invoice->is_refunded()) {
170 170
             die(); // Don't allow modify items for paid invoice.
171 171
         }
172 172
         
173
-        if ( !empty( $_POST['user_id'] ) ) {
174
-            $wpi_userID = absint( $_POST['user_id'] ); 
173
+        if (!empty($_POST['user_id'])) {
174
+            $wpi_userID = absint($_POST['user_id']); 
175 175
         }
176 176
 
177
-        $item = new WPInv_Item( $item_id );
178
-        if ( !( !empty( $item ) && $item->post_type == 'wpi_item' ) ) {
177
+        $item = new WPInv_Item($item_id);
178
+        if (!(!empty($item) && $item->post_type == 'wpi_item')) {
179 179
             die();
180 180
         }
181 181
         
182 182
         // Validate item before adding to invoice because recurring item must be paid individually.
183
-        if ( !empty( $invoice->cart_details ) ) {
183
+        if (!empty($invoice->cart_details)) {
184 184
             $valid = true;
185 185
             
186
-            if ( $recurring_item = $invoice->get_recurring() ) {
187
-                if ( $recurring_item != $item_id ) {
186
+            if ($recurring_item = $invoice->get_recurring()) {
187
+                if ($recurring_item != $item_id) {
188 188
                     $valid = false;
189 189
                 }
190
-            } else if ( wpinv_is_recurring_item( $item_id ) ) {
190
+            } else if (wpinv_is_recurring_item($item_id)) {
191 191
                 $valid = false;
192 192
             }
193 193
             
194
-            if ( !$valid ) {
194
+            if (!$valid) {
195 195
                 $response               = array();
196 196
                 $response['success']    = false;
197
-                $response['msg']        = __( 'You can not add item to invoice because recurring item must be paid individually!', 'invoicing' );
198
-                wp_send_json( $response );
197
+                $response['msg']        = __('You can not add item to invoice because recurring item must be paid individually!', 'invoicing');
198
+                wp_send_json($response);
199 199
             }
200 200
         }
201 201
         
@@ -203,9 +203,9 @@  discard block
 block discarded – undo
203 203
         
204 204
         $data                   = array();
205 205
         $data['invoice_id']     = $invoice_id;
206
-        $data['cart_discounts'] = $invoice->get_discounts( true );
206
+        $data['cart_discounts'] = $invoice->get_discounts(true);
207 207
         
208
-        wpinv_set_checkout_session( $data );
208
+        wpinv_set_checkout_session($data);
209 209
         
210 210
         $quantity = wpinv_item_quantities_enabled() && !empty($_POST['qty']) && (int)$_POST['qty'] > 0 ? (int)$_POST['qty'] : 1;
211 211
 
@@ -220,21 +220,21 @@  discard block
 block discarded – undo
220 220
             'fees'          => array()
221 221
         );
222 222
 
223
-        $invoice->add_item( $item_id, $args );
223
+        $invoice->add_item($item_id, $args);
224 224
         $invoice->save();
225 225
         
226
-        if ( empty( $_POST['country'] ) ) {
226
+        if (empty($_POST['country'])) {
227 227
             $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country();
228 228
         }
229
-        if ( empty( $_POST['state'] ) ) {
229
+        if (empty($_POST['state'])) {
230 230
             $_POST['state'] = $invoice->state;
231 231
         }
232 232
          
233
-        $invoice->country   = sanitize_text_field( $_POST['country'] );
234
-        $invoice->state     = sanitize_text_field( $_POST['state'] );
233
+        $invoice->country   = sanitize_text_field($_POST['country']);
234
+        $invoice->state     = sanitize_text_field($_POST['state']);
235 235
         
236
-        $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) );
237
-        $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) );
236
+        $invoice->set('country', sanitize_text_field($_POST['country']));
237
+        $invoice->set('state', sanitize_text_field($_POST['state']));
238 238
         
239 239
         $wpinv_ip_address_country = $invoice->country;
240 240
 
@@ -242,7 +242,7 @@  discard block
 block discarded – undo
242 242
         
243 243
         $response                       = array();
244 244
         $response['success']            = true;
245
-        $response['data']['items']      = wpinv_admin_get_line_items( $invoice );
245
+        $response['data']['items']      = wpinv_admin_get_line_items($invoice);
246 246
         $response['data']['subtotal']   = $invoice->get_subtotal();
247 247
         $response['data']['subtotalf']  = $invoice->get_subtotal(true);
248 248
         $response['data']['tax']        = $invoice->get_tax();
@@ -254,40 +254,40 @@  discard block
 block discarded – undo
254 254
         
255 255
         wpinv_set_checkout_session($checkout_session);
256 256
         
257
-        wp_send_json( $response );
257
+        wp_send_json($response);
258 258
     }
259 259
     
260 260
     public static function remove_invoice_item() {
261 261
         global $wpi_userID, $wpinv_ip_address_country;
262 262
         
263
-        check_ajax_referer( 'invoice-item', '_nonce' );
264
-        if ( !current_user_can( 'manage_options' ) ) {
263
+        check_ajax_referer('invoice-item', '_nonce');
264
+        if (!current_user_can('manage_options')) {
265 265
             die(-1);
266 266
         }
267 267
         
268
-        $item_id    = sanitize_text_field( $_POST['item_id'] );
269
-        $invoice_id = absint( $_POST['invoice_id'] );
270
-        $cart_index = isset( $_POST['index'] ) && $_POST['index'] >= 0 ? $_POST['index'] : false;
268
+        $item_id    = sanitize_text_field($_POST['item_id']);
269
+        $invoice_id = absint($_POST['invoice_id']);
270
+        $cart_index = isset($_POST['index']) && $_POST['index'] >= 0 ? $_POST['index'] : false;
271 271
         
272
-        if ( !is_numeric( $invoice_id ) || !is_numeric( $item_id ) ) {
272
+        if (!is_numeric($invoice_id) || !is_numeric($item_id)) {
273 273
             die();
274 274
         }
275 275
 
276
-        $invoice    = wpinv_get_invoice( $invoice_id );
277
-        if ( empty( $invoice ) ) {
276
+        $invoice = wpinv_get_invoice($invoice_id);
277
+        if (empty($invoice)) {
278 278
             die();
279 279
         }
280 280
         
281
-        if ( $invoice->is_paid() || $invoice->is_refunded() ) {
281
+        if ($invoice->is_paid() || $invoice->is_refunded()) {
282 282
             die(); // Don't allow modify items for paid invoice.
283 283
         }
284 284
         
285
-        if ( !empty( $_POST['user_id'] ) ) {
286
-            $wpi_userID = absint( $_POST['user_id'] ); 
285
+        if (!empty($_POST['user_id'])) {
286
+            $wpi_userID = absint($_POST['user_id']); 
287 287
         }
288 288
 
289
-        $item       = new WPInv_Item( $item_id );
290
-        if ( !( !empty( $item ) && $item->post_type == 'wpi_item' ) ) {
289
+        $item = new WPInv_Item($item_id);
290
+        if (!(!empty($item) && $item->post_type == 'wpi_item')) {
291 291
             die();
292 292
         }
293 293
         
@@ -295,9 +295,9 @@  discard block
 block discarded – undo
295 295
         
296 296
         $data                   = array();
297 297
         $data['invoice_id']     = $invoice_id;
298
-        $data['cart_discounts'] = $invoice->get_discounts( true );
298
+        $data['cart_discounts'] = $invoice->get_discounts(true);
299 299
         
300
-        wpinv_set_checkout_session( $data );
300
+        wpinv_set_checkout_session($data);
301 301
 
302 302
         $args = array(
303 303
             'id'         => $item_id,
@@ -305,21 +305,21 @@  discard block
 block discarded – undo
305 305
             'cart_index' => $cart_index
306 306
         );
307 307
 
308
-        $invoice->remove_item( $item_id, $args );
308
+        $invoice->remove_item($item_id, $args);
309 309
         $invoice->save();
310 310
         
311
-        if ( empty( $_POST['country'] ) ) {
311
+        if (empty($_POST['country'])) {
312 312
             $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country();
313 313
         }
314
-        if ( empty( $_POST['state'] ) ) {
314
+        if (empty($_POST['state'])) {
315 315
             $_POST['state'] = $invoice->state;
316 316
         }
317 317
          
318
-        $invoice->country   = sanitize_text_field( $_POST['country'] );
319
-        $invoice->state     = sanitize_text_field( $_POST['state'] );
318
+        $invoice->country   = sanitize_text_field($_POST['country']);
319
+        $invoice->state     = sanitize_text_field($_POST['state']);
320 320
         
321
-        $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) );
322
-        $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) );
321
+        $invoice->set('country', sanitize_text_field($_POST['country']));
322
+        $invoice->set('state', sanitize_text_field($_POST['state']));
323 323
         
324 324
         $wpinv_ip_address_country = $invoice->country;
325 325
         
@@ -327,7 +327,7 @@  discard block
 block discarded – undo
327 327
         
328 328
         $response                       = array();
329 329
         $response['success']            = true;
330
-        $response['data']['items']      = wpinv_admin_get_line_items( $invoice );
330
+        $response['data']['items']      = wpinv_admin_get_line_items($invoice);
331 331
         $response['data']['subtotal']   = $invoice->get_subtotal();
332 332
         $response['data']['subtotalf']  = $invoice->get_subtotal(true);
333 333
         $response['data']['tax']        = $invoice->get_tax();
@@ -339,40 +339,40 @@  discard block
 block discarded – undo
339 339
         
340 340
         wpinv_set_checkout_session($checkout_session);
341 341
         
342
-        wp_send_json( $response );
342
+        wp_send_json($response);
343 343
     }
344 344
     
345 345
     public static function create_invoice_item() {
346
-        check_ajax_referer( 'invoice-item', '_nonce' );
347
-        if ( !current_user_can( 'manage_options' ) ) {
346
+        check_ajax_referer('invoice-item', '_nonce');
347
+        if (!current_user_can('manage_options')) {
348 348
             die(-1);
349 349
         }
350 350
         
351
-        $invoice_id = absint( $_POST['invoice_id'] );
351
+        $invoice_id = absint($_POST['invoice_id']);
352 352
 
353 353
         // Find the item
354
-        if ( !is_numeric( $invoice_id ) ) {
354
+        if (!is_numeric($invoice_id)) {
355 355
             die();
356 356
         }        
357 357
         
358
-        $invoice     = wpinv_get_invoice( $invoice_id );
359
-        if ( empty( $invoice ) ) {
358
+        $invoice = wpinv_get_invoice($invoice_id);
359
+        if (empty($invoice)) {
360 360
             die();
361 361
         }
362 362
         
363 363
         // Validate item before adding to invoice because recurring item must be paid individually.
364
-        if ( !empty( $invoice->cart_details ) && $invoice->get_recurring() ) {
364
+        if (!empty($invoice->cart_details) && $invoice->get_recurring()) {
365 365
             $response               = array();
366 366
             $response['success']    = false;
367
-            $response['msg']        = __( 'You can not add item to invoice because recurring item must be paid individually!', 'invoicing' );
368
-            wp_send_json( $response );
367
+            $response['msg']        = __('You can not add item to invoice because recurring item must be paid individually!', 'invoicing');
368
+            wp_send_json($response);
369 369
         }        
370 370
         
371 371
         $save_item = $_POST['_wpinv_quick'];
372 372
         
373 373
         $meta               = array();
374 374
         $meta['type']       = !empty($save_item['type']) ? sanitize_text_field($save_item['type']) : 'custom';
375
-        $meta['price']      = !empty($save_item['price']) ? wpinv_sanitize_amount( $save_item['price'] ) : 0;
375
+        $meta['price']      = !empty($save_item['price']) ? wpinv_sanitize_amount($save_item['price']) : 0;
376 376
         $meta['vat_rule']   = !empty($save_item['vat_rule']) ? sanitize_text_field($save_item['vat_rule']) : 'digital';
377 377
         $meta['vat_class']  = !empty($save_item['vat_class']) ? sanitize_text_field($save_item['vat_class']) : '_standard';
378 378
         
@@ -382,9 +382,9 @@  discard block
 block discarded – undo
382 382
         $data['meta']           = $meta;
383 383
         
384 384
         $item = new WPInv_Item();
385
-        $item->create( $data );
385
+        $item->create($data);
386 386
         
387
-        if ( !empty( $item ) ) {
387
+        if (!empty($item)) {
388 388
             $_POST['item_id']   = $item->ID;
389 389
             $_POST['qty']       = !empty($save_item['qty']) && $save_item['qty'] > 0 ? (int)$save_item['qty'] : 1;
390 390
             
@@ -394,15 +394,15 @@  discard block
 block discarded – undo
394 394
     }
395 395
     
396 396
     public static function get_billing_details() {
397
-        check_ajax_referer( 'get-billing-details', '_nonce' );
397
+        check_ajax_referer('get-billing-details', '_nonce');
398 398
         
399
-        if ( !current_user_can( 'manage_options' ) ) {
399
+        if (!current_user_can('manage_options')) {
400 400
             die(-1);
401 401
         }
402 402
 
403 403
         $user_id            = (int)$_POST['user_id'];
404 404
         $billing_details    = wpinv_get_user_address($user_id);
405
-        $billing_details    = apply_filters( 'wpinv_fill_billing_details', $billing_details, $user_id );
405
+        $billing_details    = apply_filters('wpinv_fill_billing_details', $billing_details, $user_id);
406 406
         
407 407
         if (isset($billing_details['user_id'])) {
408 408
             unset($billing_details['user_id']);
@@ -416,20 +416,20 @@  discard block
 block discarded – undo
416 416
         $response['success']                    = true;
417 417
         $response['data']['billing_details']    = $billing_details;
418 418
         
419
-        wp_send_json( $response );
419
+        wp_send_json($response);
420 420
     }
421 421
     
422 422
     public static function admin_recalculate_totals() {
423 423
         global $wpi_userID, $wpinv_ip_address_country;
424 424
         
425
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
426
-        if ( !current_user_can( 'manage_options' ) ) {
425
+        check_ajax_referer('wpinv-nonce', '_nonce');
426
+        if (!current_user_can('manage_options')) {
427 427
             die(-1);
428 428
         }
429 429
         
430
-        $invoice_id = absint( $_POST['invoice_id'] );        
431
-        $invoice    = wpinv_get_invoice( $invoice_id );
432
-        if ( empty( $invoice ) ) {
430
+        $invoice_id = absint($_POST['invoice_id']);        
431
+        $invoice    = wpinv_get_invoice($invoice_id);
432
+        if (empty($invoice)) {
433 433
             die();
434 434
         }
435 435
         
@@ -437,23 +437,23 @@  discard block
 block discarded – undo
437 437
         
438 438
         $data                   = array();
439 439
         $data['invoice_id']     = $invoice_id;
440
-        $data['cart_discounts'] = $invoice->get_discounts( true );
440
+        $data['cart_discounts'] = $invoice->get_discounts(true);
441 441
         
442
-        wpinv_set_checkout_session( $data );
442
+        wpinv_set_checkout_session($data);
443 443
         
444
-        if ( !empty( $_POST['user_id'] ) ) {
445
-            $wpi_userID = absint( $_POST['user_id'] ); 
444
+        if (!empty($_POST['user_id'])) {
445
+            $wpi_userID = absint($_POST['user_id']); 
446 446
         }
447 447
         
448
-        if ( empty( $_POST['country'] ) ) {
448
+        if (empty($_POST['country'])) {
449 449
             $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country();
450 450
         }
451 451
             
452
-        $invoice->country = sanitize_text_field( $_POST['country'] );
453
-        $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) );
454
-        if ( isset( $_POST['state'] ) ) {
455
-            $invoice->state = sanitize_text_field( $_POST['state'] );
456
-            $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) );
452
+        $invoice->country = sanitize_text_field($_POST['country']);
453
+        $invoice->set('country', sanitize_text_field($_POST['country']));
454
+        if (isset($_POST['state'])) {
455
+            $invoice->state = sanitize_text_field($_POST['state']);
456
+            $invoice->set('state', sanitize_text_field($_POST['state']));
457 457
         }
458 458
         
459 459
         $wpinv_ip_address_country = $invoice->country;
@@ -462,7 +462,7 @@  discard block
 block discarded – undo
462 462
         
463 463
         $response                       = array();
464 464
         $response['success']            = true;
465
-        $response['data']['items']      = wpinv_admin_get_line_items( $invoice );
465
+        $response['data']['items']      = wpinv_admin_get_line_items($invoice);
466 466
         $response['data']['subtotal']   = $invoice->get_subtotal();
467 467
         $response['data']['subtotalf']  = $invoice->get_subtotal(true);
468 468
         $response['data']['tax']        = $invoice->get_tax();
@@ -474,25 +474,25 @@  discard block
 block discarded – undo
474 474
         
475 475
         wpinv_set_checkout_session($checkout_session);
476 476
         
477
-        wp_send_json( $response );
477
+        wp_send_json($response);
478 478
     }
479 479
     
480 480
     public static function admin_apply_discount() {
481 481
         global $wpi_userID;
482 482
         
483
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
484
-        if ( !current_user_can( 'manage_options' ) ) {
483
+        check_ajax_referer('wpinv-nonce', '_nonce');
484
+        if (!current_user_can('manage_options')) {
485 485
             die(-1);
486 486
         }
487 487
         
488
-        $invoice_id = absint( $_POST['invoice_id'] );
489
-        $discount_code = sanitize_text_field( $_POST['code'] );
490
-        if ( empty( $invoice_id ) || empty( $discount_code ) ) {
488
+        $invoice_id = absint($_POST['invoice_id']);
489
+        $discount_code = sanitize_text_field($_POST['code']);
490
+        if (empty($invoice_id) || empty($discount_code)) {
491 491
             die();
492 492
         }
493 493
         
494
-        $invoice = wpinv_get_invoice( $invoice_id );
495
-        if ( empty( $invoice ) || ( !empty( $invoice ) && ( $invoice->is_paid() || $invoice->is_refunded() ) ) ) {
494
+        $invoice = wpinv_get_invoice($invoice_id);
495
+        if (empty($invoice) || (!empty($invoice) && ($invoice->is_paid() || $invoice->is_refunded()))) {
496 496
             die();
497 497
         }
498 498
         
@@ -500,49 +500,49 @@  discard block
 block discarded – undo
500 500
         
501 501
         $data                   = array();
502 502
         $data['invoice_id']     = $invoice_id;
503
-        $data['cart_discounts'] = $invoice->get_discounts( true );
503
+        $data['cart_discounts'] = $invoice->get_discounts(true);
504 504
         
505
-        wpinv_set_checkout_session( $data );
505
+        wpinv_set_checkout_session($data);
506 506
         
507 507
         $response               = array();
508 508
         $response['success']    = false;
509
-        $response['msg']        = __( 'This discount is invalid.', 'invoicing' );
509
+        $response['msg']        = __('This discount is invalid.', 'invoicing');
510 510
         $response['data']['code'] = $discount_code;
511 511
         
512
-        if ( wpinv_is_discount_valid( $discount_code, $invoice->get_user_id() ) ) {
513
-            $discounts = wpinv_set_cart_discount( $discount_code );
512
+        if (wpinv_is_discount_valid($discount_code, $invoice->get_user_id())) {
513
+            $discounts = wpinv_set_cart_discount($discount_code);
514 514
             
515 515
             $response['success'] = true;
516
-            $response['msg'] = __( 'Discount has been applied successfully.', 'invoicing' );
517
-        }  else {
516
+            $response['msg'] = __('Discount has been applied successfully.', 'invoicing');
517
+        } else {
518 518
             $errors = wpinv_get_errors();
519
-            if ( !empty( $errors['wpinv-discount-error'] ) ) {
519
+            if (!empty($errors['wpinv-discount-error'])) {
520 520
                 $response['msg'] = $errors['wpinv-discount-error'];
521 521
             }
522
-            wpinv_unset_error( 'wpinv-discount-error' );
522
+            wpinv_unset_error('wpinv-discount-error');
523 523
         }
524 524
         
525 525
         wpinv_set_checkout_session($checkout_session);
526 526
         
527
-        wp_send_json( $response );
527
+        wp_send_json($response);
528 528
     }
529 529
     
530 530
     public static function admin_remove_discount() {
531 531
         global $wpi_userID;
532 532
         
533
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
534
-        if ( !current_user_can( 'manage_options' ) ) {
533
+        check_ajax_referer('wpinv-nonce', '_nonce');
534
+        if (!current_user_can('manage_options')) {
535 535
             die(-1);
536 536
         }
537 537
         
538
-        $invoice_id = absint( $_POST['invoice_id'] );
539
-        $discount_code = sanitize_text_field( $_POST['code'] );
540
-        if ( empty( $invoice_id ) || empty( $discount_code ) ) {
538
+        $invoice_id = absint($_POST['invoice_id']);
539
+        $discount_code = sanitize_text_field($_POST['code']);
540
+        if (empty($invoice_id) || empty($discount_code)) {
541 541
             die();
542 542
         }
543 543
         
544
-        $invoice = wpinv_get_invoice( $invoice_id );
545
-        if ( empty( $invoice ) || ( !empty( $invoice ) && ( $invoice->is_paid() || $invoice->is_refunded() ) ) ) {
544
+        $invoice = wpinv_get_invoice($invoice_id);
545
+        if (empty($invoice) || (!empty($invoice) && ($invoice->is_paid() || $invoice->is_refunded()))) {
546 546
             die();
547 547
         }
548 548
         
@@ -550,38 +550,38 @@  discard block
 block discarded – undo
550 550
         
551 551
         $data                   = array();
552 552
         $data['invoice_id']     = $invoice_id;
553
-        $data['cart_discounts'] = $invoice->get_discounts( true );
553
+        $data['cart_discounts'] = $invoice->get_discounts(true);
554 554
         
555
-        wpinv_set_checkout_session( $data );
555
+        wpinv_set_checkout_session($data);
556 556
         
557 557
         $response               = array();
558 558
         $response['success']    = false;
559 559
         $response['msg']        = NULL;
560 560
         
561
-        $discounts  = wpinv_unset_cart_discount( $discount_code );
561
+        $discounts = wpinv_unset_cart_discount($discount_code);
562 562
         $response['success'] = true;
563
-        $response['msg'] = __( 'Discount has been removed successfully.', 'invoicing' );
563
+        $response['msg'] = __('Discount has been removed successfully.', 'invoicing');
564 564
         
565 565
         wpinv_set_checkout_session($checkout_session);
566 566
         
567
-        wp_send_json( $response );
567
+        wp_send_json($response);
568 568
     }
569 569
     
570 570
     public static function check_email() {
571
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
572
-        if ( !current_user_can( 'manage_options' ) ) {
571
+        check_ajax_referer('wpinv-nonce', '_nonce');
572
+        if (!current_user_can('manage_options')) {
573 573
             die(-1);
574 574
         }
575 575
         
576
-        $email = sanitize_text_field( $_POST['email'] );
576
+        $email = sanitize_text_field($_POST['email']);
577 577
         
578 578
         $response = array();
579
-        if ( is_email( $email ) && email_exists( $email ) && $user_data = get_user_by( 'email', $email ) ) {
579
+        if (is_email($email) && email_exists($email) && $user_data = get_user_by('email', $email)) {
580 580
             $user_id            = $user_data->ID;
581 581
             $user_login         = $user_data->user_login;
582 582
             $display_name       = $user_data->display_name ? $user_data->display_name : $user_login;
583 583
             $billing_details    = wpinv_get_user_address($user_id);
584
-            $billing_details    = apply_filters( 'wpinv_fill_billing_details', $billing_details, $user_id );
584
+            $billing_details    = apply_filters('wpinv_fill_billing_details', $billing_details, $user_id);
585 585
             
586 586
             if (isset($billing_details['user_id'])) {
587 587
                 unset($billing_details['user_id']);
@@ -597,54 +597,54 @@  discard block
 block discarded – undo
597 597
             $response['data']['billing_details']    = $billing_details;
598 598
         }
599 599
         
600
-        wp_send_json( $response );
600
+        wp_send_json($response);
601 601
     }
602 602
     
603 603
     public static function run_tool() {
604
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
605
-        if ( !current_user_can( 'manage_options' ) ) {
604
+        check_ajax_referer('wpinv-nonce', '_nonce');
605
+        if (!current_user_can('manage_options')) {
606 606
             die(-1);
607 607
         }
608 608
         
609
-        $tool = sanitize_text_field( $_POST['tool'] );
609
+        $tool = sanitize_text_field($_POST['tool']);
610 610
         
611
-        do_action( 'wpinv_run_tool' );
611
+        do_action('wpinv_run_tool');
612 612
         
613
-        if ( !empty( $tool ) ) {
614
-            do_action( 'wpinv_tool_' . $tool );
613
+        if (!empty($tool)) {
614
+            do_action('wpinv_tool_' . $tool);
615 615
         }
616 616
     }
617 617
     
618 618
     public static function apply_discount() {
619 619
         global $wpi_userID;
620 620
         
621
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
621
+        check_ajax_referer('wpinv-nonce', '_nonce');
622 622
         
623 623
         $response = array();
624 624
         
625
-        if ( isset( $_POST['code'] ) ) {
626
-            $discount_code = sanitize_text_field( $_POST['code'] );
625
+        if (isset($_POST['code'])) {
626
+            $discount_code = sanitize_text_field($_POST['code']);
627 627
 
628 628
             $response['success']        = false;
629 629
             $response['msg']            = '';
630 630
             $response['data']['code']   = $discount_code;
631 631
             
632 632
             $invoice = wpinv_get_invoice_cart();
633
-            if ( empty( $invoice->ID ) ) {
634
-                $response['msg'] = __( 'Invalid checkout request.', 'invoicing' );
635
-                wp_send_json( $response );
633
+            if (empty($invoice->ID)) {
634
+                $response['msg'] = __('Invalid checkout request.', 'invoicing');
635
+                wp_send_json($response);
636 636
             }
637 637
 
638 638
             $wpi_userID = $invoice->get_user_id();
639 639
 
640
-            if ( wpinv_is_discount_valid( $discount_code, $wpi_userID ) ) {
641
-                $discount       = wpinv_get_discount_by_code( $discount_code );
642
-                $discounts      = wpinv_set_cart_discount( $discount_code );
643
-                $amount         = wpinv_format_discount_rate( wpinv_get_discount_type( $discount->ID ), wpinv_get_discount_amount( $discount->ID ) );
644
-                $total          = wpinv_get_cart_total( null, $discounts );
645
-                $cart_totals    = wpinv_recalculate_tax( true );
640
+            if (wpinv_is_discount_valid($discount_code, $wpi_userID)) {
641
+                $discount       = wpinv_get_discount_by_code($discount_code);
642
+                $discounts      = wpinv_set_cart_discount($discount_code);
643
+                $amount         = wpinv_format_discount_rate(wpinv_get_discount_type($discount->ID), wpinv_get_discount_amount($discount->ID));
644
+                $total          = wpinv_get_cart_total(null, $discounts);
645
+                $cart_totals    = wpinv_recalculate_tax(true);
646 646
             
647
-                if ( !empty( $cart_totals ) ) {
647
+                if (!empty($cart_totals)) {
648 648
                     $response['success']        = true;
649 649
                     $response['data']           = $cart_totals;
650 650
                     $response['data']['code']   = $discount_code;
@@ -653,29 +653,29 @@  discard block
 block discarded – undo
653 653
                 }
654 654
             } else {
655 655
                 $errors = wpinv_get_errors();
656
-                $response['msg']  = $errors['wpinv-discount-error'];
657
-                wpinv_unset_error( 'wpinv-discount-error' );
656
+                $response['msg'] = $errors['wpinv-discount-error'];
657
+                wpinv_unset_error('wpinv-discount-error');
658 658
             }
659 659
 
660 660
             // Allow for custom discount code handling
661
-            $response = apply_filters( 'wpinv_ajax_discount_response', $response );
661
+            $response = apply_filters('wpinv_ajax_discount_response', $response);
662 662
         }
663 663
         
664
-        wp_send_json( $response );
664
+        wp_send_json($response);
665 665
     }
666 666
     
667 667
     public static function remove_discount() {
668
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
668
+        check_ajax_referer('wpinv-nonce', '_nonce');
669 669
         
670 670
         $response = array();
671 671
         
672
-        if ( isset( $_POST['code'] ) ) {
673
-            $discount_code  = sanitize_text_field( $_POST['code'] );
674
-            $discounts      = wpinv_unset_cart_discount( $discount_code );
675
-            $total          = wpinv_get_cart_total( null, $discounts );
676
-            $cart_totals    = wpinv_recalculate_tax( true );
672
+        if (isset($_POST['code'])) {
673
+            $discount_code  = sanitize_text_field($_POST['code']);
674
+            $discounts      = wpinv_unset_cart_discount($discount_code);
675
+            $total          = wpinv_get_cart_total(null, $discounts);
676
+            $cart_totals    = wpinv_recalculate_tax(true);
677 677
             
678
-            if ( !empty( $cart_totals ) ) {
678
+            if (!empty($cart_totals)) {
679 679
                 $response['success']        = true;
680 680
                 $response['data']           = $cart_totals;
681 681
                 $response['data']['code']   = $discount_code;
@@ -684,10 +684,10 @@  discard block
 block discarded – undo
684 684
             }
685 685
             
686 686
             // Allow for custom discount code handling
687
-            $response = apply_filters( 'wpinv_ajax_discount_response', $response );
687
+            $response = apply_filters('wpinv_ajax_discount_response', $response);
688 688
         }
689 689
         
690
-        wp_send_json( $response );
690
+        wp_send_json($response);
691 691
     }
692 692
 
693 693
 
@@ -696,20 +696,20 @@  discard block
 block discarded – undo
696 696
      *
697 697
      * @since 1.0.0
698 698
      */
699
-    public function buy_items(){
699
+    public function buy_items() {
700 700
 
701 701
         $user_id = get_current_user_id();
702
-        if(!$user_id ){ // if not logged in then lets redirect to the login page
702
+        if (!$user_id) { // if not logged in then lets redirect to the login page
703 703
 
704 704
             wp_send_json(array(
705
-                'success' => wp_login_url( wp_get_referer() )
705
+                'success' => wp_login_url(wp_get_referer())
706 706
             ));
707
-        }else{
707
+        } else {
708 708
 
709 709
             // only check nonce if logged in as it could be cached when logged out.
710
-            if ( ! isset( $_POST['wpinv_buy_nonce'] ) || ! wp_verify_nonce( $_POST['wpinv_buy_nonce'], 'wpinv_buy_items' ) ) {
710
+            if (!isset($_POST['wpinv_buy_nonce']) || !wp_verify_nonce($_POST['wpinv_buy_nonce'], 'wpinv_buy_items')) {
711 711
                 wp_send_json(array(
712
-                    'error' => __('Security checks failed.','invoicing')
712
+                    'error' => __('Security checks failed.', 'invoicing')
713 713
                 ));
714 714
                 wp_die();
715 715
             }
@@ -717,36 +717,36 @@  discard block
 block discarded – undo
717 717
             // allow to set a custom price through post_id
718 718
             $items = $_POST['items'];
719 719
             $related_post_id = isset($_POST['post_id']) ? (int)$_POST['post_id'] : 0;
720
-            $custom_item_price = $related_post_id ? abs(get_post_meta($related_post_id,'_wpi_custom_price',true)) : 0;
720
+            $custom_item_price = $related_post_id ? abs(get_post_meta($related_post_id, '_wpi_custom_price', true)) : 0;
721 721
 
722 722
 
723 723
             $cart_items = array();
724
-            if($items){
725
-                $items = explode(',',$items);
726
-                foreach($items as $item){
724
+            if ($items) {
725
+                $items = explode(',', $items);
726
+                foreach ($items as $item) {
727 727
                     $item_id = $item;
728 728
                     $quantity = 1;
729 729
                     if (strpos($item, '|') !== false) {
730
-                        $item_parts = explode('|',$item);
730
+                        $item_parts = explode('|', $item);
731 731
                         $item_id = $item_parts[0];
732 732
                         $quantity = $item_parts[1];
733 733
                     }
734 734
 
735
-                    if($item_id && $quantity){
735
+                    if ($item_id && $quantity) {
736 736
                         $cart_items_arr = array(
737 737
                             'id'            => (int)$item_id,
738 738
                             'quantity'      => (int)$quantity
739 739
                         );
740 740
 
741 741
                         // if there is a related post id then add it to meta
742
-                        if($related_post_id){
742
+                        if ($related_post_id) {
743 743
                             $cart_items_arr['meta'] = array(
744 744
                                 'post_id'   => $related_post_id
745 745
                             );
746 746
                         }
747 747
 
748 748
                         // if there is a custom price then set it.
749
-                        if($custom_item_price){
749
+                        if ($custom_item_price) {
750 750
                             $cart_items_arr['custom_price'] = $custom_item_price;
751 751
 
752 752
                         }
@@ -765,12 +765,12 @@  discard block
 block discarded – undo
765 765
              * @param int $related_post_id The related post id if any.
766 766
              * @since 1.0.0
767 767
              */
768
-            $cart_items = apply_filters('wpinv_buy_cart_items',$cart_items,$related_post_id);
768
+            $cart_items = apply_filters('wpinv_buy_cart_items', $cart_items, $related_post_id);
769 769
 
770 770
 
771 771
             //make sure its not in the cart already, if it is then redirect to checkout.
772 772
             $cart_invoice = wpinv_get_invoice_cart();
773
-            if(isset($cart_invoice->items) && !empty($cart_invoice->items) && !empty($cart_items) && serialize($cart_invoice->items)==serialize($cart_items) ){
773
+            if (isset($cart_invoice->items) && !empty($cart_invoice->items) && !empty($cart_items) && serialize($cart_invoice->items) == serialize($cart_items)) {
774 774
                 wp_send_json(array(
775 775
                     'success' =>  $cart_invoice->get_checkout_payment_url()
776 776
                 ));
@@ -779,25 +779,25 @@  discard block
 block discarded – undo
779 779
 
780 780
 
781 781
             // check if user has invoice with same items waiting to be paid.
782
-            $user_invoices = wpinv_get_users_invoices( $user_id , 1 , false , 'pending' );
783
-            if(!empty($user_invoices)){
782
+            $user_invoices = wpinv_get_users_invoices($user_id, 1, false, 'pending');
783
+            if (!empty($user_invoices)) {
784 784
 
785
-                foreach($user_invoices as $user_invoice){
785
+                foreach ($user_invoices as $user_invoice) {
786 786
                     $user_cart_details = array();
787
-                    $invoice  = wpinv_get_invoice( $user_invoice->ID );
787
+                    $invoice = wpinv_get_invoice($user_invoice->ID);
788 788
                     $cart_details = $invoice->get_cart_details();
789
-                    if(!empty($cart_details)){
790
-                        foreach($cart_details as $invoice_item){
789
+                    if (!empty($cart_details)) {
790
+                        foreach ($cart_details as $invoice_item) {
791 791
 
792 792
                             $ii_arr = array();
793 793
                             $ii_arr['id'] = (int)$invoice_item['id'];
794 794
                             $ii_arr['quantity'] = (int)$invoice_item['quantity'];
795 795
 
796
-                            if(isset($invoice_item['meta']) && !empty($invoice_item['meta'])){
796
+                            if (isset($invoice_item['meta']) && !empty($invoice_item['meta'])) {
797 797
                                 $ii_arr['meta'] = $invoice_item['meta'];
798 798
                             }
799 799
 
800
-                            if(isset($invoice_item['custom_price']) && !empty($invoice_item['custom_price'])){
800
+                            if (isset($invoice_item['custom_price']) && !empty($invoice_item['custom_price'])) {
801 801
                                 $ii_arr['custom_price'] = $invoice_item['custom_price'];
802 802
                             }
803 803
 
@@ -806,7 +806,7 @@  discard block
 block discarded – undo
806 806
                         }
807 807
                     }
808 808
 
809
-                    if(!empty($user_cart_details) && serialize($cart_items) == serialize($user_cart_details)){
809
+                    if (!empty($user_cart_details) && serialize($cart_items) == serialize($user_cart_details)) {
810 810
                         wp_send_json(array(
811 811
                             'success' =>  $invoice->get_checkout_payment_url()
812 812
                         ));
@@ -819,7 +819,7 @@  discard block
 block discarded – undo
819 819
 
820 820
 
821 821
             // Create invoice and send user to checkout
822
-            if(!empty($cart_items)){
822
+            if (!empty($cart_items)) {
823 823
 
824 824
                 $invoice_data = array(
825 825
                     'status'        =>  'wpi-pending',
@@ -829,26 +829,26 @@  discard block
 block discarded – undo
829 829
                 );
830 830
 
831 831
                 // default invoice args
832
-                $invoice_data['status']  = !empty( $invoice_data['status'] ) ? $invoice_data['status'] : 'pending';
833
-                $invoice_data['user_id'] = !empty( $invoice_data['user_id'] ) ? (int)$invoice_data['user_id'] : get_current_user_id();
832
+                $invoice_data['status']  = !empty($invoice_data['status']) ? $invoice_data['status'] : 'pending';
833
+                $invoice_data['user_id'] = !empty($invoice_data['user_id']) ? (int)$invoice_data['user_id'] : get_current_user_id();
834 834
 
835
-                $invoice = wpinv_insert_invoice( $invoice_data, true );
835
+                $invoice = wpinv_insert_invoice($invoice_data, true);
836 836
 
837
-                if(isset($invoice->ID)){
837
+                if (isset($invoice->ID)) {
838 838
 
839 839
                     wp_send_json(array(
840 840
                         'success' =>  $invoice->get_checkout_payment_url()
841 841
                     ));
842 842
 
843
-                }else{
843
+                } else {
844 844
                     wp_send_json(array(
845
-                        'error' => __('Invoice failed to create','invoicing')
845
+                        'error' => __('Invoice failed to create', 'invoicing')
846 846
                     ));
847 847
                 }
848 848
 
849
-            }else{
849
+            } else {
850 850
                 wp_send_json(array(
851
-                    'error' => __('Items not valid.','invoicing')
851
+                    'error' => __('Items not valid.', 'invoicing')
852 852
                 ));
853 853
             }
854 854
 
Please login to merge, or discard this patch.